示例#1
0
        private static void Draw(SpriteBatch spr)
        {
            JEngine.Camera.UpdateMatrix(JEngine.MainGraphicsDevice);
            JEngine.MainGraphicsDevice.SetRenderTarget(null);
            JEngine.MainGraphicsDevice.Clear(JEngine.BackgroundColor);

            SamplerState s = JEngine.Camera.Zoom > 1 ? SamplerState.PointClamp : SamplerState.LinearClamp;

            spr.Begin(SpriteSortMode.Deferred, null, s, null, null, null, JEngine.Camera.GetMatrix());

            // Draw the world.
            JEngine.EngineDraw();
            DrawPending(spr);
            Debug.Draw(spr);

            spr.End();

            InUIDraw = true;
            spr.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);

            // Draw the UI.
            JEngine.EngineDrawUI();
            Debug.DrawUI(spr);

            spr.End();

            // Draw the ECS UI.
            UserInterface.Active.Draw(spr);

            InUIDraw = false;

            Statistics.RenderTargetDraws = GameScreen.RTDrawCount;
            GameScreen.RTDrawCount       = 0;
        }
示例#2
0
 public static void Start()
 {
     try
     {
         using (var game = new JEngine())
         {
             JEngine.Instance = game;
             game.Run();
             JEngine.Instance = null;
         }
     }
     finally
     {
         Debug.Shutdown();
     }
 }
示例#3
0
        private static void Update()
        {
            cumulativeFrames++;
            if (frameTimer.Elapsed.TotalSeconds >= 1.0)
            {
                frameTimer.Restart();
                Framerate        = cumulativeFrames;
                cumulativeFrames = 0;
            }

            Input.StartFrame();
            Debug.Update();

            #region Debug Text
            Debug.Text($"FPS: {Framerate:F0} (Target: {(TargetFramerate == 0 ? "uncapped" : TargetFramerate.ToString("F0"))}, VSync: {VSyncMode})");
            Debug.Text($"Time Scale: {Time.TimeScale}");
            Debug.Text($"Screen Res: ({Screen.Width}x{Screen.Height})");
            Debug.Text($"Allocated memory: {System.GC.GetTotalMemory(false) / 1024 / 1024}MB.");
            Debug.Text($"Texture Swap Count: {Loop.Statistics.DrawMetrics.TextureCount}");
            Debug.Text($"Draw Calls: {Loop.Statistics.DrawMetrics.DrawCount}");
            Debug.Text($"Sprites Drawn: {Loop.Statistics.DrawMetrics.SpriteCount}");
            Debug.Text($"Render Target Draw Count: {Loop.Statistics.RenderTargetDraws}");
            Debug.Text($"Total Entities: {JEngine.Entities.EntityCount} of {JEngine.Entities.MaxEntityCount}.");
            var   tm       = JEngine.TileMap;
            var   tilePos  = tm.PixelToTileCoords((int)Input.MouseWorldPos.X, (int)Input.MouseWorldPos.Y);
            var   chunkPos = tm.TileToChunkCoords(tilePos.X, tilePos.Y);
            Chunk chunk    = tm.GetChunk(chunkPos);
            Debug.Box(new Rectangle(chunkPos.X * Chunk.SIZE * Tile.SIZE, chunkPos.Y * Chunk.SIZE * Tile.SIZE, Chunk.SIZE * Tile.SIZE, Chunk.SIZE * Tile.SIZE), new Color(20, 60, 160, 50));
            if (chunk == null)
            {
                Debug.Text($"Chunk under mouse ({chunkPos}) is not loaded.");
            }
            else
            {
                Debug.Text($"Chunk under mouse: {chunkPos}, contains {chunk.EntityCount} entities.");
            }
            #endregion

            if (Input.KeyDown(Keys.E))
            {
                JEngine.Camera.UpdateViewBounds = !JEngine.Camera.UpdateViewBounds;
            }

            // Update currently active screen.
            JEngine.EngineUpdate();
        }
示例#4
0
        public static void ToggleFullscreen()
        {
            JEngine.AddAction(() =>
            {
                if (!JEngine.GraphicsDeviceManager.IsFullScreen)
                {
                    oldW   = Width;
                    oldH   = Height;
                    oldPos = JEngine.GameWindow.Position;
                    JEngine.GraphicsDeviceManager.PreferredBackBufferWidth  = MonitorWidth;
                    JEngine.GraphicsDeviceManager.PreferredBackBufferHeight = MonitorHeight;
                }
                else
                {
                    JEngine.GraphicsDeviceManager.PreferredBackBufferWidth  = oldW;
                    JEngine.GraphicsDeviceManager.PreferredBackBufferHeight = oldH;
                    JEngine.GameWindow.Position = oldPos;
                }

                JEngine.GraphicsDeviceManager.ApplyChanges();
                JEngine.GraphicsDeviceManager.ToggleFullScreen();
            });
        }