Skip to content

Commit

Permalink
More Stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed Jan 4, 2024
1 parent a6fdfc0 commit ba151f5
Show file tree
Hide file tree
Showing 18 changed files with 497 additions and 29 deletions.
10 changes: 5 additions & 5 deletions OpenJPOG/Source/States/ARootState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ TBOOL ARootState::RemoveChild()

ARootState& ARootState::GetCurrent()
{
ARootState i;
for (i = *this; i.m_pChild != TNULL; i = *i.m_pChild) {
if (i.m_pChild == TNULL) {
return i;
ARootState* i;
for (i = this; i->m_pChild != TNULL; i = i->m_pChild) {
if (i->m_pChild == TNULL) {
return *i;
}
}
return i;
return *i;
}
13 changes: 13 additions & 0 deletions Toshi/Include/TKernel/TFreeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

#include "TMemory.h"

#define DECLARE_FREELIST(class_name) \
public: \
static TPVOID TOSHI_API operator new(TUINT s, TPVOID mem) { return mem; } \
static TPVOID TOSHI_API operator new(TUINT s) { return ms_oFreeList.New(s); } \
static TPVOID TOSHI_API operator new(TUINT s, TPCHAR mem, TINT unk) { return ms_oFreeList.New(s); } \
static void TOSHI_API operator delete(void* ptr) { ms_oFreeList.Delete(ptr); } \
static Toshi::TFreeList& TOSHI_API GetFreeList() {return ms_oFreeList;} \
\
private: static Toshi::TFreeList ms_oFreeList;

#define IMPLEMENT_FREELIST(class_name, InitialSize, GrowSize) \
Toshi::TFreeList class_name::ms_oFreeList = Toshi::TFreeList(sizeof(class_name), InitialSize, GrowSize, TNULL);

TOSHI_NAMESPACE_BEGIN

class TKERNELINTERFACE_EXPORTS TFreeList
Expand Down
34 changes: 17 additions & 17 deletions Toshi/Include/TKernel/TNodeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TNodeTree
m_Next = (T*)this;
m_Prev = (T*)this;
m_Parent = TNULL;
m_Attached = TNULL;
m_Child = TNULL;
}

public:
Expand All @@ -37,14 +37,14 @@ class TNodeTree
T* Next() const { return m_Next; }
T* Prev() const { return m_Prev; }
TNodeTree<T>* GetTree() const { return m_Tree; }
T* Attached() const { return m_Attached; }
T* Child() const { return m_Child; }

protected:
TNodeTree<T>* m_Tree;
T* m_Next;
T* m_Prev;
T* m_Parent;
T* m_Attached;
T* m_Child;
};

public:
Expand Down Expand Up @@ -74,7 +74,7 @@ class TNodeTree
Remove(*a_pSourceNode, TFALSE);

// Get the first attached to parent node
T* firstAttached = parentNode->Attached();
T* firstAttached = parentNode->Child();

if (firstAttached != TNULL)
{
Expand All @@ -90,7 +90,7 @@ class TNodeTree
else
{
// Attach node as the first one
parentNode->m_Attached = a_pSourceNode;
parentNode->m_Child = a_pSourceNode;
}

a_pSourceNode->m_Tree = this;
Expand Down Expand Up @@ -147,7 +147,7 @@ class TNodeTree

if (flag)
{
T* attachedNode = node.Attached();
T* attachedNode = node.Child();

while (attachedNode != TNULL)
{
Expand All @@ -164,9 +164,9 @@ class TNodeTree
if (nodeParent != TNULL)
{
// If it's the first attached to the root node, set it to next or just remove
if (nodeParent->Attached() == &node)
if (nodeParent->Child() == &node)
{
nodeParent->m_Attached = (node.Next() != &node) ? node.Next() : TNULL;
nodeParent->m_Child = (node.Next() != &node) ? node.Next() : TNULL;
}

node.m_Parent = TNULL;
Expand All @@ -191,9 +191,9 @@ class TNodeTree
{
T* next = (node->Next() != node) ? node->Next() : TNULL;

if (node->Attached() != TNULL)
if (node->Child() != TNULL)
{
DeleteRecurse(node->Attached());
DeleteRecurse(node->Child());
}

if (node->GetTree() == this)
Expand All @@ -208,16 +208,16 @@ class TNodeTree
if (nodeParent != TNULL)
{
// If it's the first attached to the root node, set it to next or just remove
if (nodeParent->Attached() == node)
if (nodeParent->Child() == node)
{
nodeParent->m_Attached = (node->Next() != node) ? node->Next() : TNULL;
nodeParent->m_Child = (node->Next() != node) ? node->Next() : TNULL;
}

node->m_Parent = TNULL;
}

node->m_Prev->m_Parent = node->m_Next;
node->m_Next->m_Attached = node->m_Prev;
node->m_Next->m_Child = node->m_Prev;
node->m_Next = node;
node->m_Prev = node;
node->m_Tree = TNULL;
Expand All @@ -230,13 +230,13 @@ class TNodeTree

void DeleteAll()
{
T* node = GetRoot()->Attached();
T* node = GetRoot()->Child();

while (node != TNULL)
{
Remove(node, TFALSE);
DeleteRecurse(node);
node = GetRoot()->Attached();
node = GetRoot()->Child();
}

TASSERT(Count() == 0);
Expand All @@ -247,9 +247,9 @@ class TNodeTree
return TSTATICCAST(T*, &m_Root);
}

T* AttachedToRoot()
T* ChildOfRoot()
{
return m_Root.Attached();
return m_Root.Child();
}

size_t Count() const
Expand Down
2 changes: 2 additions & 0 deletions Toshi/Include/TRender/TRenderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class TRENDERINTERFACE_EXPORTS TRenderInterface : public TObject
DECLARE_DYNAMIC(TRenderInterface)

public:


enum FLAG
{
FLAG_DIRTY = BITFIELD(0),
Expand Down
15 changes: 13 additions & 2 deletions Toshi/Include/TRender/TResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class TRENDERINTERFACE_EXPORTS TResource : public TObject, public TNodeTree<TRes
{
DECLARE_DYNAMIC(TResource)

public:
using t_RecurseCb = TBOOL(*)(TResource* a_pResource, void* a_pUserData);

enum FLAGS
{
FLAGS_VALID = BITFIELD(0),
Expand All @@ -35,12 +38,20 @@ class TRENDERINTERFACE_EXPORTS TResource : public TObject, public TNodeTree<TRes

virtual TBOOL Create();
virtual TBOOL Validate();
virtual void Invalidate();
virtual void DestroyResource();
virtual void OnDestroy();

void SetParent(TResource *a_pParent);
void SetName(TPCCHAR a_strName);

TBOOL IsDying() { return HASFLAG(m_Flags & FLAGS_DYING); }
TBOOL IsCreated() { return HASFLAG(m_Flags & FLAGS_CREATED); }
void RecurseSimple(t_RecurseCb a_pfnCallback, TResource* a_pResource, TPVOID a_pUserData);

TBOOL IsCreated() const { return m_Flags & FLAGS_CREATED; }
TBOOL IsDying() const { return m_Flags & FLAGS_DYING; }
TBOOL IsSceneObject() const { return m_Flags & FLAGS_SCENEOBJECT; }
TBOOL IsDead() const { return m_Flags & FLAGS_DEAD; }
TBOOL IsValid() const { return IsCreated() && m_Flags & FLAGS_VALID; }

TUINT GetUId() const { return m_uiUId; }
TPCCHAR GetName() const { return m_szName; }
Expand Down
2 changes: 2 additions & 0 deletions Toshi/Include/TRender/TVertexFactoryResourceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class TVertexPoolResourceInterface;
class TRENDERINTERFACE_EXPORTS TVertexFactoryResourceInterface : public TResource
{
DECLARE_DYNAMIC(TVertexFactoryResourceInterface)

friend TVertexPoolResourceInterface;
public:
TVertexFactoryResourceInterface();

Expand Down
46 changes: 46 additions & 0 deletions Toshi/Include/TRender/TVertexPoolResourceInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once
#include "TVertexFactoryResourceInterface.h"

TOSHI_NAMESPACE_BEGIN

class TVertexPoolResourceInterface : public TResource
{
DECLARE_DYNAMIC(TVertexPoolResourceInterface)

public:

class LockBuffer
{
LockBuffer();

TUINT uiNumStreams;
TUINT32 uiOffset;
unsigned char* apStreams[TVertexFactoryFormat::MAX_NUM_STREAMS];
};

TVertexPoolResourceInterface();

protected:
virtual void OnDestroy() override;
virtual TBOOL Lock(LockBuffer* a_pLockBuffer) = 0;
virtual void Unlock(TUSHORT a_uiNewNumVertices) = 0;
virtual TBOOL Create(TVertexFactoryResourceInterface* a_pFactory, TUINT a_uiMaxVertices, TUINT a_uiFlags);

public:

TVertexFactoryResourceInterface* GetFactory() { return m_pFactory; }
TUINT GetFlags() const { return m_usFlags; }
TUINT GetMaxVertices() const { return m_usMaxVertices; }
TUINT GetNumVertices() const { return m_usNumVertices; }
TBOOL IsLocked() const { return m_uiLockCount != 0; }

private:
// TResource base 0x0 -> 0x30
TVertexFactoryResourceInterface* m_pFactory; // 0x30
TUSHORT m_usFlags; // 0x34
TUSHORT m_usMaxVertices; // 0x36
TUSHORT m_usNumVertices; // 0x38
TUINT m_uiLockCount; // 0x3A
};

TOSHI_NAMESPACE_END
47 changes: 47 additions & 0 deletions Toshi/Include/TRenderD3D/TD3DVertexBlockResource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once
#include "TRender/TResource.h"
#include "TKernel/TFreeList.h"
#include "TRender/TVertexFactoryResourceInterface.h"
#include <d3d8.h>

TOSHI_NAMESPACE_BEGIN

class TVertexPoolResource;
class TVertexFactoryResource;

class TVertexBlockResource : public TResource
{
DECLARE_DYNAMIC(TVertexBlockResource)
DECLARE_FREELIST(TVertexBlockResource)

public:

struct HALBuffer
{
HALBuffer();

TUINT uiNumStreams;
TUSHORT uiVertexOffset;
IDirect3DVertexBuffer8* apVertexBuffers[TVertexFactoryFormat::MAX_NUM_STREAMS];
};

TBOOL Create(TVertexFactoryResource* a_pFactory, TUSHORT a_uiMaxVertices, TUINT a_uiFlags);

TBOOL AttachPool(TVertexPoolResource* a_pPool);
TBOOL CanFit(TVertexPoolResource* a_pPoolResource);

TVertexFactoryResourceInterface* GetFactory() { return m_pFactory; }
TUINT GetFlags() { return m_uiFlags; }

private:
TVertexFactoryResourceInterface* m_pFactory; // 0x30
TUINT m_uiFlags; // 0x34
TUSHORT m_uiMaxVertices;
TUINT m_uiOffset;
TUINT m_uiVerticesUsed;
TUINT m_uiLockCount;
TUINT m_Unk1;
HALBuffer m_HALBuffer;
};

TOSHI_NAMESPACE_END
20 changes: 20 additions & 0 deletions Toshi/Include/TRenderD3D/TD3DVertexFactoryResource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "TRender/TVertexFactoryResourceInterface.h"
#include "TD3DVertexPoolResource.h"
#include "TD3DVertexBlockResource.h"

TOSHI_NAMESPACE_BEGIN

class TVertexFactoryResource : public TVertexFactoryResourceInterface
{
DECLARE_DYNAMIC(TVertexFactoryResource)

public:
virtual TVertexPoolResourceInterface* CreatePoolResource(TUSHORT a_uiMaxStaticVertices, TUINT a_uiFlags);

TVertexBlockResource* FindBlockResource(TVertexPoolResource* a_pResource);
TVertexBlockResource* CreateBlockResource(TUSHORT a_uiMaxVertices, TUINT a_uiFlags);
};

TOSHI_NAMESPACE_END
23 changes: 23 additions & 0 deletions Toshi/Include/TRenderD3D/TD3DVertexPoolResource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "TRender/TVertexPoolResourceInterface.h"


TOSHI_NAMESPACE_BEGIN

class TVertexPoolResource : public TVertexPoolResourceInterface
{
DECLARE_DYNAMIC(TVertexPoolResource)

friend class TVertexFactoryResource;

protected:
virtual TBOOL Validate() override;
virtual void Invalidate() override;
virtual void OnDestroy() override;
virtual TBOOL Lock(LockBuffer* a_pLockBuffer) override;
virtual void Unlock(TUSHORT a_uiNewNumVertices) override;
virtual TBOOL Create(TVertexFactoryResourceInterface* a_pFactory, TUINT a_uiMaxVertices, TUINT a_uiFlags) override;
};

TOSHI_NAMESPACE_END
6 changes: 3 additions & 3 deletions Toshi/Source/TKernel/TScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void TScheduler::Update()
m_fCurrentTimeDelta = 0.0f;
}

DestroyDyingTasks(m_oTaskTree.AttachedToRoot());
UpdateActiveTasks(m_oTaskTree.AttachedToRoot());
DestroyDyingTasks(m_oTaskTree.ChildOfRoot());
UpdateActiveTasks(m_oTaskTree.ChildOfRoot());
}

void TScheduler::DestroyDyingTasks(TTask* a_pTask)
Expand Down Expand Up @@ -107,7 +107,7 @@ void TScheduler::UpdateActiveTasks(TTask* a_pTask)

void TScheduler::DestroyAllTasks()
{
TTask* pAttached = m_oTaskTree.AttachedToRoot();
TTask* pAttached = m_oTaskTree.ChildOfRoot();
if (pAttached) {
DestroyTask(*pAttached);
DeleteTaskAtomic(pAttached);
Expand Down
Loading

0 comments on commit ba151f5

Please sign in to comment.