public void Recycle() { foreach (var item in this.data) { var st = item; WorldUtilities.ReleaseState(ref st); } PoolArray <TState> .Recycle(ref this.data); PoolArray <Tick> .Recycle(ref this.dataTicks); }
public void Discard() { this.isEmpty = true; WorldUtilities.ReleaseState(ref this.state); }
public void CopyState() { // Initialize var world = TestsHelper.CreateWorld(); // Adding items world.AddSystem <PointsSystem>(); var entity = world.AddEntity(new Point() { position = Vector3.one, unitsCount = 99f, increaseRate = 1f }); var entityToRemove = world.AddEntity(new Point() { position = Vector3.one, unitsCount = 1f, increaseRate = 1f }); world.AddComponent <Point, PointIncreaseUnits>(entity); world.AddComponent <Point, PointIncreaseUnits>(entityToRemove); // Save state var state = world.GetState(); Assert.IsTrue(state.points.Count == 2); Assert.IsTrue(state.units.Count == 0); Assert.IsTrue(state.pointComponents.Count == 2); world.RemoveEntity <Point>(entityToRemove); Assert.IsTrue(state.points.Count == 1); Assert.IsTrue(state.pointComponents.Count == 1); var savedState = (IState <State>)WorldUtilities.CreateState <State>(); savedState.Initialize(world, freeze: true, restore: false); Assert.IsTrue(state.points.Count == 1); Assert.IsTrue(state.pointComponents.Count == 1); { var dic = TestsHelper.GetValue <Dictionary <int, IComponentsBase> >(world, "componentsCache"); Assert.IsTrue(dic.Count == 2); } savedState.CopyFrom(state); world.Update(1f); WorldUtilities.ReleaseState(ref state); // Restore state world.SetState((State)savedState); //((IWorldBase)world).Simulate(savedState.tick); Assert.IsTrue(((State)savedState).points.Count == 1); Assert.IsTrue(((State)savedState).pointComponents.Count == 1); { var dic = TestsHelper.GetValue <Dictionary <int, IList> >(world, "entitiesCache"); Assert.IsTrue(dic.Count == 1); } { var dic = TestsHelper.GetValue <Dictionary <int, IList> >(world, "filtersCache"); Assert.IsTrue(dic.Count == 2); } { var dic = TestsHelper.GetValue <Dictionary <int, IComponentsBase> >(world, "componentsCache"); Assert.IsTrue(dic.Count == 2); } TestsHelper.ReleaseWorld(ref world); }