From 70121799046e74bb742c8c0a914005a46d8d612e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Nov 2018 07:43:05 +0100 Subject: [PATCH] - moved MarkPrecacheSounds completely to the script side and added native support to make this a usable feature. --- src/actor.h | 2 -- src/d_player.h | 1 - src/g_inventory/a_pickups.cpp | 12 ----------- src/g_inventory/a_pickups.h | 1 - src/g_inventory/a_weapons.cpp | 12 ----------- src/g_inventory/a_weapons.h | 2 -- src/p_mobj.cpp | 20 ------------------- src/p_user.cpp | 10 +++++----- src/s_advsound.cpp | 18 +++++++++++++---- src/s_sound.cpp | 5 ----- wadsrc/static/zscript/actor.txt | 13 +++++++++++- wadsrc/static/zscript/base.txt | 1 + wadsrc/static/zscript/inventory/inventory.txt | 11 ++++++++++ wadsrc/static/zscript/inventory/weapons.txt | 12 +++++++++++ wadsrc/static/zscript/shared/player.txt | 13 ++++++++++++ .../static/zscript/shared/soundsequence.txt | 8 ++++++++ 16 files changed, 76 insertions(+), 65 deletions(-) diff --git a/src/actor.h b/src/actor.h index bd6b51a4da..b6d67cd184 100644 --- a/src/actor.h +++ b/src/actor.h @@ -685,8 +685,6 @@ public: void LevelSpawned(); // Called after BeginPlay if this actor was spawned by the world void HandleSpawnFlags(); // Translates SpawnFlags into in-game flags. - virtual void MarkPrecacheSounds() const; // Marks sounds used by this actor for precaching. - virtual void Activate (AActor *activator); void CallActivate(AActor *activator); diff --git a/src/d_player.h b/src/d_player.h index 6099b57aea..1008f837d4 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -92,7 +92,6 @@ public: virtual void AddInventory (AInventory *item) override; virtual void RemoveInventory (AInventory *item) override; virtual bool UseInventory (AInventory *item) override; - virtual void MarkPrecacheSounds () const override; virtual void BeginPlay () override; virtual bool UpdateWaterLevel (bool splash) override; diff --git a/src/g_inventory/a_pickups.cpp b/src/g_inventory/a_pickups.cpp index ac9cbe330f..1399915ee6 100644 --- a/src/g_inventory/a_pickups.cpp +++ b/src/g_inventory/a_pickups.cpp @@ -161,18 +161,6 @@ bool AInventory::Massacre() return false; } -//=========================================================================== -// -// AInventory :: MarkPrecacheSounds -// -//=========================================================================== - -void AInventory::MarkPrecacheSounds() const -{ - Super::MarkPrecacheSounds(); - PickupSound.MarkUsed(); -} - //=========================================================================== // // AInventory :: Grind diff --git a/src/g_inventory/a_pickups.h b/src/g_inventory/a_pickups.h index 3815c6f771..7e4ad03f1d 100644 --- a/src/g_inventory/a_pickups.h +++ b/src/g_inventory/a_pickups.h @@ -72,7 +72,6 @@ public: virtual void Finalize(FStateDefinitions &statedef) override; virtual void Serialize(FSerializer &arc) override; - virtual void MarkPrecacheSounds() const override; virtual void OnDestroy() override; virtual void Tick() override; virtual bool Massacre() override; diff --git a/src/g_inventory/a_weapons.cpp b/src/g_inventory/a_weapons.cpp index f9e6357564..8758a132df 100644 --- a/src/g_inventory/a_weapons.cpp +++ b/src/g_inventory/a_weapons.cpp @@ -184,18 +184,6 @@ void AWeapon::Serialize(FSerializer &arc) } -//=========================================================================== -// -// AWeapon :: MarkPrecacheSounds -// -//=========================================================================== - -void AWeapon::MarkPrecacheSounds() const -{ - Super::MarkPrecacheSounds(); - UpSound.MarkUsed(); - ReadySound.MarkUsed(); -} /* Weapon slots ***********************************************************/ diff --git a/src/g_inventory/a_weapons.h b/src/g_inventory/a_weapons.h index 1a7bfb0ded..4c498f7c24 100644 --- a/src/g_inventory/a_weapons.h +++ b/src/g_inventory/a_weapons.h @@ -159,8 +159,6 @@ public: bool bAltFire; // *** only accessed from ZScript. Set when this weapon's alternate fire is used. bool bDehAmmo; - virtual void MarkPrecacheSounds() const; - void Finalize(FStateDefinitions &statedef) override; void Serialize(FSerializer &arc) override; diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 089fd1972c..56b19a5de5 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5310,26 +5310,6 @@ void AActor::CallPostBeginPlay() E_WorldThingSpawned(this); } -void AActor::MarkPrecacheSounds() const -{ - SeeSound.MarkUsed(); - AttackSound.MarkUsed(); - PainSound.MarkUsed(); - DeathSound.MarkUsed(); - ActiveSound.MarkUsed(); - UseSound.MarkUsed(); - BounceSound.MarkUsed(); - WallBounceSound.MarkUsed(); - CrushPainSound.MarkUsed(); -} - -DEFINE_ACTION_FUNCTION(AActor, MarkPrecacheSounds) -{ - PARAM_SELF_PROLOGUE(AActor); - self->MarkPrecacheSounds(); - return 0; -} - bool AActor::isFast() { if (flags5&MF5_ALWAYSFAST) return true; diff --git a/src/p_user.cpp b/src/p_user.cpp index 50da7fe9a7..9a8463c9d0 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -833,16 +833,16 @@ void APlayerPawn::Serialize(FSerializer &arc) //=========================================================================== // -// APlayerPawn :: MarkPrecacheSounds +// APlayerPawn :: MarkPlayerSounds // //=========================================================================== -void APlayerPawn::MarkPrecacheSounds() const +DEFINE_ACTION_FUNCTION(APlayerPawn, MarkPlayerSounds) { - Super::MarkPrecacheSounds(); - S_MarkPlayerSounds(GetSoundClass()); + PARAM_SELF_PROLOGUE(APlayerPawn); + S_MarkPlayerSounds(self->GetSoundClass()); + return 0; } - //=========================================================================== // // APlayerPawn :: BeginPlay diff --git a/src/s_advsound.cpp b/src/s_advsound.cpp index f0ec171c69..0be53d7e9e 100644 --- a/src/s_advsound.cpp +++ b/src/s_advsound.cpp @@ -2232,18 +2232,20 @@ void AAmbientSound::Serialize(FSerializer &arc) //========================================================================== // -// AmbientSound :: MarkPrecacheSounds +// AmbientSound :: MarkAmbientSounds // //========================================================================== -void AAmbientSound::MarkPrecacheSounds() const +DEFINE_ACTION_FUNCTION(AAmbientSound, MarkAmbientSounds) { - Super::MarkPrecacheSounds(); - FAmbientSound *ambient = Ambients.CheckKey(args[0]); + PARAM_SELF_PROLOGUE(AAmbientSound); + + FAmbientSound *ambient = Ambients.CheckKey(self->args[0]); if (ambient != NULL) { ambient->sound.MarkUsed(); } + return 0; } //========================================================================== @@ -2458,3 +2460,11 @@ void S_ParseMusInfo() } +DEFINE_ACTION_FUNCTION(DObject, MarkSound) +{ + PARAM_PROLOGUE; + PARAM_SOUND(sound_id); + sound_id.MarkUsed(); + return 0; +} + diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 4ba1d476e7..3eec90d39d 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -504,14 +504,9 @@ void S_PrecacheLevel () { IFVIRTUALPTR(actor, AActor, MarkPrecacheSounds) { - // Without the type cast this picks the 'void *' assignment... VMValue params[1] = { actor }; VMCall(func, params, 1, nullptr, 0); } - else - { - actor->MarkPrecacheSounds(); - } } for (auto snd : gameinfo.PrecachedSounds) { diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index c2405b40e9..3c2eec9301 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -420,6 +420,18 @@ class Actor : Thinker native native clearscope static Vector2 RotateVector(Vector2 vec, double angle); native clearscope static double Normalize180(double ang); + virtual void MarkPrecacheSounds() + { + MarkSound(SeeSound); + MarkSound(AttackSound); + MarkSound(PainSound); + MarkSound(DeathSound); + MarkSound(ActiveSound); + MarkSound(UseSound); + MarkSound(BounceSound); + MarkSound(WallBounceSound); + MarkSound(CrushPainSound); + } bool IsPointerEqual(int ptr_select1, int ptr_select2) { @@ -439,7 +451,6 @@ class Actor : Thinker native virtual native void Die(Actor source, Actor inflictor, int dmgflags = 0, Name MeansOfDeath = 'none'); virtual native bool Slam(Actor victim); virtual native void Touch(Actor toucher); - virtual native void MarkPrecacheSounds(); native void Substitute(Actor replacement); // Called by PIT_CheckThing to check if two actors actually can collide. diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 9a8baf9906..3aec2fef7b 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -385,6 +385,7 @@ class Object native native static void S_ResumeSound (bool notsfx); native static bool S_ChangeMusic(String music_name, int order = 0, bool looping = true, bool force = false); native static float S_GetLength(Sound sound_id); + native static void MarkSound(Sound snd); native static uint BAM(double angle); native static void SetMusicVolume(float vol); native static uint MSTime(); diff --git a/wadsrc/static/zscript/inventory/inventory.txt b/wadsrc/static/zscript/inventory/inventory.txt index 8131190892..839e3aa71f 100644 --- a/wadsrc/static/zscript/inventory/inventory.txt +++ b/wadsrc/static/zscript/inventory/inventory.txt @@ -74,6 +74,17 @@ class Inventory : Actor native Stop; } + //=========================================================================== + // + // AInventory :: MarkPrecacheSounds + // + //=========================================================================== + + override void MarkPrecacheSounds() + { + Super.MarkPrecacheSounds(); + MarkSound(PickupSound); + } //=========================================================================== // diff --git a/wadsrc/static/zscript/inventory/weapons.txt b/wadsrc/static/zscript/inventory/weapons.txt index 879063a634..b03edbde71 100644 --- a/wadsrc/static/zscript/inventory/weapons.txt +++ b/wadsrc/static/zscript/inventory/weapons.txt @@ -78,6 +78,18 @@ class Weapon : StateProvider native Stop; } + //=========================================================================== + // + // AWeapon :: MarkPrecacheSounds + // + //=========================================================================== + + override void MarkPrecacheSounds() + { + Super.MarkPrecacheSounds(); + MarkSound(UpSound); + MarkSound(ReadySound); + } virtual int, int CheckAddToSlots() { diff --git a/wadsrc/static/zscript/shared/player.txt b/wadsrc/static/zscript/shared/player.txt index 998b1ce6b9..a213e2c0c6 100644 --- a/wadsrc/static/zscript/shared/player.txt +++ b/wadsrc/static/zscript/shared/player.txt @@ -113,6 +113,18 @@ class PlayerPawn : Actor native Obituary "$OB_MPDEFAULT"; } + //=========================================================================== + // + // APlayerPawn :: MarkPrecacheSounds + // + //=========================================================================== + + override void MarkPrecacheSounds() + { + Super.MarkPrecacheSounds(); + MarkPlayerSounds(); + } + //---------------------------------------------------------------------------- // // @@ -2065,6 +2077,7 @@ class PlayerPawn : Actor native native void CheckEnvironment(); native void CheckUse(); native void CheckWeaponButtons(); + native void MarkPlayerSounds(); } class PlayerChunk : PlayerPawn diff --git a/wadsrc/static/zscript/shared/soundsequence.txt b/wadsrc/static/zscript/shared/soundsequence.txt index c5e2b26041..e7c3f8454a 100644 --- a/wadsrc/static/zscript/shared/soundsequence.txt +++ b/wadsrc/static/zscript/shared/soundsequence.txt @@ -66,6 +66,14 @@ class AmbientSound : Actor native +NOSECTOR +DONTSPLASH } + + native void MarkAmbientSounds(); + + override void MarkPrecacheSounds() + { + Super.MarkPrecacheSounds(); + MarkAmbientSounds(); + } } class AmbientSoundNoGravity : AmbientSound