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 <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-01-08 12:03:39 -05:00
parent f6eac71643
commit db4ca5f1d5
4 changed files with 23 additions and 10 deletions

View File

@ -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
*/

View File

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

View File

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

View File

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