public override void OnRenderFrame(RenderFrameEventArgs e) { GL.ClearColor(ClearColor); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.DepthTest); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); UpdateProjection(); #region Modelview GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); Glu.LookAt(camera.Position, camera.Position + camera.Attitude.Direction, camera.Attitude.Up); #endregion objects.Objects["Camera Position"] = camera.Position.ToString(2); objects.Objects["Camera Direction"] = camera.Attitude.Direction.ToString(2); objects.Objects["Camera Up"] = camera.Attitude.Up.ToString(2); objects.Objects["Camera Side"] = camera.Attitude.Side.ToString(2); Renderables.Render(GetRenderInfo()); SwapBuffers(); }
public void FrameUpdate(RenderFrameEventArgs renderFrameEventArgs) { if (_lobby == null) { return; } if (_gameStarted) { _lobby.StartTime.Text = ""; return; } string text; var difference = _startTime - DateTime.UtcNow; if (difference.Ticks < 0) { if (difference.TotalSeconds < -5) { text = "Right Now?"; } else { text = "Right Now"; } } else { text = $"{(int) Math.Floor(difference.TotalMinutes)}:{difference.Seconds:D2}"; } _lobby.StartTime.Text = "Round Starts In: " + text; }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); var tileSize = MouseCoords.Grid.TileSize; if (!RangeCheck()) { return(false); } if (pManager.CurrentPermission.IsTile) { MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2, CurrentTile.Y + tileSize / 2, MouseCoords.Grid); } else { MouseCoords = new LocalCoordinates(CurrentTile.X + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.X, CurrentTile.Y + tileSize / 2 + pManager.CurrentPrototype.PlacementOffset.Y, MouseCoords.Grid); } MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); return(true); }
public override void FrameUpdate(RenderFrameEventArgs e) { placementManager.FrameUpdate(e); _entityManager.FrameUpdate(e.Elapsed); var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(inputManager.MouseScreenPosition)); var entityToClick = GetEntityUnderPosition(mousePosWorld); if (entityToClick == lastHoveredEntity) { return; } if (lastHoveredEntity != null && !lastHoveredEntity.Deleted) { lastHoveredEntity.GetComponent <IClientClickableComponent>().OnMouseLeave(); } lastHoveredEntity = entityToClick; if (lastHoveredEntity != null) { lastHoveredEntity.GetComponent <IClientClickableComponent>().OnMouseEnter(); } }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { onGrid = false; return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); snapSize = MouseCoords.Grid.SnapSize; //Find snap size. onGrid = true; var mouselocal = new Vector2( //Round local coordinates onto the snap grid (float)Math.Round(MouseCoords.X / (double)snapSize, MidpointRounding.AwayFromZero) * snapSize, (float)Math.Round(MouseCoords.Y / (double)snapSize, MidpointRounding.AwayFromZero) * snapSize); //Convert back to original world and screen coordinates after applying offset MouseCoords = new LocalCoordinates(mouselocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), MouseCoords.Grid); MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); if (!RangeCheck()) { return(false); } return(true); }
public override void FrameUpdate(RenderFrameEventArgs e) { placementManager.FrameUpdate(e); _entityManager.FrameUpdate(e.Elapsed); var map = playerManager.LocalPlayer.ControlledEntity.GetComponent <ITransformComponent>().MapID; var mousePosWorld = eyeManager.ScreenToWorld(new ScreenCoordinates(inputManager.MouseScreenPosition, map)); IEntity entityToClick = GetEntityUnderPosition(mousePosWorld); if (entityToClick == lastHoveredEntity) { return; } if (lastHoveredEntity != null) { lastHoveredEntity.GetComponent <IClientClickableComponent>().OnMouseLeave(); } lastHoveredEntity = entityToClick; if (lastHoveredEntity != null) { lastHoveredEntity.GetComponent <IClientClickableComponent>().OnMouseEnter(); } }
/// <inheritdoc /> public void FrameUpdate(RenderFrameEventArgs e) { // Try to get current map. var map = MapId.Nullspace; var ent = PlayerManager.LocalPlayer.ControlledEntity; if (ent != null && ent.TryGetComponent <IGodotTransformComponent>(out var component)) { map = component.MapID; } if (map == MapId.Nullspace || CurrentPermission == null || CurrentMode == null) { return; } var mouseScreen = new ScreenCoordinates(inputManager.MouseScreenPosition, map); ValidPosition = CurrentMode.FrameUpdate(e, mouseScreen); // purge old unapproved tile changes _pendingTileChanges.RemoveAll(c => c.Item2 < _time.RealTime); // continues tile placement but placement of entities only occurs on mouseup if (_tileMouseDown && CurrentPermission.IsTile) { HandlePlacement(); } drawNode.Update(); }
public void FrameUpdate(RenderFrameEventArgs args) { foreach (var overlay in _overlays.Values) { overlay.FrameUpdate(args); } }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { onGrid = false; return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); snapSize = MouseCoords.Grid.SnapSize; //Find snap size. onGrid = true; var mouseLocal = new Vector2( //Round local coordinates onto the snap grid (float)(Math.Round((MouseCoords.Position.X / (double)snapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * snapSize, (float)(Math.Round((MouseCoords.Position.Y / (double)snapSize - 0.5f), MidpointRounding.AwayFromZero) + 0.5) * snapSize); //Adjust mouseCoords to new calculated position MouseCoords = new LocalCoordinates(mouseLocal + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), MouseCoords.Grid); MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); if (!RangeCheck()) { return(false); } return(true); }
public void FrameUpdate(RenderFrameEventArgs eventArgs) { foreach (var label in _aliveLabels) { label.Update(eventArgs); } _aliveLabels.RemoveAll(l => l.Disposed); }
/// <summary> /// Takes care of refreshing the screen /// </summary> private void MachineOnRenderFrameCompleted(object sender, RenderFrameEventArgs e) { // --- Refresh the screen Dispatcher.Invoke(() => { _lastBuffer = e.ScreenPixels; RefreshSpectrumScreen(_lastBuffer); }, DispatcherPriority.Send ); }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); return(true); }
public override void Update(AssemblyLoader.UpdateLevel level, float frameTime) { base.Update(level, frameTime); switch (level) { case AssemblyLoader.UpdateLevel.FramePreEngine: var renderFrameEventArgs = new RenderFrameEventArgs(frameTime); IoCManager.Resolve <IClientNotifyManager>().FrameUpdate(renderFrameEventArgs); IoCManager.Resolve <IClientGameTicker>().FrameUpdate(renderFrameEventArgs); break; } }
public void Update(RenderFrameEventArgs eventArgs) { _timeLeft += eventArgs.Elapsed; Position = InitialPos - new Vector2(0, 20 * (_timeLeft * _timeLeft + _timeLeft)); if (_timeLeft > 0.5f) { Modulate = Color.White.WithAlpha(1f - 0.2f * (float)Math.Pow(_timeLeft - 0.5f, 3f)); if (_timeLeft > 3f) { Dispose(); } } }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); if (pManager.CurrentPermission.IsTile) { return(false); } CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); if (!RangeCheck()) { return(false); } var nodes = new List <Vector2>(); if (pManager.CurrentPrototype.MountingPoints != null) { nodes.AddRange( pManager.CurrentPrototype.MountingPoints.Select( current => new Vector2(MouseCoords.X, CurrentTile.Y + current))); } else { nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 0.5f)); nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.0f)); nodes.Add(new Vector2(MouseCoords.X, CurrentTile.Y + 1.5f)); } Vector2 closestNode = (from Vector2 node in nodes orderby(node - MouseCoords.Position).LengthSquared ascending select node).First(); MouseCoords = new LocalCoordinates(closestNode + new Vector2(pManager.CurrentPrototype.PlacementOffset.X, pManager.CurrentPrototype.PlacementOffset.Y), MouseCoords.Grid); MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); return(true); }
/// <summary> /// Takes care of refreshing the screen /// </summary> private void MachineOnRenderFrameCompleted(object sender, RenderFrameEventArgs e) { // --- Refresh the screen Dispatcher.Invoke(() => { _lastBuffer = e.ScreenPixels; RefreshSpectrumScreen(_lastBuffer); if (!_justPaused) { Vm.Machine.BeeperProvider?.PlaySound(); Vm.Machine.SoundProvider?.PlaySound(); } _justPaused = false; }, DispatcherPriority.Send ); }
/// <summary> /// Refresh the view periodically /// </summary> private void OnRenderFrameCompleted(object sender, RenderFrameEventArgs e) { if (Vm.ScreenRefreshCount % 100 == 0) { #pragma warning disable VSTHRD001 // Avoid legacy thread switching APIs Dispatcher.Invoke(() => { var newModel = Vm.CreateBasicListViewModel(); newModel.DecodeBasicProgram(); if (!BasicListViewModel.Compare(_lastModel, newModel)) { Vm.RefreshBasicList(); _lastModel = newModel; } }); #pragma warning restore VSTHRD001 // Avoid legacy thread switching APIs } }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); var tilesize = MouseCoords.Grid.TileSize; if (!RangeCheck()) { return(false); } var entitymanager = IoCManager.Resolve <IClientEntityManager>(); var failtoplace = !entitymanager.AnyEntitiesIntersecting(MouseCoords.MapID, new Box2(new Vector2(CurrentTile.X, CurrentTile.Y), new Vector2(CurrentTile.X + 0.99f, CurrentTile.Y + 0.99f))); if (pManager.CurrentPermission.IsTile) { MouseCoords = new LocalCoordinates(CurrentTile.X + tilesize / 2, CurrentTile.Y + tilesize / 2, MouseCoords.Grid); } else { MouseCoords = new LocalCoordinates(CurrentTile.X + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.X, CurrentTile.Y + tilesize / 2 + pManager.CurrentPrototype.PlacementOffset.Y, MouseCoords.Grid); } MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); return(failtoplace); }
/// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> public override void OnRenderFrame(RenderFrameEventArgs e) { base.OnRenderFrame(e); GL.Clear(ClearBufferMask.ColorBufferBit); // // Draw particles as meta-circles (meta-balls / blobs) // if (m_useBlobs) { m_blobs.Render(this.m_particleSystem.Particles, m_fluidSim.Domain); } // Draw particles as points and a velocity line else { GL.Disable(EnableCap.Texture2D); GL.Color4(m_blobs.Color); foreach (var particle in this.m_particleSystem.Particles) { GL.Begin(BeginMode.Points); GL.Vertex2(particle.Position.X, particle.Position.Y); GL.End(); if (m_drawVel) { Vector2 vel = particle.Position + particle.Velocity * 0.1f; GL.Begin(BeginMode.Lines); GL.Vertex2(particle.Position.X, particle.Position.Y); GL.Vertex2(vel.X, vel.Y); GL.End(); } } } // // Draw Bounding Volumes // m_collisionSolver.BoundingVolumes.Draw(Color.LightGreen); if (m_selectedBoundingVolume != null) { GL.Color3(Color.GreenYellow); m_selectedBoundingVolume.Draw(); } // Draw PointList if (m_pointList != null) { GL.Color4(Color.Red); GL.Begin(BeginMode.LineStrip); foreach (var point in m_pointList) { GL.Vertex2(point.X, point.Y); } GL.End(); } // // Draw OpenTK text // // Text Background if (m_showHelp) { GL.PushAttrib(AttribMask.EnableBit); GL.Enable(EnableCap.Blend); GL.Color4(0.0f, 0.0f, 0.0f, 0.8f); GL.Begin(BeginMode.Quads); GL.Vertex2(m_fluidSim.Domain.Left, m_fluidSim.Domain.Bottom); GL.Vertex2(m_fluidSim.Domain.Right, m_fluidSim.Domain.Bottom); GL.Vertex2(m_fluidSim.Domain.Right, m_fluidSim.Domain.Top); GL.Vertex2(m_fluidSim.Domain.Left, m_fluidSim.Domain.Top); GL.End(); GL.PopAttrib(); } GL.Color4(Color.White); m_textPrinter.Begin(); // FPS & Co. // Show fps (Frames per second) m_textPrinter.Prepare(CreateFPSText(e.Time), m_textFont, out m_textHandleStats); m_textPrinter.Draw(m_textHandleStats); // Help if (m_showHelp) { GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); GL.Translate(0.0f, m_textFont.Height, 0.0f); m_textPrinter.Draw(m_textHandleHelp); GL.MatrixMode(MatrixMode.Modelview); GL.PopMatrix(); } m_textPrinter.End(); // Present SwapBuffers(); // Check OGL errors Utils.TraceGlError(); }
public virtual bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseScreen) { return(false); }
protected override void FrameUpdate(RenderFrameEventArgs args) { _frameTimes[_frameIndex] = (float)_gameTiming.RealFrameTime.TotalSeconds; _frameIndex = (_frameIndex + 1) % TrackedFrames; }
public void FrameUpdate(RenderFrameEventArgs e) { CurrentState?.FrameUpdate(e); }
public override bool FrameUpdate(RenderFrameEventArgs e, ScreenCoordinates mouseS) { if (mouseS.MapID == MapId.Nullspace) { return(false); } MouseScreen = mouseS; MouseCoords = pManager.eyeManager.ScreenToWorld(MouseScreen); if (pManager.CurrentPermission.IsTile) { return(false); } CurrentTile = MouseCoords.Grid.GetTile(MouseCoords); if (!RangeCheck()) { return(false); } var manager = IoCManager.Resolve <IClientEntityManager>(); var snapToEntities = manager.GetEntitiesInRange(MouseCoords, SnapToRange) .Where(entity => entity.Prototype == pManager.CurrentPrototype && entity.GetComponent <ITransformComponent>().MapID == MouseCoords.MapID) .OrderBy(entity => (entity.GetComponent <ITransformComponent>().WorldPosition - MouseCoords.ToWorld().Position).LengthSquared) .ToList(); if (snapToEntities.Any()) { var closestEntity = snapToEntities.First(); if (closestEntity.TryGetComponent <ISpriteRenderableComponent>(out var component)) { var closestSprite = component.CurrentSprite; var closestBounds = closestSprite.Size; var closestRect = Box2.FromDimensions( closestEntity.GetComponent <ITransformComponent>().WorldPosition.X - closestBounds.X / 2f, closestEntity.GetComponent <ITransformComponent>().WorldPosition.Y - closestBounds.Y / 2f, closestBounds.X, closestBounds.Y); var sides = new[] { new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Top - closestBounds.Y / 2f), new Vector2(closestRect.Left + closestRect.Width / 2f, closestRect.Bottom + closestBounds.Y / 2f), new Vector2(closestRect.Left - closestBounds.X / 2f, closestRect.Top + closestRect.Height / 2f), new Vector2(closestRect.Right + closestBounds.X / 2f, closestRect.Top + closestRect.Height / 2f) }; var closestSide = (from Vector2 side in sides orderby(side - MouseCoords.Position).LengthSquared select side).First(); MouseCoords = new LocalCoordinates(closestSide, MouseCoords.Grid); MouseScreen = pManager.eyeManager.WorldToScreen(MouseCoords); } } if (CheckCollision()) { return(false); } return(true); }
public override void FrameUpdate(RenderFrameEventArgs e) { placementManager.FrameUpdate(e); _entityManager.FrameUpdate(e.Elapsed); }
private void OnFrameRender(object sender, RenderFrameEventArgs args) { _stateHandler.Draw(args.Renderer); }
public void FrameProcess(RenderFrameEventArgs eventArgs) { _updateAudio(); }
public void FrameProcess(RenderFrameEventArgs eventArgs) { // Nada. }
public virtual void FrameUpdate(RenderFrameEventArgs e) { }
protected override void FrameUpdate(RenderFrameEventArgs args) { if (!VisibleInTree) { return; } var stringBuilder = new StringBuilder(); var mouseScreenPos = inputManager.MouseScreenPosition; var screenSize = _displayManager.ScreenSize; int mouseWorldMap; int mouseWorldGrid; GridCoordinates mouseWorldPos; ScreenCoordinates worldToScreen; IEntity mouseEntity = null; try { var coords = eyeManager.ScreenToWorld(new ScreenCoordinates(mouseScreenPos)); mouseWorldMap = (int)coords.MapID; mouseWorldGrid = (int)coords.GridID; mouseWorldPos = coords; worldToScreen = eyeManager.WorldToScreen(coords); if (stateManager.CurrentState is GameScreen gameScreen) { mouseEntity = gameScreen.GetEntityUnderPosition(coords); } } catch { mouseWorldPos = eyeManager.ScreenToWorld(mouseScreenPos); mouseWorldGrid = 0; mouseWorldMap = 0; worldToScreen = new ScreenCoordinates(); } stringBuilder.AppendFormat(@"Positioning Debug: Screen Size: {0} Mouse Pos: Screen: {1} World: {2} W2S: {3} Grid: {4} Map: {5} Entity: {6} GUI: {7} ", screenSize, mouseScreenPos, mouseWorldPos, worldToScreen, mouseWorldGrid, mouseWorldMap, mouseEntity, UserInterfaceManager.CurrentlyHovered); stringBuilder.AppendLine("\nAttached Entity:"); if (playerManager.LocalPlayer?.ControlledEntity == null) { stringBuilder.AppendLine("No attached entity."); } else { var entityTransform = playerManager.LocalPlayer.ControlledEntity.Transform; var playerWorldOffset = entityTransform.WorldPosition; var playerScreen = eyeManager.WorldToScreen(playerWorldOffset); stringBuilder.AppendFormat(@" World: {0} Screen: {1} Grid: {2} Map: {3}", playerWorldOffset, playerScreen, entityTransform.GridID, entityTransform.MapID); } contents.Text = stringBuilder.ToString(); MinimumSizeChanged(); }
// this is called when it is time to render the next frame. public override void OnRenderFrame(RenderFrameEventArgs e) { if (pdoc.pgame().GameOver) { MessageBox.Show(pdoc.pgame().GameOverMessage); Exit(); } DateTime currentDate = new DateTime(); currentDate = DateTime.Now; /* This gets the number of 100-nanosecond time intervals that have * elapsed since midnight, January 1, 0001 AD. I hope it is really this * accurate, but it is probably more of a joke. Yet, I don't believe that * there is anything more accurate that can be used in C# for calculating * a decent dt -- JC */ long elapsedTimeIn100ns = currentDate.Ticks - savetime; // savetime is the time saved from a previous iteration of OnRenderFrame savetime = currentDate.Ticks; float timeInSeconds = elapsedTimeIn100ns / 10000000.0f; // elapsed time in seconds if (timeInSeconds < _mindt) { timeInSeconds = _mindt; } else if (timeInSeconds > _maxdt) { timeInSeconds = _maxdt; } // I won't let the time be less than _mindt or greater than _maxdt so // that we get a decent number of frames per second. If it's less // than _mindt, the picture can get kind of jittery. If it's greater // than _maxdt, the number of frames per second is down in the mud. // At that point, we might as well just pretend we are getting 10 frames // per second, which gives as good a picture as can be expected -- JC float thisdt = _runspeed * timeInSeconds; // you can set _runspeed higher than 1.0 above, which will make things // appear to run faster -- I don't think it is necessary, though, and // it might do more harm than good. Note that if the real // TimeInSeconds is greater than _maxdt, and we "pretend" we are // getting 10 frames per second, it has the same effect as // increasing the _runspeed -- it's just an artificial increase -- JC if (framecount < 30) { dthistory.Add(thisdt); framecount++; dtsum += thisdt; } else { dtsum -= dthistory[0]; dthistory.RemoveAt(); dtsum += thisdt; dthistory.Add(thisdt); } // I keep a history of the past 30 dt's, and take the average of them // to use as the final dt (below). This can compensate for such // artificial changes in the real dt as when C# spends some unexpected // time doing its garbage collection. We don't want the dt to change // too abruptly or the picture will be screwed up and jittery. -- JC float dt = dtsum / framecount; // You can Console.WriteLine here the value 1.0 / dt, and it will tell // you how many frames per second you are getting. About 50 frames // per second seems to be ideal, but anything between 10 and 100 seems // OK. If you are getting close to 10, you probably don't have a // compatible graphics card, and you have all graphics running from software -- JC pdoc.stepDoc(dt, view); // the stepDoc call does a lot -- calculates all positions, velocities, // and accelerations for critters, sets up the drawing for the game // world, sets up the drawing of the critters, etc. -- this call is // the main call to the guts of AC Framework -- JC ShowStatusMessage(view.pgame().statusMessage()); SwapBuffers(); // a GameWindow method whieh displays everything // that was drawn in stepDoc -- JC }