Added actual storage capabilities to ChunkData
Also a block can be changed at (0; 0; 0) by pressing G
This commit is contained in:
parent
3e0f17c959
commit
ed9a52c7a5
@ -29,6 +29,8 @@ import ru.windcorp.optica.client.graphics.backend.GraphicsInterface;
|
|||||||
import ru.windcorp.optica.client.graphics.input.CursorMoveEvent;
|
import ru.windcorp.optica.client.graphics.input.CursorMoveEvent;
|
||||||
import ru.windcorp.optica.client.graphics.input.KeyEvent;
|
import ru.windcorp.optica.client.graphics.input.KeyEvent;
|
||||||
import ru.windcorp.optica.client.world.WorldRender;
|
import ru.windcorp.optica.client.world.WorldRender;
|
||||||
|
import ru.windcorp.optica.common.block.BlockData;
|
||||||
|
import ru.windcorp.optica.common.block.BlockDataRegistry;
|
||||||
import ru.windcorp.optica.common.world.WorldData;
|
import ru.windcorp.optica.common.world.WorldData;
|
||||||
|
|
||||||
public class LayerWorld extends Layer {
|
public class LayerWorld extends Layer {
|
||||||
@ -129,6 +131,19 @@ public class LayerWorld extends Layer {
|
|||||||
|
|
||||||
flag = !flag;
|
flag = !flag;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GLFW.GLFW_KEY_G:
|
||||||
|
if (!event.isPress()) return;
|
||||||
|
|
||||||
|
BlockData[][][] data = world.getData().getChunk(0, 0, 0).tmp_getBlocks();
|
||||||
|
if (data[0][0][0].getId().equals("Test:Stone")) {
|
||||||
|
data[0][0][0] = BlockDataRegistry.get("Test:Glass");
|
||||||
|
} else {
|
||||||
|
data[0][0][0] = BlockDataRegistry.get("Test:Stone");
|
||||||
|
}
|
||||||
|
world.getChunk(0, 0, 0).markForUpdate();
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public class ChunkRender {
|
|||||||
private final WorldRender world;
|
private final WorldRender world;
|
||||||
private final ChunkData data;
|
private final ChunkData data;
|
||||||
|
|
||||||
|
private boolean needsUpdate;
|
||||||
private Model model = null;
|
private Model model = null;
|
||||||
|
|
||||||
public ChunkRender(WorldRender world, ChunkData data) {
|
public ChunkRender(WorldRender world, ChunkData data) {
|
||||||
@ -55,6 +56,14 @@ public class ChunkRender {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void markForUpdate() {
|
||||||
|
this.needsUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean needsUpdate() {
|
||||||
|
return needsUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockRender getBlock(int xInChunk, int yInChunk, int zInChunk) {
|
public BlockRender getBlock(int xInChunk, int yInChunk, int zInChunk) {
|
||||||
return BlockRenders.get(
|
return BlockRenders.get(
|
||||||
getData().getBlock(xInChunk, yInChunk, zInChunk).getId()
|
getData().getBlock(xInChunk, yInChunk, zInChunk).getId()
|
||||||
@ -62,7 +71,7 @@ public class ChunkRender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render(WorldRenderer renderer) {
|
public void render(WorldRenderer renderer) {
|
||||||
if (model == null) {
|
if (model == null || needsUpdate()) {
|
||||||
buildModel();
|
buildModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +131,7 @@ public class ChunkRender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model = new StaticModel(builder);
|
model = new StaticModel(builder);
|
||||||
|
needsUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean tryToForwardToOptimizers(
|
private boolean tryToForwardToOptimizers(
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package ru.windcorp.optica.client.world;
|
package ru.windcorp.optica.client.world;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import ru.windcorp.optica.client.graphics.world.WorldRenderer;
|
import ru.windcorp.optica.client.graphics.world.WorldRenderer;
|
||||||
import ru.windcorp.optica.common.world.ChunkData;
|
import ru.windcorp.optica.common.world.ChunkData;
|
||||||
@ -28,13 +29,13 @@ public class WorldRender {
|
|||||||
|
|
||||||
private final WorldData data;
|
private final WorldData data;
|
||||||
|
|
||||||
private final Collection<ChunkRender> chunks = new ArrayList<>();
|
private final Map<ChunkData, ChunkRender> chunks = new HashMap<>();
|
||||||
|
|
||||||
public WorldRender(WorldData data) {
|
public WorldRender(WorldData data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
|
||||||
for (ChunkData chunkData : data.getChunks()) {
|
for (ChunkData chunkData : data.getChunks()) {
|
||||||
chunks.add(new ChunkRender(this, chunkData));
|
chunks.put(chunkData, new ChunkRender(this, chunkData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,10 +43,22 @@ public class WorldRender {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChunkRender getChunk(ChunkData chunkData) {
|
||||||
|
return chunks.get(chunkData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChunkRender getChunk(int x, int y, int z) {
|
||||||
|
return chunks.get(getData().getChunk(x, y, z));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<ChunkRender> getChunks() {
|
||||||
|
return chunks.values();
|
||||||
|
}
|
||||||
|
|
||||||
public void render(WorldRenderer renderer) {
|
public void render(WorldRenderer renderer) {
|
||||||
renderer.pushWorldTransform().rotateX(-Math.PI / 2);
|
renderer.pushWorldTransform().rotateX(-Math.PI / 2);
|
||||||
|
|
||||||
for (ChunkRender chunk : chunks) {
|
for (ChunkRender chunk : getChunks()) {
|
||||||
chunk.render(renderer);
|
chunk.render(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,14 @@ public class BlockRenders {
|
|||||||
private BlockRenders() {}
|
private BlockRenders() {}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
register(new BlockRenderOpaqueCube("Grass", "Test", grassTop, dirtT, grassSide, grassSide, grassSide, grassSide));
|
register(new BlockRenderOpaqueCube("Test", "Grass", grassTop, dirtT, grassSide, grassSide, grassSide, grassSide));
|
||||||
register(new BlockRenderOpaqueCube("Dirt", "Test", dirtT, dirtT, dirtT, dirtT, dirtT, dirtT));
|
register(new BlockRenderOpaqueCube("Test", "Dirt", dirtT, dirtT, dirtT, dirtT, dirtT, dirtT));
|
||||||
register(new BlockRenderOpaqueCube("Stone", "Test", stoneT, stoneT, stoneT, stoneT, stoneT, stoneT));
|
register(new BlockRenderOpaqueCube("Test", "Stone", stoneT, stoneT, stoneT, stoneT, stoneT, stoneT));
|
||||||
|
|
||||||
register(new BlockRenderOpaqueCube("Compass", "Test", qtex("compass"), qtex("compass"), qtex("side_north"), qtex("side_south"), qtex("side_east"), qtex("side_west")));
|
register(new BlockRenderOpaqueCube("Test", "Compass", qtex("compass"), qtex("compass"), qtex("side_north"), qtex("side_south"), qtex("side_east"), qtex("side_west")));
|
||||||
|
|
||||||
register(new BlockRenderNone("Air", "Test"));
|
register(new BlockRenderNone("Test", "Air"));
|
||||||
register(new BlockRenderTransparentCube("Glass", "Test", glassT, glassT, glassT, glassT, glassT, glassT));
|
register(new BlockRenderTransparentCube("Test", "Glass", glassT, glassT, glassT, glassT, glassT, glassT));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockRender get(String name) {
|
public static BlockRender get(String name) {
|
||||||
|
@ -24,6 +24,14 @@ public class BlockDataRegistry {
|
|||||||
|
|
||||||
private static final Map<String, BlockData> REGISTRY = new HashMap<>();
|
private static final Map<String, BlockData> REGISTRY = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
register(new BlockData("Test", "Grass"));
|
||||||
|
register(new BlockData("Test", "Dirt"));
|
||||||
|
register(new BlockData("Test", "Stone"));
|
||||||
|
register(new BlockData("Test", "Air"));
|
||||||
|
register(new BlockData("Test", "Glass"));
|
||||||
|
}
|
||||||
|
|
||||||
public static BlockData get(String name) {
|
public static BlockData get(String name) {
|
||||||
return REGISTRY.get(name);
|
return REGISTRY.get(name);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package ru.windcorp.optica.common.world;
|
|||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.optica.common.block.BlockData;
|
import ru.windcorp.optica.common.block.BlockData;
|
||||||
|
import ru.windcorp.optica.common.block.BlockDataRegistry;
|
||||||
|
|
||||||
public class ChunkData {
|
public class ChunkData {
|
||||||
|
|
||||||
@ -32,12 +33,10 @@ public class ChunkData {
|
|||||||
[BLOCKS_PER_CHUNK]
|
[BLOCKS_PER_CHUNK]
|
||||||
[BLOCKS_PER_CHUNK];
|
[BLOCKS_PER_CHUNK];
|
||||||
|
|
||||||
private final BlockData grass = new BlockData("Grass", "Test");
|
private final BlockData grass = BlockDataRegistry.get("Test:Grass");
|
||||||
private final BlockData dirt = new BlockData("Dirt", "Test");
|
private final BlockData dirt = BlockDataRegistry.get("Test:Dirt");
|
||||||
private final BlockData stone = new BlockData("Stone", "Test");
|
private final BlockData stone = BlockDataRegistry.get("Test:Stone");
|
||||||
private final BlockData air = new BlockData("Air", "Test");
|
private final BlockData air = BlockDataRegistry.get("Test:Air");
|
||||||
// private final BlockData glass = new BlockData("Glass", "Test");
|
|
||||||
// private final BlockData compass = new BlockData("Compass", "Test");
|
|
||||||
|
|
||||||
public ChunkData(int x, int y, int z) {
|
public ChunkData(int x, int y, int z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -47,6 +46,10 @@ public class ChunkData {
|
|||||||
tmp_generate();
|
tmp_generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BlockData[][][] tmp_getBlocks() {
|
||||||
|
return blocks;
|
||||||
|
}
|
||||||
|
|
||||||
private void tmp_generate() {
|
private void tmp_generate() {
|
||||||
Vec3i aPoint = new Vec3i(5, 0, BLOCKS_PER_CHUNK + BLOCKS_PER_CHUNK/2);
|
Vec3i aPoint = new Vec3i(5, 0, BLOCKS_PER_CHUNK + BLOCKS_PER_CHUNK/2);
|
||||||
Vec3i pos = new Vec3i();
|
Vec3i pos = new Vec3i();
|
||||||
|
Reference in New Issue
Block a user