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:
parent
9db9c2f3ad
commit
516e6280c7
|
@ -109,7 +109,7 @@ public class Opsu extends StateBasedGame {
|
|||
public void uncaughtException(Thread t, Throwable e) {
|
||||
if (!(e instanceof ThreadDeath)) { // TODO: see MusicController
|
||||
Log.error("** Uncaught Exception! **", e);
|
||||
openCrashPopup();
|
||||
openErrorPopup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -196,16 +196,16 @@ public class Opsu extends StateBasedGame {
|
|||
}
|
||||
|
||||
/**
|
||||
* Opens the crash popup.
|
||||
* Opens the error popup.
|
||||
*/
|
||||
private static void openCrashPopup() {
|
||||
private static void openErrorPopup() {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
if (Desktop.isDesktopSupported()) {
|
||||
// try to open the log file and/or issues webpage
|
||||
String[] options = {"Send Report", "View Error Log", "Close"};
|
||||
int n = JOptionPane.showOptionDialog(null,
|
||||
"opsu! has crashed. Please report this!",
|
||||
"opsu! has encountered an error.\nPlease report this!",
|
||||
"Error", JOptionPane.DEFAULT_OPTION,
|
||||
JOptionPane.ERROR_MESSAGE, null, options,
|
||||
options[2]);
|
||||
|
@ -218,7 +218,7 @@ public class Opsu extends StateBasedGame {
|
|||
} else {
|
||||
// display error only
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"opsu! has crashed. Please report this!",
|
||||
"opsu! has encountered an error.\nPlease report this!",
|
||||
"Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -95,6 +95,7 @@ public class MusicController {
|
|||
|
||||
// releases all sources from previous tracks
|
||||
destroyOpenAL();
|
||||
System.gc();
|
||||
|
||||
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
|
||||
case "ogg":
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user