endlesstravel / Love2dCS

C# Wrapper for LÖVE, a 2d game engine
MIT License
166 stars 14 forks source link

setting window size should apply both width and height immediately #102

Open Shadowblitz16 opened 4 years ago

Shadowblitz16 commented 4 years ago

setting window size should apply both width and height immediately disregarding fps. right now it slowly applys width and height one at a time and it takes about 2 seconds to do so.

using Love;
using System;

namespace PureCore
{
    public static class Sys
    {

        static SysRunner Scene { get; set; }
        public static void Init()
        {
            Scene = new SysRunner();
        }

        public static bool IsRunning()
        {
            return Scene.IsRunning();
        }

        public static void SetName(string name)
        {
            Scene.Name = name;
        }
        public static void SetFps (uint    fps)
        {
            Scene.Fps = fps;
        }
        public static void SetW   (uint      w)
        {
            Scene.W = w;
        }
        public static void SetH   (uint      h)
        {
            Scene.H = h;
        }
    }

    internal class SysRunner : Scene
    {
        bool running = true;
        uint fps;
        public string  Name
        {
            get
            {
                return Window.GetTitle();
            }
            set
            {
                Window.SetTitle(value);
            }
        }
        public uint    Fps
        {
            get
            {
                return (uint)(Timer.GetFPS() * fps);
            }
            set
            {
                fps = value;
                Timer.EnableLimitMaxFPS(1f / fps);
            }
        }
        public uint    W
        {
            get
            {
                Window.GetMode(out int w, out int _);
                return (uint)w;
            }
            set
            {
                Window.SetMode((int)value, (int)H);
            }
        }
        public uint    H
        {
            get
            {
                Window.GetMode(out _, out int h);
                return (uint)h;
            }
            set
            {
                Window.SetMode((int)W, (int)value);
            }
        }

        public SysRunner()
        {
            Boot.Init(new BootConfig());
            Name = "Untitled game";
            Fps  = 60;
            W    = 256;
            H    = 240;
        }

        public bool IsRunning()
        {
            Boot.SystemStep(this);
            Timer.Sleep(1/Timer.GetDelta());
            return running;
        }

        public override bool Quit()
        {
            running = false; // mark it as true to break loop
            return false; // return true will lead Application.Exit(); 
        }
    }
}
endlesstravel commented 4 years ago

I agree with you that the function of changing the window size brought by LÖVE's slow, which you can respond to the official forum.

Shadowblitz16 commented 4 years ago

do you have a link to a topic where I can complain?