From 0843c23fe9610942bf6246fb9d8e64244b154154 Mon Sep 17 00:00:00 2001 From: jaburns Date: Wed, 28 Oct 2020 23:00:11 -0600 Subject: [PATCH] Only update platforms on change --- src/decomp/engine/surface_collision.c | 65 --------------------------- src/decomp/game/mario_misc.c | 5 +-- src/decomp/global_state.h | 1 + src/libsm64.c | 32 ++++--------- src/load_surfaces.c | 2 + 5 files changed, 13 insertions(+), 92 deletions(-) diff --git a/src/decomp/engine/surface_collision.c b/src/decomp/engine/surface_collision.c index dca89ae..94d6fc1 100644 --- a/src/decomp/engine/surface_collision.c +++ b/src/decomp/engine/surface_collision.c @@ -1,5 +1,3 @@ -// CUSTOM/PATCH - #include "../shim.h" #include "surface_collision.h" #include "../include/surface_terrains.h" @@ -44,17 +42,6 @@ static struct Surface *find_ceil_from_list( s32 x, s32 y, s32 z, f32 *pheight) { continue; } -// // Determine if checking for the camera or not. -// if (gCheckingSurfaceCollisionsForCamera != 0) { -// if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) { -// continue; -// } -// } -// // Ignore camera only surfaces. -// else if (surf->type == SURFACE_CAMERA_BOUNDARY) { -// continue; -// } - { f32 nx = surf->normal.x; f32 ny = surf->normal.y; @@ -85,9 +72,6 @@ static struct Surface *find_ceil_from_list( s32 x, s32 y, s32 z, f32 *pheight) { } } } - - //! (Surface Cucking) Since only the first ceil is returned and not the lowest, - // lower ceilings can be "cucked" by higher ceilings. return ceil; } @@ -107,11 +91,9 @@ static struct Surface *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight) for( int i = 0; i < count; ++i ) { surf = loaded_surface_get_at_index(i); - // 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]; x2 = surf->vertex2[0]; @@ -133,17 +115,6 @@ static struct Surface *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight) continue; } -// // Determine if we are checking for the camera or not. -// if (gCheckingSurfaceCollisionsForCamera != 0) { -// if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) { -// continue; -// } -// } -// // If we are not checking for the camera, ignore camera only floors. -// else if (surf->type == SURFACE_CAMERA_BOUNDARY) { -// continue; -// } - nx = surf->normal.x; ny = surf->normal.y; nz = surf->normal.z; @@ -167,9 +138,6 @@ static struct Surface *find_floor_from_list( s32 x, s32 y, s32 z, f32 *pheight) floor = surf; } } - - //! (Surface Cucking) Since only the first floor is returned and not the highest, - // higher floors can be "cucked" by lower floors. return floor; } @@ -195,14 +163,12 @@ static s32 find_wall_collisions_from_list( struct WallCollisionData *data) { for( int i = 0; i < count; ++i ) { surf = loaded_surface_get_at_index(i); - // 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; } - // Exclude a large number of walls immediately to optimize. if (y < surf->lowerY || y > surf->upperY) { continue; @@ -272,33 +238,6 @@ static s32 find_wall_collisions_from_list( struct WallCollisionData *data) { } } - // Determine if checking for the camera or not. -// if (gCheckingSurfaceCollisionsForCamera) { -// if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) { -// continue; -// } -// } else { -// // Ignore camera only surfaces. -// if (surf->type == SURFACE_CAMERA_BOUNDARY) { -// continue; -// } - -// // If an object can pass through a vanish cap wall, pass through. -// if (surf->type == SURFACE_VANISH_CAP_WALLS) { -// // If an object can pass through a vanish cap wall, pass through. -// if (gCurrentObject != NULL -// && (gCurrentObject->activeFlags & ACTIVE_FLAG_MOVE_THROUGH_GRATE)) { -// continue; -// } - -// // If Mario has a vanish cap, pass through the vanish cap wall. -// if (gCurrentObject != NULL && gCurrentObject == gMarioObject -// && (gMarioState->flags & MARIO_VANISH_CAP)) { -// continue; -// } -// } -// } - //! (Wall Overlaps) Because this doesn't update the x and z local variables, // multiple walls can push mario more than is required. data->x += surf->normal.x * (radius - offset); @@ -317,10 +256,6 @@ static s32 find_wall_collisions_from_list( struct WallCollisionData *data) { return numCols; } - - - - s32 f32_find_wall_collision(f32 *xPtr, f32 *yPtr, f32 *zPtr, f32 offsetY, f32 radius) { struct WallCollisionData collision; diff --git a/src/decomp/game/mario_misc.c b/src/decomp/game/mario_misc.c index 7b35a43..aaf4bb0 100644 --- a/src/decomp/game/mario_misc.c +++ b/src/decomp/game/mario_misc.c @@ -466,7 +466,6 @@ Gfx *geo_switch_mario_hand(s32 callContext, struct GraphNode *node, UNUSED Mat4 * (such as in the mirror room) results in a faster and desynced punch / kick animation. */ Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED Mat4 *c) { - static s16 sMarioAttackAnimCounter = 0; struct GraphNodeGenerated *asGenerated = (struct GraphNodeGenerated *) node; struct GraphNodeScale *scaleNode = (struct GraphNodeScale *) node->next; struct MarioBodyState *bodyState = &gBodyStates[0]; @@ -474,9 +473,9 @@ Gfx *geo_mario_hand_foot_scaler(s32 callContext, struct GraphNode *node, UNUSED if (callContext == GEO_CONTEXT_RENDER) { scaleNode->scale = 1.0f; if (asGenerated->parameter == bodyState->punchState >> 6) { - if (sMarioAttackAnimCounter != gAreaUpdateCounter && (bodyState->punchState & 0x3F) > 0) { + if (g_state->msMarioAttackAnimCounter != gAreaUpdateCounter && (bodyState->punchState & 0x3F) > 0) { bodyState->punchState -= 1; - sMarioAttackAnimCounter = gAreaUpdateCounter; + g_state->msMarioAttackAnimCounter = gAreaUpdateCounter; } scaleNode->scale = gMarioAttackScaleAnimation[asGenerated->parameter * 6 + (bodyState->punchState & 0x3F)] diff --git a/src/decomp/global_state.h b/src/decomp/global_state.h index 15c2ed9..39e7531 100644 --- a/src/decomp/global_state.h +++ b/src/decomp/global_state.h @@ -21,6 +21,7 @@ struct GlobalState // mario_misc.c struct MarioBodyState mgBodyStates[2]; + s16 msMarioAttackAnimCounter; // rendering_graph_node.c u16 mgAreaUpdateCounter; diff --git a/src/libsm64.c b/src/libsm64.c index cc16daa..bbeadcb 100644 --- a/src/libsm64.c +++ b/src/libsm64.c @@ -76,28 +76,6 @@ static void free_area( struct Area *area ) free( area ); } -static void update_terrain_objects( void ) -{ - // TODO, this is way more expensive than it needs to be. - update_dynamic_surface_list(); -} - -static void update_non_terrain_objects( void ) -{ - bhv_mario_update(); -} - -static void update_objects( void ) -{ - update_mario_platform(); - - //clear_dynamic_surfaces(); - update_terrain_objects(); - apply_mario_platform_displacement(); - //detect_object_collisions(); - update_non_terrain_objects(); -} - SM64_LIB_FN void sm64_global_init( uint8_t *rom, uint8_t *outTexture, SM64DebugPrintFunctionPtr debugPrintFunction ) { if( s_init_global ) @@ -204,7 +182,9 @@ SM64_LIB_FN void sm64_mario_tick( uint32_t marioId, const struct SM64MarioInputs gController.stickY = 64.0f * inputs->stickY; gController.stickMag = sqrtf( gController.stickX*gController.stickX + gController.stickY*gController.stickY ); - update_objects(); + update_mario_platform(); + apply_mario_platform_displacement(); + bhv_mario_update(); gfx_adapter_bind_output_buffers( outBuffers ); @@ -238,15 +218,19 @@ SM64_LIB_FN void sm64_mario_delete( uint32_t marioId ) SM64_LIB_FN uint32_t sm64_surface_object_create( const struct SM64SurfaceObject *surfaceObject ) { - return surfaces_load_object( surfaceObject ); + uint32_t id = surfaces_load_object( surfaceObject ); + update_dynamic_surface_list(); + return id; } SM64_LIB_FN void sm64_surface_object_move( uint32_t objectId, const struct SM64ObjectTransform *transform ) { surface_object_update_transform( objectId, transform ); + update_dynamic_surface_list(); } SM64_LIB_FN void sm64_surface_object_delete( uint32_t objectId ) { surfaces_unload_object( objectId ); + update_dynamic_surface_list(); } \ No newline at end of file diff --git a/src/load_surfaces.c b/src/load_surfaces.c index ccdc69c..bbdb318 100644 --- a/src/load_surfaces.c +++ b/src/load_surfaces.c @@ -203,6 +203,8 @@ static void engine_surface_from_lib_surface( struct Surface *surface, const stru void update_dynamic_surface_list( void ) { + // TODO, this is way more expensive than it needs to be. + free( s_dynamic_surface_list ); s_dynamic_surface_count = 0; s_dynamic_surface_list = NULL;