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
Opsu.closeSocket();
// prevent loading tracks from re-initializing OpenAL
MusicController.reset();
// destroy images
InternalTextureLoader.get().clear();
// reset image references
GameImage.clearReferences();
OsuFile.resetImageCache();
// prevent loading tracks from re-initializing OpenAL
MusicController.reset();
}
@Override

View File

@ -33,7 +33,7 @@ public class OsuGroupList {
/**
* 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.
@ -69,6 +69,11 @@ public class OsuGroupList {
*/
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.
*/

View File

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

View File

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

View File

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