Skip to content

Commit

Permalink
Add external screen teardown functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ckosmic committed Oct 29, 2021
1 parent b483f8e commit 170aefe
Show file tree
Hide file tree
Showing 24 changed files with 927 additions and 77 deletions.
19 changes: 19 additions & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ struct GraphNodeObject_sub
/*0x0A 0x42*/ u16 animTimer;
/*0x0C 0x44*/ s32 animFrameAccelAssist;
/*0x10 0x48*/ s32 animAccel;
s16 prevAnimFrame;
s16 prevAnimID;
u32 prevAnimFrameTimestamp;
struct Animation *prevAnimPtr;
};

struct GraphNodeObject
Expand All @@ -128,11 +132,22 @@ struct GraphNodeObject
/*0x19*/ s8 unk19;
/*0x1A*/ Vec3s angle;
/*0x20*/ Vec3f pos;
Vec3s prevAngle;
Vec3f prevPos;
u32 prevTimestamp;
Vec3f prevShadowPos;
u32 prevShadowPosTimestamp;
/*0x2C*/ Vec3f scale;
Vec3f prevScale;
u32 prevScaleTimestamp;
/*0x38*/ struct GraphNodeObject_sub unk38;
/*0x4C*/ struct SpawnInfo *unk4C;
/*0x50*/ Mat4 *throwMatrix; // matrix ptr
Mat4 prevThrowMatrix;
u32 prevThrowMatrixTimestamp;
Mat4 *throwMatrixInterpolated;
/*0x54*/ Vec3f cameraToObject;
u32 skipInterpolationTimestamp;
};

struct ObjectNode
Expand Down Expand Up @@ -243,6 +258,10 @@ struct Surface
} normal;
/*0x28*/ f32 originOffset;
/*0x2C*/ struct Object *object;
Vec3s prevVertex1;
Vec3s prevVertex2;
Vec3s prevVertex3;
u32 modifiedTimestamp;
};

struct MarioBodyState
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions sm64ios/sm64ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.christiankosman.sm64ios;
Expand Down Expand Up @@ -1750,7 +1750,7 @@
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 13.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.christiankosman.sm64ios;
Expand Down
16 changes: 15 additions & 1 deletion src/engine/graph_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ struct GraphNodePerspective
/*0x1C*/ f32 fov; // horizontal field of view in degrees
/*0x20*/ s16 near; // near clipping plane
/*0x22*/ s16 far; // far clipping plane
f32 prevFov;
f32 prevTimestamp;
};

/** An entry in the master list. It is a linked list of display lists
Expand All @@ -118,7 +120,9 @@ struct GraphNodePerspective
struct DisplayListNode
{
Mtx *transform;
void *transformInterpolated;
void *displayList;
void *displayListInterpolated;
struct DisplayListNode *next;
};

Expand Down Expand Up @@ -185,7 +189,11 @@ struct GraphNodeCamera
} config;
/*0x1C*/ Vec3f pos;
/*0x28*/ Vec3f focus;
Vec3f prevPos;
Vec3f prevFocus;
u32 prevTimestamp;
/*0x34*/ Mat4 *matrixPtr; // pointer to look-at matrix of this camera as a Mat4
Mat4 *matrixPtrInterpolated;
/*0x38*/ s16 roll; // roll in look at matrix. Doesn't account for light direction unlike rollScreen.
/*0x3A*/ s16 rollScreen; // rolls screen while keeping the light direction consistent
};
Expand Down Expand Up @@ -226,7 +234,8 @@ struct GraphNodeRotation
/*0x00*/ struct GraphNode node;
/*0x14*/ void *displayList;
/*0x18*/ Vec3s rotation;
u8 pad1E[2];
Vec3s prevRotation;
u32 prevTimestamp;
};

/** GraphNode part that transforms itself and its children based on animation
Expand Down Expand Up @@ -323,6 +332,9 @@ struct GraphNodeBackground
/*0x00*/ struct FnGraphNode fnNode;
/*0x18*/ s32 unused;
/*0x1C*/ s32 background; // background ID, or rgba5551 color if fnNode.func is null
Vec3f prevCameraPos;
Vec3f prevCameraFocus;
u32 prevCameraTimestamp;
};

/** Renders the object that Mario is holding.
Expand All @@ -333,6 +345,8 @@ struct GraphNodeHeldObject
/*0x18*/ s32 playerIndex;
/*0x1C*/ struct Object *objNode;
/*0x20*/ Vec3s translation;
Vec3f prevShadowPos;
u32 prevShadowPosTimestamp;
};

/** A node that allows an object to specify a different culling radius than the
Expand Down
62 changes: 57 additions & 5 deletions src/engine/surface_collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "surface_collision.h"
#include "surface_load.h"
#include "math_util.h"
#include "game/game_init.h"

/**************************************************
* WALLS *
Expand Down Expand Up @@ -394,26 +395,44 @@ f32 find_floor_height_and_data(f32 xPos, f32 yPos, f32 zPos, struct FloorGeometr
return floorHeight;
}

u8 gInterpolatingSurfaces;

/**
* Iterate through the list of floors and find the first floor under a given point.
*/
static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32 x, s32 y, s32 z, f32 *pheight) {
register struct Surface *surf;
register s32 x1, z1, x2, z2, x3, z3;
register f32 x1, z1, x2, z2, x3, z3;
f32 nx, ny, nz;
f32 oo;
f32 height;
struct Surface *floor = NULL;
s32 interpolate;

// Iterate through the list of floors until there are no more floors.
while (surfaceNode != NULL) {
surf = surfaceNode->surface;
surfaceNode = surfaceNode->next;
interpolate = gInterpolatingSurfaces && surf->modifiedTimestamp == gGlobalTimer;

x1 = surf->vertex1[0];
z1 = surf->vertex1[2];
x2 = surf->vertex2[0];
z2 = surf->vertex2[2];
if (interpolate) {
f32 diff = (surf->prevVertex1[0] - x1) * (surf->prevVertex1[0] - x1);
diff += (surf->prevVertex1[1] - surf->vertex1[1]) * (surf->prevVertex1[1] - surf->vertex1[1]);
diff += (surf->prevVertex1[2] - z1) * (surf->prevVertex1[2] - z1);
//printf("%f\n", sqrtf(diff));
if (diff > 10000) {
interpolate = FALSE;
} else {
x1 = (surf->prevVertex1[0] + x1) / 2;
z1 = (surf->prevVertex1[2] + z1) / 2;
x2 = (surf->prevVertex2[0] + x2) / 2;
z2 = (surf->prevVertex2[2] + z2) / 2;
}
}

// Check that the point is within the triangle bounds.
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) {
Expand All @@ -423,6 +442,10 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
// To slightly save on computation time, set this later.
x3 = surf->vertex3[0];
z3 = surf->vertex3[2];
if (interpolate) {
x3 = (surf->prevVertex3[0] + x3) / 2;
z3 = (surf->prevVertex3[2] + z3) / 2;
}

if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) {
continue;
Expand All @@ -442,10 +465,30 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
continue;
}

nx = surf->normal.x;
ny = surf->normal.y;
nz = surf->normal.z;
oo = surf->originOffset;
if (interpolate) {
f32 y1, y2, y3;
f32 mag;
y1 = (surf->prevVertex1[1] + surf->vertex1[1]) / 2;
y2 = (surf->prevVertex2[1] + surf->vertex2[1]) / 2;
y3 = (surf->prevVertex3[1] + surf->vertex3[1]) / 2;
nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2);
ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2);
nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2);
mag = sqrtf(nx * nx + ny * ny + nz * nz);
if (mag < 0.0001) {
continue;
}
mag = (f32)(1.0 / mag);
nx *= mag;
ny *= mag;
nz *= mag;
oo = -(nx * x1 + ny * y1 + nz * z1);
} else {
nx = surf->normal.x;
ny = surf->normal.y;
nz = surf->normal.z;
oo = surf->originOffset;
}

// If a wall, ignore it. Likely a remnant, should never occur.
if (ny == 0.0f) {
Expand All @@ -460,6 +503,15 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
}

*pheight = height;
if (interpolate) {
static struct Surface s;
s.type = surf->type;
s.normal.x = nx;
s.normal.y = ny;
s.normal.z = nz;
s.originOffset = oo;
return &s;
}
floor = surf;
break;
}
Expand Down
7 changes: 7 additions & 0 deletions src/engine/surface_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "game/mario.h"
#include "game/object_list_processor.h"
#include "surface_load.h"
#include "game/game_init.h"
#include "math_util.h"

s32 unused8038BE90;

Expand Down Expand Up @@ -359,6 +361,11 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {

surface = alloc_surface();

vec3s_copy(surface->prevVertex1, surface->vertex1);
vec3s_copy(surface->prevVertex2, surface->vertex2);
vec3s_copy(surface->prevVertex3, surface->vertex3);
surface->modifiedTimestamp = gGlobalTimer;

surface->vertex1[0] = x1;
surface->vertex2[0] = x2;
surface->vertex3[0] = x3;
Expand Down
17 changes: 17 additions & 0 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ CameraTransition sModeTransitions[] = {
extern u8 sDanceCutsceneIndexTable[][4];
extern u8 sZoomOutAreaMasks[];

static void skip_camera_interpolation(void) {
gLakituState.skipCameraInterpolationTimestamp = gGlobalTimer;
}

/**
* Starts a camera shake triggered by an interaction
*/
Expand Down Expand Up @@ -5552,6 +5556,7 @@ s32 set_camera_mode_fixed(struct Camera *c, s16 x, s16 y, s16 z) {
c->mode = CAMERA_MODE_FIXED;
vec3f_set(c->pos, sFixedModeBasePosition[0], sMarioCamState->pos[1],
sFixedModeBasePosition[2]);
skip_camera_interpolation();
}
return basePosSet;
}
Expand Down Expand Up @@ -5714,6 +5719,7 @@ BAD_RETURN(s32) cam_rr_enter_building_side(struct Camera *c) {
if (c->mode != CAMERA_MODE_FIXED) {
sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT;
c->mode = CAMERA_MODE_FIXED;
skip_camera_interpolation();
}
}

Expand Down Expand Up @@ -5909,6 +5915,7 @@ BAD_RETURN(s32) cam_castle_enter_lobby(struct Camera *c) {
sStatusFlags &= ~CAM_FLAG_SMOOTH_MOVEMENT;
set_fixed_cam_axis_sa_lobby(c->mode);
c->mode = CAMERA_MODE_FIXED;
skip_camera_interpolation();
}
}

Expand Down Expand Up @@ -7279,6 +7286,7 @@ BAD_RETURN(s32) cutscene_unused_loop(UNUSED struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_mario_fall_start(struct Camera *c) {
vec3f_set(c->focus, -26.f, 0.f, -137.f);
vec3f_set(c->pos, 165.f, 4725.f, 324.f);
skip_camera_interpolation();
}

/**
Expand Down Expand Up @@ -7311,6 +7319,7 @@ BAD_RETURN(s32) cutscene_ending_mario_fall(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) {
vec3f_set(c->focus, 85.f, 826.f, 250.f);
vec3f_set(c->pos, -51.f, 988.f, -202.f);
skip_camera_interpolation();
player2_rotate_cam(c, -0x2000, 0x2000, -0x2000, 0x2000);
}

Expand All @@ -7320,6 +7329,7 @@ BAD_RETURN(s32) cutscene_ending_mario_land_closeup(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_reset_spline(UNUSED struct Camera *c) {
sCutsceneVars[9].point[0] = 0.f;
cutscene_reset_spline();
skip_camera_interpolation();
}

/**
Expand Down Expand Up @@ -7355,6 +7365,7 @@ BAD_RETURN(s32) cutscene_ending_peach_appear_closeup(struct Camera *c) {
vec3f_set(c->pos, 179.f, 2463.f, -1216.f);
c->pos[1] = gCutsceneFocus->oPosY + 35.f;
vec3f_set(c->focus, gCutsceneFocus->oPosX, gCutsceneFocus->oPosY + 125.f, gCutsceneFocus->oPosZ);
skip_camera_interpolation();
}

/**
Expand All @@ -7373,6 +7384,7 @@ BAD_RETURN(s32) cutscene_ending_peach_appears(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_peach_descends_start(UNUSED struct Camera *c) {
cutscene_reset_spline();
sCutsceneVars[2].point[1] = 150.f;
skip_camera_interpolation();
}

/**
Expand Down Expand Up @@ -7459,6 +7471,7 @@ BAD_RETURN(s32) cutscene_ending_peach_wakeup(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_dialog(struct Camera *c) {
vec3f_set(c->focus, 11.f, 983.f, -1273.f);
vec3f_set(c->pos, -473.f, 970.f, -1152.f);
skip_camera_interpolation();
player2_rotate_cam(c, -0x800, 0x2000, -0x2000, 0x2000);
}

Expand All @@ -7469,6 +7482,7 @@ BAD_RETURN(s32) cutscene_ending_kiss_closeup(struct Camera *c) {
set_fov_function(CAM_FOV_SET_29);
vec3f_set(c->focus, 350.f, 1034.f, -1216.f);
vec3f_set(c->pos, -149.f, 1021.f, -1216.f);
skip_camera_interpolation();
}

/**
Expand Down Expand Up @@ -7504,6 +7518,7 @@ BAD_RETURN(s32) cutscene_ending_kiss(struct Camera *c) {
BAD_RETURN(s32) cutscene_ending_look_at_sky(struct Camera *c) {
move_point_along_spline(c->focus, sEndingLookAtSkyFocus, &sCutsceneSplineSegment, &sCutsceneSplineSegmentProgress);
vec3f_set(c->pos, 699.f, 1680.f, -703.f);
skip_camera_interpolation();
}

/**
Expand Down Expand Up @@ -10340,6 +10355,7 @@ BAD_RETURN(s32) cutscene_door_start(struct Camera *c) {
BAD_RETURN(s32) cutscene_door_fix_cam(struct Camera *c) {
vec3f_copy(c->pos, sCutsceneVars[0].point);
vec3f_copy(c->focus, sCutsceneVars[1].point);
skip_camera_interpolation();
}

/**
Expand Down Expand Up @@ -10373,6 +10389,7 @@ BAD_RETURN(s32) cutscene_door_move_behind_mario(struct Camera *c) {
}

offset_rotated(c->pos, sMarioCamState->pos, camOffset, sCutsceneVars[0].angle);
skip_camera_interpolation();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ struct LakituState
/// Mario's action from the previous frame. Only used to determine if Mario just finished a dive.
/*0xB8*/ u32 lastFrameAction;
/*0xBC*/ s16 unused;

u32 skipCameraInterpolationTimestamp;
};

// bss order hack to not affect BSS order. if possible, remove me, but it will be hard to match otherwise
Expand Down
Loading

0 comments on commit 170aefe

Please sign in to comment.