fp: Hide debug UI behind a flag

This commit is contained in:
doyle 2023-10-05 21:30:56 +11:00
parent 5f8344ddda
commit 4bcbc61721
3 changed files with 73 additions and 89 deletions

View File

@ -1252,10 +1252,13 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
Dqn_f32 pan_speed = 5.f; Dqn_f32 pan_speed = 5.f;
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_Space)) if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_Space))
pan_speed *= 2.5f; pan_speed *= 2.5f;
game->camera.world_pos += dir_vector * pan_speed; game->camera.world_pos += dir_vector * pan_speed;
} }
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F1))
game->debug_ui = !game->debug_ui;
Dqn_ProfilerZone update_zone = Dqn_Profiler_BeginZoneWithIndex(DQN_STRING8("FP_Update: Entity loop"), FP_ProfileZone_FPUpdate_EntityLoop); Dqn_ProfilerZone update_zone = Dqn_Profiler_BeginZoneWithIndex(DQN_STRING8("FP_Update: Entity loop"), FP_ProfileZone_FPUpdate_EntityLoop);
// NOTE: Handle input ========================================================================== // NOTE: Handle input ==========================================================================
@ -1574,15 +1577,6 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F)) if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F))
game->build_mode = !game->build_mode; game->build_mode = !game->build_mode;
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F1)) {
entity->sprite_height.meters += 1;
Dqn_Log_InfoF("Height: %.1f", entity->sprite_height.meters);
}
if (TELY_Platform_InputScanCodeIsPressed(input, TELY_PlatformInputScanCode_F2)) {
entity->sprite_height.meters -= 1;
Dqn_Log_InfoF("Height: %.1f", entity->sprite_height.meters);
}
if (entity->flags & FP_GameEntityFlag_CameraTracking) if (entity->flags & FP_GameEntityFlag_CameraTracking)
game->camera.world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle) - Dqn_V2_InitV2I(platform->core.window_size) * .5f; game->camera.world_pos = FP_Game_CalcEntityWorldPos(game, entity->handle) - Dqn_V2_InitV2I(platform->core.window_size) * .5f;
@ -1986,27 +1980,77 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
} }
// NOTE: Render waypoint entities ========================================================== // NOTE: Render waypoint entities ==========================================================
if (entity->flags & FP_GameEntityFlag_MobSpawner) { if (game->debug_ui) {
Dqn_V2 start = world_pos; if (entity->flags & FP_GameEntityFlag_MobSpawner) {
for (FP_GameEntity *waypoint_entity = entity->first_child; waypoint_entity; waypoint_entity = waypoint_entity->next) { Dqn_V2 start = world_pos;
if ((waypoint_entity->flags & FP_GameEntityFlag_MobSpawnerWaypoint) == 0) for (FP_GameEntity *waypoint_entity = entity->first_child; waypoint_entity; waypoint_entity = waypoint_entity->next) {
continue; if ((waypoint_entity->flags & FP_GameEntityFlag_MobSpawnerWaypoint) == 0)
continue;
Dqn_V2 end = FP_Game_CalcEntityWorldPos(game, waypoint_entity->handle); Dqn_V2 end = FP_Game_CalcEntityWorldPos(game, waypoint_entity->handle);
TELY_Render_LineColourV4(renderer, start, end, TELY_COLOUR_BLUE_CADET_V4, 2.f); TELY_Render_LineColourV4(renderer, start, end, TELY_COLOUR_BLUE_CADET_V4, 2.f);
start = end; start = end;
}
}
if (entity->flags & FP_GameEntityFlag_MobSpawner)
TELY_Render_RectColourV4(renderer, world_hit_box, TELY_RenderShapeMode_Line, TELY_COLOUR_BLUE_CADET_V4);
if (entity->flags & FP_GameEntityFlag_MobSpawnerWaypoint)
TELY_Render_CircleColourV4(renderer, world_pos, 16.f /*radius*/, TELY_RenderShapeMode_Line, TELY_COLOUR_BLUE_CADET_V4);
if (entity->flags & FP_GameEntityFlag_BuildZone) {
{
Dqn_V2 line_p1 = Dqn_Rect_InterpolatedPoint(world_hit_box, Dqn_V2_InitNx2(0, 0));
Dqn_V2 line_p2 = Dqn_Rect_InterpolatedPoint(world_hit_box, Dqn_V2_InitNx2(1, 1));
TELY_Render_LineColourV4(renderer, line_p1, line_p2, TELY_COLOUR_BLACK_V4, 2.f);
}
{
Dqn_V2 line_p1 = Dqn_Rect_InterpolatedPoint(world_hit_box, Dqn_V2_InitNx2(0, 1));
Dqn_V2 line_p2 = Dqn_Rect_InterpolatedPoint(world_hit_box, Dqn_V2_InitNx2(1, 0));
TELY_Render_LineColourV4(renderer, line_p1, line_p2, TELY_COLOUR_BLACK_V4, 2.f);
}
}
// NOTE: Render attack box =================================================================
{
Dqn_Rect attack_box = FP_Game_CalcEntityAttackWorldHitBox(game, entity->handle);
TELY_Render_RectColourV4(renderer, attack_box, TELY_RenderShapeMode_Line, TELY_COLOUR_RED_TOMATO_V4);
}
// NOTE: Render world position =============================================================
TELY_Render_CircleColourV4(renderer, world_pos, 4.f, TELY_RenderShapeMode_Fill, TELY_COLOUR_RED_TOMATO_V4);
// NOTE: Render hot/active entity ==========================================================
if (game->clicked_entity == entity->handle) {
TELY_Render_RectColourV4(renderer, world_hit_box, TELY_RenderShapeMode_Line, TELY_COLOUR_WHITE_PALE_GOLDENROD_V4);
// NOTE: Draw the waypoints that the entity is moving along
Dqn_V2 start = world_pos;
for (FP_SentinelListLink<FP_GameWaypoint> *link = nullptr; FP_SentinelList_Iterate(&entity->waypoints, &link); ) {
Dqn_V2 end = FP_Game_CalcWaypointWorldPos(game, &link->data);
TELY_Render_LineColourV4(renderer, start, end, TELY_COLOUR_WHITE_PALE_GOLDENROD_V4, 2.f);
start = end;
}
} else if (game->hot_entity == entity->handle || (entity->flags & FP_GameEntityFlag_DrawHitBox)) {
Dqn_V4 hot_colour = game->hot_entity == entity->handle ? TELY_COLOUR_RED_TOMATO_V4 : TELY_Colour_V4Alpha(TELY_COLOUR_YELLOW_SANDY_V4, .5f);
TELY_Render_RectColourV4(renderer, world_hit_box, TELY_RenderShapeMode_Line, hot_colour);
}
if (game->hot_entity == entity->handle) {
if (entity->name.size) {
Dqn_V2I player_tile = Dqn_V2I_InitNx2(world_pos.x / game->tile_size, world_pos.y / game->tile_size);
Dqn_f32 line_height = TELY_Render_FontHeight(renderer, &platform->assets);
Dqn_V2 draw_p = world_mouse_p;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "%.*s", DQN_STRING_FMT(entity->name)); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Pos: (%.1f, %.1f)", world_pos.x, world_pos.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Hit Box Size: %.1fx%.1f", world_hit_box.size.x, world_hit_box.size.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Tile: %I32dx%I32d", player_tile.x, player_tile.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Mouse Pos: (%.1f, %.1f)", world_mouse_p.x, world_mouse_p.y); draw_p.y += line_height;
}
} }
} }
// NOTE: Render attack box =================================================================
{
Dqn_Rect attack_box = FP_Game_CalcEntityAttackWorldHitBox(game, entity->handle);
TELY_Render_RectColourV4(renderer, attack_box, TELY_RenderShapeMode_Line, TELY_COLOUR_RED_TOMATO_V4);
}
// NOTE: Render world position =============================================================
TELY_Render_CircleColourV4(renderer, world_pos, 4.f, TELY_RenderShapeMode_Fill, TELY_COLOUR_RED_TOMATO_V4);
// NOTE: Render building blueprint ========================================================= // NOTE: Render building blueprint =========================================================
if (game->clicked_entity == entity->handle && game->build_mode) { if (game->clicked_entity == entity->handle && game->build_mode) {
@ -2032,34 +2076,6 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer)
colour); colour);
} }
// NOTE: Render hot/active entity ==========================================================
if (game->clicked_entity == entity->handle) {
TELY_Render_RectColourV4(renderer, world_hit_box, TELY_RenderShapeMode_Line, TELY_COLOUR_WHITE_PALE_GOLDENROD_V4);
// NOTE: Draw the waypoints that the entity is moving along
Dqn_V2 start = world_pos;
for (FP_SentinelListLink<FP_GameWaypoint> *link = nullptr; FP_SentinelList_Iterate(&entity->waypoints, &link); ) {
Dqn_V2 end = FP_Game_CalcWaypointWorldPos(game, &link->data);
TELY_Render_LineColourV4(renderer, start, end, TELY_COLOUR_WHITE_PALE_GOLDENROD_V4, 2.f);
start = end;
}
} else if (game->hot_entity == entity->handle || (entity->flags & FP_GameEntityFlag_DrawHitBox)) {
Dqn_V4 hot_colour = game->hot_entity == entity->handle ? TELY_COLOUR_RED_TOMATO_V4 : TELY_Colour_V4Alpha(TELY_COLOUR_YELLOW_SANDY_V4, .5f);
TELY_Render_RectColourV4(renderer, world_hit_box, TELY_RenderShapeMode_Line, hot_colour);
}
if (game->hot_entity == entity->handle) {
if (entity->name.size) {
Dqn_V2I player_tile = Dqn_V2I_InitNx2(world_pos.x / game->tile_size, world_pos.y / game->tile_size);
Dqn_f32 line_height = TELY_Render_FontHeight(renderer, &platform->assets);
Dqn_V2 draw_p = world_mouse_p;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "%.*s", DQN_STRING_FMT(entity->name)); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Pos: (%.1f, %.1f)", world_pos.x, world_pos.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Hit Box Size: %.1fx%.1f", world_hit_box.size.x, world_hit_box.size.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "Tile: %I32dx%I32d", player_tile.x, player_tile.y); draw_p.y += line_height;
TELY_Render_TextF(renderer, draw_p, Dqn_V2_InitNx2(0.f, 1), "World Mouse Pos: (%.1f, %.1f)", world_mouse_p.x, world_mouse_p.y); draw_p.y += line_height;
}
}
} }
} }
@ -2141,7 +2157,7 @@ void TELY_DLL_FrameUpdate(void *user_data)
// NOTE: UI ==================================================================================== // NOTE: UI ====================================================================================
TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity());
DQN_DEFER { TELY_Render_PopTransform(renderer); }; DQN_DEFER { TELY_Render_PopTransform(renderer); };
{ if (game->debug_ui) {
// NOTE: Info bar ========================================================================== // NOTE: Info bar ==========================================================================
{ {
TELY_RFuiResult info_bar = TELY_RFui_Row(rfui, DQN_STRING8("Info Bar")); TELY_RFuiResult info_bar = TELY_RFui_Row(rfui, DQN_STRING8("Info Bar"));

View File

@ -270,12 +270,6 @@ static FP_GameEntityHandle FP_Entity_CreateWaypointF(FP_Game *game, Dqn_V2 pos,
entity->local_hit_box_size = Dqn_V2_InitNx1(32); entity->local_hit_box_size = Dqn_V2_InitNx1(32);
FP_Entity_AddDebugEditorFlags(game, entity->handle); FP_Entity_AddDebugEditorFlags(game, entity->handle);
entity->flags |= FP_GameEntityFlag_MobSpawnerWaypoint; entity->flags |= FP_GameEntityFlag_MobSpawnerWaypoint;
FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
shape->type = FP_GameShapeType_Circle;
shape->circle_radius = 16.f;
shape->render_mode = TELY_RenderShapeMode_Line;
shape->colour = TELY_COLOUR_BLUE_CADET_V4;
return result; return result;
} }
@ -375,26 +369,6 @@ static FP_GameEntityHandle FP_Entity_CreatePermittedBuildZone(FP_Game *game, Dqn
entity->type = FP_EntityType_Nil; entity->type = FP_EntityType_Nil;
entity->flags |= FP_GameEntityFlag_BuildZone; entity->flags |= FP_GameEntityFlag_BuildZone;
FP_Entity_AddDebugEditorFlags(game, entity->handle); FP_Entity_AddDebugEditorFlags(game, entity->handle);
FP_GameShape *wall = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
wall->type = FP_GameShapeType_Rect;
wall->p2 = entity->local_hit_box_size;
wall->colour = TELY_COLOUR_BLACK_V4;
Dqn_Rect local_hit_box = Dqn_Rect_InitV2x2(Dqn_V2_Zero, entity->local_hit_box_size);
FP_GameShape *line_1 = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
line_1->type = FP_GameShapeType_Line;
line_1->p1 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(0.f, 0.f)) - size * .5f;
line_1->p2 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(1.f, 1.f)) - size * .5f;
line_1->line_thickness = 1.f;
line_1->colour = TELY_COLOUR_BLACK_V4;
FP_GameShape *line_2 = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
line_2->type = FP_GameShapeType_Line;
line_2->p1 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(0.f, 1.f)) - size * .5f;
line_2->p2 = Dqn_Rect_InterpolatedPoint(local_hit_box, Dqn_V2_InitNx2(1.f, 0.f)) - size * .5f;
line_2->line_thickness = 1.f;
line_2->colour = TELY_COLOUR_BLACK_V4;
return result; return result;
} }
@ -418,13 +392,6 @@ static FP_GameEntityHandle FP_Entity_CreateMobSpawner(FP_Game *game, Dqn_V2 pos,
entity->enemies_per_wave = 5; entity->enemies_per_wave = 5;
entity->enemies_spawned_this_wave = 0; entity->enemies_spawned_this_wave = 0;
entity->wave_cooldown_timestamp_s = 0; entity->wave_cooldown_timestamp_s = 0;
FP_GameShape *shape = Dqn_FArray_Make(&entity->shapes, Dqn_ZeroMem_Yes);
shape->type = FP_GameShapeType_Rect;
shape->p1 = {};
shape->p2 = entity->local_hit_box_size;
shape->render_mode = TELY_RenderShapeMode_Line;
shape->colour = TELY_COLOUR_BLUE_CADET_V4;
return result; return result;
} }

View File

@ -262,6 +262,7 @@ struct FP_Game
bool build_mode; bool build_mode;
bool build_mode_can_place_building; bool build_mode_can_place_building;
bool debug_ui;
}; };
struct FP_GameAStarNode struct FP_GameAStarNode