mapmusrng variable, proper sync, cleanup

This commit is contained in:
wolfy852 2023-02-11 08:15:45 -06:00
parent 116d8d8f99
commit 2c162b50a3
7 changed files with 24 additions and 10 deletions

View file

@ -42,6 +42,7 @@ extern char mapmusname[7];
extern UINT16 mapmusflags; extern UINT16 mapmusflags;
extern UINT32 mapmusposition; extern UINT32 mapmusposition;
extern UINT32 mapmusresume; extern UINT32 mapmusresume;
extern UINT32 mapmusrng;
#define MUSIC_TRACKMASK 0x0FFF // ----************ #define MUSIC_TRACKMASK 0x0FFF // ----************
#define MUSIC_RELOADRESET 0x8000 // *--------------- #define MUSIC_RELOADRESET 0x8000 // *---------------
#define MUSIC_FORCERESET 0x4000 // -*-------------- #define MUSIC_FORCERESET 0x4000 // -*--------------
@ -412,7 +413,7 @@ struct mapheader_t
fixed_t gravity; ///< Map-wide gravity. fixed_t gravity; ///< Map-wide gravity.
// Music information // Music information
char musname[MAXMUSNAMES][7]; ///< Music tracks to play. First dimension is the track number, second is the music string. "" for no music. char musname[MAXMUSNAMES][7]; ///< Music tracks to play. First dimension is the track number, second is the music string. "" for no music.
UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore. UINT16 mustrack; ///< Subsong to play. Only really relevant for music modules and specific formats supported by GME. 0 to ignore.
UINT32 muspos; ///< Music position to jump to. UINT32 muspos; ///< Music position to jump to.
UINT8 musname_size; ///< Number of music tracks defined UINT8 musname_size; ///< Number of music tracks defined

View file

@ -93,6 +93,7 @@ char mapmusname[7]; // Music name
UINT16 mapmusflags; // Track and reset bit UINT16 mapmusflags; // Track and reset bit
UINT32 mapmusposition; // Position to jump to UINT32 mapmusposition; // Position to jump to
UINT32 mapmusresume; UINT32 mapmusresume;
UINT32 mapmusrng; // Random selection result
INT16 gamemap = 1; INT16 gamemap = 1;
UINT32 maptol; UINT32 maptol;

View file

@ -309,6 +309,9 @@ int LUA_PushGlobals(lua_State *L, const char *word)
} else if (fastcmp(word,"mapmusposition")) { } else if (fastcmp(word,"mapmusposition")) {
lua_pushinteger(L, mapmusposition); lua_pushinteger(L, mapmusposition);
return 1; return 1;
} else if (fastcmp(word,"mapmusrng")) {
lua_pushinteger(L, mapmusrng);
return 1;
// local player variables, by popular request // local player variables, by popular request
} else if (fastcmp(word,"consoleplayer")) { // player controlling console (aka local player 1) } else if (fastcmp(word,"consoleplayer")) { // player controlling console (aka local player 1)
if (!addedtogame || consoleplayer < 0 || !playeringame[consoleplayer]) if (!addedtogame || consoleplayer < 0 || !playeringame[consoleplayer])
@ -429,6 +432,8 @@ int LUA_WriteGlobals(lua_State *L, const char *word)
} }
else if (fastcmp(word, "mapmusflags")) else if (fastcmp(word, "mapmusflags"))
mapmusflags = (UINT16)luaL_checkinteger(L, 2); mapmusflags = (UINT16)luaL_checkinteger(L, 2);
else if (fastcmp(word, "mapmusrng"))
mapmusrng = (UINT32)luaL_checkinteger(L, 2);
// SRB2Kart // SRB2Kart
else if (fastcmp(word,"racecountdown")) else if (fastcmp(word,"racecountdown"))
racecountdown = (tic_t)luaL_checkinteger(L, 2); racecountdown = (tic_t)luaL_checkinteger(L, 2);

View file

@ -4881,6 +4881,8 @@ static void P_NetArchiveMisc(savebuffer_t *save, boolean resending)
} }
WRITEUINT8(save->p, encoremode); WRITEUINT8(save->p, encoremode);
WRITEUINT32(save->p, mapmusrng);
WRITEUINT32(save->p, leveltime); WRITEUINT32(save->p, leveltime);
WRITEINT16(save->p, lastmap); WRITEINT16(save->p, lastmap);
@ -5045,6 +5047,8 @@ static inline boolean P_NetUnArchiveMisc(savebuffer_t *save, boolean reloading)
} }
encoremode = (boolean)READUINT8(save->p); encoremode = (boolean)READUINT8(save->p);
mapmusrng = READUINT32(save->p);
if (!P_LoadLevel(true, reloading)) if (!P_LoadLevel(true, reloading))
{ {

View file

@ -7640,10 +7640,9 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
S_StartSound(NULL, sfx_s3k73); S_StartSound(NULL, sfx_s3k73);
} }
// As oddly named as this is, this handles music only. // We should be fine starting music here.
// We should be fine starting it here.
// Don't do this during titlemap, because the menu code handles music by itself. // Don't do this during titlemap, because the menu code handles music by itself.
S_Start(); S_InitLevelMusic(fromnetsave);
} }
if (gametyperules & GTR_SPECIALSTART) if (gametyperules & GTR_SPECIALSTART)

View file

@ -2426,14 +2426,19 @@ boolean S_FadeOutStopMusic(UINT32 ms)
// Kills playing sounds at start of level, // Kills playing sounds at start of level,
// determines music if any, changes music. // determines music if any, changes music.
// //
void S_StartEx(boolean reset) void S_InitLevelMusic(boolean fromnetsave)
{ {
(void)reset;
if (mapmusflags & MUSIC_RELOADRESET) if (mapmusflags & MUSIC_RELOADRESET)
{ {
UINT32 t = P_RandomKey(PR_MUSICSELECT, mapheaderinfo[gamemap-1]->musname_size); if (!fromnetsave)
strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[t], 7); {
if (mapheaderinfo[gamemap-1]->musname_size > 1)
mapmusrng = P_RandomKey(PR_MUSICSELECT, mapheaderinfo[gamemap-1]->musname_size);
else
mapmusrng = 0;
}
strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname[mapmusrng], 7);
mapmusname[6] = 0; mapmusname[6] = 0;
mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK);
mapmusposition = mapheaderinfo[gamemap-1]->muspos; mapmusposition = mapheaderinfo[gamemap-1]->muspos;

View file

@ -123,8 +123,7 @@ void S_InitSfxChannels(INT32 sfxVolume);
// //
void S_StopSounds(void); void S_StopSounds(void);
void S_ClearSfx(void); void S_ClearSfx(void);
void S_StartEx(boolean reset); void S_InitLevelMusic(boolean reset);
#define S_Start() S_StartEx(false)
// //
// Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum. // Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum.