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.
This commit is contained in:
Zandrewnum 2021-04-15 14:31:22 -07:00 committed by Christoph Oelckers
parent 4c9461d364
commit a5cf0c6605
4 changed files with 12 additions and 13 deletions

View file

@ -391,7 +391,7 @@ public:
float BlendB = 0; float BlendB = 0;
float BlendA = 0; float BlendA = 0;
FString SoundClass = "player"; FString SoundClass = "";
FString LogText; // [RH] Log for Strife FString LogText; // [RH] Log for Strife
FString SubtitleText; FString SubtitleText;
int SubtitleCounter; int SubtitleCounter;

View file

@ -4313,6 +4313,10 @@ void DLevelScript::DoSetActorProperty (AActor *actor, int property, int value)
{ {
if (actor->player != NULL) if (actor->player != NULL)
{ {
if(!strcmp(Level->Behaviors.LookupString(value), ""))
{
actor->player->SoundClass = "";
}
actor->player->SoundClass = Level->Behaviors.LookupString(value); 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_MaxStepHeight: return DoubleToACS(actor->MaxStepHeight);
case APROP_MaxDropOffHeight: return DoubleToACS(actor->MaxDropOffHeight); case APROP_MaxDropOffHeight: return DoubleToACS(actor->MaxDropOffHeight);
case APROP_DamageType: return GlobalACSStrings.AddString(actor->DamageType.GetChars()); 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; 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_Species: string = actor->GetSpecies().GetChars(); break;
case APROP_NameTag: string = actor->GetTag(); break; case APROP_NameTag: string = actor->GetTag(); break;
case APROP_DamageType: string = actor->DamageType.GetChars(); 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 = ""; if (string == NULL) string = "";
return (!stricmp(string, Level->Behaviors.LookupString(value))); return (!stricmp(string, Level->Behaviors.LookupString(value)));

View file

@ -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; 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 && if (player != nullptr &&
(player->mo == nullptr || !(player->mo->flags4 &MF4_NOSKIN)) && (player->mo == nullptr || !(player->mo->flags4 &MF4_NOSKIN)) &&
(unsigned int)player->userinfo.GetSkin() >= PlayerClasses.Size() && (unsigned int)player->userinfo.GetSkin() >= PlayerClasses.Size() &&
(unsigned)player->userinfo.GetSkin() < Skins.Size() && (unsigned)player->userinfo.GetSkin() < Skins.Size() &&
strcmp(pp->player->SoundClass.GetChars(),sclass) == 0) player->SoundClass.IsEmpty())
{ {
return Skins[player->userinfo.GetSkin()].Name.GetChars(); 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";
} }
//========================================================================== //==========================================================================

View file

@ -70,6 +70,7 @@ bool S_AreSoundsEquivalent (AActor *actor, int id1, int id2);
bool S_AreSoundsEquivalent (AActor *actor, const char *name1, const char *name2); 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, const char *logicalname);
int S_LookupPlayerSound (const char *playerclass, int gender, FSoundID refid); int S_LookupPlayerSound (const char *playerclass, int gender, FSoundID refid);
const char *GetSoundClass(AActor *pp);
int S_FindSkinnedSound (AActor *actor, FSoundID refid); int S_FindSkinnedSound (AActor *actor, FSoundID refid);
int S_FindSkinnedSoundEx (AActor *actor, const char *logicalname, const char *extendedname); 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 int S_AddSound (const char *logicalname, const char *lumpname, FScanner *sc=NULL); // Add sound by lumpname