com.badlogic.gdx.utils.Pool Java Examples

The following examples show how to use com.badlogic.gdx.utils.Pool. 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 File: AnimationControllerHack.java    From gdx-gltf with 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 File: ParallelAction.java    From Scene3d with 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 File: TemporalAction.java    From Scene3d with 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 #4
Source File: SequenceAction.java    From Scene3d with 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 #5
Source File: Pools.java    From Cubes with 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 #6
Source File: Explosion.java    From buffer_bci with 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 #7
Source File: Pools.java    From Cubes with 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 #8
Source File: Pools.java    From Cubes with 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 #9
Source File: Pools.java    From Cubes with 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 #10
Source File: Pools.java    From Cubes with 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 #11
Source File: DelegateAction.java    From Scene3d with 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 #12
Source File: Actions3d.java    From Scene3d with 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 #13
Source File: RunnableAction.java    From Scene3d with 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 #14
Source File: PooledBehaviorTreeLibrary.java    From gdx-ai with 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 #15
Source File: PooledBehaviorTreeLibrary.java    From gdx-ai with 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 #16
Source File: PooledBehaviorTreeLibrary.java    From gdx-ai with 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 #17
Source File: PooledBehaviorTreeLibrary.java    From gdx-ai with 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 #18
Source File: AnimationControllerHack.java    From gdx-gltf with 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 #19
Source File: Pools.java    From Cubes with 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 #20
Source File: Pools.java    From Cubes with 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 #21
Source File: Pools.java    From Cubes with 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 #22
Source File: AreaRenderer.java    From Cubes with 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 #23
Source File: WorldGraphicsPools.java    From Cubes with 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 #24
Source File: RainRenderer.java    From Cubes with 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 #25
Source File: Pools.java    From Cubes with 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 #26
Source File: ParticleFactory.java    From Unlucky with 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 #27
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
protected void calculateOffsets () {
	super.calculateOffsets();
	if (!this.text.equals(lastText)) {
		this.lastText = text;
		BitmapFont font = style.font;
		float maxWidthLine = this.getWidth()
				- (style.background != null ? style.background.getLeftWidth() + style.background.getRightWidth() : 0);
		linesBreak.clear();
		int lineStart = 0;
		int lastSpace = 0;
		char lastCharacter;
		Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
		GlyphLayout layout = layoutPool.obtain();
		for (int i = 0; i < text.length(); i++) {
			lastCharacter = text.charAt(i);
			if (lastCharacter == ENTER_DESKTOP || lastCharacter == ENTER_ANDROID) {
				linesBreak.add(lineStart);
				linesBreak.add(i);
				lineStart = i + 1;
			} else {
				lastSpace = (continueCursor(i, 0) ? lastSpace : i);
				layout.setText(font, text.subSequence(lineStart, i + 1));
				if (layout.width > maxWidthLine && softwrap) {
					if (lineStart >= lastSpace) {
						lastSpace = i - 1;
					}
					linesBreak.add(lineStart);
					linesBreak.add(lastSpace + 1);
					lineStart = lastSpace + 1;
					lastSpace = lineStart;
				}
			}
		}
		layoutPool.free(layout);
		// Add last line
		if (lineStart < text.length()) {
			linesBreak.add(lineStart);
			linesBreak.add(text.length());
		}
		showCursor();
	}
}
 
Example #28
Source File: Scene.java    From gdx-gltf with 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 #29
Source File: PooledEngine.java    From ashley with Apache License 2.0 4 votes vote down vote up
public void clear () {
	for (Pool pool : pools.values()) {
		pool.clear();
	}
}
 
Example #30
Source File: SceneSkybox.java    From gdx-gltf with Apache License 2.0 4 votes vote down vote up
@Override
public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) {
	renderables.add(box);
}