mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
rendering: use more features of modding api, fix some bugs in ServerListCell
This commit is contained in:
parent
4ad8c4933c
commit
cb27476401
@ -24,6 +24,10 @@ data class Location(val x: Double, val y: Double, val z: Double) {
|
|||||||
return "($x $y $z)"
|
return "($x $y $z)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun toVec3(): Vec3 {
|
||||||
|
return Vec3(x, y, z)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun fromPosition(position: BlockPosition): Location {
|
fun fromPosition(position: BlockPosition): Location {
|
||||||
|
@ -76,7 +76,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
public MenuButton optionsMenu;
|
public MenuButton optionsMenu;
|
||||||
public Label pingField;
|
public Label pingField;
|
||||||
|
|
||||||
boolean canConnect;
|
private boolean canConnect;
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
public static ServerListCell newInstance() {
|
public static ServerListCell newInstance() {
|
||||||
@ -286,21 +286,26 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
if (!this.canConnect || this.server.getLastPing() == null) {
|
if (!this.canConnect || this.server.getLastPing() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.server.isConnected()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.root.getStyleClass().add("list-cell-connecting");
|
this.root.getStyleClass().add("list-cell-connecting");
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
Connection connection = new Connection(Connection.lastConnectionId++, this.server.getAddress(), new Player(Minosoft.getConfig().getSelectedAccount()));
|
Connection connection = new Connection(Connection.lastConnectionId++, this.server.getAddress(), new Player(Minosoft.getConfig().getSelectedAccount()));
|
||||||
|
this.server.addConnection(connection);
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
this.optionsConnect.setDisable(true);
|
||||||
|
});
|
||||||
Version version;
|
Version version;
|
||||||
if (this.server.getDesiredVersionId() == ProtocolDefinition.QUERY_PROTOCOL_VERSION_ID) {
|
if (this.server.getDesiredVersionId() == ProtocolDefinition.QUERY_PROTOCOL_VERSION_ID) {
|
||||||
version = this.server.getLastPing().getVersion();
|
version = this.server.getLastPing().getVersion();
|
||||||
} else {
|
} else {
|
||||||
version = Versions.getVersionById(this.server.getDesiredVersionId());
|
version = Versions.getVersionById(this.server.getDesiredVersionId());
|
||||||
}
|
}
|
||||||
this.optionsConnect.setDisable(true);
|
|
||||||
// ToDo: show progress dialog
|
// ToDo: show progress dialog
|
||||||
|
|
||||||
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
|
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
|
||||||
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
|
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
|
||||||
this.server.addConnection(connection);
|
|
||||||
}, "ConnectThread").start();
|
}, "ConnectThread").start();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -328,15 +333,19 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
|||||||
default -> "";
|
default -> "";
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!connection.isConnected()) {
|
if (connection.isConnected()) {
|
||||||
// maybe we got disconnected
|
this.optionsConnect.setDisable(Minosoft.getConfig().getSelectedAccount() == connection.getPlayer().getAccount());
|
||||||
if (!this.server.isConnected()) {
|
this.optionsSessions.setDisable(false);
|
||||||
this.optionsSessions.setDisable(true);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.optionsConnect.setDisable(Minosoft.getConfig().getSelectedAccount() == connection.getPlayer().getAccount());
|
if (this.server.isConnected()) {
|
||||||
|
this.optionsSessions.setDisable(false);
|
||||||
|
this.optionsConnect.setDisable(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.optionsConnect.setDisable(false);
|
||||||
this.optionsSessions.setDisable(false);
|
this.optionsSessions.setDisable(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,11 @@ import de.bixilon.minosoft.data.entities.Location
|
|||||||
import de.bixilon.minosoft.gui.rendering.chunk.ChunkRenderer
|
import de.bixilon.minosoft.gui.rendering.chunk.ChunkRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
|
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.hud.elements.RenderStats
|
import de.bixilon.minosoft.gui.rendering.hud.elements.RenderStats
|
||||||
|
import de.bixilon.minosoft.modding.event.EventInvokerCallback
|
||||||
|
import de.bixilon.minosoft.modding.event.events.ConnectionStateChangeEvent
|
||||||
|
import de.bixilon.minosoft.modding.event.events.PacketReceiveEvent
|
||||||
import de.bixilon.minosoft.protocol.network.Connection
|
import de.bixilon.minosoft.protocol.network.Connection
|
||||||
|
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketPlayerPositionAndRotation
|
||||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionAndRotationSending
|
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionAndRotationSending
|
||||||
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
@ -30,7 +34,7 @@ class RenderWindow(private val connection: Connection, val rendering: Rendering)
|
|||||||
|
|
||||||
private var lastFrame = 0.0
|
private var lastFrame = 0.0
|
||||||
lateinit var camera: Camera
|
lateinit var camera: Camera
|
||||||
var latch = CountUpAndDownLatch(1)
|
private val latch = CountUpAndDownLatch(1)
|
||||||
|
|
||||||
// all renderers
|
// all renderers
|
||||||
val chunkRenderer: ChunkRenderer = ChunkRenderer(connection, connection.player.world, this)
|
val chunkRenderer: ChunkRenderer = ChunkRenderer(connection, connection.player.world, this)
|
||||||
@ -38,6 +42,29 @@ class RenderWindow(private val connection: Connection, val rendering: Rendering)
|
|||||||
|
|
||||||
val renderQueue = ConcurrentLinkedQueue<Runnable>()
|
val renderQueue = ConcurrentLinkedQueue<Runnable>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
connection.registerEvent(EventInvokerCallback<ConnectionStateChangeEvent> {
|
||||||
|
if (it.connection.isDisconnected) {
|
||||||
|
renderQueue.add {
|
||||||
|
glfwSetWindowShouldClose(windowId, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
connection.registerEvent(EventInvokerCallback<PacketReceiveEvent> {
|
||||||
|
val packet = it.packet
|
||||||
|
if (packet !is PacketPlayerPositionAndRotation) {
|
||||||
|
return@EventInvokerCallback
|
||||||
|
}
|
||||||
|
if (latch.count > 0) {
|
||||||
|
latch.countDown()
|
||||||
|
}
|
||||||
|
renderQueue.add {
|
||||||
|
camera.cameraPosition = packet.location.toVec3()
|
||||||
|
camera.setRotation(packet.rotation.yaw.toDouble(), packet.rotation.pitch.toDouble())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun init(latch: CountUpAndDownLatch) {
|
fun init(latch: CountUpAndDownLatch) {
|
||||||
// Setup an error callback. The default implementation
|
// Setup an error callback. The default implementation
|
||||||
@ -191,6 +218,9 @@ class RenderWindow(private val connection: Connection, val rendering: Rendering)
|
|||||||
// Terminate GLFW and free the error callback
|
// Terminate GLFW and free the error callback
|
||||||
glfwTerminate()
|
glfwTerminate()
|
||||||
glfwSetErrorCallback(null)!!.free()
|
glfwSetErrorCallback(null)!!.free()
|
||||||
|
|
||||||
|
// disconnect
|
||||||
|
connection.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchPolygonMode() {
|
private fun switchPolygonMode() {
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package de.bixilon.minosoft.gui.rendering
|
package de.bixilon.minosoft.gui.rendering
|
||||||
|
|
||||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
|
||||||
import de.bixilon.minosoft.data.entities.Location
|
|
||||||
import de.bixilon.minosoft.protocol.network.Connection
|
import de.bixilon.minosoft.protocol.network.Connection
|
||||||
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
||||||
import de.bixilon.minosoft.util.Util
|
import de.bixilon.minosoft.util.Util
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
import glm_.vec3.Vec3
|
|
||||||
import org.lwjgl.Version
|
import org.lwjgl.Version
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
@ -24,22 +21,4 @@ class Rendering(private val connection: Connection) {
|
|||||||
renderWindow.exit()
|
renderWindow.exit()
|
||||||
}, "Rendering").start()
|
}, "Rendering").start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun teleport(position: Location) {
|
|
||||||
// tell the window we are ready (received position)
|
|
||||||
if (renderWindow.latch.count > 0) {
|
|
||||||
renderWindow.latch.countDown()
|
|
||||||
}
|
|
||||||
renderWindow.renderQueue.add {
|
|
||||||
renderWindow.camera.cameraPosition = Vec3(position.x, position.y, position.z)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun rotate(rotation: EntityRotation) {
|
|
||||||
renderWindow.renderQueue.add {
|
|
||||||
renderWindow.camera.setRotation(rotation.yaw.toDouble(), rotation.pitch.toDouble())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ public class Connection {
|
|||||||
this.pong = pong;
|
this.pong = pong;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldDisconnect() {
|
public boolean isDisconnected() {
|
||||||
return getConnectionState() == ConnectionStates.DISCONNECTING || getConnectionState() == ConnectionStates.DISCONNECTED || getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY;
|
return getConnectionState() == ConnectionStates.DISCONNECTING || getConnectionState() == ConnectionStates.DISCONNECTED || getConnectionState() == ConnectionStates.FAILED || getConnectionState() == ConnectionStates.FAILED_NO_RETRY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ public class BlockingSocketNetwork extends Network {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
if (this.connection.shouldDisconnect()) {
|
if (this.connection.isDisconnected()) {
|
||||||
// already trying
|
// already trying
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,6 @@ public class PacketPlayerPositionAndRotation extends ClientboundPacket {
|
|||||||
} else {
|
} else {
|
||||||
connection.sendPacket(new PacketPlayerPositionAndRotationSending(getLocation(), getRotation(), isOnGround()));
|
connection.sendPacket(new PacketPlayerPositionAndRotationSending(getLocation(), getRotation(), isOnGround()));
|
||||||
}
|
}
|
||||||
connection.getRenderer().teleport(this.location);
|
|
||||||
connection.getRenderer().rotate(this.rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user