aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/olacraft
diff options
context:
space:
mode:
authorolamedia <[email protected]>2012-10-02 08:44:44 +0600
committerolamedia <[email protected]>2012-10-02 08:44:44 +0600
commitf237dee94a617114f0af13f90d28493037e7edc4 (patch)
tree95a844185e5e45c0a0a2b345c300fe7c3751bdf2 /src/ru/olamedia/olacraft
parent22a02f099f05bf19a1a6e02879b8111d01d4f358 (diff)
fixed bitset issue
Diffstat (limited to 'src/ru/olamedia/olacraft')
-rw-r--r--src/ru/olamedia/olacraft/network/GameClient.java2
-rw-r--r--src/ru/olamedia/olacraft/network/GameServer.java10
-rw-r--r--src/ru/olamedia/olacraft/network/Network.java20
-rw-r--r--src/ru/olamedia/olacraft/network/packet/RegionDataPacket.java7
-rw-r--r--src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java213
-rw-r--r--src/ru/olamedia/olacraft/render/jogl/PlaneRenderer.java3
-rw-r--r--src/ru/olamedia/olacraft/scene/GameScene.java24
-rw-r--r--src/ru/olamedia/olacraft/world/chunk/BlockSlice.java61
-rw-r--r--src/ru/olamedia/olacraft/world/chunk/Chunk.java55
-rw-r--r--src/ru/olamedia/olacraft/world/chunk/ChunkSlice.java34
-rw-r--r--src/ru/olamedia/olacraft/world/data/ChunkData.java59
-rw-r--r--src/ru/olamedia/olacraft/world/data/HeightMap.java4
-rw-r--r--src/ru/olamedia/olacraft/world/data/RegionData.java4
-rw-r--r--src/ru/olamedia/olacraft/world/data/SectorData.java10
-rw-r--r--src/ru/olamedia/olacraft/world/dataProvider/CachedChunkDataProvider.java17
-rw-r--r--src/ru/olamedia/olacraft/world/dataProvider/LocalChunkDataProvider.java109
-rw-r--r--src/ru/olamedia/olacraft/world/dataProvider/RemoteChunkDataProvider.java5
-rw-r--r--src/ru/olamedia/olacraft/world/generator/HeightMapGenerator.java15
-rw-r--r--src/ru/olamedia/olacraft/world/generator/RegionGenerator.java36
-rw-r--r--src/ru/olamedia/olacraft/world/location/ChunkLocation.java5
-rw-r--r--src/ru/olamedia/olacraft/world/location/RegionLocation.java12
-rw-r--r--src/ru/olamedia/olacraft/world/location/SectorLocation.java8
-rw-r--r--src/ru/olamedia/olacraft/world/provider/WorldProvider.java14
23 files changed, 415 insertions, 312 deletions
diff --git a/src/ru/olamedia/olacraft/network/GameClient.java b/src/ru/olamedia/olacraft/network/GameClient.java
index acd50fd..2312c3d 100644
--- a/src/ru/olamedia/olacraft/network/GameClient.java
+++ b/src/ru/olamedia/olacraft/network/GameClient.java
@@ -25,6 +25,7 @@ import ru.olamedia.olacraft.network.packet.WorldInfoPacket;
import ru.olamedia.olacraft.scene.GameScene;
import ru.olamedia.olacraft.world.WorldInfo;
import ru.olamedia.olacraft.world.dataProvider.CachedChunkDataProvider;
+import ru.olamedia.olacraft.world.dataProvider.LocalChunkDataProvider;
import ru.olamedia.olacraft.world.dataProvider.RemoteChunkDataProvider;
import ru.olamedia.olacraft.world.provider.WorldProvider;
@@ -64,6 +65,7 @@ public class GameClient extends ConnectionStateListener implements IPacketListen
// INIT WORLD
worldProvider = new WorldProvider();
worldProvider.setChunkDataProvider(new CachedChunkDataProvider(new RemoteChunkDataProvider(this)));
+ //worldProvider.setChunkDataProvider(new CachedChunkDataProvider(new LocalChunkDataProvider(worldProvider.getInfo().name)));
// CREATE SCENE
scene = new GameScene(worldProvider);
Kryo kryo = client.getKryo();
diff --git a/src/ru/olamedia/olacraft/network/GameServer.java b/src/ru/olamedia/olacraft/network/GameServer.java
index 3d3832d..e1e7723 100644
--- a/src/ru/olamedia/olacraft/network/GameServer.java
+++ b/src/ru/olamedia/olacraft/network/GameServer.java
@@ -31,7 +31,7 @@ import com.esotericsoftware.kryonet.Server;
public class GameServer {
private WorldProvider worldProvider;
-
+
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
public static Server server = new Server(10 * 1024 * 1024, 1024 * 1024) {
@Override
@@ -56,7 +56,10 @@ public class GameServer {
public GameServer() {
// INIT WORLD
worldProvider = new WorldProvider();
- worldProvider.setChunkDataProvider(new CachedChunkDataProvider(new LocalChunkDataProvider(worldProvider.getInfo().name)));
+ // worldProvider.setChunkDataProvider(new
+ // LocalChunkDataProvider(worldProvider.getInfo().name));
+ worldProvider.setChunkDataProvider(new CachedChunkDataProvider(new LocalChunkDataProvider(worldProvider
+ .getInfo().name)));
// CREATE SCENE
scene = new GameScene(worldProvider);
// worldProvider.getInfo().name = "world";
@@ -78,8 +81,7 @@ public class GameServer {
if (object instanceof GetRegionPacket) {
GetRegionPacket p = (GetRegionPacket) object;
RegionData data = worldProvider.getRegion(p.location);
- RegionDataPacket response = new RegionDataPacket();
- response.data = data;
+ RegionDataPacket response = new RegionDataPacket(data);
server.sendToTCP(connection.getID(), response);
}
if (object instanceof SpawnRequestPacket) {
diff --git a/src/ru/olamedia/olacraft/network/Network.java b/src/ru/olamedia/olacraft/network/Network.java
index 2ba8eab..22434f1 100644
--- a/src/ru/olamedia/olacraft/network/Network.java
+++ b/src/ru/olamedia/olacraft/network/Network.java
@@ -2,6 +2,9 @@ package ru.olamedia.olacraft.network;
import java.util.BitSet;
+import org.objenesis.strategy.SerializingInstantiatorStrategy;
+
+import ru.olamedia.math.OpenBitSet;
import ru.olamedia.olacraft.network.packet.ChunkDataPacket;
import ru.olamedia.olacraft.network.packet.ConnectionPacket;
import ru.olamedia.olacraft.network.packet.ConnectionRequestPacket;
@@ -26,7 +29,14 @@ import ru.olamedia.olacraft.world.location.SectorLocation;
import com.esotericsoftware.kryo.Kryo;
public class Network {
+ private static boolean isRegistered = false;
+
public static void registerPackets(Kryo kryo) {
+ if (isRegistered) {
+ // return;
+ }
+ isRegistered = true;
+ //kryo.setInstantiatorStrategy(new SerializingInstantiatorStrategy());
// types
kryo.register(boolean.class);
kryo.register(boolean[].class);
@@ -39,7 +49,7 @@ public class Network {
kryo.register(float[].class);
kryo.register(long.class);
kryo.register(long[].class);
- kryo.register(BitSet.class);
+ kryo.register(OpenBitSet.class);
kryo.register(HeightMap.class);
kryo.register(WorldInfo.class);
kryo.register(WorldInfoPacket.class);
@@ -55,17 +65,11 @@ public class Network {
kryo.register(RegionData.class);
kryo.register(GetRegionPacket.class);
kryo.register(RegionDataPacket.class);
-
-
- kryo.register(ChunkLightData.class);
- kryo.register(ChunkData.class);
- // packets
kryo.register(ConnectionRequestPacket.class);
kryo.register(ConnectionPacket.class);
kryo.register(SpawnRequestPacket.class);
kryo.register(SpawnPacket.class);
- kryo.register(GetChunkDataPacket.class);
- kryo.register(ChunkDataPacket.class);
kryo.register(LiveEntityLocationUpdatePacket.class);
+ // packets
}
}
diff --git a/src/ru/olamedia/olacraft/network/packet/RegionDataPacket.java b/src/ru/olamedia/olacraft/network/packet/RegionDataPacket.java
index 3a60230..72ddba3 100644
--- a/src/ru/olamedia/olacraft/network/packet/RegionDataPacket.java
+++ b/src/ru/olamedia/olacraft/network/packet/RegionDataPacket.java
@@ -3,5 +3,12 @@ package ru.olamedia.olacraft.network.packet;
import ru.olamedia.olacraft.world.data.RegionData;
public class RegionDataPacket implements IPacket {
+ public RegionDataPacket() {
+ }
+
+ public RegionDataPacket(RegionData data) {
+ this.data = data;
+ }
+
public RegionData data;
}
diff --git a/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java b/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java
index e24e8e9..22a88ab 100644
--- a/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java
+++ b/src/ru/olamedia/olacraft/render/jogl/ChunkRenderer.java
@@ -4,6 +4,8 @@ import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLContext;
+import ru.olamedia.Options;
+import ru.olamedia.geom.SimpleQuadMesh;
import ru.olamedia.math.Box;
import ru.olamedia.math.Classifier;
import ru.olamedia.olacraft.game.Game;
@@ -11,6 +13,8 @@ import ru.olamedia.olacraft.world.chunk.BlockSlice;
import ru.olamedia.olacraft.world.chunk.Chunk;
import ru.olamedia.olacraft.world.chunk.ChunkMeshBulder;
import ru.olamedia.olacraft.world.chunk.ChunkSlice;
+import ru.olamedia.olacraft.world.location.BlockLocation;
+import ru.olamedia.olacraft.world.location.ChunkLocation;
public class ChunkRenderer {
private BlockSlice slice;
@@ -30,22 +34,21 @@ public class ChunkRenderer {
public int frustumIntersectChunks = 0;
public boolean renderChunk(Chunk chunk, boolean skipnew) {
- GL gl = GLContext.getCurrentGL();
+
if (!chunk.isAvailable()) {
// System.out.println("not available");
chunk.request();
return skipnew;
}
- /*
- * if (!chunk.isNeighborsAvailable()) {
- * System.out.println("no neighbors");
- * chunk.requestNeighbors();
- * return;
- * }
- */
+
+ if (!chunk.isNeighborsAvailable()) {
+ chunk.requestNeighbors();
+ return skipnew;
+ }
+
// System.out.println("available");
- Box box = new Box(chunk.getX(), chunk.getY(), chunk.getZ(), chunk.getX() + chunk.getWidth(), chunk.getY()
- + chunk.getHeight(), chunk.getZ() + chunk.getDepth());
+ Box box = new Box(chunk.getOffset().x, chunk.getOffset().y, chunk.getOffset().z, chunk.getOffset().x
+ + chunk.getWidth(), chunk.getOffset().y + chunk.getHeight(), chunk.getOffset().z + chunk.getDepth());
if (Game.instance.camera.frustum.quickClassify(box) == Classifier.OUTSIDE) {
frustumCulledChunks++;
return skipnew;
@@ -74,20 +77,27 @@ public class ChunkRenderer {
if (!chunk.isMeshCostructed) {
ChunkMeshBulder.instance.add(chunk);
if (ChunkMeshBulder.instance.isFull()) {
+ // System.out.println("queue is full, skipping");
skipnew = true;
}
+ // System.out.println("not constructed");
return skipnew;
}
if (null == chunk.getMesh()) {
+ // System.out.println("mesh is null");
+ // skipnew = true;
} else {
- chunk.getMesh().joglRender(gl);
+ SimpleQuadMesh mesh = chunk.getMesh();
+ // System.out.println("render " + chunk + " " +
+ // mesh.getVertexCount());
+ mesh.joglRender();
}
return skipnew;
}
public void render(GLAutoDrawable drawable) {
- if (!ChunkMeshBulder.instance.isAlive()) {
+ if (!ChunkMeshBulder.instance.isAlive() && !ChunkMeshBulder.instance.isInterrupted()) {
ChunkMeshBulder.instance.start();
}
@@ -100,47 +110,162 @@ public class ChunkRenderer {
frustumCulledChunks = 0;
boolean skipnew = false;
ChunkSlice cs = slice.getChunkSlice();
+ for (int x = cs.getX(); x < cs.getX() + cs.getWidth(); x++) {
+ for (int z = cs.getZ(); z < cs.getZ() + cs.getDepth(); z++) {
+ for (int y = cs.getY(); y < cs.getY() + cs.getHeight(); y++) {
+ skipnew = renderChunk(cs.getChunk(new ChunkLocation(x, y, z)), skipnew);
+ }
+ }
+ }
+ if (true) {
+ return;
+ }
// rendering from center
int x, y, z;
- int dw = cs.getWidth() / 2;
- int dd = cs.getDepth() / 2;
- int dh = cs.getHeight() / 2;
- for (int dx = 0; dx < dw; dx++) {
- x = cs.getX() + dw + dx;
- for (int dz = 0; dz < dd; dz++) {
- z = cs.getZ() + dd + dz;
- for (int dy = 0; dy < dh; dy++) {
- y = cs.getY() + dh + dy;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
- y = cs.getY() + dh - dy - 1;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ int half = (Options.renderDistance / 16) / 2 + 1;
+ BlockLocation camera = new BlockLocation();
+ camera.x = (int) Game.client.getScene().getPlayer().getCameraX();
+ camera.y = (int) Game.client.getScene().getPlayer().getCameraY();
+ camera.z = (int) Game.client.getScene().getPlayer().getCameraZ();
+ ChunkLocation cameraChunk = camera.getChunkLocation();
+ int cx = cameraChunk.x;
+ int cy = cameraChunk.y;
+ int cz = cameraChunk.z;
+ ChunkLocation cLoc = new ChunkLocation(cx, cy, cz);
+ for (int r = 0; r <= half; r++) {
+ // +x
+ x = cx + r;
+ for (z = cz - r - 1; z <= cz + r; z++) {
+ for (y = cy - r - 1; y <= cy + r; y++) {
+ cLoc = new ChunkLocation(x, y, z);
+ skipnew = renderChunk(cs.getChunk(cLoc), skipnew);
}
- z = cs.getZ() + dd - dz - 1;
- for (int dy = 0; dy < dh; dy++) {
- y = cs.getY() + dh + dy;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
- y = cs.getY() + dh - dy - 1;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ }
+ // -x
+ x = cx - r - 1;
+ for (z = cz - r - 1; z <= cz + r; z++) {
+ for (y = cy - r - 1; y <= cy + r; y++) {
+ cLoc = new ChunkLocation(x, y, z);
+ skipnew = renderChunk(cs.getChunk(cLoc), skipnew);
+ }
+ }
+
+ // +z
+ z = cz + r;
+ for (x = cx - r - 1; x <= cz + r; x++) {
+ for (y = cy - r - 1; y <= cy + r; y++) {
+ cLoc = new ChunkLocation(x, y, z);
+ skipnew = renderChunk(cs.getChunk(cLoc), skipnew);
}
}
- x = cs.getX() + dw - dx - 1;
- for (int dz = 0; dz < dd; dz++) {
- z = cs.getZ() + dd + dz;
- for (int dy = 0; dy < dh; dy++) {
- y = cs.getY() + dh + dy;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
- y = cs.getY() + dh - dy - 1;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // -z
+ z = cz - r - 1;
+ for (x = cx - r - 1; x <= cz + r; x++) {
+ for (y = cy - r - 1; y <= cy + r; y++) {
+ cLoc = new ChunkLocation(x, y, z);
+ skipnew = renderChunk(cs.getChunk(cLoc), skipnew);
}
- z = cs.getZ() + dd - dz - 1;
- for (int dy = 0; dy < dh; dy++) {
- y = cs.getY() + dh + dy;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
- y = cs.getY() + dh - dy - 1;
- skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ }
+ // +y
+ y = cy + r;
+ for (x = cx - r - 1; x <= cz + r; x++) {
+ for (z = cz - r - 1; z <= cz + r; z++) {
+ cLoc = new ChunkLocation(x, y, z);
+ skipnew = renderChunk(cs.getChunk(cLoc), skipnew);
+ }
+ }
+ // -y
+ y = cy - r - 1;
+ for (x = cx - r - 1; x <= cz + r; x++) {
+ for (z = cz - r - 1; z <= cz + r; z++) {
+ cLoc = new ChunkLocation(x, y, z);
+ skipnew = renderChunk(cs.getChunk(cLoc), skipnew);
}
}
+ if (skipnew) {
+ // break;
+ }
+ // break;
}
+
+ // int dw = cs.getWidth() / 2;
+ // int dd = cs.getDepth() / 2;
+ // int dh = cs.getHeight() / 2;
+ // for (int dx = 0; dx < dw; dx++) {
+ // x = cs.getX() + dw + dx;
+ // for (int dz = 0; dz < dd; dz++) {
+ // z = cs.getZ() + dd + dz;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // z = cs.getZ() + dd - dz - 1;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // }
+ // x = cs.getX() + dw - dx - 1;
+ // for (int dz = 0; dz < dd; dz++) {
+ // z = cs.getZ() + dd + dz;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // int dd = cs.getDepth() / 2;
+ // int dh = cs.getHeight() / 2;
+ // for (int dx = 0; dx < dw; dx++) {
+ // x = cs.getX() + dw + dx;
+ // for (int dz = 0; dz < dd; dz++) {
+ // z = cs.getZ() + dd + dz;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // z = cs.getZ() + dd - dz - 1;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // }
+ // x = cs.getX() + dw - dx - 1;
+ // for (int dz = 0; dz < dd; dz++) {
+ // z = cs.getZ() + dd + dz;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // z = cs.getZ() + dd - dz - 1;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // }
+ // }
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // z = cs.getZ() + dd - dz - 1;
+ // for (int dy = 0; dy < dh; dy++) {
+ // y = cs.getY() + dh + dy;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // y = cs.getY() + dh - dy - 1;
+ // skipnew = renderChunk(cs.getChunk(x, y, z), skipnew);
+ // }
+ // }
+ // }
+
// System.out.println("visible top " + visibleTop);
}
}
diff --git a/src/ru/olamedia/olacraft/render/jogl/PlaneRenderer.java b/src/ru/olamedia/olacraft/render/jogl/PlaneRenderer.java
index 754a093..a6e796c 100644
--- a/src/ru/olamedia/olacraft/render/jogl/PlaneRenderer.java
+++ b/src/ru/olamedia/olacraft/render/jogl/PlaneRenderer.java
@@ -19,6 +19,9 @@ public class PlaneRenderer {
}
public static void render(Plane p, GLAutoDrawable drawable) {
+ if (true){
+ return;
+ }
GL2 gl = drawable.getGL().getGL2();
float size = 100;
float step = size / 5;
diff --git a/src/ru/olamedia/olacraft/scene/GameScene.java b/src/ru/olamedia/olacraft/scene/GameScene.java
index 618e270..7f2e1fa 100644
--- a/src/ru/olamedia/olacraft/scene/GameScene.java
+++ b/src/ru/olamedia/olacraft/scene/GameScene.java
@@ -25,6 +25,7 @@ import ru.olamedia.olacraft.weapon.BulletScene;
import ru.olamedia.olacraft.world.blockTypes.AbstractBlockType;
import ru.olamedia.olacraft.world.blockTypes.GrassBlockType;
import ru.olamedia.olacraft.world.chunk.BlockSlice;
+import ru.olamedia.olacraft.world.chunk.ChunkSlice;
import ru.olamedia.olacraft.world.provider.WorldProvider;
import ru.olamedia.player.Player;
import ru.olamedia.vbo.VBO;
@@ -97,7 +98,7 @@ public class GameScene {
*/
public void setRenderDistance(int renderDistance) {
this.renderDistance = renderDistance;
- viewSlice = new BlockSlice(provider, renderDistance, renderDistance * 2, renderDistance);
+ viewSlice = new BlockSlice(provider, renderDistance, renderDistance, renderDistance);
blockRenderer = new ChunkRenderer(viewSlice);
}
@@ -152,10 +153,12 @@ public class GameScene {
gl.glClearColor(49f / 255f, 119f / 255f, 243f / 255f, 1);
// GOING 3D
gl.glPushMatrix();
+ gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS);
Game.instance.camera.setUp(drawable);
viewSlice.setCenter((int) Game.instance.camera.getX(), (int) Game.instance.camera.getY(),
(int) Game.instance.camera.getZ());
// RENDER BLOCKS
+ gl.glPopAttrib();
gl.glPushAttrib(GL2.GL_ALL_ATTRIB_BITS);
gl.glColor4f(0f, 1f, 0, 1);
gl.glEnable(GL2.GL_DEPTH_TEST);
@@ -180,6 +183,7 @@ public class GameScene {
for (LiveEntity entity : liveEntities.values()) {
gl.glPushMatrix();
gl.glTranslatef(entity.getX(), entity.getCameraY(), entity.getZ());
+ gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE);
glu.gluSphere(qobj0, 0.5f, 10, 10);
gl.glPopMatrix();
}
@@ -187,7 +191,7 @@ public class GameScene {
// bullets.render(drawable);
gl.glPopMatrix();
- testObject.render();
+ // testObject.render();
// GOIND 2D
gl.glMatrixMode(GL2.GL_PROJECTION);
@@ -227,7 +231,7 @@ public class GameScene {
// inventoryprivate PMVMatrix matrix;
if (null != inventoryRenderer) {
- inventoryRenderer.render(drawable);
+ // inventoryRenderer.render(drawable);
}
viewport.drawText("avg fps: " + (int) Game.timer.getAvgFps(), 10, height - 20);
@@ -244,9 +248,21 @@ public class GameScene {
viewport.drawText("inAir: " + Game.instance.player.inAir(), width - msz - 10, height - msz - 110);
viewport.drawText("rdistance: " + renderDistance, width - msz - 10, height - msz - 155);
- viewport.drawText("cam x: " + Game.instance.camera.getX(), width - msz - 10, height - msz - 170);
+ ChunkSlice cs = viewSlice.getChunkSlice();
+ viewport.drawText("slice x: " + cs.getX() + ".." + (cs.getX() + cs.getWidth() - 1) + " y: " + cs.getY() + ".."
+ + (cs.getY() + cs.getHeight() - 1) + " z: " + cs.getZ() + ".." + (cs.getZ() + cs.getDepth() - 1), width
+ - msz * 2 - 10, height - msz - 170);
+ // viewport.drawText("slice x: " + (cs.getX() + cs.getWidth() - 1) +
+ // " y: " + (cs.getY() + cs.getHeight() - 1)
+ // + " z: " + (cs.getY() + cs.getDepth() - 1), width - msz * 2 - 10,
+ // height - msz - 185);
+
gl.glPopAttrib();
gl.glPopMatrix();
gl.glFlush();
}
+
+ public Player getPlayer() {
+ return player;
+ }
}
diff --git a/src/ru/olamedia/olacraft/world/chunk/BlockSlice.java b/src/ru/olamedia/olacraft/world/chunk/BlockSlice.java
index ca4c92a..bc744c4 100644
--- a/src/ru/olamedia/olacraft/world/chunk/BlockSlice.java
+++ b/src/ru/olamedia/olacraft/world/chunk/BlockSlice.java
@@ -1,37 +1,20 @@
package ru.olamedia.olacraft.world.chunk;
+import ru.olamedia.olacraft.world.location.BlockLocation;
+import ru.olamedia.olacraft.world.location.ChunkLocation;
import ru.olamedia.olacraft.world.provider.WorldProvider;
public class BlockSlice {
protected WorldProvider provider;
- protected int leftX;
- protected int bottomY;
- protected int backZ;
+ protected BlockLocation offset;
protected int width;
protected int height;
protected int depth;
protected ChunkSlice chunkSlice;
- // Memory leak:
- //protected int[][] highest = new int[256][256];
-
- public void invalidateCache(){
- //highest = new int[256][256];
+ public void invalidateCache() {
}
-
-/* public int getHighest(int blockX, int blockZ) {
- if (highest[blockX - leftX][blockZ - backZ] > 0){
- return highest[blockX - leftX][blockZ - backZ];
- }
- for (int y = 0; y < 128; y++) {
- if (provider.isEmptyBlock(blockX, y, blockZ)){
- highest[blockX - leftX][blockZ - backZ] = y;
- return y;
- }
- }
- return 0;
- }*/
/**
*
@@ -44,6 +27,7 @@ public class BlockSlice {
* (blocks)
*/
public BlockSlice(WorldProvider provider, int width, int height, int depth) {
+ offset = new BlockLocation();
this.provider = provider;
this.width = width;
this.height = height;
@@ -54,10 +38,8 @@ public class BlockSlice {
if (null == chunkSlice) {
chunkSlice = new ChunkSlice(provider, width / 16, height / 16, depth / 16);
}
- int x = Chunk.v(leftX);
- int y = Chunk.v(bottomY);
- int z = Chunk.v(backZ);
- chunkSlice.setLocation(x, y, z);
+ ChunkLocation chunkOffset = offset.getChunkLocation();
+ chunkSlice.setLocation(chunkOffset);
return chunkSlice;
}
@@ -120,12 +102,12 @@ public class BlockSlice {
* (blocks)
*/
public void setLocation(int x, int y, int z) {
- if (x != leftX || y != bottomY || z != backZ){
+ if (x != offset.x || y != offset.y || z != offset.z) {
invalidateCache();
}
- leftX = x;
- bottomY = y;
- backZ = z;
+ offset.x = x;
+ offset.y = y;
+ offset.z = z;
}
/**
@@ -142,23 +124,14 @@ public class BlockSlice {
}
/**
- * @return the left x (blocks)
- */
- public int getX() {
- return leftX;
- }
-
- /**
- * @return the bottom y (blocks)
+ * @return offset
*/
- public int getY() {
- return bottomY;
+ public BlockLocation getOffset() {
+ return offset;
}
- /**
- * @return the back z (blocks)
- */
- public int getZ() {
- return backZ;
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + "[" + offset + ";" + width + "x" + height + "x" + depth + "]";
}
}
diff --git a/src/ru/olamedia/olacraft/world/chunk/Chunk.java b/src/ru/olamedia/olacraft/world/chunk/Chunk.java
index ca2d4bf..0eaad3c 100644
--- a/src/ru/olamedia/olacraft/world/chunk/Chunk.java
+++ b/src/ru/olamedia/olacraft/world/chunk/Chunk.java
@@ -37,6 +37,24 @@ public class Chunk extends BlockSlice {
}
/**
+ * Convert chunk coordinate into block coordinate (back left bottom)
+ *
+ * @param v
+ * block coordinate along one axis
+ * @return
+ */
+ public static int rev(int v) {
+ return v * 16; // -32..-17 -16..-1 0..15 16..31 32..
+ /*
+ * if (v >= 0) {
+ * return v * 16;
+ * } else {
+ * return (v + 1) * 16 - 1;
+ * }
+ */
+ }
+
+ /**
* Convert block coordinate into block position inside of chunk
*
* @param v
@@ -78,11 +96,11 @@ public class Chunk extends BlockSlice {
if (isMeshCostructed) {
return mesh;
}
- if (getY() > provider.getInfo().maxHeight) {
+ if (offset.y > provider.getInfo().maxHeight) {
isMeshCostructed = true;
return null;
}
- if (getY() < provider.getInfo().minHeight) {
+ if (offset.y < provider.getInfo().minHeight) {
isMeshCostructed = true;
return null;
}
@@ -95,9 +113,9 @@ public class Chunk extends BlockSlice {
// gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_FASTEST);
// gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST);
GrassBlockType grass = new GrassBlockType();
- for (int x = getX(); x < getX() + getWidth(); x++) {
- for (int y = getY(); y < getY() + getHeight(); y++) {
- for (int z = getZ(); z < getZ() + getDepth(); z++) {
+ for (int x = offset.x; x < offset.x + getWidth(); x++) {
+ for (int y = offset.y; y < offset.y + getHeight(); y++) {
+ for (int z = offset.z; z < offset.z + getDepth(); z++) {
//
if (!isEmptyBlock(x, y, z)) {
@@ -168,6 +186,9 @@ public class Chunk extends BlockSlice {
mesh.addFrontQuad();
visibleFront++;
}
+ // System.out.println("mesh not empty");
+ } else {
+ // System.out.println("mesh empty");
}
}
}
@@ -193,7 +214,7 @@ public class Chunk extends BlockSlice {
}
private BlockLocation getBlockLocation() {
- return new BlockLocation(getX(), getY(), getZ());
+ return offset;
}
public boolean isAvailable() {
@@ -201,9 +222,9 @@ public class Chunk extends BlockSlice {
}
public boolean isNeighborsAvailable() {
- int x = Chunk.v(getX());
- int y = Chunk.v(getY());
- int z = Chunk.v(getZ());
+ int x = offset.getChunkLocation().x;
+ int y = offset.getChunkLocation().y;
+ int z = offset.getChunkLocation().z;
return provider.isChunkAvailable(new ChunkLocation(x - 1, y, z))
&& provider.isChunkAvailable(new ChunkLocation(x + 1, y, z))
&& provider.isChunkAvailable(new ChunkLocation(x, y - 1, z))
@@ -213,9 +234,9 @@ public class Chunk extends BlockSlice {
}
public void requestNeighbors() {
- int x = Chunk.v(getX());
- int y = Chunk.v(getY());
- int z = Chunk.v(getZ());
+ int x = offset.getChunkLocation().x;
+ int y = offset.getChunkLocation().y;
+ int z = offset.getChunkLocation().z;
if (!provider.isChunkAvailable(new ChunkLocation(x - 1, y, z))) {
provider.loadChunk(new ChunkLocation(x - 1, y, z));
}
@@ -237,11 +258,7 @@ public class Chunk extends BlockSlice {
}
public void request() {
- BlockLocation blockLocation = new BlockLocation(getX(), getY(), getZ());
- // System.out.println("provider.requestChunk(" +
- // blockLocation.getRegionLocation() + blockLocation.getChunkLocation()
- // + ")");
- provider.loadChunk(blockLocation.getChunkLocation());
+ provider.loadChunk(offset.getChunkLocation());
}
// public BlockType getBlockType(int x, int y, int z) {
@@ -287,4 +304,8 @@ public class Chunk extends BlockSlice {
public WorldProvider getProvider() {
return provider;
}
+
+ public void setLocation(ChunkLocation location) {
+ setLocation(location.getBlockLocation().x, location.getBlockLocation().y, location.getBlockLocation().z);
+ }
}
diff --git a/src/ru/olamedia/olacraft/world/chunk/ChunkSlice.java b/src/ru/olamedia/olacraft/world/chunk/ChunkSlice.java
index e440740..d0307bb 100644
--- a/src/ru/olamedia/olacraft/world/chunk/ChunkSlice.java
+++ b/src/ru/olamedia/olacraft/world/chunk/ChunkSlice.java
@@ -2,13 +2,12 @@ package ru.olamedia.olacraft.world.chunk;
import java.util.HashMap;
+import ru.olamedia.olacraft.world.location.ChunkLocation;
import ru.olamedia.olacraft.world.provider.WorldProvider;
public class ChunkSlice {
private WorldProvider provider;
- private int leftX;
- private int bottomY;
- private int backZ;
+ private ChunkLocation offset;
private int width;
private int height;
private int depth;
@@ -18,17 +17,21 @@ public class ChunkSlice {
this.width = width;
this.height = height;
this.depth = depth;
+ offset = new ChunkLocation();
}
protected HashMap<String, Chunk> chunks = new HashMap<String, Chunk>();
- public Chunk getChunk(int x, int y, int z) {
+ public Chunk getChunk(ChunkLocation location) {
+ int x = location.x;
+ int y = location.y;
+ int z = location.z;
String key = x + ";" + y + ";" + z;
if (chunks.containsKey(key)) {
return chunks.get(key);
} else {
Chunk chunk = new Chunk(provider);
- chunk.setLocation(x * 16, y * 16, z * 16);
+ chunk.setLocation(location);
chunks.put(key, chunk);
return chunk;
}
@@ -79,36 +82,33 @@ public class ChunkSlice {
this.depth = depth;
}
- public void setLocation(int x, int y, int z) {
- leftX = x;
- bottomY = y;
- backZ = z;
- }
-
public void setCenter(int x, int y, int z) {
- leftX = x - width / 2;
- bottomY = y - height / 2;
- backZ = z - depth / 2;
+ offset.x = x - width / 2;
+ offset.y = y - height / 2;
+ offset.z = z - depth / 2;
}
/**
* @return the leftX
*/
public int getX() {
- return leftX;
+ return offset.x;
}
/**
* @return the bottomY
*/
public int getY() {
- return bottomY;
+ return offset.y;
}
/**
* @return the backZ
*/
public int getZ() {
- return backZ;
+ return offset.z;
+ }
+ public void setLocation(ChunkLocation chunkOffset) {
+ offset = chunkOffset;
}
}
diff --git a/src/ru/olamedia/olacraft/world/data/ChunkData.java b/src/ru/olamedia/olacraft/world/data/ChunkData.java
index a1abc9e..a6b9f34 100644
--- a/src/ru/olamedia/olacraft/world/data/ChunkData.java
+++ b/src/ru/olamedia/olacraft/world/data/ChunkData.java
@@ -1,8 +1,8 @@
package ru.olamedia.olacraft.world.data;
import java.io.Serializable;
-import java.util.BitSet;
+import ru.olamedia.math.OpenBitSet;
import ru.olamedia.olacraft.world.chunk.Chunk;
import ru.olamedia.olacraft.world.location.BlockLocation;
import ru.olamedia.olacraft.world.location.ChunkLocation;
@@ -12,58 +12,30 @@ public class ChunkData implements Serializable {
public ChunkLocation location;
public static transient int SIZE = 4096;
// private boolean[] notEmpty = new boolean[SIZE];
- private BitSet emptyBlocks = new BitSet(4096);
+ public OpenBitSet emptyBlocks = new OpenBitSet(4096);
public int notEmptyCount = 0;
// public transient int[] type = new int[SIZE];
- // /public transient ChunkLightData light;
public ChunkData() {
- // light = new ChunkLightData();
}
public void compact() {
- if (notEmptyCount == 0) {
+ if (emptyBlocks.cardinality() == 0) {
emptyBlocks = null;
}
}
- public static int normalize(int v) {
- int n = v;
- if (n > 15) {
- n = n % 16;
- }
- if (n < 0) {
- n = 16 + n % 16 - 1;
- // v = 15 - v;
- }
- // System.out.println("normalize(" + v + ") = " + n);
- return n;
- }
-
- public static int getId(int xInsideChunk, int yInsideChunk, int zInsideChunk) {
- xInsideChunk = normalize(xInsideChunk);
- yInsideChunk = normalize(yInsideChunk);
- zInsideChunk = normalize(zInsideChunk);
- int id = xInsideChunk * 16 * 16 + yInsideChunk * 16 + zInsideChunk;
- if (id > SIZE) {
- System.err.println("Exception while getID(" + xInsideChunk + "," + yInsideChunk + "," + zInsideChunk + ")");
- throw new ArrayIndexOutOfBoundsException(id);
- }
- return id;
- }
-
public boolean isEmpty(BlockLocation blockLocation) {
- if (notEmptyCount == 0) {
+ if (emptyBlocks == null) {
return true;
}
- int id = getId(Chunk.in(blockLocation.x), Chunk.in(blockLocation.y), Chunk.in(blockLocation.z));
+ int id = Chunk.in(blockLocation.x) * 16 * 16 + Chunk.in(blockLocation.y) * 16 + Chunk.in(blockLocation.z);
return isEmpty(id);
- // return !notEmpty[id];
}
public boolean isEmpty(int id) {
- if (notEmptyCount == 0) {
+ if (emptyBlocks == null) {
return true;
}
return emptyBlocks.get(id);
@@ -77,10 +49,25 @@ public class ChunkData implements Serializable {
notEmptyCount--;
}
}
- emptyBlocks.set(id, isEmpty);
+ if (isEmpty) {
+ emptyBlocks.set(id);
+ } else {
+ emptyBlocks.clear(id);
+ }
}
public boolean isEmpty() {
- return notEmptyCount == 0;
+ return emptyBlocks == null || emptyBlocks.cardinality() == 0;
+ }
+
+ public void setEmpty(int inChunkX, int inChunkY, int inChunkZ, boolean isEmpty) {
+ int id = inChunkX * 16 * 16 + inChunkY * 16 + inChunkZ;
+ setEmpty(id, isEmpty);
}
+
+ public void setEmpty(BlockLocation blockLocation, boolean isEmpty) {
+ int id = Chunk.in(blockLocation.x) * 16 * 16 + Chunk.in(blockLocation.y) * 16 + Chunk.in(blockLocation.z);
+ setEmpty(id, isEmpty);
+ }
+
}
diff --git a/src/ru/olamedia/olacraft/world/data/HeightMap.java b/src/ru/olamedia/olacraft/world/data/HeightMap.java
index b2c0a63..4d5d458 100644
--- a/src/ru/olamedia/olacraft/world/data/HeightMap.java
+++ b/src/ru/olamedia/olacraft/world/data/HeightMap.java
@@ -12,10 +12,14 @@ import java.io.Serializable;
public class HeightMap implements Serializable {
private static final long serialVersionUID = -6777972159522169977L;
public byte[][] map; // -128..127
+ public int width;
+ public int height;
public HeightMap(){
}
public HeightMap(int width, int height) {
+ this.width = width;
+ this.height = height;
map = new byte[width][height];
}
diff --git a/src/ru/olamedia/olacraft/world/data/RegionData.java b/src/ru/olamedia/olacraft/world/data/RegionData.java
index fa292d2..f58a424 100644
--- a/src/ru/olamedia/olacraft/world/data/RegionData.java
+++ b/src/ru/olamedia/olacraft/world/data/RegionData.java
@@ -24,6 +24,10 @@ public class RegionData implements Serializable {
public HeightMap heightMap = new HeightMap(256, 256);
public SectorData[][] sectorData = new SectorData[16][16];
+ public RegionData(){
+
+ }
+
public void writeTo(OutputStream stream) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(stream);
out.writeObject(this);
diff --git a/src/ru/olamedia/olacraft/world/data/SectorData.java b/src/ru/olamedia/olacraft/world/data/SectorData.java
index 12a97cd..31526a7 100644
--- a/src/ru/olamedia/olacraft/world/data/SectorData.java
+++ b/src/ru/olamedia/olacraft/world/data/SectorData.java
@@ -12,10 +12,14 @@ import ru.olamedia.olacraft.world.location.SectorLocation;
*/
public class SectorData implements Serializable{
private static final long serialVersionUID = 5304471397211814748L;
- public HeightMap heightMap; // locations of highest nonempty blocks
- public ChunkData[] chunkData; // 256/16 = 16
+ public HeightMap heightMap = new HeightMap(16, 16); // locations of highest nonempty blocks
+ public ChunkData[] chunkData = new ChunkData[16]; // 256/16 = 16
public SectorLocation location;
+ public SectorData(){
+
+ }
+
public static int yIndex(int y) {
return (y + 128) / 16;
// 1: (-128 + 128) / 16 = 0
@@ -26,8 +30,6 @@ public class SectorData implements Serializable{
}
public static SectorData generate(){
SectorData data = new SectorData();
- data.heightMap = new HeightMap(16, 16);
- data.chunkData = new ChunkData[16];
return data;
}
}
diff --git a/src/ru/olamedia/olacraft/world/dataProvider/CachedChunkDataProvider.java b/src/ru/olamedia/olacraft/world/dataProvider/CachedChunkDataProvider.java
index 23270a7..444cff6 100644
--- a/src/ru/olamedia/olacraft/world/dataProvider/CachedChunkDataProvider.java
+++ b/src/ru/olamedia/olacraft/world/dataProvider/CachedChunkDataProvider.java
@@ -27,29 +27,19 @@ public class CachedChunkDataProvider extends AbstractChunkDataProvider {
@Override
public boolean isRegionAvailable(RegionLocation regionLocation) {
String key = regionLocation.toString();// regionLocation.x + "-" +
- // regionLocation.z;
if (regionMap.containsKey(key)) {
return true;
}
- if (loading.contains(key)) {
- // return false;
- }
return provider.isRegionAvailable(regionLocation);
}
@Override
public void loadRegion(RegionLocation regionLocation) {
String key = regionLocation.toString();
- //debug("loadRegion(" + regionLocation + ")");
+ // debug("loadRegion(" + regionLocation + ")");
if (!regionMap.containsKey(key)) {
- if (!loading.contains(key)) {
- debug("load()");
- loading.add(key);
- provider.loadRegion(regionLocation);
- }else{
- //debug("loadRegion(" + regionLocation + ") already in loading");
- }
- }else{
+ provider.loadRegion(regionLocation);
+ } else {
debug("error: loadRegion(" + regionLocation + ") already in regionMap");
}
}
@@ -62,7 +52,6 @@ public class CachedChunkDataProvider extends AbstractChunkDataProvider {
} else {
RegionData data = provider.getRegion(regionLocation);
regionMap.put(key, data);
- loading.remove(key);
return data;
}
}
diff --git a/src/ru/olamedia/olacraft/world/dataProvider/LocalChunkDataProvider.java b/src/ru/olamedia/olacraft/world/dataProvider/LocalChunkDataProvider.java
index 514081f..887421f 100644
--- a/src/ru/olamedia/olacraft/world/dataProvider/LocalChunkDataProvider.java
+++ b/src/ru/olamedia/olacraft/world/dataProvider/LocalChunkDataProvider.java
@@ -9,10 +9,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
-import ru.olamedia.olacraft.world.data.ChunkData;
import ru.olamedia.olacraft.world.data.RegionData;
-import ru.olamedia.olacraft.world.generator.HeightMapGenerator;
import ru.olamedia.olacraft.world.generator.RegionGenerator;
import ru.olamedia.olacraft.world.location.RegionLocation;
@@ -80,41 +80,23 @@ public class LocalChunkDataProvider extends AbstractChunkDataProvider {
debug("loadRegion(" + regionLocation + ")");
}
- private ChunkData createChunk(int chunkX, int chunkY, int chunkZ) {
- debug("createChunk " + chunkX + " " + chunkY + " " + chunkZ);
- ChunkData data = new ChunkData();
- try {
- getSeed();
- } catch (IOException e) {
- e.printStackTrace();
- }
- HeightMapGenerator.minValue = 1;
- HeightMapGenerator.maxValue = 64;
- HeightMapGenerator.init();
- HeightMapGenerator.seed = seed[0];
- int[][] heightMap = HeightMapGenerator.getChunkHeightMap(chunkX, chunkZ);
- for (int y = 0; y < 16; y++) {
- for (int x = 0; x < 16; x++) {
- for (int z = 0; z < 16; z++) {
- data.setEmpty(ChunkData.getId(x, y, z), (heightMap[x][z] < chunkY * 16 + y));
- }
- }
- }
- return data;
- }
-
+ @SuppressWarnings("unused")
@Override
public RegionData getRegion(RegionLocation regionLocation) {
String filename = path + File.separator + regionLocation.getFilename();
RegionData data = null;
- // TODO READ/WRITE FILE
+ if (true) {
+ return generateRegion(regionLocation);
+ }
File chunkFile = new File(filename);
- if (chunkFile.exists()) {
+ if (false && chunkFile.exists()) {
InputStream in;
try {
- in = new FileInputStream(chunkFile);
+ FileInputStream fIn = new FileInputStream(chunkFile);
+ in = new GZIPInputStream(fIn);
data = RegionData.loadFrom(in);
in.close();
+ fIn.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
@@ -124,11 +106,14 @@ public class LocalChunkDataProvider extends AbstractChunkDataProvider {
}
} else {
data = generateRegion(regionLocation);
+ OutputStream out;
try {
chunkFile.createNewFile();
- FileOutputStream out = new FileOutputStream(chunkFile);
+ FileOutputStream fOut = new FileOutputStream(chunkFile);
+ out = new GZIPOutputStream(fOut);
data.writeTo(out);
out.close();
+ fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
@@ -139,7 +124,6 @@ public class LocalChunkDataProvider extends AbstractChunkDataProvider {
public RegionData generateRegion(RegionLocation regionLocation) {
RegionData data = new RegionData();
data.location = regionLocation;
- // TODO FILL HERE
RegionGenerator generator = new RegionGenerator();
try {
generator.setSeed(getSeed());
@@ -150,69 +134,4 @@ public class LocalChunkDataProvider extends AbstractChunkDataProvider {
return data;
}
- public ChunkData get(int chunkX, int chunkY, int chunkZ) {
- debug("get " + chunkX + " " + chunkY + " " + chunkZ);
- ChunkData data = null;
- String filename = path + File.separator + chunkX + "_" + chunkY + "_" + chunkZ + ".chunk";
- /*
- * File chunkFile = new File(filename);
- * if (chunkFile.exists()) {
- * try {
- * InputStream in = new FileInputStream(chunkFile);
- * DataInputStream din = new DataInputStream(in);
- * data = new ChunkData();
- * data.readFrom(din);
- * din.close();
- * in.close();
- * } catch (FileNotFoundException e) {
- * e.printStackTrace();
- * } catch (IOException e) {
- * e.printStackTrace();
- * }
- * } else {
- */
- data = createChunk(chunkX, chunkY, chunkZ);
- /*
- * OutputStream out = null;
- * ByteArrayOutputStream bout = null;
- * DataOutputStream dout = null;
- * try {
- * chunkFile.createNewFile();
- * out = new FileOutputStream(chunkFile);
- * // bout = new ByteArrayOutputStream(4096);
- * dout = new DataOutputStream(out);
- * data.writeTo(dout);
- * // dout.flush();
- * // out.write(bout.toByteArray());
- * out.flush();
- * } catch (IOException e) {
- * e.printStackTrace();
- * } finally {
- * if (null != dout) {
- * try {
- * dout.close();
- * } catch (IOException e) {
- * e.printStackTrace();
- * }
- * }
- * if (null != bout) {
- * try {
- * bout.close();
- * } catch (IOException e) {
- * e.printStackTrace();
- * }
- * }
- * if (null != out) {
- * try {
- * out.close();
- * } catch (IOException e) {
- * e.printStackTrace();
- * }
- * }
- * }
- * }
- */
- return data;
- }
-
}
diff --git a/src/ru/olamedia/olacraft/world/dataProvider/RemoteChunkDataProvider.java b/src/ru/olamedia/olacraft/world/dataProvider/RemoteChunkDataProvider.java
index 8284ff9..cd48071 100644
--- a/src/ru/olamedia/olacraft/world/dataProvider/RemoteChunkDataProvider.java
+++ b/src/ru/olamedia/olacraft/world/dataProvider/RemoteChunkDataProvider.java
@@ -36,8 +36,8 @@ public class RemoteChunkDataProvider extends AbstractChunkDataProvider implement
@Override
public void loadRegion(RegionLocation regionLocation) {
String key = regionLocation.toString();
- debug("loadRegion(" + key + ")");
if (!loading.contains(key)) {
+ debug("loadRegion(" + key + ")");
loading.add(key);
client.send(new GetRegionPacket(regionLocation));
debug("sent packet: GetRegionPacket");
@@ -64,8 +64,9 @@ public class RemoteChunkDataProvider extends AbstractChunkDataProvider implement
@Override
public void onPacket(Connection connection, IPacket p) {
if (p instanceof RegionDataPacket) {
- debug("received packet [conn " + connection.getID() + "]: ChunkDataPacket");
+ debug("received packet [conn " + connection.getID() + "]: RegionDataPacket");
RegionData data = ((RegionDataPacket) p).data;
+ System.out.println(data.sectorData[0][0].chunkData[15].isEmpty(0) + "");
String key = data.location.toString();
map.put(key, data);
loading.remove(key);
diff --git a/src/ru/olamedia/olacraft/world/generator/HeightMapGenerator.java b/src/ru/olamedia/olacraft/world/generator/HeightMapGenerator.java
index c3e32b5..649961f 100644
--- a/src/ru/olamedia/olacraft/world/generator/HeightMapGenerator.java
+++ b/src/ru/olamedia/olacraft/world/generator/HeightMapGenerator.java
@@ -77,6 +77,7 @@ public class HeightMapGenerator {
maxTerrain = new Max(plains, turbulence);
finalTerrain = new ScaleBias(maxTerrain);
finalTerrain.setBias(2);
+ finalTerrain.setScale(0.4);
setSeed(seed);
} catch (ExceptionInvalidParam e) {
e.printStackTrace();
@@ -117,7 +118,7 @@ public class HeightMapGenerator {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
// System.out.print(((float) heights[x][z]) + ";");
- ints[x][z] = (int) (minValue + (maxValue - minValue) * (heights[x][z] + 1) / 2);
+ ints[x][z] = (int) (50 + minValue + (maxValue - minValue) * (heights[x][z] + 1) / 2);
}
}
// System.out.println("");
@@ -137,15 +138,17 @@ public class HeightMapGenerator {
builder.setSourceModule(finalTerrain);
builder.setDestNoiseMap(heightMap);
builder.setDestSize(256, 256);
- float bx = location.x;
- float bz = location.z;
- builder.setBounds(bx, bx + 1, bz, bz + 1);
+ float bx = location.getBlockLocation().x;
+ float bz = location.getBlockLocation().z;
+ float cx = location.getChunkLocation().x;
+ float cz = location.getChunkLocation().z;
+ builder.setBounds(cx, cx + 16, cz, cz + 16);
builder.build();
double[][] heights = heightMap.getNoiseMap();
for (int x = 0; x < 256; x++) {
for (int z = 0; z < 256; z++) {
- map.setHeight(x, z, 0);
- //(int) (minValue + (maxValue - minValue) * (heights[x][z] + 1) / 2)
+ // map.setHeight(x, z, 0);
+ map.setHeight(x, z, (int) (minValue + ((1 + heights[x][z]) / 2) * (maxValue - minValue)));
}
}
return map;
diff --git a/src/ru/olamedia/olacraft/world/generator/RegionGenerator.java b/src/ru/olamedia/olacraft/world/generator/RegionGenerator.java
index 9657e32..05fc067 100644
--- a/src/ru/olamedia/olacraft/world/generator/RegionGenerator.java
+++ b/src/ru/olamedia/olacraft/world/generator/RegionGenerator.java
@@ -21,42 +21,54 @@ public class RegionGenerator {
public void generate(RegionData data) {
HeightMapGenerator.minValue = -5;
- HeightMapGenerator.maxValue = 100;
+ HeightMapGenerator.maxValue = 60;
HeightMapGenerator.init();
HeightMapGenerator.seed = seed[0];
- BlockLocation offset = data.location.getBlockLocation();
+ // BlockLocation blockOffset = data.location.getBlockLocation();
+ SectorLocation sectorOffset = data.location.getSectorLocation();
// int[][] heightMap =
// HeightMapGenerator.getHeightMap(data.location.getBlockLocation().x,
// data.location.getBlockLocation().z, 256, 256);
debug(data.location.toString());
data.heightMap = HeightMapGenerator.getHeightMap(data.location);
- //debug(data.heightMap.toString());
+ // debug(data.heightMap.toString());
data.sectorData = new SectorData[16][16];
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
// CREATE SECTOR
SectorData sector = new SectorData();
- sector.location = new SectorLocation(offset.x + x * 16, offset.z + z * 16);
+ sector.location = new SectorLocation(sectorOffset.x + x, sectorOffset.z + z);
sector.heightMap = new HeightMap(16, 16);
sector.chunkData = new ChunkData[16];
for (int y = 0; y < 16; y++) {
// CREATE CHUNK
ChunkData chunk = new ChunkData();
chunk.location = new ChunkLocation(sector.location.x, y, sector.location.z);
- int chunkOffsetY = y * 16 - 128;
+ BlockLocation chunkOffset = chunk.location.getBlockLocation();
for (int inChunkX = 0; inChunkX < 16; inChunkX++) {
for (int inChunkZ = 0; inChunkZ < 16; inChunkZ++) {
int height = data.heightMap.getHeight(x * 16 + inChunkX, z * 16 + inChunkZ);
- //System.out.println("height: " + height);
+ // System.out.println("height: " + height);
sector.heightMap.setHeight(inChunkX, inChunkZ, height);
+ BlockLocation blockOffset = new BlockLocation();
+ blockOffset.x = chunkOffset.x + inChunkX;
+ blockOffset.z = chunkOffset.z + inChunkZ;
for (int inChunkY = 0; inChunkY < 16; inChunkY++) {
- //height = sector.heightMap.getHeight(inChunkX, inChunkZ);
- int id = ChunkData.getId(inChunkX, inChunkY, inChunkZ);
- if (chunkOffsetY + inChunkY > height) {
- chunk.setEmpty(id, true);
+ blockOffset.y = chunkOffset.y + inChunkY;
+ // height = sector.heightMap.getHeight(inChunkX,
+ // inChunkZ);
+ if (blockOffset.y > height) {
+ // System.out.println("--- height: " +
+ // height + " block:" + blockOffset);
+ chunk.setEmpty(blockOffset, true);
} else {
- //System.out.println("not empty, height: " + height);
- chunk.setEmpty(id, false);
+ if (blockOffset.y > 0) {
+ // System.out.println("+++ height: " +
+ // height + " block:" + blockOffset);
+ // System.out.println("not empty, height: "
+ // + height);
+ }
+ chunk.setEmpty(blockOffset, false);
}
}
}
diff --git a/src/ru/olamedia/olacraft/world/location/ChunkLocation.java b/src/ru/olamedia/olacraft/world/location/ChunkLocation.java
index 57acc52..a772c6d 100644
--- a/src/ru/olamedia/olacraft/world/location/ChunkLocation.java
+++ b/src/ru/olamedia/olacraft/world/location/ChunkLocation.java
@@ -32,9 +32,14 @@ public class ChunkLocation implements Serializable {
public String toString() {
return "chunkLocation[" + x + "," + y + "," + z + "]";
}
+
/*
* public BlockSlice getSlice(){
*
* }
*/
+
+ public BlockLocation getBlockLocation() {
+ return new BlockLocation(Chunk.rev(x), Chunk.rev(y) - 128, Chunk.rev(z));
+ }
}
diff --git a/src/ru/olamedia/olacraft/world/location/RegionLocation.java b/src/ru/olamedia/olacraft/world/location/RegionLocation.java
index 59a57ec..a1100c0 100644
--- a/src/ru/olamedia/olacraft/world/location/RegionLocation.java
+++ b/src/ru/olamedia/olacraft/world/location/RegionLocation.java
@@ -2,6 +2,8 @@ package ru.olamedia.olacraft.world.location;
import java.io.Serializable;
+import ru.olamedia.olacraft.world.chunk.Chunk;
+
public class RegionLocation implements Serializable {
private static final long serialVersionUID = -141619138379029773L;
public int x;
@@ -23,7 +25,15 @@ public class RegionLocation implements Serializable {
return "" + x + "_" + z + ".region";
}
+ public SectorLocation getSectorLocation() {
+ return new SectorLocation(Chunk.rev(x), Chunk.rev(z));
+ }
+
+ public ChunkLocation getChunkLocation() {
+ return new ChunkLocation(Chunk.rev(x), 0, Chunk.rev(z));
+ }
+
public BlockLocation getBlockLocation() {
- return new BlockLocation(x * 256, 0, z * 256);
+ return new BlockLocation(Chunk.rev(Chunk.rev(x)), 0, Chunk.rev(Chunk.rev(z)));
}
}
diff --git a/src/ru/olamedia/olacraft/world/location/SectorLocation.java b/src/ru/olamedia/olacraft/world/location/SectorLocation.java
index 59390b8..0c3af25 100644
--- a/src/ru/olamedia/olacraft/world/location/SectorLocation.java
+++ b/src/ru/olamedia/olacraft/world/location/SectorLocation.java
@@ -23,6 +23,14 @@ public class SectorLocation implements Serializable {
return new RegionLocation(Chunk.v(x), Chunk.v(z));
}
+ public ChunkLocation getChunkLocation() {
+ return new ChunkLocation(Chunk.rev(x), 0, Chunk.rev(z));
+ }
+
+ public BlockLocation getBlockLocation() {
+ return new BlockLocation(Chunk.rev(Chunk.rev(x)), 0, Chunk.rev(Chunk.rev(z)));
+ }
+
public String toString() {
return "sectorLocation[" + x + "," + z + "]";
}
diff --git a/src/ru/olamedia/olacraft/world/provider/WorldProvider.java b/src/ru/olamedia/olacraft/world/provider/WorldProvider.java
index 8dacce9..b7984bc 100644
--- a/src/ru/olamedia/olacraft/world/provider/WorldProvider.java
+++ b/src/ru/olamedia/olacraft/world/provider/WorldProvider.java
@@ -45,9 +45,7 @@ public class WorldProvider {
spawnLocation.y = y;
System.out.print(y + ". ");
ChunkData chunk = dataProvider.getChunk(spawnLocation.getChunkLocation());
- boolean notEmpty = !chunk.isEmpty(ChunkData.getId(Chunk.in(spawnLocation.x), Chunk.in(spawnLocation.y),
- Chunk.in(spawnLocation.z)));
- if (notEmpty) {
+ if (!chunk.isEmpty(spawnLocation)) {
// found
l.y = y + 1;
System.out.println("found: " + y);
@@ -65,6 +63,9 @@ public class WorldProvider {
}
public boolean renderTop(int x, int y, int z) {
+ // System.out.println("Check render top " + y + "[" + x + " " + y + " "
+ // + z + "]" + !isEmptyBlock(x, y, z)
+ // + " && " + isEmptyBlock(x, y + 1, z));
return (!isEmptyBlock(x, y, z)) && (isEmptyBlock(x, y + 1, z));
}
@@ -91,9 +92,14 @@ public class WorldProvider {
ChunkData data = dataProvider.getChunk(blockLocation.getChunkLocation());
if (null != data) {
return data.isEmpty(blockLocation);
+ } else {
+ // System.out.println("chunk null " + x + " " + y + " " + z);
}
+ } else {
+ // System.out.println("chunk not available " + x + " " + y + " " +
+ // z);
}
- return false;
+ return true;
}
public void requestChunk(int chunkX, int chunkY, int chunkZ) {