Thanks!
I was trying to use proximity, unaware that it was disabled and that made me a bit confused.
Now I've looked through the code for the synchronization and I couldn't find a mention of proximity in there, so I added it at a place where I thought it would fit.
It wasn't a difficult fix (although I'm not sure my fix is the most efficient) and it worked well until I moved in the game and found new dynamic objects that needed to be sync'ed (these objects are dynamically created on the client when you get near them). I then got "Unable to find object x" since the clients didn't get a SynchronizeCreateMessage, so I had to add a method in SynchronizationManager that let me find the SyncWrapper id for an object that I wanted to sync to a client, so I could send it with the object creation message.
With these two changes it seems now that my implementation is working as expected.
If you think they are good enough to include in JGN, feel free to use them (that proximity method is great, so it would be nice to be able to use it, of course). Here they are:
In SyncWrapper.java
protected void update(SynchronizationManager manager, JGNServer server, GraphicalController controller) {
long updateRate = rate;
for(JGNConnection conn : server.getConnections()) {
if(controller.proximity(getObject(), conn.getPlayerId()) > 0f) {
updateRate = (long) (rate/controller.proximity(getObject(), conn.getPlayerId()));
if (lastUpdate + updateRate < System.nanoTime()) {
if (server.getConnections().length > 0) {
SynchronizeMessage message = controller.createSynchronizationMessage(getObject());
message.setSyncManagerId(manager.getId());
message.setSyncObjectId(getId());
server.sendToPlayer(message, conn.getPlayerId());
}
lastUpdate = System.nanoTime();
}
}
}
}
protected void update(SynchronizationManager manager, JGNClient client, GraphicalController controller) {
long updateRate = rate;
for(JGNConnection conn : client.getConnections()) {
if(controller.proximity(getObject(), conn.getPlayerId()) > 0f) {
updateRate = (long) (rate/controller.proximity(getObject(), conn.getPlayerId()));
if (lastUpdate + updateRate < System.nanoTime()) {
if(client.getConnections().length > 0) {
SynchronizeMessage message = controller.createSynchronizationMessage(getObject());
message.setSyncManagerId(manager.getId());
message.setSyncObjectId(getId());
client.sendToPlayer(message, conn.getPlayerId());
}
lastUpdate = System.nanoTime();
}
}
}
}
In SynchronizationManager.java:
public short findSyncObjectId(Object obj) {
SyncWrapper sync = findWrapper(obj);
if(sync != null) {
return sync.getId();
}
return -1;
}
However, I did get this old error when I tried connecting two clients, but only after at least one of them disconnected:
2009-okt-28 21:51:19 com.captiveimagination.jgn.MessageClient setStatus
VARNING:
java.lang.Exception: MC 599948211598647296 state equal. PLEASE SEND LOG to JGN, if this appears ...(DISCONNECTED-->DISCONNECTED). Thanks
at com.captiveimagination.jgn.MessageClient.setStatus(MessageClient.java:192)
at com.captiveimagination.jgn.NIOMessageServer.disconnectInternal(NIOMessageServer.java:109)
at com.captiveimagination.jgn.NIOMessageServer.updateTraffic(NIOMessageServer.java:169)
at com.captiveimagination.jgn.clientserver.JGNServer.updateTraffic(JGNServer.java:171)
at com.captiveimagination.jgn.clientserver.JGNServer.update(JGNServer.java:160)
at com.captiveimagination.jgn.UpdatableRunnable.run(JGN.java:437)
at java.lang.Thread.run(Unknown Source)