Updates to reflect new BodyObject.location change. We now have a ScenePlace and

ScenedBodyObject goes away.


git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@372 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Michael Bayne
2007-07-21 00:47:00 +00:00
parent c8b2f7212b
commit e03ddd71e8
20 changed files with 174 additions and 156 deletions
@@ -73,9 +73,8 @@ public /*abstract*/ class GameController extends PlaceController
}
/**
* Adds this controller as a listener to the game object (thus derived
* classes need not do so) and lets the game manager know that we are
* now ready to go.
* Adds this controller as a listener to the game object (thus derived classes need not do so)
* and lets the game manager know that we are now ready to go.
*/
override public function willEnterPlace (plobj :PlaceObject) :void
{
@@ -84,26 +83,22 @@ public /*abstract*/ class GameController extends PlaceController
// obtain a casted reference
_gobj = (plobj as GameObject);
// if this place object is not our current location we'll need to
// add it as an auxiliary chat source
var bobj :BodyObject =
(_ctx.getClient().getClientObject() as BodyObject);
if (bobj.location != plobj.getOid()) {
_ctx.getChatDirector().addAuxiliarySource(
_gobj, GameCodes.GAME_CHAT_TYPE);
// if this place object is not our current location we'll need to add it as an auxiliary
// chat source
var bobj :BodyObject = (_ctx.getClient().getClientObject() as BodyObject);
if (bobj.getPlaceOid() != plobj.getOid()) {
_ctx.getChatDirector().addAuxiliarySource(_gobj, GameCodes.GAME_CHAT_TYPE);
}
// and add ourselves as a listener
_gobj.addListener(this);
// we don't want to claim to be finished until any derived classes
// that overrode this method have executed, so we'll queue up a
// runnable here that will let the game manager know that we're
// ready on the next pass through the distributed event loop
// we don't want to claim to be finished until any derived classes that overrode this
// method have executed, so we'll queue up a runnable here that will let the game manager
// know that we're ready on the next pass through the distributed event loop
log.info("Entering game " + _gobj.which() + ".");
if (_gobj.getPlayerIndex(bobj.getVisibleName()) != -1) {
// finally let the game manager know that we're ready
// to roll
// finally let the game manager know that we're ready to roll
_ctx.getClient().callLater(playerReady);
}
}
@@ -0,0 +1,69 @@
//
// $Id$
//
// Vilya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/vilya/
//
// 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.whirled.data {
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.Place;
/**
* Extends {@link Place} with scene information.
*/
public class ScenePlace extends Place
{
/** The id of the scene occupied by the body. */
public var sceneId :int;
/**
* Returns the scene id occupied by the supplied body or -1 if the body is not in a scene.
*/
public static function getSceneId (bobj :BodyObject) :int
{
return (bobj.location is ScenePlace) ? (bobj.location as ScenePlace).sceneId : -1;
}
/**
* Creates a scene place with the supplied {@link SceneObject} oid and scene id.
*/
public function ScenePlace (sceneOid :int = 0, sceneID :int = 0)
{
super(sceneOid);
this.sceneId = sceneId;
}
// from interface Streamable
override public function readObject (ins :ObjectInputStream) :void
{
super.readObject(ins);
sceneId = ins.readInt();
}
// from interface Streamable
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
out.writeInt(sceneId);
}
}
}
@@ -1,40 +0,0 @@
//
// $Id$
//
// Vilya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/vilya/
//
// 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.whirled.data {
/**
* A system that uses the whirled services must provide a body object
* extension that implements this interface.
*/
public interface ScenedBodyObject
{
/**
* Returns the scene id currently occupied by this body.
*/
function getSceneId () :int;
// /**
// * Sets the scene id currently occupied by this body.
// */
// function setSceneId (sceneId :int) :void;
}
}
@@ -44,6 +44,7 @@ import com.threerings.crowd.data.PlaceObject;
import com.threerings.whirled.client.SceneDirector;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.ScenePlace;
import com.threerings.whirled.util.WhirledContext;
import com.threerings.whirled.spot.data.ClusteredBodyObject;
@@ -121,9 +122,10 @@ public class SpotSceneDirector extends BasicDirector
// sanity check the server's notion of what scene we're in with our notion of it
var sceneId :int = _scdir.getScene().getId();
if (sceneId != _self.getSceneId()) {
var clSceneId :int = ScenePlace.getSceneId(_self as BodyObject);
if (sceneId != clSceneId) {
log.warning("Client and server differ in opinion of what scene we're in " +
"[sSceneId=" + _self.getSceneId() + ", cSceneId=" + sceneId + "].");
"[sSceneId=" + clSceneId + ", cSceneId=" + sceneId + "].");
return false;
}
@@ -21,13 +21,13 @@
package com.threerings.whirled.spot.data {
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.crowd.data.BodyObject;
/**
* Defines some required methods for a {@link ScenedBodyObject} that is to
* participate in the Whirled Spot system.
* Defines some required methods for a {@link BodyObject} that is to participate in the Whirled
* Spot system.
*/
public interface ClusteredBodyObject extends ScenedBodyObject
public interface ClusteredBodyObject
{
/**
* Returns the field name of the cluster oid distributed object field.
@@ -105,9 +105,9 @@ public class ClientController extends Controller
", err=" + nfe + "].");
}
} else if (_body.location != -1) {
} else if (_body.location != null) {
// if we were already in a location, go there
moveOid = _body.location;
moveOid = _body.location.placeOid;
} else {
// otherwise head to the default lobby to start things off
@@ -84,7 +84,7 @@ public abstract class GameController extends PlaceController
// if this place object is not our current location we'll need to add it as an auxiliary
// chat source
BodyObject bobj = (BodyObject)_ctx.getClient().getClientObject();
if (bobj.location != plobj.getOid()) {
if (bobj.location == null || bobj.location.placeOid != plobj.getOid()) {
_ctx.getChatDirector().addAuxiliarySource(_gobj, GameCodes.GAME_CHAT_TYPE);
}
@@ -708,7 +708,7 @@ public class GameManager extends PlaceManager
return; // body object can be null for ai players
}
DObject place = CrowdServer.omgr.getObject(user.location);
DObject place = CrowdServer.omgr.getObject(user.getPlaceOid());
if (place != null) {
place.postMessage(PLAYER_KNOCKED_OUT, new Object[] { new int[] { user.getOid() } });
}
@@ -1180,7 +1180,7 @@ public class GameManager extends PlaceManager
for (int ii=0; ii < numPlayers; ii++) {
BodyObject user = getPlayer(ii);
if (user != null) {
places.add(user.location);
places.add(user.getPlaceOid());
(_gameobj.isWinner(ii) ? winners : losers).add(user.getOid());
}
}
@@ -21,19 +21,36 @@
package com.threerings.whirled.data;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.Place;
/**
* A system that uses the whirled services must provide a body object
* extension that implements this interface.
* Extends {@link Place} with scene information.
*/
public interface ScenedBodyObject
public class ScenePlace extends Place
{
/**
* Returns the scene id currently occupied by this body.
*/
public int getSceneId ();
/** The id of the scene occupied by the body. */
public int sceneId;
/**
* Sets the scene id currently occupied by this body.
* Returns the scene id occupied by the supplied body or -1 if the body is not in a scene.
*/
public void setSceneId (int sceneId);
public static int getSceneId (BodyObject bobj)
{
return (bobj.location instanceof ScenePlace) ? ((ScenePlace)bobj.location).sceneId : -1;
}
/** Used when unserializing. */
public ScenePlace ()
{
}
/**
* Creates a scene place with the supplied {@link SceneObject} oid and scene id.
*/
public ScenePlace (int sceneOid, int sceneId)
{
super(sceneOid);
this.sceneId = sceneId;
}
}
@@ -24,12 +24,14 @@ package com.threerings.whirled.server;
import com.samskivert.io.PersistenceException;
import com.samskivert.util.Invoker;
import com.threerings.crowd.data.Place;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.crowd.server.PlaceManager;
import com.threerings.presents.server.PresentsServer;
import com.threerings.whirled.Log;
import com.threerings.whirled.data.Scene;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.whirled.data.ScenePlace;
import com.threerings.whirled.data.SceneUpdate;
import com.threerings.whirled.server.WhirledServer;
import com.threerings.whirled.util.UpdateList;
@@ -58,6 +60,12 @@ public class SceneManager extends PlaceManager
return _updates.getUpdates(fromVersion);
}
@Override // from PlaceManager
public Place getLocation ()
{
return new ScenePlace(_plobj.getOid(), _scene.getId());
}
/**
* Called by the scene registry once the scene manager has been created (and initialized), but
* before it is started up.
@@ -100,7 +108,7 @@ public class SceneManager extends PlaceManager
// Wait until us and all of our subclasses have completely finished running didStartup
// prior to registering the scene as being ready.
PresentsServer.omgr.postRunnable(new Runnable() {
CrowdServer.omgr.postRunnable(new Runnable() {
public void run () {
_screg.sceneManagerDidStart(SceneManager.this);
}
@@ -32,7 +32,6 @@ import com.threerings.whirled.client.SceneService;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
import com.threerings.whirled.data.ScenedBodyObject;
/**
* Handles a simple scene to scene move.
@@ -49,13 +48,10 @@ public class SceneMoveHandler extends AbstractSceneMoveHandler
protected void effectSceneMove (SceneManager scmgr)
throws InvocationException
{
// move to the place object associated with this scene
// move to location associated with this scene
int ploid = scmgr.getPlaceObject().getOid();
PlaceConfig config = CrowdServer.plreg.locprov.moveTo(_body, ploid);
// now that we've finally moved, we can update the user object with the new scene id
((ScenedBodyObject)_body).setSceneId(scmgr.getScene().getId());
// check to see if they need a newer version of the scene data
SceneService.SceneMoveListener listener = (SceneService.SceneMoveListener)_listener;
SceneModel model = scmgr.getScene().getSceneModel();
@@ -43,7 +43,6 @@ import com.threerings.whirled.data.Scene;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.whirled.server.persist.SceneRepository;
import com.threerings.whirled.util.SceneFactory;
import com.threerings.whirled.util.UpdateList;
@@ -245,13 +244,10 @@ public class SceneRegistry
* Ejects the specified body from their current scene and zone. This is the zone equivalent to
* {@link LocationProvider#leaveOccupiedPlace}.
*/
public void leaveOccupiedScene (ScenedBodyObject source)
public void leaveOccupiedScene (BodyObject source)
{
// remove them from their occupied place
CrowdServer.plreg.locprov.leaveOccupiedPlace((BodyObject)source);
// and clear out their scene information
source.setSceneId(0);
// remove them from their occupied place (clears out scene info as well)
CrowdServer.plreg.locprov.leaveOccupiedPlace(source);
}
/**
@@ -21,19 +21,12 @@
package com.threerings.whirled.server;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.CrowdClient;
import com.threerings.whirled.data.ScenedBodyObject;
/**
* The client object used by client management on the Whirled server.
*/
public class WhirledClient extends CrowdClient
{
// documentation inherited from interface
protected void clearLocation (BodyObject bobj)
{
WhirledServer.screg.leaveOccupiedScene((ScenedBodyObject)bobj);
}
// nothing needed at the moment
}
@@ -38,11 +38,12 @@ import com.threerings.crowd.chat.client.ChatDirector;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.client.LocationAdapter;
import com.threerings.crowd.client.LocationDirector;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.whirled.client.SceneDirector;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.whirled.data.ScenePlace;
import com.threerings.whirled.util.WhirledContext;
import com.threerings.whirled.spot.Log;
@@ -130,10 +131,10 @@ public class SpotSceneDirector extends BasicDirector
// sanity check the server's notion of what scene we're in with our notion of it
int sceneId = _scdir.getScene().getId();
ScenedBodyObject sbobj = (ScenedBodyObject)_ctx.getClient().getClientObject();
if (sceneId != sbobj.getSceneId()) {
int clSceneId = ScenePlace.getSceneId((BodyObject)_ctx.getClient().getClientObject());
if (sceneId != clSceneId) {
Log.warning("Client and server differ in opinion of what scene we're in " +
"[sSceneId=" + sbobj.getSceneId() + ", cSceneId=" + sceneId + "].");
"[sSceneId=" + clSceneId + ", cSceneId=" + sceneId + "].");
return false;
}
@@ -21,13 +21,13 @@
package com.threerings.whirled.spot.data;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.crowd.data.BodyObject;
/**
* Defines some required methods for a {@link ScenedBodyObject} that is to
* participate in the Whirled Spot system.
* Defines some required methods for a {@link BodyObject} that is to participate in the Whirled
* Spot system.
*/
public interface ClusteredBodyObject extends ScenedBodyObject
public interface ClusteredBodyObject
{
/**
* Returns the field name of the cluster oid distributed object field.
@@ -35,8 +35,7 @@ public interface ClusteredBodyObject extends ScenedBodyObject
public String getClusterField ();
/**
* Returns the oid of the cluster to which this user currently
* belongs.
* Returns the oid of the cluster to which this user currently belongs.
*/
public int getClusterOid ();
@@ -37,7 +37,7 @@ import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.PlaceRegistry;
import com.threerings.whirled.client.SceneService.SceneMoveListener;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.whirled.data.ScenePlace;
import com.threerings.whirled.server.SceneManager;
import com.threerings.whirled.server.SceneRegistry;
@@ -74,7 +74,8 @@ public class SpotProvider
throws InvocationException
{
// le sanity check
int cSceneId = getCallerSceneId(caller);
BodyObject body = (BodyObject)caller;
int cSceneId = ScenePlace.getSceneId(body);
if (cSceneId != sceneId) {
Log.info("Ignoring stale traverse portal request [caller=" + caller.who() +
", oSceneId=" + sceneId + ", portalId=" + portalId +
@@ -84,7 +85,6 @@ public class SpotProvider
}
// obtain the source scene
BodyObject body = (BodyObject)caller;
SpotSceneManager srcmgr = (SpotSceneManager)_screg.getSceneManager(sceneId);
if (srcmgr == null) {
Log.warning("Traverse portal missing source scene " +
@@ -124,7 +124,7 @@ public class SpotProvider
throws InvocationException
{
BodyObject source = (BodyObject)caller;
int cSceneId = getCallerSceneId(caller);
int cSceneId = ScenePlace.getSceneId(source);
if (cSceneId != sceneId) {
Log.info("Rejecting changeLocation for invalid scene [user=" + source.who() +
", insid=" + cSceneId + ", wantsid=" + sceneId + ", loc=" + loc + "].");
@@ -153,8 +153,8 @@ public class SpotProvider
SpotService.ConfirmListener listener)
throws InvocationException
{
int sceneId = getCallerSceneId(caller);
BodyObject source = (BodyObject)caller;
int sceneId = ScenePlace.getSceneId(source);
// look up the scene manager for the specified scene
SpotSceneManager smgr = (SpotSceneManager)_screg.getSceneManager(sceneId);
@@ -184,7 +184,7 @@ public class SpotProvider
if (errmsg != null) {
SpeakProvider.sendFeedback(source, MessageManager.GLOBAL_BUNDLE, errmsg);
} else {
sendClusterChatMessage(getCallerSceneId(caller), source.getOid(),
sendClusterChatMessage(ScenePlace.getSceneId(source), source.getOid(),
source.getVisibleName(), null, message, mode);
}
}
@@ -221,23 +221,6 @@ public class SpotProvider
smgr.handleClusterSpeakRequest(speakerOid, speaker, bundle, message, mode);
}
/**
* Obtains the scene id occupied by the supplied caller.
*
* @exception InvocationException thrown if the caller does not implement {@link
* ScenedBodyObject}.
*/
protected static int getCallerSceneId (ClientObject caller)
throws InvocationException
{
if (caller instanceof ScenedBodyObject) {
return ((ScenedBodyObject)caller).getSceneId();
} else {
Log.warning("Can't get scene from non-scened caller " + caller.who() + ".");
throw new InvocationException(INTERNAL_ERROR);
}
}
/** The place registry with which we interoperate. */
protected PlaceRegistry _plreg;
@@ -61,23 +61,25 @@ public class SpotSceneManager extends SceneManager
*/
public static void moveBodyToDefaultPortal (BodyObject body)
{
SpotSceneManager mgr = (SpotSceneManager)CrowdServer.plreg.getPlaceManager(body.location);
if (mgr != null) {
SpotScene scene = (SpotScene)mgr.getScene();
if (scene == null) {
Log.warning("No scene in moveBodyToDefaultPortal()? " +
"[who=" + body.who() +
", where=" + mgr.where() + "].");
return;
}
try {
Location eloc = scene.getDefaultEntrance().getLocation();
mgr.handleChangeLoc(body, eloc);
} catch (InvocationException ie) {
Log.warning("Could not move user to default portal " +
"[where=" + mgr.where() + ", who=" + body.who() +
", error=" + ie + "].");
}
SpotSceneManager mgr = (SpotSceneManager)
CrowdServer.plreg.getPlaceManager(body.getPlaceOid());
if (mgr == null) {
return;
}
SpotScene scene = (SpotScene)mgr.getScene();
if (scene == null) {
Log.warning("No scene in moveBodyToDefaultPortal()? [who=" + body.who() +
", where=" + mgr.where() + "].");
return;
}
try {
Location eloc = scene.getDefaultEntrance().getLocation();
mgr.handleChangeLoc(body, eloc);
} catch (InvocationException ie) {
Log.warning("Could not move user to default portal [where=" + mgr.where() +
", who=" + body.who() + ", error=" + ie + "].");
}
}
@@ -21,13 +21,13 @@
package com.threerings.whirled.zone.data;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.crowd.data.BodyObject;
/**
* A system that uses the zone services must provide a body object
* extension that implements this interface.
* A system that uses the zone services must extend {@link BodyObject} and implement this
* interface.
*/
public interface ZonedBodyObject extends ScenedBodyObject
public interface ZonedBodyObject
{
/**
* Returns the zone id currently occupied by this body.
@@ -29,7 +29,6 @@ import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.client.SceneService;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.whirled.server.AbstractSceneMoveHandler;
import com.threerings.whirled.server.SceneManager;
import com.threerings.whirled.server.SceneMoveHandler;
@@ -90,7 +89,6 @@ public class ZoneMoveHandler extends AbstractSceneMoveHandler
// now that we've moved, we can update the user object with the new scene and zone ids
_body.startTransaction();
try {
((ScenedBodyObject)_body).setSceneId(scmgr.getScene().getId());
((ZonedBodyObject)_body).setZoneId(_summary.zoneId);
} finally {
_body.commitTransaction();
@@ -33,7 +33,6 @@ import com.threerings.crowd.server.LocationProvider;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
import com.threerings.whirled.data.ScenedBodyObject;
import com.threerings.whirled.server.SceneManager;
import com.threerings.whirled.server.SceneRegistry;
@@ -150,7 +149,7 @@ public class ZoneProvider
}
// remove them from their occupied scene
_screg.leaveOccupiedScene(source);
_screg.leaveOccupiedScene((BodyObject)source);
// and clear out their zone information
source.setZoneId(-1);