Added support for ds1 object paths

Added support for ds1 object paths
Added first debug system PathDebugSystem -- more features will be moved from RenderSystem
Added radius field to RenderSystem to track radius of overscan (used to clamp rendering of entities to fov)
This commit is contained in:
Collin Smith
2019-11-04 14:51:59 -08:00
parent 909e74c166
commit 1f9ca594ba
4 changed files with 153 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import com.riiablo.engine.component.LabelComponent;
import com.riiablo.engine.component.MapComponent;
import com.riiablo.engine.component.MonsterComponent;
import com.riiablo.engine.component.ObjectComponent;
import com.riiablo.engine.component.PathComponent;
import com.riiablo.engine.component.PositionComponent;
import com.riiablo.engine.component.TypeComponent;
import com.riiablo.engine.component.WarpComponent;
@ -248,6 +249,12 @@ public class Engine extends PooledEngine {
labelComponent.actor.setUserObject(entity);
if (object != null && object.path != null) {
PathComponent pathComponent = createComponent(PathComponent.class);
pathComponent.path = object.path;
entity.add(pathComponent);
}
return entity;
}

View File

@ -0,0 +1,14 @@
package com.riiablo.engine.component;
import com.badlogic.ashley.core.Component;
import com.badlogic.gdx.utils.Pool;
import com.riiablo.map.DS1;
public class PathComponent implements Component, Pool.Poolable {
public DS1.Path path;
@Override
public void reset() {
path = null;
}
}

View File

@ -0,0 +1,118 @@
package com.riiablo.engine.system.debug;
import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.riiablo.Riiablo;
import com.riiablo.camera.IsometricCamera;
import com.riiablo.engine.component.PathComponent;
import com.riiablo.engine.component.PositionComponent;
import com.riiablo.graphics.PaletteIndexedBatch;
import com.riiablo.map.DS1;
import com.riiablo.map.RenderSystem;
public class PathDebugSystem extends EntitySystem {
private final float BOX_SIZE = 8;
private final float HALF_BOX = BOX_SIZE / 2;
private final ComponentMapper<PathComponent> pathComponent = ComponentMapper.getFor(PathComponent.class);
private final ComponentMapper<PositionComponent> positionComponent = ComponentMapper.getFor(PositionComponent.class);
private final Family family = Family.all(PathComponent.class, PositionComponent.class).get();
private ImmutableArray<Entity> entities;
private final Vector2 tmpVec2a = new Vector2();
private final Vector2 tmpVec2b = new Vector2();
private final IsometricCamera iso;
private final RenderSystem renderer;
private final PaletteIndexedBatch batch;
private final ShapeRenderer shapes;
public PathDebugSystem(IsometricCamera iso, RenderSystem renderer, PaletteIndexedBatch batch, ShapeRenderer shapes) {
super();
this.iso = iso;
this.renderer = renderer;
this.batch = batch;
this.shapes = shapes;
setProcessing(false);
}
@Override
public void addedToEngine(Engine engine) {
super.addedToEngine(engine);
entities = engine.getEntitiesFor(family);
}
@Override
public void removedFromEngine(Engine engine) {
super.removedFromEngine(engine);
entities = null;
}
@Override
public void update(float delta) {
for (int i = 0, size = entities.size(); i < size; i++) {
Entity entity = entities.get(i);
PositionComponent positionComponent = this.positionComponent.get(entity);
if (!renderer.withinRadius(positionComponent.position)) continue;
PathComponent pathComponent = this.pathComponent.get(entity);
shapes.setProjectionMatrix(iso.combined);
shapes.begin(ShapeRenderer.ShapeType.Filled); {
drawDebugShapes(pathComponent);
} shapes.end();
batch.begin(); {
batch.setShader(null);
drawDebugBatch(pathComponent);
} batch.end();
batch.setShader(Riiablo.shader);
}
}
private void drawDebugShapes(PathComponent pathComponent) {
DS1.Path path = pathComponent.path;
DS1.Path.Point point;
tmpVec2a.setZero();
tmpVec2b.setZero();
for (int i = 0; i < path.numPoints; i++, tmpVec2a.set(tmpVec2b)) {
point = path.points[i];
iso.toScreen(point.x, point.y, tmpVec2b);
if (tmpVec2a.isZero()) continue;
shapes.setColor(Color.PURPLE);
shapes.rectLine(tmpVec2a, tmpVec2b, 2);
}
if (path.numPoints > 1) {
point = path.points[0];
iso.toScreen(point.x, point.y, tmpVec2a);
shapes.setColor(Color.PURPLE);
shapes.rectLine(tmpVec2b, tmpVec2a, 2);
}
for (int i = 0; i < path.numPoints; i++) {
point = path.points[i];
iso.toScreen(point.x, point.y, tmpVec2a).sub(HALF_BOX, HALF_BOX);
shapes.setColor(Color.WHITE);
shapes.rect(tmpVec2a.x, tmpVec2a.y, BOX_SIZE, BOX_SIZE);
}
}
private void drawDebugBatch(PathComponent pathComponent) {
DS1.Path path = pathComponent.path;
DS1.Path.Point point;
for (int i = 0; i < path.numPoints; i++) {
point = path.points[i];
iso.toScreen(point.x, point.y, tmpVec2a).sub(0, BOX_SIZE);
Riiablo.fonts.consolas12.draw(batch, Integer.toString(point.action), tmpVec2a.x, tmpVec2a.y, 0, Align.center, false);
}
}
}

View File

@ -146,6 +146,8 @@ public class RenderSystem extends EntitySystem {
int renderMinX, renderMinY;
int renderMaxX, renderMaxY;
float radius;
// DT1 mainIndexes to not draw
final Bits popped = new Bits();
@ -198,6 +200,14 @@ public class RenderSystem extends EntitySystem {
}
}
public float radius() {
return radius;
}
public boolean withinRadius(Vector2 vec) {
return iso.position.dst(vec) <= radius;
}
public float zoom() {
return iso.zoom;
}
@ -264,6 +274,10 @@ public class RenderSystem extends EntitySystem {
renderHeight = tilesY * Tile.HEIGHT;
assert (tilesX & 1) == 1;
assert (tilesY & 1) == 1;
float yardsX = (renderWidth / 2) / Tile.SUBTILE_WIDTH;
float yardsY = (renderHeight / 2) / Tile.SUBTILE_HEIGHT;
radius = Vector2.len(yardsX, yardsY);
}
private void updateCameraBounds() {