private void DevelopmentTests() { // GC test. TODO: MAKE SURE THIS IS COMMENTED OUT WHEN NOT NEEDED!!!!!!!!!!!!!!!!!! //if (InputManager.KeyCodePressed(Keys.A)) { // GC.Collect(); //} time -= Time.DeltaTime; if (time <= 0.0f) { time = 2.0f; Console.WriteLine("NEW: " + ParticleEngine.ParticleCount + ", OLD: " + ParticleEngine.ParticleCount); } // Multithreaded render test. if (InputManager.KeyCodePressed(Keys.F)) { Renderer.Multithreaded = !Renderer.Multithreaded; Console.WriteLine("Multithreaded: " + (Renderer.Multithreaded ? "on" : "off")); } if (InputManager.KeyCodePressed(Keys.L)) { ParticleEngine.UpdateMode = ParticleEngine.UpdateMode == UpdateMode.ParallelAsynchronous ? UpdateMode.Synchronous : UpdateMode.ParallelAsynchronous; Console.WriteLine("Multithreaded particles: " + (ParticleEngine.UpdateMode == UpdateMode.ParallelAsynchronous ? "on" : "off")); } //Debug.WriteLine(SpatialPartitionManager.EntitiesCount); }
public void DrawUI(Camera2D camera) { GraphicsDevice.SetRenderTarget(UIRender); GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 0.0f, 0); RenderUI(); RenderUIGizmos(camera); ChangeDrawCall(SpriteSortMode.FrontToBack, Screen.ScreenScaleMatrix, BlendState.AlphaBlend, SamplerState.PointClamp, null, rasterizerScissor); Console.DrawOverlay(camera, Core.Rendering.SpriteBatch); EndDrawCall(); }
static RenderLoop() { // Do not set rendering loop if fully headless. if (Screen.IsFullHeadless) { return; } // Headless mode. if (Screen.DisplayMode == DisplayMode.Headless) { Add(LoopEnum.PrepareFrame, Render.NewFrame); Add(LoopEnum.Culling, Core.Rendering.PerformCulling); Add(LoopEnum.DrawUI, Render.DrawUI); Add(LoopEnum.DrawRenderTargets, Core.Rendering.DrawRenderTargets); return; } // Full graphics mode. Add(LoopEnum.NewFrame, Core.Lighting.Update); Add(LoopEnum.PrepareFrame, Render.NewFrame); Add(LoopEnum.Culling, Core.Rendering.PerformCulling); Add(LoopEnum.GenerateRenderLists, cam => Render.GenerateRenderLists()); Add(LoopEnum.LightingStart, _ => Render.StartLighting()); Add(LoopEnum.FinalizeParticles, _ => ParticleEngine.WaitForThreads()); Add(LoopEnum.LightingEnd, _ => Render.EndLighting()); Add(LoopEnum.RenderAlphaParticlesUnlit, cam => Render.DrawNewParticles(cam)); Add(LoopEnum.DrawUnderlay, cam => Console.DrawUnderlay(cam, Core.Rendering.SpriteBatch)); Add(LoopEnum.DrawUI, Render.DrawUI); Add(LoopEnum.DrawRenderTargets, Core.Rendering.DrawRenderTargets); }
/// <summary> /// Initializes the engine. /// </summary> protected sealed override void Initialize() { FileMarshal.Setup(); Content.RootDirectory = "Data"; LoadEngineContent(); LoadAssets(); IsMouseVisible = true; GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = Screen.IsFullHeadless; TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 60); InactiveSleepTime = IsEditor ? TimeSpan.FromSeconds(1.0f / 2000) : TimeSpan.FromSeconds(1.0f / 60); // Alt-tabbed update rate. // If the engine ISN'T initialized (i.e, in editor mode)... if (!isInitialized) { ThreadPool.SetMinThreads(Environment.ProcessorCount, 8); Config.Initialize(); InputManager.Initialize(this); Reflection.Initialize(); ModLoader.Initialize(); GameLoop = new GameLoop(); ParticleEngine.AllocationMode = Config.Performance.UseArrayPoolParticles ? ParticleAllocationMode.ArrayPool : ParticleAllocationMode.Array; ParticleEngine.Initialize(); UIManager.Initialize(); if (!Screen.IsFullHeadless) { Core.Lighting.Initialize(); } SpatialPartitionManager.Initialize(192, 192 * 8); Core.Physics.Initialize(); Network.OnLogInfo += (msg, important) => Console.LogInfo(msg, important, LogSource.Network); Network.OnLogWarning += (msg, exception) => { if (!string.IsNullOrEmpty(msg)) { Console.LogWarning(msg, LogSource.Network); } else { Console.LogWarning(exception, LogSource.Network); } }; Network.OnLogError += (msg, exception) => { if (!string.IsNullOrEmpty(msg)) { Console.LogError(msg, LogSource.Network); } else { Console.LogError(exception, LogSource.Network); } }; SetCurrentScene("_MAIN\\empty"); if (!Screen.IsFullHeadless) { Core.Rendering.Initialize(GraphicsDeviceManager, GraphicsDevice); Console.InitializeStats(Core.Rendering.SpriteBatch); } // After core initialization. Console will work here. Console.Initialize(); Console.LogInfo("Core engine loaded.", true); Console.LogInfo("Game loop loaded:", true); Console.LogInfo(GameLoop.ToString()); Network.Initialize(); Screen.Reset(); Initalized?.Invoke(); Console.LogInfo("Finished initialization.", true); } if (IsEditor) { Editor.ChangeInstance(this); Editor.OnInitialize(this); } OnInitialize(); isInitialized = true; }