aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Williams2026-01-31 15:06:23 +0000
committerEmil Williams2026-01-31 15:06:23 +0000
commita1a82802c8abb4ec296cd271cc87df1b6a67ebea (patch)
tree86b72c8288c368b0ee54455756fd223fefac8bb8
parent9efa9a51eda66f212847ce3e5576a8d3078ca899 (diff)
downloadEUROPAXI-a1a82802c8abb4ec296cd271cc87df1b6a67ebea.tar.xz
EUROPAXI-a1a82802c8abb4ec296cd271cc87df1b6a67ebea.tar.zst
Game loop + fix to Makefile
-rwxr-xr-xMakefile4
-rw-r--r--source/main.c50
2 files changed, 48 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 90e1138..dd1c603 100755
--- a/Makefile
+++ b/Makefile
@@ -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);