Ejemplo n.º 1
0
        public void AddAndUpdateEntity()
        {
            GameSnapshot   snapshot  = (GameSnapshot)LevelManager.CreateSnapshot();
            ITemplateGroup templates = LevelManager.CreateTemplateGroup();

            snapshot.Systems.Add(new SystemEventLogger(new Type[] { }));

            IEntity entity = snapshot.CreateEntity(GameSnapshot.EntityAddTarget.Added);

            IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value;

            engine.Update().Wait();
            engine.SynchronizeState().Wait();

            List <TriggerEvent> events = new List <TriggerEvent>();

            events.Add(TriggerEvent.OnAdded);
            events.Add(TriggerEvent.OnGlobalPreUpdate);
            events.Add(TriggerEvent.OnUpdate);
            events.Add(TriggerEvent.OnGlobalPostUpdate);
            Assert.Equal(events, engine.GetSystem <SystemEventLogger>().Events);

            for (int i = 0; i < 20; ++i)
            {
                engine.Update().Wait();
                engine.SynchronizeState().Wait();

                events.Add(TriggerEvent.OnGlobalPreUpdate);
                events.Add(TriggerEvent.OnUpdate);
                events.Add(TriggerEvent.OnGlobalPostUpdate);
                Assert.Equal(events, engine.GetSystem <SystemEventLogger>().Events);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
        public GameEngineManager(string snapshotJson, string templateJson, int targetUpdatesPerSecond)
        {
            // allocate the engine
            // TODO: examine the maybe, make sure the game actually loaded
            _gameEngine = GameEngineFactory.CreateEngine(snapshotJson, templateJson).Value;

            // create the event monitors
            CreateEventMonitors(_gameEngine.EventNotifier);

            _networkContext = NetworkContext.CreateServer(new Player("test-player"), "");
            _turnGame       = new AutomaticTurnGame(_networkContext, targetUpdatesPerSecond);
        }
Ejemplo n.º 6
0
        public void CreateEngineUpdateNonList()
        {
            IGameEngine engine = GameEngineFactory.CreateEngine(LevelManager.CreateSnapshot(),
                                                                LevelManager.CreateTemplateGroup()).Value;

            for (int i = 0; i < 20; ++i)
            {
                engine.Update(new LinkedList <IGameInput>()).Wait();
                engine.SynchronizeState().Wait();
                engine.DispatchEvents();
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public void CorrectUpdateCount()
        {
            GameSnapshot   snapshot  = (GameSnapshot)LevelManager.CreateSnapshot();
            ITemplateGroup templates = LevelManager.CreateTemplateGroup();

            for (int i = 0; i < 10; ++i)
            {
                IEntity entity = snapshot.CreateEntity(GameSnapshot.EntityAddTarget.Active);
                entity.AddData <DataEmpty>();
            }

            snapshot.Systems.Add(new SystemCounter()
            {
                Filter = new[] { typeof(DataEmpty) }
            });

            IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value;

            engine.Update().Wait();
            engine.SynchronizeState().Wait();

            Assert.Equal(snapshot.ActiveEntities.Count(), engine.GetSystem <SystemCounter>().UpdateCount);
        }
Ejemplo n.º 11
0
        public void RemoveEntityAndModifyInRemoveNotification()
        {
            GameSnapshot   snapshot  = (GameSnapshot)LevelManager.CreateSnapshot();
            ITemplateGroup templates = LevelManager.CreateTemplateGroup();

            snapshot.Systems.Add(new SystemEventLogger(new Type[] { }));
            snapshot.Systems.Add(new ModifyOnRemovedTrigger());

            {
                IEntity e = snapshot.CreateEntity(GameSnapshot.EntityAddTarget.Removed);
                e.AddData <DataEmpty>();
            }

            IGameEngine engine = GameEngineFactory.CreateEngine(snapshot, templates).Value;

            engine.Update().Wait();
            engine.SynchronizeState().Wait();

            List <TriggerEvent> events = new List <TriggerEvent>();

            events.Add(
                TriggerEvent.OnRemoved,
                TriggerEvent.OnGlobalPreUpdate,
                TriggerEvent.OnGlobalPostUpdate);
            Assert.Equal(events, engine.GetSystem <SystemEventLogger>().Events);

            for (int i = 0; i < 20; ++i)
            {
                engine.Update().Wait();
                engine.SynchronizeState().Wait();

                events.Add(
                    TriggerEvent.OnGlobalPreUpdate,
                    TriggerEvent.OnGlobalPostUpdate);
                Assert.Equal(events, engine.GetSystem <SystemEventLogger>().Events);
            }
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 public void CreateBadEngine()
 {
     Assert.True(GameEngineFactory.CreateEngine("bad data", "bad data").IsEmpty);
 }