I am trying to make a multiplayer game, and from what I understand from Source Multiplayer Networking - Valve Developer Community
I need to send the tick that the program is in so when the other gets the packet it knows when it happened.
psudo code
server:
private long startEpochTime = System.currentTimeMillis();
private float time = 0;
public final float tps = 64f;
public final float secondsPerTick = 1 / tps;
public int currentTick;
public void simpleUpdate(float tpf){
time += tpf;
currentTick = (int) (time / secondsPerTick);
//send message
}
public void connectionAdded(Server s, HostedConnection c){
SendMessage(startEpochTime);
}
client:
public float time = 0;
public int tick = 0;
public float tps = 64f;
public float secondsPerTick = (1 / tps);
messageRecieved(Message m){
time = System.currentTimeMillis() - m.getEpochTime();
}
public void simpleUpdate(float tpf){
time += tpf;
tick = (int) (time / secondsPerTick);
//send message
}
is this convoluted? I would think that there would be a default way to sync but I couldnt find it. Thanks for the help