Initial version of runtime miso scene business.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2055 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// $Id: RuntimeMisoScene.java,v 1.1 2002/12/11 23:07:21 shaper Exp $
|
||||||
|
|
||||||
|
package com.threerings.miso.server;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import com.threerings.miso.scene.SceneObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Miso scene interface used by the server to deal with scenes.
|
||||||
|
*/
|
||||||
|
public interface RuntimeMisoScene
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Iterates over the {@link RuntimeSceneObject} instances representing
|
||||||
|
* all available objects in the scene.
|
||||||
|
*/
|
||||||
|
public Iterator enumerateSceneObjects ();
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
//
|
||||||
|
// $Id: RuntimeMisoSceneImpl.java,v 1.1 2002/12/11 23:07:21 shaper Exp $
|
||||||
|
|
||||||
|
package com.threerings.miso.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import com.threerings.miso.scene.MisoSceneModel;
|
||||||
|
import com.threerings.miso.scene.SceneObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A basic implementation of the {@link RuntimeMisoScene} interface which
|
||||||
|
* is used by default if no extended implementation is desired.
|
||||||
|
*/
|
||||||
|
public class RuntimeMisoSceneImpl
|
||||||
|
implements RuntimeMisoScene
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates an instance that will obtain data from the supplied scene
|
||||||
|
* model and place config.
|
||||||
|
*/
|
||||||
|
public RuntimeMisoSceneImpl (MisoSceneModel model)
|
||||||
|
{
|
||||||
|
// keep a casted reference to our scene model around
|
||||||
|
_model = model;
|
||||||
|
|
||||||
|
// build a list of all objects in the scene
|
||||||
|
populateSceneObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gathers and stores information about all objects in the scene.
|
||||||
|
*/
|
||||||
|
protected void populateSceneObjects ()
|
||||||
|
{
|
||||||
|
int ocount = _model.objectTileIds.length;
|
||||||
|
for (int ii = 0; ii < ocount; ii += 3) {
|
||||||
|
RuntimeSceneObject scobj = new RuntimeSceneObject();
|
||||||
|
scobj.x = _model.objectTileIds[ii];
|
||||||
|
scobj.y = _model.objectTileIds[ii+1];
|
||||||
|
scobj.action = _model.objectActions[ii/3];
|
||||||
|
_objects.add(scobj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public Iterator enumerateSceneObjects ()
|
||||||
|
{
|
||||||
|
return _objects.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A casted reference to our scene model. */
|
||||||
|
protected MisoSceneModel _model;
|
||||||
|
|
||||||
|
/** The scene object records. */
|
||||||
|
protected ArrayList _objects = new ArrayList();
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// $Id: RuntimeSceneObject.java,v 1.1 2002/12/11 23:07:21 shaper Exp $
|
||||||
|
|
||||||
|
package com.threerings.miso.server;
|
||||||
|
|
||||||
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to track server-side information about an object in a miso scene.
|
||||||
|
*/
|
||||||
|
public class RuntimeSceneObject
|
||||||
|
{
|
||||||
|
/** The x and y tile coordinates of the object. */
|
||||||
|
public int x = -1, y = -1;
|
||||||
|
|
||||||
|
/** The action associated with this object or null if it has no
|
||||||
|
* action. */
|
||||||
|
public String action;
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public boolean equals (Object other)
|
||||||
|
{
|
||||||
|
if (other instanceof RuntimeSceneObject) {
|
||||||
|
RuntimeSceneObject oso = (RuntimeSceneObject)other;
|
||||||
|
// TODO: we should probably check the tile type as well, but
|
||||||
|
// for now we only differentiate runtime miso scene objects by
|
||||||
|
// their coordinates within the scene since we don't bother
|
||||||
|
// keeping around tile information server-side
|
||||||
|
return (x == oso.x && y == oso.y);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// documentation inherited
|
||||||
|
public int hashCode ()
|
||||||
|
{
|
||||||
|
return x ^ y;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Generates a string representation of this instance. */
|
||||||
|
public String toString ()
|
||||||
|
{
|
||||||
|
return StringUtil.fieldsToString(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user