Nearing completion.
This commit is contained in:
parent
43eb2b2b38
commit
3f8f29d9f8
|
@ -19,7 +19,7 @@ public class Team {
|
||||||
private Set<String> players;
|
private Set<String> players;
|
||||||
|
|
||||||
public Collection<String> getPlayers() {
|
public Collection<String> getPlayers() {
|
||||||
return (Collection<String>) Collections.unmodifiableSet((Set<?>) this.players);
|
return (Collection<String>) (Collection<?>) Collections.unmodifiableSet((Set<?>) this.players);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(final String name) {
|
public void addPlayer(final String name) {
|
||||||
|
|
|
@ -9,11 +9,22 @@ import java.util.Map;
|
||||||
|
|
||||||
public class ExpiringSet<T> extends HashSet<T> {
|
public class ExpiringSet<T> extends HashSet<T> {
|
||||||
private final long expiration;
|
private final long expiration;
|
||||||
|
private final ExpiringEvent<T> event;
|
||||||
|
|
||||||
private final Map<T, Long> timestamps = new HashMap<>();
|
private final Map<T, Long> timestamps = new HashMap<>();
|
||||||
|
|
||||||
public ExpiringSet(long expiration) {
|
public ExpiringSet(long expiration) {
|
||||||
this.expiration = expiration;
|
this.expiration = expiration;
|
||||||
|
this.event = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpiringSet(long expiration, ExpiringEvent<T> event) {
|
||||||
|
this.expiration = expiration;
|
||||||
|
this.event = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ExpiringEvent<T> {
|
||||||
|
void onExpiration(T item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkForExpirations() {
|
public void checkForExpirations() {
|
||||||
|
@ -23,6 +34,7 @@ public class ExpiringSet<T> extends HashSet<T> {
|
||||||
T element = iterator.next();
|
T element = iterator.next();
|
||||||
if (super.contains(element)) {
|
if (super.contains(element)) {
|
||||||
if (this.timestamps.get(element) + this.expiration < now) {
|
if (this.timestamps.get(element) + this.expiration < now) {
|
||||||
|
if (this.event != null) this.event.onExpiration(element);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
super.remove(element);
|
super.remove(element);
|
||||||
}
|
}
|
||||||
|
@ -56,4 +68,4 @@ public class ExpiringSet<T> extends HashSet<T> {
|
||||||
checkForExpirations();
|
checkForExpirations();
|
||||||
return super.contains(o);
|
return super.contains(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
109920
javascript/classes.js
109920
javascript/classes.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -132,7 +132,7 @@ window.initializeVoiceClient = (() => {
|
||||||
this.descriptionHandler = null;
|
this.descriptionHandler = null;
|
||||||
this.peerTrackHandler = null;
|
this.peerTrackHandler = null;
|
||||||
this.peerDisconnectHandler = null;
|
this.peerDisconnectHandler = null;
|
||||||
this.microphoneVolumeAudioContext = new AudioContext();
|
this.microphoneVolumeAudioContext = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
voiceClientSupported() {
|
voiceClientSupported() {
|
||||||
|
@ -177,6 +177,7 @@ window.initializeVoiceClient = (() => {
|
||||||
this.taskState = TASKSTATE_LOADING;
|
this.taskState = TASKSTATE_LOADING;
|
||||||
const self = this;
|
const self = this;
|
||||||
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then((stream) => {
|
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then((stream) => {
|
||||||
|
self.microphoneVolumeAudioContext = new AudioContext();
|
||||||
self.localRawMediaStream = stream;
|
self.localRawMediaStream = stream;
|
||||||
self.localRawMediaStream.getAudioTracks()[0].enabled = false;
|
self.localRawMediaStream.getAudioTracks()[0].enabled = false;
|
||||||
self.localMediaStream = self.microphoneVolumeAudioContext.createMediaStreamDestination();
|
self.localMediaStream = self.microphoneVolumeAudioContext.createMediaStreamDestination();
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>eagler</title>
|
<title>eagler</title>
|
||||||
<script type="text/javascript" src="classes.js"></script>
|
|
||||||
<script type="text/javascript" src="eagswebrtc.js"></script>
|
<script type="text/javascript" src="eagswebrtc.js"></script>
|
||||||
|
<script type="text/javascript" src="classes.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
if(document.location.href.startsWith("file:")) {
|
if(document.location.href.startsWith("file:")) {
|
||||||
alert("You're not supposed to 'open' this file in your browser. Please upload this folder to your HTTP(s) server and access it via the internet. This is not a bug, please read the documentation");
|
alert("You're not supposed to 'open' this file in your browser. Please upload this folder to your HTTP(s) server and access it via the internet. This is not a bug, please read the documentation");
|
||||||
|
@ -27,4 +27,4 @@ main();
|
||||||
</head>
|
</head>
|
||||||
<body style="margin:0px;width:100vw;height:100vh;" id="game_frame">
|
<body style="margin:0px;width:100vw;height:100vh;" id="game_frame">
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -13,6 +13,11 @@ public class ExpiringSet<T> extends HashSet<T> {
|
||||||
|
|
||||||
private final Map<T, Long> timestamps = new HashMap<>();
|
private final Map<T, Long> timestamps = new HashMap<>();
|
||||||
|
|
||||||
|
public ExpiringSet(long expiration) {
|
||||||
|
this.expiration = expiration;
|
||||||
|
this.event = null;
|
||||||
|
}
|
||||||
|
|
||||||
public ExpiringSet(long expiration, ExpiringEvent<T> event) {
|
public ExpiringSet(long expiration, ExpiringEvent<T> event) {
|
||||||
this.expiration = expiration;
|
this.expiration = expiration;
|
||||||
this.event = event;
|
this.event = event;
|
||||||
|
@ -29,7 +34,7 @@ public class ExpiringSet<T> extends HashSet<T> {
|
||||||
T element = iterator.next();
|
T element = iterator.next();
|
||||||
if (super.contains(element)) {
|
if (super.contains(element)) {
|
||||||
if (this.timestamps.get(element) + this.expiration < now) {
|
if (this.timestamps.get(element) + this.expiration < now) {
|
||||||
this.event.onExpiration(element);
|
if (this.event != null) this.event.onExpiration(element);
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
super.remove(element);
|
super.remove(element);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1125,18 +1125,19 @@ public class Minecraft implements Runnable {
|
||||||
|
|
||||||
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) {
|
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) {
|
||||||
if (this.theWorld != null && this.thePlayer != null) {
|
if (this.theWorld != null && this.thePlayer != null) {
|
||||||
|
HashSet<String> seenPlayers = new HashSet<>();
|
||||||
for (Object playerObject : this.theWorld.playerEntities) {
|
for (Object playerObject : this.theWorld.playerEntities) {
|
||||||
EntityPlayer player = (EntityPlayer) playerObject;
|
EntityPlayer player = (EntityPlayer) playerObject;
|
||||||
if (player == this.thePlayer) continue;
|
if (player == this.thePlayer) continue;
|
||||||
EaglerAdapter.updateVoicePosition(player.username, player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
EaglerAdapter.updateVoicePosition(player.username, player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||||
int prox = EaglerAdapter.getVoiceProximity();
|
int prox = EaglerAdapter.getVoiceProximity();
|
||||||
// cube
|
// cube
|
||||||
if (Math.abs(thePlayer.posX - player.posX) < prox && Math.abs(thePlayer.posY - player.posY) < prox && Math.abs(thePlayer.posZ - player.posZ) < prox) {
|
if (Math.abs(thePlayer.posX - player.posX) <= prox && Math.abs(thePlayer.posY - player.posY) <= prox && Math.abs(thePlayer.posZ - player.posZ) <= prox) {
|
||||||
EaglerAdapter.addNearbyPlayer(player.username);
|
EaglerAdapter.addNearbyPlayer(player.username);
|
||||||
} else {
|
seenPlayers.add(player.username);
|
||||||
EaglerAdapter.removeNearbyPlayer(player.username);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
EaglerAdapter.cleanupNearbyPlayers(seenPlayers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.io.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -16,6 +15,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.lax1dude.eaglercraft.*;
|
import net.lax1dude.eaglercraft.*;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -2118,13 +2118,16 @@ public class EaglerAdapterImpl2 {
|
||||||
});
|
});
|
||||||
|
|
||||||
public static final void removeNearbyPlayer(String username) {
|
public static final void removeNearbyPlayer(String username) {
|
||||||
// todo: add 5-10s disconnect delay
|
|
||||||
if (nearbyPlayers.remove(username)) {
|
if (nearbyPlayers.remove(username)) {
|
||||||
if (getVoiceStatus() == Voice.VoiceStatus.DISCONNECTED || getVoiceStatus() == Voice.VoiceStatus.UNAVAILABLE) return;
|
if (getVoiceStatus() == Voice.VoiceStatus.DISCONNECTED || getVoiceStatus() == Voice.VoiceStatus.UNAVAILABLE) return;
|
||||||
recentlyNearbyPlayers.add(username);
|
recentlyNearbyPlayers.add(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final void cleanupNearbyPlayers(HashSet<String> existingPlayers) {
|
||||||
|
nearbyPlayers.stream().filter(un -> !existingPlayers.contains(un)).collect(Collectors.toSet()).forEach(EaglerAdapterImpl2::removeNearbyPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
public static final void updateVoicePosition(String username, double x, double y, double z) {
|
public static final void updateVoicePosition(String username, double x, double y, double z) {
|
||||||
if (voicePanners.containsKey(username)) voicePanners.get(username).setPosition((float) x, (float) y, (float) z);
|
if (voicePanners.containsKey(username)) voicePanners.get(username).setPosition((float) x, (float) y, (float) z);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user