示例#1
0
        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;
        }
示例#2
0
文件: Body.cs 项目: hhy5277/dwarfcorp
        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();
        }
示例#4
0
        public void Flush(
            GraphicsDevice Device,
            Shader Effect,
            Camera Camera,
            InstanceRenderMode Mode)
        {
            foreach (var group in InstanceTypes)
            {
                group.Value.Flush(Device, Effect, Camera, Mode);
            }

            PerformanceMonitor.SetMetric("INSTANCES DRAWN", _instanceCounter);
            _instanceCounter = 0;
        }
示例#5
0
        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();
        }
示例#6
0
        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);
        }
示例#7
0
        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
        }
示例#8
0
        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
        }
示例#9
0
 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();
 }
示例#10
0
        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.Current.EntityUpdateDistance, GameSettings.Current.EntityUpdateDistance, GameSettings.Current.EntityUpdateDistance);
            var updateBox          = new BoundingBox(playerPoint - distanceVec, playerPoint + distanceVec);
            var componentsToUpdate = World.EnumerateIntersectingRootEntitiesLoose(updateBox);

            var i = 0;

            foreach (var body in componentsToUpdate)
            {
                i += 1;
                body.Update(gameTime, chunks, camera);
                body.ProcessTransformChange();
            }

            PerformanceMonitor.SetMetric("ENTITIES UPDATED", i);


            if (Debugger.Switches.DrawUpdateBox)
            {
                foreach (var chunk in World.EnumerateChunksInBounds(updateBox))
                {
                    Drawer3D.DrawBox(chunk.GetBoundingBox(), Color.Red, 0.4f, false);
                }
            }

            PerformanceMonitor.PopFrame();

            AddRemove();
            ReceiveMessage();
        }
示例#11
0
文件: Body.cs 项目: hhy5277/dwarfcorp
        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();
        }
示例#12
0
        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);
        }
示例#13
0
        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;
        }
示例#14
0
        public void RebuildVoxelsThread()
        {
            Console.Out.WriteLine("Starting chunk regeneration thread.");
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            var liveChunks = new List <VoxelChunk>();

#if !DEBUG
            try
#endif
            {
                while (!DwarfGame.ExitGame && !ExitThreads)
                {
                    try
                    {
                        RebuildEvent.WaitOne();
                    }
                    catch (ThreadAbortException exception)
                    {
                        continue;
                    }

                    VoxelChunk chunk = null;

                    do
                    {
                        chunk = PopInvalidChunk();
                        if (chunk != null)
                        {
                            if (!chunk.Visible)
                            {
                                continue;                 // Don't bother rebuilding chunks that won't be rendered.
                            }
                            chunk.Rebuild(GameState.Game.GraphicsDevice);

                            liveChunks.Add(chunk);

                            if (liveChunks.Count() > GameSettings.Current.MaxLiveChunks)
                            {
                                liveChunks.Sort((a, b) => a.RenderCycleWhenLastVisible - b.RenderCycleWhenLastVisible);

                                while (liveChunks.Count() > GameSettings.Current.MaxLiveChunks)
                                {
                                    if (liveChunks[0].Visible)
                                    {
                                        break;
                                    }
                                    liveChunks[0].DiscardPrimitive();
                                    liveChunks.RemoveAt(0);
                                }
                            }

                            NeedsMinimapUpdate = true; // Soon to be redundant.
                        }
                    }while (chunk != null);

                    PerformanceMonitor.SetMetric("VISIBLE CHUNKS", liveChunks.Count);
                }
            }
#if !DEBUG
            catch (Exception exception)
            {
                Console.Out.WriteLine("Chunk regeneration thread encountered an exception.");
                ProgramData.WriteExceptionLog(exception);
                //throw;
            }
#endif
            Console.Out.WriteLine(String.Format("Chunk regeneration thread exited cleanly Exit Game: {0} Exit Thread: {1}.", DwarfGame.ExitGame, ExitThreads));
        }