From e812b3660457bee39cbc0b1fe3d2f37262a40009 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 18 May 2025 21:17:07 +0100 Subject: [PATCH] Update test --- Makefile | 2 +- common.h | 2 +- dod.c | 29 +++++++++++------------------ no_dod.c | 16 ++++++++-------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index f10ca63..84387c0 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC = clang CFLAGS = -g -O3 -Iraylib/include -Iwapp/src -LDFLAGS = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib -lprofiler +LDFLAGS = '-Wl,-rpath,$$ORIGIN/raylib/lib' -Lraylib/lib -lraylib .PHONY: all raylib no_dod dod diff --git a/common.h b/common.h index 5eb00b0..54c89f1 100644 --- a/common.h +++ b/common.h @@ -10,7 +10,7 @@ #define BG_COLOR (Color){.r = 0xea, .g = 0xf2, .b = 0xe3, .a = 0xff} #define FG_COLOR (Color){.r = 0x42, .g = 0x4C, .b = 0x55, .a = 0xff} #define ZONE_COLOR (Color){.r = 0xb4, .g = 0x65, .b = 0x4a, .a = 0xff} -#define WANDERER_COUNT 300000 +#define WANDERER_COUNT 500000 #define ZONE_COUNT 5 #define WANDERER_SLOWDOWN_FACTOR 0.5f #define WANDERER_SPEEDUP_FACTOR 2.0f diff --git a/dod.c b/dod.c index ae7a58a..23ee751 100644 --- a/dod.c +++ b/dod.c @@ -61,8 +61,7 @@ void init_scale_wanderer(Scale *scale, XOR256State *state); void init_scale_zone(Scale *scale, XOR256State *state); void init_velocity(Velocity *velocity, XOR256State *state); void zero_velocity(Velocity *velocity, XOR256State *state); -void check_collisions(u8 *tags, Rect *rects, u64 count); -void update_positions(const u8 *tags, Rect *rects, Velocity *velocities, u64 count); +void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count); void render_entities(const u8 *tags, const Rect *rects, u64 count); u64 collides(const Rect *rect, const Rect *collider); f32 get_random_float(XOR256State *state); @@ -70,7 +69,7 @@ f32 get_random_float(XOR256State *state); int main(void) { SetTraceLogLevel(LOG_NONE); InitWindow(WIDTH, HEIGHT, "DOD test"); - SetTargetFPS(120); + // SetTargetFPS(120); Allocator arena = wapp_mem_arena_allocator_init(MB(20)); assert(!wapp_mem_allocator_invalid(&arena)); @@ -100,15 +99,13 @@ int main(void) { break; } - check_collisions(manager.tags, manager.rects, manager.count); - update_positions(manager.tags, manager.rects, manager.velocities, manager.count); BeginDrawing(); ClearBackground(BG_COLOR); - render_entities(manager.tags, manager.rects, manager.count); + // render_entities(manager.tags, manager.rects, manager.count); DrawFPS(10, 10); @@ -170,11 +167,17 @@ void zero_velocity(Velocity *velocity, XOR256State *state) { velocity->y = 0.0f; } -void update_positions(const u8 *tags, Rect *rects, Velocity *velocities, u64 count) { +void update_positions(u8 *tags, Rect *rects, Velocity *velocities, u64 count) { u8 index = 0; f32 multipliers[2] = {1.0f, 0.5f}; + persistent u64 inside_zone_mask = 0x7; + + for (u64 i = ZONE_COUNT; i < count; ++i) { + tags[i] &= inside_zone_mask; + for (u64 j = 0; j < ZONE_COUNT; ++j) { + tags[i] |= collides(&rects[i], &rects[j]) << 3; + } - for (u64 i = 0; i < count; ++i) { index = (tags[i] & ENTITY_TAG_INSIDE_ZONE) == ENTITY_TAG_INSIDE_ZONE; rects[i].position.x += velocities[i].x * multipliers[index]; @@ -195,16 +198,6 @@ void update_positions(const u8 *tags, Rect *rects, Velocity *velocities, u64 cou } } -void check_collisions(u8 *tags, Rect *rects, u64 count) { - persistent u64 inside_zone_mask = 0x7; - for (u64 i = ZONE_COUNT; i < count; ++i) { - tags[i] &= inside_zone_mask; - for (u64 j = 0; j < ZONE_COUNT; ++j) { - tags[i] |= collides(&rects[i], &rects[j]) << 3; - } - } -} - void render_entities(const u8 *tags, const Rect *rects, u64 count) { persistent RaylibDrawRectFunc renderers[2] = {DrawRectangle, DrawRectangleLines}; persistent Color colors[2] = {FG_COLOR, ZONE_COLOR}; diff --git a/no_dod.c b/no_dod.c index e5daf1f..c00560a 100644 --- a/no_dod.c +++ b/no_dod.c @@ -51,7 +51,7 @@ f32 get_random_float(XOR256State *state); int main(void) { SetTraceLogLevel(LOG_NONE); InitWindow(WIDTH, HEIGHT, "No-DOD test"); - SetTargetFPS(120); + // SetTargetFPS(120); Allocator arena = wapp_mem_arena_allocator_init(MB(20)); XOR256State state = wapp_prng_xorshift_init_state(); @@ -85,13 +85,13 @@ int main(void) { ClearBackground(BG_COLOR); - for (u64 i = 0; i < ZONE_COUNT; ++i) { - render_slow_zone(&(zones[i])); - } - - for (u64 i = 0; i < WANDERER_COUNT; ++i) { - render_wanderer(&(wanderers[i])); - } + // for (u64 i = 0; i < ZONE_COUNT; ++i) { + // render_slow_zone(&(zones[i])); + // } + // + // for (u64 i = 0; i < WANDERER_COUNT; ++i) { + // render_wanderer(&(wanderers[i])); + // } DrawFPS(10, 10);