Example #1
0
        public void Load()
        {
            var timer = Timer.Start();

            MasterRenderer.ResetRenderer(this);
            Camera.Reset();
            MusicController.ResetIntense();

            World.Load();

            if (!string.IsNullOrEmpty(MapType.Music))
            {
                MusicController.LoopSong(MapType.Music, MapType.IntenseMusic);
            }
            else if (MusicController.SongLooping)
            {
                MusicController.LoopAllSongs();
            }

            ScreenControl.Load();

            if (World.Map.Type.IsSave)
            {
                script?.LoadState(Save.ScriptState);
            }
            else
            {
                script?.OnStart();
            }

            timer.StopAndWrite("Loading Game");
            Log.Debug("Loading successful!");
        }
Example #2
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            if (!Ready || Stopped)
            {
                return;
            }

            timer.Restart();

            MasterRenderer.Render();

            lock (MasterRenderer.GLLock)
            {
                SwapBuffers();
            }

            PerfInfo.RenderLoop(timer.Stop(), 1 / e.Time);
            if (GlobalRender % 20 == 0)
            {
                if (Settings.LogTimeMeasuring)
                {
                    Log.Performance(PerfInfo.FMS, " render " + GlobalRender);
                }

                if (Settings.DeveloperMode || Program.IsDebug)
                {
                    Title = $"{Program.Title} [{MasterRenderer.RenderCalls} Calls, {MasterRenderer.Batches} Batches]";
                }
            }

            GlobalRender++;

            sleep();
        }
Example #3
0
        protected override void Dispose(bool disposing)
        {
            Stopped = true;

            UISpriteManager.Dispose();

            MasterRenderer.Dispose();

            SheetManager.DeleteSheets();

            FontManager.Dispose();

            base.Dispose(disposing);
        }
Example #4
0
        public static void Render()
        {
            Shaders.Uniform(Shaders.TextureShader, ref matrix, Color.White);

            foreach (var r in beforeRender)
            {
                r.Render();
            }

            game.ScreenControl.Render();

            foreach (var r in afterRender)
            {
                r.Render();
            }

            var possibleTarget = game.World.LocalPlayer != null && game.World.LocalPlayer.GetPart <PlayerPart>().FindValidTarget(MouseInput.GamePosition) != null;

            if (Settings.DeveloperMode)
            {
                ColorManager.DrawRect(new CPos(-64, -64, 0), new CPos(64, 64, 0), Color.Cyan);
                ColorManager.DrawRect(MouseInput.WindowPosition + new CPos(-64, -64, 0), MouseInput.WindowPosition + new CPos(64, 64, 0), possibleTarget ? Color.Red : Color.Blue);
            }
            else
            {
                Cursor.Current = possibleTarget ? CursorType.ATTACK : CursorType.DEFAULT;
                Cursor.Render();
            }

            tooltip?.Render();

            MasterRenderer.RenderBatch();

            if (Settings.DeveloperMode)
            {
                MasterRenderer.UseDebugRenderer = true;
                MasterRenderer.PrimitiveType    = PrimitiveType.Lines;

                game.ScreenControl.DebugRender();

                MasterRenderer.RenderBatch();
                MasterRenderer.PrimitiveType    = PrimitiveType.Triangles;
                MasterRenderer.UseDebugRenderer = false;
            }
        }
Example #5
0
        protected override void OnLoad()
        {
            Console.Write("Loading...");

            base.OnLoad();

            KeyInput.SetWindow(this);
            MouseInput.SetWindow(this);

            // Load icon
            var iconData = BitmapLoader.LoadBytes(FileExplorer.FindIn(FileExplorer.Misc, "warsnu"), out var iconWidth, out var iconHeight);

            Icon = new WindowIcon(new Image(iconWidth, iconHeight, iconData));

            MasterRenderer.Initialize();
            SheetManager.InitSheets();

            timer.Restart();
            FontManager.Load();
            timer.StopAndWrite("Loading Fonts");

            timer.Restart();
            AudioController.Load();
            MusicController.Load();
            timer.StopAndWrite("Loading Sound");

            timer.Restart();
            GameController.Load();
            timer.StopAndWrite("Loading Rules");

            SheetManager.FinishSheets();
            MasterRenderer.InitRenderer();

            GameController.CreateFirst();

            Ready = true;
            Console.WriteLine(" Done!");

            if (Program.OnlyLoad)
            {
                Program.Exit();
            }
        }
Example #6
0
        protected override void OnKeyDown(KeyboardKeyEventArgs e)
        {
            if (e.Key == Keys.N && !MusicController.SongLooping)
            {
                MusicController.NextSong();
            }

            if (e.Alt && e.Key == Keys.F4)
            {
                Program.Exit();
            }

            if (e.Control && e.Key == Keys.P)
            {
                MasterRenderer.CreateScreenshot();
                GameController.AddInfoMessage(150, "Screenshot!");
            }

            GameController.KeyDown(e.Key, e.Control, e.Shift, e.Alt);
        }
Example #7
0
        public static void Render()
        {
            game.LocalRender++;

            if (beforeRender.Count != 0)
            {
                foreach (var o in beforeRender)
                {
                    o.Render();
                }

                MasterRenderer.RenderBatch();
            }

            Shaders.Uniform(Shaders.TextureShader, ref Camera.Matrix, Ambient);

            world.TerrainLayer.Render();
            world.SmudgeLayer.Render();

            var pos = world.Game.Editor ? MouseInput.GamePosition : world.PlayerAlive ? world.LocalPlayer.Position : CPos.Zero;

            foreach (var o in prepareRenderList())
            {
                if (((o is Actor actor && actor.WorldPart != null && actor.WorldPart.Hideable) || (o is Wall wall && wall.IsHorizontal && wall.Type.Height >= 512)) && o.Position.Y > pos.Y && Math.Abs(o.Position.X - pos.X) < 4096)
                {
                    var alpha     = o.Position.Y - pos.Y < 1024 ? 1 - (o.Position.Y - pos.Y) / 1024f : (o.Position.Y - pos.Y - 1024) / 1024f;
                    var sidealpha = Math.Abs(o.Position.X - pos.X) / 4096f;
                    if (sidealpha > alpha)
                    {
                        alpha = sidealpha;
                    }
                    alpha = Math.Clamp(alpha, 0.5f, 1f);

                    o.SetColor(new Color(1f, 1f, 1f, alpha));
                    o.Render();
                    o.SetColor(Color.White);
                }
Example #8
0
        void setScreen()
        {
            if (Settings.Fullscreen && !Program.NoFullscreen)
            {
                WindowBorder = WindowBorder.Hidden;
                WindowState  = WindowState.Fullscreen;

                ClientRectangle = new Box2i(0, 0, ScreenInfo.ScreenWidth, ScreenInfo.ScreenHeight);
            }
            else
            {
                WindowBorder = WindowBorder.Fixed;
                WindowState  = WindowState.Normal;
                var offsetX = (ScreenInfo.ScreenWidth - Settings.Width) / 2;
                var offsetY = (ScreenInfo.ScreenHeight - Settings.Height) / 2;
                ClientRectangle = new Box2i(offsetX, offsetY + 1, Settings.Width + offsetX, Settings.Height + offsetY);
            }

            RenderFrequency   = Settings.FrameLimiter == 0 ? ScreenInfo.ScreenRefreshRate : Settings.FrameLimiter;
            WindowInfo.Width  = ClientRectangle.Size.X;
            WindowInfo.Height = ClientRectangle.Size.Y;

            MasterRenderer.UpdateViewport();
        }