From eaabd436698882943913a684cff7ce5558e47145 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sat, 2 Mar 2019 01:06:50 -0800 Subject: [PATCH] Improved Animation bounds calculation and debugging --- core/src/gdx/diablo/codec/Animation.java | 80 ++++++++----------- core/src/gdx/diablo/entity/Entity.java | 6 +- .../gdx/diablo/widget/CharacterPreview.java | 4 +- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/core/src/gdx/diablo/codec/Animation.java b/core/src/gdx/diablo/codec/Animation.java index 81a2f611..5eaca002 100644 --- a/core/src/gdx/diablo/codec/Animation.java +++ b/core/src/gdx/diablo/codec/Animation.java @@ -108,11 +108,12 @@ public class Animation extends BaseDrawable { } public Animation setLayer(int component, DC dc) { - Layer layer = layers[component] = dc != null ? new Layer(dc).load(direction) : null; - if (layer != null) { - //box.reset(); - //dc.getBox() - } + return setLayer(component, dc, true); + } + + public Animation setLayer(int component, DC dc, boolean updateBox) { + layers[component] = dc != null ? new Layer(dc).load(direction) : null; + if (updateBox) updateBox(); return this; } @@ -193,7 +194,9 @@ public class Animation extends BaseDrawable { } 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(); if (reset) { shapes.begin(ShapeRenderer.ShapeType.Line); @@ -207,50 +210,9 @@ public class Animation extends BaseDrawable { //shapes.line(x, y, x, y + 50); //shapes.setColor(Color.BLUE); //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.rect(x + box.xMin, y - box.yMax, box.width, box.height); - - if (reset) { - shapes.end(); - } + if (reset) shapes.end(); } else if (DEBUG_MODE == 2) { int d = DC.Direction.toReadDir(direction, cof.getNumDirections()); int f = frame; @@ -345,6 +307,28 @@ public class Animation extends BaseDrawable { 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() { //return cof == null // ? layers[0].dc.getDirection(direction).box diff --git a/core/src/gdx/diablo/entity/Entity.java b/core/src/gdx/diablo/entity/Entity.java index 59eefb75..cfa9b5c2 100644 --- a/core/src/gdx/diablo/entity/Entity.java +++ b/core/src/gdx/diablo/entity/Entity.java @@ -371,6 +371,7 @@ public class Entity { boolean changed = updateAnimation(cof); if (changed) dirty = Dirty.ALL; + if (dirty == Dirty.NONE) return; if (DEBUG_DIRTY) Gdx.app.debug(TAG, "dirty layers: " + Dirty.toString(dirty)); for (int l = 0; l < cof.getNumLayers(); l++) { @@ -387,7 +388,7 @@ public class Entity { String weaponClass = layer.weaponClass; path = entType.PATH + type + "\\" + component + "\\" + type + component + armType + mode + weaponClass + ".dcc"; if (armType.isEmpty()) { - animation.setLayer(c, null); + animation.setLayer(c, null, false); continue; } if (DEBUG_DIRTY) Gdx.app.log(TAG, path); @@ -396,7 +397,7 @@ public class Entity { Diablo.assets.load(descriptor); Diablo.assets.finishLoadingAsset(descriptor); DCC dcc = Diablo.assets.get(descriptor); - animation.setLayer(c, dcc); + animation.setLayer(c, dcc, false); /*Runnable loader = new Runnable() { @Override @@ -437,6 +438,7 @@ public class Entity { animation.setFrameDelta(128); } + animation.updateBox(); dirty = 0; } diff --git a/core/src/gdx/diablo/widget/CharacterPreview.java b/core/src/gdx/diablo/widget/CharacterPreview.java index eeeecc20..09c75042 100644 --- a/core/src/gdx/diablo/widget/CharacterPreview.java +++ b/core/src/gdx/diablo/widget/CharacterPreview.java @@ -73,9 +73,11 @@ public class CharacterPreview extends Widget implements Disposable { Diablo.assets.load(assets[i]); Diablo.assets.finishLoadingAsset(assets[i]); 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.updateBox(); } @Override