diff --git a/OpenJPOG/Source/main.cpp b/OpenJPOG/Source/main.cpp index db44d13..b128ca9 100644 --- a/OpenJPOG/Source/main.cpp +++ b/OpenJPOG/Source/main.cpp @@ -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); diff --git a/OpenJPOG/premake5.lua b/OpenJPOG/premake5.lua index ad42e4b..b1fda98 100644 --- a/OpenJPOG/premake5.lua +++ b/OpenJPOG/premake5.lua @@ -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}\"", } diff --git a/Tools/UnitTests/Source/TRender/TResource_Tests.cpp b/Tools/UnitTests/Source/TRender/TResource_Tests.cpp new file mode 100644 index 0000000..0b1efb4 --- /dev/null +++ b/Tools/UnitTests/Source/TRender/TResource_Tests.cpp @@ -0,0 +1,10 @@ +#include "TRender/TResource.h" +#include + +TOSHI_NAMESPACE_USING + +TEST_CASE("SetName", "[TResource]") +{ + TResource res; + res.SetName(TNULL); +} \ No newline at end of file diff --git a/Tools/UnitTests/Source/main.cpp b/Tools/UnitTests/Source/main.cpp index e87be2b..2226c78 100644 --- a/Tools/UnitTests/Source/main.cpp +++ b/Tools/UnitTests/Source/main.cpp @@ -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); diff --git a/Tools/UnitTests/premake5.lua b/Tools/UnitTests/premake5.lua index c0d6be5..20f27b7 100644 --- a/Tools/UnitTests/premake5.lua +++ b/Tools/UnitTests/premake5.lua @@ -17,7 +17,8 @@ project "UnitTests" links { "TKernelInterface", - "TApplication" + "TApplication", + "TRenderInterface" } libdirs @@ -29,6 +30,7 @@ project "UnitTests" { "Source/**.h", "Source/**.cpp", + "%{wks.location}/Toshi/Include/*.h", } includedirs @@ -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" diff --git a/Toshi/Include/Defines.h b/Toshi/Include/Defines.h index 391ca3e..65533ab 100644 --- a/Toshi/Include/Defines.h +++ b/Toshi/Include/Defines.h @@ -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; diff --git a/Toshi/Include/TKernel/TNodeTree.h b/Toshi/Include/TKernel/TNodeTree.h index 6621900..5b48aa1 100644 --- a/Toshi/Include/TKernel/TNodeTree.h +++ b/Toshi/Include/TKernel/TNodeTree.h @@ -7,10 +7,10 @@ TOSHI_NAMESPACE_BEGIN // Code from OpenToshi template -class TOSHI_EXPORT TNodeTree +class TNodeTree { public: - class TOSHI_EXPORT TNode + class TNode { public: friend TNodeTree; @@ -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* Tree() const { return m_Tree; } + TNodeTree* GetTree() const { return m_Tree; } T* Attached() const { return m_Attached; } protected: @@ -130,7 +130,7 @@ class TOSHI_EXPORT TNodeTree T* Remove(T& node, TBOOL flag = TFALSE) { // Toshi::TNodeTree::Remove - 00691e70 - TNodeTree* nodeRoot = node.Tree(); + TNodeTree* nodeRoot = node.GetTree(); T* nodeParent = node.Parent(); if (nodeRoot != TNULL) @@ -151,7 +151,7 @@ class TOSHI_EXPORT TNodeTree while (attachedNode != TNULL) { - TNodeTree* nodeRoot = node.Tree(); + TNodeTree* nodeRoot = node.GetTree(); Remove(*attachedNode, TFALSE); Insert(node.Parent(), attachedNode); @@ -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(); diff --git a/Toshi/Include/TKernel/TSystemTools.h b/Toshi/Include/TKernel/TSystemTools.h index f0b1de5..0dad724 100644 --- a/Toshi/Include/TKernel/TSystemTools.h +++ b/Toshi/Include/TKernel/TSystemTools.h @@ -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); diff --git a/Toshi/Include/TRender/TResource.h b/Toshi/Include/TRender/TResource.h new file mode 100644 index 0000000..cc37177 --- /dev/null +++ b/Toshi/Include/TRender/TResource.h @@ -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::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 \ No newline at end of file diff --git a/Toshi/Include/TRender/TTextureResource.h b/Toshi/Include/TRender/TTextureResource.h index a5a9d5f..77d0369 100644 --- a/Toshi/Include/TRender/TTextureResource.h +++ b/Toshi/Include/TRender/TTextureResource.h @@ -4,7 +4,7 @@ TOSHI_NAMESPACE_BEGIN -class TTextureResource +class TOSHI_EXPORT TTextureResource { }; diff --git a/Toshi/Source/TKernel/TSystemTools.cpp b/Toshi/Source/TKernel/TSystemTools.cpp index 646f6df..14c5ddc 100644 --- a/Toshi/Source/TKernel/TSystemTools.cpp +++ b/Toshi/Source/TKernel/TSystemTools.cpp @@ -1,9 +1,27 @@ #include "TSystemTools.h" #include "TDebug.h" #include +#include 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); diff --git a/Toshi/Source/TRender/TResource.cpp b/Toshi/Source/TRender/TResource.cpp new file mode 100644 index 0000000..58728fd --- /dev/null +++ b/Toshi/Source/TRender/TResource.cpp @@ -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); +}