Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

meszaros-lajos-gyorgy
Copy link
Contributor

@meszaros-lajos-gyorgy meszaros-lajos-gyorgy commented Oct 13, 2023

Currently only 4 spells (Heal, DetectTrap, Armor, LowerArmor) check whether the SPELLCAST_FLAG_NOSOUND flag is set. This addition adds support for all the sounds of all the spells.

@meszaros-lajos-gyorgy meszaros-lajos-gyorgy marked this pull request as ready for review October 14, 2023 17:44
@@ -56,25 +56,35 @@ 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);
Copy link
Contributor

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

bool emitsSound = GET_EMITS_SOUND(m_flags);

also removes code repetition

Copy link
Contributor

@bsxf-47 bsxf-47 Oct 15, 2023

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.

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.


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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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

#define conditional_call(condition, func) if(condition){func;}
conditional_call(emitsSound, ARX_SOUND_PlaySFX_loop(g_snd.SPELL_VISION_LOOP, &m_caster_pos, 1.f))

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
It looks like the flag is set at the start of a spell and not anywhere else, so why not check the bit value once and use a member variable for that? Maybe see if you can use Spell base class to simplify what you want to do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, ARX_SOUND_PlaySFX_loop() could be wrapped in a member function, say playSoundLoop() that checks for the member variable away from the main code, if reducing clutter is the goal.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -460,9 +460,7 @@ void SlowDownSpell::End() {
m_targets.clear();
}

void SlowDownSpell::Update() {

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be more going on than what the commit message says. Please split formatting changes into a separate commit.

Copy link
Contributor Author

@meszaros-lajos-gyorgy meszaros-lajos-gyorgy Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have restored the whitespace here and a few other places as it's not necessary for this PR. I'll try to split my commits in the future according to what you wrote.

@dscharrer dscharrer force-pushed the master branch 5 times, most recently from 391b7f7 to 3d8a7e6 Compare May 30, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants