mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
- moved game specific data out of the sound backend.
In Raze I already had a user data array for that so this gets used here, too, now. Also copied a few other fixes.
This commit is contained in:
parent
50e1efa965
commit
018794f1dd
5 changed files with 107 additions and 66 deletions
|
@ -251,7 +251,7 @@ static bool S_CheckSound(sfxinfo_t *startsfx, sfxinfo_t *sfx, TArray<sfxinfo_t *
|
||||||
bool success = true;
|
bool success = true;
|
||||||
unsigned siz = chain.Size();
|
unsigned siz = chain.Size();
|
||||||
|
|
||||||
if (sfx->bPlayerReserve)
|
if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ unsigned int S_GetMSLength(FSoundID sound)
|
||||||
// Resolve player sounds, random sounds, and aliases
|
// Resolve player sounds, random sounds, and aliases
|
||||||
if (sfx->link != sfxinfo_t::NO_LINK)
|
if (sfx->link != sfxinfo_t::NO_LINK)
|
||||||
{
|
{
|
||||||
if (sfx->bPlayerReserve)
|
if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
sfx = &S_sfx[S_FindSkinnedSound (NULL, sound)];
|
sfx = &S_sfx[S_FindSkinnedSound (NULL, sound)];
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ static int S_AddSound (const char *logicalname, int lumpnum, FScanner *sc)
|
||||||
{ // If the sound has already been defined, change the old definition
|
{ // If the sound has already been defined, change the old definition
|
||||||
sfxinfo_t *sfx = &S_sfx[sfxid];
|
sfxinfo_t *sfx = &S_sfx[sfxid];
|
||||||
|
|
||||||
if (sfx->bPlayerReserve)
|
if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
if (sc != NULL)
|
if (sc != NULL)
|
||||||
{
|
{
|
||||||
|
@ -430,7 +430,7 @@ static int S_AddSound (const char *logicalname, int lumpnum, FScanner *sc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Redefining a player compatibility sound will redefine the target instead.
|
// Redefining a player compatibility sound will redefine the target instead.
|
||||||
if (sfx->bPlayerCompat)
|
if (sfx->UserData[0] & SND_PlayerCompat)
|
||||||
{
|
{
|
||||||
sfx = &S_sfx[sfx->link];
|
sfx = &S_sfx[sfx->link];
|
||||||
}
|
}
|
||||||
|
@ -938,7 +938,7 @@ static void S_AddSNDINFO (int lump)
|
||||||
sfxnum = S_AddPlayerSound (pclass, gender, refid, sc.String);
|
sfxnum = S_AddPlayerSound (pclass, gender, refid, sc.String);
|
||||||
if (0 == stricmp(sc.String, "dsempty"))
|
if (0 == stricmp(sc.String, "dsempty"))
|
||||||
{
|
{
|
||||||
S_sfx[sfxnum].bPlayerSilent = true;
|
S_sfx[sfxnum].UserData[0] |= SND_PlayerSilent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -950,7 +950,7 @@ static void S_AddSNDINFO (int lump)
|
||||||
|
|
||||||
S_ParsePlayerSoundCommon (sc, pclass, gender, refid);
|
S_ParsePlayerSoundCommon (sc, pclass, gender, refid);
|
||||||
targid = soundEngine->FindSoundNoHash (sc.String);
|
targid = soundEngine->FindSoundNoHash (sc.String);
|
||||||
if (!S_sfx[targid].bPlayerReserve)
|
if (!S_sfx[targid].UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
sc.ScriptError ("%s is not a player sound", sc.String);
|
sc.ScriptError ("%s is not a player sound", sc.String);
|
||||||
}
|
}
|
||||||
|
@ -968,7 +968,7 @@ static void S_AddSNDINFO (int lump)
|
||||||
sfxfrom = S_AddSound (sc.String, -1, &sc);
|
sfxfrom = S_AddSound (sc.String, -1, &sc);
|
||||||
aliasto = S_LookupPlayerSound (pclass, gender, refid);
|
aliasto = S_LookupPlayerSound (pclass, gender, refid);
|
||||||
S_sfx[sfxfrom].link = aliasto;
|
S_sfx[sfxfrom].link = aliasto;
|
||||||
S_sfx[sfxfrom].bPlayerCompat = true;
|
S_sfx[sfxfrom].UserData[0] |= SND_PlayerCompat;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -991,7 +991,7 @@ static void S_AddSNDINFO (int lump)
|
||||||
sc.MustGetString ();
|
sc.MustGetString ();
|
||||||
sfxfrom = S_AddSound (sc.String, -1, &sc);
|
sfxfrom = S_AddSound (sc.String, -1, &sc);
|
||||||
sc.MustGetString ();
|
sc.MustGetString ();
|
||||||
if (S_sfx[sfxfrom].bPlayerCompat)
|
if (S_sfx[sfxfrom].UserData[0] & SND_PlayerCompat)
|
||||||
{
|
{
|
||||||
sfxfrom = S_sfx[sfxfrom].link;
|
sfxfrom = S_sfx[sfxfrom].link;
|
||||||
}
|
}
|
||||||
|
@ -1261,7 +1261,7 @@ static void S_ParsePlayerSoundCommon (FScanner &sc, FString &pclass, int &gender
|
||||||
sc.MustGetString ();
|
sc.MustGetString ();
|
||||||
refid = soundEngine->FindSoundNoHash (sc.String);
|
refid = soundEngine->FindSoundNoHash (sc.String);
|
||||||
auto &S_sfx = soundEngine->GetSounds();
|
auto &S_sfx = soundEngine->GetSounds();
|
||||||
if (refid != 0 && !S_sfx[refid].bPlayerReserve && !S_sfx[refid].bTentative)
|
if (refid != 0 && !S_sfx[refid].UserData[0] & SND_PlayerReserve && !S_sfx[refid].bTentative)
|
||||||
{
|
{
|
||||||
sc.ScriptError ("%s has already been used for a non-player sound.", sc.String);
|
sc.ScriptError ("%s has already been used for a non-player sound.", sc.String);
|
||||||
}
|
}
|
||||||
|
@ -1274,7 +1274,7 @@ static void S_ParsePlayerSoundCommon (FScanner &sc, FString &pclass, int &gender
|
||||||
{
|
{
|
||||||
S_sfx[refid].link = NumPlayerReserves++;
|
S_sfx[refid].link = NumPlayerReserves++;
|
||||||
S_sfx[refid].bTentative = false;
|
S_sfx[refid].bTentative = false;
|
||||||
S_sfx[refid].bPlayerReserve = true;
|
S_sfx[refid].UserData[0] |= SND_PlayerReserve;
|
||||||
}
|
}
|
||||||
sc.MustGetString ();
|
sc.MustGetString ();
|
||||||
}
|
}
|
||||||
|
@ -1423,7 +1423,7 @@ int S_LookupPlayerSound (const char *pclass, int gender, const char *name)
|
||||||
int S_LookupPlayerSound (const char *pclass, int gender, FSoundID refid)
|
int S_LookupPlayerSound (const char *pclass, int gender, FSoundID refid)
|
||||||
{
|
{
|
||||||
auto &S_sfx = soundEngine->GetSounds();
|
auto &S_sfx = soundEngine->GetSounds();
|
||||||
if (!S_sfx[refid].bPlayerReserve)
|
if (!S_sfx[refid].UserData[0] & SND_PlayerReserve)
|
||||||
{ // Not a player sound, so just return this sound
|
{ // Not a player sound, so just return this sound
|
||||||
return refid;
|
return refid;
|
||||||
}
|
}
|
||||||
|
@ -1469,7 +1469,7 @@ static int S_LookupPlayerSound (int classidx, int gender, FSoundID refid)
|
||||||
(sndnum == 0 ||
|
(sndnum == 0 ||
|
||||||
((S_sfx[sndnum].lumpnum == -1 || S_sfx[sndnum].lumpnum == sfx_empty) &&
|
((S_sfx[sndnum].lumpnum == -1 || S_sfx[sndnum].lumpnum == sfx_empty) &&
|
||||||
S_sfx[sndnum].link == sfxinfo_t::NO_LINK &&
|
S_sfx[sndnum].link == sfxinfo_t::NO_LINK &&
|
||||||
!S_sfx[sndnum].bPlayerSilent)))
|
!(S_sfx[sndnum].UserData[0] & SND_PlayerSilent))))
|
||||||
{ // This sound is unavailable.
|
{ // This sound is unavailable.
|
||||||
if (ingender != 0)
|
if (ingender != 0)
|
||||||
{ // Try "male"
|
{ // Try "male"
|
||||||
|
@ -1549,7 +1549,7 @@ bool S_AreSoundsEquivalent (AActor *actor, int id1, int id2)
|
||||||
// Dereference aliases, but not random or player sounds
|
// Dereference aliases, but not random or player sounds
|
||||||
while ((sfx = &S_sfx[id1])->link != sfxinfo_t::NO_LINK)
|
while ((sfx = &S_sfx[id1])->link != sfxinfo_t::NO_LINK)
|
||||||
{
|
{
|
||||||
if (sfx->bPlayerReserve)
|
if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
id1 = S_FindSkinnedSound (actor, id1);
|
id1 = S_FindSkinnedSound (actor, id1);
|
||||||
}
|
}
|
||||||
|
@ -1564,7 +1564,7 @@ bool S_AreSoundsEquivalent (AActor *actor, int id1, int id2)
|
||||||
}
|
}
|
||||||
while ((sfx = &S_sfx[id2])->link != sfxinfo_t::NO_LINK)
|
while ((sfx = &S_sfx[id2])->link != sfxinfo_t::NO_LINK)
|
||||||
{
|
{
|
||||||
if (sfx->bPlayerReserve)
|
if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
id2 = S_FindSkinnedSound (actor, id2);
|
id2 = S_FindSkinnedSound (actor, id2);
|
||||||
}
|
}
|
||||||
|
@ -1706,7 +1706,7 @@ CCMD (soundlinks)
|
||||||
|
|
||||||
if (sfx->link != sfxinfo_t::NO_LINK &&
|
if (sfx->link != sfxinfo_t::NO_LINK &&
|
||||||
!sfx->bRandomHeader &&
|
!sfx->bRandomHeader &&
|
||||||
!sfx->bPlayerReserve)
|
!(sfx->UserData[0] & SND_PlayerReserve))
|
||||||
{
|
{
|
||||||
Printf ("%s -> %s\n", sfx->name.GetChars(), S_sfx[sfx->link].name.GetChars());
|
Printf ("%s -> %s\n", sfx->name.GetChars(), S_sfx[sfx->link].name.GetChars());
|
||||||
}
|
}
|
||||||
|
@ -1730,7 +1730,7 @@ CCMD (playersounds)
|
||||||
memset (reserveNames, 0, sizeof(reserveNames));
|
memset (reserveNames, 0, sizeof(reserveNames));
|
||||||
for (i = j = 0; j < NumPlayerReserves && i < S_sfx.Size(); ++i)
|
for (i = j = 0; j < NumPlayerReserves && i < S_sfx.Size(); ++i)
|
||||||
{
|
{
|
||||||
if (S_sfx[i].bPlayerReserve)
|
if (S_sfx[i].UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
++j;
|
++j;
|
||||||
reserveNames[S_sfx[i].link] = S_sfx[i].name;
|
reserveNames[S_sfx[i].link] = S_sfx[i].name;
|
||||||
|
|
|
@ -85,6 +85,20 @@ class DoomSoundEngine : public SoundEngine
|
||||||
TArray<uint8_t> ReadSound(int lumpnum);
|
TArray<uint8_t> ReadSound(int lumpnum);
|
||||||
int PickReplacement(int refid);
|
int PickReplacement(int refid);
|
||||||
FSoundID ResolveSound(const void *ent, int type, FSoundID soundid, float &attenuation) override;
|
FSoundID ResolveSound(const void *ent, int type, FSoundID soundid, float &attenuation) override;
|
||||||
|
void CacheSound(sfxinfo_t* sfx) override;
|
||||||
|
void StopChannel(FSoundChan* chan) override;
|
||||||
|
int AddSoundLump(const char* logicalname, int lump, int CurrentPitchMask, int resid = -1, int nearlimit = 2) override
|
||||||
|
{
|
||||||
|
auto ndx = SoundEngine::AddSoundLump(logicalname, lump, CurrentPitchMask, resid, nearlimit);
|
||||||
|
S_sfx[ndx].UserData.Resize(1);
|
||||||
|
return ndx;
|
||||||
|
}
|
||||||
|
bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel) override
|
||||||
|
{
|
||||||
|
if (sourcetype != SOURCE_Actor) actor = nullptr; //ZDoom did this.
|
||||||
|
return SoundEngine::CheckSoundLimit(sfx, pos, near_limit, limit_range, sourcetype, actor, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DoomSoundEngine() = default;
|
DoomSoundEngine() = default;
|
||||||
|
@ -416,6 +430,17 @@ DEFINE_ACTION_FUNCTION(DObject, S_StartSound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
void DoomSoundEngine::CacheSound(sfxinfo_t* sfx)
|
||||||
|
{
|
||||||
|
if (!(sfx->UserData[0] & SND_PlayerReserve)) SoundEngine::CacheSound(sfx);
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -424,7 +449,8 @@ DEFINE_ACTION_FUNCTION(DObject, S_StartSound)
|
||||||
|
|
||||||
FSoundID DoomSoundEngine::ResolveSound(const void * ent, int type, FSoundID soundid, float &attenuation)
|
FSoundID DoomSoundEngine::ResolveSound(const void * ent, int type, FSoundID soundid, float &attenuation)
|
||||||
{
|
{
|
||||||
if (isPlayerReserve(soundid))
|
auto sfx = &S_sfx[soundid];
|
||||||
|
if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
AActor *src;
|
AActor *src;
|
||||||
if (type != SOURCE_Actor) src = nullptr;
|
if (type != SOURCE_Actor) src = nullptr;
|
||||||
|
@ -460,6 +486,21 @@ static bool VerifyActorSound(AActor* ent, FSoundID& sound_id, int& channel, ECha
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// Common checking code for the actor sound functions
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
void DoomSoundEngine::StopChannel(FSoundChan* chan)
|
||||||
|
{
|
||||||
|
if (chan && chan->SysChannel != NULL && !(chan->ChanFlags & CHANF_EVICTED) && chan->SourceType == SOURCE_Actor)
|
||||||
|
{
|
||||||
|
chan->Source = NULL;
|
||||||
|
}
|
||||||
|
SoundEngine::StopChannel(chan);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
@ -1351,7 +1392,7 @@ void DoomSoundEngine::PrintSoundList()
|
||||||
}
|
}
|
||||||
Printf("}\n");
|
Printf("}\n");
|
||||||
}
|
}
|
||||||
else if (sfx->bPlayerReserve)
|
else if (sfx->UserData[0] & SND_PlayerReserve)
|
||||||
{
|
{
|
||||||
Printf("%3d. %s <<player sound %d>>\n", i, sfx->name.GetChars(), sfx->link);
|
Printf("%3d. %s <<player sound %d>>\n", i, sfx->name.GetChars(), sfx->link);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ int sfx_empty = -1;
|
||||||
|
|
||||||
void SoundEngine::Init(TArray<uint8_t> &curve)
|
void SoundEngine::Init(TArray<uint8_t> &curve)
|
||||||
{
|
{
|
||||||
|
StopAllChannels();
|
||||||
// Free all channels for use.
|
// Free all channels for use.
|
||||||
while (Channels != NULL)
|
while (Channels != NULL)
|
||||||
{
|
{
|
||||||
|
@ -153,12 +154,8 @@ void SoundEngine::CacheMarkedSounds()
|
||||||
|
|
||||||
void SoundEngine::CacheSound (sfxinfo_t *sfx)
|
void SoundEngine::CacheSound (sfxinfo_t *sfx)
|
||||||
{
|
{
|
||||||
if (GSnd)
|
if (GSnd && !sfx->bTentative)
|
||||||
{
|
{
|
||||||
if (sfx->bPlayerReserve)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sfxinfo_t *orig = sfx;
|
sfxinfo_t *orig = sfx;
|
||||||
while (!sfx->bRandomHeader && sfx->link != sfxinfo_t::NO_LINK)
|
while (!sfx->bRandomHeader && sfx->link != sfxinfo_t::NO_LINK)
|
||||||
{
|
{
|
||||||
|
@ -278,7 +275,7 @@ TArray<FSoundChan*> SoundEngine::AllActiveChannels()
|
||||||
// If the sound is forgettable, this is as good a time as
|
// If the sound is forgettable, this is as good a time as
|
||||||
// any to forget about it. And if it's a UI sound, it shouldn't
|
// any to forget about it. And if it's a UI sound, it shouldn't
|
||||||
// be stored in the savegame.
|
// be stored in the savegame.
|
||||||
if (!(chan->ChanFlags & (CHANF_FORGETTABLE | CHANF_UI)))
|
if (!(chan->ChanFlags & (CHANF_FORGETTABLE | CHANF_UI | CHANF_TRANSIENT)))
|
||||||
{
|
{
|
||||||
chans.Push(chan);
|
chans.Push(chan);
|
||||||
}
|
}
|
||||||
|
@ -461,9 +458,8 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
|
||||||
near_limit = 0;
|
near_limit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this sound doesn't like playing near itself, don't play it if
|
// If this sound doesn't like playing near itself, don't play it if that's what would happen.
|
||||||
// that's what would happen. (Does this really need the SOURCE_Actor restriction?)
|
if (near_limit > 0 && CheckSoundLimit(sfx, pos, near_limit, limit_range, type, source, channel))
|
||||||
if (near_limit > 0 && CheckSoundLimit(sfx, pos, near_limit, limit_range, type, type == SOURCE_Actor? source : nullptr, channel))
|
|
||||||
{
|
{
|
||||||
chanflags |= CHANF_EVICTED;
|
chanflags |= CHANF_EVICTED;
|
||||||
}
|
}
|
||||||
|
@ -587,7 +583,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
|
||||||
GSnd->MarkStartTime(chan);
|
GSnd->MarkStartTime(chan);
|
||||||
chanflags |= CHANF_EVICTED;
|
chanflags |= CHANF_EVICTED;
|
||||||
}
|
}
|
||||||
if (attenuation > 0)
|
if (attenuation > 0 && type != SOURCE_None)
|
||||||
{
|
{
|
||||||
chanflags |= CHANF_IS3D | CHANF_JUSTSTARTED;
|
chanflags |= CHANF_IS3D | CHANF_JUSTSTARTED;
|
||||||
}
|
}
|
||||||
|
@ -1390,10 +1386,6 @@ void SoundEngine::StopChannel(FSoundChan *chan)
|
||||||
if (!(chan->ChanFlags & CHANF_EVICTED))
|
if (!(chan->ChanFlags & CHANF_EVICTED))
|
||||||
{
|
{
|
||||||
chan->ChanFlags |= CHANF_FORGETTABLE;
|
chan->ChanFlags |= CHANF_FORGETTABLE;
|
||||||
if (chan->SourceType == SOURCE_Actor)
|
|
||||||
{
|
|
||||||
chan->Source = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (GSnd) GSnd->StopChannel(chan);
|
if (GSnd) GSnd->StopChannel(chan);
|
||||||
}
|
}
|
||||||
|
@ -1517,14 +1509,11 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc
|
||||||
newsfx.NearLimit = nearlimit;
|
newsfx.NearLimit = nearlimit;
|
||||||
newsfx.LimitRange = 256 * 256;
|
newsfx.LimitRange = 256 * 256;
|
||||||
newsfx.bRandomHeader = false;
|
newsfx.bRandomHeader = false;
|
||||||
newsfx.bPlayerReserve = false;
|
|
||||||
newsfx.bLoadRAW = false;
|
newsfx.bLoadRAW = false;
|
||||||
newsfx.bPlayerCompat = false;
|
|
||||||
newsfx.b16bit = false;
|
newsfx.b16bit = false;
|
||||||
newsfx.bUsed = false;
|
newsfx.bUsed = false;
|
||||||
newsfx.bSingular = false;
|
newsfx.bSingular = false;
|
||||||
newsfx.bTentative = false;
|
newsfx.bTentative = false;
|
||||||
newsfx.bPlayerSilent = false;
|
|
||||||
newsfx.ResourceId = resid;
|
newsfx.ResourceId = resid;
|
||||||
newsfx.RawRate = 0;
|
newsfx.RawRate = 0;
|
||||||
newsfx.link = sfxinfo_t::NO_LINK;
|
newsfx.link = sfxinfo_t::NO_LINK;
|
||||||
|
@ -1537,13 +1526,6 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc
|
||||||
return (int)S_sfx.Size()-1;
|
return (int)S_sfx.Size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SoundEngine::AddSfx(sfxinfo_t &sfx)
|
|
||||||
{
|
|
||||||
S_sfx.Push(sfx);
|
|
||||||
if (sfx.ResourceId >= 0) ResIdMap[sfx.ResourceId] = S_sfx.Size() - 1;
|
|
||||||
return (int)S_sfx.Size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
|
|
|
@ -40,6 +40,20 @@ struct FLevelLocals;
|
||||||
#include "name.h"
|
#include "name.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
|
||||||
|
enum SndUserFlags
|
||||||
|
{
|
||||||
|
SND_PlayerReserve = 1,
|
||||||
|
SND_PlayerCompat = 2,
|
||||||
|
SND_PlayerSilent = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
enum // This cannot be remain as this, but for now it has to suffice.
|
||||||
|
{
|
||||||
|
SOURCE_Actor = SOURCE_None+1, // Sound is coming from an actor.
|
||||||
|
SOURCE_Sector, // Sound is coming from a sector.
|
||||||
|
SOURCE_Polyobj, // Sound is coming from a polyobject.
|
||||||
|
};
|
||||||
|
|
||||||
// Per level startup code.
|
// Per level startup code.
|
||||||
// Kills playing sounds at start of level and starts new music.
|
// Kills playing sounds at start of level and starts new music.
|
||||||
//
|
//
|
||||||
|
|
|
@ -37,9 +37,7 @@ struct sfxinfo_t
|
||||||
unsigned bSingular:1;
|
unsigned bSingular:1;
|
||||||
|
|
||||||
unsigned bTentative:1;
|
unsigned bTentative:1;
|
||||||
unsigned bPlayerReserve : 1;
|
TArray<int> UserData;
|
||||||
unsigned bPlayerCompat : 1;
|
|
||||||
unsigned bPlayerSilent:1; // This player sound is intentionally silent.
|
|
||||||
|
|
||||||
int RawRate; // Sample rate to use when bLoadRAW is true
|
int RawRate; // Sample rate to use when bLoadRAW is true
|
||||||
|
|
||||||
|
@ -171,11 +169,8 @@ struct FSoundChan : public FISoundChannel
|
||||||
int8_t Priority;
|
int8_t Priority;
|
||||||
uint8_t SourceType;
|
uint8_t SourceType;
|
||||||
float LimitRange;
|
float LimitRange;
|
||||||
union
|
const void *Source;
|
||||||
{
|
float Point[3]; // Sound is not attached to any source.
|
||||||
const void *Source;
|
|
||||||
float Point[3]; // Sound is not attached to any source.
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,14 +204,11 @@ enum EChannel
|
||||||
#define ATTN_IDLE 1.001f
|
#define ATTN_IDLE 1.001f
|
||||||
#define ATTN_STATIC 3.f // diminish very rapidly with distance
|
#define ATTN_STATIC 3.f // diminish very rapidly with distance
|
||||||
|
|
||||||
enum // This cannot be remain as this, but for now it has to suffice.
|
enum // The core source types, implementations may extend this list as they see fit.
|
||||||
{
|
{
|
||||||
SOURCE_Any = -1, // Input for check functions meaning 'any source'
|
SOURCE_Any = -1, // Input for check functions meaning 'any source'
|
||||||
SOURCE_None, // Sound is always on top of the listener.
|
|
||||||
SOURCE_Actor, // Sound is coming from an actor.
|
|
||||||
SOURCE_Sector, // Sound is coming from a sector.
|
|
||||||
SOURCE_Polyobj, // Sound is coming from a polyobject.
|
|
||||||
SOURCE_Unattached, // Sound is not attached to any particular emitter.
|
SOURCE_Unattached, // Sound is not attached to any particular emitter.
|
||||||
|
SOURCE_None, // Sound is always on top of the listener.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,16 +256,22 @@ private:
|
||||||
|
|
||||||
// Checks if a copy of this sound is already playing.
|
// Checks if a copy of this sound is already playing.
|
||||||
bool CheckSingular(int sound_id);
|
bool CheckSingular(int sound_id);
|
||||||
bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel);
|
|
||||||
virtual TArray<uint8_t> ReadSound(int lumpnum) = 0;
|
virtual TArray<uint8_t> ReadSound(int lumpnum) = 0;
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel);
|
||||||
virtual FSoundID ResolveSound(const void *ent, int srctype, FSoundID soundid, float &attenuation);
|
virtual FSoundID ResolveSound(const void *ent, int srctype, FSoundID soundid, float &attenuation);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~SoundEngine() = default;
|
virtual ~SoundEngine()
|
||||||
|
{
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
void EvictAllChannels();
|
void EvictAllChannels();
|
||||||
|
|
||||||
void StopChannel(FSoundChan* chan);
|
virtual int SoundSourceIndex(FSoundChan* chan) { return 0; }
|
||||||
|
virtual void SetSource(FSoundChan* chan, int index) {}
|
||||||
|
|
||||||
|
virtual void StopChannel(FSoundChan* chan);
|
||||||
sfxinfo_t* LoadSound(sfxinfo_t* sfx);
|
sfxinfo_t* LoadSound(sfxinfo_t* sfx);
|
||||||
|
|
||||||
// Initializes sound stuff, including volume
|
// Initializes sound stuff, including volume
|
||||||
|
@ -294,7 +292,7 @@ public:
|
||||||
void CalcPosVel(FSoundChan* chan, FVector3* pos, FVector3* vel);
|
void CalcPosVel(FSoundChan* chan, FVector3* pos, FVector3* vel);
|
||||||
|
|
||||||
// Loads a sound, including any random sounds it might reference.
|
// Loads a sound, including any random sounds it might reference.
|
||||||
void CacheSound(sfxinfo_t* sfx);
|
virtual void CacheSound(sfxinfo_t* sfx);
|
||||||
void CacheSound(int sfx) { CacheSound(&S_sfx[sfx]); }
|
void CacheSound(int sfx) { CacheSound(&S_sfx[sfx]); }
|
||||||
void UnloadSound(sfxinfo_t* sfx);
|
void UnloadSound(sfxinfo_t* sfx);
|
||||||
|
|
||||||
|
@ -331,14 +329,14 @@ public:
|
||||||
{
|
{
|
||||||
return object && listener.ListenerObject == object;
|
return object && listener.ListenerObject == object;
|
||||||
}
|
}
|
||||||
bool isPlayerReserve(int snd_id)
|
|
||||||
{
|
|
||||||
return S_sfx[snd_id].bPlayerReserve; // Later this needs to be abstracted out of the engine itself. Right now that cannot be done.
|
|
||||||
}
|
|
||||||
void SetListener(SoundListener& l)
|
void SetListener(SoundListener& l)
|
||||||
{
|
{
|
||||||
listener = l;
|
listener = l;
|
||||||
}
|
}
|
||||||
|
const SoundListener& GetListener() const
|
||||||
|
{
|
||||||
|
return listener;
|
||||||
|
}
|
||||||
void SetRestartTime(int time)
|
void SetRestartTime(int time)
|
||||||
{
|
{
|
||||||
RestartEvictionsAt = time;
|
RestartEvictionsAt = time;
|
||||||
|
@ -371,6 +369,10 @@ public:
|
||||||
{
|
{
|
||||||
S_rnd.Clear();
|
S_rnd.Clear();
|
||||||
}
|
}
|
||||||
|
int *GetUserData(int snd)
|
||||||
|
{
|
||||||
|
return S_sfx[snd].UserData.Data();
|
||||||
|
}
|
||||||
bool isValidSoundId(int id)
|
bool isValidSoundId(int id)
|
||||||
{
|
{
|
||||||
return id > 0 && id < (int)S_sfx.Size() && !S_sfx[id].bTentative && S_sfx[id].lumpnum != sfx_empty;
|
return id > 0 && id < (int)S_sfx.Size() && !S_sfx[id].bTentative && S_sfx[id].lumpnum != sfx_empty;
|
||||||
|
@ -378,10 +380,13 @@ public:
|
||||||
|
|
||||||
template<class func> bool EnumerateChannels(func callback)
|
template<class func> bool EnumerateChannels(func callback)
|
||||||
{
|
{
|
||||||
for (FSoundChan* chan = Channels; chan; chan = chan->NextChan)
|
FSoundChan* chan = Channels;
|
||||||
|
while (chan)
|
||||||
{
|
{
|
||||||
|
auto next = chan->NextChan;
|
||||||
int res = callback(chan);
|
int res = callback(chan);
|
||||||
if (res) return res > 0;
|
if (res) return res > 0;
|
||||||
|
chan = next;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -403,8 +408,7 @@ public:
|
||||||
int FindSoundByResID(int rid);
|
int FindSoundByResID(int rid);
|
||||||
int FindSoundNoHash(const char* logicalname);
|
int FindSoundNoHash(const char* logicalname);
|
||||||
int FindSoundByLump(int lump);
|
int FindSoundByLump(int lump);
|
||||||
int AddSoundLump(const char* logicalname, int lump, int CurrentPitchMask, int resid = -1, int nearlimit = 2);
|
virtual int AddSoundLump(const char* logicalname, int lump, int CurrentPitchMask, int resid = -1, int nearlimit = 2);
|
||||||
int AddSfx(sfxinfo_t &sfx);
|
|
||||||
int FindSoundTentative(const char* name);
|
int FindSoundTentative(const char* name);
|
||||||
void CacheRandomSound(sfxinfo_t* sfx);
|
void CacheRandomSound(sfxinfo_t* sfx);
|
||||||
unsigned int GetMSLength(FSoundID sound);
|
unsigned int GetMSLength(FSoundID sound);
|
||||||
|
|
Loading…
Reference in a new issue