Changed AddObjectUpdate to a more general ModifyObjectsUpdate and added a service call to delete an object.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3572 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -18,4 +18,10 @@ public interface StageSceneService extends InvocationService
|
||||
*/
|
||||
public void addObject (Client client, ObjectInfo info,
|
||||
ConfirmListener listener);
|
||||
|
||||
/**
|
||||
* Requests to remove the supplied object from the current scene.
|
||||
*/
|
||||
public void removeObject (Client client, ObjectInfo info,
|
||||
ConfirmListener listener);
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// $Id: AddObjectUpdate.java 15953 2004-06-11 23:40:47Z ray $
|
||||
|
||||
package com.threerings.stage.data;
|
||||
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.data.SceneUpdate;
|
||||
|
||||
/**
|
||||
* A scene update that is broadcast when an object has been added to a
|
||||
* scene.
|
||||
*/
|
||||
public class AddObjectUpdate extends SceneUpdate
|
||||
{
|
||||
/** The info on the object. */
|
||||
public ObjectInfo info;
|
||||
|
||||
/** If non-null, a list of objects to remove from the scene. */
|
||||
public ObjectInfo[] casualties;
|
||||
|
||||
/**
|
||||
* Initializes this update with all necessary data.
|
||||
*
|
||||
* @param casualties optional, a list of objects to remove.
|
||||
*/
|
||||
public void init (int targetId, int targetVersion, ObjectInfo info,
|
||||
ObjectInfo[] casualties)
|
||||
{
|
||||
init(targetId, targetVersion);
|
||||
this.info = info;
|
||||
this.casualties = casualties;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void apply (SceneModel model)
|
||||
{
|
||||
super.apply(model);
|
||||
|
||||
StageMisoSceneModel mmodel = StageMisoSceneModel.getSceneModel(model);
|
||||
|
||||
// wipe out the objects that need to go
|
||||
if (casualties != null) {
|
||||
for (int ii = 0; ii < casualties.length; ii++) {
|
||||
mmodel.removeObject(casualties[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
// add the new object
|
||||
mmodel.addObject(info);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// $Id: AddObjectUpdate.java 15953 2004-06-11 23:40:47Z ray $
|
||||
|
||||
package com.threerings.stage.data;
|
||||
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
|
||||
import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.data.SceneUpdate;
|
||||
|
||||
/**
|
||||
* A scene update that is broadcast when objects have been added to or removed
|
||||
* from the scene.
|
||||
*/
|
||||
public class ModifyObjectsUpdate extends SceneUpdate
|
||||
{
|
||||
/** The objects added to the scene (or <code>null</code> for none). */
|
||||
public ObjectInfo[] added;
|
||||
|
||||
/** The objects removed from the scene (or <code>null</code> for none). */
|
||||
public ObjectInfo[] removed;
|
||||
|
||||
/**
|
||||
* Initializes this update with all necessary data.
|
||||
*
|
||||
* @param added the objects added to the scene, or <code>null</code> for
|
||||
* none
|
||||
* @param removed the objects removed from the scene, or <code>null</code>
|
||||
* for none
|
||||
*/
|
||||
public void init (int targetId, int targetVersion, ObjectInfo[] added,
|
||||
ObjectInfo[] removed)
|
||||
{
|
||||
init(targetId, targetVersion);
|
||||
this.added = added;
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void apply (SceneModel model)
|
||||
{
|
||||
super.apply(model);
|
||||
|
||||
StageMisoSceneModel mmodel = StageMisoSceneModel.getSceneModel(model);
|
||||
|
||||
// wipe out the objects that need to go
|
||||
if (removed != null) {
|
||||
for (int ii = 0; ii < removed.length; ii++) {
|
||||
mmodel.removeObject(removed[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
// add the new objects
|
||||
if (added != null) {
|
||||
for (int ii = 0; ii < added.length; ii++) {
|
||||
mmodel.addObject(added[ii]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,4 +51,17 @@ public class StageSceneMarshaller extends InvocationMarshaller
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #removeObject} requests. */
|
||||
public static final int REMOVE_OBJECT = 2;
|
||||
|
||||
// documentation inherited from interface
|
||||
public void removeObject (Client arg1, ObjectInfo arg2, InvocationService.ConfirmListener arg3)
|
||||
{
|
||||
InvocationMarshaller.ConfirmMarshaller listener3 = new InvocationMarshaller.ConfirmMarshaller();
|
||||
listener3.listener = arg3;
|
||||
sendRequest(arg1, REMOVE_OBJECT, new Object[] {
|
||||
arg2, listener3
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,6 +64,13 @@ public class StageSceneDispatcher extends InvocationDispatcher
|
||||
);
|
||||
return;
|
||||
|
||||
case StageSceneMarshaller.REMOVE_OBJECT:
|
||||
((StageSceneProvider)provider).removeObject(
|
||||
source,
|
||||
(ObjectInfo)args[0], (InvocationService.ConfirmListener)args[1]
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ import com.threerings.whirled.spot.server.SpotSceneManager;
|
||||
|
||||
import com.threerings.stage.Log;
|
||||
import com.threerings.stage.client.StageSceneService;
|
||||
import com.threerings.stage.data.AddObjectUpdate;
|
||||
import com.threerings.stage.data.DefaultColorUpdate;
|
||||
import com.threerings.stage.data.ModifyObjectsUpdate;
|
||||
import com.threerings.stage.data.StageCodes;
|
||||
import com.threerings.stage.data.StageMisoSceneModel;
|
||||
import com.threerings.stage.data.StageOccupantInfo;
|
||||
@@ -110,11 +110,11 @@ public class StageSceneManager extends SpotSceneManager
|
||||
|
||||
// create our scene update which will be stored in the database
|
||||
// and used to efficiently update clients
|
||||
final AddObjectUpdate update = new AddObjectUpdate();
|
||||
update.init(_sscene.getId(), _sscene.getVersion(), info,
|
||||
killOverlap ? lappers : null);
|
||||
final ModifyObjectsUpdate update = new ModifyObjectsUpdate();
|
||||
update.init(_sscene.getId(), _sscene.getVersion(),
|
||||
new ObjectInfo[] { info }, killOverlap ? lappers : null);
|
||||
|
||||
Log.info("Adding object '" + update + ".");
|
||||
Log.info("Modifying objects '" + update + ".");
|
||||
recordUpdate(update, true);
|
||||
|
||||
return true;
|
||||
@@ -166,15 +166,36 @@ public class StageSceneManager extends SpotSceneManager
|
||||
throw new InvocationException(err);
|
||||
}
|
||||
|
||||
boolean allowOverlap =
|
||||
(user.checkAccess(StageCodes.MODIFY_SCENE_ACCESS, _sscene) == null);
|
||||
if (addObject(info, false, allowOverlap)) {
|
||||
if (addObject(info, false, true)) {
|
||||
listener.requestProcessed();
|
||||
} else {
|
||||
listener.requestFailed(StageCodes.ERR_NO_OVERLAP);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void removeObject (ClientObject caller, ObjectInfo info,
|
||||
StageSceneService.ConfirmListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
BodyObject user = (BodyObject)caller;
|
||||
String err = user.checkAccess(StageCodes.MODIFY_SCENE_ACCESS, _sscene);
|
||||
if (err != null) {
|
||||
throw new InvocationException(err);
|
||||
}
|
||||
|
||||
// create our scene update which will be stored in the database
|
||||
// and used to efficiently update clients
|
||||
ModifyObjectsUpdate update = new ModifyObjectsUpdate();
|
||||
update.init(_sscene.getId(), _sscene.getVersion(),
|
||||
null, new ObjectInfo[] { info });
|
||||
|
||||
Log.info("Modifying objects '" + update + ".");
|
||||
recordUpdate(update, true);
|
||||
|
||||
listener.requestProcessed();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
protected void gotSceneData ()
|
||||
{
|
||||
|
||||
@@ -22,4 +22,11 @@ public interface StageSceneProvider extends InvocationProvider
|
||||
public void addObject (ClientObject caller, ObjectInfo info,
|
||||
StageSceneService.ConfirmListener listener)
|
||||
throws InvocationException;
|
||||
|
||||
/**
|
||||
* Handles a {@link StageSceneService#removeObject} request.
|
||||
*/
|
||||
public void removeObject (ClientObject caller, ObjectInfo info,
|
||||
StageSceneService.ConfirmListener listener)
|
||||
throws InvocationException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user