[GD-General] Scripting Systems
Brought to you by:
vexxed72
From: Dan T. <da...@ar...> - 2004-01-20 22:50:26
|
I've looked around and implemented a few systems, but I thought I'd get everyone's opinion on how scripting should be incorporated into a game. Note that I'm *not* talking about what language to use, or what the scripting should be used for, nessesarily. Also note that the archives search on sourceforge is the worst search engine ever known to mankind. If this has been covered already, I apologize. The best way I've seen so far is every game object has a script running behind it that is essentially in an infinite loop. It spins on a check for messages call into the engine. Then when it gets a message it does stuff. e.g. Move Forward Was Pressed This Frame message. Then the controlling script does some trig, comes up with an appropriate force, and calls into the physics engine to add the force for the object. Also, these scripts run in a user level thread, where the script manager throttles the script timeslice based on current game performance, and the scripts call a Yeild() function when there are no messages to process. (btw, the scripts are effectively preemtive because we altered the lua execution engine to stop the stack for a given thread when a certain instruction count is hit. That way we get many threads, with throttling , and no synchronization issues to speak of. We also get the ability to limit all scripts to a certain % of frame time.) The primary downside is with a lot of game objects out there, you run into some pretty serious dividing of the time you have. Under release mode, we were getting about 200k lua instructions/second executed in the time given to the script manager. You get 100 objects in the game, and you are down to 1k instructions, with isn't a whole lot. This is mediated by the fact that scripts call a Yeild when they aren't doing anything (so you get 2 instructions, though both are C calls). This method is vs. just running a script and creating the stack when the message comes in. This seemed far too expensive, as you could be creating script stacks all over the place, and it also runs into the problem where the game locks because the scripts are being run in the same thread. These are just the ways I've come up with, and I'd really appreciate some ideas shot at me on how people think it should be done. Thanks! Dan |