From 03f1cd89a318413e6369040f0544faaaea3cf4af Mon Sep 17 00:00:00 2001 From: mrshigure Date: Tue, 16 Jan 2024 01:02:58 -0800 Subject: [PATCH] Matched ClusterExec --- configure.py | 2 +- include/game/ClusterExec.h | 13 +++ include/game/EnvelopeExec.h | 2 + include/game/hsfformat.h | 2 +- include/game/hsfman.h | 2 - src/game/ClusterExec.c | 174 ++++++++++++++++++++++++++++++++++++ src/game/EnvelopeExec.c | 4 +- src/game/hsfman.c | 1 + src/game/hsfmotion.c | 5 +- 9 files changed, 195 insertions(+), 10 deletions(-) create mode 100644 include/game/ClusterExec.h create mode 100644 src/game/ClusterExec.c diff --git a/configure.py b/configure.py index 98e0ca1c..6303a8a0 100644 --- a/configure.py +++ b/configure.py @@ -343,7 +343,7 @@ config.libs = [ Object(Matching, "game/ovllist.c"), Object(NonMatching, "game/esprite.c"), Object(NonMatching, "game/code_8003FF68.c"), - Object(NonMatching, "game/ClusterExec.c"), + Object(Matching, "game/ClusterExec.c"), Object(NonMatching, "game/ShapeExec.c"), Object(Matching, "game/wipe.c"), Object(Matching, "game/window.c"), diff --git a/include/game/ClusterExec.h b/include/game/ClusterExec.h new file mode 100644 index 00000000..785e3fe0 --- /dev/null +++ b/include/game/ClusterExec.h @@ -0,0 +1,13 @@ +#ifndef _GAME_CLUSTER_EXEC_H +#define _GAME_CLUSTER_EXEC_H + +#include "game/hsfformat.h" +#include "game/hsfman.h" + +float GetClusterCurve(HsfTrack *arg0, float arg1); +float GetClusterWeightCurve(HsfTrack *arg0, float arg1); +void SetClusterMain(HsfCluster *arg0); +void ClusterProc(ModelData *arg0); +void ClusterMotionExec(ModelData *arg0); + +#endif diff --git a/include/game/EnvelopeExec.h b/include/game/EnvelopeExec.h index cad722f5..0cbcb61f 100644 --- a/include/game/EnvelopeExec.h +++ b/include/game/EnvelopeExec.h @@ -7,4 +7,6 @@ void InitEnvelope(HsfData *arg0); void EnvelopeProc(HsfData *arg0); void InitVtxParm(HsfData *arg0); +extern Vec *Vertextop; + #endif diff --git a/include/game/hsfformat.h b/include/game/hsfformat.h index 4a567220..d3104319 100644 --- a/include/game/hsfformat.h +++ b/include/game/hsfformat.h @@ -238,7 +238,7 @@ typedef struct hsf_cluster { char *name[2]; union { char *targetName; - u32 target; + s32 target; }; HsfPart *part; float unk10; diff --git a/include/game/hsfman.h b/include/game/hsfman.h index fcf2105a..a0ed6ff6 100644 --- a/include/game/hsfman.h +++ b/include/game/hsfman.h @@ -117,8 +117,6 @@ typedef struct light_data { GXColor color; } LightData; -extern void ClusterMotionExec(ModelData*); /* extern */ -extern void ClusterProc(ModelData*); /* extern */ extern void GXWaitDrawDone(); /* extern */ extern void ShapeProc(HsfData*); /* extern */ extern void GXInitSpecularDir(GXLightObj*, f32, f32, f32); diff --git a/src/game/ClusterExec.c b/src/game/ClusterExec.c new file mode 100644 index 00000000..f1494664 --- /dev/null +++ b/src/game/ClusterExec.c @@ -0,0 +1,174 @@ +#include "game/ClusterExec.h" +#include "game/EnvelopeExec.h" +#include "game/hsfmotion.h" + +float GetClusterCurve(HsfTrack *arg0, float arg1) { + float *var_r30; + + switch (arg0->curveType) { + case 1: + return GetLinear(arg0->numKeyframes, arg0->data, arg1); + case 2: + return GetBezier(arg0->numKeyframes, arg0, arg1); + case 4: + var_r30 = &arg0->value; + return *var_r30; + } + return 0.0f; +} + +float GetClusterWeightCurve(HsfTrack *arg0, float arg1) { + float *var_r30; + + switch (arg0->curveType) { + case 1: + return GetLinear(arg0->numKeyframes, arg0->data, arg1); + case 2: + return GetBezier(arg0->numKeyframes, arg0, arg1); + case 4: + var_r30 = &arg0->value; + return *var_r30; + } + return 0.0f; +} + +void SetClusterMain(HsfCluster *arg0) { + float var_f30; + float var_f31; + s32 temp_r24; + s32 temp_r29; + u16 *var_r28; + s32 var_r23; + s32 i; + s32 j; + HsfBuffer *temp_r25; + HsfPart *temp_r27; + HsfBuffer *temp_r30; + + temp_r27 = arg0->part; + if (arg0->vertexCnt != 0) { + if (arg0->type == 2) { + var_r28 = temp_r27->vertex; + temp_r30 = *arg0->vertex; + var_f30 = 0.0f; + for (i = 0; i < arg0->vertexCnt; i++) { + var_f30 += arg0->unk14[i]; + } + for (i = 0; i < temp_r27->count; i++, var_r28++) { + temp_r29 = *var_r28; + Vertextop[temp_r29].x = ((Vec*) temp_r30->data)[i].x; + Vertextop[temp_r29].y = ((Vec*) temp_r30->data)[i].y; + Vertextop[temp_r29].z = ((Vec*) temp_r30->data)[i].z; + } + for (i = 1; i < arg0->vertexCnt; i++) { + temp_r30 = arg0->vertex[i]; + var_r28 = temp_r27->vertex; + var_f31 = arg0->unk14[i]; + if (var_f31 < 0.0f) { + var_f31 = 0.0f; + } else if (var_f30 > 1.0f) { + var_f31 /= var_f30; + } + for (j = 0; j < temp_r27->count; j++, var_r28++) { + temp_r29 = *var_r28; + Vertextop[temp_r29].x += var_f31 * (((Vec*) temp_r30->data)[j].x - Vertextop[temp_r29].x); + Vertextop[temp_r29].y += var_f31 * (((Vec*) temp_r30->data)[j].y - Vertextop[temp_r29].y); + Vertextop[temp_r29].z += var_f31 * (((Vec*) temp_r30->data)[j].z - Vertextop[temp_r29].z); + } + } + return; + } + temp_r24 = arg0->unk10; + var_r23 = temp_r24 + 1; + if (var_r23 >= arg0->vertexCnt) { + var_r23 = temp_r24; + } + var_f31 = arg0->unk10 - temp_r24; + temp_r30 = arg0->vertex[temp_r24]; + temp_r25 = arg0->vertex[var_r23]; + var_r28 = temp_r27->vertex; + for (i = 0; i < temp_r27->count; i++, var_r28++) { + temp_r29 = *var_r28; + Vertextop[temp_r29].x = ((Vec*) temp_r30->data)[i].x + var_f31 * (((Vec*) temp_r25->data)[i].x - ((Vec*) temp_r30->data)[i].x); + Vertextop[temp_r29].y = ((Vec*) temp_r30->data)[i].y + var_f31 * (((Vec*) temp_r25->data)[i].y - ((Vec*) temp_r30->data)[i].y); + Vertextop[temp_r29].z = ((Vec*) temp_r30->data)[i].z + var_f31 * (((Vec*) temp_r25->data)[i].z - ((Vec*) temp_r30->data)[i].z); + } + } +} + +void ClusterProc(ModelData *arg0) { + s32 temp_r24; + s32 i; + s32 j; + s32 k; + HsfData *temp_r27; + HsfData *temp_r23; + MotionData *temp_r22; + HsfCluster *var_r29; + HsfObject *temp_r31; + + for (i = 0; i < 4; i++) { + temp_r24 = arg0->unk_10[i]; + if (temp_r24 != -1) { + temp_r22 = &Hu3DMotion[temp_r24]; + temp_r27 = temp_r22->unk_04; + temp_r23 = arg0->hsfData; + var_r29 = temp_r27->cluster; + for (j = 0; j < temp_r27->clusterCnt; j++, var_r29++) { + if (var_r29->target != -1) { + temp_r31 = temp_r23->object; + temp_r31 += var_r29->target; + Vertextop = temp_r31->data.vertex->data; + if (temp_r31->data.hook) { + for (k = 0; k < temp_r31->data.vertex->count; k++) { + Vertextop[k].x = ((Vec*) temp_r31->data.file[0])[k].x; + Vertextop[k].y = ((Vec*) temp_r31->data.file[0])[k].y; + Vertextop[k].z = ((Vec*) temp_r31->data.file[0])[k].z; + } + } + SetClusterMain(var_r29); + DCStoreRangeNoSync(Vertextop, temp_r31->data.vertex->count * sizeof(Vec)); + temp_r31->data.unk120[0]++; + } + } + } + } +} + +void ClusterMotionExec(ModelData *arg0) { + float temp_f31; + s32 i; + s32 j; + s16 var_r20; + HsfCluster *temp_r26; + HsfData *temp_r28; + HsfMotion *temp_r27; + HsfTrack *var_r31; + HsfTrack *var_r30; + MotionData *var_r23; + + var_r31 = temp_r27->track; + for (i = 0; i < 4; i++) { + if (arg0->unk_10[i] != -1) { + var_r20 = arg0->unk_10[i]; + var_r23 = &Hu3DMotion[var_r20]; + temp_r28 = var_r23->unk_04; + temp_r27 = temp_r28->motion; + var_r31 = temp_r27->track; + temp_f31 = arg0->unk_A4[i]; + for (j = 0; j < temp_r27->numTracks; j++, var_r31++) { + switch (var_r31->type) { + case 5: + temp_r26 = &temp_r28->cluster[var_r31->target_s16]; + temp_r26->unk10 = GetClusterCurve(var_r31, temp_f31); + break; + case 6: + var_r30 = var_r31; + temp_r26 = &temp_r28->cluster[var_r30->target_s16]; + temp_r26->unk14[var_r30->unk04] = GetClusterCurve(var_r30, temp_f31); + break; + } + } + } + } +} diff --git a/src/game/EnvelopeExec.c b/src/game/EnvelopeExec.c index 3cc9618b..b67b1117 100644 --- a/src/game/EnvelopeExec.c +++ b/src/game/EnvelopeExec.c @@ -185,8 +185,8 @@ static void SetEnvelopMain(HsfData *arg0) { sp10 = temp_r30->data; spC = var_r31->data.file[0]; sp8 = temp_r30->data; - DCStoreRangeNoSync(normenv, temp_r28->count * 0xC); - DCStoreRangeNoSync(vtxenv, temp_r30->count * 0xC); + DCStoreRangeNoSync(normenv, temp_r28->count * sizeof(Vec)); + DCStoreRangeNoSync(vtxenv, temp_r30->count * sizeof(Vec)); Meshno++; } } diff --git a/src/game/hsfman.c b/src/game/hsfman.c index 0dd95cc5..8cad6a9f 100644 --- a/src/game/hsfman.c +++ b/src/game/hsfman.c @@ -1,4 +1,5 @@ #include "game/hsfman.h" +#include "game/ClusterExec.h" #include "game/data.h" #include "game/EnvelopeExec.h" #include "game/hsfdraw.h" diff --git a/src/game/hsfmotion.c b/src/game/hsfmotion.c index 2f9d275e..5ba08d51 100644 --- a/src/game/hsfmotion.c +++ b/src/game/hsfmotion.c @@ -1,4 +1,5 @@ #include "game/hsfmotion.h" +#include "game/ClusterExec.h" #include "game/EnvelopeExec.h" #include "game/hsfdraw.h" #include "game/hsfload.h" @@ -11,10 +12,6 @@ static s32 SearchObjectIndex(HsfData *arg0, u32 arg1); static s32 SearchAttributeIndex(HsfData *arg0, u32 arg1); -float GetClusterCurve(HsfTrack*, float); -float GetClusterWeightCurve(HsfTrack*, float); -void ClusterMotionExec(ModelData*); -void ClusterProc(ModelData*); void ShapeProc(HsfData*); MotionData Hu3DMotion[256];