Whirled actionscript code, transferred from narya.

git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@5 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Ray Greenwell
2006-06-23 19:21:10 +00:00
parent 88ba927cb5
commit 01866933eb
38 changed files with 3654 additions and 0 deletions
@@ -0,0 +1,35 @@
//
// $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.util.Cloneable;
import com.threerings.io.Streamable;
/**
* An interface that must be implemented by auxiliary scene models.
*/
public interface AuxModel extends Streamable, Cloneable
{
// no new methods
}
}
@@ -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,53 @@
//
// $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.util.Integer;
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, [ new Integer(arg2), new Integer(arg3), listener4 ]);
}
}
}
@@ -0,0 +1,81 @@
package com.threerings.whirled.data {
import com.threerings.util.Integer;
import com.threerings.io.TypedArray;
import com.threerings.presents.data.InvocationMarshaller_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 InvocationMarshaller_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,
[ new Integer(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,
[ new Integer(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,
[ new Integer(arg1), arg2, arg3 ]));
}
// documentation inherited
override public function dispatchResponse (methodId :int, args :Array) :void
{
switch (methodId) {
case MOVE_SUCCEEDED:
(listener as SceneService_SceneMoveListener).moveSucceeded(
(args[0] as Integer).value, args[1] as PlaceConfig);
return;
case MOVE_SUCCEEDED_WITH_SCENE:
(listener as SceneService_SceneMoveListener).moveSucceededWithScene(
(args[0] as Integer).value, args[1] as PlaceConfig, args[2] as SceneModel);
return;
case MOVE_SUCCEEDED_WITH_UPDATES:
(listener as SceneService_SceneMoveListener).moveSucceededWithUpdates(
(args[0] as Integer).value, 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.util.Cloneable;
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 from interface Cloneable
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.writeObject(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.readObject() 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;
}
}