The great Interval revamp.

There is no more SafeInterval, instead Intervals can be constructed with a RunQueue to use for expiring.
PresentsDObjectMgr implements RunQueue.
Client has a getRunQueue() method to get the client side RunQueue.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3283 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2004-12-22 19:23:00 +00:00
parent 8ee6cb6fae
commit bd80c348eb
22 changed files with 199 additions and 391 deletions
@@ -1,5 +1,5 @@
//
// $Id: AIGameTicker.java,v 1.6 2004/08/27 02:20:14 mdb Exp $
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
@@ -24,15 +24,14 @@ package com.threerings.parlor.game;
import java.util.Iterator;
import java.util.HashSet;
import com.samskivert.util.IntervalManager;
import com.samskivert.util.Interval;
import com.threerings.presents.server.util.SafeInterval;
import com.threerings.crowd.server.CrowdServer;
/**
* Handles ticking all the GameManagers that are hosting games with AIs.
*/
public class AIGameTicker extends SafeInterval
public class AIGameTicker extends Interval
{
/** The frequency with which we dispatch AI game ticks. */
public static final long TICK_FREQUENCY = 3333L; // every 3 1/3 seconds
@@ -66,7 +65,7 @@ public class AIGameTicker extends SafeInterval
super(CrowdServer.omgr);
_games = new HashSet();
_id = IntervalManager.register(this, TICK_FREQUENCY, null, true);
schedule(TICK_FREQUENCY, true);
}
/**
@@ -88,15 +87,15 @@ public class AIGameTicker extends SafeInterval
// if there aren't any AIs, let's stop running
if (_games.isEmpty()) {
cancel();
_ticker = null;
IntervalManager.remove(_id);
}
}
/**
* Tick all the game AIs while on the dobj thread.
*/
public void run ()
public void expired ()
{
Iterator iter = _games.iterator();
while (iter.hasNext()) {
@@ -107,9 +106,6 @@ public class AIGameTicker extends SafeInterval
/** Our set of ai games. */
protected HashSet _games;
/** Our interval id. */
protected int _id;
/** Our single ticker for all AI games. */
protected static AIGameTicker _ticker;
}
@@ -99,7 +99,7 @@ public abstract class GameController extends PlaceController
Name username =
((BodyObject)_ctx.getClient().getClientObject()).username;
if (_gobj.getPlayerIndex(username) != -1) {
_ctx.getClient().getInvoker().invokeLater(new Runnable() {
_ctx.getClient().getRunQueue().postRunnable(new Runnable() {
public void run () {
// finally let the game manager know that we're ready
// to roll
@@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import com.samskivert.util.IntervalManager;
import com.samskivert.util.Interval;
import com.samskivert.util.RepeatCallTracker;
import com.samskivert.util.StringUtil;
import com.threerings.util.Name;
@@ -35,7 +35,6 @@ import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.presents.dobj.DObject;
import com.threerings.presents.dobj.OidList;
import com.threerings.presents.server.util.SafeInterval;
import com.threerings.crowd.chat.server.SpeakProvider;
@@ -72,13 +71,13 @@ public class GameManager extends PlaceManager
_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);
if (_tickInterval == null) {
_tickInterval = new Interval(CrowdServer.omgr) {
public void expired () {
tickAllGames();
}
};
_tickInterval.schedule(TICK_DELAY, true);
}
}
@@ -443,11 +442,11 @@ public class GameManager extends PlaceManager
// start up a no-show timer if needed
if (needsNoShowTimer()) {
IntervalManager.register(new SafeInterval(CrowdServer.omgr) {
public void run () {
new Interval(CrowdServer.omgr) {
public void expired () {
checkForNoShows();
}
}, NOSHOW_DELAY, null, false);
}.schedule(NOSHOW_DELAY);
}
}
@@ -471,8 +470,8 @@ public class GameManager extends PlaceManager
// remove the tick interval if there are no remaining managers
if (_managers.size() == 0) {
IntervalManager.remove(_tiid);
_tiid = -1;
_tickInterval.cancel();
_tickInterval = null;
}
// clear out our service registration
@@ -610,7 +609,7 @@ public class GameManager extends PlaceManager
if (_committedState == GameObject.IN_PLAY) {
Log.info("Postponing start of still-ending game " +
"[which=" + _gameobj.which() + "].");
CrowdServer.omgr.postUnit(new Runnable() {
CrowdServer.omgr.postRunnable(new Runnable() {
public void run () {
startGame();
}
@@ -1087,8 +1086,8 @@ public class GameManager extends PlaceManager
/** 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;
/** The interval for the game manager tick. */
protected static Interval _tickInterval;
/** We give players 30 seconds to turn up in a puzzle and after that,
* they're considered a no show. */