From fc66c15cd66a85bb87c3a1699de83cdd5b1c17cb Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 28 Nov 2014 19:55:41 +0100 Subject: [PATCH] Bugfix in Main and LoadingScreen. LoadingScreen will now be displayed properly. --- src/de/teamteamteam/spacescooter/Main.java | 52 +++++++++++-------- .../spacescooter/screen/LoadingScreen.java | 7 ++- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/Main.java b/src/de/teamteamteam/spacescooter/Main.java index cb66be5..9afdb6e 100644 --- a/src/de/teamteamteam/spacescooter/Main.java +++ b/src/de/teamteamteam/spacescooter/Main.java @@ -17,45 +17,47 @@ public class Main { /** * Main entry point of the game. - * "... for i am the Alpha and the Omega." - God + * + * "... for i am the Alpha and the Omega." + * - God, a long time ago. * * @param args Command line arguments. */ public static void main(String[] args) { - //Initialize the GameFrame properly within the AWT EventQueue + final GraphicsSettings gs = new GraphicsSettings(); // Get settings + + // Initialize SuperScreen and add to GameFrame, so we can call doPaint() + // on it. + final SuperScreen superScreen = new SuperScreen(null); + + // Set up the LoadingScreen + final LoadingScreen loadingScreen = new LoadingScreen(superScreen); + superScreen.setOverlay(loadingScreen); + + // Initialize the GameFrame properly within the AWT EventQueue try { EventQueue.invokeAndWait(new Runnable() { public void run() { - GraphicsSettings gs = new GraphicsSettings(); //Get settings - - //Instantiate the GameFrame + // Instantiate the GameFrame final GameFrame gameFrame = new GameFrame(); - - //Initialize SuperScreen and add to GameFrame, so we can call doPaint() on it. - final SuperScreen superScreen = new SuperScreen(null); + + // Set the SuperScreen gameFrame.setSuperScreen(superScreen); - //Initialize the gameFrame and trigger a first draw. + // Initialize the gameFrame and trigger a first draw. gameFrame.init(); - gameFrame.draw(); //Draw nothing for the first time. - - //Initialize GameThread + gameFrame.draw(); // Draw nothing for the first time. + + // Initialize GameThread PaintThread paintThread = new PaintThread(gameFrame); - paintThread.setHz(gs.getRefreshRate()); //This may be set depending on the system graphic settings. + paintThread.setHz(gs.getRefreshRate()); // Use refresh rate from system graphics configuration. paintThread.start(); - - //Initialize UpdateThread + + // Initialize UpdateThread UpdateThread updateThread = new UpdateThread(); updateThread.setSuperScreen(superScreen); - updateThread.setHz(100); //This shall remain constant across all systems. + updateThread.setHz(100); // This is constant across all systems. updateThread.start(); - - //Set up the LoadingScreen - LoadingScreen loadingScreen = new LoadingScreen(superScreen); - superScreen.setOverlay(loadingScreen); - - //Start loading and everything will follow up. - Loader.load(loadingScreen); } }); } catch (InvocationTargetException e) { @@ -63,5 +65,9 @@ public class Main { } catch (InterruptedException e) { e.printStackTrace(); } + + // Finally start loading and everything will follow up. + // This has to happen after the AWT-Eventqueue is done initializing everything. + Loader.load(loadingScreen); } } diff --git a/src/de/teamteamteam/spacescooter/screen/LoadingScreen.java b/src/de/teamteamteam/spacescooter/screen/LoadingScreen.java index 4c97f78..0cc67f1 100644 --- a/src/de/teamteamteam/spacescooter/screen/LoadingScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/LoadingScreen.java @@ -15,9 +15,11 @@ public class LoadingScreen extends Screen { private int currentProcessed; private int totalProcessable; + private boolean initialized; public LoadingScreen(Screen parent) { super(parent); + this.initialized = false; this.currentProcessed = 0; this.totalProcessable = 1; //sane default } @@ -25,6 +27,7 @@ public class LoadingScreen extends Screen { public void initialize(int currentProcessed, int totalProcessable) { this.currentProcessed = currentProcessed; this.totalProcessable = totalProcessable; + this.initialized = true; } public void increaseCurrentProcessed() { @@ -32,7 +35,7 @@ public class LoadingScreen extends Screen { } public int getProgress() { - return (int) Math.round((100.0 * this.currentProcessed) / this.totalProcessable); + return (int) Math.floor((100.0 * this.currentProcessed) / this.totalProcessable); } @Override @@ -47,7 +50,7 @@ public class LoadingScreen extends Screen { @Override protected void update() { - if(this.getProgress() == 100) { + if(this.initialized == true && this.getProgress() == 100) { this.parent.setOverlay(new MainMenuScreen(this.parent)); } }