Steering#761
Conversation
Refer to steering position instead of steering angle, to make clear that it is not the same thing as degrees.
| current_steering_change_increment = player->steerChangeIncrement; | ||
| player->steerChangeIncrement -= 1 << 11; | ||
| //signed vs unsigned weirdness, actually checking if negative | ||
| if (player->steerChangeIncrement >= 0xF0000000) { |
There was a problem hiding this comment.
Do you think this might technically be UB?
I wonder if it's a compiler optimization and that it might actaully be < 0
There was a problem hiding this comment.
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.
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.cthat explains it in more detail (before many calls toupdate_steering_largeandupdate_steering_small)Note that
player->steerPositionrarely uses the rightmost 16 bits, so there's a fair amount of bit shifting.