Bugfix in Main and LoadingScreen. LoadingScreen will now be displayed properly.

This commit is contained in:
Jan Philipp Timme 2014-11-28 19:55:41 +01:00
parent d38f016ee0
commit fc66c15cd6
2 changed files with 34 additions and 25 deletions

View File

@ -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);
}
}

View File

@ -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));
}
}