Search in sources :

Example 86 with Vector3i

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;
    }
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 87 with Vector3i

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);
        }
    }
}
Also used : NetData(org.terasology.protobuf.NetData) WorldProvider(org.terasology.engine.world.WorldProvider) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 88 with Vector3i

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())));
}
Also used : Vector3i(org.joml.Vector3i)

Example 89 with 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;
}
Also used : Vector3i(org.joml.Vector3i)

Example 90 with Vector3i

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));
}
Also used : Vector3i(org.joml.Vector3i)

Aggregations

Vector3i (org.joml.Vector3i)203 Test (org.junit.jupiter.api.Test)87 Vector3ic (org.joml.Vector3ic)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)38 Chunk (org.terasology.engine.world.chunks.Chunk)36 BlockRegion (org.terasology.engine.world.block.BlockRegion)30 Block (org.terasology.engine.world.block.Block)22 ChunkImpl (org.terasology.engine.world.chunks.internal.ChunkImpl)21 Vector3f (org.joml.Vector3f)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Map (java.util.Map)11 BeforeEach (org.junit.jupiter.api.BeforeEach)10 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)10 ChunkViewCoreImpl (org.terasology.engine.world.internal.ChunkViewCoreImpl)8 OnChunkLoaded (org.terasology.engine.world.chunks.event.OnChunkLoaded)7 Lists (com.google.common.collect.Lists)6 Maps (com.google.common.collect.Maps)6 List (java.util.List)6 ExecutionException (java.util.concurrent.ExecutionException)6 Future (java.util.concurrent.Future)6