diff --git a/assets.mdesk b/assets.mdesk index afbfd15..07a15b9 100644 --- a/assets.mdesk +++ b/assets.mdesk @@ -150,5 +150,5 @@ } @level level0: { - filepath: "newsmalllevel.json", + filepath: "new_level.json", } diff --git a/better_assert.h b/better_assert.h new file mode 100644 index 0000000..a25c83a --- /dev/null +++ b/better_assert.h @@ -0,0 +1,15 @@ +#include + +static inline void assert_impl(bool cond, const char *expression) +{ + if(!cond) + { + fprintf(stderr, "Assertion failed: %s\n", expression); + __debugbreak(); + } +} +#ifdef assert +#undef assert +#endif + +#define assert(cond) assert_impl(cond, #cond) diff --git a/build_desktop_debug.bat b/build_desktop_debug.bat index 6a0bf98..7822789 100644 --- a/build_desktop_debug.bat +++ b/build_desktop_debug.bat @@ -3,14 +3,12 @@ @REM https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170 -FOR /F "tokens=*" %%g IN ('rg -g *.c -g !thirdparty break') do (SET VAR=%%g) - -echo %g% - -remedybg.exe stop-debugging +START /B remedybg.exe stop-debugging if "%1" == "codegen" ( call run_codegen.bat || goto :error ) else ( echo NOT RUNNING CODEGEN ) -cl /diagnostics:caret /DDEVTOOLS /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error +@REM cl /diagnostics:caret /DDEVTOOLS /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error +zig cc -DDEVTOOLS -Igen -Ithirdparty -lGdi32 -lD3D11 -lOle32 -gfull -gcodeview -o main.exe main.c || goto :error @REM cl /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error + remedybg.exe start-debugging goto :EOF diff --git a/codegen.c b/codegen.c index a2ab085..3d95417 100644 --- a/codegen.c +++ b/codegen.c @@ -1,6 +1,6 @@ #include #include -#include +#include "better_assert.h" #include "buff.h" diff --git a/main.c b/main.c index a814b33..83c5856 100644 --- a/main.c +++ b/main.c @@ -500,6 +500,7 @@ AABB centered_aabb(Vec2 at, Vec2 size) }; } + AABB entity_aabb_at(Entity *e, Vec2 at) { return centered_aabb(at, entity_aabb_size(e)); @@ -919,6 +920,7 @@ SwordToDamage entity_sword_to_do_damage(Entity *from, Overlapping o) #define WHITE ((Color) { 1.0f, 1.0f, 1.0f, 1.0f }) +#define GREY ((Color) { 0.4f, 0.4f, 0.4f, 1.0f }) #define BLACK ((Color) { 0.0f, 0.0f, 0.0f, 1.0f }) #define RED ((Color) { 1.0f, 0.0f, 0.0f, 1.0f }) #define PINK ((Color) { 1.0f, 0.0f, 1.0f, 1.0f }) @@ -1295,6 +1297,10 @@ Quad quad_aabb(AABB aabb) }; } +Quad centered_quad(Vec2 at, Vec2 size) +{ + return quad_aabb(centered_aabb(at, size)); +} // both segment_a and segment_b must be arrays of length 2 bool segments_overlapping(float *a_segment, float *b_segment) @@ -2264,6 +2270,9 @@ typedef struct bool interact; bool mouse_down; bool mouse_up; + + bool speak_shortcut; + bool give_shortcut; } PressedState; PressedState pressed = { 0 }; @@ -2689,14 +2698,14 @@ void frame(void) { Entity *targeting = player; - /* - G cost: distance from the current node to the start node - H cost: distance from the current node to the target node +/* +G cost: distance from the current node to the start node +H cost: distance from the current node to the target node - G H - SUM - F cost: G + H - */ +G H + SUM +F cost: G + H +*/ Vec2 to = targeting->pos; PathCache *cached = get_path_cache(elapsed_time, it->cached_path); @@ -3760,20 +3769,47 @@ void frame(void) ); float button_grid_width = button_size.x*num_buttons + space_btwn_buttons * (num_buttons - 1.0f); Vec2 cur_upper_left = V2((panel_aabb.upper_left.x + panel_aabb.lower_right.x) / 2.0f - button_grid_width / 2.0f, panel_aabb.lower_right.y + button_size.y); - if (imbutton_key(aabb_at(cur_upper_left, button_size), text_scale, "Speak", __LINE__, unwarped_dt, receiving_text_input)) + if(receiving_text_input && pressed.speak_shortcut) + { + end_text_input(""); + pressed.speak_shortcut = false; + } + if (imbutton_key(aabb_at(cur_upper_left, button_size), text_scale, "Speak", __LINE__, unwarped_dt, receiving_text_input) || pressed.speak_shortcut) { begin_text_input(); } - float button_grid_height = button_size.y; + + + // draw keyboard hint + { + Vec2 keyboard_helper_at = V2(cur_upper_left.x + button_size.x*0.5f, cur_upper_left.y - button_size.y*0.75f); + draw_quad((DrawParams){false, centered_quad(keyboard_helper_at, V2(40.0f, 40.0f)), IMG(image_white_square), blendalpha(GREY, 0.4f)}); + draw_centered_text((TextParams){false, false, "S", keyboard_helper_at, BLACK, 1.5f}); + } cur_upper_left.x += button_size.x + space_btwn_buttons; - if (imbutton(aabb_at(cur_upper_left, button_size), text_scale, "Give Item")) + + if(choosing_item_grid && pressed.give_shortcut) + { + pressed.give_shortcut = false; + choosing_item_grid = false; + } + + if (imbutton_key(aabb_at(cur_upper_left, button_size), text_scale, "Give Item", __LINE__, unwarped_dt, choosing_item_grid) || pressed.give_shortcut) { choosing_item_grid = true; } - const float dialog_text_scale = 1.0f; + + // draw keyboard hint + { + Vec2 keyboard_helper_at = V2(cur_upper_left.x + button_size.x*0.5f, cur_upper_left.y - button_size.y*0.75f); + draw_quad((DrawParams){false, centered_quad(keyboard_helper_at, V2(40.0f, 40.0f)), IMG(image_white_square), blendalpha(GREY, 0.4f)}); + draw_centered_text((TextParams){false, false, "G", keyboard_helper_at, BLACK, 1.5f}); + } + const float dialog_text_scale = 1.0f; + float button_grid_height = button_size.y; AABB dialog_text_aabb = panel_aabb; dialog_text_aabb.lower_right.y += button_grid_height + 20.0f; // a little bit of padding because the buttons go up float new_line_height = dialog_text_aabb.lower_right.y; @@ -4315,6 +4351,15 @@ void frame(void) pressed.interact = true; } + if (e->key_code == SAPP_KEYCODE_S) + { + pressed.speak_shortcut = true; + } + if (e->key_code == SAPP_KEYCODE_G) + { + pressed.give_shortcut = true; + } + if (e->key_code == SAPP_KEYCODE_LEFT_SHIFT) { learned_shift += 0.15f; diff --git a/makeprompt.h b/makeprompt.h index e302af9..e7814d3 100644 --- a/makeprompt.h +++ b/makeprompt.h @@ -2,7 +2,7 @@ #include "buff.h" #include "HandmadeMath.h" // vector types in entity struct definition -#include +#include "better_assert.h" #include #include #include // atoi diff --git a/profiling.h b/profiling.h index d98b6b1..37aa38a 100644 --- a/profiling.h +++ b/profiling.h @@ -8,7 +8,11 @@ #define DeferLoop(start, end) for (int _i_ = ((start), 0); _i_ == 0; _i_ += 1, (end)) #ifdef PROFILING +#if defined(__clang__) +#define THREADLOCAL _Thread_local +#else #define THREADLOCAL __declspec(thread) +#endif #define PROFILING_BUFFER_SIZE (1 * 1024 * 1024) #ifdef PROFILING_IMPL diff --git a/thirdparty/stb_ds.h b/thirdparty/stb_ds.h index e84c82d..974d080 100644 --- a/thirdparty/stb_ds.h +++ b/thirdparty/stb_ds.h @@ -1113,7 +1113,13 @@ static size_t stbds_siphash_bytes(void *p, size_t len, size_t seed) #endif } -size_t stbds_hash_bytes(void *p, size_t len, size_t seed) +#if defined(__clang__) +#define no_ubsan_overflow __attribute__((no_sanitize("undefined"))) +#else +#define no_ubsan_overflow +#endif + +size_t no_ubsan_overflow stbds_hash_bytes(void *p, size_t len, size_t seed) { #ifdef STBDS_SIPHASH_2_4 return stbds_siphash_bytes(p,len,seed);