diff options
| -rwxr-xr-x | Makefile | 4 | ||||
| -rw-r--r-- | source/main.c | 50 |
2 files changed, 48 insertions, 6 deletions
@@ -31,9 +31,9 @@ all: EUROPA\|XI clean: rm -f $(OBJECT) EUROPA\|XI -EUROPA|XI: $(HEADER) | $(OBJECT) +EUROPA|XI: $(OBJECT) @echo "LD $@" - @${LINK.c} -o "$@" $| library/libraylib.amd64.a $(LDFLAGS) + @${LINK.c} -o "$@" $+ library/libraylib.amd64.a $(LDFLAGS) library/libraylib.amd64.a: @rm -rf /tmp/raylib-5.5_linux_amd64 diff --git a/source/main.c b/source/main.c index 552b906..d1cb359 100644 --- a/source/main.c +++ b/source/main.c @@ -1,12 +1,18 @@ +#include <stdio.h> + +#include <stdint.h> +#include <time.h> +#include <unistd.h> + #include <raylib.h> +#include <rlgl.h> int main (int count, char ** arguments) { /* :config */ int horizontal = 1920, vertical = 1080; - /* this idented (DENTED) style is autistic and dumb but I like it visually */ - { + { /* this idented (DENTED) style is autistic and dumb but I like it visually */ SetConfigFlags(FLAG_WINDOW_RESIZABLE); /* tell raylib to shut up */ /* SetTraceLogLevel(LOG_NONE); */ @@ -15,9 +21,45 @@ int main (int count, char ** arguments) InitAudioDevice(); SetWindowPosition(0, 0); } - /* loop to end all loops */ - { + /* :todo ping me I'll update this to a u/f seperated game loop */ + { /* loop to end all loops */ + uint64_t frame = 0; + /* :config */ + float fps = 30; + double wait = wait = 1.0 / fps, Δ = wait; + struct timespec start, end; + clock_gettime(CLOCK_MONOTONIC, &start); + ClearWindowState(FLAG_WINDOW_HIDDEN); + while (1) { + if (Δ > wait) { + clock_gettime(CLOCK_MONOTONIC, &start); + { /* update */ + ++frame; + PollInputEvents(); + /* physical keys */ + switch (GetKeyPressed()) { + case KEY_Q: goto stop; + case KEY_ESCAPE: goto stop; + } + /* routed keys */ + /* switch (GetCharPressed()) { case 'q': goto stop; } */ + } + { /* draw */ + BeginDrawing(); + ClearBackground(BLACK); + DrawText(TextFormat("Delta (Δ): %d", Δ), 10, 10, 20, WHITE); + rlDrawRenderBatchActive(); + SwapScreenBuffer(); + } + } + clock_gettime(CLOCK_MONOTONIC, &end); + Δ = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9; + if (Δ < wait) { + double should = -(Δ - wait); + if (should > 0) { usleep(1e6 * should); } + } + } } stop: SetWindowState(FLAG_WINDOW_HIDDEN); |
