Closed RobLoach closed 5 years ago
Original PR was over at https://github.com/kodi-game/game.libretro/pull/39 . Cores that use this...
If it's needed by cores then it should probably be implemented. Might be a little late to get it in v18 though.
No rush! I've been hacking away trying to build stuff here too :+1:
I think the other PR was held up because I didn't understand how frame time is supposed to work. Do you have a better idea now? Should it be based on wall time or Kodi's clock?
Do you have a better idea now?
Yes, it makes more sense after some work with it. It's the difference in time in micro-seconds between each loop. Here's an example of RetroArch's run loop...
if (runloop_frame_time.callback) {
retro_time_t current = cpu_features_get_time_usec();
retro_time_t delta = current - runloop_frame_time_last;
runloop_frame_time_last = current;
runloop_frame_time.callback(delta);
}
cpu_features_get_time_usec()
retrieves the current time in microseconds. In the SDL world, it returns SDL_GetTicks() * 1000
.
Should it be based on wall time or Kodi's clock?
I believe either should work fine. It expects the delta in microseconds between the loop runs, so however game.libretro generates that should be okay.
In the original PR I used clock()
, which isn't correct. I'm unclear on what is the best platform-independent method for us to use to get the current micro-seconds. Do you know?
Do we have access to #include <chrono>
? Found this useful: https://codereview.stackexchange.com/a/132885
The functions of std::chrono available in C++11 should be available. Kodi can FF/RW, so Kodi's clock is not always equal to wall time.
Thanks for the merge! Looking forward to doing some testing on it. A good follow up would be investigating Chrono and seeing if the given method is the best way to determine microsecond diffs.
Close this or leave open for further improvements?
I think so. Thanks for all the feedback and help on getting this in.
The Frame Time Callback will help with a few cores... https://github.com/kodi-game/game.libretro/blob/master/src/libretro/LibretroEnvironment.cpp#L317-L326
Once set, it should be called every game loop, passing in the delta since the last time the loop was run. An example of how this can be run is over at SDLArch: https://github.com/heuripedes/sdlarch/blob/master/sdlarch.c#L774-L783