diff --git a/README.md b/README.md index a260856..cc9d152 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ with all fancy features, check out these instead: - [playn-artemis-quickstart](https://github.com/DaanVanYperen/playn-artemis-quickstart) ### Library Versions -Artemis-odb 2.0.x, (Optional) LibGDX 1.9+, tested with 1.9.4. +Artemis-odb 2.1.x, (Optional) LibGDX 1.9.0-1.9.4, tested with 1.9.4. ### License The primary license for this code is MIT. @@ -32,13 +32,13 @@ Some stubs from LibGDX are licensed under Apache 2.0. net.mostlyoriginal.artemis-odb contrib-core - 1.2.1 + 2.1 net.mostlyoriginal.artemis-odb contrib-eventbus - 1.2.1 + 2.1 ``` @@ -46,7 +46,7 @@ Some stubs from LibGDX are licensed under Apache 2.0. ```groovy dependencies { - compile "net.mostlyoriginal.artemis-odb:contrib-core:1.2.1" - compile "net.mostlyoriginal.artemis-odb:contrib-eventbus:1.2.1" + compile "net.mostlyoriginal.artemis-odb:contrib-core:2.1" + compile "net.mostlyoriginal.artemis-odb:contrib-eventbus:2.1" } ``` diff --git a/contrib-benchmark/pom.xml b/contrib-benchmark/pom.xml index eda22d1..021dd6f 100644 --- a/contrib-benchmark/pom.xml +++ b/contrib-benchmark/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-benchmark jar diff --git a/contrib-core/pom.xml b/contrib-core/pom.xml index bd85bf7..f019e53 100644 --- a/contrib-core/pom.xml +++ b/contrib-core/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-core jar @@ -27,6 +27,25 @@ mockito-all test + + com.badlogicgames.gdx + gdx + test + ${libgdx.version} + + + com.badlogicgames.gdx + gdx-backend-lwjgl + test + ${libgdx.version} + + + com.badlogicgames.gdx + gdx-platform + natives-desktop + test + ${libgdx.version} + @@ -47,4 +66,4 @@ - \ No newline at end of file + diff --git a/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/ExtendedComponent.java b/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/ExtendedComponent.java index 18cf261..0f85046 100644 --- a/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/ExtendedComponent.java +++ b/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/ExtendedComponent.java @@ -1,6 +1,7 @@ package net.mostlyoriginal.api.component.common; import com.artemis.PooledComponent; +import com.artemis.annotations.Fluid; import java.io.Serializable; @@ -13,6 +14,7 @@ * * @author Daan van Yperen */ +@Fluid(swallowGettersWithParameters = true) public abstract class ExtendedComponent extends PooledComponent implements Serializable, Mirrorable { } diff --git a/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Mirrorable.java b/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Mirrorable.java index 556877b..bf3e115 100644 --- a/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Mirrorable.java +++ b/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Mirrorable.java @@ -14,5 +14,5 @@ public interface Mirrorable { * @param t component to mirror * @return {@code this} */ - T set(T t); + void set(T t); } diff --git a/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Tweenable.java b/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Tweenable.java index a749007..158a6b3 100644 --- a/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Tweenable.java +++ b/contrib-core/src/main/java/net/mostlyoriginal/api/component/common/Tweenable.java @@ -17,5 +17,5 @@ public interface Tweenable> { * @param value tween (0..1) * @return {@code this} */ - T tween(T a, T b, float value); + void tween(T a, T b, float value); } diff --git a/contrib-core/src/main/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/M.java b/contrib-core/src/main/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/M.java index ff5d445..1d98829 100644 --- a/contrib-core/src/main/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/M.java +++ b/contrib-core/src/main/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/M.java @@ -38,7 +38,7 @@ public boolean isMirrorable() { * @return the instance of the component */ public A getSafe(int entityId, A fallback) { - final A c = getSafe(entityId); + final A c = get(entityId); return (c != null) ? c : fallback; } @@ -96,9 +96,11 @@ public A mirror(int targetId, int sourceId) { throw new RuntimeException("Component does not extend ExtendedComponent or just Mirrorable, required for #set."); } - final A source = getSafe(sourceId); + final A source = get(sourceId); if ( source != null ) { - return (A) ((Mirrorable)create(targetId)).set(source); + Mirrorable mirrorable = (Mirrorable) create(targetId); + mirrorable.set(source); + return (A) mirrorable; } else { remove(targetId); return null; @@ -169,17 +171,6 @@ public A get(Entity e) throws ArrayIndexOutOfBoundsException { return mapper.get(e); } - @Deprecated - public A getSafe(Entity e, boolean forceNewInstance) { - A component = mapper.get(e); - - if(component == null && forceNewInstance) { - component = mapper.create(e); - } - - return component; - } - public A get(int entityId) throws ArrayIndexOutOfBoundsException { return mapper.get(entityId); } @@ -196,21 +187,21 @@ public boolean has(Entity e) throws ArrayIndexOutOfBoundsException { return mapper.has(e); } - /** - * @deprecated as of odb version 2.0.0 {@see #get} is as safe as getSafe. - */ - public A getSafe(Entity e) { - return mapper.get(e); - } - public boolean has(int entityId) { return mapper.has(entityId); } + /** Get instance of M for passed component type. moderately efficient. */ public static M getFor(Class type, World world) { return world.getSystem(ExtendedComponentMapperManager.class).getFor(type); } + /** Get instance of M for passed component. moderately efficient. */ + @SuppressWarnings("unchecked") + public static M getFor(T component, World world) { + return getFor((Class)component.getClass(), world); + } + public A get(Entity e, boolean forceNewInstance) throws ArrayIndexOutOfBoundsException { A component = mapper.get(e); diff --git a/contrib-core/src/main/java/net/mostlyoriginal/api/system/core/ReferenceManager.java b/contrib-core/src/main/java/net/mostlyoriginal/api/system/core/ReferenceManager.java deleted file mode 100644 index a042e15..0000000 --- a/contrib-core/src/main/java/net/mostlyoriginal/api/system/core/ReferenceManager.java +++ /dev/null @@ -1,90 +0,0 @@ -package net.mostlyoriginal.api.system.core; - -import com.artemis.Entity; -import com.artemis.annotations.Wire; -import com.artemis.managers.TagManager; -import com.artemis.managers.UuidEntityManager; -import net.mostlyoriginal.api.utils.reference.EntityReference; - -import java.util.UUID; - -/** - * Fetch safe entity references. - * - * @author Daan van Yperen - * @TODO make this pooled. - */ -@Wire -public class ReferenceManager extends PassiveSystem { - - private static final EntityReference NONE = new EntityReferenceImpl(); - - // Should be part of world. - private UuidEntityManager uem; - private TagManager tagManager; - - /** Return entity reference of entity, which will expire when entity gets deleted from the world. */ - public EntityReference of( Entity entity ) - { - return new EntityReferenceImpl(entity, uem); - } - - /** REturn entity reference that resolves by tag. */ - public EntityReference ofTag( String tag ) - { - return new TagEntityReference(tagManager, tag); - } - - /** Return empty reference. */ - public EntityReference none() - { - return NONE; - } - - /** - * Invalidates volatile entity when UUID invalidates. - * - * @todo deserialize entity. - * @author Daan van Yperen - */ - private static class EntityReferenceImpl implements net.mostlyoriginal.api.utils.reference.EntityReference { - - private UUID uuid; - private transient Entity entity; - private transient UuidEntityManager uuidEntityManager; - - public EntityReferenceImpl() { - this.uuid = null; - this.entity = null; - this.uuidEntityManager = null; - } - - public EntityReferenceImpl(Entity entity, UuidEntityManager uuidEntityManager) { - this.entity = entity; - this.uuidEntityManager = uuidEntityManager; - this.uuid = uuidEntityManager.getUuid(entity); - } - - @Override - public Entity get() { - return entity != null && uuidEntityManager.getUuid(entity).equals(uuid) ? entity : null; - } - } - - /** Tag based entity reference. */ - private static class TagEntityReference implements EntityReference { - - private transient TagManager tagManager; - private String tag; - - public TagEntityReference( TagManager tagManager, String tag ) { - this.tagManager = tagManager; - this.tag = tag; - } - - @Override - public Entity get() { - return tagManager.getEntity(tag); - } - } -} diff --git a/contrib-core/src/main/java/net/mostlyoriginal/api/utils/reference/EntityReference.java b/contrib-core/src/main/java/net/mostlyoriginal/api/utils/reference/EntityReference.java deleted file mode 100644 index 3d81f1a..0000000 --- a/contrib-core/src/main/java/net/mostlyoriginal/api/utils/reference/EntityReference.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.mostlyoriginal.api.utils.reference; - -import com.artemis.Entity; - -/** - * Abstract entity reference. - * - * @author Daan van Yperen - */ -public interface EntityReference { - - /** Return entity from reference, or null if none. */ - public Entity get(); - -} diff --git a/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/ExtendedComponentMapperPluginTest.java b/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/ExtendedComponentMapperPluginTest.java index 76e4689..2789220 100644 --- a/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/ExtendedComponentMapperPluginTest.java +++ b/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/ExtendedComponentMapperPluginTest.java @@ -306,4 +306,28 @@ protected void process(Entity e) { createAndProcessWorld(new TestSystem()); } + @Test + public void Regression_When_superMapper_plugin_in_use_Should_not_break_regular_object_inection() { + + class Injectable {} + class TestSystem extends BaseSystem { + + private M mTest; + @Wire Injectable injectable; + + @Override + protected void processSystem() { + Assert.assertNotNull(injectable); + } + } + + WorldConfiguration configuration = new WorldConfigurationBuilder() + .dependsOn(ExtendedComponentMapperPlugin.class) + .with(new TestSystem()) + .build(); + + configuration.register(new Injectable()); + + new World(configuration).process(); + } } \ No newline at end of file diff --git a/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/Pos.java b/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/Pos.java index 764f32c..8f25b79 100644 --- a/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/Pos.java +++ b/contrib-core/src/test/java/net/mostlyoriginal/api/plugin/extendedcomponentmapper/Pos.java @@ -24,9 +24,8 @@ protected void reset() { } @Override - public Pos set(Pos pos) { + public void set(Pos pos) { x = pos.x; y = pos.y; - return this; } } diff --git a/contrib-core/src/test/java/net/mostlyoriginal/api/utils/quadtree/QuadTreeIntegrationTest.java b/contrib-core/src/test/java/net/mostlyoriginal/api/utils/quadtree/QuadTreeIntegrationTest.java new file mode 100644 index 0000000..887fc42 --- /dev/null +++ b/contrib-core/src/test/java/net/mostlyoriginal/api/utils/quadtree/QuadTreeIntegrationTest.java @@ -0,0 +1,205 @@ +package net.mostlyoriginal.api.utils.quadtree; + +import com.artemis.*; +import com.artemis.annotations.Wire; +import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; +import com.artemis.utils.EntityBuilder; +import com.artemis.utils.IntBag; +import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.backends.lwjgl.LwjglApplication; +import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; +import net.mostlyoriginal.api.utils.QuadTree; + +/** + * Integration test for {@link QuadTree} + * + * @author Piotr-J + */ +public class QuadTreeIntegrationTest extends Game { + OrthographicCamera camera; + ShapeRenderer renderer; + + World world; + @Override public void create () { + camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + camera.setToOrtho(false); + camera.update(); + renderer = new ShapeRenderer(); + + WorldConfiguration config = new WorldConfigurationBuilder() + .with(new GodSystem()) + .with(new QuadTreeSystem()) + .build(); + config.register(camera).register(renderer); + world = new World(config); + + for (int i = 0; i < 10000; i++) { + new EntityBuilder(world).with( + new Position(MathUtils.random(Gdx.graphics.getWidth() - 25), MathUtils.random(Gdx.graphics.getHeight() - 25)), + new Velocity(MathUtils.random(-50, 50), MathUtils.random(-50, 50)), + new Bounds(MathUtils.random(3, 15), MathUtils.random(3, 15)) + ).build(); + } + } + + @Wire + public static class QuadTreeSystem extends IteratingSystem { + private ComponentMapper mBounds; + QuadTree qt; + + public QuadTreeSystem () { + super(Aspect.all()); + } + + @Override protected void initialize () { + // pixels, bad but simple + qt = new QuadTree(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } + + @Override protected void inserted (int entityId) { + Rectangle b = mBounds.get(entityId).rect; + qt.insert(entityId, b.x, b.y, b.width, b.height); + } + + @Override protected void process (int entityId) { + Rectangle b = mBounds.get(entityId).rect; + qt.update(entityId, b.x, b.y, b.width, b.height); + } + + @Override protected void removed (int entityId) { + qt.remove(entityId); + } + + public void get (IntBag fill, Rectangle r) { + qt.getExact(fill, r.x, r.y, r.width, r.height); + } + } + + public static class Position extends Component { + public Vector2 pos = new Vector2(); + public Position() {} + public Position (float x, float y) {pos.set(x, y);} + } + + public static class Velocity extends Component { + public Vector2 vel = new Vector2(); + public Velocity () {} + public Velocity (float x, float y) {vel.set(x, y);} + } + + public static class Bounds extends Component { + public Rectangle rect = new Rectangle(); + public Bounds() {} + public Bounds (float w, float h) {rect.setSize(w, h);} + } + + public static class Selected extends Component {} + + /** + * This is a poor system because it is doing way too much, but it makes test concise + */ + @Wire + public static class GodSystem extends EntityProcessingSystem { + @Wire OrthographicCamera camera; + @Wire ShapeRenderer renderer; + private ComponentMapper mPosition; + private ComponentMapper mVelocity; + private ComponentMapper mBounds; + private ComponentMapper mSelected; + + @Wire QuadTreeSystem qt; + + public GodSystem () { + super(Aspect.all(Position.class, Bounds.class)); + } + + float timer = 1; + Rectangle test = new Rectangle(); + IntBag fill = new IntBag(); + @Override protected void begin () { + timer += world.delta; + if (timer > 1) { + timer -= 1; + test.set( + MathUtils.random(Gdx.graphics.getWidth() - 50), MathUtils.random(Gdx.graphics.getHeight() - 50), + MathUtils.random(10f, 100f), MathUtils.random(10f, 100f) + ); + } + fill.clear(); + qt.get(fill, test); + for (int i = 0; i < fill.size(); i++) { + // since we modify and test in same system this is delayed 1 frame + world.getEntity(fill.get(i)).edit().create(Selected.class); + } + renderer.setProjectionMatrix(camera.combined); + renderer.begin(ShapeRenderer.ShapeType.Line); + } + + Vector2 tmp = new Vector2(); + @Override protected void process (Entity e) { + Vector2 pos = mPosition.get(e).pos; + Vector2 vel = mVelocity.get(e).vel; + Rectangle bounds = mBounds.get(e).rect; + pos.add(tmp.set(vel).scl(world.delta)); + if (pos.x < 0) { + pos.x = 0; + vel.x *= -1; + } else if (pos.x + bounds.width > Gdx.graphics.getWidth()) { + pos.x = Gdx.graphics.getWidth() - bounds.width; + vel.x *= -1; + } + + if (pos.y < 0) { + pos.y = 0; + vel.y *= -1; + } else if (pos.y + bounds.height> Gdx.graphics.getHeight()) { + pos.y = Gdx.graphics.getHeight() - bounds.height; + vel.y *= -1; + } + bounds.setPosition(pos.x, pos.y); + if (mSelected.has(e)) { + e.edit().remove(Selected.class); + renderer.setColor(Color.RED); + } else { + renderer.setColor(Color.MAROON); + } + renderer.rect(bounds.x, bounds.y, bounds.width, bounds.height); + } + + @Override protected void end () { + renderer.setColor(Color.CYAN); + renderer.rect(test.x, test.y, test.width, test.height); + renderer.end(); + } + } + + @Override public void render () { + Gdx.gl.glClearColor(0, 0, 0, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + world.delta = Gdx.graphics.getDeltaTime(); + world.process(); + } + + @Override public void dispose () { + world.dispose(); + renderer.dispose(); + } + + public static void main (String[] arg) { + LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); + config.width = 800; + config.height = 600; + config.useHDPI = true; + config.resizable = false; + new LwjglApplication(new QuadTreeIntegrationTest(), config); + } +} diff --git a/contrib-eventbus/pom.xml b/contrib-eventbus/pom.xml index 34fb9a4..622395b 100644 --- a/contrib-eventbus/pom.xml +++ b/contrib-eventbus/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-eventbus jar diff --git a/contrib-jam/pom.xml b/contrib-jam/pom.xml index 0a0c014..20b2c28 100644 --- a/contrib-jam/pom.xml +++ b/contrib-jam/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-jam jar diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Angle.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Angle.java index d5e599e..ff72e63 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Angle.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Angle.java @@ -1,15 +1,20 @@ package net.mostlyoriginal.api.component.basic; import com.artemis.Component; +import com.badlogic.gdx.math.Interpolation; +import net.mostlyoriginal.api.component.common.ExtendedComponent; +import net.mostlyoriginal.api.component.common.Tweenable; import java.io.Serializable; /** + * Rotation around origin (!) + * * @author Daan van Yperen * @see net.mostlyoriginal.api.system.render.AnimRenderSystem - * @todo turn into Matrix? */ -public class Angle extends Component implements Serializable { +public class Angle extends ExtendedComponent implements Tweenable { + public static final int ORIGIN_AUTO = Integer.MIN_VALUE; public static final Angle NONE = new Angle(); @@ -17,8 +22,10 @@ public class Angle extends Component implements Serializable { public float rotation = 0; /** Rotational X origin */ + @Deprecated public int ox = ORIGIN_AUTO; // rotational origin X /** Rotational Y origin */ + @Deprecated public int oy = ORIGIN_AUTO; // rotational origin Y public Angle(float rotation) { @@ -33,4 +40,21 @@ public Angle(float rotation, int ox, int oy) { public Angle() { } + + @Override + protected void reset() { + rotation=0; + } + + public void rotate(float angle) { this.rotation += angle; } + + @Override + public void set(Angle angle) { + this.rotation = angle.rotation; + } + + @Override + public void tween(Angle a, Angle b, float value) { + rotation = Interpolation.linear.apply(a.rotation, b.rotation, value); + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Bounds.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Bounds.java index db9d05c..e7c9029 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Bounds.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Bounds.java @@ -2,6 +2,7 @@ import com.artemis.Component; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import net.mostlyoriginal.api.component.common.ExtendedComponent; import java.io.Serializable; @@ -11,39 +12,39 @@ * @author Daan van Yperen * @see net.mostlyoriginal.api.system.physics.PhysicsSystem */ -public class Bounds extends Component implements Serializable { +public class Bounds extends ExtendedComponent implements Serializable { - public static final Bounds NONE = new Bounds(0,0,0,0); + public static final Bounds NONE = new Bounds(); - public int minx; - public int miny; - public int maxx; - public int maxy; + public float minx; + public float miny; + public float maxx; + public float maxy; - public Bounds(final int width, final int height) { - this.minx =this.miny =0; - this.maxx =width; - this.maxy =height; + public Bounds() {} + + @Override + protected void reset() { + this.minx = 0; + this.miny = 0; + this.maxx = 0; + this.maxy = 0; } - public Bounds(final int minx, final int miny, final int maxx, final int maxy) { + public void set(final float minx, final float miny, final float maxx, final float maxy) { this.minx = minx; this.miny = miny; this.maxx = maxx; this.maxy = maxy; } - public Bounds(TextureRegion region) { - this.minx = this.maxx =0; - this.maxx = region.getRegionWidth(); - this.maxy = region.getRegionHeight(); - } - - public Bounds() { - } - /** Center X */ - public int cx() { return minx + (maxx - minx)/2; } + public float cx() { return minx + (maxx - minx)/2; } /** Center Y */ - public int cy() { return miny + (maxy - miny)/2; } + public float cy() { return miny + (maxy - miny)/2; } + + @Override + public void set(Bounds bounds) { + set(bounds.minx, bounds.miny, bounds.maxx, bounds.maxy); + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Origin.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Origin.java new file mode 100644 index 0000000..4a9d4e9 --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Origin.java @@ -0,0 +1,90 @@ +package net.mostlyoriginal.api.component.basic; + +import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; +import net.mostlyoriginal.api.component.common.ExtendedComponent; +import net.mostlyoriginal.api.component.common.Tweenable; + +/** + * Origin relative to the dimensions of this object. + * + * 0.5, 0.5 is center. + * + * @author Daan van Yperen + */ +public class Origin extends ExtendedComponent implements Tweenable { + public Vector3 xy = new Vector3(); + + public Origin() {} + public Origin(float x, float y) { + set(x, y); + } + public Origin(float x, float y, float z) { + set(x, y, z); + } + + @Override + protected void reset() { + xy.x=0; + xy.y=0; + xy.z=0; + } + + @Override + public void set(Origin o) { + xy.x=o.xy.x; + xy.y=o.xy.y; + xy.z=o.xy.z; + } + + public void set(float x, float y) + { + xy.x = x; + xy.y = y; + } + + public void set(float x, float y, float z) + { + xy.x = x; + xy.y = y; + xy.z = z; + } + + public void set(Vector2 v) + { + xy.x = v.x; + xy.y = v.y; + } + + public void set(Vector3 v) + { + xy.x = v.x; + xy.y = v.y; + xy.z = v.z; + } + + public float getX() + { + return xy.x; + } + public float getY() + { + return xy.y; + } + public float getZ() + { + return xy.z; + } + + public void setX( float x ) { xy.x = x; } + public void setY( float y ) { xy.y = y; } + public void setZ( float z ) { xy.z = z; } + + @Override + public void tween(Origin a, Origin b, float value) { + xy.x = Interpolation.linear.apply(a.xy.x, b.xy.x, value); + xy.y = Interpolation.linear.apply(a.xy.y, b.xy.y, value); + xy.z = Interpolation.linear.apply(a.xy.z, b.xy.z, value); + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Pos.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Pos.java index 5c16208..3420e43 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Pos.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Pos.java @@ -2,65 +2,92 @@ import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; import net.mostlyoriginal.api.component.common.ExtendedComponent; import net.mostlyoriginal.api.component.common.Tweenable; /** - * Position component. + * World anchor for both 2d and 3d coordinate systems. + * + * By default Pos is the bottom-left point. {@Origin} to override. + * Use bounds to determine the center. * * @author Daan van Yperen + * @see Origin to override anchor point. + * @see Bounds to provide a bounding box. */ public class Pos extends ExtendedComponent implements Tweenable { - public Vector2 xy = new Vector2(); + public Vector3 xy = new Vector3(); + public Pos() {} public Pos(float x, float y) { set(x, y); } - - public Pos() { + public Pos(float x, float y, float z) { + set(x, y, z); } @Override protected void reset() { - xy.set(0, 0); + xy.x=0; + xy.y=0; + xy.z=0; } @Override - public Pos set(Pos pos) { - xy.set(pos.xy.x,pos.xy.y); - return this; + public void set(Pos pos) { + xy.x=pos.xy.x; + xy.y=pos.xy.y; + xy.z=pos.xy.z; + } + + public void set(float x, float y) + { + xy.x = x; + xy.y = y; + } + + public void set(float x, float y, float z) + { + xy.x = x; + xy.y = y; + xy.z = z; } - public Pos set(float x, float y) + public void set(Vector2 v) { - xy.set(x, y); - return this; + xy.x = v.x; + xy.y = v.y; } - public Pos set(Vector2 v) + public void set(Vector3 v) { - xy.set(v); - return this; + xy.x = v.x; + xy.y = v.y; + xy.z = v.z; } public float getX() { return xy.x; } - public float getY() { return xy.y; } + public float getZ() + { + return xy.z; + } - @Override - public Pos tween(Pos a, Pos b, float value) { - - final Interpolation linear = Interpolation.linear; - - xy.x = linear.apply(a.xy.x, b.xy.x, value); - xy.y = linear.apply(a.xy.y, b.xy.y, value); + public void setX( float x ) { xy.x = x; } + public void setY( float y ) { xy.y = y; } + public void setZ( float z ) { xy.z = z; } - return this; + @Override + public void tween(Pos a, Pos b, float value) { + xy.x = Interpolation.linear.apply(a.xy.x, b.xy.x, value); + xy.y = Interpolation.linear.apply(a.xy.y, b.xy.y, value); + xy.z = Interpolation.linear.apply(a.xy.z, b.xy.z, value); } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Scale.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Scale.java index cbb82a9..704a006 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Scale.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Scale.java @@ -1,12 +1,14 @@ package net.mostlyoriginal.api.component.basic; +import com.artemis.annotations.Fluid; import com.badlogic.gdx.math.Interpolation; import net.mostlyoriginal.api.component.common.ExtendedComponent; import net.mostlyoriginal.api.component.common.Tweenable; /** * @author Daan van Yperen - */ + * @deprecated behaviour not clearly defined at this time, avoid.*/ +@Deprecated public class Scale extends ExtendedComponent implements Tweenable { public static final Scale DEFAULT = new Scale(1); @@ -23,14 +25,17 @@ protected void reset() { } @Override - public Scale set(Scale scale) { + public void set(Scale scale) { this.scale = scale.scale; - return this; } + public void set(float scale) { + this.scale = scale; + } + + @Override - public Scale tween(Scale a, Scale b, float value) { + public void tween(Scale a, Scale b, float value) { scale = Interpolation.linear.apply(a.scale, b.scale, value); - return this; } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Size.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Size.java new file mode 100644 index 0000000..905a1bc --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/basic/Size.java @@ -0,0 +1,86 @@ +package net.mostlyoriginal.api.component.basic; + +import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.math.Vector3; +import net.mostlyoriginal.api.component.common.ExtendedComponent; +import net.mostlyoriginal.api.component.common.Tweenable; + +/** + * @author Daan van Yperen + */ +public class Size extends ExtendedComponent implements Tweenable { + public Vector3 xy = new Vector3(); + + public Size() {} + public Size(float x, float y) { + set(x, y); + } + public Size(float x, float y, float z) { + set(x, y, z); + } + + @Override + protected void reset() { + xy.x=0; + xy.y=0; + xy.z=0; + } + + @Override + public void set(Size size) { + xy.x=size.xy.x; + xy.y=size.xy.y; + xy.z=size.xy.z; + } + + public void set(float x, float y) + { + xy.x = x; + xy.y = y; + } + + public void set(float x, float y, float z) + { + xy.x = x; + xy.y = y; + xy.z = z; + } + + public void set(Vector2 v) + { + xy.x = v.x; + xy.y = v.y; + } + + public void set(Vector3 v) + { + xy.x = v.x; + xy.y = v.y; + xy.z = v.z; + } + + public float getX() + { + return xy.x; + } + public float getY() + { + return xy.y; + } + public float getZ() + { + return xy.z; + } + + public void setX( float x ) { xy.x = x; } + public void setY( float y ) { xy.y = y; } + public void setZ( float z ) { xy.z = z; } + + @Override + public void tween(Size a, Size b, float value) { + xy.x = Interpolation.linear.apply(a.xy.x, b.xy.x, value); + xy.y = Interpolation.linear.apply(a.xy.y, b.xy.y, value); + xy.z = Interpolation.linear.apply(a.xy.z, b.xy.z, value); + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Anim.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Anim.java index 0d976dc..4afc009 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Anim.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Anim.java @@ -1,12 +1,14 @@ package net.mostlyoriginal.api.component.graphics; import com.artemis.Component; +import com.artemis.annotations.Fluid; /** * Animations. * * @author Daan van Yperen */ +@Fluid(swallowGettersWithParameters = true) public class Anim extends Component { public boolean flippedX; // flip animation, should not affect rotation. @@ -30,4 +32,10 @@ public Anim(String id) { public Anim() { } + + public Anim set( String id) + { + this.id = id; + return this; + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/ColorAnimation.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/ColorAnimation.java deleted file mode 100644 index ab7cee8..0000000 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/ColorAnimation.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.mostlyoriginal.api.component.graphics; - -import com.artemis.Component; - -/** - * @author Daan van Yperen - */ -public class ColorAnimation extends Component { - - public Tint startTint; - public Tint endTint; - public InterpolationStrategy tween; - public float duration = -1; - public Tint speed = new Tint(1, 1, 1, 1); - public Tint age = new Tint(0, 0, 0, 0); - - /** - * - * @param startTint - * @param endTint - * @param tween - * @param speed - * @param duration duration until this ends, or -1 if unending. - */ - public ColorAnimation(Tint startTint, Tint endTint, InterpolationStrategy tween, float speed, float duration) { - this.startTint = startTint; - this.endTint = endTint; - this.tween = tween; - this.duration = duration; - this.speed.set(speed,speed,speed,speed); - } -} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Invisible.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Invisible.java index 6480b3b..4a537bd 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Invisible.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Invisible.java @@ -8,4 +8,6 @@ * @author Daan van Yperen */ public class Invisible extends Component { + public Invisible() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Renderable.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Render.java similarity index 61% rename from contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Renderable.java rename to contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Render.java index 89bdc50..b84b008 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Renderable.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Render.java @@ -3,23 +3,23 @@ import net.mostlyoriginal.api.component.common.ExtendedComponent; /** - * Indicate this entity is renderable. + * Indicate this entity requires rendering. *

* Combine with specialized renderables, like Anim or Label. * * @author Daan van Yperen * @see Anim */ -public class Renderable extends ExtendedComponent { +@Deprecated +public class Render extends ExtendedComponent { /** * target layer, higher is in front, lower is behind. */ public int layer = 0; - public Renderable() { - } - public Renderable(int layer) { + public Render() {} + public Render(int layer) { this.layer = layer; } @@ -29,8 +29,11 @@ protected void reset() { } @Override - public Renderable set(Renderable renderable) { - layer = renderable.layer; - return this; + public void set(Render render) { + layer = render.layer; + } + + public void set(int layer) { + this.layer = layer; } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Sprite.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Sprite.java new file mode 100644 index 0000000..83ccb34 --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Sprite.java @@ -0,0 +1,25 @@ +package net.mostlyoriginal.api.component.graphics; + +import net.mostlyoriginal.api.component.common.ExtendedComponent; + +/** + * @author Daan van Yperen + */ +public class Sprite extends ExtendedComponent { + + public String id; + + @Override + protected void reset() { + id = null; + } + + @Override + public void set(Sprite sprite) { + this.id = sprite.id; + } + + public void set(String id) { + this.id=id; + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/SpriteAsset.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/SpriteAsset.java new file mode 100644 index 0000000..441844e --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/SpriteAsset.java @@ -0,0 +1,23 @@ +package net.mostlyoriginal.api.component.graphics; + +import com.artemis.PooledComponent; +import com.artemis.annotations.Fluid; +import com.artemis.annotations.Transient; +import com.artemis.annotations.Fluid; +import com.artemis.annotations.Transient; +import com.badlogic.gdx.graphics.Texture; + +/** + * @author Daan van Yperen + */ +@Fluid(exclude = true) +@Transient +public class SpriteAsset extends PooledComponent { + + public Texture asset; + + @Override + protected void reset() { + asset = null; + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Terrain.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Terrain.java new file mode 100644 index 0000000..63d76bc --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Terrain.java @@ -0,0 +1,26 @@ +package net.mostlyoriginal.api.component.graphics; + +import net.mostlyoriginal.api.component.common.ExtendedComponent; + +/** + * @author Daan van Yperen + */ +public class Terrain extends ExtendedComponent { + + public String id; + + @Override + protected void reset() { + id=null; + } + + @Override + public void set(Terrain terrain) { + this.id=terrain.id; + } + + public void set(String id) + { + this.id=id; + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/TerrainAsset.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/TerrainAsset.java new file mode 100644 index 0000000..2a6bf1f --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/TerrainAsset.java @@ -0,0 +1,31 @@ +package net.mostlyoriginal.api.component.graphics; + +import com.artemis.PooledComponent; +import com.artemis.annotations.Fluid; +import com.artemis.annotations.Transient; +import com.badlogic.gdx.maps.MapRenderer; +import com.badlogic.gdx.maps.tiled.TiledMap; +import com.badlogic.gdx.maps.tiled.TiledMapRenderer; + +/** + * @author Daan van Yperen + */ +@Transient +public class TerrainAsset extends PooledComponent { + + public TiledMap map; + public MapRenderer renderer; + public int width; + public int height; + public int tileWidth; + public int tileHeight; + + public int pixelWidth() { return width * tileWidth; } + public int pixelHeight() { return height * tileHeight; } + + @Override + protected void reset() { + renderer = null; + map = null; + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Tint.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Tint.java index cd54169..d54a4cf 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Tint.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/graphics/Tint.java @@ -1,5 +1,6 @@ package net.mostlyoriginal.api.component.graphics; +import com.artemis.annotations.Fluid; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Interpolation; import net.mostlyoriginal.api.component.common.ExtendedComponent; @@ -13,9 +14,11 @@ * @see Color * @author Daan van Yperen */ +@Fluid(swallowGettersWithParameters=true) public class Tint extends ExtendedComponent implements Tweenable { public static final Tint WHITE = new Tint(Color.WHITE); + public static final Tint TRANSPARENT = new Tint("ffffff00"); public Color color = new Color(); @@ -49,38 +52,34 @@ public Tint(String hex) { /** * Set color to hex, RRGGBBAA. */ - public Tint setHex(String hex) { + public void setHex(String hex) { set((float) Integer.valueOf(hex.substring(0, 2), 16) / 255.0F, (float) Integer.valueOf(hex.substring(2, 4), 16) / 255.0F, (float) Integer.valueOf(hex.substring(4, 6), 16) / 255.0F, (float) (hex.length() != 8 ? 255 : Integer.valueOf(hex.substring(6, 8), 16)) / 255.0F); - return this; } - public Tint set(Color color) { + public void set(Color color) { this.color.set(color); - return this; } - public Tint set(float r, float g, float b, float a) { + public void set(float r, float g, float b, float a) { this.color.r = r; this.color.g = g; this.color.b = b; this.color.a = a; - return this; } @Override - public Tint set(Tint tint) { + public void set(Tint tint) { this.color.r = tint.color.r; this.color.g = tint.color.g; this.color.b = tint.color.b; this.color.a = tint.color.a; - return this; } @Override - public Tint tween(Tint a, Tint b, float value) { + public void tween(Tint a, Tint b, float value) { final Interpolation linear = Interpolation.linear; @@ -91,7 +90,5 @@ public Tint tween(Tint a, Tint b, float value) { color.g = linear.apply(colorA.g, colorB.g, value); color.b = linear.apply(colorA.b, colorB.b, value); color.a = linear.apply(colorA.a, colorB.a, value); - - return this; } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Aim.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Aim.java index c906c7e..cb9efde 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Aim.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Aim.java @@ -1,7 +1,7 @@ package net.mostlyoriginal.api.component.interact; import com.artemis.Component; -import net.mostlyoriginal.api.utils.reference.EntityReference; +import com.artemis.annotations.EntityId; /** * Entity aims at target entity. @@ -9,9 +9,11 @@ * @author Daan van Yperen */ public class Aim extends Component { - public EntityReference at; - public Aim(EntityReference at) { + @EntityId + public int at; + + public Aim(int at) { this.at = at; } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Focus.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Focus.java index 99bfc1b..2c1a1e0 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Focus.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/interact/Focus.java @@ -1,7 +1,7 @@ package net.mostlyoriginal.api.component.interact; import com.artemis.Component; -import net.mostlyoriginal.api.utils.reference.EntityReference; +import com.artemis.annotations.EntityId; /** * Focus of entity (for example, focus for aggression). @@ -9,9 +9,14 @@ * @author Daan van Yperen */ public class Focus extends Component { - public EntityReference entity; - public Focus(EntityReference entity) { + @EntityId + public int entity; + + public Focus(int entity) { this.entity = entity; } + + public Focus() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapSolid.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapSolid.java index ca43517..214fc80 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapSolid.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapSolid.java @@ -11,4 +11,6 @@ * @see net.mostlyoriginal.api.system.map.MapCollisionSystem */ public class MapSolid extends Component implements Serializable { + public MapSolid() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapWallSensor.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapWallSensor.java index 77c1829..27001d4 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapWallSensor.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/map/MapWallSensor.java @@ -20,4 +20,7 @@ public class MapWallSensor extends Component implements Serializable { public boolean onAnySurface() { return onHorizontalSurface || onVerticalSurface; } + + public MapWallSensor() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/mouse/MouseCursor.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/mouse/MouseCursor.java index c3efc01..2a4ed24 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/mouse/MouseCursor.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/mouse/MouseCursor.java @@ -10,4 +10,6 @@ * @author Daan van Yperen */ public class MouseCursor extends Component implements Serializable { + public MouseCursor() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Attached.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Attached.java index df4eabc..3a3bd0d 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Attached.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Attached.java @@ -1,7 +1,7 @@ package net.mostlyoriginal.api.component.physics; import com.artemis.Component; -import net.mostlyoriginal.api.utils.reference.EntityReference; +import com.artemis.annotations.EntityId; /** * Attach entity to parent entity. @@ -10,7 +10,8 @@ */ public class Attached extends Component { - public EntityReference parent; + @EntityId + public int parent; // xo + parent x = entity x public int xo; @@ -27,7 +28,10 @@ public class Attached extends Component { // Tension on the spring to return to its original state. 1= really slow. public float tension = 30; - public Attached(EntityReference parent) { + public Attached() { + } + + public Attached(int parent) { this.parent = parent; } @@ -36,7 +40,7 @@ public Attached(EntityReference parent) { * @param xo X offset relative to parent X. * @param yo Y offset relative to parent Y. */ - public Attached(EntityReference parent, int xo, int yo) { + public Attached(int parent, int xo, int yo) { this.parent = parent; this.xo = xo; this.yo = yo; diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Frozen.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Frozen.java index dbf15cd..75099e0 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Frozen.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Frozen.java @@ -12,4 +12,6 @@ * @see net.mostlyoriginal.api.system.physics.PhysicsSystem */ public class Frozen extends Component implements Serializable { + public Frozen() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Gravity.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Gravity.java index 3267fd7..c415959 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Gravity.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Gravity.java @@ -24,4 +24,6 @@ public Gravity() {} public Gravity(float y) { this.y = y; } + + public void set(float x, float y) { this.x=x; this.y=y;} } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Homing.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Homing.java index 68690e7..fe36b75 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Homing.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Homing.java @@ -1,7 +1,7 @@ package net.mostlyoriginal.api.component.physics; import com.artemis.Component; -import net.mostlyoriginal.api.utils.reference.EntityReference; +import com.artemis.annotations.EntityId; /** * Accelerate entity towards target entity in a straight path. @@ -10,14 +10,17 @@ */ public class Homing extends Component { - public EntityReference target; + @EntityId + public int target; public float speedFactor = 5f; // Distance within which this entity will accelerate. public float maxDistance = 999999f; - public Homing(EntityReference target) { + public Homing(int target) { this.target = target; } + public Homing() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Inbetween.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Inbetween.java index dc53a8f..d65e728 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Inbetween.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Inbetween.java @@ -1,7 +1,7 @@ package net.mostlyoriginal.api.component.physics; import com.artemis.Component; -import net.mostlyoriginal.api.utils.reference.EntityReference; +import com.artemis.annotations.EntityId; /** * Entity positions itself somewhere between two target entities. @@ -10,8 +10,8 @@ */ public class Inbetween extends Component { - public EntityReference a; - public EntityReference b; + @EntityId public int a; + @EntityId public int b; /** Location in between point A and B 0.0 at a, 1.0 at b location */ public float tween = 0.5f; /** Offset between A and B. */ @@ -20,14 +20,17 @@ public class Inbetween extends Component { /** Maximum pixel distance from point A. */ public float maxDistance = Float.MAX_VALUE; - public Inbetween(EntityReference a, EntityReference b) { + public Inbetween(int a, int b) { this.a = a; this.b = b; } - public Inbetween(EntityReference a, EntityReference b, float tween) { + public Inbetween(int a, int b, float tween) { this.a = a; this.b = b; this.tween = tween; } + + public Inbetween() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Physics.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Physics.java index 7cb6a18..bcf5f2c 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Physics.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/physics/Physics.java @@ -1,6 +1,7 @@ package net.mostlyoriginal.api.component.physics; import com.artemis.Component; +import com.artemis.annotations.Fluid; import java.io.Serializable; @@ -11,6 +12,7 @@ * @author Daan van Yperen * @see net.mostlyoriginal.api.system.physics.PhysicsSystem */ +@Fluid(swallowGettersWithParameters = true) public class Physics extends Component implements Serializable { // velocityX in units per second. @@ -28,4 +30,14 @@ public class Physics extends Component implements Serializable { // Maximum travel distance in units (typically pixels) per second. public float maxVelocity = Float.MAX_VALUE; + + public Physics() { + } + + public Physics velocity(float vx, float vy, float friction) { + this.vx = vx; + this.vy = vy; + this.friction = friction; + return this; + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/script/EntitySpawner.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/script/EntitySpawner.java index 3fd20f0..3913398 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/script/EntitySpawner.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/script/EntitySpawner.java @@ -9,6 +9,8 @@ * @see net.mostlyoriginal.api.system.script.EntitySpawnerSystem */ public class EntitySpawner extends Component { + public EntitySpawner() { + } public String[] entityIds; diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/BitmapFontAsset.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/BitmapFontAsset.java index 1ae675c..8833790 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/BitmapFontAsset.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/BitmapFontAsset.java @@ -11,13 +11,15 @@ public class BitmapFontAsset extends ExtendedComponent { public BitmapFont bitmapFont; @Override - public BitmapFontAsset set(BitmapFontAsset asset) { + public void set(BitmapFontAsset asset) { bitmapFont = asset.bitmapFont; - return this; } @Override protected void reset() { bitmapFont = null; } + + public BitmapFontAsset() { + } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Font.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Font.java index 4b0906b..e960e9a 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Font.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Font.java @@ -16,9 +16,8 @@ public Font(String fontName) { } @Override - public Font set(Font font) { + public void set(Font font) { fontName = font.fontName; - return this; } @Override @@ -26,4 +25,6 @@ protected void reset() { fontName = null; scale = 1f; } + + } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Label.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Label.java index 0274bee..ae9c1a9 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Label.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/component/ui/Label.java @@ -22,10 +22,9 @@ protected void reset() { } @Override - public Label set(Label label) { + public void set(Label label) { text = label.text; align = label.align; - return this; } public enum Align { diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/AbstractAssetSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/AbstractAssetSystem.java index 8aeb52f..81824d2 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/AbstractAssetSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/AbstractAssetSystem.java @@ -77,11 +77,12 @@ protected void loadSounds(String[] soundnames) { } public void playSfx(String name) { - if (sfxVolume > 0 ) - { + if (sfxVolume > 0) { Sound sfx = getSfx(name); - sfx.stop(); - sfx.play(sfxVolume, MathUtils.random(1f, 1.04f), 0); + if (sfx != null) { + sfx.stop(); + sfx.play(sfxVolume, MathUtils.random(1f, 1.04f), 0); + } } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/SpriteManager.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/SpriteManager.java new file mode 100644 index 0000000..b604184 --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/SpriteManager.java @@ -0,0 +1,40 @@ +package net.mostlyoriginal.api.manager; + +import com.artemis.ComponentMapper; +import com.artemis.Entity; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.maps.MapProperties; +import com.badlogic.gdx.maps.tiled.TmxMapLoader; +import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; +import net.mostlyoriginal.api.component.basic.Size; +import net.mostlyoriginal.api.component.graphics.Sprite; +import net.mostlyoriginal.api.component.graphics.SpriteAsset; +import net.mostlyoriginal.api.component.graphics.Terrain; +import net.mostlyoriginal.api.component.graphics.TerrainAsset; + +/** + * Sprite loader. + * + * @author Daan van Yperen + */ +public class SpriteManager extends AssetManager { + + protected ComponentMapper mSize; + + public SpriteManager() { + super(Sprite.class, SpriteAsset.class); + } + + private com.badlogic.gdx.assets.AssetManager manager = new com.badlogic.gdx.assets.AssetManager(); + + @Override + protected void setup(Entity e, Sprite sprite, SpriteAsset spriteAsset) { + spriteAsset.asset = new Texture(sprite.id); + + // set size to asset. + if (!mSize.has(e)) { + mSize.create(e).set(spriteAsset.asset.getWidth(), spriteAsset.asset.getHeight()); + } + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/TerrainManager.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/TerrainManager.java new file mode 100644 index 0000000..616307b --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/manager/TerrainManager.java @@ -0,0 +1,53 @@ +package net.mostlyoriginal.api.manager; + +import com.artemis.ComponentMapper; +import com.artemis.Entity; +import com.badlogic.gdx.maps.MapProperties; +import com.badlogic.gdx.maps.tiled.TiledMap; +import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; +import com.badlogic.gdx.maps.tiled.TmxMapLoader; +import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; +import net.mostlyoriginal.api.component.basic.Size; +import net.mostlyoriginal.api.component.graphics.Terrain; +import net.mostlyoriginal.api.component.graphics.TerrainAsset; +import net.mostlyoriginal.api.component.ui.BitmapFontAsset; +import net.mostlyoriginal.api.component.ui.Font; + +/** + * @author Daan van Yperen + */ +public class TerrainManager extends AssetManager { + + protected ComponentMapper mSize; + private TmxMapLoader loader; + + public TerrainManager() { + super(Terrain.class, TerrainAsset.class); + } + + @Override + protected void initialize() { + super.initialize(); + loader = new TmxMapLoader(); + } + + @Override + protected void setup(Entity e, Terrain terrain, TerrainAsset asset) { + if (terrain.id == null ) { + throw new RuntimeException("TerrainManager: terrain.id is null."); + } + asset.map = loader.load(terrain.id); + asset.renderer = new OrthogonalTiledMapRenderer(asset.map); + //asset.layers = map.getLayers().getByType(TiledMapTileLayer.class); + final MapProperties properties = asset.map.getProperties(); + asset.width = properties.get("width", Integer.class); + asset.height = properties.get("height", Integer.class); + asset.tileWidth = properties.get("tilewidth", Integer.class); + asset.tileHeight = properties.get("tileheight", Integer.class); + + // set unitialized size to asset. + if (!mSize.has(e)) { + mSize.create(e).set(asset.pixelWidth(), asset.pixelHeight()); + } + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/JamOperationFactory.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/JamOperationFactory.java index 6574ce8..23763b6 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/JamOperationFactory.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/JamOperationFactory.java @@ -1,9 +1,12 @@ package net.mostlyoriginal.api.operation; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Pos; +import net.mostlyoriginal.api.component.graphics.Tint; import net.mostlyoriginal.api.operation.common.Operation; +import net.mostlyoriginal.api.operation.temporal.TweenOperation; /** * @author Daan van Yperen @@ -90,7 +93,7 @@ public static TweenPosOperation moveBetween(Pos from, Pos to, float duration, In } /** - * Set Pos. + * Instantly move to coords. */ public static SetPosOperation moveTo(float x, float y) { final SetPosOperation operation = Operation.prepare(SetPosOperation.class); @@ -99,19 +102,20 @@ public static SetPosOperation moveTo(float x, float y) { } /** - * Set pos by {@see Pos}. + * Instantly move to coords {@see Pos}. */ public static SetPosOperation moveTo(Pos pos) { return moveTo(pos.xy.x, pos.xy.y); } /** - * Set pos by {@see com.badlogic.gdx.math.Vector2}. + * Instantly move to coords {@see Pos}. */ public static SetPosOperation moveTo(Vector2 v) { return moveTo(v.x, v.y); } + /** * Linear scale between pos. * @@ -140,11 +144,57 @@ public static TweenScaleOperation scaleBetween(float from, float to, float durat } /** - * Set Scale. + * Instantly scale to coords {@see Pos}. */ public static SetScaleOperation scaleTo(float scale) { final SetScaleOperation operation = Operation.prepare(SetScaleOperation.class); operation.get().scale = scale; return operation; } + + /** + * Set tint. + * + * @param to end + */ + public static SetTintOperation tintTo(Tint to) { + SetTintOperation operation = Operation.prepare(SetTintOperation.class); + operation.get().set(to); + return operation; + } + + /** + * Linear tween for tint (color). + * + * @param from start + * @param to end + * @param duration duration of tween, in seconds. + */ + public static TweenTintOperation tintBetween(Tint from, Tint to, float duration) { + return tintBetween(from, to, duration, Interpolation.linear); + } + + /** + * Tween for tint (color). + * + * @param from start + * @param to end + * @param duration duration of tween, in seconds. + * @param interpolation method of interpolation. + */ + public static TweenTintOperation tintBetween(Tint from, Tint to, float duration, Interpolation interpolation) { + final TweenTintOperation operation = prepTween(TweenTintOperation.class, duration, interpolation); + operation.getFrom().set(from); + operation.getTo().set(to); + return operation; + } + + private static Tint fromTmp = new Tint(); + private static Tint toTmp = new Tint(); + + private static T prepTween(Class operationType, float duration, Interpolation interpolation) { + final T operation = Operation.prepare(operationType); + operation.setup(interpolation, duration); + return operation; + } } \ No newline at end of file diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/SetTintOperation.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/SetTintOperation.java new file mode 100644 index 0000000..976ab16 --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/SetTintOperation.java @@ -0,0 +1,14 @@ +package net.mostlyoriginal.api.operation; + +import net.mostlyoriginal.api.component.basic.Pos; +import net.mostlyoriginal.api.component.graphics.Tint; +import net.mostlyoriginal.api.operation.basic.SetOperation; + +/** + * @author Daan van Yperen + */ +public class SetTintOperation extends SetOperation { + public SetTintOperation() { + super(Tint.class); + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/TweenTintOperation.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/TweenTintOperation.java new file mode 100644 index 0000000..aad722b --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/operation/TweenTintOperation.java @@ -0,0 +1,16 @@ +package net.mostlyoriginal.api.operation; + +import net.mostlyoriginal.api.component.basic.Pos; +import net.mostlyoriginal.api.component.graphics.Tint; +import net.mostlyoriginal.api.operation.temporal.TweenOperation; + +/** + * Tween between tints. + * + * @author Daan van Yperen + */ +public class TweenTintOperation extends TweenOperation { + public TweenTintOperation() { + super(Tint.class); + } +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/screen/core/WorldScreen.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/screen/core/WorldScreen.java index 3b80ce3..ce26025 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/screen/core/WorldScreen.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/screen/core/WorldScreen.java @@ -1,4 +1,4 @@ -package net.mostlyoriginal.api.screen.core; + package net.mostlyoriginal.api.screen.core; import com.artemis.World; import com.badlogic.gdx.Screen; diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/camera/EntityCameraSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/camera/EntityCameraSystem.java index 3dcb010..10d010d 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/camera/EntityCameraSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/camera/EntityCameraSystem.java @@ -5,19 +5,24 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; +import net.mostlyoriginal.api.component.basic.Angle; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.camera.Camera; /** * Lock camera center on camera entity. * + * Rotation support. + * * @author Daan van Yperen * @see net.mostlyoriginal.api.component.camera.Camera */ @Wire -public class EntityCameraSystem extends EntityProcessingSystem { +public class EntityCameraSystem extends IteratingSystem { private ComponentMapper pm; + protected ComponentMapper mAngle; private CameraSystem cameraSystem; public EntityCameraSystem() { @@ -25,10 +30,17 @@ public EntityCameraSystem() { } @Override - protected void process(Entity e) { + protected void process(int e) { final Pos pos = pm.get(e); + cameraSystem.camera.position.x = (int)(pos.xy.x); cameraSystem.camera.position.y = (int)(pos.xy.y); + + if ( mAngle.has(e)) + { + cameraSystem.camera.up.set(0, 1, 0).rotate(cameraSystem.camera.direction, -mAngle.get(e).rotation); + } + cameraSystem.camera.update(); } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/ColorAnimationSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/ColorAnimationSystem.java deleted file mode 100644 index 5bcb2f6..0000000 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/ColorAnimationSystem.java +++ /dev/null @@ -1,59 +0,0 @@ -package net.mostlyoriginal.api.system.graphics; - -import com.artemis.Aspect; -import com.artemis.ComponentMapper; -import com.artemis.Entity; -import com.artemis.annotations.Wire; -import com.artemis.systems.EntityProcessingSystem; -import net.mostlyoriginal.api.component.graphics.ColorAnimation; -import net.mostlyoriginal.api.component.graphics.Tint; - -/** - * Tween Entity animation between two colors. - * - * @author Daan van Yperen - * @see net.mostlyoriginal.api.component.graphics.ColorAnimation - */ -@Wire -public class ColorAnimationSystem extends EntityProcessingSystem { - - protected ComponentMapper mColor; - protected ComponentMapper cm; - - @SuppressWarnings("unchecked") - public ColorAnimationSystem() { - super(Aspect.all(Tint.class, ColorAnimation.class)); - } - - @Override - protected void process(final Entity entity) { - - final ColorAnimation colorAnimation = cm.get(entity); - final Tint tint = mColor.get(entity); - - // age colors individually. - - colorAnimation.age.color.r += colorAnimation.speed.color.r * world.delta; - colorAnimation.age.color.g += colorAnimation.speed.color.g * world.delta; - colorAnimation.age.color.b += colorAnimation.speed.color.b * world.delta; - colorAnimation.age.color.a += colorAnimation.speed.color.a * world.delta; - - // tween colors individually. - tint.color.r = colorAnimation.tween.apply( colorAnimation.startTint.color.r, colorAnimation.endTint.color.r, 1- Math.abs(colorAnimation.age.color.r % 2f - 1)); - tint.color.g = colorAnimation.tween.apply( colorAnimation.startTint.color.g, colorAnimation.endTint.color.g, 1- Math.abs(colorAnimation.age.color.g % 2f - 1)); - tint.color.b = colorAnimation.tween.apply( colorAnimation.startTint.color.b, colorAnimation.endTint.color.b, 1- Math.abs(colorAnimation.age.color.b % 2f - 1)); - tint.color.a = colorAnimation.tween.apply( colorAnimation.startTint.color.a, colorAnimation.endTint.color.a, 1- Math.abs(colorAnimation.age.color.a % 2f - 1)); - - if ( colorAnimation.duration != -1 ) - { - colorAnimation.duration -= world.delta; - if ( colorAnimation.duration <= 0 ) - { - // always end on the end tint. - tint.set(colorAnimation.endTint); - entity.edit().remove(ColorAnimation.class); - } - - } - } -} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/RenderBatchingSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/RenderBatchingSystem.java index d11f063..1f71853 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/RenderBatchingSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/graphics/RenderBatchingSystem.java @@ -9,7 +9,7 @@ import com.artemis.World; import com.artemis.annotations.Wire; import com.artemis.utils.Bag; -import net.mostlyoriginal.api.component.graphics.Renderable; +import net.mostlyoriginal.api.component.graphics.Render; import net.mostlyoriginal.api.system.delegate.EntityProcessAgent; import net.mostlyoriginal.api.system.delegate.EntityProcessPrincipal; import net.mostlyoriginal.api.utils.BagUtils; @@ -29,7 +29,7 @@ @Wire public class RenderBatchingSystem extends BaseSystem implements EntityProcessPrincipal { - protected ComponentMapper mRenderable; + protected ComponentMapper mRenderable; protected final Bag sortedJobs = new Bag<>(); public boolean sortedDirty = false; diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/interact/AimSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/interact/AimSystem.java index 63fce5f..1724a04 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/interact/AimSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/interact/AimSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Angle; import net.mostlyoriginal.api.component.basic.Pos; @@ -20,9 +21,10 @@ * @see net.mostlyoriginal.api.component.interact.Aim */ @Wire -public class AimSystem extends EntityProcessingSystem { +public class AimSystem extends IteratingSystem { private ComponentMapper am; + private ComponentMapper pm; private ComponentMapper anm; public AimSystem() { @@ -32,16 +34,20 @@ public AimSystem() { Vector2 vTmp = new Vector2(); @Override - protected void process(Entity e) { + protected void process(int e) { final Aim aim = am.get(e); - final Entity target = aim.at.get(); - if (target != null) { + final int target = aim.at; + if (target != -1) { aimAt(e, target); } } - public void aimAt(Entity e, Entity at) { - anm.get(e).rotation = EntityUtil.angle(e, at); + public void aimAt(int e, int at) { + + final Pos pa = pm.get(e); + final Pos pb = pm.get(at); + + anm.get(e).rotation = vTmp.set(pb.xy.x, pb.xy.y).sub(pa.xy.x, pa.xy.y).angle(); } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapCollisionSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapCollisionSystem.java index 6fb97d1..0b59d9f 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapCollisionSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapCollisionSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import net.mostlyoriginal.api.component.basic.Bounds; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.map.MapSolid; @@ -26,7 +27,7 @@ * @see net.mostlyoriginal.api.component.map.MapSolid */ @Wire -public class MapCollisionSystem extends EntityProcessingSystem { +public class MapCollisionSystem extends IteratingSystem { private TiledMapSystem mapSystem; private CameraSystem cameraSystem; @@ -55,7 +56,7 @@ protected void end() { } @Override - protected void process(Entity e) { + protected void process(int e) { final Physics physics = ym.get(e); final Pos pos = pm.get(e); final Bounds bounds = bm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapWallSensorSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapWallSensorSystem.java index 57b80be..c6bf9f3 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapWallSensorSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/map/MapWallSensorSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import net.mostlyoriginal.api.component.basic.Bounds; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.map.MapWallSensor; @@ -21,7 +22,7 @@ * @see net.mostlyoriginal.api.component.map.MapWallSensor */ @Wire -public class MapWallSensorSystem extends EntityProcessingSystem { +public class MapWallSensorSystem extends IteratingSystem { public static final String MASK_SOLID_ID = "solid"; @@ -52,7 +53,7 @@ protected void end() { } @Override - protected void process(Entity e) { + protected void process(int e) { final Pos pos = pm.get(e); final Bounds bounds = bm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/mouse/MouseCursorSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/mouse/MouseCursorSystem.java index 9e55a1d..ce3f2eb 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/mouse/MouseCursorSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/mouse/MouseCursorSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector3; import net.mostlyoriginal.api.component.basic.Pos; @@ -18,7 +19,7 @@ * @see net.mostlyoriginal.api.component.mouse.MouseCursor */ @Wire -public class MouseCursorSystem extends EntityProcessingSystem { +public class MouseCursorSystem extends IteratingSystem { private ComponentMapper pm; private ComponentMapper am; @@ -32,7 +33,7 @@ public MouseCursorSystem() { private Vector3 aimAtTmp = new Vector3(); @Override - protected void process(Entity e) { + protected void process(int e) { final Pos pos = pm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/AttachmentSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/AttachmentSystem.java index 3539d59..8c40e7a 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/AttachmentSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/AttachmentSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.physics.Attached; @@ -17,7 +18,7 @@ * @see net.mostlyoriginal.api.component.physics.Attached */ @Wire -public class AttachmentSystem extends EntityProcessingSystem { +public class AttachmentSystem extends IteratingSystem { private ComponentMapper pm; private ComponentMapper am; @@ -29,11 +30,11 @@ public AttachmentSystem() { Vector2 vTmp = new Vector2(); @Override - protected void process(Entity e) { + protected void process(int e) { final Attached attached = am.get(e); - final Entity parent = attached.parent.get(); - if (parent != null) { + final int parent = attached.parent; + if (parent != -1) { // move attachment to absolute position, adjusted with slack. Pos pos = pm.get(e); @@ -44,7 +45,7 @@ protected void process(Entity e) { updateSlack(attached); } else { // parent gone? we gone! - e.deleteFromWorld(); + world.delete(e); } } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/ClampedSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/ClampedSystem.java index 1d57ac2..e2baad6 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/ClampedSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/ClampedSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.math.MathUtils; import net.mostlyoriginal.api.component.basic.Bounds; import net.mostlyoriginal.api.component.basic.Pos; @@ -22,7 +23,7 @@ * @see net.mostlyoriginal.api.component.basic.Bounds */ @Wire(injectInherited = true) -public class ClampedSystem extends EntityProcessingSystem { +public class ClampedSystem extends IteratingSystem { private ComponentMapper pm; private ComponentMapper bm; @@ -39,7 +40,7 @@ public ClampedSystem() { } @Override - protected void process(Entity e) { + protected void process(int e) { final Pos pos = pm.get(e); final Bounds bounds = bm.has(e) ? bm.get(e) : Bounds.NONE; final Clamped clamped = cm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/GravitySystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/GravitySystem.java index 30ef723..5aa9042 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/GravitySystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/GravitySystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import net.mostlyoriginal.api.component.physics.Gravity; import net.mostlyoriginal.api.component.physics.Physics; @@ -15,7 +16,7 @@ * @see net.mostlyoriginal.api.component.physics.Gravity */ @Wire -public class GravitySystem extends EntityProcessingSystem { +public class GravitySystem extends IteratingSystem { public static final int GRAVITY_FACTOR = 50; @@ -27,7 +28,7 @@ public GravitySystem() { } @Override - protected void process(Entity e) { + protected void process(int e) { final Physics physics = pm.get(e); final Gravity gravity = gm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/HomingSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/HomingSystem.java index 818770b..9cc6cf1 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/HomingSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/HomingSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.physics.Attached; @@ -19,7 +20,7 @@ * @see net.mostlyoriginal.api.component.physics.Homing */ @Wire -public class HomingSystem extends EntityProcessingSystem { +public class HomingSystem extends IteratingSystem { ComponentMapper hm; ComponentMapper pm; @@ -33,13 +34,13 @@ public HomingSystem() { private static final Vector2 tmp = new Vector2(); @Override - protected void process(Entity e) { + protected void process(int e) { final Homing homing = hm.get(e); - final Entity homingTarget = homing.target.get(); - if (homingTarget != null) { + final int homingTarget = homing.target; + if (homingTarget != -1) { - final float distance = EntityUtil.distance(e, homingTarget); + final float distance = distance(e, homingTarget); if (distance < homing.maxDistance) { final Pos myPos = pm.get(e); @@ -62,6 +63,15 @@ protected void process(Entity e) { } } - } else homing.target = null; + } else homing.target = -1; } + + public float distance( final int a, final int b) + { + final Pos pa = pm.get(a); + final Pos pb = pm.get(b); + + return tmp.set(pa.xy.x, pa.xy.y).dst(pb.xy.x, pb.xy.y); + } + } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/InbetweenSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/InbetweenSystem.java index 836f292..93420b8 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/InbetweenSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/InbetweenSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.physics.Inbetween; @@ -16,7 +17,7 @@ * @see net.mostlyoriginal.api.component.physics.Inbetween */ @Wire -public class InbetweenSystem extends EntityProcessingSystem { +public class InbetweenSystem extends IteratingSystem { ComponentMapper dm; ComponentMapper pm; @@ -29,13 +30,13 @@ public InbetweenSystem() { Vector2 tmp = new Vector2(); @Override - protected void process(Entity e) { + protected void process(int e) { final Inbetween inbetween = dm.get(e); - final Entity entityA = inbetween.a.get(); - final Entity entityB = inbetween.b.get(); - if ( entityA == null || entityB == null ) return; + final int entityA = inbetween.a; + final int entityB = inbetween.b; + if ( entityA == -1 || entityB == -1 ) return; Pos pos1 = pm.get(entityA); Pos pos2 = pm.get(entityB); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/PhysicsSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/PhysicsSystem.java index 4de4bdf..16a3d6b 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/PhysicsSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/physics/PhysicsSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Angle; import net.mostlyoriginal.api.component.basic.Pos; @@ -24,7 +25,7 @@ */ @Wire -public class PhysicsSystem extends EntityProcessingSystem { +public class PhysicsSystem extends IteratingSystem { public static final float AIR_FRICTION = 0.25f; public static final int FLOOR_FRICTION = 1; @@ -49,7 +50,7 @@ public void push(Entity entity, float rotation, float force) { } } - public void clampVelocity(Entity entity, float minSpeed, float maxSpeed) { + public void clampVelocity(int entity, float minSpeed, float maxSpeed) { if (ym.has(entity)) { final Physics physics = ym.get(entity); clampVelocity(physics, minSpeed, maxSpeed); @@ -63,7 +64,7 @@ private void clampVelocity(Physics physics, float minSpeed, float maxSpeed) { } @Override - protected void process(Entity e) { + protected void process(int e) { final Physics physics = ym.get(e); final Pos pos = pm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/AnimRenderSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/AnimRenderSystem.java index e358870..052c3f7 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/AnimRenderSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/AnimRenderSystem.java @@ -13,7 +13,7 @@ import net.mostlyoriginal.api.component.basic.Scale; import net.mostlyoriginal.api.component.graphics.Anim; import net.mostlyoriginal.api.component.graphics.Invisible; -import net.mostlyoriginal.api.component.graphics.Renderable; +import net.mostlyoriginal.api.component.graphics.Render; import net.mostlyoriginal.api.component.graphics.Tint; import net.mostlyoriginal.api.manager.AbstractAssetSystem; import net.mostlyoriginal.api.plugin.extendedcomponentmapper.M; @@ -42,7 +42,7 @@ public class AnimRenderSystem extends DeferredEntityProcessingSystem { protected SpriteBatch batch; public AnimRenderSystem(EntityProcessPrincipal principal) { - super(Aspect.all(Pos.class, Anim.class, Renderable.class).exclude(Invisible.class), principal); + super(Aspect.all(Pos.class, Anim.class, Render.class).exclude(Invisible.class), principal); } @Override diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/BasicSpriteRenderSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/BasicSpriteRenderSystem.java new file mode 100644 index 0000000..c6917ce --- /dev/null +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/BasicSpriteRenderSystem.java @@ -0,0 +1,84 @@ +package net.mostlyoriginal.api.system.render; + +import com.artemis.Aspect; +import com.artemis.ComponentMapper; +import com.artemis.annotations.Wire; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.maps.tiled.renderers.BatchTiledMapRenderer; +import com.badlogic.gdx.math.Matrix4; +import net.mostlyoriginal.api.component.basic.Angle; +import net.mostlyoriginal.api.component.basic.Origin; +import net.mostlyoriginal.api.component.basic.Pos; +import net.mostlyoriginal.api.component.basic.Size; +import net.mostlyoriginal.api.component.graphics.Invisible; +import net.mostlyoriginal.api.component.graphics.Render; +import net.mostlyoriginal.api.component.graphics.SpriteAsset; +import net.mostlyoriginal.api.component.graphics.TerrainAsset; +import net.mostlyoriginal.api.system.camera.CameraSystem; +import net.mostlyoriginal.api.system.delegate.DeferredEntityProcessingSystem; +import net.mostlyoriginal.api.system.delegate.EntityProcessPrincipal; + +/** + * Very basic sprite render system. + * + * @author Daan van Yperen + */ +@Wire +public class BasicSpriteRenderSystem extends DeferredEntityProcessingSystem { + + private CameraSystem cameraSystem; + + protected ComponentMapper mSpriteAsset; + protected ComponentMapper mPos; + protected ComponentMapper mAngle; + protected ComponentMapper mOrigin; + protected ComponentMapper mSize; + + private static final Origin DEFAULT_ORIGIN = new Origin(); + private static final Size DEFAULT_SIZE = new Size(0,0,0); + private SpriteBatch batch = new SpriteBatch(); + private Angle angle = new Angle(0); + + public BasicSpriteRenderSystem(EntityProcessPrincipal principal) { + super(Aspect.all(Pos.class, SpriteAsset.class, Render.class).exclude(Invisible.class), principal); + } + + private TextureRegion region = new TextureRegion(); + + @Override + protected void process(int e) { + + Pos pos = mPos.get(e); + batch.setProjectionMatrix(cameraSystem.camera.combined); + batch.begin(); + Texture asset = mSpriteAsset.get(e).asset; + + final Angle angle = mAngle.getSafe(e, this.angle); + + region.setTexture(asset); + region.setRegion(0,0,32,32); + + final Origin origin = mOrigin.getSafe(e, DEFAULT_ORIGIN); + final Size size = mSize.getSafe(e, DEFAULT_SIZE); + + float ox = size.getX() * origin.getX(); + float oy = size.getY() * origin.getY(); + + batch.draw( + region, + pos.xy.x - (size.getX() - ox), + pos.xy.y - (size.getY() - oy), + ox, + oy, + size.getX(), + size.getY(), + 1f,1f, + angle.rotation); + + batch.end(); + } + +} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/LabelRenderSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/LabelRenderSystem.java index 1d5dbde..39ae8f6 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/LabelRenderSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/LabelRenderSystem.java @@ -11,7 +11,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.graphics.Invisible; -import net.mostlyoriginal.api.component.graphics.Renderable; +import net.mostlyoriginal.api.component.graphics.Render; import net.mostlyoriginal.api.component.graphics.Tint; import net.mostlyoriginal.api.component.ui.BitmapFontAsset; import net.mostlyoriginal.api.component.ui.Label; @@ -40,7 +40,7 @@ public class LabelRenderSystem extends DeferredEntityProcessingSystem { private GlyphLayout glyphLayout = new GlyphLayout(); public LabelRenderSystem(EntityProcessPrincipal principal) { - super(Aspect.all(Pos.class, Label.class, Renderable.class, BitmapFontAsset.class).exclude(Invisible.class), principal); + super(Aspect.all(Pos.class, Label.class, Render.class, BitmapFontAsset.class).exclude(Invisible.class), principal); batch = new SpriteBatch(1000); } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/MapRenderSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/MapRenderSystem.java deleted file mode 100644 index 80d83ab..0000000 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/render/MapRenderSystem.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.mostlyoriginal.api.system.render; - -import com.artemis.BaseSystem; -import com.artemis.annotations.Wire; -import com.badlogic.gdx.maps.MapLayer; -import com.badlogic.gdx.maps.tiled.TiledMap; -import com.badlogic.gdx.maps.tiled.TiledMapTileLayer; -import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; -import net.mostlyoriginal.api.system.camera.CameraSystem; -import net.mostlyoriginal.api.system.map.TiledMapSystem; - -/** - * Renders tiled map with libgdx.7 - * - * @author Daan van Yperen - */ -@Wire -public class MapRenderSystem extends BaseSystem { - - public final String layer = "infront"; - private TiledMapSystem mapSystem; - private CameraSystem cameraSystem; - - public IndividualLayerRenderer renderer; - - - @Override - protected void initialize() { - renderer = new IndividualLayerRenderer(mapSystem.map); - } - - @Override - protected void processSystem() { - renderer.setView(cameraSystem.camera); - for (MapLayer layer : mapSystem.map.getLayers()) { - if (layer.isVisible()) { - renderer.renderLayer((TiledMapTileLayer) layer); - } - } - } - - /** - * Helper for rendering individual map layers. - */ - public static class IndividualLayerRenderer extends OrthogonalTiledMapRenderer { - public IndividualLayerRenderer(TiledMap map) { - super(map); - } - - public void renderLayer(TiledMapTileLayer layer) { - batch.setColor(1f, 1f, 1f, 1f); - beginRender(); - super.renderTileLayer(layer); - endRender(); - } - } - -} diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/script/EntitySpawnerSystem.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/script/EntitySpawnerSystem.java index dbd76d5..5a9c735 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/system/script/EntitySpawnerSystem.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/system/script/EntitySpawnerSystem.java @@ -5,6 +5,7 @@ import com.artemis.Entity; import com.artemis.annotations.Wire; import com.artemis.systems.EntityProcessingSystem; +import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.maps.MapProperties; import com.badlogic.gdx.math.MathUtils; import net.mostlyoriginal.api.component.basic.Bounds; @@ -20,7 +21,7 @@ * @see net.mostlyoriginal.api.component.script.EntitySpawner */ @Wire -public class EntitySpawnerSystem extends EntityProcessingSystem { +public class EntitySpawnerSystem extends IteratingSystem { public static final MapProperties EMPTY_MAP_PROPERTIES = new MapProperties(); private ComponentMapper sm; @@ -35,7 +36,7 @@ public EntitySpawnerSystem() { } @Override - protected void process(Entity e) { + protected void process(int e) { final EntitySpawner spawner = sm.get(e); diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityEditor.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityEditor.java index 7628e88..50a4e8a 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityEditor.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityEditor.java @@ -9,7 +9,7 @@ import net.mostlyoriginal.api.component.basic.Pos; import net.mostlyoriginal.api.component.basic.Scale; import net.mostlyoriginal.api.component.graphics.Anim; -import net.mostlyoriginal.api.component.graphics.Renderable; +import net.mostlyoriginal.api.component.graphics.Render; import net.mostlyoriginal.api.component.graphics.Tint; import net.mostlyoriginal.api.component.physics.Physics; import net.mostlyoriginal.api.component.ui.Font; @@ -76,8 +76,8 @@ protected final T add(Class componentType) { @SuppressWarnings("unchecked") public final T renderable(int layer) { - final Renderable renderable = add(Renderable.class); - renderable.layer = layer; + final Render render = add(Render.class); + render.layer = layer; return (T) this; } diff --git a/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityUtil.java b/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityUtil.java index 3d364b8..40107bf 100644 --- a/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityUtil.java +++ b/contrib-jam/src/main/java/net/mostlyoriginal/api/utils/EntityUtil.java @@ -27,7 +27,7 @@ public static float angle( final Entity a, final Entity b) final Pos pb = (Pos)b.getComponent(Pos.class); return tmp.set(pb.xy.x, pb.xy.y).sub(pa.xy.x, pa.xy.y).angle(); - } + } public static float distance( final Entity a, final Entity b) { diff --git a/contrib-jam/src/test/java/net/mostlyoriginal/api/operation/JamOperationFactoryTest.java b/contrib-jam/src/test/java/net/mostlyoriginal/api/operation/JamOperationFactoryTest.java index d23daa6..739e6eb 100644 --- a/contrib-jam/src/test/java/net/mostlyoriginal/api/operation/JamOperationFactoryTest.java +++ b/contrib-jam/src/test/java/net/mostlyoriginal/api/operation/JamOperationFactoryTest.java @@ -3,6 +3,7 @@ import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Vector2; import net.mostlyoriginal.api.component.basic.Pos; +import net.mostlyoriginal.api.component.graphics.Tint; import net.mostlyoriginal.api.utils.Duration; import org.junit.Assert; import org.junit.Test; @@ -12,6 +13,9 @@ */ public class JamOperationFactoryTest { + public static final Tint START_TINT = new Tint(1f, 1f, 1f, 1f); + public static final Tint END_TINT = new Tint(0f, 0f, 0f, 0f); + @Test public void valid_tweenPos_xy_setup_properly() { TweenPosOperation tweenPos = JamOperationFactory.moveBetween(0, 1, 2, 3, Duration.seconds(1)); @@ -19,9 +23,9 @@ public void valid_tweenPos_xy_setup_properly() { } @Test - public void valid_tweenPos_pos_setup_properly() { - TweenPosOperation tweenPos = JamOperationFactory.moveBetween(new Pos(0, 1), new Pos(2, 3), Duration.seconds(1)); - assertTweenPosProperlySet(tweenPos); + public void valid_tweenTint_tint_setup_properly() { + TweenTintOperation t = JamOperationFactory.tintBetween(START_TINT, END_TINT, Duration.seconds(1)); + assertTweenTintProperlySet(t); } @Test @@ -31,6 +35,12 @@ public void valid_tweenPos_vector2_setup_properly() { } + @Test + public void valid_tweenPos_pos_setup_properly() { + TweenPosOperation tweenPos = JamOperationFactory.moveBetween(new Pos(0, 1), new Pos(2, 3), Duration.seconds(1)); + assertTweenPosProperlySet(tweenPos); + } + @Test public void valid_tweenPos_xy_custom_interpolate_setup_properly() { TweenPosOperation tweenPos = JamOperationFactory.moveBetween(0, 1, 2, 3, Duration.seconds(1), Interpolation.bounce); @@ -56,6 +66,11 @@ protected void assertTweenPosProperlySet(TweenPosOperation tweenPos) { Assert.assertEquals(3f, tweenPos.getTo().xy.y, 0.001f); } + protected void assertTweenTintProperlySet(TweenTintOperation tweenPos) { + Assert.assertEquals(0f, tweenPos.getFrom().color.a, START_TINT.color.a); + Assert.assertEquals(0f, tweenPos.getTo().color.a, END_TINT.color.a); + } + @Test public void valid_moveTo_xy_setup_properly() { assertValidPos(JamOperationFactory.moveTo(0,1)); @@ -76,4 +91,15 @@ protected void assertValidPos(SetPosOperation pos) { Assert.assertEquals(1f, pos.get().xy.y, 0.001f); } + + @Test + public void valid_tintTo_setup_properly() { + assertValidTint(JamOperationFactory.tintTo(START_TINT)); + } + + private void assertValidTint(SetTintOperation o) { + Assert.assertEquals(0f, o.get().color.a, START_TINT.color.a); + } + + } \ No newline at end of file diff --git a/contrib-network/pom.xml b/contrib-network/pom.xml index 0b87f68..af00b6e 100644 --- a/contrib-network/pom.xml +++ b/contrib-network/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-network jar diff --git a/contrib-network/src/main/java/net/mostlyoriginal/api/network/marshal/kryonet/KryonetServerMarshalStrategy.java b/contrib-network/src/main/java/net/mostlyoriginal/api/network/marshal/kryonet/KryonetServerMarshalStrategy.java index bb41000..3d3ce80 100644 --- a/contrib-network/src/main/java/net/mostlyoriginal/api/network/marshal/kryonet/KryonetServerMarshalStrategy.java +++ b/contrib-network/src/main/java/net/mostlyoriginal/api/network/marshal/kryonet/KryonetServerMarshalStrategy.java @@ -50,4 +50,12 @@ protected void connectEndpoint() { public void sendToAll(Object o) { ((Server)endpoint).sendToAllTCP(o); } + + public void sendToAllExcept(int connectionId, Object o) { + ((Server)endpoint).sendToAllExceptTCP(connectionId, o); + } + + public void sendTo(int connectionId, Object o) { + ((Server)endpoint).sendToTCP(connectionId, o); + } } diff --git a/contrib-plugin-operations/pom.xml b/contrib-plugin-operations/pom.xml index c1ce55c..4636db1 100644 --- a/contrib-plugin-operations/pom.xml +++ b/contrib-plugin-operations/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-plugin-operations diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/component/Schedule.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/component/Schedule.java index c9c591b..ca6f212 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/component/Schedule.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/component/Schedule.java @@ -1,6 +1,7 @@ package net.mostlyoriginal.api.component; import com.artemis.PooledComponent; +import com.artemis.annotations.Fluid; import net.mostlyoriginal.api.operation.common.Operation; import net.mostlyoriginal.api.operation.flow.ParallelOperation; import net.mostlyoriginal.api.system.SchedulerSystem; @@ -11,6 +12,7 @@ * @author Daan van Yperen * @see SchedulerSystem */ +@Fluid(name = "script") public class Schedule extends PooledComponent { public ParallelOperation operation = new ParallelOperation(); @@ -27,4 +29,20 @@ protected void reset() { public Schedule(Operation operation) { this.operation.add(operation); } + + public void add(Operation operation) { + this.operation.add(operation); + } + public void set(Operation operation) { + this.operation.add(operation); + } + public void set(Operation operationA, Operation operationB) { + this.operation.add(operationA); + this.operation.add(operationB); + } + public void set(Operation operationA, Operation operationB, Operation operationC) { + this.operation.add(operationA); + this.operation.add(operationB); + this.operation.add(operationC); + } } diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/OperationFactory.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/OperationFactory.java index bb917b7..5150f79 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/OperationFactory.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/OperationFactory.java @@ -5,10 +5,7 @@ import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.utils.reflect.ClassReflection; import net.mostlyoriginal.api.component.common.Tweenable; -import net.mostlyoriginal.api.operation.basic.DeleteFromWorldOperation; -import net.mostlyoriginal.api.operation.basic.LegacyAddOperation; -import net.mostlyoriginal.api.operation.basic.RemoveOperation; -import net.mostlyoriginal.api.operation.basic.UnpooledMirrorOperation; +import net.mostlyoriginal.api.operation.basic.*; import net.mostlyoriginal.api.operation.common.Operation; import net.mostlyoriginal.api.operation.flow.ParallelOperation; import net.mostlyoriginal.api.operation.flow.RepeatOperation; @@ -206,22 +203,37 @@ public static DelayOperation delay( float delay ) /** * Add component instance to entity. * - * Not compatible with pooled components. Do not use this if you want to avoid GC! + * Does not support pooled components. Use {@see #create} or + * extend {@see SetOperation} instead. * * @see UnpooledMirrorOperation for a poolable solution. * @param component - * @return {@see LegacyAddOperation} + * @return {@see AddOperation} */ - @Deprecated - public static LegacyAddOperation add(Component component) + public static AddOperation add(Component component) { Preconditions.checkNotNull(component); - Preconditions.checkArgument(!ClassReflection.isAssignableFrom(PooledComponent.class, component.getClass()), "Does not support Pooled components."); - final LegacyAddOperation operation = Operation.prepare(LegacyAddOperation.class); + Preconditions.checkArgument(!ClassReflection.isAssignableFrom(PooledComponent.class, component.getClass()), "Does not support Pooled components. Use CreateOperation or extend AddOperation."); + final AddOperation operation = Operation.prepare(AddOperation.class); operation.component = component; return operation; } + /** + * Add class to entity. + * + * @param componentClass component to add. + * @return {@see CreateOperation} + * @see AddOperation extend for pooled solutions. + */ + public static CreateOperation add(Class componentClass) + { + Preconditions.checkNotNull(componentClass); + final CreateOperation operation = Operation.prepare(CreateOperation.class); + operation.componentClass = componentClass; + return operation; + } + /** * Remove class from entity. * diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/LegacyAddOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/AddOperation.java similarity index 72% rename from contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/LegacyAddOperation.java rename to contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/AddOperation.java index 35adb60..0544766 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/LegacyAddOperation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/AddOperation.java @@ -8,17 +8,18 @@ /** * Add component to entity. * - * Not compatible with pooled components. - * Do not use this if you want to avoid GC! + * Does not support pooled components. Use {@see CreateOperation} or + * {@see SetOperation} instead. * * @author Daan van Yperen * @see Schedule */ -@Deprecated -public class LegacyAddOperation extends BasicOperation { +public class AddOperation extends BasicOperation { + // not managed. public Component component; - public LegacyAddOperation() {} + + public AddOperation() {} @Override public void process(Entity e) { diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/CreateOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/CreateOperation.java new file mode 100644 index 0000000..912f1a0 --- /dev/null +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/CreateOperation.java @@ -0,0 +1,31 @@ +package net.mostlyoriginal.api.operation.basic; + +import com.artemis.Component; +import com.artemis.Entity; +import net.mostlyoriginal.api.component.Schedule; +import net.mostlyoriginal.api.operation.common.BasicOperation; + +/** + * Create component in entity. + * + * @author Daan van Yperen + * @see Schedule + */ +public class CreateOperation extends BasicOperation { + + public Class componentClass; + + public CreateOperation() { + } + + @Override + public void process(Entity e) { + e.edit().create(componentClass); + } + + @Override + public void reset() { + super.reset(); + componentClass = null; + } +} diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/SetOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/SetOperation.java index b6bc9d0..3aa1f74 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/SetOperation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/basic/SetOperation.java @@ -13,7 +13,7 @@ *

* Creates component if missing. Calls {@see Mirrorable#set} on target component. *

- * State is owned by this class, safe from garbage collection. + * Fully pooled; state container is preserved when returned to pool. * * @author Daan van Yperen */ diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/common/Operation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/common/Operation.java index b73c193..b4d9a1c 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/common/Operation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/common/Operation.java @@ -1,6 +1,7 @@ package net.mostlyoriginal.api.operation.common; import com.artemis.Entity; +import com.artemis.World; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.Pools; import net.mostlyoriginal.api.component.Schedule; @@ -80,4 +81,29 @@ public final void setPool(Pool pool) { public void setCompleted(boolean completed) { this.completed = completed; } + + /** + * Add operation to empty entity in world. + * @param world + */ + public void on(World world) { + world.createEntity().edit().create(Schedule.class).add(this); + } + + /** + * Add operation to entity. + * @param e Apply script to passed entity. + * @see net.mostlyoriginal.api.operation.flow.ParallelOperation + * @see net.mostlyoriginal.api.operation.flow.SequenceOperation + */ + public void on(Entity e) { + e.edit().create(Schedule.class).add(this); + } + + /** + * Add operation to entity by id. + */ + public void on(World w, int entityId) { + on(w.getEntity(entityId)); + } } diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/ParallelOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/ParallelOperation.java index dcd3d65..f462206 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/ParallelOperation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/ParallelOperation.java @@ -17,13 +17,11 @@ public boolean process(float delta, Entity e) { boolean operationsRemain = false; for (int i = 0; i < operations.size; i++) { - + if (!e.isActive()) break; final Operation operation = operations.get(i); if (!operation.process(delta, e)) { operationsRemain = true; } - - if (!e.isActive()) break; } completed = !operationsRemain; diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/RepeatOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/RepeatOperation.java index 1d08a2c..9de0218 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/RepeatOperation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/RepeatOperation.java @@ -40,7 +40,7 @@ public void setup( Operation operation ) @Override public boolean process(float delta, Entity e) { - if (!completed) { + if (!completed && e.isActive()) { if ( operation.process(delta,e) ) { completed = (desiredRepetitions != UNLIMITED) && (++repetition >= desiredRepetitions); if ( !completed ) { diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/SequenceOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/SequenceOperation.java index 67e8514..475a19e 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/SequenceOperation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/flow/SequenceOperation.java @@ -34,7 +34,7 @@ public boolean process(float delta, Entity e) { protected void nextOperation(float delta, Entity e, Operation operation) { Preconditions.checkArgument(!operation.isCompleted(), "Operation should never be completed before the first process."); - if (operation.process(delta, e)) { + if ( e.isActive() && operation.process(delta, e)) { index++; } } diff --git a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/temporal/TweenOperation.java b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/temporal/TweenOperation.java index 29f4255..625766e 100644 --- a/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/temporal/TweenOperation.java +++ b/contrib-plugin-operations/src/main/java/net/mostlyoriginal/api/operation/temporal/TweenOperation.java @@ -60,6 +60,12 @@ public TweenOperation setup(Interpolation interpolation, float duration) { return this; } + @Override + public void reset() { + super.reset(); + m = null; // might be after world reset. + } + @SuppressWarnings("unchecked") public final T getFrom() { return (T) a; diff --git a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/OperationIntegrationTest.java b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/OperationIntegrationTest.java index 552be12..ac93392 100644 --- a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/OperationIntegrationTest.java +++ b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/OperationIntegrationTest.java @@ -1,7 +1,7 @@ package net.mostlyoriginal.api.operation; import com.artemis.Component; -import net.mostlyoriginal.api.operation.basic.LegacyAddOperation; +import net.mostlyoriginal.api.operation.basic.AddOperation; import net.mostlyoriginal.api.operation.common.Operation; import net.mostlyoriginal.api.operation.common.TestOperation; import net.mostlyoriginal.api.operation.flow.OperationTest; @@ -29,15 +29,15 @@ public void ensure_operations_chain_released() { DelayOperation delayOperation = delay(1); Operation deleteFromWorldOperation = deleteFromWorld(); - LegacyAddOperation legacyAddOperation = add(new TestComponent()); + AddOperation addOperation = add(new TestComponent()); - SequenceOperation sequenceOperation = sequence(delayOperation, deleteFromWorldOperation, legacyAddOperation); + SequenceOperation sequenceOperation = sequence(delayOperation, deleteFromWorldOperation, addOperation); ParallelOperation parallelOperation = parallel(sequenceOperation); // set all completed as an easy test to see if reset. delayOperation.setCompleted(true); deleteFromWorldOperation.setCompleted(true); - legacyAddOperation.setCompleted(true); + addOperation.setCompleted(true); sequenceOperation.setCompleted(true); parallelOperation.setCompleted(true); @@ -45,7 +45,7 @@ public void ensure_operations_chain_released() { Assert.assertFalse(delayOperation.isCompleted()); Assert.assertFalse(deleteFromWorldOperation.isCompleted()); - Assert.assertFalse(legacyAddOperation.isCompleted()); + Assert.assertFalse(addOperation.isCompleted()); Assert.assertFalse(sequenceOperation.isCompleted()); Assert.assertFalse(parallelOperation.isCompleted()); } diff --git a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent.java b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent.java index 12a2688..ee0a757 100644 --- a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent.java +++ b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent.java @@ -19,8 +19,7 @@ public TweenableTestComponent(float val) { } @Override - public TweenableTestComponent tween(TweenableTestComponent a, TweenableTestComponent b, float value) { + public void tween(TweenableTestComponent a, TweenableTestComponent b, float value) { this.val = Interpolation.linear.apply(a.val, b.val, value); - return this; } } diff --git a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent2.java b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent2.java index 2b082b6..e44e5fb 100644 --- a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent2.java +++ b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/TweenableTestComponent2.java @@ -16,8 +16,7 @@ public TweenableTestComponent2(float val) { } @Override - public TweenableTestComponent2 tween(TweenableTestComponent2 a, TweenableTestComponent2 b, float value) { + public void tween(TweenableTestComponent2 a, TweenableTestComponent2 b, float value) { this.val = Interpolation.linear.apply(a.val, b.val, value); - return this; } } diff --git a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/basic/MirrorableTestComponent.java b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/basic/MirrorableTestComponent.java index 39a294d..663e9e6 100644 --- a/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/basic/MirrorableTestComponent.java +++ b/contrib-plugin-operations/src/test/java/net/mostlyoriginal/api/operation/basic/MirrorableTestComponent.java @@ -18,8 +18,7 @@ public MirrorableTestComponent(int val) { } @Override - public MirrorableTestComponent set(MirrorableTestComponent monkey) { + public void set(MirrorableTestComponent monkey) { this.val = monkey.val; - return this; } } diff --git a/contrib-plugin-profiler/pom.xml b/contrib-plugin-profiler/pom.xml index 148f616..4df8fbd 100644 --- a/contrib-plugin-profiler/pom.xml +++ b/contrib-plugin-profiler/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-plugin-profiler diff --git a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/ProfilerPlugin.java b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/ProfilerPlugin.java index 5f0af0a..495d61a 100644 --- a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/ProfilerPlugin.java +++ b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/ProfilerPlugin.java @@ -13,7 +13,7 @@ * * Does not require {@see @com.artemis.annotations.Profile} on systems. * - * Open/Close with F3. + * Open/Close with P by default. * * @author piotr-j (Plugin) * @author Daan van Yperen (Integration) diff --git a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerInvocationStrategy.java b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerInvocationStrategy.java index b40378d..6daf1df 100644 --- a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerInvocationStrategy.java +++ b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerInvocationStrategy.java @@ -8,7 +8,7 @@ /** * {@link SystemInvocationStrategy} that will create a profiler for all systems that don't already have one * Can be used in addition to or instead of {@link com.artemis.annotations.Profile} annotation - * + *

* In addition creates {@link SystemProfiler} with name "Frame" for total frame time * It can be accessed with {@link SystemProfiler#get(String)} * @@ -16,63 +16,66 @@ * @author Daan van Yperen */ public class ProfilerInvocationStrategy extends SystemInvocationStrategy { - private boolean initialized = false; + private boolean initialized = false; + + protected SystemProfiler frameProfiler; + protected SystemProfiler[] profilers; + + @Override + protected void process() { - protected SystemProfiler frameProfiler; - protected SystemProfiler[] profilers; + if (!initialized) { + initialize(); + initialized = true; + } - @Override - protected void process () { + frameProfiler.start(); + processProfileSystems(systems); + frameProfiler.stop(); + } - if ( !initialized ) - { - initialize(); - initialized = true; - } + private void processProfileSystems(Bag systems) { + final Object[] systemsData = systems.getData(); + for (int i = 0, s = systems.size(); s > i; i++) { + if (disabled.get(i)) + continue; - frameProfiler.start(); - processProfileSystems(systems); - frameProfiler.stop(); - } + updateEntityStates(); + processProfileSystem(profilers[i], (BaseSystem) systemsData[i]); + } - private void processProfileSystems(Bag systems) { - final Object[] systemsData = systems.getData(); - for (int i = 0; i < systems.size(); i++) { - final BaseSystem system = (BaseSystem)systemsData[i]; - processProfileSystem(profilers[i], system); - updateEntityStates(); - } - } + updateEntityStates(); + } - private void processProfileSystem(SystemProfiler profiler, BaseSystem system) { - if (profiler != null) profiler.start(); - system.process(); - if (profiler != null) profiler.stop(); - } + private void processProfileSystem(SystemProfiler profiler, BaseSystem system) { + if (profiler != null) profiler.start(); + system.process(); + if (profiler != null) profiler.stop(); + } - protected void initialize() { - createFrameProfiler(); - createSystemProfilers(); - } + protected void initialize() { + createFrameProfiler(); + createSystemProfilers(); + } - private void createSystemProfilers() { - final ImmutableBag systems = world.getSystems(); - profilers = new SystemProfiler[systems.size()]; - for (int i = 0; i < systems.size(); i++) { - profilers[i] = createSystemProfiler(systems.get(i)); - } - } + private void createSystemProfilers() { + final ImmutableBag systems = world.getSystems(); + profilers = new SystemProfiler[systems.size()]; + for (int i = 0; i < systems.size(); i++) { + profilers[i] = createSystemProfiler(systems.get(i)); + } + } - private SystemProfiler createSystemProfiler(BaseSystem system) { - SystemProfiler old = SystemProfiler.getFor(system); - if (old == null) { - old = SystemProfiler.createFor(system, world); - } - return old; - } + private SystemProfiler createSystemProfiler(BaseSystem system) { + SystemProfiler old = SystemProfiler.getFor(system); + if (old == null) { + old = SystemProfiler.createFor(system, world); + } + return old; + } - private void createFrameProfiler() { - frameProfiler = SystemProfiler.create("Frame"); - frameProfiler.setColor(1, 1, 1, 1); - } + private void createFrameProfiler() { + frameProfiler = SystemProfiler.create("Frame"); + frameProfiler.setColor(1, 1, 1, 1); + } } diff --git a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerSystem.java b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerSystem.java index fc24958..a1ce075 100644 --- a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerSystem.java +++ b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/ProfilerSystem.java @@ -21,13 +21,15 @@ @Wire public class ProfilerSystem extends BaseSystem { - public static final int TOGGLE_PROFILER_KEY = Input.Keys.P; + public static final int DEFAULT_PROFILER_KEY = Input.Keys.P; OrthographicCamera camera; ShapeRenderer renderer; Stage stage; Skin skin; + private int key = DEFAULT_PROFILER_KEY; + SystemProfilerGUI gui; private boolean f3ButtonDown; @@ -78,7 +80,7 @@ private void render() { } private void checkActivationButton() { - if ( Gdx.input.isKeyPressed(TOGGLE_PROFILER_KEY) ) { + if ( Gdx.input.isKeyPressed(key) ) { if ( !f3ButtonDown ) { if (!SystemProfiler.isRunning()) { gui.setHeight(Gdx.graphics.getHeight()/2); @@ -113,4 +115,12 @@ private void processInput() { protected void dispose() { SystemProfiler.dispose(); } + + public int getKey() { + return key; + } + + public void setKey(int key) { + this.key = key; + } } diff --git a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/SystemProfilerGUI.java b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/SystemProfilerGUI.java index 4829f02..157d0d9 100644 --- a/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/SystemProfilerGUI.java +++ b/contrib-plugin-profiler/src/main/java/net/mostlyoriginal/plugin/profiler/SystemProfilerGUI.java @@ -287,7 +287,7 @@ public ProfilerRow(SystemProfiler profiler, Skin skin) { public void init (final SystemProfiler profiler) { this.profiler = profiler; - draw.removeListener(listener); + if ( listener != null ) draw.removeListener(listener); draw.setChecked(profiler.getDrawGraph()); draw.addListener(listener = new ChangeListener() { @Override public void changed (ChangeEvent event, Actor actor) { diff --git a/contrib-test-gwt/pom.xml b/contrib-test-gwt/pom.xml index 002fe0d..a3c1b5e 100644 --- a/contrib-test-gwt/pom.xml +++ b/contrib-test-gwt/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 contrib-test-gwt war diff --git a/pom.xml b/pom.xml index e2798b7..9dbad38 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ net.mostlyoriginal.artemis-odb contrib-parent - 1.2.1 + 2.1.0 pom contrib-parent Drop-in extensions for artemis-odb. Prefab systems, components, networking, events! @@ -16,7 +16,7 @@ UTF-8 4.1 [2.0.0,3.0.0) - [1.9.0,2.0.0) + [1.9.0,1.9.4]