Skip to content

Commit

Permalink
Some more progress on PProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed May 19, 2024
1 parent e49d678 commit 4a0df24
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 22 deletions.
3 changes: 1 addition & 2 deletions OpenJPOG/Source/States/AFrontEndState.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ class AFrontendState : public ARootState

protected:
static inline int sm_iFERefCount = 0;
};

};
58 changes: 42 additions & 16 deletions OpenJPOG/Source/States/ARootState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ TOSHI_NAMESPACE_USING

IMPLEMENT_DYNAMIC(ARootState, TObject)

ARootState::ARootState()
{
m_pParent = TNULL;
m_pChild = TNULL;
m_bAllowExit = TTRUE;
m_bHasControl = TFALSE;
}

void ARootState::OnActivate()
{
}
Expand Down Expand Up @@ -32,7 +40,7 @@ void ARootState::TransferControl(ARootState* a_pState)
OnDeactivate();
}
else {
ExplicitDelete();
m_pChild->ExplicitDelete();
}
m_pChild = a_pState;
a_pState->m_pParent = this;
Expand All @@ -42,6 +50,15 @@ void ARootState::TransferControl(ARootState* a_pState)

void ARootState::RemoveSelf()
{
ExplicitDelete();
if (m_pParent) {
m_pParent->m_pChild = TNULL;
if (!m_bHasControl) {
m_pParent->OnActivate();
return;
}
TWARNING("Not implemented: AGUIGameHUD::OnActivate(&this->m_pParent->m_oGameHUD);");
}
}

ARootState* ARootState::ReturnToState(const TClass& a_rStateClass)
Expand Down Expand Up @@ -75,32 +92,41 @@ TBOOL ARootState::AddChild(ARootState& a_rState)

TBOOL ARootState::RemoveChild()
{
return TBOOL();
if (m_pChild) {
m_pChild = TNULL;
ExplicitDelete();
if (!m_bHasControl) {
OnActivate();
}
else {
TWARNING("Not implemented: AGUIGameHUD::OnActivate(&this->m_oGameHUD);");
}
return TTRUE;
}
return TFALSE;
}

ARootState& ARootState::GetCurrent()
{
ARootState* i;
for (i = this; i->m_pChild != TNULL; i = i->m_pChild) {
if (i->m_pChild == TNULL) {
return *i;
}
}
return *i;
ARootState* current;
for (current = this; current->m_pChild != TNULL; current = current->m_pChild);
return *current;
}

void ARootState::ExplicitDelete()
{
ARootState* i;
for (i = this; i->m_pChild != TNULL; i = i->m_pChild);
i->OnDeactivate();
ARootState* parent = m_pParent;

ARootState* current;
for (current = this; current->m_pChild != TNULL; current = current->m_pChild);
current->OnDeactivate();

for (ARootState* j = i; j != m_pParent; j = j->m_pParent) {
ARootState* j;
while (j = current, j != parent) {
current = j->m_pParent;
j->OnRemoval();
j->m_pParent = TNULL;
j->m_pChild = TNULL;
if (j) {
delete j;
}
delete j;
}
}
3 changes: 3 additions & 0 deletions OpenJPOG/Source/States/ARootState.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ARootState : public Toshi::TObject

public:

ARootState();

virtual ~ARootState() = default;
//virtual void ProcessControllerLoss();
//virtual void ProcessLostInput();
Expand Down Expand Up @@ -42,6 +44,7 @@ class ARootState : public Toshi::TObject
private:
ARootState* m_pParent; // 0x4
ARootState* m_pChild; // 0x8
TBOOL m_bAllowExit; // 0xC
TBOOL m_bHasControl; // 0xE
AGUIGameHUD m_oHUDState; // 0x10
};
Expand Down
3 changes: 3 additions & 0 deletions OpenJPOG/Source/Tasks/AFrontEndController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "AFrontEndController.h"

IMPLEMENT_DYNCREATE(AFrontEndController, Toshi::TTask)
7 changes: 7 additions & 0 deletions OpenJPOG/Source/Tasks/AFrontEndController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "TKernel/TTask.h"

class AFrontEndController : public Toshi::TTask
{
DECLARE_DYNAMIC(AFrontEndController)
};
3 changes: 2 additions & 1 deletion OpenJPOG/Source/Tasks/ARootStateController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ TBOOL ARootStateController::OnCreate()
TBOOL ARootStateController::OnUpdate(TFLOAT a_fDeltaTime)
{
if (m_pBaseAppState) {

ARootState currentState = m_pBaseAppState->GetCurrent();
currentState.OnUpdate(a_fDeltaTime);
}
return TTRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenJPOG/Source/Tasks/ARootStateController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static inline ARootStateController* s_pCurrentStateController = TNULL;

class ARootStateController : public Toshi::TTask
{
DECLARE_DYNAMIC(ARootTask);
DECLARE_DYNAMIC(ARootStateController);

public:
ARootStateController();
Expand Down
9 changes: 9 additions & 0 deletions OpenJPOG/Source/Tasks/ARootTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ void ARootTask::OnDeactivate()

void ARootTask::LoadFrontEndController()
{
m_pFrontEndController = (AFrontEndController*)g_oTheApp.GetKernel()->GetScheduler()->CreateTask(TGetClass(AFrontEndController), this);
m_pFrontEndController->Create();
LoadMaterialLibrary(1);
LoadMaterialLibrary(25);
g_oTheApp.GetKernel()->GetSystemTimer()->Reset();
}

void ARootTask::UnloadFrontEndController()
Expand Down Expand Up @@ -183,3 +188,7 @@ const TRenderAdapter::Mode::Device* ARootTask::CreateDisplayDevice(TRenderInterf
return pDevice;

}

void ARootTask::LoadMaterialLibrary(TINT a_iIndex)
{
}
5 changes: 4 additions & 1 deletion OpenJPOG/Source/Tasks/ARootTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "GUI/AGUISystem.h"
#include "ARootStateController.h"
#include "ARenderer.h"

#include "Tasks/AFrontEndController.h"

class ARootTask : public Toshi::TTask
{
Expand Down Expand Up @@ -52,8 +52,11 @@ class ARootTask : public Toshi::TTask

const Toshi::TRenderAdapter::Mode::Device* CreateDisplayDevice(Toshi::TRenderInterface::DisplayParams& a_rDisplayParams, bool a_bReverseOrder);

void LoadMaterialLibrary(TINT a_iIndex);

private:
Toshi::TCString m_szName;
AFrontEndController* m_pFrontEndController; // 0x28
AGUISystem* m_pGUISystem; // 0x34
Toshi::TTask* m_pInputTask; // 0x38
Toshi::TRenderInterface* m_pRenderInterface; // 0xD0
Expand Down
2 changes: 1 addition & 1 deletion Toshi/Include/TKernel/TDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define TASSERT(expression) \
TFIREFLAG_CREATE(__LINE__); \
if (!(expression)) { \
if (TDebug::AssertHandler(const_cast<TPCHAR>(#expression), const_cast<TPCHAR>(__FILE__), __LINE__, TFIREFLAG(__LINE__))) { \
if (Toshi::TDebug::AssertHandler(const_cast<TPCHAR>(#expression), const_cast<TPCHAR>(__FILE__), __LINE__, TFIREFLAG(__LINE__))) { \
__debugbreak(); \
} \
}
Expand Down
27 changes: 27 additions & 0 deletions Toshi/Plugins/Include/PPropertyParser/PPropertyReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#include "TObject.h"
#include "TFile.h"
#include "TFileLexerUTF8.h"

class PPropertyReader : public Toshi::TObject
{
public:
PPropertyReader();

void Close();

void Error(const Toshi::TCString& a_sMsg);

virtual ~PPropertyReader() { Close(); }
virtual TBOOL Open(const Toshi::TCString& a_rFileName, Toshi::TFile* a_pFile);
virtual TBOOL Open(const Toshi::TCString& a_rFileName);

void Warning(const Toshi::TCString& a_sMsg);

private:
Toshi::TCString m_szFileName; // 0x4
Toshi::TFile* m_pFile; // 0xC
Toshi::TFileLexerUTF8* m_pLexer; // 0x10
TBOOL m_bLoadComments; // 0x24
TBOOL m_bAssertOnError; // 0x25
};
57 changes: 57 additions & 0 deletions Toshi/Plugins/Source/PPropertyParser/PPropertyReader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "PPropertyParser/PPropertyReader.h"

PPropertyReader::PPropertyReader()
{
m_pFile = TNULL;
m_pLexer = TNULL;
m_bLoadComments = TFALSE;
m_bAssertOnError = TTRUE;
}

void PPropertyReader::Close()
{
if (m_pFile) {
m_pFile->Destroy();
m_pFile = TNULL;
}
if (m_pLexer) {
delete m_pLexer;
m_pLexer = TNULL;
}
}

void PPropertyReader::Error(const Toshi::TCString& a_sMsg)
{
TDPRINTF("%s : error: %s\n", m_szFileName, a_sMsg);
if (m_bAssertOnError) {
TASSERT(!"PPropertyReader::Error()");
}
}

TBOOL PPropertyReader::Open(const Toshi::TCString& a_rFileName, Toshi::TFile* a_pFile)
{
m_szFileName = a_rFileName;
Close();
m_pFile = a_pFile;
m_pLexer = new Toshi::TFileLexerUTF8(m_pFile, 2);
m_pLexer->SetOutputComments(m_bLoadComments);
}

TBOOL PPropertyReader::Open(const Toshi::TCString& a_rFileName)
{
m_szFileName = a_rFileName;
Close();
m_pFile = Toshi::TFile::Create(m_szFileName, Toshi::TMODE_READONLY);
if (!m_pFile) {
Warning("Can't open file");
return TFALSE;
}
m_pLexer = new Toshi::TFileLexerUTF8(m_pFile, 2);
m_pLexer->SetOutputComments(m_bLoadComments);
return TTRUE;
}

void PPropertyReader::Warning(const Toshi::TCString& a_sMsg)
{
TDPRINTF("%s : warning: %s\n", m_szFileName, a_sMsg);
}

0 comments on commit 4a0df24

Please sign in to comment.