diff --git a/asm/rom_header.s b/asm/rom_header.s index d6ba482e..ee296ff0 100644 --- a/asm/rom_header.s +++ b/asm/rom_header.s @@ -24,12 +24,10 @@ .ascii "SM" /* Cartridge ID */ /* Region */ -#ifdef VERSION_EU - .ascii "P" /* PAL (Europe) */ -#elif defined(VERSION_US) - .ascii "E" /* NTSC-U (North America) */ -#else +#if defined(VERSION_JP) || defined(VERSION_SH) .ascii "J" /* NTSC-J (Japan) */ +#else + .ascii "E" /* NTSC-U (North America) */ #endif diff --git a/include/config.h b/include/config.h index ca21728b..f170f10a 100644 --- a/include/config.h +++ b/include/config.h @@ -163,6 +163,12 @@ // Use a much better implementation of reverb over vanilla's fake echo reverb. Great for caves or eerie levels, as well as just a better audio experience in general. // Reverb parameters can be configured in audio/synthesis.c to meet desired aesthetic/performance needs. //#define BETTER_REVERB +//Collision data is the type that the collision system uses. All data by default is stored as an s16, but you may change it to s32. +//Naturally, that would double the size of all collision data, but would allow you to use 32 bit values instead of 16. +//Rooms are s8 in vanilla, but if you somehow have more than 255 rooms, you may raise this number. +//Currently, they *must* say as s8, because the room tables generated by literally anything are explicitly u8 and don't use a macro, making this currently infeasable. +#define COLLISION_DATA_TYPE s16 +#define ROOM_DATA_TYPE s8 // If you want to change the extended boundaries mode, go to engine/extended_bounds.h and change EXTENDED_BOUNDS_MODE diff --git a/include/types.h b/include/types.h index fa73730a..9e423479 100644 --- a/include/types.h +++ b/include/types.h @@ -49,12 +49,14 @@ typedef uintptr_t GeoLayout; typedef uintptr_t LevelScript; typedef s16 Movtex; typedef s16 MacroObject; -typedef s16 Collision; +typedef COLLISION_DATA_TYPE Collision; //Collision is by default an s16, but it's best to have it match the type of COLLISION_DATA_TYPE typedef s16 Trajectory; typedef s16 PaintingData; typedef uintptr_t BehaviorScript; typedef u8 Texture; typedef u16 ModelID; +typedef COLLISION_DATA_TYPE TerrainData; +typedef ROOM_DATA_TYPE RoomData; enum SpTaskState { SPTASK_STATE_NOT_STARTED, diff --git a/src/engine/surface_collision.c b/src/engine/surface_collision.c index 03482770..98f7f396 100644 --- a/src/engine/surface_collision.c +++ b/src/engine/surface_collision.c @@ -708,10 +708,10 @@ f32 find_water_floor(f32 xPos, f32 yPos, f32 zPos, struct Surface **pfloor) { f32 find_water_level_and_floor(f32 x, f32 z, struct Surface **pfloor) { s32 i; s32 numRegions; - s16 val; - f32 loX, hiX, loZ, hiZ; - f32 waterLevel = FLOOR_LOWER_LIMIT; - s16 *p = gEnvironmentRegions; + s32 val; + s32 loX, hiX, loZ, hiZ; + s32 waterLevel = FLOOR_LOWER_LIMIT; + TerrainData *p = gEnvironmentRegions; struct Surface *floor = NULL; #ifdef PUPPYPRINT OSTime first = osGetTime(); @@ -759,10 +759,10 @@ f32 find_water_level_and_floor(f32 x, f32 z, struct Surface **pfloor) { f32 find_water_level(f32 x, f32 z) { s32 i; s32 numRegions; - s16 val; - f32 loX, hiX, loZ, hiZ; - f32 waterLevel = FLOOR_LOWER_LIMIT; - s16 *p = gEnvironmentRegions; + s32 val; + s32 loX, hiX, loZ, hiZ; + s32 waterLevel = FLOOR_LOWER_LIMIT; + TerrainData *p = gEnvironmentRegions; struct Surface *floor; #ifdef PUPPYPRINT OSTime first = osGetTime(); @@ -808,11 +808,10 @@ f32 find_water_level(f32 x, f32 z) { f32 find_poison_gas_level(f32 x, f32 z) { s32 i; s32 numRegions; - UNUSED s32 unused; - s16 val; - f32 loX, hiX, loZ, hiZ; - f32 gasLevel = FLOOR_LOWER_LIMIT; - s16 *p = gEnvironmentRegions; + s32 val; + s32 loX, hiX, loZ, hiZ; + s32 gasLevel = FLOOR_LOWER_LIMIT; + TerrainData *p = gEnvironmentRegions; #ifdef PUPPYPRINT OSTime first = osGetTime(); #endif diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index d889ea95..935001f7 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -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; diff --git a/src/engine/surface_load.h b/src/engine/surface_load.h index d947cf80..dea40ce4 100644 --- a/src/engine/surface_load.h +++ b/src/engine/surface_load.h @@ -38,9 +38,9 @@ extern s16 sSurfacePoolSize; void alloc_surface_pools(void); #ifdef NO_SEGMENTED_MEMORY -u32 get_area_terrain_size(s16 *data); +u32 get_area_terrain_size(TerrainData *data); #endif -void load_area_terrain(s16 index, s16 *data, s8 *surfaceRooms, s16 *macroObjects); +void load_area_terrain(s32 index, TerrainData *data, RoomData *surfaceRooms, s16 *macroObjects); void clear_dynamic_surfaces(void); void load_object_collision_model(void); diff --git a/src/game/macro_special_objects.c b/src/game/macro_special_objects.c index bd15a227..94dbac9a 100644 --- a/src/game/macro_special_objects.c +++ b/src/game/macro_special_objects.c @@ -104,7 +104,7 @@ struct LoadedPreset { #define MACRO_OBJ_Z 3 #define MACRO_OBJ_PARAMS 4 -void spawn_macro_objects(s16 areaIndex, s16 *macroObjList) { +void spawn_macro_objects(s32 areaIndex, s16 *macroObjList) { UNUSED u32 pad5C; s32 presetID; @@ -171,7 +171,7 @@ void spawn_macro_objects(s16 areaIndex, s16 *macroObjList) { } } -void spawn_macro_objects_hardcoded(s16 areaIndex, s16 *macroObjList) { +void spawn_macro_objects_hardcoded(s32 areaIndex, s16 *macroObjList) { UNUSED u8 pad[8]; // This version of macroObjList has the preset and Y-Rotation separated, @@ -237,7 +237,7 @@ void spawn_macro_objects_hardcoded(s16 areaIndex, s16 *macroObjList) { } } -void spawn_special_objects(s16 areaIndex, s16 **specialObjList) { +void spawn_special_objects(s32 areaIndex, TerrainData **specialObjList) { s32 numOfSpecialObjects; s32 i; s32 offset; diff --git a/src/game/macro_special_objects.h b/src/game/macro_special_objects.h index d8bdc237..1996aac5 100644 --- a/src/game/macro_special_objects.h +++ b/src/game/macro_special_objects.h @@ -11,9 +11,9 @@ void spawn_macro_abs_yrot_2params(s32 model, const BehaviorScript *behavior, s16 void spawn_macro_abs_yrot_param1(s32 model, const BehaviorScript *behavior, s16 x, s16 y, s16 z, s16 ry, s16 params); void spawn_macro_abs_special(s32 model, const BehaviorScript *behavior, s16 x, s16 y, s16 z, s16 unkA, s16 unkB, s16 unkC); -void spawn_macro_objects(s16 areaIndex, s16 *macroObjList); -void spawn_macro_objects_hardcoded(s16 areaIndex, s16 *macroObjList); -void spawn_special_objects(s16 areaIndex, s16 **specialObjList); +void spawn_macro_objects(s32 areaIndex, s16 *macroObjList); +void spawn_macro_objects_hardcoded(s32 areaIndex, s16 *macroObjList); +void spawn_special_objects(s32 areaIndex, TerrainData **specialObjList); #ifdef NO_SEGMENTED_MEMORY u32 get_special_objects_size(s16 *data); #endif diff --git a/src/game/object_list_processor.c b/src/game/object_list_processor.c index f071e217..6188fea2 100644 --- a/src/game/object_list_processor.c +++ b/src/game/object_list_processor.c @@ -147,9 +147,9 @@ struct MemoryPool *gObjectMemoryPool; s16 gCheckingSurfaceCollisionsForCamera; s16 gFindFloorIncludeSurfaceIntangible; -s16 *gEnvironmentRegions; +TerrainData *gEnvironmentRegions; s32 gEnvironmentLevels[20]; -s8 gDoorAdjacentRooms[60][2]; +RoomData gDoorAdjacentRooms[60][2]; s16 gMarioCurrentRoom; s16 D_8035FEE2; s16 D_8035FEE4; diff --git a/src/game/object_list_processor.h b/src/game/object_list_processor.h index e3884f34..f41550fa 100644 --- a/src/game/object_list_processor.h +++ b/src/game/object_list_processor.h @@ -100,9 +100,9 @@ extern struct MemoryPool *gObjectMemoryPool; extern s16 gCheckingSurfaceCollisionsForCamera; extern s16 gFindFloorIncludeSurfaceIntangible; -extern s16 *gEnvironmentRegions; +extern TerrainData *gEnvironmentRegions; extern s32 gEnvironmentLevels[20]; -extern s8 gDoorAdjacentRooms[60][2]; +extern RoomData gDoorAdjacentRooms[60][2]; extern s16 gMarioCurrentRoom; extern s16 D_8035FEE2; extern s16 D_8035FEE4;