Resolved some reported issues.

- Threaded OGG loading (in addition to MP3) to eliminate delays in song select menu. (reported by xasuma)
- Changed default OSZ unpacking location to a "SongPacks" directory to prevent unintended unpacking. (reported by Lanturn)
- Fixed a null pointer for a corner case in 'getRandomNode()'. (reported by @iceblade112)

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2014-07-15 00:20:36 -04:00
parent f0f8160fa1
commit 943c2af178
7 changed files with 32 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
/.opsu_tmp/
/Screenshots/
/Skins/
/SongPacks/
/Songs/
/.opsu.log
/.opsu.cfg

View File

@ -23,7 +23,7 @@ configuration file to the path of the root song directory.
Note that beatmaps are typically delivered as OSZ files. These can be extracted
with any ZIP tool, and opsu! will automatically extract them into the songs
folder if placed in the root directory.
folder if placed in the `SongPacks` directory.
### First Run
The `Music Offset` value will likely need to be adjusted when playing for the

View File

@ -56,9 +56,9 @@ public class MusicController {
private static File wavFile;
/**
* Thread for MP3 conversions.
* Thread for loading tracks.
*/
private static Thread conversion;
private static Thread trackLoader;
// This class should not be instantiated.
private MusicController() {}
@ -71,11 +71,11 @@ public class MusicController {
boolean play = (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename));
lastOsu = osu;
if (play) {
// TODO: properly interrupt instead of using deprecated conversion.stop();
// interrupt the conversion
if (isConverting())
// conversion.interrupt();
conversion.stop();
// TODO: properly interrupt instead of using deprecated Thread.stop();
// interrupt the conversion/track loading
if (isTrackLoading())
// trackLoader.interrupt();
trackLoader.stop();
if (wavFile != null)
wavFile.delete();
@ -85,11 +85,16 @@ public class MusicController {
switch (OsuParser.getExtension(osu.audioFilename.getName())) {
case "ogg":
loadTrack(osu.audioFilename, osu.previewTime, loop);
trackLoader = new Thread() {
@Override
public void run() {
loadTrack(osu.audioFilename, osu.previewTime, loop);
}
};
trackLoader.start();
break;
case "mp3":
// convert MP3 to WAV in a new conversion
conversion = new Thread() {
trackLoader = new Thread() {
@Override
public void run() {
convertMp3(osu.audioFilename);
@ -97,7 +102,7 @@ public class MusicController {
loadTrack(wavFile, osu.previewTime, loop);
}
};
conversion.start();
trackLoader.start();
break;
default:
break;
@ -149,10 +154,10 @@ public class MusicController {
}
/**
* Returns true if a conversion is running.
* Returns true if a track is being loaded.
*/
public static boolean isConverting() {
return (conversion != null && conversion.isAlive());
public static boolean isTrackLoading() {
return (trackLoader != null && trackLoader.isAlive());
}
/**
@ -246,11 +251,11 @@ public class MusicController {
/**
* Gets the length of the track, in milliseconds.
* Returns 0 if no file is loaded or an MP3 is currently being converted.
* Returns 0 if no file is loaded or a track is currently being loaded.
* @author bdk (http://slick.ninjacave.com/forum/viewtopic.php?t=2699)
*/
public static int getTrackLength() {
if (!trackExists() || isConverting())
if (!trackExists() || isTrackLoading())
return 0;
float duration = 0f;
@ -273,10 +278,10 @@ public class MusicController {
/**
* Gets the length of the track as a formatted string (M:SS).
* Returns "--" if an MP3 is currently being converted.
* Returns "--" if a track is currently being loaded.
*/
public static String getTrackLengthString() {
if (isConverting())
if (isTrackLoading())
return "...";
int duration = getTrackLength();

View File

@ -135,7 +135,7 @@ public class OsuGroupList {
*/
public OsuGroupNode getRandomNode() {
OsuGroupNode node = getBaseNode((int) (Math.random() * size()));
if (node.index == expandedIndex) // don't choose an expanded group node
if (node != null && node.index == expandedIndex) // don't choose an expanded group node
node = node.next;
return node;
}

View File

@ -188,7 +188,7 @@ public class MainMenu extends BasicGameState {
g.setColor(Utils.COLOR_BLACK_ALPHA);
g.fillRoundRect(width - 168, 54, 148, 5, 4);
g.setColor(Color.white);
if (!MusicController.isConverting())
if (!MusicController.isTrackLoading())
g.fillRoundRect(width - 168, 54,
148f * MusicController.getPosition() / MusicController.getTrackLength(), 5, 4);
@ -197,7 +197,7 @@ public class MainMenu extends BasicGameState {
int lineHeight = Utils.FONT_MEDIUM.getLineHeight();
g.drawString(String.format("Loaded %d songs and %d beatmaps.",
Opsu.groups.size(), Opsu.groups.getMapCount()), 25, 25);
if (MusicController.isConverting())
if (MusicController.isTrackLoading())
g.drawString("Track loading...", 25, 25 + lineHeight);
else if (MusicController.trackExists()) {
g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", 25, 25 + lineHeight);
@ -290,7 +290,7 @@ public class MainMenu extends BasicGameState {
if (musicPlay.contains(x, y)) {
if (MusicController.isPlaying())
MusicController.pause();
else if (!MusicController.isConverting())
else if (!MusicController.isTrackLoading())
MusicController.resume();
} else if (musicNext.contains(x, y)) {
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);

View File

@ -1193,7 +1193,8 @@ public class Options extends BasicGameState {
if (oszDir != null && oszDir.isDirectory())
return oszDir;
oszDir = new File("").getAbsoluteFile();
oszDir = new File("SongPacks/");
oszDir.mkdir();
return oszDir;
}

View File

@ -606,7 +606,7 @@ public class SongMenu extends BasicGameState {
* @param osu the OsuFile to send to the game
*/
private void startGame() {
if (MusicController.isConverting())
if (MusicController.isTrackLoading())
return;
SoundController.playSound(SoundController.SOUND_MENUHIT);