Refactor to make surface iteration easier to make safer
This commit is contained in:
@@ -13,10 +13,11 @@ static struct Surface *find_ceil_from_list( s32 x, s32 y, s32 z, f32 *pheight) {
|
||||
|
||||
ceil = NULL;
|
||||
|
||||
// Stay in this loop until out of ceilings.
|
||||
int count = loaded_surface_get_count();
|
||||
for( int i = 0; i < count; ++i ) {
|
||||
surf = loaded_surface_get_at_index(i);
|
||||
uint32_t groupCount = loaded_surface_iter_group_count();
|
||||
for( int i = 0; i < groupCount; ++i ) {
|
||||
uint32_t surfCount = loaded_surface_iter_group_size( i );
|
||||
for( int j = 0; j < surfCount; ++j ) {
|
||||
surf = loaded_surface_iter_get_at_index( i, j );
|
||||
|
||||
// Do the check normally done in add_surface_to_cell
|
||||
if( surf->normal.y >= -0.01f ) continue;
|
||||
@@ -71,7 +72,7 @@ static struct Surface *find_ceil_from_list( s32 x, s32 y, s32 z, f32 *pheight) {
|
||||
ceil = surf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
return ceil;
|
||||
}
|
||||
|
||||
@@ -86,10 +87,11 @@ static struct Surface *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight)
|
||||
f32 height;
|
||||
struct Surface *floor = NULL;
|
||||
|
||||
// Iterate through the list of floors until there are no more floors.
|
||||
int count = loaded_surface_get_count();
|
||||
for( int i = 0; i < count; ++i ) {
|
||||
surf = loaded_surface_get_at_index(i);
|
||||
uint32_t groupCount = loaded_surface_iter_group_count();
|
||||
for( int i = 0; i < groupCount; ++i ) {
|
||||
uint32_t surfCount = loaded_surface_iter_group_size( i );
|
||||
for( int j = 0; j < surfCount; ++j ) {
|
||||
surf = loaded_surface_iter_get_at_index( i, j );
|
||||
|
||||
// Do the check normally done in add_surface_to_cell
|
||||
if( surf->normal.y <= 0.01f ) continue;
|
||||
@@ -137,7 +139,7 @@ static struct Surface *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight)
|
||||
*pheight = height;
|
||||
floor = surf;
|
||||
}
|
||||
}
|
||||
}}
|
||||
return floor;
|
||||
}
|
||||
|
||||
@@ -158,10 +160,11 @@ static s32 find_wall_collisions_from_list( struct WallCollisionData *data) {
|
||||
radius = 200.0f;
|
||||
}
|
||||
|
||||
// Stay in this loop until out of walls.
|
||||
int count = loaded_surface_get_count();
|
||||
for( int i = 0; i < count; ++i ) {
|
||||
surf = loaded_surface_get_at_index(i);
|
||||
uint32_t groupCount = loaded_surface_iter_group_count();
|
||||
for( int i = 0; i < groupCount; ++i ) {
|
||||
uint32_t surfCount = loaded_surface_iter_group_size( i );
|
||||
for( int j = 0; j < surfCount; ++j ) {
|
||||
surf = loaded_surface_iter_get_at_index( i, j );
|
||||
|
||||
// Do the check normally done in add_surface_to_cell
|
||||
if( surf->normal.y < -0.01f || surf->normal.y > 0.01f ) continue;
|
||||
@@ -251,7 +254,7 @@ static s32 find_wall_collisions_from_list( struct WallCollisionData *data) {
|
||||
}
|
||||
|
||||
numCols++;
|
||||
}
|
||||
}}
|
||||
|
||||
return numCols;
|
||||
}
|
||||
|
||||
@@ -47,16 +47,13 @@ void update_mario_platform(void) {
|
||||
|
||||
switch (awayFromFloor) {
|
||||
case 1:
|
||||
g_state->mgMarioPlatform = NULL;
|
||||
gMarioObject->platform = NULL;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
if (floor != NULL && floor->object != NULL) {
|
||||
g_state->mgMarioPlatform = floor->object;
|
||||
gMarioObject->platform = floor->object;
|
||||
if (floor != NULL && floor->transform != NULL) {
|
||||
gMarioObject->platform = floor->transform;
|
||||
} else {
|
||||
g_state->mgMarioPlatform = NULL;
|
||||
gMarioObject->platform = NULL;
|
||||
}
|
||||
break;
|
||||
@@ -166,16 +163,7 @@ void apply_platform_displacement(u32 isMario, struct SurfaceObjectTransform *pla
|
||||
* If Mario's platform is not null, apply platform displacement.
|
||||
*/
|
||||
void apply_mario_platform_displacement(void) {
|
||||
struct SurfaceObjectTransform *platform = g_state->mgMarioPlatform;
|
||||
|
||||
if (gMarioObject != NULL && platform != NULL) {
|
||||
apply_platform_displacement(TRUE, platform);
|
||||
if (gMarioObject != NULL && gMarioObject->platform != NULL) {
|
||||
apply_platform_displacement(TRUE, gMarioObject->platform);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Mario's platform to NULL.
|
||||
*/
|
||||
void clear_mario_platform(void) {
|
||||
g_state->mgMarioPlatform = NULL;
|
||||
}
|
||||
@@ -6,6 +6,5 @@
|
||||
|
||||
void update_mario_platform(void);
|
||||
void apply_mario_platform_displacement(void);
|
||||
void clear_mario_platform(void);
|
||||
|
||||
#endif // PLATFORM_DISPLACEMENT_H
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "macros.h"
|
||||
#include "PR/ultratypes.h"
|
||||
|
||||
|
||||
// Certain functions are marked as having return values, but do not
|
||||
// actually return a value. This causes undefined behavior, which we'd rather
|
||||
// avoid on modern GCC. This only impacts -O2 and can matter for both the function
|
||||
@@ -84,13 +85,27 @@ enum SpTaskState {
|
||||
#define ANIM_FLAG_6 (1 << 6) // 0x40
|
||||
#define ANIM_FLAG_7 (1 << 7) // 0x80
|
||||
|
||||
// Added by libsm64
|
||||
struct SurfaceObjectTransform
|
||||
{
|
||||
float aPosX, aPosY, aPosZ;
|
||||
float aVelX, aVelY, aVelZ;
|
||||
|
||||
s16 aFaceAnglePitch;
|
||||
s16 aFaceAngleYaw;
|
||||
s16 aFaceAngleRoll;
|
||||
|
||||
s16 aAngleVelPitch;
|
||||
s16 aAngleVelYaw;
|
||||
s16 aAngleVelRoll;
|
||||
};
|
||||
|
||||
struct Animation {
|
||||
/*0x00*/ s16 flags;
|
||||
/*0x02*/ s16 animYTransDivisor;
|
||||
/*0x04*/ s16 startFrame;
|
||||
/*0x06*/ s16 loopStart;
|
||||
/*0x08*/ s16 loopEnd;
|
||||
/*0x0A*/ s16 unusedBoneCount;
|
||||
/*0x08*/ s16 loopEnd; /*0x0A*/ s16 unusedBoneCount;
|
||||
/*0x0C*/ s16 *values;
|
||||
/*0x10*/ u16 *index;
|
||||
/*0x14*/ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
|
||||
@@ -199,7 +214,7 @@ struct Object
|
||||
/*0x208*/ f32 hitboxDownOffset;
|
||||
/*0x20C*/ const BehaviorScript *behavior;
|
||||
/*0x210*/ u32 unused2;
|
||||
/*0x214*/ struct Object *platform;
|
||||
/*0x214*/ struct SurfaceObjectTransform *platform; // libsm64: type change from Object*
|
||||
/*0x218*/ void *collisionData;
|
||||
/*0x21C*/ Mat4 transform;
|
||||
/*0x25C*/ void *respawnInfo;
|
||||
@@ -241,9 +256,10 @@ struct Surface
|
||||
f32 z;
|
||||
} normal;
|
||||
/*0x28*/ f32 originOffset;
|
||||
/*0x2C*/ struct Object *object;
|
||||
|
||||
u16 terrain;
|
||||
// /*0x2C*/ struct Object *object;
|
||||
|
||||
struct SurfaceObjectTransform *transform; // libsm64: added field
|
||||
u16 terrain; // libsm64: added field
|
||||
};
|
||||
|
||||
struct MarioBodyState
|
||||
@@ -346,7 +362,7 @@ struct MarioState
|
||||
/*0xC0*/ f32 quicksandDepth;
|
||||
/*0xC4*/ f32 unkC4;
|
||||
|
||||
u16 curTerrain;
|
||||
u16 curTerrain; // libsm64: added field
|
||||
};
|
||||
|
||||
#endif // TYPES_H
|
||||
|
||||
Reference in New Issue
Block a user