mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
Merge branch 'lua-sectorsounds' into 'next'
Support sectors as sound origins in Lua See merge request STJr/SRB2!1144
This commit is contained in:
commit
c3c34c489b
2 changed files with 58 additions and 35 deletions
|
@ -2589,26 +2589,52 @@ static int lib_rGetNameByColor(lua_State *L)
|
|||
|
||||
// S_SOUND
|
||||
////////////
|
||||
static int GetValidSoundOrigin(lua_State *L, void **origin)
|
||||
{
|
||||
const char *type;
|
||||
|
||||
lua_settop(L, 1);
|
||||
type = GetUserdataUType(L);
|
||||
|
||||
if (fasticmp(type, "mobj_t"))
|
||||
{
|
||||
*origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
if (!(*origin))
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
return 1;
|
||||
}
|
||||
else if (fasticmp(type, "sector_t"))
|
||||
{
|
||||
*origin = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR));
|
||||
if (!(*origin))
|
||||
return LUA_ErrInvalid(L, "sector_t");
|
||||
|
||||
*origin = &((sector_t *)(*origin))->soundorg;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return LUA_ErrInvalid(L, "mobj_t/sector_t");
|
||||
}
|
||||
|
||||
static int lib_sStartSound(lua_State *L)
|
||||
{
|
||||
const void *origin = NULL;
|
||||
void *origin = NULL;
|
||||
sfxenum_t sound_id = luaL_checkinteger(L, 2);
|
||||
player_t *player = NULL;
|
||||
//NOHUD
|
||||
|
||||
if (sound_id >= NUMSFX)
|
||||
return luaL_error(L, "sfx %d out of range (0 - %d)", sound_id, NUMSFX-1);
|
||||
if (!lua_isnil(L, 1))
|
||||
{
|
||||
origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
if (!origin)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
if (!lua_isnil(L, 1))
|
||||
if (!GetValidSoundOrigin(L, &origin))
|
||||
return 0;
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
{
|
||||
if (hud_running || hook_cmd_running)
|
||||
|
@ -2621,18 +2647,12 @@ static int lib_sStartSound(lua_State *L)
|
|||
|
||||
static int lib_sStartSoundAtVolume(lua_State *L)
|
||||
{
|
||||
const void *origin = NULL;
|
||||
void *origin = NULL;
|
||||
sfxenum_t sound_id = luaL_checkinteger(L, 2);
|
||||
INT32 volume = (INT32)luaL_checkinteger(L, 3);
|
||||
player_t *player = NULL;
|
||||
//NOHUD
|
||||
|
||||
if (!lua_isnil(L, 1))
|
||||
{
|
||||
origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
if (!origin)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
}
|
||||
if (sound_id >= NUMSFX)
|
||||
return luaL_error(L, "sfx %d out of range (0 - %d)", sound_id, NUMSFX-1);
|
||||
if (!lua_isnone(L, 4) && lua_isuserdata(L, 4))
|
||||
|
@ -2641,30 +2661,37 @@ static int lib_sStartSoundAtVolume(lua_State *L)
|
|||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!lua_isnil(L, 1))
|
||||
if (!GetValidSoundOrigin(L, &origin))
|
||||
return LUA_ErrInvalid(L, "mobj_t/sector_t");
|
||||
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
S_StartSoundAtVolume(origin, sound_id, volume);
|
||||
S_StartSoundAtVolume(origin, sound_id, volume);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lib_sStopSound(lua_State *L)
|
||||
{
|
||||
void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
void *origin = NULL;
|
||||
//NOHUD
|
||||
if (!origin)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
if (!GetValidSoundOrigin(L, &origin))
|
||||
return LUA_ErrInvalid(L, "mobj_t/sector_t");
|
||||
|
||||
S_StopSound(origin);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lib_sStopSoundByID(lua_State *L)
|
||||
{
|
||||
void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
void *origin = NULL;
|
||||
sfxenum_t sound_id = luaL_checkinteger(L, 2);
|
||||
//NOHUD
|
||||
if (!origin)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
|
||||
if (sound_id >= NUMSFX)
|
||||
return luaL_error(L, "sfx %d out of range (0 - %d)", sound_id, NUMSFX-1);
|
||||
if (!lua_isnil(L, 1))
|
||||
if (!GetValidSoundOrigin(L, &origin))
|
||||
return LUA_ErrInvalid(L, "mobj_t/sector_t");
|
||||
|
||||
S_StopSoundByID(origin, sound_id);
|
||||
return 0;
|
||||
|
@ -2890,11 +2917,12 @@ static int lib_sSetMusicPosition(lua_State *L)
|
|||
|
||||
static int lib_sOriginPlaying(lua_State *L)
|
||||
{
|
||||
void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
void *origin = NULL;
|
||||
//NOHUD
|
||||
INLEVEL
|
||||
if (!origin)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
if (!GetValidSoundOrigin(L, &origin))
|
||||
return LUA_ErrInvalid(L, "mobj_t/sector_t");
|
||||
|
||||
lua_pushboolean(L, S_OriginPlaying(origin));
|
||||
return 1;
|
||||
}
|
||||
|
@ -2911,14 +2939,15 @@ static int lib_sIdPlaying(lua_State *L)
|
|||
|
||||
static int lib_sSoundPlaying(lua_State *L)
|
||||
{
|
||||
void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
void *origin = NULL;
|
||||
sfxenum_t id = luaL_checkinteger(L, 2);
|
||||
//NOHUD
|
||||
INLEVEL
|
||||
if (!origin)
|
||||
return LUA_ErrInvalid(L, "mobj_t");
|
||||
if (id >= NUMSFX)
|
||||
return luaL_error(L, "sfx %d out of range (0 - %d)", id, NUMSFX-1);
|
||||
if (!GetValidSoundOrigin(L, &origin))
|
||||
return LUA_ErrInvalid(L, "mobj_t/sector_t");
|
||||
|
||||
lua_pushboolean(L, S_SoundPlaying(origin, id));
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1045,7 +1045,6 @@ void S_ClearSfx(void)
|
|||
|
||||
static void S_StopChannel(INT32 cnum)
|
||||
{
|
||||
INT32 i;
|
||||
channel_t *c = &channels[cnum];
|
||||
|
||||
if (c->sfxinfo)
|
||||
|
@ -1054,17 +1053,12 @@ static void S_StopChannel(INT32 cnum)
|
|||
if (I_SoundIsPlaying(c->handle))
|
||||
I_StopSound(c->handle);
|
||||
|
||||
// check to see
|
||||
// if other channels are playing the sound
|
||||
for (i = 0; i < numofchannels; i++)
|
||||
if (cnum != i && c->sfxinfo == channels[i].sfxinfo)
|
||||
break;
|
||||
|
||||
// degrade usefulness of sound data
|
||||
c->sfxinfo->usefulness--;
|
||||
|
||||
c->sfxinfo = 0;
|
||||
}
|
||||
|
||||
c->origin = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue