Added support for animation transformations / alphas

Added support for animation transformations / alphas
Changed CofComponent transformation field back to byte
Introduced update dirty flags in CofComponent to track transformation changes
This commit is contained in:
Collin Smith 2019-11-10 15:02:34 -08:00
parent 32b20d284e
commit 29f619fe1b
4 changed files with 69 additions and 13 deletions

View File

@ -43,10 +43,10 @@ public class CofComponent implements Component, Pool.Poolable {
Arrays.fill(DEFAULT_COMPONENT, COMPONENT_NIL);
}
public static final int TRANSFORM_NULL = -1;
public static final int[] DEFAULT_TRANSFORM;
public static final byte TRANSFORM_NULL = -1;
public static final byte[] DEFAULT_TRANSFORM;
static {
DEFAULT_TRANSFORM = new int[COF.Component.NUM_COMPONENTS];
DEFAULT_TRANSFORM = new byte[COF.Component.NUM_COMPONENTS];
Arrays.fill(DEFAULT_TRANSFORM, TRANSFORM_NULL);
}
@ -61,16 +61,17 @@ public class CofComponent implements Component, Pool.Poolable {
public int mode;
public int wclass;
public COF cof;
public int dirty;
public int load;
public int dirty; // cof layers need to be loaded
public int load; // cof layers loading
public int update; // update component
public final int component[];
public final int transform[];
public final byte transform[];
public final float alpha[];
public CofComponent() {
component = new int[COF.Component.NUM_COMPONENTS];
transform = new int[COF.Component.NUM_COMPONENTS];
transform = new byte[COF.Component.NUM_COMPONENTS];
alpha = new float[COF.Component.NUM_COMPONENTS];
reset();
}
@ -86,6 +87,7 @@ public class CofComponent implements Component, Pool.Poolable {
cof = null;
dirty = Dirty.NONE;
load = Dirty.NONE;
update = Dirty.NONE;
System.arraycopy(DEFAULT_COMPONENT, 0, component, 0, COF.Component.NUM_COMPONENTS);
System.arraycopy(DEFAULT_TRANSFORM, 0, transform, 0, COF.Component.NUM_COMPONENTS);
System.arraycopy(DEFAULT_ALPHA, 0, alpha, 0, COF.Component.NUM_COMPONENTS);

View File

@ -30,13 +30,13 @@ public class AnimationLoaderSystem extends IteratingSystem {
}
@Override
public void update(float deltaTime) {
public void update(float delta) {
//Riiablo.assets.update();
super.update(deltaTime);
super.update(delta);
}
@Override
protected void processEntity(Entity entity, float deltaTime) {
protected void processEntity(Entity entity, float delta) {
AnimationComponent animComponent = this.animComponent.get(entity);
CofComponent cofComponent = this.cofComponent.get(entity);
@ -57,11 +57,13 @@ public class AnimationLoaderSystem extends IteratingSystem {
AssetDescriptor<? extends DC> descriptor = cofComponent.layer[layer.component];
if (Riiablo.assets.isLoaded(descriptor)) {
cofComponent.load &= ~(1 << layer.component);
int flag = (1 << layer.component);
cofComponent.load &= ~flag;
cofComponent.update &= ~flag;
Gdx.app.debug(TAG, "finished loading " + descriptor);
DC dc = Riiablo.assets.get(descriptor);
anim.setLayer(layer, dc, false)
.setTransform((byte) cofComponent.transform[layer.component])
.setTransform(cofComponent.transform[layer.component])
.setAlpha(cofComponent.alpha[layer.component])
;
changed = true;

View File

@ -0,0 +1,52 @@
package com.riiablo.engine.system;
import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.riiablo.codec.Animation;
import com.riiablo.codec.COF;
import com.riiablo.engine.Dirty;
import com.riiablo.engine.SystemPriority;
import com.riiablo.engine.component.AnimationComponent;
import com.riiablo.engine.component.CofComponent;
public class AnimationTransformationSystem extends IteratingSystem {
private static final String TAG = "AnimationTransformationSystem";
private static final boolean DEBUG = true;
private static final boolean DEBUG_STATE = DEBUG && !true;
private final ComponentMapper<CofComponent> cofComponent = ComponentMapper.getFor(CofComponent.class);
private final ComponentMapper<AnimationComponent> animComponent = ComponentMapper.getFor(AnimationComponent.class);
public AnimationTransformationSystem() {
super(Family.all(CofComponent.class, AnimationComponent.class).get(), SystemPriority.AnimationLoaderSystem);
}
@Override
protected void processEntity(Entity entity, float delta) {
CofComponent cofComponent = this.cofComponent.get(entity);
int flags = cofComponent.update;
if (flags == Dirty.NONE) return;
AnimationComponent animComponent = this.animComponent.get(entity);
Animation animation = animComponent.animation;
if (animation == null) return;
COF cof = cofComponent.cof;
for (int l = 0, numLayers = cof.getNumLayers(); l < numLayers; l++) {
int component = cof.getLayer(l).component;
if (!Dirty.isDirty(flags, component)) continue;
Animation.Layer layer = animation.getLayer(component);
if (layer != null) {
layer
.setTransform(cofComponent.transform[component])
.setAlpha(cofComponent.alpha[component])
;
}
}
cofComponent.update = Dirty.NONE;
}
}

View File

@ -46,7 +46,7 @@ import java.util.Comparator;
public class RenderSystem extends EntitySystem {
private static final String TAG = "RenderSystem";
private static final boolean DEBUG = true;
private static final boolean DEBUG_MATH = DEBUG && true;
private static final boolean DEBUG_MATH = DEBUG && !true;
private static final boolean DEBUG_BUFFER = DEBUG && true;
private static final boolean DEBUG_SUBTILE = DEBUG && true;
private static final boolean DEBUG_TILE = DEBUG && !true;