public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera) { iter++; PerformanceMonitor.PushFrame("Component Update"); if (_componentList == null) { _componentList = Components.Values.ToList(); } for (uint j = 0; j < Math.Min(GameSettings.Default.EntityUpdateRate, _componentList.Count); j++) { var c = (k + j) % (uint)_componentList.Count; if (iter % (ulong)_componentList[(int)c].UpdateRate == 0) { _componentList[(int)c].Update(gameTime, chunks, camera); } } k += (uint)Math.Min(GameSettings.Default.EntityUpdateRate, _componentList.Count); /* * foreach (var component in Components.Values) * component.Update(gameTime, chunks, camera); */ PerformanceMonitor.PopFrame(); AddRemove(); }
public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera) // Todo: Camera redundant { PerformanceMonitor.PushFrame("Component Update"); PerformanceMonitor.SetMetric("COMPONENTS", NumComponents()); var playerPoint = World.Renderer.Camera.Position; // Todo: Make this a sphere? var distanceVec = new Vector3(GameSettings.Default.EntityUpdateDistance, GameSettings.Default.EntityUpdateDistance, GameSettings.Default.EntityUpdateDistance); var updateBox = new BoundingBox(playerPoint - distanceVec, playerPoint + distanceVec); var componentsToUpdate = World.EnumerateIntersectingObjectsLoose(updateBox); PerformanceMonitor.SetMetric("COMPONENTS UPDATED", componentsToUpdate.Count); foreach (var body in componentsToUpdate) { body.Update(gameTime, chunks, camera); body.ProcessTransformChange(); } if (Debugger.Switches.DrawUpdateBox) { foreach (var chunk in World.EnumerateChunksInBounds(updateBox)) { Drawer3D.DrawBox(chunk.GetBoundingBox(), Color.Red, 0.4f, false); } } PerformanceMonitor.PopFrame(); AddRemove(); ReceiveMessage(); }
public void EnumerateIntersectingObjectsLoose(BoundingBox Box, HashSet <GameComponent> Into, Func <GameComponent, bool> Filter = null) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateIntersectingObjects w/ Filter"); var minChunkID = GlobalVoxelCoordinate.FromVector3(Box.Min).GetGlobalChunkCoordinate(); var maxChunkID = GlobalVoxelCoordinate.FromVector3(Box.Max).GetGlobalChunkCoordinate(); for (var x = minChunkID.X; x <= maxChunkID.X; ++x) { for (var y = minChunkID.Y; y <= maxChunkID.Y; ++y) { for (var z = minChunkID.Z; z <= maxChunkID.Z; ++z) { var coord = new GlobalChunkCoordinate(x, y, z); if (ChunkManager.CheckBounds(coord)) { var chunk = ChunkManager.GetChunk(coord); lock (chunk) { foreach (var entity in chunk.Components) { if (Filter == null || Filter(entity)) { Into.Add(entity); } } } } } } } PerformanceMonitor.PopFrame(); }
public void UpdateTransform() { HasMoved = false; PerformanceMonitor.PushFrame("Body.UpdateTransform"); if (Parent != null) { globalTransform = LocalTransform * Parent.GlobalTransform; } else { globalTransform = LocalTransform; } UpdateBoundingBox(); if (NeedsSpacialStorageUpdate(LastBounds, BoundingBox)) { Manager.World.RemoveGameObject(this, LastBounds); Manager.World.AddGameObject(this, BoundingBox); if (IsRoot() && !IsFlagSet(Flag.DontUpdate)) { Manager.World.RemoveRootGameObject(this, LastBounds); Manager.World.AddRootGameObject(this, BoundingBox); } } LastBounds = BoundingBox; PerformanceMonitor.PopFrame(); }
public IEnumerable <GameComponent> EnumerateIntersectingObjects(BoundingBox box, CollisionType queryType) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateIntersectingObjects"); var r = EnumerateIntersectingObjects(box, t => (t.CollisionType & queryType) == t.CollisionType); PerformanceMonitor.PopFrame(); return(r); }
public HashSet <GameComponent> EnumerateIntersectingRootEntitiesLoose(BoundingBox box) { PerformanceMonitor.PushFrame("Enumerate Roots"); var hash = new HashSet <GameComponent>(); EnumerateIntersectingRootEntitiesLoose(box, hash); PerformanceMonitor.PopFrame(); return(hash); }
public IEnumerable <Body> EnumerateIntersectingObjects(BoundingBox box, CollisionType queryType) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateIntersectingObjects"); var hash = new HashSet <Body>(); OctTree.EnumerateItems(box, hash, t => (t.CollisionType & queryType) == t.CollisionType); PerformanceMonitor.PopFrame(); return(hash); }
public IEnumerable <Body> EnumerateIntersectingObjects(BoundingFrustum Frustum) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateFrustum"); var hash = new HashSet <Body>(); OctTree.EnumerateItems(Frustum, hash); PerformanceMonitor.PopFrame(); return(hash); }
public IEnumerable <GameComponent> EnumerateIntersectingObjects(BoundingBox box, Func <GameComponent, bool> Filter = null) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateIntersectingObjects w/ Filter"); var hash = new HashSet <GameComponent>(); EnumerateIntersectingObjects(box, hash, Filter); PerformanceMonitor.PopFrame(); return(hash); }
protected override void Update(GameTime time) { if (!IsActive) { base.Update(time); return; } #if SHARP_RAVEN && !DEBUG try { #endif if (GumInputMapper.WasConsoleTogglePressed()) { ConsoleVisible = !ConsoleVisible; if (ConsoleVisible) { var commandPanel = GetConsoleTile("COMMAND"); commandPanel.AddCommandEntry(); ConsoleGui.SetFocus(commandPanel.Children[0]); } } if (ConsoleVisible) { ConsoleGui.Update(time); if (ConsoleGui.FocusItem != null) { DwarfGame.GumInput.FireKeyboardActionsOnly(ConsoleGui); } } PerformanceMonitor.BeginFrame(); PerformanceMonitor.PushFrame("Update"); AssetManagement.Steam.Steam.Update(); DwarfTime.LastTime.Update(time); StateManager.Update(DwarfTime.LastTime); base.Update(time); PerformanceMonitor.PopFrame(); #if SHARP_RAVEN && !DEBUG } catch (Exception exception) { if (ravenClient != null) { ravenClient.Capture(new SentryEvent(exception)); } throw; } #endif HasRendered = false; }
public void PropogateTransforms() { PerformanceMonitor.PushFrame("Propogate Transforms"); UpdateTransform(); for (var i = 0; i < Children.Count; ++i) { Children[i].PropogateTransforms(); } PerformanceMonitor.PopFrame(); }
public void UpdatePaused(DwarfTime gameTime, ChunkManager chunks, Camera camera) { PerformanceMonitor.PushFrame("Component Update"); foreach (var component in Components.Values) { component.UpdatePaused(gameTime, chunks, camera); } PerformanceMonitor.PopFrame(); AddRemove(); }
public void UpdateTransform() { PerformanceMonitor.PushFrame("Body.UpdateTransform"); var newTransform = Matrix.Identity; if ((Parent as Body) != null) { newTransform = LocalTransform * (Parent as Body).GlobalTransform; } else { newTransform = LocalTransform; } globalTransform = newTransform; UpdateBoundingBox(); if (CachedOcttreeNode == null || MaxDiff(LastBounds, BoundingBox) > 0.1f) { //if (CollisionType != CollisionType.None) { if (CachedOcttreeNode == null || CachedOcttreeNode.Contains(BoundingBox) == ContainmentType.Disjoint) { RemoveFromOctTree(); if (!IsDead) { CachedOcttreeNode = Manager.World.OctTree.Add(this, BoundingBox); } } else { CachedOcttreeNode.Remove(this, LastBounds); if (!IsDead) { CachedOcttreeNode = CachedOcttreeNode.Add(this, BoundingBox); } } } LastBounds = BoundingBox; } hasMoved = false; PerformanceMonitor.PopFrame(); }
public IEnumerable <Body> EnumerateIntersectingObjects(BoundingFrustum Frustum, Func <Body, bool> Filter = null) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateFrustum"); var hash = new HashSet <Body>(); if (Filter == null) { OctTree.EnumerateItems(Frustum, hash); } else { OctTree.EnumerateItems(Frustum, hash, Filter); } PerformanceMonitor.PopFrame(); return(hash); }
protected override void Draw(GameTime time) { if (GraphicsDevice.IsDisposed) { return; } HasRendered = true; #if !DEBUG try { #endif PerformanceMonitor.PushFrame("Render"); GraphicsDevice.Clear(Color.Black); if (GameStateManager.DrawScreensaver) { ScreenSaver.Render(GraphicsDevice, DwarfTime.LastTime); } GameStateManager.Render(DwarfTime.LastTime); GraphicsDevice.SetRenderTarget(null); base.Draw(time); PerformanceMonitor.PopFrame(); PerformanceMonitor.Render(); if (ConsoleVisible) { ConsoleGui.Draw(); } #if !DEBUG } catch (Exception exception) { Program.CaptureException(exception); if (Program.ShowErrorDialog(exception.Message)) { throw new HandledException(exception); } } #endif }
protected override void Draw(GameTime time) { if (GraphicsDevice.IsDisposed) { return; } HasRendered = true; #if SHARP_RAVEN && !DEBUG try { #endif PerformanceMonitor.PushFrame("Render"); GraphicsDevice.Clear(Color.Black); if (GameStateManager.DrawScreensaver) { ScreenSaver.Render(GraphicsDevice, DwarfTime.LastTime); } GameStateManager.Render(DwarfTime.LastTime); GraphicsDevice.SetRenderTarget(null); base.Draw(time); PerformanceMonitor.PopFrame(); PerformanceMonitor.Render(); if (ConsoleVisible) { ConsoleGui.Draw(); } #if SHARP_RAVEN && !DEBUG } catch (Exception exception) { if (ravenClient != null) { ravenClient.Capture(new SentryEvent(exception)); } throw; } #endif }
public void EnumerateIntersectingObjectsLoose(BoundingBox box, HashSet <GameComponent> Into, Func <GameComponent, bool> Filter = null) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateIntersectingObjects w/ Filter"); foreach (var chunk in EnumerateChunksInBounds(box)) { lock (chunk) { foreach (var entity in chunk.Entities) { if (Filter == null || Filter(entity)) { Into.Add(entity); } } } } PerformanceMonitor.PopFrame(); }
public IEnumerable <GameComponent> EnumerateIntersectingObjects(BoundingFrustum Frustum, Func <GameComponent, bool> Filter = null) { PerformanceMonitor.PushFrame("CollisionManager.EnumerateFrustum"); var hash = new HashSet <GameComponent>(); foreach (var chunk in EnumerateChunksInBounds(Frustum)) { lock (chunk) { foreach (var entity in chunk.Entities) { if (Frustum.Contains(entity.BoundingBox) != ContainmentType.Disjoint) { if (Filter == null || Filter(entity)) { hash.Add(entity); } } } } } PerformanceMonitor.PopFrame(); return(hash); }
public void UpdateTransform() { HasMoved = false; PerformanceMonitor.PushFrame("Body.UpdateTransform"); if (Parent != null) { globalTransform = LocalTransform * Parent.GlobalTransform; } else { globalTransform = LocalTransform; } UpdateBoundingBox(); // Todo: Only bother if we are not fully contained in the current voxel chunk OR we've crossed a boundary. Manager.World.RemoveGameObject(this, LastBounds); Manager.World.AddGameObject(this, BoundingBox); LastBounds = BoundingBox; PerformanceMonitor.PopFrame(); }
protected override void Update(GameTime time) { if (!IsActive) { base.Update(time); return; } #if !DEBUG try { #endif if (GumInputMapper.WasConsoleTogglePressed()) { ConsoleVisible = !ConsoleVisible; if (ConsoleVisible) { var commandPanel = GetConsoleTile("COMMAND"); commandPanel.AddCommandEntry(); ConsoleGui.SetFocus(commandPanel.Children[0]); } } if (ConsoleVisible) { ConsoleGui.Update(time); if (ConsoleGui.FocusItem != null) { DwarfGame.GumInput.FireKeyboardActionsOnly(ConsoleGui); } } PerformanceMonitor.BeginFrame(); PerformanceMonitor.PushFrame("Update"); AssetManagement.Steam.Steam.Update(); DwarfTime.LastTime.Update(time); GameStateManager.Update(DwarfTime.LastTime); lock (_actionMutex) { foreach (var action in _lazyActions) { action.Action(); action.Result?.Invoke(); } _lazyActions.Clear(); } base.Update(time); PerformanceMonitor.PopFrame(); #if !DEBUG } catch (HandledException) { throw; } catch (Exception exception) { Program.CaptureException(exception); if (Program.ShowErrorDialog(exception.Message)) { throw new HandledException(exception); } } #endif HasRendered = false; }