public async Task RoomProperlyRendered_Test() { int threadID = AGSGame.UIThreadID; AGSGame.UIThreadID = Environment.CurrentManagedThreadId; try { _mocks.Room().Setup(m => m.ShowPlayer).Returns(false); AGSViewport viewport = new AGSViewport(new AGSDisplayListSettings(), new AGSCamera()); viewport.RoomProvider = new AGSSingleRoomProvider(_mocks.Room().Object); _mocks.GameState().Setup(m => m.Viewport).Returns(viewport); _areas.Clear(); _areas.Add(getArea()); _roomObjects.Clear(); _roomObjects.Add(_mocks.Object(true).Object); _uiObjects.Clear(); _uiObjects.Add(_mocks.Object(true).Object); IRendererLoop loop = getLoop(); Assert.IsTrue(loop.Tick()); //First tick just to tell the display list about our viewport, the second tick will have the objects to render await _events.OnRepeatedlyExecute.InvokeAsync(); Assert.IsTrue(loop.Tick()); _renderer.Verify(r => r.Render(It.IsAny <IObject>(), It.IsAny <IViewport>()), Times.Exactly(2)); } finally { AGSGame.UIThreadID = threadID; } }
public void RoomProperlyRendered_Test() { int threadID = AGSGame.UIThreadID; AGSGame.UIThreadID = Environment.CurrentManagedThreadId; try { _mocks.Room().Setup(m => m.ShowPlayer).Returns(false); AGSViewport viewport = new AGSViewport(new AGSDisplayListSettings(), new AGSCamera(), Mocks.GetResolver()); viewport.RoomProvider = new AGSSingleRoomProvider(_mocks.Room().Object); _mocks.GameState().Setup(m => m.Viewport).Returns(viewport); _mocks.GameState().Setup(m => m.GetSortedViewports()).Returns(new List <IViewport> { _mocks.GameState().Object.Viewport }); _areas.Clear(); _areas.Add(getArea()); var roomObj = _mocks.Object(true); var uiObj = _mocks.Object(true); roomObj.Setup(c => c.ID).Returns("roomObj"); uiObj.Setup(c => c.ID).Returns("uiObj"); _roomObjects.Clear(); _roomObjects.Add(roomObj.Object); _uiObjects.Clear(); _uiObjects.Add(uiObj.Object); var displayList = getDisplayList(); var pipeline = getPipeline(displayList); var roomRenderer = new Mock <IRenderer>(); var uiRenderer = new Mock <IRenderer>(); var roomInsturction = new Mock <IRenderInstruction>(); var uiInstruction = new Mock <IRenderInstruction>(); roomRenderer.Setup(r => r.GetNextInstruction(_mocks.GameState().Object.Viewport)).Returns(roomInsturction.Object); uiRenderer.Setup(r => r.GetNextInstruction(_mocks.GameState().Object.Viewport)).Returns(uiInstruction.Object); pipeline.Subscribe("roomObj", roomRenderer.Object); pipeline.Subscribe("uiObj", uiRenderer.Object); IRendererLoop loop = getLoop(displayList, pipeline); Assert.IsTrue(loop.Tick()); //First tick just to tell the display list about our viewport, the second tick will have the objects to render displayList.GetDisplayList(_mocks.GameState().Object.Viewport); displayList.Update(); pipeline.Update(); Assert.IsTrue(loop.Tick()); roomInsturction.Verify(r => r.Render(), Times.Once); uiInstruction.Verify(r => r.Render(), Times.Once); } finally { AGSGame.UIThreadID = threadID; } }
public void EmptyRoom_NotError_Test() { _mocks.Room().Setup(m => m.ShowPlayer).Returns(false); _areas.Clear(); _roomObjects.Clear(); _uiObjects.Clear(); IRendererLoop loop = getLoop(); Assert.IsTrue(loop.Tick()); _renderer.Verify(r => r.Render(It.IsAny <IObject>(), It.IsAny <IViewport>()), Times.Never); }
public void RoomProperlyRendered_Test() { _mocks.Room().Setup(m => m.ShowPlayer).Returns(false); _areas.Clear(); _areas.Add(getArea()); _roomObjects.Clear(); _roomObjects.Add(_mocks.Object(true).Object); _uiObjects.Clear(); _uiObjects.Add(_mocks.Object(true).Object); IRendererLoop loop = getLoop(); Assert.IsTrue(loop.Tick()); _renderer.Verify(r => r.Render(It.IsAny <IObject>(), It.IsAny <IViewport>()), Times.Exactly(2)); }
public void EmptyRoom_NotError_Test() { _mocks.Room().Setup(m => m.ShowPlayer).Returns(false); _mocks.GameState().Setup(m => m.GetSortedViewports()).Returns(new List <IViewport> { _mocks.GameState().Object.Viewport }); _areas.Clear(); _roomObjects.Clear(); _uiObjects.Clear(); IRendererLoop loop = getLoop(); Assert.IsTrue(loop.Tick()); }
public void Start(IGameSettings settings) { GameLoop = _resolver.Container.Resolve <IGameLoop>(new TypedParameter(typeof(AGS.API.Size), settings.VirtualResolution)); TypedParameter settingsParameter = new TypedParameter(typeof(IGameSettings), settings); try { GameWindow = Resolver.Container.Resolve <IGameWindow>(settingsParameter); } catch (Exception ese) { Debug.WriteLine(ese.ToString()); throw; } //using (GameWindow) { try { TypedParameter gameWindowParameter = new TypedParameter(typeof(IGameWindow), GameWindow); GameWindow.Load += (sender, e) => { Settings = Resolver.Container.Resolve <IRuntimeSettings>(settingsParameter, gameWindowParameter); _graphics.ClearColor(0f, 0f, 0f, 1f); _graphics.Init(); _glUtils.GenBuffers(); Factory = Resolver.Container.Resolve <IGameFactory>(); TypedParameter sizeParameter = new TypedParameter(typeof(AGS.API.Size), Settings.VirtualResolution); Input = _resolver.Container.Resolve <IInput>(gameWindowParameter, sizeParameter); TypedParameter inputParamater = new TypedParameter(typeof(IInput), Input); TypedParameter gameParameter = new TypedParameter(typeof(IGame), this); _renderLoop = _resolver.Container.Resolve <IRendererLoop>(inputParamater, gameParameter); updateResolver(); AudioSettings = _resolver.Container.Resolve <IAudioSettings>(); SaveLoad = _resolver.Container.Resolve <ISaveLoad>(); _glUtils.AdjustResolution(settings.VirtualResolution.Width, settings.VirtualResolution.Height); Events.OnLoad.Invoke(sender, new AGSEventArgs()); }; GameWindow.Resize += async(sender, e) => { await Task.Delay(10); //todo: For some reason on the Mac, the GL Viewport assignment is overridden without this delay (so aspect ratio is not preserved), a bug in OpenTK? resize(); Events.OnScreenResize.Invoke(sender, new AGSEventArgs()); }; GameWindow.UpdateFrame += async(sender, e) => { try { _messagePump.PumpMessages(); if (State.Paused) { return; } adjustSpeed(); await GameLoop.UpdateAsync().ConfigureAwait(false); AGSEventArgs args = new AGSEventArgs(); //Invoking repeatedly execute asynchronously, as if one subscriber is waiting on another subscriber the event will //never get to it (for example: calling ChangeRoom from within RepeatedlyExecute calls StopWalking which //waits for the walk to stop, only the walk also happens on RepeatedlyExecute and we'll hang. //Since we're running asynchronously, the next UpdateFrame will call RepeatedlyExecute for the walk cycle to stop itself and we're good. ///The downside of this approach is that we need to look out for re-entrancy issues. await Events.OnRepeatedlyExecute.InvokeAsync(sender, args); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw ex; } }; GameWindow.RenderFrame += (sender, e) => { if (_renderLoop == null) { return; } try { // render graphics _graphics.ClearScreen(); Events.OnBeforeRender.Invoke(sender, _renderEventArgs); if (_renderLoop.Tick()) { GameWindow.SwapBuffers(); } if (Repeat.OnceOnly("SetFirstRestart")) { SaveLoad.SetRestartPoint(); } } catch (Exception ex) { Debug.WriteLine("Exception when rendering:"); Debug.WriteLine(ex.ToString()); throw; } }; // Run the game at 60 updates per second GameWindow.Run(UPDATE_RATE); } catch (Exception exx) { Debug.WriteLine(exx.ToString()); throw; } } }