public void CreateEngineOnEngineLoaded(IGameSnapshot snapshot, ITemplateGroup templates) { snapshot.Systems.Add(new OnEngineLoadedSystem()); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; Assert.Equal(1, engine.GetSystem <OnEngineLoadedSystem>().CallCount); }
public void ToFromContentDatabase(IGameSnapshot snapshot0, ITemplateGroup templates) { IGameEngine engine0 = GameEngineFactory.CreateEngine(snapshot0, templates).Value; IGameSnapshot snapshot1 = engine0.TakeSnapshot(); IGameEngine engine1 = GameEngineFactory.CreateEngine(snapshot1, templates).Value; Assert.Equal(engine0.GetVerificationHash(), engine1.GetVerificationHash()); }
public void CreateEngine(IGameSnapshot snapshot, ITemplateGroup templateGroup) { IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templateGroup).Value; for (int i = 0; i < 20; ++i) { engine.Update().Wait(); engine.SynchronizeState().Wait(); engine.DispatchEvents(); } }
public void EntityUniqueId() { HashSet <int> ids = new HashSet <int>(); IGameSnapshot snapshot = LevelManager.CreateSnapshot(); for (int i = 0; i < 200; ++i) { IEntity entity = snapshot.CreateEntity(); Assert.True(ids.Add(entity.UniqueId)); } }
public void TestGlobalInputOnlySystem(IGameSnapshot snapshot, ITemplateGroup templates) { snapshot.Systems.Add(new GlobalInputSystem()); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; engine.Update(new List<IGameInput>() { new MyInputType() }).Wait(); engine.SynchronizeState().Wait(); Assert.Equal(1, engine.GetSystem<GlobalInputSystem>().CallCount); engine.Update(new List<IGameInput>() { new MyInputType(), new MyInputType() }).Wait(); engine.SynchronizeState().Wait(); Assert.Equal(3, engine.GetSystem<GlobalInputSystem>().CallCount); }
public void SendRemoveFromContentDatabase(IGameSnapshot snapshot, ITemplateGroup templates) { snapshot.Systems.Add(new SystemCounter() { Filter = new Type[] { } }); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; engine.Update().Wait(); engine.SynchronizeState().Wait(); Assert.Equal(snapshot.RemovedEntities.Count(), engine.GetSystem <SystemCounter>().RemovedCount); }
public void RemodifyCurrentData() { IGameSnapshot snapshot = LevelManager.CreateSnapshot(); IEntity entity = snapshot.CreateEntity(); entity.AddData <DataConcurrentNonVersioned>(); entity.AddData <DataConcurrentVersioned>(); snapshot.Systems.Add(new DoubleModifySystem()); ITemplateGroup templates = LevelManager.CreateTemplateGroup(); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; for (int i = 0; i < 20; ++i) { engine.Update().Wait(); engine.SynchronizeState().Wait(); } }
public void TestGlobalInputOnlySystem(IGameSnapshot snapshot, ITemplateGroup templates) { snapshot.Systems.Add(new GlobalInputSystem()); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; engine.Update(new List <IGameInput>() { new MyInputType() }).Wait(); engine.SynchronizeState().Wait(); Assert.Equal(1, engine.GetSystem <GlobalInputSystem>().CallCount); engine.Update(new List <IGameInput>() { new MyInputType(), new MyInputType() }).Wait(); engine.SynchronizeState().Wait(); Assert.Equal(3, engine.GetSystem <GlobalInputSystem>().CallCount); }
public void GotAddedEventsForInitialDatabase(IGameSnapshot snapshot, ITemplateGroup templates) { IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; engine.Update().Wait(); int notifiedCount = 0; engine.EventNotifier.OnEvent<EntityAddedEvent>(evnt => { ++notifiedCount; }); engine.DispatchEvents(); Assert.Equal(1 + snapshot.AddedEntities.Count() + snapshot.ActiveEntities.Count() + snapshot.RemovedEntities.Count(), notifiedCount); engine.SynchronizeState().Wait(); engine.Update().Wait(); notifiedCount = 0; engine.DispatchEvents(); Assert.Equal(0, notifiedCount); }
public void GotAddedEventsForInitialDatabase(IGameSnapshot snapshot, ITemplateGroup templates) { IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; engine.Update().Wait(); int notifiedCount = 0; engine.EventNotifier.OnEvent <EntityAddedEvent>(evnt => { ++notifiedCount; }); engine.DispatchEvents(); Assert.Equal(1 + snapshot.AddedEntities.Count() + snapshot.ActiveEntities.Count() + snapshot.RemovedEntities.Count(), notifiedCount); engine.SynchronizeState().Wait(); engine.Update().Wait(); notifiedCount = 0; engine.DispatchEvents(); Assert.Equal(0, notifiedCount); }
/// <summary> /// Creates a new game engine that can be used to simulate the game using the content from /// the given content database. The passed in snapshot will not be modified. /// </summary> /// <remarks> /// This is a helper method; it serializes the arguments and then calls CreateEngine(string, /// string) which does the actual work. /// </remarks> /// <param name="snapshot">The IGameSnapshot to use to create the engine.</param> /// <param name="templates">The ITemplateGroup used to create the engine.</param> /// <returns>A game engine that can play the given content.</returns> public static Maybe <IGameEngine> CreateEngine(IGameSnapshot snapshot, ITemplateGroup templates) { return(CreateEngine(LevelManager.SaveSnapshot(snapshot), LevelManager.SaveTemplateGroup(templates))); }
/// <summary> /// Converts a game snapshot to JSON that can be restored later. /// </summary> public static string SaveSnapshot(IGameSnapshot snapshot) { return SerializationHelpers.Serialize<GameSnapshot>((GameSnapshot)snapshot, RequiredConverters.GetConverters(), RequiredConverters.GetContextObjects(Maybe<GameEngine>.Empty)); }
/// <summary> /// Creates a new game engine that can be used to simulate the game using the content from /// the given content database. The passed in snapshot will not be modified. /// </summary> /// <remarks> /// This is a helper method; it serializes the arguments and then calls CreateEngine(string, /// string) which does the actual work. /// </remarks> /// <param name="snapshot">The IGameSnapshot to use to create the engine.</param> /// <param name="templates">The ITemplateGroup used to create the engine.</param> /// <returns>A game engine that can play the given content.</returns> public static Maybe<IGameEngine> CreateEngine(IGameSnapshot snapshot, ITemplateGroup templates) { return CreateEngine(LevelManager.SaveSnapshot(snapshot), LevelManager.SaveTemplateGroup(templates)); }
public void SendRemoveFromContentDatabase(IGameSnapshot snapshot, ITemplateGroup templates) { snapshot.Systems.Add(new SystemCounter() { Filter = new Type[] { } }); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; engine.Update().Wait(); engine.SynchronizeState().Wait(); Assert.Equal(snapshot.RemovedEntities.Count(), engine.GetSystem<SystemCounter>().RemovedCount); }
/// <summary> /// Converts a game snapshot to JSON that can be restored later. /// </summary> public static string SaveSnapshot(IGameSnapshot snapshot) { return(SerializationHelpers.Serialize <GameSnapshot>((GameSnapshot)snapshot, RequiredConverters.GetConverters(), RequiredConverters.GetContextObjects(Maybe <GameEngine> .Empty))); }
public void CreateEngineOnEngineLoaded(IGameSnapshot snapshot, ITemplateGroup templates) { snapshot.Systems.Add(new OnEngineLoadedSystem()); IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value; Assert.Equal(1, engine.GetSystem<OnEngineLoadedSystem>().CallCount); }