From db4ca5f1d55c43cad9fb2e3b048e66497aadb4a4 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Thu, 8 Jan 2015 12:03:39 -0500 Subject: [PATCH] Minor optimizations. - Only retrieve song information String[] when needed. - Don't try to load glyphs if Unicode metadata is disabled. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/GameImage.java | 4 ++-- src/itdelatrisu/opsu/OszUnpacker.java | 5 ++++- src/itdelatrisu/opsu/Utils.java | 5 ++++- src/itdelatrisu/opsu/states/SongMenu.java | 19 +++++++++++++------ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/itdelatrisu/opsu/GameImage.java b/src/itdelatrisu/opsu/GameImage.java index 5cbb9daa..94264926 100644 --- a/src/itdelatrisu/opsu/GameImage.java +++ b/src/itdelatrisu/opsu/GameImage.java @@ -324,7 +324,7 @@ public enum GameImage { } /** - * Game image constructor. + * Constructor. * @param filename the image file name */ GameImage(String filename) { @@ -333,7 +333,7 @@ public enum GameImage { } /** - * Game image constructor. + * Constructor. * @param filename the image file name * @param gameImage whether or not the image is related to gameplay */ diff --git a/src/itdelatrisu/opsu/OszUnpacker.java b/src/itdelatrisu/opsu/OszUnpacker.java index 0ab56bd3..82c7a8a6 100644 --- a/src/itdelatrisu/opsu/OszUnpacker.java +++ b/src/itdelatrisu/opsu/OszUnpacker.java @@ -24,6 +24,8 @@ import java.io.FilenameFilter; import net.lingala.zip4j.core.ZipFile; import net.lingala.zip4j.exception.ZipException; +import org.newdawn.slick.util.Log; + /** * Unpacker for OSZ (ZIP) archives. */ @@ -83,7 +85,8 @@ public class OszUnpacker { ZipFile zipFile = new ZipFile(file); zipFile.extractAll(dest.getAbsolutePath()); } catch (ZipException e) { - e.printStackTrace(); + Log.error(String.format("Failed to unzip file %s to dest %s.", + file.getAbsolutePath(), dest.getAbsolutePath()), e); } } diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index 6b83e8cc..ba7dc2f2 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -500,6 +500,9 @@ public class Utils { * @param osu the OsuFile */ public static void loadGlyphs(OsuFile osu) { + if (!Options.useUnicodeMetadata()) + return; + boolean glyphsAdded = false; if (!osu.titleUnicode.isEmpty() && !loadedGlyphs.contains(osu.titleUnicode)) { Utils.FONT_LARGE.addGlyphs(osu.titleUnicode); @@ -515,7 +518,7 @@ public class Utils { loadedGlyphs.add(osu.artistUnicode); glyphsAdded = true; } - if (glyphsAdded && Options.useUnicodeMetadata()) { + if (glyphsAdded) { try { Utils.FONT_LARGE.loadGlyphs(); Utils.FONT_MEDIUM.loadGlyphs(); diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index f13a6228..704faf47 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -85,6 +85,11 @@ public class SongMenu extends BasicGameState { */ private int oldFileIndex = -1; + /** + * Current focus node's song information. + */ + private String[] songInfo; + /** * Button coordinate values. */ @@ -208,17 +213,18 @@ public class SongMenu extends BasicGameState { int iconWidth = musicNote.getWidth(); int iconHeight = musicNote.getHeight(); - String[] info = focusNode.getInfo(); + if (songInfo == null) + songInfo = focusNode.getInfo(); g.setColor(Color.white); - Utils.FONT_LARGE.drawString(iconWidth + 5, -3, info[0]); + Utils.FONT_LARGE.drawString(iconWidth + 5, -3, songInfo[0]); Utils.FONT_DEFAULT.drawString( - iconWidth + 5, -3 + Utils.FONT_LARGE.getLineHeight() * 0.75f, info[1]); + iconWidth + 5, -3 + Utils.FONT_LARGE.getLineHeight() * 0.75f, songInfo[1]); int headerY = iconHeight - 3; - Utils.FONT_BOLD.drawString(5, headerY, info[2]); + Utils.FONT_BOLD.drawString(5, headerY, songInfo[2]); headerY += Utils.FONT_BOLD.getLineHeight() - 6; - Utils.FONT_DEFAULT.drawString(5, headerY, info[3]); + Utils.FONT_DEFAULT.drawString(5, headerY, songInfo[3]); headerY += Utils.FONT_DEFAULT.getLineHeight() - 4; - Utils.FONT_SMALL.drawString(5, headerY, info[4]); + Utils.FONT_SMALL.drawString(5, headerY, songInfo[4]); } // song buttons @@ -546,6 +552,7 @@ public class SongMenu extends BasicGameState { if (node == null) return null; + songInfo = null; OsuGroupNode oldFocus = focusNode; // expand node before focusing it