Compare commits

...
8 Commits
Author SHA1 Message Date
Jim C K Flaten 2fb530de2b Merge branch 'hotfix/0.2.2' 2024-07-19 00:17:07 +02:00
Jim C K Flaten dbc97a9366 0.2.2 2024-07-19 00:17:02 +02:00
Jim C K Flaten e2c0e3f88a Bump protocol version to match client spec. 2024-07-19 00:15:45 +02:00
Jim C K Flaten bbc26ef9d7 Merge branch 'release/0.2.1' 2024-07-18 23:39:59 +02:00
Jim C K Flaten fbb07e329d 0.2.1 2024-07-18 23:39:53 +02:00
Jim C K Flaten e0299eb798 Data chunking (#42)
Waiting for [client-side support for
chunking](https://gitlab.com/jeseibel/distant-horizons-core/-/commits/serverside-feature/fulldata-chunked-payload/?ref_type=heads)
2024-07-18 23:19:02 +02:00
Jim C K Flaten 5fcd6b8b52 Bump version number. 2024-07-16 16:43:15 +02:00
Jim C K Flaten 32567079f0 Merge tag '0.2.0' into develop
0.2.0
2024-07-16 16:34:23 +02:00
6 changed files with 108 additions and 15 deletions

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@
<groupId>no.jckf</groupId>
<name>dh-support</name>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.2</version>
<artifactId>DHSupport</artifactId>
<properties>
@@ -19,18 +19,24 @@
package no.jckf.dhsupport.core.handler;
import no.jckf.dhsupport.core.DhSupport;
import no.jckf.dhsupport.core.message.plugin.FullDataChunkMessage;
import no.jckf.dhsupport.core.message.plugin.FullDataSourceRequestMessage;
import no.jckf.dhsupport.core.message.plugin.FullDataSourceResponseMessage;
import org.bukkit.Bukkit;
import java.util.Arrays;
import java.util.UUID;
public class LodHandler
{
protected static int CHUNK_SIZE = 1024 * 16; // TODO: Configurable?
protected DhSupport dhSupport;
protected PluginMessageHandler pluginMessageHandler;
protected int bufferId = 0; // TODO: Should be tracked per player instead of globally, and reset when a player disconnects.
public LodHandler(DhSupport dhSupport, PluginMessageHandler pluginMessageHandler)
{
this.dhSupport = dhSupport;
@@ -42,18 +48,35 @@ public class LodHandler
this.pluginMessageHandler.getEventBus().registerHandler(FullDataSourceRequestMessage.class, (requestMessage) -> {
//this.dhSupport.info("LOD request for " + requestMessage.getPosition().getX() + " x " + requestMessage.getPosition().getZ());
int myBufferId = this.bufferId++;
// TODO: Some sort of Player wrapper or interface object. Bukkit classes should not be imported here.
UUID worldUuid = Bukkit.getPlayer(requestMessage.getSender()).getWorld().getUID();
this.dhSupport.getLodData(worldUuid, requestMessage.getPosition())
.thenAccept((lod) -> {
FullDataSourceResponseMessage response = new FullDataSourceResponseMessage();
response.isResponseTo(requestMessage);
response.setData(lod);
int chunkCount = (int) Math.ceil((double) lod.length / CHUNK_SIZE);
this.pluginMessageHandler.sendPluginMessage(requestMessage.getSender(), response);
for (int chunkNo = 0; chunkNo < chunkCount; chunkNo++) {
FullDataChunkMessage chunkResponse = new FullDataChunkMessage();
chunkResponse.setBufferId(myBufferId);
chunkResponse.setIsFirst(chunkNo == 0);
chunkResponse.setData(Arrays.copyOfRange(
lod,
CHUNK_SIZE * chunkNo,
Math.min(CHUNK_SIZE * chunkNo + CHUNK_SIZE, lod.length)
));
//this.dhSupport.info("LOD sent for " + requestMessage.getPosition().getX() + " x " + requestMessage.getPosition().getZ());
this.pluginMessageHandler.sendPluginMessage(requestMessage.getSender(), chunkResponse);
}
FullDataSourceResponseMessage responseMessage = new FullDataSourceResponseMessage();
responseMessage.isResponseTo(requestMessage);
responseMessage.setBufferId(myBufferId);
this.pluginMessageHandler.sendPluginMessage(requestMessage.getSender(), responseMessage);
//this.dhSupport.info("LOD in " + chunkCount + " parts sent for " + requestMessage.getPosition().getX() + " x " + requestMessage.getPosition().getZ());
})
.exceptionally((exception) -> {
this.dhSupport.warning(exception.getMessage());
@@ -38,7 +38,7 @@ public class PluginMessageHandler
public final String pluginChannel = "distant_horizons:message";
public final int protocolVersion = 2;
public final int protocolVersion = 3;
private EventBus<PluginMessage> eventBus;
@@ -58,7 +58,8 @@ public class PluginMessageHandler
this.messageTypeRegistry.registerMessageType(5, ExceptionMessage.class);
this.messageTypeRegistry.registerMessageType(6, FullDataSourceRequestMessage.class);
this.messageTypeRegistry.registerMessageType(7, FullDataSourceResponseMessage.class);
//this.messageTypeRegistry.registerMessageType(8, FullDataPartialUpdateMessage.class);
this.messageTypeRegistry.registerMessageType(8, /*FullDataPartialUpdateMessage.class*/ null);
this.messageTypeRegistry.registerMessageType(9, FullDataChunkMessage.class);
}
public void onEnable()
@@ -0,0 +1,69 @@
/*
* DH Support, server-side support for Distant Horizons.
* Copyright (C) 2024 Jim C K Flaten
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package no.jckf.dhsupport.core.message.plugin;
import no.jckf.dhsupport.core.bytestream.Encoder;
public class FullDataChunkMessage extends PluginMessage
{
protected int bufferId;
protected byte[] data;
protected boolean isFirst = true;
public void setBufferId(int bufferId)
{
this.bufferId = bufferId;
}
public int getBufferId()
{
return bufferId;
}
public void setData(byte[] data)
{
this.data = data;
}
public byte[] getData()
{
return data;
}
public void setIsFirst(boolean isFirst)
{
this.isFirst = isFirst;
}
public boolean getIsFirst()
{
return this.isFirst;
}
@Override
public void encode(Encoder encoder)
{
encoder.writeInt(this.bufferId);
encoder.writeInt(this.data.length);
encoder.write(this.data);
encoder.writeBoolean(this.isFirst);
}
}
@@ -22,22 +22,22 @@ import no.jckf.dhsupport.core.bytestream.Encoder;
public class FullDataSourceResponseMessage extends TrackablePluginMessage
{
protected byte[] data;
protected int bufferId;
public void setData(byte[] data)
public void setBufferId(int bufferId)
{
this.data = data;
this.bufferId = bufferId;
}
public byte[] getData()
public int getBufferId()
{
return data;
return bufferId;
}
@Override
public void encode(Encoder encoder)
{
encoder.writeBoolean(true);
encoder.write(this.data);
encoder.writeInt(this.bufferId);
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
name: DHSupport
version: 0.2.0-SNAPSHOT
version: 0.2.2
main: no.jckf.dhsupport.bukkit.DhSupportBukkitPlugin
api-version: 1.21