mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix touch buttons, make master server async on native, fix minor crash
This commit is contained in:
parent
89bbbe777a
commit
f76c7a7c39
4 changed files with 122 additions and 37 deletions
|
|
@ -146,12 +146,14 @@ class MPServerListGui extends GuiImage {
|
|||
var failed = true;
|
||||
haxe.Timer.delay(() -> {
|
||||
if (failed) {
|
||||
if (MarbleGame.canvas.content is MultiplayerLoadingGui) {
|
||||
var loadGui:MultiplayerLoadingGui = cast MarbleGame.canvas.content;
|
||||
if (loadGui != null) {
|
||||
loadGui.setErrorStatus("Failed to connect to server");
|
||||
Net.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 15000);
|
||||
Net.joinServer(ourServerList[curSelection].name, false, () -> {
|
||||
failed = false;
|
||||
|
|
|
|||
|
|
@ -24,27 +24,99 @@ class MasterServerClient {
|
|||
|
||||
var open = false;
|
||||
|
||||
#if hl
|
||||
var wsThread:sys.thread.Thread;
|
||||
static var responses:sys.thread.Deque<() -> Void> = new sys.thread.Deque<() -> Void>();
|
||||
var toSend:sys.thread.Deque<String> = new sys.thread.Deque<String>();
|
||||
var stopping:Bool = false;
|
||||
var stopMutex: sys.thread.Mutex = new sys.thread.Mutex();
|
||||
#end
|
||||
|
||||
public function new(onOpenFunc:() -> Void) {
|
||||
#if hl
|
||||
wsThread = sys.thread.Thread.create(() -> {
|
||||
#end
|
||||
ws = WebSocket.create(serverIp);
|
||||
ws.onopen = () -> {
|
||||
open = true;
|
||||
#if hl
|
||||
responses.add(() -> onOpenFunc());
|
||||
#end
|
||||
#if js
|
||||
onOpenFunc();
|
||||
#end
|
||||
}
|
||||
ws.onmessageString = (m) -> {
|
||||
#if hl
|
||||
responses.add(() -> handleMessage(m));
|
||||
#end
|
||||
#if js
|
||||
handleMessage(m);
|
||||
#end
|
||||
}
|
||||
ws.onerror = (m) -> {
|
||||
#if hl
|
||||
responses.add(() -> {
|
||||
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to connect to master server: " + m));
|
||||
});
|
||||
#end
|
||||
#if js
|
||||
MarbleGame.canvas.pushDialog(new MessageBoxOkDlg("Failed to connect to master server: " + m));
|
||||
#end
|
||||
#if hl
|
||||
stopMutex.acquire();
|
||||
#end
|
||||
open = false;
|
||||
ws = null;
|
||||
instance = null;
|
||||
#if hl
|
||||
stopMutex.acquire();
|
||||
stopping = true;
|
||||
stopMutex.release();
|
||||
wsThread = null;
|
||||
#end
|
||||
}
|
||||
ws.onclose = (?e) -> {
|
||||
#if hl
|
||||
stopMutex.acquire();
|
||||
#end
|
||||
open = false;
|
||||
ws = null;
|
||||
instance = null;
|
||||
#if hl
|
||||
stopping = true;
|
||||
stopMutex.release();
|
||||
wsThread = null;
|
||||
#end
|
||||
}
|
||||
#if hl
|
||||
while (true) {
|
||||
stopMutex.acquire();
|
||||
if (stopping)
|
||||
break;
|
||||
while (true) {
|
||||
var s = toSend.pop(false);
|
||||
if (s == null)
|
||||
break;
|
||||
ws.sendString(s);
|
||||
}
|
||||
|
||||
ws.process();
|
||||
stopMutex.release();
|
||||
Sys.sleep(0.1);
|
||||
}
|
||||
#end
|
||||
#if hl
|
||||
});
|
||||
#end
|
||||
}
|
||||
|
||||
public static function process() {
|
||||
#if sys
|
||||
if (instance != null)
|
||||
instance.ws.process();
|
||||
var resp = responses.pop(false);
|
||||
if (resp != null) {
|
||||
resp();
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +128,6 @@ class MasterServerClient {
|
|||
onConnect();
|
||||
else {
|
||||
instance.ws.close();
|
||||
instance = null;
|
||||
instance = new MasterServerClient(onConnect);
|
||||
}
|
||||
}
|
||||
|
|
@ -65,18 +136,26 @@ class MasterServerClient {
|
|||
public static function disconnectFromMasterServer() {
|
||||
if (instance != null) {
|
||||
instance.ws.close();
|
||||
instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
function queueMessage(m:String) {
|
||||
#if hl
|
||||
toSend.add(m);
|
||||
#end
|
||||
#if js
|
||||
ws.sendString(m);
|
||||
#end
|
||||
}
|
||||
|
||||
public function heartBeat() {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "heartbeat"
|
||||
}));
|
||||
}
|
||||
|
||||
public function sendServerInfo(serverInfo:ServerInfo) {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "serverInfo",
|
||||
name: serverInfo.name,
|
||||
players: serverInfo.players,
|
||||
|
|
@ -91,13 +170,13 @@ class MasterServerClient {
|
|||
|
||||
public function sendConnectToServer(serverName:String, sdp:String, isInvite:Bool = false) {
|
||||
if (!isInvite) {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "connect",
|
||||
serverName: serverName,
|
||||
sdp: sdp
|
||||
}));
|
||||
} else {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "connectInvite",
|
||||
sdp: sdp,
|
||||
inviteCode: serverName
|
||||
|
|
@ -107,7 +186,7 @@ class MasterServerClient {
|
|||
|
||||
public function getServerList(serverListCb:Array<RemoteServerInfo>->Void) {
|
||||
this.serverListCb = serverListCb;
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "serverList"
|
||||
}));
|
||||
}
|
||||
|
|
@ -122,7 +201,7 @@ class MasterServerClient {
|
|||
}
|
||||
if (conts.type == "connect") {
|
||||
if (!Net.isHost) {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "connectFailed",
|
||||
success: false,
|
||||
reason: "The server has shut down"
|
||||
|
|
@ -132,7 +211,7 @@ class MasterServerClient {
|
|||
var joiningPrivate = conts.isPrivate;
|
||||
|
||||
if (Net.serverInfo.players >= Net.serverInfo.maxPlayers) {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "connectFailed",
|
||||
success: false,
|
||||
reason: "The server is full"
|
||||
|
|
@ -153,7 +232,7 @@ class MasterServerClient {
|
|||
}
|
||||
|
||||
if (!joiningPrivate && pubCount >= pubSlotsAvail) {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
type: "connectFailed",
|
||||
success: false,
|
||||
reason: "The server is full"
|
||||
|
|
@ -166,7 +245,7 @@ class MasterServerClient {
|
|||
}
|
||||
|
||||
Net.addClientFromSdp(conts.sdp, joiningPrivate, (sdpReply) -> {
|
||||
ws.sendString(Json.stringify({
|
||||
queueMessage(Json.stringify({
|
||||
success: true,
|
||||
type: "connectResponse",
|
||||
sdp: sdpReply,
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ class Net {
|
|||
}, 5000);
|
||||
|
||||
clientDatachannel = client.createDatachannel("mp");
|
||||
clientDatachannelUnreliable = client.createDatachannelWithOptions("unreliable", false, 0, 600);
|
||||
clientDatachannelUnreliable = client.createDatachannelWithOptions("unreliable", false, null, 600);
|
||||
|
||||
var closing = false;
|
||||
var openFlags = 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package touch;
|
||||
|
||||
import net.Net;
|
||||
import gui.GuiControl;
|
||||
import src.MarbleWorld;
|
||||
import h3d.Vector;
|
||||
|
|
@ -118,17 +119,18 @@ class TouchInput {
|
|||
this.movementInput = new MovementInput();
|
||||
this.jumpButton = new JumpButton();
|
||||
this.powerupButton = new PowerupButton();
|
||||
if (Settings.optionsSettings.rewindEnabled)
|
||||
if (Settings.optionsSettings.rewindEnabled && !Net.isMP)
|
||||
this.rewindButton = new RewindButton();
|
||||
if (ultra)
|
||||
this.blastbutton = new BlastButton();
|
||||
this.pauseButton = new PauseButton();
|
||||
if (!Net.isMP)
|
||||
this.restartButton = new RestartButton();
|
||||
pauseButton.add(parentGui);
|
||||
restartButton.add(parentGui);
|
||||
jumpButton.add(parentGui);
|
||||
powerupButton.add(parentGui);
|
||||
if (Settings.optionsSettings.rewindEnabled)
|
||||
if (Settings.optionsSettings.rewindEnabled && !Net.isMP)
|
||||
rewindButton.add(parentGui);
|
||||
if (ultra)
|
||||
blastbutton.add(parentGui);
|
||||
|
|
@ -144,6 +146,7 @@ class TouchInput {
|
|||
this.blastbutton.setVisible(enabled);
|
||||
this.movementInput.setVisible(enabled);
|
||||
this.pauseButton.setVisible(enabled);
|
||||
if (this.restartButton != null)
|
||||
this.restartButton.setVisible(enabled);
|
||||
if (this.rewindButton != null)
|
||||
this.rewindButton.setVisible(enabled);
|
||||
|
|
@ -157,6 +160,7 @@ class TouchInput {
|
|||
blastbutton.remove(parentGui);
|
||||
movementInput.remove(parentGui);
|
||||
pauseButton.remove(parentGui);
|
||||
if (this.restartButton != null)
|
||||
restartButton.remove(parentGui);
|
||||
cameraInput.remove(parentGui);
|
||||
if (this.rewindButton != null)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue