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:
parent
f98edf8fc8
commit
2bc45bec0a
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -113,14 +113,16 @@ public class Splash extends BasicGameState {
|
|||
if (!init) {
|
||||
init = true;
|
||||
|
||||
// load other resources in a new thread
|
||||
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() {
|
||||
// application restart: everything already loaded
|
||||
if (OsuGroupList.get().size() < 1) {
|
||||
File beatmapDir = Options.getBeatmapDir();
|
||||
|
||||
// unpack all OSZ archives
|
||||
|
@ -131,13 +133,13 @@ public class Splash extends BasicGameState {
|
|||
|
||||
// load sounds
|
||||
SoundController.init();
|
||||
}
|
||||
|
||||
finished = true;
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
// fade in logo
|
||||
Image logo = GameImage.MENU_LOGO.getImage();
|
||||
|
|
Loading…
Reference in New Issue
Block a user