More cluster fiddly.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2335 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SpotService.java,v 1.14 2003/03/26 02:06:06 mdb Exp $
|
// $Id: SpotService.java,v 1.15 2003/03/27 00:10:08 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.whirled.spot.client;
|
package com.threerings.whirled.spot.client;
|
||||||
|
|
||||||
@@ -42,9 +42,10 @@ public interface SpotService extends InvocationService
|
|||||||
* Requests that this client start or join the specified cluster. They
|
* Requests that this client start or join the specified cluster. They
|
||||||
* will be relocated appropriately by the scene manager.
|
* will be relocated appropriately by the scene manager.
|
||||||
*
|
*
|
||||||
* @param friendOid the bodyOid of another user; the calling user will
|
* @param friendOid the bodyOid of another user or the oid of an
|
||||||
* be made to join the target user's cluster, or create a cluster with
|
* existing cluster; the calling user will be made to join the cluster
|
||||||
* the target user if they are not already in one.
|
* or target user's cluster, or create a cluster with the target user
|
||||||
|
* if they are not already in one.
|
||||||
*/
|
*/
|
||||||
public void joinCluster (Client client, int friendOid,
|
public void joinCluster (Client client, int friendOid,
|
||||||
ConfirmListener listener);
|
ConfirmListener listener);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SpotSceneManager.java,v 1.33 2003/03/26 22:34:24 mdb Exp $
|
// $Id: SpotSceneManager.java,v 1.34 2003/03/27 00:10:08 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.whirled.spot.server;
|
package com.threerings.whirled.spot.server;
|
||||||
|
|
||||||
@@ -230,42 +230,44 @@ public class SpotSceneManager extends SceneManager
|
|||||||
* user to join a particular cluster.
|
* user to join a particular cluster.
|
||||||
*
|
*
|
||||||
* @param joiner the body to be moved.
|
* @param joiner the body to be moved.
|
||||||
* @param friendOid the bodyOid of another user; the moving user will
|
* @param targetOid the bodyOid of another user or the oid of an
|
||||||
* be made to join the other user's cluster.
|
* existing cluster; the moving user will be made to join the other
|
||||||
|
* user's cluster.
|
||||||
*
|
*
|
||||||
* @exception InvocationException thrown with a reason code explaining
|
* @exception InvocationException thrown with a reason code explaining
|
||||||
* the failure if there is a problem processing the request.
|
* the failure if there is a problem processing the request.
|
||||||
*/
|
*/
|
||||||
protected void handleJoinCluster (BodyObject joiner, int friendOid)
|
protected void handleJoinCluster (BodyObject joiner, int targetOid)
|
||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
ClusterRecord clrec = (ClusterRecord)_clusters.get(friendOid);
|
// if the cluster already exists, add this user and be done
|
||||||
|
ClusterRecord clrec = (ClusterRecord)_clusters.get(targetOid);
|
||||||
if (clrec != null) {
|
if (clrec != null) {
|
||||||
// if the cluster already exists, add this user and be done
|
clrec.addBody(joiner);
|
||||||
if (clrec.addBody(joiner)) {
|
|
||||||
_clusters.put(joiner.getOid(), clrec);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise we have to create a new cluster and add our two
|
// otherwise see if they sent us the user's oid
|
||||||
// charter members!
|
DObject tobj = CrowdServer.omgr.getObject(targetOid);
|
||||||
clrec = new ClusterRecord();
|
if (!(tobj instanceof BodyObject)) {
|
||||||
BodyObject member = (BodyObject)CrowdServer.omgr.getObject(friendOid);
|
Log.warning("Can't join cluster, missing target " +
|
||||||
if (member == null) {
|
|
||||||
Log.warning("Can't create cluster, missing target " +
|
|
||||||
"[creator=" + joiner.who() +
|
"[creator=" + joiner.who() +
|
||||||
", friendOid=" + friendOid + "].");
|
", targetOid=" + targetOid + "].");
|
||||||
|
throw new InvocationException(NO_SUCH_CLUSTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// see if the friend is already in a cluster
|
||||||
|
BodyObject friend = (BodyObject)tobj;
|
||||||
|
clrec = getCluster(friend.getOid());
|
||||||
|
if (clrec != null) {
|
||||||
|
clrec.addBody(joiner);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add our two lovely users to the newly created cluster
|
// otherwise we create a new cluster and add our charter members!
|
||||||
if (clrec.addBody(member)) {
|
clrec = new ClusterRecord();
|
||||||
_clusters.put(member.getOid(), clrec);
|
clrec.addBody(friend);
|
||||||
}
|
clrec.addBody(joiner);
|
||||||
if (clrec.addBody(joiner)) {
|
|
||||||
_clusters.put(joiner.getOid(), clrec);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -273,12 +275,23 @@ public class SpotSceneManager extends SceneManager
|
|||||||
*/
|
*/
|
||||||
protected void removeFromCluster (int bodyOid)
|
protected void removeFromCluster (int bodyOid)
|
||||||
{
|
{
|
||||||
ClusterRecord clrec = (ClusterRecord)_clusters.remove(bodyOid);
|
ClusterRecord clrec = getCluster(bodyOid);
|
||||||
if (clrec != null) {
|
if (clrec != null) {
|
||||||
clrec.removeBody(bodyOid);
|
clrec.removeBody(bodyOid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the cluster record for the specified body.
|
||||||
|
*/
|
||||||
|
protected ClusterRecord getCluster (int bodyOid)
|
||||||
|
{
|
||||||
|
ClusteredBodyObject bobj = (ClusteredBodyObject)
|
||||||
|
CrowdServer.omgr.getObject(bodyOid);
|
||||||
|
return (bobj == null) ? null :
|
||||||
|
(ClusterRecord)_clusters.get(bobj.getClusterOid());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the {@link SpotProvider} when we receive a cluster speak
|
* Called by the {@link SpotProvider} when we receive a cluster speak
|
||||||
* request.
|
* request.
|
||||||
@@ -286,7 +299,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
protected void handleClusterSpeakRequest (
|
protected void handleClusterSpeakRequest (
|
||||||
int sourceOid, String source, String bundle, String message, byte mode)
|
int sourceOid, String source, String bundle, String message, byte mode)
|
||||||
{
|
{
|
||||||
ClusterRecord clrec = (ClusterRecord)_clusters.get(sourceOid);
|
ClusterRecord clrec = getCluster(sourceOid);
|
||||||
if (clrec == null) {
|
if (clrec == null) {
|
||||||
Log.warning("Non-clustered user requested cluster speak " +
|
Log.warning("Non-clustered user requested cluster speak " +
|
||||||
"[where=" + where() + ", chatter=" + source +
|
"[where=" + where() + ", chatter=" + source +
|
||||||
@@ -306,34 +319,6 @@ public class SpotSceneManager extends SceneManager
|
|||||||
return (SceneLocation)_ssobj.occupantLocs.get(new Integer(bodyOid));
|
return (SceneLocation)_ssobj.occupantLocs.get(new Integer(bodyOid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the x and y coordinates in the supplied location object to
|
|
||||||
* Cartesian coordinates that can be manipulated geometrically. The
|
|
||||||
* default implementation assumes the location coordinates are
|
|
||||||
* Cartesian, but systems that use different coordinate systems will
|
|
||||||
* want to override this method and perform the appropriate
|
|
||||||
* conversions.
|
|
||||||
*/
|
|
||||||
protected void locationToCoords (int lx, int ly, Point coords)
|
|
||||||
{
|
|
||||||
coords.x = lx;
|
|
||||||
coords.y = ly;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the supplied x and y coordinates (obtained from a prior
|
|
||||||
* call to {@link #locationToCoords}) to location coordinates that can
|
|
||||||
* be sent back to the client. The default implementation assumes the
|
|
||||||
* location coordinates are Cartesian, but systems that use different
|
|
||||||
* coordinate systems will want to override this method and perform
|
|
||||||
* the appropriate conversions.
|
|
||||||
*/
|
|
||||||
protected void coordsToLocation (int cx, int cy, Point loc)
|
|
||||||
{
|
|
||||||
loc.x = cx;
|
|
||||||
loc.y = cy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that the specified cluster can be expanded to include
|
* Verifies that the specified cluster can be expanded to include
|
||||||
* another body.
|
* another body.
|
||||||
@@ -463,6 +448,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
{
|
{
|
||||||
// keep this feller around
|
// keep this feller around
|
||||||
_clobj = (ClusterObject)object;
|
_clobj = (ClusterObject)object;
|
||||||
|
_clusters.put(_clobj.getOid(), this);
|
||||||
|
|
||||||
// let any mapped users know about our cluster
|
// let any mapped users know about our cluster
|
||||||
Iterator iter = values().iterator();
|
Iterator iter = values().iterator();
|
||||||
@@ -506,6 +492,7 @@ public class SpotSceneManager extends SceneManager
|
|||||||
Log.info("Cluster empty, going away " +
|
Log.info("Cluster empty, going away " +
|
||||||
"[cloid=" + _clobj.getOid() + "].");
|
"[cloid=" + _clobj.getOid() + "].");
|
||||||
_ssobj.removeFromClusters(_cluster.getKey());
|
_ssobj.removeFromClusters(_cluster.getKey());
|
||||||
|
_clusters.remove(_clobj.getOid());
|
||||||
CrowdServer.omgr.destroyObject(_clobj.getOid());
|
CrowdServer.omgr.destroyObject(_clobj.getOid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user