Skip to content

Conversation

@V10lator
Copy link
Contributor

No description provided.

Signed-off-by: Thomas Rohloff <v10lator@myway.de>
V10lator added 2 commits July 18, 2025 21:06
Signed-off-by: Thomas Rohloff <v10lator@myway.de>
Signed-off-by: Thomas Rohloff <v10lator@myway.de>
@MegaMech
Copy link
Contributor

MegaMech commented Jul 19, 2025

The random function being changed effects the podium ceremony.
I thought this PR altered how the players spawn in grand prix mode.

Please clarify what the intentions are.

The best way to prevent random spawn order is likely to alter the random function in spawn_players.c

@V10lator
Copy link
Contributor Author

Please clarify what the intentions are.

There are two PRNGs in the game. On vanilla the seeds of both PRNGs are set to zero at multiple times, making the pseudo random number generator deterministic (it will produce the same random numbers after each time the seed is set to zero).

On Spaghetti Kart the PRNGs seeds are never set to zero after initialising, changing the behavior.

What this pull request does is:

  1. Setting the seeds to zero when vanilla would do it, too, making it just as deterministic as vanilla.
  2. Add an option to not set the seeds to zero, like it is done in spaghetti kart 0.9.9 and 0.9.9.1.

What does this affect?

  • The first PRNG affects plaxers pawning in grand prix, without resetting the seeds the spawning is bound on the player you select, so for example if you select toad the spawning will be:
  1. Bowser
  2. Mario
  3. Wario
  4. Donkey Kong
  5. Yoshi
  6. Luigi
  7. Peach
  8. Toad
    20250720093435_1

You can test this by starting a game (make sure the new option from this PR is not checked, so the seeds are set to zero), starting a cup as toad, looking at player spawn positions on screen, exiting the cup, starting it again, ... You will get the exact same spawn positions each time.

Next activate the new option and do the exact same thing again, you will get different spawn positions each time (except for toad, the player you selected).
20250720093411_1.

With 0.9.9.1 release you should get the second behaviour while vanilla should give you the first behaviour.

It should also affect item boxes and all other things using the PRNG with the gRandomSeed16 seed.

The random function being changed effects the podium ceremony.

This is the second PRNG. It's seed is sRandomSeed16. With the option from this PR activated this second PRNG isn't used at all but the first one is used in its case instead, highering the randomness of both PRNGs.

Note that without this PR the second PRNGs seed is never zeroed, different to vanilla, so I'm very interrested in what exactly changed for you with this option. According to Discord it should affect the confetty and balloons.

@V10lator
Copy link
Contributor Author

V10lator commented Jul 20, 2025

I btw observed something weird: In src/code_80057C60.c there is a function called randomize_seed_from_controller which seems to try to collect real random data from controller events. It looks too simple to collect good randomness through and what it collects just rots in RAM but never ever gets xored to one of the PRNG seeds or anything...

Only speculation but did the original MK64 devs want to have better randomness but ran out of time?

V10lator added 2 commits July 31, 2025 10:04
Signed-off-by: Thomas Rohloff <v10lator@myway.de>
This reverts commit 6762257 as talked up on Discord.
}

void balloons_and_fireworks_init(void) {
sRandomSeed16 = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be placed in?

void init_segment_ending_sequences(void) {
#ifdef TARGET_N64
    bzero((void*) SEG_ENDING, SEG_ENDING_SIZE);
    osWritebackDCacheAll();
    dma_copy((u8*) SEG_ENDING, (u8*) SEG_ENDING_ROM_START, SEG_ENDING_ROM_SIZE);
    osInvalICache((void*) SEG_ENDING, SEG_ENDING_SIZE);
    osInvalDCache((void*) SEG_ENDING, SEG_ENDING_SIZE);
#endif
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see it's static. Yea this is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

But it's not around a CVar?


f32 random_float_between_0_and_1(void) {
return random_u16_credits() / 65536.0f;
return random_u16_credits() / (f32) UINT16_MAX;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not identical behaviour


u16 random_u16_credits(void) {
u16 temp1, temp2;
if (CVarGetInteger("gBugfixRNGReset", true) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand this change.

The idea is to remove the duplicate function and use the original one. But now the random seed won't have been reset because we're now using gRandomSeed instead of sRandomSeed.

I would recommend one of two options

  1. Just delete random_u16_credits, and modify the game to act how expected using just the one random function
  • This is simpler, makes more sense, etc.
  1. Not call the original random_u16() and just use random_u16_credits()
  • Otherwise it's more likely to get mixed up and confused.

AddSidebarEntry("Enhancements", "Bugfixes", 3);
AddWidget(path, "Don't reset random seed", WIDGET_CVAR_CHECKBOX)
.CVar("gBugfixRNGReset")
.Options(CheckboxOptions().Tooltip("The section handling of MK8 zeroes the random seed before races. Enable this to never zero the seed.").DefaultValue(true));
Copy link
Contributor

@MegaMech MegaMech Aug 8, 2025

Choose a reason for hiding this comment

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

Racer spawns are not randomized at the start of Grand Prix. Enable this to fix random seeding.
or

Fix random seeding allowing randomized racer spawns at the start of a Grand Prix and randomized firework spawns during the podium ceremony.

(I think I like this one the best so far of everything I've come up with)


path = { "Enhancements", "Bugfixes", SECTION_COLUMN_1 };
AddSidebarEntry("Enhancements", "Bugfixes", 3);
AddWidget(path, "Don't reset random seed", WIDGET_CVAR_CHECKBOX)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix random seeding ? Maybe Prevent random seeding from being reset
Or perhaps
Randomize racer spawns and then have the explanation in the tooltip?

@MegaMech
Copy link
Contributor

MegaMech commented Aug 8, 2025

Regarding the enhancement button. Try to reword it in a way that explains to users what the button does. Users won't understand the technical jargon like "The game resets gRandomSeed to zero for the racing code segment at the start of the race resulting in spawn locations not being reset" is more info then necessary because they don't know what a code segment or gRandomSeed is.

But the end result of "fireworks and racers not being randomized" is moreso something they would understand.

Or perhaps another way of wording it "Racer and firework spawn locations do not get randomized due to the random seed being reset just before the race begins"

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.

3 participants