From 962cec230a38f1b238c76d076d8d242f900a2a89 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Tue, 13 Aug 2024 00:40:03 -0400 Subject: [PATCH] Near 60fps --- scene.c | 15 ++++++++++++++- unigi/pullall.sh | 10 ++++++++++ unigi/unigi.headers | 2 +- unigi/unigi.platform.sdl1 | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 unigi/pullall.sh diff --git a/scene.c b/scene.c index 5654e97..b504ea2 100644 --- a/scene.c +++ b/scene.c @@ -17,6 +17,11 @@ #define DOLIGHTING #define FASTTRIS +// IDK you probably have to change this based on your display. +// Maybe there's a way to fix this? +#define UNIGIBITDEPTH 32 +#define TARGETFPS 60 + #define WIDTH 640 #define HEIGHT 480 #define ASPECT ((float)WIDTH / HEIGHT) @@ -125,7 +130,7 @@ int main(int argc, char **argv) { unigi_type_resolution res; res.width = WIDTH; res.height = HEIGHT; - res.depth = 32; // Not actually 32 bit + res.depth = UNIGIBITDEPTH; // Printing to screen needs tracking haloo3d_print_tracker t; @@ -143,7 +148,9 @@ int main(int argc, char **argv) { struct vec4 *vert_precalc; mallocordie(vert_precalc, sizeof(struct vec4) * H3D_OBJ_MAXVERTICES); clock_t begin, end; + // Measured in milliseconds float sumframe = 0, lastframe = 0; + float msperframe = 1000.0 / TARGETFPS; int totaldrawn = 0; eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts); @@ -229,8 +236,14 @@ int main(int argc, char **argv) { end = clock(); CALCTIME(lastframe, begin, end, sumframe); + + float waittime = msperframe - lastframe; + if (waittime > 0) { + unigi_time_sleep(waittime * unigi_time_clocks_per_s / 1000); + } } + // Free after loop for (int i = 0; i < NUMOBJECTS; i++) { haloo3d_obj_free(models + i); haloo3d_fb_free(textures + i); diff --git a/unigi/pullall.sh b/unigi/pullall.sh new file mode 100644 index 0000000..2d29ebc --- /dev/null +++ b/unigi/pullall.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e +cd unigi +git pull +cd ../unigi.headers +git pull +cd ../unigi.ext +git pull +cd ../unigi.platform.sdl1 +git pull diff --git a/unigi/unigi.headers b/unigi/unigi.headers index 41e4f12..196b306 160000 --- a/unigi/unigi.headers +++ b/unigi/unigi.headers @@ -1 +1 @@ -Subproject commit 41e4f122d1910927760a08b6bbc9b645bb11f8f6 +Subproject commit 196b30670bca3829fc29aa37666cedc1a973958c diff --git a/unigi/unigi.platform.sdl1 b/unigi/unigi.platform.sdl1 index ab5f142..e407020 160000 --- a/unigi/unigi.platform.sdl1 +++ b/unigi/unigi.platform.sdl1 @@ -1 +1 @@ -Subproject commit ab5f142e3413c5e9850049e49ae60bc3ed3d1b71 +Subproject commit e407020c2118d7ad2f4d43eca5214b6360a0b7cc