Added infinite terrain to main aoo

This commit is contained in:
Ziver Koc 2020-07-15 23:28:54 +02:00
parent 4d41cbf8c9
commit 68cdc81597
8 changed files with 92 additions and 18 deletions

View file

@ -1,6 +1,5 @@
package se.cookery;
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.collision.CollisionResults;
import com.jme3.input.ChaseCamera;
@ -15,11 +14,13 @@ import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Geometry;
import se.cookery.core.world.Block;
import se.cookery.core.world.gen.GrassLandWorldGenerator;
import se.cookery.core.world.World;
import se.cookery.core.world.gen.BlockGenerator;
import se.cookery.core.world.gen.GrassLandBlockGenerator;
import se.cookery.gfx.character.Player;
import se.cookery.gfx.input.WireFrameToggleAction;
import se.cookery.gfx.terrain.TerrainMesh;
import se.cookery.gfx.terrain.BlockHeightMap;
import se.cookery.gfx.terrain.TerrainManager;
import se.cookery.gfx.util.MaterialUtil;
import com.jme3.post.filters.CartoonEdgeFilter;
@ -33,11 +34,18 @@ public class CookeryClient extends SimpleApplication {
// Setup Terrain
// -----------------------------------------
Block block = new GrassLandWorldGenerator().generateBlock(0, 0);
//Geometry terrain = new Geometry("Terrain", new TerrainMesh(1, 1, Block.BLOCK_SIZE, Block.BLOCK_SIZE));
//terrain.setMaterial(MaterialUtil.createMaterial(assetManager, ColorRGBA.Green));
//rootNode.attachChild();
Geometry terrain = new Geometry("Terrain", new TerrainMesh(1, 1, Block.BLOCK_SIZE, Block.BLOCK_SIZE));
terrain.setMaterial(MaterialUtil.createMaterial(assetManager, ColorRGBA.Green));
rootNode.attachChild(terrain);
BlockGenerator blockGenerator = new GrassLandBlockGenerator();
World world = new World(blockGenerator);
TerrainManager terrain = new TerrainManager(1, 1,
new BlockHeightMap(world),
MaterialUtil.createMaterial(assetManager, ColorRGBA.Green));
rootNode.attachChild(terrain.getNode());
// -----------------------------------------
// Setup Player
@ -121,7 +129,7 @@ public class CookeryClient extends SimpleApplication {
// The closest result is the target that the player picked:
Geometry target = results.getClosestCollision().getGeometry();
// Here comes the action:
target.setLocalTranslation(target.getLocalTranslation().add(1, 0, 0));
// target.setLocalTranslation(target.getLocalTranslation().add(1, 0, 0));
}
}
};

View file

@ -1,6 +1,6 @@
package se.cookery.core.world;
import se.cookery.core.world.gen.WorldGenerator;
import se.cookery.core.world.gen.BlockGenerator;
import java.util.HashMap;
import java.util.Map;
@ -10,10 +10,10 @@ public class World {
// Variables
private Map<Long, Map<Long, Block>> worldBlocks = new TreeMap<>();
private WorldGenerator generator;
private BlockGenerator generator;
public World(WorldGenerator generator) {
public World(BlockGenerator generator) {
this.generator = generator;
}

View file

@ -8,7 +8,7 @@ import se.cookery.core.world.Block;
* A class that implements this interface can be used
* to generate a static or dynamic world.
*/
public interface WorldGenerator {
public interface BlockGenerator {
/**
* Method to generate a block with the provided coordinates,

View file

@ -2,7 +2,7 @@ package se.cookery.core.world.gen;
import se.cookery.core.world.Block;
public class GrassLandWorldGenerator implements WorldGenerator {
public class GrassLandBlockGenerator implements BlockGenerator {
@Override
public Block generateBlock(long x, long y) {

View file

@ -0,0 +1,24 @@
package se.cookery.gfx.terrain;
import se.cookery.core.world.Block;
import se.cookery.core.world.World;
public class BlockHeightMap implements TerrainHeightMap {
private World world;
public BlockHeightMap(World world) {
this.world = world;
}
@Override
public int getSquareCountWidth() {
return Block.BLOCK_SIZE;
}
@Override
public int getSquareCountHeight() {
return Block.BLOCK_SIZE;
}
}

View file

@ -1,8 +1,7 @@
package se.cookery.core.world;
import org.junit.jupiter.api.Test;
import se.cookery.core.world.World;
import se.cookery.core.world.gen.GrassLandWorldGenerator;
import se.cookery.core.world.gen.GrassLandBlockGenerator;
import static org.junit.jupiter.api.Assertions.*;
@ -10,7 +9,7 @@ public class WorldTest {
@Test
public void blockExists() {
World w = new World(new GrassLandWorldGenerator());
World w = new World(new GrassLandBlockGenerator());
assertFalse(w.blockExists(0, 0));
assertFalse(w.blockExists(Long.MAX_VALUE, Long.MAX_VALUE));
assertFalse(w.blockExists(Long.MIN_VALUE, Long.MAX_VALUE));
@ -20,7 +19,7 @@ public class WorldTest {
@Test
public void getBlock() {
World w = new World(new GrassLandWorldGenerator());
World w = new World(new GrassLandBlockGenerator());
assertFalse(w.blockExists(0, 0));
assertNotNull(w.getBlock(0,0));
assertTrue(w.blockExists(0, 0));