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 <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-01-20 22:19:14 -05:00
parent 2bc45bec0a
commit e2c1f2f937
3 changed files with 20 additions and 1 deletions

View File

@ -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]);

View File

@ -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;

View File

@ -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;