mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 00:27:42 +00:00
macOS decal rendering support
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "CStateManager.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "Graphics/Shaders/CDecalShaders.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
@@ -15,24 +16,46 @@ CAssetId CDecalManager::m_LastDecalCreatedAssetId = -1;
|
||||
rstl::reserved_vector<CDecalManager::SDecal, 64> CDecalManager::m_DecalPool;
|
||||
rstl::reserved_vector<s32, 64> CDecalManager::m_ActiveIndexList;
|
||||
|
||||
URDE_DECL_SPECIALIZE_SHADER(CDecalShaders)
|
||||
|
||||
void CDecalManager::Initialize()
|
||||
{
|
||||
if (m_PoolInitialized)
|
||||
return;
|
||||
|
||||
m_DecalPool.clear();
|
||||
m_DecalPool.resize(64);
|
||||
for (int i=0 ; i<64 ; ++i)
|
||||
m_DecalPool.emplace_back(std::experimental::optional<CDecal>{}, 0, i-1, false);
|
||||
|
||||
m_FreeIndex = 63;
|
||||
m_PoolInitialized = true;
|
||||
m_DeltaTimeSinceLastDecalCreation = 0.f;
|
||||
m_LastDecalCreatedIndex = -1;
|
||||
m_LastDecalCreatedAssetId = -1;
|
||||
|
||||
/* Compile shaders */
|
||||
TShader<CDecalShaders>::Initialize();
|
||||
}
|
||||
|
||||
void CDecalManager::Reinitialize()
|
||||
{
|
||||
if (!m_PoolInitialized)
|
||||
Initialize();
|
||||
|
||||
m_DecalPool.clear();
|
||||
for (int i=0 ; i<64 ; ++i)
|
||||
m_DecalPool.emplace_back(std::experimental::optional<CDecal>{}, 0, i-1, false);
|
||||
|
||||
m_ActiveIndexList.clear();
|
||||
|
||||
m_FreeIndex = 63;
|
||||
}
|
||||
|
||||
void CDecalManager::Shutdown()
|
||||
{
|
||||
|
||||
m_ActiveIndexList.clear();
|
||||
m_DecalPool.clear();
|
||||
TShader<CDecalShaders>::Shutdown();
|
||||
}
|
||||
|
||||
void CDecalManager::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr)
|
||||
@@ -40,7 +63,7 @@ void CDecalManager::AddToRenderer(const zeus::CFrustum& frustum, const CStateMan
|
||||
for (s32 idx : m_ActiveIndexList)
|
||||
{
|
||||
CDecalManager::SDecal& decal = m_DecalPool[idx];
|
||||
if (decal.x75_flags & 0x2 || mgr.GetThermalDrawFlag() != EThermalDrawFlag::Hot)
|
||||
if (decal.x75_24_notIce || mgr.GetThermalDrawFlag() != EThermalDrawFlag::Hot)
|
||||
{
|
||||
const zeus::CVector3f& point = decal.x0_decal->xc_transform.origin;
|
||||
zeus::CAABox aabb(point, point);
|
||||
@@ -50,15 +73,61 @@ void CDecalManager::AddToRenderer(const zeus::CFrustum& frustum, const CStateMan
|
||||
}
|
||||
}
|
||||
|
||||
rstl::reserved_vector<s32, 64>::iterator
|
||||
CDecalManager::RemoveFromActiveList(rstl::reserved_vector<s32, 64>::iterator it, s32 idx)
|
||||
{
|
||||
it = m_ActiveIndexList.erase(it);
|
||||
m_DecalPool[idx].x74_index = u8(m_FreeIndex);
|
||||
m_FreeIndex = idx;
|
||||
if (m_LastDecalCreatedIndex == m_FreeIndex)
|
||||
m_LastDecalCreatedIndex = -1;
|
||||
return it;
|
||||
}
|
||||
|
||||
void CDecalManager::Update(float dt, CStateManager& mgr)
|
||||
{
|
||||
|
||||
m_DeltaTimeSinceLastDecalCreation += dt;
|
||||
for (auto it = m_ActiveIndexList.begin() ; it != m_ActiveIndexList.end() ;)
|
||||
{
|
||||
SDecal& decal = m_DecalPool[*it];
|
||||
if (decal.x70_areaId != mgr.GetNextAreaId() ||
|
||||
(decal.x0_decal->x5c_29_modelInvalid &&
|
||||
decal.x0_decal->x5c_30_quad2Invalid &&
|
||||
decal.x0_decal->x5c_31_quad1Invalid))
|
||||
{
|
||||
it = RemoveFromActiveList(it, *it);
|
||||
continue;
|
||||
}
|
||||
decal.x0_decal->Update(dt);
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void CDecalManager::AddDecal(const TToken<CDecalDescription>& decal, const zeus::CTransform& xf,
|
||||
bool b1, CStateManager& mgr)
|
||||
bool notIce, CStateManager& mgr)
|
||||
{
|
||||
if (m_LastDecalCreatedIndex != -1 && m_DeltaTimeSinceLastDecalCreation < 0.75f &&
|
||||
m_LastDecalCreatedAssetId == decal.GetObjectTag()->id)
|
||||
{
|
||||
SDecal& existingDecal = m_DecalPool[m_LastDecalCreatedIndex];
|
||||
if ((existingDecal.x0_decal->xc_transform.origin - xf.origin).magSquared() < 0.01f)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_FreeIndex == -1)
|
||||
RemoveFromActiveList(m_ActiveIndexList.begin(), m_ActiveIndexList[0]);
|
||||
|
||||
s32 thisIndex = m_FreeIndex;
|
||||
SDecal& freeDecal = m_DecalPool[thisIndex];
|
||||
m_FreeIndex = freeDecal.x74_index;
|
||||
freeDecal.x0_decal.emplace(decal, xf);
|
||||
|
||||
freeDecal.x70_areaId = mgr.GetNextAreaId();
|
||||
freeDecal.x75_24_notIce = notIce;
|
||||
m_DeltaTimeSinceLastDecalCreation = 0.f;
|
||||
m_LastDecalCreatedIndex = thisIndex;
|
||||
m_LastDecalCreatedAssetId = decal.GetObjectTag()->id;
|
||||
m_ActiveIndexList.push_back(thisIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user