Implement/match LegoPlantManager::ScheduleAnimation (#1051)

* Implement/match LegoPlantManager::ScheduleAnimation

* Add assert
This commit is contained in:
Christian Semmler 2024-07-01 16:14:04 -07:00 committed by GitHub
parent a21fd5975c
commit 9ba05d021d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 13 deletions

View file

@ -45,7 +45,7 @@ class LegoBuildingManager : public MxCore {
struct AnimEntry { struct AnimEntry {
LegoEntity* m_entity; // 0x00 LegoEntity* m_entity; // 0x00
LegoROI* m_roi; // 0x04 LegoROI* m_roi; // 0x04
LegoTime m_time; // 0x08 MxLong m_time; // 0x08
float m_unk0x0c; // 0x0c float m_unk0x0c; // 0x0c
MxBool m_muted; // 0x10 MxBool m_muted; // 0x10
}; };
@ -81,7 +81,7 @@ class LegoBuildingManager : public MxCore {
MxBool FUN_10030000(LegoEntity* p_entity); MxBool FUN_10030000(LegoEntity* p_entity);
MxBool FUN_10030030(MxS32 p_index); MxBool FUN_10030030(MxS32 p_index);
MxBool FUN_10030110(LegoBuildingInfo* p_data); MxBool FUN_10030110(LegoBuildingInfo* p_data);
void ScheduleAnimation(LegoEntity* p_entity, MxU32 p_length, MxBool p_haveSound, MxBool p_unk0x28); void ScheduleAnimation(LegoEntity* p_entity, MxLong p_length, MxBool p_haveSound, MxBool p_unk0x28);
void FUN_10030590(); void FUN_10030590();
void AdjustHeight(MxS32 p_index); void AdjustHeight(MxS32 p_index);
MxResult FUN_10030630(); MxResult FUN_10030630();

View file

@ -15,6 +15,13 @@ class LegoWorld;
// SIZE 0x2c // SIZE 0x2c
class LegoPlantManager : public MxCore { class LegoPlantManager : public MxCore {
public: public:
// SIZE 0x0c
struct AnimEntry {
LegoEntity* m_entity; // 0x00
LegoROI* m_roi; // 0x04
MxLong m_time; // 0x08
};
LegoPlantManager(); LegoPlantManager();
~LegoPlantManager() override; // vtable+0x00 ~LegoPlantManager() override; // vtable+0x00
@ -40,6 +47,7 @@ class LegoPlantManager : public MxCore {
MxU32 GetAnimationId(LegoEntity* p_entity); MxU32 GetAnimationId(LegoEntity* p_entity);
MxU32 GetSoundId(LegoEntity* p_entity, MxBool p_state); MxU32 GetSoundId(LegoEntity* p_entity, MxBool p_state);
MxBool FUN_10026c50(LegoEntity* p_entity); MxBool FUN_10026c50(LegoEntity* p_entity);
void ScheduleAnimation(LegoEntity* p_entity, MxLong p_length);
void FUN_10027120(); void FUN_10027120();
static void SetCustomizeAnimFile(const char* p_value); static void SetCustomizeAnimFile(const char* p_value);
@ -54,6 +62,7 @@ class LegoPlantManager : public MxCore {
void FUN_10026860(MxS32 p_index); void FUN_10026860(MxS32 p_index);
LegoPlantInfo* GetInfo(LegoEntity* p_entity); LegoPlantInfo* GetInfo(LegoEntity* p_entity);
MxBool FUN_10026c80(MxS32 p_index); MxBool FUN_10026c80(MxS32 p_index);
void FUN_100271b0(LegoEntity* p_entity, MxS32 p_adjust);
static char* g_customizeAnimFile; static char* g_customizeAnimFile;
static MxS32 g_maxMove[4]; static MxS32 g_maxMove[4];
@ -61,9 +70,9 @@ class LegoPlantManager : public MxCore {
MxS32 m_worldId; // 0x08 MxS32 m_worldId; // 0x08
undefined m_unk0x0c; // 0x0c undefined m_unk0x0c; // 0x0c
undefined* m_unk0x10[5]; // 0x10 AnimEntry* m_entries[5]; // 0x10
MxS8 m_unk0x24; // 0x24 MxS8 m_numEntries; // 0x24
undefined4 m_unk0x28; // 0x28 LegoWorld* m_world; // 0x28
}; };
#endif // LEGOPLANTMANAGER_H #endif // LEGOPLANTMANAGER_H

View file

@ -613,7 +613,7 @@ MxBool LegoBuildingManager::FUN_10030110(LegoBuildingInfo* p_data)
} }
// FUNCTION: LEGO1 0x10030150 // FUNCTION: LEGO1 0x10030150
void LegoBuildingManager::ScheduleAnimation(LegoEntity* p_entity, MxU32 p_length, MxBool p_haveSound, MxBool p_unk0x28) void LegoBuildingManager::ScheduleAnimation(LegoEntity* p_entity, MxLong p_length, MxBool p_haveSound, MxBool p_unk0x28)
{ {
m_world = CurrentWorld(); m_world = CurrentWorld();
@ -633,7 +633,7 @@ void LegoBuildingManager::ScheduleAnimation(LegoEntity* p_entity, MxU32 p_length
entry->m_entity = p_entity; entry->m_entity = p_entity;
entry->m_roi = p_entity->GetROI(); entry->m_roi = p_entity->GetROI();
entry->m_time = Timer()->GetTime() + p_length + 1000; entry->m_time = Timer()->GetTime() + p_length + 1000;
entry->m_unk0x0c = entry->m_roi->GetLocal2World()[3][1]; entry->m_unk0x0c = entry->m_roi->GetWorldPosition()[1];
entry->m_muted = p_haveSound == FALSE; entry->m_muted = p_haveSound == FALSE;
FUN_100307b0(p_entity, -2); FUN_100307b0(p_entity, -2);
} }

View file

@ -8,6 +8,9 @@
#include "legoworld.h" #include "legoworld.h"
#include "misc.h" #include "misc.h"
#include "misc/legostorage.h" #include "misc/legostorage.h"
#include "mxmisc.h"
#include "mxticklemanager.h"
#include "mxtimer.h"
#include "scripts.h" #include "scripts.h"
#include "sndanim_actions.h" #include "sndanim_actions.h"
#include "viewmanager/viewmanager.h" #include "viewmanager/viewmanager.h"
@ -15,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
DECOMP_SIZE_ASSERT(LegoPlantManager, 0x2c) DECOMP_SIZE_ASSERT(LegoPlantManager, 0x2c)
DECOMP_SIZE_ASSERT(LegoPlantManager::AnimEntry, 0x0c)
// GLOBAL: LEGO1 0x100f1660 // GLOBAL: LEGO1 0x100f1660
const char* g_plantLodNames[4][5] = { const char* g_plantLodNames[4][5] = {
@ -73,7 +77,7 @@ void LegoPlantManager::Init()
m_worldId = -1; m_worldId = -1;
m_unk0x0c = 0; m_unk0x0c = 0;
m_unk0x24 = 0; m_numEntries = 0;
} }
// FUNCTION: LEGO1 0x10026360 // FUNCTION: LEGO1 0x10026360
@ -96,11 +100,11 @@ void LegoPlantManager::Reset(MxS32 p_worldId)
MxU32 i; MxU32 i;
DeleteObjects(g_sndAnimScript, SndanimScript::c_AnimC1, SndanimScript::c_AnimBld18); DeleteObjects(g_sndAnimScript, SndanimScript::c_AnimC1, SndanimScript::c_AnimBld18);
for (i = 0; i < m_unk0x24; i++) { for (i = 0; i < m_numEntries; i++) {
delete m_unk0x10[i]; delete m_entries[i];
} }
m_unk0x24 = 0; m_numEntries = 0;
for (i = 0; i < sizeOfArray(g_plantInfo); i++) { for (i = 0; i < sizeOfArray(g_plantInfo); i++) {
RemovePlant(i, p_worldId); RemovePlant(i, p_worldId);
@ -499,11 +503,28 @@ MxBool LegoPlantManager::FUN_10026c80(MxS32 p_index)
return result; return result;
} }
// FUNCTION: LEGO1 0x10026d70
void LegoPlantManager::ScheduleAnimation(LegoEntity* p_entity, MxLong p_length)
{
m_world = CurrentWorld();
if (m_numEntries == 0) {
TickleManager()->RegisterClient(this, 50);
}
AnimEntry* entry = m_entries[m_numEntries] = new AnimEntry;
m_numEntries++;
entry->m_entity = p_entity;
entry->m_roi = p_entity->GetROI();
entry->m_time = Timer()->GetTime() + p_length + 1000;
FUN_100271b0(p_entity, -1);
}
// STUB: LEGO1 0x10026e00 // STUB: LEGO1 0x10026e00
MxResult LegoPlantManager::Tickle() MxResult LegoPlantManager::Tickle()
{ {
// TODO return SUCCESS;
return 0;
} }
// FUNCTION: LEGO1 0x10027120 // FUNCTION: LEGO1 0x10027120
@ -526,3 +547,22 @@ void LegoPlantManager::FUN_10027120()
} }
} }
} }
// FUNCTION: LEGO1 0x100271b0
void LegoPlantManager::FUN_100271b0(LegoEntity* p_entity, MxS32 p_adjust)
{
LegoPlantInfo* info = GetInfo(p_entity);
if (info != NULL) {
if (info->m_unk0x16 < 0) {
info->m_unk0x16 = g_unk0x100f16c0[info->m_variant];
}
if (info->m_unk0x16 > 0) {
info->m_unk0x16 += p_adjust;
if (info->m_unk0x16 <= 1 && p_adjust < 0) {
info->m_unk0x16 = 0;
}
}
}
}