Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit b57c0cb

Browse files
committed
Added HDFirearm property PreFireSound, which is used to define a sound that should play exactly once before the weapon fires.
Fixed HDFirearm DeactivationSound so it's not completely broken. It'll also play when the trigger is held til the gun runs out of ammo, so it's pretty reliable Cleaned up a HDFirearm Activate and Deactivate a little as I passed by Made it so all HDFirearm sounds will update their positions, not just active and deactivation sounds
1 parent ac728ea commit b57c0cb

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Entities/HDFirearm.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void HDFirearm::Clear()
3535
m_pMagazine = 0;
3636

3737
m_pFlash = 0;
38+
m_PreFireSound.Reset();
3839
m_FireSound.Reset();
3940
m_FireEchoSound.Reset();
4041
m_ActiveSound.Reset();
@@ -112,6 +113,7 @@ int HDFirearm::Create(const HDFirearm &reference)
112113
m_pFlash = dynamic_cast<Attachable *>(reference.m_pFlash->Clone());
113114
m_pFlash->Attach(this, m_pFlash->GetParentOffset());
114115
}
116+
m_PreFireSound = reference.m_PreFireSound;
115117
m_FireSound = reference.m_FireSound;
116118
m_FireEchoSound = reference.m_FireEchoSound;
117119
m_ActiveSound = reference.m_ActiveSound;
@@ -174,8 +176,10 @@ int HDFirearm::ReadProperty(std::string propName, Reader &reader)
174176
if (m_pFlash)
175177
m_pFlash->Attach(this);
176178
}
177-
}
178-
else if (propName == "FireSound")
179+
} else if (propName == "PreFireSound") {
180+
reader >> m_PreFireSound;
181+
m_DeactivationSound.SetSoundOverlapMode(SoundContainer::SoundOverlapMode::MODE_IGNORE_PLAY);
182+
} else if (propName == "FireSound")
179183
reader >> m_FireSound;
180184
else if (propName == "FireEchoSound") {
181185
reader >> m_FireEchoSound;
@@ -184,6 +188,7 @@ int HDFirearm::ReadProperty(std::string propName, Reader &reader)
184188
reader >> m_ActiveSound;
185189
} else if (propName == "DeactivationSound") {
186190
reader >> m_DeactivationSound;
191+
m_DeactivationSound.SetSoundOverlapMode(SoundContainer::SoundOverlapMode::MODE_IGNORE_PLAY);
187192
} else if (propName == "EmptySound")
188193
reader >> m_EmptySound;
189194
else if (propName == "ReloadStartSound")
@@ -258,6 +263,8 @@ int HDFirearm::Save(Writer &writer) const
258263
writer << m_pMagazine;
259264
writer.NewProperty("Flash");
260265
writer << m_pFlash;
266+
writer.NewProperty("PreFireSound");
267+
writer << m_PreFireSound;
261268
writer.NewProperty("FireSound");
262269
writer << m_FireSound;
263270
writer.NewProperty("FireEchoSound");
@@ -318,6 +325,7 @@ void HDFirearm::Destroy(bool notInherited)
318325
{
319326
delete m_pMagazine;
320327
delete m_pFlash;
328+
m_PreFireSound.Stop();
321329
m_FireSound.Stop();
322330
m_FireEchoSound.Stop();
323331
m_ActiveSound.Stop();
@@ -562,13 +570,14 @@ void HDFirearm::SetID(const MOID newID)
562570
// Description: Activates one of this HDFirearm's features. Analogous to 'pulling
563571
// the trigger'.
564572

565-
void HDFirearm::Activate()
566-
{
573+
void HDFirearm::Activate() {
574+
bool wasActivated = m_Activated;
567575
HeldDevice::Activate();
568576

569-
// Play the pre-fire sound
570-
if (!IsReloading() && !m_ActiveSound.IsBeingPlayed())
571-
m_ActiveSound.Play(this->m_Pos);
577+
if (!IsReloading()) {
578+
if (!m_ActiveSound.IsBeingPlayed()) { m_ActiveSound.Play(this->m_Pos); }
579+
if (!wasActivated && !m_PreFireSound.IsBeingPlayed()) { m_PreFireSound.Play(this->m_Pos); }
580+
}
572581
}
573582

574583

@@ -578,18 +587,14 @@ void HDFirearm::Activate()
578587
// Description: Deactivates one of this HDFirearm's features. Analogous to 'releasing
579588
// the trigger'.
580589

581-
void HDFirearm::Deactivate()
582-
{
590+
void HDFirearm::Deactivate() {
591+
bool wasActivated = m_Activated;
583592
HeldDevice::Deactivate();
584593
m_FiredOnce = false;
585594

586-
// Stop any looping fire sounds
587-
if (m_FireSound.GetLoopSetting() == -1 && m_FireSound.IsBeingPlayed())
588-
m_FireSound.Stop();
589-
590-
// Play the post-fire sound
591-
if (!m_DeactivationSound.IsBeingPlayed())
592-
m_DeactivationSound.Play(m_Pos);
595+
m_PreFireSound.Stop();
596+
if (m_FireSound.GetLoopSetting() == -1) { m_FireSound.Stop(); }
597+
if (wasActivated && m_pMagazine && !m_pMagazine->IsEmpty() && !m_DeactivationSound.IsBeingPlayed()) { m_DeactivationSound.Play(m_Pos); }
593598
}
594599

595600
//////////////////////////////////////////////////////////////////////////////////////////
@@ -698,6 +703,8 @@ void HDFirearm::Update()
698703
{
699704
HeldDevice::Update();
700705

706+
if (m_PreFireSound.IsBeingPlayed()) { m_PreFireSound.SetPosition(m_Pos); }
707+
if (m_FireSound.IsBeingPlayed()) { m_FireSound.SetPosition(m_Pos); }
701708
if (m_ActiveSound.IsBeingPlayed()) { m_ActiveSound.SetPosition(m_Pos); }
702709
if (m_DeactivationSound.IsBeingPlayed()) { m_DeactivationSound.SetPosition(m_Pos); }
703710

@@ -715,8 +722,7 @@ void HDFirearm::Update()
715722

716723
if (m_pMagazine && !m_pMagazine->IsEmpty())
717724
{
718-
if (m_Activated)
719-
{
725+
if (m_Activated && !m_PreFireSound.IsBeingPlayed()) {
720726

721727
// Get the parent root of this AEmitter
722728
// TODO: Potentially get this once outside instead, like in attach/detach")
@@ -915,6 +921,7 @@ void HDFirearm::Update()
915921
{
916922
// Play empty pin click sound.
917923
m_EmptySound.Play(m_Pos);
924+
m_DeactivationSound.Play(m_Pos);
918925
// Indicate that we have clicked once during the current activation.
919926
m_AlreadyClicked = true;
920927

@@ -934,6 +941,8 @@ void HDFirearm::Update()
934941
m_ActivationTimer.Reset();
935942
m_ActivationTimer.Reset();
936943
m_LastFireTmr.Reset();
944+
945+
if (m_Activated) { m_PreFireSound.Play(); }
937946
}
938947

939948
m_Reloading = false;
@@ -946,6 +955,7 @@ void HDFirearm::Update()
946955
// Reset the click indicator.
947956
m_AlreadyClicked = false;
948957

958+
m_PreFireSound.Stop();
949959
// Stop any looping activation sounds
950960
if (m_FireSound.GetLoopSetting() == -1)// && m_FireSound.IsBeingPlayed())
951961
m_FireSound.Stop();

Entities/HDFirearm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ ClassInfoGetters
741741
// Muzzle Flash Attachable. Owned
742742
Attachable *m_pFlash;
743743

744+
SoundContainer m_PreFireSound; //!< The sound this HDFirearm should play before it starts firing. Distinct from activation sound in that it will play exactly once per trigger pull and not pitch up.
744745
// The audio of this FireArm being fired.
745746
SoundContainer m_FireSound;
746747
SoundContainer m_FireEchoSound; //!< The audio that is played as the echo for the gun. Each shot will restart this sound, so it doesn't ever overlap.

0 commit comments

Comments
 (0)