diff --git a/src/de/teamteamteam/spacescooter/sound/SoundSystem.java b/src/de/teamteamteam/spacescooter/sound/SoundSystem.java index 5b43f08..792f500 100644 --- a/src/de/teamteamteam/spacescooter/sound/SoundSystem.java +++ b/src/de/teamteamteam/spacescooter/sound/SoundSystem.java @@ -128,7 +128,7 @@ public class SoundSystem { public static void playSound(String filename) { - SoundSystem.playFromAudioInputStream(Loader.getAudioInputStreamByFilename(filename)); + SoundSystem.playFromAudioInputStream(Loader.getSoundURLByFilename(filename)); } diff --git a/src/de/teamteamteam/spacescooter/thread/TimedThread.java b/src/de/teamteamteam/spacescooter/thread/TimedThread.java index 2f922d5..6ac81b7 100644 --- a/src/de/teamteamteam/spacescooter/thread/TimedThread.java +++ b/src/de/teamteamteam/spacescooter/thread/TimedThread.java @@ -1,5 +1,10 @@ package de.teamteamteam.spacescooter.thread; +/** + * Since things like drawing the next image or triggering the next game tick + * need to happen in time, this TimedThread allows more precise timing + * combined with a nap for the cpu in case there is enough time for it. + */ public abstract class TimedThread extends Thread { private long workInterval; diff --git a/src/de/teamteamteam/spacescooter/thread/UpdateThread.java b/src/de/teamteamteam/spacescooter/thread/UpdateThread.java index cbd492f..b2e579d 100644 --- a/src/de/teamteamteam/spacescooter/thread/UpdateThread.java +++ b/src/de/teamteamteam/spacescooter/thread/UpdateThread.java @@ -2,18 +2,34 @@ package de.teamteamteam.spacescooter.thread; import de.teamteamteam.spacescooter.screen.Screen; +/** + * This UpdateThread triggers the hierarchical Screen structure, + * resulting in constant game ticks. + */ public class UpdateThread extends TimedThread { - + + /** + * The SuperScreen instance to trigger. + */ private Screen superScreen; + /** + * Constructor. Sets the ThreadName. + */ public UpdateThread() { this.setName("UpdateThread"); } + /** + * Setter for the SuperScreen. + */ public void setSuperScreen(Screen superScreen) { this.superScreen = superScreen; } + /** + * On every tick, hit the SuperScreens doUpdate() method. + */ public void work() { this.superScreen.doUpdate(); } diff --git a/src/de/teamteamteam/spacescooter/utility/CodeEnvironment.java b/src/de/teamteamteam/spacescooter/utility/CodeEnvironment.java index 4100bd7..2464696 100644 --- a/src/de/teamteamteam/spacescooter/utility/CodeEnvironment.java +++ b/src/de/teamteamteam/spacescooter/utility/CodeEnvironment.java @@ -9,6 +9,12 @@ import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +/** + * This helper is used by the Loader to get a list of files of the whole Code + * and determine specific runtime configurations. + * Since there are some differences between OS and jar/non-jar environments, + * this helper makes sure, everything still works. + */ public class CodeEnvironment { /** diff --git a/src/de/teamteamteam/spacescooter/utility/GameConfig.java b/src/de/teamteamteam/spacescooter/utility/GameConfig.java index 8cb1245..6ef0186 100644 --- a/src/de/teamteamteam/spacescooter/utility/GameConfig.java +++ b/src/de/teamteamteam/spacescooter/utility/GameConfig.java @@ -1,10 +1,23 @@ package de.teamteamteam.spacescooter.utility; +/** + * This static class contains important game configuration. + */ public class GameConfig { + /** + * Whether debug output (and more) is enabled or disabled. + */ public static boolean DEBUG = false; + /** + * Width of GameWindow. + */ public static int windowWidth; + + /** + * Height of GameWindow. + */ public static int windowHeight; diff --git a/src/de/teamteamteam/spacescooter/utility/GraphicsSettings.java b/src/de/teamteamteam/spacescooter/utility/GraphicsSettings.java index 86805b7..9c9f1a1 100644 --- a/src/de/teamteamteam/spacescooter/utility/GraphicsSettings.java +++ b/src/de/teamteamteam/spacescooter/utility/GraphicsSettings.java @@ -4,39 +4,76 @@ import java.awt.DisplayMode; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; +/** + * GraphicsSettings allows to fetch the current graphical settings in order + * to determine a sane refresh rate and the current screen resolution. + */ public class GraphicsSettings { + /** + * Height of the primary screen. + */ private int height; + + /** + * Width of the primary screen. + */ private int width; + + /** + * The set refreshRate in Hz. + */ private int refreshRate; + + /** + * Available bitDepth. In case you get -1, do not worry. :-) + */ private int bitDepth; + + /** + * Constructor. Just retrieve the settings once. + */ public GraphicsSettings() { this.retrieveSettings(); } + /** + * Returns the refresh rate to use. + */ public int getRefreshRate() { return this.refreshRate; } + /** + * This method fetches the current settings and refreshes the GraphicsSettings attributes. + * In case the current refresh rate could not be detected, it uses 60Hz as a default value. + */ public void retrieveSettings() { + if(GameConfig.DEBUG) { + System.out.println("OS: " + System.getProperty("os.name")); + } GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); - + int refreshRate; + //iterate over all available screen devices for(int i=0; i < gs.length; i++) { DisplayMode dm = gs[i].getDisplayMode(); - this.refreshRate = dm.getRefreshRate(); - if(this.refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) { + refreshRate = dm.getRefreshRate(); + //handle unknown refresh rate + if(refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) { System.err.println("[!]Display Mode " + i + ": Unknown refresh rate!"); - this.refreshRate = 60; //sane default value. :/ + refreshRate = 60; //sane default value. :/ + } + //only store the values of the primary screen. + if(i == 0) { + this.refreshRate = refreshRate; + this.bitDepth = dm.getBitDepth(); + this.height = dm.getHeight(); + this.width = dm.getWidth(); } - this.bitDepth = dm.getBitDepth(); - this.height = dm.getHeight(); - this.width = dm.getWidth(); - if(GameConfig.DEBUG) { System.out.println("Display Mode " + i + ": " + this.width + "x" + this.height+ "@" + this.refreshRate + "Hz, " + this.bitDepth + " bit"); - System.out.println("OS: " + System.getProperty("os.name")); } } } diff --git a/src/de/teamteamteam/spacescooter/utility/Loader.java b/src/de/teamteamteam/spacescooter/utility/Loader.java index ded2c88..114d002 100644 --- a/src/de/teamteamteam/spacescooter/utility/Loader.java +++ b/src/de/teamteamteam/spacescooter/utility/Loader.java @@ -29,6 +29,9 @@ public class Loader { */ private static Hashtable sounds; + /** + * Initialize the HashTables on load. + */ static { Loader.images = new Hashtable(); Loader.sounds = new Hashtable(); @@ -59,9 +62,9 @@ public class Loader { } /** - * Return the loaded AudioInputStream by its relative filename. + * Return the loaded sound URL by its relative filename. */ - public static URL getAudioInputStreamByFilename(String filename) { + public static URL getSoundURLByFilename(String filename) { if(CodeEnvironment.isJar()) { return Loader.sounds.get(filename); } else { @@ -88,7 +91,7 @@ public class Loader { if(e.endsWith(".wav")) { if(GameConfig.DEBUG) System.out.println("Creating AudioInputStream for: " + e); - Loader.addAudioInputStreamByFilename(e); + Loader.addSoundURLByFilename(e); } loadingScreen.increaseCurrentProcessed(); } @@ -111,7 +114,7 @@ public class Loader { /** * Load an AudioInputStream by relative filename. */ - private static void addAudioInputStreamByFilename(String filename) { + private static void addSoundURLByFilename(String filename) { try { URL soundURL = Loader.class.getClassLoader().getResource(filename); //make sure the sound is in a valid AudioFormat