move main loop into midlet class
This commit is contained in:
parent
59c57aec1a
commit
3a7c10a53c
@ -2,16 +2,25 @@ package dothack;
|
|||||||
import javax.microedition.lcdui.Display;
|
import javax.microedition.lcdui.Display;
|
||||||
import javax.microedition.midlet.MIDlet;
|
import javax.microedition.midlet.MIDlet;
|
||||||
|
|
||||||
|
import sillysagiri.Sagiri;
|
||||||
|
|
||||||
public class DotHack extends MIDlet implements Runnable {
|
public class DotHack extends MIDlet implements Runnable {
|
||||||
public DotHackC game;
|
public DotHackC game;
|
||||||
|
public Sagiri sagiri;
|
||||||
private Display _display;
|
private Display _display;
|
||||||
|
public Thread thread;
|
||||||
|
|
||||||
public void startApp() {
|
public void startApp() {
|
||||||
Global.app = this;
|
Global.app = this;
|
||||||
|
sagiri = new Sagiri();
|
||||||
game = new DotHackC(this);
|
game = new DotHackC(this);
|
||||||
|
|
||||||
_display = Display.getDisplay(this);
|
_display = Display.getDisplay(this);
|
||||||
_display.setCurrent(game);
|
_display.setCurrent(game);
|
||||||
|
|
||||||
|
thread = new Thread(this);
|
||||||
|
thread.setPriority(Thread.MAX_PRIORITY);
|
||||||
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pauseApp() {}
|
public void pauseApp() {}
|
||||||
@ -19,6 +28,17 @@ public class DotHack extends MIDlet implements Runnable {
|
|||||||
public void destroyApp(boolean paramBoolean) {}
|
public void destroyApp(boolean paramBoolean) {}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try
|
||||||
|
{
|
||||||
|
game.repaint();
|
||||||
|
game.serviceRepaints();
|
||||||
|
Thread.sleep(1000/sagiri.fps);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// TODO: catch any unhandled exception here
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -151,29 +151,6 @@ public class DotHackC extends Canvas {
|
|||||||
this.thread.start();
|
this.thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
|
||||||
while (true) {
|
|
||||||
if (_scene_current != null) _scene_current.Update();
|
|
||||||
repaint();
|
|
||||||
serviceRepaints();
|
|
||||||
try {
|
|
||||||
Thread.sleep(80L);
|
|
||||||
} catch (Exception exception) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Scene Get_Scene() { return _scene_current; }
|
|
||||||
public void Set_Scene(Scene scene)
|
|
||||||
{
|
|
||||||
if (_scene_current != null)
|
|
||||||
{
|
|
||||||
_scene_current.Destroy();
|
|
||||||
_scene_current = null;
|
|
||||||
System.gc();
|
|
||||||
}
|
|
||||||
_scene_current = scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void soundPlay(int id) {
|
public void soundPlay(int id) {
|
||||||
try {
|
try {
|
||||||
if (soundS) {
|
if (soundS) {
|
||||||
|
@ -35,5 +35,17 @@ public class Sagiri
|
|||||||
_scene_current.Update(_time_delta = System.currentTimeMillis() - _time_begin, g);
|
_scene_current.Update(_time_delta = System.currentTimeMillis() - _time_begin, g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Scene Get_Scene() { return _scene_current; }
|
||||||
|
public void Set_Scene(Scene scene)
|
||||||
|
{
|
||||||
|
if (_scene_current != null)
|
||||||
|
{
|
||||||
|
_scene_current.Destroy();
|
||||||
|
_scene_current = null;
|
||||||
|
System.gc();
|
||||||
|
}
|
||||||
|
_scene_current = scene;
|
||||||
|
}
|
||||||
|
|
||||||
public final long GetFrameTime() { return _time_delta; }
|
public final long GetFrameTime() { return _time_delta; }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user