2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Particle/CDecalManager.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
|
|
|
#include "Runtime/Graphics/Shaders/CDecalShaders.hpp"
|
|
|
|
#include "Runtime/Particle/CDecal.hpp"
|
|
|
|
#include "Runtime/Particle/CDecalDescription.hpp"
|
2016-04-07 07:10:08 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CDecalManager::m_PoolInitialized = false;
|
|
|
|
s32 CDecalManager::m_FreeIndex = 63;
|
|
|
|
float CDecalManager::m_DeltaTimeSinceLastDecalCreation = 0.f;
|
|
|
|
s32 CDecalManager::m_LastDecalCreatedIndex = -1;
|
2022-02-19 13:04:45 +00:00
|
|
|
CAssetId CDecalManager::m_LastDecalCreatedAssetId = {};
|
2016-04-15 20:42:40 +00:00
|
|
|
rstl::reserved_vector<CDecalManager::SDecal, 64> CDecalManager::m_DecalPool;
|
|
|
|
rstl::reserved_vector<s32, 64> CDecalManager::m_ActiveIndexList;
|
2016-04-07 07:10:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CDecalManager::Initialize() {
|
|
|
|
if (m_PoolInitialized)
|
|
|
|
return;
|
2016-04-07 07:10:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_DecalPool.clear();
|
2020-04-13 05:43:00 +00:00
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
|
|
m_DecalPool.emplace_back(std::nullopt, 0, i - 1, false);
|
|
|
|
}
|
2016-04-07 07:10:08 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_FreeIndex = 63;
|
|
|
|
m_PoolInitialized = true;
|
|
|
|
m_DeltaTimeSinceLastDecalCreation = 0.f;
|
|
|
|
m_LastDecalCreatedIndex = -1;
|
2022-02-19 13:04:45 +00:00
|
|
|
m_LastDecalCreatedAssetId = {};
|
2018-03-17 03:41:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
/* Compile shaders */
|
|
|
|
CDecalShaders::Initialize();
|
2016-04-07 07:10:08 +00:00
|
|
|
}
|
2017-01-22 01:40:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CDecalManager::Reinitialize() {
|
|
|
|
if (!m_PoolInitialized)
|
|
|
|
Initialize();
|
2017-01-22 01:40:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_DecalPool.clear();
|
2020-04-13 05:43:00 +00:00
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
|
|
m_DecalPool.emplace_back(std::nullopt, 0, i - 1, false);
|
|
|
|
}
|
2018-03-17 03:41:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_ActiveIndexList.clear();
|
2018-03-17 03:41:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_FreeIndex = 63;
|
2018-03-17 03:41:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CDecalManager::Shutdown() {
|
|
|
|
m_ActiveIndexList.clear();
|
|
|
|
m_DecalPool.clear();
|
|
|
|
CDecalShaders::Shutdown();
|
2017-01-22 01:40:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CDecalManager::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) {
|
|
|
|
for (s32 idx : m_ActiveIndexList) {
|
|
|
|
CDecalManager::SDecal& decal = m_DecalPool[idx];
|
|
|
|
if (decal.x75_24_notIce || mgr.GetThermalDrawFlag() != EThermalDrawFlag::Hot) {
|
|
|
|
const zeus::CVector3f& point = decal.x0_decal->xc_transform.origin;
|
|
|
|
zeus::CAABox aabb(point, point);
|
|
|
|
g_Renderer->AddDrawable(&*decal.x0_decal, point, aabb, 2, IRenderer::EDrawableSorting::SortedCallback);
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-03-04 04:31:08 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 03:41:01 +00:00
|
|
|
rstl::reserved_vector<s32, 64>::iterator
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
2018-03-17 03:41:01 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
2018-03-17 03:41:01 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
decal.x0_decal->Update(dt);
|
|
|
|
++it;
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CDecalManager::AddDecal(const TToken<CDecalDescription>& decal, const zeus::CTransform& xf, bool notIce,
|
|
|
|
CStateManager& mgr) {
|
2021-04-03 16:48:39 +00:00
|
|
|
OPTICK_EVENT();
|
2018-12-08 05:30:43 +00:00
|
|
|
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);
|
2018-02-12 05:30:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|