Skip to content

Commit

Permalink
Implementing TClass & TObject
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Nov 11, 2023
1 parent af0cd6e commit 3fedbe1
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 10 deletions.
12 changes: 12 additions & 0 deletions Tools/UnitTests/Source/TApplication/TApplication_Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "TApplication/TApplication.h"
#include <catch2/catch_test_macros.hpp>

TOSHI_NAMESPACE_USING

TEST_CASE("Create", "[TApplication]")
{
TApplication app;
TPCCHAR argv[2] = {"Path", "Hello there"};
TBOOL bRes = app.Create("Test", 1, argv);
REQUIRE(bRes);
}
4 changes: 3 additions & 1 deletion Tools/UnitTests/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ project "UnitTests"

links
{
"TKernelInterface"
"TKernelInterface",
"TApplication"
}

libdirs
Expand Down Expand Up @@ -44,6 +45,7 @@ project "UnitTests"
postbuildcommands
{
"{COPY} \"%{wks.location}bin/" .. outputdir .. "/TKernelInterface/TKernelInterface.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\"",
"{COPY} \"%{wks.location}bin/" .. outputdir .. "/TApplication/TApplication.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\""
}

filter "system:windows"
Expand Down
5 changes: 4 additions & 1 deletion Toshi/Include/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
typedef bool TBOOL;
typedef int TINT;
typedef unsigned int TUINT;
typedef short TSHORT;
typedef unsigned short TUSHORT;
typedef const char* TPCCHAR;
typedef char* TPCHAR;
typedef char TCHAR;
typedef unsigned char TBYTE;
typedef unsigned char* TPBYTE;
typedef void* TPVOID;
typedef const void* TPCVOID;
typedef const void* TPCVOID;
typedef float TFLOAT;
42 changes: 40 additions & 2 deletions Toshi/Include/TApplication/TApplication.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include "Defines.h"
#include "TKernel/TCString.h"

TOSHI_NAMESPACE_BEGIN

Expand All @@ -14,15 +15,52 @@ class TOSHI_EXPORT TApplication
};

public:
TBOOL Create(TPCCHAR a_pcName, TINT a_unk, TPCCHAR* a_ppcUnk2);

TApplication()
{
m_uiState = 0;
m_bVerbose = TTRUE;
m_bShowConsole = TTRUE;
}

TBOOL Create(TPCCHAR a_pcName, TINT argc, TPCCHAR* argv);

TBOOL IsCreated()
{
return (m_uiState & TApplicationFlag_Created) != 0;
}

void SetVerbose(TBOOL a_bVerbose)
{
m_bVerbose = a_bVerbose;
}

void Destroy()
{
m_uiState |= TApplicationFlag_Destroyed;
}

virtual TBOOL OnCreate(TINT argc, TPCCHAR* argv)
{
m_uiState |= TApplicationFlag_Created;
return TTRUE;
}

virtual TBOOL OnDestroy()
{
return TTRUE;
}

virtual TBOOL OnUpdate(TFLOAT a_fDelta)
{
return (m_uiState & TApplicationFlag_Destroyed) != 0;
}

private:
TINT m_uiState;
TCString m_pcName; // 0x8
TINT m_uiState; // 0x10
TBOOL m_bVerbose; // 0x14
TBOOL m_bShowConsole; // 0x15
};

TOSHI_NAMESPACE_END
2 changes: 1 addition & 1 deletion Toshi/Include/TKernel/TCString.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TOSHI_EXPORT TCString

private:

inline static char* m_aNull = TNULL;
inline static TCHAR m_aNull[4] = { 0, 0, 0, 0 };

TPCHAR m_pBuffer; // 0x0
TINT m_iExcessLen : 8 = 0; // 0x4
Expand Down
111 changes: 111 additions & 0 deletions Toshi/Include/TKernel/TObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "Defines.h"
#include <new>
TOSHI_NAMESPACE_BEGIN

class TObject;

// TClassProps definitions
typedef class TObject* (*t_CreateTObject)();
typedef class TObject* (*t_CreateTObjectInPlace)(TPVOID);
typedef void (*t_InitializeStatic)();
typedef void (*t_UninitializeStatic)();

// RecurseTree definitions
typedef TBOOL (*t_RecurceTreeCheck)(class TClass*, TPCVOID);
typedef TBOOL (*t_RecurceTreeBaseBeginCb)(class TClass*, TPCVOID);
typedef TBOOL (*t_RecurceTreeBaseEndCb)(class TClass*, TPCVOID);

TOSHI_EXPORT class TClass
{
public:
TClass(TPCCHAR a_pcName, TClass* a_pParent, t_CreateTObject a_Create, t_CreateTObjectInPlace a_CreateInPlace, t_InitializeStatic a_Init, t_UninitializeStatic a_Uninit, TUINT a_uiVersion);
~TClass();

TObject* CreateObject() const
{
return m_Create ? m_Create() : TNULL;
}

TObject* CreateObjectInPlace(TPVOID a_pMem) const
{
return m_CreateInPlace ? m_CreateInPlace(a_pMem) : TNULL;
}

void DeinitialiseStatic();
TBOOL DetachClassFromParent() { return TTRUE; }
static void __stdcall DumpObjectClassTree();
static const TClass* __stdcall Find(TPCCHAR a_pcClassName, const TClass* a_pClass);
static const TClass* __stdcall FindCommonBaseClass(const TClass& a_rClass, const TClass& a_rBaseClass);
static const TClass* __stdcall FindRecurse(TPCCHAR a_pcClassName, const TClass* a_pClass, TBOOL a_bHasPrevious);

TPCCHAR GetName() const { return m_pcName; }
const TClass* GetParent() const { return m_pParent; }
TUINT GetVersion() const { return m_uiVersion; }
TUSHORT GetVersionMajor() const { return m_uiVersion >> 16; }
TUSHORT GetVersionMinor() const { return m_uiVersion & 0xFFFF; }

void InitialiseStatic();
TBOOL IsA(const TClass &a_rClass) const;
TBOOL IsAttached() const;
TBOOL IsExactly(const TClass& a_rClass) const
{
return *this == a_rClass;
}
TBOOL IsStaticInitialised() const
{
return m_bInitialised;
}

TClass& operator=(const TClass& a_rClass)
{
m_pcName = a_rClass.m_pcName;
m_Create = a_rClass.m_Create;
m_CreateInPlace = a_rClass.m_CreateInPlace;
m_Initialize = a_rClass.m_Initialize;
m_Uninitialize = a_rClass.m_Uninitialize;
m_pParent = a_rClass.m_pParent;
m_uiVersion = a_rClass.m_uiVersion;
m_bInitialised = TFALSE;
return *this;
}
TBOOL operator==(const TClass& a_rClass) const
{
return m_pcName == a_rClass.m_pcName;
}

void RecurseTree(t_RecurceTreeBaseBeginCb a_BaseBegin, t_RecurceTreeBaseEndCb a_BaseEnd, t_RecurceTreeCheck a_Check, TPCVOID a_pMem);
void RecurseTree2(t_RecurceTreeBaseBeginCb a_BaseBegin, t_RecurceTreeBaseEndCb a_BaseEnd, t_RecurceTreeCheck a_Check, TPCVOID a_pMem);

TBOOL AttachClassToParent();

private:
TPCCHAR m_pcName; // 0x00
t_CreateTObject m_Create; // 0x04
t_CreateTObjectInPlace m_CreateInPlace; // 0x08
t_InitializeStatic m_Initialize; // 0x0C
t_UninitializeStatic m_Uninitialize; // 0x10
TClass* m_pParent; // 0x14
TClass* m_pPrevious; // 0x18
TClass* m_pLastAttached; // 0x1C
TUINT m_uiVersion; // 0x20
TBOOL m_bInitialised; // 0x24
};

class TOSHI_EXPORT TObject
{
private:
static TObject* __stdcall CreateObject()
{
TObject* pObject = new TObject();
return pObject ? pObject : TNULL;
}
static TObject* __stdcall CreateObjectInPlace(TPVOID m_pMem)
{
TObject* pObject = new (m_pMem) TObject();
return pObject ? pObject : TNULL;
}
public:
//static TClass m_sClass;
};

TOSHI_NAMESPACE_END
1 change: 1 addition & 0 deletions Toshi/Include/TKernel/TSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TOSHI_EXPORT TSystem
public:

static TINT __stdcall StringLength(TPCCHAR a_String);
static TINT __stdcall StringCompareNoCase(TPCCHAR a_String1, TPCCHAR a_String2, TINT a_uiSize);
static TPVOID __stdcall MemCopy(TPVOID a_dest, TPCVOID a_src, TUINT a_iSize);

static TPBYTE GetScratchMem() { return ms_aScratchMem; }
Expand Down
18 changes: 15 additions & 3 deletions Toshi/Source/TApplication/TApplication.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#include "TApplication.h"
#include "TCString.h"
#include "TDebug.h"

TOSHI_NAMESPACE_USING

TBOOL TApplication::Create(TPCCHAR a_pcName, TINT a_unk, TPCCHAR* a_ppcUnk2)
TBOOL TApplication::Create(TPCCHAR a_pcName, TINT argc, TPCCHAR* argv)
{
TCString test;
m_pcName = a_pcName;
if (m_bVerbose)
{
TDebug_Printf("Creating Toshi Application \"%s\".\n", m_pcName.GetString());
if (argc > 0 && argv)
{
TDebug_Printf("Command line parameters: %d.\n", argc);
for (TINT i = 0; i < argc; i++)
{
TDebug_Printf(" Arg[%d]: \"%s\"\n", i, argv[i+1]);
}
}
}
return TTRUE;
}
2 changes: 1 addition & 1 deletion Toshi/Source/TKernel/TCString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TBOOL TCString::AllocBuffer(TINT a_iLength, TBOOL a_bClear)
}
m_iStrLen = a_iLength;
}
if (a_bClear) m_pBuffer[0] = '\0';
if (a_bClear) m_pBuffer[0] = 0;
return hasChanged;
}

Expand Down
Loading

0 comments on commit 3fedbe1

Please sign in to comment.