mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 00:42:08 +00:00
- did a bit of optimization on sfxinfo_t.
Using two bytes of alignment gap to add a userval variable.
This commit is contained in:
parent
1468bedf4c
commit
92f2503160
7 changed files with 24 additions and 44 deletions
|
@ -90,6 +90,7 @@ constexpr FSoundID INVALID_SOUND = FSoundID::fromInt(-1);
|
|||
float DefPitchMax = 0.f; // Randomized range with stronger control over pitch itself.
|
||||
|
||||
int16_t NearLimit = 4; // 0 means unlimited.
|
||||
int16_t UserVal = 0; // repurpose this gap for something useful
|
||||
uint8_t PitchMask = 0;
|
||||
bool bRandomHeader = false;
|
||||
bool bLoadRAW = false;
|
||||
|
@ -99,17 +100,16 @@ constexpr FSoundID INVALID_SOUND = FSoundID::fromInt(-1);
|
|||
bool bTentative = true;
|
||||
bool bExternal = false;
|
||||
|
||||
TArray<int> UserData;
|
||||
|
||||
int RawRate = 0; // Sample rate to use when bLoadRAW is true
|
||||
int LoopStart = -1; // -1 means no specific loop defined
|
||||
int LoopEnd = -1; // -1 means no specific loop defined
|
||||
float Attenuation = 1.f; // Multiplies the attenuation passed to S_Sound.
|
||||
|
||||
FSoundID link = NO_LINK;
|
||||
constexpr static FSoundID NO_LINK = FSoundID::fromInt(-1);
|
||||
|
||||
TArray<int> UserData;
|
||||
FRolloffInfo Rolloff{};
|
||||
float Attenuation = 1.f; // Multiplies the attenuation passed to S_Sound.
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -493,7 +493,7 @@ static void S_AddSNDINFO (int lump)
|
|||
sfx->UserData.Resize(Duke3d::kMaxUserData);
|
||||
memset(sfx->UserData.Data(), 0, Duke3d::kMaxUserData * sizeof(int));
|
||||
}
|
||||
sfx->UserData[Duke3d::kFlags] = flags;
|
||||
sfx->UserVal = flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -523,11 +523,7 @@ static void S_AddSNDINFO (int lump)
|
|||
if (isSWALL())
|
||||
{
|
||||
auto sfx = soundEngine->GetWritableSfx(sfxid);
|
||||
if (sfx->UserData.Size() < 1)
|
||||
{
|
||||
sfx->UserData.Resize(1);
|
||||
}
|
||||
sfx->UserData[0] = flags;
|
||||
sfx->UserVal = flags;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -560,11 +556,7 @@ static void S_AddSNDINFO (int lump)
|
|||
if (isBlood())
|
||||
{
|
||||
auto sfx = soundEngine->GetWritableSfx(sfxid);
|
||||
if (sfx->UserData.Size() < 1)
|
||||
{
|
||||
sfx->UserData.Resize(1);
|
||||
}
|
||||
sfx->UserData[0] = sc.Number;
|
||||
sfx->UserVal = sc.Number;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -149,10 +149,10 @@ void GameInterface::UpdateSounds()
|
|||
|
||||
FSoundID getSfx(FSoundID soundId, float& attenuation, int& relvol)
|
||||
{
|
||||
auto udata = soundEngine->GetUserData(soundId);
|
||||
auto udata = soundEngine->GetSfx(soundId);
|
||||
|
||||
if (relvol < 0) relvol = 0;
|
||||
else if (relvol == 0) relvol = udata && udata[0] ? udata[0] : 80;
|
||||
else if (relvol == 0) relvol = udata && udata->UserVal ? udata->UserVal : 80;
|
||||
if (relvol > 255) relvol = 255;
|
||||
// Limit the attenuation. More than 2.0 is simply too much.
|
||||
attenuation = relvol > 0 ? clamp(80.f / relvol, 0.f, 2.f) : 1.f;
|
||||
|
|
|
@ -91,7 +91,6 @@ static void S_AddBloodSFX(int lumpnum)
|
|||
{
|
||||
sfxnum = soundEngine->AddSoundLump(FStringf("SfxSound@%04d", resid), rawlump, 0, resid, 6); // use a generic name here in case sound replacements are being used.
|
||||
soundfx = soundEngine->GetWritableSfx(sfxnum);
|
||||
soundfx->UserData.Resize(1);
|
||||
}
|
||||
if (sfx->format < 5 || sfx->format > 12)
|
||||
{ // [0..4] + invalid formats
|
||||
|
@ -117,8 +116,7 @@ static void S_AddBloodSFX(int lumpnum)
|
|||
else soundfx->DefPitch = 0;
|
||||
if (sfx->relVol != 80) // 80 is the default
|
||||
{
|
||||
soundfx->UserData.Resize(1);
|
||||
soundfx->UserData[0] = sfx->relVol;
|
||||
soundfx->UserVal = sfx->relVol;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -211,8 +209,8 @@ void sndStartSample(unsigned int nSound, int nVolume, int nChannel, bool bLoop,
|
|||
{
|
||||
if (nVolume < 0)
|
||||
{
|
||||
auto udata = soundEngine->GetUserData(snd);
|
||||
if (udata) nVolume = min(Scale(udata[0], 255, 80), 255);
|
||||
auto udata = soundEngine->GetSfx(snd);
|
||||
if (udata) nVolume = min(Scale(udata->UserVal, 255, 80), 255);
|
||||
else nVolume = 255;
|
||||
}
|
||||
if (bLoop) chanflags |= CHANF_LOOP;
|
||||
|
|
|
@ -176,9 +176,9 @@ void S_CacheAllSounds(void)
|
|||
int S_GetUserFlags(FSoundID soundid)
|
||||
{
|
||||
if (!soundEngine->isValidSoundId(soundid)) return 0;
|
||||
auto const* snd = soundEngine->GetUserData(soundid);
|
||||
auto const* snd = soundEngine->GetSfx(soundid);
|
||||
if (!snd) return 0;
|
||||
return snd[kFlags];
|
||||
return snd->UserVal;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
@ -222,15 +222,14 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit
|
|||
auto& sndinf = sfx->UserData;
|
||||
sndinf[kVolAdjust] = 0;
|
||||
sndinf[kWorldTourMapping] = 0;
|
||||
sndinf[kFlags] = 0;
|
||||
sfx->UserVal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sfx->ResourceId = index;
|
||||
sfx->UserData.Resize(kMaxUserData);
|
||||
sfx->bExternal = true;
|
||||
auto& sndinf = sfx->UserData;
|
||||
sndinf[kFlags] = (type & SF_CON_MASK);
|
||||
sfx->UserVal = (type & SF_CON_MASK);
|
||||
|
||||
// Take care of backslashes in sound names. Also double backslashes which occur in World Tour.
|
||||
FString fn = filename;
|
||||
|
@ -250,8 +249,8 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit
|
|||
sfx->DefPitch = (float)pow(2, clamp<int>(minpitch, INT16_MIN, INT16_MAX) / 1200.);
|
||||
sfx->DefPitchMax = (float)pow(2, clamp<int>(maxpitch, INT16_MIN, INT16_MAX) / 1200.);
|
||||
}
|
||||
sndinf[kVolAdjust] = clamp<int>(distance, INT16_MIN, INT16_MAX);
|
||||
sndinf[kWorldTourMapping] = 0;
|
||||
sfx->UserData[kVolAdjust] = clamp<int>(distance, INT16_MIN, INT16_MAX);
|
||||
sfx->UserData[kWorldTourMapping] = 0;
|
||||
sfx->Volume = volume;
|
||||
sfx->bTentative = false;
|
||||
return 0;
|
||||
|
@ -276,9 +275,9 @@ static int GetPositionInfo(DDukeActor* actor, FSoundID soundid, sectortype* sect
|
|||
// However, ultimately rolloff would also just reposition the sound source so this can remain as it is.
|
||||
|
||||
int orgsndist = 0, sndist = 0;
|
||||
auto const* snd = soundEngine->GetUserData(soundid);
|
||||
int userflags = snd ? snd[kFlags] : 0;
|
||||
int dist_adjust = snd ? snd[kVolAdjust] : 0;
|
||||
auto const* sfx = soundEngine->GetSfx(soundid);
|
||||
int userflags = sfx->UserVal;
|
||||
int dist_adjust = sfx->UserData.Size() ? sfx->UserData[kVolAdjust] : 0;
|
||||
|
||||
FVector3 sndorg = GetSoundPos(pos);
|
||||
FVector3 campos = GetSoundPos(cam);
|
||||
|
|
|
@ -26,7 +26,6 @@ enum {
|
|||
enum esound_t
|
||||
{
|
||||
kVolAdjust,
|
||||
kFlags,
|
||||
kWorldTourMapping,
|
||||
kMaxUserData
|
||||
};
|
||||
|
|
|
@ -216,7 +216,7 @@ void InitAmbient(int num, DSWActor* actor)
|
|||
amb->vocIndex = vnum;
|
||||
amb->ChanFlags = CHANF_TRANSIENT;
|
||||
if (ambarray[num].ambient_flags & v3df_dontpan) amb->ChanFlags |= EChanFlags::FromInt(CHANEXF_DONTPAN);
|
||||
if (sfx->UserData[0] & SFLAG_LOOP) amb->ChanFlags |= CHANF_LOOP;
|
||||
if (sfx->UserVal & SFLAG_LOOP) amb->ChanFlags |= CHANF_LOOP;
|
||||
amb->maxIndex = ambarray[num].maxtics;
|
||||
amb->curIndex = 0;
|
||||
amb->intermit = !!(ambarray[num].ambient_flags & v3df_intermit);
|
||||
|
@ -432,14 +432,6 @@ void InitFX(void)
|
|||
{
|
||||
|
||||
auto &S_sfx = soundEngine->GetSounds();
|
||||
for (auto& sfx : S_sfx)
|
||||
{
|
||||
if (sfx.UserData.Size() < 1)
|
||||
{
|
||||
sfx.UserData.Resize(1);
|
||||
sfx.UserData[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
soundEngine->HashSounds();
|
||||
for (auto& sfx : S_sfx)
|
||||
|
@ -632,7 +624,7 @@ int _PlaySound(const FSoundID sndid, DSWActor* actor, PLAYER* pp, const DVector3
|
|||
|
||||
//if (flags & v3df_doppler) cflags |= EChanFlags::FromInt(CHANEXF_NODOPPLER); // intentionally not implemented
|
||||
//if (flags & v3df_dontpan) cflags |= EChanFlags::FromInt(CHANEXF_DONTPAN); // disabled due to poor use
|
||||
if (sfx->UserData[0] & SFLAG_LOOP) cflags |= CHANF_LOOP; // with the new sound engine these can just be started and don't have to be stopped ever.
|
||||
if (sfx->UserVal & SFLAG_LOOP) cflags |= CHANF_LOOP; // with the new sound engine these can just be started and don't have to be stopped ever.
|
||||
|
||||
FVector3 spos = GetSoundPos(pos);
|
||||
auto chan = soundEngine->StartSound(sourcetype, source, &spos, channel, cflags, sndid, 1.f, ATTN_NORM);
|
||||
|
@ -772,11 +764,11 @@ int _PlayerSound(int num, PLAYER* pp)
|
|||
// If this is a player voice and he's already yacking, forget it.
|
||||
|
||||
// Not a player voice, bail.
|
||||
if (!(sfx->UserData[0] & (SFLAG_PLAYERSPEECH|SFLAG_PLAYERVOICE)))
|
||||
if (!(sfx->UserVal & (SFLAG_PLAYERSPEECH|SFLAG_PLAYERVOICE)))
|
||||
return 0;
|
||||
|
||||
// Don't talk if not allowed to.
|
||||
if ((sfx->UserData[0] & SFLAG_PLAYERSPEECH) && !snd_speech)
|
||||
if ((sfx->UserVal & SFLAG_PLAYERSPEECH) && !snd_speech)
|
||||
return 0;
|
||||
|
||||
// The surfacing sound should not block other player speech.
|
||||
|
|
Loading…
Reference in a new issue