Skip to content

creating Sleep() method that doesn't lock up window? #103

@Shadowblitz16

Description

@Shadowblitz16

I can't really post this on the love forums since this has to do with handling the loop manually however
I was wanting to make a Sleep method that doesn't lock up the window and using it for setting fps in the while loop.

        public bool IsRunning()
        {
            var delta = Timer.GetDelta() == 0 ? 1 : Timer.GetDelta();
            Sleep(1.0/ delta);
            return running;
        }

        public void Sleep(double time)
        {
            double timer = time;
            if (timer > 0)
            {
                while (timer > 0) //this needs to be accurate 
                {
                    Boot.SystemStep(this); //process events
                    var delta = 1.0f / Timer.GetDelta() == 0 ? 1 : Timer.GetDelta();
                    timer -= delta; //subtract delta from timer
                }
                Console.WriteLine("Sleep done!");
            }
            else
            {
                Boot.SystemStep(this);
            }
        }
        public static void Main()
        {
            uint step = 0;
            Sys.Init();
            Sys.SetFps(1);
            
            while(Sys.IsRunning())
            {
                //Console.WriteLine("frame: " + step);
                step++;
            }
        }

however I am having trouble getting it to work. the idea is to lock up the process based on a double seconds parameter while processing events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions