chore: add .clang_format for consistent code formatting

This commit is contained in:
Patoke committed 2026-03-01 20:03:40 -03:00
1 parent 67332bbc79
commit 6e6440f0f3
24 files changed
+400 -440

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# Format Style Options - Created with Clang Power Tools
---
AccessModifierOffset: -4
AlignConsecutiveMacros: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortEnumsOnASingleLine: false
AlwaysBreakTemplateDeclarations: Yes
ColumnLimit: 150
EmptyLineBeforeAccessModifier: Never
IndentAccessModifiers: false
IndentWidth: 4
NamespaceIndentation: All
BreakBeforeBraces: Allman
+3 -3
View File
@@ -1,6 +1,6 @@
#include "4J_Input.h" #include "4J_Input.h"
#include "INP_Main.h"
#include "INP_Keyboard.h" #include "INP_Keyboard.h"
#include "INP_Main.h"
C_4JInput InputManager; C_4JInput InputManager;
CKeyboard InternalKeyboard; CKeyboard InternalKeyboard;
@@ -130,7 +130,8 @@ void C_4JInput::SetMenuDisplayed(int iPad, bool bVal)
InternalInputManager.SetMenuDisplayed(iPad, bVal); InternalInputManager.SetMenuDisplayed(iPad, bVal);
} }
EKeyboardResult C_4JInput::RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int(*Func)(LPVOID, const bool), LPVOID lpParam, C_4JInput::EKeyboardMode eMode) EKeyboardResult C_4JInput::RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int (*Func)(LPVOID, const bool), LPVOID lpParam,
C_4JInput::EKeyboardMode eMode)
{ {
return InternalKeyboard.RequestKeyboard(Title, Text, dwPad, uiMaxChars, Func, lpParam, eMode); return InternalKeyboard.RequestKeyboard(Title, Text, dwPad, uiMaxChars, Func, lpParam, eMode);
} }
@@ -140,7 +141,6 @@ void C_4JInput::GetText(uint16_t* UTF16String)
InternalKeyboard.GetText(UTF16String); InternalKeyboard.GetText(UTF16String);
} }
bool C_4JInput::VerifyStrings(WCHAR **pwStringA, int iStringC, int (*Func)(LPVOID, STRING_VERIFY_RESPONSE *), LPVOID lpParam) bool C_4JInput::VerifyStrings(WCHAR **pwStringA, int iStringC, int (*Func)(LPVOID, STRING_VERIFY_RESPONSE *), LPVOID lpParam)
{ {
return true; return true;
+3 -12
View File
@@ -12,10 +12,7 @@ void CForceFeedback::Initialise(int iInputStateC, unsigned char ucMapC, unsigned
m_unkBool = 0; m_unkBool = 0;
} }
void CForceFeedback::RumbleEnable(int iQuadrant, bool bRumbleEnabled) void CForceFeedback::RumbleEnable(int iQuadrant, bool bRumbleEnabled) {}
{
}
void CForceFeedback::CreateEffect(void) void CForceFeedback::CreateEffect(void)
{ {
@@ -52,15 +49,9 @@ void CForceFeedback::SetEffectInstanceState(unsigned int uiEffectInstance, unsig
pNode->GetDataAs<FF_EFFECT_INSTANCE>()->m_bIsActive = true; pNode->GetDataAs<FF_EFFECT_INSTANCE>()->m_bIsActive = true;
} }
void CForceFeedback::ProcessEventInstance(FF_EFFECT_INSTANCE* pEffectInst) void CForceFeedback::ProcessEventInstance(FF_EFFECT_INSTANCE *pEffectInst) {}
{
} void CForceFeedback::PauseEventInstance(FF_EFFECT_INSTANCE *pEffectInst) {}
void CForceFeedback::PauseEventInstance(FF_EFFECT_INSTANCE* pEffectInst)
{
}
void CForceFeedback::AddRumble(unsigned int uiPad, WORD leftMotorSpeed, WORD rightMotorSpeed, float fSeconds) void CForceFeedback::AddRumble(unsigned int uiPad, WORD leftMotorSpeed, WORD rightMotorSpeed, float fSeconds)
{ {
@@ -6,7 +6,6 @@
class CForceFeedback class CForceFeedback
{ {
public: public:
enum FF_PARAMS enum FF_PARAMS
{ {
FF_PARAMS_RAMP, FF_PARAMS_RAMP,
+3 -5
View File
@@ -1,11 +1,9 @@
#include "INP_Keyboard.h" #include "INP_Keyboard.h"
void CKeyboard::Tick(void) void CKeyboard::Tick(void) {}
{
} EKeyboardResult CKeyboard::RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int (*Func)(LPVOID, const bool), LPVOID lpParam,
C_4JInput::EKeyboardMode eMode)
EKeyboardResult CKeyboard::RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int(*Func)(LPVOID, const bool), LPVOID lpParam, C_4JInput::EKeyboardMode eMode)
{ {
ClearGlobalText(); ClearGlobalText();
SeedEditBox(); SeedEditBox();
+2 -5
View File
@@ -8,22 +8,19 @@ void SeedEditBox();
class CKeyboard class CKeyboard
{ {
public: public:
enum EKeyboardProcessState enum EKeyboardProcessState
{ {
}; };
struct SKeyboardInfo struct SKeyboardInfo
{ {
}; };
void Tick(void); void Tick(void);
EKeyboardResult RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int(*Func)(LPVOID, const bool), LPVOID lpParam, C_4JInput::EKeyboardMode eMode); EKeyboardResult RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int (*Func)(LPVOID, const bool), LPVOID lpParam,
C_4JInput::EKeyboardMode eMode);
void GetText(uint16_t *UTF16String); void GetText(uint16_t *UTF16String);
BYTE gap0[0x68]; BYTE gap0[0x68];
}; };
+6 -4
View File
@@ -402,7 +402,8 @@ unsigned int CInput::GetValue(int iPad, unsigned char ucAction, bool bRepeat)
bool CInput::IsSet(int iPad, unsigned char ucAction) bool CInput::IsSet(int iPad, unsigned char ucAction)
{ {
return (!m_bIsMenuDisplayed[iPad] || ucAction <= m_ucMenuActionC) && (m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtons) != 0; return (!m_bIsMenuDisplayed[iPad] || ucAction <= m_ucMenuActionC) &&
(m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtons) != 0;
} }
bool CInput::ButtonPressed(int iPad, unsigned char ucAction) bool CInput::ButtonPressed(int iPad, unsigned char ucAction)
@@ -422,7 +423,8 @@ bool CInput::ButtonPressed(int iPad, unsigned char ucAction)
bool CInput::ButtonReleased(int iPad, unsigned char ucAction) bool CInput::ButtonReleased(int iPad, unsigned char ucAction)
{ {
return (!m_bIsMenuDisplayed[iPad] || ucAction <= m_ucMenuActionC) && (m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtonsReleased) != 0; return (!m_bIsMenuDisplayed[iPad] || ucAction <= m_ucMenuActionC) &&
(m_JoypadMap[m_Joypads[iPad].m_ucMappingValue][ucAction] & m_Joypads[iPad].m_uiButtonsReleased) != 0;
} }
bool CInput::ButtonDown(int iPad, unsigned char ucAction) bool CInput::ButtonDown(int iPad, unsigned char ucAction)
@@ -627,8 +629,8 @@ bool CInput::UpdateJoypads()
ClearJoypadValues(pThisPad); ClearJoypadValues(pThisPad);
} }
if (m_pDebugSequenceFn && if (m_pDebugSequenceFn && (pThisPad->m_uiButtonsPressed & (_360_JOY_BUTTON_A | _360_JOY_BUTTON_B | _360_JOY_BUTTON_X | _360_JOY_BUTTON_Y |
(pThisPad->m_uiButtonsPressed & (_360_JOY_BUTTON_A | _360_JOY_BUTTON_B | _360_JOY_BUTTON_X | _360_JOY_BUTTON_Y | _360_JOY_BUTTON_RB | _360_JOY_BUTTON_LB)) != 0) _360_JOY_BUTTON_RB | _360_JOY_BUTTON_LB)) != 0)
{ {
char chSeq; char chSeq;
-3
View File
@@ -7,8 +7,6 @@
class CInput class CInput
{ {
public: public:
struct JOYPAD struct JOYPAD
{ {
bool m_bIsDisabled; bool m_bIsDisabled;
@@ -56,7 +54,6 @@ public:
struct JOYPADS struct JOYPADS
{ {
}; };
struct TimeInfo struct TimeInfo
+2 -1
View File
@@ -37,7 +37,8 @@ void LinkedList::AddToTail(void* pvData)
m_Head = pNode; m_Head = pNode;
} }
if (m_Tail) { if (m_Tail)
{
m_Tail->m_Next = pNode; m_Tail->m_Next = pNode;
pNode->m_Prev = m_Tail; pNode->m_Prev = m_Tail;
} }
-2
View File
@@ -3,8 +3,6 @@
class LinkedList class LinkedList
{ {
public: public:
struct _LL_NODE struct _LL_NODE
{ {
template <typename T> template <typename T>
+3 -2
View File
@@ -2,8 +2,11 @@
#include "4J_Render.h" #include "4J_Render.h"
#include "Renderer.h" #include "Renderer.h"
C4JRender RenderManager;
void C4JRender::Tick() void C4JRender::Tick()
{ {
InternalRenderManager.CBuffTick();
} }
void C4JRender::UpdateGamma(unsigned short usGamma) void C4JRender::UpdateGamma(unsigned short usGamma)
@@ -474,5 +477,3 @@ void C4JRender::Resume()
{ {
InternalRenderManager.Resume(); InternalRenderManager.Resume();
} }
C4JRender RenderManager;
+6 -8
View File
@@ -41,8 +41,10 @@ public:
void EndConditionalSurvey(); void EndConditionalSurvey();
void BeginConditionalRendering(int identifier); void BeginConditionalRendering(int identifier);
void EndConditionalRendering(); void EndConditionalRendering();
void DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void* dataIn, C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType); void DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void *dataIn, C4JRender::eVertexType vType,
void DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer* buffer, C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType); C4JRender::ePixelShaderType psType);
void DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType);
void CBuffLockStaticCreations(); void CBuffLockStaticCreations();
int CBuffCreate(int count); int CBuffCreate(int count);
void CBuffDelete(int first, int count); void CBuffDelete(int first, int count);
@@ -108,11 +110,11 @@ public:
bool Suspended(); bool Suspended();
void Resume(); void Resume();
void StateUpdate(); void StateUpdate();
private: private:
void SetupShaders(); void SetupShaders();
void ConvertLinearToPng(ImageFileBuffer *pngOut, unsigned char *linearData, unsigned int width, unsigned int height); void ConvertLinearToPng(ImageFileBuffer *pngOut, unsigned char *linearData, unsigned int width, unsigned int height);
void DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType primitiveType, int* count, bool* drawIndexed); void DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType primitiveType, int *count,
bool *drawIndexed);
void UpdateTexGenState(); void UpdateTexGenState();
void UpdateLightingState(); void UpdateLightingState();
void UpdateViewportState(); void UpdateViewportState();
@@ -127,9 +129,7 @@ private:
Renderer::Context &getContext(); Renderer::Context &getContext();
static D3D11_PRIMITIVE_TOPOLOGY *m_Topologies; static D3D11_PRIMITIVE_TOPOLOGY *m_Topologies;
static DXGI_FORMAT textureFormats[C4JRender::MAX_TEXTURE_FORMATS]; static DXGI_FORMAT textureFormats[C4JRender::MAX_TEXTURE_FORMATS];
public: public:
struct Texture struct Texture
{ {
bool allocated; bool allocated;
@@ -298,8 +298,6 @@ public:
std::uint64_t m_allocated; std::uint64_t m_allocated;
BYTE isActive; BYTE isActive;
BYTE paddingAfterActive[7]; BYTE paddingAfterActive[7];
}; };
struct DeferredCBuff struct DeferredCBuff
+4 -16
View File
@@ -9,12 +9,7 @@
#include <new> #include <new>
Renderer::CommandBuffer::CommandBuffer(bool full) Renderer::CommandBuffer::CommandBuffer(bool full)
: m_vertexBuffer(nullptr) : m_vertexBuffer(nullptr), m_vertexData(nullptr), m_vertexDataLength(0), m_commands(), m_allocated(0x1000), isActive(full ? 1 : 0)
, m_vertexData(nullptr)
, m_vertexDataLength(0)
, m_commands()
, m_allocated(0x1000)
, isActive(full ? 1 : 0)
{ {
std::memset(paddingAfterActive, 0, sizeof(paddingAfterActive)); std::memset(paddingAfterActive, 0, sizeof(paddingAfterActive));
m_vertexData = std::malloc(m_allocated); m_vertexData = std::malloc(m_allocated);
@@ -37,9 +32,7 @@ Renderer::CommandBuffer::~CommandBuffer()
LeaveCriticalSection(&Renderer::totalAllocCS); LeaveCriticalSection(&Renderer::totalAllocCS);
} }
void Renderer::CommandBuffer::StartRecording() void Renderer::CommandBuffer::StartRecording() {}
{
}
void Renderer::CommandBuffer::EndRecording(ID3D11Device *device) void Renderer::CommandBuffer::EndRecording(ID3D11Device *device)
{ {
@@ -269,13 +262,8 @@ void Renderer::CommandBuffer::Render(C4JRender::eVertexType vertexType, Renderer
{ {
if (drawVertexType == C4JRender::VERTEX_TYPE_COMPRESSED) if (drawVertexType == C4JRender::VERTEX_TYPE_COMPRESSED)
{ {
const float row[4] = const float row[4] = {command.add_matrix.m_matrix[12], command.add_matrix.m_matrix[13], command.add_matrix.m_matrix[14],
{ command.add_matrix.m_matrix[15]};
command.add_matrix.m_matrix[12],
command.add_matrix.m_matrix[13],
command.add_matrix.m_matrix[14],
command.add_matrix.m_matrix[15]
};
D3D11_MAPPED_SUBRESOURCE mappedAux0 = {}; D3D11_MAPPED_SUBRESOURCE mappedAux0 = {};
context.m_pDeviceContext->Map(context.cbAux0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedAux0); context.m_pDeviceContext->Map(context.cbAux0, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedAux0);
std::memcpy(mappedAux0.pData, row, sizeof(row)); std::memcpy(mappedAux0.pData, row, sizeof(row));
+220 -236
View File
@@ -9,70 +9,52 @@
#include <limits> #include <limits>
#include <new> #include <new>
Renderer InternalRenderManager;
DWORD Renderer::tlsIdx = TlsAlloc();
int Renderer::totalAlloc = 0;
_RTL_CRITICAL_SECTION Renderer::totalAllocCS = {0};
static const unsigned int kVertexBufferSize = 0x100000u; static const unsigned int kVertexBufferSize = 0x100000u;
static const float kAspectRatio = 1.7777778f; static const float kAspectRatio = 1.7777778f;
static const unsigned int kScreenGrabWidth = 1920u; static const unsigned int kScreenGrabWidth = 1920u;
static const unsigned int kScreenGrabHeight = 1080u; static const unsigned int kScreenGrabHeight = 1080u;
static const unsigned int kThumbnailSize = 64u; static const unsigned int kThumbnailSize = 64u;
static const unsigned int g_vertexStrides[C4JRender::VERTEX_TYPE_COUNT] = { static const unsigned int g_vertexStrides[C4JRender::VERTEX_TYPE_COUNT] = {32u, 16u, 32u, 32u};
32u, 16u, 32u, 32u};
Renderer InternalRenderManager; unsigned int Renderer::s_auiWidths[MAX_MIP_LEVELS + 1] = {1920u, 512u, 256u, 128u, 64u, 0u};
unsigned int Renderer::s_auiHeights[MAX_MIP_LEVELS + 1] = {1080u, 512u, 256u, 128u, 64u, 0xFFFFFFFFu};
DWORD Renderer::tlsIdx = TlsAlloc();
unsigned int Renderer::s_auiWidths[MAX_MIP_LEVELS + 1] = {1920u, 512u, 256u,
128u, 64u, 0u};
unsigned int Renderer::s_auiHeights[MAX_MIP_LEVELS + 1] = {
1080u, 512u, 256u, 128u, 64u, 0xFFFFFFFFu};
D3D11_INPUT_ELEMENT_DESC Renderer::g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1[5] = { D3D11_INPUT_ELEMENT_DESC Renderer::g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1[5] = {
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
D3D11_INPUT_PER_VERTEX_DATA, 0}, {"NORMAL", 0, DXGI_FORMAT_R8G8B8A8_SNORM, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, {"TEXCOORD", 1, DXGI_FORMAT_R16G16_SINT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
0},
{"NORMAL", 0, DXGI_FORMAT_R8G8B8A8_SNORM, 0, 24,
D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 1, DXGI_FORMAT_R16G16_SINT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA,
0},
}; };
D3D11_INPUT_ELEMENT_DESC Renderer::g_vertex_PTN_Elements_Compressed[2] = {
{"POSITION", 0, DXGI_FORMAT_R16G16B16A16_SINT, 0, 0,
D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R16G16B16A16_SINT, 0, 8,
D3D11_INPUT_PER_VERTEX_DATA, 0},
};
D3D11_PRIMITIVE_TOPOLOGY Renderer::g_topologies[C4JRender::PRIMITIVE_TYPE_COUNT] = {
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
D3D11_PRIMITIVE_TOPOLOGY_LINELIST,
D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
};
int Renderer::totalAlloc = 0;
_RTL_CRITICAL_SECTION Renderer::totalAllocCS = {0};
Renderer::Context::Context(ID3D11Device *device, D3D11_INPUT_ELEMENT_DESC Renderer::g_vertex_PTN_Elements_Compressed[2] = {
ID3D11DeviceContext *deviceContext) {"POSITION", 0, DXGI_FORMAT_R16G16B16A16_SINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
: m_pDeviceContext(deviceContext), userAnnotation(nullptr), {"TEXCOORD", 0, DXGI_FORMAT_R16G16B16A16_SINT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
contextStateFlags(0), matrixModeType(0), boundTextureIndex(0), };
faceCullEnabled(1), depthTestEnabled(1), alphaTestEnabled(0),
alphaReference(1.0f), depthWriteEnabled(1), fogEnabled(0), D3D11_PRIMITIVE_TOPOLOGY Renderer::g_topologies[C4JRender::PRIMITIVE_TYPE_COUNT] = {
fogNearDistance(0.0f), fogFarDistance(0.0f), fogDensity(0.0f), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
fogColourRed(0.0f), fogColourBlue(0.0f), fogColourGreen(0.0f), fogMode(0), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, D3D11_PRIMITIVE_TOPOLOGY_LINELIST, D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
lightingEnabled(0), lightingDirty(0), forcedLOD(0xFFFFFFFFu), };
cbMatrix0(nullptr), cbMatrix1(nullptr), cbMatrix2(nullptr),
cbMatrix3(nullptr), cbVertexTexcoord(nullptr), cbFogParams(nullptr), Renderer::Context::Context(ID3D11Device *device, ID3D11DeviceContext *deviceContext)
cbLighting(nullptr), cbTexGen(nullptr), cbAux0(nullptr), cbAux1(nullptr), : m_pDeviceContext(deviceContext), userAnnotation(nullptr), contextStateFlags(0), matrixModeType(0), boundTextureIndex(0), faceCullEnabled(1),
cbColour(nullptr), cbFogColour(nullptr), cbAux2(nullptr), depthTestEnabled(1), alphaTestEnabled(0), alphaReference(1.0f), depthWriteEnabled(1), fogEnabled(0), fogNearDistance(0.0f),
cbAlphaTest(nullptr), cbAux3(nullptr), cbAux4(nullptr), fogFarDistance(0.0f), fogDensity(0.0f), fogColourRed(0.0f), fogColourBlue(0.0f), fogColourGreen(0.0f), fogMode(0), lightingEnabled(0),
dynamicVertexBase(0), dynamicVertexOffset(0), lightingDirty(0), forcedLOD(0xFFFFFFFFu), cbMatrix0(nullptr), cbMatrix1(nullptr), cbMatrix2(nullptr), cbMatrix3(nullptr),
dynamicVertexBuffer(nullptr), commandBuffer(nullptr), cbVertexTexcoord(nullptr), cbFogParams(nullptr), cbLighting(nullptr), cbTexGen(nullptr), cbAux0(nullptr), cbAux1(nullptr), cbColour(nullptr),
recordingBufferIndex(0), recordingVertexType(0), cbFogColour(nullptr), cbAux2(nullptr), cbAlphaTest(nullptr), cbAux3(nullptr), cbAux4(nullptr), dynamicVertexBase(0), dynamicVertexOffset(0),
recordingPrimitiveType(0), deferredModeEnabled(0), deferredBuffers(), dynamicVertexBuffer(nullptr), commandBuffer(nullptr), recordingBufferIndex(0), recordingVertexType(0), recordingPrimitiveType(0),
reservedContext0(0), reservedContext1(0) { deferredModeEnabled(0), deferredBuffers(), reservedContext0(0), reservedContext1(0)
{
deviceContext->QueryInterface(IID_PPV_ARGS(&userAnnotation)); deviceContext->QueryInterface(IID_PPV_ARGS(&userAnnotation));
std::memset(matrixStacks, 0, sizeof(matrixStacks)); std::memset(matrixStacks, 0, sizeof(matrixStacks));
std::memset(matrixDirty, 0, sizeof(matrixDirty)); std::memset(matrixDirty, 0, sizeof(matrixDirty));
@@ -91,7 +73,8 @@ Renderer::Context::Context(ID3D11Device *device,
blendFactor[3] = 0.0f; blendFactor[3] = 0.0f;
const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity(); const DirectX::XMMATRIX identity = DirectX::XMMatrixIdentity();
for (unsigned int i = 0; i < 4; ++i) { for (unsigned int i = 0; i < 4; ++i)
{
matrixStacks[i][0] = identity; matrixStacks[i][0] = identity;
matrixStackDepth[i] = 0; matrixStackDepth[i] = 0;
} }
@@ -105,8 +88,7 @@ Renderer::Context::Context(ID3D11Device *device,
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].RenderTargetWriteMask = blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
D3D11_COLOR_WRITE_ENABLE_ALL;
depthStencilDesc.DepthEnable = TRUE; depthStencilDesc.DepthEnable = TRUE;
depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
@@ -161,8 +143,7 @@ Renderer::Context::Context(ID3D11Device *device,
device->CreateBuffer(&cbDesc, &cbData, &cbVertexTexcoord); device->CreateBuffer(&cbDesc, &cbData, &cbVertexTexcoord);
device->CreateBuffer(&cbDesc, &cbData, &cbFogParams); device->CreateBuffer(&cbDesc, &cbData, &cbFogParams);
const UINT lightingBytes = const UINT lightingBytes = sizeof(lightDirection) + sizeof(lightColour) + sizeof(lightAmbientColour);
sizeof(lightDirection) + sizeof(lightColour) + sizeof(lightAmbientColour);
cbDesc.ByteWidth = lightingBytes; cbDesc.ByteWidth = lightingBytes;
cbData.pSysMem = lightDirection; cbData.pSysMem = lightDirection;
device->CreateBuffer(&cbDesc, &cbData, &cbLighting); device->CreateBuffer(&cbDesc, &cbData, &cbLighting);
@@ -214,7 +195,8 @@ void Renderer::BeginConditionalSurvey(int) {}
void Renderer::CaptureScreen(ImageFileBuffer *, XSOCIAL_PREVIEWIMAGE *) {} void Renderer::CaptureScreen(ImageFileBuffer *, XSOCIAL_PREVIEWIMAGE *) {}
void Renderer::Clear(int flags, D3D11_RECT *) { void Renderer::Clear(int flags, D3D11_RECT *)
{
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
ID3D11BlendState *blendState = nullptr; ID3D11BlendState *blendState = nullptr;
@@ -231,15 +213,12 @@ void Renderer::Clear(int flags, D3D11_RECT *) {
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].RenderTargetWriteMask = blendDesc.RenderTarget[0].RenderTargetWriteMask = (flags & CLEAR_COLOUR_FLAG) ? D3D11_COLOR_WRITE_ENABLE_ALL : 0;
(flags & CLEAR_COLOUR_FLAG) ? D3D11_COLOR_WRITE_ENABLE_ALL : 0;
m_pDevice->CreateBlendState(&blendDesc, &blendState); m_pDevice->CreateBlendState(&blendDesc, &blendState);
D3D11_DEPTH_STENCIL_DESC depthDesc = {}; D3D11_DEPTH_STENCIL_DESC depthDesc = {};
depthDesc.DepthEnable = (flags & CLEAR_DEPTH_FLAG) ? TRUE : FALSE; depthDesc.DepthEnable = (flags & CLEAR_DEPTH_FLAG) ? TRUE : FALSE;
depthDesc.DepthWriteMask = depthDesc.DepthEnable depthDesc.DepthWriteMask = depthDesc.DepthEnable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
? D3D11_DEPTH_WRITE_MASK_ALL
: D3D11_DEPTH_WRITE_MASK_ZERO;
depthDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; depthDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
depthDesc.StencilEnable = FALSE; depthDesc.StencilEnable = FALSE;
depthDesc.StencilReadMask = 0xFFu; depthDesc.StencilReadMask = 0xFFu;
@@ -264,43 +243,40 @@ void Renderer::Clear(int flags, D3D11_RECT *) {
context.m_pDeviceContext->VSSetShader(screenClearVertexShader, nullptr, 0); context.m_pDeviceContext->VSSetShader(screenClearVertexShader, nullptr, 0);
context.m_pDeviceContext->IASetInputLayout(nullptr); context.m_pDeviceContext->IASetInputLayout(nullptr);
context.m_pDeviceContext->PSSetShader(screenClearPixelShader, nullptr, 0); context.m_pDeviceContext->PSSetShader(screenClearPixelShader, nullptr, 0);
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
depthStencilView);
context.m_pDeviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFFu); context.m_pDeviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFFu);
context.m_pDeviceContext->OMSetDepthStencilState(depthState, 0); context.m_pDeviceContext->OMSetDepthStencilState(depthState, 0);
context.m_pDeviceContext->RSSetState(rasterizerState); context.m_pDeviceContext->RSSetState(rasterizerState);
context.m_pDeviceContext->PSSetShaderResources(0, 0, nullptr); context.m_pDeviceContext->PSSetShaderResources(0, 0, nullptr);
context.m_pDeviceContext->IASetPrimitiveTopology( context.m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
context.m_pDeviceContext->Draw(4, 0); context.m_pDeviceContext->Draw(4, 0);
if (blendState) { if (blendState)
{
blendState->Release(); blendState->Release();
blendState = nullptr; blendState = nullptr;
} }
if (depthState) { if (depthState)
{
depthState->Release(); depthState->Release();
depthState = nullptr; depthState = nullptr;
} }
if (rasterizerState) { if (rasterizerState)
{
rasterizerState->Release(); rasterizerState->Release();
rasterizerState = nullptr; rasterizerState = nullptr;
} }
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
context.blendFactor, 0xFFFFFFFFu); context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
context.m_pDeviceContext->OMSetDepthStencilState(
this->GetManagedDepthStencilState(), 0);
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState()); context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
depthStencilView);
activeVertexType = 0xFFFFFFFFu; activeVertexType = 0xFFFFFFFFu;
activePixelType = 0xFFFFFFFFu; activePixelType = 0xFFFFFFFFu;
} }
void Renderer::ConvertLinearToPng(ImageFileBuffer *pngOut, void Renderer::ConvertLinearToPng(ImageFileBuffer *pngOut, unsigned char *linearData, unsigned int width, unsigned int height)
unsigned char *linearData, unsigned int width, {
unsigned int height) {
const size_t dataSize = size_t(width) * size_t(height) * 4u; const size_t dataSize = size_t(width) * size_t(height) * 4u;
const size_t outputCapacity = ((dataSize * 24u) / 20u) + 256u; const size_t outputCapacity = ((dataSize * 24u) / 20u) + 256u;
const int outputCapacityInt = int(outputCapacity); const int outputCapacityInt = int(outputCapacity);
@@ -308,45 +284,46 @@ void Renderer::ConvertLinearToPng(ImageFileBuffer *pngOut,
const int heightInt = int(height); const int heightInt = int(height);
void *outputBuffer = std::malloc(outputCapacity); void *outputBuffer = std::malloc(outputCapacity);
int outputLength = 0; int outputLength = 0;
this->SaveTextureDataToMemory(outputBuffer, outputCapacityInt, &outputLength, this->SaveTextureDataToMemory(outputBuffer, outputCapacityInt, &outputLength, widthInt, heightInt, reinterpret_cast<int *>(linearData));
widthInt, heightInt,
reinterpret_cast<int *>(linearData));
pngOut->m_type = ImageFileBuffer::e_typePNG; pngOut->m_type = ImageFileBuffer::e_typePNG;
pngOut->m_pBuffer = outputBuffer; pngOut->m_pBuffer = outputBuffer;
pngOut->m_bufferSize = outputLength; pngOut->m_bufferSize = outputLength;
} }
void Renderer::DoScreenGrabOnNextPresent() { shouldScreenGrabNextFrame = 1; } void Renderer::DoScreenGrabOnNextPresent()
{
shouldScreenGrabNextFrame = 1;
}
void Renderer::EndConditionalRendering() {} void Renderer::EndConditionalRendering() {}
void Renderer::EndConditionalSurvey() {} void Renderer::EndConditionalSurvey() {}
void Renderer::BeginEvent(LPCWSTR eventName) { void Renderer::BeginEvent(LPCWSTR eventName)
Renderer::Context *context = {
static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx)); Renderer::Context *context = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
if (context && if (context && context->m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && context->userAnnotation)
context->m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && {
context->userAnnotation) {
context->userAnnotation->BeginEvent(eventName); context->userAnnotation->BeginEvent(eventName);
++context->contextStateFlags; ++context->contextStateFlags;
} }
} }
void Renderer::EndEvent() { void Renderer::EndEvent()
Renderer::Context *context = {
static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx)); Renderer::Context *context = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
if (context && if (context && context->m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && context->userAnnotation)
context->m_pDeviceContext->GetType() != D3D11_DEVICE_CONTEXT_DEFERRED && {
context->userAnnotation) {
context->userAnnotation->EndEvent(); context->userAnnotation->EndEvent();
if (context->contextStateFlags > 0) { if (context->contextStateFlags > 0)
{
--context->contextStateFlags; --context->contextStateFlags;
} }
} }
} }
void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) { void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain)
{
m_pDevice = pDevice; m_pDevice = pDevice;
m_pDeviceContext = this->InitialiseContext(true); m_pDeviceContext = this->InitialiseContext(true);
m_pSwapChain = pSwapChain; m_pSwapChain = pSwapChain;
@@ -382,7 +359,8 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
UINT backBufferSampleQuality = 0; UINT backBufferSampleQuality = 0;
ID3D11Texture2D *backBuffer = nullptr; ID3D11Texture2D *backBuffer = nullptr;
pSwapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)); pSwapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer));
if (backBuffer) { if (backBuffer)
{
D3D11_TEXTURE2D_DESC backDesc = {}; D3D11_TEXTURE2D_DESC backDesc = {};
backBuffer->GetDesc(&backDesc); backBuffer->GetDesc(&backDesc);
backBufferWidth = backDesc.Width; backBufferWidth = backDesc.Width;
@@ -390,18 +368,19 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
backBufferSampleCount = backDesc.SampleDesc.Count; backBufferSampleCount = backDesc.SampleDesc.Count;
backBufferSampleQuality = backDesc.SampleDesc.Quality; backBufferSampleQuality = backDesc.SampleDesc.Quality;
m_pDevice->CreateRenderTargetView(backBuffer, nullptr, &renderTargetView); m_pDevice->CreateRenderTargetView(backBuffer, nullptr, &renderTargetView);
m_pDevice->CreateShaderResourceView(backBuffer, nullptr, m_pDevice->CreateShaderResourceView(backBuffer, nullptr, &renderTargetShaderResourceView);
&renderTargetShaderResourceView);
backBuffer->Release(); backBuffer->Release();
} }
ID3D11RenderTargetView *boundRTV = nullptr; ID3D11RenderTargetView *boundRTV = nullptr;
m_pDeviceContext->OMGetRenderTargets(1, &boundRTV, &depthStencilView); m_pDeviceContext->OMGetRenderTargets(1, &boundRTV, &depthStencilView);
if (boundRTV) { if (boundRTV)
{
boundRTV->Release(); boundRTV->Release();
} }
if (!depthStencilView && backBufferWidth != 0 && backBufferHeight != 0) { if (!depthStencilView && backBufferWidth != 0 && backBufferHeight != 0)
{
D3D11_TEXTURE2D_DESC depthDesc = {}; D3D11_TEXTURE2D_DESC depthDesc = {};
depthDesc.Width = backBufferWidth; depthDesc.Width = backBufferWidth;
depthDesc.Height = backBufferHeight; depthDesc.Height = backBufferHeight;
@@ -414,15 +393,15 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
depthDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
ID3D11Texture2D *depthTexture = nullptr; ID3D11Texture2D *depthTexture = nullptr;
if (SUCCEEDED( if (SUCCEEDED(m_pDevice->CreateTexture2D(&depthDesc, nullptr, &depthTexture)))
m_pDevice->CreateTexture2D(&depthDesc, nullptr, &depthTexture))) { {
m_pDevice->CreateDepthStencilView(depthTexture, nullptr, m_pDevice->CreateDepthStencilView(depthTexture, nullptr, &depthStencilView);
&depthStencilView);
depthTexture->Release(); depthTexture->Release();
} }
} }
for (unsigned int i = 0; i < MAX_MIP_LEVELS - 1; ++i) { for (unsigned int i = 0; i < MAX_MIP_LEVELS - 1; ++i)
{
D3D11_TEXTURE2D_DESC desc = {}; D3D11_TEXTURE2D_DESC desc = {};
desc.Width = s_auiWidths[i + 1]; desc.Width = s_auiWidths[i + 1];
desc.Height = s_auiHeights[i + 1]; desc.Height = s_auiHeights[i + 1];
@@ -434,10 +413,8 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
m_pDevice->CreateTexture2D(&desc, nullptr, &renderTargetTextures[i]); m_pDevice->CreateTexture2D(&desc, nullptr, &renderTargetTextures[i]);
m_pDevice->CreateRenderTargetView(renderTargetTextures[i], nullptr, m_pDevice->CreateRenderTargetView(renderTargetTextures[i], nullptr, &renderTargetViews[i]);
&renderTargetViews[i]); m_pDevice->CreateShaderResourceView(renderTargetTextures[i], nullptr, &renderTargetShaderResourceViews[i]);
m_pDevice->CreateShaderResourceView(renderTargetTextures[i], nullptr,
&renderTargetShaderResourceViews[i]);
} }
std::memset(m_textures, 0, sizeof(m_textures)); std::memset(m_textures, 0, sizeof(m_textures));
@@ -446,8 +423,7 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
unsigned char *defaultTextureData = new unsigned char[0x400u]; unsigned char *defaultTextureData = new unsigned char[0x400u];
std::memset(defaultTextureData, 0xFF, 0x400u); std::memset(defaultTextureData, 0xFF, 0x400u);
this->TextureData(16, 16, defaultTextureData, 0, this->TextureData(16, 16, defaultTextureData, 0, C4JRender::TEXTURE_FORMAT_RxGyBzAw);
C4JRender::TEXTURE_FORMAT_RxGyBzAw);
delete[] defaultTextureData; delete[] defaultTextureData;
presentCount = 0; presentCount = 0;
@@ -464,7 +440,8 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
reservedRendererByte0 = 0; reservedRendererByte0 = 0;
unsigned short *quadIndices = new unsigned short[0x18000u]; unsigned short *quadIndices = new unsigned short[0x18000u];
for (unsigned int i = 0; i < 0x4000u; ++i) { for (unsigned int i = 0; i < 0x4000u; ++i)
{
const unsigned short base = (unsigned short)(i * 4u); const unsigned short base = (unsigned short)(i * 4u);
const unsigned int offset = i * 6u; const unsigned int offset = i * 6u;
quadIndices[offset + 0] = base; quadIndices[offset + 0] = base;
@@ -484,7 +461,8 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
delete[] quadIndices; delete[] quadIndices;
unsigned short *fanIndices = new unsigned short[0x2FFFAu]; unsigned short *fanIndices = new unsigned short[0x2FFFAu];
for (unsigned int i = 0; i < 65534u; ++i) { for (unsigned int i = 0; i < 65534u; ++i)
{
const unsigned int offset = i * 3u; const unsigned int offset = i * 3u;
fanIndices[offset + 0] = 0u; fanIndices[offset + 0] = 0u;
fanIndices[offset + 1] = (unsigned short)(i + 1u); fanIndices[offset + 1] = (unsigned short)(i + 1u);
@@ -503,32 +481,44 @@ void Renderer::Initialise(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) {
m_Topologies = g_topologies; m_Topologies = g_topologies;
} }
ID3D11DeviceContext *Renderer::InitialiseContext(bool fromPresent) { ID3D11DeviceContext *Renderer::InitialiseContext(bool fromPresent)
{
ID3D11DeviceContext *deviceContext = nullptr; ID3D11DeviceContext *deviceContext = nullptr;
if (fromPresent) { if (fromPresent)
{
m_pDevice->GetImmediateContext(&deviceContext); m_pDevice->GetImmediateContext(&deviceContext);
} else { }
else
{
m_pDevice->CreateDeferredContext(0, &deviceContext); m_pDevice->CreateDeferredContext(0, &deviceContext);
} }
Renderer::Context *context = Renderer::Context *context = new (std::nothrow) Renderer::Context(m_pDevice, deviceContext);
new (std::nothrow) Renderer::Context(m_pDevice, deviceContext);
TlsSetValue(Renderer::tlsIdx, context); TlsSetValue(Renderer::tlsIdx, context);
return deviceContext; return deviceContext;
} }
bool Renderer::IsHiDef() { return true; } bool Renderer::IsHiDef()
{
return true;
}
bool Renderer::IsWidescreen() { return true; } bool Renderer::IsWidescreen()
{
return true;
}
void Renderer::Present() { void Renderer::Present()
if (shouldScreenGrabNextFrame) { {
if (shouldScreenGrabNextFrame)
{
int *linearData = new int[kScreenGrabWidth * kScreenGrabHeight]; int *linearData = new int[kScreenGrabWidth * kScreenGrabHeight];
ID3D11Texture2D *backBuffer = nullptr; ID3D11Texture2D *backBuffer = nullptr;
ID3D11Texture2D *stagingTexture = nullptr; ID3D11Texture2D *stagingTexture = nullptr;
m_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer)); m_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&backBuffer));
if (backBuffer) { if (backBuffer)
{
D3D11_TEXTURE2D_DESC desc = {}; D3D11_TEXTURE2D_DESC desc = {};
backBuffer->GetDesc(&desc); backBuffer->GetDesc(&desc);
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
@@ -538,19 +528,21 @@ void Renderer::Present() {
m_pDevice->CreateTexture2D(&desc, nullptr, &stagingTexture); m_pDevice->CreateTexture2D(&desc, nullptr, &stagingTexture);
} }
if (stagingTexture && backBuffer) { if (stagingTexture && backBuffer)
{
m_pDeviceContext->CopyResource(stagingTexture, backBuffer); m_pDeviceContext->CopyResource(stagingTexture, backBuffer);
D3D11_MAPPED_SUBRESOURCE mapped = {}; D3D11_MAPPED_SUBRESOURCE mapped = {};
if (SUCCEEDED(m_pDeviceContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, if (SUCCEEDED(m_pDeviceContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mapped)))
&mapped))) { {
unsigned char *dst = reinterpret_cast<unsigned char *>(linearData); unsigned char *dst = reinterpret_cast<unsigned char *>(linearData);
const unsigned char *src = const unsigned char *src = reinterpret_cast<const unsigned char *>(mapped.pData);
reinterpret_cast<const unsigned char *>(mapped.pData); for (unsigned int y = 0; y < kScreenGrabHeight; ++y)
for (unsigned int y = 0; y < kScreenGrabHeight; ++y) { {
unsigned char *dstRow = dst + y * (kScreenGrabWidth * 4u); unsigned char *dstRow = dst + y * (kScreenGrabWidth * 4u);
const unsigned char *srcRow = src + y * mapped.RowPitch; const unsigned char *srcRow = src + y * mapped.RowPitch;
std::memcpy(dstRow, srcRow, kScreenGrabWidth * 4u); std::memcpy(dstRow, srcRow, kScreenGrabWidth * 4u);
for (unsigned int x = 0; x < kScreenGrabWidth; ++x) { for (unsigned int x = 0; x < kScreenGrabWidth; ++x)
{
dstRow[x * 4u + 3u] = 0xFF; dstRow[x * 4u + 3u] = 0xFF;
} }
} }
@@ -567,11 +559,13 @@ void Renderer::Present() {
this->SaveTextureData(fileName, &info, linearData); this->SaveTextureData(fileName, &info, linearData);
delete[] linearData; delete[] linearData;
if (stagingTexture) { if (stagingTexture)
{
stagingTexture->Release(); stagingTexture->Release();
stagingTexture = nullptr; stagingTexture = nullptr;
} }
if (backBuffer) { if (backBuffer)
{
backBuffer->Release(); backBuffer->Release();
backBuffer = nullptr; backBuffer = nullptr;
} }
@@ -582,35 +576,41 @@ void Renderer::Present() {
++presentCount; ++presentCount;
} }
void Renderer::Resume() { suspended = 0; } void Renderer::Resume()
{
suspended = 0;
}
void Renderer::SetClearColour(const float colourRGBA[4]) { void Renderer::SetClearColour(const float colourRGBA[4])
{
std::memcpy(m_fClearColor, colourRGBA, sizeof(m_fClearColor)); std::memcpy(m_fClearColor, colourRGBA, sizeof(m_fClearColor));
Renderer::Context *context = Renderer::Context *context = static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx)); if (context)
if (context) { {
D3D11_MAPPED_SUBRESOURCE mapped = {}; D3D11_MAPPED_SUBRESOURCE mapped = {};
context->m_pDeviceContext->Map(context->cbAux3, 0, D3D11_MAP_WRITE_DISCARD, context->m_pDeviceContext->Map(context->cbAux3, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
0, &mapped);
std::memcpy(mapped.pData, colourRGBA, sizeof(float) * 4); std::memcpy(mapped.pData, colourRGBA, sizeof(float) * 4);
context->m_pDeviceContext->Unmap(context->cbAux3, 0); context->m_pDeviceContext->Unmap(context->cbAux3, 0);
} }
} }
void Renderer::SetupShaders() { void Renderer::SetupShaders()
{
vertexShaderTable = new ID3D11VertexShader *[C4JRender::VERTEX_TYPE_COUNT]; vertexShaderTable = new ID3D11VertexShader *[C4JRender::VERTEX_TYPE_COUNT];
pixelShaderTable = new ID3D11PixelShader *[C4JRender::PIXEL_SHADER_COUNT]; pixelShaderTable = new ID3D11PixelShader *[C4JRender::PIXEL_SHADER_COUNT];
vertexStrideTable = new unsigned int[C4JRender::VERTEX_TYPE_COUNT]; vertexStrideTable = new unsigned int[C4JRender::VERTEX_TYPE_COUNT];
inputLayoutTable = new ID3D11InputLayout *[C4JRender::VERTEX_TYPE_COUNT]; inputLayoutTable = new ID3D11InputLayout *[C4JRender::VERTEX_TYPE_COUNT];
for (unsigned int i = 0; i < C4JRender::VERTEX_TYPE_COUNT; ++i) { for (unsigned int i = 0; i < C4JRender::VERTEX_TYPE_COUNT; ++i)
{
vertexShaderTable[i] = nullptr; vertexShaderTable[i] = nullptr;
inputLayoutTable[i] = nullptr; inputLayoutTable[i] = nullptr;
vertexStrideTable[i] = g_vertexStrides[i]; vertexStrideTable[i] = g_vertexStrides[i];
} }
for (unsigned int i = 0; i < C4JRender::PIXEL_SHADER_COUNT; ++i) { for (unsigned int i = 0; i < C4JRender::PIXEL_SHADER_COUNT; ++i)
{
pixelShaderTable[i] = nullptr; pixelShaderTable[i] = nullptr;
} }
@@ -619,62 +619,35 @@ void Renderer::SetupShaders() {
screenSpacePixelShader = nullptr; screenSpacePixelShader = nullptr;
screenClearPixelShader = nullptr; screenClearPixelShader = nullptr;
m_pDevice->CreateVertexShader( m_pDevice->CreateVertexShader(VS_PF3_TF2_CB4_NB4_XW1_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Data), nullptr,
VS_PF3_TF2_CB4_NB4_XW1_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Data), nullptr,
&vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1]); &vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1]);
m_pDevice->CreateVertexShader( m_pDevice->CreateVertexShader(VS_Compressed_Data, sizeof(VS_Compressed_Data), nullptr, &vertexShaderTable[C4JRender::VERTEX_TYPE_COMPRESSED]);
VS_Compressed_Data, sizeof(VS_Compressed_Data), nullptr, m_pDevice->CreateVertexShader(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data), nullptr,
&vertexShaderTable[C4JRender::VERTEX_TYPE_COMPRESSED]);
m_pDevice->CreateVertexShader(
VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data,
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data), nullptr,
&vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]); &vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]);
m_pDevice->CreateVertexShader( m_pDevice->CreateVertexShader(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data), nullptr,
VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data,
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data), nullptr,
&vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]); &vertexShaderTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]);
m_pDevice->CreateVertexShader(VS_ScreenSpace_Data, m_pDevice->CreateVertexShader(VS_ScreenSpace_Data, sizeof(VS_ScreenSpace_Data), nullptr, &screenSpaceVertexShader);
sizeof(VS_ScreenSpace_Data), nullptr, m_pDevice->CreateVertexShader(VS_ScreenClear_Data, sizeof(VS_ScreenClear_Data), nullptr, &screenClearVertexShader);
&screenSpaceVertexShader);
m_pDevice->CreateVertexShader(VS_ScreenClear_Data,
sizeof(VS_ScreenClear_Data), nullptr,
&screenClearVertexShader);
m_pDevice->CreatePixelShader( m_pDevice->CreatePixelShader(PS_Standard_Data, sizeof(PS_Standard_Data), nullptr, &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_STANDARD]);
PS_Standard_Data, sizeof(PS_Standard_Data), nullptr, m_pDevice->CreatePixelShader(PS_TextureProjection_Data, sizeof(PS_TextureProjection_Data), nullptr,
&pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_STANDARD]);
m_pDevice->CreatePixelShader(
PS_TextureProjection_Data, sizeof(PS_TextureProjection_Data), nullptr,
&pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_PROJECTION]); &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_PROJECTION]);
m_pDevice->CreatePixelShader( m_pDevice->CreatePixelShader(PS_ForceLOD_Data, sizeof(PS_ForceLOD_Data), nullptr, &pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_FORCELOD]);
PS_ForceLOD_Data, sizeof(PS_ForceLOD_Data), nullptr, m_pDevice->CreatePixelShader(PS_ScreenSpace_Data, sizeof(PS_ScreenSpace_Data), nullptr, &screenSpacePixelShader);
&pixelShaderTable[C4JRender::PIXEL_SHADER_TYPE_FORCELOD]); m_pDevice->CreatePixelShader(PS_ScreenClear_Data, sizeof(PS_ScreenClear_Data), nullptr, &screenClearPixelShader);
m_pDevice->CreatePixelShader(PS_ScreenSpace_Data, sizeof(PS_ScreenSpace_Data),
nullptr, &screenSpacePixelShader);
m_pDevice->CreatePixelShader(PS_ScreenClear_Data, sizeof(PS_ScreenClear_Data),
nullptr, &screenClearPixelShader);
m_pDevice->CreateInputLayout( m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Data, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Data),
g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Data,
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Data),
&inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1]); &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1]);
m_pDevice->CreateInputLayout( m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_Compressed, 2, VS_Compressed_Data, sizeof(VS_Compressed_Data),
g_vertex_PTN_Elements_Compressed, 2, VS_Compressed_Data,
sizeof(VS_Compressed_Data),
&inputLayoutTable[C4JRender::VERTEX_TYPE_COMPRESSED]); &inputLayoutTable[C4JRender::VERTEX_TYPE_COMPRESSED]);
m_pDevice->CreateInputLayout( m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data,
g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, sizeof(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data), &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]);
VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data, m_pDevice->CreateInputLayout(g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5, VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data,
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Lighting_Data), sizeof(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data), &inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]);
&inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_LIT]);
m_pDevice->CreateInputLayout(
g_vertex_PTN_Elements_PF3_TF2_CB4_NB4_XW1, 5,
VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data,
sizeof(VS_PF3_TF2_CB4_NB4_XW1_Texgen_Data),
&inputLayoutTable[C4JRender::VERTEX_TYPE_PF3_TF2_CB4_NB4_XW1_TEXGEN]);
} }
void Renderer::StartFrame() { void Renderer::StartFrame()
{
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
activeVertexType = 0xFFFFFFFFu; activeVertexType = 0xFFFFFFFFu;
@@ -706,21 +679,28 @@ void Renderer::StartFrame() {
viewport.MinDepth = 0.0f; viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f; viewport.MaxDepth = 1.0f;
context.m_pDeviceContext->RSSetViewports(1, &viewport); context.m_pDeviceContext->RSSetViewports(1, &viewport);
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
depthStencilView);
} }
void Renderer::Suspend() { suspended = 1; } void Renderer::Suspend()
{
suspended = 1;
}
bool Renderer::Suspended() { return suspended != 0; } bool Renderer::Suspended()
{
return suspended != 0;
}
void Renderer::UpdateGamma(unsigned short) {} void Renderer::UpdateGamma(unsigned short) {}
Renderer::Context &Renderer::getContext() { Renderer::Context &Renderer::getContext()
{
return *static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx)); return *static_cast<Renderer::Context *>(TlsGetValue(Renderer::tlsIdx));
} }
void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) { void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut)
{
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
float left; float left;
@@ -731,7 +711,8 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
bottom = 0.0f; bottom = 0.0f;
right = 1.0f; right = 1.0f;
top = 1.0f; top = 1.0f;
switch (m_ViewportType) { switch (m_ViewportType)
{
case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
bottom = 0.5f; bottom = 0.5f;
break; break;
@@ -769,11 +750,14 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
const float viewportHeight = top - bottom; const float viewportHeight = top - bottom;
const float viewportScaledWidth = rightScaled - leftScaled; const float viewportScaledWidth = rightScaled - leftScaled;
if (viewportHeight <= viewportScaledWidth) { if (viewportHeight <= viewportScaledWidth)
{
const float pad = (viewportScaledWidth - viewportHeight) * 0.5f; const float pad = (viewportScaledWidth - viewportHeight) * 0.5f;
leftScaled += pad; leftScaled += pad;
rightScaled -= pad; rightScaled -= pad;
} else { }
else
{
const float pad = (viewportHeight - viewportScaledWidth) * 0.5f; const float pad = (viewportHeight - viewportScaledWidth) * 0.5f;
bottom += pad; bottom += pad;
top -= pad; top -= pad;
@@ -797,8 +781,7 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].RenderTargetWriteMask = blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
D3D11_COLOR_WRITE_ENABLE_ALL;
m_pDevice->CreateBlendState(&blendDesc, &blendState); m_pDevice->CreateBlendState(&blendDesc, &blendState);
D3D11_DEPTH_STENCIL_DESC depthDesc = {}; D3D11_DEPTH_STENCIL_DESC depthDesc = {};
@@ -843,7 +826,8 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
context.m_pDeviceContext->OMSetDepthStencilState(depthState, 0); context.m_pDeviceContext->OMSetDepthStencilState(depthState, 0);
context.m_pDeviceContext->RSSetState(rasterizerState); context.m_pDeviceContext->RSSetState(rasterizerState);
for (unsigned int i = 0; i < MAX_MIP_LEVELS - 1; ++i) { for (unsigned int i = 0; i < MAX_MIP_LEVELS - 1; ++i)
{
D3D11_VIEWPORT viewport = {}; D3D11_VIEWPORT viewport = {};
viewport.TopLeftX = 0.0f; viewport.TopLeftX = 0.0f;
viewport.TopLeftY = 0.0f; viewport.TopLeftY = 0.0f;
@@ -852,28 +836,26 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
viewport.MinDepth = 0.0f; viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f; viewport.MaxDepth = 1.0f;
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetViews[i], context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetViews[i], nullptr);
nullptr);
context.m_pDeviceContext->RSSetViewports(1, &viewport); context.m_pDeviceContext->RSSetViewports(1, &viewport);
ID3D11ShaderResourceView *inputTexture = ID3D11ShaderResourceView *inputTexture = (i == 0) ? renderTargetShaderResourceView : renderTargetShaderResourceViews[i - 1];
(i == 0) ? renderTargetShaderResourceView
: renderTargetShaderResourceViews[i - 1];
context.m_pDeviceContext->PSSetShaderResources(0, 1, &inputTexture); context.m_pDeviceContext->PSSetShaderResources(0, 1, &inputTexture);
context.m_pDeviceContext->PSSetSamplers(0, 1, &samplerState); context.m_pDeviceContext->PSSetSamplers(0, 1, &samplerState);
context.m_pDeviceContext->IASetPrimitiveTopology( context.m_pDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
D3D11_MAPPED_SUBRESOURCE mapped = {}; D3D11_MAPPED_SUBRESOURCE mapped = {};
context.m_pDeviceContext->Map(context.cbAux1, 0, D3D11_MAP_WRITE_DISCARD, 0, context.m_pDeviceContext->Map(context.cbAux1, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
&mapped);
float *constants = static_cast<float *>(mapped.pData); float *constants = static_cast<float *>(mapped.pData);
if (i == 0) { if (i == 0)
{
constants[0] = sampleLeft; constants[0] = sampleLeft;
constants[1] = bottom; constants[1] = bottom;
constants[2] = sampleWidth; constants[2] = sampleWidth;
constants[3] = sampleHeight; constants[3] = sampleHeight;
} else { }
else
{
constants[0] = 0.0f; constants[0] = 0.0f;
constants[1] = 0.0f; constants[1] = 0.0f;
constants[2] = 1.0f; constants[2] = 1.0f;
@@ -891,20 +873,20 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
desc.MiscFlags = 0; desc.MiscFlags = 0;
m_pDevice->CreateTexture2D(&desc, nullptr, &stagingTexture); m_pDevice->CreateTexture2D(&desc, nullptr, &stagingTexture);
unsigned char *linearData = unsigned char *linearData = new unsigned char[kThumbnailSize * kThumbnailSize * 4u];
new unsigned char[kThumbnailSize * kThumbnailSize * 4u]; if (stagingTexture)
if (stagingTexture) { {
context.m_pDeviceContext->CopyResource( context.m_pDeviceContext->CopyResource(stagingTexture, renderTargetTextures[MAX_MIP_LEVELS - 2]);
stagingTexture, renderTargetTextures[MAX_MIP_LEVELS - 2]);
D3D11_MAPPED_SUBRESOURCE mapped = {}; D3D11_MAPPED_SUBRESOURCE mapped = {};
if (SUCCEEDED(context.m_pDeviceContext->Map(stagingTexture, 0, if (SUCCEEDED(context.m_pDeviceContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mapped)))
D3D11_MAP_READ, 0, &mapped))) { {
const unsigned char *src = const unsigned char *src = static_cast<const unsigned char *>(mapped.pData);
static_cast<const unsigned char *>(mapped.pData);
unsigned char *dst = linearData; unsigned char *dst = linearData;
for (unsigned int y = 0; y < kThumbnailSize; ++y) { for (unsigned int y = 0; y < kThumbnailSize; ++y)
{
std::memcpy(dst, src, kThumbnailSize * 4u); std::memcpy(dst, src, kThumbnailSize * 4u);
for (unsigned int x = 0; x < kThumbnailSize; ++x) { for (unsigned int x = 0; x < kThumbnailSize; ++x)
{
dst[x * 4u + 3u] = 0xFF; dst[x * 4u + 3u] = 0xFF;
} }
src += mapped.RowPitch; src += mapped.RowPitch;
@@ -917,31 +899,34 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
this->ConvertLinearToPng(pngOut, linearData, kThumbnailSize, kThumbnailSize); this->ConvertLinearToPng(pngOut, linearData, kThumbnailSize, kThumbnailSize);
delete[] linearData; delete[] linearData;
if (stagingTexture) { if (stagingTexture)
{
stagingTexture->Release(); stagingTexture->Release();
stagingTexture = nullptr; stagingTexture = nullptr;
} }
if (samplerState) { if (samplerState)
{
samplerState->Release(); samplerState->Release();
samplerState = nullptr; samplerState = nullptr;
} }
if (rasterizerState) { if (rasterizerState)
{
rasterizerState->Release(); rasterizerState->Release();
rasterizerState = nullptr; rasterizerState = nullptr;
} }
if (depthState) { if (depthState)
{
depthState->Release(); depthState->Release();
depthState = nullptr; depthState = nullptr;
} }
if (blendState) { if (blendState)
{
blendState->Release(); blendState->Release();
blendState = nullptr; blendState = nullptr;
} }
context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.m_pDeviceContext->OMSetBlendState(this->GetManagedBlendState(), context.blendFactor, 0xFFFFFFFFu);
context.blendFactor, 0xFFFFFFFFu); context.m_pDeviceContext->OMSetDepthStencilState(this->GetManagedDepthStencilState(), 0);
context.m_pDeviceContext->OMSetDepthStencilState(
this->GetManagedDepthStencilState(), 0);
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState()); context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
D3D11_VIEWPORT viewport = {}; D3D11_VIEWPORT viewport = {};
@@ -952,8 +937,7 @@ void Renderer::CaptureThumbnail(ImageFileBuffer *pngOut) {
viewport.MinDepth = 0.0f; viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f; viewport.MaxDepth = 1.0f;
context.m_pDeviceContext->RSSetViewports(1, &viewport); context.m_pDeviceContext->RSSetViewports(1, &viewport);
context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, context.m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
depthStencilView);
activeVertexType = 0xFFFFFFFFu; activeVertexType = 0xFFFFFFFFu;
activePixelType = 0xFFFFFFFFu; activePixelType = 0xFFFFFFFFu;
} }
+8 -26
View File
@@ -10,11 +10,8 @@ ID3D11BlendState* Renderer::GetManagedBlendState()
Context &context = this->getContext(); Context &context = this->getContext();
const D3D11_RENDER_TARGET_BLEND_DESC &rtBlend = context.blendDesc.RenderTarget[0]; const D3D11_RENDER_TARGET_BLEND_DESC &rtBlend = context.blendDesc.RenderTarget[0];
const int key = const int key = (rtBlend.BlendEnable ? 1 : 0) | ((static_cast<int>(rtBlend.SrcBlend) & 0x1F) << 1) |
(rtBlend.BlendEnable ? 1 : 0) | ((static_cast<int>(rtBlend.DestBlend) & 0x1F) << 6) | ((static_cast<int>(rtBlend.RenderTargetWriteMask) & 0x0F) << 11);
((static_cast<int>(rtBlend.SrcBlend) & 0x1F) << 1) |
((static_cast<int>(rtBlend.DestBlend) & 0x1F) << 6) |
((static_cast<int>(rtBlend.RenderTargetWriteMask) & 0x0F) << 11);
auto it = managedBlendStates.find(key); auto it = managedBlendStates.find(key);
if (it != managedBlendStates.end()) if (it != managedBlendStates.end())
@@ -32,9 +29,7 @@ ID3D11DepthStencilState* Renderer::GetManagedDepthStencilState()
{ {
Context &context = this->getContext(); Context &context = this->getContext();
const int key = const int key = (context.depthStencilDesc.DepthEnable ? 2 : 0) | ((static_cast<int>(context.depthStencilDesc.DepthFunc) & 0x0F) << 2) |
(context.depthStencilDesc.DepthEnable ? 2 : 0) |
((static_cast<int>(context.depthStencilDesc.DepthFunc) & 0x0F) << 2) |
(context.depthStencilDesc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL ? 1 : 0); (context.depthStencilDesc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL ? 1 : 0);
auto it = managedDepthStencilStates.find(key); auto it = managedDepthStencilStates.find(key);
@@ -53,8 +48,7 @@ ID3D11RasterizerState* Renderer::GetManagedRasterizerState()
{ {
Context &context = this->getContext(); Context &context = this->getContext();
const int key = const int key = (static_cast<std::uint8_t>(context.rasterizerDesc.DepthBias)) |
(static_cast<std::uint8_t>(context.rasterizerDesc.DepthBias)) |
(static_cast<std::uint8_t>(static_cast<int>(context.rasterizerDesc.SlopeScaledDepthBias)) << 8) | (static_cast<std::uint8_t>(static_cast<int>(context.rasterizerDesc.SlopeScaledDepthBias)) << 8) |
((static_cast<int>(context.rasterizerDesc.CullMode) & 0x03) << 16); ((static_cast<int>(context.rasterizerDesc.CullMode) & 0x03) << 16);
@@ -146,9 +140,7 @@ void Renderer::StateSetFogColour(float red, float green, float blue)
context.fogColourGreen = green; context.fogColourGreen = green;
} }
void Renderer::UpdateViewportState() void Renderer::UpdateViewportState() {}
{
}
void Renderer::StateSetLightingEnable(bool enable) void Renderer::StateSetLightingEnable(bool enable)
{ {
@@ -347,9 +339,7 @@ void Renderer::StateSetFaceCullCW(bool enable)
context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState()); context.m_pDeviceContext->RSSetState(this->GetManagedRasterizerState());
} }
void Renderer::StateSetLineWidth(float) void Renderer::StateSetLineWidth(float) {}
{
}
void Renderer::StateSetWriteEnable(bool red, bool green, bool blue, bool alpha) void Renderer::StateSetWriteEnable(bool red, bool green, bool blue, bool alpha)
{ {
@@ -422,13 +412,7 @@ void Renderer::UpdateFogState()
} }
} }
const float fogColour[4] = const float fogColour[4] = {context.fogColourRed, context.fogColourGreen, context.fogColourBlue, 1.0f};
{
context.fogColourRed,
context.fogColourGreen,
context.fogColourBlue,
1.0f
};
D3D11_MAPPED_SUBRESOURCE mapped = {}; D3D11_MAPPED_SUBRESOURCE mapped = {};
d3d11->Map(context.cbFogParams, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped); d3d11->Map(context.cbFogParams, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped);
@@ -581,9 +565,7 @@ void Renderer::StateSetViewport(C4JRender::eViewportType viewportType)
m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView); m_pDeviceContext->OMSetRenderTargets(1, &renderTargetView, depthStencilView);
} }
void Renderer::StateSetEnableViewportClipPlanes(bool) void Renderer::StateSetEnableViewportClipPlanes(bool) {}
{
}
void Renderer::StateSetTexGenCol(int col, float x, float y, float z, float w, bool eyeSpace) void Renderer::StateSetTexGenCol(int col, float x, float y, float z, float w, bool eyeSpace)
{ {
+94 -65
View File
@@ -11,10 +11,13 @@ DXGI_FORMAT Renderer::textureFormats[C4JRender::MAX_TEXTURE_FORMATS] = {
DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM,
}; };
int Renderer::TextureCreate() { int Renderer::TextureCreate()
for (int i = 0; i < 512; ++i) { {
for (int i = 0; i < 512; ++i)
{
Texture &texture = m_textures[i]; Texture &texture = m_textures[i];
if (!texture.allocated) { if (!texture.allocated)
{
texture.texture = nullptr; texture.texture = nullptr;
texture.allocated = true; texture.allocated = true;
texture.mipLevels = 1; texture.mipLevels = 1;
@@ -26,42 +29,50 @@ int Renderer::TextureCreate() {
return -1; return -1;
} }
void Renderer::TextureSetTextureLevels(int levels) { void Renderer::TextureSetTextureLevels(int levels)
{
const int boundTextureIndex = this->getContext().boundTextureIndex; const int boundTextureIndex = this->getContext().boundTextureIndex;
m_textures[boundTextureIndex].mipLevels = levels; m_textures[boundTextureIndex].mipLevels = levels;
} }
int Renderer::TextureGetTextureLevels() { int Renderer::TextureGetTextureLevels()
{
const int boundTextureIndex = this->getContext().boundTextureIndex; const int boundTextureIndex = this->getContext().boundTextureIndex;
return m_textures[boundTextureIndex].mipLevels; return m_textures[boundTextureIndex].mipLevels;
} }
void Renderer::TextureSetParam(int param, int value) { void Renderer::TextureSetParam(int param, int value)
{
Texture &texture = m_textures[this->getContext().boundTextureIndex]; Texture &texture = m_textures[this->getContext().boundTextureIndex];
switch (param) { switch (param)
{
case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MIN_FILTER:
texture.samplerParams &= ~4u; texture.samplerParams &= ~4u;
if (value == 1) { if (value == 1)
{
texture.samplerParams |= 4u; texture.samplerParams |= 4u;
} }
break; break;
case GL_TEXTURE_MAG_FILTER: case GL_TEXTURE_MAG_FILTER:
texture.samplerParams &= ~8u; texture.samplerParams &= ~8u;
if (value == 1) { if (value == 1)
{
texture.samplerParams |= 8u; texture.samplerParams |= 8u;
} }
break; break;
case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_S:
texture.samplerParams &= ~1u; texture.samplerParams &= ~1u;
if (value == 0) { if (value == 0)
{
texture.samplerParams |= 1u; texture.samplerParams |= 1u;
} }
break; break;
case GL_TEXTURE_WRAP_T: case GL_TEXTURE_WRAP_T:
case 5: case 5:
texture.samplerParams &= ~2u; texture.samplerParams &= ~2u;
if (value == 0) { if (value == 0)
{
texture.samplerParams |= 2u; texture.samplerParams |= 2u;
} }
break; break;
@@ -74,13 +85,14 @@ void Renderer::TextureDynamicUpdateStart() {}
void Renderer::TextureDynamicUpdateEnd() {} void Renderer::TextureDynamicUpdateEnd() {}
void Renderer::TextureData(int width, int height, void *data, int level, void Renderer::TextureData(int width, int height, void *data, int level, C4JRender::eTextureFormat format)
C4JRender::eTextureFormat format) { {
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
Texture &texture = m_textures[context.boundTextureIndex]; Texture &texture = m_textures[context.boundTextureIndex];
texture.textureFormat = format; texture.textureFormat = format;
if (level == 0) { if (level == 0)
{
D3D11_TEXTURE2D_DESC desc = {}; D3D11_TEXTURE2D_DESC desc = {};
desc.Width = width; desc.Width = width;
desc.Height = height; desc.Height = height;
@@ -91,18 +103,16 @@ void Renderer::TextureData(int width, int height, void *data, int level,
desc.Usage = D3D11_USAGE_DEFAULT; desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
m_pDevice->CreateTexture2D(&desc, nullptr, &texture.texture); m_pDevice->CreateTexture2D(&desc, nullptr, &texture.texture);
m_pDevice->CreateShaderResourceView(texture.texture, nullptr, m_pDevice->CreateShaderResourceView(texture.texture, nullptr, &texture.view);
&texture.view);
} }
const UINT rowPitch = width * 4u; const UINT rowPitch = width * 4u;
const UINT depthPitch = width * height * 4u; const UINT depthPitch = width * height * 4u;
context.m_pDeviceContext->UpdateSubresource(texture.texture, level, nullptr, context.m_pDeviceContext->UpdateSubresource(texture.texture, level, nullptr, data, rowPitch, depthPitch);
data, rowPitch, depthPitch);
} }
void Renderer::TextureDataUpdate(int xoffset, int yoffset, int width, void Renderer::TextureDataUpdate(int xoffset, int yoffset, int width, int height, void *data, int level)
int height, void *data, int level) { {
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
Texture &texture = m_textures[context.boundTextureIndex]; Texture &texture = m_textures[context.boundTextureIndex];
@@ -119,11 +129,11 @@ void Renderer::TextureDataUpdate(int xoffset, int yoffset, int width,
const UINT rowPitch = width * 4u; const UINT rowPitch = width * 4u;
const UINT depthPitch = width * height * 4u; const UINT depthPitch = width * height * 4u;
context.m_pDeviceContext->UpdateSubresource(texture.texture, level, &box, context.m_pDeviceContext->UpdateSubresource(texture.texture, level, &box, data, rowPitch, depthPitch);
data, rowPitch, depthPitch);
} }
void Renderer::TextureFree(int idx) { void Renderer::TextureFree(int idx)
{
Texture &texture = m_textures[idx]; Texture &texture = m_textures[idx];
texture.texture->Release(); texture.texture->Release();
texture.view->Release(); texture.view->Release();
@@ -134,28 +144,34 @@ void Renderer::TextureFree(int idx) {
void Renderer::TextureGetStats() {} void Renderer::TextureGetStats() {}
ID3D11ShaderResourceView *Renderer::TextureGetTexture(int idx) { ID3D11ShaderResourceView *Renderer::TextureGetTexture(int idx)
if (idx < 0 || idx > 0x1FF) { {
if (idx < 0 || idx > 0x1FF)
{
return nullptr; return nullptr;
} }
const Texture &texture = m_textures[idx]; const Texture &texture = m_textures[idx];
if (!texture.allocated) { if (!texture.allocated)
{
return nullptr; return nullptr;
} }
return texture.view; return texture.view;
} }
void Renderer::TextureBind(int idx) { void Renderer::TextureBind(int idx)
{
int textureIndex = idx; int textureIndex = idx;
if (textureIndex == -1) { if (textureIndex == -1)
{
textureIndex = defaultTextureIndex; textureIndex = defaultTextureIndex;
} }
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
if (context.commandBuffer && context.commandBuffer->isActive) { if (context.commandBuffer && context.commandBuffer->isActive)
{
context.commandBuffer->BindTexture(textureIndex); context.commandBuffer->BindTexture(textureIndex);
} }
@@ -165,9 +181,11 @@ void Renderer::TextureBind(int idx) {
this->UpdateTextureState(false); this->UpdateTextureState(false);
} }
void Renderer::TextureBindVertex(int idx) { void Renderer::TextureBindVertex(int idx)
{
int textureIndex = idx; int textureIndex = idx;
if (textureIndex == -1) { if (textureIndex == -1)
{
textureIndex = defaultTextureIndex; textureIndex = defaultTextureIndex;
} }
@@ -179,20 +197,25 @@ void Renderer::TextureBindVertex(int idx) {
this->UpdateTextureState(true); this->UpdateTextureState(true);
} }
void Renderer::UpdateTextureState(bool vertexSampler) { void Renderer::UpdateTextureState(bool vertexSampler)
{
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
ID3D11SamplerState *sampler = this->GetManagedSamplerState(); ID3D11SamplerState *sampler = this->GetManagedSamplerState();
if (vertexSampler) { if (vertexSampler)
{
context.m_pDeviceContext->VSSetSamplers(0, 1, &sampler); context.m_pDeviceContext->VSSetSamplers(0, 1, &sampler);
} else { }
else
{
context.m_pDeviceContext->PSSetSamplers(0, 1, &sampler); context.m_pDeviceContext->PSSetSamplers(0, 1, &sampler);
} }
} }
HRESULT Renderer::LoadTextureData(const char *szFilename, HRESULT Renderer::LoadTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut)
D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut) { {
if (!szFilename || !pSrcInfo || !ppDataOut) { if (!szFilename || !pSrcInfo || !ppDataOut)
{
return -1; return -1;
} }
@@ -201,32 +224,35 @@ HRESULT Renderer::LoadTextureData(const char *szFilename,
png_image image; png_image image;
std::memset(&image, 0, sizeof(image)); std::memset(&image, 0, sizeof(image));
image.version = PNG_IMAGE_VERSION; image.version = PNG_IMAGE_VERSION;
if (!png_image_begin_read_from_file(&image, szFilename)) { if (!png_image_begin_read_from_file(&image, szFilename))
{
return -1; return -1;
} }
if (image.width == 0 || image.height == 0) { if (image.width == 0 || image.height == 0)
{
png_image_free(&image); png_image_free(&image);
return -1; return -1;
} }
image.format = PNG_FORMAT_RGBA; image.format = PNG_FORMAT_RGBA;
const png_alloc_size_t pixelCount = const png_alloc_size_t pixelCount = png_alloc_size_t(image.width) * png_alloc_size_t(image.height);
png_alloc_size_t(image.width) * png_alloc_size_t(image.height); if (pixelCount == 0 || pixelCount > (std::numeric_limits<size_t>::max)() / sizeof(int))
if (pixelCount == 0 || {
pixelCount > (std::numeric_limits<size_t>::max)() / sizeof(int)) {
png_image_free(&image); png_image_free(&image);
return -1; return -1;
} }
int *output = new (std::nothrow) int[size_t(pixelCount)]; int *output = new (std::nothrow) int[size_t(pixelCount)];
if (!output) { if (!output)
{
png_image_free(&image); png_image_free(&image);
return -1; return -1;
} }
if (!png_image_finish_read(&image, nullptr, output, 0, nullptr)) { if (!png_image_finish_read(&image, nullptr, output, 0, nullptr))
{
delete[] output; delete[] output;
png_image_free(&image); png_image_free(&image);
return -1; return -1;
@@ -239,9 +265,10 @@ HRESULT Renderer::LoadTextureData(const char *szFilename,
return 0; return 0;
} }
HRESULT Renderer::LoadTextureData(BYTE *pbData, DWORD dwBytes, HRESULT Renderer::LoadTextureData(BYTE *pbData, DWORD dwBytes, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut)
D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut) { {
if (!pbData || dwBytes == 0 || !pSrcInfo || !ppDataOut) { if (!pbData || dwBytes == 0 || !pSrcInfo || !ppDataOut)
{
return -1; return -1;
} }
@@ -250,32 +277,35 @@ HRESULT Renderer::LoadTextureData(BYTE *pbData, DWORD dwBytes,
png_image image; png_image image;
std::memset(&image, 0, sizeof(image)); std::memset(&image, 0, sizeof(image));
image.version = PNG_IMAGE_VERSION; image.version = PNG_IMAGE_VERSION;
if (!png_image_begin_read_from_memory(&image, pbData, dwBytes)) { if (!png_image_begin_read_from_memory(&image, pbData, dwBytes))
{
return -1; return -1;
} }
if (image.width == 0 || image.height == 0) { if (image.width == 0 || image.height == 0)
{
png_image_free(&image); png_image_free(&image);
return -1; return -1;
} }
image.format = PNG_FORMAT_RGBA; image.format = PNG_FORMAT_RGBA;
const png_alloc_size_t pixelCount = const png_alloc_size_t pixelCount = png_alloc_size_t(image.width) * png_alloc_size_t(image.height);
png_alloc_size_t(image.width) * png_alloc_size_t(image.height); if (pixelCount == 0 || pixelCount > (std::numeric_limits<size_t>::max)() / sizeof(int))
if (pixelCount == 0 || {
pixelCount > (std::numeric_limits<size_t>::max)() / sizeof(int)) {
png_image_free(&image); png_image_free(&image);
return -1; return -1;
} }
int *output = new (std::nothrow) int[size_t(pixelCount)]; int *output = new (std::nothrow) int[size_t(pixelCount)];
if (!output) { if (!output)
{
png_image_free(&image); png_image_free(&image);
return -1; return -1;
} }
if (!png_image_finish_read(&image, nullptr, output, 0, nullptr)) { if (!png_image_finish_read(&image, nullptr, output, 0, nullptr))
{
delete[] output; delete[] output;
png_image_free(&image); png_image_free(&image);
return -1; return -1;
@@ -288,8 +318,8 @@ HRESULT Renderer::LoadTextureData(BYTE *pbData, DWORD dwBytes,
return 0; return 0;
} }
HRESULT Renderer::SaveTextureData(const char *szFilename, HRESULT Renderer::SaveTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int *ppDataOut)
D3DXIMAGE_INFO *pSrcInfo, int *ppDataOut) { {
png_image image = {}; png_image image = {};
image.version = PNG_IMAGE_VERSION; image.version = PNG_IMAGE_VERSION;
image.width = pSrcInfo->Width; image.width = pSrcInfo->Width;
@@ -300,11 +330,10 @@ HRESULT Renderer::SaveTextureData(const char *szFilename,
return 0; return 0;
} }
HRESULT Renderer::SaveTextureDataToMemory(void *pOutput, int outputCapacity, HRESULT Renderer::SaveTextureDataToMemory(void *pOutput, int outputCapacity, int *outputLength, int width, int height, int *ppDataIn)
int *outputLength, int width, {
int height, int *ppDataIn) { if (!pOutput || outputCapacity <= 0 || !outputLength || width <= 0 || height <= 0 || !ppDataIn)
if (!pOutput || outputCapacity <= 0 || !outputLength || width <= 0 || {
height <= 0 || !ppDataIn) {
return -1; return -1;
} }
@@ -316,8 +345,8 @@ HRESULT Renderer::SaveTextureDataToMemory(void *pOutput, int outputCapacity,
image.format = PNG_FORMAT_RGBA; image.format = PNG_FORMAT_RGBA;
png_alloc_size_t memoryBytes = static_cast<png_alloc_size_t>(outputCapacity); png_alloc_size_t memoryBytes = static_cast<png_alloc_size_t>(outputCapacity);
if (!png_image_write_to_memory(&image, pOutput, &memoryBytes, 0, ppDataIn, 0, if (!png_image_write_to_memory(&image, pOutput, &memoryBytes, 0, ppDataIn, 0, nullptr))
nullptr)) { {
*outputLength = 0; *outputLength = 0;
png_image_free(&image); png_image_free(&image);
return -1; return -1;
+3 -15
View File
@@ -7,11 +7,7 @@
D3D11_PRIMITIVE_TOPOLOGY *Renderer::m_Topologies = nullptr; D3D11_PRIMITIVE_TOPOLOGY *Renderer::m_Topologies = nullptr;
void Renderer::DrawVertexBuffer( void Renderer::DrawVertexBuffer(C4JRender::ePrimitiveType PrimitiveType, int count, ID3D11Buffer *buffer, C4JRender::eVertexType vType,
C4JRender::ePrimitiveType PrimitiveType,
int count,
ID3D11Buffer* buffer,
C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType) C4JRender::ePixelShaderType psType)
{ {
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
@@ -36,11 +32,7 @@ void Renderer::DrawVertexBuffer(
} }
} }
void Renderer::DrawVertexSetup( void Renderer::DrawVertexSetup(C4JRender::eVertexType vType, C4JRender::ePixelShaderType psType, C4JRender::ePrimitiveType PrimitiveType, int *count,
C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType,
C4JRender::ePrimitiveType PrimitiveType,
int* count,
bool *indexed) bool *indexed)
{ {
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
@@ -118,11 +110,7 @@ void Renderer::DrawVertexSetup(
*indexed = false; *indexed = false;
} }
void Renderer::DrawVertices( void Renderer::DrawVertices(C4JRender::ePrimitiveType PrimitiveType, int count, void *vertices, C4JRender::eVertexType vType,
C4JRender::ePrimitiveType PrimitiveType,
int count,
void* vertices,
C4JRender::eVertexType vType,
C4JRender::ePixelShaderType psType) C4JRender::ePixelShaderType psType)
{ {
Renderer::Context &context = this->getContext(); Renderer::Context &context = this->getContext();
+14 -10
View File
@@ -5,10 +5,7 @@
C4JStorage StorageManager; C4JStorage StorageManager;
XMARKETPLACE_CONTENTOFFER_INFO InternalContentOfferInfo; XMARKETPLACE_CONTENTOFFER_INFO InternalContentOfferInfo;
C4JStorage::C4JStorage() C4JStorage::C4JStorage() {}
{
}
void C4JStorage::Tick(void) void C4JStorage::Tick(void)
{ {
@@ -16,7 +13,8 @@ void C4JStorage::Tick(void)
} }
C4JStorage::EMessageResult C4JStorage::RequestMessageBox(UINT uiTitle, UINT uiText, UINT *uiOptionA, UINT uiOptionC, DWORD dwPad, C4JStorage::EMessageResult C4JStorage::RequestMessageBox(UINT uiTitle, UINT uiText, UINT *uiOptionA, UINT uiOptionC, DWORD dwPad,
int(*Func)(LPVOID, int, const C4JStorage::EMessageResult), LPVOID lpParam, C4JStringTable* pStringTable, WCHAR* pwchFormatString, DWORD dwFocusButton) int (*Func)(LPVOID, int, const C4JStorage::EMessageResult), LPVOID lpParam,
C4JStringTable *pStringTable, WCHAR *pwchFormatString, DWORD dwFocusButton)
{ {
return EMessage_Undefined; return EMessage_Undefined;
} }
@@ -31,7 +29,8 @@ bool C4JStorage::SetSaveDevice(int(*Func)(LPVOID, const bool), LPVOID lpParam, b
return true; return true;
} }
void C4JStorage::Init(unsigned int uiSaveVersion, LPCWSTR pwchDefaultSaveName, char* pszSavePackName, int iMinimumSaveSize, int(*Func)(LPVOID, const ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID) void C4JStorage::Init(unsigned int uiSaveVersion, LPCWSTR pwchDefaultSaveName, char *pszSavePackName, int iMinimumSaveSize,
int (*Func)(LPVOID, const ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID)
{ {
InternalStorageManager.Init(Func, lpParam, szGroupID); InternalStorageManager.Init(Func, lpParam, szGroupID);
} }
@@ -137,7 +136,8 @@ void C4JStorage::SetSaveMessageVPosition(float fY)
; ;
} }
C4JStorage::ESaveGameState C4JStorage::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS* pSaveDetails, const bool), LPVOID lpParam, char* pszSavePackName) C4JStorage::ESaveGameState C4JStorage::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS *pSaveDetails, const bool), LPVOID lpParam,
char *pszSavePackName)
{ {
return InternalStorageManager.m_SaveGame.GetSavesInfo(iPad, Func, lpParam, pszSavePackName); return InternalStorageManager.m_SaveGame.GetSavesInfo(iPad, Func, lpParam, pszSavePackName);
} }
@@ -152,7 +152,8 @@ void C4JStorage::ClearSavesInfo()
InternalStorageManager.m_SaveGame.ClearSavesInfo(); InternalStorageManager.m_SaveGame.ClearSavesInfo();
} }
C4JStorage::ESaveGameState C4JStorage::LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, int(*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam) C4JStorage::ESaveGameState C4JStorage::LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo,
int (*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam)
{ {
return InternalStorageManager.m_SaveGame.LoadSaveDataThumbnail(pSaveInfo, Func, lpParam); return InternalStorageManager.m_SaveGame.LoadSaveDataThumbnail(pSaveInfo, Func, lpParam);
} }
@@ -253,7 +254,8 @@ std::string C4JStorage::GetMountedPath(std::string szMount)
} }
C4JStorage::ETMSStatus C4JStorage::ReadTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, C4JStorage::eTMS_FileType eFileType, C4JStorage::ETMSStatus C4JStorage::ReadTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, C4JStorage::eTMS_FileType eFileType,
WCHAR* pwchFilename, BYTE** ppBuffer, DWORD* pdwBufferSize, int(*Func)(LPVOID, WCHAR*, int, bool, int), LPVOID lpParam, int iAction) WCHAR *pwchFilename, BYTE **ppBuffer, DWORD *pdwBufferSize,
int (*Func)(LPVOID, WCHAR *, int, bool, int), LPVOID lpParam, int iAction)
{ {
return ETMSStatus_Idle; return ETMSStatus_Idle;
} }
@@ -273,7 +275,9 @@ void C4JStorage::StoreTMSPathName(WCHAR* pwchName)
; ;
} }
C4JStorage::ETMSStatus C4JStorage::TMSPP_ReadFile(int iPad, C4JStorage::eGlobalStorage eStorageFacility, C4JStorage::eTMS_FILETYPEVAL eFileTypeVal, LPCSTR szFilename, int(*Func)(LPVOID, int, int, PTMSPP_FILEDATA, LPCSTR), LPVOID lpParam, int iUserData) C4JStorage::ETMSStatus C4JStorage::TMSPP_ReadFile(int iPad, C4JStorage::eGlobalStorage eStorageFacility, C4JStorage::eTMS_FILETYPEVAL eFileTypeVal,
LPCSTR szFilename, int (*Func)(LPVOID, int, int, PTMSPP_FILEDATA, LPCSTR), LPVOID lpParam,
int iUserData)
{ {
return ETMSStatus_Idle; return ETMSStatus_Idle;
} }
-1
View File
@@ -203,7 +203,6 @@ std::string CDLC::GetMountedPath(std::string szMount)
return ""; return "";
} }
void CDLC::SetDLCProductCode(const char *szProductCode) void CDLC::SetDLCProductCode(const char *szProductCode)
{ {
strcpy(m_szDLCProductCode, szProductCode); strcpy(m_szDLCProductCode, szProductCode);
+2 -2
View File
@@ -4,7 +4,6 @@
class CDLC class CDLC
{ {
public: public:
struct DriveMapping struct DriveMapping
{ {
DriveMapping(std::string szDirectoryPath, std::string szMountPath) : m_szDirectoryPath(szDirectoryPath), m_szMountPath(szMountPath) DriveMapping(std::string szDirectoryPath, std::string szMountPath) : m_szDirectoryPath(szDirectoryPath), m_szMountPath(szMountPath)
@@ -19,7 +18,8 @@ public:
XCONTENT_DATA &GetDLC(DWORD dw); XCONTENT_DATA &GetDLC(DWORD dw);
CDLC(void); CDLC(void);
C4JStorage::EDLCStatus GetOffers(int iPad, int(*Func)(LPVOID, int, DWORD, int), LPVOID lpParam, DWORD dwOfferTypesBitmask = XMARKETPLACE_OFFERING_TYPE_CONTENT); C4JStorage::EDLCStatus GetOffers(int iPad, int (*Func)(LPVOID, int, DWORD, int), LPVOID lpParam,
DWORD dwOfferTypesBitmask = XMARKETPLACE_OFFERING_TYPE_CONTENT);
void ClearOffers(); void ClearOffers();
C4JStorage::EDLCStatus GetInstalledDLC(int iPad, int (*Func)(LPVOID, int, int), LPVOID lpParam); C4JStorage::EDLCStatus GetInstalledDLC(int iPad, int (*Func)(LPVOID, int, int), LPVOID lpParam);
DWORD MountInstalledDLC(int iPad, DWORD dwDLC, int (*Func)(LPVOID, int, DWORD, DWORD), LPVOID lpParam, LPCSTR szMountDrive = NULL); DWORD MountInstalledDLC(int iPad, DWORD dwDLC, int (*Func)(LPVOID, int, DWORD, DWORD), LPVOID lpParam, LPCSTR szMountDrive = NULL);
+1 -4
View File
@@ -10,10 +10,7 @@ CStorage::CStorage(void)
m_DLC = CDLC(); m_DLC = CDLC();
} }
void CStorage::Init(int(*Func)(LPVOID, const C4JStorage::ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID) void CStorage::Init(int (*Func)(LPVOID, const C4JStorage::ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID) {}
{
}
void CStorage::Tick(void) void CStorage::Tick(void)
{ {
+1 -2
View File
@@ -1,11 +1,10 @@
#pragma once #pragma once
#include "STO_SaveGame.h"
#include "STO_DLC.h" #include "STO_DLC.h"
#include "STO_SaveGame.h"
class CStorage class CStorage
{ {
public: public:
CStorage(void); CStorage(void);
void Init(int (*Func)(LPVOID, const C4JStorage::ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID); void Init(int (*Func)(LPVOID, const C4JStorage::ESavingMessage, int), LPVOID lpParam, LPCSTR szGroupID);
+8 -14
View File
@@ -39,7 +39,8 @@ void CSaveGame::ResetSaveData()
m_uiSaveSize = 0; m_uiSaveSize = 0;
} }
C4JStorage::ESaveGameState CSaveGame::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS* pSaveDetails, const bool), LPVOID lpParam, char* pszSavePackName) C4JStorage::ESaveGameState CSaveGame::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS *pSaveDetails, const bool), LPVOID lpParam,
char *pszSavePackName)
{ {
WIN32_FIND_DATAA findFileData; WIN32_FIND_DATAA findFileData;
WIN32_FILE_ATTRIBUTE_DATA fileInfoBuffer; WIN32_FILE_ATTRIBUTE_DATA fileInfoBuffer;
@@ -90,9 +91,8 @@ C4JStorage::ESaveGameState CSaveGame::GetSavesInfo(int iPad, int (*Func)(LPVOID
{ {
do do
{ {
if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 && strcmp(findFileData.cFileName, ".") &&
&& strcmp(findFileData.cFileName, ".") strcmp(findFileData.cFileName, ".."))
&& strcmp(findFileData.cFileName, ".."))
{ {
strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveFilename, findFileData.cFileName); strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveFilename, findFileData.cFileName);
strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle, findFileData.cFileName); strcpy_s(m_pSaveDetails->SaveInfoA[i].UTF8SaveTitle, findFileData.cFileName);
@@ -142,7 +142,8 @@ void CSaveGame::ClearSavesInfo()
} }
} }
C4JStorage::ESaveGameState CSaveGame::LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, int(*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam) C4JStorage::ESaveGameState CSaveGame::LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo,
int (*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam)
{ {
Func(lpParam, pSaveInfo->thumbnailData, pSaveInfo->metaData.thumbnailSize); Func(lpParam, pSaveInfo->thumbnailData, pSaveInfo->metaData.thumbnailSize);
return C4JStorage::ESaveGame_GetSaveThumbnail; return C4JStorage::ESaveGame_GetSaveThumbnail;
@@ -273,18 +274,11 @@ void CSaveGame::SetSaveUniqueFilename(char* szFilename)
strcpy_s(m_szSaveUniqueName, szFilename); strcpy_s(m_szSaveUniqueName, szFilename);
} }
void CSaveGame::CreateSaveUniqueName(void) void CSaveGame::CreateSaveUniqueName(void)
{ {
_SYSTEMTIME UTCSysTime; _SYSTEMTIME UTCSysTime;
GetSystemTime(&UTCSysTime); GetSystemTime(&UTCSysTime);
sprintf_s(m_szSaveUniqueName, sizeof(m_szSaveUniqueName), sprintf_s(m_szSaveUniqueName, sizeof(m_szSaveUniqueName), "%4d%02d%02d%02d%02d%02d", UTCSysTime.wYear, UTCSysTime.wMonth, UTCSysTime.wDay,
"%4d%02d%02d%02d%02d%02d", UTCSysTime.wHour, UTCSysTime.wMinute, UTCSysTime.wSecond);
UTCSysTime.wYear,
UTCSysTime.wMonth,
UTCSysTime.wDay,
UTCSysTime.wHour,
UTCSysTime.wMinute,
UTCSysTime.wSecond);
} }
+4 -3
View File
@@ -4,16 +4,17 @@
class CSaveGame class CSaveGame
{ {
public: public:
CSaveGame(); CSaveGame();
void SetSaveDisabled(bool bDisable); void SetSaveDisabled(bool bDisable);
bool GetSaveDisabled(void); bool GetSaveDisabled(void);
void ResetSaveData(); void ResetSaveData();
C4JStorage::ESaveGameState GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS* pSaveDetails, const bool), LPVOID lpParam, char* pszSavePackName); C4JStorage::ESaveGameState GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS *pSaveDetails, const bool), LPVOID lpParam,
char *pszSavePackName);
PSAVE_DETAILS ReturnSavesInfo(); PSAVE_DETAILS ReturnSavesInfo();
void ClearSavesInfo(); void ClearSavesInfo();
C4JStorage::ESaveGameState LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, int(*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam); C4JStorage::ESaveGameState LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes),
LPVOID lpParam);
C4JStorage::ESaveGameState LoadSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool, const bool), LPVOID lpParam); C4JStorage::ESaveGameState LoadSaveData(PSAVE_INFO pSaveInfo, int (*Func)(LPVOID lpParam, const bool, const bool), LPVOID lpParam);
unsigned int GetSaveSize(); unsigned int GetSaveSize();
void GetSaveData(void *pvData, unsigned int *puiBytes); void GetSaveData(void *pvData, unsigned int *puiBytes);