From 9478d997d1fb4ef68e706e9435f1c56ec6db7d72 Mon Sep 17 00:00:00 2001 From: AdventureT Date: Tue, 26 Dec 2023 12:10:26 +0100 Subject: [PATCH] Problems with TObject, macro needs fixes --- OpenJPOG/Source/ADummyTask.cpp | 3 +++ OpenJPOG/Source/ADummyTask.h | 4 +--- OpenJPOG/Source/ARootTask.cpp | 5 +---- OpenJPOG/Source/main.cpp | 32 ++++++++++---------------------- OpenJPOG/Source/main.h | 24 ++++++++++++++++++++++++ OpenJPOG/premake5.lua | 3 ++- Toshi/Include/TKernel/TObject.h | 28 ++++++++++++++++++++++++++-- Toshi/Include/TKernel/TTask.h | 2 +- Toshi/Source/TKernel/TTask.cpp | 2 -- 9 files changed, 68 insertions(+), 35 deletions(-) create mode 100644 OpenJPOG/Source/ADummyTask.cpp create mode 100644 OpenJPOG/Source/main.h diff --git a/OpenJPOG/Source/ADummyTask.cpp b/OpenJPOG/Source/ADummyTask.cpp new file mode 100644 index 0000000..aeea397 --- /dev/null +++ b/OpenJPOG/Source/ADummyTask.cpp @@ -0,0 +1,3 @@ +#include "ADummyTask.h" + +IMPLEMENT_DYNCREATE(ADummyTask, Toshi::TTask); \ No newline at end of file diff --git a/OpenJPOG/Source/ADummyTask.h b/OpenJPOG/Source/ADummyTask.h index 0e6942c..9a793f8 100644 --- a/OpenJPOG/Source/ADummyTask.h +++ b/OpenJPOG/Source/ADummyTask.h @@ -21,6 +21,4 @@ class ADummyTask : public Toshi::TTask private: Toshi::TCString m_szName; -}; - -IMPLEMENT_DYNCREATE(ADummyTask, Toshi::TTask); \ No newline at end of file +}; \ No newline at end of file diff --git a/OpenJPOG/Source/ARootTask.cpp b/OpenJPOG/Source/ARootTask.cpp index 6b44389..0e7e346 100644 --- a/OpenJPOG/Source/ARootTask.cpp +++ b/OpenJPOG/Source/ARootTask.cpp @@ -1,7 +1,5 @@ #include "ARootTask.h" - -class AApplication; -extern AApplication g_oTheApp; +#include "main.h" TOSHI_NAMESPACE_USING @@ -13,5 +11,4 @@ void ARootTask::AllocateInputSystem() ADummyTask* pInputTask = g_oTheApp.GetInputRootTask(); m_pInputTask = pScheduler->CreateTask(TGetClass(ADummyTask), pInputTask); m_pVibrationTask = (AVibrationManager*)pScheduler->CreateTask(TGetClass(AVibrationManager), pInputTask); - } diff --git a/OpenJPOG/Source/main.cpp b/OpenJPOG/Source/main.cpp index b795d11..171a40a 100644 --- a/OpenJPOG/Source/main.cpp +++ b/OpenJPOG/Source/main.cpp @@ -1,28 +1,16 @@ -#include "TApplication/TApplication.h" -#include "TKernel/TMemory.h" -#include "ADummyTask.h" +#include "main.h" -class AApplication : public Toshi::TApplication -{ - virtual TBOOL OnCreate(TINT argc, TPCHAR* const argv) override - { - - m_pInputTask = (ADummyTask*)GetKernel()->GetScheduler()->CreateTask(TGetClass(ADummyTask), m_pInputTask); - m_pInputTask->Create(); - m_pInputTask->Activate(TTRUE); - m_pInputTask->SetName((TPCHAR)"InputTask"); +AApplication g_oTheApp; - return TApplication::OnCreate(argc, argv); - } -public: - ADummyTask* GetInputRootTask() const { return m_pInputTask; } - -private: - // TApplication 0x0 -> 0x1C - ADummyTask* m_pInputTask; // 0x1C -}; +TBOOL AApplication::OnCreate(TINT argc, TPCHAR* const argv) +{ + m_pInputTask = (ADummyTask*)GetKernel()->GetScheduler()->CreateTask(TGetClass(ADummyTask), m_pInputTask); + m_pInputTask->Create(); + m_pInputTask->Activate(TTRUE); + m_pInputTask->SetName((TPCHAR)"InputTask"); -static AApplication g_oTheApp; + return TApplication::OnCreate(argc, argv); +} int main(int argc, char** argv) { diff --git a/OpenJPOG/Source/main.h b/OpenJPOG/Source/main.h new file mode 100644 index 0000000..0a57257 --- /dev/null +++ b/OpenJPOG/Source/main.h @@ -0,0 +1,24 @@ +#pragma once +#include "TApplication/TApplication.h" +#include "TKernel/TMemory.h" +#include "ADummyTask.h" + +class AApplication : public Toshi::TApplication +{ +public: + + AApplication() + { + + } + + virtual TBOOL OnCreate(TINT argc, TPCHAR* const argv) override; +public: + ADummyTask* GetInputRootTask() const { return m_pInputTask; } + +private: + // TApplication 0x0 -> 0x1C + ADummyTask* m_pInputTask; // 0x1C +}; + +extern AApplication g_oTheApp; \ No newline at end of file diff --git a/OpenJPOG/premake5.lua b/OpenJPOG/premake5.lua index c3e35aa..31cc73b 100644 --- a/OpenJPOG/premake5.lua +++ b/OpenJPOG/premake5.lua @@ -10,7 +10,8 @@ project ("OpenJPOG") "TApplication", "libtheora", "theoraplay", - "fmodvc.lib" + "fmodvc.lib", + "TKernelInterface.lib" } files diff --git a/Toshi/Include/TKernel/TObject.h b/Toshi/Include/TKernel/TObject.h index 54b8b3f..074d89d 100644 --- a/Toshi/Include/TKernel/TObject.h +++ b/Toshi/Include/TKernel/TObject.h @@ -103,7 +103,31 @@ private: \ static Toshi::TObject* TOSHI_API CreateObject(); \ static Toshi::TObject* TOSHI_API CreateObjectInPlace(TPVOID a_pMem); \ static void TOSHI_API DeinitialiseStatic(); \ - static void TOSHI_API InitialiseStatic(); \ + static void TOSHI_API InitialiseStatic(); + +#define TOBJECT_DYNCREATE(class_name, base_class_name) \ +public: \ + virtual Toshi::TClass& GetClass() const { return class_name::m_sClass; } \ + inline static Toshi::TClass m_sClass = { \ + #class_name, &TGetClass(base_class_name), class_name::CreateObject, class_name::CreateObjectInPlace, \ + class_name::InitialiseStatic, class_name::DeinitialiseStatic, 1 }; \ +public: \ + static Toshi::TObject* TOSHI_API CreateObject() { return new class_name; } \ + static Toshi::TObject* TOSHI_API CreateObjectInPlace(TPVOID a_pMem){ return new (a_pMem) class_name; } \ + static void TOSHI_API DeinitialiseStatic() {} \ + static void TOSHI_API InitialiseStatic() {} + +#define TOBJECT_DYN(class_name, base_class_name) \ +public: \ + virtual Toshi::TClass& GetClass() const { return class_name::m_sClass; } \ + inline static Toshi::TClass m_sClass = { \ + #class_name, &TGetClass(base_class_name), class_name::CreateObject, class_name::CreateObjectInPlace, \ + class_name::InitialiseStatic, class_name::DeinitialiseStatic, 1 }; \ +public: \ + static Toshi::TObject* TOSHI_API CreateObject() { TASSERT(!"This class does not support dynamic creation!"); return TNULL; } \ + static Toshi::TObject* TOSHI_API CreateObjectInPlace(TPVOID a_pMem){ TASSERT(!"This class does not support dynamic creation!"); return TNULL; } \ + static void TOSHI_API DeinitialiseStatic() {} \ + static void TOSHI_API InitialiseStatic() {} #define IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, pfnCreateObject, pfnCreateObjectInPlace, version) \ Toshi::TClass& class_name::GetClass() const \ @@ -133,7 +157,7 @@ private: \ class TOSHI_EXPORT TObject { -private: +public: static TObject* TOSHI_API CreateObject() { return new TObject; diff --git a/Toshi/Include/TKernel/TTask.h b/Toshi/Include/TKernel/TTask.h index 34bb54b..f4ee194 100644 --- a/Toshi/Include/TKernel/TTask.h +++ b/Toshi/Include/TKernel/TTask.h @@ -7,7 +7,7 @@ TOSHI_NAMESPACE_BEGIN class TOSHI_EXPORT TTask : public TObject, public TNodeTree::TNode { - DECLARE_DYNAMIC(TTask, TObject); + TOBJECT_DYN(TTask, TObject); enum State { diff --git a/Toshi/Source/TKernel/TTask.cpp b/Toshi/Source/TKernel/TTask.cpp index 33283c8..b3ed28f 100644 --- a/Toshi/Source/TKernel/TTask.cpp +++ b/Toshi/Source/TKernel/TTask.cpp @@ -2,8 +2,6 @@ TOSHI_NAMESPACE_USING -IMPLEMENT_DYNAMIC(TTask, TObject); - TBOOL TTask::Create() { TASSERT(IsCreated()==TFALSE);