[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: One or many instances?
- From: Christopher Eykamp <chris@...>
- Date: Fri, 08 Jan 2010 12:25:22 -0800
Hello,
I'm the lead developer for Bitfighter (http://bitfighter.org), written
in C++ and Lunar, and have been working on creating Lua scripted robot
players for a while. There is one script per robot, and several robots
could be running the same script, or each could be running a different
one. Typically, I would expect no more than 10 robots would exist at
any time.
Currently, management is quite easy: we create a single Lua instance for
each robot, each with a function that gets called one per game-cycle.
Because they are running in their own instance, there is no possibility
of one robot mucking up the environment of another, and it seems a very
clean solution. When a robot is removed from the game, we simply delete
the instance, and everything associated with that robot is gone.
Lately, however, I've been thinking about adding event listeners to the
robots, in the form of a series of functions with a name like
"onPlayerAdded(player)", "onShipKilled(ship, killer)", etc. that would
be called from C++ as needed. This complicates things a bit because
instead of calling each script once per game cycle, we might be calling
different functions within the same script a dozen times each cycle.
Multiplied over the number of robots, this becomes a lot of calls, and
I'm afraid of the increasing overhead this might incur.
So I've been rethinking my original design, and am wondering if it might
make sense to have the robots all running in a single process, which
would get called once per event, with some sort of Lua management script
calling the event handlers in each robot. Furthermore, management of
timers and keeping track of which robots implement which listeners might
be easier, as there could be one timer management script for all robots,
rather than the current practice of one-per-robot. And it seems that
keeping track of which robots implement which listener would be easier
in Lua than in C++, which would also argue against the
one-instance-per-bot design.
So the question is what is the best architecture for this sort of
problem? My two key goals are maintaining adequate performance, and
making the bot scripting as simple as possible, which would seem to
imply that each robot should feel like it has it's own global namespace.
How have others addressed this issue?
Thanks,
Chris