53 lines
972 B
Java
53 lines
972 B
Java
package shootergame.mainloop;
|
|
|
|
import mainloop.event.IMainloopEvent;
|
|
import mainloop.task.IMainloopTask;
|
|
import shootergame.Main;
|
|
|
|
public class MainloopEventHandler implements IMainloopEvent, IMainloopTask
|
|
{
|
|
public static final MainloopEventHandler MAINLOOP_EVENT_HANDLER = new MainloopEventHandler();
|
|
|
|
public long mspf = 1000/60;
|
|
private long max_mspf = 1;
|
|
|
|
@Override
|
|
public void onClose() {
|
|
System.out.println("Mainloop closed normally");
|
|
}
|
|
|
|
@Override
|
|
public void onEarly() {
|
|
mspf -= 1;
|
|
if(mspf < max_mspf) mspf = 1;
|
|
}
|
|
|
|
@Override
|
|
public void onLate() {
|
|
mspf += 1;
|
|
}
|
|
|
|
@Override
|
|
public void onStart() {
|
|
System.out.println("Mainloop started");
|
|
}
|
|
|
|
@Override
|
|
public boolean MainLoopDelay(long millis) {
|
|
return millis > 1;
|
|
}
|
|
|
|
@Override
|
|
public boolean MainLoopRepeat() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void MainLoopUpdate()
|
|
{
|
|
// Stop the mainloop if the window should close
|
|
if(Main.window.shouldClose()) Main.mainloop.stop();
|
|
}
|
|
|
|
}
|