Skip to content

Steering#761

Merged
MegaMech merged 3 commits into
n64decomp:masterfrom
JedGrabman:steering
Apr 13, 2026
Merged

Steering#761
MegaMech merged 3 commits into
n64decomp:masterfrom
JedGrabman:steering

Conversation

@JedGrabman

Copy link
Copy Markdown
Contributor

Document the steering process.

Basically, your desired steering position is set by your joystick's position. However, your steering can only change so much in one frame.

I recommend starting by reading the large comment in src/player_controller.c that explains it in more detail (before many calls to update_steering_large and update_steering_small)

Note that player->steerPosition rarely uses the rightmost 16 bits, so there's a fair amount of bit shifting.

Refer to steering position instead of steering angle, to make clear that it is not the same thing as degrees.
MegaMech
MegaMech previously approved these changes Apr 12, 2026
Comment thread src/player_controller.c
current_steering_change_increment = player->steerChangeIncrement;
player->steerChangeIncrement -= 1 << 11;
//signed vs unsigned weirdness, actually checking if negative
if (player->steerChangeIncrement >= 0xF0000000) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you think this might technically be UB?

I wonder if it's a compiler optimization and that it might actaully be < 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's strange that it's checking for 0xF... instead of 0x8... If it was compiler checking for < 0, I would expect it to only be checking the first bit for the sign. I'll admit I missed that initially. But it's a detail that makes me think it was coded by a human instead of a compiler.

I think that leads to a theoretical bug. A negative number with a large enough magnitude fails the comparison when I run it on an online c compiler, presumably because the two's complement actually makes it smaller when interpreted as an unsigned int. But, that bug can't actually come into play because steerChangeIncrement only changes by 2**11 at a time.

I'm not an expert on undefined behavior, but the wikipedia article on it uses underflows in C as an example, so I suppose it is.

Comment thread src/player_controller.c Outdated
@MegaMech MegaMech merged commit c68b3d4 into n64decomp:master Apr 13, 2026
1 of 4 checks passed
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.

2 participants