-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for spellcast command's -x flag for all spells #293
base: master
Are you sure you want to change the base?
Changes from 16 commits
13421bd
0d1ad32
1721114
b54b528
81a1934
8de7c0c
cfa4083
a63450d
d12d6d0
9953856
af9cf90
bf23d43
11dca3a
70fa40d
9256ffb
07e16a5
31551cf
2736b66
cef5377
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,38 +56,48 @@ void MagicSightSpell::Launch() { | |
m_hasDuration = m_launchDuration >= 0; | ||
m_duration = m_hasDuration ? m_launchDuration : 0; | ||
|
||
ARX_SOUND_PlaySFX(g_snd.SPELL_VISION_START, &m_caster_pos); | ||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
if(emitsSound) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_VISION_START, &m_caster_pos); | ||
} | ||
|
||
if(m_caster == EntityHandle_Player) { | ||
player.m_improve = true; | ||
m_snd_loop = ARX_SOUND_PlaySFX_loop(g_snd.SPELL_VISION_LOOP, &m_caster_pos, 1.f); | ||
if(emitsSound) { | ||
m_snd_loop = ARX_SOUND_PlaySFX_loop(g_snd.SPELL_VISION_LOOP, &m_caster_pos, 1.f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could all or some of these ARX_SOUND calls get a conditional variant where you pass the bool in? yes of course its more efficient to put the if() around each call instead of doing a method call just to jump back immediately, but i dont think this would affect anything. just easier than to have 500 if(emitsSound) clauses in each spell file. alternatively, create a macro
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, you'd pass a bool to a function just to tell it if it should do anything or not? That doesn't sound good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that playSoundLoop would do exactly what i proposed first with a function. the conditional macro thing would not add any extra function calls but make it a oneliner that is much easier to read. the files are long enough as they are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't imagine reading that code a year later without having to inspect that macro and spending time on it. This doesn't feel like self-documenting code. |
||
} | ||
} | ||
} | ||
|
||
void MagicSightSpell::End() { | ||
|
||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
if(m_caster == EntityHandle_Player) { | ||
player.m_improve = false; | ||
} | ||
|
||
ARX_SOUND_Stop(m_snd_loop); | ||
m_snd_loop = audio::SourcedSample(); | ||
|
||
Entity * caster = entities.get(m_caster); | ||
if(caster) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_VISION_START, &caster->pos); | ||
if(emitsSound) { | ||
ARX_SOUND_Stop(m_snd_loop); | ||
m_snd_loop = audio::SourcedSample(); | ||
|
||
Entity * caster = entities.get(m_caster); | ||
if(caster) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_VISION_START, &caster->pos); | ||
} | ||
} | ||
} | ||
|
||
void MagicSightSpell::Update() { | ||
|
||
if(m_caster == EntityHandle_Player) { | ||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
if(emitsSound && m_caster == EntityHandle_Player) { | ||
Vec3f pos = ARX_PLAYER_FrontPos(); | ||
ARX_SOUND_RefreshPosition(m_snd_loop, pos); | ||
} | ||
} | ||
|
||
static void LaunchMagicMissileExplosion(const Vec3f & _ePos, bool mrCheat) { | ||
static void LaunchMagicMissileExplosion(const Vec3f & _ePos, bool mrCheat, bool emitsSound) { | ||
|
||
std::unique_ptr<ParticleSystem> particles = std::make_unique<ParticleSystem>(); | ||
if(mrCheat) { | ||
|
@@ -112,7 +122,9 @@ static void LaunchMagicMissileExplosion(const Vec3f & _ePos, bool mrCheat) { | |
light->duration = 1500ms; | ||
} | ||
|
||
ARX_SOUND_PlaySFX(g_snd.SPELL_MM_HIT, &_ePos); | ||
if(emitsSound) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_MM_HIT, &_ePos); | ||
} | ||
|
||
} | ||
|
||
|
@@ -223,9 +235,13 @@ void MagicMissileSpell::Launch() { | |
missile.SetDuration(lTime); | ||
} | ||
|
||
ARX_SOUND_PlaySFX(g_snd.SPELL_MM_CREATE, &startPos); | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_MM_LAUNCH, &startPos); | ||
snd_loop = ARX_SOUND_PlaySFX_loop(g_snd.SPELL_MM_LOOP, &startPos, 1.f); | ||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
if(emitsSound) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_MM_CREATE, &startPos); | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_MM_LAUNCH, &startPos); | ||
snd_loop = ARX_SOUND_PlaySFX_loop(g_snd.SPELL_MM_LOOP, &startPos, 1.f); | ||
} | ||
|
||
m_duration = lMax + 1s; | ||
} | ||
|
@@ -238,12 +254,18 @@ void MagicMissileSpell::End() { | |
|
||
m_missiles.clear(); | ||
|
||
ARX_SOUND_Stop(snd_loop); | ||
snd_loop = audio::SourcedSample(); | ||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
if(emitsSound) { | ||
ARX_SOUND_Stop(snd_loop); | ||
snd_loop = audio::SourcedSample(); | ||
} | ||
} | ||
|
||
void MagicMissileSpell::Update() { | ||
|
||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
for(CMagicMissile & missile : util::dereference(m_missiles)) { | ||
|
||
if(missile.bExplo) { | ||
|
@@ -255,7 +277,7 @@ void MagicMissileSpell::Update() { | |
Entity * caster = entities.get(m_caster); | ||
if(CheckAnythingInSphere(sphere, caster, CAS_NO_SAME_GROUP)) { | ||
|
||
LaunchMagicMissileExplosion(missile.eCurPos, m_mrCheat); | ||
LaunchMagicMissileExplosion(missile.eCurPos, m_mrCheat, emitsSound); | ||
if(caster) { | ||
spawnAudibleSound(missile.eCurPos, *caster); | ||
} | ||
|
@@ -287,7 +309,10 @@ void MagicMissileSpell::Update() { | |
} | ||
|
||
averageMissilePos /= float(m_missiles.size()); | ||
ARX_SOUND_RefreshPosition(snd_loop, averageMissilePos); | ||
|
||
if(emitsSound) { | ||
ARX_SOUND_RefreshPosition(snd_loop, averageMissilePos); | ||
} | ||
|
||
arx_assert(m_lights.size() == m_missiles.size()); | ||
|
||
|
@@ -396,10 +421,14 @@ void IgnitSpell::Launch() { | |
|
||
void IgnitSpell::End() { | ||
|
||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
for(T_LINKLIGHTTOFX & entry : m_lights) { | ||
EERIE_LIGHT * light = &g_staticLights[entry.m_targetLight]; | ||
light->m_ignitionStatus = true; | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_IGNITE, &light->pos); | ||
if(emitsSound) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_IGNITE, &light->pos); | ||
} | ||
lightHandleDestroy(entry.m_effectLight); | ||
} | ||
|
||
|
@@ -499,10 +528,14 @@ void DouseSpell::Launch() { | |
|
||
void DouseSpell::End() { | ||
|
||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
for(size_t index : m_lights) { | ||
EERIE_LIGHT * light = &g_staticLights[index]; | ||
light->m_ignitionStatus = false; | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_DOUSE, &light->pos); | ||
if(emitsSound) { | ||
ARX_SOUND_PlaySFX(g_snd.SPELL_DOUSE, &light->pos); | ||
} | ||
} | ||
|
||
} | ||
|
@@ -513,7 +546,11 @@ void DouseSpell::Update() { | |
|
||
void ActivatePortalSpell::Launch() { | ||
|
||
ARX_SOUND_PlayInterface(g_snd.SPELL_ACTIVATE_PORTAL); | ||
bool emitsSound = !(m_flags & SPELLCAST_FLAG_NOSOUND); | ||
|
||
if(emitsSound) { | ||
ARX_SOUND_PlayInterface(g_snd.SPELL_ACTIVATE_PORTAL); | ||
} | ||
|
||
m_duration = 20ms; | ||
m_hasDuration = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bit flag magic could be moved to a macro or function instead. makes it easier to understand
also removes code repetition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a member function would look much cleaner than a macro. I lean towards keeping the flag checks as they are, they are fairly clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a double negation in there (NO and !) so they are much harder to read than "getEmitsSound"
a macro would mean no extra call to a function for such a simple operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I'm concerned, macros are just preprocessor crutches. I wouldn't worry about efficiency as the function would probably get inlined, and this is not a hot codepath anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also lean towards a method in the Spell class as opposed to adding a macro because macros are leaning the codebase back towards C and low level constructs while a method could be migrated more easily to a more modern language if needed.