Skip to content

Commit

Permalink
Created Display toggle for Terrain using 'T' Key, fixed error in Grid…
Browse files Browse the repository at this point in the history
… formation fro cubes too full to pass through.
  • Loading branch information
ImpalerWrG committed Feb 22, 2015
1 parent 131b113 commit 2931764
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 29 deletions.
12 changes: 2 additions & 10 deletions src/PathFinding/KhazadGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private BitSet BuildConnectivitySet(MapCoordinate TargetCoords) {
BitSet Flags = new BitSet(MapCoordinate.CUBESPERCELL);
CubeShape TargetShape = SourceMap.getCubeShape(TargetCoords);

if (!TargetShape.isSky() && !TargetShape.isSolid()) {
if (!TargetShape.isSky() && !TargetShape.hasCeiling()) {
MapCoordinate OverheadTileCoords = TargetCoords.clone();
OverheadTileCoords.TranslateMapCoordinates(Direction.DIRECTION_UP);
CubeShape OverheadCube = SourceMap.getCubeShape(OverheadTileCoords);
Expand All @@ -181,17 +181,9 @@ private BitSet BuildConnectivitySet(MapCoordinate TargetCoords) {
for (Direction dir: Direction.ANGULAR_DIRECTIONS) {
MapCoordinate AdjacentTileCoords = TargetCoords.clone();
AdjacentTileCoords.TranslateMapCoordinates(dir);
Direction InvertedDirection = dir.Invert();

// if we've done this already..
if (getDirectionEdgeSet(AdjacentTileCoords).get(InvertedDirection.ordinal())) {
Flags.set(dir.ordinal());
continue;
}

CubeShape AdjacentCubeShape = SourceMap.getCubeShape(AdjacentTileCoords);

if (!AdjacentCubeShape.isSky() && !AdjacentCubeShape.isSolid()) {
if (!AdjacentCubeShape.isSky() && !AdjacentCubeShape.hasCeiling()) {
if (dir.ValueonAxis(Axis.AXIS_Z) == 1) {
if (OverheadPassable) {
Flags.set(dir.ordinal());
Expand Down
30 changes: 15 additions & 15 deletions src/Renderer/PathingRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ public void initialize(AppStateManager stateManager, Application app) {

this.vertices = new Vector3f[Direction.ANGULAR_DIRECTIONS.length];

for (int i = 0; i < Direction.ANGULAR_DIRECTIONS.length; i++) {
Direction dir = Direction.ANGULAR_DIRECTIONS[i];
vertices[i] = new Vector3f(dir.ValueonAxis(Axis.AXIS_X) * MapCoordinate.HALFCUBE, dir.ValueonAxis(Axis.AXIS_Y) * MapCoordinate.HALFCUBE, dir.ValueonAxis(Axis.AXIS_Z) * MapCoordinate.HALFCUBE);
for (Direction dir: Direction.ANGULAR_DIRECTIONS) {
vertices[dir.ordinal()] = new Vector3f(dir.ValueonAxis(Axis.AXIS_X) * MapCoordinate.HALFCUBE, dir.ValueonAxis(Axis.AXIS_Y) * MapCoordinate.HALFCUBE, dir.ValueonAxis(Axis.AXIS_Z) * MapCoordinate.HALFCUBE);
}
registerWithInput(app.getInputManager());
}
Expand Down Expand Up @@ -109,10 +108,7 @@ public void registerWithInput(InputManager inputManager) {
}

public Node BuildRendering(Cell TargetCell) {
Mesh EdgeWires = new Mesh();
EdgeWires.setMode(Mesh.Mode.Lines);
EdgeWires.setLineWidth(5);


Node PathRenderingNode = new Node();
MovementModality Mod = new MovementModality(MovementModality.MovementType.WALK_MOVEMENT, 1, 1);

Expand All @@ -121,10 +117,10 @@ public Node BuildRendering(Cell TargetCell) {
for (int x = 0; x < MapCoordinate.CELLEDGESIZE; x++) {
for (int y = 0; y < MapCoordinate.CELLEDGESIZE; y++) {

MapCoordinate Coords = new MapCoordinate(CellCoords, x, y);
BitSet Connectivity = Pathing.getDirectionFlags(Coords, Mod);
MapCoordinate TargetCoords = new MapCoordinate(CellCoords, x, y);
BitSet Connectivity = Pathing.getDirectionFlags(TargetCoords, Mod);

int Zone = Pathing.getConnectivityZone(Coords, Mod);
int Zone = Pathing.getConnectivityZone(TargetCoords, Mod);
Material mat = ZoneMaterials.get(Zone);
if (mat == null) {
mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
Expand All @@ -133,11 +129,15 @@ public Node BuildRendering(Cell TargetCell) {
}

if (Connectivity.cardinality() > 0) {
Mesh EdgeWires = new Mesh();
EdgeWires.setMode(Mesh.Mode.Lines);
EdgeWires.setLineWidth(5);

ArrayList<Integer> Indexes = new ArrayList<Integer>();
for (int i = 0; i < Direction.ANGULAR_DIRECTIONS.length; i++) {
if (Pathing.getEdgeCost(Coords, Direction.ANGULAR_DIRECTIONS[i], Mod) != -1) {
for (Direction dir: Direction.ANGULAR_DIRECTIONS) {
if (Pathing.getEdgeCost(TargetCoords, dir, Mod) != -1) {
Indexes.add(0);
Indexes.add(i);
Indexes.add(dir.ordinal());
}
}

Expand All @@ -147,12 +147,12 @@ public Node BuildRendering(Cell TargetCell) {
}

EdgeWires.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
EdgeWires.setBuffer(VertexBuffer.Type.Index, 3, BufferUtils.createIntBuffer(indexes));
EdgeWires.setBuffer(VertexBuffer.Type.Index, 2, BufferUtils.createIntBuffer(indexes));
EdgeWires.updateBound();

Geometry Wires = new Geometry("Connection Wires", EdgeWires);
Wires.setLocalTranslation(new Vector3f(x, y, 0));
Wires.setMaterial(mat);
Wires.setLocalTranslation(new Vector3f(x, y, 0));
PathRenderingNode.attachChild(Wires);
}
}
Expand Down
58 changes: 54 additions & 4 deletions src/Renderer/TerrainRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.input.controls.ActionListener;

import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
Expand Down Expand Up @@ -44,7 +49,7 @@
*
* @author Impaler
*/
public class TerrainRenderer extends AbstractAppState {
public class TerrainRenderer extends AbstractAppState implements ActionListener {

SimpleApplication app = null;
AppStateManager state = null;
Expand Down Expand Up @@ -91,6 +96,8 @@ public void initialize(AppStateManager stateManager, Application app) {
ImageManager Images = ImageManager.getImageManager();
Images.Initialize(assetmanager);
imagemanager = Images;

registerWithInput(app.getInputManager());
}

public void attachToGame(Game TargetGame) {
Expand Down Expand Up @@ -123,6 +130,21 @@ public void detachFromGame() {
sunnyterrainNode = null;
}

public void onAction(String name, boolean keyPressed, float tpf) {
if (this.isEnabled()) {
if (name.equals("TerrainRenderToggle") && keyPressed) {
DisplayToggle = !DisplayToggle;
}
}
}

public void registerWithInput(InputManager inputManager) {
String[] inputs = {"TerrainRenderToggle"};

inputManager.addMapping("TerrainRenderToggle", new KeyTrigger(KeyInput.KEY_T));
inputManager.addListener(this, inputs);
}

public Node getCellNodeLight(CellCoordinate TargetCell) {
Node CellNode = LightCellNodeMap.get(TargetCell);
if (CellNode == null) {
Expand Down Expand Up @@ -179,9 +201,20 @@ private Node getZNodeDark(int zlevel) {

public void RebuildDirtyCells(ConcurrentHashMap<CellCoordinate, Cell> cells) {
for (Cell target : cells.values()) {
if (target.isTerrainRenderingDirty()) {
CellCoordinate Coords = target.getCellCoordinates();
CellCoordinate Coords = target.getCellCoordinates();

Node CellLight = getCellNodeLight(Coords);
Node CellDark = getCellNodeDark(Coords);

Spatial light = CellLight.getChild("LightGeometry Cell" + target.toString());
Spatial dark = CellDark.getChild("DarkGeometry Cell" + target.toString());

if (light != null)
light.setCullHint(Spatial.CullHint.Dynamic);
if (dark != null)
dark.setCullHint(Spatial.CullHint.Dynamic);

if (target.isTerrainRenderingDirty()) {
TerrainBuilder Builder = new TerrainBuilder(app, target, builder, mat);
Builder.setNodes(getCellNodeLight(Coords), getCellNodeDark(Coords));
Executor.submit(Builder);
Expand All @@ -192,6 +225,23 @@ public void RebuildDirtyCells(ConcurrentHashMap<CellCoordinate, Cell> cells) {
}
}

public void HideTerrain(ConcurrentHashMap<CellCoordinate, Cell> cells) {
for (Cell target : cells.values()) {
CellCoordinate Coords = target.getCellCoordinates();

Node CellLight = getCellNodeLight(Coords);
Node CellDark = getCellNodeDark(Coords);

Spatial light = CellLight.getChild("LightGeometry Cell" + target.toString());
Spatial dark = CellDark.getChild("DarkGeometry Cell" + target.toString());

if (light != null)
light.setCullHint(Spatial.CullHint.Always);
if (dark != null)
dark.setCullHint(Spatial.CullHint.Always);
}
}

public void PopulateActors() {
Game game = state.getState(Game.class);
GameMap map = game.getMap();
Expand Down Expand Up @@ -335,7 +385,7 @@ public void update(float tpf) {
if (DisplayToggle) {
RebuildDirtyCells(map.getCellMap());
} else {

HideTerrain(map.getCellMap());
}
if (game.getTickRate() <= 256) {
PopulateActors();
Expand Down

0 comments on commit 2931764

Please sign in to comment.