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