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

Hook is weaker while hooking to left #89

Open
gerdoe-jr opened this issue Feb 5, 2024 · 5 comments
Open

Hook is weaker while hooking to left #89

gerdoe-jr opened this issue Feb 5, 2024 · 5 comments

Comments

@gerdoe-jr
Copy link

gerdoe-jr commented Feb 5, 2024

libtw2/world/src/lib.rs

Lines 737 to 748 in b928667

pub fn saturated_add(min: f32, max: f32, value: f32, modifier: f32) -> f32 {
if modifier < 0.0 {
if value < min {
return value;
}
} else {
if value > max {
return value;
}
}
clamp(value + modifier, min, max)
}

After changing this code to next given hook problem disappears though

pub fn saturated_add(min: f32, max: f32, value: f32, modifier: f32) -> f32 {
    if modifier < 0.0 {
        if value < min {
            return value;
        } else {
            return min.max(value + modifier);
        }
    } else {
        if value > max {
            return value;
        } else {
            return max.min(value + modifier);
        }
    }
}
@heinrich5991
Copy link
Owner

I don't understand what's different about the new code. Can you give example values where they differ?

@gerdoe-jr
Copy link
Author

I have no example values, but gameplay videos, you can see the difference

weak.mp4
normal.mp4

@heinrich5991
Copy link
Owner

If you can generate these examples, perhaps you could run both functions and issue a println! statement when their result differs?

@Patiga
Copy link
Collaborator

Patiga commented Feb 11, 2024

I was curious about the difference between those two functions as well. I created a small playground project to get value mismatches.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=708e855ce0717c7690ccb6db3994cdb3

@heinrich5991
Copy link
Owner

The difference happens when the updated value is still outside the range, but closer to the accepted range:

E.g. range -1..0, value 2, modifier -1. The old code outputted 0 (a bug, I think), the new code outputs 1. Thanks for the clear reproduction example, @Patiga!

@gerdoe-jr Can you create a pull request? :)

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

No branches or pull requests

3 participants