|
SpaghettiKart
|
#include <stdint.h>#include <libultraship.h>#include <macros.h>#include <libultra/gbi.h>#include <mk64.h>#include <common_structs.h>#include <actor_types.h>#include "main.h"#include "memory.h"#include "collision.h"#include "math_util.h"#include "code_800029B0.h"#include <defines.h>#include "port/Engine.h"#include "port/Game.h"#include "libultraship/bridge/resourcebridge.h"#include <stdio.h>#include "RaceManager.h"Macros | |
| #define | MAX3(a, b, c, out) |
| #define | MIN3(a, b, c, out) |
Functions | |
| void | nullify_displaylist (uintptr_t addr) |
| void | func_802AAAAC (Collision *collision) |
| f32 | get_water_level (Player *player) |
| s32 | check_collision_zx (Collision *collision, f32 boundingBoxSize, f32 posX, f32 posY, f32 posZ, u16 index) |
| s32 | check_collision_yx (Collision *collision, f32 boundingBoxSize, f32 posX, f32 posY, f32 posZ, u16 index) |
| s32 | check_collision_zy (Collision *collision, f32 boundingBoxSize, f32 posX, f32 posY, f32 posZ, u16 index) |
| s32 | check_horizontally_colliding_with_triangle (f32 posX, f32 posZ, u16 index) |
| s8 | get_surface_type (u16 index) |
| s16 | get_track_section_id (u16 index) |
| s16 | func_802ABD7C (u16 index) |
| s16 | func_802ABDB8 (u16 index) |
| s16 | func_802ABDF4 (u16 index) |
| f32 | calculate_surface_height (f32 x, f32 y, f32 z, u16 index) |
| f32 | func_802ABEAC (Collision *collision, Vec3f pos) |
| void | process_shell_collision (Vec3f pos, UNUSED f32 boundingBoxSize, Vec3f velocity, UNUSED f32 unk) |
| void | shell_collision (Collision *collision, Vec3f velocity) |
| void | adjust_pos_orthogonally (Vec3f pos1, f32 boundingBoxSize, Vec3f pos2, UNUSED f32 unk) |
| UNUSED s32 | detect_tyre_collision (KartTyre *tyre) |
| s32 | is_colliding_with_drivable_surface (Collision *collision, f32 boundingBoxSize, f32 newX, f32 newY, f32 newZ, u16 index, f32 oldX, f32 oldY, f32 oldZ) |
| s32 | is_colliding_with_wall2 (Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 surfaceIndex, f32 posX, f32 posY, f32 posZ) |
| s32 | is_colliding_with_wall1 (Collision *arg, f32 boundingBoxSize, f32 x1, f32 y1, f32 z1, u16 surfaceIndex, f32 posX, f32 posY, f32 posZ) |
| u16 | actor_terrain_collision (Collision *collision, f32 boundingBoxSize, f32 newX, f32 newY, f32 newZ, f32 oldX, f32 oldY, f32 oldZ) |
| u16 | check_bounding_collision (Collision *collision, f32 boundingBoxSize, f32 posX, f32 posY, f32 posZ) |
| f32 | spawn_actor_on_surface (f32 posX, f32 posY, f32 posZ) |
| void | add_collision_triangle (Vtx *vtx1, Vtx *vtx2, Vtx *vtx3, s8 surfaceType, u16 sectionId) |
| void | set_vtx_from_triangle (u32 triangle, s8 surfaceType, u16 sectionId) |
| void | set_vtx_from_tri2 (u32 triangle1, u32 triangle2, s8 surfaceType, u16 sectionId) |
| void | set_vtx_from_quadrangle (u32 line, s8 surfaceType, u16 sectionId) |
| void | add_vtx_from_quadrangle (Vtx *vert, size_t count) |
| void | set_vtx_buffer (uintptr_t addr, u32 numVertices, u32 bufferIndex) |
| s32 | is_point_inside_triangle (s16 px, s16 pz, s16 x1, s16 z1, s16 x2, s16 z2, s16 x3, s16 z3) |
| s32 | is_line_intersecting_rectangle (s16 minX, s16 maxX, s16 minZ, s16 maxZ, s16 x1, s16 z1, s16 x2, s16 z2) |
| s32 | is_triangle_intersecting_bounding_box (s16 minX, s16 maxX, s16 minZ, s16 maxZ, u16 index) |
| void | generate_collision_grid (void) |
| void | generate_collision_mesh_with_defaults (Gfx *gfx) |
| void | generate_collision_mesh_with_default_section_id (Gfx *gfx, s8 surfaceType) |
| bool | is_cull_box (const char *filePath) |
| void | generate_collision_mesh (Gfx *addr, s8 surfaceType, u16 sectionId) |
| void | find_and_set_tile_size (uintptr_t addr, s32 uls, s32 ult) |
| void | set_vertex_colours (uintptr_t addr, u32 vertexCount, UNUSED s32 vert3, s8 alpha, u8 red, u8 green, u8 blue) |
| void | find_vtx_and_set_colours (Gfx *displayList, s8 alpha, u8 red, u8 green, u8 blue) |
| void | subtract_scaled_vector (Vec3f pos1, f32 boundingBoxSize, Vec3f pos2) |
| u16 | player_terrain_collision (Player *player, KartTyre *tyre, f32 tyre2X, f32 tyre2Y, f32 tyre2Z) |
Variables | |
| u8 | D_8014F1110 |
| u32 | D_8015F58C |
| u32 | numTimes = 0 |
| #define MAX3 | ( | a, | |
| b, | |||
| c, | |||
| out ) |
| #define MIN3 | ( | a, | |
| b, | |||
| c, | |||
| out ) |
| u16 actor_terrain_collision | ( | Collision * | collision, |
| f32 | boundingBoxSize, | ||
| f32 | newX, | ||
| f32 | newY, | ||
| f32 | newZ, | ||
| f32 | oldX, | ||
| f32 | oldY, | ||
| f32 | oldZ ) |
| void add_collision_triangle | ( | Vtx * | vtx1, |
| Vtx * | vtx2, | ||
| Vtx * | vtx3, | ||
| s8 | surfaceType, | ||
| u16 | sectionId ) |
| void add_vtx_from_quadrangle | ( | Vtx * | vert, |
| size_t | count ) |
Adjusts the position of pos2 based on pos1 but in the orthogonal direction to pos2.
| f32 calculate_surface_height | ( | f32 | x, |
| f32 | y, | ||
| f32 | z, | ||
| u16 | index ) |
| u16 check_bounding_collision | ( | Collision * | collision, |
| f32 | boundingBoxSize, | ||
| f32 | posX, | ||
| f32 | posY, | ||
| f32 | posZ ) |
| s32 check_collision_yx | ( | Collision * | collision, |
| f32 | boundingBoxSize, | ||
| f32 | posX, | ||
| f32 | posY, | ||
| f32 | posZ, | ||
| u16 | index ) |
| s32 check_collision_zx | ( | Collision * | collision, |
| f32 | boundingBoxSize, | ||
| f32 | posX, | ||
| f32 | posY, | ||
| f32 | posZ, | ||
| u16 | index ) |
| s32 check_collision_zy | ( | Collision * | collision, |
| f32 | boundingBoxSize, | ||
| f32 | posX, | ||
| f32 | posY, | ||
| f32 | posZ, | ||
| u16 | index ) |
| s32 check_horizontally_colliding_with_triangle | ( | f32 | posX, |
| f32 | posZ, | ||
| u16 | index ) |
| void find_and_set_tile_size | ( | uintptr_t | addr, |
| s32 | uls, | ||
| s32 | ult ) |
Search for G_SETTILESIZE and set its args.
| void find_vtx_and_set_colours | ( | Gfx * | displayList, |
| s8 | alpha, | ||
| u8 | red, | ||
| u8 | green, | ||
| u8 | blue ) |
Recursive search for vertices and set their colour values.
| void func_802AAAAC | ( | Collision * | collision | ) |
| s16 func_802ABD7C | ( | u16 | index | ) |
| s16 func_802ABDB8 | ( | u16 | index | ) |
| s16 func_802ABDF4 | ( | u16 | index | ) |
| void generate_collision_grid | ( | void | ) |
Splits the collision mesh into a 32x32 grid of cells. This allows the game to check only nearby geography for a collision rather than checking against the whole collision mesh. (checking against the whole mesh for every actor would be expensive)
| void generate_collision_mesh | ( | Gfx * | addr, |
| s8 | surfaceType, | ||
| u16 | sectionId ) |
| void generate_collision_mesh_with_default_section_id | ( | Gfx * | gfx, |
| s8 | surfaceType ) |
Recursive search for vtx and set sectionId's to 0xFF
| void generate_collision_mesh_with_defaults | ( | Gfx * | gfx | ) |
Recursive search for vtx and set surfaceTypes to -1 and sectionId's to 0xFF
| s8 get_surface_type | ( | u16 | index | ) |
| s16 get_track_section_id | ( | u16 | index | ) |
| f32 get_water_level | ( | Player * | player | ) |
| s32 is_colliding_with_drivable_surface | ( | Collision * | collision, |
| f32 | boundingBoxSize, | ||
| f32 | newX, | ||
| f32 | newY, | ||
| f32 | newZ, | ||
| u16 | index, | ||
| f32 | oldX, | ||
| f32 | oldY, | ||
| f32 | oldZ ) |
| s32 is_colliding_with_wall1 | ( | Collision * | arg, |
| f32 | boundingBoxSize, | ||
| f32 | x1, | ||
| f32 | y1, | ||
| f32 | z1, | ||
| u16 | surfaceIndex, | ||
| f32 | posX, | ||
| f32 | posY, | ||
| f32 | posZ ) |
This is actually more like colliding with face X/Y/Z
| s32 is_colliding_with_wall2 | ( | Collision * | arg, |
| f32 | boundingBoxSize, | ||
| f32 | x1, | ||
| f32 | y1, | ||
| f32 | z1, | ||
| u16 | surfaceIndex, | ||
| f32 | posX, | ||
| f32 | posY, | ||
| f32 | posZ ) |
Wall collision
| bool is_cull_box | ( | const char * | filePath | ) |
Generate via a recursive search and set for vertex data.
| s32 is_line_intersecting_rectangle | ( | s16 | minX, |
| s16 | maxX, | ||
| s16 | minZ, | ||
| s16 | maxZ, | ||
| s16 | x1, | ||
| s16 | z1, | ||
| s16 | x2, | ||
| s16 | z2 ) |
| s32 is_point_inside_triangle | ( | s16 | px, |
| s16 | pz, | ||
| s16 | x1, | ||
| s16 | z1, | ||
| s16 | x2, | ||
| s16 | z2, | ||
| s16 | x3, | ||
| s16 | z3 ) |
Source: https://web.archive.org/web/20220920081010/https://www.gamedev.net/forums/topic.asp?topic_id=295943
| s32 is_triangle_intersecting_bounding_box | ( | s16 | minX, |
| s16 | maxX, | ||
| s16 | minZ, | ||
| s16 | maxZ, | ||
| u16 | index ) |
Check if any point of the bounding box is inside the triangle Bug fix that was not in the original game. Without this, triangles that are bigger than a collision grid cell, will not be included in that cell Thus, players would spawn in the air at 3000.0f as a fallback, or could fall through that portion of the track.
| void nullify_displaylist | ( | uintptr_t | addr | ) |
| u16 player_terrain_collision | ( | Player * | player, |
| KartTyre * | tyre, | ||
| f32 | tyre2X, | ||
| f32 | tyre2Y, | ||
| f32 | tyre2Z ) |
| void process_shell_collision | ( | Vec3f | pos, |
| UNUSED f32 | boundingBoxSize, | ||
| Vec3f | velocity, | ||
| UNUSED f32 | unk ) |
| void set_vertex_colours | ( | uintptr_t | addr, |
| u32 | vertexCount, | ||
| UNUSED s32 | vert3, | ||
| s8 | alpha, | ||
| u8 | red, | ||
| u8 | green, | ||
| u8 | blue ) |
| void set_vtx_buffer | ( | uintptr_t | addr, |
| u32 | numVertices, | ||
| u32 | bufferIndex ) |
Generates a list of pointers to track vtx.
| void set_vtx_from_quadrangle | ( | u32 | line, |
| s8 | surfaceType, | ||
| u16 | sectionId ) |
| void set_vtx_from_tri2 | ( | u32 | triangle1, |
| u32 | triangle2, | ||
| s8 | surfaceType, | ||
| u16 | sectionId ) |
| void set_vtx_from_triangle | ( | u32 | triangle, |
| s8 | surfaceType, | ||
| u16 | sectionId ) |
Triangle contains three indices that are used to get the actual vertices.
| f32 spawn_actor_on_surface | ( | f32 | posX, |
| f32 | posY, | ||
| f32 | posZ ) |
If unable to spawn actor on the surface set to -3000.0f or if outside the collision grid, spawn in the air (3000.0f).
|
extern |
|
extern |
| u32 numTimes = 0 |