Mario Kart 64
|
The developers wrote mk64 using a state-driven paradigm. Gamestate, gamemode, course, actors, structs, and more decide which branches code should follow. As an example, a condition can check the current course to load that courses resources or run logic based on that.
After boot, the game begins by setting up its four threads; idle, video, audio, and the game loop.
The idle thread allows the cpu to sleep. Without it, if at any time execution of all threads were paused, the cpu would never be able to continue. The idle thread is active if all the other threads are paused.
As such, the idle thread runs the following loop: while(true);
(it runs in a perpetual loop of nothing; sleep). In mips assembly it looks like this:
b stands for branch which acts akin to a goto. In this case, branch to the label .L800005B8
. This creates an infinite loop. Whenever the cpu branches it always runs the next instruction as well which is called a delay slot. This means the cpu will continuously branch then run nop
or no operation
with no method of escaping the loop (except for when another thread has a higher priority which means the cpu switches to that thread and stops running the idle thread).
N64 threads are ran based on priority running whichever thread holds the most of it. Threads can also pause and wait for events. Note that the N64 is not multi-threaded by modern standards as the other threads contain specific purposes which slightly differs from the concept of splitting a single program into multiple processes for efficiency.
order of initialisation of thread: boot:
If mk64 is in a menu state it will branch off to the menu code, running relevant bits of code based on more flags such as which particular menu the user is in. This will loop until the state changes to a different one such as race mode. If mk64 is in a race state, then race related code is ran and it spaghetti's off into a wide series of branches. This may include concepts such as isLinedUp, isRacing, isRaceFinished, gotoNextCourse, isHuman, and isAI
.
This relatively primitive design could be defined as a state machine from an abstract point of view. This would differ from an OOP design that uses objects and hierarchy. You will become very familiar with this design principle as you explore the code-base. During any step of the game loop, a switch can be setup to check a flag then run code relevant to the situation. For instance, a flag can check whether a race is in-progress or complete. If in-progress set the player to human controlled. If complete, set player to AI controlled.
mk64 code is split into three sections for now.
Segment | desc |
---|---|
Main | Menus, audio, libultra, rsp (include in libultra) |
Racing | Memory management, courses, players, actors, skybox, collision, math |
Ending | Podium ceremony, credits |
Racing segment loads after selecting a grand prix. Note that it is always reloaded preventing randomization of cpu's at the start of the first race due to no time for the random seed to actually become random.
file | desc |
---|---|
menus | Menu related code |
save | Save related |
startup_logo | Startup logo |
Player related code resides in
file | desc |
---|---|
player_controller | Applies physics to players |
camera | Player cameras |
Actor related code resides in
file | desc |
---|---|
actors | Variety of actors, see link for specifics. |
actors_extended | Shells and bananas |
code_80005FD0 | Vehicles; trains, cars, trucks, boats |
Object related code resides in
file | desc |
---|---|
code_80057C60 | Objects |
update_objects | Objects |
code_80086E70 | Objects |
Documentation of the specifics still in-progress. See actors for more information.
Course related code resides in
file | desc |
---|---|
memory | Loads and extracts course data |
render_courses | Renders course content |
common_textures | Content accessible to every course such as items and portraits |
[course folder link][Courses]
file | desc |
---|---|
courses/course_name/course_data.c | Course data |
courses/course_name/course_vertices.inc.c | Course vertices (this + _displaylists.inc.c makes the course geography) |
courses/course_name/course_displaylists.inc.c | Course displaylists (these get compressed during compile) |
courses/course_name/course_offsets.c | Textures used in the course |
file | desc |
---|---|
render_objects | ItemWindows |
file | desc |
---|---|
collision | |
code_80005FD0 | Pathing code |
Math related code resides in
file | desc |
---|---|
math_util | |
math_util_2 |
file | desc |
---|---|
ceremony_and_credits | Camera rails for podium ceremony and credits |
podium_ceremony_actors | Fireworks and balloons for podium ceremony |
ceremony_data | Trophies and podium models. Paths. |
credits | Credits text and UI positions |