From 9b1e40a3686063d7233e745b2320786a55993e70 Mon Sep 17 00:00:00 2001 From: doyle Date: Sun, 15 Oct 2023 21:02:28 +1100 Subject: [PATCH] fp: Fix scanlines --- External/tely | 2 +- feely_pona.cpp | 24 ++++++++++++++---------- feely_pona_game.cpp | 32 +++++++------------------------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/External/tely b/External/tely index 60aec2d..9ec8c29 160000 --- a/External/tely +++ b/External/tely @@ -1 +1 @@ -Subproject commit 60aec2dd926ff7cde98408c25ecbc40eb33fddd7 +Subproject commit 9ec8c2953c3726276c44d7ab58dba3a938da6f97 diff --git a/feely_pona.cpp b/feely_pona.cpp index 1d547c6..ff11692 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -470,9 +470,11 @@ static void FP_PlayReset(FP_Game *game, TELY_Platform *platform) // NOTE: Heart game->play.heart = FP_Entity_CreateHeart(game, base_mid_p, "Heart"); - play->camera.world_pos = base_mid_p - Dqn_V2_InitV2I(platform->core.window_size * .5f); play->tile_size = 37; - play->camera.scale = Dqn_V2_InitNx1(1); + + // NOTE: Camera ================================================================================ + play->camera.world_pos = base_mid_p - Dqn_V2_InitV2I(platform->core.window_size * .5f); + play->camera.scale = Dqn_V2_InitNx1(1); } #if defined(DQN_OS_WIN32) @@ -2296,12 +2298,14 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_PlatformInput *input } if (!FP_Game_IsNilEntityHandle(game, game->play.clicked_entity)) { - Dqn_usize const target_width = 1800; - Dqn_usize const target_height = 1046; - game->play.camera.world_pos.x = DQN_MIN(game->play.camera.world_pos.x, game->play.map->local_hit_box_size.w * +0.5f - target_width); - game->play.camera.world_pos.x = DQN_MAX(game->play.camera.world_pos.x, game->play.map->local_hit_box_size.w * -0.5f); - game->play.camera.world_pos.y = DQN_MAX(game->play.camera.world_pos.y, game->play.map->local_hit_box_size.h * -0.5f); - game->play.camera.world_pos.y = DQN_MIN(game->play.camera.world_pos.y, game->play.map->local_hit_box_size.h * +0.5f - target_height); + Dqn_V2 target_camera_size = Dqn_V2_InitNx2(1826, 1046); + Dqn_V2 window_size = Dqn_V2_InitV2I(platform->core.window_size); + FP_GamePlay *play = &game->play; + play->camera.scale = window_size / target_camera_size; + play->camera.world_pos.x = DQN_MIN(play->camera.world_pos.x, play->map->local_hit_box_size.w * +0.5f - target_camera_size.w); + play->camera.world_pos.x = DQN_MAX(play->camera.world_pos.x, play->map->local_hit_box_size.w * -0.5f); + play->camera.world_pos.y = DQN_MAX(play->camera.world_pos.y, play->map->local_hit_box_size.h * -0.5f); + play->camera.world_pos.y = DQN_MIN(play->camera.world_pos.y, play->map->local_hit_box_size.h * +0.5f - target_camera_size.h); } Dqn_Profiler_EndZone(update_zone); @@ -3233,7 +3237,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, Dqn_V2 screen_size = Dqn_V2_InitNx2(platform->core.window_size.w, platform->core.window_size.h); Dqn_f32 scanline_gap = 4.0f; Dqn_f32 scanline_thickness = 3.0f; - FP_GameRenderCameraFollowScanlines(renderer, screen_size, game->play.camera.world_pos, scanline_gap, scanline_thickness); + FP_GameRenderScanlines(renderer, scanline_gap, scanline_thickness, screen_size); } // NOTE: Render the other game state modes ===================================================== @@ -3395,7 +3399,7 @@ void FP_Render(FP_Game *game, TELY_Platform *platform, TELY_Renderer *renderer, Dqn_f32 scanline_gap = 4.0f; Dqn_f32 scanline_thickness = 3.0f; - FP_GameRenderCameraFollowScanlines(renderer, window_rect.size, Dqn_V2_Zero, scanline_gap, scanline_thickness); + FP_GameRenderScanlines(renderer, scanline_gap, scanline_thickness, window_rect.size); } // NOTE: Debug UI ============================================================================== diff --git a/feely_pona_game.cpp b/feely_pona_game.cpp index 481133b..b67e235 100644 --- a/feely_pona_game.cpp +++ b/feely_pona_game.cpp @@ -905,35 +905,17 @@ static void FP_Game_EntityTransitionState(FP_Game *game, FP_GameEntity *entity, entity->action.next_state = desired_state; } -static void FP_GameRenderScanlines(TELY_Renderer *renderer, Dqn_f32 scanline_gap, Dqn_f32 scanline_thickness, - Dqn_V2 screen_size, Dqn_V2 camera_offset) +static void FP_GameRenderScanlines(TELY_Renderer *renderer, + Dqn_f32 scanline_gap, + Dqn_f32 scanline_thickness, + Dqn_V2 screen_size) { + TELY_Render_PushTransform(renderer, Dqn_M2x3_Identity()); + DQN_DEFER { TELY_Render_PopTransform(renderer); }; Dqn_f32 scanline_interval = scanline_gap + scanline_thickness; - Dqn_f32 y_offset = fmodf(camera_offset.y, scanline_interval); - - for (Dqn_f32 y = -y_offset; y < screen_size.h; y += scanline_interval) - { + for (Dqn_f32 y = 0; y < screen_size.h; y += scanline_interval) { Dqn_V2 start = Dqn_V2_InitNx2(0, y); Dqn_V2 end = Dqn_V2_InitNx2(screen_size.w, y); TELY_Render_LineColourV4(renderer, start, end, TELY_Colour_V4Alpha(TELY_COLOUR_WHITE_V4, 0.1f), scanline_thickness); } } - -static void FP_GameRenderCameraFollowScanlines(TELY_Renderer *renderer, - Dqn_V2 screen_size, - Dqn_V2 camera_offset, - Dqn_f32 scanline_gap, - Dqn_f32 scanline_thickness) -{ - Dqn_f32 y_offset = camera_offset.y; - - // Adjust starting y to be more negative - Dqn_f32 starting_y = -screen_size.h - 150 - y_offset; - - for (Dqn_f32 y = starting_y; y < screen_size.h; y += scanline_gap + scanline_thickness) { - Dqn_V2 start = Dqn_V2_InitNx2(camera_offset.x, y + camera_offset.y); - Dqn_V2 end = Dqn_V2_InitNx2(screen_size.w + camera_offset.x, y + camera_offset.y); - TELY_Render_LineColourV4(renderer, start, end, TELY_Colour_V4Alpha(TELY_COLOUR_BLACK_V4, 0.1f), scanline_thickness); - } -} -