Fixed chunk load radius and removed debug leftovers
This commit is contained in:
parent
b44540999b
commit
5d570a810b
@ -1,7 +1,5 @@
|
||||
package ru.windcorp.progressia.client;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||
import ru.windcorp.progressia.client.graphics.world.Camera;
|
||||
@ -48,8 +46,6 @@ public class Client {
|
||||
}
|
||||
|
||||
public void onLocalPlayerEntityChanged(EntityData entity, EntityData lastKnownEntity) {
|
||||
LogManager.getLogger().info("LocalPlayer entity changed from {} to {}", lastKnownEntity, entity);
|
||||
|
||||
if (entity == null) {
|
||||
getCamera().setAnchor(null);
|
||||
return;
|
||||
|
@ -21,6 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import gnu.trove.TCollections;
|
||||
import gnu.trove.map.TLongObjectMap;
|
||||
@ -35,7 +37,6 @@ import ru.windcorp.progressia.common.world.generic.GenericWorld;
|
||||
import ru.windcorp.progressia.common.world.generic.LongBasedChunkMap;
|
||||
import ru.windcorp.progressia.common.world.tile.TileData;
|
||||
import ru.windcorp.progressia.common.world.tile.TileDataStack;
|
||||
import ru.windcorp.progressia.test.TestContent;
|
||||
|
||||
public class WorldData
|
||||
implements GenericWorld<
|
||||
@ -87,23 +88,16 @@ implements GenericWorld<
|
||||
return entities;
|
||||
}
|
||||
|
||||
public TLongSet getLoadedEntities() {
|
||||
return entitiesById.keySet();
|
||||
@Override
|
||||
public void forEachEntity(Consumer<? super EntityData> action) {
|
||||
synchronized (entitiesById) { // TODO HORRIBLY MUTILATE THE CORPSE OF TROVE4J so that gnu.trove.impl.sync.SynchronizedCollection.forEach is synchronized
|
||||
getEntities().forEach(action);
|
||||
}
|
||||
}
|
||||
|
||||
public void tmp_generate() {
|
||||
final int size = 1;
|
||||
Vec3i cursor = new Vec3i(0, 0, 0);
|
||||
|
||||
for (cursor.x = -(size / 2); cursor.x <= (size / 2); ++cursor.x) {
|
||||
for (cursor.y = -(size / 2); cursor.y <= (size / 2); ++cursor.y) {
|
||||
for (cursor.z = -(size / 2); cursor.z <= (size / 2); ++cursor.z) {
|
||||
ChunkData chunk = new ChunkData(cursor, this);
|
||||
TestContent.generateChunk(chunk);
|
||||
addChunk(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TLongSet getLoadedEntities() {
|
||||
return entitiesById.keySet();
|
||||
}
|
||||
|
||||
private void addChunkListeners(ChunkData chunk) {
|
||||
|
@ -118,9 +118,7 @@ public interface GenericWorld<
|
||||
*/
|
||||
|
||||
default void forEachEntity(Consumer<? super E> action) {
|
||||
synchronized (this) { // TODO HORRIBLY MUTILATE THE CORPSE OF TROVE4J so that gnu.trove.impl.sync.SynchronizedCollection.forEach is synchronized
|
||||
getEntities().forEach(action);
|
||||
}
|
||||
getEntities().forEach(action);
|
||||
}
|
||||
|
||||
default void forEachEntityIn(Vec3i min, Vec3i max, Consumer<? super E> action) {
|
||||
|
@ -4,8 +4,6 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.world.ChunkData;
|
||||
import ru.windcorp.progressia.common.world.PacketRevokeChunk;
|
||||
@ -119,8 +117,6 @@ public class ChunkManager {
|
||||
}
|
||||
|
||||
public void loadChunk(Vec3i chunkPos) {
|
||||
|
||||
LogManager.getLogger().info("Loading {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
|
||||
WorldData world = getServer().getWorld().getData();
|
||||
|
||||
@ -132,8 +128,6 @@ public class ChunkManager {
|
||||
|
||||
public void unloadChunk(Vec3i chunkPos) {
|
||||
|
||||
LogManager.getLogger().info("Unloading {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
|
||||
WorldData world = getServer().getWorld().getData();
|
||||
|
||||
ChunkData chunk = world.getChunk(chunkPos);
|
||||
@ -148,8 +142,6 @@ public class ChunkManager {
|
||||
}
|
||||
|
||||
public void sendChunk(Player player, Vec3i chunkPos) {
|
||||
LogManager.getLogger().info("Sending {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
|
||||
ChunkData chunk = server.getWorld().getData().getChunk(chunkPos);
|
||||
|
||||
if (chunk == null) {
|
||||
@ -167,8 +159,6 @@ public class ChunkManager {
|
||||
}
|
||||
|
||||
public void revokeChunk(Player player, Vec3i chunkPos) {
|
||||
LogManager.getLogger().info("Revoking {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z);
|
||||
|
||||
PacketRevokeChunk packet = new PacketRevokeChunk();
|
||||
packet.set(chunkPos);
|
||||
player.getClient().sendPacket(packet);
|
||||
|
@ -4,8 +4,6 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import gnu.trove.TCollections;
|
||||
import gnu.trove.iterator.TLongIterator;
|
||||
@ -132,8 +130,6 @@ public class EntityManager {
|
||||
);
|
||||
}
|
||||
|
||||
LogManager.getLogger().info("Sending {}", entity);
|
||||
|
||||
PacketSendEntity packet = new PacketSendEntity();
|
||||
packet.set(entity);
|
||||
player.getClient().sendPacket(packet);
|
||||
@ -142,8 +138,6 @@ public class EntityManager {
|
||||
}
|
||||
|
||||
public void revokeEntity(Player player, long entityId) {
|
||||
LogManager.getLogger().info("Revoking {}", new String(StringUtil.toFullHex(entityId)));
|
||||
|
||||
PacketRevokeEntity packet = new PacketRevokeEntity();
|
||||
packet.set(entityId);
|
||||
player.getClient().sendPacket(packet);
|
||||
|
@ -36,19 +36,20 @@ public class Player extends PlayerData implements ChunkLoader {
|
||||
Coordinates.convertInWorldToChunk(start, start);
|
||||
|
||||
Vec3i cursor = new Vec3i();
|
||||
float radius = getServer().getLoadDistance(this);
|
||||
float radiusSq = radius / Units.get(16.0f, "m");
|
||||
radiusSq *= radiusSq;
|
||||
float radius = getServer().getLoadDistance(this) / Units.get(16.0f, "m");
|
||||
|
||||
float radiusSq = radius * radius;
|
||||
int iRadius = (int) Math.ceil(radius);
|
||||
|
||||
for (cursor.x = -iRadius; cursor.x <= +iRadius; ++cursor.x) {
|
||||
for (cursor.y = -iRadius; cursor.y <= +iRadius; ++cursor.y) {
|
||||
for (cursor.z = -iRadius; cursor.z <= +iRadius; ++cursor.z) {
|
||||
if (cursor.x * cursor.x + cursor.y * cursor.y + cursor.z * cursor.z <= radius) {
|
||||
if (cursor.x * cursor.x + cursor.y * cursor.y + cursor.z * cursor.z <= radiusSq) {
|
||||
|
||||
cursor.add(start);
|
||||
chunkConsumer.accept(cursor);
|
||||
cursor.sub(start);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public float getLoadDistance(Player player) {
|
||||
return Units.get(10.0f, "m");
|
||||
return Units.get(100.0f, "m");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,6 @@ public class ServerState {
|
||||
|
||||
public static void startServer() {
|
||||
Server server = new Server(new WorldData());
|
||||
// server.getWorld().getData().tmp_generate();
|
||||
setInstance(server);
|
||||
server.start();
|
||||
}
|
||||
|
Reference in New Issue
Block a user