Implement LegoRaceCar::HandleSkeletonKicks and dependents

This commit is contained in:
jonschz 2024-07-09 22:03:29 +02:00
parent afa5b90117
commit ec014bc075
6 changed files with 107 additions and 13 deletions

View File

@ -52,6 +52,9 @@ class CarRace : public LegoRace {
MxLong HandleEndAction(MxEndActionNotificationParam&) override; // vtable+0x74
MxLong HandleType0Notification(MxNotificationParam&) override; // vtable+0x78
// FUNCTION: BETA10 0x100cd060
undefined4 GetUnk0x150() { return m_unk0x150; }
// SYNTHETIC: LEGO1 0x10016c70
// CarRace::`scalar deleting destructor'

View File

@ -4,12 +4,24 @@
#include "legocarraceactor.h"
#include "legoracemap.h"
#define LEGORACECAR_UNKNOWN_STATE 0
#define LEGORACECAR_KICK1 2 // name guessed
#define LEGORACECAR_KICK2 4 // name validated by BETA10 0x100cb659
// SIZE 0x08
struct EdgeReference {
const char* m_name; // 0x00
LegoPathBoundary* m_data; // 0x04
};
// SIZE 0x10
struct SkeletonKickPhase {
EdgeReference* m_edgeRef;
float m_lower;
float m_upper;
unsigned char m_userState;
};
// VTABLE: LEGO1 0x100d58a0 LegoRaceActor
// VTABLE: LEGO1 0x100d58a8 LegoAnimActor
// VTABLE: LEGO1 0x100d58b8 LegoPathActor
@ -59,7 +71,7 @@ class LegoRaceCar : public LegoCarRaceActor, public LegoRaceMap {
virtual void SetMaxLinearVelocity(float p_maxLinearVelocity);
virtual void FUN_10012ff0(float);
virtual MxBool FUN_10013130(float);
virtual MxS32 HandleSkeletonKicks(float);
// SYNTHETIC: LEGO1 0x10014240
// LegoRaceCar::`scalar deleting destructor'
@ -74,7 +86,9 @@ class LegoRaceCar : public LegoCarRaceActor, public LegoRaceMap {
LegoPathBoundary* m_unk0x7c; // 0x7c
static EdgeReference g_edgeReferences[];
static const EdgeReference* g_pEdgeReferences;
static const SkeletonKickPhase g_skeletonKickPhases[]; // TODO: better name
static const char* g_soundSke13;
};
#endif // LEGORACERS_H

View File

@ -12,8 +12,10 @@ class RaceSkel : public LegoAnimActor {
public:
RaceSkel();
void GetCurrentAnimData(float*, float*);
private:
undefined4 m_unk0x1c; // 0x1c
float m_animPosition; // 0x1c
};
#endif // RACESKEL_H

View File

@ -1,15 +1,21 @@
#include "legoracers.h"
#include "anim/legoanim.h"
#include "carrace.h"
#include "define.h"
#include "legocachesoundmanager.h"
#include "legocameracontroller.h"
#include "legorace.h"
#include "legosoundmanager.h"
#include "misc.h"
#include "mxdebug.h"
#include "mxmisc.h"
#include "mxnotificationmanager.h"
#include "mxutilities.h"
#include "raceskel.h"
DECOMP_SIZE_ASSERT(EdgeReference, 0x08)
DECOMP_SIZE_ASSERT(SkeletonKickPhase, 0x10)
DECOMP_SIZE_ASSERT(LegoRaceCar, 0x200)
// GLOBAL: LEGO1 0x100f0a20
@ -41,7 +47,24 @@ EdgeReference LegoRaceCar::g_edgeReferences[] = {
};
// GLOBAL: LEGO1 0x100f0a50
const EdgeReference* LegoRaceCar::g_pEdgeReferences = g_edgeReferences;
const SkeletonKickPhase LegoRaceCar::g_skeletonKickPhases[] = {
{&LegoRaceCar::g_edgeReferences[0], 0.1, 0.2, LEGORACECAR_KICK2},
{&LegoRaceCar::g_edgeReferences[1], 0.2, 0.3, LEGORACECAR_KICK2},
{&LegoRaceCar::g_edgeReferences[2], 0.3, 0.4, LEGORACECAR_KICK2},
{&LegoRaceCar::g_edgeReferences[2], 0.6, 0.7, LEGORACECAR_KICK1},
{&LegoRaceCar::g_edgeReferences[1], 0.7, 0.8, LEGORACECAR_KICK1},
{&LegoRaceCar::g_edgeReferences[0], 0.8, 0.9, LEGORACECAR_KICK1},
{&LegoRaceCar::g_edgeReferences[3], 0.1, 0.2, LEGORACECAR_KICK1},
{&LegoRaceCar::g_edgeReferences[4], 0.2, 0.3, LEGORACECAR_KICK1},
{&LegoRaceCar::g_edgeReferences[5], 0.3, 0.4, LEGORACECAR_KICK1},
{&LegoRaceCar::g_edgeReferences[5], 0.6, 0.7, LEGORACECAR_KICK2},
{&LegoRaceCar::g_edgeReferences[4], 0.7, 0.8, LEGORACECAR_KICK2},
{&LegoRaceCar::g_edgeReferences[3], 0.8, 0.9, LEGORACECAR_KICK2},
};
// GLOBAL: LEGO1 0x100f0b70
// STRING: LEGO1 0x100f08bc
const char* LegoRaceCar::g_soundSke13 = "ske13";
// FUNCTION: LEGO1 0x10012950
LegoRaceCar::LegoRaceCar()
@ -140,13 +163,11 @@ void LegoRaceCar::FUN_10012ff0(float p_param)
LegoAnimActorStruct* a; // called `a` in BETA10
float deltaTime;
if (m_userState == 2) {
if (m_userState == LEGORACECAR_KICK1) {
a = m_unk0x70;
}
else {
// TODO: Possibly an enum?
const char legoracecarKick2 = 4; // original name: LEGORACECAR_KICK2
assert(m_userState == legoracecarKick2);
assert(m_userState == LEGORACECAR_KICK2);
a = m_unk0x74;
}
@ -156,7 +177,7 @@ void LegoRaceCar::FUN_10012ff0(float p_param)
deltaTime = p_param - m_unk0x58;
if (a->GetDuration() <= deltaTime || deltaTime < 0.0) {
if (m_userState == 2) {
if (m_userState == LEGORACECAR_KICK1) {
LegoEdge** edges = m_unk0x78->GetEdges();
m_destEdge = (LegoUnknown100db7f4*) (edges[2]);
m_boundary = m_unk0x78;
@ -167,7 +188,7 @@ void LegoRaceCar::FUN_10012ff0(float p_param)
m_boundary = m_unk0x7c;
}
m_userState = 0;
m_userState = LEGORACECAR_UNKNOWN_STATE;
}
else if (a->GetAnimTreePtr()->GetCamAnim()) {
MxMatrix transformationMatrix;
@ -189,10 +210,50 @@ void LegoRaceCar::FUN_10012ff0(float p_param)
}
}
// STUB: LEGO1 0x10013130
MxBool LegoRaceCar::FUN_10013130(float)
// FUNCTION: LEGO1 0x10013130
// FUNCTION: BETA10 0x100cce50
MxS32 LegoRaceCar::HandleSkeletonKicks(float p_param1)
{
// TODO
const SkeletonKickPhase* current = g_skeletonKickPhases;
// TODO: Type is guesswork so far
CarRace* r = (CarRace*) CurrentWorld(); // called `r` in BETA10
assert(r);
RaceSkel* s = (RaceSkel*) r->GetUnk0x150(); // called `s` in BETA10
assert(s);
float skeletonCurAnimPosition;
float skeletonCurAnimDuration;
s->GetCurrentAnimData(&skeletonCurAnimPosition, &skeletonCurAnimDuration);
float skeletonCurAnimPhase = skeletonCurAnimPosition / skeletonCurAnimDuration;
for (MxS32 i = 0; i < sizeOfArray(g_skeletonKickPhases); i++) {
if (m_boundary == current->m_edgeRef->m_data && current->m_lower <= skeletonCurAnimPhase &&
skeletonCurAnimPhase <= current->m_upper) {
m_userState = current->m_userState;
}
current = &current[1];
}
if (m_userState != LEGORACECAR_KICK1 && m_userState != LEGORACECAR_KICK2) {
MxTrace(
// STRING: BETA10 0x101f64c8
"Got kicked in boundary %s %d %g:%g %g\n",
// TODO: same as in above comparison
m_boundary->GetName(),
skeletonCurAnimPosition,
skeletonCurAnimDuration,
skeletonCurAnimPhase
);
return FALSE;
}
m_unk0x58 = p_param1;
SoundManager()->GetCacheSoundManager()->Play(g_soundSke13, NULL, FALSE);
return TRUE;
}

View File

@ -1,5 +1,7 @@
#include "raceskel.h"
#include <cassert>
DECOMP_SIZE_ASSERT(RaceSkel, 0x178)
// STUB: LEGO1 0x100719b0
@ -7,3 +9,13 @@ RaceSkel::RaceSkel()
{
// TODO
}
// FUNCTION: LEGO1 0x10071cb0
// FUNCTION: BETA10 0x100f158b
void RaceSkel::GetCurrentAnimData(float* p_outCurAnimPosition, float* p_outCurAnimDuration)
{
*p_outCurAnimPosition = m_animPosition;
assert(m_curAnim >= 0);
*p_outCurAnimDuration = m_animMaps[m_curAnim]->GetDuration();
}

View File

@ -43,6 +43,8 @@ class LegoWEGEdge : public LegoWEEdge {
LegoU32 GetFlag0x10() { return m_flags & c_bit5 ? FALSE : TRUE; }
Mx4DPointFloat* GetUnknown0x14() { return &m_unk0x14; }
Mx4DPointFloat* GetEdgeNormal(int index) { return &m_edgeNormals[index]; }
// FUNCTION: BETA10 0x1001c9b0
LegoChar* GetName() { return m_name; }
void SetFlag0x10(LegoU32 p_disable)