fp: Fix scanlines

This commit is contained in:
doyle 2023-10-15 21:02:28 +11:00
parent edfa461c9a
commit 9b1e40a368
3 changed files with 22 additions and 36 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit 60aec2dd926ff7cde98408c25ecbc40eb33fddd7 Subproject commit 9ec8c2953c3726276c44d7ab58dba3a938da6f97

View File

@ -470,8 +470,10 @@ static void FP_PlayReset(FP_Game *game, TELY_Platform *platform)
// NOTE: Heart // NOTE: Heart
game->play.heart = FP_Entity_CreateHeart(game, base_mid_p, "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->tile_size = 37;
// NOTE: Camera ================================================================================
play->camera.world_pos = base_mid_p - Dqn_V2_InitV2I(platform->core.window_size * .5f);
play->camera.scale = Dqn_V2_InitNx1(1); play->camera.scale = Dqn_V2_InitNx1(1);
} }
@ -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)) { if (!FP_Game_IsNilEntityHandle(game, game->play.clicked_entity)) {
Dqn_usize const target_width = 1800; Dqn_V2 target_camera_size = Dqn_V2_InitNx2(1826, 1046);
Dqn_usize const target_height = 1046; Dqn_V2 window_size = Dqn_V2_InitV2I(platform->core.window_size);
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); FP_GamePlay *play = &game->play;
game->play.camera.world_pos.x = DQN_MAX(game->play.camera.world_pos.x, game->play.map->local_hit_box_size.w * -0.5f); play->camera.scale = window_size / target_camera_size;
game->play.camera.world_pos.y = DQN_MAX(game->play.camera.world_pos.y, game->play.map->local_hit_box_size.h * -0.5f); 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);
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); 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); 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_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_gap = 4.0f;
Dqn_f32 scanline_thickness = 3.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 ===================================================== // 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_gap = 4.0f;
Dqn_f32 scanline_thickness = 3.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 ============================================================================== // NOTE: Debug UI ==============================================================================

View File

@ -905,35 +905,17 @@ static void FP_Game_EntityTransitionState(FP_Game *game, FP_GameEntity *entity,
entity->action.next_state = desired_state; entity->action.next_state = desired_state;
} }
static void FP_GameRenderScanlines(TELY_Renderer *renderer, Dqn_f32 scanline_gap, Dqn_f32 scanline_thickness, static void FP_GameRenderScanlines(TELY_Renderer *renderer,
Dqn_V2 screen_size, Dqn_V2 camera_offset) 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 scanline_interval = scanline_gap + scanline_thickness;
Dqn_f32 y_offset = fmodf(camera_offset.y, scanline_interval); for (Dqn_f32 y = 0; y < screen_size.h; y += scanline_interval) {
for (Dqn_f32 y = -y_offset; y < screen_size.h; y += scanline_interval)
{
Dqn_V2 start = Dqn_V2_InitNx2(0, y); Dqn_V2 start = Dqn_V2_InitNx2(0, y);
Dqn_V2 end = Dqn_V2_InitNx2(screen_size.w, 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); 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);
}
}