Follow-up to f98edf8: better checks for application restart.

- Fixes resource reloading when OsuGroupList is empty (i.e. if user has no beatmaps installed).
- OsuGroupList is no longer initialized with a class instance; OsuGroupList.create() is called by OsuParser.
- Also clear 'lastOsu' field in MusicController.reset().  Fixes theme song not playing on restart if it was the last track played (i.e. if no beatmaps installed).
- Call MusicController.reset() last so that more garbage is collected.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-01-20 19:24:59 -05:00
parent f98edf8fc8
commit 2bc45bec0a
5 changed files with 32 additions and 22 deletions

View File

@ -91,15 +91,15 @@ public class Container extends AppGameContainer {
// close server socket // close server socket
Opsu.closeSocket(); Opsu.closeSocket();
// prevent loading tracks from re-initializing OpenAL
MusicController.reset();
// destroy images // destroy images
InternalTextureLoader.get().clear(); InternalTextureLoader.get().clear();
// reset image references // reset image references
GameImage.clearReferences(); GameImage.clearReferences();
OsuFile.resetImageCache(); OsuFile.resetImageCache();
// prevent loading tracks from re-initializing OpenAL
MusicController.reset();
} }
@Override @Override

View File

@ -33,7 +33,7 @@ public class OsuGroupList {
/** /**
* Song group structure (each group contains of an ArrayList of OsuFiles). * Song group structure (each group contains of an ArrayList of OsuFiles).
*/ */
private static OsuGroupList list = new OsuGroupList(); private static OsuGroupList list;
/** /**
* Search pattern for conditional expressions. * Search pattern for conditional expressions.
@ -69,6 +69,11 @@ public class OsuGroupList {
*/ */
private String lastQuery = ""; private String lastQuery = "";
/**
* Creates a new instance of this class (overwriting any previous instance).
*/
public static void create() { list = new OsuGroupList(); }
/** /**
* Returns the single instance of this class. * Returns the single instance of this class.
*/ */

View File

@ -67,6 +67,9 @@ public class OsuParser {
* @param height the container height * @param height the container height
*/ */
public static void parseAllFiles(File root, int width, int height) { public static void parseAllFiles(File root, int width, int height) {
// create a new OsuGroupList
OsuGroupList.create();
// progress tracking // progress tracking
File[] folders = root.listFiles(); File[] folders = root.listFiles();
currentDirectoryIndex = 0; currentDirectoryIndex = 0;

View File

@ -83,9 +83,7 @@ public class MusicController {
* Plays an audio file at the preview position. * Plays an audio file at the preview position.
*/ */
public static void play(final OsuFile osu, final boolean loop) { public static void play(final OsuFile osu, final boolean loop) {
boolean play = (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename)); if (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename)) {
lastOsu = osu;
if (play) {
reset(); reset();
System.gc(); System.gc();
@ -114,6 +112,7 @@ public class MusicController {
break; break;
} }
} }
lastOsu = osu;
} }
/** /**
@ -335,6 +334,7 @@ public class MusicController {
} }
// reset state // reset state
lastOsu = null;
themePlaying = false; themePlaying = false;
pauseTime = 0f; pauseTime = 0f;
trackDimmed = false; trackDimmed = false;

View File

@ -113,14 +113,16 @@ public class Splash extends BasicGameState {
if (!init) { if (!init) {
init = true; init = true;
// load other resources in a new thread if (OsuGroupList.get() != null) {
final int width = container.getWidth(); // resources already loaded (from application restart)
final int height = container.getHeight(); finished = true;
thread = new Thread() { } else {
@Override // load resources in a new thread
public void run() { final int width = container.getWidth();
// application restart: everything already loaded final int height = container.getHeight();
if (OsuGroupList.get().size() < 1) { thread = new Thread() {
@Override
public void run() {
File beatmapDir = Options.getBeatmapDir(); File beatmapDir = Options.getBeatmapDir();
// unpack all OSZ archives // unpack all OSZ archives
@ -131,12 +133,12 @@ public class Splash extends BasicGameState {
// load sounds // load sounds
SoundController.init(); SoundController.init();
}
finished = true; finished = true;
} }
}; };
thread.start(); thread.start();
}
} }
// fade in logo // fade in logo