mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-01-02 20:29:20 +00:00
Fix loading issues for OGG on windows
This commit is contained in:
parent
e435aa3a7a
commit
191066f65c
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +1,4 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "automatic"
|
||||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"java.debug.settings.onBuildFailureProceed": true
|
||||
}
|
@ -158,7 +158,10 @@ public class Utility {
|
||||
if (isHeadless) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Image img = loadIcon(filename).get();
|
||||
Optional<Image> img = loadIcon(filename);
|
||||
if (img.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Label label = new Label() {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@ -174,7 +177,7 @@ public class Utility {
|
||||
return getText().hashCode();
|
||||
}
|
||||
};
|
||||
label.setGraphic(new ImageView(img));
|
||||
label.setGraphic(new ImageView(img.get()));
|
||||
label.setAlignment(Pos.CENTER);
|
||||
label.setContentDisplay(ContentDisplay.TOP);
|
||||
label.setTextFill(Color.WHITE);
|
||||
|
@ -59,6 +59,9 @@ public class Joystick extends Device {
|
||||
|
||||
public Joystick(int port, Computer computer) {
|
||||
super(computer);
|
||||
if (LawlessLegends.getApplication() == null) {
|
||||
return;
|
||||
}
|
||||
Stage stage = LawlessLegends.getApplication().primaryStage;
|
||||
// Register a mouse handler on the primary stage that tracks the
|
||||
// mouse x/y position as a percentage of window width and height
|
||||
|
@ -2,6 +2,8 @@ package jace.lawless;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
@ -21,21 +23,20 @@ public class Media {
|
||||
File tempFile;
|
||||
|
||||
public Media(String resourcePath) throws IOException {
|
||||
// Copy resource to temp file because STBVorbis can't read from jar
|
||||
tempFile = File.createTempFile("temp", ".ogg");
|
||||
tempFile.deleteOnExit();
|
||||
getClass().getResource(resourcePath).openStream().transferTo(new java.io.FileOutputStream(tempFile));
|
||||
String canonicalPath = tempFile.getAbsolutePath();
|
||||
|
||||
// Get caononical file path from relative resource path
|
||||
// String canonicalPath = URLDecoder.decode(getClass().getResource(resourcePath).getPath(), "UTF-8");
|
||||
System.out.println("Loading media: " + canonicalPath);
|
||||
System.out.println("Loading media: " + resourcePath);
|
||||
byte[] oggFile;
|
||||
try (InputStream oggStream = getClass().getResourceAsStream(resourcePath)) {
|
||||
oggFile = oggStream.readAllBytes();
|
||||
}
|
||||
|
||||
try (MemoryStack stack = MemoryStack.stackPush()) {
|
||||
ByteBuffer oggBuffer = MemoryUtil.memAlloc(oggFile.length);
|
||||
oggBuffer.put(oggFile);
|
||||
oggBuffer.flip();
|
||||
IntBuffer error = stack.callocInt(1);
|
||||
Long decoder = STBVorbis.stb_vorbis_open_filename(canonicalPath, error, null);
|
||||
Long decoder = STBVorbis.stb_vorbis_open_memory(oggBuffer, error, null);
|
||||
if (decoder == null || decoder <= 0) {
|
||||
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + getError(error.get(0)));
|
||||
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + getError(error.get(0)) + " -- file is located at " + resourcePath);
|
||||
}
|
||||
STBVorbisInfo info = STBVorbisInfo.malloc(stack);
|
||||
STBVorbis.stb_vorbis_get_info(decoder, info);
|
||||
|
@ -0,0 +1,12 @@
|
||||
package jace;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import javafx.application.Platform;
|
||||
|
||||
public abstract class AbstractFXTest {
|
||||
@BeforeClass
|
||||
public static void initJfxRuntime() {
|
||||
Platform.startup(() -> {});
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import jace.core.SoundMixer.SoundBuffer;
|
||||
import jace.lawless.LawlessHacks;
|
||||
import jace.lawless.Media;
|
||||
|
||||
public class SoundTest {
|
||||
public class SoundTest extends AbstractFXTest {
|
||||
@Test
|
||||
public void musicDecodeTest() {
|
||||
// For every song in the music folder, decode it and print out the duration
|
||||
@ -25,7 +25,7 @@ public class SoundTest {
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
//@Test (Only use this to ensure the sound engine produces audible output, it's otherwise annoying to hear all the time)
|
||||
public void soundGenerationTest() {
|
||||
try {
|
||||
System.out.println("Performing sound test...");
|
||||
|
Loading…
Reference in New Issue
Block a user