The variables are not the same for some reason.
Here is where I receive the object:
if(omsg instanceof ServerPlayerStateMessage){
ServerPlayerStateMessage msg = (ServerPlayerStateMessage) omsg;
for(int i=0; i<msg.players.length; i++){
PlayerModel newModel = msg.players[i];
PlayerModel oldModel = playerManager.getByID(newModel.clientID);
if(oldModel != null){
oldModel.setTilePos(newModel.tileX,newModel.tileY);
}
}
}
Here is where I send:
if(msg instanceof ClientMoveMessage){
System.out.println("Client move msg");
ClientMoveMessage msg2 = (ClientMoveMessage) msg;
cThread1.getPlayerModel().setTilePos(msg2.tileX, msg2.tileY);
}
public void sendPlayerStates(){
ArrayList<PlayerModel> playerModels = new ArrayList<PlayerModel>();
for(int i=0; i<cThreads.size(); i++){
ClientThread t = cThreads.get(i);
playerModels.add(t.getPlayerModel());
}
ServerPlayerStateMessage msg = new ServerPlayerStateMessage();
msg.players = new PlayerModel[playerModels.size()];
msg.players = playerModels.toArray(msg.players);
broadcast(msg);
}
Here is the actual objectoutputstream writing:
public void sendAll() {
if(socket.isConnected()){
Object msg = null;
while((msg = outQueue.poll()) != null){
try {
out.writeUnshared(msg);
out.flush();
out.reset();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public class ServerPlayerStateMessage implements Serializable {
public PlayerModel[] players;
}
public class PlayerModel implements Serializable {
//Owner of this player model
public int clientID;
public int tileX;
public int tileY;
public void setTilePos(int tileX, int tileY){
this.tileX = tileX;
this.tileY = tileY;
}
}