Began porting 'whirled'.

The basic whirled stuff is here; compiling and working.
'Spot' still to come.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4133 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-05-20 02:18:18 +00:00
parent fb10d38232
commit f7eb18460a
26 changed files with 1950 additions and 26 deletions
@@ -494,17 +494,17 @@ public class LocationDirector extends BasicDirector
// does whatever's necessary
// try to return to our previous location
// if (_failureHandler != null) {
// _failureHandler.recoverFailedMove(placeId);
//
// } else {
if (_failureHandler != null) {
_failureHandler.recoverFailedMove(placeId);
} else {
// if we were previously somewhere (and that somewhere isn't
// where we just tried to go), try going back to that happy
// place
if (_previousPlaceId != -1 && _previousPlaceId != placeId) {
moveTo(_previousPlaceId);
}
// }
}
}
/**
@@ -517,19 +517,20 @@ public class LocationDirector extends BasicDirector
* this interface whereby they can interject themseves into the
* failure recovery process and do their own failure recovery.
*/
// public void setFailureHandler (FailureHandler handler)
// {
// if (_failureHandler != null) {
// log.warning("Requested to set failure handler, but we've " +
// "already got one. The conflicting entities will " +
// "likely need to perform more sophisticated " +
// "coordination to deal with failures. " +
// "[old=" + _failureHandler + ", new=" + handler + "].");
//
// } else {
// _failureHandler = handler;
// }
// }
public function setFailureHandler (
handler :LocationDirector_FailureHandler) :void
{
if (_failureHandler != null) {
log.warning("Requested to set failure handler, but we've " +
"already got one. The conflicting entities will " +
"likely need to perform more sophisticated " +
"coordination to deal with failures. " +
"[old=" + _failureHandler + ", new=" + handler + "].");
} else {
_failureHandler = handler;
}
}
protected function notifyFailure (placeId :int, reason :String) :void
{
@@ -572,7 +573,7 @@ public class LocationDirector extends BasicDirector
/** The entity that deals when we fail to subscribe to a place
* object. */
// protected FailureHandler _failureHandler;
protected var _failureHandler :LocationDirector_FailureHandler;
/** A listener that wants to know if we succeeded or
* how we failed to move. */
@@ -81,8 +81,9 @@ public class InvocationDirector
// if we're logged on, clear out any receiver id mapping
if (_clobj != null) {
var rreg :InvocationRegistration =
(_clobj.receivers.get(receiverCode) as InvocationRegistration);
var rreg :InvocationReceiver_Registration =
(_clobj.receivers.get(receiverCode) as
InvocationReceiver_Registration);
if (rreg == null) {
log.warning("Receiver unregistered for which we have no " +
"id to code mapping [code=" + receiverCode + "].");
@@ -102,8 +103,9 @@ public class InvocationDirector
*/
internal function assignReceiverId (decoder :InvocationDecoder) :void
{
var reg :InvocationRegistration = new InvocationRegistration(
decoder.getReceiverCode(), nextReceiverId());
var reg :InvocationReceiver_Registration =
new InvocationReceiver_Registration(decoder.getReceiverCode(),
nextReceiverId());
_clobj.addToReceivers(reg);
_receivers.put(reg.receiverId, decoder);
}
@@ -13,7 +13,7 @@ import com.threerings.presents.dobj.DSet_Entry;
* used to convert (large) hash codes into (small) registration
* numbers.
*/
public class InvocationRegistration
public class InvocationReceiver_Registration
implements DSet_Entry
{
/** The unique hash code associated with this invocation receiver class. */
@@ -24,8 +24,8 @@ public class InvocationRegistration
public var receiverId :int;
/** Creates and initializes a registration instance. */
public function InvocationRegistration (
receiverCode :String, receiverId :int)
public function InvocationReceiver_Registration (
receiverCode :String = null, receiverId :int = 0)
{
this.receiverCode = receiverCode;
this.receiverId = receiverId;
@@ -0,0 +1,92 @@
//
// $Id: SceneController.java 3099 2004-08-27 02:21:06Z 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.whirled.client {
import com.threerings.presents.dobj.MessageEvent;
import com.threerings.presents.dobj.MessageListener;
import com.threerings.crowd.client.PlaceController;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.whirled.data.SceneUpdate;
import com.threerings.whirled.util.WhirledContext;
/**
* The base scene controller class. It is expected that users of the
* Whirled services will extend this controller class when creating
* specialized controllers for their scenes.
*/
public /*abstract*/ class SceneController extends PlaceController
{
// documentation inherited
public override function init (ctx :CrowdContext, config :PlaceConfig) :void
{
super.init(ctx, config);
_wctx = WhirledContext(ctx);
}
// documentation inherited
public override function willEnterPlace (plobj :PlaceObject) :void
{
super.willEnterPlace(plobj);
plobj.addListener(_updateListener);
}
// documentation inherited
public override function didLeavePlace (plobj :PlaceObject) :void
{
super.didLeavePlace(plobj);
plobj.removeListener(_updateListener);
}
/**
* This method is called if a scene update is recorded while we
* currently occupy a scene. The default implementation will update
* our local scene and scene model, but derived classes will likely
* want to ensure that the update is properly displayed.
*/
protected function sceneUpdated (update :SceneUpdate) :void
{
// apply the update to the scene
_wctx.getSceneDirector().getScene().updateReceived(update);
// we don't persistify these updates in this circumstance, but
// next time we come to this scene we'll redownload the update and
// apply it to the repository; as the updates are meant to be very
// small, this shouldn't be horribly less efficient
}
/** Used to listen for scene updates. */
protected var _updateListener :MessageListener = new MessageAdapter(
function (event :MessageEvent) :void {
if (event.getName() == SceneCodes.SCENE_UPDATE) {
sceneUpdated(event.getArgs()[0] as SceneUpdate);
}
}
);
protected var _wctx :WhirledContext;
}
}
@@ -0,0 +1,68 @@
//
// $Id: SceneDecoder.java 3914 2006-03-06 21:51:59Z mdb $
//
// 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.whirled.client {
import com.threerings.presents.client.InvocationDecoder;
import com.threerings.whirled.client.SceneReceiver;
/**
* Dispatches calls to a {@link SceneReceiver} instance.
*/
public class SceneDecoder extends InvocationDecoder
{
/** The generated hash code used to identify this receiver class. */
public static const RECEIVER_CODE :String =
"c4d0cf66b81a6e83d119b2d607725651";
/** The method id used to dispatch {@link SceneReceiver#forcedMove}
* notifications. */
public static const FORCED_MOVE :int = 1;
/**
* Creates a decoder that may be registered to dispatch invocation
* service notifications to the specified receiver.
*/
public function SceneDecoder (receiver :SceneReceiver)
{
this.receiver = receiver;
}
// documentation inherited
public override function getReceiverCode () :String
{
return RECEIVER_CODE;
}
// documentation inherited
public override function dispatchNotification (methodId :int, args :Array) :void
{
switch (methodId) {
case FORCED_MOVE:
(receiver as SceneReceiver).forcedMove(args[0] as int);
return;
default:
super.dispatchNotification(methodId, args);
}
}
}
}
@@ -0,0 +1,527 @@
//
// $Id: SceneDirector.java 4088 2006-05-04 00:39:46Z mjohnson $
//
// 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.whirled.client {
import flash.errors.IOError;
import flash.errors.IllegalOperationError;
import com.threerings.util.HashMap;
import com.threerings.util.ResultListener;
import com.threerings.io.TypedArray;
import com.threerings.presents.client.BasicDirector;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.ClientEvent;
import com.threerings.presents.data.InvocationCodes;
import com.threerings.crowd.client.LocationDirector;
import com.threerings.crowd.client.LocationDirector_FailureHandler;
import com.threerings.crowd.client.LocationObserver;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.client.persist.SceneRepository;
import com.threerings.whirled.data.Scene;
import com.threerings.whirled.data.SceneCodes;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.util.NoSuchSceneError;
import com.threerings.whirled.util.SceneFactory;
import com.threerings.whirled.util.WhirledContext;
import com.threerings.whirled.data.SceneUpdate;
/**
* The scene director is the client's interface to all things scene
* related. It interfaces with the scene repository to ensure that scene
* objects are available when the client enters a particular scene. It
* handles moving from scene to scene (it coordinates with the {@link
* LocationDirector} in order to do this).
*
* <p> Note that when the scene director is in use instead of the location
* director, scene ids instead of place oids will be supplied to {@link
* LocationObserver#locationMayChange} and {@link
* LocationObserver#locationChangeFailed}.
*/
public class SceneDirector extends BasicDirector
implements LocationDirector_FailureHandler,
SceneReceiver, SceneService_SceneMoveListener
{
private static const log :Log = Log.getLog(SceneDirector);
/**
* Creates a new scene director with the specified context.
*
* @param ctx the active client context.
* @param locdir the location director in use on the client, with
* which the scene director will coordinate when changing location.
* @param screp the entity from which the scene director will load
* scene data from the local client scene storage. This may be null
* when the SceneDirector is constructed, but it should be
* supplied via {@link #setSceneRepository} prior to really using
* this director.
* @param fact the factory that knows which derivation of {@link
* Scene} to create for the current system.
*/
public function SceneDirector (
ctx :WhirledContext, locdir :LocationDirector,
screp :SceneRepository, fact :SceneFactory)
{
super(ctx);
// we'll need these for later
_wctx = ctx;
_locdir = locdir;
setSceneRepository(screp);
_fact = fact;
// set ourselves up as a failure handler with the location
// director because we need to do special processing
_locdir.setFailureHandler(this);
// register for scene notifications
_wctx.getClient().getInvocationDirector().registerReceiver(
new SceneDecoder(this));
}
/**
* Set the scene repository.
*/
public function setSceneRepository (screp :SceneRepository) :void
{
_screp = screp;
_scache.clear();
}
/**
* Returns the display scene object associated with the scene we
* currently occupy or null if we currently occupy no scene.
*/
public function getScene () :Scene
{
return _scene;
}
/**
* Requests that this client move the specified scene. A request will
* be made and when the response is received, the location observers
* will be notified of success or failure.
*
* @return true if the move to request was issued, false if it was
* rejected by a location observer or because we have another request
* outstanding.
*/
public function moveTo (sceneId :int) :Boolean
{
// make sure the sceneId is valid
if (sceneId < 0) {
log.warning("Refusing moveTo(): invalid sceneId " + sceneId + ".");
return false;
}
// sanity-check the destination scene id
if (sceneId == _sceneId) {
log.warning("Refusing request to move to the same scene " +
"[sceneId=" + sceneId + "].");
return false;
}
// prepare to move to this scene (sets up pending data)
if (!prepareMoveTo(sceneId, null)) {
return false;
}
// check the version of our cached copy of the scene to which
// we're requesting to move; if we were unable to load it, assume
// a cached version of zero
var sceneVers :int = 0;
if (_pendingModel != null) {
sceneVers = _pendingModel.version;
}
// issue a moveTo request
log.info("Issuing moveTo(" + sceneId + ", " + sceneVers + ").");
_sservice.moveTo(_wctx.getClient(), sceneId, sceneVers, this);
return true;
}
/**
* Prepares to move to the requested scene. The location observers are
* asked to ratify the move and our pending scene mode is loaded from
* the scene repository. This can be called by cooperating directors
* that need to coopt the moveTo process.
*/
public function prepareMoveTo (sceneId :int, rl :ResultListener) :Boolean
{
// first check to see if our observers are happy with this move
// request
if (!_locdir.mayMoveTo(sceneId, rl)) {
return false;
}
// we need to call this both to mark that we're issuing a move
// request and to check to see if the last issued request should
// be considered stale
var refuse :Boolean = _locdir.checkRepeatMove();
// complain if we're over-writing a pending request
if (_pendingSceneId != -1) {
if (refuse) {
log.warning("Refusing moveTo; We have a request outstanding " +
"[psid=" + _pendingSceneId +
", nsid=" + sceneId + "].");
return false;
} else {
log.warning("Overriding stale moveTo request " +
"[psid=" + _pendingSceneId +
", nsid=" + sceneId + "].");
}
}
// load up the pending scene so that we can communicate it's most
// recent version to the server
_pendingModel = loadSceneModel(sceneId);
// make a note of our pending scene id
_pendingSceneId = sceneId;
// all systems go
return true;
}
/**
* Returns the model loaded in preparation for a scene
* transition. This is made available only for cooperating directors
* which may need to coopt the scene transition process. The pending
* model is only valid immediately following a call to {@link
* #prepareMoveTo}.
*/
public function getPendingModel () :SceneModel
{
return _pendingModel;
}
// documentation inherited from interface SceneService_SceneMoveListener
public function moveSucceeded (placeId :int, config :PlaceConfig) :void
{
// our move request was successful, deal with subscribing to our
// new place object
_locdir.didMoveTo(placeId, config);
// since we're committed to moving to the new scene, we'll
// parallelize and go ahead and load up the new scene now rather
// than wait until subscription to our place object succeeds
// keep track of our previous scene info
_previousSceneId = _sceneId;
// clear out the old info
clearScene();
// make the pending scene the active scene
_sceneId = _pendingSceneId;
_pendingSceneId = -1;
// load the new scene model
_model = loadSceneModel(_sceneId);
// complain if we didn't find a scene
if (_model == null) {
log.warning("Aiya! Unable to load scene [sid=" + _sceneId +
", plid=" + placeId + "].");
return;
}
// and finally create a display scene instance with the model and
// the place config
_scene = _fact.createScene(_model, config);
}
// documentation inherited from interface SceneService_SceneMoveListener
public function moveSucceededWithUpdates (
placeId :int, config :PlaceConfig, updates :TypedArray) :void
{
log.info("Got updates [placeId=" + placeId + ", config=" + config +
", updates=" + updates + "].");
// apply the updates to our cached scene
var model :SceneModel = loadSceneModel(_pendingSceneId);
var failure :Boolean = false;
for each (var update :SceneUpdate in updates) {
try {
update.validate(model);
} catch (ise :IllegalOperationError) {
log.warning("Scene update failed validation [model=" + model +
", update=" + update +
", error=" + ise.getMessage() + "].");
failure = true;
break;
}
try {
update.apply(model);
} catch (e :Error) {
log.warning("Failure applying scene update [model=" + model +
", update=" + update + "].");
log.logStackTrace(e);
failure = true;
break;
}
}
if (failure) {
// delete the now half-booched scene model from the repository
try {
_screp.deleteSceneModel(_pendingSceneId);
} catch (ioe :IOError) {
log.warning("Failure removing booched scene model " +
"[sceneId=" + _pendingSceneId + "].");
log.logStackTrace(ioe);
}
// act as if the scene move failed, though we'll be in a funny
// state because the server thinks we've changed scenes, but
// the client can try again without its booched scene model
requestFailed(InvocationCodes.INTERNAL_ERROR);
return;
}
// store the updated scene in the repository
try {
_screp.storeSceneModel(model);
} catch (ioe :IOError) {
log.warning("Failed to update repository with updated scene " +
"[sceneId=" + model.sceneId + "].");
log.logStackTrace(ioe);
}
// finally pass through to the normal success handler
moveSucceeded(placeId, config);
}
// documentation inherited from interface SceneService-SceneMoveListener
public function moveSucceededWithScene (
placeId :int, config :PlaceConfig, model :SceneModel) :void
{
log.info("Got updated scene model [placeId=" + placeId +
", config=" + config + ", scene=" + model.sceneId + "/" +
model.name + "/" + model.version + "].");
// update the model in the repository
try {
_screp.storeSceneModel(model);
} catch (ioe :IOError) {
log.warning("Failed to update repository with new version " +
"[sceneId=" + model.sceneId +
", nvers=" + model.version + "].");
log.logStackTrace(ioe);
}
// update our scene cache
_scache.put(model.sceneId, model);
// and pass through to the normal move succeeded handler
moveSucceeded(placeId, config);
}
// documentation inherited from interface
public function requestFailed (reason :String) :void
{
// clear out our pending request oid
var sceneId :int = _pendingSceneId;
_pendingSceneId = -1;
// let our observers know that something has gone horribly awry
_locdir.failedToMoveTo(sceneId, reason);
}
/**
* Called to clean up our place and scene state information when we
* leave a scene.
*/
public function didLeaveScene () :void
{
// let the location director know what's up
_locdir.didLeavePlace();
// clear out our own scene state
clearScene();
}
// documentation inherited from interface
public function forcedMove (sceneId :int) :void
{
log.info("Moving at request of server [sceneId=" + sceneId + "].");
// clear out our old scene and place data
didLeaveScene();
// move to the new scene
moveTo(sceneId);
}
/**
* Sets the moveHandler for use in recoverFailedMove.
*/
public function setMoveHandler (handler :SceneDirector_MoveHandler) :void
{
if (_moveHandler != null) {
log.warning("Requested to set move handler, but we've " +
"already got one. The conflicting entities will " +
"likely need to perform more sophisticated " +
"coordination to deal with failures. " +
"[old=" + _moveHandler + ", new=" + handler + "].");
} else {
_moveHandler = handler;
}
}
/**
* Called when something breaks down in the process of performing a
* <code>moveTo</code> request.
*/
public function recoverFailedMove (placeId :int) :void
{
// we'll need this momentarily
var sceneId :int = _sceneId;
// clear out our now bogus scene tracking info
clearScene();
// if we were previously somewhere (and that somewhere isn't where
// we just tried to go), try going back to that happy place
if (_previousSceneId != -1 && _previousSceneId != sceneId) {
// if we have a move handler use that
if (_moveHandler != null) {
_moveHandler.recoverMoveTo(_previousSceneId);
} else {
moveTo(_previousSceneId);
}
}
}
/**
* Clears out our current scene information and releases the scene
* model for the loaded scene back to the cache.
*/
protected function clearScene () :void
{
// clear out our scene id info
_sceneId = -1;
// clear out our references
_model = null;
_scene = null;
}
/**
* Loads a scene from the repository. If the scene is cached, it will
* be returned from the cache instead.
*/
protected function loadSceneModel (sceneId :int) :SceneModel
{
// first look in the model cache
var model :SceneModel = (_scache.get(sceneId) as SceneModel);
// load from the repository if it's not cached
if (model == null) {
try {
model = _screp.loadSceneModel(sceneId);
_scache.put(sceneId, model);
} catch (nsse :NoSuchSceneError) {
// nothing special here, just fall through and return null
} catch (ioe :IOError) {
// complain first, then return null
log.warning("Error loading scene [scid=" + sceneId +
", error=" + ioe + "].");
}
}
return model;
}
// documentation inherited
public override function clientDidLogoff (event :ClientEvent) :void
{
super.clientDidLogoff(event);
// clear out our business
clearScene();
_scache.clear();
_pendingSceneId = -1;
_pendingModel = null;
_previousSceneId = -1;
_sservice = null;
}
// documentation inherited
protected override function fetchServices (client :Client) :void
{
// get a handle on our scene service
_sservice = (client.requireService(SceneService) as SceneService);
}
/** Access to general client services. */
protected var _wctx :WhirledContext;
/** Access to our scene services. */
protected var _sservice :SceneService;
/** The client's active location director. */
protected var _locdir :LocationDirector;
/** The entity via which we load scene data. */
protected var _screp :SceneRepository;
/** The entity we use to create scenes from scene models. */
protected var _fact :SceneFactory;
/** A cache of scene model information. */
protected var _scache :HashMap = new HashMap(); // TODO: LRUHashMap(5)
/** The display scene object for the scene we currently occupy. */
protected var _scene :Scene;
/** The scene model for the scene we currently occupy. */
protected var _model :SceneModel;
/** The id of the scene we currently occupy. */
protected var _sceneId :int = -1;
/** Our most recent copy of the scene model for the scene we're about
* to enter. */
protected var _pendingModel :SceneModel;
/** The id of the scene for which we have an outstanding moveTo
* request, or -1 if we have no outstanding request. */
protected var _pendingSceneId :int = -1;
/** The id of the scene we previously occupied. */
protected var _previousSceneId :int = -1;
/** Reference to our move handler. */
protected var _moveHandler :SceneDirector_MoveHandler = null;
}
}
@@ -0,0 +1,14 @@
package com.threerings.whirled.client {
/**
* Used to recover from a problem after a completed moveTo.
*/
public interface SceneDirector_MoveHandler
{
/**
* Should instruct the client to move the last known working
* location (as well as clean up after the failed moveTo request).
*/
function recoverMoveTo (sceneId :int) :void;
}
}
@@ -0,0 +1,40 @@
//
// $Id: SceneReceiver.java 3099 2004-08-27 02:21:06Z 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.whirled.client {
import com.threerings.presents.client.InvocationReceiver;
/**
* Defines, for the scene services, a set of notifications delivered
* asynchronously by the server to the client.
*/
public interface SceneReceiver extends InvocationReceiver
{
/**
* Used to communicate a required move notification to the client. The
* server will have removed the client from their existing scene
* and the client is then responsible for generating a {@link
* SceneService#moveTo} request to move to the new scene.
*/
function forcedMove (sceneId :int) :void
}
}
@@ -0,0 +1,50 @@
//
// $Id: SceneService.java 3099 2004-08-27 02:21:06Z 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.whirled.client {
import com.threerings.presents.client.Client;
import com.threerings.presents.client.InvocationService;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
/**
* The scene service class provides the client interface to the scene
* related invocation services (e.g. moving from scene to scene).
*/
public interface SceneService extends InvocationService
{
/**
* Requests that that this client's body be moved to the specified
* scene.
*
* @param sceneId the scene id to which we want to move.
* @param version the version number of the scene object that we have
* in our local repository.
*/
function moveTo (
client :Client, sceneId :int, version :int,
listener :SceneService_SceneMoveListener) :void;
}
}
@@ -0,0 +1,50 @@
package com.threerings.whirled.client {
import com.threerings.presents.client.InvocationListener;
import com.threerings.io.TypedArray;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
/**
* Used to communicate the response to a {@link #moveTo} request.
*/
public interface SceneService_SceneMoveListener extends InvocationListener
{
/**
* Indicates that a move succeeded.
*
* @param placeId the place object id of the newly occupied scene.
* @param config metadata related to the newly occupied scene.
*/
function moveSucceeded (placeId :int, config :PlaceConfig) :void;
/**
* Indicates that a move succeeded and that the client's cached
* scene information should be updated with the supplied data.
*
* @param placeId the place object id of the newly occupied scene.
* @param config metadata related to the newly occupied scene.
* @param updates updates that must be applied to the client's
* copy of a scene model to bring it up to date.
*/
function moveSucceededWithUpdates (
placeId :int, config :PlaceConfig,
updates :TypedArray /*of SceneUpdate*/) :void;
/**
* Indicates that a move succeeded and that the client's cached
* scene information should be updated with the supplied data.
*
* @param placeId the place object id of the newly occupied scene.
* @param config metadata related to the newly occupied scene.
* @param model a fresh copy of the most recent scene data for the
* newly occupied scene.
*/
function moveSucceededWithScene (
placeId :int, config :PlaceConfig, model :SceneModel) :void;
}
}
@@ -0,0 +1,66 @@
//
// $Id: SceneRepository.java 3099 2004-08-27 02:21:06Z 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.whirled.client.persist {
import flash.errors.IOError;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.util.NoSuchSceneError;
/**
* The scene repository provides access to a persistent repository of
* scene information.
*
* @see SceneModel
*/
public interface SceneRepository
{
/**
* Fetches the model for the scene with the specified id.
*
* @exception IOException thrown if an error occurs attempting to load
* the scene data.
* @exception NoSuchSceneException thrown if no scene exists with the
* specified scene id.
*/
function loadSceneModel (sceneId :int) :SceneModel;
//throws IOException, NoSuchSceneException;
/**
* Updates or inserts this scene model as appropriate.
*
* @exception IOException thrown if an error occurs attempting to
* access the repository.
*/
function storeSceneModel (model :SceneModel) :void;
//throws IOException;
/**
* Deletes the specified scene model from the repository.
*
* @exception IOException thrown if an error occurs attempting to
* access the repository.
*/
function deleteSceneModel (sceneId :int) :void;
//throws IOException;
}
}
@@ -0,0 +1,37 @@
//
// $Id: AuxModel.java 3099 2004-08-27 02:21:06Z 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.whirled.data {
import com.threerings.io.Streamable;
/**
* An interface that must be implemented by auxiliary scene models.
*/
public interface AuxModel extends Streamable /*, Cloneable*/
{
/**
* Creates a clone of this auxiliary model.
*/
function clone () :Object;
//throws CloneNotSupportedException;
}
}
@@ -0,0 +1,45 @@
//
// $Id: DefaultSceneConfig.java 4026 2006-04-18 01:32:41Z 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.whirled.data {
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.client.SceneController;
/**
* The default scene config simply causes the default scene manager and
* controller to be created. A user of the Whirled services would most
* likely extend the default scene config.
*
* <p> Note that this place config won't even work on the client side
* because it instantiates a {@link SceneController} which is an abstract
* class. It is used only for testing the server side and as a placeholder
* in case standard scene configuration information is one day needed.
*/
public class DefaultSceneConfig extends PlaceConfig
{
// documentation inherited
public function getManagerClassName () :String
{
return "com.threerings.whirled.server.SceneManager";
}
}
}
@@ -0,0 +1,84 @@
//
// $Id: Scene.java 3099 2004-08-27 02:21:06Z 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.whirled.data {
import com.threerings.crowd.data.PlaceConfig;
/**
* This interface makes available basic scene information. At this basic
* level, not much information is available, but extensions to this
* interface begin to create a more comprehensive picture of a scene in a
* system built from the Whirled services.
*/
public interface Scene
{
/**
* Returns the unique identifier for this scene.
*/
function getId () :int;
/**
* Returns the human readable name of this scene.
*/
function getName () :String;
/**
* Returns the version number of this scene.
*/
function getVersion () :int;
/**
* Returns the place config that can be used to determine which place
* controller instance should be used to display this scene as well as
* to obtain runtime configuration information.
*/
function getPlaceConfig () :PlaceConfig;
/**
* Sets this scene's unique identifier.
*/
function setId (sceneId :int) :void;
/**
* Sets the human readable name of this scene.
*/
function setName (name :String) :void;
/**
* Sets this scene's version number.
*/
function setVersion (version :int) :void;
/**
* Called to inform the scene that an update has been received while
* the scene was resolved and active. The update should be applied to
* the underlying scene model and any derivative data should be
* appropriately updated.
*/
function updateReceived (update :SceneUpdate) :void;
/**
* Returns the scene model from which this scene was created.
*/
function getSceneModel () :SceneModel;
}
}
@@ -0,0 +1,34 @@
//
// $Id: SceneCodes.java 3099 2004-08-27 02:21:06Z 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.whirled.data {
import com.threerings.crowd.data.LocationCodes;
/**
* Contains codes used by the scene invocation services.
*/
public class SceneCodes extends LocationCodes
{
/** The message identifier for scene update messages. */
public static const SCENE_UPDATE :String = "scene_update";
}
}
@@ -0,0 +1,124 @@
//
// $Id: SceneImpl.java 3099 2004-08-27 02:21:06Z 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.whirled.data {
import com.threerings.crowd.data.PlaceConfig;
/**
* An implementation of the {@link Scene} interface.
*/
public class SceneImpl implements Scene
{
/**
* Creates an instance that will obtain data from the supplied scene
* model and place config.
*/
public function SceneImpl (
model :SceneModel = null, config :PlaceConfig = null)
{
if (model != null) {
_model = model;
_config = config;
} else {
_model = SceneModel.blankSceneModel();
}
}
// documentation inherited
public function getId () :int
{
return _model.sceneId;
}
// documentation inherited
public function getName () :String
{
return _model.name;
}
// documentation inherited
public function getVersion () :int
{
return _model.version;
}
// documentation inherited
public function getPlaceConfig () :PlaceConfig
{
return _config;
}
// documentation inherited from interface
public function setId (sceneId :int) :void
{
_model.sceneId = sceneId;
}
// documentation inherited from interface
public function setName (name :String) :void
{
_model.name = name;
}
// documentation inherited from interface
public function setVersion (version :int) :void
{
_model.version = version;
}
// documentation inherited from interface
public function updateReceived (update :SceneUpdate) :void
{
try {
// validate and apply the update
update.validate(_model);
update.apply(_model);
} catch (e :Error) {
var log :Log = Log.getLog(this);
log.warning("Error applying update [scene=" + this +
", update=" + update + "].");
log.logStackTrace(e);
}
}
// documentation inherited from interface
public function getSceneModel () :SceneModel
{
return _model;
}
/**
* Generates a string representation of this instance.
*/
public function toString () :String
{
return "[model=" + _model + ", config=" + _config + "]";
}
/** A reference to our scene model. */
protected var _model :SceneModel;
/** A reference to our place configuration. */
protected var _config :PlaceConfig;
}
}
@@ -0,0 +1,51 @@
//
// $Id: SceneMarshaller.java 3793 2005-12-21 02:12:57Z ray $
//
// 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.whirled.data {
import com.threerings.presents.client.Client;
import com.threerings.presents.data.InvocationMarshaller;
import com.threerings.whirled.client.SceneService;
import com.threerings.whirled.client.SceneService_SceneMoveListener;
/**
* Provides the implementation of the {@link SceneService} interface
* that marshalls the arguments and delivers the request to the provider
* on the server. Also provides an implementation of the response listener
* interfaces that marshall the response arguments and deliver them back
* to the requesting client.
*/
public class SceneMarshaller extends InvocationMarshaller
implements SceneService
{
/** The method id used to dispatch {@link #moveTo} requests. */
public static const MOVE_TO :int = 1;
// documentation inherited from interface
public function moveTo (arg1 :Client, arg2 :int, arg3 :int, arg4 :SceneService_SceneMoveListener) :void
{
var listener4 :SceneMarshaller_SceneMoveMarshaller = new SceneMarshaller_SceneMoveMarshaller();
listener4.listener = arg4;
sendRequest(arg1, MOVE_TO, [ arg2, arg3, listener4 ]);
}
}
}
@@ -0,0 +1,79 @@
package com.threerings.whirled.data {
import com.threerings.io.TypedArray;
import com.threerings.presents.data.ListenerMarshaller;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.presents.dobj.InvocationResponseEvent;
import com.threerings.whirled.client.SceneService_SceneMoveListener;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.data.SceneUpdate;
public class SceneMarshaller_SceneMoveMarshaller extends ListenerMarshaller
implements SceneService_SceneMoveListener
{
/** The method id used to dispatch {@link #moveSucceeded}
* responses. */
public static const MOVE_SUCCEEDED :int = 1;
// documentation inherited from interface SceneService_SceneMoveListener
public function moveSucceeded (arg1 :int, arg2 :PlaceConfig) :void
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, MOVE_SUCCEEDED,
[ arg1, arg2 ]));
}
/** The method id used to dispatch {@link #moveSucceededWithScene}
* responses. */
public static const MOVE_SUCCEEDED_WITH_SCENE :int = 2;
// documentation inherited from interface SceneService_SceneMoveListener
public function moveSucceededWithScene (arg1 :int, arg2 :PlaceConfig, arg3 :SceneModel) :void
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, MOVE_SUCCEEDED_WITH_SCENE,
[ arg1, arg2, arg3 ]));
}
/** The method id used to dispatch {@link #moveSucceededWithUpdates}
* responses. */
public static const MOVE_SUCCEEDED_WITH_UPDATES :int = 3;
// documentation inherited from interface SceneService_SceneMoveListener
public function moveSucceededWithUpdates (arg1 :int, arg2 :PlaceConfig, arg3 :TypedArray /* of SceneUpdate */) :void
{
omgr.postEvent(new InvocationResponseEvent(
callerOid, requestId, MOVE_SUCCEEDED_WITH_UPDATES,
[ arg1, arg2, arg3 ]));
}
// documentation inherited
public override function dispatchResponse (methodId :int, args :Array) :void
{
switch (methodId) {
case MOVE_SUCCEEDED:
(listener as SceneService_SceneMoveListener).moveSucceeded(
args[0] as int, args[1] as PlaceConfig);
return;
case MOVE_SUCCEEDED_WITH_SCENE:
(listener as SceneService_SceneMoveListener).moveSucceededWithScene(
args[0] as int, args[1] as PlaceConfig, args[2] as SceneModel);
return;
case MOVE_SUCCEEDED_WITH_UPDATES:
(listener as SceneService_SceneMoveListener).moveSucceededWithUpdates(
args[0] as int, args[1] as PlaceConfig, args[2] as TypedArray);
return;
default:
super.dispatchResponse(methodId, args);
}
}
}
}
@@ -0,0 +1,118 @@
//
// $Id: SceneModel.java 3726 2005-10-11 19:17:43Z ray $
//
// 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.whirled.data {
import com.threerings.util.ClassUtil;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
import com.threerings.io.TypedArray;
/**
* The scene model is the bare bones representation of the data for a
* scene in the Whirled system. From the scene model, one would create an
* instance of {@link Scene}.
*
* <p> The scene model is what is loaded from the scene repositories and
* what is transmitted over the wire when communicating scenes from the
* server to the client.
*/
public class SceneModel
implements Streamable /*, Cloneable */
{
/** This scene's unique identifier. */
public var sceneId :int;
/** The human readable name of this scene. */
public var name :String;
/** The version number of this scene. Versions are incremented
* whenever modifications are made to a scene so that clients can
* determine whether or not they have the latest version of a
* scene. */
public var version :int;
/** Auxiliary scene model information. */
public var auxModels :TypedArray =
new TypedArray("[Lcom.threerings.whirled.data.AuxModel;");
/**
* Adds the specified auxiliary model to this scene model.
*/
public function addAuxModel (auxModel :AuxModel) :void
{
auxModels.push(auxModel);
}
// documentation inherited
public function clone () :Object
{
var clazz :Class = ClassUtil.getClass(this);
var model :SceneModel = new clazz();
for each (var aux :AuxModel in auxModels) {
model.addAuxModel(aux.clone() as AuxModel);
}
return model;
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
{
out.writeInt(sceneId);
out.writeField(name);
out.writeInt(version);
out.writeField(auxModels);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
{
sceneId = ins.readInt();
name = (ins.readField(String) as String);
version = ins.readInt();
auxModels = (ins.readField("[Lcom.threerings.whirled.data.AuxModel;")
as TypedArray);
}
/**
* Creates and returns a blank scene model.
*/
public static function blankSceneModel () :SceneModel
{
var model :SceneModel = new SceneModel();
populateBlankSceneModel(model);
return model;
}
/**
* Populates a blank scene model with blank values.
*/
protected static function populateBlankSceneModel (model :SceneModel) :void
{
model.sceneId = -1;
model.name = "<blank>";
model.version = 0;
}
}
}
@@ -0,0 +1,29 @@
//
// $Id: SceneObject.java 3288 2004-12-28 03:51:29Z 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.whirled.data {
import com.threerings.crowd.data.PlaceObject;
public class SceneObject extends PlaceObject
{
}
}
@@ -0,0 +1,153 @@
//
// $Id: SceneUpdate.java 3760 2005-11-15 03:08:23Z ray $
//
// 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.whirled.data {
import flash.errors.IllegalOperationError;
import com.threerings.util.StringBuilder;
import com.threerings.io.ObjectInputStream;
import com.threerings.io.ObjectOutputStream;
import com.threerings.io.Streamable;
/**
* Used to encapsulate updates to scenes in such a manner that updates can
* be stored persistently and sent to clients to update their own local
* copies of scenes.
*/
public class SceneUpdate
implements Streamable /*, Cloneable */
{
/**
* Initializes this scene update such that it will operate on a scene
* with the specified target scene and version number.
*
* @param targetId the id of the scene on which we are to operate.
* @param targetVersion the version of the scene on which we are to
* operate.
*/
public function init (targetId :int, targetVersion :int) :void
{
_targetId = targetId;
_targetVersion = targetVersion;
}
/**
* Returns the scene id for which this update is appropriate.
*/
public function getSceneId () :int
{
return _targetId;
}
/**
* Returns the scene version for which this update is appropriate.
*/
public function getSceneVersion () :int
{
return _targetVersion;
}
/**
* Called to ensure that the scene is in the appropriate state prior
* to applying the update.
*
* @exception IllegalStateException thrown if the update cannot be
* applied to the scene because it is not in a valid state
* (appropriate previous updates were not applied, it's the wrong kind
* of scene, etc.).
*/
public function validate (model :SceneModel) :void
//throws IllegalStateException
{
if (model.sceneId != _targetId) {
var errmsg :String = "Wrong target scene, expected id " +
_targetId + " got id " + model.sceneId;
throw new IllegalOperationError(errmsg);
}
if (model.version != _targetVersion) {
var errmsg :String = "Target scene not proper version, expected " +
_targetVersion + " got " + model.version;
throw new IllegalOperationError(errmsg);
}
}
/**
* Applies this update to the specified scene model. Derived classes
* will want to override this method and apply updates of their own,
* being sure to call <code>super.apply</code>.
*/
public function apply (model :SceneModel) :void
{
// increment the version; disallowing integer overflow
model.version = Math.max(_targetVersion + 1, model.version);
// sanity check for the amazing two billion updates
if (model.version == _targetVersion) {
Log.getLog(this).warning("Egads! This scene has been updated two" +
" billion times [model=" + model + ", update=" + this + "].");
}
}
// documentation inherited from interface Streamable
public function writeObject (out :ObjectOutputStream) :void
//throws IOException
{
out.writeInt(_targetId);
out.writeInt(_targetVersion);
}
// documentation inherited from interface Streamable
public function readObject (ins :ObjectInputStream) :void
//throws IOException, ClassNotFoundException
{
_targetId = ins.readInt();
_targetVersion = ins.readInt();
}
/**
* Generates a string representation of this instance.
*/
public function toString () :String
{
var buf :StringBuilder = new StringBuilder("[");
toStringBuf(buf);
return buf.append("]").toString();
}
/**
* An extensible mechanism for generating a string representation of
* this instance.
*/
protected function toStringBuf (buf :StringBuilder) :void
{
buf.append("sceneId=").append(_targetId);
buf.append(", version=").append(_targetVersion);
}
/** The version number of the scene on which we operate. */
protected var _targetId :int;
/** The version number of the scene on which we operate. */
protected var _targetVersion :int;
}
}
@@ -0,0 +1,40 @@
//
// $Id: ScenedBodyObject.java 3099 2004-08-27 02:21:06Z 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.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;
}
}
@@ -0,0 +1,43 @@
//
// $Id: NoSuchSceneError.java 3099 2004-08-27 02:21:06Z 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.whirled.util {
/**
* Thrown when an attempt to load a non-existent scene is made on the
* repository.
*/
public class NoSuchSceneError extends Error
{
public function NoSuchSceneError (sceneid :int)
{
super("No such scene [sceneid=" + sceneid + "]");
_sceneid = sceneid;
}
public function getSceneId () :int
{
return _sceneid;
}
protected var _sceneid :int;
}
}
@@ -0,0 +1,40 @@
//
// $Id: SceneFactory.java 3099 2004-08-27 02:21:06Z 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.whirled.util {
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.data.Scene;
import com.threerings.whirled.data.SceneModel;
/**
* This is used by the Whirled services to obtain a {@link Scene}
* implementation given a scene model and associated data.
*/
public interface SceneFactory
{
/**
* Creates a {@link Scene} implementation given the supplied scene
* model and place config.
*/
function createScene (model :SceneModel, config :PlaceConfig) :Scene;
}
}
@@ -0,0 +1,99 @@
//
// $Id: UpdateList.java 3099 2004-08-27 02:21:06Z 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.whirled.util {
import com.threerings.whirled.data.SceneUpdate;
/**
* A list specialized for storing {@link SceneUpdate} objects.
*/
public class UpdateList
{
public function UpdateList ()
{
_updates = new Array();
}
/**
* Adds an update to this list. The update must follow appropriately
* the chain of updates established by the updates already in the list
* (meaning it must operate on one version higher than the most recent
* update already in the list).
*/
public function addUpdate (update :SceneUpdate) :void
{
if (_minVersion == -1) {
// this is our first update, so we initialize our min version
_minVersion = update.getSceneVersion();
} else {
var gotVersion :int = update.getSceneVersion();
var expVersion :int = _minVersion + _updates.length;
if (gotVersion > expVersion) {
Log.getLog(this).warning("Update continuity broken, " +
"flushing list [got=" + update + ", expect=" + expVersion +
", ucount=" + _updates.length + "].");
// flush out our old updates and start anew from here
_updates.length = 0;
_minVersion = expVersion;
} else if (gotVersion < expVersion) {
// we somehow got an update that's older than updates we
// already have? wick wick wack
throw new IllegalArgumentError("Invalid update version " +
"[want=" + expVersion + ", got=" + update + "]");
}
}
_updates.push(update);
}
/**
* Returns all of the updates that should be applied to a scene with
* the specified version to bring it up to date. <code>null</code> is
* returned if the scene's version is older than the oldest update in
* our list, in which case it cannot be brought up to date by applying
* updates from this list.
*/
public function getUpdates (fromVersion :int) :Array /*of SceneUpdate*/
{
if (_minVersion == -1 || fromVersion < _minVersion) {
return null;
}
var offset :int = fromVersion - _minVersion;
return _updates.slice(offset);
}
/**
* Returns true if the supplied actual scene version is in accordance
* with the updates contained in this list.
*/
public function validate (sceneVersion :int) :Boolean
{
return ((_minVersion == -1) || // we have no updates
(_minVersion + _updates.length == sceneVersion));
}
protected var _updates :Array;
protected var _minVersion :int = -1;
}
}
@@ -0,0 +1,38 @@
//
// $Id: WhirledContext.java 3099 2004-08-27 02:21:06Z 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.whirled.util {
import com.threerings.crowd.util.CrowdContext;
import com.threerings.whirled.client.SceneDirector;
/**
* The whirled context provides access to the various managers, etc. that
* are needed by the whirled client code.
*/
public interface WhirledContext extends CrowdContext
{
/**
* Returns a reference to the scene director.
*/
function getSceneDirector () :SceneDirector;
}
}