diff options
| author | Uneven Prankster <unevenprankster@protonmail.com> | 2023-08-12 13:32:39 -0300 |
|---|---|---|
| committer | Uneven Prankster <unevenprankster@protonmail.com> | 2023-08-12 13:32:39 -0300 |
| commit | 58c6022ebc22e88397f4ac85788b02dafa679b7d (patch) | |
| tree | f5069cb935b79ef71c04d0bec7742c28fcbed3b2 | |
| parent | e7379bed59af0f50126af61953bc4f10af04a4dd (diff) | |
Replaced checks with trap asserts, it's 2023, you can use gdb, we have technology
| -rw-r--r-- | src/config.h | 14 | ||||
| -rw-r--r-- | src/rumble.c | 7 | ||||
| -rw-r--r-- | src/shader_sys.c | 14 | ||||
| -rw-r--r-- | src/texture_sys.c | 13 |
4 files changed, 22 insertions, 26 deletions
diff --git a/src/config.h b/src/config.h index 18dc414..019ceaf 100644 --- a/src/config.h +++ b/src/config.h @@ -38,4 +38,16 @@ typedef struct{ typedef i32 b32; #define false 0 -#define true 1
\ No newline at end of file +#define true 1 + +#ifdef DEBUG +# if __GNUC__ +# define assert(c) if (!(c)) __builtin_trap() +# elif _MSC_VER +# define assert(c) if (!(c)) __debugbreak() +# else +# define assert(c) if (!(c)) *(volatile int *)0 = 0 +# endif +#else +# define assert(c) +#endif
\ No newline at end of file diff --git a/src/rumble.c b/src/rumble.c index 5e782b7..798b5ec 100644 --- a/src/rumble.c +++ b/src/rumble.c @@ -20,11 +20,8 @@ static fx32 timer = 0; void set_rumble(f32 duration, f32 strength) { - // Sanity check - if(strength > 1.0f) - strength = 1.0f; - else if(strength < 0.0f) - strength = 0.0f; + // If game code is surpassing this something is wrong!! + assert(strength >= 0.f && strength <= 1.f); XINPUT_VIBRATION state = {}; state.wLeftMotorSpeed = (unsigned)(strength * 65535.0f); diff --git a/src/shader_sys.c b/src/shader_sys.c index 2686f5f..d19e64b 100644 --- a/src/shader_sys.c +++ b/src/shader_sys.c @@ -111,18 +111,15 @@ i32 load_new_shader(const char* path) } } //TODO: Handle slots a bit better. - if(current_idx == BLANK_DEFAULT) - TRACELOG(LOG_WARNING, "Warning: No more empty shader slots.\n"); + assert(current_idx != BLANK_DEFAULT); return current_idx; } void set_active_shader(i32 idx) { - if(idx < 0 || idx >= MAX_SHADER_SIZE) - TRACELOG(LOG_WARNING,"Bounds check: Attempted to set shader at non-existent index %i.\n", idx); - else - BeginShaderMode(shader_slots[idx]); + assert(idx >= 0 && idx < MAX_SHADER_SIZE); + BeginShaderMode(shader_slots[idx]); } void update_shaders(void) @@ -148,10 +145,7 @@ void reset_active_shader(void) void unload_shader(i32 idx) { - if(idx < 0 || idx >= MAX_SHADER_SIZE){ - TRACELOG(LOG_WARNING,"Bounds check: Attempted to unload shader at non-existent index %i.\n", idx); - return; - } + assert(idx >= 0 && idx < MAX_SHADER_SIZE); UnloadShader(shader_slots[idx]); shader_slots[idx] = (Shader){0}; diff --git a/src/texture_sys.c b/src/texture_sys.c index 3254d75..cb7f631 100644 --- a/src/texture_sys.c +++ b/src/texture_sys.c @@ -31,18 +31,14 @@ i32 load_new_tex(const char* path) } } //TODO: Handle slots a bit better. - if(current_idx == BLANK_DEFAULT) - TRACELOG(LOG_WARNING, "Warning: No more empty texture slots.\n"); + assert(current_idx != BLANK_DEFAULT); return current_idx; } void draw_texture(i32 idx, i32 x, i32 y) { - if(idx < 0 || idx >= MAX_TEX_SIZE){ - TRACELOG(LOG_WARNING,"Bounds check: Attempted to draw texture from non-existent index %i.\n", idx); - return; - } + assert(idx >= 0 && idx < MAX_TEX_SIZE); DrawTexture(texture_slots[idx], x, y, WHITE); } @@ -64,10 +60,7 @@ void update_textures(void) void unload_tex(i32 idx) { - if(idx < 0 || idx >= MAX_TEX_SIZE){ - TRACELOG(LOG_WARNING,"Bounds check: Attempted to unload texture from non-existent index %i.\n", idx); - return; - } + assert(idx >= 0 && idx < MAX_TEX_SIZE); UnloadTexture(texture_slots[idx]); texture_slots[idx] = (Texture2D){0}; texture_modtimes[idx] = BLANK_DEFAULT; |
