From 92fed87080a04bef38e2c14c8bc4ac9065a09f2c Mon Sep 17 00:00:00 2001 From: snit Date: Sun, 27 Oct 2024 23:48:51 -0500 Subject: [PATCH] just for fun: a test game loop that cycles world width/height from 0-100 once a second; client prints them too btw --- client/src/render/render.c | 2 ++ server/src/main.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/client/src/render/render.c b/client/src/render/render.c index 7fc2181..8212f74 100644 --- a/client/src/render/render.c +++ b/client/src/render/render.c @@ -6,6 +6,8 @@ void render_world(struct world_t const *world) { + printf("%zu %zu\n", world->height, world->width); + for (size_t i = 0; i < MAX_ENTITIES; i++) { struct entity_t const *const entity = &world->entities[i]; struct entity_registrant_t const *const registrant = diff --git a/server/src/main.c b/server/src/main.c index db985ba..94894e2 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -28,9 +28,19 @@ static enum error_t simulation_thread_body(struct game_data_t *data) { assert(data != NULL); // TODO: An actual game loop lol - printf("Hello, world!\n"); + while (true) { + if (pthread_mutex_lock(&data->world_lock) != 0) goto error; + data->world.width = (data->world.width + 1) % 100; + data->world.height = (data->world.height + 1) % 100; + if (pthread_mutex_unlock(&data->world_lock) != 0) goto error; + + sleep(1); + } return ERR_OK; + +error: + return ERR_MUTEX; }