From 299a8b707c58286a16a54c64519e656ce79c1e9d Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 29 Jun 2023 19:09:00 -0700 Subject: [PATCH] Add 2P and 3P/4P timer HUD variations --- src/CMakeLists.txt | 1 + src/hud/CMakeLists.txt | 3 +++ src/hud/timer.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ src/k_hud.c | 31 +++++++++---------------- src/k_hud.h | 2 ++ 5 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 src/hud/CMakeLists.txt create mode 100644 src/hud/timer.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 24b59ae08..666c208c1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -581,6 +581,7 @@ add_subdirectory(menus) if(SRB2_CONFIG_ENABLE_WEBM_MOVIES) add_subdirectory(media) endif() +add_subdirectory(hud) # strip debug symbols into separate file when using gcc. # to be consistent with Makefile, don't generate for OS X. diff --git a/src/hud/CMakeLists.txt b/src/hud/CMakeLists.txt new file mode 100644 index 000000000..7ef234ac1 --- /dev/null +++ b/src/hud/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(SRB2SDL2 PRIVATE + timer.cpp +) diff --git a/src/hud/timer.cpp b/src/hud/timer.cpp new file mode 100644 index 000000000..e59955473 --- /dev/null +++ b/src/hud/timer.cpp @@ -0,0 +1,52 @@ +#include + +#include "../doomstat.h" +#include "../g_game.h" +#include "../k_hud.h" +#include "../p_local.h" +#include "../v_draw.hpp" + +using srb2::Draw; + +namespace +{ + +constexpr INT32 kHudFlags = V_HUDTRANS | V_SLIDEIN; + +}; // namespace + +void K_drawKart2PTimestamp(void) +{ + auto get_row = [] + { + if (stplyr == &players[displayplayers[0]]) + { + return Draw(286, 31).flags(V_SNAPTOTOP); + } + else + { + return Draw(286, 163).flags(V_SNAPTOBOTTOM); + } + }; + + Draw row = get_row().flags(kHudFlags | V_SNAPTORIGHT).font(Draw::Font::kZVote); + + row.patch("K_STTIMS"); + row.xy(12, 2).text("{:03}", stplyr->realtime / TICRATE); +} + +void K_drawKart4PTimestamp(void) +{ + Draw row = Draw(154, 0).flags(kHudFlags).font(Draw::Font::kZVote).align(Draw::Align::kCenter); + + auto draw = [](const Draw& row, tic_t time) + { + row.patch("K_STTIMS"); + row.xy(5, 12).text("{:03}", time / TICRATE); + }; + + auto time_of = [](int k) -> tic_t { return k <= r_splitscreen ? players[displayplayers[k]].realtime : 0u; }; + + draw(row.y(1).flags(V_SNAPTOTOP), std::max(time_of(0), time_of(1))); + draw(row.y(178).flags(V_SNAPTOBOTTOM), std::max(time_of(2), time_of(3))); +} diff --git a/src/k_hud.c b/src/k_hud.c index ecfbc6e59..acbaa24c2 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -5294,7 +5294,6 @@ void K_drawKartHUD(void) boolean islonesome = false; boolean battlefullscreen = false; boolean freecam = demo.freecam; //disable some hud elements w/ freecam - UINT8 i; UINT8 viewnum = R_GetViewNumber(); // Define the X and Y for each drawn object @@ -5376,27 +5375,19 @@ void K_drawKartHUD(void) islonesome = K_drawKartPositionFaces(); } - else if (viewnum == r_splitscreen - && (gametyperules & GTR_TIMELIMIT) - && timelimitintics > 0) + else if (r_splitscreen == 1) { - tic_t highestrealtime = players[displayplayers[1]].realtime; - - // Uses the highest time across all players (handles paused timer on exiting) - for (i = 1; i <= r_splitscreen; i++) - { - if (players[displayplayers[i]].realtime <= highestrealtime) - continue; - highestrealtime = players[displayplayers[i]].realtime; - } - - // Draw the timestamp (mostly) CENTERED if (LUA_HudEnabled(hud_time)) - K_drawKartTimestamp(highestrealtime, - (r_splitscreen == 1 ? TIME_X : ((BASEVIDWIDTH/2) - 69)), - TIME_Y, - V_HUDTRANS|V_SLIDEIN|V_SNAPTOTOP|(r_splitscreen == 1 ? V_SNAPTORIGHT : 0), - 0); + { + K_drawKart2PTimestamp(); + } + } + else if (viewnum == r_splitscreen) + { + if (LUA_HudEnabled(hud_time)) + { + K_drawKart4PTimestamp(); + } } if (!stplyr->spectator && !demo.freecam) // Bottom of the screen elements, don't need in spectate mode diff --git a/src/k_hud.h b/src/k_hud.h index df17214e2..9f6f7c3c9 100644 --- a/src/k_hud.h +++ b/src/k_hud.h @@ -41,6 +41,8 @@ void K_LoadKartHUDGraphics(void); void K_drawKartHUD(void); void K_drawKartFreePlay(void); void K_drawKartTimestamp(tic_t drawtime, INT32 TX, INT32 TY, INT32 splitflags, UINT8 mode); +void K_drawKart2PTimestamp(void); +void K_drawKart4PTimestamp(void); void K_DrawMapThumbnail(fixed_t x, fixed_t y, fixed_t width, UINT32 flags, UINT16 map, const UINT8 *colormap); void K_DrawLikeMapThumbnail(fixed_t x, fixed_t y, fixed_t width, UINT32 flags, patch_t *patch, const UINT8 *colormap); void K_drawTargetHUD(const vector3_t *origin, player_t *player);