mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 19:35:00 -04:00
rendering: limit chat messages, improve to chat logging, movement: send rotation or position or both
This commit is contained in:
parent
18324e0791
commit
3f1aa921e3
@ -27,6 +27,8 @@ import de.bixilon.minosoft.gui.rendering.chunk.Frustum
|
||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||
import de.bixilon.minosoft.protocol.network.Connection
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionAndRotationSending
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionSending
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerRotationSending
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import glm_.glm
|
||||
import glm_.mat4x4.Mat4
|
||||
@ -48,8 +50,9 @@ class Camera(
|
||||
var pitch = 0.0
|
||||
private var zoom = 0f
|
||||
|
||||
private var lastPositionChange = 0L
|
||||
private var lastMovementPacketSent = 0L
|
||||
private var currentPositionSent = false
|
||||
private var currentRotationSent = false
|
||||
|
||||
var cameraFront = Vec3(0.0f, 0.0f, -1.0f)
|
||||
var cameraRight = Vec3(0.0f, 0.0f, -1.0f)
|
||||
@ -164,6 +167,7 @@ class Camera(
|
||||
}
|
||||
if (lastPosition != cameraPosition) {
|
||||
recalculateViewProjectionMatrix()
|
||||
currentPositionSent = false
|
||||
sendPositionToServer()
|
||||
}
|
||||
|
||||
@ -242,24 +246,30 @@ class Camera(
|
||||
cameraRight = cameraFront.cross(CAMERA_UP_VEC3).normalize()
|
||||
cameraUp = cameraRight.cross(cameraFront).normalize()
|
||||
recalculateViewProjectionMatrix()
|
||||
currentRotationSent = false
|
||||
sendPositionToServer()
|
||||
}
|
||||
|
||||
fun draw() {
|
||||
if (!currentPositionSent) {
|
||||
if (!currentPositionSent || !currentRotationSent) {
|
||||
sendPositionToServer()
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendPositionToServer() {
|
||||
if (System.currentTimeMillis() - lastPositionChange > ProtocolDefinition.TICK_TIME) {
|
||||
// ToDo: Replace this with proper movement and only send it, when our position changed
|
||||
connection.sendPacket(PacketPlayerPositionAndRotationSending(feetLocation, EntityRotation(yaw, pitch), false))
|
||||
lastPositionChange = System.currentTimeMillis()
|
||||
if (System.currentTimeMillis() - lastMovementPacketSent > ProtocolDefinition.TICK_TIME) {
|
||||
if (!currentPositionSent && !currentPositionSent) {
|
||||
connection.sendPacket(PacketPlayerPositionAndRotationSending(feetLocation, EntityRotation(yaw, pitch), false))
|
||||
} else if (!currentPositionSent) {
|
||||
connection.sendPacket(PacketPlayerPositionSending(feetLocation, false))
|
||||
} else {
|
||||
connection.sendPacket(PacketPlayerRotationSending(EntityRotation(yaw, pitch), false))
|
||||
}
|
||||
lastMovementPacketSent = System.currentTimeMillis()
|
||||
currentPositionSent = true
|
||||
currentRotationSent = true
|
||||
return
|
||||
}
|
||||
currentPositionSent = false
|
||||
}
|
||||
|
||||
fun setPosition(location: Position) {
|
||||
|
@ -25,6 +25,9 @@ class HUDChatElement(hudTextElement: HUDTextElement) : HUDText {
|
||||
|
||||
init {
|
||||
hudTextElement.connection.registerEvent(EventInvokerCallback<ChatMessageReceivingEvent> {
|
||||
if (chatMessages.size > MAX_MESSAGES_IN_CHAT) {
|
||||
chatMessages.remove(chatMessages.iterator().next())
|
||||
}
|
||||
chatMessages.add(Pair(it.message, System.currentTimeMillis()))
|
||||
})
|
||||
}
|
||||
@ -40,4 +43,8 @@ class HUDChatElement(hudTextElement: HUDTextElement) : HUDText {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MAX_MESSAGES_IN_CHAT = 20
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.serverbound.play;
|
||||
|
||||
import de.bixilon.minosoft.data.entities.Position;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
|
||||
@ -22,43 +23,29 @@ import de.bixilon.minosoft.util.logging.Log;
|
||||
import static de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W06B;
|
||||
|
||||
public class PacketPlayerPositionSending implements ServerboundPacket {
|
||||
private final double x;
|
||||
private final double feetY;
|
||||
private final double headY;
|
||||
private final double z;
|
||||
private final Position position;
|
||||
private final boolean onGround;
|
||||
|
||||
public PacketPlayerPositionSending(double x, double feetY, double headY, double z, boolean onGround) {
|
||||
this.x = x;
|
||||
this.feetY = feetY;
|
||||
this.headY = headY;
|
||||
this.z = z;
|
||||
this.onGround = onGround;
|
||||
}
|
||||
|
||||
public PacketPlayerPositionSending(double x, double feetY, double z, boolean onGround) {
|
||||
this.x = x;
|
||||
this.feetY = feetY;
|
||||
this.headY = feetY - 1.62F;
|
||||
this.z = z;
|
||||
public PacketPlayerPositionSending(Position position, boolean onGround) {
|
||||
this.position = position;
|
||||
this.onGround = onGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutPacketBuffer write(Connection connection) {
|
||||
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_POSITION);
|
||||
buffer.writeDouble(this.x);
|
||||
buffer.writeDouble(this.feetY);
|
||||
buffer.writeDouble(this.position.getX());
|
||||
buffer.writeDouble(this.position.getY());
|
||||
if (buffer.getVersionId() < V_14W06B) {
|
||||
buffer.writeDouble(this.headY);
|
||||
buffer.writeDouble(0.0); // TODo
|
||||
}
|
||||
buffer.writeDouble(this.z);
|
||||
buffer.writeDouble(this.position.getZ());
|
||||
buffer.writeBoolean(this.onGround);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[OUT] Sending player position: %s %s %s", this.x, this.headY, this.z));
|
||||
Log.protocol(String.format("[OUT] Sending player position (position=%s)", this.position));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.serverbound.play;
|
||||
|
||||
import de.bixilon.minosoft.data.entities.EntityRotation;
|
||||
import de.bixilon.minosoft.protocol.network.Connection;
|
||||
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
|
||||
@ -20,27 +21,25 @@ import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||
import de.bixilon.minosoft.util.logging.Log;
|
||||
|
||||
public class PacketPlayerRotationSending implements ServerboundPacket {
|
||||
private final float yaw;
|
||||
private final float pitch;
|
||||
private final EntityRotation rotation;
|
||||
private final boolean onGround;
|
||||
|
||||
public PacketPlayerRotationSending(float yaw, float pitch, boolean onGround) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
public PacketPlayerRotationSending(EntityRotation rotation, boolean onGround) {
|
||||
this.rotation = rotation;
|
||||
this.onGround = onGround;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutPacketBuffer write(Connection connection) {
|
||||
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_ROTATION);
|
||||
buffer.writeFloat(this.yaw);
|
||||
buffer.writeFloat(this.pitch);
|
||||
buffer.writeFloat(this.rotation.getYaw());
|
||||
buffer.writeFloat(this.rotation.getPitch());
|
||||
buffer.writeBoolean(this.onGround);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[OUT] Sending player rotation (yaw=%s, pitch=%s)", this.yaw, this.pitch));
|
||||
Log.protocol(String.format("[OUT] Sending player rotation (rotation=%s)", this.rotation));
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.text.BaseComponent;
|
||||
import de.bixilon.minosoft.data.text.ChatColors;
|
||||
import de.bixilon.minosoft.data.text.ChatComponent;
|
||||
import de.bixilon.minosoft.data.text.RGBColor;
|
||||
import de.bixilon.minosoft.util.Pair;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -28,7 +29,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
public class Log {
|
||||
public static final long MINOSOFT_START_TIME = System.currentTimeMillis();
|
||||
private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
private static final LinkedBlockingQueue<ChatComponent> LOG_QUEUE = new LinkedBlockingQueue<>();
|
||||
private static final LinkedBlockingQueue<Pair<ChatComponent, ChatComponent>> LOG_QUEUE = new LinkedBlockingQueue<>(); // prefix, message
|
||||
private static final PrintStream SYSTEM_ERR_STREAM = System.err;
|
||||
private static final PrintStream SYSTEM_OUT_STREAM = System.out;
|
||||
private static final PrintStream ERROR_PRINT_STREAM = new LogPrintStream(LogLevels.WARNING);
|
||||
@ -41,18 +42,18 @@ public class Log {
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
// something to print
|
||||
ChatComponent message;
|
||||
Pair<ChatComponent, ChatComponent> message;
|
||||
try {
|
||||
message = LOG_QUEUE.take();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
SYSTEM_OUT_STREAM.println(message.getANSIColoredMessage());
|
||||
SYSTEM_OUT_STREAM.println(message.getKey().getANSIColoredMessage() + message.getValue().getANSIColoredMessage());
|
||||
|
||||
if (StaticConfiguration.SHOW_LOG_MESSAGES_IN_CHAT) {
|
||||
for (var connection : Minosoft.CONNECTIONS.values()) {
|
||||
connection.getSender().sendFakeChatMessage(message, ChatTextPositions.CHAT_BOX);
|
||||
connection.getSender().sendFakeChatMessage(message.getValue(), ChatTextPositions.CHAT_BOX);
|
||||
}
|
||||
}
|
||||
// ToDo: log to file
|
||||
@ -111,8 +112,7 @@ public class Log {
|
||||
if (color != null && StaticConfiguration.COLORED_LOG) {
|
||||
messageComponent.applyDefaultColor(color);
|
||||
}
|
||||
component.append(messageComponent);
|
||||
LOG_QUEUE.add(component);
|
||||
LOG_QUEUE.add(new Pair<>(component, messageComponent));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user