From a5cf0c6605d9910e96fd530675854018f26554c8 Mon Sep 17 00:00:00 2001 From: Zandrewnum Date: Thu, 15 Apr 2021 14:31:22 -0700 Subject: [PATCH] Sound Class renovations - SoundClass is instantiated to "" by default. Since this property is only used when it is not empty (otherwise GetSoundClass just defaults to player), we can get away with this. - We may want the soundclass to remain the same if we explicitly set it to the same one that is currently used (say, we set SoundClass to "Caleb" so all other skins can use it) - GetActorProperty for APROP_SoundClass just calls GetSoundClass, - CheckActorProperty also just runs GetSoundClass - GetSoundClass is no longer a static method. We needed to access it in other places. - Made renovations to GetSoundClass. First of all, SoundClass is no longer instantiated there. Secondly, skinned sounds are now returned if SoundClass is empty. Thirdly, "sclass" in this method will return the default soundclass of the player pawn or SoundClass, depending on if SoundClass is empty. Finally, sclass will retrieve "player" if it is empty. --- src/playsim/d_player.h | 2 +- src/playsim/p_acs.cpp | 8 ++++++-- src/sound/s_advsound.cpp | 14 ++++---------- src/sound/s_sound.h | 1 + 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/playsim/d_player.h b/src/playsim/d_player.h index 3c649b5db..44f72d002 100644 --- a/src/playsim/d_player.h +++ b/src/playsim/d_player.h @@ -391,7 +391,7 @@ public: float BlendB = 0; float BlendA = 0; - FString SoundClass = "player"; + FString SoundClass = ""; FString LogText; // [RH] Log for Strife FString SubtitleText; int SubtitleCounter; diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index c67ec1cc5..fe7eba54f 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -4313,6 +4313,10 @@ void DLevelScript::DoSetActorProperty (AActor *actor, int property, int value) { if (actor->player != NULL) { + if(!strcmp(Level->Behaviors.LookupString(value), "")) + { + actor->player->SoundClass = ""; + } actor->player->SoundClass = Level->Behaviors.LookupString(value); } } @@ -4416,7 +4420,7 @@ int DLevelScript::GetActorProperty (int tid, int property) case APROP_MaxStepHeight: return DoubleToACS(actor->MaxStepHeight); case APROP_MaxDropOffHeight: return DoubleToACS(actor->MaxDropOffHeight); case APROP_DamageType: return GlobalACSStrings.AddString(actor->DamageType.GetChars()); - case APROP_SoundClass: return GlobalACSStrings.AddString(actor->player->SoundClass.GetChars()); + case APROP_SoundClass: return GlobalACSStrings.AddString(GetSoundClass(actor)); default: return 0; } @@ -4490,7 +4494,7 @@ int DLevelScript::CheckActorProperty (int tid, int property, int value) case APROP_Species: string = actor->GetSpecies().GetChars(); break; case APROP_NameTag: string = actor->GetTag(); break; case APROP_DamageType: string = actor->DamageType.GetChars(); break; - case APROP_SoundClass: string = actor->player->SoundClass; break; + case APROP_SoundClass: string = GetSoundClass(actor); break; } if (string == NULL) string = ""; return (!stricmp(string, Level->Behaviors.LookupString(value))); diff --git a/src/sound/s_advsound.cpp b/src/sound/s_advsound.cpp index 5a9c4be9d..5699b327b 100644 --- a/src/sound/s_advsound.cpp +++ b/src/sound/s_advsound.cpp @@ -1608,27 +1608,21 @@ bool S_AreSoundsEquivalent (AActor *actor, int id1, int id2) // //=========================================================================== -static const char *GetSoundClass(AActor *pp) +const char *GetSoundClass(AActor *pp) { auto player = pp->player; - /*I couldn't just init SoundClass to NAME_SoundClass, GZDoom won't launch at all. Probably because that info is not parsed by the time the variable is initialized. - So I just SoundClass to NAME_SoundClass here if NAME_SoundClass is not null and the current SoundClass is player*/ - if (strcmp(pp->player->SoundClass.GetChars(), "player") == 0 && pp->NameVar(NAME_SoundClass) != NAME_None) - pp->player->SoundClass = pp->NameVar(NAME_SoundClass).GetChars(); - - FString sclass = player ? pp->player->SoundClass.GetChars() : "player"; - if (player != nullptr && (player->mo == nullptr || !(player->mo->flags4 &MF4_NOSKIN)) && (unsigned int)player->userinfo.GetSkin() >= PlayerClasses.Size() && (unsigned)player->userinfo.GetSkin() < Skins.Size() && - strcmp(pp->player->SoundClass.GetChars(),sclass) == 0) + player->SoundClass.IsEmpty()) { return Skins[player->userinfo.GetSkin()].Name.GetChars(); } + auto sclass = player->SoundClass.IsEmpty() ? pp->NameVar(NAME_SoundClass).GetChars() : player->SoundClass.GetChars(); - return sclass; + return sclass ? sclass : "player"; } //========================================================================== diff --git a/src/sound/s_sound.h b/src/sound/s_sound.h index c8bcf7ebc..29b2f7b2b 100644 --- a/src/sound/s_sound.h +++ b/src/sound/s_sound.h @@ -70,6 +70,7 @@ bool S_AreSoundsEquivalent (AActor *actor, int id1, int id2); bool S_AreSoundsEquivalent (AActor *actor, const char *name1, const char *name2); int S_LookupPlayerSound (const char *playerclass, int gender, const char *logicalname); int S_LookupPlayerSound (const char *playerclass, int gender, FSoundID refid); +const char *GetSoundClass(AActor *pp); int S_FindSkinnedSound (AActor *actor, FSoundID refid); int S_FindSkinnedSoundEx (AActor *actor, const char *logicalname, const char *extendedname); int S_AddSound (const char *logicalname, const char *lumpname, FScanner *sc=NULL); // Add sound by lumpname