manger->update()
{
int64_t beginTime = ::Effekseer::GetTime(); //開始時間
for (size_t i = 0; i < m_RemovingDrawSets.size(); i++)
{
for (auto& ds : m_RemovingDrawSets[i])
{
ds.second.UpdateCountAfterRemoving++;
}
}
//遍歷效果執(zhí)行預更新,每個效果執(zhí)行一次
//遍歷效果馅闽,若效果已停止則下一次唉擂,若效果沒有粒子實例或者只有root節(jié)點存在,則停止該效果
//遍歷效果如果GoingToStop為true场靴,則殺掉所有粒子實例包括其子實例如果GoingToStopRoot為true,則殺掉所有粒子實例但不包括其子實例
//若效果IsRemoving為true港准,做內(nèi)存回收
//清空 正在渲染的效果 集合旨剥;重新裝填該集合
//更新渲染幀數(shù)
BeginUpdate();
for (auto& drawSet : m_DrawSets)
{
//若效果暫停則為0,否則是效果播放速度(幀增量)浅缸。并指定給效果
float df = drawSet.second.IsPaused ? 0 : deltaFrame * drawSet.second.Speed;
drawSet.second.GlobalPointer->BeginDeltaFrame(df);
}
//遍歷size=20的實例塊集合的集合
for (auto& chunks : instanceChunks_)
{
//size=8000/16的實例塊集合
for (auto chunk : chunks)
{
//更新size=16的實例塊轨帜;若實例狀態(tài)為true則執(zhí)行以下邏輯
//若實例m_State=INSTANCE_STATE_ACTIVE,則根據(jù)幀增量更新實例
//若實例m_State=INSTANCE_STATE_REMOVING衩椒,m_State置為INSTANCE_STATE_REMOVED
//若實例m_State=INSTANCE_STATE_REMOVED蚌父,調(diào)用析構回收實例內(nèi)存哮兰。置實例狀態(tài)false,存活粒子減一
chunk->UpdateInstances();
}
}
//遍歷效果苟弛;遍歷每個效果的所有動態(tài)參數(shù)喝滞;
//若效果為show的粒子實例及其子實例不為active則在實例group鏈表中回收該實例。
//m_updatedFrame當前幀加上增量膏秫,增量置0
for (auto& drawSet : m_DrawSets)
{
UpdateHandleInternal(drawSet.second);
}
//遍歷所有的實例塊集合(5000)右遭;
//對于每個實例塊中粒子存活數(shù)為0的實例塊,將其加入到pooledChunks_缤削;清除掉最后一個實例塊
//將所有的可創(chuàng)建實例塊offset置0狸演。offset最大值為5000/16,表示當前應當在 實例塊集合[offset]的實例塊中創(chuàng)建實例
EndUpdate();
//本次update時間
m_updateTime = (int)(Effekseer::GetTime() - beginTime);
}
instance->Update(deltaTime, true)
InstanceGlobal 表示rootIntance
void Instance::Update( float deltaFrame, bool shown )
{
assert(this->m_pContainer != nullptr);
// 標志位,自己和父實例是否已經(jīng)更新
m_GlobalMatrix43Calculated = false;
m_ParentMatrix43Calculated = false;
if (is_time_step_allowed && m_pEffectNode->GetType() != EFFECT_NODE_TYPE_ROOT)
{
/* 音の更新(現(xiàn)狀放置) */
if (m_pEffectNode->SoundType == ParameterSoundType_Use)
{
float living_time = m_LivingTime;
float living_time_p = living_time + deltaFrame;
if (living_time <= (float) soundValues.delay && (float) soundValues.delay < living_time_p)
{
m_pEffectNode->PlaySound_(*this, m_pContainer->GetRootInstance(), m_pManager);
}
}
}
float originalTime = m_LivingTime;
// step time
// frame 0 - generated time
// frame 1- now
if (is_time_step_allowed)
{
m_LivingTime += deltaFrame;
}
if(shown)
{
//若已計算僻他,返回。通過manager更新intance的序列幀數(shù)腊尚;若父實例不為空(指的是父節(jié)點的第一個group里的intance)計算父節(jié)點帶來的影響(父節(jié)點調(diào)用CalculateMatrix吨拗;若節(jié)點不是root,則提取該節(jié)點的繼承參數(shù)(position婿斥,rotation劝篷,scale));
CalculateMatrix( deltaFrame );
}
else if (m_pEffectNode->LocationAbs.type != LocationAbsType::None
|| m_pEffectNode->LocalForceFields[0].Turbulence != nullptr
|| m_pEffectNode->LocalForceFields[1].Turbulence != nullptr
|| m_pEffectNode->LocalForceFields[2].Turbulence != nullptr)
{
// If attraction forces are not default, updating is needed in each frame.
CalculateMatrix( deltaFrame );
}
// Get parent color.
if (m_pParent != NULL)
{
if (m_pEffectNode->RendererCommon.ColorBindType == BindType::Always)
{
ColorParent = m_pParent->ColorInheritance;
}
}
/* 親の削除処理 */
if (m_pParent != NULL && m_pParent->GetState() != INSTANCE_STATE_ACTIVE)
{
CalculateParentMatrix( deltaFrame );
m_pParent = nullptr;
}
// Create child particles
if( is_time_step_allowed && (originalTime <= m_LivedTime || !m_pEffectNode->CommonValues.RemoveWhenLifeIsExtinct) )
{
GenerateChildrenInRequired(originalTime + deltaFrame);
}
UpdateChildrenGroupMatrix();
// check whether killed?
bool killed = false;
if( m_pEffectNode->GetType() != EFFECT_NODE_TYPE_ROOT )
{
// if pass time
if( m_pEffectNode->CommonValues.RemoveWhenLifeIsExtinct )
{
if( m_LivingTime > m_LivedTime )
{
killed = true;
}
}
// if remove parent
if( m_pEffectNode->CommonValues.RemoveWhenParentIsRemoved )
{
if( m_pParent == nullptr || m_pParent->GetState() != INSTANCE_STATE_ACTIVE )
{
m_pParent = nullptr;
killed = true;
}
}
// if children are removed and going not to generate a child
if( !killed && m_pEffectNode->CommonValues.RemoveWhenChildrenIsExtinct )
{
int maxcreate_count = 0;
InstanceGroup* group = childrenGroups_;
for (int i = 0; i < m_pEffectNode->GetChildrenCount(); i++, group = group->NextUsedByInstance)
{
auto child = (EffectNodeImplemented*) m_pEffectNode->GetChild(i);
if (maxGenerationChildrenCount[i] <= m_generatedChildrenCount[i] && group->GetInstanceCount() == 0)
{
maxcreate_count++;
}
else
{
break;
}
}
if( maxcreate_count == m_pEffectNode->GetChildrenCount() )
{
killed = true;
}
}
}
if(killed)
{
// if it need to calculate a matrix
if( m_pEffectNode->GetChildrenCount() > 0)
{
// Get parent color.
if (m_pParent != nullptr)
{
if (m_pEffectNode->RendererCommon.ColorBindType == BindType::Always)
{
ColorParent = m_pParent->ColorInheritance;
}
}
}
// Delete this particle with myself.
Kill();
return;
}
// allow to pass time
is_time_step_allowed = true;
}