Call System.gc() on track changes and game resets.
This causes a noticeable drop in memory usage in most cases. Also renamed the "crash" popup since the game doesn't necessarily crash. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -752,19 +752,22 @@ public class Game extends BasicGameState {
|
||||
|
||||
// restart the game
|
||||
if (restart != Restart.FALSE) {
|
||||
// new game
|
||||
if (restart == Restart.NEW) {
|
||||
// new game
|
||||
loadImages();
|
||||
setMapModifiers();
|
||||
retries = 0;
|
||||
} else
|
||||
} else {
|
||||
// retry
|
||||
retries++;
|
||||
}
|
||||
|
||||
// reset game data
|
||||
resetGameData();
|
||||
MusicController.setPosition(0);
|
||||
MusicController.pause();
|
||||
|
||||
// initialize object maps
|
||||
circles = new HashMap<Integer, Circle>();
|
||||
sliders = new HashMap<Integer, Slider>();
|
||||
spinners = new HashMap<Integer, Spinner>();
|
||||
|
||||
for (int i = 0; i < osu.objects.length; i++) {
|
||||
OsuHitObject hitObject = osu.objects[i];
|
||||
|
||||
@@ -783,28 +786,6 @@ public class Game extends BasicGameState {
|
||||
}
|
||||
}
|
||||
|
||||
// reset data
|
||||
MusicController.setPosition(0);
|
||||
MusicController.pause();
|
||||
score.clear();
|
||||
objectIndex = 0;
|
||||
breakIndex = 0;
|
||||
breakTime = 0;
|
||||
breakSound = false;
|
||||
timingPointIndex = 0;
|
||||
beatLengthBase = beatLength = 1;
|
||||
pauseTime = -1;
|
||||
pausedMouseX = -1;
|
||||
pausedMouseY = -1;
|
||||
countdownReadySound = false;
|
||||
countdown3Sound = false;
|
||||
countdown1Sound = false;
|
||||
countdown2Sound = false;
|
||||
countdownGoSound = false;
|
||||
checkpointLoaded = false;
|
||||
deaths = 0;
|
||||
deathTime = -1;
|
||||
|
||||
// load the first timingPoint
|
||||
if (!osu.timingPoints.isEmpty()) {
|
||||
OsuTimingPoint timingPoint = osu.timingPoints.get(0);
|
||||
@@ -829,6 +810,35 @@ public class Game extends BasicGameState {
|
||||
// container.setMouseGrabbed(false);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Resets all game data and structures.
|
||||
*/
|
||||
public void resetGameData() {
|
||||
circles = new HashMap<Integer, Circle>();
|
||||
sliders = new HashMap<Integer, Slider>();
|
||||
spinners = new HashMap<Integer, Spinner>();
|
||||
score.clear();
|
||||
objectIndex = 0;
|
||||
breakIndex = 0;
|
||||
breakTime = 0;
|
||||
breakSound = false;
|
||||
timingPointIndex = 0;
|
||||
beatLengthBase = beatLength = 1;
|
||||
pauseTime = -1;
|
||||
pausedMouseX = -1;
|
||||
pausedMouseY = -1;
|
||||
countdownReadySound = false;
|
||||
countdown3Sound = false;
|
||||
countdown1Sound = false;
|
||||
countdown2Sound = false;
|
||||
countdownGoSound = false;
|
||||
checkpointLoaded = false;
|
||||
deaths = 0;
|
||||
deathTime = -1;
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the beginning of a track.
|
||||
* @return true if skipped, false otherwise
|
||||
|
||||
@@ -130,6 +130,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||
MusicController.stop();
|
||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
gameState.resetGameData();
|
||||
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
} else {
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
@@ -173,6 +174,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||
MusicController.pause(); // lose state
|
||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
gameState.resetGameData();
|
||||
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,11 +174,13 @@ public class GameRanking extends BasicGameState {
|
||||
} else if (exitButton.contains(x, y)) {
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset();
|
||||
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
|
||||
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
} else if (Utils.getBackButton().contains(x, y)) {
|
||||
MusicController.pause();
|
||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||
SoundController.playSound(SoundEffect.MENUBACK);
|
||||
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
|
||||
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user