mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
change ws library, start "restart" netcode, fix some marble move bugs
This commit is contained in:
parent
75e9c13579
commit
3bad263e89
13 changed files with 164 additions and 76 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
-cp src
|
-cp src
|
||||||
-lib hxWebSockets
|
-lib colyseus-websocket
|
||||||
-lib datachannel
|
-lib datachannel
|
||||||
-lib heaps
|
-lib heaps
|
||||||
-lib stb_ogg_sound
|
-lib stb_ogg_sound
|
||||||
|
|
@ -10,5 +10,6 @@
|
||||||
-D keep-inline-positions
|
-D keep-inline-positions
|
||||||
-D highDPI
|
-D highDPI
|
||||||
-D analyzer-optimize
|
-D analyzer-optimize
|
||||||
|
--dce full
|
||||||
--main Main
|
--main Main
|
||||||
-debug
|
-debug
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
-cp src
|
-cp src
|
||||||
-lib heaps
|
-lib heaps
|
||||||
-lib hlsdl
|
-lib hlsdl
|
||||||
-lib hxWebSockets
|
-lib colyseus-websocket
|
||||||
-lib datachannel
|
-lib datachannel
|
||||||
-hl marblegame.hl
|
-hl marblegame.hl
|
||||||
-D windowSize=1280x720
|
-D windowSize=1280x720
|
||||||
|
|
|
||||||
|
|
@ -1796,17 +1796,23 @@ class Marble extends GameObject {
|
||||||
|
|
||||||
public function updateServer(timeState:TimeState, collisionWorld:CollisionWorld, pathedInteriors:Array<PathedInterior>) {
|
public function updateServer(timeState:TimeState, collisionWorld:CollisionWorld, pathedInteriors:Array<PathedInterior>) {
|
||||||
var move:NetMove = null;
|
var move:NetMove = null;
|
||||||
if (this.controllable && this.mode != Finish && !MarbleGame.instance.paused && !this.level.isWatching && !this.level.isReplayingMovement) {
|
if (this.controllable && this.mode != Finish) {
|
||||||
if (Net.isClient) {
|
if (Net.isClient) {
|
||||||
var axis = getMarbleAxis()[1];
|
var axis = getMarbleAxis()[1];
|
||||||
move = Net.clientConnection.recordMove(cast this, axis, timeState, recvServerTick);
|
move = Net.clientConnection.recordMove(cast this, axis, timeState, recvServerTick);
|
||||||
} else if (Net.isHost) {
|
} else if (Net.isHost) {
|
||||||
var axis = getMarbleAxis()[1];
|
var axis = getMarbleAxis()[1];
|
||||||
var innerMove = recordMove();
|
var innerMove = recordMove();
|
||||||
var qx = Std.int((innerMove.d.x * 16) + 16);
|
if (MarbleGame.instance.paused) {
|
||||||
var qy = Std.int((innerMove.d.y * 16) + 16);
|
innerMove.d.x = 0;
|
||||||
innerMove.d.x = (qx - 16) / 16.0;
|
innerMove.d.y = 0;
|
||||||
innerMove.d.y = (qy - 16) / 16.0;
|
innerMove.blast = innerMove.jump = innerMove.powerup = false;
|
||||||
|
} else {
|
||||||
|
var qx = Std.int((innerMove.d.x * 16) + 16);
|
||||||
|
var qy = Std.int((innerMove.d.y * 16) + 16);
|
||||||
|
innerMove.d.x = (qx - 16) / 16.0;
|
||||||
|
innerMove.d.y = (qy - 16) / 16.0;
|
||||||
|
}
|
||||||
move = new NetMove(innerMove, axis, timeState, recvServerTick, 65535);
|
move = new NetMove(innerMove, axis, timeState, recvServerTick, 65535);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1844,7 +1850,7 @@ class Marble extends GameObject {
|
||||||
advancePhysics(timeState, move.move, collisionWorld, pathedInteriors);
|
advancePhysics(timeState, move.move, collisionWorld, pathedInteriors);
|
||||||
physicsAccumulator = 0;
|
physicsAccumulator = 0;
|
||||||
|
|
||||||
if (move.move.jump && this.outOfBounds) {
|
if (move.move.jump && this.outOfBounds && Net.isHost) {
|
||||||
this.level.cancel(this.oobSchedule);
|
this.level.cancel(this.oobSchedule);
|
||||||
this.level.restart(cast this);
|
this.level.restart(cast this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import net.MasterServerClient;
|
||||||
import gui.MultiplayerLevelSelectGui;
|
import gui.MultiplayerLevelSelectGui;
|
||||||
import net.NetCommands;
|
import net.NetCommands;
|
||||||
import net.Net;
|
import net.Net;
|
||||||
|
|
@ -183,6 +184,7 @@ class MarbleGame {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(dt:Float) {
|
public function update(dt:Float) {
|
||||||
|
MasterServerClient.process();
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
if (world._disposed) {
|
if (world._disposed) {
|
||||||
world = null;
|
world = null;
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,8 @@ class MarbleWorld extends Scheduler {
|
||||||
// Multiplayer
|
// Multiplayer
|
||||||
public var isMultiplayer:Bool;
|
public var isMultiplayer:Bool;
|
||||||
|
|
||||||
public var startRealTime:Float = 0;
|
public var serverStartTicks:Int;
|
||||||
|
public var startTime:Float = 1e8;
|
||||||
public var multiplayerStarted:Bool = false;
|
public var multiplayerStarted:Bool = false;
|
||||||
|
|
||||||
var tickAccumulator:Float = 0.0;
|
var tickAccumulator:Float = 0.0;
|
||||||
|
|
@ -511,6 +512,16 @@ class MarbleWorld extends Scheduler {
|
||||||
NetCommands.clientIsReady(Net.clientId);
|
NetCommands.clientIsReady(Net.clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function restartMultiplayerState() {
|
||||||
|
if (this.isMultiplayer) {
|
||||||
|
serverStartTicks = 0;
|
||||||
|
lastMoves = new MarbleUpdateQueue();
|
||||||
|
predictions = new MarblePredictionStore();
|
||||||
|
powerupPredictions = new PowerupPredictionStore();
|
||||||
|
gemPredictions = new GemPredictionStore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function restart(marble:Marble, full:Bool = false) {
|
public function restart(marble:Marble, full:Bool = false) {
|
||||||
Console.log("LEVEL RESTART");
|
Console.log("LEVEL RESTART");
|
||||||
if (!full && this.currentCheckpoint != null) {
|
if (!full && this.currentCheckpoint != null) {
|
||||||
|
|
@ -536,6 +547,7 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
this.timeState.currentAttemptTime = 0;
|
this.timeState.currentAttemptTime = 0;
|
||||||
this.timeState.gameplayClock = this.gameMode.getStartTime();
|
this.timeState.gameplayClock = this.gameMode.getStartTime();
|
||||||
|
this.timeState.ticks = 0;
|
||||||
this.bonusTime = 0;
|
this.bonusTime = 0;
|
||||||
this.marble.outOfBounds = false;
|
this.marble.outOfBounds = false;
|
||||||
this.marble.blastAmount = 0;
|
this.marble.blastAmount = 0;
|
||||||
|
|
@ -679,7 +691,7 @@ class MarbleWorld extends Scheduler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function allClientsReady() {
|
public function allClientsReady() {
|
||||||
NetCommands.setStartTime(3); // Start after 3 seconds
|
NetCommands.setStartTicks(this.timeState.ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateGameState() {
|
public function updateGameState() {
|
||||||
|
|
@ -696,8 +708,9 @@ class MarbleWorld extends Scheduler {
|
||||||
this.marble.setMode(Play);
|
this.marble.setMode(Play);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!this.multiplayerStarted) {
|
if (!this.multiplayerStarted && this.finishTime == null) {
|
||||||
if (this.startRealTime != 0 && this.timeState.timeSinceLoad > this.startRealTime) {
|
if ((Net.isHost && (this.timeState.timeSinceLoad >= startTime)) // 3.5 == 109 ticks
|
||||||
|
|| (Net.isClient && this.serverStartTicks != 0 && @:privateAccess this.marble.serverTicks >= this.serverStartTicks + 109)) {
|
||||||
this.multiplayerStarted = true;
|
this.multiplayerStarted = true;
|
||||||
this.marble.setMode(Play);
|
this.marble.setMode(Play);
|
||||||
for (client => marble in this.clientMarbles)
|
for (client => marble in this.clientMarbles)
|
||||||
|
|
@ -1637,10 +1650,15 @@ class MarbleWorld extends Scheduler {
|
||||||
timeTravelSound.stop();
|
timeTravelSound.stop();
|
||||||
timeTravelSound = null;
|
timeTravelSound = null;
|
||||||
}
|
}
|
||||||
if (this.timeState.currentAttemptTime + skipStartBugPauseTime >= 3.5) {
|
|
||||||
|
if (!this.isMultiplayer) {
|
||||||
|
if (this.timeState.currentAttemptTime + skipStartBugPauseTime >= 3.5) {
|
||||||
|
this.timeState.gameplayClock += dt * timeMultiplier;
|
||||||
|
} else if (this.timeState.currentAttemptTime + dt >= 3.5) {
|
||||||
|
this.timeState.gameplayClock += ((this.timeState.currentAttemptTime + dt) - 3.5) * timeMultiplier;
|
||||||
|
}
|
||||||
|
} else if (this.multiplayerStarted) {
|
||||||
this.timeState.gameplayClock += dt * timeMultiplier;
|
this.timeState.gameplayClock += dt * timeMultiplier;
|
||||||
} else if (this.timeState.currentAttemptTime + dt >= 3.5) {
|
|
||||||
this.timeState.gameplayClock += ((this.timeState.currentAttemptTime + dt) - 3.5) * timeMultiplier;
|
|
||||||
}
|
}
|
||||||
if (this.timeState.gameplayClock < 0)
|
if (this.timeState.gameplayClock < 0)
|
||||||
this.gameMode.onTimeExpire();
|
this.gameMode.onTimeExpire();
|
||||||
|
|
@ -1990,6 +2008,9 @@ class MarbleWorld extends Scheduler {
|
||||||
if (Util.isTouchDevice()) {
|
if (Util.isTouchDevice()) {
|
||||||
MarbleGame.instance.touchInput.setControlsEnabled(true);
|
MarbleGame.instance.touchInput.setControlsEnabled(true);
|
||||||
}
|
}
|
||||||
|
if (this.isMultiplayer) {
|
||||||
|
NetCommands.restartGame();
|
||||||
|
}
|
||||||
// @:privateAccess playGui.playGuiCtrl.render(scene2d);
|
// @:privateAccess playGui.playGuiCtrl.render(scene2d);
|
||||||
}
|
}
|
||||||
if (MarbleGame.instance.toRecord) {
|
if (MarbleGame.instance.toRecord) {
|
||||||
|
|
@ -2166,7 +2187,7 @@ class MarbleWorld extends Scheduler {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (Net.isHost) {
|
if (!this.isMultiplayer || Net.isHost) {
|
||||||
marble.oobSchedule = this.schedule(this.timeState.currentAttemptTime + 2.5, () -> {
|
marble.oobSchedule = this.schedule(this.timeState.currentAttemptTime + 2.5, () -> {
|
||||||
this.restart(marble);
|
this.restart(marble);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import hxd.Key;
|
||||||
import shaders.RendererDefaultPass;
|
import shaders.RendererDefaultPass;
|
||||||
import hxd.Window;
|
import hxd.Window;
|
||||||
import src.ResourceLoader;
|
import src.ResourceLoader;
|
||||||
|
|
@ -193,6 +194,18 @@ class Renderer extends h3d.scene.Renderer {
|
||||||
copyPass.render();
|
copyPass.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cubemapPass) {
|
||||||
|
#if sys
|
||||||
|
if (Key.isDown(Key.CTRL) && Key.isPressed(Key.P)) {
|
||||||
|
var pixels = backBuffer.capturePixels();
|
||||||
|
var filename = StringTools.replace('Screenshot ${Date.now().toString()}.png', ":", ".");
|
||||||
|
var pixdata = pixels.toPNG();
|
||||||
|
hxd.File.createDirectory("data/screenshots");
|
||||||
|
hxd.File.saveBytes("data/screenshots/" + filename, pixdata);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
// h3d.pass.Copy.run(backBuffers[0], backBuffers[1]);
|
// h3d.pass.Copy.run(backBuffers[0], backBuffers[1]);
|
||||||
// renderPass(defaultPass, get("refract"));
|
// renderPass(defaultPass, get("refract"));
|
||||||
// ctx.engine.popTarget();
|
// ctx.engine.popTarget();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ class EndGameGui extends GuiImage {
|
||||||
var mission:Mission;
|
var mission:Mission;
|
||||||
var innerCtrl:GuiControl;
|
var innerCtrl:GuiControl;
|
||||||
var endGameWnd:GuiImage;
|
var endGameWnd:GuiImage;
|
||||||
|
var retryFunc:GuiControl->Void;
|
||||||
|
var nextFunc:GuiControl->Void;
|
||||||
|
var continueFunc:GuiControl->Void;
|
||||||
|
|
||||||
var scoreSubmitted:Bool = false;
|
var scoreSubmitted:Bool = false;
|
||||||
|
|
||||||
|
|
@ -31,6 +34,9 @@ class EndGameGui extends GuiImage {
|
||||||
this.position = new Vector(0, 0);
|
this.position = new Vector(0, 0);
|
||||||
this.extent = new Vector(640, 480);
|
this.extent = new Vector(640, 480);
|
||||||
this.mission = mission;
|
this.mission = mission;
|
||||||
|
this.retryFunc = restartFunc;
|
||||||
|
this.nextFunc = nextLevelFunc;
|
||||||
|
this.continueFunc = continueFunc;
|
||||||
|
|
||||||
function loadButtonImages(path:String) {
|
function loadButtonImages(path:String) {
|
||||||
var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile();
|
var normal = ResourceLoader.getResource('${path}_n.png', ResourceLoader.getImage, this.imageResources).toTile();
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,18 @@ class MPServerListGui extends GuiImage {
|
||||||
nextButton.gamepadAccelerator = ["X"];
|
nextButton.gamepadAccelerator = ["X"];
|
||||||
nextButton.pressedAction = (e) -> {
|
nextButton.pressedAction = (e) -> {
|
||||||
MarbleGame.canvas.setContent(new MultiplayerLoadingGui("Connecting"));
|
MarbleGame.canvas.setContent(new MultiplayerLoadingGui("Connecting"));
|
||||||
|
var failed = true;
|
||||||
|
haxe.Timer.delay(() -> {
|
||||||
|
if (failed) {
|
||||||
|
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, () -> {
|
Net.joinServer(ourServerList[curSelection].name, () -> {
|
||||||
|
failed = false;
|
||||||
MarbleGame.canvas.setContent(new MultiplayerLevelSelectGui(false));
|
MarbleGame.canvas.setContent(new MultiplayerLevelSelectGui(false));
|
||||||
Net.remoteServerInfo = ourServerList[curSelection];
|
Net.remoteServerInfo = ourServerList[curSelection];
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -665,6 +665,30 @@ class PlayGui {
|
||||||
playerListScoresCtrl.setTexts(plScores);
|
playerListScoresCtrl.setTexts(plScores);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function doMPEndGameMessage() {
|
||||||
|
playerList.sort((a, b) -> a.score > b.score ? -1 : (a.score < b.score ? 1 : 0));
|
||||||
|
var p1 = playerList[0];
|
||||||
|
var p2 = playerList.length > 1 ? playerList[1] : null;
|
||||||
|
if (p2 == null) {
|
||||||
|
var onePt = p1.score == 1;
|
||||||
|
if (onePt)
|
||||||
|
MarbleGame.instance.world.displayAlert('${p1.name} won with 1 point!');
|
||||||
|
else
|
||||||
|
MarbleGame.instance.world.displayAlert('${p1.name} won with ${p1.score} points!');
|
||||||
|
} else {
|
||||||
|
var tie = p1.score == p2.score;
|
||||||
|
if (tie) {
|
||||||
|
MarbleGame.instance.world.displayAlert('Game tied!');
|
||||||
|
} else {
|
||||||
|
var onePt = p1.score == 1;
|
||||||
|
if (onePt)
|
||||||
|
MarbleGame.instance.world.displayAlert('${p1.name} won with 1 point!');
|
||||||
|
else
|
||||||
|
MarbleGame.instance.world.displayAlert('${p1.name} won with ${p1.score} points!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function addPlayer(id:Int, name:String, us:Bool) {
|
public function addPlayer(id:Int, name:String, us:Bool) {
|
||||||
playerList.push({
|
playerList.push({
|
||||||
id: id,
|
id: id,
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ class HuntMode extends NullMode {
|
||||||
if (!this.level.isMultiplayer || Net.isHost) {
|
if (!this.level.isMultiplayer || Net.isHost) {
|
||||||
rng.setSeed(100);
|
rng.setSeed(100);
|
||||||
rng2.setSeed(100);
|
rng2.setSeed(100);
|
||||||
if (Settings.optionsSettings.huntRandom) {
|
if (Settings.optionsSettings.huntRandom || Net.isMP) {
|
||||||
rng.setSeed(cast Math.random() * 10000);
|
rng.setSeed(cast Math.random() * 10000);
|
||||||
rng2.setSeed(cast Math.random() * 10000);
|
rng2.setSeed(cast Math.random() * 10000);
|
||||||
}
|
}
|
||||||
|
|
@ -592,7 +592,11 @@ class HuntMode extends NullMode {
|
||||||
level.marble.camera.finish = true;
|
level.marble.camera.finish = true;
|
||||||
level.finishYaw = level.marble.camera.CameraYaw;
|
level.finishYaw = level.marble.camera.CameraYaw;
|
||||||
level.finishPitch = level.marble.camera.CameraPitch;
|
level.finishPitch = level.marble.camera.CameraPitch;
|
||||||
level.displayAlert("Congratulations! You've finished!");
|
if (level.isMultiplayer) {
|
||||||
|
@:privateAccess level.playGui.doMPEndGameMessage();
|
||||||
|
} else {
|
||||||
|
level.displayAlert("Congratulations! You've finished!");
|
||||||
|
}
|
||||||
level.cancel(@:privateAccess level.oobSchedule);
|
level.cancel(@:privateAccess level.oobSchedule);
|
||||||
level.cancel(@:privateAccess level.marble.oobSchedule);
|
level.cancel(@:privateAccess level.marble.oobSchedule);
|
||||||
if (!level.isWatching) {
|
if (!level.isWatching) {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ import gui.MessageBoxOkDlg;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
import haxe.Json;
|
import haxe.Json;
|
||||||
import net.Net.ServerInfo;
|
import net.Net.ServerInfo;
|
||||||
import hx.ws.WebSocket;
|
import haxe.net.WebSocket;
|
||||||
import src.Console;
|
import src.Console;
|
||||||
import hx.ws.Types.MessageType;
|
|
||||||
import gui.MultiplayerLoadingGui;
|
import gui.MultiplayerLoadingGui;
|
||||||
|
|
||||||
typedef RemoteServerInfo = {
|
typedef RemoteServerInfo = {
|
||||||
|
|
@ -26,29 +25,23 @@ class MasterServerClient {
|
||||||
var open = false;
|
var open = false;
|
||||||
|
|
||||||
public function new(onOpenFunc:() -> Void) {
|
public function new(onOpenFunc:() -> Void) {
|
||||||
#if sys
|
ws = WebSocket.create(serverIp);
|
||||||
var senderThread = sys.thread.Thread.current();
|
|
||||||
#end
|
|
||||||
ws = new WebSocket(serverIp);
|
|
||||||
ws.onopen = () -> {
|
ws.onopen = () -> {
|
||||||
open = true;
|
open = true;
|
||||||
#if sys
|
|
||||||
senderThread.events.run(onOpenFunc);
|
|
||||||
#end
|
|
||||||
#if js
|
|
||||||
onOpenFunc();
|
onOpenFunc();
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
ws.onmessage = (m) -> {
|
ws.onmessageString = (m) -> {
|
||||||
switch (m) {
|
handleMessage(m);
|
||||||
case StrMessage(content):
|
|
||||||
handleMessage(content);
|
|
||||||
case _:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function process() {
|
||||||
|
#if sys
|
||||||
|
if (instance != null)
|
||||||
|
instance.ws.process();
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
public static function connectToMasterServer(onConnect:() -> Void) {
|
public static function connectToMasterServer(onConnect:() -> Void) {
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
instance = new MasterServerClient(onConnect);
|
instance = new MasterServerClient(onConnect);
|
||||||
|
|
@ -71,7 +64,7 @@ class MasterServerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendServerInfo(serverInfo:ServerInfo) {
|
public function sendServerInfo(serverInfo:ServerInfo) {
|
||||||
ws.send(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
type: "serverInfo",
|
type: "serverInfo",
|
||||||
name: serverInfo.name,
|
name: serverInfo.name,
|
||||||
players: serverInfo.players,
|
players: serverInfo.players,
|
||||||
|
|
@ -84,7 +77,7 @@ class MasterServerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendConnectToServer(serverName:String, sdp:String) {
|
public function sendConnectToServer(serverName:String, sdp:String) {
|
||||||
ws.send(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
type: "connect",
|
type: "connect",
|
||||||
serverName: serverName,
|
serverName: serverName,
|
||||||
sdp: sdp
|
sdp: sdp
|
||||||
|
|
@ -93,7 +86,7 @@ class MasterServerClient {
|
||||||
|
|
||||||
public function getServerList(serverListCb:Array<RemoteServerInfo>->Void) {
|
public function getServerList(serverListCb:Array<RemoteServerInfo>->Void) {
|
||||||
this.serverListCb = serverListCb;
|
this.serverListCb = serverListCb;
|
||||||
ws.send(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
type: "serverList"
|
type: "serverList"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +101,7 @@ class MasterServerClient {
|
||||||
}
|
}
|
||||||
if (conts.type == "connect") {
|
if (conts.type == "connect") {
|
||||||
if (!Net.isHost) {
|
if (!Net.isHost) {
|
||||||
ws.send(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
type: "connectFailed",
|
type: "connectFailed",
|
||||||
success: false,
|
success: false,
|
||||||
reason: "The server has shut down"
|
reason: "The server has shut down"
|
||||||
|
|
@ -116,7 +109,7 @@ class MasterServerClient {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Net.serverInfo.players >= Net.serverInfo.maxPlayers) {
|
if (Net.serverInfo.players >= Net.serverInfo.maxPlayers) {
|
||||||
ws.send(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
type: "connectFailed",
|
type: "connectFailed",
|
||||||
success: false,
|
success: false,
|
||||||
reason: "The server is full"
|
reason: "The server is full"
|
||||||
|
|
@ -124,7 +117,7 @@ class MasterServerClient {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Net.addClientFromSdp(conts.sdp, (sdpReply) -> {
|
Net.addClientFromSdp(conts.sdp, (sdpReply) -> {
|
||||||
ws.send(Json.stringify({
|
ws.sendString(Json.stringify({
|
||||||
success: true,
|
success: true,
|
||||||
type: "connectResponse",
|
type: "connectResponse",
|
||||||
sdp: sdpReply,
|
sdp: sdpReply,
|
||||||
|
|
|
||||||
|
|
@ -70,39 +70,47 @@ class MoveManager {
|
||||||
}
|
}
|
||||||
var move = new Move();
|
var move = new Move();
|
||||||
move.d = new Vector();
|
move.d = new Vector();
|
||||||
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
|
if (!MarbleGame.instance.paused) {
|
||||||
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
|
move.d.x = Gamepad.getAxis(Settings.gamepadSettings.moveYAxis);
|
||||||
if (Key.isDown(Settings.controlsSettings.forward)) {
|
move.d.y = -Gamepad.getAxis(Settings.gamepadSettings.moveXAxis);
|
||||||
move.d.x -= 1;
|
if (Key.isDown(Settings.controlsSettings.forward)) {
|
||||||
}
|
move.d.x -= 1;
|
||||||
if (Key.isDown(Settings.controlsSettings.backward)) {
|
}
|
||||||
move.d.x += 1;
|
if (Key.isDown(Settings.controlsSettings.backward)) {
|
||||||
}
|
move.d.x += 1;
|
||||||
if (Key.isDown(Settings.controlsSettings.left)) {
|
}
|
||||||
move.d.y += 1;
|
if (Key.isDown(Settings.controlsSettings.left)) {
|
||||||
}
|
move.d.y += 1;
|
||||||
if (Key.isDown(Settings.controlsSettings.right)) {
|
}
|
||||||
move.d.y -= 1;
|
if (Key.isDown(Settings.controlsSettings.right)) {
|
||||||
}
|
move.d.y -= 1;
|
||||||
if (Key.isDown(Settings.controlsSettings.jump)
|
}
|
||||||
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
if (Key.isDown(Settings.controlsSettings.jump)
|
||||||
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
|| MarbleGame.instance.touchInput.jumpButton.pressed
|
||||||
move.jump = true;
|
|| Gamepad.isDown(Settings.gamepadSettings.jump)) {
|
||||||
}
|
move.jump = true;
|
||||||
if ((!Util.isTouchDevice() && Key.isDown(Settings.controlsSettings.powerup))
|
}
|
||||||
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
if ((!Util.isTouchDevice() && Key.isDown(Settings.controlsSettings.powerup))
|
||||||
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
|| (Util.isTouchDevice() && MarbleGame.instance.touchInput.powerupButton.pressed)
|
||||||
move.powerup = true;
|
|| Gamepad.isDown(Settings.gamepadSettings.powerup)) {
|
||||||
}
|
move.powerup = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (Key.isDown(Settings.controlsSettings.blast)
|
if (Key.isDown(Settings.controlsSettings.blast)
|
||||||
|| (MarbleGame.instance.touchInput.blastbutton.pressed)
|
|| (MarbleGame.instance.touchInput.blastbutton.pressed)
|
||||||
|| Gamepad.isDown(Settings.gamepadSettings.blast))
|
|| Gamepad.isDown(Settings.gamepadSettings.blast))
|
||||||
move.blast = true;
|
move.blast = true;
|
||||||
|
|
||||||
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
if (MarbleGame.instance.touchInput.movementInput.pressed) {
|
||||||
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x;
|
||||||
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
move.d.x = MarbleGame.instance.touchInput.movementInput.value.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// quantize moves for client
|
||||||
|
var qx = Std.int((move.d.x * 16) + 16);
|
||||||
|
var qy = Std.int((move.d.y * 16) + 16);
|
||||||
|
move.d.x = (qx - 16) / 16.0;
|
||||||
|
move.d.y = (qy - 16) / 16.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var netMove = new NetMove(move, motionDir, timeState.clone(), serverTicks, nextMoveId++);
|
var netMove = new NetMove(move, motionDir, timeState.clone(), serverTicks, nextMoveId++);
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,9 @@ import net.NetPacket.MarbleMovePacket;
|
||||||
import haxe.Json;
|
import haxe.Json;
|
||||||
import datachannel.RTCPeerConnection;
|
import datachannel.RTCPeerConnection;
|
||||||
import datachannel.RTCDataChannel;
|
import datachannel.RTCDataChannel;
|
||||||
import hx.ws.WebSocket;
|
|
||||||
import src.Console;
|
import src.Console;
|
||||||
import net.NetCommands;
|
import net.NetCommands;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
import hx.ws.Types.MessageType;
|
|
||||||
import src.Settings;
|
import src.Settings;
|
||||||
|
|
||||||
enum abstract NetPacketType(Int) from Int to Int {
|
enum abstract NetPacketType(Int) from Int to Int {
|
||||||
|
|
@ -371,7 +369,8 @@ class Net {
|
||||||
var movePacket = new MarbleMovePacket();
|
var movePacket = new MarbleMovePacket();
|
||||||
movePacket.deserialize(input);
|
movePacket.deserialize(input);
|
||||||
var cc = clientIdMap[movePacket.clientId];
|
var cc = clientIdMap[movePacket.clientId];
|
||||||
cc.queueMove(movePacket.move);
|
if (cc.state == GAME)
|
||||||
|
cc.queueMove(movePacket.move);
|
||||||
|
|
||||||
case PowerupPickup:
|
case PowerupPickup:
|
||||||
var powerupPickupPacket = new PowerupPickupPacket();
|
var powerupPickupPacket = new PowerupPickupPacket();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue