public GameSnapshot() { EntityIdGenerator = new UniqueIntGenerator(); GlobalEntity = new ContentEntity(EntityIdGenerator.Next(), "Global Entity"); ActiveEntities = new List <IEntity>(); AddedEntities = new List <IEntity>(); RemovedEntities = new List <IEntity>(); _systems = new SystemSerializationContainer(); }
public void UniqueIntGeneratorConsumeStartsAtNextInt() { var gen = new UniqueIntGenerator(); gen.Consume(5); Assert.Equal(6, gen.Next()); gen.Consume(3); Assert.Equal(7, gen.Next()); gen.Consume(7); Assert.Equal(8, gen.Next()); gen.Consume(9); Assert.Equal(10, gen.Next()); gen.Consume(-32); gen.Consume(-35); gen.Consume(3); gen.Consume(-10000); Assert.Equal(11, gen.Next()); }
public override void ShuffleNet(List <GridElementMain> listToShaffle) { UniqueIntGenerator randomizer = new UniqueIntGenerator(0, (listToShaffle.Count)); Vector2 targetPosition; for (int i = 0; i < listToShaffle.Count; i++) { int?index = randomizer.GetRandomeValue(i); if (index != null) { targetPosition = listToShaffle[(int)index].ElementTransform.anchoredPosition; } else { targetPosition = listToShaffle[i].ElementTransform.anchoredPosition; } if (listToShaffle[i] is GridLetterElement item) { item.StartMovement(targetPosition); } } }
public void UniqueIntGeneratorStartsAt0() { var gen = new UniqueIntGenerator(); Assert.Equal(0, gen.Next()); }
static UniqueIntGenerator() { _instance = new UniqueIntGenerator(); }
public GameEngine(string snapshotJson, string templateJson) { _templateJson = templateJson; // Create our own little island of references with its own set of templates GameSnapshotRestorer restorer = GameSnapshotRestorer.Restore( snapshotJson, templateJson, Maybe.Just(this)); GameSnapshot snapshot = restorer.GameSnapshot; EntityIdGenerator = snapshot.EntityIdGenerator; _systems = snapshot.Systems; _entityIndex = new EntityIndex(); // TODO: ensure that when correctly restore UpdateNumber //UpdateNumber = updateNumber; _globalEntity = (RuntimeEntity)snapshot.GlobalEntity; EventNotifier.Submit(EntityAddedEvent.Create(_globalEntity)); foreach (var entity in snapshot.AddedEntities) { AddEntity((RuntimeEntity)entity); } foreach (var entity in snapshot.ActiveEntities) { RuntimeEntity runtimeEntity = (RuntimeEntity)entity; // add the entity InternalAddEntity(runtimeEntity); // TODO: verify that if the modification notifier is already triggered, we can // ignore this //if (((ContentEntity)entity).HasModification) { // runtimeEntity.ModificationNotifier.Notify(); //} // done via InternalAddEntity //if (deserializedEntity.HasStateChange) { // deserializedEntity.Entity.DataStateChangeNotifier.Notify(); //} } foreach (var entity in snapshot.RemovedEntities) { RuntimeEntity runtimeEntity = (RuntimeEntity)entity; // add the entity InternalAddEntity(runtimeEntity); // TODO: verify that if the modification notifier is already triggered, we can // ignore this //if (((ContentEntity)entity).HasModification) { // runtimeEntity.ModificationNotifier.Notify(); //} // done via InternalAddEntity //if (deserializedEntity.HasStateChange) { // deserializedEntity.Entity.DataStateChangeNotifier.Notify(); //} RemoveEntity(runtimeEntity); } TemplateIndex templateIndex = new TemplateIndex(restorer.Templates.Templates); _executionGroups = new List <ExecutionGroup>(); var executionGroups = SystemExecutionGroup.GetExecutionGroups(snapshot.Systems); foreach (var executionGroup in executionGroups) { List <MultithreadedSystem> multithreadedSystems = new List <MultithreadedSystem>(); foreach (var system in executionGroup.Systems) { MultithreadedSystem multithreaded = CreateMultithreadedSystem(system, templateIndex); multithreadedSystems.Add(multithreaded); } _executionGroups.Add(new ExecutionGroup(multithreadedSystems)); } _nextState = GameEngineNextState.SynchronizeState; SynchronizeState().Wait(); // call of the engine loaded systems foreach (var group in _executionGroups) { foreach (var system in group.Systems) { var onLoaded = system.System as Trigger.OnEngineLoaded; if (onLoaded != null) { onLoaded.OnEngineLoaded(EventNotifier); // TODO: verify that OnEngineLoaded didn't change any state (via hashing) } } } }