2016-03-19 06:57:51 +13:00
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
// Iwa_ParticlesManager for Marnie
|
|
|
|
|
// based on ParticlesManager by Digital Video
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#include "trenderer.h"
|
|
|
|
|
|
|
|
|
|
#include <QMutexLocker>
|
|
|
|
|
|
|
|
|
|
#include "iwa_particlesmanager.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
EXPLANATION:
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
ParticlesManager improves the old particles system as follows - the particles
|
|
|
|
|
manager stores the
|
2016-03-19 06:57:51 +13:00
|
|
|
|
last particles configuration which had some particle rendered by a thread.
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Under normal cicumstances, this means that every thread has the particles
|
|
|
|
|
configuration that rendered
|
2016-03-19 06:57:51 +13:00
|
|
|
|
last. In case a trail was set, such frame is that beyond the trail.
|
2016-06-15 18:43:10 +12:00
|
|
|
|
This managemer works well on the assumption that each thread builds particle in
|
|
|
|
|
an incremental timeline.
|
2016-03-19 06:57:51 +13:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
DEFINE_CLASS_CODE(Iwa_ParticlesManager::FxData,
|
|
|
|
|
170) /*- 注:ParticlesManager::FxDataは110 -*/
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
typedef std::map<double, Iwa_ParticlesManager::FrameData> FramesMap;
|
|
|
|
|
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
// Preliminaries
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
|
class Iwa_ParticlesManagerGenerator final
|
|
|
|
|
: public TRenderResourceManagerGenerator {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManagerGenerator() : TRenderResourceManagerGenerator(true) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-20 14:23:05 +12:00
|
|
|
|
TRenderResourceManager *operator()(void) override {
|
|
|
|
|
return new Iwa_ParticlesManager;
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
};
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
MANAGER_FILESCOPE_DECLARATION(Iwa_ParticlesManager,
|
|
|
|
|
Iwa_ParticlesManagerGenerator);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
// FrameData implementation
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
|
|
|
|
|
Iwa_ParticlesManager::FrameData::FrameData(FxData *fxData)
|
2016-06-15 18:43:10 +12:00
|
|
|
|
: m_fxData(fxData)
|
|
|
|
|
, m_frame((std::numeric_limits<int>::min)())
|
|
|
|
|
, m_calculated(false)
|
|
|
|
|
, m_maxTrail(-1)
|
|
|
|
|
, m_totalParticles(0) {
|
|
|
|
|
m_fxData->addRef();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManager::FrameData::~FrameData() { m_fxData->release(); }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void Iwa_ParticlesManager::FrameData::buildMaxTrail() {
|
|
|
|
|
// Store the maximum trail of each particle
|
|
|
|
|
std::list<Iwa_Particle>::iterator it;
|
|
|
|
|
for (it = m_particles.begin(); it != m_particles.end(); ++it)
|
|
|
|
|
m_maxTrail = std::max(m_maxTrail, it->trail);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void Iwa_ParticlesManager::FrameData::clear() {
|
|
|
|
|
m_frame = (std::numeric_limits<int>::min)();
|
|
|
|
|
m_particles.clear();
|
|
|
|
|
m_random = TRandom();
|
|
|
|
|
m_calculated = false;
|
|
|
|
|
m_maxTrail = -1;
|
|
|
|
|
m_totalParticles = 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
// FxData implementation
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManager::FxData::FxData() : TSmartObject(m_classCode) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
// ParticlesContainer implementation
|
|
|
|
|
//************************************************************************************************
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManager *Iwa_ParticlesManager::instance() {
|
|
|
|
|
return static_cast<Iwa_ParticlesManager *>(
|
|
|
|
|
Iwa_ParticlesManager::gen()->getManager(TRenderer::renderId()));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManager::Iwa_ParticlesManager() : m_renderStatus(-1) {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManager::~Iwa_ParticlesManager() {
|
|
|
|
|
// Release all fxDatas
|
|
|
|
|
std::map<unsigned long, FxData *>::iterator it, end = m_fxs.end();
|
|
|
|
|
for (it = m_fxs.begin(); it != end; ++it) it->second->release();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
void Iwa_ParticlesManager::onRenderStatusStart(int renderStatus) {
|
|
|
|
|
m_renderStatus = renderStatus;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
Iwa_ParticlesManager::FrameData *Iwa_ParticlesManager::data(
|
|
|
|
|
unsigned long fxId) {
|
|
|
|
|
QMutexLocker locker(&m_mutex);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
std::map<unsigned long, FxData *>::iterator it = m_fxs.find(fxId);
|
|
|
|
|
if (it == m_fxs.end()) {
|
|
|
|
|
it = m_fxs.insert(std::make_pair(fxId, new FxData)).first;
|
|
|
|
|
it->second->addRef();
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
FxData *fxData = it->second;
|
|
|
|
|
FrameData *d = fxData->m_frames.localData();
|
|
|
|
|
if (!d) {
|
|
|
|
|
d = new FrameData(fxData);
|
|
|
|
|
fxData->m_frames.setLocalData(d);
|
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
return d;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
|
bool Iwa_ParticlesManager::isCached(unsigned long fxId) {
|
|
|
|
|
std::map<unsigned long, FxData *>::iterator it = m_fxs.find(fxId);
|
|
|
|
|
return (it != m_fxs.end());
|
2016-03-19 06:57:51 +13:00
|
|
|
|
}
|