From 332771104f8afe14cccf6c36dc0aadd991f0e2b2 Mon Sep 17 00:00:00 2001 From: duarteapcoelho Date: Thu, 8 Dec 2022 16:20:43 +0000 Subject: [PATCH] gint: Add libprof for more accurate FPS --- README.md | 1 + gint/Makefile | 2 +- src/main.cpp | 2 ++ src/time-gint.cpp | 15 +++++++++++++-- src/time-prizm.cpp | 2 ++ src/time-sdl.cpp | 2 ++ src/time.h | 1 + 7 files changed, 22 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 06fec6e..07dafb5 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ This version supports multiplayer, but it's slower than the gint version. This version doesn't support multiplayer, but it runs faster and doesn't have a border. #### Linux - Install gint ([https://gitea.planet-casio.com/Lephenixnoir/gint](https://gitea.planet-casio.com/Lephenixnoir/gint)) +- Install libprof ([https://gitea.planet-casio.com/Lephenixnoir/libprof](https://gitea.planet-casio.com/Lephenixnoir/libprof)) - Run `make gint` ## Technical information diff --git a/gint/Makefile b/gint/Makefile index e957186..f481dcd 100644 --- a/gint/Makefile +++ b/gint/Makefile @@ -1,7 +1,7 @@ CC = sh-elf-g++ CFLAGS += -Wall -Wextra -Ofast -funroll-loops -DGINT CFLAGS += -DFXCG50 -DTARGET_FXCG50 -m4-nofpu -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -LDFLAGS = -m4-nofpu -mb -nostdlib -Wl,--no-warn-rwx-segments -T fxcg50.ld -lgint-cg -lc -lgcc -lgint-cg +LDFLAGS = -m4-nofpu -mb -nostdlib -Wl,--no-warn-rwx-segments -T fxcg50.ld -lgint-cg -lc -lgcc -lgint-cg -lprof-cg INCLUDES = diff --git a/src/main.cpp b/src/main.cpp index 53df0ec..e5cddcb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,8 @@ int main(){ Track::coneMesh = {22, cone_triangles}; Track::simpleConeMesh = {2, simpleConeTriangles}; + Time::init(); + Display::init(); Display::clear(newColor(70, 180, 220)); Display::show(); diff --git a/src/time-gint.cpp b/src/time-gint.cpp index 339c59d..d7e1550 100644 --- a/src/time-gint.cpp +++ b/src/time-gint.cpp @@ -1,12 +1,23 @@ #ifdef GINT #include "time.h" #include +#include + namespace Time { - void init(){} + prof_t prof; + void init(){ + prof_init(); + prof = prof_make(); + } void update(){ + prof_leave(prof); + const float lastTime = time; time = rtc_ticks(); - delta = time - lastTime; + delta = prof_time(prof) / 1000.0f / (1000.0f / 128.0f); + + prof = prof_make(); + prof_enter(prof); } }; #endif diff --git a/src/time-prizm.cpp b/src/time-prizm.cpp index 07891cc..644f25d 100644 --- a/src/time-prizm.cpp +++ b/src/time-prizm.cpp @@ -3,6 +3,8 @@ #include namespace Time { + void init(){ + } void update(){ const float lastTime = time; time = RTC_GetTicks(); diff --git a/src/time-sdl.cpp b/src/time-sdl.cpp index 75fe880..3d9ff5e 100644 --- a/src/time-sdl.cpp +++ b/src/time-sdl.cpp @@ -3,6 +3,8 @@ #include namespace Time { + void init(){ + } void update(){ const float lastTime = time; time = ((float)(SDL_GetTicks()) / (1000.0/128.0)); diff --git a/src/time.h b/src/time.h index 8b1a76f..ea853e1 100644 --- a/src/time.h +++ b/src/time.h @@ -3,5 +3,6 @@ namespace Time { extern float time; extern float delta; + void init(); void update(); };