From e0195ecab51628259655d70707c0c7574d3835db Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 10 Oct 2023 20:10:58 +0200 Subject: [PATCH] allow passing resource IDs to sound properties and added some test code. --- source/core/namedef_custom.h | 1 + source/core/zcc_compile_raze.cpp | 11 +++++ source/games/blood/src/actor.cpp | 47 +++---------------- source/games/blood/src/aiunicult.cpp | 17 +++++++ source/games/blood/src/sfx.cpp | 21 +++++---- source/games/blood/src/sound.h | 15 ++++-- source/games/blood/src/vmexports.cpp | 24 +++++++++- .../zscript/games/blood/actors/dudes.zs | 30 +++++++++++- .../static/zscript/games/blood/bloodactor.zs | 1 + 9 files changed, 112 insertions(+), 55 deletions(-) diff --git a/source/core/namedef_custom.h b/source/core/namedef_custom.h index b79fd41be..9ec131bb5 100644 --- a/source/core/namedef_custom.h +++ b/source/core/namedef_custom.h @@ -102,6 +102,7 @@ xx(CloseAttackPercent) xx(AttackPercent) xx(BloodMissileBase) xx(gibtype) +xx(explodeSound) // Blood state names. Most of these can be removed after the state system refactor is complete. xx(genIdle) diff --git a/source/core/zcc_compile_raze.cpp b/source/core/zcc_compile_raze.cpp index 55bd0b3df..1424b769d 100644 --- a/source/core/zcc_compile_raze.cpp +++ b/source/core/zcc_compile_raze.cpp @@ -620,6 +620,17 @@ void ZCCRazeCompiler::DispatchScriptProperty(PProperty *prop, ZCC_PropertyStmt * } else if (f->Type == TypeSound) { + if (ctx.Version >= MakeVersion(4, 11, 100)) + { + // Check if we got passed a number, if so treat it as a resource ID. + ex = ex->Resolve(ctx); + if (!ex) goto vector_ok; + if (ex->IsNumeric()) + { + *(FSoundID*)addr = S_FindSoundByResID(GetIntConst(ex, ctx)); + goto vector_ok; + } + } *(FSoundID*)addr = S_FindSound(GetStringConst(ex, ctx)); } else if (f->Type == TypeColor && ex->ValueType == TypeString) // colors can also be specified as ints. diff --git a/source/games/blood/src/actor.cpp b/source/games/blood/src/actor.cpp index 459b8a22b..b09453560 100644 --- a/source/games/blood/src/actor.cpp +++ b/source/games/blood/src/actor.cpp @@ -1269,39 +1269,13 @@ static int checkDamageType(DBloodActor* actor, DAMAGE_TYPE damageType) switch (damageType) { case kDamageExplode: + { nSeq = 2; - switch (actor->GetType()) - { -#ifdef NOONE_EXTENSIONS - case kDudeModernCustom: - case kDudeModernCustomBurning: - { - playGenDudeSound(actor, kGenDudeSndDeathExplode); - GENDUDEEXTRA* pExtra = &actor->genDudeExtra; - if (!pExtra->availDeaths[damageType]) - { - nSeq = 1; - damageType = kDamageFall; - } - break; - } -#endif - case kDudeCultistTommy: - case kDudeCultistShotgun: - case kDudeCultistTommyProne: - case kDudeBurningInnocent: - case kDudeBurningCultist: - case kDudeInnocent: - case kDudeCultistShotgunProne: - case kDudeCultistTesla: - case kDudeCultistTNT: - case kDudeCultistBeast: - case kDudeTinyCaleb: - case kDudeBurningTinyCaleb: - sfxPlay3DSound(actor, 717, -1, 0); - break; - } + + auto snd = actor->SoundVar(NAME_explodeSound); + sfxPlay3DSound(actor, snd, -1, 0); break; + } case kDamageBurn: nSeq = 3; sfxPlay3DSound(actor, 351, -1, 0); @@ -1321,16 +1295,7 @@ static int checkDamageType(DBloodActor* actor, DAMAGE_TYPE damageType) } break; case kDamageFall: - switch (actor->GetType()) - { - case kDudeCultistTommy: - case kDudeCultistShotgun: - nSeq = 1; - break; - default: - nSeq = 1; - break; - } + nSeq = 1; break; default: nSeq = 1; diff --git a/source/games/blood/src/aiunicult.cpp b/source/games/blood/src/aiunicult.cpp index 4c9f34184..c854327a3 100644 --- a/source/games/blood/src/aiunicult.cpp +++ b/source/games/blood/src/aiunicult.cpp @@ -2677,5 +2677,22 @@ case kDudePodMother: // FakeDude type (no seq, custom flags, clipdist and cstat } break; */ + +/* checkDamageType + + case kDudeModernCustom: + case kDudeModernCustomBurning: + { + playGenDudeSound(actor, kGenDudeSndDeathExplode); + GENDUDEEXTRA* pExtra = &actor->genDudeExtra; + if (!pExtra->availDeaths[damageType]) + { + nSeq = 1; + damageType = kDamageFall; + } + break; + } + +*/ END_BLD_NS #endif diff --git a/source/games/blood/src/sfx.cpp b/source/games/blood/src/sfx.cpp index a629cd744..d6c847915 100644 --- a/source/games/blood/src/sfx.cpp +++ b/source/games/blood/src/sfx.cpp @@ -181,11 +181,9 @@ void sfxPlay3DSectorSound(const DVector3& pos, int soundId, sectortype* pSector) // //--------------------------------------------------------------------------- -void sfxPlay3DSoundVolume(DBloodActor* pActor, int soundId, int playchannel, int playflags, int pitch, int volume) +void sfxPlay3DSoundVolume(DBloodActor* pActor, FSoundID sid, int playchannel, int playflags, int pitch, int volume) { - if (!SoundEnabled() || soundId <= 0 || !pActor) return; - auto sid = soundEngine->FindSoundByResID(soundId); - if (!sid.isvalid()) return; + if (!SoundEnabled() || !sid.isvalid() || !pActor) return; auto svec = GetSoundPos(pActor->spr.pos); @@ -224,11 +222,18 @@ void sfxPlay3DSoundVolume(DBloodActor* pActor, int soundId, int playchannel, int soundEngine->StartSound(SOURCE_Actor, pActor, &svec, playchannel, flags, sid, volume * (0.8f / 80.f), attenuation, nullptr, pitch / 65536.f); } -void sfxPlay3DSound(DBloodActor* pActor, int soundId, int a3, int a4) -{ - sfxPlay3DSoundVolume(pActor, soundId, a3, a4, -1); -} +//--------------------------------------------------------------------------- +// +// +// +//--------------------------------------------------------------------------- +void sfxPlay3DSoundVolume(DBloodActor* pActor, int soundId, int playchannel, int playflags, int pitch, int volume) +{ + if (soundId <= 0) return; + auto sid = soundEngine->FindSoundByResID(soundId); + if (sid.isvalid()) sfxPlay3DSoundVolume(pActor, sid, playchannel, playflags, pitch, volume); +} //--------------------------------------------------------------------------- // diff --git a/source/games/blood/src/sound.h b/source/games/blood/src/sound.h index 8b23c2e7e..ce4ecd41d 100644 --- a/source/games/blood/src/sound.h +++ b/source/games/blood/src/sound.h @@ -29,9 +29,18 @@ void sndTerm(void); void sndInit(void); void sfxPlay3DSectorSound(const DVector3& pos, int soundId, sectortype* pSector); -void sfxPlay3DSound(DBloodActor* pSprite, int soundId, int a3 = -1, int a4 = 0); -void sfxPlay3DSoundVolume(DBloodActor* pSprite, int soundId, int a3 = -1, int a4 = 0, int pitch = 0, int volume = 0); -void sfxKill3DSound(DBloodActor* pSprite, int a2 = -1, int a3 = -1); +void sfxPlay3DSoundVolume(DBloodActor* pActor, FSoundID sid, int playchannel = -1, int playflags = 0, int pitch = 0, int volume = 0); +void sfxPlay3DSoundVolume(DBloodActor* pActor, int soundId, int playchannel = -1, int playflags = 0, int pitch = 0, int volume = 0); + +inline void sfxPlay3DSound(DBloodActor* pActor, FSoundID soundId, int a3 = -1, int a4 = 0) +{ + sfxPlay3DSoundVolume(pActor, soundId, a3, a4, 0, -1); +} +inline void sfxPlay3DSound(DBloodActor* pActor, int soundId, int a3 = -1, int a4 = 0) +{ + sfxPlay3DSoundVolume(pActor, soundId, a3, a4, 0, -1); +} +void sfxKill3DSound(DBloodActor* pActor, int a2 = -1, int a3 = -1); void sfxKillAllSounds(void); void sfxSetReverb(bool toggle); void sfxSetReverb2(bool toggle); diff --git a/source/games/blood/src/vmexports.cpp b/source/games/blood/src/vmexports.cpp index fb83fa35a..1f21c66e8 100644 --- a/source/games/blood/src/vmexports.cpp +++ b/source/games/blood/src/vmexports.cpp @@ -327,13 +327,33 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBloodActor, HitScan, bloodactor_HitScan) ACTION_RETURN_INT(bloodactor_HitScan(self, z, x, y, zz, clipmask, clipdist)); } -DEFINE_ACTION_FUNCTION_NATIVE(DBloodActor, play3DSoundID, sfxPlay3DSound) +void blood_play3DSoundID(DBloodActor* actor, int snd, int chn, int flags) +{ + sfxPlay3DSoundVolume(actor, snd, chn, flags, 0, -1); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBloodActor, play3DSoundID, blood_play3DSoundID) { PARAM_SELF_PROLOGUE(DBloodActor); PARAM_INT(sound); PARAM_INT(chan); PARAM_INT(flags); - sfxPlay3DSound(self, sound, chan, flags); + blood_play3DSoundID(self, sound, chan, flags); + return 0; +} + +void blood_play3DSound(DBloodActor* actor, int snd, int chn, int flags) +{ + sfxPlay3DSoundVolume(actor, FSoundID::fromInt(snd), chn, flags, 0, -1); +} + +DEFINE_ACTION_FUNCTION_NATIVE(DBloodActor, play3DSound, blood_play3DSound) +{ + PARAM_SELF_PROLOGUE(DBloodActor); + PARAM_INT(sound); + PARAM_INT(chan); + PARAM_INT(flags); + blood_play3DSound(self, sound, chan, flags); return 0; } diff --git a/wadsrc/static/zscript/games/blood/actors/dudes.zs b/wadsrc/static/zscript/games/blood/actors/dudes.zs index 56de487a0..7cc15bd54 100644 --- a/wadsrc/static/zscript/games/blood/actors/dudes.zs +++ b/wadsrc/static/zscript/games/blood/actors/dudes.zs @@ -19,6 +19,8 @@ class BloodDudeBase : Bloodactor meta double backSpeed; meta double turnRange; meta int gibType[3]; // which gib used when explode dude + + meta Sound explodeSound; property prefix: none; property seqStartID: seqStartID; @@ -40,6 +42,8 @@ class BloodDudeBase : Bloodactor property sideSpeed: sideSpeed; property backSpeed: backSpeed; property turnRange: turnRange; + + property explodeSound: explodeSound; default @@ -421,6 +425,8 @@ class BloodDudeCultistTommy : BloodDudeBase turnrange 45; gibtype 15, -1, -1; dmgcontrol 256, 256, 96, 256, 256, 256, 192; + + explodesound 717; } } @@ -450,6 +456,8 @@ class BloodDudeCultistShotgun : BloodDudeBase turnrange 45; gibtype 15, -1, -1; dmgcontrol 256, 256, 128, 256, 256, 256, 192; + + explodesound 717; } } @@ -1214,6 +1222,8 @@ class BloodDudeCultistTommyProne : BloodDudeBase turnrange 67.5; gibtype 15, -1, -1; dmgcontrol 256, 256, 96, 256, 256, 256, 192; + + explodesound 717; } } @@ -1272,6 +1282,8 @@ class BloodDudeBurningInnocent : BloodDudeBase turnrange 28.125; gibtype 7, 5, -1; dmgcontrol 256, 256, 256, 256, 256, 256, 256; + + explodesound 717; } } @@ -1298,6 +1310,8 @@ class BloodDudeBurningCultist : BloodDudeBase turnrange 28.125; gibtype 7, 5, -1; dmgcontrol 256, 256, 256, 256, 256, 256, 256; + + explodesound 717; } } @@ -1357,7 +1371,7 @@ class BloodDudeBurningZombieButcher : BloodDudeBase } } -class BloodDudeCultistReserved : BloodDudeBase +class BloodDudeCultistReserved : BloodDudeBase // this is never checked as a cultist in the code. { default { @@ -1440,6 +1454,8 @@ class BloodDudeInnocent : BloodDudeBase turnrange 67.5; gibtype 15, -1, -1; dmgcontrol 288, 288, 288, 288, 288, 288, 288; + + explodesound 717; } } @@ -1467,6 +1483,8 @@ class BloodDudeCultistShotgunProne : BloodDudeBase turnrange 11.25; gibtype 7, 5, -1; dmgcontrol 256, 256, 256, 256, 256, 256, 256; + + explodesound 717; } } @@ -1496,6 +1514,8 @@ class BloodDudeCultistTesla : BloodDudeBase turnrange 45; gibtype 15, -1, -1; dmgcontrol 256, 256, 96, 160, 256, 256, 12; + + explodesound 717; } } @@ -1525,6 +1545,8 @@ class BloodDudeCultistTNT : BloodDudeBase turnrange 45; gibtype 15, -1, -1; dmgcontrol 256, 160, 96, 64, 256, 256, 256; + + explodesound 717; } } @@ -1554,6 +1576,8 @@ class BloodDudeCultistBeast : BloodDudeBase turnrange 45; gibtype 15, -1, -1; dmgcontrol 128, 128, 16, 16, 0, 64, 48; + + explodesound 717; } } @@ -1581,6 +1605,8 @@ class BloodDudeTinyCaleb : BloodDudeBase turnrange 67.5; gibtype 7, -1, -1; dmgcontrol 160, 160, 160, 160, 256, 128, 288; + + explodesound 717; } } @@ -1637,6 +1663,8 @@ class BloodDudeBurningTinyCaleb : BloodDudeBase turnrange 67.5; gibtype 7, -1, -1; dmgcontrol 256, 256, 256, 256, 256, 256, 256; + + explodesound 717; } } diff --git a/wadsrc/static/zscript/games/blood/bloodactor.zs b/wadsrc/static/zscript/games/blood/bloodactor.zs index 6bae1353b..d33574357 100644 --- a/wadsrc/static/zscript/games/blood/bloodactor.zs +++ b/wadsrc/static/zscript/games/blood/bloodactor.zs @@ -380,6 +380,7 @@ native void callbackMissileBurst(); native void explodeSprite(); native void radiusDamage(Vector3 pos, sectortype pSector, int dist, int basedmg, int distdmg, int dmgtype, int flags, int burn); + native void play3DSound(Sound soundId, int a3 = -1, int a4 = 0); native void play3DSoundID(int soundId, int a3 = -1, int a4 = 0); native void seqSpawnID(int seqID, VMFunction seqCallbackID = null);