The variables are not the same for some reason.
Here is where I receive the object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| 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:
1 2 3 4 5 6 7
| if(msg instanceof ClientMoveMessage){ System.out.println("Client move msg"); ClientMoveMessage msg2 = (ClientMoveMessage) msg; cThread1.getPlayerModel().setTilePos(msg2.tileX, msg2.tileY); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| 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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| 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) { e.printStackTrace(); } } } } |
1 2 3 4
| public class ServerPlayerStateMessage implements Serializable { public PlayerModel[] players; } |
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class PlayerModel implements Serializable { public int clientID; public int tileX; public int tileY; public void setTilePos(int tileX, int tileY){ this.tileX = tileX; this.tileY = tileY; } } |