private void setCurrent(int index, TrackEntry entry) { TrackEntry current = expandToIndex(index); if (current != null) { TrackEntry previous = current.previous; current.previous = null; if (current.listener != null) current.listener.end(index); for (int i = 0, n = listeners.size; i < n; i++) listeners.get(i).end(index); entry.mixDuration = data.getMix(current.animation, entry.animation); if (entry.mixDuration > 0) { entry.mixTime = 0; // If a mix is in progress, mix from the closest animation. if (previous != null && current.mixTime / current.mixDuration < 0.5f) { entry.previous = previous; previous = current; } else entry.previous = current; } else trackEntryPool.free(current); if (previous != null) trackEntryPool.free(previous); } tracks.set(index, entry); if (entry.listener != null) entry.listener.start(index); for (int i = 0, n = listeners.size; i < n; i++) listeners.get(i).start(index); }
public boolean remove() { if (super.remove()) { pool.free(this); return true; } return false; }
public void defineSnapperViews() { if (logic.level == null) return; SnapperView view; int i; int j; int state; synchronized (activeSnappers) { for (i = 0; i < activeSnappers.size; i++) removeActor(activeSnappers.get(i)); snapperViewPool.free(activeSnappers); activeSnappers.clear(); int w = logic.width; int h = logic.height; for (i = 0; i < Snappers.WIDTH; i++) for (j = 0; j < Snappers.HEIGHT; j++) if ((state = logic.snappers.getSnapper(i, j)) > 0) { view = snapperViewPool.obtain(); view.set(i, j, state); view.setRandomStart(0, 0, w, h, SNAPPER_WARM_TIME); activeSnappers.add(view); addActor(view); view.setListener(snapperAnimationListener); view.setAnimFn(snapperAnimFn); } } }
private void freeAll(TrackEntry entry) { while (entry != null) { TrackEntry next = entry.next; trackEntryPool.free(entry); entry = next; } }
@Override public boolean handleMessage(Telegram telegram) { switch (telegram.message) { case PF_RESPONSE: // PathFinderQueue will call us directly, no need to register for this // message if (PathFinderRequestControl.DEBUG) { @SuppressWarnings("unchecked") PathFinderQueue<HierarchicalTiledNode> pfQueue = (PathFinderQueue<HierarchicalTiledNode>) telegram.sender; System.out.println("pfQueue.size = " + pfQueue.size()); } MyPathFinderRequest pfr = (MyPathFinderRequest) telegram.extraInfo; TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[pfr.pathIndex]; int n = path.getCount(); if (n > 0 && pfr.pathFound && pfr.endNode != path.get(n - 1)) { pfr.startNode = path.get(n - 1); if (pfr.pathIndex + 1 < paths.length) { pfr.pathIndex++; } pfr.resultPath = paths[pfr.pathIndex]; pfr.changeStatus(PathFinderRequest.SEARCH_NEW); numPaths = pfr.pathIndex; } else { requestPool.free(pfr); numPaths = pfr.pathIndex + 1; } break; } return true; }
@Override public void draw(SpriteBatch spriteBatch) { delta = Math.min(0.06f, Gdx.graphics.getDeltaTime()); this.setOrigin(0, 0); for (int i = particles.size - 1; i >= 0; i--) { Particle particle = particles.get(i); if (particle.life > 0) { updateParticle(particle); float dx = this.getWidth() / 2 * particle.scale; float dy = this.getHeight() / 2 * particle.scale; this.setColor(1, 1, 1, Math.max(particle.life / this.life, 0)); this.setScale(particle.scale); this.setPosition(particle.position.x - dx, particle.position.y - dy); if (!(particle.position.y - dy >= -10 && particle.position.y - dy <= 10) && !(particle.position.x - dx >= -10 && particle.position.x - dx <= 10)) { super.draw(spriteBatch); } else { particle.life = 0; } } else { particles.removeIndex(i); freeParticles.free(particle); } } }
/** End applying multiple animations to the instance and update it to reflect the changes. */ protected void end() { if (!applying) throw new GdxRuntimeException("You must call begin() first"); for (Entry<Node, Transform> entry : transforms.entries()) { entry.value.toMatrix4(entry.key.localTransform); transformPool.free(entry.value); } transforms.clear(); target.calculateTransforms(); applying = false; }
public void clearTrack(int trackIndex) { if (trackIndex >= tracks.size) return; TrackEntry current = tracks.get(trackIndex); if (current == null) return; if (current.listener != null) current.listener.end(trackIndex); for (int i = 0, n = listeners.size; i < n; i++) listeners.get(i).end(trackIndex); tracks.set(trackIndex, null); freeAll(current); if (current.previous != null) trackEntryPool.free(current.previous); }
public void apply(Skeleton skeleton) { Array<Event> events = this.events; int listenerCount = listeners.size; for (int i = 0; i < tracks.size; i++) { TrackEntry current = tracks.get(i); if (current == null) continue; events.size = 0; float time = current.time; float lastTime = current.lastTime; float endTime = current.endTime; boolean loop = current.loop; if (!loop && time > endTime) time = endTime; TrackEntry previous = current.previous; if (previous == null) current.animation.mix(skeleton, lastTime, time, loop, events, current.mix); else { float previousTime = previous.time; if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime; previous.animation.apply(skeleton, previousTime, previousTime, previous.loop, null); float alpha = current.mixTime / current.mixDuration * current.mix; if (alpha >= 1) { alpha = 1; trackEntryPool.free(previous); current.previous = null; } current.animation.mix(skeleton, lastTime, time, loop, events, alpha); } for (int ii = 0, nn = events.size; ii < nn; ii++) { Event event = events.get(ii); if (current.listener != null) current.listener.event(i, event); for (int iii = 0; iii < listenerCount; iii++) listeners.get(iii).event(i, event); } // Check if completed the animation or a loop iteration. if (loop ? (lastTime % endTime > time % endTime) : (lastTime < endTime && time >= endTime)) { int count = (int) (time / endTime); if (current.listener != null) current.listener.complete(i, count); for (int ii = 0, nn = listeners.size; ii < nn; ii++) listeners.get(ii).complete(i, count); } current.lastTime = current.time; } }
public static <T extends GameObject> void removeOutOfBounds( Pool<T> pool, Array<T> gos, Rectangle bounds) { float minX = bounds.x; float maxX = minX + bounds.width; float minY = bounds.y; float maxY = minY + bounds.height; for (int i = gos.size - 1; i >= 0; i--) { T go = gos.get(i); if (go.getX() >= maxX || go.getX() + go.width <= minX || go.getY() >= maxY || go.getY() + go.getHeight() <= minY) { gos.removeIndex(i); pool.free(go); } } }
public void remove(Array<RobotNinjas> robotNinjases) { if (body.getUserData() == Constants.deadID) { robotNinjases.removeValue(this, true); robotNinjasPool.free(this); } if (body.getPosition().x < 0 - width) { body.setUserData(Constants.deadID); if (!dead) { Constants.currentScoreValue++; Constants.standardVelocity.x += Constants.globalAcceleration; Constants.ninjaVelocity.x += Constants.globalAcceleration; Constants.globalAcceleration -= Constants.globalAccelerationDecline; } dead = true; } }
@Override public void free() { if (pool != null) pool.free(this); reset(); }
public void free(SnapperView view) { synchronized (activeSnappers) { activeSnappers.removeValue(view, true); snapperViewPool.free(view); } }
@Override public void free() { POOL.free(this); }
@Override public void free() { rotationControllerPool.free(this); }
@Override public void free() { pool.free(this); }
void processEvents() { synchronized (this) { justTouched = false; if (processor != null) { final InputProcessor processor = this.processor; int len = keyEvents.size(); for (int i = 0; i < len; i++) { KeyEvent e = keyEvents.get(i); currentEventTimeStamp = e.timeStamp; switch (e.type) { case KeyEvent.KEY_DOWN: processor.keyDown(e.keyCode); break; case KeyEvent.KEY_UP: processor.keyUp(e.keyCode); break; case KeyEvent.KEY_TYPED: processor.keyTyped(e.keyChar); } usedKeyEvents.free(e); } len = touchEvents.size(); for (int i = 0; i < len; i++) { TouchEvent e = touchEvents.get(i); currentEventTimeStamp = e.timeStamp; switch (e.type) { case TouchEvent.TOUCH_DOWN: processor.touchDown(e.x, e.y, e.pointer, Buttons.LEFT); justTouched = true; break; case TouchEvent.TOUCH_UP: processor.touchUp(e.x, e.y, e.pointer, Buttons.LEFT); break; case TouchEvent.TOUCH_DRAGGED: processor.touchDragged(e.x, e.y, e.pointer); } usedTouchEvents.free(e); } } else { int len = touchEvents.size(); for (int i = 0; i < len; i++) { TouchEvent e = touchEvents.get(i); if (e.type == TouchEvent.TOUCH_DOWN) justTouched = true; usedTouchEvents.free(e); } len = keyEvents.size(); for (int i = 0; i < len; i++) { usedKeyEvents.free(keyEvents.get(i)); } } if (touchEvents.size() == 0) { for (int i = 0; i < deltaX.length; i++) { deltaX[0] = 0; deltaY[0] = 0; } } keyEvents.clear(); touchEvents.clear(); } }
/** * delete the native object if required and allow the instance to be reused by the obtain method */ public static void free(final btManifoldPoint inst) { inst.dispose(); pool.free(inst); }