1
0
mirror of https://github.com/Dejvino/roadtrip synced 2024-11-13 04:27:30 +00:00

Map: re-enabled map objects, cleanup.

This commit is contained in:
Dejvino 2017-01-25 22:19:11 +01:00
parent bdadc3c739
commit 275bea8a91
4 changed files with 22 additions and 9 deletions

View File

@ -1,5 +1,6 @@
package roadtrip.model;
import com.jme3.terrain.geomipmap.LRUCache;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Random;
@ -11,6 +12,8 @@ public abstract class AbstractProceduralBlock implements ProceduralBlock
{
private long seed;
private LRUCache<String, ProceduralBlock> subBlocksCache = new LRUCache<>(getSubBlocksCacheSize());
public AbstractProceduralBlock(long seed)
{
this.seed = seed;
@ -38,13 +41,24 @@ public abstract class AbstractProceduralBlock implements ProceduralBlock
public <T extends ProceduralBlock> T getSubBlock(String subBlockKey, Class<T> subBlockClass)
{
if (subBlockClass == null) throw new NullPointerException("subBlockClass");
T result = (T) subBlocksCache.get(subBlockKey);
if (result != null) {
return result;
}
try {
Constructor<T> constructor = subBlockClass.getConstructor(Long.TYPE);
return constructor.newInstance(getSubBlockSeed(subBlockKey));
result = constructor.newInstance(getSubBlockSeed(subBlockKey));
subBlocksCache.put(subBlockKey, result);
return result;
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Class " + subBlockClass + " does not have the default constructor with a single 'long' parameter.", e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new IllegalArgumentException("Unable to instantiate sub-block.", e);
}
}
public int getSubBlocksCacheSize()
{
return 8;
}
}

View File

@ -32,7 +32,7 @@ public class ProceduralMapQuadBlock extends AbstractProceduralBlock
Random quadRand = getBlockRandom();
Vector2f prevPos = null;
Vector2f quadPos = new Vector2f(terrainQuad.getLocalTranslation().x, terrainQuad.getLocalTranslation().z);
for (int i = 0; i < quadRand.nextInt(10000); i++) {
for (int i = 0; i < quadRand.nextInt(100); i++) {
Vector2f pos;
if (prevPos == null || quadRand.nextFloat() < 0.2f) {
pos = new Vector2f((quadRand.nextFloat() - 0.5f) * cellSize, (quadRand.nextFloat() - 0.5f) * cellSize)

View File

@ -421,15 +421,15 @@ public class FineTerrainGrid extends TerrainQuad {
int xMax = getSubdivisionsPerSide();
int yMin = 0;
int yMax = getSubdivisionsPerSide();
if (dx == -1) { // camera moved to -X direction
if (dx < 0) { // camera moved to -X direction
xMax = getSubdivisionsPerSide() - 1;
} else if (dx == 1) { // camera moved to +X direction
} else if (dx > 0) { // camera moved to +X direction
xMin = 1;
}
if (dy == -1) { // camera moved to -Y direction
if (dy < 0) { // camera moved to -Y direction
yMax = getSubdivisionsPerSide() - 1;
} else if (dy == 1) { // camera moved to +Y direction
} else if (dy > 0) { // camera moved to +Y direction
yMin = 1;
}

View File

@ -36,7 +36,7 @@ import roadtrip.view.model.GameWorldState;
*/
public class GameWorldView {
public static boolean DEBUG = true;
public static boolean DEBUG = false;//true;
private final GameWorldState state;
@ -184,8 +184,7 @@ public class GameWorldView {
String quadObjectsNodeKey = getQuadObjectsNodeKey(quad);
Node objects = new Node(quadObjectsNodeKey);
// TODO: fix
//populateQuadObjectsNode(quad, objects);
populateQuadObjectsNode(quad, objects);
rootNode.attachChild(objects);
}