Collision data type define

Terrain data can now be configured to be a different type other than s16, for any nefarious reasons
This commit is contained in:
Fazana committed 2021-08-18 22:36:42 +01:00
1 parent 20ffa3de16
commit 57e9301751
10 files changed
+81 -95

No files matched your search

+45 -64
View File
@@ -18,8 +18,6 @@
#include "config.h"
s32 unused8038BE90;
/**
* Partitions for course and object surfaces. The arrays represent
* the 16x16 cells that each level is split into.
@@ -38,8 +36,6 @@ struct Surface *sSurfacePool;
*/
s16 sSurfacePoolSize;
u8 unused8038EEA8[0x30];
u8 gSurfacePoolError = 0;
/**
@@ -116,14 +112,14 @@ static void clear_static_surfaces(void) {
* @param cellZ The Z position of the cell in which the surface resides
* @param surface The surface to add
*/
static void add_surface_to_cell(s16 dynamic, s16 cellX, s16 cellZ, struct Surface *surface) {
static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surface *surface) {
struct SurfaceNode *newNode = alloc_surface_node();
struct SurfaceNode *list;
s16 surfacePriority;
s16 priority;
s16 sortDir;
s16 listIndex;
s16 isWater = surface->type == SURFACE_NEW_WATER || surface->type == SURFACE_NEW_WATER_BOTTOM;
s32 surfacePriority;
s32 priority;
s32 sortDir;
s32 listIndex;
s32 isWater = surface->type == SURFACE_NEW_WATER || surface->type == SURFACE_NEW_WATER_BOTTOM;
if (surface->normal.y > 0.01) {
listIndex = isWater ? SPATIAL_PARTITION_WATER : SPATIAL_PARTITION_FLOORS;
@@ -174,7 +170,7 @@ static void add_surface_to_cell(s16 dynamic, s16 cellX, s16 cellZ, struct Surfac
/**
* Returns the lowest of three values.
*/
static s16 min_3(s16 a0, s16 a1, s16 a2) {
static s32 min_3(s32 a0, s32 a1, s32 a2) {
if (a1 < a0) {
a0 = a1;
}
@@ -189,7 +185,7 @@ static s16 min_3(s16 a0, s16 a1, s16 a2) {
/**
* Returns the highest of three values.
*/
static s16 max_3(s16 a0, s16 a1, s16 a2) {
static s32 max_3(s32 a0, s32 a1, s32 a2) {
if (a1 > a0) {
a0 = a1;
}
@@ -206,8 +202,8 @@ static s16 max_3(s16 a0, s16 a1, s16 a2) {
* time). This function determines the lower cell for a given x/z position.
* @param coord The coordinate to test
*/
static s16 lower_cell_index(s32 coord) {
s16 index;
static s32 lower_cell_index(s32 coord) {
s32 index;
// Move from range [-0x2000, 0x2000) to [0, 0x4000)
coord += LEVEL_BOUNDARY_MAX;
@@ -238,8 +234,8 @@ static s16 lower_cell_index(s32 coord) {
* time). This function determines the upper cell for a given x/z position.
* @param coord The coordinate to test
*/
static s16 upper_cell_index(s32 coord) {
s16 index;
static s32 upper_cell_index(s32 coord) {
s32 index;
// Move from range [-0x2000, 0x2000) to [0, 0x4000)
coord += LEVEL_BOUNDARY_MAX;
@@ -273,15 +269,11 @@ static s16 upper_cell_index(s32 coord) {
* @param dynamic Boolean determining whether the surface is static or dynamic
*/
static void add_surface(struct Surface *surface, s32 dynamic) {
// minY/maxY maybe? s32 instead of s16, though.
UNUSED s32 unused1, unused2;
s16 minX, minZ, maxX, maxZ;
s32 minX, minZ, maxX, maxZ;
s16 minCellX, minCellZ, maxCellX, maxCellZ;
s32 minCellX, minCellZ, maxCellX, maxCellZ;
s16 cellZ, cellX;
// cellY maybe? s32 instead of s16, though.
UNUSED s32 unused3 = 0;
s32 cellZ, cellX;
minX = min_3(surface->vertex1[0], surface->vertex2[0], surface->vertex3[0]);
minZ = min_3(surface->vertex1[2], surface->vertex2[2], surface->vertex3[2]);
@@ -300,15 +292,12 @@ static void add_surface(struct Surface *surface, s32 dynamic) {
}
}
UNUSED static void stub_surface_load_1(void) {
}
/**
* Initializes a Surface struct using the given vertex data
* @param vertexData The raw data containing vertex positions
* @param vertexIndices Helper which tells positions in vertexData to start reading vertices
*/
static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {
static struct Surface *read_surface_data(TerrainData *vertexData, TerrainData **vertexIndices) {
struct Surface *surface;
register s32 x1, y1, z1;
register s32 x2, y2, z2;
@@ -316,7 +305,7 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {
s32 maxY, minY;
f32 nx, ny, nz;
f32 mag;
s16 offset1, offset2, offset3;
s32 offset1, offset2, offset3;
offset1 = 3 * (*vertexIndices)[0];
offset2 = 3 * (*vertexIndices)[1];
@@ -397,7 +386,7 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {
* Returns whether a surface has exertion/moves Mario
* based on the surface type.
*/
static s32 surface_has_force(s16 surfaceType) {
static s32 surface_has_force(s32 surfaceType) {
s32 hasForce = FALSE;
switch (surfaceType) {
@@ -422,7 +411,7 @@ static s32 surface_has_force(s16 surfaceType) {
* Returns whether a surface should have the
* SURFACE_FLAG_NO_CAM_COLLISION flag.
*/
static s32 surf_has_no_cam_collision(s16 surfaceType) {
static s32 surf_has_no_cam_collision(s32 surfaceType) {
s32 flags = 0;
switch (surfaceType) {
@@ -444,15 +433,15 @@ static s32 surf_has_no_cam_collision(s16 surfaceType) {
* Load in the surfaces for a given surface type. This includes setting the flags,
* exertion, and room.
*/
static void load_static_surfaces(s16 **data, s16 *vertexData, s16 surfaceType, s8 **surfaceRooms) {
static void load_static_surfaces(TerrainData **data, TerrainData *vertexData, s32 surfaceType, RoomData **surfaceRooms) {
s32 i;
s32 numSurfaces;
struct Surface *surface;
s8 room = 0;
s32 room = 0;
#ifndef ALL_SURFACES_HAVE_FORCE
s16 hasForce = surface_has_force(surfaceType);
#endif
s16 flags = surf_has_no_cam_collision(surfaceType);
s32 flags = surf_has_no_cam_collision(surfaceType);
numSurfaces = *(*data);
*data += 1;
@@ -496,11 +485,9 @@ static void load_static_surfaces(s16 **data, s16 *vertexData, s16 surfaceType, s
/**
* Read the data for vertices for reference by triangles.
*/
static s16 *read_vertex_data(s16 **data) {
static TerrainData *read_vertex_data(TerrainData **data) {
s32 numVertices;
UNUSED s16 unused1[3];
UNUSED s16 unused2[3];
s16 *vertexData;
TerrainData *vertexData;
numVertices = *(*data);
(*data)++;
@@ -514,7 +501,7 @@ static s16 *read_vertex_data(s16 **data) {
/**
* Loads in special environmental regions, such as water, poison gas, and JRB fog.
*/
static void load_environmental_regions(s16 **data) {
static void load_environmental_regions(TerrainData **data) {
s32 numRegions;
s32 i;
@@ -525,8 +512,8 @@ static void load_environmental_regions(s16 **data) {
}
for (i = 0; i < numRegions; i++) {
UNUSED s16 val, loX, loZ, hiX, hiZ;
s16 height;
UNUSED TerrainData val, loX, loZ, hiX, hiZ;
TerrainData height;
val = *(*data)++;
@@ -557,15 +544,15 @@ void alloc_surface_pools(void) {
/**
* Get the size of the terrain data, to get the correct size when copying later.
*/
u32 get_area_terrain_size(s16 *data) {
s16 *startPos = data;
u32 get_area_terrain_size(TerrainData *data) {
TerrainData *startPos = data;
s32 end = FALSE;
s16 terrainLoadType;
TerrainData terrainLoadType;
s32 numVertices;
s32 numRegions;
s32 numSurfaces;
#ifndef ALL_SURFACES_HAVE_FORCE
s16 hasForce;
TerrainData hasForce;
#endif
while (!end) {
@@ -614,17 +601,15 @@ u32 get_area_terrain_size(s16 *data) {
* Process the level file, loading in vertices, surfaces, some objects, and environmental
* boxes (water, gas, JRB fog).
*/
void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects) {
s16 terrainLoadType;
s16 *vertexData = NULL;
UNUSED s32 unused;
void load_area_terrain(s32 index, TerrainData *data, RoomData *surfaceRooms, s16 *macroObjects) {
s32 terrainLoadType;
TerrainData *vertexData = NULL;
#ifdef PUPPYPRINT
OSTime first = osGetTime();
#endif
// Initialize the data for this.
gEnvironmentRegions = NULL;
unused8038BE90 = 0;
gSurfaceNodesAllocated = 0;
gSurfacesAllocated = 0;
@@ -686,14 +671,11 @@ void clear_dynamic_surfaces(void) {
}
}
UNUSED static void unused_80383604(void) {
}
/**
* Applies an object's transformation to the object's vertices.
*/
void transform_object_vertices(s16 **data, s16 *vertexData) {
register s16 *vertices;
void transform_object_vertices(TerrainData **data, TerrainData *vertexData) {
register TerrainData *vertices;
register f32 vx, vy, vz;
register s32 numVertices;
@@ -721,9 +703,9 @@ void transform_object_vertices(s16 **data, s16 *vertexData) {
vz = *(vertices++);
//! No bounds check on vertex data
*vertexData++ = (s16)(vx * m[0][0] + vy * m[1][0] + vz * m[2][0] + m[3][0]);
*vertexData++ = (s16)(vx * m[0][1] + vy * m[1][1] + vz * m[2][1] + m[3][1]);
*vertexData++ = (s16)(vx * m[0][2] + vy * m[1][2] + vz * m[2][2] + m[3][2]);
*vertexData++ = (TerrainData)(vx * m[0][0] + vy * m[1][0] + vz * m[2][0] + m[3][0]);
*vertexData++ = (TerrainData)(vx * m[0][1] + vy * m[1][1] + vz * m[2][1] + m[3][1]);
*vertexData++ = (TerrainData)(vx * m[0][2] + vy * m[1][2] + vz * m[2][2] + m[3][2]);
}
*data = vertices;
@@ -732,15 +714,15 @@ void transform_object_vertices(s16 **data, s16 *vertexData) {
/**
* Load in the surfaces for the gCurrentObject. This includes setting the flags, exertion, and room.
*/
void load_object_surfaces(s16 **data, s16 *vertexData) {
void load_object_surfaces(TerrainData **data, TerrainData *vertexData) {
s32 surfaceType;
s32 i;
s32 numSurfaces;
#ifndef ALL_SURFACES_HAVE_FORCE
s16 hasForce;
TerrainData hasForce;
#endif
s16 flags;
s16 room;
s32 flags;
s32 room;
surfaceType = *(*data);
(*data)++;
@@ -801,13 +783,12 @@ void load_object_surfaces(s16 **data, s16 *vertexData) {
* Transform an object's vertices, reload them, and render the object.
*/
void load_object_collision_model(void) {
UNUSED s32 unused;
s16 vertexData[600];
TerrainData vertexData[600];
#ifdef PUPPYPRINT
OSTime first = osGetTime();
#endif
s16 *collisionData = gCurrentObject->collisionData;
TerrainData *collisionData = gCurrentObject->collisionData;
f32 marioDist = gCurrentObject->oDistanceToMario;
f32 tangibleDist = gCurrentObject->oCollisionDistance;