Add support for updating particle effects in editor view when editing
This commit is contained in:
@@ -194,7 +194,7 @@ void LevelService::Update()
|
|||||||
for (int32 i = 0; i < scenes.Count(); i++)
|
for (int32 i = 0; i < scenes.Count(); i++)
|
||||||
{
|
{
|
||||||
if (scenes[i]->GetIsActive())
|
if (scenes[i]->GetIsActive())
|
||||||
scenes[i]->Ticking.Update.TickEditorScripts();
|
scenes[i]->Ticking.Update.TickExecuteInEditor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -223,7 +223,7 @@ void LevelService::LateUpdate()
|
|||||||
for (int32 i = 0; i < scenes.Count(); i++)
|
for (int32 i = 0; i < scenes.Count(); i++)
|
||||||
{
|
{
|
||||||
if (scenes[i]->GetIsActive())
|
if (scenes[i]->GetIsActive())
|
||||||
scenes[i]->Ticking.LateUpdate.TickEditorScripts();
|
scenes[i]->Ticking.LateUpdate.TickExecuteInEditor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -255,7 +255,7 @@ void LevelService::FixedUpdate()
|
|||||||
for (int32 i = 0; i < scenes.Count(); i++)
|
for (int32 i = 0; i < scenes.Count(); i++)
|
||||||
{
|
{
|
||||||
if (scenes[i]->GetIsActive())
|
if (scenes[i]->GetIsActive())
|
||||||
scenes[i]->Ticking.FixedUpdate.TickEditorScripts();
|
scenes[i]->Ticking.FixedUpdate.TickExecuteInEditor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,15 +17,9 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tick function type.
|
/// Tick function type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Tick
|
struct Tick
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Signature of the function to call
|
|
||||||
/// </summary>
|
|
||||||
typedef void (*Signature)();
|
typedef void (*Signature)();
|
||||||
|
|
||||||
typedef void (*SignatureObj)(void*);
|
typedef void (*SignatureObj)(void*);
|
||||||
|
|
||||||
template<class T, void(T::*Method)()>
|
template<class T, void(T::*Method)()>
|
||||||
@@ -51,8 +45,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calls the binded function.
|
/// Calls the binded function.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Function result</returns>
|
FORCE_INLINE void Call() const
|
||||||
void Call() const
|
|
||||||
{
|
{
|
||||||
(*FunctionObj)(Callee);
|
(*FunctionObj)(Callee);
|
||||||
}
|
}
|
||||||
@@ -63,10 +56,11 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
Array<Script*> Scripts;
|
Array<Script*> Scripts;
|
||||||
|
Array<Tick> Ticks;
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
Array<Script*> ScriptsExecuteInEditor;
|
Array<Script*> ScriptsExecuteInEditor;
|
||||||
|
Array<Tick> TicksExecuteInEditor;
|
||||||
#endif
|
#endif
|
||||||
Array<Tick> Ticks;
|
|
||||||
|
|
||||||
TickData(int32 capacity)
|
TickData(int32 capacity)
|
||||||
: Scripts(capacity)
|
: Scripts(capacity)
|
||||||
@@ -81,18 +75,17 @@ public:
|
|||||||
TickScripts(Scripts);
|
TickScripts(Scripts);
|
||||||
|
|
||||||
for (int32 i = 0; i < Ticks.Count(); i++)
|
for (int32 i = 0; i < Ticks.Count(); i++)
|
||||||
{
|
|
||||||
Ticks[i].Call();
|
Ticks[i].Call();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
void TickExecuteInEditor()
|
||||||
void TickEditorScripts()
|
|
||||||
{
|
{
|
||||||
TickScripts(ScriptsExecuteInEditor);
|
TickScripts(ScriptsExecuteInEditor);
|
||||||
}
|
|
||||||
|
|
||||||
|
for (int32 i = 0; i < TicksExecuteInEditor.Count(); i++)
|
||||||
|
TicksExecuteInEditor[i].Call();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void AddScript(Script* script);
|
void AddScript(Script* script);
|
||||||
@@ -118,12 +111,35 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
template<class T, void(T::*Method)()>
|
||||||
|
void AddTickExecuteInEditor(T* callee)
|
||||||
|
{
|
||||||
|
SceneTicking::Tick tick;
|
||||||
|
tick.Bind<T, Method>(callee);
|
||||||
|
TicksExecuteInEditor.Add(tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveTickExecuteInEditor(void* callee)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < TicksExecuteInEditor.Count(); i++)
|
||||||
|
{
|
||||||
|
if (TicksExecuteInEditor[i].Callee == callee)
|
||||||
|
{
|
||||||
|
TicksExecuteInEditor.RemoveAt(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
Scripts.Clear();
|
Scripts.Clear();
|
||||||
Ticks.Clear();
|
Ticks.Clear();
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
ScriptsExecuteInEditor.Clear();
|
ScriptsExecuteInEditor.Clear();
|
||||||
|
TicksExecuteInEditor.Clear();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -373,6 +373,18 @@ void ParticleEffect::Update()
|
|||||||
UpdateSimulation();
|
UpdateSimulation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_EDITOR
|
||||||
|
|
||||||
|
#include "Editor/Editor.h"
|
||||||
|
|
||||||
|
void ParticleEffect::UpdateExecuteInEditor()
|
||||||
|
{
|
||||||
|
if (!Editor::IsPlayMode)
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
void ParticleEffect::CacheModifiedParameters()
|
void ParticleEffect::CacheModifiedParameters()
|
||||||
{
|
{
|
||||||
if (_parameters.IsEmpty())
|
if (_parameters.IsEmpty())
|
||||||
@@ -649,6 +661,7 @@ void ParticleEffect::OnEnable()
|
|||||||
GetSceneRendering()->AddGeometry(this);
|
GetSceneRendering()->AddGeometry(this);
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
GetSceneRendering()->AddViewportIcon(this);
|
GetSceneRendering()->AddViewportIcon(this);
|
||||||
|
GetScene()->Ticking.Update.AddTickExecuteInEditor<ParticleEffect, &ParticleEffect::UpdateExecuteInEditor>(this);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Base
|
// Base
|
||||||
@@ -658,6 +671,7 @@ void ParticleEffect::OnEnable()
|
|||||||
void ParticleEffect::OnDisable()
|
void ParticleEffect::OnDisable()
|
||||||
{
|
{
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
|
GetScene()->Ticking.Update.RemoveTickExecuteInEditor(this);
|
||||||
GetSceneRendering()->RemoveViewportIcon(this);
|
GetSceneRendering()->RemoveViewportIcon(this);
|
||||||
#endif
|
#endif
|
||||||
GetSceneRendering()->RemoveGeometry(this);
|
GetSceneRendering()->RemoveGeometry(this);
|
||||||
|
|||||||
@@ -366,6 +366,9 @@ protected:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
#if USE_EDITOR
|
||||||
|
void UpdateExecuteInEditor();
|
||||||
|
#endif
|
||||||
void CacheModifiedParameters();
|
void CacheModifiedParameters();
|
||||||
void ApplyModifiedParameters();
|
void ApplyModifiedParameters();
|
||||||
void OnParticleSystemModified();
|
void OnParticleSystemModified();
|
||||||
|
|||||||
@@ -17,6 +17,9 @@
|
|||||||
#include "Engine/Profiler/ProfilerGPU.h"
|
#include "Engine/Profiler/ProfilerGPU.h"
|
||||||
#include "Engine/Renderer/Utils/BitonicSort.h"
|
#include "Engine/Renderer/Utils/BitonicSort.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if USE_EDITOR
|
||||||
|
#include "Editor/Editor.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
struct SpriteParticleVertex
|
struct SpriteParticleVertex
|
||||||
{
|
{
|
||||||
@@ -1155,6 +1158,13 @@ void ParticleManagerService::Update()
|
|||||||
// Simulation delta time can be based on a time since last update or the current delta time
|
// Simulation delta time can be based on a time since last update or the current delta time
|
||||||
float dt = effect->UseTimeScale ? deltaTime : deltaTimeUnscaled;
|
float dt = effect->UseTimeScale ? deltaTime : deltaTimeUnscaled;
|
||||||
float t = effect->UseTimeScale ? time : timeUnscaled;
|
float t = effect->UseTimeScale ? time : timeUnscaled;
|
||||||
|
#if USE_EDITOR
|
||||||
|
if (!Editor::IsPlayMode)
|
||||||
|
{
|
||||||
|
dt = deltaTimeUnscaled;
|
||||||
|
t = timeUnscaled;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
const float lastUpdateTime = instance.LastUpdateTime;
|
const float lastUpdateTime = instance.LastUpdateTime;
|
||||||
if (lastUpdateTime > 0 && t > lastUpdateTime)
|
if (lastUpdateTime > 0 && t > lastUpdateTime)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user