-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01f65ef
commit 4287fb4
Showing
7 changed files
with
199 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "PCPrimitivePool.h" | ||
#include "util/Hooking.h" | ||
|
||
void* cdc::PCPrimitivePool::AllocateVertices(unsigned int numVerts) | ||
{ | ||
unsigned int baseOffset; | ||
auto vertices = m_vertexPool.Create(numVerts, &baseOffset); | ||
auto offset = 0; | ||
|
||
auto currentPrimitive = m_currentPrimitive->currentPrimitive; | ||
|
||
if (currentPrimitive && currentPrimitive->vertexBuffer == vertices) | ||
{ | ||
offset = currentPrimitive->numVertices * m_stride; | ||
currentPrimitive->numVertices += numVerts; | ||
} | ||
else | ||
{ | ||
auto primitive = (PartialPrimitive*)m_pFrameHeap->Alloc(sizeof(PartialPrimitive)); | ||
|
||
primitive->baseOffset = baseOffset; | ||
primitive->next = nullptr; | ||
primitive->numVertices = numVerts; | ||
primitive->vertexBuffer = vertices; | ||
|
||
if (m_currentPrimitive->currentPrimitive) | ||
{ | ||
m_currentPrimitive->currentPrimitive->next = primitive; | ||
} | ||
else | ||
{ | ||
m_currentPrimitive->firstPrimitive = primitive; | ||
} | ||
|
||
m_currentPrimitive->currentPrimitive = primitive; | ||
} | ||
|
||
m_currentPrimitive->totalNumVertices += numVerts; | ||
m_totalNumVertices += numVerts; | ||
|
||
return (char*)vertices->m_pVertexData + offset; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <d3d9.h> | ||
|
||
#include "TransientHeapAllocator.h" | ||
#include "PCVertexPool.h" | ||
|
||
namespace cdc | ||
{ | ||
class PCPrimitivePool | ||
{ | ||
private: | ||
TransientHeapAllocator* m_pFrameHeap; | ||
|
||
PCBasicVertexPool m_vertexPool; | ||
D3DPRIMITIVETYPE m_primType; | ||
|
||
unsigned int m_primVerts; | ||
unsigned int m_totalNumVertices; | ||
unsigned int m_stride; | ||
|
||
struct PartialPrimitive | ||
{ | ||
PCDynamicVertexBuffer* vertexBuffer; | ||
unsigned int numVertices; | ||
unsigned int baseOffset; | ||
PartialPrimitive* next; | ||
}; | ||
|
||
struct Primitive | ||
{ | ||
PartialPrimitive* firstPrimitive; | ||
PartialPrimitive* currentPrimitive; | ||
unsigned int totalNumVertices; | ||
}; | ||
|
||
Primitive* m_currentPrimitive; | ||
|
||
public: | ||
void* AllocateVertices(unsigned int numVerts); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "PCVertexPool.h" | ||
#include "util/Hooking.h" | ||
|
||
cdc::PCDynamicVertexBuffer* cdc::PCBasicVertexPool::Create(unsigned int numVertices, unsigned int* baseOffsetInVerts) | ||
{ | ||
auto addr = GET_ADDRESS(0xECDE60, 0x61F840, 0x000000); | ||
|
||
return Hooking::ThisCallReturn<cdc::PCDynamicVertexBuffer*>(addr, this, numVertices, baseOffsetInVerts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#pragma once | ||
|
||
#include <d3d9.h> | ||
|
||
#include "TransientHeapAllocator.h" | ||
|
||
namespace cdc | ||
{ | ||
class PCVertexFormat | ||
{ | ||
}; | ||
|
||
class PCVertexBufferMemPool | ||
{ | ||
}; | ||
|
||
class PCVertexBuffer | ||
{ | ||
public: | ||
virtual ~PCVertexBuffer() = 0; | ||
|
||
virtual unsigned int GetBaseVertexIndex() = 0; | ||
virtual IDirect3DVertexBuffer9* GetD3DVertexBuffer() = 0; | ||
virtual IDirect3DVertexDeclaration9* GetD3DVertexDeclaration() = 0; | ||
virtual unsigned int GetNumVertices() = 0; | ||
virtual unsigned __int16 GetStride() = 0; | ||
}; | ||
|
||
class PCDynamicVertexBuffer : public PCVertexBuffer | ||
{ | ||
public: | ||
IDirect3DVertexBuffer9* m_pD3DVertexBuffer; | ||
void* m_pVertexData; | ||
PCVertexFormat* m_pVertexFormat; | ||
unsigned int m_baseVertexIndex; | ||
unsigned int m_numVertices; | ||
}; | ||
|
||
class PCBasicVertexPool | ||
{ | ||
private: | ||
PCVertexFormat* m_pVertexFormat; | ||
cdc::PCVertexBufferMemPool* m_pVertexBufferMemPool; | ||
TransientHeapAllocator* m_pFrameHeap; | ||
IDirect3DVertexBuffer9* m_pLastVB; | ||
cdc::PCDynamicVertexBuffer* m_pLastSharedVB; | ||
unsigned int m_nVertices; | ||
|
||
public: | ||
PCDynamicVertexBuffer* Create(unsigned int numVertices, unsigned int* baseOffsetInVerts); | ||
|
||
virtual ~PCBasicVertexPool() { }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "TransientHeapAllocator.h" | ||
|
||
char* cdc::TransientHeapAllocator::Alloc(unsigned int size) | ||
{ | ||
auto ptr = m_freePtr; | ||
|
||
if (ptr + size > m_size) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
m_freePtr += size; | ||
return &m_pHeap[ptr]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
namespace cdc | ||
{ | ||
class TransientHeapAllocator | ||
{ | ||
private: | ||
char* m_pHeap; | ||
unsigned int m_size; | ||
unsigned int m_freePtr; | ||
|
||
public: | ||
char* Alloc(unsigned int size); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters