Reformat to something more readable for me :3
This commit is contained in:
+95
-79
@@ -27,7 +27,7 @@ static struct LoadedSurfaceObject *s_surface_object_list = NULL;
|
||||
|
||||
#define CONVERT_ANGLE( x ) ((s16)( -(x) / 180.0f * 32768.0f ))
|
||||
|
||||
static void init_transform( struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in )
|
||||
static void init_transform(struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in)
|
||||
{
|
||||
out->aVelX = 0.0f;
|
||||
out->aVelY = 0.0f;
|
||||
@@ -37,14 +37,14 @@ static void init_transform( struct SM64SurfaceObjectTransform *out, const struct
|
||||
out->aPosZ = in->position[2];
|
||||
|
||||
out->aAngleVelPitch = 0.0f;
|
||||
out->aAngleVelYaw = 0.0f;
|
||||
out->aAngleVelRoll = 0.0f;
|
||||
out->aAngleVelYaw = 0.0f;
|
||||
out->aAngleVelRoll = 0.0f;
|
||||
out->aFaceAnglePitch = CONVERT_ANGLE(in->eulerRotation[0]);
|
||||
out->aFaceAngleYaw = CONVERT_ANGLE(in->eulerRotation[1]);
|
||||
out->aFaceAngleRoll = CONVERT_ANGLE(in->eulerRotation[2]);
|
||||
out->aFaceAngleYaw = CONVERT_ANGLE(in->eulerRotation[1]);
|
||||
out->aFaceAngleRoll = CONVERT_ANGLE(in->eulerRotation[2]);
|
||||
}
|
||||
|
||||
static void update_transform( struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in )
|
||||
static void update_transform(struct SM64SurfaceObjectTransform *out, const struct SM64ObjectTransform *in)
|
||||
{
|
||||
out->aVelX = in->position[0] - out->aPosX;
|
||||
out->aVelY = in->position[1] - out->aPosY;
|
||||
@@ -58,21 +58,23 @@ static void update_transform( struct SM64SurfaceObjectTransform *out, const stru
|
||||
s16 inZ = CONVERT_ANGLE(in->eulerRotation[2]);
|
||||
|
||||
out->aAngleVelPitch = inX - out->aFaceAnglePitch;
|
||||
out->aAngleVelYaw = inY - out->aFaceAngleYaw;
|
||||
out->aAngleVelRoll = inZ - out->aFaceAngleRoll;
|
||||
out->aAngleVelYaw = inY - out->aFaceAngleYaw;
|
||||
out->aAngleVelRoll = inZ - out->aFaceAngleRoll;
|
||||
out->aFaceAnglePitch = inX;
|
||||
out->aFaceAngleYaw = inY;
|
||||
out->aFaceAngleRoll = inZ;
|
||||
out->aFaceAngleYaw = inY;
|
||||
out->aFaceAngleRoll = inZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(s16 surfaceType)
|
||||
{
|
||||
s32 hasForce = FALSE;
|
||||
|
||||
switch (surfaceType) {
|
||||
switch (surfaceType)
|
||||
{
|
||||
case SURFACE_0004: // Unused
|
||||
case SURFACE_FLOWING_WATER:
|
||||
case SURFACE_DEEP_MOVING_QUICKSAND:
|
||||
@@ -89,7 +91,7 @@ static s32 surface_has_force(s16 surfaceType) {
|
||||
return hasForce;
|
||||
}
|
||||
|
||||
static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *surface, const struct SM64Surface *libSurf, struct SM64SurfaceObjectTransform *transform )
|
||||
static void engine_surface_from_lib_surface(struct SM64SurfaceCollisionData *surface, const struct SM64Surface *libSurf, struct SM64SurfaceObjectTransform *transform)
|
||||
{
|
||||
int16_t type = libSurf->type;
|
||||
int16_t force = libSurf->force;
|
||||
@@ -107,24 +109,30 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
|
||||
f32 nx, ny, nz;
|
||||
f32 mag;
|
||||
|
||||
if( transform != NULL )
|
||||
if (transform != NULL)
|
||||
{
|
||||
Mat4 m;
|
||||
Vec3s rotation = { transform->aFaceAnglePitch, transform->aFaceAngleYaw, transform->aFaceAngleRoll };
|
||||
Vec3f position = { transform->aPosX, transform->aPosY, transform->aPosZ };
|
||||
Vec3s rotation = {transform->aFaceAnglePitch, transform->aFaceAngleYaw, transform->aFaceAngleRoll};
|
||||
Vec3f position = {transform->aPosX, transform->aPosY, transform->aPosZ};
|
||||
mtxf_rotate_zxy_and_translate(m, position, rotation);
|
||||
|
||||
Vec3f v1 = { x1, y1, z1 };
|
||||
Vec3f v2 = { x2, y2, z2 };
|
||||
Vec3f v3 = { x3, y3, z3 };
|
||||
Vec3f v1 = {x1, y1, z1};
|
||||
Vec3f v2 = {x2, y2, z2};
|
||||
Vec3f v3 = {x3, y3, z3};
|
||||
|
||||
mtxf_mul_vec3f( m, v1 );
|
||||
mtxf_mul_vec3f( m, v2 );
|
||||
mtxf_mul_vec3f( m, v3 );
|
||||
mtxf_mul_vec3f(m, v1);
|
||||
mtxf_mul_vec3f(m, v2);
|
||||
mtxf_mul_vec3f(m, v3);
|
||||
|
||||
x1 = v1[0]; y1 = v1[1]; z1 = v1[2];
|
||||
x2 = v2[0]; y2 = v2[1]; z2 = v2[2];
|
||||
x3 = v3[0]; y3 = v3[1]; z3 = v3[2];
|
||||
x1 = v1[0];
|
||||
y1 = v1[1];
|
||||
z1 = v1[2];
|
||||
x2 = v2[0];
|
||||
y2 = v2[1];
|
||||
z2 = v2[2];
|
||||
x3 = v3[0];
|
||||
y3 = v3[1];
|
||||
z3 = v3[2];
|
||||
|
||||
surface->transform = transform;
|
||||
}
|
||||
@@ -141,26 +149,31 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
|
||||
|
||||
// Could have used min_3 and max_3 for this...
|
||||
minY = y1;
|
||||
if (y2 < minY) {
|
||||
if (y2 < minY)
|
||||
{
|
||||
minY = y2;
|
||||
}
|
||||
if (y3 < minY) {
|
||||
if (y3 < minY)
|
||||
{
|
||||
minY = y3;
|
||||
}
|
||||
|
||||
maxY = y1;
|
||||
if (y2 > maxY) {
|
||||
if (y2 > maxY)
|
||||
{
|
||||
maxY = y2;
|
||||
}
|
||||
if (y3 > maxY) {
|
||||
if (y3 > maxY)
|
||||
{
|
||||
maxY = y3;
|
||||
}
|
||||
|
||||
if (mag < 0.0001) {
|
||||
if (mag < 0.0001)
|
||||
{
|
||||
DEBUG_PRINT("ERROR: normal magnitude is very close to zero:");
|
||||
DEBUG_PRINT("v1 %f %f %f", x1, y1, z1 );
|
||||
DEBUG_PRINT("v2 %f %f %f", x2, y2, z2 );
|
||||
DEBUG_PRINT("v3 %f %f %f", x3, y3, z3 );
|
||||
DEBUG_PRINT("v1 %f %f %f", x1, y1, z1);
|
||||
DEBUG_PRINT("v2 %f %f %f", x2, y2, z2);
|
||||
DEBUG_PRINT("v3 %f %f %f", x3, y3, z3);
|
||||
surface->isValid = 0;
|
||||
return;
|
||||
}
|
||||
@@ -196,59 +209,62 @@ static void engine_surface_from_lib_surface( struct SM64SurfaceCollisionData *su
|
||||
|
||||
surface->room = 0;
|
||||
surface->type = type;
|
||||
surface->flags = (s8) flags;
|
||||
surface->flags = (s8)flags;
|
||||
surface->terrain = libSurf->terrain;
|
||||
|
||||
if (hasForce) {
|
||||
if (hasForce)
|
||||
{
|
||||
surface->force = force;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
surface->force = 0;
|
||||
}
|
||||
|
||||
surface->isValid = 1;
|
||||
}
|
||||
|
||||
uint32_t loaded_surface_iter_group_count( void )
|
||||
uint32_t loaded_surface_iter_group_count(void)
|
||||
{
|
||||
return 1 + s_surface_object_count;
|
||||
}
|
||||
|
||||
uint32_t loaded_surface_iter_group_size( uint32_t groupIndex )
|
||||
uint32_t loaded_surface_iter_group_size(uint32_t groupIndex)
|
||||
{
|
||||
if( groupIndex == 0 )
|
||||
if (groupIndex == 0)
|
||||
return s_static_surface_count;
|
||||
|
||||
return s_surface_object_list[ groupIndex - 1 ].surfaceCount;
|
||||
return s_surface_object_list[groupIndex - 1].surfaceCount;
|
||||
}
|
||||
|
||||
struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index( uint32_t groupIndex, uint32_t surfaceIndex )
|
||||
struct SM64SurfaceCollisionData *loaded_surface_iter_get_at_index(uint32_t groupIndex, uint32_t surfaceIndex)
|
||||
{
|
||||
if( groupIndex == 0 )
|
||||
return &s_static_surface_list[ surfaceIndex ];
|
||||
if (groupIndex == 0)
|
||||
return &s_static_surface_list[surfaceIndex];
|
||||
|
||||
return &s_surface_object_list[ groupIndex - 1 ].engineSurfaces[ surfaceIndex ];
|
||||
return &s_surface_object_list[groupIndex - 1].engineSurfaces[surfaceIndex];
|
||||
}
|
||||
|
||||
void surfaces_load_static( const struct SM64Surface *surfaceArray, uint32_t numSurfaces )
|
||||
void surfaces_load_static(const struct SM64Surface *surfaceArray, uint32_t numSurfaces)
|
||||
{
|
||||
if( s_static_surface_list != NULL )
|
||||
free( s_static_surface_list );
|
||||
if (s_static_surface_list != NULL)
|
||||
free(s_static_surface_list);
|
||||
|
||||
s_static_surface_count = numSurfaces;
|
||||
s_static_surface_list = malloc( sizeof( struct SM64SurfaceCollisionData ) * numSurfaces );
|
||||
s_static_surface_list = malloc(sizeof(struct SM64SurfaceCollisionData) * numSurfaces);
|
||||
|
||||
for( int i = 0; i < numSurfaces; ++i )
|
||||
engine_surface_from_lib_surface( &s_static_surface_list[i], &surfaceArray[i], NULL );
|
||||
for (int i = 0; i < numSurfaces; ++i)
|
||||
engine_surface_from_lib_surface(&s_static_surface_list[i], &surfaceArray[i], NULL);
|
||||
}
|
||||
|
||||
uint32_t surfaces_load_object( const struct SM64SurfaceObject *surfaceObject )
|
||||
uint32_t surfaces_load_object(const struct SM64SurfaceObject *surfaceObject)
|
||||
{
|
||||
bool pickedOldIndex = false;
|
||||
uint32_t idx = s_surface_object_count;
|
||||
|
||||
for( int i = 0; i < s_surface_object_count; ++i )
|
||||
for (int i = 0; i < s_surface_object_count; ++i)
|
||||
{
|
||||
if( s_surface_object_list[i].surfaceCount == 0 )
|
||||
if (s_surface_object_list[i].surfaceCount == 0)
|
||||
{
|
||||
pickedOldIndex = true;
|
||||
idx = i;
|
||||
@@ -256,41 +272,41 @@ uint32_t surfaces_load_object( const struct SM64SurfaceObject *surfaceObject )
|
||||
}
|
||||
}
|
||||
|
||||
if( !pickedOldIndex )
|
||||
if (!pickedOldIndex)
|
||||
{
|
||||
idx = s_surface_object_count;
|
||||
s_surface_object_count++;
|
||||
s_surface_object_list = realloc( s_surface_object_list, s_surface_object_count * sizeof( struct LoadedSurfaceObject ));
|
||||
s_surface_object_list = realloc(s_surface_object_list, s_surface_object_count * sizeof(struct LoadedSurfaceObject));
|
||||
}
|
||||
|
||||
struct LoadedSurfaceObject *obj = &s_surface_object_list[idx];
|
||||
|
||||
obj->surfaceCount = surfaceObject->surfaceCount;
|
||||
|
||||
obj->transform = malloc( sizeof( struct SM64SurfaceObjectTransform ));
|
||||
init_transform( obj->transform, &surfaceObject->transform );
|
||||
obj->transform = malloc(sizeof(struct SM64SurfaceObjectTransform));
|
||||
init_transform(obj->transform, &surfaceObject->transform);
|
||||
|
||||
obj->libSurfaces = malloc( obj->surfaceCount * sizeof( struct SM64Surface ));
|
||||
memcpy( obj->libSurfaces, surfaceObject->surfaces, obj->surfaceCount * sizeof( struct SM64Surface ));
|
||||
obj->libSurfaces = malloc(obj->surfaceCount * sizeof(struct SM64Surface));
|
||||
memcpy(obj->libSurfaces, surfaceObject->surfaces, obj->surfaceCount * sizeof(struct SM64Surface));
|
||||
|
||||
obj->engineSurfaces = malloc( obj->surfaceCount * sizeof( struct SM64SurfaceCollisionData ));
|
||||
for( int i = 0; i < obj->surfaceCount; ++i )
|
||||
engine_surface_from_lib_surface( &obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform );
|
||||
obj->engineSurfaces = malloc(obj->surfaceCount * sizeof(struct SM64SurfaceCollisionData));
|
||||
for (int i = 0; i < obj->surfaceCount; ++i)
|
||||
engine_surface_from_lib_surface(&obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
void surfaces_unload_object( uint32_t objId )
|
||||
void surfaces_unload_object(uint32_t objId)
|
||||
{
|
||||
if( objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0 )
|
||||
if (objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0)
|
||||
{
|
||||
DEBUG_PRINT("Tried to unload non-existant surface object with ID: %u", objId);
|
||||
return;
|
||||
}
|
||||
|
||||
free( s_surface_object_list[objId].transform );
|
||||
free( s_surface_object_list[objId].libSurfaces );
|
||||
free( s_surface_object_list[objId].engineSurfaces );
|
||||
free(s_surface_object_list[objId].transform);
|
||||
free(s_surface_object_list[objId].libSurfaces);
|
||||
free(s_surface_object_list[objId].engineSurfaces);
|
||||
|
||||
s_surface_object_list[objId].surfaceCount = 0;
|
||||
s_surface_object_list[objId].transform = NULL;
|
||||
@@ -298,40 +314,40 @@ void surfaces_unload_object( uint32_t objId )
|
||||
s_surface_object_list[objId].engineSurfaces = NULL;
|
||||
}
|
||||
|
||||
void surface_object_update_transform( uint32_t objId, const struct SM64ObjectTransform *newTransform )
|
||||
void surface_object_update_transform(uint32_t objId, const struct SM64ObjectTransform *newTransform)
|
||||
{
|
||||
if( objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0 )
|
||||
if (objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0)
|
||||
{
|
||||
DEBUG_PRINT("Tried to update non-existant surface object with ID: %u", objId);
|
||||
return;
|
||||
}
|
||||
|
||||
update_transform( s_surface_object_list[objId].transform, newTransform );
|
||||
for( int i = 0; i < s_surface_object_list[objId].surfaceCount; ++i )
|
||||
update_transform(s_surface_object_list[objId].transform, newTransform);
|
||||
for (int i = 0; i < s_surface_object_list[objId].surfaceCount; ++i)
|
||||
{
|
||||
struct LoadedSurfaceObject *obj = &s_surface_object_list[objId];
|
||||
engine_surface_from_lib_surface( &obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform );
|
||||
engine_surface_from_lib_surface(&obj->engineSurfaces[i], &obj->libSurfaces[i], obj->transform);
|
||||
}
|
||||
}
|
||||
|
||||
struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr( uint32_t objId )
|
||||
struct SM64SurfaceObjectTransform *surfaces_object_get_transform_ptr(uint32_t objId)
|
||||
{
|
||||
if( objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0 )
|
||||
if (objId >= s_surface_object_count || s_surface_object_list[objId].surfaceCount == 0)
|
||||
return NULL;
|
||||
|
||||
return s_surface_object_list[objId].transform;
|
||||
}
|
||||
|
||||
void surfaces_unload_all( void )
|
||||
void surfaces_unload_all(void)
|
||||
{
|
||||
free( s_static_surface_list );
|
||||
free(s_static_surface_list);
|
||||
s_static_surface_count = 0;
|
||||
s_static_surface_list = NULL;
|
||||
|
||||
for( int i = 0; i < s_surface_object_count; ++i )
|
||||
surfaces_unload_object( i );
|
||||
for (int i = 0; i < s_surface_object_count; ++i)
|
||||
surfaces_unload_object(i);
|
||||
|
||||
free( s_surface_object_list );
|
||||
free(s_surface_object_list);
|
||||
s_surface_object_count = 0;
|
||||
s_surface_object_list = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user