From 7932c1af6f66b1ed6ff94bd0eedaaa79b506eb8a Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 27 May 2025 18:30:55 +0200 Subject: [PATCH 01/14] Print the current SDL_mixer version when initializing the sound system --- src/sdl/mixer_sound.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 647958653..fbdf6d005 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -213,7 +213,17 @@ void I_StartupSound(void) // call to start audio failed -- we do not have it return; } - + + SDL_version SDLmixcompiled; + const SDL_version *SDLmixlinked; + SDL_MIXER_VERSION(&SDLmixcompiled) + SDLmixlinked = Mix_Linked_Version(); + + I_OutputMsg("Compiled for SDL_mixer version: %d.%d.%d\n", + SDLmixcompiled.major, SDLmixcompiled.minor, SDLmixcompiled.patch); + I_OutputMsg("Linked with SDL_mixer version: %d.%d.%d\n", + SDLmixlinked->major, SDLmixlinked->minor, SDLmixlinked->patch); + #ifdef HAVE_OPENMPT CONS_Printf("libopenmpt version: %s\n", openmpt_get_string("library_version")); CONS_Printf("libopenmpt build date: %s\n", openmpt_get_string("build")); From e8969b0645fa760538b80c44fd5195497a5a8d46 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 27 May 2025 18:30:30 +0200 Subject: [PATCH 02/14] dont always print openmpt version to console just use I_OutputMsg instead --- src/sdl/mixer_sound.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index fbdf6d005..9035e8241 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -225,8 +225,8 @@ void I_StartupSound(void) SDLmixlinked->major, SDLmixlinked->minor, SDLmixlinked->patch); #ifdef HAVE_OPENMPT - CONS_Printf("libopenmpt version: %s\n", openmpt_get_string("library_version")); - CONS_Printf("libopenmpt build date: %s\n", openmpt_get_string("build")); + I_OutputMsg("libopenmpt version: %s\n", openmpt_get_string("library_version")); + I_OutputMsg("libopenmpt build date: %s\n", openmpt_get_string("build")); #endif sound_started = true; From b6923d0d0dc7e4ee18d4ac3a7507c7dbb0a95a63 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 16:18:13 +0200 Subject: [PATCH 03/14] readd flexible array for softwarepatch columnofs how did this ever work lel --- src/r_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_defs.h b/src/r_defs.h index 95f8a796d..a202b49ef 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -668,7 +668,7 @@ typedef struct INT16 height; INT16 leftoffset; // pixels to the left of origin INT16 topoffset; // pixels below the origin - INT32 columnofs[8]; // only [width] used + INT32 columnofs[]; // only [width] used // the [0] is &columnofs[width] } ATTRPACK softwarepatch_t; From 1219ecf818581959f6afab9ced175904816c2f92 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 16:26:26 +0200 Subject: [PATCH 04/14] check for 32bit with __SIZEOF_POINTER__ for precip drawdistance thx @chromaticpipe for the tip! --- src/r_main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 5a7d77acd..f16d138ee 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -125,16 +125,17 @@ static CV_PossibleValue_t drawdist_cons_t[] = { {8192, "8192"}, {12288, "12288"}, {20480, "20480"}, {24576, "24576"},{0, "Infinite"}, {0, NULL}}; -#if defined(__x86_64__) || defined(__amd64__) || defined(__aarch64__) || defined(__arm64__) // only for 64bit (idk how else to proper check lmao) +#if __SIZEOF_POINTER__ < 8 // only for 64bit static CV_PossibleValue_t drawdist_precip_cons_t[] = { - {256, "256"}, {512, "512"}, {768, "768"}, + {256, "256"}, {512, "512"}, {768, "768"}, {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, - {3072, "3072"}, {4096, "4096"}, {0, "None"}, {0, NULL}}; + {0, "None"}, {0, NULL}}; + #else static CV_PossibleValue_t drawdist_precip_cons_t[] = { - {256, "256"}, {512, "512"}, {768, "768"}, - {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, - {0, "None"}, {0, NULL}}; + {256, "256"}, {512, "512"}, {768, "768"}, + {1024, "1024"}, {1536, "1536"}, {2048, "2048"}, + {3072, "3072"}, {4096, "4096"}, {0, "None"}, {0, NULL}}; #endif static CV_PossibleValue_t maxinterpdist_cons_t[] = { From 18914f22f20e204917d50824645639b6ee0418b0 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 18:29:18 +0200 Subject: [PATCH 05/14] remove crappy memcpy redifine from md5 --- src/md5.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/md5.c b/src/md5.c index 66d563666..8292fb9ee 100644 --- a/src/md5.c +++ b/src/md5.c @@ -26,12 +26,6 @@ #if defined (STDC_HEADERS) || defined (_LIBC) #include -#else - #ifndef HAVE_MEMCPY - #if !(defined (_WIN32) && !defined (__CYGWIN__)) && !defined (__APPLE__) - #define memcpy(d, s, n) bcopy ((s), (d), (n)) - #endif - #endif #endif #include "md5.h" From 346dee019ca4e7571be7baf83104e2bd43c2b17b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 18:30:26 +0200 Subject: [PATCH 06/14] fix compiler warning bout playeringame --- src/d_clisrv.c | 14 +++++++------- src/d_netcmd.c | 7 ++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9625934fc..98b4b1e55 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1693,7 +1693,7 @@ static void SV_SendPlayerInfo(INT32 node) continue; } - if (playeringame[i] == UINT8_MAX || !playeringame[i]) + if (playernode[i] == UINT8_MAX || !playeringame[i]) { netbuffer->u.playerinfo[i].node = 255; // This slot is empty. continue; @@ -5324,18 +5324,18 @@ static void HandlePacketFromPlayer(SINT8 node) /// \todo Use a separate cvar for that kind of timeout? freezetimeout[node] = I_GetTime() + connectiontimeout; - // If we've alredy received a ticcmd for this tic, just submit it for the next one. - tic_t faketic = maketic; - if ((!!(netcmds[maketic % TICQUEUE][netconsole].angleturn & TICCMD_RECEIVED)) - && (maketic - firstticstosend < TICQUEUE - 1)) - faketic++; - // Don't do anything for packets of type NODEKEEPALIVE? // Sryder 2018/07/01: Update the freezetimeout still! if (netbuffer->packettype == PT_NODEKEEPALIVE || netbuffer->packettype == PT_NODEKEEPALIVEMIS) break; + // If we've alredy received a ticcmd for this tic, just submit it for the next one. + tic_t faketic = maketic; + if ((!!(netcmds[maketic % TICQUEUE][netconsole].angleturn & TICCMD_RECEIVED)) + && (maketic - firstticstosend < TICQUEUE - 1)) + faketic++; + // Copy ticcmd G_MoveTiccmd(&netcmds[faketic%TICQUEUE][netconsole], &netbuffer->u.clientpak.cmd, 1); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 5b8a8c18b..862ebb679 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -216,11 +216,8 @@ static CV_PossibleValue_t teamscramble_cons_t[] = {{0, "Off"}, {1, "Random"}, {2 static CV_PossibleValue_t startingliveslimit_cons_t[] = {{1, "MIN"}, {99, "MAX"}, {0, NULL}}; static CV_PossibleValue_t sleeping_cons_t[] = {{0, "MIN"}, {1000/TICRATE, "MAX"}, {0, NULL}}; -static CV_PossibleValue_t competitionboxes_cons_t[] = {{0, "Normal"}, {1, "Random"}, {2, "Teleports"}, - {3, "None"}, {0, NULL}}; - -static CV_PossibleValue_t matchboxes_cons_t[] = {{0, "Normal"}, {1, "Random"}, {2, "Non-Random"}, - {3, "None"}, {0, NULL}}; +static CV_PossibleValue_t competitionboxes_cons_t[] = {{0, "Normal"}, {1, "Random"}, {2, "Teleports"}, {3, "None"}, {0, NULL}}; +static CV_PossibleValue_t matchboxes_cons_t[] = {{0, "Normal"}, {1, "Random"}, {2, "Non-Random"}, {3, "None"}, {0, NULL}}; //static CV_PossibleValue_t chances_cons_t[] = {{0, "MIN"}, {9, "MAX"}, {0, NULL}}; static CV_PossibleValue_t match_scoring_cons_t[] = {{0, "Normal"}, {1, "Classic"}, {0, NULL}}; From 19e5366c5bef6d2b98825a3fbc1847d614b2fa94 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 18:31:21 +0200 Subject: [PATCH 07/14] add wireframe mode for ogl --- src/hardware/hw_main.c | 20 ++++++++++++++++++-- src/hardware/hw_main.h | 2 ++ src/hardware/r_opengl/r_opengl.c | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 94767ff5d..0f308017d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -226,6 +226,8 @@ consvar_t cv_glsolvetjoin = {"gr_solvetjoin", "On", 0, CV_OnOff, NULL, 0, NULL, consvar_t cv_glbatching = {"gr_batching", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_glwireframe = {"gr_wireframe", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_glrenderdistance = {"gr_renderdistance", "Max", CV_SAVE, glrenderdistance_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_glhorizonlines = {"gr_horizonlines", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -338,6 +340,12 @@ static void HWR_SetShaderState(void) GL_SetSpecialState(HWD_SET_SHADERS, HWR_UseShader() ? 1 : 0); } + +static boolean HWR_IsWireframeMode(void) +{ + return (cv_glwireframe.value /*&& cv_debug*/); +} + static boolean HWR_OverrideObjectLightLevel(mobj_t *thing, INT32 *lightlevel) { if (R_ThingIsFullBright(thing)) @@ -5259,6 +5267,9 @@ static void HWR_DrawSkyBackground(void) if (drewsky) return; + if (HWR_IsWireframeMode()) + return; + GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); memcpy(&dometransform, &atransform, sizeof(FTransform)); @@ -5461,8 +5472,8 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl HWR_PortalClipping(rootportal); } - // Set transform. - GL_SetTransform(&atransform); + if (HWR_IsWireframeMode()) + GL_SetSpecialState(HWD_SET_WIREFRAME, 1); ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; @@ -5527,6 +5538,9 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, const float fpov, player_t *pl ps_hw_nodedrawtime.value.p = 0; HWR_RenderDrawNodes(); + if (HWR_IsWireframeMode()) + GL_SetSpecialState(HWD_SET_WIREFRAME, 0); + HWR_FreePortalList(portallist); } @@ -5801,6 +5815,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_glbatching); + CV_RegisterVar(&cv_glwireframe); + CV_RegisterVar(&cv_glrenderdistance); CV_RegisterVar(&cv_glhorizonlines); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index b8d6ef939..87b1faaf4 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -202,6 +202,8 @@ extern consvar_t cv_glsolvetjoin; extern consvar_t cv_glbatching; +extern consvar_t cv_glwireframe; + extern consvar_t cv_glrenderdistance; extern consvar_t cv_glhorizonlines; diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 12ec0cd97..07ceaf86f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -350,6 +350,8 @@ typedef void (APIENTRY * PFNglDisable) (GLenum cap); static PFNglDisable pglDisable; typedef void (APIENTRY * PFNglGetFloatv) (GLenum pname, GLfloat *params); static PFNglGetFloatv pglGetFloatv; +typedef void (APIENTRY * PFNglPolygonMode) (GLenum, GLenum); +static PFNglPolygonMode pglPolygonMode; /* Depth Buffer */ typedef void (APIENTRY * PFNglClearDepth) (GLclampd depth); @@ -549,6 +551,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglGetFloatv, glGetFloatv) GETOPENGLFUNC(pglGetIntegerv, glGetIntegerv) GETOPENGLFUNC(pglGetString, glGetString) + GETOPENGLFUNC(pglPolygonMode, glPolygonMode) GETOPENGLFUNC(pglClearDepth, glClearDepth) GETOPENGLFUNC(pglDepthFunc, glDepthFunc) @@ -2364,6 +2367,10 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) GL_Flush(); //??? if we want to change filter mode by texture, remove this break; + case HWD_SET_WIREFRAME: + pglPolygonMode(GL_FRONT_AND_BACK, Value ? GL_LINE : GL_FILL); + break; + case HWD_SET_TEXTURE_FORMAT: gltexformat = (Value == 32) ? GL_RGBA : GL_RGB5_A1; GL_Flush(); From f15d3be263cad5ee319646cad281ef89283ac730 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 28 May 2025 16:37:37 +0100 Subject: [PATCH 08/14] forgor the hw state lel --- src/hardware/hw_defs.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 08cce42c9..1da42770a 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -318,6 +318,8 @@ enum hwdsetspecialstate HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, + HWD_SET_WIREFRAME, + HWD_SET_MSAA, HWD_SET_SCREEN_TEXTURES, From 279dfcafc41788b27bbba298d7aa0cea481b1ede Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 28 May 2025 22:10:25 +0300 Subject: [PATCH 09/14] Expose S_FindMusicCredit and musiccredit_t to lua --- src/lua_infolib.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ src/lua_libs.h | 6 +++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 3ff2d97ae..08e26a48b 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -16,6 +16,7 @@ #include "dehacked.h" #include "p_mobj.h" #include "p_local.h" +#include "s_sound.h" #include "z_zone.h" #include "lua_script.h" @@ -1072,6 +1073,72 @@ static int sfxinfo_num(lua_State *L) return 1; } +enum musicdef_e { + musicdef_name = 0, + musicdef_usage, + musicdef_source, + musicdef_filename, + musicdef_title, + musicdef_alttitle, + musicdef_authors, +}; + +const char *const musicdef_opt[] = { + "name", + "usage", + "source", + "filename", + "title", + "alttitle", + "authors", + NULL +}; + +static int musicdef_fields_ref = LUA_NOREF; + +static int lib_sFindMusicCredit(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + LUA_PushUserdata(L, S_FindMusicCredit(name), META_MUSICDEF); + return 1; +} + +static int musicdef_get(lua_State *L) +{ + musicdef_t *musicdef = *((musicdef_t **)luaL_checkudata(L, 1, META_MUSICDEF)); + enum musicdef_e field = Lua_optoption(L, 2, -1, musicdef_fields_ref); + + I_Assert(musicdef != NULL); + + switch (field) + { + case musicdef_name: + lua_pushstring(L, musicdef->name); + return 1; + case musicdef_usage: + lua_pushstring(L, musicdef->usage); + return 1; + case musicdef_source: + lua_pushstring(L, musicdef->source); + return 1; + case musicdef_filename: + lua_pushstring(L, musicdef->filename); + return 1; + case musicdef_title: + lua_pushstring(L, musicdef->title); + return 1; + case musicdef_alttitle: + lua_pushstring(L, musicdef->alttitle); + return 1; + case musicdef_authors: + lua_pushstring(L, musicdef->authors); + return 1; + default: + return luaL_error(L, LUA_QL("musicdef_t") " has no field named " LUA_QS, lua_tostring(L, 2)); + } + return 0; +} + ////////////////////////////// // // Now push all these functions into the Lua state! @@ -1126,6 +1193,15 @@ int LUA_InfoLib(lua_State *L) sfxinfo_fields_ref = Lua_CreateFieldTable(L, sfxinfo_opt); + luaL_newmetatable(L, META_MUSICDEF); + lua_pushcfunction(L, musicdef_get); + lua_setfield(L, -2, "__index"); + lua_pop(L, 1); + + musicdef_fields_ref = Lua_CreateFieldTable(L, musicdef_opt); + + lua_register(L, "S_FindMusicCredit", lib_sFindMusicCredit); + lua_newuserdata(L, 0); lua_createtable(L, 0, 2); lua_pushcfunction(L, lib_getSprname); diff --git a/src/lua_libs.h b/src/lua_libs.h index c226c4714..729cea68d 100644 --- a/src/lua_libs.h +++ b/src/lua_libs.h @@ -10,6 +10,9 @@ /// \file lua_libs.h /// \brief libraries for Lua scripting +#include "doomtype.h" +#include "blua/lua.h" + extern lua_State *gL; #define LREG_VALID "VALID_USERDATA" @@ -20,6 +23,7 @@ extern lua_State *gL; #define META_STATE "STATE_T*" #define META_MOBJINFO "MOBJINFO_T*" #define META_SFXINFO "SFXINFO_T*" +#define META_MUSICDEF "MUSICDEF_T*" #define META_MOBJ "MOBJ_T*" #define META_MAPTHING "MAPTHING_T*" @@ -68,4 +72,4 @@ int LUA_SkinLib(lua_State *L); int LUA_ThinkerLib(lua_State *L); int LUA_MapLib(lua_State *L); int LUA_BlockmapLib(lua_State *L); -int LUA_HudLib(lua_State *L); \ No newline at end of file +int LUA_HudLib(lua_State *L); From 359befd85722f341e44822ad434e75741d09d541 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 28 May 2025 23:27:30 +0300 Subject: [PATCH 10/14] Add MusicCredit lua hook --- src/lua_hook.h | 2 ++ src/lua_hooklib.c | 12 ++++++++++++ src/s_sound.c | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 45237aa80..c31a58a67 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -55,6 +55,7 @@ X (PlayerQuit),\ X (PlayerThink),/* P_PlayerThink */\ X (MusicChange),\ + X (MusicCredit),\ X (ShouldSpin),/*SRB2KART*/\ X (ShouldExplode),/*SRB2KART*/\ X (ShouldSquish),/*SRB2KART*/\ @@ -130,6 +131,7 @@ int LUA_HookPlayerCanDamage(player_t *, mobj_t *); void LUA_HookPlayerQuit(player_t *, int); int LUA_HookPlayerCmd(player_t *, ticcmd_t *); int LUA_HookMusicChange(const char *oldname, struct MusicChange *); +int LUA_HookMusicCredit(musicdef_t *musicdef); int LUA_HookShouldSpin(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be spun out? int LUA_HookShouldExplode(player_t *player, mobj_t *inflictor, mobj_t *source); // SRB2KART: Should player be exploded? diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index a0f795985..1ef02b886 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -1065,6 +1065,18 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param) return hook.status; } +int LUA_HookMusicCredit(musicdef_t *musicdef) +{ + Hook_State hook; + if (prepare_hook(&hook, 0, HOOK(MusicCredit))) + { + LUA_PushUserdata(gL, musicdef, META_MUSICDEF); + call_hooks(&hook, 1, res_true); + } + + return hook.status; +} + static int kartdamage_hook ( player_t *player, diff --git a/src/s_sound.c b/src/s_sound.c index 922d864d5..ab9a1a2d7 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -32,6 +32,7 @@ #include "m_menu.h" // bird music stuff #include "lua_hook.h" // MusicChange hook +#include "lua_hud.h" // LUA_HudEnabled(hud_musiccredit) static boolean S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, INT32 *vol, INT32 *sep, INT32 *pitch, sfxinfo_t *sfxinfo); static void SetChannelsNum(void); @@ -1452,7 +1453,7 @@ void S_ShowSpecifiedMusicCredit(const char *musname) def = S_FindMusicCredit(musname); - if (def) + if (def && !LUA_HookMusicCredit(def)) { cursongcredit.def = def; cursongcredit.anim = 5*TICRATE; From 68ae8809791b1012e88724dc1ca3d8629ced02c0 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 31 May 2025 18:04:08 +0300 Subject: [PATCH 11/14] Change the way how musicdefs are stored (preparing for exposing them to lua) --- src/m_menu.c | 38 ++++++++++---------- src/s_sound.c | 98 +++++++++++++++++++++++++++++---------------------- src/s_sound.h | 11 ++---- 3 files changed, 77 insertions(+), 70 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2fb38a4d5..9e9fbe1c9 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -8458,7 +8458,7 @@ static void M_MusicTest(INT32 choice) { (void)choice; - if (!S_PrepareSoundTest()) + if (!nummusicdefs) { M_StartMessage(M_GetText("No selectable tracks found.\n"),NULL,MM_NOTHING); return; @@ -8537,33 +8537,33 @@ static void M_DrawMusicTest(void) { INT32 t, b, q, m = 128; - if (numsoundtestdefs <= 8) + if (nummusicdefs <= 8) { t = 0; - b = numsoundtestdefs - 1; + b = nummusicdefs - 1; i = 0; } else { q = m; - m = (5*m)/numsoundtestdefs; + m = (5*m)/nummusicdefs; if (st_sel < 3) { t = 0; b = 7; i = 0; } - else if (st_sel >= numsoundtestdefs-4) + else if (st_sel >= nummusicdefs-4) { - t = numsoundtestdefs - 8; - b = numsoundtestdefs - 1; + t = nummusicdefs - 8; + b = nummusicdefs - 1; i = q-m; } else { t = st_sel - 3; b = st_sel + 4; - i = (t * (q-m))/(numsoundtestdefs - 8); + i = (t * (q-m))/(nummusicdefs - 8); } } @@ -8572,7 +8572,7 @@ static void M_DrawMusicTest(void) if (t != 0) V_DrawString(20+280+4, 60+4 - (skullAnimCounter/5), V_YELLOWMAP, "\x1A"); - if (b != numsoundtestdefs - 1) + if (b != nummusicdefs - 1) V_DrawString(20+280+4, 60+128-12 + (skullAnimCounter/5), V_YELLOWMAP, "\x1B"); x = 24; @@ -8586,8 +8586,9 @@ static void M_DrawMusicTest(void) V_DrawFill(20, y-4, 280-1, 16, 237); { + const musicdef_t *def = S_GetMusicCredit(t); const size_t MAXLENGTH = 34; - const char *songname = soundtestdefs[t]->title[0] ? soundtestdefs[t]->title : soundtestdefs[t]->source; + const char *songname = def->title[0] ? def->title : def->source; size_t namelength = strlen(songname); @@ -8600,7 +8601,7 @@ static void M_DrawMusicTest(void) buf[MAXLENGTH] = 0; V_DrawString(x, y, (t == st_sel ? V_YELLOWMAP : 0)|V_ALLOWLOWERCASE|V_MONOSPACE, buf); - if (curplaying == soundtestdefs[t]) + if (curplaying == def) { V_DrawFill(20+280-9, y-4, 8, 16, 230); } @@ -8618,7 +8619,7 @@ static void M_HandleMusicTest(INT32 choice) switch (choice) { case KEY_DOWNARROW: - if (st_sel++ >= numsoundtestdefs-1) + if (st_sel++ >= nummusicdefs-1) st_sel = 0; { S_StartSound(NULL, sfx_menu1); @@ -8627,18 +8628,18 @@ static void M_HandleMusicTest(INT32 choice) break; case KEY_UPARROW: if (!st_sel--) - st_sel = numsoundtestdefs-1; + st_sel = nummusicdefs-1; { S_StartSound(NULL, sfx_menu1); } st_musictime = 0; break; case KEY_PGDN: - if (st_sel < numsoundtestdefs-1) + if (st_sel < nummusicdefs-1) { st_sel += 3; - if (st_sel >= numsoundtestdefs-1) - st_sel = numsoundtestdefs-1; + if (st_sel >= nummusicdefs-1) + st_sel = nummusicdefs-1; S_StartSound(NULL, sfx_menu1); } st_musictime = 0; @@ -8672,7 +8673,7 @@ static void M_HandleMusicTest(INT32 choice) case KEY_ENTER: S_StopSounds(); S_StopMusic(); - curplaying = soundtestdefs[st_sel]; + curplaying = S_GetMusicCredit(st_sel); S_ChangeMusicInternal(curplaying->name, true); break; @@ -8681,9 +8682,6 @@ static void M_HandleMusicTest(INT32 choice) } if (exitmenu) { - Z_Free(soundtestdefs); - soundtestdefs = NULL; - if (currentMenu->prevMenu) M_SetupNextMenu(currentMenu->prevMenu); else diff --git a/src/s_sound.c b/src/s_sound.c index ab9a1a2d7..e4f15333f 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1203,8 +1203,58 @@ static consvar_t *music_refade_cv; /// Music Definitions /// ------------------------ -musicdef_t *musicdefstart = NULL; // First music definition -struct cursongcredit cursongcredit; // Currently displayed song credit info +// Similar system to vissprite allocation. Exists so external pointers to musicdefs are not invalidated +// when allocating more space for musicdefs +#define MUSICDEFCHUNKBITS 6 +#define MUSICDEFSPERCHUNK (1 << MUSICDEFCHUNKBITS) +#define MUSICDEFINDEXMASK (MUSICDEFSPERCHUNK - 1) +static musicdef_t **musicdefs = NULL; +static INT32 numchunks = 0; +INT32 nummusicdefs = 0; + +// +// S_GetMusicCredit +// +// Return music credit with given index. +// +musicdef_t *S_GetMusicCredit(INT32 i) +{ + if (i < 0 || i >= nummusicdefs) + return NULL; + + INT32 chunk = i >> MUSICDEFCHUNKBITS; + i &= MUSICDEFINDEXMASK; + + return &musicdefs[chunk][i]; +} + +// +// S_AddMusicCredit +// +// Return new music credit, allocates memory for it if needed. +// +static musicdef_t *S_AddMusicCredit(void) +{ + INT32 chunk = nummusicdefs >> MUSICDEFCHUNKBITS; + INT32 i = nummusicdefs & MUSICDEFINDEXMASK; + + // Allocate new chunk if needed. Other chunks stay valid + if (chunk == numchunks) + { + ++numchunks; + musicdefs = (musicdef_t**)Z_Realloc(musicdefs, sizeof(musicdef_t*)*numchunks, PU_STATIC, NULL); + musicdefs[chunk] = Z_Calloc(sizeof(musicdef_t)*MUSICDEFSPERCHUNK, PU_STATIC, NULL); + } + + // Store "id" of new musicdef (mostly exists only for lua) + musicdefs[chunk][i].num = nummusicdefs; + + ++nummusicdefs; + + return &musicdefs[chunk][i]; +} + +struct cursongcredit cursongcredit = {0}; // Currently displayed song credit info static boolean ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) @@ -1232,14 +1282,11 @@ ReadMusicDefFields (UINT16 wadnum, int line, char *stoken, musicdef_t **defp) // Nothing found, add to the end. if (!def) { - def = Z_Calloc(sizeof (musicdef_t), PU_STATIC, NULL); + def = S_AddMusicCredit(); STRBUFCPY(def->name, value); strlwr(def->name); def->hash = quickncasehash (def->name, 6); - - def->next = musicdefstart; - musicdefstart = def; } (*defp) = def; @@ -1424,8 +1471,10 @@ musicdef_t *S_FindMusicCredit(const char *musname) UINT32 hash = quickncasehash (musname, 6); musicdef_t *def; - for (def = musicdefstart; def; def = def->next) + for (INT32 i = 0; i < nummusicdefs; ++i) { + def = S_GetMusicCredit(i); + if (hash != def->hash) continue; if (stricmp(def->name, musname)) @@ -1472,41 +1521,6 @@ void S_ShowMusicCredit(void) S_ShowSpecifiedMusicCredit(music.name); } -musicdef_t **soundtestdefs = NULL; -INT32 numsoundtestdefs = 0; - -// -// S_PrepareSoundTest -// -// Prepare sound test. What am I, your butler? -// -boolean S_PrepareSoundTest(void) -{ - musicdef_t *def; - INT32 pos = numsoundtestdefs = 0; - - for (def = musicdefstart; def; def = def->next) - { - numsoundtestdefs++; - } - - if (!numsoundtestdefs) - return false; - - if (soundtestdefs) - Z_Free(soundtestdefs); - - if (!(soundtestdefs = Z_Malloc(numsoundtestdefs*sizeof(musicdef_t *), PU_STATIC, NULL))) - I_Error("S_PrepareSoundTest(): could not allocate soundtestdefs."); - - for (def = musicdefstart; def /*&& i < numsoundtestdefs*/; def = def->next) - { - soundtestdefs[pos++] = def; - } - - return true; -} - /// ------------------------ /// Music Status /// ------------------------ diff --git a/src/s_sound.h b/src/s_sound.h index 92e206e1b..d909bf63d 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -182,14 +182,9 @@ typedef struct musicdef_s char alttitle[256]; char authors[256]; boolean use_info; - struct musicdef_s *next; + size_t num; } musicdef_t; -extern musicdef_t *musicdefstart; -extern musicdef_t **soundtestdefs; -extern INT32 numsoundtestdefs; -extern UINT8 soundtestpage; - extern struct cursongcredit { musicdef_t *def; @@ -198,17 +193,17 @@ extern struct cursongcredit UINT8 trans; } cursongcredit; +extern INT32 nummusicdefs; void S_LoadMusicDefs(UINT16 wadnum); void S_InitMusicDefs(void); void S_LoadMTDefs(UINT16 wadnum); void S_InitMTDefs(void); +musicdef_t *S_GetMusicCredit(INT32 i); musicdef_t *S_FindMusicCredit(const char *musname); void S_ShowSpecifiedMusicCredit(const char *musname); void S_ShowMusicCredit(void); -boolean S_PrepareSoundTest(void); - // // Music Seeking // From b29ca13916b4fe9ec5934f58a32925198e8af283 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 31 May 2025 18:54:07 +0300 Subject: [PATCH 12/14] Add musicdefs table into lua --- src/lua_infolib.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 08e26a48b..0ac308bcb 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -1103,6 +1103,33 @@ static int lib_sFindMusicCredit(lua_State *L) return 1; } +static int lib_getMusicDef(lua_State *L) +{ + musicdef_t *def = NULL; + + if (lua_isnumber(L, 2)) + def = S_GetMusicCredit(lua_tonumber(L, 2)); + else if (lua_isstring(L, 2)) + def = S_FindMusicCredit(lua_tostring(L, 2)); + else + return luaL_error(L, "musicdefs index must be number or string (got %s)", luaL_typename(L, 2)); + + LUA_PushUserdata(L, def, META_MUSICDEF); + + return 1; +} + +static int lib_setMusicDef(lua_State *L) +{ + return luaL_error(L, "musicdefs is read only"); +} + +static int lib_musicdefslen(lua_State *L) +{ + lua_pushinteger(L, nummusicdefs); + return 1; +} + static int musicdef_get(lua_State *L) { musicdef_t *musicdef = *((musicdef_t **)luaL_checkudata(L, 1, META_MUSICDEF)); @@ -1139,6 +1166,16 @@ static int musicdef_get(lua_State *L) return 0; } +static int musicdef_num(lua_State *L) +{ + musicdef_t *musicdef = *((musicdef_t **)luaL_checkudata(L, 1, META_MUSICDEF)); + + I_Assert(musicdef != NULL); + + lua_pushinteger(L, musicdef->num); + return 1; +} + ////////////////////////////// // // Now push all these functions into the Lua state! @@ -1196,6 +1233,9 @@ int LUA_InfoLib(lua_State *L) luaL_newmetatable(L, META_MUSICDEF); lua_pushcfunction(L, musicdef_get); lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, musicdef_num); + lua_setfield(L, -2, "__len"); lua_pop(L, 1); musicdef_fields_ref = Lua_CreateFieldTable(L, musicdef_opt); @@ -1252,5 +1292,19 @@ int LUA_InfoLib(lua_State *L) lua_pushvalue(L, -1); lua_setglobal(L, "S_sfx"); lua_setglobal(L, "sfxinfo"); + + lua_newuserdata(L, 0); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_getMusicDef); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_setMusicDef); + lua_setfield(L, -2, "__newindex"); + + lua_pushcfunction(L, lib_musicdefslen); + lua_setfield(L, -2, "__len"); + lua_setmetatable(L, -2); + lua_setglobal(L, "musicdefs"); + return 0; } From fab76353730f4c3b519ae5013b26bbdb6f0d65ec Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 31 May 2025 19:10:58 +0300 Subject: [PATCH 13/14] Add musicdef lua stuff into LUASTUFF.md --- LUASTUFF.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/LUASTUFF.md b/LUASTUFF.md index 8960fad48..3853f6e43 100644 --- a/LUASTUFF.md +++ b/LUASTUFF.md @@ -161,6 +161,32 @@ Duration is in milliseconds and is optional to set, default value is 84ms. Exactly same as P_CheckSight but uses cheaper algorithm, useful for things like nametags. Doesn't work exactly like P_CheckSight so don't use it for anything gameplay-related. +## musicdef_t + +Userdata structure representing a musicdef. Fields: + +`musicdef.name` - song identifier ("kmap01" for example). + +`musicdef.usage`, `musicdef.source` - fields from vanilla MUSICDEFS lump. + +`musicdef.filename` - unused for now. + +`musicdef.title`, `musicdef.alttitle`, `musicdef.authors` - fields from MUSCINFO lump. + +`#musicdef` - returns integer id for musicdef (which can be used as index in `musicdefs`). + +All fields are read-only. + +## S_FindMusicCredit(name) + +Returns musicdef corresponding to music with given identifier. For example, `S_FindMusicCredit("kmap01")` will return +musicdef for green hills music. + +## musicdefs + +Global table for all musicdefs, similar to mobjinfo, states, etc. Can take either integer indices, +from `0` to `#musicdefs-1`, or string indices (which is equal to calling `S_FindMusicCredit`). + # Other changes ## P_PlayRinglossSound(source, damager) From 8fb17756062c14247f88ff63b60ad72e90ea877f Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 31 May 2025 19:15:04 +0300 Subject: [PATCH 14/14] Forgot MusicCredit hook --- LUASTUFF.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/LUASTUFF.md b/LUASTUFF.md index 3853f6e43..83ec76545 100644 --- a/LUASTUFF.md +++ b/LUASTUFF.md @@ -187,6 +187,11 @@ musicdef for green hills music. Global table for all musicdefs, similar to mobjinfo, states, etc. Can take either integer indices, from `0` to `#musicdefs-1`, or string indices (which is equal to calling `S_FindMusicCredit`). +## addHook("MusicCredit", function(musicdef)) + +Hook is called whenever `S_ShowMusicCredit` (either from game or mod) is called. Takes musicdef as only argument, returning true +will overwrite vanilla behavior (not show music credit), can be used to implement custom music credit pop-ups. + # Other changes ## P_PlayRinglossSound(source, damager)