Filter out surfaces with bad tris, use 32 bit ints for collision surfaces

This commit is contained in:
jaburns
2021-08-16 15:01:57 -06:00
parent 54f979df93
commit e108c03608
4 changed files with 45 additions and 27 deletions
+19 -10
View File
@@ -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 ) {
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
if( surf->normal.y >= -0.01f ) continue;
x1 = surf->vertex1[0];
z1 = surf->vertex1[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 ) {
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
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 ) {
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
if( surf->normal.y < -0.01f || surf->normal.y > 0.01f ) continue;
if( surf->normal.x < -0.707f || surf->normal.x > 0.707f ) {
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 numCollisions = 0;
s16 x = colData->x;
s16 z = colData->z;
colData->numWalls = 0;
if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
return numCollisions;
}
if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
return numCollisions;
}
// libsm64: Don't care about level boundaries with 32-bit ints for vertex positions
// s16 x = colData->x;
// s16 z = colData->z;
// if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
// return numCollisions;
// }
// if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
// return numCollisions;
// }
numCollisions += find_wall_collisions_from_list(colData);
return numCollisions;
+1 -1
View File
@@ -12,7 +12,7 @@ static s16 sMovingSandSpeeds[] = { 12, 8, 4, 0 };
struct Surface gWaterSurfacePseudoFloor = {
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
View File
@@ -241,23 +241,24 @@ struct Waypoint
struct Surface
{
/*0x00*/ s16 type;
/*0x02*/ s16 force;
/*0x04*/ s8 flags;
/*0x05*/ s8 room;
/*0x06*/ s16 lowerY;
/*0x08*/ s16 upperY;
/*0x0A*/ Vec3s vertex1;
/*0x10*/ Vec3s vertex2;
/*0x16*/ Vec3s vertex3;
/*0x1C*/ struct {
s16 type;
s16 force;
s8 flags;
s8 room;
s32 lowerY; // libsm64: 32 bit
s32 upperY; // libsm64: 32 bit
Vec3i vertex1; // libsm64: 32 bit
Vec3i vertex2; // libsm64: 32 bit
Vec3i vertex3; // libsm64: 32 bit
struct {
f32 x;
f32 y;
f32 z;
} normal;
/*0x28*/ f32 originOffset;
// /*0x2C*/ struct Object *object;
f32 originOffset;
//struct Object *object;
u8 isValid; // libsm64: added field
struct SurfaceObjectTransform *transform; // libsm64: added field
u16 terrain; // libsm64: added field
};
@@ -333,7 +334,7 @@ struct MarioState
/*0x6C*/ f32 ceilHeight;
/*0x70*/ f32 floorHeight;
/*0x74*/ s16 floorAngle;
/*0x76*/ s16 waterLevel;
/*0x76*/ s32 waterLevel; // libsm64: 32 bit (address offsets after this are wrong)
/*0x78*/ struct Object *interactObj;
/*0x7C*/ struct Object *heldObj;
/*0x80*/ struct Object *usedObj;
+10 -2
View File
@@ -156,8 +156,14 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru
maxY = y3;
}
if (mag < 0.0001)
DEBUG_PRINT("ERROR: normal magnitude is very close to zero");
if (mag < 0.0001) {
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);
nx *= mag;
@@ -198,6 +204,8 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru
} else {
surface->force = 0;
}
surface->isValid = 1;
}
uint32_t loaded_surface_iter_group_count( void )