use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class ServerPlayer method updateTrackedEntities.
// Entity tracking
public void updateTrackedEntities() {
EntityControllable controlledEntity = this.controlledEntity;
if (controlledEntity == null)
return;
// Cache (idk if HotSpot makes it redudant but whatever)
double world_size = controlledEntity.getWorld().getWorldSize();
Location controlledEntityLocation = controlledEntity.getLocation();
double ENTITY_VISIBILITY_SIZE = 192;
Iterator<Entity> inRangeEntitiesIterator = controlledEntity.getWorld().getEntitiesInBox(controlledEntityLocation, new Vector3d(ENTITY_VISIBILITY_SIZE, ENTITY_VISIBILITY_SIZE, ENTITY_VISIBILITY_SIZE));
while (inRangeEntitiesIterator.hasNext()) {
Entity e = inRangeEntitiesIterator.next();
// && chunk != null;
boolean shouldTrack = e.shouldBeTrackedBy(this);
boolean contains = subscribedEntities.contains(e);
if (shouldTrack && !contains)
this.subscribe(e);
if (!shouldTrack && contains)
this.unsubscribe(e);
}
Iterator<Entity> subscribedEntitiesIterator = subscribedEntities.iterator();
while (subscribedEntitiesIterator.hasNext()) {
Entity e = subscribedEntitiesIterator.next();
Location loc = e.getLocation();
// Distance calculations
double dx = LoopingMathHelper.moduloDistance(controlledEntityLocation.x(), loc.x(), world_size);
double dy = Math.abs(controlledEntityLocation.y() - loc.y());
double dz = LoopingMathHelper.moduloDistance(controlledEntityLocation.z(), loc.z(), world_size);
boolean inRange = (dx < ENTITY_VISIBILITY_SIZE && dz < ENTITY_VISIBILITY_SIZE && dy < ENTITY_VISIBILITY_SIZE);
// Reasons other than distance to stop tracking this entity
if (!e.shouldBeTrackedBy(this) || !inRange)
this.unsubscribe(e);
// No need to do anything as the component system handles the updates
}
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class ServerPlayer method save.
/**
* Serializes the stuff describing this player
*/
public void save() {
long lastTime = playerDataFile.getLong("timeplayed", 0);
long lastLogin = playerDataFile.getLong("lastlogin", 0);
if (controlledEntity != null) {
// Useless, kept for admin easyness, scripts, whatnot
Location controlledEntityLocation = controlledEntity.getLocation();
// Safely assumes as a SERVER the world will be master ;)
WorldMaster world = (WorldMaster) controlledEntityLocation.getWorld();
playerDataFile.setDouble("posX", controlledEntityLocation.x());
playerDataFile.setDouble("posY", controlledEntityLocation.y());
playerDataFile.setDouble("posZ", controlledEntityLocation.z());
playerDataFile.setString("world", world.getWorldInfo().getInternalName());
// Serializes the whole player entity !!!
SerializedEntityFile playerEntityFile = new SerializedEntityFile(world.getFolderPath() + "/players/" + this.getName().toLowerCase() + ".csf");
playerEntityFile.write(controlledEntity);
}
// Telemetry (EVIL)
playerDataFile.setString("timeplayed", "" + (lastTime + (System.currentTimeMillis() - lastLogin)));
playerDataFile.save();
System.out.println("Player profile " + name + " saved.");
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class DefaultWeatherEffectsRenderer method tick.
@Override
public void tick() {
// Spawn some snow arround
float snowPresence = getSnowPresence();
Entity e = world.getClient().getPlayer().getControlledEntity();
if (e != null && world.getWorldRenderer() != null) {
Location loc = e.getLocation();
for (int i = 0; i < snowPresence * 10; i++) world.getParticlesManager().spawnParticleAtPosition("snow", loc.add(Math.random() * 20 - 10, Math.random() * 20, Math.random() * 20 - 10));
}
// TODO server-side
if (world.getWeather() > 0.9) {
if (world.getWorldInfo().resolveProperty("thunderEnabled", "true").equals("true")) {
// noThunderUntil = 0;
if (System.currentTimeMillis() > noThunderUntil) {
long maxDelay = Long.parseLong(world.getWorldInfo().resolveProperty("maxThunderDelayInMs", "30000"));
long delay = Math.max(0, random.nextLong() % maxDelay);
if (noThunderUntil != 0) {
int worldX = random.nextInt(world.getSizeInChunks() * 32);
int worldZ = random.nextInt(world.getSizeInChunks() * 32);
// Spawn the strike
world.getParticlesManager().spawnParticleAtPosition("lightning_strike_illumination", new Location(world, worldX, 0, worldZ));
}
noThunderUntil = System.currentTimeMillis() + delay;
}
}
}
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class FarTerrainGSMeshRenderer method renderTerrain.
@Override
public void renderTerrain(RenderingInterface renderer, ReadyVoxelMeshesMask mask) {
Shader terrainShader = renderer.useShader("terrain_blocky");
renderer.setBlendMode(BlendMode.DISABLED);
renderer.getCamera().setupShader(terrainShader);
worldRenderer.getSkyRenderer().setupShader(terrainShader);
terrainShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
Texture2D waterTexture = renderer.textures().getTexture("./textures/water/shallow.png");
waterTexture.setLinearFiltering(true);
waterTexture.setMipMapping(true);
Texture2D waterTexture2 = renderer.textures().getTexture("./textures/water/deep.png");
waterTexture2.setLinearFiltering(true);
waterTexture2.setMipMapping(true);
// renderer.bindCubemap("environmentCubemap", worldRenderer.renderBuffers.rbEnvironmentMap);
renderer.bindTexture2D("blockLightmap", TexturesHandler.getTexture("./textures/environement/light.png"));
Texture2D lightColors = TexturesHandler.getTexture("./textures/environement/lightcolors.png");
renderer.bindTexture2D("lightColors", lightColors);
renderer.bindTexture2D("waterNormalShallow", waterTexture);
renderer.bindTexture2D("waterNormalDeep", waterTexture2);
world.getGenerator().getEnvironment().setupShadowColors(renderer, terrainShader);
renderer.bindTexture2D("vegetationColorTexture", world.getGenerator().getEnvironment().getGrassTexture(renderer));
terrainShader.setUniform1f("mapSize", worldRenderer.getWorld().getSizeInChunks() * 32);
terrainShader.setUniform1f("animationTimer", worldRenderer.getAnimationTimer());
renderer.bindArrayTexture("heights", worldRenderer.getSummariesTexturesHolder().getHeightsArrayTexture());
renderer.bindArrayTexture("topVoxels", worldRenderer.getSummariesTexturesHolder().getTopVoxelsArrayTexture());
renderer.bindTexture1D("blocksTexturesSummary", colours.get());
if (renderer.getClient().getInputsManager().getInputByName("wireframeFarTerrain").isPressed() && ClientLimitations.isDebugAllowed)
renderer.setPolygonFillMode(PolygonFillMode.WIREFRAME);
if (!renderer.getClient().getInputsManager().getInputByName("hideFarTerrain").isPressed() && ClientLimitations.isDebugAllowed) {
renderer.setCullingMode(CullingMode.DISABLED);
// renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
Player player = Client.getInstance().getPlayer();
Location playerPosition = player.getLocation();
if (playerPosition == null)
// We won't do shit with that going on
return;
Vector2d playerCenter = new Vector2d(playerPosition.x, playerPosition.z);
int chunkX = (int) Math.floor(playerPosition.x / 32.0);
int chunkZ = (int) Math.floor(playerPosition.z / 32.0);
int regionX = chunkX / 8;
int regionZ = chunkZ / 8;
int[] lodInstanceCount = new int[detailLevels.length];
ByteBuffer[] lodByteBuffer = new ByteBuffer[detailLevels.length];
// ByteBuffer summariesAttributes = MemoryUtil.memAlloc(9 * 9 * (4 + 2 * 4));
// MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
// int count = 0;
double lodBias = -0.2;
double lodExponent = 0.35;
if (!world.getClient().getConfiguration().getBooleanOption("client.rendering.hqTerrain")) {
lodBias = 0.3;
lodExponent = 0.35;
} else {
lodBias = 0.0;
lodExponent = 0.45;
}
if (mask == null) {
lodExponent = 1.0;
lodBias = 0.6;
}
Vector2d center = new Vector2d();
for (int i = -4; i <= 4; i++) for (int j = -4; j <= 4; j++) {
int regionI = regionX + i;
int regionJ = regionZ + j;
int index = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ);
if (index == -1)
continue;
// For the extra row of triangles to mask the seams
int index10 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ);
int index01 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ + 1);
int index11 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ + 1);
if (index10 == -1 || index01 == -1 || index11 == -1)
continue;
HeightmapImplementation sum = (HeightmapImplementation) world.getRegionsSummariesHolder().getHeightmap(regionI, regionJ);
// Early out
if (sum == null || !sum.isLoaded())
continue;
if (!renderer.getCamera().isBoxInFrustrum(new CollisionBox(regionI * 256, 0, regionJ * 256, 256, 1024, /*+ sum.getHeightMipmapped(0, 0, 9)*/
256)))
continue;
for (int l = 0; l < 8; l++) for (int m = 0; m < 8; m++) {
if (mask != null) {
if (mask.shouldMaskSlab(regionI * 8 + l, regionJ * 8 + m, sum.min[l][m], sum.max[l][m]))
continue;
}
center.set(regionI * 256 + l * 32 + 16, regionJ * 256 + m * 32 + 16);
int lod = detailLevels.length - (int) ((lodBias + Math.pow(Math.min(1024, center.distance(playerCenter)) / 1024, lodExponent)) * detailLevels.length);
// System.out.println(center.distance(playerCenter));
if (lod <= 0)
lod = 0;
if (lod >= detailLevels.length)
lod = detailLevels.length - 1;
// lod = 2;
// lod = 2;
// System.out.println("lod:"+lod);
// lod = Math.random() > 0.5 ? 1 : 2;
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte) index);
summariesAttributes.put((byte) index10);
summariesAttributes.put((byte) index01);
summariesAttributes.put((byte) index11);
lodInstanceCount[lod]++;
// Always add both so lod 1 is drew under
/*if(lod != 0) {
lod = 0;
summariesAttributes = lodByteBuffer[lod];
if(summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte)index);
summariesAttributes.put((byte)index10);
summariesAttributes.put((byte)index01);
summariesAttributes.put((byte)index11);
lodInstanceCount[lod]++;
}*/
}
}
// for(int lod = 0; lod < detailLevels.length; lod++) {
for (int lod = detailLevels.length - 1; lod >= 0; lod--) {
// Check if anything was supposed to be drew at this lod
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null)
continue;
if (lod < 0) {
MemoryUtil.memFree(summariesAttributes);
continue;
}
// Flip buffer, box it for autodeletion, upload it
summariesAttributes.flip();
MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
gridAttributes.uploadData(auto_free_summariesAttributes);
terrainShader.setUniform1i("lodLevel", lod);
terrainShader.setUniform1f("textureLodLevel", lod - 5);
terrainShader.setUniform1i("maskPresence", mask == null ? 0 : 1);
renderer.bindAttribute("vertexIn", grids[lod].asAttributeSource(VertexFormat.FLOAT, 3, 0, 0L));
renderer.bindAttribute("displacementIn", gridAttributes.asAttributeSource(VertexFormat.FLOAT, 2, (4 + 2 * 4), 0L, 1));
renderer.bindAttribute("indexIn", gridAttributes.asIntegerAttributeSource(VertexFormat.BYTE, 4, (4 + 2 * 4), 8L, 1));
renderer.draw(Primitive.POINT, 0, (detailLevels[lod] + 1) * (detailLevels[lod] + 1) * 1, lodInstanceCount[lod]);
}
}
renderer.setPolygonFillMode(PolygonFillMode.FILL);
}
use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.
the class FarTerrainNoMeshRenderer method renderTerrain.
@Override
public void renderTerrain(RenderingInterface renderer, ReadyVoxelMeshesMask mask) {
Shader terrainShader = renderer.useShader("terrain");
renderer.setBlendMode(BlendMode.DISABLED);
renderer.getCamera().setupShader(terrainShader);
worldRenderer.getSkyRenderer().setupShader(terrainShader);
terrainShader.setUniform1f("viewDistance", world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance"));
Texture2D waterTexture = renderer.textures().getTexture("./textures/water/shallow.png");
waterTexture.setLinearFiltering(true);
waterTexture.setMipMapping(true);
// renderer.bindCubemap("environmentCubemap", worldRenderer.renderBuffers.rbEnvironmentMap);
renderer.bindTexture2D("blockLightmap", TexturesHandler.getTexture("./textures/environement/light.png"));
Texture2D lightColors = TexturesHandler.getTexture("./textures/environement/lightcolors.png");
renderer.bindTexture2D("lightColors", lightColors);
renderer.bindTexture2D("normalTexture", waterTexture);
world.getGenerator().getEnvironment().setupShadowColors(renderer, terrainShader);
// worldRenderer.setupShadowColors(terrainShader);
renderer.bindTexture2D("vegetationColorTexture", world.getGenerator().getEnvironment().getGrassTexture(renderer));
terrainShader.setUniform1f("mapSize", worldRenderer.getWorld().getSizeInChunks() * 32);
renderer.bindArrayTexture("heights", worldRenderer.getSummariesTexturesHolder().getHeightsArrayTexture());
renderer.bindArrayTexture("topVoxels", worldRenderer.getSummariesTexturesHolder().getTopVoxelsArrayTexture());
renderer.bindTexture1D("blocksTexturesSummary", colours.get());
if (renderer.getClient().getInputsManager().getInputByName("wireframeFarTerrain").isPressed() && ClientLimitations.isDebugAllowed)
renderer.setPolygonFillMode(PolygonFillMode.WIREFRAME);
if (!renderer.getClient().getInputsManager().getInputByName("hideFarTerrain").isPressed() && ClientLimitations.isDebugAllowed) {
renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
Player player = Client.getInstance().getPlayer();
Location playerPosition = player.getLocation();
if (playerPosition == null)
// We won't do shit with that going on
return;
Vector2d playerCenter = new Vector2d(playerPosition.x, playerPosition.z);
int chunkX = (int) Math.floor(playerPosition.x / 32.0);
int chunkZ = (int) Math.floor(playerPosition.z / 32.0);
int regionX = chunkX / 8;
int regionZ = chunkZ / 8;
int[] lodInstanceCount = new int[detailLevels.length];
ByteBuffer[] lodByteBuffer = new ByteBuffer[detailLevels.length];
// ByteBuffer summariesAttributes = MemoryUtil.memAlloc(9 * 9 * (4 + 2 * 4));
// MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
// int count = 0;
double lodBias = -0.0;
double lodExponent = 0.35;
if (!world.getClient().getConfiguration().getBooleanOption("client.rendering.hqTerrain")) {
lodBias = 0.4;
lodExponent = 0.35;
}
if (mask == null) {
lodExponent = 1.0;
lodBias = 0.6;
}
Vector2d center = new Vector2d();
for (int i = -4; i <= 4; i++) for (int j = -4; j <= 4; j++) {
int regionI = regionX + i;
int regionJ = regionZ + j;
int index = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ);
if (index == -1)
continue;
// For the extra row of triangles to mask the seams
int index10 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ);
int index01 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI, regionJ + 1);
int index11 = worldRenderer.getSummariesTexturesHolder().getSummaryIndex(regionI + 1, regionJ + 1);
if (i < 4 && index10 == -1)
continue;
if (j < 4 && index01 == -1)
continue;
if (i < 4 && j < 4 && index11 == -1)
continue;
HeightmapImplementation sum = (HeightmapImplementation) world.getRegionsSummariesHolder().getHeightmap(regionI, regionJ);
// Early out
if (sum == null || !sum.isLoaded())
continue;
if (!renderer.getCamera().isBoxInFrustrum(new CollisionBox(regionI * 256, 0, regionJ * 256, 256, 1024, /*+ sum.getHeightMipmapped(0, 0, 9)*/
256)))
continue;
for (int l = 0; l < 8; l++) for (int m = 0; m < 8; m++) {
if (mask != null) {
if (mask.shouldMaskSlab(regionI * 8 + l, regionJ * 8 + m, sum.min[l][m], sum.max[l][m]))
continue;
}
center.set(regionI * 256 + l * 32 + 16, regionJ * 256 + m * 32 + 16);
int lod = detailLevels.length - (int) ((lodBias + Math.pow(Math.min(1024, center.distance(playerCenter)) / 1024, lodExponent)) * detailLevels.length);
// System.out.println(center.distance(playerCenter));
if (lod <= 0)
lod = 0;
if (lod >= detailLevels.length)
lod = detailLevels.length - 1;
// lod = 2;
// System.out.println("lod:"+lod);
// lod = Math.random() > 0.5 ? 1 : 2;
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte) index);
summariesAttributes.put((byte) index10);
summariesAttributes.put((byte) index01);
summariesAttributes.put((byte) index11);
lodInstanceCount[lod]++;
// Always add both so lod 1 is drew under
if (lod != 0) {
lod = 0;
summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null) {
summariesAttributes = MemoryUtil.memAlloc(9 * 9 * 8 * 8 * (4 + 2 * 4));
lodByteBuffer[lod] = summariesAttributes;
}
summariesAttributes.putFloat(regionI * 256 + l * 32);
summariesAttributes.putFloat(regionJ * 256 + m * 32);
summariesAttributes.put((byte) index);
summariesAttributes.put((byte) index10);
summariesAttributes.put((byte) index01);
summariesAttributes.put((byte) index11);
lodInstanceCount[lod]++;
}
}
}
// for(int lod = 0; lod < detailLevels.length; lod++) {
for (int lod = detailLevels.length - 1; lod >= 0; lod--) {
// Check if anything was supposed to be drew at this lod
ByteBuffer summariesAttributes = lodByteBuffer[lod];
if (summariesAttributes == null)
continue;
if (lod < 0) {
MemoryUtil.memFree(summariesAttributes);
continue;
}
// Flip buffer, box it for autodeletion, upload it
summariesAttributes.flip();
MemFreeByteBuffer auto_free_summariesAttributes = new MemFreeByteBuffer(summariesAttributes);
gridAttributes.uploadData(auto_free_summariesAttributes);
terrainShader.setUniform1i("lodLevel", lod);
terrainShader.setUniform1f("textureLodLevel", lod - 5);
terrainShader.setUniform1i("maskPresence", mask == null ? 0 : 1);
renderer.bindAttribute("vertexIn", grids[lod].asAttributeSource(VertexFormat.FLOAT, 3, 0, 0L));
renderer.bindAttribute("displacementIn", gridAttributes.asAttributeSource(VertexFormat.FLOAT, 2, (4 + 2 * 4), 0L, 1));
renderer.bindAttribute("indexIn", gridAttributes.asIntegerAttributeSource(VertexFormat.BYTE, 4, (4 + 2 * 4), 8L, 1));
renderer.draw(Primitive.TRIANGLE, 0, (detailLevels[lod] + 1) * (detailLevels[lod] + 1) * 2 * 3, lodInstanceCount[lod]);
}
}
renderer.setPolygonFillMode(PolygonFillMode.FILL);
}
Aggregations