From 1ef20fc08a23c7bac1f3e5fcd2328c18c0f9fdf4 Mon Sep 17 00:00:00 2001 From: TEDERIs Date: Sat, 9 Dec 2023 17:37:37 +0700 Subject: [PATCH] Better model enqueueing --- .../mods/deathmatch/logic/CModelRenderer.cpp | 11 +++---- Client/mods/deathmatch/logic/CModelRenderer.h | 30 +++++++++++-------- .../logic/luadefs/CLuaDrawingDefs.cpp | 8 ++--- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Client/mods/deathmatch/logic/CModelRenderer.cpp b/Client/mods/deathmatch/logic/CModelRenderer.cpp index b54580c9ad..7da378b287 100644 --- a/Client/mods/deathmatch/logic/CModelRenderer.cpp +++ b/Client/mods/deathmatch/logic/CModelRenderer.cpp @@ -12,16 +12,13 @@ #include "StdInc.h" #include "game\CRenderer.h" -SModelToRender& CModelRenderer::EnqueueModel(CModelInfo* pModelInfo) +bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, EModelLoadingScheme scheme) { - static SModelToRender DEFAULT_MODEL_TO_RENDER{}; - if (!pModelInfo || g_pCore->IsWindowMinimized()) - return DEFAULT_MODEL_TO_RENDER; + return false; - SModelToRender& entry = m_Queue.emplace_back(); - entry.pModelInfo = pModelInfo; - return entry; + m_Queue.emplace_back(pModelInfo, matrix, scheme); + return true; } void CModelRenderer::Update() diff --git a/Client/mods/deathmatch/logic/CModelRenderer.h b/Client/mods/deathmatch/logic/CModelRenderer.h index 546633d8b4..de3558ef87 100644 --- a/Client/mods/deathmatch/logic/CModelRenderer.h +++ b/Client/mods/deathmatch/logic/CModelRenderer.h @@ -18,27 +18,31 @@ enum class EModelLoadingScheme : uint8_t Blocking }; -struct SModelToRender final -{ - EModelLoadingScheme scheme{EModelLoadingScheme::Loaded}; - CMatrix matrix; - - // Invariants -private: - friend class CModelRenderer; - CModelInfo* pModelInfo{}; - bool bLoaded{}; -}; - class CModelRenderer final { public: - SModelToRender& EnqueueModel(CModelInfo* pModelInfo); + bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, EModelLoadingScheme scheme); void Update(); void Render(); private: + struct SModelToRender final + { + CModelInfo* pModelInfo; + CMatrix matrix; + EModelLoadingScheme scheme; + bool bLoaded; + + SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, EModelLoadingScheme scheme) : + pModelInfo(pModelInfo), + matrix(matrix), + scheme(scheme), + bLoaded(false) + { + } + }; + std::vector m_Queue; }; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp index f76a53e117..501d8fc78b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp @@ -2137,9 +2137,7 @@ bool CLuaDrawingDefs::DxDrawModel3D(uint32_t modelID, CVector position, CVector ConvertDegreesToRadians(rotation); - SModelToRender& modelDesc = g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo); - modelDesc.matrix = {position, rotation, scale.value_or(CVector(1.0f, 1.0f, 1.0f))}; - modelDesc.scheme = loadingScheme.value_or(EModelLoadingScheme::Async); - - return true; + return g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo, + CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, + loadingScheme.value_or(EModelLoadingScheme::Async)); }