I am creating a game that is based in space. One computer runs a server which contains information about different objects such as spaceships and bullets. Whenver a ship or bullet moves on the server, it sends a message to all of the clients telling them the new x,y position of the object.
I was wondering how the proffessionals that make games like Generals, Red Alert, and Tiberian Sun are able to update all the clients so effeciently. My implementation is really laggy.
Does anyone have any ideas?
Here is some of the code:
new javax.swing.Timer(TICKRATE, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(time>=100)
time = 0;
time++;
tickShips(time);
tickProjectiles(time);
updateClients();
}
}).start();
public void updateClients(){
for(int i = 0; i<ships.size(); i++){
Ship current = ships.get(i);
Sender.sendToAll(current);
}
}
public static void sendToAll(Ship s){
sendToAll("moveship"+" "+s.ID+" "+((int)s.x)+" "+((int)s.y));
}