I have created a minimal test case to show the wrong behaviour
The server:
import java.io.IOException;
import com.jme3.app.SimpleApplication;
import com.jme3.math.Vector3f;
import com.jme3.network.Network;
import com.jme3.network.Server;
import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.FieldSerializer;
import com.jme3.system.JmeContext.Type;
import com.simsilica.es.Entity;
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import com.simsilica.es.EntitySet;
import com.simsilica.es.Name;
import com.simsilica.es.base.DefaultEntityData;
import com.simsilica.es.net.EntitySerializers;
import com.simsilica.es.server.EntityDataHostService;
public class TestServer extends SimpleApplication {
public static final int PORT = 12345;
private Server host;
private EntityDataHostService edHost;
private EntityData ed = new DefaultEntityData();
private EntitySet set;
static {
EntitySerializers.initialize();
Serializer fieldSerializer = new FieldSerializer();
Serializer.registerClass(OwnedByPlayer.class, fieldSerializer);
Serializer.registerClass(Position.class, fieldSerializer);
}
@Override
public void simpleInitApp() {
try {
host = Network.createServer("Test", 1, PORT, PORT);
host.addChannel(PORT + 1);
edHost = new EntityDataHostService(host, 0, ed);
host.start();
initData();
} catch (IOException e) {
e.printStackTrace();
}
}
private void initData() {
EntityId player1 = ed.createEntity();
EntityId player2 = ed.createEntity();
System.out.println("player1: " + player1);
System.out.println("player2: " + player2);
ed.setComponent(player1, new Name("Player 1"));
ed.setComponent(player2, new Name("Player 2"));
EntityId unit1 = ed.createEntity();
EntityId unit2 = ed.createEntity();
System.out.println("unit1: " + unit1);
System.out.println("unit2: " + unit2);
ed.setComponents(unit1, new Position(new Vector3f(0, 0, 0)),
new OwnedByPlayer(player1));
ed.setComponents(unit2, new Position(new Vector3f(100, 0, 0)),
new OwnedByPlayer(player2));
set = ed.getEntities(Position.class);
}
@Override
public void update() {
for (Entity e : set) {
Position pos = e.get(Position.class);
e.set(new Position(pos.getPosition().add(0, 1, 2)));
}
edHost.sendUpdates();
}
public static void main(String[] args) {
TestServer server = new TestServer();
server.start(Type.Headless);
}
}
The client:
import java.io.IOException;
import com.jme3.app.SimpleApplication;
import com.jme3.network.Client;
import com.jme3.network.ClientStateListener;
import com.jme3.network.Message;
import com.jme3.network.MessageListener;
import com.jme3.network.Network;
import com.jme3.network.serializing.Serializer;
import com.jme3.network.serializing.serializers.FieldSerializer;
import com.jme3.system.JmeContext.Type;
import com.simsilica.es.Entity;
import com.simsilica.es.EntityId;
import com.simsilica.es.EntitySet;
import com.simsilica.es.client.RemoteEntityData;
import com.simsilica.es.filter.FieldFilter;
import com.simsilica.es.net.ComponentChangeMessage;
import com.simsilica.es.net.EntitySerializers;
public class TestClient extends SimpleApplication {
private Client client;
private RemoteEntityData ed;
private EntitySet set;
private static final int PLAYER_ID = 0;
static {
EntitySerializers.initialize();
Serializer fieldSerializer = new FieldSerializer();
Serializer.registerClass(OwnedByPlayer.class, fieldSerializer);
Serializer.registerClass(Position.class, fieldSerializer);
}
@Override
public void simpleInitApp() {
try {
client = Network.connectToServer("Test", 1, "localhost",
TestServer.PORT, TestServer.PORT);
client.addMessageListener(new MessageListener<Client>() {
@Override
public void messageReceived(Client source, Message m) {
if (m instanceof ComponentChangeMessage) {
}
System.out.println("Received: " + m.toString());
}
});
ed = new RemoteEntityData(client, 0);
client.addClientStateListener(new ClientStateListener() {
@Override
public void clientDisconnected(Client c, DisconnectInfo info) {
}
@Override
public void clientConnected(Client c) {
set = ed.getEntities(FieldFilter.create(
OwnedByPlayer.class, "playerID", new EntityId(
PLAYER_ID)), OwnedByPlayer.class,
Position.class);
}
});
client.start();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void update() {
if (set != null) {
if (set.applyChanges()) {
for (Entity e : set.getChangedEntities()) {
OwnedByPlayer own = e.get(OwnedByPlayer.class);
System.out.println(own.toString());
}
}
}
}
public static void main(String[] args) {
TestClient client = new TestClient();
client.start(Type.Headless);
}
}
Output of the server:
player1: EntityId[0]
player2: EntityId[1]
unit1: EntityId[2]
unit2: EntityId[3]
Output of the client:
Received: ComponentChangeMessage[[EntityChange[EntityId[3], Position[position=(100.0, 237.0, 474.0)], class Position], EntityChange[EntityId[2], Position[position=(0.0, 237.0, 474.0)], class Position]]]
Received: ReturnComponentsMessage[72, EntityId[3], [OwnedByPlayer[playerID=1]]]
OwnedByPlayer[playerID=0]
So you can see the client gets the updates for both units (EntityId 2 and 3), where he should only get one for ID 2.
In the EntitySet only the correct Entity arrivies (OwnedByPlayer[playerID=0]).