From bb16c32bde58cba70e4877aa2d3ebd04332eb575 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Tue, 4 Jan 2022 13:35:02 +0100 Subject: linux compile and imgs --- timing/timing.cpp | 86 +++++++++++++++++++++++++++---------------------------- timing/timing.h | 46 ++++++++++++++--------------- 2 files changed, 66 insertions(+), 66 deletions(-) (limited to 'timing') diff --git a/timing/timing.cpp b/timing/timing.cpp index 37c5f40..38c9c29 100644 --- a/timing/timing.cpp +++ b/timing/timing.cpp @@ -1,44 +1,44 @@ -#include "timing.h" - -timing_sdl::timing_sdl (double fps) { - frame_time = 1/fps; - last_time = SDL_GetTicks(); - frame_counter = 0; - tot_time = 0; - unprocessed_time = 0; - frames = 0; - render = false; -} - -void timing_sdl::process () { - render = false; - - double startTime = SDL_GetTicks(); - double passedTime = (startTime - last_time)/1000; - last_time = startTime; - - unprocessed_time += passedTime; - frame_counter += passedTime; - tot_time += passedTime; - - if (frame_counter >= 1.0) { - //printf("FPS: %i | %f ms\n", frames, 1000.0 / ((double)frames)); - frames = 0; - frame_counter = 0; - } -} - -bool timing_sdl::check_process () { - if (unprocessed_time > frame_time) { - render = true; - unprocessed_time -= frame_time; - return true; - } else { - return false; - } -} - -bool timing_sdl::check_render () { - if (render) { frames ++; } - return render; +#include "timing.h" + +timing_sdl::timing_sdl (double fps) { + frame_time = 1/fps; + last_time = SDL_GetTicks(); + frame_counter = 0; + tot_time = 0; + unprocessed_time = 0; + frames = 0; + render = false; +} + +void timing_sdl::process () { + render = false; + + double startTime = SDL_GetTicks(); + double passedTime = (startTime - last_time)/1000; + last_time = startTime; + + unprocessed_time += passedTime; + frame_counter += passedTime; + tot_time += passedTime; + + if (frame_counter >= 1.0) { + //printf("FPS: %i | %f ms\n", frames, 1000.0 / ((double)frames)); + frames = 0; + frame_counter = 0; + } +} + +bool timing_sdl::check_process () { + if (unprocessed_time > frame_time) { + render = true; + unprocessed_time -= frame_time; + return true; + } else { + return false; + } +} + +bool timing_sdl::check_render () { + if (render) { frames ++; } + return render; } \ No newline at end of file diff --git a/timing/timing.h b/timing/timing.h index f420582..f036abc 100644 --- a/timing/timing.h +++ b/timing/timing.h @@ -1,24 +1,24 @@ -#ifndef TIMING_H -#define TIMING_H - -#define SDL_MAIN_HANDLED -#include - -class timing_sdl { - public: - timing_sdl(double fps); - void process(); - bool check_process(); - bool check_render(); - - private: - double frame_time; - double last_time; - double frame_counter; - double tot_time; - double unprocessed_time; - int frames; - bool render; -}; - +#ifndef TIMING_H +#define TIMING_H + +#define SDL_MAIN_HANDLED +#include + +class timing_sdl { + public: + timing_sdl(double fps); + void process(); + bool check_process(); + bool check_render(); + + private: + double frame_time; + double last_time; + double frame_counter; + double tot_time; + double unprocessed_time; + int frames; + bool render; +}; + #endif \ No newline at end of file -- cgit v1.2.3-54-g00ecf