|
11 | 11 |
|
12 | 12 | #include "StdInc.h" |
13 | 13 | #include <game/CSettings.h> |
| 14 | +#include <memory> |
14 | 15 | #include "DXHook/CProxyDirect3DDevice9.h" |
15 | 16 | #include "CTileBatcher.h" |
16 | 17 | #include "CLine3DBatcher.h" |
@@ -52,37 +53,83 @@ CGraphics::CGraphics(CLocalGUI* pGUI) |
52 | 53 | m_ActiveBlendMode = EBlendMode::BLEND; |
53 | 54 | m_CurDrawMode = EDrawMode::NONE; |
54 | 55 | m_CurBlendMode = EBlendMode::BLEND; |
55 | | - |
56 | | - m_pRenderItemManager = new CRenderItemManager(); |
57 | | - m_pTileBatcher = new CTileBatcher(); |
58 | | - m_pLine3DBatcherPreGUI = new CLine3DBatcher(true); |
59 | | - m_pLine3DBatcherPostFX = new CLine3DBatcher(true); |
60 | | - m_pLine3DBatcherPostGUI = new CLine3DBatcher(false); |
61 | | - m_pMaterialLine3DBatcherPreGUI = new CMaterialLine3DBatcher(true); |
62 | | - m_pMaterialLine3DBatcherPostFX = new CMaterialLine3DBatcher(true); |
63 | | - m_pMaterialLine3DBatcherPostGUI = new CMaterialLine3DBatcher(false); |
64 | | - m_pPrimitive3DBatcherPreGUI = new CPrimitive3DBatcher(true); |
65 | | - m_pPrimitive3DBatcherPostFX = new CPrimitive3DBatcher(true); |
66 | | - m_pPrimitive3DBatcherPostGUI = new CPrimitive3DBatcher(false); |
67 | | - m_pMaterialPrimitive3DBatcherPreGUI = new CMaterialPrimitive3DBatcher(true, this); |
68 | | - m_pMaterialPrimitive3DBatcherPostFX = new CMaterialPrimitive3DBatcher(true, this); |
69 | | - m_pMaterialPrimitive3DBatcherPostGUI = new CMaterialPrimitive3DBatcher(false, this); |
70 | | - m_pPrimitiveBatcher = new CPrimitiveBatcher(); |
71 | | - m_pPrimitiveMaterialBatcher = new CPrimitiveMaterialBatcher(this); |
72 | | - |
73 | | - m_pScreenGrabber = NewScreenGrabber(); |
74 | | - m_pPixelsManager = NewPixelsManager(); |
75 | | - m_LastLostDeviceTimer.SetMaxIncrement(250); |
76 | | - m_pAspectRatioConverter = new CAspectRatioConverter(); |
| 56 | + std::unique_ptr<CRenderItemManager> renderItemManager(new CRenderItemManager()); |
| 57 | + std::unique_ptr<CTileBatcher> tileBatcher(new CTileBatcher()); |
| 58 | + std::unique_ptr<CLine3DBatcher> line3DPreGUI(new CLine3DBatcher(true)); |
| 59 | + std::unique_ptr<CLine3DBatcher> line3DPostFX(new CLine3DBatcher(true)); |
| 60 | + std::unique_ptr<CLine3DBatcher> line3DPostGUI(new CLine3DBatcher(false)); |
| 61 | + std::unique_ptr<CMaterialLine3DBatcher> materialLinePreGUI(new CMaterialLine3DBatcher(true)); |
| 62 | + std::unique_ptr<CMaterialLine3DBatcher> materialLinePostFX(new CMaterialLine3DBatcher(true)); |
| 63 | + std::unique_ptr<CMaterialLine3DBatcher> materialLinePostGUI(new CMaterialLine3DBatcher(false)); |
| 64 | + std::unique_ptr<CPrimitive3DBatcher> primitive3DPreGUI(new CPrimitive3DBatcher(true)); |
| 65 | + std::unique_ptr<CPrimitive3DBatcher> primitive3DPostFX(new CPrimitive3DBatcher(true)); |
| 66 | + std::unique_ptr<CPrimitive3DBatcher> primitive3DPostGUI(new CPrimitive3DBatcher(false)); |
| 67 | + std::unique_ptr<CMaterialPrimitive3DBatcher> materialPrimitivePreGUI(new CMaterialPrimitive3DBatcher(true, this)); |
| 68 | + std::unique_ptr<CMaterialPrimitive3DBatcher> materialPrimitivePostFX(new CMaterialPrimitive3DBatcher(true, this)); |
| 69 | + std::unique_ptr<CMaterialPrimitive3DBatcher> materialPrimitivePostGUI(new CMaterialPrimitive3DBatcher(false, this)); |
| 70 | + std::unique_ptr<CPrimitiveBatcher> primitiveBatcher(new CPrimitiveBatcher()); |
| 71 | + std::unique_ptr<CPrimitiveMaterialBatcher> primitiveMaterialBatcher(new CPrimitiveMaterialBatcher(this)); |
| 72 | + std::unique_ptr<CScreenGrabberInterface> screenGrabber(NewScreenGrabber()); |
| 73 | + std::unique_ptr<CPixelsManagerInterface> pixelsManager(NewPixelsManager()); |
| 74 | + std::unique_ptr<CAspectRatioConverter> aspectRatioConverter(new CAspectRatioConverter()); |
| 75 | + |
| 76 | + m_pRenderItemManager = renderItemManager.release(); |
| 77 | + m_pTileBatcher = tileBatcher.release(); |
| 78 | + m_pLine3DBatcherPreGUI = line3DPreGUI.release(); |
| 79 | + m_pLine3DBatcherPostFX = line3DPostFX.release(); |
| 80 | + m_pLine3DBatcherPostGUI = line3DPostGUI.release(); |
| 81 | + m_pMaterialLine3DBatcherPreGUI = materialLinePreGUI.release(); |
| 82 | + m_pMaterialLine3DBatcherPostFX = materialLinePostFX.release(); |
| 83 | + m_pMaterialLine3DBatcherPostGUI = materialLinePostGUI.release(); |
| 84 | + m_pPrimitive3DBatcherPreGUI = primitive3DPreGUI.release(); |
| 85 | + m_pPrimitive3DBatcherPostFX = primitive3DPostFX.release(); |
| 86 | + m_pPrimitive3DBatcherPostGUI = primitive3DPostGUI.release(); |
| 87 | + m_pMaterialPrimitive3DBatcherPreGUI = materialPrimitivePreGUI.release(); |
| 88 | + m_pMaterialPrimitive3DBatcherPostFX = materialPrimitivePostFX.release(); |
| 89 | + m_pMaterialPrimitive3DBatcherPostGUI = materialPrimitivePostGUI.release(); |
| 90 | + m_pPrimitiveBatcher = primitiveBatcher.release(); |
| 91 | + m_pPrimitiveMaterialBatcher = primitiveMaterialBatcher.release(); |
| 92 | + m_pScreenGrabber = screenGrabber.release(); |
| 93 | + m_pPixelsManager = pixelsManager.release(); |
| 94 | + m_pAspectRatioConverter = aspectRatioConverter.release(); |
77 | 95 | } |
78 | 96 |
|
79 | 97 | CGraphics::~CGraphics() |
80 | 98 | { |
81 | 99 | if (m_pLineInterface) |
| 100 | + { |
82 | 101 | m_pLineInterface->Release(); |
| 102 | + m_pLineInterface = nullptr; |
| 103 | + } |
| 104 | + |
| 105 | + // Ensure queued draw items release their allocations before we tear down batchers |
| 106 | + ClearDrawQueue(m_PreGUIQueue); |
| 107 | + ClearDrawQueue(m_PostGUIQueue); |
| 108 | + |
| 109 | + if (m_pPrimitiveBatcher) |
| 110 | + m_pPrimitiveBatcher->ClearQueue(); |
| 111 | + if (m_pPrimitiveMaterialBatcher) |
| 112 | + m_pPrimitiveMaterialBatcher->ClearQueue(); |
| 113 | + if (m_pPrimitive3DBatcherPreGUI) |
| 114 | + m_pPrimitive3DBatcherPreGUI->ClearQueue(); |
| 115 | + if (m_pPrimitive3DBatcherPostFX) |
| 116 | + m_pPrimitive3DBatcherPostFX->ClearQueue(); |
| 117 | + if (m_pPrimitive3DBatcherPostGUI) |
| 118 | + m_pPrimitive3DBatcherPostGUI->ClearQueue(); |
| 119 | + if (m_pMaterialPrimitive3DBatcherPreGUI) |
| 120 | + m_pMaterialPrimitive3DBatcherPreGUI->ClearQueue(); |
| 121 | + if (m_pMaterialPrimitive3DBatcherPostFX) |
| 122 | + m_pMaterialPrimitive3DBatcherPostFX->ClearQueue(); |
| 123 | + if (m_pMaterialPrimitive3DBatcherPostGUI) |
| 124 | + m_pMaterialPrimitive3DBatcherPostGUI->ClearQueue(); |
83 | 125 |
|
84 | 126 | DestroyStandardDXFonts(); |
85 | 127 |
|
| 128 | + SAFE_RELEASE(m_pDXSprite); |
| 129 | + SAFE_RELEASE(m_pSavedStateBlock); |
| 130 | + SAFE_RELEASE(m_pSavedFrontBufferData); |
| 131 | + SAFE_RELEASE(m_pTempBackBufferData); |
| 132 | + |
86 | 133 | SAFE_RELEASE(m_ProgressSpinnerTexture); |
87 | 134 | SAFE_RELEASE(m_RectangleEdgeTexture); |
88 | 135 | SAFE_DELETE(m_pRenderItemManager); |
@@ -1435,21 +1482,32 @@ bool CGraphics::CreateStandardDXFontWithCustomScale(eFontType fontType, float fS |
1435 | 1482 | bool CGraphics::LoadAdditionalDXFont(std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, DWORD ulQuality, |
1436 | 1483 | ID3DXFont** ppD3DXFont) |
1437 | 1484 | { |
1438 | | - int iLoaded = AddFontResourceEx(strFontPath.c_str(), FR_PRIVATE, 0); |
| 1485 | + int iLoaded = AddFontResourceEx(strFontPath.c_str(), FR_PRIVATE, 0); |
| 1486 | + bool bFontResourceAdded = (iLoaded > 0); |
1439 | 1487 |
|
1440 | 1488 | int iWeight = bBold ? FW_BOLD : FW_NORMAL; |
1441 | 1489 | *ppD3DXFont = NULL; |
1442 | 1490 |
|
1443 | 1491 | bool bSuccess = true; |
1444 | | - // Normal size |
1445 | 1492 | if (!SUCCEEDED(D3DXCreateFont(m_pDevice, uiHeight, 0, iWeight, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ulQuality, DEFAULT_PITCH | FF_DONTCARE, |
1446 | 1493 | strFontName.c_str(), ppD3DXFont))) |
1447 | 1494 | { |
1448 | 1495 | WriteErrorEvent(SString("Could not create Direct3D font '%s'", strFontName.c_str())); |
1449 | 1496 | bSuccess = false; |
1450 | 1497 | } |
1451 | 1498 |
|
1452 | | - return bSuccess && (iLoaded == 1); |
| 1499 | + if (!bSuccess && bFontResourceAdded) |
| 1500 | + { |
| 1501 | + RemoveFontResourceEx(strFontPath.c_str(), FR_PRIVATE, 0); |
| 1502 | + } |
| 1503 | + |
| 1504 | + if (!bFontResourceAdded) |
| 1505 | + { |
| 1506 | + SAFE_RELEASE(*ppD3DXFont); |
| 1507 | + return false; |
| 1508 | + } |
| 1509 | + |
| 1510 | + return bSuccess; |
1453 | 1511 | } |
1454 | 1512 |
|
1455 | 1513 | bool CGraphics::LoadAdditionalDXFont(std::string strFontPath, std::string strFontName, unsigned int uiHeight, bool bBold, ID3DXFont** ppD3DXFont) |
|
0 commit comments