22w34c Re-implement music disc functionality & add asset overrides.
Music discs are NOT implemented by default, due to file size; you must manually add them yourself to hear them.
This commit is contained in:
parent
47a81e6589
commit
78e502bb7a
Binary file not shown.
36834
javascript/classes.js
36834
javascript/classes.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
3
javascript/index.html
vendored
3
javascript/index.html
vendored
|
@ -12,6 +12,9 @@ alert("You're not supposed to 'open' this file in your browser. Please upload th
|
||||||
window.addEventListener("load", function(){
|
window.addEventListener("load", function(){
|
||||||
window.eaglercraftOpts = {
|
window.eaglercraftOpts = {
|
||||||
container: "game_frame", assetsURI: "assets.epk", serverWorkerURI: "worker_bootstrap.js", worldsFolder: "TEST",
|
container: "game_frame", assetsURI: "assets.epk", serverWorkerURI: "worker_bootstrap.js", worldsFolder: "TEST",
|
||||||
|
assetOverrides: {
|
||||||
|
"records/wait.mp3": "wait.mp3"
|
||||||
|
},
|
||||||
servers: [
|
servers: [
|
||||||
{ serverName: "Local Test Server", serverAddress: "localhost:25565", hideAddress: false }
|
{ serverName: "Local Test Server", serverAddress: "localhost:25565", hideAddress: false }
|
||||||
],
|
],
|
||||||
|
|
BIN
javascript/wait.mp3
Normal file
BIN
javascript/wait.mp3
Normal file
Binary file not shown.
|
@ -10,10 +10,29 @@ import java.util.HashMap;
|
||||||
import com.jcraft.jzlib.CRC32;
|
import com.jcraft.jzlib.CRC32;
|
||||||
import com.jcraft.jzlib.GZIPInputStream;
|
import com.jcraft.jzlib.GZIPInputStream;
|
||||||
import com.jcraft.jzlib.InflaterInputStream;
|
import com.jcraft.jzlib.InflaterInputStream;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class AssetRepository {
|
public class AssetRepository {
|
||||||
|
|
||||||
private static final HashMap<String,byte[]> filePool = new HashMap();
|
private static final HashMap<String,byte[]> filePool = new HashMap();
|
||||||
|
public static final HashMap<String, String> fileNameOverrides = new HashMap();
|
||||||
|
|
||||||
|
public static final void loadOverrides(JSONObject json) {
|
||||||
|
JSONObject overrides = json.optJSONObject("assetOverrides", null);
|
||||||
|
if (overrides != null) {
|
||||||
|
for (String fileName : overrides.keySet()) {
|
||||||
|
if(fileName.startsWith("/")) fileName = fileName.substring(1);
|
||||||
|
String val = overrides.optString(fileName, null);
|
||||||
|
if (val != null) {
|
||||||
|
AssetRepository.fileNameOverrides.put(fileName, val);
|
||||||
|
if (!fileName.toLowerCase().endsWith(".mp3")) {
|
||||||
|
loadFromURL(fileName, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final void install(byte[] pkg) throws IOException {
|
public static final void install(byte[] pkg) throws IOException {
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(pkg);
|
ByteArrayInputStream in = new ByteArrayInputStream(pkg);
|
||||||
|
@ -209,4 +228,8 @@ public class AssetRepository {
|
||||||
return filePool.get(path);
|
return filePool.get(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final void loadFromURL(String path, String url) {
|
||||||
|
filePool.put(path, EaglerAdapter.downloadURL(url));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ public class ConfigConstants {
|
||||||
|
|
||||||
public static boolean profanity = false;
|
public static boolean profanity = false;
|
||||||
|
|
||||||
public static final String version = "22w34b";
|
public static final String version = "22w34c";
|
||||||
public static final String mainMenuString = "eaglercraft " + version;
|
public static final String mainMenuString = "eaglercraft " + version;
|
||||||
|
|
||||||
public static final String forkMe = "https://github.com/lax1dude/eaglercraft";
|
public static final String forkMe = "https://github.com/lax1dude/eaglercraft";
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class GameSettings {
|
||||||
private static final String[] LIMIT_FRAMERATES = new String[] { "performance.max", "performance.balanced", "performance.powersaver" };
|
private static final String[] LIMIT_FRAMERATES = new String[] { "performance.max", "performance.balanced", "performance.powersaver" };
|
||||||
private static final String[] AMBIENT_OCCLUSIONS = new String[] { "options.ao.off", "options.ao.min", "options.ao.max" };
|
private static final String[] AMBIENT_OCCLUSIONS = new String[] { "options.ao.off", "options.ao.min", "options.ao.max" };
|
||||||
private static final String[] ANTIALIASING = new String[] { "options.framebufferAntialias.none", "options.framebufferAntialias.auto", "options.framebufferAntialias.fxaa" , "options.framebufferAntialias.msaa4", "options.framebufferAntialias.msaa8" };
|
private static final String[] ANTIALIASING = new String[] { "options.framebufferAntialias.none", "options.framebufferAntialias.auto", "options.framebufferAntialias.fxaa" , "options.framebufferAntialias.msaa4", "options.framebufferAntialias.msaa8" };
|
||||||
public float musicVolume = 0.0F;
|
public float musicVolume = 1.0F;
|
||||||
public float soundVolume = 1.0F;
|
public float soundVolume = 1.0F;
|
||||||
public float mouseSensitivity = 0.5F;
|
public float mouseSensitivity = 0.5F;
|
||||||
public boolean invertMouse = false;
|
public boolean invertMouse = false;
|
||||||
|
|
|
@ -1549,15 +1549,13 @@ public class RenderGlobal implements IWorldAccess {
|
||||||
* Plays the specified record. Arg: recordName, x, y, z
|
* Plays the specified record. Arg: recordName, x, y, z
|
||||||
*/
|
*/
|
||||||
public void playRecord(String par1Str, int par2, int par3, int par4) {
|
public void playRecord(String par1Str, int par2, int par3, int par4) {
|
||||||
Minecraft.getMinecraft().displayEaglercraftText("records have been deleted to reduce file size");
|
|
||||||
|
|
||||||
ItemRecord var5 = ItemRecord.getRecord(par1Str);
|
ItemRecord var5 = ItemRecord.getRecord(par1Str);
|
||||||
|
|
||||||
if (par1Str != null && var5 != null) {
|
if (par1Str != null && var5 != null) {
|
||||||
this.mc.ingameGUI.setRecordPlayingMessage(var5.getRecordTitle());
|
this.mc.ingameGUI.setRecordPlayingMessage(var5.getRecordTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mc.sndManager.playStreaming(par1Str, (float) par2, (float) par3, (float) par4);
|
this.mc.sndManager.playStreaming(par1Str, (float)par2 + 0.5F, (float)par3 + 0.5F, (float)par4 + 0.5F, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import net.lax1dude.eaglercraft.AssetRepository;
|
||||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||||
import net.lax1dude.eaglercraft.EaglercraftRandom;
|
import net.lax1dude.eaglercraft.EaglercraftRandom;
|
||||||
|
|
||||||
|
@ -41,12 +42,14 @@ public class SoundManager {
|
||||||
private GameSettings options;
|
private GameSettings options;
|
||||||
private ArrayList<EntitySoundEvent> soundevents;
|
private ArrayList<EntitySoundEvent> soundevents;
|
||||||
private ArrayList<QueuedSoundEvent> queuedsoundevents;
|
private ArrayList<QueuedSoundEvent> queuedsoundevents;
|
||||||
|
private ArrayList<Integer> activerecords;
|
||||||
private HashMap<String,Integer> sounddefinitions;
|
private HashMap<String,Integer> sounddefinitions;
|
||||||
private EaglercraftRandom soundrandom;
|
private EaglercraftRandom soundrandom;
|
||||||
|
|
||||||
public SoundManager() {
|
public SoundManager() {
|
||||||
this.soundevents = new ArrayList();
|
this.soundevents = new ArrayList();
|
||||||
this.queuedsoundevents = new ArrayList();
|
this.queuedsoundevents = new ArrayList();
|
||||||
|
this.activerecords = new ArrayList();
|
||||||
this.sounddefinitions = null;
|
this.sounddefinitions = null;
|
||||||
this.soundrandom = new EaglercraftRandom();
|
this.soundrandom = new EaglercraftRandom();
|
||||||
}
|
}
|
||||||
|
@ -78,6 +81,7 @@ public class SoundManager {
|
||||||
* Called when one of the sound level options has changed.
|
* Called when one of the sound level options has changed.
|
||||||
*/
|
*/
|
||||||
public void onSoundOptionsChanged() {
|
public void onSoundOptionsChanged() {
|
||||||
|
EaglerAdapter.setMusicVolume(options.musicVolume);
|
||||||
EaglerAdapter.setMasterVolume(options.soundVolume);
|
EaglerAdapter.setMasterVolume(options.soundVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,10 +127,29 @@ public class SoundManager {
|
||||||
for(EntitySoundEvent e : soundevents) {
|
for(EntitySoundEvent e : soundevents) {
|
||||||
EaglerAdapter.endSound(e.id);
|
EaglerAdapter.endSound(e.id);
|
||||||
}
|
}
|
||||||
|
for(Integer i : activerecords) {
|
||||||
|
EaglerAdapter.endSound(i.intValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playStreaming(String par1Str, float par2, float par3, float par4) {
|
public void playStreaming(String par1Str, float par2, float par3, float par4) {
|
||||||
|
playStreaming(par1Str, par2, par3, par4, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playStreaming(String par1Str, float par2, float par3, float par4, boolean music) {
|
||||||
|
for (Integer record : activerecords) {
|
||||||
|
EaglerAdapter.endSound(record.intValue());
|
||||||
|
}
|
||||||
|
activerecords.clear();
|
||||||
|
if (par1Str != null) {
|
||||||
|
String path = "/records/" + par1Str.replace('.', '/') + ".mp3";
|
||||||
|
int snd = EaglerAdapter.beginPlayback(path, par2, par3, par4, 1.0F, 1.0F, music);
|
||||||
|
if (snd != -1) {
|
||||||
|
activerecords.add(new Integer(snd));
|
||||||
|
} else {
|
||||||
|
System.err.println("unregistered record: "+par1Str);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -327,7 +350,7 @@ public class SoundManager {
|
||||||
|
|
||||||
public void playTheTitleMusic() {
|
public void playTheTitleMusic() {
|
||||||
if(titleMusic == -1 || !EaglerAdapter.isPlaying(titleMusic)) {
|
if(titleMusic == -1 || !EaglerAdapter.isPlaying(titleMusic)) {
|
||||||
titleMusic = EaglerAdapter.beginPlaybackStatic("/sounds/gta.mp3", 1.0f, 1.0f);
|
titleMusic = EaglerAdapter.beginPlaybackStatic("/sounds/gta.mp3", 1.0f, 1.0f, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ public class Client {
|
||||||
|
|
||||||
registerErrorHandler();
|
registerErrorHandler();
|
||||||
ServerList.loadDefaultServers(conf);
|
ServerList.loadDefaultServers(conf);
|
||||||
|
AssetRepository.loadOverrides(conf);
|
||||||
LocalStorageManager.loadStorage();
|
LocalStorageManager.loadStorage();
|
||||||
|
|
||||||
run0();
|
run0();
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.teavm.jso.dom.events.KeyboardEvent;
|
||||||
import org.teavm.jso.dom.events.MessageEvent;
|
import org.teavm.jso.dom.events.MessageEvent;
|
||||||
import org.teavm.jso.dom.events.MouseEvent;
|
import org.teavm.jso.dom.events.MouseEvent;
|
||||||
import org.teavm.jso.dom.events.WheelEvent;
|
import org.teavm.jso.dom.events.WheelEvent;
|
||||||
|
import org.teavm.jso.dom.html.HTMLAudioElement;
|
||||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||||
import org.teavm.jso.dom.html.HTMLDocument;
|
import org.teavm.jso.dom.html.HTMLDocument;
|
||||||
import org.teavm.jso.dom.html.HTMLElement;
|
import org.teavm.jso.dom.html.HTMLElement;
|
||||||
|
@ -64,6 +65,8 @@ import org.teavm.jso.webaudio.AudioBuffer;
|
||||||
import org.teavm.jso.webaudio.AudioBufferSourceNode;
|
import org.teavm.jso.webaudio.AudioBufferSourceNode;
|
||||||
import org.teavm.jso.webaudio.AudioContext;
|
import org.teavm.jso.webaudio.AudioContext;
|
||||||
import org.teavm.jso.webaudio.AudioListener;
|
import org.teavm.jso.webaudio.AudioListener;
|
||||||
|
import org.teavm.jso.webaudio.AudioNode;
|
||||||
|
import org.teavm.jso.webaudio.ChannelMergerNode;
|
||||||
import org.teavm.jso.webaudio.DecodeErrorCallback;
|
import org.teavm.jso.webaudio.DecodeErrorCallback;
|
||||||
import org.teavm.jso.webaudio.DecodeSuccessCallback;
|
import org.teavm.jso.webaudio.DecodeSuccessCallback;
|
||||||
import org.teavm.jso.webaudio.GainNode;
|
import org.teavm.jso.webaudio.GainNode;
|
||||||
|
@ -185,6 +188,29 @@ public class EaglerAdapterImpl2 {
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public static native byte[] downloadURL(String url);
|
||||||
|
|
||||||
|
private static void downloadURL(String url, final AsyncCallback<byte[]> cb) {
|
||||||
|
final XMLHttpRequest request = XMLHttpRequest.create();
|
||||||
|
request.setResponseType("arraybuffer");
|
||||||
|
request.open("GET", url, true);
|
||||||
|
request.setOnReadyStateChange(new ReadyStateChangeHandler() {
|
||||||
|
@Override
|
||||||
|
public void stateChanged() {
|
||||||
|
if(request.getReadyState() == XMLHttpRequest.DONE) {
|
||||||
|
Uint8Array bl = Uint8Array.create((ArrayBuffer)request.getResponse());
|
||||||
|
byte[] res = new byte[bl.getByteLength()];
|
||||||
|
for(int i = 0; i < res.length; ++i) {
|
||||||
|
res[i] = (byte) bl.get(i);
|
||||||
|
}
|
||||||
|
cb.complete(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
request.send();
|
||||||
|
}
|
||||||
|
|
||||||
@JSBody(params = { "v", "s" }, script = "window[v] = s;")
|
@JSBody(params = { "v", "s" }, script = "window[v] = s;")
|
||||||
public static native void setDebugVar(String v, String s);
|
public static native void setDebugVar(String v, String s);
|
||||||
|
|
||||||
|
@ -396,6 +422,9 @@ public class EaglerAdapterImpl2 {
|
||||||
masterVolumeNode = audioctx.createGain();
|
masterVolumeNode = audioctx.createGain();
|
||||||
masterVolumeNode.getGain().setValue(1.0f);
|
masterVolumeNode.getGain().setValue(1.0f);
|
||||||
masterVolumeNode.connect(audioctx.getDestination());
|
masterVolumeNode.connect(audioctx.getDestination());
|
||||||
|
musicVolumeNode = audioctx.createGain();
|
||||||
|
musicVolumeNode.getGain().setValue(1.0f);
|
||||||
|
musicVolumeNode.connect(audioctx.getDestination());
|
||||||
|
|
||||||
mouseEvents.clear();
|
mouseEvents.clear();
|
||||||
keyEvents.clear();
|
keyEvents.clear();
|
||||||
|
@ -1949,9 +1978,11 @@ public class EaglerAdapterImpl2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int playbackId = 0;
|
private static int playbackId = 0;
|
||||||
|
private static int audioElementId = 0;
|
||||||
private static final HashMap<String,AudioBufferX> loadedSoundFiles = new HashMap();
|
private static final HashMap<String,AudioBufferX> loadedSoundFiles = new HashMap();
|
||||||
private static AudioContext audioctx = null;
|
private static AudioContext audioctx = null;
|
||||||
private static GainNode masterVolumeNode = null;
|
private static GainNode masterVolumeNode = null;
|
||||||
|
private static GainNode musicVolumeNode = null;
|
||||||
private static float playbackOffsetDelay = 0.03f;
|
private static float playbackOffsetDelay = 0.03f;
|
||||||
|
|
||||||
public static final void setPlaybackOffsetDelay(float f) {
|
public static final void setPlaybackOffsetDelay(float f) {
|
||||||
|
@ -1962,6 +1993,10 @@ public class EaglerAdapterImpl2 {
|
||||||
masterVolumeNode.getGain().setValue(f);
|
masterVolumeNode.getGain().setValue(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final void setMusicVolume(float f) {
|
||||||
|
musicVolumeNode.getGain().setValue(f);
|
||||||
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
public static native AudioBuffer decodeAudioAsync(ArrayBuffer buffer);
|
public static native AudioBuffer decodeAudioAsync(ArrayBuffer buffer);
|
||||||
|
|
||||||
|
@ -1979,7 +2014,7 @@ public class EaglerAdapterImpl2 {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HashMap<Integer,AudioBufferSourceNodeX> activeSoundEffects = new HashMap();
|
private static final HashMap<Integer,AudioSourceNodeX> activeSoundEffects = new HashMap();
|
||||||
|
|
||||||
private static class AudioBufferX {
|
private static class AudioBufferX {
|
||||||
private final AudioBuffer buffer;
|
private final AudioBuffer buffer;
|
||||||
|
@ -1988,17 +2023,33 @@ public class EaglerAdapterImpl2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class AudioBufferSourceNodeX {
|
private static class AudioSourceNodeX {
|
||||||
private final AudioBufferSourceNode source;
|
|
||||||
private final PannerNode panner;
|
private final PannerNode panner;
|
||||||
private final GainNode gain;
|
private final GainNode gain;
|
||||||
private AudioBufferSourceNodeX(AudioBufferSourceNode source, PannerNode panner, GainNode gain) {
|
private AudioSourceNodeX(PannerNode panner, GainNode gain) {
|
||||||
this.source = source;
|
|
||||||
this.panner = panner;
|
this.panner = panner;
|
||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class AudioBufferSourceNodeX extends AudioSourceNodeX {
|
||||||
|
private final AudioBufferSourceNode source;
|
||||||
|
private AudioBufferSourceNodeX(AudioBufferSourceNode source, PannerNode panner, GainNode gain) {
|
||||||
|
super(panner, gain);
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class MediaElementAudioSourceNodeX extends AudioSourceNodeX {
|
||||||
|
private final MediaElementAudioSourceNode source;
|
||||||
|
private final HTMLAudioElement audio;
|
||||||
|
private MediaElementAudioSourceNodeX(MediaElementAudioSourceNode source, HTMLAudioElement audio, PannerNode panner, GainNode gain) {
|
||||||
|
super(panner, gain);
|
||||||
|
this.source = source;
|
||||||
|
this.audio = audio;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final AudioBuffer getBufferFor(String fileName) {
|
private static final AudioBuffer getBufferFor(String fileName) {
|
||||||
AudioBufferX ret = loadedSoundFiles.get(fileName);
|
AudioBufferX ret = loadedSoundFiles.get(fileName);
|
||||||
if(ret == null) {
|
if(ret == null) {
|
||||||
|
@ -2012,11 +2063,29 @@ public class EaglerAdapterImpl2 {
|
||||||
return ret.buffer;
|
return ret.buffer;
|
||||||
}
|
}
|
||||||
public static final int beginPlayback(String fileName, float x, float y, float z, float volume, float pitch) {
|
public static final int beginPlayback(String fileName, float x, float y, float z, float volume, float pitch) {
|
||||||
|
return beginPlayback(fileName, x, y, z, volume, pitch, false);
|
||||||
|
}
|
||||||
|
public static final int beginPlayback(String fileNamePre, float x, float y, float z, float volume, float pitch, boolean music) {
|
||||||
|
if(fileNamePre.startsWith("/")) fileNamePre = fileNamePre.substring(1);
|
||||||
|
String fileName = AssetRepository.fileNameOverrides.getOrDefault(fileNamePre, fileNamePre);
|
||||||
|
AudioNode s;
|
||||||
|
HTMLAudioElement audioElement = null;
|
||||||
|
String lowerFileName = fileName.toLowerCase();
|
||||||
|
boolean usingUrl = AssetRepository.fileNameOverrides.containsKey(fileNamePre) || lowerFileName.startsWith("http://") || lowerFileName.startsWith("https://") || lowerFileName.startsWith("blob:") || lowerFileName.startsWith("data:");
|
||||||
|
if (usingUrl) {
|
||||||
|
audioElement = (HTMLAudioElement) win.getDocument().createElement("audio");
|
||||||
|
audioElement.setAutoplay(true);
|
||||||
|
audioElement.setSrc(fileName);
|
||||||
|
s = audioctx.createMediaElementSource(audioElement);
|
||||||
|
audioElement.setPlaybackRate(pitch);
|
||||||
|
} else {
|
||||||
AudioBuffer b = getBufferFor(fileName);
|
AudioBuffer b = getBufferFor(fileName);
|
||||||
if(b == null) return -1;
|
if(b == null) return -1;
|
||||||
AudioBufferSourceNode s = audioctx.createBufferSource();
|
s = audioctx.createBufferSource();
|
||||||
s.setBuffer(b);
|
((AudioBufferSourceNode) s).setBuffer(b);
|
||||||
s.getPlaybackRate().setValue(pitch);
|
((AudioBufferSourceNode) s).getPlaybackRate().setValue(pitch);
|
||||||
|
}
|
||||||
|
ChannelMergerNode c = audioctx.createChannelMerger(1);
|
||||||
PannerNode p = audioctx.createPanner();
|
PannerNode p = audioctx.createPanner();
|
||||||
p.setPosition(x, y, z);
|
p.setPosition(x, y, z);
|
||||||
p.setMaxDistance(volume * 16f + 0.1f);
|
p.setMaxDistance(volume * 16f + 0.1f);
|
||||||
|
@ -2030,69 +2099,132 @@ public class EaglerAdapterImpl2 {
|
||||||
p.setOrientation(0f, 1f, 0f);
|
p.setOrientation(0f, 1f, 0f);
|
||||||
GainNode g = audioctx.createGain();
|
GainNode g = audioctx.createGain();
|
||||||
g.getGain().setValue(volume > 1.0f ? 1.0f : volume);
|
g.getGain().setValue(volume > 1.0f ? 1.0f : volume);
|
||||||
s.connect(g);
|
s.connect(c);
|
||||||
|
c.connect(g);
|
||||||
g.connect(p);
|
g.connect(p);
|
||||||
p.connect(masterVolumeNode);
|
p.connect(music ? musicVolumeNode : masterVolumeNode);
|
||||||
s.start(0.0d, playbackOffsetDelay);
|
if (!usingUrl) {
|
||||||
|
((AudioBufferSourceNode) s).start(0.0d, playbackOffsetDelay);
|
||||||
|
}
|
||||||
final int theId = ++playbackId;
|
final int theId = ++playbackId;
|
||||||
activeSoundEffects.put(theId, new AudioBufferSourceNodeX(s, p, g));
|
if (usingUrl) {
|
||||||
s.setOnEnded(new EventListener<MediaEvent>() {
|
activeSoundEffects.put(theId, new MediaElementAudioSourceNodeX((MediaElementAudioSourceNode) s, audioElement, p, g));
|
||||||
|
audioElement.addEventListener("canplay", new EventListener<Event>() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event evt) {
|
||||||
|
if (activeSoundEffects.containsKey(theId)) {
|
||||||
|
((MediaElementAudioSourceNodeX) activeSoundEffects.get(theId)).audio.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
audioElement.addEventListener("ended", new EventListener<Event>() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event evt) {
|
||||||
|
((MediaElementAudioSourceNodeX) activeSoundEffects.remove(theId)).audio.setSrc("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
activeSoundEffects.put(theId, new AudioBufferSourceNodeX((AudioBufferSourceNode) s, p, g));
|
||||||
|
((AudioBufferSourceNode) s).setOnEnded(new EventListener<MediaEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(MediaEvent evt) {
|
public void handleEvent(MediaEvent evt) {
|
||||||
activeSoundEffects.remove(theId);
|
activeSoundEffects.remove(theId);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return theId;
|
return theId;
|
||||||
}
|
}
|
||||||
public static final int beginPlaybackStatic(String fileName, float volume, float pitch) {
|
public static final int beginPlaybackStatic(String fileName, float volume, float pitch) {
|
||||||
|
return beginPlaybackStatic(fileName, volume, pitch, false);
|
||||||
|
}
|
||||||
|
public static final int beginPlaybackStatic(String fileNamePre, float volume, float pitch, boolean music) {
|
||||||
|
if(fileNamePre.startsWith("/")) fileNamePre = fileNamePre.substring(1);
|
||||||
|
String fileName = AssetRepository.fileNameOverrides.getOrDefault(fileNamePre, fileNamePre);
|
||||||
|
AudioNode s;
|
||||||
|
HTMLAudioElement audioElement = null;
|
||||||
|
String lowerFileName = fileName.toLowerCase();
|
||||||
|
boolean usingUrl = AssetRepository.fileNameOverrides.containsKey(fileNamePre) || lowerFileName.startsWith("http://") || lowerFileName.startsWith("https://") || lowerFileName.startsWith("blob:") || lowerFileName.startsWith("data:");
|
||||||
|
if (usingUrl) {
|
||||||
|
audioElement = (HTMLAudioElement) win.getDocument().createElement("audio");
|
||||||
|
audioElement.setAutoplay(true);
|
||||||
|
audioElement.setSrc(fileName);
|
||||||
|
s = audioctx.createMediaElementSource(audioElement);
|
||||||
|
audioElement.setPlaybackRate(pitch);
|
||||||
|
} else {
|
||||||
AudioBuffer b = getBufferFor(fileName);
|
AudioBuffer b = getBufferFor(fileName);
|
||||||
if(b == null) return -1;
|
if(b == null) return -1;
|
||||||
AudioBufferSourceNode s = audioctx.createBufferSource();
|
s = audioctx.createBufferSource();
|
||||||
s.setBuffer(b);
|
((AudioBufferSourceNode) s).setBuffer(b);
|
||||||
s.getPlaybackRate().setValue(pitch);
|
((AudioBufferSourceNode) s).getPlaybackRate().setValue(pitch);
|
||||||
|
}
|
||||||
GainNode g = audioctx.createGain();
|
GainNode g = audioctx.createGain();
|
||||||
g.getGain().setValue(volume > 1.0f ? 1.0f : volume);
|
g.getGain().setValue(volume > 1.0f ? 1.0f : volume);
|
||||||
s.connect(g);
|
s.connect(g);
|
||||||
g.connect(masterVolumeNode);
|
g.connect(music ? musicVolumeNode : masterVolumeNode);
|
||||||
s.start(0.0d, playbackOffsetDelay);
|
if (!usingUrl) {
|
||||||
|
((AudioBufferSourceNode) s).start(0.0d, playbackOffsetDelay);
|
||||||
|
}
|
||||||
final int theId = ++playbackId;
|
final int theId = ++playbackId;
|
||||||
activeSoundEffects.put(theId, new AudioBufferSourceNodeX(s, null, g));
|
if (usingUrl) {
|
||||||
s.setOnEnded(new EventListener<MediaEvent>() {
|
activeSoundEffects.put(theId, new MediaElementAudioSourceNodeX(((MediaElementAudioSourceNode) s), audioElement, null, g));
|
||||||
|
audioElement.addEventListener("canplay", new EventListener<Event>() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event evt) {
|
||||||
|
if (activeSoundEffects.containsKey(theId)) {
|
||||||
|
((MediaElementAudioSourceNodeX) activeSoundEffects.get(theId)).audio.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
audioElement.addEventListener("ended", new EventListener<Event>() {
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event evt) {
|
||||||
|
((MediaElementAudioSourceNodeX) activeSoundEffects.remove(theId)).audio.setSrc("");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
activeSoundEffects.put(theId, new AudioBufferSourceNodeX(((AudioBufferSourceNode) s), null, g));
|
||||||
|
((AudioBufferSourceNode) s).setOnEnded(new EventListener<MediaEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(MediaEvent evt) {
|
public void handleEvent(MediaEvent evt) {
|
||||||
activeSoundEffects.remove(theId);
|
activeSoundEffects.remove(theId);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
return playbackId;
|
}
|
||||||
|
return theId;
|
||||||
}
|
}
|
||||||
public static final void setPitch(int id, float pitch) {
|
public static final void setPitch(int id, float pitch) {
|
||||||
AudioBufferSourceNodeX b = activeSoundEffects.get(id);
|
AudioSourceNodeX a = activeSoundEffects.get(id);
|
||||||
if(b != null) {
|
if(a != null) {
|
||||||
b.source.getPlaybackRate().setValue(pitch);
|
if (a instanceof AudioBufferSourceNodeX) {
|
||||||
|
((AudioBufferSourceNodeX) a).source.getPlaybackRate().setValue(pitch);
|
||||||
|
} else if (a instanceof MediaElementAudioSourceNodeX) {
|
||||||
|
((MediaElementAudioSourceNodeX) a).audio.setPlaybackRate(pitch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static final void setVolume(int id, float volume) {
|
public static final void setVolume(int id, float volume) {
|
||||||
AudioBufferSourceNodeX b = activeSoundEffects.get(id);
|
AudioSourceNodeX a = activeSoundEffects.get(id);
|
||||||
if(b != null) {
|
if(a != null) {
|
||||||
b.gain.getGain().setValue(volume > 1.0f ? 1.0f : volume);
|
a.gain.getGain().setValue(volume > 1.0f ? 1.0f : volume);
|
||||||
if(b.panner != null) b.panner.setMaxDistance(volume * 16f + 0.1f);
|
if(a.panner != null) a.panner.setMaxDistance(volume * 16f + 0.1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static final void moveSound(int id, float x, float y, float z, float vx, float vy, float vz) {
|
public static final void moveSound(int id, float x, float y, float z, float vx, float vy, float vz) {
|
||||||
AudioBufferSourceNodeX b = activeSoundEffects.get(id);
|
AudioSourceNodeX a = activeSoundEffects.get(id);
|
||||||
if(b != null && b.panner != null) {
|
if(a != null && a.panner != null) {
|
||||||
b.panner.setPosition(x, y, z);
|
a.panner.setPosition(x, y, z);
|
||||||
//b.panner.setVelocity(vx, vy, vz);
|
//a.panner.setVelocity(vx, vy, vz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static final void endSound(int id) {
|
public static final void endSound(int id) {
|
||||||
AudioBufferSourceNodeX b = activeSoundEffects.get(id);
|
AudioSourceNodeX a = activeSoundEffects.get(id);
|
||||||
if(b != null) {
|
if(a != null) {
|
||||||
b.source.stop();
|
if (a instanceof AudioBufferSourceNodeX) {
|
||||||
|
((AudioBufferSourceNodeX) a).source.stop();
|
||||||
|
} else if (a instanceof MediaElementAudioSourceNodeX) {
|
||||||
|
((MediaElementAudioSourceNodeX) a).audio.pause();
|
||||||
|
((MediaElementAudioSourceNodeX) a).audio.setSrc("");
|
||||||
|
}
|
||||||
activeSoundEffects.remove(id);
|
activeSoundEffects.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3919,7 +4051,7 @@ public class EaglerAdapterImpl2 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int fragmentSize = 16384;
|
private static final int fragmentSize = 65536;
|
||||||
|
|
||||||
public static final void serverLANWritePacket(String peer, byte[] data) {
|
public static final void serverLANWritePacket(String peer, byte[] data) {
|
||||||
if (data.length > fragmentSize) {
|
if (data.length > fragmentSize) {
|
||||||
|
|
36840
stable-download/Offline_Download_Version.html
vendored
36840
stable-download/Offline_Download_Version.html
vendored
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user