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

Fix Tux being permanently safe after mix of using door and scripting Tux safe #3187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Brockengespenst
Copy link
Contributor

@Brockengespenst Brockengespenst commented Jan 22, 2025

  • Use a separate timer for temporary safety instead of reusing m_is_intentionally_safe
  • Split timers for post damage safety and temporary safety

Fixes #3186

@Alasdairbugs Alasdairbugs self-requested a review January 24, 2025 14:58
Copy link
Member

@MatusGuy MatusGuy left a comment

Choose a reason for hiding this comment

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

Code looks..... ok.... ugh. Don't worry, it's not your fault.

Comment on lines 578 to 582
/**
* @description Flag indicating that Tux shall not blink while being safe
*/
bool m_avoid_blinking_while_safe;

Copy link
Member

Choose a reason for hiding this comment

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

Avoid blinking while safe?? Man... This file needs a rewrite so bad...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Giving variables a good name can be very challenging. ;-) I‘d be grateful for any suggestion.

@@ -2571,7 +2572,7 @@ Player::check_bounds()
/* fallen out of the level? */
if ((get_pos().y > Sector::get().get_height())
&& !m_ghost_mode
&& !(m_is_intentionally_safe && m_safe_timer.started())) {
&& !(m_avoid_blinking_while_safe && m_safe_timer.started())) {
Copy link
Contributor

@mstoeckl mstoeckl Jan 25, 2025

Choose a reason for hiding this comment

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

This use of m_avoid_blinking_while_safe does not match the variable description.

One strategy that might work here is to avoid such name/purpose problems is to avoid "derived" names, properties and state as much as possible. For example, instead of having a m_avoid_blinking_while_safe variable, store a variable expressing the cause, from which one determine whether the player should blink, or whether it should be allowed to fall out of bounds.

enum TemporarySafetyCause {
        Damage, // has blink effect
        Transition, // stay alive even if out of bounds        
};
TemporarySafetyCause m_safe_timer_reason;

Another approach is to replace m_safe_timer with two distinct timers for the different causes; e.g. use m_post_damage_timer, started only in Player::kill, and m_temp_safety_timer, started only in make_temporarily_safe . Doing this would make it possible to have the player blink for the specified time after being damaged, even when going through a door halfway through.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another approach is to replace m_safe_timer with two distinct timers for the different causes; e.g. use m_post_damage_timer, started only in Player::kill, and m_temp_safety_timer, started only in make_temporarily_safe . Doing this would make it possible to have the player blink for the specified time after being damaged, even when going through a door halfway through.

This totally makes sense in my opinion, so I modified the PR accordingly.

…Tux safe

* Use a separate timer for temporary safety instead of reusing
m_is_intentionally_safe
* Split timers for post damage safety and temporary safety

Fixes SuperTux#3186
@Brockengespenst Brockengespenst force-pushed the fix_invincibility_after_door_and_scripting branch from 49d73db to b45af28 Compare January 25, 2025 16:59
Copy link
Contributor

@Alasdairbugs Alasdairbugs left a comment

Choose a reason for hiding this comment

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

Sorry, wrong PR. will review this one shortly

@mstoeckl
Copy link
Contributor

mstoeckl commented Jan 25, 2025

I do not see any problems with the current version of this PR, and have tested it in a few scenarios (going through doors, applying damage, sector changes, etc.) without finding any issues.

@Alasdairbugs
Copy link
Contributor

Nevermind, I can't review this, because there is no functional windows build. I'm going to assume it works though and i think 2 reviewers is enough.

For context, i made a review in the wrong place. Sorry!

@Alasdairbugs Alasdairbugs dismissed their stale review January 25, 2025 20:08

I cannot review this PR

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.

[Bug]: Tux immunity after door
5 participants