From 934f2d347c51750e6a23950ee54cc724af9edc85 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 11 Nov 2023 02:27:39 -0800 Subject: [PATCH 01/12] Add basic profiling for Lua hooks (except HUD hooks) - Add lua_profile cheat: calculate average time spent in hooks over a period - Show hook times in a sorted table, along with lump name, script line number and hook type - Show cumulative time spent in game logic hooks and percentage of overhead to game logic --- src/CMakeLists.txt | 2 + src/Makefile | 2 +- src/Sourcefile | 1 + src/d_clisrv.c | 3 + src/d_main.c | 6 ++ src/d_netcmd.c | 6 ++ src/d_netcmd.h | 2 + src/lua_hooklib.c | 46 ++++++++- src/lua_infolib.c | 6 +- src/lua_profile.cpp | 246 ++++++++++++++++++++++++++++++++++++++++++++ src/lua_profile.h | 38 +++++++ src/m_perfstats.c | 1 + src/m_perfstats.h | 1 + src/p_tick.c | 8 +- 14 files changed, 364 insertions(+), 4 deletions(-) create mode 100644 src/lua_profile.cpp create mode 100644 src/lua_profile.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc456905a..864a5870c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -275,6 +275,7 @@ if(${SRB2_CONFIG_HAVE_BLUA}) lua_hooklib.c lua_hudlib.c lua_hudlib_drawlist.c + lua_profile.cpp lua_infolib.c lua_maplib.c lua_mathlib.c @@ -290,6 +291,7 @@ if(${SRB2_CONFIG_HAVE_BLUA}) lua_hook.h lua_hud.h lua_hudlib_drawlist.h + lua_profile.ch lua_libs.h lua_script.h lua_udatalib.h diff --git a/src/Makefile b/src/Makefile index 4ee7cf1a9..77c9f7129 100644 --- a/src/Makefile +++ b/src/Makefile @@ -307,7 +307,7 @@ opts+=$(WFLAGS) $(CFLAGS) cxxopts:=$(opts) $(CXXFLAGS) opts+=$(CWFLAGS) # warning flags that shouldnt be passed to c++ compiler -libs+=$(LDFLAGS) -lstdc++ -lpthread +libs+=$(LDFLAGS) -lstdc++ -lpthread -lfmt asflags:=$(ASFLAGS) -x assembler-with-cpp diff --git a/src/Sourcefile b/src/Sourcefile index 08c18ebf0..f09a143bd 100644 --- a/src/Sourcefile +++ b/src/Sourcefile @@ -99,3 +99,4 @@ lua_skinlib.c lua_thinkerlib.c lua_udatalib.c lua_glib.c +lua_profile.cpp diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8cb038251..8f93bc9e7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -6848,7 +6848,10 @@ boolean TryRunTics(tic_t realtics) DEBFILE(va("============ Running tic %d (local %d)\n", gametic, leveltime)); if (update_stats) + { + ps_prevtictime = ps_tictime; PS_START_TIMING(ps_tictime); + } G_Ticker((gametic % NEWTICRATERATIO) == 0); ExtraDataTicker(); diff --git a/src/d_main.c b/src/d_main.c index 2150b1e72..0e095d9a4 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -79,6 +79,7 @@ #include "core/memory.h" #include "lua_script.h" +#include "lua_profile.h" /* Manually defined asset hashes for non-CMake builds * Last updated 2015 / 05 / 03 - SRB2 v2.1.15 - srb2.srb @@ -658,6 +659,11 @@ static boolean D_Display(void) CON_Drawer(); // Ha, i LIED! + if (cv_lua_profile.value > 0) + { + LUA_RenderTimers(); + } + PS_START_TIMING(ps_swaptime); I_FinishUpdate(); // page flip or blit buffer PS_STOP_TIMING(ps_swaptime); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index fd08830f0..42e5dec19 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -47,6 +47,7 @@ #include "z_zone.h" #include "lua_script.h" #include "lua_hook.h" +#include "lua_profile.h" #include "m_cond.h" #include "m_anigif.h" #include "k_kart.h" // SRB2kart @@ -506,6 +507,9 @@ static CV_PossibleValue_t ps_descriptor_cons_t[] = { {1, "Average"}, {2, "SD"}, {3, "Minimum"}, {4, "Maximum"}, {0, NULL}}; consvar_t cv_ps_descriptor = {"ps_descriptor", "Average", 0, ps_descriptor_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +//consvar_t cv_lua_profile = {"lua_profile", "0").values(CV_Unsigned).onchange(lua_profile_OnChange).description("Show hook timings over an average of N tics"); +consvar_t cv_lua_profile = {"lua_profile", "0", CV_CALL, CV_Unsigned, lua_profile_OnChange, 0, NULL, NULL, 0, 0, NULL}; + // only there to better keep track of it globally consvar_t cv_director = {"director", "Off", CV_HIDEN, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -933,6 +937,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_palette); CV_RegisterVar(&cv_palettenum); + CV_RegisterVar(&cv_lua_profile); + // m_menu.c CV_RegisterVar(&cv_chatheight); CV_RegisterVar(&cv_chatwidth); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 46ec396ec..25e050a13 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -189,6 +189,8 @@ extern consvar_t cv_ps_thinkframe_page; extern consvar_t cv_ps_samplesize; extern consvar_t cv_ps_descriptor; +extern consvar_t cv_lua_profile; + extern consvar_t cv_director, cv_kartdebugdirector, cv_showdirectorhud; extern consvar_t cv_showtrackaddon; diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 90d8ec367..bed23cf36 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -25,6 +25,7 @@ #include "lua_libs.h" #include "lua_hook.h" #include "lua_hud.h" // hud_running errors +#include "lua_profile.h" /* ========================================================================= ABSTRACTION @@ -445,11 +446,54 @@ FUNCINLINE static ATTRINLINE void get_hook_from_table(Hook_State *hook, int n) lua_getref(gL, hookRefs[hook->id]); } +static int pcall(Hook_State *hook) +{ + return lua_pcall(gL, hook->values, hook->results, EINDEX); +} + +static const char *hook_name(Hook_State *hook) +{ + if (hud_running) + { + return hudHookNames[hook->hook_type]; + } + else if (hook->string) + { + return stringHookNames[hook->hook_type]; + } + //else if (hook->mobj_type > 0) + else if (hook->mobj_type != NONMOHOOK) + { + return mobjHookNames[hook->hook_type]; + } + else + { + return hookNames[hook->hook_type]; + } +} + +static int pcall_timed_or_untimed(Hook_State *hook) +{ + if (!hud_running && cv_lua_profile.value > 0) + { + lua_timer_t *timer = LUA_BeginFunctionTimer(gL, -1 - hook->values, hook_name(hook)); + int k = pcall(hook); + LUA_EndFunctionTimer(timer); + + return k; + } + else + { + return pcall(hook); + } +} + static int call_single_hook_no_copy(Hook_State *hook) { hook_important = hook->important; - if (lua_pcall(gL, hook->values, hook->results, EINDEX) == 0) + //if (lua_pcall(gL, hook->values, hook->results, EINDEX) == 0) + if (pcall_timed_or_untimed(hook) == 0) { if (hook->results > 0) { diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 4c84c48d5..5f2f4f80c 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -22,7 +22,8 @@ #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors -#include "lua_hook.h" // cmd errors +#include "lua_hook.h" // hook_cmd_running errors +#include "lua_profile.h" boolean LUA_CallAction(enum actionnum actionnum, mobj_t *actor); state_t *astate = NULL; @@ -110,7 +111,10 @@ static void A_Lua(mobj_t *actor) LUA_PushUserdata(gL, actor, META_MOBJ); lua_pushinteger(gL, var1); lua_pushinteger(gL, var2); + + lua_timer_t *timer = LUA_BeginFunctionTimer(gL, -4, "A_Lua"); LUA_Call(gL, 3, 0, 1); + LUA_EndFunctionTimer(timer); lua_pop(gL, 1); // pop error handler diff --git a/src/lua_profile.cpp b/src/lua_profile.cpp new file mode 100644 index 000000000..db13dde70 --- /dev/null +++ b/src/lua_profile.cpp @@ -0,0 +1,246 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by James Robert Roman +// Copyright (C) 2025 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- + +#include "screen.h" +#include +#include +#include +#include +#include +#include + +#include +#include + +extern "C" { +#include "blua/lua.h" +}; + +#include "v_video.h" + +#include "command.h" +#include "doomtype.h" +#include "i_system.h" +#include "lua_profile.h" +#include "m_perfstats.h" + +extern "C" consvar_t cv_lua_profile; + +namespace +{ + +precise_t g_time_reference; +int g_tics_counted; + +double g_running_tic_time; +double g_avg_tic_time; + +bool g_invalid; + +}; // namespace + +struct lua_timer_t +{ + struct Stat + { + double calls = 0; + double time = 0.0; + }; + + Stat running, avg; +}; + +namespace +{ + +std::unordered_map g_tic_timers; + +}; // namespace + +lua_timer_t* LUA_BeginFunctionTimer(lua_State* L, int fn_idx, const char* name) +{ + lua_Debug ar; + + lua_pushvalue(L, fn_idx); + lua_getinfo(L, ">S", &ar); + + auto label = [&] + { + using sv = std::string_view; + sv view{ar.source}; + + switch (view.front()) + { + case '@': // file + if (std::size_t p = view.rfind('/'); p != sv::npos) // lump or base + { + return view.substr(p + 1); + } + break; + + case '=': // ?? + view.remove_prefix(1); + break; + } + + return view; + }; + + auto [it, ins] = g_tic_timers.try_emplace(fmt::format("{}:{} ({})", label(), ar.linedefined, name)); + auto& [key, timer] = *it; + + g_time_reference = I_GetPreciseTime(); + + return &timer; +} + +void LUA_EndFunctionTimer(lua_timer_t* timer) +{ + precise_t t = I_GetPreciseTime() - g_time_reference; + double precision = I_GetPrecisePrecision(); + + timer->running.time += t / precision; + timer->running.calls += 1.0; +} + +void LUA_ResetTicTimers(void) +{ + if (cv_lua_profile.value <= 0) + { + return; + } + + if (g_tics_counted < cv_lua_profile.value) + { + g_tics_counted++; + + double precision = I_GetPrecisePrecision(); + g_running_tic_time += ps_prevtictime.value.p / precision; + } + else + { + double counted = g_tics_counted; + + for (auto& [key, timer] : g_tic_timers) + { + timer.avg = {timer.running.calls / counted, timer.running.time / counted}; + timer.running = {}; + } + + g_avg_tic_time = g_running_tic_time / counted; + g_running_tic_time = 0.0; + + g_tics_counted = 1; + + g_invalid = false; + } +} + +void LUA_RenderTimers(void) +{ + using srb2::Draw; + + constexpr int kRowHeight = 4; + constexpr float kScale = 0.5f; + + Draw row = Draw(0, kRowHeight).font(Draw::Font::kConsole).align(Draw::Align::kLeft).scale(0.5).flags(V_MONOSPACE); + row.y(-kRowHeight).text("-- AVERAGES PER TIC (over {} tics) --", cv_lua_profile.value); + + if (g_invalid) + { + row.flags(V_GRAYMAP).text(" "); + return; + } + + std::vector view; + view.reserve(g_tic_timers.size()); + + auto color_flag = [](double t) + { + if (t < 10.0) + { + return V_GRAYMAP; + } + else if (t >= 100.0) + { + return V_YELLOWMAP; + } + else + { + return 0; + } + }; + + { + double cum = 0.0; + + for (auto it = g_tic_timers.begin(); it != g_tic_timers.end(); ++it) + { + auto& [key, timer] = *it; + + cum += timer.avg.time; + + if (timer.avg.time > 0.0) + { + view.push_back(it); + } + } + + Draw tally = row.flags(color_flag(cum * 1'000'000.0)); + + tally.text("{:8.2f} us - TOTAL", cum * 1'000'000.0); + tally.y(kRowHeight).text("{:8.2f} ms", cum * 1000.0); + tally.y(kRowHeight * 2).text( + "{:8.2f}% overhead ({:.2f} / {:.2f}) <-- not counting rendering time", + (cum / g_avg_tic_time) * 100.0, + cum * TICRATE, + g_avg_tic_time * TICRATE + ); + + row = row.y(kRowHeight * 4); + } + + std::sort( + view.rbegin(), + view.rend(), + [](auto a, auto b) + { + auto& [k1, t1] = *a; + auto& [k2, t2] = *b; + return t1.avg.time < t2.avg.time; + } + ); + + for (auto it : view) + { + auto& [key, timer] = *it; + + double t = timer.avg.time * 1'000'000.0; + + row.flags(color_flag(t)).text( + "{:>8.2f} us {:>8.2f} calls - {}", + t, + timer.avg.calls, + key + ); + + row = row.y(kRowHeight); + } +} + +extern "C" void lua_profile_OnChange(void) +{ + g_invalid = true; + + if (cv_lua_profile.value == 0) + { + g_tic_timers = {}; + } +} diff --git a/src/lua_profile.h b/src/lua_profile.h new file mode 100644 index 000000000..80475613d --- /dev/null +++ b/src/lua_profile.h @@ -0,0 +1,38 @@ +// DR. ROBOTNIK'S RING RACERS +//----------------------------------------------------------------------------- +// Copyright (C) 2025 by James Robert Roman +// Copyright (C) 2025 by Kart Krew +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- + +#ifndef lua_profile_h +#define lua_profile_h + +#include "blua/lua.h" +#include "doomtype.h" +//#include "typedef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct lua_timer_t; +typedef struct lua_timer_t lua_timer_t; + +void LUA_ResetTicTimers(void); + +lua_timer_t *LUA_BeginFunctionTimer(lua_State *L, int fn_idx, const char *name); +void LUA_EndFunctionTimer(lua_timer_t *timer); + +void LUA_RenderTimers(void); + +void lua_profile_OnChange(void); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif/*lua_profile_h*/ diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 49a855686..90bde47e9 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -47,6 +47,7 @@ struct perfstatrow { static ps_metric_t ps_frametime = {0}; ps_metric_t ps_tictime = {0}; +ps_metric_t ps_prevtictime = {0}; ps_metric_t ps_playerthink_time = {0}; ps_metric_t ps_thinkertime = {0}; diff --git a/src/m_perfstats.h b/src/m_perfstats.h index 083656d61..474c6c841 100644 --- a/src/m_perfstats.h +++ b/src/m_perfstats.h @@ -36,6 +36,7 @@ typedef struct #define PS_STOP_TIMING(metric) metric.value.p = I_GetPreciseTime() - metric.value.p extern ps_metric_t ps_tictime; +extern ps_metric_t ps_prevtictime; extern ps_metric_t ps_playerthink_time; extern ps_metric_t ps_thinkertime; diff --git a/src/p_tick.c b/src/p_tick.c index d0d25be69..455a8d5ac 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -38,6 +38,8 @@ #include "i_video.h" // rendermode #include "m_perfstats.h" +#include "lua_profile.h" + // Object place #include "m_cheat.h" @@ -622,6 +624,8 @@ void P_Ticker(boolean run) } } + LUA_ResetTicTimers(); + ps_lua_mobjhooks.value.i = 0; ps_checkposition_calls.value.i = 0; @@ -629,6 +633,7 @@ void P_Ticker(boolean run) LUA_HookPreThinkFrame(); PS_STOP_TIMING(ps_lua_prethinkframe_time); + // OK! Now that we got all of that sorted, players can think! PS_START_TIMING(ps_playerthink_time); for (i = 0; i < MAXPLAYERS; i++) { @@ -675,6 +680,7 @@ void P_Ticker(boolean run) PS_STOP_TIMING(ps_lua_thinkframe_time); } + // Run shield positioning P_RunOverlays(); P_RunShadows(); @@ -796,7 +802,7 @@ void P_Ticker(boolean run) if (!player->mo) continue; - const boolean skybox = (skyboxmo[0] && cv_skybox.value); + const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on if (skyVisiblePerPlayer[i] && skybox) { From 38a248193e6344ba1a480c67ad4f18f9b285ae48 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 1 Jul 2026 18:14:54 +0200 Subject: [PATCH 02/12] make lua hook profiler kinda work very scuffed up since we dont have the srb2::Draw lib so it may display stuff out of screen bounds i also rather not use fmt here but va since i dont want another dependency needs to be fixed up sometime --- src/lua_profile.cpp | 59 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/src/lua_profile.cpp b/src/lua_profile.cpp index db13dde70..a25646a74 100644 --- a/src/lua_profile.cpp +++ b/src/lua_profile.cpp @@ -145,17 +145,33 @@ void LUA_ResetTicTimers(void) void LUA_RenderTimers(void) { - using srb2::Draw; + ///using srb2::Draw; constexpr int kRowHeight = 4; - constexpr float kScale = 0.5f; + //constexpr float kScale = 0.5f; - Draw row = Draw(0, kRowHeight).font(Draw::Font::kConsole).align(Draw::Align::kLeft).scale(0.5).flags(V_MONOSPACE); - row.y(-kRowHeight).text("-- AVERAGES PER TIC (over {} tics) --", cv_lua_profile.value); + // pretty much what the whole srb2::Draw does lol + auto draw_row = [](float x, float y, INT32 flags, const std::string& str) + { + V_DrawSmallStringAtFixed( + FloatToFixed(x), + FloatToFixed(y), + V_MONOSPACE|V_ALLOWLOWERCASE|flags, + str.c_str() + ); + }; + + float row_y = kRowHeight - 60; + draw_row(0.f, row_y - kRowHeight, 0, fmt::format("-- AVERAGES PER TIC (over {} tics) --", cv_lua_profile.value)); + + //Draw row = Draw(0, kRowHeight).font(Draw::Font::kConsole).align(Draw::Align::kLeft).scale(0.5).flags(V_MONOSPACE); + //row.y(-kRowHeight).text("-- AVERAGES PER TIC (over {} tics) --", cv_lua_profile.value); if (g_invalid) { - row.flags(V_GRAYMAP).text(" "); + row_y += kRowHeight; + //row.flags(V_GRAYMAP).text(" "); + draw_row(0.f, row_y - kRowHeight, V_GRAYMAP, " "); return; } @@ -193,6 +209,7 @@ void LUA_RenderTimers(void) } } + /* Draw tally = row.flags(color_flag(cum * 1'000'000.0)); tally.text("{:8.2f} us - TOTAL", cum * 1'000'000.0); @@ -205,6 +222,23 @@ void LUA_RenderTimers(void) ); row = row.y(kRowHeight * 4); + */ + + { + const INT32 tally_flags = color_flag(cum * 1'000'000.0); + + draw_row(0.f, row_y, tally_flags, fmt::format("{:8.2f} us - TOTAL", cum * 1'000'000.0)); + draw_row(0.f, row_y + kRowHeight, tally_flags, fmt::format("{:8.2f} ms", cum * 1000.0)); + draw_row(0.f, row_y + kRowHeight * 2, tally_flags, fmt::format( + "{:8.2f}% overhead ({:.2f} / {:.2f}) <-- not counting rendering time", + (cum / g_avg_tic_time) * 100.0, + (cum * (double)TICRATE), + (g_avg_tic_time * (double)TICRATE) + )); + } + + row_y += kRowHeight * 4; // row = row.y(kRowHeight * 4) + } std::sort( @@ -224,6 +258,7 @@ void LUA_RenderTimers(void) double t = timer.avg.time * 1'000'000.0; + /* row.flags(color_flag(t)).text( "{:>8.2f} us {:>8.2f} calls - {}", t, @@ -232,6 +267,20 @@ void LUA_RenderTimers(void) ); row = row.y(kRowHeight); + */ + + draw_row(0.f, row_y, color_flag(t), fmt::format( + "{:>8.2f} us {:>8.2f} calls - {}", + t, + timer.avg.calls, + key + )); + + row_y += kRowHeight; // row = row.y(kRowHeight) + + // FIXME this is all ugly and sucks + if (row_y >= BASEVIDHEIGHT) + break; } } From a539f38e72f6c0a858e8b4139f21322b7b134d95 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 21 Jul 2026 20:32:58 +0200 Subject: [PATCH 03/12] add more safety checks to some maploading stuff + rename things to make more sense --- src/hardware/hw_cache.c | 2 +- src/p_setup.c | 146 ++++++++++++++++++++++------------------ src/r_segs.cpp | 2 +- 3 files changed, 81 insertions(+), 69 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 9300cbe81..c4cd7d383 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -998,7 +998,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) const char *flatname = W_CheckNameForNum(flatlumpnum); // hack for gba rainbow roads cyan floors - if (UNLIKELY(memcmp(flatname, "GBA_RRF5", 8) == 0 && flatname[8] == 0)) + if (UNLIKELY(flatname && memcmp(flatname, "GBA_RRF5", 8) == 0 && flatname[8] == 0)) { glMipmap->flags &= ~TF_CHROMAKEYED; } diff --git a/src/p_setup.c b/src/p_setup.c index 54b461665..c878d35d4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -318,15 +318,15 @@ void P_AllocMapHeader(INT16 i) // Loads the vertexes for a level. FUNCINLINE static ATTRINLINE void P_LoadVertices(UINT8 *data) { - mapvertex_t *ml = (mapvertex_t *)data; - vertex_t *li = vertexes; + mapvertex_t *mv = (mapvertex_t *)data; + vertex_t *v = vertexes; size_t i; // Copy and convert vertex coordinates, internal representation as fixed. - for (i = 0; i < numvertexes; i++, li++, ml++) + for (i = 0; i < numvertexes; i++, v++, mv++) { - li->x = SHORT(ml->x)<y = SHORT(ml->y)<x = SHORT(mv->x)<y = SHORT(mv->y)<v1); - v2 = SHORT(ml->v2); + v1 = SHORT(ms->v1); + v2 = SHORT(ms->v2); // e6y - // check and fix wrong references to non-existent vertexes - // see e1m9 @ NIVELES.WAD - // http://www.doomworld.com/idgames/index.php?id=12647 - if ((unsigned)v1 >= numvertexes || (unsigned)v2 >= numvertexes) - { - if ((unsigned)v1 >= numvertexes) - CorruptMapWarning(va("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v1)); - if ((unsigned)v2 >= numvertexes) - CorruptMapWarning(va("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v2)); + // moved down for additional checks to avoid overflow + // if wrong vertexe's indexes are in SEGS lump + // see below for more detailed information - if (li->sidedef == &sides[li->linedef->sidenum[0]]) - { - li->v1 = lines[ml->linedef].v1; - li->v2 = lines[ml->linedef].v2; - } - else - { - li->v1 = lines[ml->linedef].v2; - li->v2 = lines[ml->linedef].v1; - } - } - else - { - li->v1 = &vertexes[v1]; - li->v2 = &vertexes[v2]; - } + seg->angle = (SHORT(ms->angle)) << FRACBITS; + seg->offset = (SHORT(ms->offset)) << FRACBITS; -#ifdef HWRENDER - if (rendermode == render_opengl) - { - li->fv1.x = FixedToFloat(li->v1->x); - li->fv1.y = FixedToFloat(li->v1->y); - //li->fv1.z = FixedToFloat(li->v1->z); // z is unused in gl - - li->fv2.x = FixedToFloat(li->v2->x); - li->fv2.y = FixedToFloat(li->v2->y); - //li->fv2.z = FixedToFloat(li->v2->z); - } -#endif - li->length = P_SegLength(li); - li->angle = (SHORT(ml->angle))<offset = (SHORT(ml->offset))<linedef); + rawlinedef = SHORT(ms->linedef); //e6y: check for wrong indexes if ((unsigned)rawlinedef >= numlines) @@ -546,8 +511,8 @@ static void P_LoadSegs(UINT8 *data) } ldef = &lines[rawlinedef]; - li->linedef = ldef; - rawside = SHORT(ml->side); + seg->linedef = ldef; + rawside = SHORT(ms->side); //e6y: fix wrong side index if (rawside != 0 && rawside != 1) @@ -562,9 +527,9 @@ static void P_LoadSegs(UINT8 *data) I_Error("P_LoadSegs: linedef %d for seg %s references a non-existent sidedef %d", rawlinedef, sizeu1(i), ldef->sidenum[rawside]); } - li->side = rawside; + seg->side = rawside; - li->sidedef = &sides[ldef->sidenum[rawside]]; + seg->sidedef = &sides[ldef->sidenum[rawside]]; /* cph 2006/09/30 - our frontsector can be the second side of the * linedef, so must check for NO_INDEX in case we are incorrectly @@ -572,11 +537,11 @@ static void P_LoadSegs(UINT8 *data) if (ldef->sidenum[rawside] == NO_INDEX) { CorruptMapWarning(va("P_LoadSegs: front of seg %s has no sidedef\n", sizeu1(i))); - li->frontsector = NULL; + seg->frontsector = NULL; } else { - li->frontsector = sides[ldef->sidenum[rawside]].sector; + seg->frontsector = sides[ldef->sidenum[rawside]].sector; } if (ldef->flags & ML_TWOSIDED) @@ -584,15 +549,58 @@ static void P_LoadSegs(UINT8 *data) if (ldef->sidenum[rawside^1] == NO_INDEX) { CorruptMapWarning(va("P_LoadSegs: back of seg %s has no sidedef while being marked as double sided\n", sizeu1(i))); - li->backsector = NULL; + seg->backsector = NULL; } else { - li->backsector = sides[ldef->sidenum[rawside^1]].sector; + seg->backsector = sides[ldef->sidenum[rawside^1]].sector; } } - P_UpdateSegLightOffset(li); + // e6y + // check and fix wrong references to non-existent vertexes + // see e1m9 @ NIVELES.WAD + // http://www.doomworld.com/idgames/index.php?id=12647 + if ((unsigned)v1 >= numvertexes || (unsigned)v2 >= numvertexes) + { + if ((unsigned)v1 >= numvertexes) + CorruptMapWarning(va("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v1)); + if ((unsigned)v2 >= numvertexes) + CorruptMapWarning(va("P_LoadSegs: seg %s references a non-existent vertex %d\n", sizeu1(i), v2)); + + if (seg->sidedef == &sides[seg->linedef->sidenum[0]]) + { + seg->v1 = lines[ms->linedef].v1; + seg->v2 = lines[ms->linedef].v2; + } + else + { + seg->v1 = lines[ms->linedef].v2; + seg->v2 = lines[ms->linedef].v1; + } + } + else + { + seg->v1 = &vertexes[v1]; + seg->v2 = &vertexes[v2]; + } + +#ifdef HWRENDER + if (rendermode == render_opengl) + { + seg->fv1.x = FixedToFloat(seg->v1->x); + seg->fv1.y = FixedToFloat(seg->v1->y); + //seg->fv1.z = FixedToFloat(seg->v1->z); // z is unused in gl + + seg->fv2.x = FixedToFloat(seg->v2->x); + seg->fv2.y = FixedToFloat(seg->v2->y); + //seg->fv2.z = FixedToFloat(seg->v2->z); + } +#endif + + seg->length = P_SegLength(seg); + + P_UpdateSegLightOffset(seg); } } @@ -610,10 +618,6 @@ FUNCINLINE static ATTRINLINE void P_LoadSubsectors(void *data) } } -// -// P_LoadSectors -// - // // levelflats // @@ -665,13 +669,17 @@ static void P_CheckCyanFlat(levelflat_t *levelflat) const char *flatname = W_CheckNameForNum(levelflat->lumpnum); // hack for gba rainbow roads cyan floors - if (UNLIKELY(memcmp(flatname, "GBA_RRF5", 8) == 0 && flatname[8] == 0)) + if (UNLIKELY(flatname && memcmp(flatname, "GBA_RRF5", 8) == 0 && flatname[8] == 0)) { levelflat->cyan = false; return; } const UINT8 *flat = R_GetFlat(levelflat->lumpnum); + + if (!flat) + return; + const size_t size = W_LumpLength(levelflat->lumpnum); for (size_t steppy = 0; steppy < size; steppy++) @@ -791,6 +799,10 @@ INT32 P_CheckLevelFlat(const char *flatname) return (INT32)i; } +// +// P_LoadSectors +// + static const sector_t sector_default = { .nexttag = -1, .firsttag = -1, @@ -1894,7 +1906,7 @@ static void P_ReadBlockMapLump(INT16 *wadblockmaplump, size_t count) // because making both the WAD and PK3 loading code use // the same functions is trickier than it looks for blockmap // -- Monster Iestyn 09/01/18 -static boolean P_LoadRawBlockMap(UINT8 *data, size_t count) +static boolean P_LoadBlockMap(UINT8 *data, size_t count) { if (!count || count >= 0x20000) return false; @@ -2120,7 +2132,7 @@ static void P_LoadMapLUT(const virtres_t* virt) rejectmatrix = NULL; } - if (!(virtblockmap && P_LoadRawBlockMap(virtblockmap->data, virtblockmap->size))) + if (!(virtblockmap && P_LoadBlockMap(virtblockmap->data, virtblockmap->size))) P_CreateBlockMap(); } diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 8a2693c84..3f6b9d449 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1882,7 +1882,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) // big room fix if (longboi) - rw_distance = (fixed_t)R_CalcSegDist(curline,viewx,viewy); + rw_distance = (fixed_t)R_CalcSegDist(curline, viewx, viewy); ds_p->x1 = rw_x = start; ds_p->x2 = stop; From 6e91e00289066aff557092c806a5cbd5f5c25f40 Mon Sep 17 00:00:00 2001 From: romoney5 Date: Fri, 24 Jul 2026 00:43:58 -0400 Subject: [PATCH 04/12] Ignore scenery thinker for player objects Prevents Lua from being able to remove player objects using MF_SCENERY and causing potential crashes --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 6eb30a7ae..8b4f5c5b1 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -9170,7 +9170,7 @@ void P_MobjThinker(mobj_t *mobj) mobj->frame = (mobj->frame & ~FF_TRANSMASK) | (((NUMTRANSMAPS-1) - mobj->fuse / 2) << FF_TRANSSHIFT); // Special thinker for scenery objects - if (mobj->flags & MF_SCENERY) + if (mobj->flags & MF_SCENERY && !mobj->player) { P_MobjSceneryThink(mobj); return; From 7e47b9b6ba44958e5c24db3c8490277c9b1497d8 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 07:35:42 +0200 Subject: [PATCH 05/12] fix crash in K_drawKartMinimapHead if player mobj was removed --- src/k_hud.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/k_hud.c b/src/k_hud.c index c5b166d36..9dbdb935b 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -3581,6 +3581,10 @@ static void K_drawKartMinimapHead(mobj_t *mo, INT32 x, INT32 y, INT32 flags) #endif skin = K_GetMobjSkin(mo); + + if (!skin) + return; + minimaphead = (skinlocal ? localfacemmapprefix : facemmapprefix)[K_GetMobjSkinNum(skin, skinlocal)]; if (minimaphead == NULL) @@ -3784,6 +3788,9 @@ static void K_drawKartMinimap(void) mobj_t *mobj = players[localplayers[i]].mo; + if (!mobj) + continue; + // dont draw for no contestants boolean playertimedout = (mobj->health <= 0 && players[localplayers[i]].pflags & PF_TIMEOVER); From 957d3f72291682753e1f344cb96ebfaa2ca160a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 15:30:56 +0200 Subject: [PATCH 06/12] delet fmt for lua hook profiler i dont want another stinky library this would just be an arsepain to include in windoze builds TODO: make this drawer less of a mess, maybe integrate into perfstats instead? --- src/Makefile | 2 +- src/lua_profile.cpp | 64 ++++++++++++--------------------------------- 2 files changed, 18 insertions(+), 48 deletions(-) diff --git a/src/Makefile b/src/Makefile index 77c9f7129..4ee7cf1a9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -307,7 +307,7 @@ opts+=$(WFLAGS) $(CFLAGS) cxxopts:=$(opts) $(CXXFLAGS) opts+=$(CWFLAGS) # warning flags that shouldnt be passed to c++ compiler -libs+=$(LDFLAGS) -lstdc++ -lpthread -lfmt +libs+=$(LDFLAGS) -lstdc++ -lpthread asflags:=$(ASFLAGS) -x assembler-with-cpp diff --git a/src/lua_profile.cpp b/src/lua_profile.cpp index a25646a74..3c7b1c81f 100644 --- a/src/lua_profile.cpp +++ b/src/lua_profile.cpp @@ -16,9 +16,6 @@ #include #include -#include -#include - extern "C" { #include "blua/lua.h" }; @@ -93,7 +90,8 @@ lua_timer_t* LUA_BeginFunctionTimer(lua_State* L, int fn_idx, const char* name) return view; }; - auto [it, ins] = g_tic_timers.try_emplace(fmt::format("{}:{} ({})", label(), ar.linedefined, name)); + // i sure hope this std::string mess is fine... + auto [it, ins] = g_tic_timers.try_emplace(std::string(va("%s:%d (%s)", std::string(label()).c_str(), ar.linedefined, name))); auto& [key, timer] = *it; g_time_reference = I_GetPreciseTime(); @@ -145,10 +143,7 @@ void LUA_ResetTicTimers(void) void LUA_RenderTimers(void) { - ///using srb2::Draw; - constexpr int kRowHeight = 4; - //constexpr float kScale = 0.5f; // pretty much what the whole srb2::Draw does lol auto draw_row = [](float x, float y, INT32 flags, const std::string& str) @@ -162,15 +157,11 @@ void LUA_RenderTimers(void) }; float row_y = kRowHeight - 60; - draw_row(0.f, row_y - kRowHeight, 0, fmt::format("-- AVERAGES PER TIC (over {} tics) --", cv_lua_profile.value)); - - //Draw row = Draw(0, kRowHeight).font(Draw::Font::kConsole).align(Draw::Align::kLeft).scale(0.5).flags(V_MONOSPACE); - //row.y(-kRowHeight).text("-- AVERAGES PER TIC (over {} tics) --", cv_lua_profile.value); + draw_row(0.f, row_y - kRowHeight, 0, va("-- AVERAGES PER TIC (over %d tics) --", cv_lua_profile.value)); if (g_invalid) { row_y += kRowHeight; - //row.flags(V_GRAYMAP).text(" "); draw_row(0.f, row_y - kRowHeight, V_GRAYMAP, " "); return; } @@ -209,36 +200,26 @@ void LUA_RenderTimers(void) } } - /* - Draw tally = row.flags(color_flag(cum * 1'000'000.0)); - - tally.text("{:8.2f} us - TOTAL", cum * 1'000'000.0); - tally.y(kRowHeight).text("{:8.2f} ms", cum * 1000.0); - tally.y(kRowHeight * 2).text( - "{:8.2f}% overhead ({:.2f} / {:.2f}) <-- not counting rendering time", - (cum / g_avg_tic_time) * 100.0, - cum * TICRATE, - g_avg_tic_time * TICRATE - ); - - row = row.y(kRowHeight * 4); - */ - { const INT32 tally_flags = color_flag(cum * 1'000'000.0); - draw_row(0.f, row_y, tally_flags, fmt::format("{:8.2f} us - TOTAL", cum * 1'000'000.0)); - draw_row(0.f, row_y + kRowHeight, tally_flags, fmt::format("{:8.2f} ms", cum * 1000.0)); - draw_row(0.f, row_y + kRowHeight * 2, tally_flags, fmt::format( - "{:8.2f}% overhead ({:.2f} / {:.2f}) <-- not counting rendering time", + draw_row(0.f, row_y, tally_flags, va("%8.2f us - TOTAL", cum * 1'000'000.0)); + draw_row(0.f, row_y + kRowHeight, tally_flags, va("%8.2f ms", cum * 1000.0)); + + // dont need to show this if we didnt capture over time + // this would just show nan or inf anyways + if (std::fpclassify(g_avg_tic_time) != FP_ZERO) + { + draw_row(0.f, row_y + kRowHeight * 2, tally_flags, va( + "%8.2f%% overhead (%.2f / %.2f) <-- not counting rendering time", (cum / g_avg_tic_time) * 100.0, (cum * (double)TICRATE), (g_avg_tic_time * (double)TICRATE) - )); + )); + } } row_y += kRowHeight * 4; // row = row.y(kRowHeight * 4) - } std::sort( @@ -258,22 +239,11 @@ void LUA_RenderTimers(void) double t = timer.avg.time * 1'000'000.0; - /* - row.flags(color_flag(t)).text( - "{:>8.2f} us {:>8.2f} calls - {}", + draw_row(0.f, row_y, color_flag(t), va( + "%8.2f us %8.2f calls - %s", t, timer.avg.calls, - key - ); - - row = row.y(kRowHeight); - */ - - draw_row(0.f, row_y, color_flag(t), fmt::format( - "{:>8.2f} us {:>8.2f} calls - {}", - t, - timer.avg.calls, - key + key.c_str() )); row_y += kRowHeight; // row = row.y(kRowHeight) From e0e8be8d46ecfa0c3211f412f2c6ca11cacfc69e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 15:47:35 +0200 Subject: [PATCH 07/12] perfstats thinkframe maxpage fix from blan + also yoink the ps types to get rid of magic numbers just prevents the cvar being set to a page that does not exist --- src/lua_hooklib.c | 2 +- src/m_perfstats.c | 97 ++++++++++++++++++++--------------------------- src/m_perfstats.h | 10 +++++ 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index b380945ab..52bf99708 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -760,7 +760,7 @@ static void hook_think_frame(int type) const hook_t * map = &hookIds[type]; int k; - const boolean perfstats = (cv_perfstats.value >= 3); + const boolean perfstats = (cv_perfstats.value >= PS_THINKFRAME); if (prepare_hook(&hook, 0, type)) { diff --git a/src/m_perfstats.c b/src/m_perfstats.c index 49a855686..5f1be305f 100644 --- a/src/m_perfstats.c +++ b/src/m_perfstats.c @@ -168,14 +168,14 @@ perfstatrow_t gamelogic_rows[] = { }; perfstatrow_t thinkercount_rows[] = { - {"thnkers", "Thinkers: ", &ps_thinkercount, PS_LEVEL}, - {" mobjs ", " Mobjs: ", &ps_mobjcount, PS_LEVEL}, + {"thnkers" , "Thinkers: ", &ps_thinkercount, PS_LEVEL}, + {" mobjs " , " Mobjs: ", &ps_mobjcount, PS_LEVEL}, {" regular", " Regular: ", &ps_regularcount, PS_LEVEL}, {" scenery", " Scenery: ", &ps_scenerycount, PS_LEVEL}, {" nothink", " Nothink: ", &ps_nothinkcount, PS_HIDE_ZERO|PS_LEVEL}, - {" precip ", " Precipitation: ", &ps_precipcount, PS_LEVEL}, - {" other ", " Other: ", &ps_otherthcount, PS_LEVEL}, - {" remove ", " Pending removal:", &ps_removecount, PS_LEVEL}, + {" precip " , " Precipitation: ", &ps_precipcount, PS_LEVEL}, + {" other " , " Other: ", &ps_otherthcount, PS_LEVEL}, + {" remove " , " Pending removal:", &ps_removecount, PS_LEVEL}, {} }; @@ -605,7 +605,9 @@ static void PS_CountThinkers(void) else if (thinker->function == (actionf_p1)P_MobjThinker) { mobj_t *mobj = (mobj_t*)thinker; + ps_mobjcount.value.i++; + if (mobj->flags & MF_NOTHINK) ps_nothinkcount.value.i++; else if (mobj->flags & MF_SCENERY) @@ -624,49 +626,17 @@ static void PS_CountThinkers(void) ps_precipcount.value.i++; } - - /*for (i = 0; i < NUM_THINKERLISTS; i++) - { - for (thinker = thlist[i].next; thinker != &thlist[i]; thinker = thinker->next) - { - ps_thinkercount.value.i++; - if (thinker->function == (actionf_p1)P_RemoveThinkerDelayed) - ps_removecount.value.i++; - else if (i == THINK_POLYOBJ) - ps_polythcount.value.i++; - else if (i == THINK_MAIN) - ps_mainthcount.value.i++; - else if (i == THINK_MOBJ) - { - if (thinker->function == (actionf_p1)P_MobjThinker) - { - mobj_t *mobj = (mobj_t*)thinker; - ps_mobjcount.value.i++; - if (mobj->flags & MF_NOTHINK) - ps_nothinkcount.value.i++; - else if (mobj->flags & MF_SCENERY) - ps_scenerycount.value.i++; - else - ps_regularcount.value.i++; - } - } - else if (i == THINK_DYNSLOPE) - ps_dynslopethcount.value.i++; - else if (i == THINK_PRECIP) - ps_precipcount.value.i++; - } - }*/ } // Update all metrics that are calculated on every tick. void PS_UpdateTickStats(void) { - if (cv_perfstats.value == 1 && cv_ps_samplesize.value > 1) + if (cv_perfstats.value == PS_RENDER && cv_ps_samplesize.value > 1) { PS_UpdateRowHistories(gamelogicbrief_row, false); } - if (cv_perfstats.value == 2) + if (cv_perfstats.value == PS_LOGIC) { if (PS_IsLevelActive()) { @@ -691,25 +661,25 @@ void PS_UpdateTickStats(void) if (cv_ps_samplesize.value > 1) { - if (cv_perfstats.value >= 3 && PS_IsLevelActive()) + if (cv_perfstats.value >= PS_THINKFRAME && PS_IsLevelActive()) { int i; switch (cv_perfstats.value) { - case 3: + case PS_THINKFRAME: for (i = 0; i < thinkframe_hooks_length; i++) { PS_UpdateMetricHistory(&thinkframe_hooks[i].time_taken, true, false); } break; - case 4: + case PS_PRETHINKFRAME: for (i = 0; i < prethinkframe_hooks_length; i++) { PS_UpdateMetricHistory(&prethinkframe_hooks[i].time_taken, true, false); } break; - case 5: + case PS_POSTTHINKFRAME: for (i = 0; i < postthinkframe_hooks_length; i++) { PS_UpdateMetricHistory(&postthinkframe_hooks[i].time_taken, true, false); @@ -719,6 +689,7 @@ void PS_UpdateTickStats(void) break; } } + if (cv_perfstats.value) { ps_tick_index++; @@ -749,7 +720,7 @@ static void PS_DrawDescriptorHeader(void) int samples_left = max(ps_frame_samples_left, ps_tick_samples_left); int x, y; - if (cv_perfstats.value >= 3) + if (cv_perfstats.value >= PS_THINKFRAME) { x = 2; y = 0; @@ -865,20 +836,19 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) last_mod_name[0] = '\0'; INT32 total = 0; - //Decide page length based and drawn text on choosen thinker type + // Decide page length based and drawn text on choosen thinker type switch (cv_perfstats.value) { - case 3: + case PS_THINKFRAME: { maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); pagestart = min((page - 1)*PAGE_ENTRIES, thinkframe_hooks_length); pageend = min(pagestart + PAGE_ENTRIES, thinkframe_hooks_length); - V_DrawSmallString(MAX_X-50, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "ThinkFrame"); } break; - case 4: + case PS_PRETHINKFRAME: { maxpage = prethinkframe_hooks_length/PAGE_ENTRIES + 1; page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); @@ -887,7 +857,7 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) V_DrawSmallString(MAX_X-60, MAX_Y+2*HEIGHT, V_MONOSPACE | V_GREENMAP, "PreThinkFrame"); } break; - case 5: + case PS_POSTTHINKFRAME: { maxpage = postthinkframe_hooks_length/PAGE_ENTRIES + 1; page = max(1, min(cv_ps_thinkframe_page.value, maxpage)); @@ -975,7 +945,22 @@ static void draw_think_frame_stats(int hook_length, ps_hookinfo_t *hook) void PS_ThinkFrame_Page_OnChange(void) { - int maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; + int maxpage = 0; + + switch (cv_perfstats.value) + { + case PS_THINKFRAME: + maxpage = thinkframe_hooks_length/PAGE_ENTRIES + 1; + break; + case PS_PRETHINKFRAME: + maxpage = prethinkframe_hooks_length/PAGE_ENTRIES + 1; + break; + case PS_POSTTHINKFRAME: + maxpage = postthinkframe_hooks_length/PAGE_ENTRIES + 1; + break; + default: + break; + } if (cv_ps_thinkframe_page.value > maxpage) CV_StealthSetValue(&cv_ps_thinkframe_page, maxpage); @@ -1008,18 +993,18 @@ static void PS_DrawPostThinkFrameStats(void) void M_DrawPerfStats(void) { - if (cv_perfstats.value == 1) // rendering + if (cv_perfstats.value == PS_RENDER) // rendering { PS_UpdateFrameStats(); PS_DrawRenderStats(); } - else if (cv_perfstats.value == 2) // logic + else if (cv_perfstats.value == PS_LOGIC) // logic { // PS_UpdateTickStats is called in TryRunTics, since otherwise it would miss // tics when frame skips happen PS_DrawGameLogicStats(); } - else if (cv_perfstats.value >= 3) // lua thinkframe + else if (cv_perfstats.value >= PS_THINKFRAME) // lua thinkframe { if (!PS_IsLevelActive()) return; @@ -1036,13 +1021,13 @@ void M_DrawPerfStats(void) switch (cv_perfstats.value) { - case 3: + case PS_THINKFRAME: PS_DrawThinkFrameStats(); break; - case 4: + case PS_PRETHINKFRAME: PS_DrawPreThinkFrameStats(); break; - case 5: + case PS_POSTTHINKFRAME: PS_DrawPostThinkFrameStats(); break; default: diff --git a/src/m_perfstats.h b/src/m_perfstats.h index 083656d61..e6f6739f3 100644 --- a/src/m_perfstats.h +++ b/src/m_perfstats.h @@ -26,6 +26,16 @@ typedef struct void *history; } ps_metric_t; +typedef enum +{ + PS_OFF = 0, + PS_RENDER, + PS_LOGIC, + PS_THINKFRAME, + PS_PRETHINKFRAME, + PS_POSTTHINKFRAME +} ps_types_t; + typedef struct { ps_metric_t time_taken; From c401926c0b07264d4fe0ddd4e69b0639fdc77c29 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 15:43:50 +0200 Subject: [PATCH 08/12] fix lua hook profiler drawing out of screen bounds in some cases this omits alot of hooks in the profiler, tho not sure if anyone should even care about those back in the list maybe just have it have multiple pages like perfstats, or better just integrate it into perfstats...... --- src/lua_profile.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lua_profile.cpp b/src/lua_profile.cpp index 3c7b1c81f..bf68035b8 100644 --- a/src/lua_profile.cpp +++ b/src/lua_profile.cpp @@ -144,6 +144,7 @@ void LUA_ResetTicTimers(void) void LUA_RenderTimers(void) { constexpr int kRowHeight = 4; + float row_y = kRowHeight; // pretty much what the whole srb2::Draw does lol auto draw_row = [](float x, float y, INT32 flags, const std::string& str) @@ -156,13 +157,11 @@ void LUA_RenderTimers(void) ); }; - float row_y = kRowHeight - 60; - draw_row(0.f, row_y - kRowHeight, 0, va("-- AVERAGES PER TIC (over %d tics) --", cv_lua_profile.value)); + draw_row(0.f, 0.f, 0, va("-- AVERAGES PER TIC (over %d tics) --", cv_lua_profile.value)); if (g_invalid) { - row_y += kRowHeight; - draw_row(0.f, row_y - kRowHeight, V_GRAYMAP, " "); + draw_row(0.f, row_y, V_GRAYMAP, " "); return; } @@ -219,7 +218,7 @@ void LUA_RenderTimers(void) } } - row_y += kRowHeight * 4; // row = row.y(kRowHeight * 4) + row_y += kRowHeight * 4; } std::sort( @@ -246,7 +245,7 @@ void LUA_RenderTimers(void) key.c_str() )); - row_y += kRowHeight; // row = row.y(kRowHeight) + row_y += kRowHeight; // FIXME this is all ugly and sucks if (row_y >= BASEVIDHEIGHT) From 5c7be859779f05f36d68a8409294bb59a44b943f Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 15:50:26 +0200 Subject: [PATCH 09/12] fix cmake .ch.......... --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 864a5870c..85ced4e54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -291,7 +291,7 @@ if(${SRB2_CONFIG_HAVE_BLUA}) lua_hook.h lua_hud.h lua_hudlib_drawlist.h - lua_profile.ch + lua_profile.h lua_libs.h lua_script.h lua_udatalib.h From 0c440d240c4464fec1e59006a55f7b6e92ba8e11 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 15:54:37 +0200 Subject: [PATCH 10/12] can pass char to this now no need to reconvert this stuff from const char to std::string and back to const char really lol --- src/lua_profile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_profile.cpp b/src/lua_profile.cpp index bf68035b8..d910c5d65 100644 --- a/src/lua_profile.cpp +++ b/src/lua_profile.cpp @@ -147,13 +147,13 @@ void LUA_RenderTimers(void) float row_y = kRowHeight; // pretty much what the whole srb2::Draw does lol - auto draw_row = [](float x, float y, INT32 flags, const std::string& str) + auto draw_row = [](float x, float y, INT32 flags, const char *str) { V_DrawSmallStringAtFixed( FloatToFixed(x), FloatToFixed(y), V_MONOSPACE|V_ALLOWLOWERCASE|flags, - str.c_str() + str ); }; From 4631844c9ff13b8389a6b121b9c72fe4bc6d88b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 16:07:14 +0200 Subject: [PATCH 11/12] revert removing the slopelanding dupe dont think this would cause any issues at all, but i dont feel like maybe causing some dumbass edge cases anywhere really can test this further after v10 release since its already taking ages --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 8b4f5c5b1..cc62c6cab 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -2573,7 +2573,7 @@ static void P_PlayerZMovement(mobj_t *mo) P_SetPlayerMobjState(mo, S_KART_STND1); } -#if 0 // praying that removing this dupe wont cause any issues... +#if 1 // praying that removing this dupe wont cause any issues... if (!mo->standingslope && (mo->eflags & MFE_VERTICALFLIP ? tmceilingslope : tmfloorslope)) { // Handle landing on slope during Z movement From 7878e01e3f10e3114b5f40223d478fee73d2ba1e Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 24 Jul 2026 16:15:48 +0200 Subject: [PATCH 12/12] update copyrights for "core" folder --- src/core/memory.cpp | 6 +++--- src/core/memory.h | 6 +++--- src/core/static_vec.hpp | 6 +++--- src/core/thread_pool.cpp | 6 +++--- src/core/thread_pool.h | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 81ba79d5d..e0289a579 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -1,7 +1,7 @@ -// BLANKART +// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- -// Copyright (C) 2024 by Ronald "Eidolon" Kinard -// Copyright (C) 2024 by Kart Krew +// Copyright (C) 2025 by Ronald "Eidolon" Kinard +// Copyright (C) 2025 by Kart Krew // // This program is free software distributed under the // terms of the GNU General Public License, version 2. diff --git a/src/core/memory.h b/src/core/memory.h index 4aec917d7..14b51a039 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -1,7 +1,7 @@ -// SONIC ROBO BLAST 2 KART +// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- -// Copyright (C) 2024 by Ronald "Eidolon" Kinard -// Copyright (C) 2024 by Kart Krew +// Copyright (C) 2025 by Ronald "Eidolon" Kinard +// Copyright (C) 2025 by Kart Krew // // This program is free software distributed under the // terms of the GNU General Public License, version 2. diff --git a/src/core/static_vec.hpp b/src/core/static_vec.hpp index c1f486a2b..f31f17939 100644 --- a/src/core/static_vec.hpp +++ b/src/core/static_vec.hpp @@ -1,7 +1,7 @@ -// SONIC ROBO BLAST 2 KART +// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- -// Copyright (C) 2024 by Ronald "Eidolon" Kinard -// Copyright (C) 2024 by Kart Krew +// Copyright (C) 2025 by Ronald "Eidolon" Kinard +// Copyright (C) 2025 by Kart Krew // // This program is free software distributed under the // terms of the GNU General Public License, version 2. diff --git a/src/core/thread_pool.cpp b/src/core/thread_pool.cpp index 11aa6f1bb..c716b6470 100644 --- a/src/core/thread_pool.cpp +++ b/src/core/thread_pool.cpp @@ -1,7 +1,7 @@ -// BLANKART +// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- -// Copyright (C) 2024 by Ronald "Eidolon" Kinard -// Copyright (C) 2024 by Kart Krew +// Copyright (C) 2025 by Ronald "Eidolon" Kinard +// Copyright (C) 2025 by Kart Krew // // This program is free software distributed under the // terms of the GNU General Public License, version 2. diff --git a/src/core/thread_pool.h b/src/core/thread_pool.h index 71eebdaf1..0c1fc88ad 100644 --- a/src/core/thread_pool.h +++ b/src/core/thread_pool.h @@ -1,7 +1,7 @@ -// SONIC ROBO BLAST 2 KART +// DR. ROBOTNIK'S RING RACERS //----------------------------------------------------------------------------- -// Copyright (C) 2024 by Ronald "Eidolon" Kinard -// Copyright (C) 2024 by Kart Krew +// Copyright (C) 2025 by Ronald "Eidolon" Kinard +// Copyright (C) 2025 by Kart Krew // // This program is free software distributed under the // terms of the GNU General Public License, version 2.