pp::Core::GetTimeTicks() getting out of sync with pp::InputEvent::GetTimeStamp() on system sleep

StackOverflow https://stackoverflow.com/questions/22688934

  •  22-06-2023
  •  | 
  •  

I'm attempting to use "tick time" to keep track of time in my PNaCl game, because game time should not be affected by the user adjusting his system clock.

I would like to use both pp::Core::GetTimeTicks() and pp::InputEvent::GetTimeStamp() to run my game simulation. The logic goes like this: When an input event occurs, run the simulation until the game time matches pp::InputEvent::GetTimeStamp() of that event. When the render completion callback happens, run the simulation until the game time matches pp::Core::GetTimeTicks().

This works well to begin with, and this usecase seems to be supported as far as I can understand the documentation, from pp::Core::GetTimeTicks():

This clock is used by the browser when passing some event times to the module (for example, using the PP_InputEvent::time_stamp_seconds field).


However, when I put the computer to sleep and open it again, these two clocks seem to be out of sync by the amount of time that the computer was sleeping. pp::Core::GetTimeTicks() seems to have stopped running while the system was sleeping, while pp::InputEvent::GetTimeStamp() seems to have been running. The input events are timestamped ahead of the core clock by the amount of time that the system was sleeping.

This defeats using both clocks for time keeping. A workaround is to use the core clock when running simulation in response to an input event, but this may cause higher latency between key presses and action on the screen. Another workaround is to simply not run simulation in response to input events. Nevertheless, I would like to get to the bottom of this conundrum.

Is this a bug in the implementation? Is it a bug in the documentation, which seems to say that these times should be in sync? Or am I reading the documentation wrong?


I'm experiencing this on Chrome 33.0.1750.152 (Official Build 256984) for Linux.

有帮助吗?

解决方案

That looks like a bug. InputEvent returns a PP_TimeTicks. Time ticks should have the behavior you see via Core::GetTimeTicks().

But the input events are returning you wall clock time. This is actually correct as a pepper input event should match a DOM event, and a DOM input event is specified as time since 1970 (wall clock time).

The the behavior is right but the return type for GetTimeStamp should be PP_Time instead. I'll file this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top