From e2c1f2f93777a57a1900898fcc831b9164f67e2d Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Tue, 20 Jan 2015 22:19:14 -0500 Subject: [PATCH] Small memory optimization: reuse audio File objects in song groups. Each song group references the same audio file probably 100% of the time, so don't create duplicate objects. Also, follow-up to 3b13cc7: the up/down arrow keys now change global volume in the main menu and game states (in addition to the scroll wheel). Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/OsuParser.java | 9 ++++++++- src/itdelatrisu/opsu/states/Game.java | 6 ++++++ src/itdelatrisu/opsu/states/MainMenu.java | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/itdelatrisu/opsu/OsuParser.java b/src/itdelatrisu/opsu/OsuParser.java index 331e8c79..222102bb 100644 --- a/src/itdelatrisu/opsu/OsuParser.java +++ b/src/itdelatrisu/opsu/OsuParser.java @@ -152,7 +152,14 @@ public class OsuParser { try { switch (tokens[0]) { case "AudioFilename": - osu.audioFilename = new File(file.getParent() + File.separator + tokens[1]); + File audioFileName = new File(file.getParent(), tokens[1]); + if (!osuFiles.isEmpty()) { + // if possible, reuse the same File object from another OsuFile in the group + File groupAudioFileName = osuFiles.get(0).audioFilename; + if (audioFileName.equals(groupAudioFileName)) + audioFileName = groupAudioFileName; + } + osu.audioFilename = audioFileName; break; case "AudioLeadIn": osu.audioLeadIn = Integer.parseInt(tokens[1]); diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java index b2028cc3..df9f63ee 100644 --- a/src/itdelatrisu/opsu/states/Game.java +++ b/src/itdelatrisu/opsu/states/Game.java @@ -644,6 +644,12 @@ public class Game extends BasicGameState { } } break; + case Input.KEY_UP: + Utils.changeVolume(1); + break; + case Input.KEY_DOWN: + Utils.changeVolume(-1); + break; case Input.KEY_F12: Utils.takeScreenShot(); break; diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index b4b7bd07..8894a865 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -428,6 +428,12 @@ public class MainMenu extends BasicGameState { game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } break; + case Input.KEY_UP: + Utils.changeVolume(1); + break; + case Input.KEY_DOWN: + Utils.changeVolume(-1); + break; case Input.KEY_F12: Utils.takeScreenShot(); break;