diff --git a/src/com/uwsoft/editor/renderer/SceneLoader.java b/src/com/uwsoft/editor/renderer/SceneLoader.java index 4ba41cfc..fb51dc1b 100644 --- a/src/com/uwsoft/editor/renderer/SceneLoader.java +++ b/src/com/uwsoft/editor/renderer/SceneLoader.java @@ -1,11 +1,9 @@ package com.uwsoft.editor.renderer; -import box2dLight.RayHandler; - import com.badlogic.ashley.core.Component; -import com.badlogic.ashley.core.Engine; import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.EntityListener; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.ashley.utils.ImmutableArray; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.OrthographicCamera; @@ -20,20 +18,37 @@ import com.badlogic.gdx.utils.viewport.ScalingViewport; import com.badlogic.gdx.utils.viewport.Viewport; import com.uwsoft.editor.renderer.commons.IExternalItemType; -import com.uwsoft.editor.renderer.components.*; +import com.uwsoft.editor.renderer.components.MainItemComponent; +import com.uwsoft.editor.renderer.components.NodeComponent; +import com.uwsoft.editor.renderer.components.ParentNodeComponent; +import com.uwsoft.editor.renderer.components.ScriptComponent; import com.uwsoft.editor.renderer.components.light.LightObjectComponent; import com.uwsoft.editor.renderer.components.physics.PhysicsBodyComponent; -import com.uwsoft.editor.renderer.data.*; +import com.uwsoft.editor.renderer.data.CompositeItemVO; +import com.uwsoft.editor.renderer.data.CompositeVO; +import com.uwsoft.editor.renderer.data.ProjectInfoVO; +import com.uwsoft.editor.renderer.data.ResolutionEntryVO; +import com.uwsoft.editor.renderer.data.SceneVO; import com.uwsoft.editor.renderer.factory.EntityFactory; import com.uwsoft.editor.renderer.physics.PhysicsBodyLoader; import com.uwsoft.editor.renderer.resources.IResourceRetriever; import com.uwsoft.editor.renderer.resources.ResourceManager; import com.uwsoft.editor.renderer.scripts.IScript; -import com.uwsoft.editor.renderer.systems.*; +import com.uwsoft.editor.renderer.systems.ButtonSystem; +import com.uwsoft.editor.renderer.systems.CompositeSystem; +import com.uwsoft.editor.renderer.systems.LabelSystem; +import com.uwsoft.editor.renderer.systems.LayerSystem; +import com.uwsoft.editor.renderer.systems.LightSystem; +import com.uwsoft.editor.renderer.systems.ParticleSystem; +import com.uwsoft.editor.renderer.systems.PhysicsSystem; +import com.uwsoft.editor.renderer.systems.ScriptSystem; +import com.uwsoft.editor.renderer.systems.SpriteAnimationSystem; import com.uwsoft.editor.renderer.systems.action.ActionSystem; import com.uwsoft.editor.renderer.systems.render.Overlap2dRenderer; import com.uwsoft.editor.renderer.utils.ComponentRetriever; +import box2dLight.RayHandler; + /** * SceneLoader is important part of runtime that utilizes provided * IResourceRetriever (or creates default one shipped with runtime) in order to @@ -46,7 +61,7 @@ public class SceneLoader { private SceneVO sceneVO; private IResourceRetriever rm = null; - public Engine engine = null; + public PooledEngine engine = null; public RayHandler rayHandler; public World world; public Entity rootEntity; @@ -66,14 +81,14 @@ public SceneLoader(World world, RayHandler rayHandler) { this.rm = rm; - this.engine = new Engine(); + this.engine = new PooledEngine(); initSceneLoader(); } public SceneLoader(IResourceRetriever rm, World world, RayHandler rayHandler) { this.world = world; this.rayHandler = rayHandler; - this.engine = new Engine(); + this.engine = new PooledEngine(); this.rm = rm; initSceneLoader(); } @@ -109,7 +124,7 @@ private void initSceneLoader() { } addSystems(); - entityFactory = new EntityFactory(rayHandler, world, rm); + entityFactory = new EntityFactory(engine,rayHandler, world, rm); } public void setResolution(String resolutionName) { @@ -142,7 +157,7 @@ public SceneVO loadScene(String sceneName, Viewport viewport, boolean customLigh engine.addEntity(rootEntity); if(sceneVO.composite != null) { - entityFactory.initAllChildren(engine, rootEntity, sceneVO.composite); + entityFactory.initAllChildren(rootEntity, sceneVO.composite); } if (!customLight) { setAmbienceInfo(sceneVO); @@ -328,7 +343,7 @@ public IResourceRetriever getRm() { return rm; } - public Engine getEngine() { + public PooledEngine getEngine() { return engine; } diff --git a/src/com/uwsoft/editor/renderer/components/ActionComponent.java b/src/com/uwsoft/editor/renderer/components/ActionComponent.java index 6bc6f9e1..7a9fb095 100644 --- a/src/com/uwsoft/editor/renderer/components/ActionComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ActionComponent.java @@ -2,11 +2,17 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.systems.action.data.ActionData; /** * Created by ZeppLondon on 10/13/2015. */ -public class ActionComponent implements Component { +public class ActionComponent implements Component,Pool.Poolable { public Array dataArray = new Array(true, 0); + + @Override + public void reset() { + dataArray.clear(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/CompositeTransformComponent.java b/src/com/uwsoft/editor/renderer/components/CompositeTransformComponent.java index 19cb9ef9..5df5e6bd 100644 --- a/src/com/uwsoft/editor/renderer/components/CompositeTransformComponent.java +++ b/src/com/uwsoft/editor/renderer/components/CompositeTransformComponent.java @@ -3,11 +3,21 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.math.Affine2; import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.utils.Pool; -public class CompositeTransformComponent implements Component { +public class CompositeTransformComponent implements Component,Pool.Poolable { public boolean automaticResize = false; public boolean transform = false; public final Affine2 worldTransform = new Affine2(); public final Matrix4 computedTransform = new Matrix4(); public final Matrix4 oldTransform = new Matrix4(); + + @Override + public void reset() { + automaticResize = false; + transform = false; + worldTransform.idt(); + computedTransform.idt(); + oldTransform.idt(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/DimensionsComponent.java b/src/com/uwsoft/editor/renderer/components/DimensionsComponent.java index edcf9bd6..fbe9788f 100644 --- a/src/com/uwsoft/editor/renderer/components/DimensionsComponent.java +++ b/src/com/uwsoft/editor/renderer/components/DimensionsComponent.java @@ -7,10 +7,11 @@ import com.badlogic.gdx.math.Polygon; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.data.ShapeVO; import com.uwsoft.editor.renderer.utils.PolygonUtils; -public class DimensionsComponent implements Component { +public class DimensionsComponent implements Component,Pool.Poolable { public float width = 0; public float height = 0; @@ -59,4 +60,12 @@ public void setFromShape(ShapeVO shape) { height = maxPoint.y - minPoint.y; } } + + @Override + public void reset() { + width=0; + height=0; + boundBox=null; + polygon=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/LayerMapComponent.java b/src/com/uwsoft/editor/renderer/components/LayerMapComponent.java index 6c328622..fa2674d6 100644 --- a/src/com/uwsoft/editor/renderer/components/LayerMapComponent.java +++ b/src/com/uwsoft/editor/renderer/components/LayerMapComponent.java @@ -5,9 +5,11 @@ import java.util.HashMap; import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.data.LayerItemVO; -public class LayerMapComponent implements Component { +public class LayerMapComponent implements Component,Pool.Poolable { + public boolean autoIndexing = true; private ArrayList layers = new ArrayList(); @@ -73,4 +75,11 @@ public void swap(String source, String target) { LayerItemVO targetVO = getLayer(target); Collections.swap(layers, layers.indexOf(sourceVO), layers.indexOf(targetVO)); } + + @Override + public void reset() { + autoIndexing=true; + layerMap.clear(); + layers.clear(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/MainItemComponent.java b/src/com/uwsoft/editor/renderer/components/MainItemComponent.java index e6af4b7e..c2e1974a 100644 --- a/src/com/uwsoft/editor/renderer/components/MainItemComponent.java +++ b/src/com/uwsoft/editor/renderer/components/MainItemComponent.java @@ -2,11 +2,12 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Pool; import java.util.HashSet; import java.util.Set; -public class MainItemComponent implements Component { +public class MainItemComponent implements Component,Pool.Poolable { public int uniqueId = 0; public String itemIdentifier = ""; public String libraryLink = ""; @@ -14,4 +15,15 @@ public class MainItemComponent implements Component { public String customVars = ""; public int entityType; public boolean visible = true; + + @Override + public void reset() { + uniqueId = 0; + itemIdentifier = ""; + libraryLink = ""; + tags.clear(); + customVars = ""; + entityType=0; + visible = true; + } } diff --git a/src/com/uwsoft/editor/renderer/components/NinePatchComponent.java b/src/com/uwsoft/editor/renderer/components/NinePatchComponent.java index 64757254..3ff6b521 100644 --- a/src/com/uwsoft/editor/renderer/components/NinePatchComponent.java +++ b/src/com/uwsoft/editor/renderer/components/NinePatchComponent.java @@ -2,8 +2,15 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.graphics.g2d.NinePatch; +import com.badlogic.gdx.utils.Pool; -public class NinePatchComponent implements Component { +public class NinePatchComponent implements Component,Pool.Poolable { public String textureRegionName; public NinePatch ninePatch; + + @Override + public void reset() { + textureRegionName=null; + ninePatch=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/NodeComponent.java b/src/com/uwsoft/editor/renderer/components/NodeComponent.java index 023c1820..60e69046 100644 --- a/src/com/uwsoft/editor/renderer/components/NodeComponent.java +++ b/src/com/uwsoft/editor/renderer/components/NodeComponent.java @@ -2,9 +2,11 @@ import com.badlogic.ashley.core.Component; import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.SnapshotArray; -public class NodeComponent implements Component { +public class NodeComponent implements Component,Pool.Poolable { + public SnapshotArray children = new SnapshotArray(true, 1, Entity.class); public void removeChild(Entity entity) { @@ -14,4 +16,9 @@ public void removeChild(Entity entity) { public void addChild(Entity entity) { children.add(entity); } + + @Override + public void reset() { + children.clear(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/ParentNodeComponent.java b/src/com/uwsoft/editor/renderer/components/ParentNodeComponent.java index d28e4a39..1fe34517 100644 --- a/src/com/uwsoft/editor/renderer/components/ParentNodeComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ParentNodeComponent.java @@ -2,7 +2,13 @@ import com.badlogic.ashley.core.Component; import com.badlogic.ashley.core.Entity; +import com.badlogic.gdx.utils.Pool; -public class ParentNodeComponent implements Component { +public class ParentNodeComponent implements Component,Pool.Poolable { public Entity parentEntity = null; + + @Override + public void reset() { + parentEntity=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/PolygonComponent.java b/src/com/uwsoft/editor/renderer/components/PolygonComponent.java index 732682dd..8c1d493a 100644 --- a/src/com/uwsoft/editor/renderer/components/PolygonComponent.java +++ b/src/com/uwsoft/editor/renderer/components/PolygonComponent.java @@ -20,11 +20,12 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Pool; /** * Created by azakhary on 7/2/2015. */ -public class PolygonComponent implements Component { +public class PolygonComponent implements Component,Pool.Poolable { public Vector2[][] vertices; public void makeRectangle(float width, float height) { @@ -49,4 +50,9 @@ public void makeRectangle(float x, float y, float width, float height) // Overlo vertices = new Vector2[1][4]; vertices[0] = points; } + + @Override + public void reset() { + vertices=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/ScissorComponent.java b/src/com/uwsoft/editor/renderer/components/ScissorComponent.java index b8579462..ef260f70 100644 --- a/src/com/uwsoft/editor/renderer/components/ScissorComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ScissorComponent.java @@ -1,10 +1,20 @@ package com.uwsoft.editor.renderer.components; import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.utils.Pool; -public class ScissorComponent implements Component { +public class ScissorComponent implements Component,Pool.Poolable { public float scissorX; public float scissorY; public float scissorWidth; public float scissorHeight; + + + @Override + public void reset() { + scissorX=0f; + scissorY=0f; + scissorWidth=0f; + scissorHeight=0f; + } } diff --git a/src/com/uwsoft/editor/renderer/components/ScriptComponent.java b/src/com/uwsoft/editor/renderer/components/ScriptComponent.java index 94eafbf4..81123600 100644 --- a/src/com/uwsoft/editor/renderer/components/ScriptComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ScriptComponent.java @@ -2,6 +2,7 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.reflect.ClassReflection; import com.badlogic.gdx.utils.reflect.ReflectionException; import com.uwsoft.editor.renderer.scripts.IScript; @@ -11,7 +12,7 @@ /** * Created by azakhary on 6/19/2015. */ -public class ScriptComponent implements Component { +public class ScriptComponent implements Component,Pool.Poolable { public Array scripts = new Array(); @@ -37,4 +38,9 @@ public void removeScript(Class className) { } } } + + @Override + public void reset() { + scripts.clear(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/ShaderComponent.java b/src/com/uwsoft/editor/renderer/components/ShaderComponent.java index 71434c2c..4beffb4f 100644 --- a/src/com/uwsoft/editor/renderer/components/ShaderComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ShaderComponent.java @@ -2,8 +2,9 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.graphics.glutils.ShaderProgram; +import com.badlogic.gdx.utils.Pool; -public class ShaderComponent implements Component { +public class ShaderComponent implements Component,Pool.Poolable { public String shaderName; private ShaderProgram shaderProgram = null; @@ -20,4 +21,10 @@ public void clear() { shaderName = null; shaderProgram = null; } + + @Override + public void reset() { + shaderName=null; + shaderProgram=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/SpineDataComponent.java b/src/com/uwsoft/editor/renderer/components/SpineDataComponent.java index 3a9ccfa3..3df4df65 100644 --- a/src/com/uwsoft/editor/renderer/components/SpineDataComponent.java +++ b/src/com/uwsoft/editor/renderer/components/SpineDataComponent.java @@ -1,8 +1,15 @@ package com.uwsoft.editor.renderer.components; import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.utils.Pool; -public class SpineDataComponent implements Component { +public class SpineDataComponent implements Component,Pool.Poolable { public String animationName = ""; public String currentAnimationName = ""; + + @Override + public void reset() { + animationName=""; + currentAnimationName=""; + } } diff --git a/src/com/uwsoft/editor/renderer/components/TextureRegionComponent.java b/src/com/uwsoft/editor/renderer/components/TextureRegionComponent.java index 03326b06..708299e1 100644 --- a/src/com/uwsoft/editor/renderer/components/TextureRegionComponent.java +++ b/src/com/uwsoft/editor/renderer/components/TextureRegionComponent.java @@ -6,9 +6,10 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.EarClippingTriangulator; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.utils.PolygonUtils; -public class TextureRegionComponent implements Component { +public class TextureRegionComponent implements Component,Pool.Poolable { public String regionName = ""; public TextureRegion region = null; public boolean isRepeat = false; @@ -31,4 +32,13 @@ public void setPolygonSprite(PolygonComponent polygonComponent, float pixelToWor PolygonRegion polygonRegion = new PolygonRegion(region, vertices, triangles); polygonSprite = new PolygonSprite(polygonRegion); } + + @Override + public void reset() { + regionName=""; + region=null; + isRepeat=false; + isPolygon=false; + polygonSprite=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/TintComponent.java b/src/com/uwsoft/editor/renderer/components/TintComponent.java index db090ec9..cf337981 100644 --- a/src/com/uwsoft/editor/renderer/components/TintComponent.java +++ b/src/com/uwsoft/editor/renderer/components/TintComponent.java @@ -2,7 +2,13 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.utils.Pool; -public class TintComponent implements Component { +public class TintComponent implements Component,Pool.Poolable { public Color color = new Color(); + + @Override + public void reset() { + color.set(0f,0f,0f,0f); + } } diff --git a/src/com/uwsoft/editor/renderer/components/TransformComponent.java b/src/com/uwsoft/editor/renderer/components/TransformComponent.java index 075727f6..9866505f 100644 --- a/src/com/uwsoft/editor/renderer/components/TransformComponent.java +++ b/src/com/uwsoft/editor/renderer/components/TransformComponent.java @@ -1,8 +1,10 @@ package com.uwsoft.editor.renderer.components; import com.badlogic.ashley.core.Component; +import com.badlogic.ashley.core.PooledEngine; +import com.badlogic.gdx.utils.Pool; -public class TransformComponent implements Component { +public class TransformComponent implements Component,Pool.Poolable { public float x; public float y; public float scaleX = 1f; @@ -47,4 +49,17 @@ public void enableTransform() { originY = backup.originY; backup = null; } + + @Override + public void reset() { + x=0; + y=0; + scaleX = 1f; + scaleY = 1f; + rotation=0; + originX=0; + originY=0; + + backup = null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/ViewPortComponent.java b/src/com/uwsoft/editor/renderer/components/ViewPortComponent.java index 9bd8880c..a746b231 100644 --- a/src/com/uwsoft/editor/renderer/components/ViewPortComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ViewPortComponent.java @@ -1,8 +1,14 @@ package com.uwsoft.editor.renderer.components; import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.viewport.Viewport; -public class ViewPortComponent implements Component { +public class ViewPortComponent implements Component,Pool.Poolable { public Viewport viewPort; + + @Override + public void reset() { + viewPort=null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/ZIndexComponent.java b/src/com/uwsoft/editor/renderer/components/ZIndexComponent.java index 2d982b05..88972e3a 100644 --- a/src/com/uwsoft/editor/renderer/components/ZIndexComponent.java +++ b/src/com/uwsoft/editor/renderer/components/ZIndexComponent.java @@ -1,8 +1,9 @@ package com.uwsoft.editor.renderer.components; import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.utils.Pool; -public class ZIndexComponent implements Component { +public class ZIndexComponent implements Component,Pool.Poolable { private int zIndex = 0; public boolean needReOrder = false; public String layerName = ""; @@ -17,4 +18,12 @@ public void setZIndex(int zIndex) { needReOrder = true; } + @Override + public void reset() { + zIndex = 0; + needReOrder = false; + layerName = ""; + layerIndex=0; + + } } \ No newline at end of file diff --git a/src/com/uwsoft/editor/renderer/components/additional/ButtonComponent.java b/src/com/uwsoft/editor/renderer/components/additional/ButtonComponent.java index 9bed7874..9379053d 100644 --- a/src/com/uwsoft/editor/renderer/components/additional/ButtonComponent.java +++ b/src/com/uwsoft/editor/renderer/components/additional/ButtonComponent.java @@ -3,16 +3,23 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Pool; /** * Created by azakhary on 8/1/2015. */ -public class ButtonComponent implements Component { +public class ButtonComponent implements Component,Pool.Poolable { public boolean isTouched = false; private Array listeners = new Array(); + @Override + public void reset() { + isTouched=false; + listeners.clear(); + } + public interface ButtonListener { public void touchUp(); public void touchDown(); diff --git a/src/com/uwsoft/editor/renderer/components/label/LabelComponent.java b/src/com/uwsoft/editor/renderer/components/label/LabelComponent.java index 509b33e2..1d124510 100644 --- a/src/com/uwsoft/editor/renderer/components/label/LabelComponent.java +++ b/src/com/uwsoft/editor/renderer/components/label/LabelComponent.java @@ -7,9 +7,11 @@ import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.utils.Align; +import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.StringBuilder; -public class LabelComponent implements Component { +public class LabelComponent implements Component,Pool.Poolable { + public LabelStyle style; public final GlyphLayout layout = new GlyphLayout(); public BitmapFontCache cache; @@ -23,7 +25,8 @@ public class LabelComponent implements Component { public float fontScaleX = 1f; public float fontScaleY = 1f; - + public LabelComponent(){} + public LabelComponent (CharSequence text, Skin skin) { this(text, skin.get(LabelStyle.class)); } @@ -148,5 +151,20 @@ public float getFontScaleY () { public void setFontScaleY (float fontScaleY) { this.fontScaleY = fontScaleY; } - + + @Override + public void reset() { + style=null; + layout.reset(); + cache=null; + + text.delete(0,text.length()); + fontName=null; + fontSize=0; + labelAlign = Align.center; + lineAlign = Align.center; + wrap=false; + fontScaleX = 1f; + fontScaleY = 1f; + } } diff --git a/src/com/uwsoft/editor/renderer/components/light/LightObjectComponent.java b/src/com/uwsoft/editor/renderer/components/light/LightObjectComponent.java index 40b0ea8e..27027785 100644 --- a/src/com/uwsoft/editor/renderer/components/light/LightObjectComponent.java +++ b/src/com/uwsoft/editor/renderer/components/light/LightObjectComponent.java @@ -3,11 +3,13 @@ import box2dLight.Light; import com.badlogic.ashley.core.Component; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.data.LightVO.LightType; import com.uwsoft.editor.renderer.physics.PhysicsBodyLoader; -public class LightObjectComponent implements Component { - private LightType type; +public class LightObjectComponent implements Component,Pool.Poolable { + + public LightType type; public int rays = 12; public float distance = 300; @@ -22,7 +24,23 @@ public LightObjectComponent(LightType type) { this.type = type; } + public LightObjectComponent(){ + + } + public LightType getType(){ return type; } + + @Override + public void reset() { + rays = 12; + distance = 300; + directionDegree = 0; + coneDegree = 30; + softnessLength = 1f; + isStatic = true; + isXRay = true; + lightObject = null; + } } diff --git a/src/com/uwsoft/editor/renderer/components/particle/ParticleComponent.java b/src/com/uwsoft/editor/renderer/components/particle/ParticleComponent.java index 6162a42a..bebe51fb 100644 --- a/src/com/uwsoft/editor/renderer/components/particle/ParticleComponent.java +++ b/src/com/uwsoft/editor/renderer/components/particle/ParticleComponent.java @@ -2,8 +2,9 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.graphics.g2d.ParticleEffect; +import com.badlogic.gdx.utils.Pool; -public class ParticleComponent implements Component { +public class ParticleComponent implements Component,Pool.Poolable { public String particleName = ""; public ParticleEffect particleEffect; public float worldMultiplyer = 1f; @@ -23,4 +24,12 @@ public void startEffect(){ scaleEffect(scaleFactor); particleEffect.start(); } + + @Override + public void reset() { + particleName = ""; + particleEffect=null; + worldMultiplyer = 1f; + scaleFactor = 1f; + } } diff --git a/src/com/uwsoft/editor/renderer/components/physics/PhysicsBodyComponent.java b/src/com/uwsoft/editor/renderer/components/physics/PhysicsBodyComponent.java index f3a3a1a5..77bc63cd 100644 --- a/src/com/uwsoft/editor/renderer/components/physics/PhysicsBodyComponent.java +++ b/src/com/uwsoft/editor/renderer/components/physics/PhysicsBodyComponent.java @@ -4,8 +4,9 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.Filter; +import com.badlogic.gdx.utils.Pool; -public class PhysicsBodyComponent implements Component { +public class PhysicsBodyComponent implements Component,Pool.Poolable { public int bodyType; public float mass; @@ -46,4 +47,22 @@ public PhysicsBodyComponent() { restitution = 1; filter = new Filter(); } + + @Override + public void reset() { + bodyType = 0; + mass = 1; + centerOfMass = new Vector2(0, 0); + rotationalInertia = 0; + damping = 0; + gravityScale = 0; + allowSleep = true; + sensor = false; + awake = true; + bullet = false; + density = 1; + friction = 1; + restitution = 1; + filter = new Filter(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/sprite/AnimationComponent.java b/src/com/uwsoft/editor/renderer/components/sprite/AnimationComponent.java index ee664f3f..4ef3ff94 100644 --- a/src/com/uwsoft/editor/renderer/components/sprite/AnimationComponent.java +++ b/src/com/uwsoft/editor/renderer/components/sprite/AnimationComponent.java @@ -4,7 +4,13 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.utils.Pool; -public class AnimationComponent implements Component { +public class AnimationComponent implements Component,Pool.Poolable { public HashMap animations = new HashMap(); + + @Override + public void reset() { + animations.clear(); + } } diff --git a/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationComponent.java b/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationComponent.java index 605d927a..06316c8f 100644 --- a/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationComponent.java +++ b/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationComponent.java @@ -5,14 +5,23 @@ import com.badlogic.ashley.core.Component; import com.badlogic.gdx.graphics.g2d.Animation; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.SceneLoader; import com.uwsoft.editor.renderer.data.FrameRange; -public class SpriteAnimationComponent implements Component { +public class SpriteAnimationComponent implements Component,Pool.Poolable { public String animationName = ""; public int fps = 24; public HashMap frameRangeMap = new HashMap(); public String currentAnimation; public Animation.PlayMode playMode = Animation.PlayMode.LOOP; - + + @Override + public void reset() { + animationName = ""; + fps = 24; + frameRangeMap = new HashMap(); + currentAnimation=null; + playMode = Animation.PlayMode.LOOP; + } } diff --git a/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationStateComponent.java b/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationStateComponent.java index d7f27dfb..665f9a45 100644 --- a/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationStateComponent.java +++ b/src/com/uwsoft/editor/renderer/components/sprite/SpriteAnimationStateComponent.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.data.FrameRange; import java.util.ArrayList; @@ -11,18 +12,21 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class SpriteAnimationStateComponent implements Component { +public class SpriteAnimationStateComponent implements Component,Pool.Poolable { public Array allRegions; public Animation currentAnimation; public float time = 0.0f; public boolean paused = false; - public SpriteAnimationStateComponent(Array allRegions) { + public SpriteAnimationStateComponent(){ + } + + public void setRegions(Array allRegions) { this.allRegions = sortAndGetRegions(allRegions); } - - public Animation get() { + + public Animation get() { return currentAnimation; } @@ -45,6 +49,14 @@ private Array sortAndGetRegions(Array { @Override public int compare(TextureAtlas.AtlasRegion o1, TextureAtlas.AtlasRegion o2) { diff --git a/src/com/uwsoft/editor/renderer/factory/EntityFactory.java b/src/com/uwsoft/editor/renderer/factory/EntityFactory.java index 001e47e4..80d87039 100644 --- a/src/com/uwsoft/editor/renderer/factory/EntityFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/EntityFactory.java @@ -4,10 +4,12 @@ import com.badlogic.ashley.core.Component; import com.badlogic.ashley.core.ComponentMapper; -import com.badlogic.ashley.core.Engine; +//import com.badlogic.ashley.core.Engine; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.physics.box2d.World; +import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.viewport.Viewport; import com.uwsoft.editor.renderer.commons.IExternalItemType; import com.uwsoft.editor.renderer.components.CompositeTransformComponent; @@ -39,22 +41,23 @@ public class EntityFactory { public RayHandler rayHandler; public World world; public IResourceRetriever rm = null; + public PooledEngine engine; - public EntityFactory( RayHandler rayHandler, World world, IResourceRetriever rm ) { - + public EntityFactory( PooledEngine engine,RayHandler rayHandler, World world, IResourceRetriever rm ) { + this.engine=engine; this.rayHandler = rayHandler; this.world = world; this.rm = rm; - compositeComponentFactory = new CompositeComponentFactory(rayHandler, world, rm); - lightComponentFactory = new LightComponentFactory(rayHandler, world, rm); - particleEffectComponentFactory = new ParticleEffectComponentFactory(rayHandler, world, rm); - simpleImageComponentFactory = new SimpleImageComponentFactory(rayHandler, world, rm); - spriteComponentFactory = new SpriteComponentFactory(rayHandler, world, rm); - spriterComponentFactory = new SpriterComponentFactory(rayHandler, world, rm); - labelComponentFactory = new LabelComponentFactory(rayHandler, world, rm); - ninePatchComponentFactory = new NinePatchComponentFactory(rayHandler, world, rm); - colorPrimitiveFactory = new ColorPrimitiveComponentFactory(rayHandler, world, rm); + compositeComponentFactory = new CompositeComponentFactory(engine,rayHandler, world, rm); + lightComponentFactory = new LightComponentFactory(engine,rayHandler, world, rm); + particleEffectComponentFactory = new ParticleEffectComponentFactory(engine,rayHandler, world, rm); + simpleImageComponentFactory = new SimpleImageComponentFactory(engine,rayHandler, world, rm); + spriteComponentFactory = new SpriteComponentFactory(engine,rayHandler, world, rm); + spriterComponentFactory = new SpriterComponentFactory(engine,rayHandler, world, rm); + labelComponentFactory = new LabelComponentFactory(engine,rayHandler, world, rm); + ninePatchComponentFactory = new NinePatchComponentFactory(engine,rayHandler, world, rm); + colorPrimitiveFactory = new ColorPrimitiveComponentFactory(engine,rayHandler, world, rm); } @@ -79,7 +82,7 @@ public void addExternalFactory(IExternalItemType itemType) { public Entity createEntity(Entity root, SimpleImageVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); simpleImageComponentFactory.createComponents(root, entity, vo); @@ -90,7 +93,7 @@ public Entity createEntity(Entity root, SimpleImageVO vo){ public Entity createEntity(Entity root, Image9patchVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); ninePatchComponentFactory.createComponents(root, entity, vo); @@ -101,7 +104,7 @@ public Entity createEntity(Entity root, Image9patchVO vo){ public Entity createEntity(Entity root, LabelVO vo) { - Entity entity = new Entity(); + Entity entity = engine.createEntity(); labelComponentFactory.createComponents(root, entity, vo); @@ -112,7 +115,7 @@ public Entity createEntity(Entity root, LabelVO vo) { public Entity createEntity(Entity root, ParticleEffectVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); particleEffectComponentFactory.createComponents(root, entity, vo); @@ -123,7 +126,7 @@ public Entity createEntity(Entity root, ParticleEffectVO vo){ public Entity createEntity(Entity root, LightVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); lightComponentFactory.createComponents(root, entity, vo); @@ -134,7 +137,7 @@ public Entity createEntity(Entity root, LightVO vo){ public Entity createEntity(Entity root, SpineVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); ComponentFactory factory = externalFactories.get(SPINE_TYPE); if(factory != null) { @@ -147,7 +150,7 @@ public Entity createEntity(Entity root, SpineVO vo){ public Entity createEntity(Entity root, SpriteAnimationVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); spriteComponentFactory.createComponents(root, entity, vo); @@ -158,7 +161,7 @@ public Entity createEntity(Entity root, SpriteAnimationVO vo){ public Entity createEntity(Entity root, SpriterVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); spriterComponentFactory.createComponents(root, entity, vo); @@ -169,7 +172,7 @@ public Entity createEntity(Entity root, SpriterVO vo){ public Entity createEntity(Entity root, CompositeItemVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); compositeComponentFactory.createComponents(root, entity, vo); @@ -180,7 +183,7 @@ public Entity createEntity(Entity root, CompositeItemVO vo){ public Entity createEntity(Entity root, ColorPrimitiveVO vo){ - Entity entity = new Entity(); + Entity entity = engine.createEntity(); colorPrimitiveFactory.createComponents(root, entity, vo); @@ -194,13 +197,13 @@ public Entity createRootEntity(CompositeVO compositeVo, Viewport viewport){ CompositeItemVO vo = new CompositeItemVO(); vo.composite = compositeVo; - Entity entity = new Entity(); + Entity entity = engine.createEntity(); compositeComponentFactory.createComponents(null, entity, vo); // CompositeTransformComponent compositeTransform = new CompositeTransformComponent(); - TransformComponent transform = new TransformComponent(); + TransformComponent transform = engine.createComponent(TransformComponent.class); - ViewPortComponent viewPortComponent = new ViewPortComponent(); + ViewPortComponent viewPortComponent = engine.createComponent(ViewPortComponent.class); viewPortComponent.viewPort = viewport; //TODO: not sure if this line is okay @@ -244,7 +247,7 @@ public Integer updateMap(Entity entity) { return mainItemComponent.uniqueId; } - public void initAllChildren(Engine engine, Entity entity, CompositeVO vo) { + public void initAllChildren(Entity entity, CompositeVO vo) { for (int i = 0; i < vo.sImages.size(); i++) { Entity child = createEntity(entity, vo.sImages.get(i)); engine.addEntity(child); @@ -293,7 +296,7 @@ public void initAllChildren(Engine engine, Entity entity, CompositeVO vo) { for (int i = 0; i < vo.sComposites.size(); i++) { Entity child = createEntity(entity, vo.sComposites.get(i)); engine.addEntity(child); - initAllChildren(engine, child, vo.sComposites.get(i).composite); + initAllChildren(child, vo.sComposites.get(i).composite); } } diff --git a/src/com/uwsoft/editor/renderer/factory/component/ColorPrimitiveComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/ColorPrimitiveComponentFactory.java index 3245198e..3210e1ab 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/ColorPrimitiveComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/ColorPrimitiveComponentFactory.java @@ -20,6 +20,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; @@ -40,8 +41,8 @@ */ public class ColorPrimitiveComponentFactory extends ComponentFactory { - public ColorPrimitiveComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public ColorPrimitiveComponentFactory(PooledEngine engine,RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -62,7 +63,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); component.setFromShape(vo.shape); entity.add(component); @@ -71,7 +72,7 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } protected TextureRegionComponent createTextureRegionComponent(Entity entity, MainItemVO vo) { - TextureRegionComponent component = new TextureRegionComponent(); + TextureRegionComponent component = engine.createComponent(TextureRegionComponent.class); Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888); pixmap.setColor(Color.WHITE); diff --git a/src/com/uwsoft/editor/renderer/factory/component/ComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/ComponentFactory.java index 9b1efc28..dc5c84d7 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/ComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/ComponentFactory.java @@ -22,7 +22,9 @@ import com.badlogic.ashley.core.ComponentMapper; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.physics.box2d.World; +import com.badlogic.gdx.utils.Pool; import com.uwsoft.editor.renderer.components.*; import com.uwsoft.editor.renderer.components.physics.PhysicsBodyComponent; import com.uwsoft.editor.renderer.data.MainItemVO; @@ -40,6 +42,7 @@ public abstract class ComponentFactory { protected IResourceRetriever rm; protected RayHandler rayHandler; protected World world; + protected PooledEngine engine; protected ComponentMapper nodeComponentMapper; @@ -47,15 +50,16 @@ public ComponentFactory() { nodeComponentMapper = ComponentMapper.getFor(NodeComponent.class); } - public ComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { + public ComponentFactory(PooledEngine engine,RayHandler rayHandler, World world, IResourceRetriever rm) { this(); - injectDependencies(rayHandler, world, rm); + injectDependencies(engine,rayHandler, world, rm); } - public void injectDependencies(RayHandler rayHandler, World world, IResourceRetriever rm) { + public void injectDependencies(PooledEngine engine,RayHandler rayHandler, World world, IResourceRetriever rm) { this.rayHandler = rayHandler; this.world = world; this.rm = rm; + this.engine=engine; } public abstract void createComponents(Entity root, Entity entity, MainItemVO vo); @@ -76,14 +80,14 @@ protected ShaderComponent createShaderComponent(Entity entity, MainItemVO vo) { if(vo.shaderName == null || vo.shaderName.isEmpty()){ return null; } - ShaderComponent component = new ShaderComponent(); + ShaderComponent component = engine.createComponent(ShaderComponent.class); component.setShader(vo.shaderName, rm.getShaderProgram(vo.shaderName)); entity.add(component); return component; } protected MainItemComponent createMainItemComponent(Entity entity, MainItemVO vo, int entityType) { - MainItemComponent component = new MainItemComponent(); + MainItemComponent component = engine.createComponent(MainItemComponent.class); component.customVars = vo.customVars; component.uniqueId = vo.uniqueId; component.itemIdentifier = vo.itemIdentifier; @@ -99,7 +103,7 @@ protected MainItemComponent createMainItemComponent(Entity entity, MainItemVO vo } protected TransformComponent createTransformComponent(Entity entity, MainItemVO vo, DimensionsComponent dimensionsComponent) { - TransformComponent component = new TransformComponent(); + TransformComponent component = engine.createComponent(TransformComponent.class); component.rotation = vo.rotation; component.scaleX = vo.scaleX; component.scaleY = vo.scaleY; @@ -120,7 +124,7 @@ protected TransformComponent createTransformComponent(Entity entity, MainItemVO protected abstract DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo); protected TintComponent createTintComponent(Entity entity, MainItemVO vo) { - TintComponent component = new TintComponent(); + TintComponent component = engine.createComponent(TintComponent.class); component.color.set(vo.tint[0], vo.tint[1], vo.tint[2], vo.tint[3]); entity.add(component); @@ -129,7 +133,7 @@ protected TintComponent createTintComponent(Entity entity, MainItemVO vo) { } protected ZIndexComponent createZIndexComponent(Entity entity, MainItemVO vo) { - ZIndexComponent component = new ZIndexComponent(); + ZIndexComponent component = engine.createComponent(ZIndexComponent.class); if(vo.layerName == "" || vo.layerName == null) vo.layerName = "Default"; @@ -142,13 +146,13 @@ protected ZIndexComponent createZIndexComponent(Entity entity, MainItemVO vo) { } protected ScriptComponent createScriptComponent(Entity entity, MainItemVO vo) { - ScriptComponent component = new ScriptComponent(); + ScriptComponent component = engine.createComponent(ScriptComponent.class); entity.add(component); return component; } protected ParentNodeComponent createParentNodeComponent(Entity root, Entity entity) { - ParentNodeComponent component = new ParentNodeComponent(); + ParentNodeComponent component = engine.createComponent(ParentNodeComponent.class); component.parentEntity = root; entity.add(component); @@ -176,7 +180,7 @@ protected void createPhysicsComponents(Entity entity, MainItemVO vo) { } protected PhysicsBodyComponent createPhysicsBodyPropertiesComponent(Entity entity, MainItemVO vo) { - PhysicsBodyComponent component = new PhysicsBodyComponent(); + PhysicsBodyComponent component = engine.createComponent(PhysicsBodyComponent.class); component.allowSleep = vo.physics.allowSleep; component.sensor = vo.physics.sensor; component.awake = vo.physics.awake; @@ -197,7 +201,7 @@ protected PhysicsBodyComponent createPhysicsBodyPropertiesComponent(Entity entit } protected PolygonComponent createMeshComponent(Entity entity, MainItemVO vo) { - PolygonComponent component = new PolygonComponent(); + PolygonComponent component = engine.createComponent(PolygonComponent.class); if(vo.shape != null) { component.vertices = vo.shape.polygons.clone(); entity.add(component); diff --git a/src/com/uwsoft/editor/renderer/factory/component/CompositeComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/CompositeComponentFactory.java index c7533875..5963c1cc 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/CompositeComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/CompositeComponentFactory.java @@ -21,6 +21,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.physics.box2d.World; import com.uwsoft.editor.renderer.components.CompositeTransformComponent; @@ -39,8 +40,8 @@ */ public class CompositeComponentFactory extends ComponentFactory { - public CompositeComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public CompositeComponentFactory(PooledEngine engine, RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -56,7 +57,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); component.width = ((CompositeItemVO) vo).width; component.height = ((CompositeItemVO) vo).height; component.boundBox = new Rectangle(0,0,component.width,component.height); @@ -70,16 +71,16 @@ protected void createNodeComponent(Entity root, Entity entity) { super.createNodeComponent(root, entity); } - NodeComponent node = new NodeComponent(); + NodeComponent node = engine.createComponent(NodeComponent.class); entity.add(node); } protected void createCompositeComponents(Entity entity, CompositeItemVO vo) { - CompositeTransformComponent compositeTransform = new CompositeTransformComponent(); + CompositeTransformComponent compositeTransform = engine.createComponent(CompositeTransformComponent.class); compositeTransform.automaticResize = vo.automaticResize; - LayerMapComponent layerMap = new LayerMapComponent(); + LayerMapComponent layerMap = engine.createComponent(LayerMapComponent.class); if(vo.composite.layers.size() == 0) { vo.composite.layers.add(LayerItemVO.createDefault()); } diff --git a/src/com/uwsoft/editor/renderer/factory/component/LabelComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/LabelComponentFactory.java index b6b903b8..6bb43258 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/LabelComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/LabelComponentFactory.java @@ -3,6 +3,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.graphics.g2d.ParticleEffect; import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.scenes.scene2d.ui.Label; @@ -18,8 +19,8 @@ public class LabelComponentFactory extends ComponentFactory{ private static int labelDefaultSize = 12; - public LabelComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public LabelComponentFactory(PooledEngine engine, RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); // TODO Auto-generated constructor stub } @@ -33,7 +34,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); component.height = ((LabelVO) vo).height; component.width = ((LabelVO) vo).width; @@ -42,7 +43,10 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } protected LabelComponent createLabelComponent(Entity entity, LabelVO vo) { - LabelComponent component = new LabelComponent(vo.text, generateStyle(rm, vo.style, vo.size)); +// LabelComponent component = new LabelComponent(vo.text, generateStyle(rm, vo.style, vo.size)); + LabelComponent component = engine.createComponent(LabelComponent.class); + component.setText(vo.text); + component.setStyle(generateStyle(rm,vo.style,vo.size)); component.fontName = vo.style; component.fontSize = vo.size; component.setAlignment(vo.align); diff --git a/src/com/uwsoft/editor/renderer/factory/component/LightComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/LightComponentFactory.java index b6ddb033..62507e49 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/LightComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/LightComponentFactory.java @@ -22,6 +22,7 @@ import box2dLight.PointLight; import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.physics.box2d.World; @@ -39,8 +40,8 @@ */ public class LightComponentFactory extends ComponentFactory { - public LightComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public LightComponentFactory(PooledEngine engine, RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -53,7 +54,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component =engine.createComponent(DimensionsComponent.class); ProjectInfoVO projectInfoVO = rm.getProjectVO(); component.boundBox = new Rectangle(-10f / projectInfoVO.pixelToWorld, -10f / projectInfoVO.pixelToWorld, 20f / projectInfoVO.pixelToWorld, 20f / projectInfoVO.pixelToWorld); @@ -66,7 +67,8 @@ protected LightObjectComponent createLightObjectComponent(Entity entity, LightVO if(vo.softnessLength == -1f) { vo.softnessLength = vo.distance * 0.1f * PhysicsBodyLoader.getScale(); } - LightObjectComponent component = new LightObjectComponent(vo.type); + LightObjectComponent component = engine.createComponent(LightObjectComponent.class); + component.type=vo.type; component.coneDegree = vo.coneDegree; component.directionDegree = vo.directionDegree; component.distance = vo.distance; diff --git a/src/com/uwsoft/editor/renderer/factory/component/NinePatchComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/NinePatchComponentFactory.java index 092853e3..258f3ff1 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/NinePatchComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/NinePatchComponentFactory.java @@ -3,6 +3,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; @@ -20,8 +21,8 @@ public class NinePatchComponentFactory extends ComponentFactory { private NinePatchComponent ninePatchComponent; - public NinePatchComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public NinePatchComponentFactory(PooledEngine engine,RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -34,7 +35,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); component.height = ((Image9patchVO) vo).height; component.width = ((Image9patchVO) vo).width; if(component.width == 0) { @@ -50,7 +51,7 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } private NinePatchComponent createNinePatchComponent(Entity entity, Image9patchVO vo) { - NinePatchComponent ninePatchComponent = new NinePatchComponent(); + NinePatchComponent ninePatchComponent =engine.createComponent(NinePatchComponent.class); AtlasRegion atlasRegion = (TextureAtlas.AtlasRegion) rm.getTextureRegion(vo.imageName); ninePatchComponent.ninePatch = new NinePatch(atlasRegion, atlasRegion.splits[0], atlasRegion.splits[1], atlasRegion.splits[2], atlasRegion.splits[3]); diff --git a/src/com/uwsoft/editor/renderer/factory/component/ParticleEffectComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/ParticleEffectComponentFactory.java index 2ed5ca95..4c2995a9 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/ParticleEffectComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/ParticleEffectComponentFactory.java @@ -20,6 +20,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.graphics.g2d.ParticleEffect; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.physics.box2d.World; @@ -37,8 +38,8 @@ public class ParticleEffectComponentFactory extends ComponentFactory { - public ParticleEffectComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public ParticleEffectComponentFactory(PooledEngine engine, RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -51,7 +52,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component= engine.createComponent(DimensionsComponent.class); ProjectInfoVO projectInfoVO = rm.getProjectVO(); float boundBoxSize = 70f; @@ -62,7 +63,7 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } protected ParticleComponent createParticleComponent(Entity entity, ParticleEffectVO vo) { - ParticleComponent component = new ParticleComponent(); + ParticleComponent component = engine.createComponent(ParticleComponent.class); component.particleName = vo.particleName; ParticleEffect particleEffect = new ParticleEffect(rm.getParticleEffect(vo.particleName)); component.particleEffect = particleEffect; diff --git a/src/com/uwsoft/editor/renderer/factory/component/SimpleImageComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/SimpleImageComponentFactory.java index fc072108..d7f809ab 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/SimpleImageComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/SimpleImageComponentFactory.java @@ -21,6 +21,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.physics.box2d.World; import com.uwsoft.editor.renderer.components.DimensionsComponent; import com.uwsoft.editor.renderer.components.PolygonComponent; @@ -40,8 +41,8 @@ public class SimpleImageComponentFactory extends ComponentFactory { private TextureRegionComponent textureRegionComponent; - public SimpleImageComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public SimpleImageComponentFactory(PooledEngine engine, RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } public void createComponents(Entity root, Entity entity, MainItemVO vo) { @@ -67,7 +68,7 @@ private void updatePolygons(Entity entity) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); TextureRegionComponent textureRegionComponent = ComponentRetriever.get(entity, TextureRegionComponent.class); @@ -83,7 +84,7 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } protected TextureRegionComponent createTextureRegionComponent(Entity entity, SimpleImageVO vo) { - TextureRegionComponent component = new TextureRegionComponent(); + TextureRegionComponent component = engine.createComponent(TextureRegionComponent.class); component.regionName = vo.imageName; component.region = rm.getTextureRegion(vo.imageName); component.isRepeat = vo.isRepeat; diff --git a/src/com/uwsoft/editor/renderer/factory/component/SpriteComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/SpriteComponentFactory.java index 9462645a..90d7a1d1 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/SpriteComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/SpriteComponentFactory.java @@ -21,6 +21,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.graphics.g2d.*; import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.utils.Array; @@ -46,8 +47,8 @@ */ public class SpriteComponentFactory extends ComponentFactory { - public SpriteComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public SpriteComponentFactory(PooledEngine engine,RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -60,7 +61,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); SpriteAnimationVO sVo = (SpriteAnimationVO) vo; Array regions = getRegions(sVo.animationName); @@ -76,7 +77,7 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } protected SpriteAnimationComponent createSpriteAnimationDataComponent(Entity entity, SpriteAnimationVO vo) { - SpriteAnimationComponent spriteAnimationComponent = new SpriteAnimationComponent(); + SpriteAnimationComponent spriteAnimationComponent = engine.createComponent(SpriteAnimationComponent.class); spriteAnimationComponent.animationName = vo.animationName; spriteAnimationComponent.frameRangeMap = new HashMap(); @@ -97,8 +98,9 @@ protected SpriteAnimationComponent createSpriteAnimationDataComponent(Entity ent // filtering regions by name Array regions = getRegions(spriteAnimationComponent.animationName); - AnimationComponent animationComponent = new AnimationComponent(); - SpriteAnimationStateComponent stateComponent = new SpriteAnimationStateComponent(regions); + AnimationComponent animationComponent = engine.createComponent(AnimationComponent.class); + SpriteAnimationStateComponent stateComponent = engine.createComponent(SpriteAnimationStateComponent.class); + stateComponent.setRegions(regions); if(spriteAnimationComponent.frameRangeMap.isEmpty()) { spriteAnimationComponent.frameRangeMap.put("Default", new FrameRange("Default", 0, regions.size-1)); @@ -112,7 +114,7 @@ protected SpriteAnimationComponent createSpriteAnimationDataComponent(Entity ent stateComponent.set(spriteAnimationComponent); - TextureRegionComponent textureRegionComponent = new TextureRegionComponent(); + TextureRegionComponent textureRegionComponent = engine.createComponent(TextureRegionComponent.class); textureRegionComponent.region = regions.get(0); entity.add(textureRegionComponent); diff --git a/src/com/uwsoft/editor/renderer/factory/component/SpriterComponentFactory.java b/src/com/uwsoft/editor/renderer/factory/component/SpriterComponentFactory.java index 6cfd6f3b..2d80efa3 100644 --- a/src/com/uwsoft/editor/renderer/factory/component/SpriterComponentFactory.java +++ b/src/com/uwsoft/editor/renderer/factory/component/SpriterComponentFactory.java @@ -21,6 +21,7 @@ import box2dLight.RayHandler; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.physics.box2d.World; import com.brashmonkey.spriter.Player; @@ -42,8 +43,8 @@ */ public class SpriterComponentFactory extends ComponentFactory { - public SpriterComponentFactory(RayHandler rayHandler, World world, IResourceRetriever rm) { - super(rayHandler, world, rm); + public SpriterComponentFactory(PooledEngine engine, RayHandler rayHandler, World world, IResourceRetriever rm) { + super(engine,rayHandler, world, rm); } @Override @@ -56,7 +57,7 @@ public void createComponents(Entity root, Entity entity, MainItemVO vo) { @Override protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemVO vo) { - DimensionsComponent component = new DimensionsComponent(); + DimensionsComponent component = engine.createComponent(DimensionsComponent.class); SpriterComponent spriterComponent = ComponentRetriever.get(entity, SpriterComponent.class); @@ -69,7 +70,7 @@ protected DimensionsComponent createDimensionsComponent(Entity entity, MainItemV } protected SpriterComponent createSpriterDataComponent(Entity entity, SpriterVO vo) { - SpriterComponent component = new SpriterComponent(); + SpriterComponent component = engine.createComponent(SpriterComponent.class); component. entity = vo.entity; component.animation = vo.animation; component. animationName = vo.animationName; @@ -88,7 +89,7 @@ protected SpriterComponent createSpriterDataComponent(Entity entity, SpriterVO v component.player.setAnimation(component.currentAnimationIndex); component.player.setScale(component.scale); - SpriterDrawerComponent spriterDrawer = new SpriterDrawerComponent(); + SpriterDrawerComponent spriterDrawer = engine.createComponent(SpriterDrawerComponent.class); spriterDrawer.drawer = new LibGdxDrawer(loader, null); diff --git a/src/com/uwsoft/editor/renderer/resources/ResourceManager.java b/src/com/uwsoft/editor/renderer/resources/ResourceManager.java index 135a6b17..7e4ecc9b 100644 --- a/src/com/uwsoft/editor/renderer/resources/ResourceManager.java +++ b/src/com/uwsoft/editor/renderer/resources/ResourceManager.java @@ -232,6 +232,13 @@ public void loadParticleEffects() { } } + public void loadParticleEffect(String name) { + ParticleEffect effect = new ParticleEffect(); + effect.load(Gdx.files.internal(particleEffectsPath + File.separator + name), mainPack, ""); + particleEffects.put(name, effect); + } + + @Override public void loadSpriteAnimations() { // empty existing ones that are not scheduled to load @@ -246,6 +253,12 @@ public void loadSpriteAnimations() { spriteAnimations.put(name, animAtlas); } } + + public void loadSpriteAnimation(String name){ + TextureAtlas animAtlas = new TextureAtlas(Gdx.files.internal(packResolutionName + File.separator + spriteAnimationsPath + File.separator + name + File.separator + name + ".atlas")); + spriteAnimations.put(name, animAtlas); + } + @Override public void loadSpriterAnimations() { // empty existing ones that are not scheduled to load diff --git a/src/com/uwsoft/editor/renderer/utils/ItemWrapper.java b/src/com/uwsoft/editor/renderer/utils/ItemWrapper.java index b2b2f2df..67f0d6f9 100644 --- a/src/com/uwsoft/editor/renderer/utils/ItemWrapper.java +++ b/src/com/uwsoft/editor/renderer/utils/ItemWrapper.java @@ -20,6 +20,8 @@ import com.badlogic.ashley.core.Component; import com.badlogic.ashley.core.Entity; +import com.badlogic.ashley.core.PooledEngine; +import com.badlogic.gdx.math.Vector2; import com.uwsoft.editor.renderer.components.MainItemComponent; import com.uwsoft.editor.renderer.components.NodeComponent; import com.uwsoft.editor.renderer.components.ParentNodeComponent; @@ -85,10 +87,10 @@ public Entity getEntity() { return entity; } - public IScript addScript(IScript script) { + public IScript addScript(IScript script, PooledEngine engine) { ScriptComponent component = ComponentRetriever.get(entity, ScriptComponent.class); if(component == null) { - component = new ScriptComponent(); + component = engine.createComponent(ScriptComponent.class); entity.add(component); } component.addScript(script); @@ -96,4 +98,6 @@ public IScript addScript(IScript script) { return script; } + + }