Java Code Examples for com.badlogic.gdx.utils.Pool

The following examples show how to use com.badlogic.gdx.utils.Pool. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gdx-gltf   Source File: AnimationControllerHack.java    License: Apache License 2.0 6 votes vote down vote up
private final static void applyNodeAnimationBlending (final NodeAnimation nodeAnim, final ObjectMap<Node, Transform> out,
	final Pool<Transform> pool, final float alpha, final float time) {

	final Node node = nodeAnim.node;
	node.isAnimated = true;
	final Transform transform = getNodeAnimationTransform(nodeAnim, time);

	Transform t = out.get(node, null);
	if (t != null) {
		if (alpha > 0.999999f)
			t.set(transform);
		else
			t.lerp(transform, alpha);
	} else {
		if (alpha > 0.999999f)
			out.put(node, pool.obtain().set(transform));
		else
			out.put(node, pool.obtain().set(node.translation, node.rotation, node.scale, ((NodePlus)node).weights).lerp(transform, alpha));
	}
}
 
Example 2
Source Project: Scene3d   Source File: ParallelAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean act (float delta) {
        if (complete) return true;
        complete = true;
        Pool pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool while executing.
        try {
                Array<Action3d> actions = this.actions;
                for (int i = 0, n = actions.size; i < n && actor3d != null; i++) {
                        if (!actions.get(i).act(delta)) complete = false;
                        if (actor3d == null) return true; // This action was removed.
                }
                return complete;
        } finally {
                setPool(pool);
        }
}
 
Example 3
Source Project: Scene3d   Source File: SequenceAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean act (float delta) {
        if (index >= actions.size) return true;
        Pool<Action3d> pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool while executings.
        try {
                if (actions.get(index).act(delta)) {
                        if (actor3d == null) return true; // This action was removed.
                        index++;
                        if (index >= actions.size) return true;
                }
                return false;
        } finally {
                setPool(pool);
        }
}
 
Example 4
Source Project: Scene3d   Source File: TemporalAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean act (float delta) {
        if (complete) return true;
        Pool pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool while executing.
        try {
                if (!began) {
                        begin();
                        began = true;
                }
                time += delta;
                complete = time >= duration;
                float percent;
                if (complete)
                        percent = 1;
                else {
                        percent = time / duration;
                        if (interpolation != null) percent = interpolation.apply(percent);
                }
                update(reverse ? 1 - percent : percent);
                if (complete) end();
                return complete;
        } finally {
                setPool(pool);
        }
}
 
Example 5
Source Project: gdx-gltf   Source File: AnimationControllerHack.java    License: Apache License 2.0 5 votes vote down vote up
/** Apply a single animation to the {@link ModelInstance} and update the it to reflect the changes. */
@Override
protected void applyAnimation (final Animation animation, final float time) {
	if (applying) throw new GdxRuntimeException("Call end() first");
	applyAnimationPlus(null, (Pool<Transform>)null, 1.f, animation, time);
	if(calculateTransforms) target.calculateTransforms();
}
 
Example 6
Source Project: Unlucky   Source File: ParticleFactory.java    License: MIT License 5 votes vote down vote up
public ParticleFactory(OrthographicCamera cam, final ResourceManager rm) {
    this.cam = cam;
    this.viewWidth = (int) cam.viewportWidth;
    this.viewHeight = (int) cam.viewportHeight;
    this.rm = rm;

    particles = new Array<Particle>();
    particlePool = new Pool<Particle>() {
        @Override
        protected Particle newObject() {
            return new Particle();
        }
    };
}
 
Example 7
Source Project: Cubes   Source File: RainRenderer.java    License: MIT License 5 votes vote down vote up
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
  Renderable renderable = pool.obtain();
  ((CubesRenderable) renderable).name = "RainMesh";
  renderable.material = Assets.blockItemSheet.getMaterial(); // not actually used
  renderable.meshPart.set(meshPart);
  if (SHADER == null) {
    SHADER = new RainShader(renderable);
    SHADER.init();
  }
  renderable.shader = SHADER;
  renderables.add(renderable);
}
 
Example 8
Source Project: Cubes   Source File: WorldGraphicsPools.java    License: MIT License 5 votes vote down vote up
public static void init() {
  Pools.registerType(AreaRenderer.class, new Pool<AreaRenderer>() {
    @Override
    protected AreaRenderer newObject() {
      return new AreaRenderer();
    }
  });
  Pools.registerType(AreaMesh.class, new DisposablePool<AreaMesh>() {
    @Override
    protected AreaMesh newObject() {
      return new AreaMesh();
    }
  });
}
 
Example 9
Source Project: Cubes   Source File: AreaRenderer.java    License: MIT License 5 votes vote down vote up
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
  if (area == null || meshs.size() == 0) return;
  renderedThisFrame++;
  for (AreaMesh mesh : meshs) {
    renderedMeshesThisFrame++;
    renderables.add(mesh.renderable);
  }
}
 
Example 10
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static <T> void registerType(Class<? extends T> c, Pool<T> pool) {
  T obj = pool.obtain();
  Class<?> objClass = obj.getClass();
  pool.free(obj);
  if (objClass.equals(c)) {
    synchronized (pools) {
      if (!pools.containsKey(c)) {
        pools.put(c, pool);
      }
    }
  } else {
    throw new CubesException("Calling obtain on " + pool + " does not return " + c.getName());
  }
}
 
Example 11
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static <T> T obtain(Class<T> c) {
  Pool<T> pool = pool(c);
  if (pool == null) return null;
  synchronized (pool) {
    return pool.obtain();
  }
}
 
Example 12
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static void clearPool(Class<?> c) {
  Pool<?> pool = pool(c);
  if (pool == null) throw new IllegalStateException("No pool for " + c.getSimpleName());
  synchronized (pool) {
    pool.clear();
  }
}
 
Example 13
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static <T> void free(Class<T> c, T obj) {
  Pool<T> pool = pool(c);
  if (pool == null) return;
  synchronized (pool) {
    pool.free(obj);
  }
}
 
Example 14
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static <T> void free(T obj) {
  Pool pool = pool(obj);
  if (pool == null) return;
  synchronized (pool) {
    pool.free(obj);
  }
}
 
Example 15
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static AreaReference obtainAreaReference() {
  Pool<AreaReference> pool = pool(AreaReference.class);
  if (pool == null) return null;
  synchronized (pool) {
    return pool.obtain();
  }
}
 
Example 16
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static void free(AreaReference obj) {
  Pool pool = pool(AreaReference.class);
  if (pool == null) return;
  synchronized (pool) {
    pool.free(obj);
  }
}
 
Example 17
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static BlockReference obtainBlockReference() {
  Pool<BlockReference> pool = pool(BlockReference.class);
  if (pool == null) return null;
  synchronized (pool) {
    return pool.obtain();
  }
}
 
Example 18
Source Project: Cubes   Source File: Pools.java    License: MIT License 5 votes vote down vote up
public static void free(BlockReference obj) {
  Pool pool = pool(BlockReference.class);
  if (pool == null) return;
  synchronized (pool) {
    pool.free(obj);
  }
}
 
Example 19
Source Project: Scene3d   Source File: DelegateAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public final boolean act (float delta) {
        Pool pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool inside the delegate action.
        try {
                return delegate(delta);
        } finally {
                setPool(pool);
        }
}
 
Example 20
Source Project: Scene3d   Source File: Actions3d.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns a new or pooled action of the specified type. */
static public <T extends Action3d> T action3d (Class<T> type) {
        Pool<T> pool = Pools.get(type);
        T action = pool.obtain();
        action.setPool(pool);
        return action;
}
 
Example 21
Source Project: Scene3d   Source File: RunnableAction.java    License: Apache License 2.0 5 votes vote down vote up
/** Called to run the runnable. */
public void run () {
        Pool pool = getPool();
        setPool(null); // Ensure this action can't be returned to the pool inside the runnable.
        try {
                runnable.run();
        } finally {
                setPool(pool);
        }
}
 
Example 22
Source Project: gdx-ai   Source File: PooledBehaviorTreeLibrary.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * retrieve pool by tree reference, create it if not already exists.
 * @param treeReference
 * @return existing or newly created pool.
 */
protected Pool<BehaviorTree> getPool(final String treeReference){
	Pool<BehaviorTree> treePool = pools.get(treeReference);
	if(treePool == null){
		treePool = new Pool<BehaviorTree>(){
			@Override
			protected BehaviorTree newObject() {
				return newBehaviorTree(treeReference);
			}
		};
		pools.put(treeReference, treePool);
	}
	return treePool;
}
 
Example 23
Source Project: gdx-ai   Source File: PooledBehaviorTreeLibrary.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> BehaviorTree<T> createBehaviorTree(String treeReference, T blackboard) {
	Pool<BehaviorTree> pool = getPool(treeReference);
	BehaviorTree<T> tree = (BehaviorTree<T>)pool.obtain();
	tree.setObject(blackboard);
	return tree;
}
 
Example 24
Source Project: gdx-ai   Source File: PooledBehaviorTreeLibrary.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Clear pool for a tree reference.
 * @param treeReference
 */
public void clear(String treeReference){
	Pool<BehaviorTree> treePool = pools.get(treeReference);
	if(treePool != null){
		treePool.clear();
	}
}
 
Example 25
Source Project: gdx-ai   Source File: PooledBehaviorTreeLibrary.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * clear all pools.
 */
public void clear(){
	for(Entry<String, Pool<BehaviorTree>> entry : pools.entries()){
		entry.value.clear();
	}
	pools.clear();
}
 
Example 26
Source Project: buffer_bci   Source File: Explosion.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void getRenderables (Array<Renderable> renderables, Pool<Renderable> pool) {
	super.getRenderables(renderables, pool);
	Renderable r = renderables.get(renderables.size - 1);
	r.meshPart.offset = 6 * (int)(15 * aliveTime / EXPLOSION_LIVE_TIME);
	r.meshPart.size = 6;
}
 
Example 27
Source Project: gdx-gltf   Source File: Scene.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
	modelInstance.getRenderables(renderables, pool);
}
 
Example 28
Source Project: gdx-gltf   Source File: SceneSkybox.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
	renderables.add(box);
}
 
Example 29
Source Project: Mundus   Source File: Terrain.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
    modelInstance.getRenderables(renderables, pool);
}
 
Example 30
Source Project: artemis-odb-orion   Source File: MultiPool.java    License: Apache License 2.0 4 votes vote down vote up
static <T extends Operation> void free(T operation) {
	Pool<T> pool = (Pool<T>) context.get().pool(operation.getClass());
	pool.free(operation);
}