Filter out surfaces with bad tris, use 32 bit ints for collision surfaces
This commit is contained in:
@@ -19,10 +19,12 @@ static struct Surface *find_ceil_from_list( s32 x, s32 y, s32 z, f32 *pheight) {
|
|||||||
for( int j = 0; j < surfCount; ++j ) {
|
for( int j = 0; j < surfCount; ++j ) {
|
||||||
surf = loaded_surface_iter_get_at_index( i, j );
|
surf = loaded_surface_iter_get_at_index( i, j );
|
||||||
|
|
||||||
|
// libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
|
||||||
|
if( !surf->isValid ) continue;
|
||||||
|
|
||||||
// Do the check normally done in add_surface_to_cell
|
// Do the check normally done in add_surface_to_cell
|
||||||
if( surf->normal.y >= -0.01f ) continue;
|
if( surf->normal.y >= -0.01f ) continue;
|
||||||
|
|
||||||
|
|
||||||
x1 = surf->vertex1[0];
|
x1 = surf->vertex1[0];
|
||||||
z1 = surf->vertex1[2];
|
z1 = surf->vertex1[2];
|
||||||
z2 = surf->vertex2[2];
|
z2 = surf->vertex2[2];
|
||||||
@@ -93,6 +95,9 @@ static struct Surface *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight)
|
|||||||
for( int j = 0; j < surfCount; ++j ) {
|
for( int j = 0; j < surfCount; ++j ) {
|
||||||
surf = loaded_surface_iter_get_at_index( i, j );
|
surf = loaded_surface_iter_get_at_index( i, j );
|
||||||
|
|
||||||
|
// libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
|
||||||
|
if( !surf->isValid ) continue;
|
||||||
|
|
||||||
// Do the check normally done in add_surface_to_cell
|
// Do the check normally done in add_surface_to_cell
|
||||||
if( surf->normal.y <= 0.01f ) continue;
|
if( surf->normal.y <= 0.01f ) continue;
|
||||||
|
|
||||||
@@ -166,8 +171,12 @@ static s32 find_wall_collisions_from_list( struct WallCollisionData *data) {
|
|||||||
for( int j = 0; j < surfCount; ++j ) {
|
for( int j = 0; j < surfCount; ++j ) {
|
||||||
surf = loaded_surface_iter_get_at_index( i, j );
|
surf = loaded_surface_iter_get_at_index( i, j );
|
||||||
|
|
||||||
|
// libsm64: Weed out surfaces whose triangles are actually line segs. TODO do this at surface load time
|
||||||
|
if( !surf->isValid ) continue;
|
||||||
|
|
||||||
// Do the check normally done in add_surface_to_cell
|
// Do the check normally done in add_surface_to_cell
|
||||||
if( surf->normal.y < -0.01f || surf->normal.y > 0.01f ) continue;
|
if( surf->normal.y < -0.01f || surf->normal.y > 0.01f ) continue;
|
||||||
|
|
||||||
if( surf->normal.x < -0.707f || surf->normal.x > 0.707f ) {
|
if( surf->normal.x < -0.707f || surf->normal.x > 0.707f ) {
|
||||||
surf->flags |= SURFACE_FLAG_X_PROJECTION;
|
surf->flags |= SURFACE_FLAG_X_PROJECTION;
|
||||||
}
|
}
|
||||||
@@ -285,17 +294,17 @@ s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 ra
|
|||||||
s32 find_wall_collisions(struct WallCollisionData *colData)
|
s32 find_wall_collisions(struct WallCollisionData *colData)
|
||||||
{
|
{
|
||||||
s32 numCollisions = 0;
|
s32 numCollisions = 0;
|
||||||
s16 x = colData->x;
|
|
||||||
s16 z = colData->z;
|
|
||||||
|
|
||||||
colData->numWalls = 0;
|
colData->numWalls = 0;
|
||||||
|
|
||||||
if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
|
// libsm64: Don't care about level boundaries with 32-bit ints for vertex positions
|
||||||
return numCollisions;
|
// s16 x = colData->x;
|
||||||
}
|
// s16 z = colData->z;
|
||||||
if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
|
// if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
|
||||||
return numCollisions;
|
// return numCollisions;
|
||||||
}
|
// }
|
||||||
|
// if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
|
||||||
|
// return numCollisions;
|
||||||
|
// }
|
||||||
|
|
||||||
numCollisions += find_wall_collisions_from_list(colData);
|
numCollisions += find_wall_collisions_from_list(colData);
|
||||||
return numCollisions;
|
return numCollisions;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ static s16 sMovingSandSpeeds[] = { 12, 8, 4, 0 };
|
|||||||
|
|
||||||
struct Surface gWaterSurfacePseudoFloor = {
|
struct Surface gWaterSurfacePseudoFloor = {
|
||||||
SURFACE_VERY_SLIPPERY, 0, 0, 0, 0, 0, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
|
SURFACE_VERY_SLIPPERY, 0, 0, 0, 0, 0, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
|
||||||
{ 0.0f, 1.0f, 0.0f }, 0.0f, NULL,
|
{ 0.0f, 1.0f, 0.0f }, 0.0f, 0, NULL, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+14
-13
@@ -241,23 +241,24 @@ struct Waypoint
|
|||||||
|
|
||||||
struct Surface
|
struct Surface
|
||||||
{
|
{
|
||||||
/*0x00*/ s16 type;
|
s16 type;
|
||||||
/*0x02*/ s16 force;
|
s16 force;
|
||||||
/*0x04*/ s8 flags;
|
s8 flags;
|
||||||
/*0x05*/ s8 room;
|
s8 room;
|
||||||
/*0x06*/ s16 lowerY;
|
s32 lowerY; // libsm64: 32 bit
|
||||||
/*0x08*/ s16 upperY;
|
s32 upperY; // libsm64: 32 bit
|
||||||
/*0x0A*/ Vec3s vertex1;
|
Vec3i vertex1; // libsm64: 32 bit
|
||||||
/*0x10*/ Vec3s vertex2;
|
Vec3i vertex2; // libsm64: 32 bit
|
||||||
/*0x16*/ Vec3s vertex3;
|
Vec3i vertex3; // libsm64: 32 bit
|
||||||
/*0x1C*/ struct {
|
struct {
|
||||||
f32 x;
|
f32 x;
|
||||||
f32 y;
|
f32 y;
|
||||||
f32 z;
|
f32 z;
|
||||||
} normal;
|
} normal;
|
||||||
/*0x28*/ f32 originOffset;
|
f32 originOffset;
|
||||||
// /*0x2C*/ struct Object *object;
|
//struct Object *object;
|
||||||
|
|
||||||
|
u8 isValid; // libsm64: added field
|
||||||
struct SurfaceObjectTransform *transform; // libsm64: added field
|
struct SurfaceObjectTransform *transform; // libsm64: added field
|
||||||
u16 terrain; // libsm64: added field
|
u16 terrain; // libsm64: added field
|
||||||
};
|
};
|
||||||
@@ -333,7 +334,7 @@ struct MarioState
|
|||||||
/*0x6C*/ f32 ceilHeight;
|
/*0x6C*/ f32 ceilHeight;
|
||||||
/*0x70*/ f32 floorHeight;
|
/*0x70*/ f32 floorHeight;
|
||||||
/*0x74*/ s16 floorAngle;
|
/*0x74*/ s16 floorAngle;
|
||||||
/*0x76*/ s16 waterLevel;
|
/*0x76*/ s32 waterLevel; // libsm64: 32 bit (address offsets after this are wrong)
|
||||||
/*0x78*/ struct Object *interactObj;
|
/*0x78*/ struct Object *interactObj;
|
||||||
/*0x7C*/ struct Object *heldObj;
|
/*0x7C*/ struct Object *heldObj;
|
||||||
/*0x80*/ struct Object *usedObj;
|
/*0x80*/ struct Object *usedObj;
|
||||||
|
|||||||
+10
-2
@@ -156,8 +156,14 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru
|
|||||||
maxY = y3;
|
maxY = y3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mag < 0.0001)
|
if (mag < 0.0001) {
|
||||||
DEBUG_PRINT("ERROR: normal magnitude is very close to zero");
|
DEBUG_PRINT("ERROR: normal magnitude is very close to zero:");
|
||||||
|
DEBUG_PRINT("v1 %i %i %i", x1, y1, z1 );
|
||||||
|
DEBUG_PRINT("v2 %i %i %i", x2, y2, z2 );
|
||||||
|
DEBUG_PRINT("v3 %i %i %i", x3, y3, z3 );
|
||||||
|
surface->isValid = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mag = (f32)(1.0 / mag);
|
mag = (f32)(1.0 / mag);
|
||||||
nx *= mag;
|
nx *= mag;
|
||||||
@@ -198,6 +204,8 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru
|
|||||||
} else {
|
} else {
|
||||||
surface->force = 0;
|
surface->force = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
surface->isValid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t loaded_surface_iter_group_count( void )
|
uint32_t loaded_surface_iter_group_count( void )
|
||||||
|
|||||||
Reference in New Issue
Block a user