Improved Animation bounds calculation and debugging

This commit is contained in:
Collin Smith
2019-03-02 01:06:50 -08:00
parent 4d7b37e386
commit eaabd43669
3 changed files with 39 additions and 51 deletions

View File

@ -108,11 +108,12 @@ public class Animation extends BaseDrawable {
} }
public Animation setLayer(int component, DC dc) { public Animation setLayer(int component, DC dc) {
Layer layer = layers[component] = dc != null ? new Layer(dc).load(direction) : null; return setLayer(component, dc, true);
if (layer != null) {
//box.reset();
//dc.getBox()
} }
public Animation setLayer(int component, DC dc, boolean updateBox) {
layers[component] = dc != null ? new Layer(dc).load(direction) : null;
if (updateBox) updateBox();
return this; return this;
} }
@ -193,7 +194,9 @@ public class Animation extends BaseDrawable {
} }
public void drawDebug(ShapeRenderer shapes, float x, float y) { public void drawDebug(ShapeRenderer shapes, float x, float y) {
if (cof == null) { if (DEBUG_MODE == 0) {
return;
} else if (DEBUG_MODE == 1 || cof == null) {
boolean reset = !shapes.isDrawing(); boolean reset = !shapes.isDrawing();
if (reset) { if (reset) {
shapes.begin(ShapeRenderer.ShapeType.Line); shapes.begin(ShapeRenderer.ShapeType.Line);
@ -207,50 +210,9 @@ public class Animation extends BaseDrawable {
//shapes.line(x, y, x, y + 50); //shapes.line(x, y, x, y + 50);
//shapes.setColor(Color.BLUE); //shapes.setColor(Color.BLUE);
//shapes.line(x, y, x + 15, y - 20); //shapes.line(x, y, x + 15, y - 20);
BBox box = getBox();
shapes.setColor(layers[0].DEBUG_COLOR);
shapes.rect(x + box.xMin, y - box.yMax, box.width, box.height);
if (reset) {
shapes.end();
}
} else if (DEBUG_MODE == 1) {
boolean reset = !shapes.isDrawing();
if (reset) {
shapes.begin(ShapeRenderer.ShapeType.Line);
} else {
shapes.set(ShapeRenderer.ShapeType.Line);
}
if (cof.getNumLayers() == 1) {
int d = DC.Direction.toReadDir(direction, cof.getNumDirections());
int f = frame;
int component = cof.getLayerOrder(d, f, 0);
Layer layer = layers[component];
box.set(layer.dc.getBox(d, f));
} else {
box.reset();
BBox dcBox;
int d = DC.Direction.toReadDir(direction, cof.getNumDirections());
int f = frame;
for (int l = 0; l < cof.getNumLayers(); l++) {
int component = cof.getLayerOrder(d, f, l);
Layer layer = layers[component];
if (layer != null) {
dcBox = layer.dc.getBox();
box.max(dcBox);
}
}
}
//BBox box = getBox();
shapes.setColor(Color.GREEN); shapes.setColor(Color.GREEN);
shapes.rect(x + box.xMin, y - box.yMax, box.width, box.height); shapes.rect(x + box.xMin, y - box.yMax, box.width, box.height);
if (reset) shapes.end();
if (reset) {
shapes.end();
}
} else if (DEBUG_MODE == 2) { } else if (DEBUG_MODE == 2) {
int d = DC.Direction.toReadDir(direction, cof.getNumDirections()); int d = DC.Direction.toReadDir(direction, cof.getNumDirections());
int f = frame; int f = frame;
@ -345,6 +307,28 @@ public class Animation extends BaseDrawable {
layer.draw(batch, direction, frame, x, y); layer.draw(batch, direction, frame, x, y);
} }
public void updateBox() {
if (cof == null) {
box.reset();
for (int l = 0; l < NUM_LAYERS; l++) {
Layer layer = layers[l];
if (layer == null) break;
box.max(layer.dc.getBox(direction));
}
} else {
int d = DC.Direction.toReadDir(direction, cof.getNumDirections());
int f = frame;
box.reset();
for (int l = 0; l < cof.getNumLayers(); l++) {
int component = cof.getLayerOrder(d, f, l);
Layer layer = layers[component];
if (layer != null) {
box.max(layer.dc.getBox());
}
}
}
}
public BBox getBox() { public BBox getBox() {
//return cof == null //return cof == null
// ? layers[0].dc.getDirection(direction).box // ? layers[0].dc.getDirection(direction).box

View File

@ -371,6 +371,7 @@ public class Entity {
boolean changed = updateAnimation(cof); boolean changed = updateAnimation(cof);
if (changed) dirty = Dirty.ALL; if (changed) dirty = Dirty.ALL;
if (dirty == Dirty.NONE) return;
if (DEBUG_DIRTY) Gdx.app.debug(TAG, "dirty layers: " + Dirty.toString(dirty)); if (DEBUG_DIRTY) Gdx.app.debug(TAG, "dirty layers: " + Dirty.toString(dirty));
for (int l = 0; l < cof.getNumLayers(); l++) { for (int l = 0; l < cof.getNumLayers(); l++) {
@ -387,7 +388,7 @@ public class Entity {
String weaponClass = layer.weaponClass; String weaponClass = layer.weaponClass;
path = entType.PATH + type + "\\" + component + "\\" + type + component + armType + mode + weaponClass + ".dcc"; path = entType.PATH + type + "\\" + component + "\\" + type + component + armType + mode + weaponClass + ".dcc";
if (armType.isEmpty()) { if (armType.isEmpty()) {
animation.setLayer(c, null); animation.setLayer(c, null, false);
continue; continue;
} }
if (DEBUG_DIRTY) Gdx.app.log(TAG, path); if (DEBUG_DIRTY) Gdx.app.log(TAG, path);
@ -396,7 +397,7 @@ public class Entity {
Diablo.assets.load(descriptor); Diablo.assets.load(descriptor);
Diablo.assets.finishLoadingAsset(descriptor); Diablo.assets.finishLoadingAsset(descriptor);
DCC dcc = Diablo.assets.get(descriptor); DCC dcc = Diablo.assets.get(descriptor);
animation.setLayer(c, dcc); animation.setLayer(c, dcc, false);
/*Runnable loader = new Runnable() { /*Runnable loader = new Runnable() {
@Override @Override
@ -437,6 +438,7 @@ public class Entity {
animation.setFrameDelta(128); animation.setFrameDelta(128);
} }
animation.updateBox();
dirty = 0; dirty = 0;
} }

View File

@ -73,9 +73,11 @@ public class CharacterPreview extends Widget implements Disposable {
Diablo.assets.load(assets[i]); Diablo.assets.load(assets[i]);
Diablo.assets.finishLoadingAsset(assets[i]); Diablo.assets.finishLoadingAsset(assets[i]);
DCC dcc = Diablo.assets.get(assets[i].fileName, DCC.class); DCC dcc = Diablo.assets.get(assets[i].fileName, DCC.class);
anim.setLayer(layer.component, dcc); anim.setLayer(layer.component, dcc, false);
anim.getLayer(layer.component).setTransform(d2s.colors[layer.component]); anim.getLayer(layer.component).setTransform(d2s.colors[layer.component]);
} }
anim.updateBox();
} }
@Override @Override