diff --git a/Source/Mocha.Common/Entities/IActor.cs b/Source/Mocha.Common/Entities/IActor.cs index 33490069..fcee3912 100644 --- a/Source/Mocha.Common/Entities/IActor.cs +++ b/Source/Mocha.Common/Entities/IActor.cs @@ -7,6 +7,7 @@ public interface IActor void Delete(); void Update(); + void FrameUpdate(); } public static class IActorExtensions diff --git a/Source/Mocha.Engine/BaseGame.cs b/Source/Mocha.Engine/BaseGame.cs index c472bb99..0b0c254c 100644 --- a/Source/Mocha.Engine/BaseGame.cs +++ b/Source/Mocha.Engine/BaseGame.cs @@ -66,6 +66,12 @@ public void Update() } DebugOverlay.ScreenText( $"BaseGame.Update assembly {GetType().Assembly.GetHashCode()}" ); + + // Call tick logic on all entities + TryCallMethodOnEntity( "Update" ); + + // Fire tick event + Event.Run( Event.TickAttribute.Name ); } public void Shutdown() diff --git a/Source/Mocha.Tests/EntityTickTests.cs b/Source/Mocha.Tests/EntityTickTests.cs new file mode 100644 index 00000000..836d8f14 --- /dev/null +++ b/Source/Mocha.Tests/EntityTickTests.cs @@ -0,0 +1,56 @@ +using Mocha; +using Mocha.Common; + +namespace Mocha.Tests; + +[TestClass] +public class EntityTickTests +{ + [TestMethod] + public void TestEntityImplementsTickInterface() + { + // Create a test actor instance + var actor = new TestActor(); + + // Verify it implements IActor correctly + Assert.IsInstanceOfType(actor, typeof(IActor)); + + // Verify it has both Update and FrameUpdate methods + var updateMethod = actor.GetType().GetMethod("Update"); + var frameUpdateMethod = actor.GetType().GetMethod("FrameUpdate"); + + Assert.IsNotNull(updateMethod); + Assert.IsNotNull(frameUpdateMethod); + } + + [TestMethod] + public void TestIActorInterfaceHasBothMethods() + { + // Verify IActor interface has both required methods + var iactorType = typeof(IActor); + var updateMethod = iactorType.GetMethod("Update"); + var frameUpdateMethod = iactorType.GetMethod("FrameUpdate"); + + Assert.IsNotNull(updateMethod, "IActor interface should have Update method"); + Assert.IsNotNull(frameUpdateMethod, "IActor interface should have FrameUpdate method"); + } +} + +// Test actor for validating interface compliance +public class TestActor : Actor +{ + public bool UpdateCalled { get; private set; } = false; + public bool FrameUpdateCalled { get; private set; } = false; + + public override void Update() + { + UpdateCalled = true; + base.Update(); + } + + public override void FrameUpdate() + { + FrameUpdateCalled = true; + base.FrameUpdate(); + } +} \ No newline at end of file