private async void onUpdateFrame(object sender, FrameEventArgs e) { if (_updateFrameRetries > 3) { return; } try { _updateMessagePump.PumpMessages(); _repeatArgs.DeltaTime = e.Time; await Events.OnRepeatedlyExecuteAlways.InvokeAsync(_repeatArgs); if (State.Paused) { return; } adjustSpeed(); GameLoop.Update(); //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(_repeatArgs); _pipeline?.Update(); } catch (Exception ex) { _updateFrameRetries++; Debug.WriteLine(ex.ToString()); throw ex; } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (Global.quitting) { this.Exit(); } #if __ANDROID__ if (In_Background) { if (Ready_To_Resume) { Loop.SetRenderTargets(); // Recreate dynamic textures here In_Background = false; } Ready_To_Resume = false; return; } #endif foreach (var time in Loop.Update(gameTime)) { base.Update(time); } this.IsMouseVisible = Tactile.Input.MouseVisible || Loop.Paused; update_debug_monitor(); }
} // BeginRun #endregion #region Update /// <summary> /// Called when the game has determined that game logic needs to be processed. /// </summary> protected override void Update(GameTime gameTime) { base.Update(gameTime); if (ResetDevice) { GraphicsDeviceManager.ApplyChanges(); ResetDevice = false; } if (UseGamerServices) GamerServicesDispatcher.Update(); if (ShowExceptionsWithGuide) // If we want to show exception in the Guide. { // If no exception was raised. if (exception == null) { try { GameLoop.Update(gameTime); } catch (Exception e) { Time.PauseGame(); exception = e; } } } else // If not then the StarEngine method will managed them. GameLoop.Update(gameTime); } // Update
/// <summary> /// Main method that initializes the Game /// </summary> static void Main(string[] args) { // Creates an instance of GameLoop to start the game GameLoop gameLoop = new GameLoop(); // Calls the Update method to update the game gameLoop.Update(); }
protected override void OnDragOver(DragEventArgs drgevent) { base.OnDragOver(drgevent); if (DesignView.Context == null || m_ghosts.Count == 0) { return; } Point clientPoint = PointToClient(new Point(drgevent.X, drgevent.Y)); Ray3F rayw = GetWorldRay(clientPoint); bool shiftPressed = Control.ModifierKeys == Keys.Shift; DomNode hitnode = null; HitRecord?hit = null; if (shiftPressed) { Matrix4F v = Camera.ViewMatrix; Matrix4F p = Camera.ProjectionMatrix; HitRecord[] hits = GameEngine.RayPick(v, p, rayw, false); foreach (HitRecord ht in hits) { hitnode = GameEngine.GetAdapterFromId(ht.instanceId).Cast <DomNode>(); bool skip = false; // ignore ghosts foreach (DomNode node in m_ghosts) { if (hitnode == node || hitnode.IsDescendantOf(node)) { skip = true; break; } } if (skip) { continue; } hit = ht; break; } } ISnapFilter snapFilter = Globals.MEFContainer.GetExportedValue <ISnapFilter>(); bool snap = (shiftPressed && hit.HasValue); foreach (DomNode ghost in m_ghosts) { HitRecord?hr = (snap && (snapFilter == null || snapFilter.CanSnapTo(ghost, hitnode))) ? hit : null; ProjectGhost(ghost, rayw, hr); } GameLoop.Update(); GameLoop.Render(); }
protected override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.Milliseconds / 1000; inputGenerator.GenerateEvents(); camera.Update(dt); gameLoop.Update(dt); MessageSystem.ProcessChanges(); }
protected override void Update(float dt) { activeLoop.Update(dt); canvas.Update(dt); // Gamestate changes don't apply until the end of the current frame. if (nextState != currentState) { activeLoop = CreateLoop(nextState); currentState = nextState; } MessageSystem.ProcessChanges(); }
public void Update_PlayerAndMonster_NotThrowException() { // ASSERT var sectorMock = new Mock <ISector>(); var sector = sectorMock.Object; var sectorManagerMock = new Mock <ISectorManager>(); sectorManagerMock.SetupGet(x => x.CurrentSector).Returns(sector); var sectorManager = sectorManagerMock.Object; var actorManagerMock = new Mock <IActorManager>(); var actorInnerList = new List <IActor>(); actorManagerMock.SetupGet(x => x.Items).Returns(actorInnerList); var actorManager = actorManagerMock.Object; var humanPlayer = new HumanPlayer(); var humanActor = CreateActor(humanPlayer); actorInnerList.Add(humanActor); var botPlayer = new BotPlayer(); var botActor = CreateActor(botPlayer); actorInnerList.Add(botActor); var gameLoop = new GameLoop(sectorManager, actorManager) { ActorTaskSources = new IActorTaskSource[0] }; // ACT Action act = () => { gameLoop.Update(); }; // ARRANGE act.Should().NotThrow(); }
protected override void OnUpdateFrame(FrameEventArgs args) { p2 = p1; p1 = DateTime.UtcNow; Input.Keyboard = KeyboardState; Input.Mouse = MouseState; if (KeyboardState.IsKeyDown(Keys.V) && !KeyboardState.WasKeyDown(Keys.V)) { if (VSync == VSyncMode.On) { VSync = VSyncMode.Off; } else { VSync = VSyncMode.On; } } if (KeyboardState.IsKeyDown(Keys.F10) && !KeyboardState.WasKeyDown(Keys.F10)) { resize = true; EditMode = !EditMode; } if (KeyboardState.IsKeyDown(Keys.F9) && !KeyboardState.WasKeyDown(Keys.F9)) { if (editorCamController.Enabled) { gameCamController.Enabled = true; editorCamController.Enabled = false; } else { gameCamController.Enabled = false; editorCamController.Enabled = true; } } if (Play) { GameLoop.Update((float)args.Time); PhysicsEngine.Simulate((float)args.Time); } EditorLoop.Update((float)args.Time); }
protected override void OnPaint(PaintEventArgs e) { try { if (DesignView.Context == null || GameEngine.IsInError || GameLoop == null) { e.Graphics.Clear(DesignView.BackColor); if (GameEngine.IsInError) { e.Graphics.DrawString(GameEngine.CriticalError, Font, Brushes.Red, 1, 1); } return; } GameLoop.Update(); Render(); } catch (Exception ex) { e.Graphics.DrawString(ex.Message, Font, Brushes.Red, 1, 1); } }
private void onUpdateFrame(object sender, FrameEventArgs e) { try { _updateMessagePump.PumpMessages(); _repeatArgs.DeltaTime = e.Time; Events.OnRepeatedlyExecuteAlways.Invoke(_repeatArgs); if (State.Paused) { return; } adjustSpeed(); GameLoop.Update(false); Events.OnRepeatedlyExecute.Invoke(_repeatArgs); _pipeline?.Update(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); _renderMessagePump.Post(_ => throw ex, null); //throwing on render thread to ensure proper application crash. } }