Love2dCS
Love2dCS copied to clipboard
creating Sleep() method that doesn't lock up window?
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.
OK, I have checked your code, I think you have done it.
I think you just want try to call the Update
in a fixed delat of time.
I'm confused about what you expect. If you expect me to add this method to the Boot/Timer class, i will not to do that, because people can do this just like what you done it. :embarrassment:
no I was just wondering how to do it I can't get it to work