-
Notifications
You must be signed in to change notification settings - Fork 76
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
bug fix: hoverbike jittering #176
Conversation
#ifdef PLATFORM_N64 | ||
if (g_Vars.lvframe60 > hov->prevframe60) | ||
#endif | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the jittering when using the combat boost.
For some reason which I don't understand yet, when the combat boost is enabled g_Vars.lvframe60 == hov->prevframe60
every other frame, causing the transform to be updated only every other frame therefore the jittering. I'll keep investigating this.
src/game/timing.c
Outdated
diffframe60 = (g_Vars.lostframetime60t + diffframet + CYCLES_PER_FRAME / 2) / CYCLES_PER_FRAME; | ||
diffframe240 = (g_Vars.lostframetime240t + diffframet + CYCLES_PER_FRAME / 2 / 4) / (CYCLES_PER_FRAME / 4); | ||
diffframe60 = (diffframet + CYCLES_PER_FRAME / 2) / CYCLES_PER_FRAME; | ||
diffframe240 = (diffframet + CYCLES_PER_FRAME / 2 / 4) / (CYCLES_PER_FRAME / 4); | ||
} while (diffframe60 < g_Vars.mininc60); | ||
|
||
g_Vars.lostframetime60t = g_Vars.lostframetime60t + diffframet - diffframe60 * CYCLES_PER_FRAME; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the random jittering without the combat boost.
I don't fully understand what is the use for this g_Vars.lostframetime60t
here, but i noticed that the way its calculated is actually redundant (I wonder if this is one of the decompilation quirks).
For clarity, lets nameg_Vars.lostframetime60t as L
, diffframet as D
and diffframe60 as D60
. In line 46, if we expand diffframe60
to the value from line 42, we get:
L = L + D - ((L + D + CYCLES_PER_FRAME/2) / CYCLES_PER_FRAME) * CYCLES_PER_FRAME
This whole thing simplifies to -CYCLES_PER_FRAME/2
. So in the next frame when we plug that into line 42, it will cancel out with the term CYCLES_PER_FRAME/2
.
Like you already mentioned, since this is a change in the timing code, it needs some thorough testing. |
Actually I tested more and noticed that the changes to frametimeCalculate() are not needed, I just reverted it. Removing the conditional in hovTick() fixes it with and without the combat boost. |
Wonder if maybe a |
Yes I still don't understand why |
The conditions are likely needed because the tick function is called for each player. If one player has already ticked the hover object on this frame then it skips this part of the function for the second player. You should test your changes in co-op mode with a human buddy. lostframetime is a remainder value of the number of CPU ticks. The game keeps track of these and applies it on the next frame to make sure time is accounted for correctly. If you remove it you might find in-game time drifting from reality. Or because PC is pretty much always 60 FPS, it might not be noticeable. lvframe60 being zero is related to running a frame within 1/60th of a second of the previous frame. The game can run a frame with lvframe240 = 3, which means lvframe60 can be 0. On the next frame even if lvframe240 is as low as 1, lvframe60 would be 1 because it's accounted for the remainder. So zero values are expected at high frame rates. If removing those conditions causes issues in co-op, an alternative fix would be to set a flag on the hov object to note that it's been ticked this frame, and clear it at the start of each frame. Eg. add a new HOVFLAG constant. |
Makes sense now, thanks for the explanation Ryan! |
I tested co-op (and counter-op as well), no issues. With 2 limitations though: currently no way to test using combat boost, and 2 hoverbikes (maybe when we have custom maps, like solo levels in MP) |
You could maybe edit one of the setup level scripts so that it spawns and 2nd bike? In the same level you could change the startup so it gives you combat boosts.
|
Ah yes of course thanks for the tip, I forgot the setup data isn't being read from the ROM, but is in code. |
It is actually being read from the ROM. However you could change it in the decomp and then use the resulting setup file data as a replacement, though you'll need to strip off the ELF header and other stuff. If you can somehow manage to build a new ROM without it being too different from the OG you can also just feed it to |
Alright, I'll try it later. It would be neat if the game used the setup data from the c files, but I dont know how complex it is to change that. |
Thank you so much for the guide. 2023-09-20.19-56-36.mp4 |
I suppose I'll merge this then. |
If we ever run into issues related to hoverbikes and multiplayer in the future, will remember to revise this (I think is unlikely though). |
Fixes #78
However, see remarks below.
I tested a bit, the jittering is fixed and I didn't observe any side effect, but definitely more testing is needed since this touches the frame time calculation code, which can be very sensitive and affect tons of things.