use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class NetClient method sendNewChunks.
private void sendNewChunks(NetData.NetMessage.Builder message) {
if (!readyChunks.isEmpty()) {
chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
if (chunkSendCounter > 1.0f) {
chunkSendCounter -= 1.0f;
Vector3i center = new Vector3i();
LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
if (loc != null) {
Vector3f target = loc.getWorldPosition(new Vector3f());
if (target.isFinite()) {
// use center as temporary variable
center.set(target, RoundingMode.HALF_UP);
// update center to chunkPos
Chunks.toChunkPos(center, center);
}
}
Vector3i pos = null;
long distance = Integer.MAX_VALUE;
for (Vector3i chunkPos : readyChunks.keySet()) {
long chunkDistance = chunkPos.distanceSquared(center);
if (pos == null || chunkDistance < distance) {
pos = chunkPos;
distance = chunkDistance;
}
}
Chunk chunk = readyChunks.remove(pos);
relevantChunks.add(pos);
message.addChunkInfo(chunk.encode());
}
} else {
chunkSendCounter = 1.0f;
}
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ServerImpl method processBlockChanges.
/**
* Apply the block changes from the message to the local world.
*/
private void processBlockChanges(NetData.NetMessage message) {
for (NetData.BlockChangeMessage blockChange : message.getBlockChangeList()) {
Block newBlock = blockManager.getBlock((short) blockChange.getNewBlock());
logger.debug("Received block change to {}", newBlock);
// TODO: Store changes to blocks that aren't ready to be modified (the surrounding chunks aren't available)
WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
Vector3i pos = NetMessageUtil.convert(blockChange.getPos());
if (worldProvider.isBlockRelevant(pos)) {
worldProvider.setBlock(pos, newBlock);
} else {
awaitingChunkReadyBlockUpdates.put(Chunks.toChunkPos(pos), blockChange);
}
}
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkMonitor method fireChunkRevived.
public static void fireChunkRevived(Chunk chunk) {
Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
post(new ChunkMonitorEvent.Revived(chunk.getPosition(new Vector3i())));
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkMonitor method registerChunk.
private static synchronized ChunkMonitorEntry registerChunk(Chunk chunk) {
Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
final Vector3i pos = chunk.getPosition(new Vector3i());
ChunkMonitorEntry entry = CHUNKS.get(pos);
if (entry == null) {
entry = new ChunkMonitorEntry(pos);
CHUNKS.put(pos, entry);
}
entry.addChunk(chunk);
return entry;
}
use of org.joml.Vector3i in project Terasology by MovingBlocks.
the class ChunkMonitor method fireChunkDeflated.
public static void fireChunkDeflated(Chunk chunk, int oldSize, int newSize) {
Preconditions.checkNotNull(chunk, "The parameter 'chunk' must not be null");
post(new ChunkMonitorEvent.Deflated(chunk.getPosition(new Vector3i()), oldSize, newSize));
}
Aggregations