A few more names + cleanup find_wall_collisions_from_list a bit

This commit is contained in:
Arceveti
2021-09-20 18:29:58 -07:00
parent 022679b8b7
commit 0d2daf0776
6 changed files with 77 additions and 179 deletions

View File

@@ -174,7 +174,7 @@ struct GraphNodeObject
/*0x20*/ Vec3f pos;
/*0x2C*/ Vec3f scale;
/*0x38*/ struct AnimInfo animInfo;
/*0x4C*/ struct SpawnInfo *unk4C;
/*0x4C*/ struct SpawnInfo *spawnInfo;
/*0x50*/ Mat4 *throwMatrix; // matrix ptr
/*0x54*/ Vec3f cameraToObject;
u8 uCode;

View File

@@ -331,8 +331,6 @@ u8 sSoundBankDisabled[16] = { 0 };
u8 D_80332108 = 0;
u8 sHasStartedFadeOut = FALSE;
u16 sSoundBanksThatLowerBackgroundMusic = 0;
u8 sUnused80332114 = 0; // never read, set to 0
u16 sUnused80332118 = 0; // never read, set to 0
u8 sBackgroundMusicMaxTargetVolume = TARGET_VOLUME_UNSET;
u8 D_80332120 = 0;
u8 D_80332124 = 0;
@@ -2142,11 +2140,9 @@ void sound_init(void) {
sound_banks_enable(SEQ_PLAYER_SFX, SOUND_BANKS_ALL_BITS);
sUnused80332118 = 0;
sBackgroundMusicTargetVolume = TARGET_VOLUME_UNSET;
sLowerBackgroundMusicVolume = FALSE;
sSoundBanksThatLowerBackgroundMusic = 0;
sUnused80332114 = 0;
sCurrentBackgroundMusicSeqId = 0xff;
gSoundMode = SOUND_MODE_STEREO;
sBackgroundMusicQueueSize = 0;
@@ -2504,9 +2500,6 @@ void func_80320ED8(void) {
* Called from threads: thread5_game_loop
*/
void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer) {
UNUSED u32 dummy;
sUnused80332118 = 0;
if (sCurrentBackgroundMusicSeqId == 0xff || sCurrentBackgroundMusicSeqId == SEQ_MENU_TITLE_SCREEN) {
return;
}
@@ -2530,6 +2523,7 @@ void play_secondary_music(u8 seqId, u8 bgMusicVolume, u8 volume, u16 fadeTimer)
/**
* Called from threads: thread5_game_loop
* Seems to be related to music fading based on position, such as sleeping Piranha Plants, BBH Merry-Go-Round, and Endless Stairs
*/
void func_80321080(u16 fadeTimer) {
if (sBackgroundMusicTargetVolume != TARGET_VOLUME_UNSET) {

View File

@@ -718,7 +718,7 @@ void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f po
vec3s_copy(graphNode->angle, angle);
graphNode->sharedChild = sharedChild;
graphNode->unk4C = 0;
graphNode->spawnInfo = 0;
graphNode->throwMatrix = NULL;
graphNode->animInfo.curAnim = NULL;
@@ -742,7 +742,7 @@ void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo
graphNode->areaIndex = spawn->areaIndex;
graphNode->activeAreaIndex = spawn->activeAreaIndex;
graphNode->sharedChild = spawn->modelNode;
graphNode->unk4C = spawn;
graphNode->spawnInfo = spawn;
graphNode->throwMatrix = NULL;
graphNode->animInfo.curAnim = 0;

View File

@@ -15,6 +15,20 @@
* WALLS *
**************************************************/
#define CALC_OFFSET(vert, next_step) { \
if ((vert)[1] != 0.0f) { \
v = (v2[1] / (vert)[1]); \
if ((v < 0.0f) || (v > 1.0f)) next_step;\
d00 = (((vert)[0] * v) - v2[0]); \
d01 = (((vert)[2] * v) - v2[2]); \
invDenom = sqrtf(sqr(d00) + sqr(d01)); \
offset = (invDenom - margin_radius); \
if (offset > 0.0f) next_step; \
goto check_collision; \
} \
next_step; \
}
/**
* Iterate through the list of walls until all walls are checked and
* have given their wall push.
@@ -24,12 +38,8 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
register struct Surface *surf;
register f32 offset;
register f32 radius = data->radius;
register f32 x = data->x;
register f32 y = data->y + data->offsetY;
register f32 z = data->z;
register f32 v0x, v0y, v0z;
register f32 v1x, v1y, v1z;
register f32 v2x, v2y, v2z;
register Vec3f pos = { data->x, data->y + data->offsetY, data->z };
register Vec3f v0, v1, v2;
register f32 d00, d01, d11, d20, d21;
register f32 invDenom;
register f32 v, w;
@@ -57,11 +67,11 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
surfaceNode = surfaceNode->next;
// Exclude a large number of walls immediately to optimize.
if (y < surf->lowerY || y > surf->upperY) {
if (pos[1] < surf->lowerY || pos[1] > surf->upperY) {
continue;
}
offset = (surf->normal.x * x) + (surf->normal.y * y) + (surf->normal.z * z) + surf->originOffset;
offset = (surf->normal.x * pos[0]) + (surf->normal.y * pos[1]) + (surf->normal.z * pos[2]) + surf->originOffset;
if (offset < -radius || offset > radius) {
continue;
@@ -94,24 +104,24 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
}
}
v0x = (f32)(surf->vertex2[0] - surf->vertex1[0]);
v0y = (f32)(surf->vertex2[1] - surf->vertex1[1]);
v0z = (f32)(surf->vertex2[2] - surf->vertex1[2]);
v0[0] = (f32)(surf->vertex2[0] - surf->vertex1[0]);
v0[1] = (f32)(surf->vertex2[1] - surf->vertex1[1]);
v0[2] = (f32)(surf->vertex2[2] - surf->vertex1[2]);
v1x = (f32)(surf->vertex3[0] - surf->vertex1[0]);
v1y = (f32)(surf->vertex3[1] - surf->vertex1[1]);
v1z = (f32)(surf->vertex3[2] - surf->vertex1[2]);
v1[0] = (f32)(surf->vertex3[0] - surf->vertex1[0]);
v1[1] = (f32)(surf->vertex3[1] - surf->vertex1[1]);
v1[2] = (f32)(surf->vertex3[2] - surf->vertex1[2]);
v2x = x - (f32)surf->vertex1[0];
v2y = y - (f32)surf->vertex1[1];
v2z = z - (f32)surf->vertex1[2];
v2[0] = pos[0] - (f32)surf->vertex1[0];
v2[1] = pos[1] - (f32)surf->vertex1[1];
v2[2] = pos[2] - (f32)surf->vertex1[2];
// Face
d00 = (v0x * v0x) + (v0y * v0y) + (v0z * v0z);
d01 = (v0x * v1x) + (v0y * v1y) + (v0z * v1z);
d11 = (v1x * v1x) + (v1y * v1y) + (v1z * v1z);
d20 = (v2x * v0x) + (v2y * v0y) + (v2z * v0z);
d21 = (v2x * v1x) + (v2y * v1y) + (v2z * v1z);
d00 = (v0[0] * v0[0]) + (v0[1] * v0[1]) + (v0[2] * v0[2]);
d01 = (v0[0] * v1[0]) + (v0[1] * v1[1]) + (v0[2] * v1[2]);
d11 = (v1[0] * v1[0]) + (v1[1] * v1[1]) + (v1[2] * v1[2]);
d20 = (v2[0] * v0[0]) + (v2[1] * v0[1]) + (v2[2] * v0[2]);
d21 = (v2[0] * v1[0]) + (v2[1] * v1[1]) + (v2[2] * v1[2]);
invDenom = 1.0f / ((d00 * d11) - (d01 * d01));
v = ((d11 * d20) - (d01 * d21)) * invDenom;
if (v < 0.0f || v > 1.0f) {
@@ -121,97 +131,38 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
if (w < 0.0f || w > 1.0f || v + w > 1.0f) {
goto edge_1_2;
}
x += surf->normal.x * (radius - offset);
z += surf->normal.z * (radius - offset);
pos[0] += surf->normal.x * (radius - offset);
pos[2] += surf->normal.z * (radius - offset);
goto hasCollision;
edge_1_2:
if (offset < 0) continue;
// Edge 1-2
if (v0y != 0.0f) {
v = (v2y / v0y);
if (v < 0.0f || v > 1.0f) {
goto edge_1_3;
}
d00 = v0x * v - v2x;
d01 = v0z * v - v2z;
invDenom = sqrtf(sqr(d00) + sqr(d01));
offset = invDenom - margin_radius;
if (offset > 0.0f) {
goto edge_1_3;
}
invDenom = offset / invDenom;
x += (d00 *= invDenom);
z += (d01 *= invDenom);
margin_radius += 0.01f;
if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
continue;
} else {
goto hasCollision;
}
}
CALC_OFFSET(v0, goto edge_1_3);
edge_1_3:
// Edge 1-3
if (v1y != 0.0f) {
v = (v2y / v1y);
if (v < 0.0f || v > 1.0f) {
goto edge_2_3;
}
d00 = v1x * v - v2x;
d01 = v1z * v - v2z;
invDenom = sqrtf(sqr(d00) + sqr(d01));
offset = invDenom - margin_radius;
if (offset > 0.0f) {
goto edge_2_3;
}
invDenom = offset / invDenom;
x += (d00 *= invDenom);
z += (d01 *= invDenom);
margin_radius += 0.01f;
if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
continue;
} else {
goto hasCollision;
}
}
CALC_OFFSET(v1, goto edge_2_3);
edge_2_3:
// Edge 2-3
v1x = (f32)(surf->vertex3[0] - surf->vertex2[0]);
v1y = (f32)(surf->vertex3[1] - surf->vertex2[1]);
v1z = (f32)(surf->vertex3[2] - surf->vertex2[2]);
v1[0] = (f32)(surf->vertex3[0] - surf->vertex2[0]);
v1[1] = (f32)(surf->vertex3[1] - surf->vertex2[1]);
v1[2] = (f32)(surf->vertex3[2] - surf->vertex2[2]);
v2x = x - (f32)surf->vertex2[0];
v2y = y - (f32)surf->vertex2[1];
v2z = z - (f32)surf->vertex2[2];
v2[0] = pos[0] - (f32)surf->vertex2[0];
v2[1] = pos[1] - (f32)surf->vertex2[1];
v2[2] = pos[2] - (f32)surf->vertex2[2];
if (v1y != 0.0f) {
v = (v2y / v1y);
if (v < 0.0f || v > 1.0f) continue;
d00 = v1x * v - v2x;
d01 = v1z * v - v2z;
invDenom = sqrtf(sqr(d00) + sqr(d01));
offset = invDenom - margin_radius;
if (offset > 0.0f) continue;
invDenom = offset / invDenom;
x += (d00 *= invDenom);
z += (d01 *= invDenom);
margin_radius += 0.01f;
if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
continue;
} else {
goto hasCollision;
}
} else {
CALC_OFFSET(v1, continue);
check_collision:
invDenom = offset / invDenom;
pos[0] += (d00 *= invDenom);
pos[2] += (d01 *= invDenom);
margin_radius += 0.01f;
if ((d00 * surf->normal.x) + (d01 * surf->normal.z) < (corner_threshold * offset)) {
continue;
}
hasCollision:
//! (Unreferenced Walls) Since this only returns the first four walls,
// this can lead to wall interaction being missed. Typically unreferenced walls
// come from only using one wall, however.
// (Unreferenced Walls) Since this only returns the first MAX_REFEREMCED_WALLS walls,
// this can lead to wall interaction being missed. Typically unreferenced walls
// come from only using one wall, however.
if (data->numWalls < MAX_REFEREMCED_WALLS) {
data->walls[data->numWalls++] = surf;
}
@@ -225,8 +176,8 @@ static s32 find_wall_collisions_from_list(struct SurfaceNode *surfaceNode, struc
// z *= gWorldScale;
// #endif
data->x = x;
data->z = z;
data->x = pos[0];
data->z = pos[2];
return numCols;
}

View File

@@ -54,7 +54,7 @@ static void handle_merry_go_round_music(void) {
// The merry-go-round is a dynamic surface.
gMarioCurrentRoom != BBH_DYNAMIC_SURFACE_ROOM
&& gMarioCurrentRoom != BBH_NEAR_MERRY_GO_ROUND_ROOM) {
func_80321080(300); // Switch to BBH music? FIXME: Audio needs labelling
func_80321080(300); //! Switch to BBH music? FIXME: Audio needs labelling
o->oMerryGoRoundMusicShouldPlay = FALSE;
} else {
cur_obj_play_sound_1(SOUND_ENV_MERRY_GO_ROUND_CREAKING);
@@ -95,6 +95,6 @@ void bhv_merry_go_round_loop(void) {
handle_merry_go_round_music();
} else {
o->oAngleVelYaw = 0;
func_80321080(300); // Switch to BBH music? FIXME: Audio needs labelling
func_80321080(300); //! Switch to BBH music? FIXME: Audio needs labelling
}
}

View File

@@ -1472,17 +1472,12 @@ void move_animator(struct ObjAnimator *animObj) {
/* @ 22EDF4 for 0x300; orig name: func_80180624 */
void drag_picked_object(struct GdObj *inputObj) {
UNUSED u32 spE4;
UNUSED u32 spE0;
UNUSED u32 spDC;
struct GdVec3f displacement;
struct GdVec3f spC4;
struct GdControl *ctrl;
Mat4f sp80;
Mat4f sp40;
UNUSED u32 pad34[3];
struct GdObj *obj;
UNUSED u32 pad2C;
f32 dispMag;
ctrl = &gGdCtrl;
@@ -1549,15 +1544,13 @@ void find_and_drag_picked_object(struct ObjGroup *group) {
/* @ 22F180 for 0x624; orig name: func_801809B0 */
void move_camera(struct ObjCamera *cam) {
struct GdObj *spEC;
struct GdVec3f spE0;
struct GdObj *obj;
struct GdVec3f worldPos;
struct GdVec3f spD4;
struct GdVec3f spC8;
UNUSED u8 padBC[0xC8 - 0xBC];
struct GdVec3f spB0;
Mat4f sp70;
UNUSED u8 pad30[0x70 - 0x30];
Mat4f *sp2C;
Mat4f mtx;
Mat4f *idMtx;
struct GdControl *ctrl;
ctrl = &gGdCtrl;
@@ -1565,16 +1558,16 @@ void move_camera(struct ObjCamera *cam) {
return;
}
spE0.x = spE0.y = spE0.z = 0.0f;
worldPos.x = worldPos.y = worldPos.z = 0.0f;
spB0.x = spB0.y = spB0.z = 0.0f;
if ((spEC = cam->unk30) != NULL) {
set_cur_dynobj(spEC);
d_get_world_pos(&spE0);
d_get_matrix(&sp70);
if ((obj = cam->unk30) != NULL) {
set_cur_dynobj(obj);
d_get_world_pos(&worldPos);
d_get_matrix(&mtx);
spC8.x = sp70[2][0] - cam->unk58;
spC8.z = sp70[2][2] - cam->unk60;
spC8.x = mtx[2][0] - cam->unk58;
spC8.z = mtx[2][2] - cam->unk60;
cam->unk58 += spC8.x * cam->unk180.y;
cam->unk60 += spC8.z * cam->unk180.y;
@@ -1597,7 +1590,7 @@ void move_camera(struct ObjCamera *cam) {
gd_set_identity_mat4(&cam->unkA8);
}
sp2C = &cam->unk64;
idMtx = &cam->unk64;
if ((cam->flags & CAMERA_FLAG_CONTROLLABLE) != 0) {
if (ctrl->btnB != FALSE && ctrl->prevFrame->btnB == FALSE) { // new B press
cam->zoomLevel++;
@@ -1645,7 +1638,7 @@ void move_camera(struct ObjCamera *cam) {
cam->unk40.y += (cam->unk4C.y - cam->unk40.y) * cam->unk17C;
cam->unk40.z += (cam->unk4C.z - cam->unk40.z) * cam->unk17C;
} else {
gd_set_identity_mat4(sp2C);
gd_set_identity_mat4(idMtx);
}
spD4.x = cam->unk40.x;
@@ -1656,16 +1649,16 @@ void move_camera(struct ObjCamera *cam) {
spD4.y += spB0.y;
spD4.z += spB0.z;
gd_mult_mat4f(sp2C, &cam->unkA8, &cam->unkA8);
gd_mult_mat4f(idMtx, &cam->unkA8, &cam->unkA8);
gd_mat4f_mult_vec3f(&spD4, &cam->unkA8);
cam->worldPos.x = spD4.x;
cam->worldPos.y = spD4.y;
cam->worldPos.z = spD4.z;
cam->worldPos.x += spE0.x;
cam->worldPos.y += spE0.y;
cam->worldPos.z += spE0.z;
cam->worldPos.x += worldPos.x;
cam->worldPos.y += worldPos.y;
cam->worldPos.z += worldPos.z;
}
/* @ 22F7A4 for 0x38; orig name: func_80180FD4 */
@@ -1675,9 +1668,6 @@ void move_cameras_in_grp(struct ObjGroup *group) {
/* @ 22F7DC for 0x36C*/
void func_8018100C(struct ObjLight *light) {
Mat4f mtx;
UNUSED u32 pad1C[3];
if (light->unk40 == 3) {
if (light->unk30 > 0.0) { //? 0.0f
light->unk30 -= 0.2; //? 0.2f
@@ -1693,44 +1683,7 @@ void func_8018100C(struct ObjLight *light) {
light->unk3C &= ~1;
}
// if (1)?
return;
// unreachable
light->position.x += light->unk80.x;
light->position.y += light->unk80.y;
light->position.z += light->unk80.z;
// should be position.x for second comparison?
if (light->position.x > 500.0f || light->position.y < -500.0f) {
light->unk80.x = -light->unk80.x;
}
if (light->position.y > 500.0f || light->position.y < -500.0f) {
light->unk80.y = -light->unk80.y;
}
if (light->position.z > 500.0f || light->position.z < -500.0f) {
light->unk80.z = -light->unk80.z;
}
return;
// more unreachable
D_801A81C0 += 1.0; //? 1.0f
D_801A81C4 += 0.6; //? 0.6f
gd_set_identity_mat4(&mtx);
gd_absrot_mat4(&mtx, GD_Y_AXIS, light->unk68.y);
gd_absrot_mat4(&mtx, GD_X_AXIS, light->unk68.x);
gd_absrot_mat4(&mtx, GD_Z_AXIS, light->unk68.z);
gd_mat4f_mult_vec3f(&light->unk8C, &mtx);
light->position.x = light->unk8C.x;
light->position.y = light->unk8C.y;
light->position.z = light->unk8C.z;
return;
// even more unreachable
gd_mat4f_mult_vec3f(&light->unk80, &mtx);
imout(); // this call would cause an issue if it was reachable
}
/* @ 22FB48 for 0x38; orig name: func_80181378 */