Tick all game managers every five seconds to allow them to engage in any

activity that isn't driven by player actions.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2093 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2003-01-03 02:35:41 +00:00
parent de0ea7b464
commit ebd50b80f5
@@ -1,5 +1,5 @@
//
// $Id: GameManager.java,v 1.57 2002/11/29 21:25:37 mdb Exp $
// $Id: GameManager.java,v 1.58 2003/01/03 02:35:41 shaper Exp $
package com.threerings.parlor.game;
@@ -48,6 +48,19 @@ public class GameManager extends PlaceManager
// save off a casted reference to our config
_gameconfig = (GameConfig)_config;
// register this game manager
_managers.add(this);
// and start up a tick interval if we've not already got one
if (_tiid == -1) {
_tiid = IntervalManager.register(
new SafeInterval(CrowdServer.omgr) {
public void run () {
tickAllGames();
}
}, TICK_DELAY, null, true);
}
}
/**
@@ -409,6 +422,15 @@ public class GameManager extends PlaceManager
{
super.didShutdown();
// unregister this game manager
_managers.remove(this);
// remove the tick interval if there are no remaining managers
if (_managers.size() == 0) {
IntervalManager.remove(_tiid);
_tiid = -1;
}
// clear out our service registration
_invmgr.clearDispatcher(_gameobj.gameService);
}
@@ -839,6 +861,15 @@ public class GameManager extends PlaceManager
return true;
}
/**
* Gives game managers an opportunity to perform periodic processing
* that is not driven by events generated by the player.
*/
protected void tick (long tickStamp)
{
// nothing for now
}
// documentation inherited
public void attributeChanged (AttributeChangedEvent event)
{
@@ -858,6 +889,20 @@ public class GameManager extends PlaceManager
}
}
/**
* Called periodically to call {@link #tick} on all registered game
* managers.
*/
protected static void tickAllGames ()
{
long now = System.currentTimeMillis();
int size = _managers.size();
for (int ii = 0; ii < size; ii++) {
GameManager gmgr = (GameManager)_managers.get(ii);
gmgr.tick(now);
}
}
/**
* A helper operation to distribute AI ticks to our delegates.
*/
@@ -900,7 +945,16 @@ public class GameManager extends PlaceManager
/** Our delegate operator to tick AIs. */
protected TickAIDelegateOp _tickAIOp;
/** A list of all currently active game managers. */
protected static ArrayList _managers = new ArrayList();
/** The interval id for the game manager tick interval. */
protected static int _tiid = -1;
/** We give players 30 seconds to turn up in a puzzle and after that,
* they're considered a no show. */
protected static final long NOSHOW_DELAY = 30 * 1000L;
/** The delay in milliseconds between ticking of all game managers. */
protected static final long TICK_DELAY = 5L * 1000L;
}