public void Test_Destroy() { using (IWorld world = Root.CreateWorld()) { IActor parent = world.CreateActor(); IActor child = world.CreateActor(); parent.AddChild(child); child.Destroy(); Assert.AreEqual(parent.Children.Count, 0); parent.Destroy(); Assert.AreEqual(world.Actors.Count, 0); parent = world.CreateActor(); child = world.CreateActor(); parent.AddChild(child); parent.Destroy(); Assert.AreEqual(0, world.Actors.Count); Assert.IsTrue(Driver.CoreDriver.HasDestroyed(parent.Handle)); Assert.IsTrue(Driver.CoreDriver.HasDestroyed(child.Handle)); } }
public void Test_Children() { using (IWorld world = Root.CreateWorld()) { IActor parent = world.CreateActor(); IActor child = world.CreateActor(); parent.AddChild(child); Assert.AreEqual(child, parent.Children[0]); Assert.AreEqual(child.Parent, parent); } }
public void Test_Children() { using (IWorld world = Root.CreateWorld()) { IActor first = world.CreateActor(); IActor second = world.CreateActor(); var actors = world.Actors; Assert.AreEqual(actors.Count, 2); Assert.AreEqual(first, actors[0]); Assert.AreEqual(second, actors[1]); } }
public void Test_Detach() { using (IWorld world = Root.CreateWorld()) { IActor parent = world.CreateActor(); IActor child = world.CreateActor(); parent.AddChild(child); Assert.AreEqual(world.Actors.Count, 1); child.Detach(); // Detach will remove parent dependency and returns to World var actors = world.Actors; Assert.AreEqual(actors.Count, 2); } }
public void Test_CreateActor() { using (IWorld world = Root.CreateWorld()) { Assert.IsNotNull(world.CreateActor()); } }
public void Test_Component_Native_Get() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); actor.CreateComponent <ILight>(); Assert.IsNotNull(actor.GetComponent <ILight>()); } }
private void MemoryLeakTest() { IWorld world = Root.CreateWorld(); for (int i = 0; i < 10; i++) { world.CreateActor(); } }
void TestEqualityActors(IWorld world) { IActor first = world.CreateActor(); IActor second = world.Actors[0]; if (first == second) { Console.WriteLine("Actors is equals"); } }
public void Test_Component_Managed_Add() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); TestComponent component = actor.CreateComponent <TestComponent>(); Assert.IsNotNull(component); } }
public void Test_Component_Native_Add() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); ILight light = actor.CreateComponent <ILight>(); Assert.IsNotNull(light); } }
public override void OnInit(IWorld world) { base.OnInit(world); var e = world.CreateActor(); var matcher = world.NewMatcher(); matcher.HasTrait <ATrait>().ExceptTrait <BTrait>(); this.Filter = world.GetFilter(this, matcher); }
public void Test_Name() { const string actorName = "I'm a Actor"; using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); actor.Name = actorName; Assert.AreEqual(actor.Name, actorName); } }
public void Test_World_After_Destroy() { IWorld world = Root.CreateWorld(); HandleUtils.ForceDestroy(world.Handle); // IWorld methods can't throw any exception after handle destroy Assert.IsNull(world.CreateActor()); world.Clear(); world.Dispose(); Assert.IsNull(HandleUtils.TryGetReferenceHolder(world.Handle)); }
public void Test_Component_HasComponent() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); actor.CreateComponent <ILight>(); actor.CreateComponent <TestComponent>(); Assert.IsTrue(actor.HasComponent <ILight>()); Assert.IsTrue(actor.HasComponent <TestComponent>()); } }
public void Test_Actor_After_Destroy() { using (IWorld world = Root.CreateWorld()) { IActor puppetActor = world.CreateActor(); IActor actor = world.CreateActor(); actor.Destroy(); Assert.IsTrue(HandleUtils.IsDestroyed(actor.Handle)); Assert.IsNull(HandleUtils.TryGetReferenceHolder(actor.Handle)); // IActor methods can't throw any exception. actor.AddChild(puppetActor); actor.RemoveChild(puppetActor); actor.Destroy(); actor.Detach(); actor.Enabled = true; Assert.IsFalse(actor.Enabled); actor.CreateComponent <TestComponent>(); Assert.IsNull(actor.Clone()); Assert.IsNull(actor.GetComponent <TestComponent>()); Assert.IsNotNull(actor.GetAllComponents()); Assert.AreEqual(0, actor.GetAllComponents().Count); Assert.IsFalse(actor.HasComponent <TestComponent>()); actor.RemoveComponent <TestComponent>(); string testStr = "Actor"; actor.Name = testStr; Assert.AreNotEqual(testStr, actor.Name); Assert.IsTrue(string.IsNullOrEmpty(actor.Name)); Assert.AreEqual(-1, actor.Id); Assert.IsNull(actor.Parent); Assert.IsNull(actor.World); Assert.IsNotNull(actor.Children); Assert.AreEqual(0, actor.Children.Count); } }
public void Test_Clear() { using (IWorld world = Root.CreateWorld()) { for (int i = 0; i < 10; i++) { world.CreateActor(); } world.Clear(); Assert.AreEqual(world.Actors.Count, 0); } }
public void Test_Component_Remove() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); actor.CreateComponent <ILight>(); actor.CreateComponent <TestComponent>(); actor.RemoveComponent <ILight>(); actor.RemoveComponent <TestComponent>(); Assert.AreEqual(0, actor.GetAllComponents().Count); Assert.IsFalse(actor.HasComponent <ILight>()); Assert.IsFalse(actor.HasComponent <TestComponent>()); } }
public void Test_Component_Destroy() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); ILight light = actor.CreateComponent <ILight>(); TestComponent testComponent = actor.CreateComponent <TestComponent>(); light.Destroy(); testComponent.Destroy(); Assert.AreEqual(0, actor.GetAllComponents().Count); Assert.IsFalse(actor.HasComponent <ILight>()); Assert.IsFalse(actor.HasComponent <TestComponent>()); } }
public void Test_World() { IActor parent; using (IWorld world = Root.CreateWorld()) { parent = world.CreateActor(); ReferenceHolder referenceHolder = HandleUtils.TryGetReferenceHolder(parent.Handle); Assert.IsNotNull(world); Assert.AreEqual(world, parent.World); Assert.IsNotNull(referenceHolder); Assert.IsTrue(referenceHolder.IsStrong); Assert.IsFalse(referenceHolder.IsWeak); } Assert.IsTrue(HandleUtils.IsDestroyed(parent.Handle)); }
public void Test_Component_GetAllComponents() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); actor.CreateComponent <ILight>(); actor.CreateComponent <TestComponent>(); var components = actor.GetAllComponents(); Assert.AreEqual(2, components.Count); Assert.IsNotNull(components[0]); Assert.IsNotNull(components[1]); Assert.AreEqual("Light", components[0].Name); Assert.AreEqual("TestComponent", components[1].Name); } }
public void Test_Component_Lifecycle() { using (IWorld world = Root.CreateWorld()) { IActor actor = world.CreateActor(); bool destroy = false; TestComponent component = actor.CreateComponent <TestComponent>(); EventHandler destroyFn = (sender, e) => destroy = true; component.OnDestroyEvent += destroyFn; actor.RemoveComponent <TestComponent>(); component.OnDestroyEvent -= destroyFn; Assert.IsTrue(destroy); } }