I_FadeOutStopMusic, I_FadeInStartDigSong, S_ChangeMusic lua

This commit is contained in:
mazmazz 2018-08-19 22:06:09 -04:00
parent 9410676737
commit fb0d1b45ac
3 changed files with 55 additions and 13 deletions

View file

@ -2184,7 +2184,7 @@ static int lib_sChangeMusic(lua_State *L)
{
#ifdef MUSICSLOT_COMPATIBILITY
const char *music_name;
UINT32 music_num;
UINT32 music_num, position, prefadems, fadeinms;
char music_compat_name[7];
boolean looping;
@ -2236,9 +2236,13 @@ static int lib_sChangeMusic(lua_State *L)
#endif
music_flags = (UINT16)luaL_optinteger(L, 4, 0);
position = (UINT32)luaL_optinteger(L, 5, 0);
prefadems = (UINT32)luaL_optinteger(L, 6, 0);
fadeinms = (UINT32)luaL_optinteger(L, 7, 0);
if (!player || P_IsLocalPlayer(player))
{
S_ChangeMusic(music_name, music_flags, looping);
S_ChangeMusicWithFade(music_name, music_flags, looping, position, prefadems, fadeinms);
lua_pushboolean(L, true);
}
else
@ -2570,8 +2574,11 @@ static int lib_sFadeMusic(lua_State *L)
source_volume = -1;
}
else
{
source_volume = (INT32)luaL_checkinteger(L, 3);
}
player_t *player = NULL;
NOHUD
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
@ -2587,6 +2594,26 @@ static int lib_sFadeMusic(lua_State *L)
return 1;
}
static int lib_sFadeOutStopMusic(lua_State *L)
{
UINT32 ms = (UINT32)luaL_checkinteger(L, 1);
player_t *player = NULL;
NOHUD
if (!lua_isnone(L, 2) && lua_isuserdata(L, 2))
{
player = *((player_t **)luaL_checkudata(L, 2, META_PLAYER));
if (!player)
return LUA_ErrInvalid(L, "player_t");
}
if (!player || P_IsLocalPlayer(player))
{
lua_pushboolean(L, S_FadeOutStopMusic(ms));
}
else
lua_pushnil(L);
return 1;
}
#endif
static int lib_sOriginPlaying(lua_State *L)
{
@ -2982,6 +3009,7 @@ static luaL_Reg lib[] = {
{"S_SetInternalMusicVolume", lib_sSetInternalMusicVolume},
{"S_StopFadingMusic",lib_sStopFadingMusic},
{"S_FadeMusic",lib_sFadeMusic},
{"S_FadeOutStopMusic",lib_sFadeOutStopMusic},
#endif
{"S_OriginPlaying",lib_sOriginPlaying},
{"S_IdPlaying",lib_sIdPlaying},

View file

@ -89,7 +89,8 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8
boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing); // Hook for P_SpawnMapThing by mobj type
boolean LUAh_FollowMobj(player_t *player, mobj_t *mo); // Hook for P_PlayerAfterThink Smiles mobj-following
#ifdef HAVE_LUA_MUSICPLUS
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping); // Hook for music changes
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping,
UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms); // Hook for music changes
#endif
#endif

View file

@ -1196,7 +1196,8 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
#ifdef HAVE_LUA_MUSICPLUS
// Hook for music changes
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping)
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping,
UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms)
{
hook_p hookp;
boolean hooked = false;
@ -1217,25 +1218,37 @@ boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusi
lua_pushstring(gL, newname);
lua_pushinteger(gL, *mflags);
lua_pushboolean(gL, *looping);
if (lua_pcall(gL, 4, 3, 0)) {
lua_pushinteger(gL, *position);
lua_pushinteger(gL, *prefadems);
lua_pushinteger(gL, *fadeinms);
if (lua_pcall(gL, 7, 6, 0)) {
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
lua_pop(gL, 1);
continue;
}
// output 1: true, false, or string musicname override
if (lua_isboolean(gL, -3) && lua_toboolean(gL, -3))
if (lua_isboolean(gL, -6) && lua_toboolean(gL, -6))
hooked = true;
else if (lua_isstring(gL, -3))
strncpy(newmusic, lua_tostring(gL, -3), 7);
// output 2: hook override
if (lua_isnumber(gL, -2))
*mflags = lua_tonumber(gL, -2);
else if (lua_isstring(gL, -6))
strncpy(newmusic, lua_tostring(gL, -6), 7);
// output 2: mflags override
if (lua_isnumber(gL, -5))
*mflags = lua_tonumber(gL, -5);
// output 3: looping override
if (lua_isboolean(gL, -4))
*looping = lua_toboolean(gL, -4);
// output 4: position override
if (lua_isboolean(gL, -3))
*position = lua_tonumber(gL, -3);
// output 5: prefadems override
if (lua_isboolean(gL, -2))
*prefadems = lua_tonumber(gL, -2);
// output 6: fadeinms override
if (lua_isboolean(gL, -1))
*looping = lua_toboolean(gL, -1);
*fadeinms = lua_tonumber(gL, -1);
lua_pop(gL, 3);
lua_pop(gL, 6);
}
lua_settop(gL, 0);