From 29f619fe1b59b84133b4229da66f6e4e9d1fa721 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Sun, 10 Nov 2019 15:02:34 -0800 Subject: [PATCH] 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 --- .../engine/component/CofComponent.java | 16 +++--- .../engine/system/AnimationLoaderSystem.java | 12 +++-- .../system/AnimationTransformationSystem.java | 52 +++++++++++++++++++ core/src/com/riiablo/map/RenderSystem.java | 2 +- 4 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 core/src/com/riiablo/engine/system/AnimationTransformationSystem.java diff --git a/core/src/com/riiablo/engine/component/CofComponent.java b/core/src/com/riiablo/engine/component/CofComponent.java index eec0c579..8611d169 100644 --- a/core/src/com/riiablo/engine/component/CofComponent.java +++ b/core/src/com/riiablo/engine/component/CofComponent.java @@ -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); diff --git a/core/src/com/riiablo/engine/system/AnimationLoaderSystem.java b/core/src/com/riiablo/engine/system/AnimationLoaderSystem.java index ca5c7238..8bc988b2 100644 --- a/core/src/com/riiablo/engine/system/AnimationLoaderSystem.java +++ b/core/src/com/riiablo/engine/system/AnimationLoaderSystem.java @@ -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 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; diff --git a/core/src/com/riiablo/engine/system/AnimationTransformationSystem.java b/core/src/com/riiablo/engine/system/AnimationTransformationSystem.java new file mode 100644 index 00000000..852f21a6 --- /dev/null +++ b/core/src/com/riiablo/engine/system/AnimationTransformationSystem.java @@ -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 = ComponentMapper.getFor(CofComponent.class); + private final ComponentMapper 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; + } +} diff --git a/core/src/com/riiablo/map/RenderSystem.java b/core/src/com/riiablo/map/RenderSystem.java index 5abfd6f8..9ee25553 100644 --- a/core/src/com/riiablo/map/RenderSystem.java +++ b/core/src/com/riiablo/map/RenderSystem.java @@ -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;