Skip to content

Commit

Permalink
Problems with TObject, macro needs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Dec 26, 2023
1 parent 6ee36ca commit 9478d99
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 35 deletions.
3 changes: 3 additions & 0 deletions OpenJPOG/Source/ADummyTask.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "ADummyTask.h"

IMPLEMENT_DYNCREATE(ADummyTask, Toshi::TTask);
4 changes: 1 addition & 3 deletions OpenJPOG/Source/ADummyTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ class ADummyTask : public Toshi::TTask

private:
Toshi::TCString m_szName;
};

IMPLEMENT_DYNCREATE(ADummyTask, Toshi::TTask);
};
5 changes: 1 addition & 4 deletions OpenJPOG/Source/ARootTask.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "ARootTask.h"

class AApplication;
extern AApplication g_oTheApp;
#include "main.h"

TOSHI_NAMESPACE_USING

Expand All @@ -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);

}
32 changes: 10 additions & 22 deletions OpenJPOG/Source/main.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
24 changes: 24 additions & 0 deletions OpenJPOG/Source/main.h
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion OpenJPOG/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ project ("OpenJPOG")
"TApplication",
"libtheora",
"theoraplay",
"fmodvc.lib"
"fmodvc.lib",
"TKernelInterface.lib"
}

files
Expand Down
28 changes: 26 additions & 2 deletions Toshi/Include/TKernel/TObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -133,7 +157,7 @@ private: \

class TOSHI_EXPORT TObject
{
private:
public:
static TObject* TOSHI_API CreateObject()
{
return new TObject;
Expand Down
2 changes: 1 addition & 1 deletion Toshi/Include/TKernel/TTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TOSHI_NAMESPACE_BEGIN

class TOSHI_EXPORT TTask : public TObject, public TNodeTree<TTask>::TNode
{
DECLARE_DYNAMIC(TTask, TObject);
TOBJECT_DYN(TTask, TObject);

enum State
{
Expand Down
2 changes: 0 additions & 2 deletions Toshi/Source/TKernel/TTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

TOSHI_NAMESPACE_USING

IMPLEMENT_DYNAMIC(TTask, TObject);

TBOOL TTask::Create()
{
TASSERT(IsCreated()==TFALSE);
Expand Down

0 comments on commit 9478d99

Please sign in to comment.