Skip to content

Commit

Permalink
Begin working on TResource
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Dec 29, 2023
1 parent 738033a commit cd0d52d
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 12 deletions.
3 changes: 3 additions & 0 deletions OpenJPOG/Source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "main.h"
#include "TRender/TResource.h"

AApplication g_oTheApp;

TBOOL AApplication::OnCreate(TINT argc, TPCHAR* const argv)
{
Toshi::TResource test;
test.SetName("ff");
m_pInputTask = (ADummyTask*)g_oTheApp.GetKernel()->GetScheduler()->CreateTask(TGetClass(ADummyTask), TNULL);
m_pInputTask->Create();
m_pInputTask->Activate(TTRUE);
Expand Down
1 change: 1 addition & 0 deletions OpenJPOG/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ project ("OpenJPOG")
{
"{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}\"",
"{COPY} \"%{wks.location}bin/" .. outputdir .. "/TRenderInterface/TRenderInterface.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\"",
"{COPY} \"%{wks.location}Toshi/vendor/fmod/lib/fmod.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\"",
"{COPY} \"%{wks.location}Toshi/vendor/bink/lib/binkw32.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\"",
}
Expand Down
10 changes: 10 additions & 0 deletions Tools/UnitTests/Source/TRender/TResource_Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "TRender/TResource.h"
#include <catch2/catch_test_macros.hpp>

TOSHI_NAMESPACE_USING

TEST_CASE("SetName", "[TResource]")
{
TResource res;
res.SetName(TNULL);
}
2 changes: 1 addition & 1 deletion Tools/UnitTests/Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static AApplication g_oTheApp;

int main(int argc, char* argv[])
{
int result;
int result = 0;
if (g_oTheApp.Create("UnitTests", argc, argv)) {
g_oTheApp.Execute();
result = Catch::Session().run(argc, argv);
Expand Down
7 changes: 5 additions & 2 deletions Tools/UnitTests/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ project "UnitTests"
links
{
"TKernelInterface",
"TApplication"
"TApplication",
"TRenderInterface"
}

libdirs
Expand All @@ -29,6 +30,7 @@ project "UnitTests"
{
"Source/**.h",
"Source/**.cpp",
"%{wks.location}/Toshi/Include/*.h",
}

includedirs
Expand All @@ -45,7 +47,8 @@ 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}\""
"{COPY} \"%{wks.location}bin/" .. outputdir .. "/TApplication/TApplication.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\"",
"{COPY} \"%{wks.location}bin/" .. outputdir .. "/TRenderInterface/TRenderInterface.dll\" \"%{wks.location}bin/" .. outputdir .. "/%{prj.name}\""
}

filter "system:windows"
Expand Down
1 change: 1 addition & 0 deletions Toshi/Include/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ typedef const char* TPCCHAR;
typedef char* TPCHAR;
typedef char TCHAR;
typedef const char TCCHAR;
typedef char TINT8;
typedef unsigned char TUINT8;
typedef unsigned char TBYTE;
typedef unsigned char* TPBYTE;
Expand Down
16 changes: 8 additions & 8 deletions Toshi/Include/TKernel/TNodeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ TOSHI_NAMESPACE_BEGIN
// Code from OpenToshi

template <class T>
class TOSHI_EXPORT TNodeTree
class TNodeTree
{
public:
class TOSHI_EXPORT TNode
class TNode
{
public:
friend TNodeTree;
Expand All @@ -29,14 +29,14 @@ class TOSHI_EXPORT TNodeTree
TBOOL IsChildOfDefaultRoot() const
{
TASSERT(IsLinked() == TTRUE);
return m_Parent == (T*)(&Tree()->m_Root);
return m_Parent == (T*)(&GetTree()->m_Root);
}

TBOOL IsLinked() const { return m_Tree != TNULL; }
T* Parent() const { return m_Parent; }
T* Next() const { return m_Next; }
T* Prev() const { return m_Prev; }
TNodeTree<T>* Tree() const { return m_Tree; }
TNodeTree<T>* GetTree() const { return m_Tree; }
T* Attached() const { return m_Attached; }

protected:
Expand Down Expand Up @@ -130,7 +130,7 @@ class TOSHI_EXPORT TNodeTree
T* Remove(T& node, TBOOL flag = TFALSE)
{
// Toshi::TNodeTree<Toshi::TResource>::Remove - 00691e70
TNodeTree<T>* nodeRoot = node.Tree();
TNodeTree<T>* nodeRoot = node.GetTree();
T* nodeParent = node.Parent();

if (nodeRoot != TNULL)
Expand All @@ -151,7 +151,7 @@ class TOSHI_EXPORT TNodeTree

while (attachedNode != TNULL)
{
TNodeTree<T>* nodeRoot = node.Tree();
TNodeTree<T>* nodeRoot = node.GetTree();

Remove(*attachedNode, TFALSE);
Insert(node.Parent(), attachedNode);
Expand Down Expand Up @@ -196,12 +196,12 @@ class TOSHI_EXPORT TNodeTree
DeleteRecurse(node->Attached());
}

if (node->Tree() == this)
if (node->GetTree() == this)
{
m_Count--;
}

if (node->Tree() == TNULL || node->Tree() == this)
if (node->GetTree() == TNULL || node->GetTree() == this)
{
T* nodeParent = node->Parent();

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

static TPCCHAR TOSHI_API StringIntToString(TINT a_iInt, TPCHAR a_szString, TINT a_iRadix);
static TINT TOSHI_API StringLength(TPCCHAR a_String);
static TINT TOSHI_API StringCompareNoCase(TPCCHAR a_String1, TPCCHAR a_String2, TINT a_uiSize);
static TCHAR const* TOSHI_API StringCopy(TPCHAR a_DestinationString, TCHAR const* a_SourceString, TINT a_iCount);
Expand Down
42 changes: 42 additions & 0 deletions Toshi/Include/TRender/TResource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
#include "TKernel/TObject.h"
#include "TKernel/TNodeTree.h"

#define MAXNAMELEN 15

TOSHI_NAMESPACE_BEGIN

class TOSHI_EXPORT TResource : public TObject, public TNodeTree<TResource>::TNode
{
DECLARE_DYNAMIC(TResource)

enum TResourceState
{
TResourceState_Valid = BITFIELD(0),
TResourceState_Created = BITFIELD(1),
TResourceState_Dying = BITFIELD(2),
TResourceState_External = BITFIELD(3),
TResourceState_Dead = BITFIELD(4),
TResourceState_SceneObject = BITFIELD(5),
};

public:

TResource()
{

}

void SetParent(TResource *a_pParent);
void SetName(TPCCHAR a_strName);
TBOOL IsDying() { return HASFLAG(m_iState & TResourceState_Dying); }

TUINT GetUId() const { return m_uiUId; }

private:
TCHAR m_szName[MAXNAMELEN]; // 0x1C
TINT8 m_iState; // 0x2B
TUINT m_uiUId; // 0x2C
};

TOSHI_NAMESPACE_END
2 changes: 1 addition & 1 deletion Toshi/Include/TRender/TTextureResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

TOSHI_NAMESPACE_BEGIN

class TTextureResource
class TOSHI_EXPORT TTextureResource
{

};
Expand Down
18 changes: 18 additions & 0 deletions Toshi/Source/TKernel/TSystemTools.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#include "TSystemTools.h"
#include "TDebug.h"
#include <string.h>
#include <stdio.h>

TOSHI_NAMESPACE_USING

TPCCHAR TOSHI_API TSystem::StringIntToString(TINT a_iInt, TPCHAR a_szString, TINT a_iRadix)
{
if (a_iRadix == 8) {
sprintf(a_szString, "%o", a_iInt);
}
else if (a_iRadix == 10) {
sprintf(a_szString, "%d", a_iInt);
}
else if (a_iRadix == 16) {
sprintf(a_szString, "%x", a_iInt);
}
else {
TASSERT(!"_itoa: radix not supported");
}
return a_szString;
}

TINT TOSHI_API TSystem::StringLength(TPCCHAR a_String)
{
TASSERT(a_String!=TNULL);
Expand Down
36 changes: 36 additions & 0 deletions Toshi/Source/TRender/TResource.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "TResource.h"
#include "TSystemTools.h"

TOSHI_NAMESPACE_USING

IMPLEMENT_DYNCREATE(TResource, TObject)

void TResource::SetParent(TResource* a_pParent)
{
TASSERT((TNULL == a_pParent) || (TTRUE == IsDying()) || (TFALSE == a_pParent->IsDying()));
TASSERT(TNULL != GetTree());

GetTree()->Remove(this, TFALSE);

if (!a_pParent) {
GetTree()->InsertAtRoot(this);
}
else {
GetTree()->Insert(a_pParent, this);
}
}

void TResource::SetName(TPCCHAR a_strName)
{
char szName[12];
if (!a_strName) {
a_strName = szName;
szName[0] = 'r';
szName[1] = 'e';
szName[2] = 's';
szName[3] = ':';
TSystem::StringIntToString(GetUId(), &szName[4], 10);
}
TASSERT(TSystem::StringLength(a_strName)<=MAXNAMELEN);
TSystem::StringCopy(m_szName, a_strName, -1);
}

0 comments on commit cd0d52d

Please sign in to comment.