Fixed PacketSendEntity
- Moved PacketSendEntity to correct package (.common.world.entity) - Temporarily added position, velocity and direction to EntityData read/write methods - Increased view distance to 150 m - Squashed visible area vertically (to load less underground and air chunks)
This commit is contained in:
parent
16c89b963e
commit
ea56b642ee
@ -1,10 +1,15 @@
|
||||
package ru.windcorp.progressia.common.world.entity;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import glm.vec._2.Vec2;
|
||||
import glm.vec._3.Vec3;
|
||||
import ru.windcorp.jputil.chars.StringUtil;
|
||||
import ru.windcorp.progressia.common.collision.Collideable;
|
||||
import ru.windcorp.progressia.common.collision.CollisionModel;
|
||||
import ru.windcorp.progressia.common.state.IOContext;
|
||||
import ru.windcorp.progressia.common.state.StatefulObject;
|
||||
import ru.windcorp.progressia.common.world.generic.GenericEntity;
|
||||
|
||||
@ -150,5 +155,51 @@ public class EntityData extends StatefulObject implements Collideable, GenericEn
|
||||
public static String formatEntityId(long entityId) {
|
||||
return new String(StringUtil.toFullHex(entityId));
|
||||
}
|
||||
|
||||
/*
|
||||
* tmp
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void write(DataOutput output, IOContext context) throws IOException {
|
||||
output.writeFloat(getPosition().x);
|
||||
output.writeFloat(getPosition().y);
|
||||
output.writeFloat(getPosition().z);
|
||||
|
||||
output.writeFloat(getVelocity().x);
|
||||
output.writeFloat(getVelocity().y);
|
||||
output.writeFloat(getVelocity().z);
|
||||
|
||||
output.writeFloat(getDirection().x);
|
||||
output.writeFloat(getDirection().y);
|
||||
|
||||
super.write(output, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput input, IOContext context) throws IOException {
|
||||
Vec3 position = new Vec3(
|
||||
input.readFloat(),
|
||||
input.readFloat(),
|
||||
input.readFloat()
|
||||
);
|
||||
|
||||
Vec3 velocity = new Vec3(
|
||||
input.readFloat(),
|
||||
input.readFloat(),
|
||||
input.readFloat()
|
||||
);
|
||||
|
||||
Vec2 direction = new Vec2(
|
||||
input.readFloat(),
|
||||
input.readFloat()
|
||||
);
|
||||
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setDirection(direction);
|
||||
|
||||
super.read(input, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package ru.windcorp.progressia.server;
|
||||
package ru.windcorp.progressia.common.world.entity;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@ -10,8 +10,6 @@ import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||
import ru.windcorp.progressia.common.world.DecodingException;
|
||||
import ru.windcorp.progressia.common.world.PacketWorldChange;
|
||||
import ru.windcorp.progressia.common.world.WorldData;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityDataRegistry;
|
||||
|
||||
public class PacketSendEntity extends PacketWorldChange {
|
||||
|
@ -13,6 +13,7 @@ import ru.windcorp.jputil.chars.StringUtil;
|
||||
import ru.windcorp.progressia.common.util.Vectors;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
import ru.windcorp.progressia.common.world.entity.PacketRevokeEntity;
|
||||
import ru.windcorp.progressia.common.world.entity.PacketSendEntity;
|
||||
import ru.windcorp.progressia.common.world.generic.ChunkSet;
|
||||
|
||||
public class EntityManager {
|
||||
|
@ -4,6 +4,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.Units;
|
||||
import ru.windcorp.progressia.common.world.ChunkData;
|
||||
import ru.windcorp.progressia.common.world.Coordinates;
|
||||
import ru.windcorp.progressia.common.world.PlayerData;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
@ -36,7 +37,7 @@ public class Player extends PlayerData implements ChunkLoader {
|
||||
Coordinates.convertInWorldToChunk(start, start);
|
||||
|
||||
Vec3i cursor = new Vec3i();
|
||||
float radius = getServer().getLoadDistance(this) / Units.get(16.0f, "m");
|
||||
float radius = getServer().getLoadDistance(this) / Units.get(ChunkData.BLOCKS_PER_CHUNK, "m");
|
||||
|
||||
float radiusSq = radius * radius;
|
||||
int iRadius = (int) Math.ceil(radius);
|
||||
@ -44,7 +45,7 @@ public class Player extends PlayerData implements ChunkLoader {
|
||||
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 <= radiusSq) {
|
||||
if (cursor.x * cursor.x + cursor.y * cursor.y + (cursor.z * 2) * (cursor.z * 2) <= radiusSq) {
|
||||
|
||||
cursor.add(start);
|
||||
chunkConsumer.accept(cursor);
|
||||
|
@ -7,7 +7,6 @@ import java.util.Collections;
|
||||
import glm.vec._2.Vec2;
|
||||
import glm.vec._3.Vec3;
|
||||
import glm.vec._3.i.Vec3i;
|
||||
import ru.windcorp.progressia.common.util.Vectors;
|
||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityDataRegistry;
|
||||
@ -31,16 +30,11 @@ public class PlayerManager {
|
||||
this.players.add(player);
|
||||
}
|
||||
|
||||
private static final Vec3i SPAWN = new Vec3i(8, 8, 20);
|
||||
|
||||
public EntityData conjurePlayerEntity(String login) {
|
||||
// TODO Live up to the name
|
||||
if (TestContent.PLAYER_LOGIN.equals(login)) {
|
||||
|
||||
Vec3i chunkPos = Vectors.ZERO_3i;
|
||||
|
||||
if (getServer().getWorld().getChunk(chunkPos) == null) {
|
||||
getServer().getChunkManager().loadChunk(chunkPos);
|
||||
}
|
||||
|
||||
EntityData entity = spawnPlayerEntity(login);
|
||||
return entity;
|
||||
} else {
|
||||
@ -52,7 +46,7 @@ public class PlayerManager {
|
||||
EntityData player = EntityDataRegistry.getInstance().create("Test:Player");
|
||||
|
||||
player.setEntityId(TestContent.PLAYER_ENTITY_ID);
|
||||
player.setPosition(new Vec3(8, 8, 8));
|
||||
player.setPosition(new Vec3(SPAWN.x, SPAWN.y, SPAWN.z));
|
||||
player.setDirection(new Vec2(
|
||||
Math.toRadians(40), Math.toRadians(10)
|
||||
));
|
||||
|
@ -174,7 +174,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public float getLoadDistance(Player player) {
|
||||
return Units.get(100.0f, "m");
|
||||
return Units.get(150.0f, "m");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user