From 39fbcc2ec422124b89247dbdaad85a1a0f97f5fe Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:27:58 +0530 Subject: [PATCH] server side only quick respawn --- src/Gamepad.hx | 9 +++++++++ src/Marble.hx | 16 ++++++++++++++++ src/MarbleWorld.hx | 30 ++++++++++++++++-------------- src/gui/MPExitGameDlg.hx | 4 ++++ src/gui/MPPlayMissionGui.hx | 1 + src/net/Move.hx | 1 + src/net/MoveManager.hx | 8 ++++++++ src/touch/RestartButton.hx | 11 +++++++++-- 8 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/Gamepad.hx b/src/Gamepad.hx index 5b7556d3..15a5c97d 100644 --- a/src/Gamepad.hx +++ b/src/Gamepad.hx @@ -83,6 +83,15 @@ class Gamepad { return false; } + public static function releaseKey(buttons:Array) { + for (button in buttons) { + var buttonId = getId(button); + if (buttonId < 0 || buttonId > gamepad.buttons.length) + continue; + @:privateAccess gamepad.buttons[buttonId] = false; + } + } + public static function isPressed(buttons:Array) { if (!hasPad) return false; diff --git a/src/Marble.hx b/src/Marble.hx index 95425e95..fd033963 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -330,6 +330,7 @@ class Marble extends GameObject { var serverTicks:Int; var recvServerTick:Int; var serverUsePowerup:Bool; + var lastRespawnTick:Int = -100000; var trapdoorContacts:Map = []; public function new() { @@ -1049,6 +1050,7 @@ class Marble extends GameObject { a.set(a.x + aFriction.x, a.y + aFriction.y, a.z + aFriction.z); lastContactNormal = bestContact.normal; + lastContactPosition = this.getAbsPos().getPosition(); } a.set(a.x + aControl.x, a.y + aControl.y, a.z + aControl.z); if (this.mode == Finish) { @@ -1863,6 +1865,13 @@ class Marble extends GameObject { for (interior in pathedInteriors) { interior.popTickState(); } + + if (m.respawn) { + if (timeState.ticks - lastRespawnTick > (25000 >> 5)) { + this.level.restart(cast this); + lastRespawnTick = timeState.ticks; + } + } } } @@ -2157,6 +2166,12 @@ class Marble extends GameObject { || Gamepad.isDown(Settings.gamepadSettings.blast)) move.blast = true; + if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) { + move.respawn = true; + @:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0; + Gamepad.releaseKey(Settings.gamepadSettings.respawn); + } + if (MarbleGame.instance.touchInput.movementInput.pressed) { move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x; move.d.x = MarbleGame.instance.touchInput.movementInput.value.y; @@ -2553,6 +2568,7 @@ class Marble extends GameObject { this.contactEntities = []; this.cloak = false; this._firstTick = true; + this.lastRespawnTick = -100000; if (this.teleporting) { var ourDts:DtsObject = cast this.children[0]; ourDts.setOpacity(1); diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 0e35f622..5cf55411 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1803,22 +1803,24 @@ class MarbleWorld extends Scheduler { ProfilerUI.measure("updateTimer"); this.updateTimer(dt); - if ((Key.isPressed(Settings.controlsSettings.respawn) || Gamepad.isPressed(Settings.gamepadSettings.respawn)) - && this.finishTime == null) { - performRestart(); - return; - } - - if ((Key.isDown(Settings.controlsSettings.respawn) - || MarbleGame.instance.touchInput.restartButton.pressed - || Gamepad.isDown(Settings.gamepadSettings.respawn)) - && !this.isWatching - && this.finishTime == null) { - if (timeState.timeSinceLoad - this.respawnPressedTime > 1.5) { - this.restart(this.marble, true); - this.respawnPressedTime = Math.POSITIVE_INFINITY; + if (!this.isMultiplayer) { + if ((Key.isPressed(Settings.controlsSettings.respawn) || Gamepad.isPressed(Settings.gamepadSettings.respawn)) + && this.finishTime == null) { + performRestart(); return; } + + if ((Key.isDown(Settings.controlsSettings.respawn) + || MarbleGame.instance.touchInput.restartButton.pressed + || Gamepad.isDown(Settings.gamepadSettings.respawn)) + && !this.isWatching + && this.finishTime == null) { + if (timeState.timeSinceLoad - this.respawnPressedTime > 1.5) { + this.restart(this.marble, true); + this.respawnPressedTime = Math.POSITIVE_INFINITY; + return; + } + } } this.tickSchedule(timeState.currentAttemptTime); diff --git a/src/gui/MPExitGameDlg.hx b/src/gui/MPExitGameDlg.hx index 9953937c..ea93f826 100644 --- a/src/gui/MPExitGameDlg.hx +++ b/src/gui/MPExitGameDlg.hx @@ -8,6 +8,7 @@ import hxd.res.BitmapFont; import h3d.Vector; import src.ResourceLoader; import src.Settings; +import hxd.Key; class MPExitGameDlg extends GuiControl { public function new(resumeFunc:() -> Void, exitFunc:() -> Void) { @@ -93,6 +94,9 @@ class MPExitGameDlg extends GuiControl { quickspawnBtn.position = new Vector(224, 132); quickspawnBtn.extent = new Vector(104, 45); quickspawnBtn.vertSizing = Top; + quickspawnBtn.pressedAction = (e) -> { + @:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = Key.getFrame() - 1; // jank + } dialogImg.addChild(quickspawnBtn); var completeRestart = new GuiButton(loadButtonImagesExt("data/ui/mp/exit/complete")); diff --git a/src/gui/MPPlayMissionGui.hx b/src/gui/MPPlayMissionGui.hx index d8eb0199..1eb71338 100644 --- a/src/gui/MPPlayMissionGui.hx +++ b/src/gui/MPPlayMissionGui.hx @@ -148,6 +148,7 @@ class MPPlayMissionGui extends GuiImage { leaveBtn.position = new Vector(59, 514); leaveBtn.extent = new Vector(93, 44); leaveBtn.pressedAction = (e) -> { + Net.disconnect(); MarbleGame.canvas.setContent(new JoinServerGui()); } window.addChild(leaveBtn); diff --git a/src/net/Move.hx b/src/net/Move.hx index 22f38775..14252c7a 100644 --- a/src/net/Move.hx +++ b/src/net/Move.hx @@ -7,6 +7,7 @@ class Move { public var jump:Bool; public var powerup:Bool; public var blast:Bool; + public var respawn:Bool; public function new() {} } diff --git a/src/net/MoveManager.hx b/src/net/MoveManager.hx index c70ee194..c0ee1cf8 100644 --- a/src/net/MoveManager.hx +++ b/src/net/MoveManager.hx @@ -105,6 +105,12 @@ class MoveManager { || Gamepad.isDown(Settings.gamepadSettings.blast)) move.blast = true; + if (Key.isDown(Settings.controlsSettings.respawn) || Gamepad.isDown(Settings.gamepadSettings.respawn)) { + move.respawn = true; + @:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = 0; + Gamepad.releaseKey(Settings.gamepadSettings.respawn); + } + if (MarbleGame.instance.touchInput.movementInput.pressed) { move.d.y = -MarbleGame.instance.touchInput.movementInput.value.x; move.d.x = MarbleGame.instance.touchInput.movementInput.value.y; @@ -159,6 +165,7 @@ class MoveManager { b.writeFlag(m.move.jump); b.writeFlag(m.move.powerup); b.writeFlag(m.move.blast); + b.writeFlag(m.move.respawn); b.writeFloat(m.motionDir.x); b.writeFloat(m.motionDir.y); b.writeFloat(m.motionDir.z); @@ -174,6 +181,7 @@ class MoveManager { move.jump = b.readFlag(); move.powerup = b.readFlag(); move.blast = b.readFlag(); + move.respawn = b.readFlag(); var motionDir = new Vector(); motionDir.x = b.readFloat(); motionDir.y = b.readFloat(); diff --git a/src/touch/RestartButton.hx b/src/touch/RestartButton.hx index 29f6e128..af32484d 100644 --- a/src/touch/RestartButton.hx +++ b/src/touch/RestartButton.hx @@ -3,6 +3,8 @@ package touch; import src.MarbleGame; import h3d.Vector; import src.ResourceLoader; +import src.Settings; +import hxd.Key; class RestartButton extends TouchButton { public function new() { @@ -11,8 +13,13 @@ class RestartButton extends TouchButton { this.guiElement.horizSizing = Right; this.guiElement.vertSizing = Bottom; this.onClick = () -> { - if (MarbleGame.instance.world.finishTime == null && !MarbleGame.instance.paused) - MarbleGame.instance.world.performRestart(); + if (MarbleGame.instance.world.finishTime == null && !MarbleGame.instance.paused) { + if (MarbleGame.instance.world.isMultiplayer) { + @:privateAccess Key.keyPressed[Settings.controlsSettings.respawn] = Key.getFrame() - 1; // jank + } else { + MarbleGame.instance.world.performRestart(); + } + } } } }