Skip to content

Commit

Permalink
Don't touch my private members
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Aug 17, 2024
1 parent 92e690c commit 32aa34b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/cdc/render/PCDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ HWND cdc::PCDeviceManager::GetWindow()
return m_hFocusWindow;
}

cdc::PCDeviceManager* cdc::PCDeviceManager::GetInstance()
{
return s_pInstance;
}

void cdc::PCDeviceManager::AddDeviceResource(PCInternalResource* resource)
{
#ifndef TR8
Expand Down
8 changes: 7 additions & 1 deletion src/cdc/render/PCDeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "PCInternalResource.h"

class Hook;

namespace cdc
{
class PCDeviceManager
Expand All @@ -28,6 +30,8 @@ namespace cdc

bool m_bIsRecreatingResources;

static PCDeviceManager* s_pInstance;

public:
bool IsStatusOk();
bool IsCreatingResources();
Expand All @@ -37,6 +41,8 @@ namespace cdc

void AddDeviceResource(PCInternalResource* resource);

static PCDeviceManager* s_pInstance;
static PCDeviceManager* GetInstance();

friend class Hook;
};
}
4 changes: 2 additions & 2 deletions src/cdc/render/PCInternalResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

cdc::PCInternalResource::PCInternalResource() : m_pPrev(nullptr), m_pNext(nullptr)
{
PCDeviceManager::s_pInstance->AddDeviceResource(this);
PCDeviceManager::GetInstance()->AddDeviceResource(this);
}

cdc::PCInternalResource::~PCInternalResource()
Expand All @@ -27,7 +27,7 @@ void cdc::PCInternalResource::OnSettingsChanged()

void cdc::PCInternalResource::OnConstruct()
{
auto deviceManager = cdc::PCDeviceManager::s_pInstance;
auto deviceManager = PCDeviceManager::GetInstance();

if (deviceManager->IsStatusOk() && !deviceManager->IsCreatingResources())
{
Expand Down
2 changes: 1 addition & 1 deletion src/input/MessageHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
void MessageHook::OnMessage(std::function<void(HWND, UINT, WPARAM, LPARAM)> callback) noexcept
{
// Get the window handle
auto hWnd = cdc::PCDeviceManager::s_pInstance->GetWindow();
auto hWnd = cdc::PCDeviceManager::GetInstance()->GetWindow();

// Set the new message handler to our handler
s_original = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)WndProc);
Expand Down
4 changes: 2 additions & 2 deletions src/menu/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Menu::Menu() : PCInternalResource()
ImGui::CreateContext();

// We can do this since we always create the menu after D3D_Init
ImGui_ImplWin32_Init(cdc::PCDeviceManager::s_pInstance->GetWindow());
ImGui_ImplWin32_Init(cdc::PCDeviceManager::GetInstance()->GetWindow());

// Add present callback to draw the UI
RenderContext::OnPresent(std::bind(&Menu::OnPresent, this));
Expand All @@ -32,7 +32,7 @@ Menu::Menu() : PCInternalResource()
bool Menu::OnCreateDevice()
{
// Initialize the DirectX9 backend for ImGui
ImGui_ImplDX9_Init(cdc::PCDeviceManager::s_pInstance->GetD3DDevice());
ImGui_ImplDX9_Init(cdc::PCDeviceManager::GetInstance()->GetD3DDevice());

m_initialized = true;

Expand Down
2 changes: 1 addition & 1 deletion src/render/Draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void DRAW_DrawLines(LINEVERTEX* verts, int numlines)
#else
// The DRAW_DrawLines method has been optimized away in Anniversary
// the code below is a reimplementation of the code from Legend
if (cdc::PCDeviceManager::s_pInstance->IsStatusOk())
if (cdc::PCDeviceManager::GetInstance()->IsStatusOk())
{
auto linePool = *(cdc::PCPrimitivePool**)0x7545E0;
auto vertices = (LINEVERTEX*)linePool->AllocateVertices(numlines * 2);
Expand Down

0 comments on commit 32aa34b

Please sign in to comment.