refactor: update & draw calls have been refactored into systems
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public abstract class Behaviour : BehaviourBase
|
||||
public abstract class Behaviour : BehaviourBase, IFirstFrameUpdate,
|
||||
IPreUpdate, IUpdate, IPostUpdate,
|
||||
IPreDraw, IDraw, IPostDraw
|
||||
{
|
||||
private bool isInitializedThisFrame = false;
|
||||
|
||||
protected IUniverse Universe => BehaviourController.UniverseObject.Universe;
|
||||
protected IUniverseObject UniverseObject => BehaviourController.UniverseObject;
|
||||
|
||||
@@ -20,11 +20,6 @@ public abstract class Behaviour : BehaviourBase
|
||||
protected virtual void OnInitialize() { }
|
||||
protected virtual void OnInitialize(IInitializable _)
|
||||
{
|
||||
isInitializedThisFrame = true;
|
||||
|
||||
BehaviourController.OnPreUpdate += PreUpdate;
|
||||
BehaviourController.OnPreDraw += PreDraw;
|
||||
BehaviourController.OnUpdate += Update;
|
||||
BehaviourController.UniverseObject.OnEnteredUniverse += EnteredUniverse;
|
||||
BehaviourController.UniverseObject.OnExitedUniverse += ExitedUniverse;
|
||||
|
||||
@@ -37,9 +32,6 @@ public abstract class Behaviour : BehaviourBase
|
||||
protected virtual void OnFinalize() { }
|
||||
protected virtual void OnFinalize(IInitializable _)
|
||||
{
|
||||
BehaviourController.OnPreUpdate -= PreUpdate;
|
||||
BehaviourController.OnPreDraw -= PreDraw;
|
||||
BehaviourController.OnUpdate -= Update;
|
||||
BehaviourController.UniverseObject.OnEnteredUniverse -= EnteredUniverse;
|
||||
BehaviourController.UniverseObject.OnExitedUniverse -= ExitedUniverse;
|
||||
|
||||
@@ -49,9 +41,16 @@ public abstract class Behaviour : BehaviourBase
|
||||
ExitedUniverse(UniverseObject, Universe);
|
||||
}
|
||||
|
||||
protected virtual void OnFirstActiveFrame() { }
|
||||
void IFirstFrameUpdate.FirstActiveFrame()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
OnFirstActiveFrame();
|
||||
}
|
||||
|
||||
protected virtual void OnPreUpdatePreActiveCheck() { }
|
||||
protected virtual void OnPreUpdate() { }
|
||||
protected virtual void PreUpdate(IBehaviourController _)
|
||||
void IPreUpdate.PreUpdate()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
|
||||
@@ -60,22 +59,12 @@ public abstract class Behaviour : BehaviourBase
|
||||
if (!IsActive)
|
||||
return;
|
||||
|
||||
if (isInitializedThisFrame)
|
||||
FirstActiveFrame();
|
||||
|
||||
OnPreUpdate();
|
||||
}
|
||||
|
||||
protected virtual void OnFirstActiveFrame() { }
|
||||
protected virtual void FirstActiveFrame()
|
||||
{
|
||||
OnFirstActiveFrame();
|
||||
isInitializedThisFrame = false;
|
||||
}
|
||||
|
||||
protected virtual void OnUpdatePreActiveCheck() { }
|
||||
protected virtual void OnUpdate() { }
|
||||
protected virtual void Update(IBehaviourController _)
|
||||
void IUpdate.Update()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
|
||||
@@ -87,9 +76,23 @@ public abstract class Behaviour : BehaviourBase
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
protected virtual void OnPostUpdatePreActiveCheck() { }
|
||||
protected virtual void OnPostUpdate() { }
|
||||
void IPostUpdate.PostUpdate()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
|
||||
OnPostUpdatePreActiveCheck();
|
||||
|
||||
if (!StateEnable.Enabled)
|
||||
return;
|
||||
|
||||
OnPostUpdate();
|
||||
}
|
||||
|
||||
protected virtual void OnPreDrawPreActiveCheck() { }
|
||||
protected virtual void OnPreDraw() { }
|
||||
protected virtual void PreDraw(IBehaviourController _)
|
||||
void IPreDraw.PreDraw()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
|
||||
@@ -101,6 +104,34 @@ public abstract class Behaviour : BehaviourBase
|
||||
OnPreDraw();
|
||||
}
|
||||
|
||||
protected virtual void OnDrawPreActiveCheck() { }
|
||||
protected virtual void OnDraw() { }
|
||||
void IDraw.Draw()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
|
||||
OnDrawPreActiveCheck();
|
||||
|
||||
if (!StateEnable.Enabled)
|
||||
return;
|
||||
|
||||
OnDraw();
|
||||
}
|
||||
|
||||
protected virtual void OnPostDrawPreActiveCheck() { }
|
||||
protected virtual void OnPostDraw() { }
|
||||
void IPostDraw.PostDraw()
|
||||
{
|
||||
Debug.Assert.AssertInitialized(this);
|
||||
|
||||
OnPostDrawPreActiveCheck();
|
||||
|
||||
if (!StateEnable.Enabled)
|
||||
return;
|
||||
|
||||
OnPostDraw();
|
||||
}
|
||||
|
||||
protected virtual void OnEnteredUniverse(IUniverse universe) { }
|
||||
protected virtual void EnteredUniverse(IUniverseObject sender, IUniverse universe) => OnEnteredUniverse(universe);
|
||||
|
||||
|
Reference in New Issue
Block a user