mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-07 10:34:48 +00:00
Separate Lua from musicplus-core
This commit is contained in:
parent
45dbadbbc2
commit
917dea7070
4 changed files with 0 additions and 476 deletions
|
@ -2269,392 +2269,6 @@ static int lib_sSpeedMusic(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LUA_MUSICPLUS
|
||||
static int lib_sMusicType(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushinteger(L, S_MusicType());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicPlaying(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushboolean(L, S_MusicPlaying());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicPaused(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushboolean(L, S_MusicPaused());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicName(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushstring(L, S_MusicName());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicInfo(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
char mname[7];
|
||||
UINT16 mflags;
|
||||
boolean looping;
|
||||
if (S_MusicInfo(mname, &mflags, &looping))
|
||||
{
|
||||
lua_pushstring(L, mname);
|
||||
lua_pushinteger(L, mflags);
|
||||
lua_pushboolean(L, looping);
|
||||
}
|
||||
else
|
||||
lua_pushboolean(L, false);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicExists(lua_State *L)
|
||||
{
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
const char *music_name;
|
||||
UINT32 music_num;
|
||||
char music_compat_name[7];
|
||||
UINT16 music_flags = 0;
|
||||
NOHUD
|
||||
if (lua_isnumber(L, 1))
|
||||
{
|
||||
music_num = (UINT32)luaL_checkinteger(L, 1);
|
||||
music_flags = (UINT16)(music_num & 0x0000FFFF);
|
||||
if (music_flags && music_flags <= 1035)
|
||||
snprintf(music_compat_name, 7, "%sM", G_BuildMapName((INT32)music_flags));
|
||||
else if (music_flags && music_flags <= 1050)
|
||||
strncpy(music_compat_name, compat_special_music_slots[music_flags - 1036], 7);
|
||||
else
|
||||
music_compat_name[0] = 0; // becomes empty string
|
||||
music_compat_name[6] = 0;
|
||||
music_name = (const char *)&music_compat_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
music_num = 0;
|
||||
music_name = luaL_checkstring(L, 1);
|
||||
}
|
||||
#else
|
||||
const char *music_name = luaL_checkstring(L, 1);
|
||||
#endif
|
||||
boolean checkMIDI = lua_opttrueboolean(L, 2);
|
||||
boolean checkDigi = lua_opttrueboolean(L, 3);
|
||||
NOHUD
|
||||
lua_pushboolean(L, S_MusicExists(music_name, checkMIDI, checkDigi));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sGetMusicLength(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushinteger(L, (int)S_GetMusicLength());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sSetMusicLoopPoint(lua_State *L)
|
||||
{
|
||||
UINT32 looppoint = (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_SetMusicLoopPoint(looppoint));
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sGetMusicLoopPoint(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushinteger(L, (int)S_GetMusicLoopPoint());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sSetMusicPosition(lua_State *L)
|
||||
{
|
||||
UINT32 position = (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_SetMusicPosition(position));
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sGetMusicPosition(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushinteger(L, (int)S_GetMusicPosition());
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sStopMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
S_StopMusic();
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sPauseMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
S_PauseAudio();
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sResumeMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
S_ResumeAudio();
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sSetInternalMusicVolume(lua_State *L)
|
||||
{
|
||||
UINT32 volume = (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))
|
||||
{
|
||||
S_SetInternalMusicVolume(volume);
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sStopFadingMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
S_StopFadingMusic();
|
||||
lua_pushboolean(L, true);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sFadeMusic(lua_State *L)
|
||||
{
|
||||
UINT32 target_volume = (UINT32)luaL_checkinteger(L, 1);
|
||||
UINT32 ms;
|
||||
INT32 source_volume;
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 3) && lua_isuserdata(L, 3))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 3, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
ms = (UINT32)luaL_checkinteger(L, 2);
|
||||
source_volume = -1;
|
||||
}
|
||||
else if (!lua_isnone(L, 4) && lua_isuserdata(L, 4))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 4, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
source_volume = (INT32)luaL_checkinteger(L, 2);
|
||||
ms = (UINT32)luaL_checkinteger(L, 3);
|
||||
}
|
||||
else if (luaL_optinteger(L, 3, UINT32_MAX) == UINT32_MAX)
|
||||
{
|
||||
ms = (UINT32)luaL_checkinteger(L, 2);
|
||||
source_volume = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
source_volume = (INT32)luaL_checkinteger(L, 2);
|
||||
ms = (UINT32)luaL_checkinteger(L, 3);
|
||||
}
|
||||
|
||||
NOHUD
|
||||
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
lua_pushboolean(L, S_FadeMusicFromVolume(target_volume, source_volume, ms));
|
||||
else
|
||||
lua_pushnil(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)
|
||||
{
|
||||
void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
|
@ -3032,26 +2646,6 @@ static luaL_Reg lib[] = {
|
|||
{"S_StopSound",lib_sStopSound},
|
||||
{"S_ChangeMusic",lib_sChangeMusic},
|
||||
{"S_SpeedMusic",lib_sSpeedMusic},
|
||||
#ifdef HAVE_LUA_MUSICPLUS
|
||||
{"S_MusicType",lib_sMusicType},
|
||||
{"S_MusicPlaying",lib_sMusicPlaying},
|
||||
{"S_MusicPaused",lib_sMusicPaused},
|
||||
{"S_MusicName",lib_sMusicName},
|
||||
{"S_MusicInfo",lib_sMusicInfo},
|
||||
{"S_MusicExists",lib_sMusicExists},
|
||||
{"S_GetMusicLength",lib_sGetMusicLength},
|
||||
{"S_SetMusicLoopPoint",lib_sSetMusicLoopPoint},
|
||||
{"S_GetMusicLoopPoint",lib_sGetMusicLoopPoint},
|
||||
{"S_SetMusicPosition",lib_sSetMusicPosition},
|
||||
{"S_GetMusicPosition",lib_sGetMusicPosition},
|
||||
{"S_PauseMusic",lib_sPauseMusic},
|
||||
{"S_ResumeMusic",lib_sResumeMusic},
|
||||
{"S_StopMusic",lib_sStopMusic},
|
||||
{"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},
|
||||
{"S_SoundPlaying",lib_sSoundPlaying},
|
||||
|
|
|
@ -88,9 +88,5 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8
|
|||
#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // Hook for P_XYMovement (when movement is blocked)
|
||||
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, char *newname, UINT16 *mflags, boolean *looping,
|
||||
UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms); // Hook for music changes
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1193,67 +1193,4 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
|
|||
return hooked;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LUA_MUSICPLUS
|
||||
|
||||
// Hook for music changes
|
||||
boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boolean *looping,
|
||||
UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms)
|
||||
{
|
||||
hook_p hookp;
|
||||
boolean hooked = false;
|
||||
|
||||
if (!gL || !(hooksAvailable[hook_MusicChange/8] & (1<<(hook_MusicChange%8))))
|
||||
return false;
|
||||
|
||||
lua_settop(gL, 0);
|
||||
|
||||
for (hookp = roothook; hookp; hookp = hookp->next)
|
||||
if (hookp->type == hook_MusicChange)
|
||||
{
|
||||
lua_pushfstring(gL, FMT_HOOKID, hookp->id);
|
||||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
lua_pushstring(gL, oldname);
|
||||
lua_pushstring(gL, newname);
|
||||
lua_pushinteger(gL, *mflags);
|
||||
lua_pushboolean(gL, *looping);
|
||||
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, -6) && lua_toboolean(gL, -6))
|
||||
hooked = true;
|
||||
else if (lua_isstring(gL, -6))
|
||||
strncpy(newname, 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))
|
||||
*fadeinms = lua_tonumber(gL, -1);
|
||||
|
||||
lua_pop(gL, 6);
|
||||
}
|
||||
|
||||
lua_settop(gL, 0);
|
||||
newname[6] = 0;
|
||||
return hooked;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -97,7 +97,4 @@ void COM_Lua_f(void);
|
|||
// uncomment if you want seg_t/node_t in Lua
|
||||
// #define HAVE_LUA_SEGS
|
||||
|
||||
// uncomment for extended music features
|
||||
#define HAVE_LUA_MUSICPLUS
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue