allow passing resource IDs to sound properties and added some test code.

This commit is contained in:
Christoph Oelckers 2023-10-10 20:10:58 +02:00
parent 7851b686ec
commit e0195ecab5
9 changed files with 112 additions and 55 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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;

View file

@ -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

View file

@ -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);
}
//---------------------------------------------------------------------------
//

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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);