NEVER EVER USE CONTINUE and better debug drawing

main
Cameron Murphy Reikes 2 years ago
parent c323c5789f
commit 4f5979405a

@ -0,0 +1,102 @@
{ "compressionlevel":-1,
"height":9,
"infinite":false,
"layers":[
{
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1],
"height":9,
"id":1,
"name":"Base",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":9,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":9,
"id":3,
"name":"Detail",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":9,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 60, 60, 0, 0, 0, 0, 0,
0, 0, 0, 60, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0],
"height":9,
"id":4,
"name":"Collideable",
"opacity":0.9,
"type":"tilelayer",
"visible":true,
"width":9,
"x":0,
"y":0
},
{
"draworder":"topdown",
"id":2,
"name":"objects",
"objects":[
{
"class":"",
"height":32,
"id":2,
"name":"PLAYER",
"rotation":0,
"visible":true,
"width":32,
"x":72.4621212121228,
"y":85.727272727277
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":17,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.9.2",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"Main.tsx"
}],
"tilewidth":32,
"type":"map",
"version":"1.9",
"width":9
}

@ -2,8 +2,13 @@
@REM https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170 @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 remedybg.exe stop-debugging
call run_codegen.bat || goto :error if "%1" == "codegen" ( call run_codegen.bat || goto :error )
cl /diagnostics:caret /DDEVTOOLS /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error cl /diagnostics:caret /DDEVTOOLS /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error
@REM cl /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error @REM cl /Igen /Ithirdparty /W3 /Zi /WX main.c || goto :error
remedybg.exe start-debugging remedybg.exe start-debugging

@ -906,10 +906,12 @@ SwordToDamage entity_sword_to_do_damage(Entity *from, Overlapping o)
typedef Vec4 Color; typedef Vec4 Color;
#define WHITE (Color){1.0f, 1.0f, 1.0f, 1.0f} #define WHITE ((Color){1.0f, 1.0f, 1.0f, 1.0f})
#define BLACK (Color){0.0f, 0.0f, 0.0f, 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 RED ((Color){1.0f, 0.0f, 0.0f, 1.0f})
#define GREEN (Color){0.0f, 1.0f, 0.0f, 1.0f} #define PINK ((Color){1.0f, 0.0f, 1.0f, 1.0f})
#define BLUE ((Color){0.0f, 0.0f, 1.0f, 1.0f})
#define GREEN ((Color){0.0f, 1.0f, 0.0f, 1.0f})
Color colhex(uint32_t hex) Color colhex(uint32_t hex)
{ {
@ -1607,11 +1609,15 @@ bool profiling;
#endif #endif
#endif #endif
Color debug_color = {1.0f, 0.0f, 0.0f, 0.0f};
#define dbgcol(col) DeferLoop(debug_color = col, debug_color = RED)
void dbgsquare(Vec2 at) void dbgsquare(Vec2 at)
{ {
#ifdef DEVTOOLS #ifdef DEVTOOLS
if(!show_devtools) return; if(!show_devtools) return;
colorquad(true, quad_centered(at, V2(10.0, 10.0)), RED); colorquad(true, quad_centered(at, V2(10.0, 10.0)), debug_color);
#else #else
(void)at; (void)at;
#endif #endif
@ -1621,7 +1627,7 @@ void dbgline(Vec2 from, Vec2 to)
{ {
#ifdef DEVTOOLS #ifdef DEVTOOLS
if(!show_devtools) return; if(!show_devtools) return;
line(from, to, 0.5f, RED); line(from, to, 0.5f, debug_color);
#else #else
(void)from; (void)from;
(void)to; (void)to;
@ -1640,7 +1646,7 @@ void dbgrect(AABB rect)
#ifdef DEVTOOLS #ifdef DEVTOOLS
if(!show_devtools) return; if(!show_devtools) return;
const float line_width = 0.5; const float line_width = 0.5;
const Color col = RED; Color col = debug_color;
Quad q = quad_aabb(rect); Quad q = quad_aabb(rect);
line(q.ul, q.ur, line_width, col); line(q.ul, q.ur, line_width, col);
line(q.ur, q.lr, line_width, col); line(q.ur, q.lr, line_width, col);
@ -1912,7 +1918,6 @@ Vec2 move_and_slide(MoveSlideParams p)
assert(collision_aabb_size.x > 0.0f); assert(collision_aabb_size.x > 0.0f);
assert(collision_aabb_size.y > 0.0f); assert(collision_aabb_size.y > 0.0f);
AABB at_new = centered_aabb(new_pos, collision_aabb_size); AABB at_new = centered_aabb(new_pos, collision_aabb_size);
dbgrect(at_new);
BUFF(AABB, 256) to_check = {0}; BUFF(AABB, 256) to_check = {0};
// add tilemap boxes // add tilemap boxes
@ -1930,8 +1935,10 @@ Vec2 move_and_slide(MoveSlideParams p)
TileCoord tilecoord_to_check = world_to_tilecoord(*it); TileCoord tilecoord_to_check = world_to_tilecoord(*it);
if(is_tile_solid(get_tile_layer(&level_level0, 2, tilecoord_to_check))) if(is_tile_solid(get_tile_layer(&level_level0, 2, tilecoord_to_check)))
{
BUFF_APPEND(&to_check, tile_aabb(tilecoord_to_check)); AABB t = tile_aabb(tilecoord_to_check);
BUFF_APPEND(&to_check, t);
}
} }
} }
@ -1951,7 +1958,11 @@ Vec2 move_and_slide(MoveSlideParams p)
// box first, because doing so is a simple heuristic to avoid depenetrating and losing // box first, because doing so is a simple heuristic to avoid depenetrating and losing
// sideways velocity. It's visual and I can't put diagrams in code so uh oh! // sideways velocity. It's visual and I can't put diagrams in code so uh oh!
BUFF(AABB, 32) actually_overlapping = {0}; typedef BUFF(AABB, 32) OverlapBuff;
OverlapBuff actually_overlapping = {0};
dbgcol(PINK)
dbgrect(at_new);
BUFF_ITER(AABB, &to_check) BUFF_ITER(AABB, &to_check)
{ {
if(overlapping(at_new, *it)) if(overlapping(at_new, *it))
@ -1960,6 +1971,7 @@ Vec2 move_and_slide(MoveSlideParams p)
} }
} }
float smallest_distance = FLT_MAX; float smallest_distance = FLT_MAX;
int smallest_aabb_index = 0; int smallest_aabb_index = 0;
int i = 0; int i = 0;
@ -1975,7 +1987,7 @@ Vec2 move_and_slide(MoveSlideParams p)
i = 0; i = 0;
BUFF(AABB, 32) overlapping_smallest_first = {0}; OverlapBuff overlapping_smallest_first = {0};
if(actually_overlapping.cur_index > 0) if(actually_overlapping.cur_index > 0)
{ {
BUFF_APPEND(&overlapping_smallest_first, actually_overlapping.data[smallest_aabb_index]); BUFF_APPEND(&overlapping_smallest_first, actually_overlapping.data[smallest_aabb_index]);
@ -1984,7 +1996,6 @@ Vec2 move_and_slide(MoveSlideParams p)
{ {
if(i == smallest_aabb_index) if(i == smallest_aabb_index)
{ {
continue;
} }
else else
{ {
@ -1993,18 +2004,34 @@ Vec2 move_and_slide(MoveSlideParams p)
i++; i++;
} }
// overlapping
BUFF_ITER(AABB, &overlapping_smallest_first)
{
dbgcol(GREEN)
{
dbgrect(*it);
}
}
//overlapping_smallest_first = actually_overlapping;
BUFF_ITER(AABB, &actually_overlapping)
dbgcol(WHITE)
dbgrect(*it);
BUFF_ITER(AABB, &overlapping_smallest_first)
dbgcol(WHITE)
dbgsquare(aabb_center(*it));
CollisionInfo info = {0}; CollisionInfo info = {0};
for(int col_iter_i = 0; col_iter_i < 1; col_iter_i++) for(int col_iter_i = 0; col_iter_i < 1; col_iter_i++)
BUFF_ITER(AABB, &overlapping_smallest_first) BUFF_ITER(AABB, &overlapping_smallest_first)
{ {
AABB to_depenetrate_from = *it; AABB to_depenetrate_from = *it;
dbgrect(to_depenetrate_from);
int iters_tried_to_push_apart = 0; int iters_tried_to_push_apart = 0;
while(overlapping(to_depenetrate_from, at_new) && iters_tried_to_push_apart < 500) while(overlapping(to_depenetrate_from, at_new) && iters_tried_to_push_apart < 500)
{ {
//dbgsquare(to_depenetrate_from.upper_left); const float move_dist = 0.1f;
//dbgsquare(to_depenetrate_from.lower_right);
const float move_dist = 0.05f;
info.happened = true; info.happened = true;
Vec2 from_point = aabb_center(to_depenetrate_from); Vec2 from_point = aabb_center(to_depenetrate_from);
@ -2070,7 +2097,6 @@ float draw_wrapped_text(bool dry_run, Vec2 at_point, float max_width, char *text
chars_from_sentence -= 1; chars_from_sentence -= 1;
break; break;
} }
chars_from_sentence += 1; chars_from_sentence += 1;
} }
if(chars_from_sentence > sentence_len) chars_from_sentence--; if(chars_from_sentence > sentence_len) chars_from_sentence--;

Loading…
Cancel
Save