59 lines
1.1 KiB
Java
59 lines
1.1 KiB
Java
package projectzombie.mainloop;
|
|
|
|
import mainloop.event.IMainloopEvent;
|
|
import mainloop.task.IMainloopTask;
|
|
import projectzombie.Main;
|
|
|
|
public class MainloopEventHandler implements IMainloopEvent, IMainloopTask
|
|
{
|
|
public static final MainloopEventHandler MAINLOOP_EVENT_HANDLER = new MainloopEventHandler();
|
|
|
|
private long max_mspf = 1000/60;
|
|
public long mspf = max_mspf;
|
|
|
|
@Override
|
|
public void onClose()
|
|
{
|
|
// Close OpenAL
|
|
System.out.println("Closed OpenAL");
|
|
Main.audio.destroy();
|
|
|
|
// Send some info to stdout
|
|
System.out.println("Mainloop closed normally");
|
|
}
|
|
|
|
@Override
|
|
public void onEarly() {
|
|
mspf -= 1;
|
|
if(mspf < max_mspf) mspf = max_mspf;
|
|
}
|
|
|
|
@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();
|
|
}
|
|
|
|
}
|