Skip to content

Commit

Permalink
Some issues are fixed although TFreeList is still buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
AdventureT committed May 18, 2024
1 parent 7b31370 commit e49d678
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 33 deletions.
6 changes: 5 additions & 1 deletion Toshi/Include/TKernel/TFreeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include "TMemory.h"

// There is some kind of critical issue with free lists which causes memory being uninitialised, so we disable it for now
#define DECLARE_FREELIST(class_name)
#define IMPLEMENT_FREELIST(class_name, InitialSize, GrowSize)
#if 0
#define DECLARE_FREELIST(class_name) \
public: \
static TPVOID TOSHI_API operator new(TUINT s, TPVOID mem) { return mem; } \
Expand All @@ -14,7 +18,7 @@ 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);

#endif
TOSHI_NAMESPACE_BEGIN

class TKERNELINTERFACE_EXPORTS TFreeList
Expand Down
2 changes: 1 addition & 1 deletion Toshi/Include/TKernel/TMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TKERNELINTERFACE_EXPORTS TMemory
public:

static TBOOL TOSHI_API Initialise();
static void TOSHI_API DebugPrintHALMemInfo(TCHAR const*) {};
static void TOSHI_API DebugPrintHALMemInfo(TCHAR const* a_pPrint) { };
static TMemory& TOSHI_API GetMemMangager();
static MemBlock* TOSHI_API GetGlobalBlock();
static MemNode* TOSHI_API GetMemNodeFromAddress(TPVOID a_pAddr);
Expand Down
42 changes: 19 additions & 23 deletions Toshi/Include/TKernel/TNodeTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ class TNodeTree
/**
* Inserts node as a child of another node.
*
* @param parentNode Pointer to the parent node.
* @param a_pSourceNode Pointer to the node you want to insert.
* @param parentNode Reference to the parent node.
* @param a_rSourceNode Reference to the node you want to insert.
*/
void Insert(T* parentNode, T* a_pSourceNode)
void Insert(T* parentNode, T* a_rSourceNode)
{
// Toshi::TNodeTree<Toshi::TResource>::Insert - 00691aa0
TASSERT(a_pSourceNode->IsLinked() == TFALSE);
TASSERT(a_rSourceNode->IsLinked() == TFALSE);

// Remove the source node from the tree
Remove(*a_pSourceNode, TFALSE);
Remove(*a_rSourceNode, TFALSE);

// Get the first attached to parent node
T* firstAttached = parentNode->Child();
Expand All @@ -81,35 +81,35 @@ class TNodeTree
// Attach node to other attached nodes
T* lastAttached = firstAttached->Prev();

lastAttached->m_Next = a_pSourceNode;
firstAttached->m_Prev = a_pSourceNode;
lastAttached->m_Next = a_rSourceNode;
firstAttached->m_Prev = a_rSourceNode;

a_pSourceNode->m_Next = firstAttached;
a_pSourceNode->m_Prev = lastAttached;
a_rSourceNode->m_Next = firstAttached;
a_rSourceNode->m_Prev = lastAttached;
}
else
{
// Attach node as the first one
parentNode->m_Child = a_pSourceNode;
parentNode->m_Child = a_rSourceNode;
}

a_pSourceNode->m_Tree = this;
a_pSourceNode->m_Parent = parentNode;
a_rSourceNode->m_Tree = this;
a_rSourceNode->m_Parent = parentNode;
m_Count++;
}

/**
* Inserts node to the default tree.
*
* @param a_pSourceNode Pointer to the node you want to insert.
* @param a_rSourceNode Pointer to the node you want to insert.
*/
void InsertAtRoot(T* sourceNode)
{
Insert(GetRoot(), sourceNode);
}

/**
* Tries to remove a_pSourceNode from the tree and inserts it to the parentNode or to the root
* Tries to remove a_rSourceNode from the tree and inserts it to the parentNode or to the root
*/
void ReInsert(T* parentNode, T* sourceNode)
{
Expand All @@ -132,24 +132,20 @@ class TNodeTree
// Toshi::TNodeTree<Toshi::TResource>::Remove - 00691e70
TNodeTree<T>* nodeRoot = node.GetTree();
T* nodeParent = node.Parent();

if (nodeRoot != TNULL)
{

if (nodeRoot) {
// Check if the node belongs to the current tree
if (nodeRoot != this)
{
if (nodeRoot != this) {
TASSERT(!"A node is being removed from a different tree from it's current tree.");
return &node;
}

m_Count--;
}

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

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

Expand Down
34 changes: 34 additions & 0 deletions Toshi/Include/TKernel/TVector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ TOSHI_NAMESPACE_BEGIN

class TKERNELINTERFACE_EXPORTS TVector2
{
public:

TVector2()
{

}

TVector2(TFLOAT a_fX, TFLOAT a_fY)
{
Set(a_fX, a_fY);
}

TVector2(const TFLOAT a_pfVec[2])
{
Set(a_pfVec);
}

void Set(TFLOAT a_fX, TFLOAT a_fY)
{
m_fX = a_fX;
m_fY = a_fY;
}

void Set(const TFLOAT a_pfVec[2])
{
m_fX = a_pfVec[0];
m_fY = a_pfVec[1];
}

static const TVector2 VEC_ZERO;
static const TVector2 VEC_POSX;
static const TVector2 VEC_POSY;
static const TVector2 VEC_NEGX;
static const TVector2 VEC_NEGY;
private:
TFLOAT m_fX; // 0x0
TFLOAT m_fY; // 0x4
Expand Down
1 change: 0 additions & 1 deletion Toshi/Include/TRender/TRenderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class TRENDERINTERFACE_EXPORTS TRenderInterface : public TObject


public:

TResource* CreateResource(const TClass* a_pClass, TPCCHAR a_szResName, TResource* a_pResource);

const TRenderAdapter::Mode::Device* FindDevice(const DisplayParams* a_pDisplayParams);
Expand Down
2 changes: 1 addition & 1 deletion Toshi/Include/TRenderD3D/TTextureResourceD3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TOSHI_NAMESPACE_BEGIN
class TRENDERINTERFACED3D_EXPORTS TTextureResourceHAL : public TTextureResource
{
DECLARE_DYNAMIC(TTextureResourceHAL)
DECLARE_FREELIST(TTextureResourceHAL)
//DECLARE_FREELIST(TTextureResourceHAL)

enum MIPMAPFLAGS
{
Expand Down
12 changes: 11 additions & 1 deletion Toshi/Source/TKernel/TVector2.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
#include "TVector2.h"
#include "TVector2.h"

TOSHI_NAMESPACE_BEGIN

const TVector2 TVector2::VEC_ZERO = { 0, 0 };
const TVector2 TVector2::VEC_POSX = { 1, 0 };
const TVector2 TVector2::VEC_POSY = { 0, 1 };
const TVector2 TVector2::VEC_NEGX = { -1, 0 };
const TVector2 TVector2::VEC_NEGY = { 0, -1 };

TOSHI_NAMESPACE_END
2 changes: 1 addition & 1 deletion Toshi/Source/TRender/TRenderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void TRenderInterface::DestroySystemResources()
}

TResource* TRenderInterface::CreateResource(const TClass* a_pClass, TPCCHAR a_szResName, TResource* a_pParent)
{
{
TASSERT(TNULL != a_pClass);
TASSERT(a_pClass->IsA(TGetClass(TResource)));

Expand Down
25 changes: 21 additions & 4 deletions Toshi/Source/TRenderD3D/TTextureResourceD3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TOSHI_NAMESPACE_USING

IMPLEMENT_DYNCREATE(TTextureResourceHAL, TTextureResource)
IMPLEMENT_FREELIST(TTextureResourceHAL, 0, 8)
//IMPLEMENT_FREELIST(TTextureResourceHAL, 0, 8)

TBOOL TTextureResourceHAL::Validate()
{
Expand All @@ -20,8 +20,10 @@ TBOOL TTextureResourceHAL::Validate()
if (m_iLoadFromMemory) {
// Load from memory
if (m_pData && m_uiDataSize != 0) {
if (HASFLAG(m_eTextureFlags & 0x40) && !CreateFromFormat()) {
return TFALSE;
if (HASFLAG(m_eTextureFlags & 0x40)) {
if (!CreateFromFormat()) {
return TFALSE;
}
}
else {
TUINT uiLayout = m_eTextureFlags & 0x38;
Expand All @@ -36,7 +38,22 @@ TBOOL TTextureResourceHAL::Validate()
CreateFromMemory8888(m_uiWidth, m_uiHeight, 0, m_pData);
}
else {
CreateFromMemoryDDS(m_uiWidth, m_uiHeight, -1, m_pData);
HRESULT hRes = D3DXCreateTextureFromFileInMemoryEx(pRenderer->GetD3DDevice(),
m_pData,
m_uiDataSize,
-1,
-1,
-1,
0,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_FILTER_BOX,
D3DX_FILTER_BOX,
0,
&m_oImageInfo,
NULL,
&m_pD3DTexture);
TRenderD3DInterface::TD3DAssert(hRes, TNULL);
}
}
}
Expand Down

0 comments on commit e49d678

Please sign in to comment.