Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / Re: Pause/Resume execution in method on: 2012-08-25 19:03:16
Interesting. Are you talking about allowing users to write any Java code (including IO, reflection, and your game's classes) or just a subset of the platform?

At the moment, yes, but eventually I'll be putting in a security manager to minimize a players ability to cheat. I really want to give the player as much freedom as possible for the type of programs they can run, which is why I'm going to need a way to deal with the decision loop running for too long. But things might get a little nuts if access to reflection methods and game classes was allowed. Of course if I do wind up using a scripting language instead I won't have to worry about that, but I kind of like when games let the players cheat and completely break the game if they are clever enough, so at the very least I'm going to put in a way to disable or reduce the security, maybe as an unlockable.
2  Game Development / Game Mechanics / Re: Pause/Resume execution in method on: 2012-08-24 15:24:41
Thanks Roquen and Riven, I'll look into both of those.

I wasn't planning on giving every entity its own thread, I just need a way to give each a restricted and roughly equal amount of computing per tick, and bytecode instrumentation seems a little too complicated if I can just use threads. I've used Akka some, so I imagine I can implement it in that but it seems like it'll have a lot of overhead and add a level of complexity I'm not sure I need. It would be pretty easy to give action points for what an entity does, but what I'm worried about is it spending a long time computing and holding up the game for everyone else. I'll give just doing a cost estimate with static analysis for each entity's decision loop a try though.
3  Game Development / Game Mechanics / Pause/Resume execution in method on: 2012-08-24 04:46:00
I'm making a programming game where the player can program their allies' behavior. The player writes the body of the decide() function for a given ally, which can be filled out with any java code but has to return an action. I would like to give each ally a set, restricted amount of computation per tick so 1) adding more entities doesn't slow down the game too much, and 2) The time an entity spends computing is reflected in game, so if an ally spends more time "thinking" it will act less often. My inspiration for how this should work is Battlecode, which gives units a set amount of bytecode per turn, then just pauses the computation and makes the programmer deal with noticing when things have changed after it's resumed in the next round of computing.

My question is how I can pause and resume an entity which is executing the decision function in a thread. I understand the 'proper' way to do this is to set a flag telling the thread to pause and have it check occasionally, but since I can't force the player to check for a flag within the decide() function, I'm not sure how to pause the thread. The entities are only looking at a fixed representation of the world and just have to return an enum value, so I don't think they should have locks on anything, but I'm hoping there's a better way to do this than using the deprecated thread pausing methods. I'm open to changing how the player has to write code, but I can't think of a way to do it while still hiding the pause flag checks from the user without making writing the decision loop confusing and onerous. There must be some way to do this, since Battlecode does it, but I'm at a loss searching online for details as to how.
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!