|
From: <ka...@us...> - 2009-05-23 09:37:12
|
Revision: 3214
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3214&view=rev
Author: kappa1
Date: 2009-05-23 09:37:10 +0000 (Sat, 23 May 2009)
Log Message:
-----------
A bit of clean up, code refactoring and commenting to GearsApplet test.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-05-23 09:09:28 UTC (rev 3213)
+++ trunk/LWJGL/src/java/org/lwjgl/test/applet/GearsApplet.java 2009-05-23 09:37:10 UTC (rev 3214)
@@ -14,9 +14,13 @@
public class GearsApplet extends Applet {
+ /** The Canvas where the LWJGL Display is added */
Canvas display_parent;
+
+ /** Thread which runs the main game loop */
Thread gameThread;
+ /** is the game loop running */
boolean running = false;
private float view_rotx = 20.0f;
@@ -30,30 +34,12 @@
boolean keyDown = false;
- public void destroy() {
- remove(display_parent);
- super.destroy();
- System.out.println("Clear up");
- }
- private void destroyLWJGL() {
- stopApplet();
- try {
- gameThread.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- public void start() {
-
- }
-
- public void stop() {
-
- }
-
- public void startApplet() {
+ /**
+ * Once the Canvas is created its add notify method will call this method to
+ * start the LWJGL Display and game loop in another thread.
+ */
+ public void startLWJGL() {
gameThread = new Thread() {
public void run() {
running = true;
@@ -71,11 +57,44 @@
};
gameThread.start();
}
-
- public void stopApplet() {
+
+
+ /**
+ * Tell game loop to stop running, after which the LWJGL Display will be destoryed.
+ * The main thread will wait for the Display.destroy() to complete
+ */
+ private void stopLWJGL() {
running = false;
+ try {
+ gameThread.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
+ public void start() {
+
+ }
+
+ public void stop() {
+
+ }
+
+ /**
+ * Applet Destroy method will remove the canvas, before canvas is destroyed it will notify
+ * stopLWJGL() to stop main game loop and to destroy the Display
+ */
+ public void destroy() {
+ remove(display_parent);
+ super.destroy();
+ System.out.println("Clear up");
+ }
+
+ /**
+ * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
+ * in another thread. It will also stop the game loop and destroy the display on canvas removal when
+ * applet is destroyed.
+ */
public void init() {
setLayout(new BorderLayout());
try {
@@ -85,7 +104,7 @@
startLWJGL();
}
public final void removeNotify() {
- destroyLWJGL();
+ stopLWJGL();
super.removeNotify();
}
};
@@ -231,7 +250,7 @@
GL11.glTranslatef(0.0f, 0.0f, -40.0f);
} catch (Exception e) {
System.err.println(e);
- stopApplet();
+ running = false;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|