Implement LegoState::Playlist (#517)

This commit is contained in:
Christian Semmler 2024-02-02 14:09:45 -05:00 committed by GitHub
parent 558bda4dd2
commit b7e274f902
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 104 additions and 56 deletions

View file

@ -30,9 +30,9 @@ public:
inline MxS16 GetInfocenterBufferSize() { return sizeof(m_buffer) / sizeof(m_buffer[0]); }
inline MxStillPresenter* GetInfocenterBufferElement(MxS32 p_index) { return m_buffer[p_index]; }
inline Shuffle& GetUnknown0x08() { return m_unk0x08; }
inline Shuffle& GetUnknown0x14() { return m_unk0x14; }
inline Shuffle& GetUnknown0x68() { return m_unk0x68; }
inline Playlist& GetUnknown0x08() { return m_unk0x08; }
inline Playlist& GetUnknown0x14() { return m_unk0x14; }
inline Playlist& GetUnknown0x68() { return m_unk0x68; }
inline MxU32 GetUnknown0x74() { return m_unk0x74; }
inline void SetUnknown0x74(MxU32 p_unk0x74) { m_unk0x74 = p_unk0x74; }
@ -41,11 +41,11 @@ public:
// InfocenterState::`scalar deleting destructor'
private:
Shuffle m_unk0x08; // 0x08
Shuffle m_unk0x14; // 0x14
Shuffle m_unk0x20[3]; // 0x20
Shuffle m_unk0x44[3]; // 0x44
Shuffle m_unk0x68; // 0x68
Playlist m_unk0x08; // 0x08
Playlist m_unk0x14; // 0x14
Playlist m_unk0x20[3]; // 0x20
Playlist m_unk0x44[3]; // 0x44
Playlist m_unk0x68; // 0x68
MxU32 m_unk0x74; // 0x74
MxStillPresenter* m_buffer[7]; // 0x78
};

View file

@ -45,45 +45,52 @@ public:
// LegoState::`scalar deleting destructor'
// SIZE 0x0c
class Shuffle {
class Playlist {
public:
enum Mode {
e_loop,
e_once,
e_random,
e_loopSkipFirst
};
// FUNCTION: LEGO1 0x10017c00
Shuffle()
Playlist()
{
m_objectIds = NULL;
m_length = 0;
m_unk0x06 = 0;
m_unk0x08 = 0;
m_mode = e_loop;
m_nextIndex = 0;
}
Shuffle(MxU32* p_objectIds, MxU16 p_length)
Playlist(MxU32* p_objectIds, MxS16 p_length)
{
m_objectIds = p_objectIds;
m_length = p_length;
m_unk0x06 = 0;
m_unk0x08 = 0;
m_mode = e_loop;
m_nextIndex = 0;
}
// FUNCTION: LEGO1 0x10071800
Shuffle& operator=(const Shuffle& p_shuffle)
Playlist& operator=(const Playlist& p_shuffle)
{
m_objectIds = p_shuffle.m_objectIds;
m_length = p_shuffle.m_length;
m_unk0x08 = p_shuffle.m_unk0x08;
m_unk0x06 = p_shuffle.m_unk0x06;
m_nextIndex = p_shuffle.m_nextIndex;
m_mode = p_shuffle.m_mode;
return *this;
}
MxU32 FUN_10014d00();
MxBool FUN_10014de0(MxU32 p_objectId);
MxU32 Next();
MxBool Contains(MxU32 p_objectId);
inline void SetUnknown0x08(MxU16 p_unk0x08) { m_unk0x08 = p_unk0x08; }
inline void SetUnknown0x08(MxS16 p_unk0x08) { m_nextIndex = p_unk0x08; }
private:
MxU32* m_objectIds; // 0x00
MxU16 m_length; // 0x04
undefined2 m_unk0x06; // 0x06
MxU16 m_unk0x08; // 0x08
MxU32* m_objectIds; // 0x00
MxS16 m_length; // 0x04
MxS16 m_mode; // 0x06
MxS16 m_nextIndex; // 0x08
};
};

View file

@ -29,7 +29,7 @@ public:
// LegoVehicleBuildState::`scalar deleting destructor'
private:
Shuffle m_unk0x08[4]; // 0x08
Playlist m_unk0x08[4]; // 0x08
// This can be one of the following:
// * LegoRaceCarBuildState

View file

@ -36,9 +36,9 @@ public:
MxBool FUN_1002d0c0(const MxAtomId& p_atom, MxU32 p_objectId);
private:
Shuffle m_unk0x08[3]; // 0x08
MxS16 m_unk0x2c; // 0x2c
MxBool m_active; // 0x2e
Playlist m_unk0x08[3]; // 0x08
MxS16 m_unk0x2c; // 0x2c
MxBool m_active; // 0x2e
};
#endif // RADIOSTATE_H

View file

@ -1,18 +1,59 @@
#include "legostate.h"
DECOMP_SIZE_ASSERT(LegoState, 0x08)
DECOMP_SIZE_ASSERT(LegoState::Shuffle, 0x0c)
#include <stdlib.h>
// STUB: LEGO1 0x10014d00
MxU32 LegoState::Shuffle::FUN_10014d00()
DECOMP_SIZE_ASSERT(LegoState, 0x08)
DECOMP_SIZE_ASSERT(LegoState::Playlist, 0x0c)
// FUNCTION: LEGO1 0x10014d00
MxU32 LegoState::Playlist::Next()
{
// TODO
return m_objectIds[0];
MxU32 objectId;
switch (m_mode) {
case e_loop:
objectId = m_objectIds[m_nextIndex];
if (m_nextIndex - m_length == -1) {
m_nextIndex = 0;
}
else {
m_nextIndex++;
}
break;
case e_once:
objectId = m_objectIds[m_nextIndex];
if (m_length > m_nextIndex + 1) {
m_nextIndex++;
}
break;
case e_random:
m_nextIndex = rand() % m_length;
objectId = m_objectIds[m_nextIndex];
break;
case e_loopSkipFirst:
objectId = m_objectIds[m_nextIndex];
if (m_nextIndex - m_length == -1) {
m_nextIndex = 1;
}
else {
m_nextIndex++;
}
}
return objectId;
}
// STUB: LEGO1 0x10014de0
MxBool LegoState::Shuffle::FUN_10014de0(MxU32 p_objectId)
// FUNCTION: LEGO1 0x10014de0
MxBool LegoState::Playlist::Contains(MxU32 p_objectId)
{
// TODO
for (MxS16 i = 0; i < m_length; i++) {
if (m_objectIds[i] == p_objectId) {
return TRUE;
}
}
return FALSE;
}

View file

@ -538,7 +538,7 @@ MxU8 Infocenter::HandleClick(LegoControlManagerEvent& p_param)
m_transitionDestination = 5;
}
else {
MxU32 objectId = m_infocenterState->GetUnknown0x68().FUN_10014d00();
MxU32 objectId = m_infocenterState->GetUnknown0x68().Next();
PlayAction((InfomainScript) objectId);
}
@ -553,7 +553,7 @@ MxU8 Infocenter::HandleClick(LegoControlManagerEvent& p_param)
m_transitionDestination = 13;
}
else {
MxU32 objectId = m_infocenterState->GetUnknown0x68().FUN_10014d00();
MxU32 objectId = m_infocenterState->GetUnknown0x68().Next();
PlayAction((InfomainScript) objectId);
}
@ -658,10 +658,10 @@ MxLong Infocenter::HandleNotification0(MxNotificationParam& p_param)
InfomainScript objectId;
if (GameState()->GetUnknown10()) {
objectId = (InfomainScript) m_infocenterState->GetUnknown0x14().FUN_10014d00();
objectId = (InfomainScript) m_infocenterState->GetUnknown0x14().Next();
}
else {
objectId = (InfomainScript) m_infocenterState->GetUnknown0x08().FUN_10014d00();
objectId = (InfomainScript) m_infocenterState->GetUnknown0x08().Next();
}
PlayAction(objectId);

View file

@ -84,26 +84,26 @@ Infocenter::InfomainScript g_unk0x100f7760[2] = {Infocenter::c_bricksterDialogue
// FUNCTION: LEGO1 0x10071600
InfocenterState::InfocenterState()
{
m_unk0x08 = LegoState::Shuffle((MxU32*) g_unk0x100f76a8, sizeof(g_unk0x100f76a8) / sizeof(g_unk0x100f76a8[0]));
m_unk0x08 = LegoState::Playlist((MxU32*) g_unk0x100f76a8, sizeof(g_unk0x100f76a8) / sizeof(g_unk0x100f76a8[0]));
m_unk0x14 = LegoState::Shuffle((MxU32*) g_unk0x100f76e0, sizeof(g_unk0x100f76e0) / sizeof(g_unk0x100f76e0[0]) - 1);
m_unk0x14 = LegoState::Playlist((MxU32*) g_unk0x100f76e0, sizeof(g_unk0x100f76e0) / sizeof(g_unk0x100f76e0[0]) - 1);
m_unk0x20[0] =
LegoState::Shuffle((MxU32*) g_unk0x100f76f8, sizeof(g_unk0x100f76f8) / sizeof(g_unk0x100f76f8[0]) - 1);
LegoState::Playlist((MxU32*) g_unk0x100f76f8, sizeof(g_unk0x100f76f8) / sizeof(g_unk0x100f76f8[0]) - 1);
m_unk0x20[1] =
LegoState::Shuffle((MxU32*) g_unk0x100f7710, sizeof(g_unk0x100f7710) / sizeof(g_unk0x100f7710[0]) - 1);
LegoState::Playlist((MxU32*) g_unk0x100f7710, sizeof(g_unk0x100f7710) / sizeof(g_unk0x100f7710[0]) - 1);
m_unk0x20[2] = LegoState::Shuffle((MxU32*) g_unk0x100f7720, sizeof(g_unk0x100f7720) / sizeof(g_unk0x100f7720[0]));
m_unk0x20[2] = LegoState::Playlist((MxU32*) g_unk0x100f7720, sizeof(g_unk0x100f7720) / sizeof(g_unk0x100f7720[0]));
m_unk0x44[0] = LegoState::Shuffle((MxU32*) g_unk0x100f7730, sizeof(g_unk0x100f7730) / sizeof(g_unk0x100f7730[0]));
m_unk0x44[0] = LegoState::Playlist((MxU32*) g_unk0x100f7730, sizeof(g_unk0x100f7730) / sizeof(g_unk0x100f7730[0]));
m_unk0x44[1] = LegoState::Shuffle((MxU32*) g_unk0x100f7740, sizeof(g_unk0x100f7740) / sizeof(g_unk0x100f7740[0]));
m_unk0x44[1] = LegoState::Playlist((MxU32*) g_unk0x100f7740, sizeof(g_unk0x100f7740) / sizeof(g_unk0x100f7740[0]));
m_unk0x44[2] =
LegoState::Shuffle((MxU32*) g_unk0x100f7750, sizeof(g_unk0x100f7750) / sizeof(g_unk0x100f7750[0]) - 1);
LegoState::Playlist((MxU32*) g_unk0x100f7750, sizeof(g_unk0x100f7750) / sizeof(g_unk0x100f7750[0]) - 1);
m_unk0x68 = LegoState::Shuffle((MxU32*) g_unk0x100f7760, sizeof(g_unk0x100f7760) / sizeof(g_unk0x100f7760[0]));
m_unk0x68 = LegoState::Playlist((MxU32*) g_unk0x100f7760, sizeof(g_unk0x100f7760) / sizeof(g_unk0x100f7760[0]));
memset(m_buffer, 0, sizeof(m_buffer));
}

View file

@ -53,13 +53,13 @@ RadioState::RadioState()
MxS32 random = rand();
m_unk0x2c = random % 3;
m_unk0x08[0] = LegoState::Shuffle((MxU32*) g_unk0x100f3218, sizeof(g_unk0x100f3218) / sizeof(g_unk0x100f3218[0]));
m_unk0x08[0] = LegoState::Playlist((MxU32*) g_unk0x100f3218, sizeof(g_unk0x100f3218) / sizeof(g_unk0x100f3218[0]));
m_unk0x08[0].SetUnknown0x08(rand() % (sizeof(g_unk0x100f3218) / sizeof(g_unk0x100f3218[0])));
m_unk0x08[1] = LegoState::Shuffle((MxU32*) g_unk0x100f3230, sizeof(g_unk0x100f3230) / sizeof(g_unk0x100f3230[0]));
m_unk0x08[1] = LegoState::Playlist((MxU32*) g_unk0x100f3230, sizeof(g_unk0x100f3230) / sizeof(g_unk0x100f3230[0]));
m_unk0x08[1].SetUnknown0x08(rand() % (sizeof(g_unk0x100f3230) / sizeof(g_unk0x100f3230[0])));
m_unk0x08[2] = LegoState::Shuffle((MxU32*) g_unk0x100f3268, sizeof(g_unk0x100f3268) / sizeof(g_unk0x100f3268[0]));
m_unk0x08[2] = LegoState::Playlist((MxU32*) g_unk0x100f3268, sizeof(g_unk0x100f3268) / sizeof(g_unk0x100f3268[0]));
m_unk0x08[2].SetUnknown0x08(rand() % (sizeof(g_unk0x100f3268) / sizeof(g_unk0x100f3268[0])));
m_active = FALSE;
@ -81,7 +81,7 @@ MxU32 RadioState::FUN_1002d090()
m_unk0x2c++;
}
return m_unk0x08[m_unk0x2c].FUN_10014d00();
return m_unk0x08[m_unk0x2c].Next();
}
// FUNCTION: LEGO1 0x1002d0c0
@ -89,7 +89,7 @@ MxBool RadioState::FUN_1002d0c0(const MxAtomId& p_atom, MxU32 p_objectId)
{
if (*g_jukeboxScript == p_atom) {
for (MxS16 i = 0; i < 3; i++) {
if (m_unk0x08[i].FUN_10014de0(p_objectId)) {
if (m_unk0x08[i].Contains(p_objectId)) {
return TRUE;
}
}