mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -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)"
|
||||
}
|
||||
|
||||
fun toVec3(): Vec3 {
|
||||
return Vec3(x, y, z)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun fromPosition(position: BlockPosition): Location {
|
||||
|
@ -76,7 +76,7 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
public MenuButton optionsMenu;
|
||||
public Label pingField;
|
||||
|
||||
boolean canConnect;
|
||||
private boolean canConnect;
|
||||
private Server server;
|
||||
|
||||
public static ServerListCell newInstance() {
|
||||
@ -286,21 +286,26 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
if (!this.canConnect || this.server.getLastPing() == null) {
|
||||
return;
|
||||
}
|
||||
if (this.server.isConnected()) {
|
||||
return;
|
||||
}
|
||||
this.root.getStyleClass().add("list-cell-connecting");
|
||||
new Thread(() -> {
|
||||
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;
|
||||
if (this.server.getDesiredVersionId() == ProtocolDefinition.QUERY_PROTOCOL_VERSION_ID) {
|
||||
version = this.server.getLastPing().getVersion();
|
||||
} else {
|
||||
version = Versions.getVersionById(this.server.getDesiredVersionId());
|
||||
}
|
||||
this.optionsConnect.setDisable(true);
|
||||
// ToDo: show progress dialog
|
||||
|
||||
connection.connect(this.server.getLastPing().getAddress(), version, new CountUpAndDownLatch(1));
|
||||
connection.registerEvent(new EventInvokerCallback<>(this::handleConnectionCallback));
|
||||
this.server.addConnection(connection);
|
||||
}, "ConnectThread").start();
|
||||
|
||||
}
|
||||
@ -328,15 +333,19 @@ public class ServerListCell extends ListCell<Server> implements Initializable {
|
||||
default -> "";
|
||||
});
|
||||
|
||||
if (!connection.isConnected()) {
|
||||
// maybe we got disconnected
|
||||
if (!this.server.isConnected()) {
|
||||
this.optionsSessions.setDisable(true);
|
||||
if (connection.isConnected()) {
|
||||
this.optionsConnect.setDisable(Minosoft.getConfig().getSelectedAccount() == connection.getPlayer().getAccount());
|
||||
this.optionsSessions.setDisable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.server.isConnected()) {
|
||||
this.optionsSessions.setDisable(false);
|
||||
this.optionsConnect.setDisable(false);
|
||||
return;
|
||||
}
|
||||
|
||||
this.optionsConnect.setDisable(Minosoft.getConfig().getSelectedAccount() == connection.getPlayer().getAccount());
|
||||
this.optionsConnect.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.hud.HUDRenderer
|
||||
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.packets.clientbound.play.PacketPlayerPositionAndRotation
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionAndRotationSending
|
||||
import de.bixilon.minosoft.util.CountUpAndDownLatch
|
||||
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
|
||||
lateinit var camera: Camera
|
||||
var latch = CountUpAndDownLatch(1)
|
||||
private val latch = CountUpAndDownLatch(1)
|
||||
|
||||
// all renderers
|
||||
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>()
|
||||
|
||||
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) {
|
||||
// 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
|
||||
glfwTerminate()
|
||||
glfwSetErrorCallback(null)!!.free()
|
||||
|
||||
// disconnect
|
||||
connection.disconnect()
|
||||
}
|
||||
|
||||
private fun switchPolygonMode() {
|
||||
|
@ -1,12 +1,9 @@
|
||||
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.util.CountUpAndDownLatch
|
||||
import de.bixilon.minosoft.util.Util
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import glm_.vec3.Vec3
|
||||
import org.lwjgl.Version
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
@ -24,22 +21,4 @@ class Rendering(private val connection: Connection) {
|
||||
renderWindow.exit()
|
||||
}, "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;
|
||||
}
|
||||
|
||||
public boolean shouldDisconnect() {
|
||||
public boolean isDisconnected() {
|
||||
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
|
||||
public void disconnect() {
|
||||
if (this.connection.shouldDisconnect()) {
|
||||
if (this.connection.isDisconnected()) {
|
||||
// already trying
|
||||
return;
|
||||
}
|
||||
|
@ -58,8 +58,6 @@ public class PacketPlayerPositionAndRotation extends ClientboundPacket {
|
||||
} else {
|
||||
connection.sendPacket(new PacketPlayerPositionAndRotationSending(getLocation(), getRotation(), isOnGround()));
|
||||
}
|
||||
connection.getRenderer().teleport(this.location);
|
||||
connection.getRenderer().rotate(this.rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user