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++;
}
}
//遍历效果执行预更新,每个效果执行一次
//遍历效果,若效果已停止则下一次,若效果没有粒子实例或者只有root节点存在,则停止该效果
//遍历效果如果GoingToStop为true,则杀掉所有粒子实例包括其子实例如果GoingToStopRoot为true,则杀掉所有粒子实例但不包括其子实例
//若效果IsRemoving为true,做内存回收
//清空 正在渲染的效果 集合;重新装填该集合
//更新渲染帧数
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的实例块;若实例状态为true则执行以下逻辑
//若实例m_State=INSTANCE_STATE_ACTIVE,则根据帧增量更新实例
//若实例m_State=INSTANCE_STATE_REMOVING,m_State置为INSTANCE_STATE_REMOVED
//若实例m_State=INSTANCE_STATE_REMOVED,调用析构回收实例内存。置实例状态false,存活粒子减一
chunk->UpdateInstances();
}
}
//遍历效果;遍历每个效果的所有动态参数;
//若效果为show的粒子实例及其子实例不为active则在实例group链表中回收该实例。
//m_updatedFrame当前帧加上增量,增量置0
for (auto& drawSet : m_DrawSets)
{
UpdateHandleInternal(drawSet.second);
}
//遍历所有的实例块集合(5000);
//对于每个实例块中粒子存活数为0的实例块,将其加入到pooledChunks_;清除掉最后一个实例块
//将所有的可创建实例块offset置0。offset最大值为5000/16,表示当前应当在 实例块集合[offset]的实例块中创建实例
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);
// 标志位,自己和父实例是否已经更新
m_GlobalMatrix43Calculated = false;
m_ParentMatrix43Calculated = false;
if (is_time_step_allowed && m_pEffectNode->GetType() != EFFECT_NODE_TYPE_ROOT)
{
/* 音の更新(現状放置) */
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的序列帧数;若父实例不为空(指的是父节点的第一个group里的intance)计算父节点带来的影响(父节点调用CalculateMatrix;若节点不是root,则提取该节点的继承参数(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;
}
网友评论