Skip to content

Commit

Permalink
Better model enqueueing
Browse files Browse the repository at this point in the history
  • Loading branch information
tederis committed Jun 1, 2024
1 parent 247b37d commit 1ef20fc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
11 changes: 4 additions & 7 deletions Client/mods/deathmatch/logic/CModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 17 additions & 13 deletions Client/mods/deathmatch/logic/CModelRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SModelToRender> m_Queue;
};
8 changes: 3 additions & 5 deletions Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 1ef20fc

Please sign in to comment.