diff --git a/Makefile b/Makefile index 6bea4a1..3cbbdaf 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,11 @@ WEB_HEAP_SIZE := 335544320 WEB_STACK_SIZE := 196608 WEB_SHELL := src/shell.html -COMPILER_FLAGS := -std=c++17 -Wno-enum-compare -O3 -g -flto -msse4.2 -mavx +DEBUG_MODE := no + +COMPILER_FLAGS := -std=c++17 -Wno-enum-compare -O3 -flto -msse4.2 -mavx COMPILER_FLAGS += -DRPROF_IMPLEMENTATION COMPILER_FLAGS += -DRAYGUI_IMPLEMENTATION -# COMPILER_FLAGS += -DRLGL_IMPLEMENTATION LINKER_FLAGS := -lraylib # SOURCES := $(wildcard src/*.cpp) @@ -25,6 +26,12 @@ SOURCES := src/main.cpp COMPILER_FLAGS += -I$(SUBMODULES_PATH)/raygui/src/ +ifeq ($(DEBUG_MODE), yes) + COMPILER_FLAGS += -DDEBUG -g +else + COMPILER_FLAGS += -DRPROF_STUB_OUT +endif + # ----------------- Prepare variables for targets ------------------ EXT := diff --git a/compile_flags.txt b/compile_flags.txt index 954dc52..5947fa1 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -4,3 +4,4 @@ -DRLGL_IMPLEMENTATION -DRPROF_IMPLEMENTATION -DRAYGUI_IMPLEMENTATION +-DDEBUG diff --git a/src/boid-playground.hpp b/src/boid-playground.hpp index 21bdecb..e73dbab 100644 --- a/src/boid-playground.hpp +++ b/src/boid-playground.hpp @@ -9,7 +9,12 @@ #define ARRAY_LEN(arr) (sizeof(arr)/sizeof(arr[0])) #define LogTrace(...) TraceLog(LOG_TRACE, __VA_ARGS__) + +#ifdef DEBUG #define DEBUG_ASSERT(...) assert(__VA_ARGS__) +#else +#define DEBUG_ASSERT(...) +#endif typedef uint16_t uboid_t; #define MAX_BOIDS (1 << (sizeof(uboid_t)*8)) diff --git a/src/main.cpp b/src/main.cpp index 68d2922..f53817f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include #endif -// #define RPROF_STUB_OUT // #define RPROF_ONLY_TOTAL_TIME #include "rprof.h" @@ -33,8 +32,8 @@ void UpdateDrawFrame(); static void profiling_test(); int main() { - profiling_test(); - return 0; + // profiling_test(); + // return 0; SetTraceLogLevel(LOG_TRACE); diff --git a/src/world.cpp b/src/world.cpp index fb13773..a18c6d3 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -170,6 +170,11 @@ static void chunkgrid_init(MemoryArena *arena, ChunkGrid *grid, int width, int h } static int g_prof_interactions = 0; +#ifdef DEBUG +#define INCREMENT_INTERACTIONS() g_prof_interactions++; +#else +#define INCREMENT_INTERACTIONS() +#endif static int nearest_multiple(int num, int divisor) { return (num / divisor + (num % divisor > 0 ? 1 : 0)) * divisor; @@ -181,7 +186,7 @@ struct boid_pair { }; #ifdef SIMD256 -#define GET_F32_CHUNK_FROM_BOIDS(i, SIDE, FIELD) \ +#define GET_F32_CHUNK_FROM_BOIDS(i, SIDE, FIELD) \ _mm256_set_ps( \ boids[b2b_cmps[8*i+7].SIDE].FIELD, \ boids[b2b_cmps[8*i+6].SIDE].FIELD, \ @@ -193,7 +198,7 @@ struct boid_pair { boids[b2b_cmps[8*i+0].SIDE].FIELD \ ) #else -#define GET_F32_CHUNK_FROM_BOIDS(i, SIDE, FIELD) \ +#define GET_F32_CHUNK_FROM_BOIDS(i, SIDE, FIELD) \ _mm_set_ps( \ boids[b2b_cmps[4*i+3].SIDE].FIELD, \ boids[b2b_cmps[4*i+2].SIDE].FIELD, \ @@ -267,11 +272,11 @@ static void world_calc_distances_and_angles(World *world, BoidList *local_boids, uboid_t to_boid = b2b_cmps[cmp_idx].to; if (do_append_mask1_f32[j]) { boid_list_append(&world->frame_arena, &local_boids[from_boid], to_boid); - g_prof_interactions++; + INCREMENT_INTERACTIONS(); } if (do_append_mask2_f32[j]) { boid_list_append(&world->frame_arena, &local_boids[to_boid], from_boid); - g_prof_interactions++; + INCREMENT_INTERACTIONS(); } } } @@ -320,7 +325,7 @@ static void world_compute_local_boids(BoidList *local_boids, World *world, Chunk for (int j = 0; j < to_boids_count; j++) { // TODO: - // DEBUG_ASSERT(b2b_cmps_count < b2b_capacity-1); + DEBUG_ASSERT(b2b_cmps_count < b2b_capacity-1); b2b_cmps[b2b_cmps_count++] = { .from = from_boid, .to = to_boids[j] @@ -343,7 +348,7 @@ static void world_compute_local_boids(BoidList *local_boids, World *world, Chunk for (int i = 0; i < chunk->count; i++) { for (int j = 0; j < neighbour_chunk->count; j++) { // TODO: - // DEBUG_ASSERT(b2b_cmps_count < b2b_capacity-1); + DEBUG_ASSERT(b2b_cmps_count < b2b_capacity-1); b2b_cmps[b2b_cmps_count++] = { .from = chunk_boids[i], .to = neighbour_boids[j]