Merge branch 'master' into newrenderer2

This commit is contained in:
Christoph Oelckers 2021-04-12 15:06:12 +02:00
commit 10d0de8dbf
16 changed files with 122 additions and 73 deletions

View file

@ -31,6 +31,7 @@ enum EChanFlag
CHANF_OVERLAP = 8192, // [MK] Does not stop any sounds in the channel and instead plays over them. CHANF_OVERLAP = 8192, // [MK] Does not stop any sounds in the channel and instead plays over them.
CHANF_LOCAL = 16384, // only plays locally for the calling actor CHANF_LOCAL = 16384, // only plays locally for the calling actor
CHANF_TRANSIENT = 32768, // Do not record in savegames - used for sounds that get restarted outside the sound system (e.g. ambients in SW and Blood) CHANF_TRANSIENT = 32768, // Do not record in savegames - used for sounds that get restarted outside the sound system (e.g. ambients in SW and Blood)
CHANF_FORCE = 65536, // Start, even if sound is paused.
}; };
typedef TFlags<EChanFlag> EChanFlags; typedef TFlags<EChanFlag> EChanFlags;

View file

@ -528,7 +528,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
// sound is paused and a non-looped sound is being started. // sound is paused and a non-looped sound is being started.
// Such a sound would play right after unpausing which wouldn't sound right. // Such a sound would play right after unpausing which wouldn't sound right.
if (!(chanflags & CHANF_LOOP) && !(chanflags & (CHANF_UI|CHANF_NOPAUSE)) && SoundPaused) if (!(chanflags & CHANF_LOOP) && !(chanflags & (CHANF_UI|CHANF_NOPAUSE|CHANF_FORCE)) && SoundPaused)
{ {
return NULL; return NULL;
} }

View file

@ -293,7 +293,7 @@ bool F7ZFile::Open(bool quiet, LumpFilterInfo *filter)
lump_p->Owner = this; lump_p->Owner = this;
lump_p->Flags = LUMPF_FULLPATH|LUMPF_COMPRESSED; lump_p->Flags = LUMPF_FULLPATH|LUMPF_COMPRESSED;
lump_p->Position = i; lump_p->Position = i;
lump_p->CheckEmbedded(); lump_p->CheckEmbedded(filter);
lump_p++; lump_p++;
} }
// Resize the lump record array to its actual size // Resize the lump record array to its actual size

View file

@ -209,7 +209,7 @@ void FDirectory::AddEntry(const char *fullpath, int size)
lump_p->LumpSize = size; lump_p->LumpSize = size;
lump_p->Owner = this; lump_p->Owner = this;
lump_p->Flags = 0; lump_p->Flags = 0;
lump_p->CheckEmbedded(); lump_p->CheckEmbedded(nullptr);
} }

View file

@ -109,7 +109,7 @@ bool FPakFile::Open(bool quiet, LumpFilterInfo* filter)
Lumps[i].Owner = this; Lumps[i].Owner = this;
Lumps[i].Position = LittleLong(fileinfo[i].filepos); Lumps[i].Position = LittleLong(fileinfo[i].filepos);
Lumps[i].LumpSize = LittleLong(fileinfo[i].filelen); Lumps[i].LumpSize = LittleLong(fileinfo[i].filelen);
Lumps[i].CheckEmbedded(); Lumps[i].CheckEmbedded(filter);
} }
GenerateHash(); GenerateHash();
PostProcessArchive(&Lumps[0], sizeof(Lumps[0]), filter); PostProcessArchive(&Lumps[0], sizeof(Lumps[0]), filter);

View file

@ -337,7 +337,7 @@ bool FZipFile::Open(bool quiet, LumpFilterInfo* filter)
lump_p->CRC32 = zip_fh->CRC32; lump_p->CRC32 = zip_fh->CRC32;
lump_p->CompressedSize = LittleLong(zip_fh->CompressedSize); lump_p->CompressedSize = LittleLong(zip_fh->CompressedSize);
lump_p->Position = LittleLong(zip_fh->LocalHeaderOffset); lump_p->Position = LittleLong(zip_fh->LocalHeaderOffset);
lump_p->CheckEmbedded(); lump_p->CheckEmbedded(filter);
lump_p++; lump_p++;
} }

View file

@ -122,7 +122,7 @@ static bool IsWadInFolder(const FResourceFile* const archive, const char* const
return 0 == filePath.CompareNoCase(resPath); return 0 == filePath.CompareNoCase(resPath);
} }
void FResourceLump::CheckEmbedded() void FResourceLump::CheckEmbedded(LumpFilterInfo* lfi)
{ {
// Checks for embedded archives // Checks for embedded archives
const char *c = strstr(FullName, ".wad"); const char *c = strstr(FullName, ".wad");
@ -130,22 +130,13 @@ void FResourceLump::CheckEmbedded()
{ {
Flags |= LUMPF_EMBEDDED; Flags |= LUMPF_EMBEDDED;
} }
/* later else if (lfi) for (auto& fstr : lfi->embeddings)
else
{ {
if (c==NULL) c = strstr(Name, ".zip"); if (!stricmp(FullName, fstr))
if (c==NULL) c = strstr(Name, ".pk3");
if (c==NULL) c = strstr(Name, ".7z");
if (c==NULL) c = strstr(Name, ".pak");
if (c && strlen(c) <= 4)
{ {
// Mark all embedded archives in any directory
Flags |= LUMPF_EMBEDDED; Flags |= LUMPF_EMBEDDED;
memset(Name, 0, 8);
} }
} }
*/
} }

View file

@ -15,6 +15,7 @@ struct LumpFilterInfo
// The following are for checking if the root directory of a zip can be removed. // The following are for checking if the root directory of a zip can be removed.
TArray<FString> reservedFolders; TArray<FString> reservedFolders;
TArray<FString> requiredPrefixes; TArray<FString> requiredPrefixes;
TArray<FString> embeddings;
std::function<void()> postprocessFunc; std::function<void()> postprocessFunc;
}; };
@ -111,7 +112,7 @@ public:
virtual int GetIndexNum() const { return -1; } virtual int GetIndexNum() const { return -1; }
virtual int GetNamespace() const { return 0; } virtual int GetNamespace() const { return 0; }
void LumpNameSetup(FString iname); void LumpNameSetup(FString iname);
void CheckEmbedded(); void CheckEmbedded(LumpFilterInfo* lfi);
virtual FCompressedBuffer GetRawData(); virtual FCompressedBuffer GetRawData();
void *Lock(); // validates the cache and increases the refcount. void *Lock(); // validates the cache and increases the refcount.

View file

@ -388,6 +388,11 @@ void InitFileSystem(TArray<GrpEntry>& groups)
LumpFilterInfo lfi; LumpFilterInfo lfi;
for (auto p : iwad_folders) lfi.reservedFolders.Push(p); for (auto p : iwad_folders) lfi.reservedFolders.Push(p);
for (auto p = iwad_reserved(); *p; p++) lfi.requiredPrefixes.Push(*p); for (auto p = iwad_reserved(); *p; p++) lfi.requiredPrefixes.Push(*p);
if (isBlood())
{
lfi.embeddings.Push("blood.rff");
lfi.embeddings.Push("sounds.rff");
}
lfi.dotFilter = LumpFilter; lfi.dotFilter = LumpFilter;

View file

@ -208,10 +208,10 @@ void S_SerializeSounds(FSerializer& arc)
{ {
FSoundChan* chan; FSoundChan* chan;
GSnd->Sync(true); GSnd->Sync(true);
if (arc.isWriting()) if (arc.isWriting())
{ {
// Count channels and accumulate them so we can store them in // Count channels and accumulate them so we can store them in
// reverse order. That way, they will be in the same order when // reverse order. That way, they will be in the same order when
// reloaded later as they are now. // reloaded later as they are now.
@ -229,9 +229,9 @@ void S_SerializeSounds(FSerializer& arc)
} }
arc.EndArray(); arc.EndArray();
} }
} }
else else
{ {
unsigned int count; unsigned int count;
soundEngine->StopAllChannels(); soundEngine->StopAllChannels();
@ -249,8 +249,66 @@ void S_SerializeSounds(FSerializer& arc)
} }
// Add a small delay so that eviction only runs once the game is up and runnnig. // Add a small delay so that eviction only runs once the game is up and runnnig.
soundEngine->SetRestartTime(I_GetTime() + 2); soundEngine->SetRestartTime(I_GetTime() + 2);
} }
GSnd->Sync(false); GSnd->Sync(false);
GSnd->UpdateSounds(); GSnd->UpdateSounds();
} }
//==========================================================================
//
// CCMD playsound
//
//==========================================================================
CCMD(playsound)
{
if (argv.argc() > 1)
{
FSoundID id = argv[1];
if (id == 0)
{
Printf("'%s' is not a sound\n", argv[1]);
}
else
{
soundEngine->StartSound(SOURCE_None, nullptr, nullptr, CHAN_AUTO, CHANF_UI | CHANF_NOPAUSE, id, 1.f, ATTN_NORM);
}
}
}
//==========================================================================
//
// CCMD playsound
//
//==========================================================================
CCMD(playsoundid)
{
if (argv.argc() > 1)
{
FSoundID id = soundEngine->FindSoundByResID((int)strtol(argv[1], nullptr, 0));
if (id == 0)
{
Printf("'%s' is not a sound\n", argv[1]);
}
else
{
soundEngine->StartSound(SOURCE_None, nullptr, nullptr, CHAN_AUTO, CHANF_UI | CHANF_NOPAUSE, id, 1.f, ATTN_NORM);
}
}
}
//==========================================================================
//
// CCMD listsounds
//
//==========================================================================
CCMD(listsounds)
{
auto& S_sfx = soundEngine->GetSounds();
for (unsigned i = 0; i < S_sfx.Size(); i++)
{
Printf("%4d: name = %s, resId = %d, lumpnum = %d\n", i, S_sfx[i].name.GetChars(), S_sfx[i].ResourceId, S_sfx[i].lumpnum);
}
}

View file

@ -2854,7 +2854,7 @@ spritetype *actDropObject(spritetype *pSprite, int nType) {
else if (nType >= kItemAmmoBase && nType < kItemAmmoMax) pSprite2 = actDropAmmo(pSprite, nType); else if (nType >= kItemAmmoBase && nType < kItemAmmoMax) pSprite2 = actDropAmmo(pSprite, nType);
else if (nType >= kItemWeaponBase && nType < kItemWeaponMax) pSprite2 = actDropWeapon(pSprite, nType); else if (nType >= kItemWeaponBase && nType < kItemWeaponMax) pSprite2 = actDropWeapon(pSprite, nType);
if (pSprite2) { if (pSprite2 && pSprite->picnum > -1) {
int top, bottom; int top, bottom;
GetSpriteExtents(pSprite2, &top, &bottom); GetSpriteExtents(pSprite2, &top, &bottom);
if (bottom >= pSprite2->z) if (bottom >= pSprite2->z)

View file

@ -121,7 +121,8 @@ static const char* DefFile(void)
int numlumps = fileSystem.GetNumEntries(); int numlumps = fileSystem.GetNumEntries();
for (int i = numlumps - 1; i >= 0; i--) for (int i = numlumps - 1; i >= 0; i--)
{ {
if (fileSystem.GetFileContainer(i) <= fileSystem.GetMaxIwadNum()) break; int fileno = fileSystem.GetFileContainer(i);
if (fileno != -1 && fileno <= fileSystem.GetMaxIwadNum()) break;
FString fn = fileSystem.GetFileFullName(i, false); FString fn = fileSystem.GetFileFullName(i, false);
FString ext = fn.Right(4); FString ext = fn.Right(4);
if (ext.CompareNoCase(".ini") == 0) if (ext.CompareNoCase(".ini") == 0)

View file

@ -58,15 +58,6 @@ public:
}; };
void sfxInit(void)
{
soundEngine = new BloodSoundEngine;
}
void sfxTerm()
{
}
//========================================================================== //==========================================================================
// //
// //
@ -149,7 +140,8 @@ FSoundID getSfx(FSoundID soundId, float &attenuation, int &pitch, int &relvol)
auto udata = soundEngine->GetUserData(soundId); auto udata = soundEngine->GetUserData(soundId);
if (pitch < 0) pitch = udata ? udata[0] : 0x10000; if (pitch < 0) pitch = udata ? udata[0] : 0x10000;
if (relvol < 0) relvol = udata && udata[2] ? udata[2] : 80; if (relvol < 0) relvol = 0;
else if (relvol == 0) relvol = udata && udata[2] ? udata[2] : 80;
if (relvol > 255) relvol = 255; if (relvol > 255) relvol = 255;
// Limit the attenuation. More than 2.0 is simply too much. // Limit the attenuation. More than 2.0 is simply too much.
attenuation = relvol > 0 ? clamp(80.f / relvol, 0.f, 2.f) : 1.f; attenuation = relvol > 0 ? clamp(80.f / relvol, 0.f, 2.f) : 1.f;
@ -167,7 +159,7 @@ void sfxPlay3DSound(int x, int y, int z, int soundId, int nSector)
float attenuation; float attenuation;
int pitch = -1; int pitch = -1;
int relvol = -1; int relvol = 0;
sid = getSfx(sid, attenuation, pitch, relvol); sid = getSfx(sid, attenuation, pitch, relvol);
auto sfx = soundEngine->GetSfx(sid); auto sfx = soundEngine->GetSfx(sid);
EChanFlags flags = CHANF_OVERLAP; EChanFlags flags = CHANF_OVERLAP;
@ -225,7 +217,7 @@ void sfxPlay3DSoundCP(spritetype* pSprite, int soundId, int a3, int a4, int pitc
void sfxPlay3DSound(spritetype* pSprite, int soundId, int a3, int a4) void sfxPlay3DSound(spritetype* pSprite, int soundId, int a3, int a4)
{ {
sfxPlay3DSoundCP(pSprite, soundId, a3, a4, -1, -1); sfxPlay3DSoundCP(pSprite, soundId, a3, a4, -1);
} }

View file

@ -106,7 +106,8 @@ static void S_AddBloodSFX(int lumpnum)
void sndInit(void) void sndInit(void)
{ {
sfxInit(); soundEngine = new BloodSoundEngine;
soundEngine->AddSoundLump("", 0, 0, -1, 6); // add a dummy entry at index #0
for (int i = fileSystem.GetNumEntries() - 1; i >= 0; i--) for (int i = fileSystem.GetNumEntries() - 1; i >= 0; i--)
{ {
auto type = fileSystem.GetResourceType(i); auto type = fileSystem.GetResourceType(i);
@ -117,6 +118,7 @@ void sndInit(void)
} }
else if (!stricmp(type, "WAV") || !stricmp(type, "OGG") || !stricmp(type, "FLAC") || !stricmp(type, "VOC")) else if (!stricmp(type, "WAV") || !stricmp(type, "OGG") || !stricmp(type, "FLAC") || !stricmp(type, "VOC"))
{ {
if (fileSystem.GetFileNamespace(i) != ns_music)
soundEngine->AddSoundLump(fileSystem.GetFileFullName(i), i, 0, fileSystem.GetResourceId(i)| 0x40000000, 6); // mark the resource ID as special. soundEngine->AddSoundLump(fileSystem.GetFileFullName(i), i, 0, fileSystem.GetResourceId(i)| 0x40000000, 6); // mark the resource ID as special.
} }
} }

View file

@ -50,11 +50,9 @@ void sndProcess(void);
void sndTerm(void); void sndTerm(void);
void sndInit(void); void sndInit(void);
void sfxInit(void);
void sfxTerm(void);
void sfxPlay3DSound(int x, int y, int z, int soundId, int nSector); void sfxPlay3DSound(int x, int y, int z, int soundId, int nSector);
void sfxPlay3DSound(spritetype *pSprite, int soundId, int a3 = -1, int a4 = 0); void sfxPlay3DSound(spritetype *pSprite, int soundId, int a3 = -1, int a4 = 0);
void sfxPlay3DSoundCP(spritetype* pSprite, int soundId, int a3 = -1, int a4 = 0, int pitch = 0, int volume = -1); void sfxPlay3DSoundCP(spritetype* pSprite, int soundId, int a3 = -1, int a4 = 0, int pitch = 0, int volume = 0);
void sfxKill3DSound(spritetype *pSprite, int a2 = -1, int a3 = -1); void sfxKill3DSound(spritetype *pSprite, int a2 = -1, int a3 = -1);
void sfxKillAllSounds(void); void sfxKillAllSounds(void);
void sfxSetReverb(bool toggle); void sfxSetReverb(bool toggle);

View file

@ -595,7 +595,7 @@ void OperateSprite(int nSprite, XSPRITE *pXSprite, EVENT event)
break; break;
gMe->restTime = 0; gMe->restTime = 0;
} }
sndStartSample(pXSprite->data1, -1, 1, 0); sndStartSample(pXSprite->data1, -1, 1, 0, CHANF_FORCE);
break; break;
case kThingObjectGib: case kThingObjectGib:
case kThingObjectExplode: case kThingObjectExplode: