diff --git a/src/dothack/DotHack.java b/src/dothack/DotHack.java index 50a3424..95fafb7 100644 --- a/src/dothack/DotHack.java +++ b/src/dothack/DotHack.java @@ -2,16 +2,25 @@ package dothack; import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; +import sillysagiri.Sagiri; + public class DotHack extends MIDlet implements Runnable { public DotHackC game; + public Sagiri sagiri; private Display _display; - + public Thread thread; + public void startApp() { Global.app = this; + sagiri = new Sagiri(); game = new DotHackC(this); - + _display = Display.getDisplay(this); _display.setCurrent(game); + + thread = new Thread(this); + thread.setPriority(Thread.MAX_PRIORITY); + thread.start(); } public void pauseApp() {} @@ -19,6 +28,17 @@ public class DotHack extends MIDlet implements Runnable { public void destroyApp(boolean paramBoolean) {} public void run() { - + while (true) { + try + { + game.repaint(); + game.serviceRepaints(); + Thread.sleep(1000/sagiri.fps); + } + catch (Exception e) + { + // TODO: catch any unhandled exception here + } + } } } \ No newline at end of file diff --git a/src/dothack/DotHackC.java b/src/dothack/DotHackC.java index acfc3ca..af72e44 100644 --- a/src/dothack/DotHackC.java +++ b/src/dothack/DotHackC.java @@ -150,30 +150,7 @@ public class DotHackC extends Canvas { thread = new Thread(this); 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) { try { if (soundS) { diff --git a/src/sillysagiri/Sagiri.java b/src/sillysagiri/Sagiri.java index 7797ae5..2f800b0 100644 --- a/src/sillysagiri/Sagiri.java +++ b/src/sillysagiri/Sagiri.java @@ -18,7 +18,7 @@ public class Sagiri private Scene _scene_current; private long _time_begin; private long _time_delta; - + public Sagiri() { _instance = this; @@ -35,5 +35,17 @@ public class Sagiri _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; } }