mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-06 00:57:03 +07:00
Refactored alpha and transform updates to components and systems
Removed generic update flags from CofComponent Created AlphaUpdate and TransformUpdate components to store flags of layers that need updating AnimationLoaderSystem no longer sets alpha and transform values and sets flags instead Created AlphaUpdateSystem and TransformUpdateSystem to update animation layers
This commit is contained in:
parent
5beafce761
commit
58a011ab07
@ -65,7 +65,6 @@ public class CofComponent implements Component, Pool.Poolable {
|
||||
public COF cof;
|
||||
public int dirty; // cof layers need to be loaded
|
||||
public int load; // cof layers loading
|
||||
public int update; // update component
|
||||
public int speed;
|
||||
|
||||
public final int component[];
|
||||
@ -90,7 +89,6 @@ public class CofComponent implements Component, Pool.Poolable {
|
||||
cof = null;
|
||||
dirty = Dirty.NONE;
|
||||
load = Dirty.NONE;
|
||||
update = Dirty.NONE;
|
||||
speed = SPEED_NULL;
|
||||
System.arraycopy(DEFAULT_COMPONENT, 0, component, 0, COF.Component.NUM_COMPONENTS);
|
||||
System.arraycopy(DEFAULT_TRANSFORM, 0, transform, 0, COF.Component.NUM_COMPONENTS);
|
||||
|
14
core/src/com/riiablo/engine/component/cof/AlphaUpdate.java
Normal file
14
core/src/com/riiablo/engine/component/cof/AlphaUpdate.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.riiablo.engine.component.cof;
|
||||
|
||||
import com.badlogic.ashley.core.Component;
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
import com.riiablo.engine.Dirty;
|
||||
|
||||
public class AlphaUpdate implements Component, Pool.Poolable {
|
||||
public int flags = Dirty.NONE;
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
flags = Dirty.NONE;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.riiablo.engine.component.cof;
|
||||
|
||||
import com.badlogic.ashley.core.Component;
|
||||
import com.badlogic.gdx.utils.Pool;
|
||||
import com.riiablo.engine.Dirty;
|
||||
|
||||
public class TransformUpdate implements Component, Pool.Poolable {
|
||||
public int flags = Dirty.NONE;
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
flags = Dirty.NONE;
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ import com.riiablo.engine.Dirty;
|
||||
import com.riiablo.engine.SystemPriority;
|
||||
import com.riiablo.engine.component.AnimationComponent;
|
||||
import com.riiablo.engine.component.CofComponent;
|
||||
import com.riiablo.engine.component.cof.AlphaUpdate;
|
||||
import com.riiablo.engine.component.cof.TransformUpdate;
|
||||
|
||||
@DependsOn(CofLoaderSystem.class)
|
||||
public class AnimationLoaderSystem extends IteratingSystem {
|
||||
@ -25,6 +27,9 @@ public class AnimationLoaderSystem extends IteratingSystem {
|
||||
private final ComponentMapper<CofComponent> cofComponent = ComponentMapper.getFor(CofComponent.class);
|
||||
private final ComponentMapper<AnimationComponent> animComponent = ComponentMapper.getFor(AnimationComponent.class);
|
||||
|
||||
private final ComponentMapper<TransformUpdate> transformUpdate = ComponentMapper.getFor(TransformUpdate.class);
|
||||
private final ComponentMapper<AlphaUpdate> alphaUpdate = ComponentMapper.getFor(AlphaUpdate.class);
|
||||
|
||||
public AnimationLoaderSystem() {
|
||||
super(Family.all(CofComponent.class, AnimationComponent.class).get(), SystemPriority.AnimationLoaderSystem);
|
||||
}
|
||||
@ -63,13 +68,18 @@ public class AnimationLoaderSystem extends IteratingSystem {
|
||||
if (Riiablo.assets.isLoaded(descriptor)) {
|
||||
int flag = (1 << layer.component);
|
||||
cofComponent.load &= ~flag;
|
||||
cofComponent.update &= ~flag;
|
||||
Gdx.app.debug(TAG, "finished loading " + descriptor);
|
||||
if (DEBUG_LOAD) Gdx.app.debug(TAG, "finished loading " + descriptor);
|
||||
DC dc = Riiablo.assets.get(descriptor);
|
||||
anim.setLayer(layer, dc, false)
|
||||
.setTransform(cofComponent.transform[layer.component])
|
||||
.setAlpha(cofComponent.alpha[layer.component])
|
||||
;
|
||||
anim.setLayer(layer, dc, false);
|
||||
|
||||
TransformUpdate transformUpdate = this.transformUpdate.get(entity);
|
||||
if (transformUpdate == null) entity.add(transformUpdate = getEngine().createComponent(TransformUpdate.class));
|
||||
transformUpdate.flags |= flag;
|
||||
|
||||
AlphaUpdate alphaUpdate = this.alphaUpdate.get(entity);
|
||||
if (alphaUpdate == null) entity.add(alphaUpdate = getEngine().createComponent(AlphaUpdate.class));
|
||||
alphaUpdate.flags |= flag;
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.riiablo.engine.system.cof;
|
||||
|
||||
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.component.AnimationComponent;
|
||||
import com.riiablo.engine.component.CofComponent;
|
||||
import com.riiablo.engine.component.cof.AlphaUpdate;
|
||||
|
||||
public class AlphaUpdateSystem extends IteratingSystem {
|
||||
private final ComponentMapper<AlphaUpdate> updateComponent = ComponentMapper.getFor(AlphaUpdate.class);
|
||||
private final ComponentMapper<CofComponent> cofComponent = ComponentMapper.getFor(CofComponent.class);
|
||||
private final ComponentMapper<AnimationComponent> animationComponent = ComponentMapper.getFor(AnimationComponent.class);
|
||||
|
||||
public AlphaUpdateSystem() {
|
||||
super(Family.all(AlphaUpdate.class, CofComponent.class, AnimationComponent.class).get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processEntity(Entity entity, float delta) {
|
||||
AlphaUpdate updateComponent = this.updateComponent.get(entity);
|
||||
int flags = updateComponent.flags;
|
||||
assert flags != Dirty.NONE;
|
||||
|
||||
CofComponent cofComponent = this.cofComponent.get(entity);
|
||||
COF cof = cofComponent.cof;
|
||||
float[] alpha = cofComponent.alpha;
|
||||
|
||||
AnimationComponent animationComponent = this.animationComponent.get(entity);
|
||||
Animation animation = animationComponent.animation;
|
||||
|
||||
for (int l = 0, numLayers = cof.getNumLayers(); l < numLayers; l++) {
|
||||
int component = cofComponent.cof.getLayer(l).component;
|
||||
if (!Dirty.isDirty(flags, component)) continue;
|
||||
animation.getLayer(component).setAlpha(alpha[component]);
|
||||
}
|
||||
|
||||
entity.remove(AlphaUpdate.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.riiablo.engine.system.cof;
|
||||
|
||||
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.component.AnimationComponent;
|
||||
import com.riiablo.engine.component.CofComponent;
|
||||
import com.riiablo.engine.component.cof.TransformUpdate;
|
||||
|
||||
public class TransformUpdateSystem extends IteratingSystem {
|
||||
private final ComponentMapper<TransformUpdate> updateComponent = ComponentMapper.getFor(TransformUpdate.class);
|
||||
private final ComponentMapper<CofComponent> cofComponent = ComponentMapper.getFor(CofComponent.class);
|
||||
private final ComponentMapper<AnimationComponent> animationComponent = ComponentMapper.getFor(AnimationComponent.class);
|
||||
|
||||
public TransformUpdateSystem() {
|
||||
super(Family.all(TransformUpdate.class, CofComponent.class, AnimationComponent.class).get());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processEntity(Entity entity, float delta) {
|
||||
TransformUpdate updateComponent = this.updateComponent.get(entity);
|
||||
int flags = updateComponent.flags;
|
||||
assert flags != Dirty.NONE;
|
||||
|
||||
CofComponent cofComponent = this.cofComponent.get(entity);
|
||||
COF cof = cofComponent.cof;
|
||||
byte[] transform = cofComponent.transform;
|
||||
|
||||
AnimationComponent animationComponent = this.animationComponent.get(entity);
|
||||
Animation animation = animationComponent.animation;
|
||||
|
||||
for (int l = 0, numLayers = cof.getNumLayers(); l < numLayers; l++) {
|
||||
int component = cofComponent.cof.getLayer(l).component;
|
||||
if (!Dirty.isDirty(flags, component)) continue;
|
||||
animation.getLayer(component).setTransform(transform[component]);
|
||||
}
|
||||
|
||||
entity.remove(TransformUpdate.class);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user