Refresh 1

This commit is contained in:
n64 committed 2019-09-01 15:50:50 -04:00
1 parent c6102eb802
commit 1ef98ec785
475 files changed
+100280 -97252

No files matched your search

+37 -20
View File
@@ -24,8 +24,9 @@ static void func_80383B70(u32 segptr) {
u16 RandomU16(void) {
u16 temp1, temp2;
if (gRandomSeed16 == 22026)
if (gRandomSeed16 == 22026) {
gRandomSeed16 = 0;
}
temp1 = (gRandomSeed16 & 0x00FF) << 8;
temp1 = temp1 ^ gRandomSeed16;
@@ -36,10 +37,11 @@ u16 RandomU16(void) {
temp2 = (temp1 >> 1) ^ 0xFF80;
if ((temp1 & 1) == 0) {
if (temp2 == 43605)
if (temp2 == 43605) {
gRandomSeed16 = 0;
else
} else {
gRandomSeed16 = temp2 ^ 0x1FF4;
}
} else {
gRandomSeed16 = temp2 ^ 0x8180;
}
@@ -53,10 +55,11 @@ f32 RandomFloat(void) {
}
s32 RandomSign(void) {
if (RandomU16() >= 0x7FFF)
if (RandomU16() >= 0x7FFF) {
return 1;
else
} else {
return -1;
}
}
void func_80383D68(struct Object *object) {
@@ -83,8 +86,9 @@ static u32 cur_object_stack_pop(void) {
static void Unknown80383E44(void) // ?
{
for (;;)
for (;;) {
;
}
}
static s32 beh_cmd_unhide(void) {
@@ -558,12 +562,15 @@ static s32 Behavior24(void) {
}
static s32 beh_cmd_begin(void) {
if (obj_has_behavior(bhvHauntedChair))
if (obj_has_behavior(bhvHauntedChair)) {
bhv_init_room();
if (obj_has_behavior(bhvMadPiano))
}
if (obj_has_behavior(bhvMadPiano)) {
bhv_init_room();
if (obj_has_behavior(bhvMessagePanel))
}
if (obj_has_behavior(bhvMessagePanel)) {
gCurrentObject->oCollisionDistance = 150.0f;
}
gBehCommand++;
return BEH_CONTINUE;
}
@@ -605,7 +612,7 @@ static s32 beh_cmd_interact_type(void) {
// unused
static s32 Behavior31(void) {
gCurrentObject->oUnk190 = gBehCommand[1];
gCurrentObject->oInteractionSubtype = gBehCommand[1];
gBehCommand += 2;
return BEH_CONTINUE;
@@ -662,8 +669,9 @@ static s32 beh_cmd_text_anim_rate(void) {
u8 objectOffset = (gBehCommand[0] >> 16) & 0xFF;
s16 arg1 = (gBehCommand[0] & 0xFFFF);
if ((gGlobalTimer % arg1) == 0)
if ((gGlobalTimer % arg1) == 0) {
cur_object_add_int(objectOffset, 1);
}
gBehCommand++;
return BEH_CONTINUE;
@@ -748,8 +756,9 @@ void cur_object_exec_behavior(void) {
distanceFromMario = 0.0f;
}
if (flagsLo & OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO)
if (flagsLo & OBJ_FLAG_COMPUTE_ANGLE_TO_MARIO) {
gCurrentObject->oAngleToMario = angle_to_object(gCurrentObject, gMarioObject);
}
if (gCurrentObject->oAction != gCurrentObject->oPrevAction) {
(void) (gCurrentObject->oTimer = 0, gCurrentObject->oSubAction = 0,
@@ -765,8 +774,9 @@ void cur_object_exec_behavior(void) {
gCurrentObject->behScript = gBehCommand;
if (gCurrentObject->oTimer < 0x3FFFFFFF)
if (gCurrentObject->oTimer < 0x3FFFFFFF) {
gCurrentObject->oTimer++;
}
if (gCurrentObject->oAction != gCurrentObject->oPrevAction) {
(void) (gCurrentObject->oTimer = 0, gCurrentObject->oSubAction = 0,
@@ -775,26 +785,33 @@ void cur_object_exec_behavior(void) {
flagsLo = (s16) gCurrentObject->oFlags;
if (flagsLo & OBJ_FLAG_0010)
if (flagsLo & OBJ_FLAG_0010) {
obj_set_facing_to_move_angles(gCurrentObject);
}
if (flagsLo & OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW)
if (flagsLo & OBJ_FLAG_SET_FACE_YAW_TO_MOVE_YAW) {
gCurrentObject->oFaceAngleYaw = gCurrentObject->oMoveAngleYaw;
}
if (flagsLo & OBJ_FLAG_MOVE_XZ_USING_FVEL)
if (flagsLo & OBJ_FLAG_MOVE_XZ_USING_FVEL) {
obj_move_xz_using_fvel_and_yaw();
}
if (flagsLo & OBJ_FLAG_MOVE_Y_WITH_TERMINAL_VEL)
if (flagsLo & OBJ_FLAG_MOVE_Y_WITH_TERMINAL_VEL) {
obj_move_y_with_terminal_vel();
}
if (flagsLo & OBJ_FLAG_TRANSFORM_RELATIVE_TO_PARENT)
if (flagsLo & OBJ_FLAG_TRANSFORM_RELATIVE_TO_PARENT) {
build_object_transform_relative_to_parent(gCurrentObject);
}
if (flagsLo & OBJ_FLAG_0800)
if (flagsLo & OBJ_FLAG_0800) {
func_802A2270(gCurrentObject);
}
if (flagsLo & OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE)
if (flagsLo & OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE) {
func_80383D68(gCurrentObject);
}
if (gCurrentObject->oRoom != -1) {
obj_enable_rendering_if_mario_in_room();
+98 -61
View File
@@ -18,8 +18,9 @@ Vec3s gVec3sZero = { 0, 0, 0 };
Vec3f gVec3fOne = { 1.0f, 1.0f, 1.0f };
UNUSED Vec3s gVec3sOne = { 1, 1, 1 };
/** Initialize a geo node with a given type. Sets all links such that there
* are no siblings, parent or children for this node.
/**
* Initialize a geo node with a given type. Sets all links such that there
* are no siblings, parent or children for this node.
*/
void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type) {
graphNode->type = type;
@@ -30,7 +31,8 @@ void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type) {
graphNode->children = NULL;
}
/** Allocated and returns a newly created root node
/**
* Allocated and returns a newly created root node
*/
struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct GraphNodeRoot *graphNode,
s16 areaIndex, s16 x, s16 y, s16 width, s16 height) {
@@ -54,7 +56,8 @@ struct GraphNodeRoot *init_graph_node_root(struct AllocOnlyPool *pool, struct Gr
return graphNode;
}
/** Allocates and returns a newly created otrhographic projection node
/**
* Allocates and returns a newly created otrhographic projection node
*/
struct GraphNodeOrthoProjection *
init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrthoProjection *graphNode,
@@ -71,7 +74,8 @@ init_graph_node_ortho_projection(struct AllocOnlyPool *pool, struct GraphNodeOrt
return graphNode;
}
/** Allocates and returns a newly created perspective node
/**
* Allocates and returns a newly created perspective node
*/
struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *pool,
struct GraphNodePerspective *graphNode,
@@ -98,7 +102,8 @@ struct GraphNodePerspective *init_graph_node_perspective(struct AllocOnlyPool *p
return graphNode;
}
/** Allocates and returns a newly created start node
/**
* Allocates and returns a newly created start node
*/
struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool,
struct GraphNodeStart *graphNode) {
@@ -113,7 +118,8 @@ struct GraphNodeStart *init_graph_node_start(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created master list node
/**
* Allocates and returns a newly created master list node
*/
struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *pool,
struct GraphNodeMasterList *graphNode, s16 on) {
@@ -132,7 +138,8 @@ struct GraphNodeMasterList *init_graph_node_master_list(struct AllocOnlyPool *po
return graphNode;
}
/** Allocates and returns a newly created render range node
/**
* Allocates and returns a newly created render range node
*/
struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool *pool,
struct GraphNodeLevelOfDetail *graphNode,
@@ -150,7 +157,8 @@ struct GraphNodeLevelOfDetail *init_graph_node_render_range(struct AllocOnlyPool
return graphNode;
}
/** Allocates and returns a newly created switch case node
/**
* Allocates and returns a newly created switch case node
*/
struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *pool,
struct GraphNodeSwitchCase *graphNode,
@@ -175,7 +183,8 @@ struct GraphNodeSwitchCase *init_graph_node_switch_case(struct AllocOnlyPool *po
return graphNode;
}
/** Allocates and returns a newly created camera node
/**
* Allocates and returns a newly created camera node
*/
struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool,
struct GraphNodeCamera *graphNode, f32 *fromPos,
@@ -201,7 +210,8 @@ struct GraphNodeCamera *init_graph_node_camera(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created translation rotation node
/**
* Allocates and returns a newly created translation rotation node
*/
struct GraphNodeTranslationRotation *
init_graph_node_translation_rotation(struct AllocOnlyPool *pool,
@@ -223,7 +233,8 @@ init_graph_node_translation_rotation(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created translation node
/**
* Allocates and returns a newly created translation node
*/
struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *pool,
struct GraphNodeTranslation *graphNode,
@@ -244,7 +255,8 @@ struct GraphNodeTranslation *init_graph_node_translation(struct AllocOnlyPool *p
return graphNode;
}
/** Allocates and returns a newly created rotation node
/**
* Allocates and returns a newly created rotation node
*/
struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool,
struct GraphNodeRotation *graphNode,
@@ -264,7 +276,8 @@ struct GraphNodeRotation *init_graph_node_rotation(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created scaling node
/**
* Allocates and returns a newly created scaling node
*/
struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool,
struct GraphNodeScale *graphNode, s32 drawingLayer,
@@ -283,7 +296,8 @@ struct GraphNodeScale *init_graph_node_scale(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created object node
/**
* Allocates and returns a newly created object node
*/
struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool,
struct GraphNodeObject *graphNode,
@@ -312,7 +326,8 @@ struct GraphNodeObject *init_graph_node_object(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created frustum culling radius node
/**
* Allocates and returns a newly created frustum culling radius node
*/
struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPool *pool,
struct GraphNodeCullingRadius *graphNode,
@@ -329,7 +344,8 @@ struct GraphNodeCullingRadius *init_graph_node_culling_radius(struct AllocOnlyPo
return graphNode;
}
/** Allocates and returns a newly created animated part node
/**
* Allocates and returns a newly created animated part node
*/
struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool *pool,
struct GraphNodeAnimatedPart *graphNode,
@@ -349,7 +365,8 @@ struct GraphNodeAnimatedPart *init_graph_node_animated_part(struct AllocOnlyPool
return graphNode;
}
/** Allocates and returns a newly created billboard node
/**
* Allocates and returns a newly created billboard node
*/
struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool,
struct GraphNodeBillboard *graphNode,
@@ -369,7 +386,8 @@ struct GraphNodeBillboard *init_graph_node_billboard(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created displaylist node
/**
* Allocates and returns a newly created displaylist node
*/
struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *pool,
struct GraphNodeDisplayList *graphNode,
@@ -387,7 +405,8 @@ struct GraphNodeDisplayList *init_graph_node_display_list(struct AllocOnlyPool *
return graphNode;
}
/** Allocates and returns a newly created shadow node
/**
* Allocates and returns a newly created shadow node
*/
struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool,
struct GraphNodeShadow *graphNode, s16 shadowScale,
@@ -406,7 +425,8 @@ struct GraphNodeShadow *init_graph_node_shadow(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created object parent node
/**
* Allocates and returns a newly created object parent node
*/
struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool *pool,
struct GraphNodeObjectParent *graphNode,
@@ -423,7 +443,8 @@ struct GraphNodeObjectParent *init_graph_node_object_parent(struct AllocOnlyPool
return graphNode;
}
/** Allocates and returns a newly created generated node
/**
* Allocates and returns a newly created generated node
*/
struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool,
struct GraphNodeGenerated *graphNode,
@@ -445,7 +466,8 @@ struct GraphNodeGenerated *init_graph_node_generated(struct AllocOnlyPool *pool,
return graphNode;
}
/** Allocates and returns a newly created background node
/**
* Allocates and returns a newly created background node
*/
struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *pool,
struct GraphNodeBackground *graphNode,
@@ -470,7 +492,8 @@ struct GraphNodeBackground *init_graph_node_background(struct AllocOnlyPool *poo
return graphNode;
}
/** Allocates and returns a newly created held object node
/**
* Allocates and returns a newly created held object node
*/
struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *pool,
struct GraphNodeHeldObject *graphNode,
@@ -495,7 +518,8 @@ struct GraphNodeHeldObject *init_graph_node_held_object(struct AllocOnlyPool *po
return graphNode;
}
/** Adds 'childNode' to the end of the list children from 'parent'
/**
* Adds 'childNode' to the end of the list children from 'parent'
*/
struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *childNode) {
struct GraphNode *parentFirstChild;
@@ -521,10 +545,11 @@ struct GraphNode *geo_add_child(struct GraphNode *parent, struct GraphNode *chil
return childNode;
}
/** Remove a node from the scene graph. It changes the links with its
* siblings and with its parent, it doesn't deallocate the memory
* since geo nodes are allocated in a pointer-bumping pool that
* gets thrown out when changing areas.
/**
* Remove a node from the scene graph. It changes the links with its
* siblings and with its parent, it doesn't deallocate the memory
* since geo nodes are allocated in a pointer-bumping pool that
* gets thrown out when changing areas.
*/
struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
struct GraphNode *parent;
@@ -550,10 +575,11 @@ struct GraphNode *geo_remove_child(struct GraphNode *graphNode) {
return parent;
}
/** Reorders the given node so it's the first child of its parent.
* This is called on the Mario object when he is spawned. That's why Mario's
* object is always drawn before any other objects. (Note that the geo order
* is independent from processing group order, where Mario is not first.)
/**
* Reorders the given node so it's the first child of its parent.
* This is called on the Mario object when he is spawned. That's why Mario's
* object is always drawn before any other objects. (Note that the geo order
* is independent from processing group order, where Mario is not first.)
*/
struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
struct GraphNode *lastSibling;
@@ -579,8 +605,9 @@ struct GraphNode *geo_make_first_child(struct GraphNode *newFirstChild) {
return parent;
}
/** Helper function for geo_call_global_function_nodes that recursively
* traverses the scene graph and calls the functions of global nodes.
/**
* Helper function for geo_call_global_function_nodes that recursively
* traverses the scene graph and calls the functions of global nodes.
*/
void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 callContext) {
struct GraphNode **globalPtr;
@@ -630,11 +657,12 @@ void geo_call_global_function_nodes_helper(struct GraphNode *graphNode, s32 call
} while ((curNode = curNode->next) != graphNode);
}
/** Call the update functions of geo nodes that are stored in global variables.
* These variables include gCurGraphNodeMasterList, gCurGraphNodeCamFrustum,
* gCurGraphNodeCamera and gCurGraphNodeObject.
* callContext is one of the GEO_CONTEXT_ defines.
* The graphNode argument should be of type GraphNodeRoot.
/**
* Call the update functions of geo nodes that are stored in global variables.
* These variables include gCurGraphNodeMasterList, gCurGraphNodeCamFrustum,
* gCurGraphNodeCamera and gCurGraphNodeObject.
* callContext is one of the GEO_CONTEXT_ defines.
* The graphNode argument should be of type GraphNodeRoot.
*/
void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext) {
if (graphNode->flags & GRAPH_RENDER_ACTIVE) {
@@ -648,7 +676,8 @@ void geo_call_global_function_nodes(struct GraphNode *graphNode, s32 callContext
}
}
/** When objects are cleared, this is called on all object nodes (loaded or unloaded).
/**
* When objects are cleared, this is called on all object nodes (loaded or unloaded).
*/
void geo_reset_object_node(struct GraphNodeObject *graphNode) {
init_graph_node_object(NULL, graphNode, 0, gVec3fZero, gVec3sZero, gVec3fOne);
@@ -657,7 +686,8 @@ void geo_reset_object_node(struct GraphNodeObject *graphNode) {
graphNode->node.flags &= ~GRAPH_RENDER_ACTIVE;
}
/** Initialize an object node using the given parameters
/**
* Initialize an object node using the given parameters
*/
void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f pos, Vec3s angle) {
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
@@ -675,7 +705,8 @@ void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f po
graphNode->node.flags &= ~GRAPH_RENDER_BILLBOARD;
}
/** Initialize and object node using the given SpawnInfo struct
/**
* Initialize and object node using the given SpawnInfo struct
*/
void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo *spawn) {
vec3f_set(graphNode->scale, 1.0f, 1.0f, 1.0f);
@@ -698,7 +729,8 @@ void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo
graphNode->node.flags &= ~GRAPH_RENDER_BILLBOARD;
}
/** Initialize the animation of an object node
/**
* Initialize the animation of an object node
*/
void geo_obj_init_animation(struct GraphNodeObject *graphNode, void *sp34) {
void **animSegmented = segmented_to_virtual(sp34);
@@ -712,7 +744,8 @@ void geo_obj_init_animation(struct GraphNodeObject *graphNode, void *sp34) {
}
}
/** Initialize the animation of an object node
/**
* Initialize the animation of an object node
*/
void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, void *sp34, u32 animAccel) {
void **animSegmented = segmented_to_virtual(sp34);
@@ -729,11 +762,12 @@ void geo_obj_init_animation_accel(struct GraphNodeObject *graphNode, void *sp34,
graphNode->unk38.animAccel = animAccel;
}
/** Retrieves an index into animation data based on the attribute pointer
* An attribute is an x-, y- or z-component of the translation / rotation for a part
* Each attribute is a pair of s16's, where the first s16 represents the maximum frame
* and the second s16 the actual index. This index can be used to index in the array
* with actual animation values.
/**
* Retrieves an index into animation data based on the attribute pointer
* An attribute is an x-, y- or z-component of the translation / rotation for a part
* Each attribute is a pair of s16's, where the first s16 represents the maximum frame
* and the second s16 the actual index. This index can be used to index in the array
* with actual animation values.
*/
s32 retrieve_animation_index(s32 frame, u16 **attributes) {
s32 result;
@@ -749,9 +783,10 @@ s32 retrieve_animation_index(s32 frame, u16 **attributes) {
return result;
}
/** Update the animation frame of an object. The animation flags determine
* whether it plays forwards or backwards, and whether it stops or loops at
* the end etc.
/**
* Update the animation frame of an object. The animation flags determine
* whether it plays forwards or backwards, and whether it stops or loops at
* the end etc.
*/
s16 geo_update_animation_frame(struct GraphNodeObject_sub *obj, s32 *accelAssist) {
s32 result;
@@ -804,12 +839,13 @@ s16 geo_update_animation_frame(struct GraphNodeObject_sub *obj, s32 *accelAssist
return GET_HIGH_S16_OF_32(result);
}
/** Unused function to retrieve an object's current animation translation
* Assumes that it has x, y and z data in animations, which isn't always the
* case since some animation types only have vertical or lateral translation.
* This might have been used for positioning the shadow under an object, which
* currently happens in-line in geo_process_shadow where it also accounts for
* animations without lateral translation.
/**
* Unused function to retrieve an object's current animation translation
* Assumes that it has x, y and z data in animations, which isn't always the
* case since some animation types only have vertical or lateral translation.
* This might have been used for positioning the shadow under an object, which
* currently happens in-line in geo_process_shadow where it also accounts for
* animations without lateral translation.
*/
void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f position) {
struct Animation *animation = obj->unk38.curAnim;
@@ -838,8 +874,9 @@ void geo_retreive_animation_translation(struct GraphNodeObject *obj, Vec3f posit
}
}
/** Unused function to find the root of the geo node tree, which should be a
* GraphNodeRoot. If it is not for some reason, null is returned.
/**
* Unused function to find the root of the geo node tree, which should be a
* GraphNodeRoot. If it is not for some reason, null is returned.
*/
struct GraphNodeRoot *geo_find_root(struct GraphNode *graphNode) {
struct GraphNodeRoot *resGraphNode = NULL;
+15 -11
View File
@@ -9,8 +9,9 @@
#include "game/area.h"
#include "geo_layout.h"
/** Takes a pointer to three shorts (supplied by a geo layout script) and
* copies it to the destination float vector.
/**
* Takes a pointer to three shorts (supplied by a geo layout script) and
* copies it to the destination float vector.
*/
s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
dst[0] = *src++;
@@ -19,9 +20,10 @@ s16 *read_vec3s_to_vec3f(Vec3f dst, s16 *src) {
return src;
}
/** Takes a pointer to three shorts (supplied by a geo layout script) and
* copies it to the destination vector. It's essentially a memcpy but consistent
* with the other two 'geo-script vector to internal vector' functions.
/**
* Takes a pointer to three shorts (supplied by a geo layout script) and
* copies it to the destination vector. It's essentially a memcpy but consistent
* with the other two 'geo-script vector to internal vector' functions.
*/
s16 *read_vec3s(Vec3s dst, s16 *src) {
dst[0] = *src++;
@@ -30,9 +32,10 @@ s16 *read_vec3s(Vec3s dst, s16 *src) {
return src;
}
/** Takes a pointer to three angles in degrees (supplied by a geo layout script)
* and converts it to a vector of three in-game angle units in [-32768, 32767]
* range.
/**
* Takes a pointer to three angles in degrees (supplied by a geo layout script)
* and converts it to a vector of three in-game angle units in [-32768, 32767]
* range.
*/
s16 *read_vec3s_angle(Vec3s dst, s16 *src) {
dst[0] = ((*src++) << 15) / 180;
@@ -41,9 +44,10 @@ s16 *read_vec3s_angle(Vec3s dst, s16 *src) {
return src;
}
/** Add the given graph node as a child to the current top of the gfx stack:
* 'gCurGraphNodeList'. This is called from geo_layout commands to add nodes
* to the scene graph.
/**
* Add the given graph node as a child to the current top of the gfx stack:
* 'gCurGraphNodeList'. This is called from geo_layout commands to add nodes
* to the scene graph.
*/
void register_scene_graph_node(struct GraphNode *graphNode) {
if (graphNode != NULL) {
+29 -15
View File
@@ -353,10 +353,11 @@ static void level_cmd_begin_area(void) {
screenArea->areaIndex = areaIndex;
gAreas[areaIndex].unk04 = (struct GraphNode *) screenArea;
if (node != NULL)
if (node != NULL) {
gAreas[areaIndex].camera = (struct LevelCamera *) node->config.levelCamera;
else
} else {
gAreas[areaIndex].camera = NULL;
}
}
sCurrentCmd = CMD_NEXT;
@@ -372,9 +373,10 @@ static void level_cmd_21(void) {
s16 val2 = CMD_GET(u16, 2) >> 12;
void *val3 = CMD_GET(void *, 4);
if (val1 < 256)
if (val1 < 256) {
gLoadedGraphNodes[val1] =
(struct GraphNode *) init_graph_node_display_list(sLevelPool, 0, val2, val3);
}
sCurrentCmd = CMD_NEXT;
}
@@ -383,8 +385,9 @@ static void level_cmd_22(void) {
s16 arg0 = CMD_GET(s16, 2);
void *arg1 = CMD_GET(void *, 4);
if (arg0 < 256)
if (arg0 < 256) {
gLoadedGraphNodes[arg0] = process_geo_layout(sLevelPool, arg1);
}
sCurrentCmd = CMD_NEXT;
}
@@ -401,11 +404,12 @@ static void level_cmd_23(void) {
arg2.i = CMD_GET(s32, 8); // store the raw word as a union s32. this allows is to reinterpret the
// contents as a f32 without the value being converted implicitly.
if (model < 256)
if (model < 256) {
// GraphNodeScale has a GraphNode at the top. This
// is being stored to the array, so cast the pointer.
gLoadedGraphNodes[model] =
(struct GraphNode *) init_graph_node_scale(sLevelPool, 0, arg0H, arg1, arg2.f);
}
sCurrentCmd = CMD_NEXT;
}
@@ -483,8 +487,9 @@ static void level_cmd_create_instant_warp(void) {
gAreas[sCurrAreaIndex].instantWarps =
alloc_only_pool_alloc(sLevelPool, 4 * sizeof(struct InstantWarp));
for (i = INSTANT_WARP_INDEX_START; i < INSTANT_WARP_INDEX_STOP; i++)
for (i = INSTANT_WARP_INDEX_START; i < INSTANT_WARP_INDEX_STOP; i++) {
gAreas[sCurrAreaIndex].instantWarps[i].id = 0;
}
}
warp = gAreas[sCurrAreaIndex].instantWarps + CMD_GET(u8, 2);
@@ -501,8 +506,9 @@ static void level_cmd_create_instant_warp(void) {
}
static void level_cmd_set_terrain_type(void) {
if (sCurrAreaIndex != -1)
if (sCurrAreaIndex != -1) {
gAreas[sCurrAreaIndex].terrainType |= CMD_GET(s16, 2);
}
sCurrentCmd = CMD_NEXT;
}
@@ -516,8 +522,9 @@ static void level_cmd_create_painting_warp_node(void) {
gAreas[sCurrAreaIndex].paintingWarpNodes =
alloc_only_pool_alloc(sLevelPool, 45 * sizeof(struct WarpNode));
for (i = 0; i < 45; i++)
for (i = 0; i < 45; i++) {
gAreas[sCurrAreaIndex].paintingWarpNodes[i].id = 0;
}
}
node = &gAreas[sCurrAreaIndex].paintingWarpNodes[CMD_GET(u8, 2)];
@@ -535,9 +542,10 @@ static void level_cmd_3A(void) {
struct UnusedArea28 *val4;
if (sCurrAreaIndex != -1) {
if ((val4 = gAreas[sCurrAreaIndex].unused28) == NULL)
if ((val4 = gAreas[sCurrAreaIndex].unused28) == NULL) {
val4 = gAreas[sCurrAreaIndex].unused28 =
alloc_only_pool_alloc(sLevelPool, sizeof(struct UnusedArea28));
}
val4->unk00 = CMD_GET(s16, 2);
val4->unk02 = CMD_GET(s16, 4);
@@ -582,20 +590,23 @@ static void level_cmd_set_gamma(void) {
}
static void level_cmd_set_terrain_data(void) {
if (sCurrAreaIndex != -1)
if (sCurrAreaIndex != -1) {
gAreas[sCurrAreaIndex].terrainData = segmented_to_virtual(CMD_GET(void *, 4));
}
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_set_rooms(void) {
if (sCurrAreaIndex != -1)
if (sCurrAreaIndex != -1) {
gAreas[sCurrAreaIndex].surfaceRooms = segmented_to_virtual(CMD_GET(void *, 4));
}
sCurrentCmd = CMD_NEXT;
}
static void level_cmd_39(void) {
if (sCurrAreaIndex != -1)
if (sCurrAreaIndex != -1) {
gAreas[sCurrAreaIndex].macroObjects = segmented_to_virtual(CMD_GET(void *, 4));
}
sCurrentCmd = CMD_NEXT;
}
@@ -634,8 +645,9 @@ static void level_cmd_2D(void) {
}
static void level_cmd_set_transition(void) {
if (gCurrentArea != NULL)
if (gCurrentArea != NULL) {
play_transition(CMD_GET(u8, 2), CMD_GET(u8, 3), CMD_GET(u8, 4), CMD_GET(u8, 5), CMD_GET(u8, 6));
}
sCurrentCmd = CMD_NEXT;
}
@@ -645,8 +657,9 @@ static void level_cmd_nop(void) {
static void level_cmd_30(void) {
if (sCurrAreaIndex != -1) {
if (CMD_GET(u8, 2) < 2)
if (CMD_GET(u8, 2) < 2) {
gAreas[sCurrAreaIndex].dialog[CMD_GET(u8, 2)] = CMD_GET(u8, 3);
}
}
sCurrentCmd = CMD_NEXT;
}
@@ -779,8 +792,9 @@ struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {
sScriptStatus = SCRIPT_RUNNING;
sCurrentCmd = cmd;
while (sScriptStatus == SCRIPT_RUNNING)
while (sScriptStatus == SCRIPT_RUNNING) {
LevelScriptJumpTable[sCurrentCmd->type]();
}
profiler_log_thread5_time(LEVEL_SCRIPT_EXECUTE);
init_render_image();
+149 -109
View File
@@ -97,8 +97,9 @@ void *vec3s_to_vec3f(Vec3f dest, Vec3s a) {
return &dest; //! warning: function returns address of local variable
}
/** Convert float vector a to a short vector 'dest' by rounding the components
* to the nearest integer.
/**
* Convert float vector a to a short vector 'dest' by rounding the components
* to the nearest integer.
*/
void *vec3f_to_vec3s(Vec3s dest, Vec3f a) {
// add/subtract 0.5 in order to round to the nearest s32 instead of truncating
@@ -108,9 +109,10 @@ void *vec3f_to_vec3s(Vec3s dest, Vec3f a) {
return &dest; //! warning: function returns address of local variable
}
/** Set 'dest' the normal vector of a triangle with vertices a, b and c.
* It is similar to vec3f_cross, but it calculates the vectors (c-b) and (b-a)
* at the same time.
/**
* Set 'dest' the normal vector of a triangle with vertices a, b and c.
* It is similar to vec3f_cross, but it calculates the vectors (c-b) and (b-a)
* at the same time.
*/
void *find_vector_perpendicular_to_plane(Vec3f dest, Vec3f a, Vec3f b, Vec3f c) {
dest[0] = (b[1] - a[1]) * (c[2] - b[2]) - (c[1] - b[1]) * (b[2] - a[2]);
@@ -146,11 +148,13 @@ void mtxf_copy(Mat4 dest, Mat4 src) {
register u32 *d = (u32 *) dest;
register u32 *s = (u32 *) src;
for (i = 0; i < 16; i++)
for (i = 0; i < 16; i++) {
*d++ = *s++;
}
}
/** Set mtx to the identity matrix
/**
* Set mtx to the identity matrix
*/
void mtxf_identity(Mat4 mtx) {
register s32 i;
@@ -158,15 +162,18 @@ void mtxf_identity(Mat4 mtx) {
// initialize everything except the first and last cells to 0
// (this need to be on one line to match on PAL)
for (dest = (f32 *) mtx + 1, i = 0; i < 14; dest++, i++)
for (dest = (f32 *) mtx + 1, i = 0; i < 14; dest++, i++) {
*dest = 0;
}
// initialize the diagonal cells to 1
for (dest = (f32 *) mtx, i = 0; i < 4; dest += 5, i++)
for (dest = (f32 *) mtx, i = 0; i < 4; dest += 5, i++) {
*dest = 1;
}
}
/** Set dest to a translation matrix of vector b
/**
* Set dest to a translation matrix of vector b
*/
void mtxf_translate(Mat4 dest, Vec3f b) {
mtxf_identity(dest);
@@ -175,10 +182,11 @@ void mtxf_translate(Mat4 dest, Vec3f b) {
dest[3][2] = b[2];
}
/** Set mtx to a look-at matrix for the camera. The resulting transformation
* transforms the world as if there exists a camera at position 'from' pointed
* at the position 'to'. The up-vector is assumed to be (0, 1, 0), but the 'roll'
* angle allows a bank rotation of the camera.
/**
* Set mtx to a look-at matrix for the camera. The resulting transformation
* transforms the world as if there exists a camera at position 'from' pointed
* at the position 'to'. The up-vector is assumed to be (0, 1, 0), but the 'roll'
* angle allows a bank rotation of the camera.
*/
void mtxf_lookat(Mat4 mtx, Vec3f from, Vec3f to, s16 roll) {
register f32 invLength;
@@ -322,10 +330,11 @@ void mtxf_rotate_xyz_and_translate(Mat4 dest, Vec3f b, Vec3s c) {
dest[3][3] = 1;
}
/** Set 'dest' to a transformation matrix that turns an object to face the camera.
* 'mtx' is the look-at matrix from the camera
* 'position' is the position of the object in the world
* 'angle' rotates the object while still facing the camera.
/**
* Set 'dest' to a transformation matrix that turns an object to face the camera.
* 'mtx' is the look-at matrix from the camera
* 'position' is the position of the object in the world
* 'angle' rotates the object while still facing the camera.
*/
void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) {
dest[0][0] = coss(angle);
@@ -352,11 +361,12 @@ void mtxf_billboard(Mat4 dest, Mat4 mtx, Vec3f position, s16 angle) {
dest[3][3] = 1;
}
/** Set 'dest' to a transformation matrix that aligns an object with the terrain
* based on the normal. Used for enemies.
* 'upDir' is the terrain normal
* 'yaw' is the angle which it should face
* 'pos' is the object's position in the world
/**
* Set 'dest' to a transformation matrix that aligns an object with the terrain
* based on the normal. Used for enemies.
* 'upDir' is the terrain normal
* 'yaw' is the angle which it should face
* 'pos' is the object's position in the world
*/
void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw) {
Vec3f lateralDir;
@@ -393,12 +403,13 @@ void mtxf_align_terrain_normal(Mat4 dest, Vec3f upDir, Vec3f pos, s16 yaw) {
dest[3][3] = 1.0f;
}
/** Set 'mtx' to a transformation matrix that aligns an object with the terrain
* based on 3 height samples in an equilateral triangle around the object.
* Used for Mario when crawling or sliding.
* 'yaw' is the angle which it should face
* 'pos' is the object's position in the world
* 'radius' is the distance from each triangle vertex to the center
/**
* Set 'mtx' to a transformation matrix that aligns an object with the terrain
* based on 3 height samples in an equilateral triangle around the object.
* Used for Mario when crawling or sliding.
* 'yaw' is the angle which it should face
* 'pos' is the object's position in the world
* 'radius' is the distance from each triangle vertex to the center
*/
void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
struct Surface *sp74;
@@ -423,14 +434,17 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
point1[1] = find_floor(point1[0], pos[1] + 150, point1[2], &sp74);
point2[1] = find_floor(point2[0], pos[1] + 150, point2[2], &sp74);
if (point0[1] - pos[1] < minY)
if (point0[1] - pos[1] < minY) {
point0[1] = pos[1];
}
if (point1[1] - pos[1] < minY)
if (point1[1] - pos[1] < minY) {
point1[1] = pos[1];
}
if (point2[1] - pos[1] < minY)
if (point2[1] - pos[1] < minY) {
point2[1] = pos[1];
}
avgY = (point0[1] + point1[1] + point2[1]) / 3;
@@ -463,12 +477,13 @@ void mtxf_align_terrain_triangle(Mat4 mtx, Vec3f pos, s16 yaw, f32 radius) {
mtx[3][3] = 1;
}
/** Sets matrix 'dest' to the matrix product b * a assuming they are both
* transformation matrices with a w-component of 1. Since the bottom row
* is assumed to equal [0, 0, 0, 1], it saves some multiplications and
* addition.
* The resulting matrix represents first applying transformation b and
* then a.
/**
* Sets matrix 'dest' to the matrix product b * a assuming they are both
* transformation matrices with a w-component of 1. Since the bottom row
* is assumed to equal [0, 0, 0, 1], it saves some multiplications and
* addition.
* The resulting matrix represents first applying transformation b and
* then a.
*/
void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
Mat4 temp;
@@ -514,7 +529,8 @@ void mtxf_mul(Mat4 dest, Mat4 a, Mat4 b) {
mtxf_copy(dest, temp);
}
/** Set matrix 'dest' to 'mtx' scaled by vector s
/**
* Set matrix 'dest' to 'mtx' scaled by vector s
*/
void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s) {
register s32 i;
@@ -527,9 +543,10 @@ void mtxf_scale_vec3f(Mat4 dest, Mat4 mtx, Vec3f s) {
}
}
/** Multiply a vector with a transformation matrix, which applies the transformation
* to the point. Note that the bottom row is assumed to be [0, 0, 0, 1], which is
* true for transformation matrices if the translation has a w component of 1.
/**
* Multiply a vector with a transformation matrix, which applies the transformation
* to the point. Note that the bottom row is assumed to be [0, 0, 0, 1], which is
* true for transformation matrices if the translation has a w component of 1.
*/
void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
register f32 x = b[0];
@@ -541,13 +558,14 @@ void mtxf_mul_vec3s(Mat4 mtx, Vec3s b) {
b[2] = x * mtx[0][2] + y * mtx[1][2] + z * mtx[2][2] + mtx[3][2];
}
/** Convert float matrix 'src' to fixed point matrix 'dest'.
* The float matrix may not contain entries larger than 65536 or the console
* crashes. The fixed point matrix has entries with a 16-bit integer part, so
* the floating point numbers are multipled by 2^16 before being cast to a s32
* integer. If this doesn't fit, the N64 and iQue consoles will throw an
* exception. On Wii and Wii U Virtual Console the value will simply be clamped
* and no crashes occur.
/**
* Convert float matrix 'src' to fixed point matrix 'dest'.
* The float matrix may not contain entries larger than 65536 or the console
* crashes. The fixed point matrix has entries with a 16-bit integer part, so
* the floating point numbers are multipled by 2^16 before being cast to a s32
* integer. If this doesn't fit, the N64 and iQue consoles will throw an
* exception. On Wii and Wii U Virtual Console the value will simply be clamped
* and no crashes occur.
*/
void mtxf_to_mtx(Mtx *dest, Mat4 src) {
s32 asFixedPoint;
@@ -563,7 +581,8 @@ void mtxf_to_mtx(Mtx *dest, Mat4 src) {
}
}
/** Set 'mtx' to a transformation matrix that rotates around the z axis.
/**
* Set 'mtx' to a transformation matrix that rotates around the z axis.
*/
void mtxf_rotate_xy(Mtx *mtx, s16 angle) {
Mat4 temp;
@@ -576,12 +595,13 @@ void mtxf_rotate_xy(Mtx *mtx, s16 angle) {
mtxf_to_mtx(mtx, temp);
}
/** Extract a position given an object's transformation matrix and a camera matrix.
* This is used for determining the world position of the held object: since objMtx
* inherits the transformation from both the camera and Mario, it calculates this
* by taking the camera matrix and inverting its transformation by first rotating
* objMtx back from screen orientation to world orientation, and then subtracting
* the camera position.
/**
* Extract a position given an object's transformation matrix and a camera matrix.
* This is used for determining the world position of the held object: since objMtx
* inherits the transformation from both the camera and Mario, it calculates this
* by taking the camera matrix and inverting its transformation by first rotating
* objMtx back from screen orientation to world orientation, and then subtracting
* the camera position.
*/
void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx) {
f32 camX = camMtx[3][0] * camMtx[0][0] + camMtx[3][1] * camMtx[0][1] + camMtx[3][2] * camMtx[0][2];
@@ -596,8 +616,9 @@ void get_pos_from_transform_mtx(Vec3f dest, Mat4 objMtx, Mat4 camMtx) {
objMtx[3][0] * camMtx[2][0] + objMtx[3][1] * camMtx[2][1] + objMtx[3][2] * camMtx[2][2] - camZ;
}
/** Take the vector starting at 'from' pointed at 'to' an retrieve the length
* of that vector, as well as the yaw and pitch angles.
/**
* Take the vector starting at 'from' pointed at 'to' an retrieve the length
* of that vector, as well as the yaw and pitch angles.
*/
void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *yaw) {
register f32 x = to[0] - from[0];
@@ -609,8 +630,9 @@ void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *
*yaw = atan2s(z, x);
}
/** Construct the 'to' point which is distance 'dist' away from the 'from' position,
* and has the angles pitch and yaw.
/**
* Construct the 'to' point which is distance 'dist' away from the 'from' position,
* and has the angles pitch and yaw.
*/
void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw) {
to[0] = from[0] + dist * coss(pitch) * sins(yaw);
@@ -618,8 +640,9 @@ void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s16 pitch, s16 yaw
to[2] = from[2] + dist * coss(pitch) * coss(yaw);
}
/** Return the value 'current' after it tries to approach target, going up at
* most 'inc' and going down at most 'dec'.
/**
* Return the value 'current' after it tries to approach target, going up at
* most 'inc' and going down at most 'dec'.
*/
s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec) {
//! If target is close to the max or min s32, then it's possible to overflow
@@ -627,83 +650,96 @@ s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec) {
if (current < target) {
current += inc;
if (current > target)
if (current > target) {
current = target;
}
} else {
current -= dec;
if (current < target)
if (current < target) {
current = target;
}
}
return current;
}
/** Return the value 'current' after it tries to approach target, going up at
* most 'inc' and going down at most 'dec'.
/**
* Return the value 'current' after it tries to approach target, going up at
* most 'inc' and going down at most 'dec'.
*/
f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec) {
if (current < target) {
current += inc;
if (current > target)
if (current > target) {
current = target;
}
} else {
current -= dec;
if (current < target)
if (current < target) {
current = target;
}
}
return current;
}
/** Helper function for atan2s. Does a look up of the arctangent of y/x assuming
* the resulting angle is in range [0, 0x2000] (1/8 of a circle).
/**
* Helper function for atan2s. Does a look up of the arctangent of y/x assuming
* the resulting angle is in range [0, 0x2000] (1/8 of a circle).
*/
static u16 atan2_lookup(f32 y, f32 x) {
u16 ret;
if (x == 0)
if (x == 0) {
ret = gArctanTable[0];
else
} else {
ret = gArctanTable[(s32)(y / x * 1024 + 0.5f)];
}
return ret;
}
/** Compute the angle from (0, 0) to (x, y) as a s16. Given that terrain is in
* the xz-plane, this is commonly called with (z, x) to get a yaw angle.
/**
* Compute the angle from (0, 0) to (x, y) as a s16. Given that terrain is in
* the xz-plane, this is commonly called with (z, x) to get a yaw angle.
*/
s16 atan2s(f32 y, f32 x) {
u16 ret;
if (x >= 0) {
if (y >= 0) {
if (y >= x)
if (y >= x) {
ret = atan2_lookup(x, y);
else
} else {
ret = 0x4000 - atan2_lookup(y, x);
}
} else {
y = -y;
if (y < x)
if (y < x) {
ret = 0x4000 + atan2_lookup(y, x);
else
} else {
ret = 0x8000 - atan2_lookup(x, y);
}
}
} else {
x = -x;
if (y < 0) {
y = -y;
if (y >= x)
if (y >= x) {
ret = 0x8000 + atan2_lookup(x, y);
else
} else {
ret = 0xC000 - atan2_lookup(y, x);
}
} else {
if (y < x)
if (y < x) {
ret = 0xC000 + atan2_lookup(y, x);
else
} else {
ret = -atan2_lookup(x, y);
}
}
}
return ret;
}
/** Compute the atan2 in radians by calling atan2s and converting the result.
/**
* Compute the atan2 in radians by calling atan2s and converting the result.
*/
f32 atan2f(f32 y, f32 x) {
return (f32) atan2s(y, x) * M_PI / 0x8000;
@@ -715,23 +751,24 @@ f32 atan2f(f32 y, f32 x) {
#define CURVE_END_1 4
#define CURVE_END_2 5
/** Set 'result' to a 4-vector with weights corresponding to interpolation
* value t in [0, 1] and gSplineState. Given the current control point P, these
* weights are for P[0], P[1], P[2] and P[3] to obtain an interpolated point.
* The weights naturally sum to 1, and they are also always in range [0, 1] so
* the inteprolated point will never overshoot. The curve is guaranteed to go
* through the first and last point, but not through intermediate points.
/**
* Set 'result' to a 4-vector with weights corresponding to interpolation
* value t in [0, 1] and gSplineState. Given the current control point P, these
* weights are for P[0], P[1], P[2] and P[3] to obtain an interpolated point.
* The weights naturally sum to 1, and they are also always in range [0, 1] so
* the inteprolated point will never overshoot. The curve is guaranteed to go
* through the first and last point, but not through intermediate points.
*
* gSplineState ensures that the curve is clamped: the first two points
* and last two points have different weight formulas. These are the weights
* just before gSplineState transitions:
* 1: [1, 0, 0, 0]
* 1->2: [0, 3/12, 7/12, 2/12]
* 2->3: [0, 1/6, 4/6, 1/6]
* 3->3: [0, 1/6, 4/6, 1/6] (repeats)
* 3->4: [0, 1/6, 4/6, 1/6]
* 4->5: [0, 2/12, 7/12, 3/12]
* 5: [0, 0, 0, 1]
* gSplineState ensures that the curve is clamped: the first two points
* and last two points have different weight formulas. These are the weights
* just before gSplineState transitions:
* 1: [1, 0, 0, 0]
* 1->2: [0, 3/12, 7/12, 2/12]
* 2->3: [0, 1/6, 4/6, 1/6]
* 3->3: [0, 1/6, 4/6, 1/6] (repeats)
* 3->4: [0, 1/6, 4/6, 1/6]
* 4->5: [0, 2/12, 7/12, 3/12]
* 5: [0, 0, 0, 1]
*
* I suspect that the weight formulas will give a 3rd degree B-spline with the
* common uniform clamped knot vector, e.g. for n points:
@@ -779,12 +816,13 @@ void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c) {
}
}
/** Initialize a spline animation.
* 'keyframes' should be an array of (s, x, y, z) vectors
* s: the speed of the keyframe in 1000/frames, e.g. s=100 means the keyframe lasts 10 frames
* (x, y, z): point in 3D space on the curve
* The array should end with three entries with s=0 (infinite keyframe duration).
* That's because the spline has a 3rd degree polynomial, so it looks 3 points ahead.
/**
* Initialize a spline animation.
* 'keyframes' should be an array of (s, x, y, z) vectors
* s: the speed of the keyframe in 1000/frames, e.g. s=100 means the keyframe lasts 10 frames
* (x, y, z): point in 3D space on the curve
* The array should end with three entries with s=0 (infinite keyframe duration).
* That's because the spline has a 3rd degree polynomial, so it looks 3 points ahead.
*/
void anim_spline_init(Vec4s *keyFrames) {
gSplineKeyframe = keyFrames;
@@ -792,9 +830,10 @@ void anim_spline_init(Vec4s *keyFrames) {
gSplineState = 1;
}
/** Poll the next point from a spline animation.
* anim_spline_init should be called before polling for vectors.
* Returns TRUE when the last point is reached, FALSE otherwise.
/**
* Poll the next point from a spline animation.
* anim_spline_init should be called before polling for vectors.
* Returns TRUE when the last point is reached, FALSE otherwise.
*/
s32 anim_spline_poll(Vec3f result) {
Vec4f weights;
@@ -817,8 +856,9 @@ s32 anim_spline_poll(Vec3f result) {
hasEnded = TRUE;
break;
case CURVE_MIDDLE:
if (gSplineKeyframe[2][0] == 0)
if (gSplineKeyframe[2][0] == 0) {
gSplineState = CURVE_END_1;
}
break;
default:
gSplineState++;
+56 -28
View File
@@ -33,8 +33,9 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode,
s32 numCols = 0;
// Max collision radius = 200
if (radius > 200.0f)
if (radius > 200.0f) {
radius = 200.0f;
}
// Stay in this loop until out of walls.
while (surfaceNode != NULL) {
@@ -67,19 +68,25 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode,
y3 = surf->vertex3[1];
if (surf->normal.x > 0.0f) {
if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) > 0.0f)
if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) > 0.0f) {
continue;
if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) > 0.0f)
}
if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) > 0.0f) {
continue;
if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) > 0.0f)
}
if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) > 0.0f) {
continue;
}
} else {
if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) < 0.0f)
if ((y1 - y) * (w2 - w1) - (w1 - -pz) * (y2 - y1) < 0.0f) {
continue;
if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) < 0.0f)
}
if ((y2 - y) * (w3 - w2) - (w2 - -pz) * (y3 - y2) < 0.0f) {
continue;
if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) < 0.0f)
}
if ((y3 - y) * (w1 - w3) - (w3 - -pz) * (y1 - y3) < 0.0f) {
continue;
}
}
} else {
w1 = surf->vertex1[0];
@@ -90,30 +97,38 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode,
y3 = surf->vertex3[1];
if (surf->normal.z > 0.0f) {
if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) > 0.0f)
if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) > 0.0f) {
continue;
if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) > 0.0f)
}
if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) > 0.0f) {
continue;
if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) > 0.0f)
}
if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) > 0.0f) {
continue;
}
} else {
if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) < 0.0f)
if ((y1 - y) * (w2 - w1) - (w1 - px) * (y2 - y1) < 0.0f) {
continue;
if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) < 0.0f)
}
if ((y2 - y) * (w3 - w2) - (w2 - px) * (y3 - y2) < 0.0f) {
continue;
if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) < 0.0f)
}
if ((y3 - y) * (w1 - w3) - (w3 - px) * (y1 - y3) < 0.0f) {
continue;
}
}
}
// Determine if checking for the camera or not.
if (gCheckingSurfaceCollisionsForCamera) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION)
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
continue;
}
} else {
// Ignore camera only surfaces.
if (surf->type == SURFACE_CAMERA_BOUNDARY)
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) {
@@ -186,10 +201,12 @@ s32 find_wall_collisions(struct WallCollisionData *colData) {
colData->numWalls = 0;
if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX)
if (x <= -LEVEL_BOUNDARY_MAX || x >= LEVEL_BOUNDARY_MAX) {
return numCollisions;
if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX)
}
if (z <= -LEVEL_BOUNDARY_MAX || z >= LEVEL_BOUNDARY_MAX) {
return numCollisions;
}
// World (level) consists of a 16x16 grid. Find where the collision is on
// the grid (round toward -inf)
@@ -236,21 +253,25 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32
x2 = surf->vertex2[0];
// Checking if point is in bounds of the triangle laterally.
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0)
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) > 0) {
continue;
}
// Slight optimization by checking these later.
x3 = surf->vertex3[0];
z3 = surf->vertex3[2];
if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0)
if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) > 0) {
continue;
if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0)
}
if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) > 0) {
continue;
}
// Determine if checking for the camera or not.
if (gCheckingSurfaceCollisionsForCamera != 0) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION)
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION) {
continue;
}
}
// Ignore camera only surfaces.
else if (surf->type == SURFACE_CAMERA_BOUNDARY) {
@@ -265,8 +286,9 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32
f32 height;
// If a wall, ignore it. Likely a remnant, should never occur.
if (ny == 0.0f)
if (ny == 0.0f) {
continue;
}
// Find the ceil height at the specific point.
height = -(x * nx + nz * z + oo) / ny;
@@ -275,8 +297,9 @@ static struct Surface *find_ceil_from_list(struct SurfaceNode *surfaceNode, s32
//! (Exposed Ceilings) Because any point above a ceiling counts
// as interacting with a ceiling, ceilings far below can cause
// "invisible walls" that are really just exposed ceilings.
if (y - (height - -78.0f) > 0.0f)
if (y - (height - -78.0f) > 0.0f) {
continue;
}
*pheight = height;
ceil = surf;
@@ -405,22 +428,26 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
z2 = surf->vertex2[2];
// Check that the point is within the triangle bounds.
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0)
if ((z1 - z) * (x2 - x1) - (x1 - x) * (z2 - z1) < 0) {
continue;
}
// To slightly save on computation time, set this later.
x3 = surf->vertex3[0];
z3 = surf->vertex3[2];
if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0)
if ((z2 - z) * (x3 - x2) - (x2 - x) * (z3 - z2) < 0) {
continue;
if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) < 0)
}
if ((z3 - z) * (x1 - x3) - (x3 - x) * (z1 - z3) < 0) {
continue;
}
// Determine if we are checking for the camera or not.
if (gCheckingSurfaceCollisionsForCamera != 0) {
if (surf->flags & SURFACE_FLAG_NO_CAM_COLLISION)
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) {
@@ -440,8 +467,9 @@ static struct Surface *find_floor_from_list(struct SurfaceNode *surfaceNode, s32
// Find the height of the floor at a given location.
height = -(x * nx + nz * z + oo) / ny;
// Checks for floor interaction with a 78 unit buffer.
if (y - (height + -78.0f) < 0.0f)
if (y - (height + -78.0f) < 0.0f) {
continue;
}
*pheight = height;
floor = surf;
+8 -4
View File
@@ -325,16 +325,20 @@ static struct Surface *read_surface_data(s16 *vertexData, s16 **vertexIndices) {
// 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;
}
// Checking to make sure no DIV/0
if (mag < 0.0001) {