Score class cleanup (#855)

* Cleanup/fixes

* Improve Paint match

* Improve Score::FillArea

* Fix naming

* Fix value
This commit is contained in:
Christian Semmler 2024-04-26 10:58:42 -04:00 committed by GitHub
parent 180a1e6360
commit 19d39394be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 145 additions and 165 deletions

View file

@ -26,19 +26,19 @@ class AmbulanceMissionState : public LegoState {
inline void SetUnknown0x08(undefined4 p_unk0x08) { m_unk0x08 = p_unk0x08; }
inline MxU16 GetColor(MxU8 p_id)
inline MxU16 GetScore(MxU8 p_id)
{
switch (p_id) {
case 1:
return m_color1;
return m_score1;
case 2:
return m_color2;
return m_score2;
case 3:
return m_color3;
return m_score3;
case 4:
return m_color4;
return m_score4;
case 5:
return m_color5;
return m_score5;
default:
return 0;
}
@ -55,11 +55,11 @@ class AmbulanceMissionState : public LegoState {
MxU16 m_unk0x14; // 0x14
MxU16 m_unk0x16; // 0x16
MxU16 m_unk0x18; // 0x18
MxU16 m_color1; // 0x1a
MxU16 m_color2; // 0x1c
MxU16 m_color3; // 0x1e
MxU16 m_color4; // 0x20
MxU16 m_color5; // 0x22
MxU16 m_score1; // 0x1a
MxU16 m_score2; // 0x1c
MxU16 m_score3; // 0x1e
MxU16 m_score4; // 0x20
MxU16 m_score5; // 0x22
};
#endif // AMBULANCEMISSIONSTATE_H

View file

@ -6,11 +6,11 @@
// SIZE 0x20
struct PizzaMissionStateEntry {
public:
undefined2 m_unk0x00;
MxU8 m_id;
undefined m_unk0x03[0x15];
MxU16 m_color;
undefined m_unk0x18[6];
undefined2 m_unk0x00; // 0x00
MxU8 m_id; // 0x02
undefined m_unk0x03[0x15]; // 0x03
MxU16 m_score; // 0x18
undefined m_unk0x18[6]; // 0x1a
};
// VTABLE: LEGO1 0x100d7408
@ -32,7 +32,7 @@ class PizzaMissionState : public LegoState {
MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c
inline MxU16 GetColor(MxU8 p_id) { return GetState(p_id)->m_color; }
inline MxU16 GetScore(MxU8 p_id) { return GetState(p_id)->m_score; }
// SYNTHETIC: LEGO1 0x10039350
// PizzaMissionState::`scalar deleting destructor'

View file

@ -7,11 +7,12 @@
struct RaceStateEntry {
public:
inline MxS16 GetUnknown0x02() { return m_unk0x02; }
inline MxU16 GetScore() { return m_score; }
// TODO: Possibly private
MxU8 m_id; // 0x00
MxS16 m_unk0x02; // 0x02
MxU16 m_color; // 0x04
MxU16 m_score; // 0x04
};
// VTABLE: LEGO1 0x100d5e30
@ -37,7 +38,6 @@ class RaceState : public LegoState {
RaceStateEntry* GetState(MxU8 p_id);
inline MxU16 GetColor(MxU8 p_id) { return GetState(p_id)->m_color; }
inline undefined4 GetUnknown0x28() { return m_unk0x28; }
// SYNTHETIC: LEGO1 0x1000f6f0

View file

@ -13,7 +13,7 @@
class Score : public LegoWorld {
public:
Score();
~Score() override; // vtable+0x00
~Score() override;
MxLong Notify(MxParam& p_param) override; // vtable+0x04
// FUNCTION: LEGO1 0x100010c0
@ -32,24 +32,23 @@ class Score : public LegoWorld {
// SYNTHETIC: LEGO1 0x100011e0
// Score::`scalar deleting destructor'
MxResult Create(MxDSAction& p_dsAction) override; // vtable+18
void ReadyWorld() override; // vtable+50
MxBool VTable0x5c() override; // vtable+5c
MxBool VTable0x64() override; // vtable+64
void Enable(MxBool p_enable) override; // vtable+68
MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18
void ReadyWorld() override; // vtable+0x50
MxBool VTable0x5c() override; // vtable+0x5c
MxBool VTable0x64() override; // vtable+0x64
void Enable(MxBool p_enable) override; // vtable+0x68
void Paint();
MxLong FUN_10001510(MxEndActionNotificationParam& p_param);
MxLong FUN_100016d0(LegoControlManagerEvent& p_param);
void FillArea(MxU32 p_x, MxU32 p_y, MxS16 p_color);
void FillArea(MxU32 i_activity, MxU32 i_actor, MxS16 score);
protected:
LegoGameState::Area m_destLocation;
ScoreState* m_state;
MxU8* m_surface;
private:
void DeleteScript();
LegoGameState::Area m_destLocation; // 0xf8
ScoreState* m_state; // 0xfc
MxU8* m_surface; // 0x100
};
#endif // SCORE_H

View file

@ -24,19 +24,19 @@ class TowTrackMissionState : public LegoState {
MxResult Serialize(LegoFile* p_legoFile) override; // vtable+0x1c
inline MxU16 GetColor(MxU8 p_id)
inline MxU16 GetScore(MxU8 p_id)
{
switch (p_id) {
case 1:
return m_color1;
return m_score1;
case 2:
return m_color2;
return m_score2;
case 3:
return m_color3;
return m_score3;
case 4:
return m_color4;
return m_score4;
case 5:
return m_color5;
return m_score5;
default:
return 0;
}
@ -54,12 +54,11 @@ class TowTrackMissionState : public LegoState {
MxU16 m_unk0x16; // 0x16
MxU16 m_unk0x18; // 0x18
MxU16 m_unk0x1a; // 0x1a
MxU16 m_unk0x1c; // 0x1c
MxU16 m_color1; // 0x1e
MxU16 m_color2; // 0x20
MxU16 m_color3; // 0x22
MxU16 m_color4; // 0x24
MxU16 m_color5; // 0x26
MxU16 m_score1; // 0x1c
MxU16 m_score2; // 0x1e
MxU16 m_score3; // 0x20
MxU16 m_score4; // 0x22
MxU16 m_score5; // 0x24
};
#endif // TOWTRACKMISSIONSTATE_H

View file

@ -605,6 +605,7 @@ MxLong LegoNavController::Notify(MxParam& p_param)
break;
case VK_ESCAPE: {
LegoWorld* currentWorld = CurrentWorld();
if (currentWorld) {
InfocenterState* infocenterState = (InfocenterState*) GameState()->GetState("InfocenterState");
if (infocenterState && infocenterState->GetUnknown0x74() != 8 && currentWorld->VTable0x64()) {

View file

@ -12,11 +12,11 @@ AmbulanceMissionState::AmbulanceMissionState()
m_unk0x16 = 0;
m_unk0x0c = 0;
m_unk0x18 = 0;
m_color1 = 0;
m_color2 = 0;
m_color3 = 0;
m_color4 = 0;
m_color5 = 0;
m_score1 = 0;
m_score2 = 0;
m_score3 = 0;
m_score4 = 0;
m_score5 = 0;
}
// STUB: LEGO1 0x10037440

View file

@ -25,6 +25,7 @@ RaceStateEntry* RaceState::GetState(MxU8 p_id)
if (i >= 5) {
return NULL;
}
if (m_state[i].m_id == p_id) {
return m_state + i;
}

View file

@ -13,11 +13,11 @@ TowTrackMissionState::TowTrackMissionState()
m_unk0x0c = 0;
m_unk0x1a = 0;
m_unk0x10 = 0;
m_unk0x1c = 0;
m_color1 = 0;
m_color2 = 0;
m_color3 = 0;
m_color4 = 0;
m_score1 = 0;
m_score2 = 0;
m_score3 = 0;
m_score4 = 0;
m_score5 = 0;
}
// FUNCTION: LEGO1 0x1004dde0
@ -31,11 +31,11 @@ MxResult TowTrackMissionState::Serialize(LegoFile* p_legoFile)
p_legoFile->Read(&m_unk0x16, sizeof(m_unk0x16));
p_legoFile->Read(&m_unk0x18, sizeof(m_unk0x18));
p_legoFile->Read(&m_unk0x1a, sizeof(m_unk0x1a));
p_legoFile->Read(&m_unk0x1c, sizeof(m_unk0x1c));
p_legoFile->Read(&m_color1, sizeof(m_color1));
p_legoFile->Read(&m_color2, sizeof(m_color2));
p_legoFile->Read(&m_color3, sizeof(m_color3));
p_legoFile->Read(&m_color4, sizeof(m_color4));
p_legoFile->Read(&m_score1, sizeof(m_score1));
p_legoFile->Read(&m_score2, sizeof(m_score2));
p_legoFile->Read(&m_score3, sizeof(m_score3));
p_legoFile->Read(&m_score4, sizeof(m_score4));
p_legoFile->Read(&m_score5, sizeof(m_score5));
}
else if (p_legoFile->IsWriteMode()) {
MxU16 write = m_unk0x12;
@ -53,19 +53,19 @@ MxResult TowTrackMissionState::Serialize(LegoFile* p_legoFile)
write = m_unk0x1a;
p_legoFile->Write(&write, sizeof(m_unk0x12));
write = m_unk0x1c;
write = m_score1;
p_legoFile->Write(&write, sizeof(m_unk0x12));
write = m_color1;
write = m_score2;
p_legoFile->Write(&write, sizeof(m_unk0x12));
write = m_color2;
write = m_score3;
p_legoFile->Write(&write, sizeof(m_unk0x12));
write = m_color3;
write = m_score4;
p_legoFile->Write(&write, sizeof(m_unk0x12));
write = m_color4;
write = m_score5;
p_legoFile->Write(&write, sizeof(m_unk0x12));
}

View file

@ -1,7 +1,9 @@
#include "score.h"
#include "ambulancemissionstate.h"
#include "carracestate.h"
#include "infoscor_actions.h"
#include "jetskiracestate.h"
#include "jukebox.h"
#include "jukebox_actions.h"
#include "legocontrolmanager.h"
@ -39,6 +41,7 @@ Score::~Score()
if (InputManager()->GetWorld() == this) {
InputManager()->ClearWorld();
}
InputManager()->UnRegister(this);
ControlManager()->Unregister(this);
NotificationManager()->Unregister(this);
@ -54,9 +57,9 @@ MxResult Score::Create(MxDSAction& p_dsAction)
ControlManager()->Register(this);
InputManager()->Register(this);
SetIsWorldActive(FALSE);
LegoGameState* gs = GameState();
ScoreState* state = (ScoreState*) gs->GetState("ScoreState");
m_state = state ? state : (ScoreState*) gs->CreateState("ScoreState");
LegoGameState* gameState = GameState();
ScoreState* state = (ScoreState*) gameState->GetState("ScoreState");
m_state = state ? state : (ScoreState*) gameState->CreateState("ScoreState");
GameState()->SetCurrentArea(LegoGameState::e_infoscor);
GameState()->StopArea(LegoGameState::e_previousArea);
}
@ -69,7 +72,7 @@ void Score::DeleteScript()
{
if (m_state->GetTutorialFlag()) {
MxDSAction action;
action.SetObjectId(0x1f5);
action.SetObjectId(InfoscorScript::c_iicc31in_PlayWav);
action.SetAtomId(*g_infoscorScript);
action.SetUnknown24(-2);
DeleteObject(action);
@ -82,18 +85,19 @@ MxLong Score::Notify(MxParam& p_param)
{
MxLong ret = 0;
LegoWorld::Notify(p_param);
if (m_worldStarted) {
switch (((MxNotificationParam&) p_param).GetNotification()) {
case c_notificationStartAction:
ret = 1;
Paint();
ret = 1;
break;
case c_notificationEndAction:
ret = FUN_10001510((MxEndActionNotificationParam&) p_param);
break;
case c_notificationKeyPress:
if (((LegoEventNotificationParam&) p_param).GetKey() == 0x20) {
DeleteScript(); // Shutting down
if (((LegoEventNotificationParam&) p_param).GetKey() == VK_SPACE) {
DeleteScript();
}
ret = 1;
break;
@ -101,16 +105,15 @@ MxLong Score::Notify(MxParam& p_param)
ret = FUN_100016d0((LegoControlManagerEvent&) p_param);
break;
case c_notificationTransitioned:
DeleteObjects(g_infoscorScript, 7, 9);
DeleteObjects(g_infoscorScript, InfoscorScript::c_LegoBox1_Flc, InfoscorScript::c_LegoBox3_Flc);
if (m_destLocation) {
GameState()->SwitchArea(m_destLocation);
}
ret = 1;
break;
default:
break;
}
}
return ret;
}
@ -120,15 +123,15 @@ MxLong Score::FUN_10001510(MxEndActionNotificationParam& p_param)
MxDSAction* action = p_param.GetAction();
if (m_atom == action->GetAtomId()) {
MxU32 id = action->GetObjectId();
switch (action->GetObjectId()) {
case 10:
case InfoscorScript::c_GoTo_HistBook:
m_destLocation = LegoGameState::e_histbook;
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 0x32, 0, 0);
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 50, FALSE, FALSE);
break;
case 0x1f5:
case InfoscorScript::c_iicc31in_PlayWav:
PlayMusic(JukeboxScript::c_InformationCenter_Music);
m_state->SetTutorialFlag(FALSE);
break;
}
}
@ -141,14 +144,14 @@ void Score::ReadyWorld()
LegoWorld::ReadyWorld();
MxDSAction action;
action.SetObjectId(0x1f4);
action.SetObjectId(InfoscorScript::c_nin001pr_RunAnim);
action.SetAtomId(m_atom);
action.SetUnknown84(this);
Start(&action);
if (m_state->GetTutorialFlag()) {
MxDSAction action2;
action.SetObjectId(0x1f5);
MxDSAction action;
action.SetObjectId(InfoscorScript::c_iicc31in_PlayWav);
action.SetAtomId(*g_infoscorScript);
Start(&action);
}
@ -162,51 +165,49 @@ void Score::ReadyWorld()
// FUNCTION: LEGO1 0x100016d0
MxLong Score::FUN_100016d0(LegoControlManagerEvent& p_param)
{
MxS16 l = p_param.GetUnknown0x28();
MxS16 unk0x28 = p_param.GetUnknown0x28();
if (l == 1 || p_param.GetClickedObjectId() == 4) {
if (unk0x28 == 1 || p_param.GetClickedObjectId() == InfoscorScript::c_LegoBox_Ctl) {
switch (p_param.GetClickedObjectId()) {
case InfoscorScript::c_LeftArrow_Ctl:
m_destLocation = LegoGameState::e_infomain;
DeleteScript();
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 0x32, 0, 0);
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 50, FALSE, FALSE);
break;
case InfoscorScript::c_RightArrow_Ctl:
m_destLocation = LegoGameState::e_infodoor;
DeleteScript();
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 0x32, 0, 0);
TransitionManager()->StartTransition(MxTransitionManager::e_mosaic, 50, FALSE, FALSE);
break;
case InfoscorScript::c_Book_Ctl: {
LegoInputManager* im = InputManager();
im->SetUnknown88(TRUE);
im->SetUnknown336(FALSE);
InputManager()->DisableInputProcessing();
DeleteScript();
MxDSAction action;
action.SetObjectId(10);
action.SetObjectId(InfoscorScript::c_GoTo_HistBook);
action.SetAtomId(*g_infoscorScript);
Start(&action);
break;
}
case InfoscorScript::c_LegoBox_Ctl: {
switch (l) {
switch (unk0x28) {
case 1: {
MxDSAction action;
action.SetObjectId(7);
action.SetObjectId(InfoscorScript::c_LegoBox1_Flc);
action.SetAtomId(*g_infoscorScript);
Start(&action);
break;
}
case 2: {
MxDSAction action;
action.SetObjectId(8);
action.SetObjectId(InfoscorScript::c_LegoBox2_Flc);
action.SetAtomId(*g_infoscorScript);
Start(&action);
break;
}
case 3: {
MxDSAction action;
action.SetObjectId(9);
action.SetObjectId(InfoscorScript::c_LegoBox3_Flc);
action.SetAtomId(*g_infoscorScript);
Start(&action);
break;
@ -235,97 +236,74 @@ void Score::Enable(MxBool p_enable)
}
// FUNCTION: LEGO1 0x100019d0
// FUNCTION: BETA10 0x100f47d8
void Score::Paint()
{
LegoTextureInfo* gd = TextureContainer()->Get("bigcube.gif");
LegoTextureInfo* cube = TextureContainer()->Get("bigcube.gif");
if (gd) {
RaceState* l78 = (RaceState*) GameState()->GetState("JetskiRaceState");
RaceState* l70 = (RaceState*) GameState()->GetState("CarRaceState");
TowTrackMissionState* lesi = (TowTrackMissionState*) GameState()->GetState("TowTrackMissionState");
PizzaMissionState* l74 = (PizzaMissionState*) GameState()->GetState("PizzaMissionState");
AmbulanceMissionState* lebp = (AmbulanceMissionState*) GameState()->GetState("AmbulanceMissionState");
if (cube != NULL) {
JetskiRaceState* jetskiRaceState = (JetskiRaceState*) GameState()->GetState("JetskiRaceState");
CarRaceState* carRaceState = (CarRaceState*) GameState()->GetState("CarRaceState");
TowTrackMissionState* towTrackMissionState =
(TowTrackMissionState*) GameState()->GetState("TowTrackMissionState");
PizzaMissionState* pizzaMissionState = (PizzaMissionState*) GameState()->GetState("PizzaMissionState");
AmbulanceMissionState* ambulanceMissionState =
(AmbulanceMissionState*) GameState()->GetState("AmbulanceMissionState");
DDSURFACEDESC desc;
memset(&desc, 0, sizeof(desc));
desc.dwSize = sizeof(desc);
if (gd->m_surface->Lock(NULL, &desc, 0, NULL) == DD_OK) {
if (cube->m_surface->Lock(NULL, &desc, 0, NULL) == DD_OK) {
if (desc.lPitch != desc.dwWidth) {
gd->m_surface->Unlock(desc.lpSurface);
cube->m_surface->Unlock(desc.lpSurface);
return;
}
for (MxU8 id = 1; id <= 5; id++) {
m_surface = (MxU8*) desc.lpSurface;
MxU16 color = 0;
if (l70) {
color = l70->GetColor(id);
}
MxU32 row = id - 1;
FillArea(0, row, color);
color = 0;
if (l78) {
color = l78->GetColor(id);
}
FillArea(1, row, color);
color = 0;
if (l74) {
color = l74->GetColor(id);
}
FillArea(2, row, color);
color = 0;
if (lesi) {
color = lesi->GetColor(id);
}
FillArea(3, row, color);
color = 0;
if (lebp) {
color = lebp->GetColor(id);
}
FillArea(4, row, color);
m_surface = (MxU8*) desc.lpSurface;
for (MxU8 actor = 1; actor <= 5; actor++) {
MxU16 score;
score = carRaceState ? carRaceState->GetState(actor)->GetScore() : 0;
FillArea(0, actor - 1, score);
score = jetskiRaceState ? jetskiRaceState->GetState(actor)->GetScore() : 0;
FillArea(1, actor - 1, score);
score = pizzaMissionState ? pizzaMissionState->GetScore(actor) : 0;
FillArea(2, actor - 1, score);
score = towTrackMissionState ? towTrackMissionState->GetScore(actor) : 0;
FillArea(3, actor - 1, score);
score = ambulanceMissionState ? ambulanceMissionState->GetScore(actor) : 0;
FillArea(4, actor - 1, score);
}
gd->m_surface->Unlock(desc.lpSurface);
gd->m_texture->Changed(TRUE, FALSE);
cube->m_surface->Unlock(desc.lpSurface);
cube->m_texture->Changed(TRUE, FALSE);
m_surface = NULL;
}
}
}
// FUNCTION: LEGO1 0x10001d20
void Score::FillArea(MxU32 p_x, MxU32 p_y, MxS16 p_color)
// FUNCTION: BETA10 0x100f4a52
void Score::FillArea(MxU32 i_activity, MxU32 i_actor, MxS16 score)
{
MxU32 data[24];
data[9] = 0x2b00;
data[10] = 0x5700;
data[11] = 0x8000;
data[19] = 0x2a;
data[12] = 0xab00;
data[13] = 0xd600;
data[20] = 0x27;
data[21] = 0x29;
data[22] = 0x29;
data[23] = 0x2a;
data[4] = 0x2f;
data[5] = 0x56;
data[6] = 0x81;
data[15] = 0x29;
data[16] = 0x27;
data[7] = 0xaa;
data[8] = 0xd4;
data[14] = 0x25;
data[0] = 0x11;
data[17] = 0x28;
data[18] = 0x28;
data[1] = 0x0f;
MxU32 size = data[p_x + 14];
MxU8* ptr = data[p_x + 4] + data[p_y + 9] + m_surface;
MxS32 count = data[p_y + 19];
data[2] = 0x08;
data[3] = 0x05;
MxU32 value = data[p_color];
for (; count > 0; count--) {
memset(ptr++, value, size);
MxS32 local3c[] = {0x2b00, 0x5700, 0x8000, 0xab00, 0xd600};
MxS32 local14[] = {0x2a, 0x27, 0x29, 0x29, 0x2a};
MxS32 local50[] = {0x2f, 0x56, 0x81, 0xaa, 0xd4};
MxS32 local28[] = {0x25, 0x29, 0x27, 0x28, 0x28};
MxS32 local60[] = {0x11, 0x0f, 0x08, 0x05};
MxU8* ptr = m_surface + local3c[i_actor] + local50[i_activity];
MxS32 val = local60[score];
MxS32 size = local28[i_activity];
for (MxS32 i = 0; i < local14[i_actor]; i++) {
memset(ptr, val, size);
ptr += 0x100;
}
}

View file

@ -45,10 +45,9 @@ class LegoContainer {
}
}
// FUNCTION: BETA10 0x1007bc00
inline T* Get(const char* p_name)
{
// TODO: Score::Paint matches better with no `value` on the stack,
// while LegoModelPresenter::CreateROI only matches with `value`
T* value = NULL;
#ifdef COMPAT_MODE

View file

@ -26,3 +26,6 @@ m_AnimTreePtr: "Allow original naming from beta"
m_BADuration: "Allow original naming from beta"
m_assAnimP: "Allow original naming from beta"
m_disAnimP: "Allow original naming from beta"
i_activity: "Allow original naming from beta"
i_actor: "Allow original naming from beta"
score: "Allow original naming from beta"