[SOLVED] Sim-eth-es which time source to use

I’m currently thinking of how to implement the count down timer. Let’s say my games duration is 4 minutes. Let’s further assume that I do not have a lobby room but you can enter a running game any time. If player 1 joins the game 30 seconds later, then his count down should start at 3:30.

I started to analyse how timing is done in sim-eth-es and I found that in the ModelViewState.class you have this

        // Retrieve the time source from the network connection
        // The time source will give us a time in recent history that we should be
        // viewing.  This currently defaults to -100 ms but could vary (someday) depending
        // on network connectivity.
        // For more information on this interpolation approach, see the Valve networking
        // articles at:
        // https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
        // https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization
        //this.timeSource = getState(ConnectionState.class).getRemoteTimeSource();
        // 
        // We now grab time from the TimeState which wraps the TimeSource to give
        // consistent timings over the whole frame
        this.timeState = getState(TimeState.class);

so you use the time from TimeState which is kind of a local time (the getRemoteTimeSource() is deactivated).

But for the HudLabelState.java

        // Retrieve the time source from the network connection
        // The time source will give us a time in recent history that we should be
        // viewing.  This currently defaults to -100 ms but could vary (someday) depending
        // on network connectivity.
        // For more information on this interpolation approach, see the Valve networking
        // articles at:
        // https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
        // https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization
        this.timeSource = getState(ConnectionState.class).getRemoteTimeSource();

the remote time source is used. And due the comment above, I somehow have the feeling this is the correct one and I also think maybe ModelViewState should also use the remote time source. Or what is the reasoning behind to have a local and a remote time source?

Back to my problem, so I would solve my problem by the player entity and attach the game state and the current time and remaining time. That means the remote time. So shouldn’t I use the remote time on the client or the local time. I guess as this count down is not super critical the local time source is ok. Are there any down sides using the remote time source?

1 Like

Ok I maybe found an answer

But it looks more like, with remote time source I have those warnings and with the local I do not. So this local time source seems like a hack to avoid another problem (which seems not to appear with the HudLabelState)?!

1 Like

TimeState should be using the remote time source. The point of TimeState is that it keeps a consistent time for the whole frame where as accessing the time source directly will give you a new time every time you ask.

See:

…which sets the time source that TimeState uses to the remote time state.

Time needs to be consistent everywhere if you want game time. That’s what RemoteTimeSource gives you.

In the linked thread, his problem was somehow that he was triggering the watchdog log statement about time not advancing. For some reason, in his case, subsequent calls to nanoTime() were returning the same value. By using the TimeState, nanoTime() is only called once per frame.

So on the client, it’s best to use TimeState… especially if you will be updating multiple time related things in the same frame. The reason the HudLabelState gets away with it is that it’s only showing one time related thing, I guess. Likely I just hadn’t implemented TimeState yet when I wrote that.

1 Like

Make sense. I missed to grep the usage of setTimeSource it seems. Thanks a lot.

1 Like