Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

How to fix this timestep once and for all?

$
0
0
One of the biggest reasons why I haven't released my game is because of this annoying timestep issue I have. To be frank, this game was poorly planned, poorly coded, and was originally written as a small tech demo and a mini-game. Now it has evolved into a fully featured (and very messy code base of a) game. If you thought Lugaru was bad, Looptil is far worse! So what happens is that the delta is not really consistent. Sometimes enemies don't spawn fast enough because the delta isn't even consistent at 60fps, which is a big reason why the game is broken. static uint64_t last_time = 0; uint64_t current_time = time_get_time(); //( get_current_time() * 1000.0f ); int fps_limit = 60; float frame_time = float( current_time - last_time ); if( last_time != 0 ) This->m_delta_speed = frame_time / ( 1000.0f / 60.0f ); And this is my timing function: uint64_t time_get_time() { #ifdef _WINRT return GetTickCount64(); #endif #if __ANDROID__ /* TODO: Fix std::chrono for Android NDK */ uint64_t ms = 0; timeval tv; gettimeofday( &tv, NULL ); ms = tv.tv_sec * 1000; ms += tv.tv_usec / 1000; return ms; #else std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); std::chrono::system_clock::duration tp = now.time_since_epoch(); std::chrono::milliseconds ms = std::chrono::duration_cast<std::chrono::milliseconds>(tp); return (uint64_t) ms.count(); #endif } Now I know some of you will cringe when you see GetTickCount64(), but that's the only function that gives me reliable results on Windows 10 (UWP) ports, so that's staying. One more thing to note here, my game has a badly written game loop. It uses a switch statement, followed by draw_game_mode(), update_game_mode(), so I kinda screwed myself there. I tried changing it, but it broke the game completely, so I left it in it's messy state. Is it possible to simply just have a proper delta calculation function? Because it's adjusting itself based on the current frame time. This may not be the best of ideas, but it was something I whipped up because I needed to have this run okay when it goes down to 30fps without running half the speed. This works in general, but it's innacurate and causes problems. Any ideas? Thanks. Shogun EDIT: Feel free to ask anything in case I missed a vital detail. My lunch break is ending and it's time for me to go. Thanks.

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>