diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.cpp b/src/main.cpp index 34cbcb4..5155f60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +#include <chrono> +#include <thread> + #include "camera.hpp" #include "candy_gear.hpp" #include "core.hpp" @@ -33,8 +36,10 @@ static void handle_error(mrb_state *mrb) int main(int argc, char *argv[]) { + using namespace std::chrono; + using namespace std::this_thread; + SDL_Event event; - Uint32 frame_start; // Random numbers random_number_generator.seed(random_seed()); @@ -79,7 +84,7 @@ int main(int argc, char *argv[]) if (cg_core.mrb->exc) handle_error(cg_core.mrb); } - frame_start = SDL_GetTicks(); + auto frame_start = steady_clock::now(); // Game main loop. while(!cg_core.quit_game) @@ -118,14 +123,12 @@ int main(int argc, char *argv[]) // Timer { - Uint32 frame_stop, frame_duration; - - frame_stop = SDL_GetTicks(); - frame_duration = frame_stop - frame_start; + auto frame_stop = steady_clock::now(); + auto frame_duration = frame_stop - frame_start; // If frame take less time than maximum allowed. - if(cg_core.max_frame_duration_ms > frame_duration) - SDL_Delay(cg_core.max_frame_duration_ms - frame_duration); + if(cg_core.max_frame_duration > frame_duration) + sleep_for(cg_core.max_frame_duration - frame_duration); frame_start = frame_stop; } |