Behold Vilya, Ring of Air and repository for our game and virtual worldly

extensions to the distributed environment provided by Narya.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@1 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2006-06-23 17:58:11 +00:00
commit a4df87e52f
317 changed files with 45818 additions and 0 deletions
@@ -0,0 +1,109 @@
//
// $Id: AIGameTicker.java 3381 2005-03-03 19:36:34Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.game.server;
import java.util.Iterator;
import java.util.HashSet;
import com.samskivert.util.Interval;
import com.threerings.crowd.server.CrowdServer;
/**
* Handles ticking all the GameManagers that are hosting games with AIs.
*/
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
/**
* Register the specified GameManager to receive AI ticks.
*/
public static synchronized void registerAIGame (GameManager mgr)
{
if (_ticker == null) {
_ticker = new AIGameTicker();
}
_ticker.addAIGame(mgr);
}
/**
* Take the specified GameManager off the AI tick list.
*/
public static synchronized void unregisterAIGame (GameManager mgr)
{
if (_ticker != null) {
_ticker.removeAIGame(mgr);
}
}
/**
* Construct an AIGameTicker and start it ticking.
*/
private AIGameTicker ()
{
super(CrowdServer.omgr);
_games = new HashSet();
schedule(TICK_FREQUENCY, true);
}
/**
* Add the specified manager to the list of those receiving AI ticks.
*/
protected void addAIGame (GameManager mgr)
{
_games.add(mgr);
}
/**
* Remove the specified manager from receiving AI ticks.
*/
protected void removeAIGame (GameManager mgr)
{
_games.remove(mgr);
// if there aren't any AIs, let's stop running
if (_games.isEmpty()) {
cancel();
_ticker = null;
}
}
/**
* Tick all the game AIs while on the dobj thread.
*/
public void expired ()
{
Iterator iter = _games.iterator();
while (iter.hasNext()) {
((GameManager) iter.next()).tickAIs();
}
}
/** Our set of ai games. */
protected HashSet _games;
/** Our single ticker for all AI games. */
protected static AIGameTicker _ticker;
}
@@ -0,0 +1,69 @@
//
// $Id: GameDispatcher.java 4145 2006-05-24 01:24:24Z ray $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.game.server;
import com.threerings.parlor.game.client.GameService;
import com.threerings.parlor.game.data.GameMarshaller;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.presents.server.InvocationDispatcher;
import com.threerings.presents.server.InvocationException;
/**
* Dispatches requests to the {@link GameProvider}.
*/
public class GameDispatcher extends InvocationDispatcher
{
/**
* Creates a dispatcher that may be registered to dispatch invocation
* service requests for the specified provider.
*/
public GameDispatcher (GameProvider provider)
{
this.provider = provider;
}
// documentation inherited
public InvocationMarshaller createMarshaller ()
{
return new GameMarshaller();
}
// documentation inherited
public void dispatchRequest (
ClientObject source, int methodId, Object[] args)
throws InvocationException
{
switch (methodId) {
case GameMarshaller.PLAYER_READY:
((GameProvider)provider).playerReady(
source
);
return;
default:
super.dispatchRequest(source, methodId, args);
return;
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,108 @@
//
// $Id: GameManagerDelegate.java 3667 2005-08-03 07:46:54Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.game.server;
import com.threerings.util.Name;
import com.threerings.crowd.server.PlaceManagerDelegate;
import com.threerings.parlor.game.data.GameAI;
/**
* Extends the {@link PlaceManagerDelegate} mechanism with game manager
* specific methods.
*/
public class GameManagerDelegate extends PlaceManagerDelegate
{
/**
* Provides the delegate with a reference to the game manager for
* which it is delegating.
*/
public GameManagerDelegate (GameManager gmgr)
{
super(gmgr);
}
/**
* Called by the game manager when the game is about to start.
*/
public void gameWillStart ()
{
}
/**
* Called by the game manager after the game was started.
*/
public void gameDidStart ()
{
}
/**
* Called when a player in the game has been replaced by a call to
* {@link GameManager#replacePlayer}.
*/
public void playerWasReplaced (int pidx, Name oldPlayer, Name newPlayer)
{
}
/**
* Called by the manager when we should do some AI. Only called while
* the game is IN_PLAY.
*
* @param pidx the player index to fake some gameplay for.
* @param ai a record indicating the AI's configuration.
*/
public void tickAI (int pidx, GameAI ai)
{
}
/**
* Called by the game manager when the game is about to end.
*/
public void gameWillEnd ()
{
}
/**
* Called by the game manager after the game ended.
*/
public void gameDidEnd ()
{
}
/**
* Called when the game is about to reset, but before any other
* clearing out of game data has taken place. Derived classes should
* override this if they need to perform some pre-reset activities.
*/
public void gameWillReset ()
{
}
/**
* Called when the specified player has been set as an AI with the
* supplied AI configuration.
*/
public void setAI (int pidx, GameAI ai)
{
}
}
@@ -0,0 +1,39 @@
//
// $Id: GameProvider.java 4145 2006-05-24 01:24:24Z ray $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2006 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.game.server;
import com.threerings.parlor.game.client.GameService;
import com.threerings.presents.client.Client;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationProvider;
/**
* Defines the server-side of the {@link GameService}.
*/
public interface GameProvider extends InvocationProvider
{
/**
* Handles a {@link GameService#playerReady} request.
*/
public void playerReady (ClientObject caller);
}
@@ -0,0 +1,76 @@
//
// $Id: GameWatcher.java 3381 2005-03-03 19:36:34Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.game.server;
import com.threerings.presents.dobj.AttributeChangeListener;
import com.threerings.presents.dobj.AttributeChangedEvent;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.server.PlaceManager;
import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.parlor.game.data.GameObject;
/**
* An abstract convenience class used server-side to keep an eye on a game
* and perform a one-time game-over activity when the game ends. Classes
* that care to make use of the game watcher should create an instance,
* implement {@link #gameDidEnd}, and pass the instance to the place
* registry in the call to {@link PlaceRegistry#createPlace} when the
* puzzle is created.
*/
public abstract class GameWatcher
implements PlaceRegistry.CreationObserver, AttributeChangeListener
{
// documentation inherited
public void placeCreated (PlaceObject place, PlaceManager pmgr)
{
_gameobj = (GameObject)place;
_gameobj.addListener(this);
}
// documentation inherited
public void attributeChanged (AttributeChangedEvent event)
{
if (event.getName().equals(GameObject.STATE)) {
// if we transitioned to a non-in-play state, the game has
// completed
if (!_gameobj.isInPlay()) {
try {
gameDidEnd(_gameobj);
} finally {
_gameobj.removeListener(this);
_gameobj = null;
}
}
}
}
/**
* Called when the game ends to give derived classes a chance to
* engage in their game-over antics.
*/
protected abstract void gameDidEnd (GameObject gameobj);
/** The game object we're observing. */
protected GameObject _gameobj;
}
@@ -0,0 +1,36 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2005 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.parlor.game.server;
/**
* An interface to be implemented by a game if it wants to hear about
* the team indices that were configured during matchmaking.
*/
public interface TeamGameManager
{
/**
* Set the team member indices. For example, a game with
* three players in two teams- players 0 and 2 versus player 1- would
* have { {0, 2}, {1} } set.
*/
public void setTeamMemberIndices (int[][] teams);
}