/** @param last May be null. */ private TrackEntry trackEntry( int trackIndex, Animation animation, boolean loop, TrackEntry last) { TrackEntry entry = trackEntryPool.obtain(); entry.trackIndex = trackIndex; entry.animation = animation; entry.loop = loop; entry.eventThreshold = 0; entry.attachmentThreshold = 0; entry.drawOrderThreshold = 0; entry.animationStart = 0; entry.animationEnd = animation.getDuration(); entry.animationLast = -1; entry.nextAnimationLast = -1; entry.delay = 0; entry.trackTime = 0; entry.trackLast = -1; entry.nextTrackLast = -1; entry.trackEnd = Float.MAX_VALUE; entry.timeScale = 1; entry.alpha = 1; entry.mixAlpha = 1; entry.mixTime = 0; entry.mixDuration = last == null ? 0 : data.getMix(last.animation, animation); return entry; }
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); } } }
public void addParticle(Vector2 position, Vector2 velocity, float life, float scale) { if (particles.size > maxParticle) return; if (Gdx.graphics.getFramesPerSecond() < 25 && !(this instanceof ExplosionParticleEmitter)) return; Particle particle = freeParticles.obtain(); particle.setup(position, velocity, life, scale); particles.add(particle); }
@Override public void onGamepadUpdated(int index) { Gamepad gamepad = Gamepad.getGamepad(index); GwtController controller = controllerMap.get(index); if (gamepad != null && controller != null) { // Determine what changed JsArrayNumber axes = gamepad.getAxes(); JsArrayNumber buttons = gamepad.getButtons(); synchronized (eventQueue) { for (int i = 0, j = axes.length(); i < j; i++) { float oldAxis = controller.getAxis(i); float newAxis = (float) axes.get(i); if (oldAxis != newAxis) { GwtControllerEvent event = eventPool.obtain(); event.type = GwtControllerEvent.AXIS; event.controller = controller; event.code = i; event.amount = newAxis; eventQueue.add(event); } } for (int i = 0, j = buttons.length(); i < j; i++) { float oldButton = controller.getButtonAmount(i); float newButton = (float) buttons.get(i); if (oldButton != newButton) { if ((oldButton < 0.5f && newButton < 0.5f) || (oldButton >= 0.5f && newButton >= 0.5f)) { controller.buttons.put(i, newButton); continue; } GwtControllerEvent event = eventPool.obtain(); event.type = newButton >= 0.5f ? GwtControllerEvent.BUTTON_DOWN : GwtControllerEvent.BUTTON_UP; event.controller = controller; event.code = i; event.amount = newButton; eventQueue.add(event); } } } } }
/** Set the current animation. Any queued animations are cleared. */ public TrackEntry setAnimation(int trackIndex, Animation animation, boolean loop) { TrackEntry current = expandToIndex(trackIndex); if (current != null) freeAll(current.next); TrackEntry entry = trackEntryPool.obtain(); entry.animation = animation; entry.loop = loop; entry.endTime = animation.getDuration(); setCurrent(trackIndex, entry); return entry; }
protected void postTap(int x, int y) { synchronized (this) { TouchEvent event = usedTouchEvents.obtain(); event.timeStamp = System.nanoTime(); event.pointer = 0; event.x = x; event.y = y; event.type = TouchEvent.TOUCH_DOWN; touchEvents.add(event); event = usedTouchEvents.obtain(); event.timeStamp = System.nanoTime(); event.pointer = 0; event.x = x; event.y = y; event.type = TouchEvent.TOUCH_UP; touchEvents.add(event); } Gdx.app.getGraphics().requestRendering(); }
@Override public void onGamepadDisconnected(int index) { GwtController controller = controllerMap.remove(index); if (controller != null) { synchronized (eventQueue) { GwtControllerEvent event = eventPool.obtain(); event.type = GwtControllerEvent.DISCONNECTED; event.controller = controller; eventQueue.add(event); } } }
@Override public void onGamepadConnected(int index) { Gamepad gamepad = Gamepad.getGamepad(index); GwtController controller = new GwtController(gamepad.getIndex(), gamepad.getId()); controllerMap.put(index, controller); synchronized (eventQueue) { GwtControllerEvent event = eventPool.obtain(); event.type = GwtControllerEvent.CONNECTED; event.controller = controller; eventQueue.add(event); } }
private void requestNewPathFinding( HierarchicalTiledNode startNode, HierarchicalTiledNode endNode, int pathIndex) { TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[pathIndex]; MyPathFinderRequest pfRequest = requestPool.obtain(); pfRequest.startNode = startNode; pfRequest.endNode = endNode; pfRequest.heuristic = heuristic; pfRequest.resultPath = path; pfRequest.pathIndex = pathIndex; pfRequest.responseMessageCode = PF_RESPONSE; MessageManager.getInstance().dispatchMessage(this, PF_REQUEST, pfRequest); }
/** * Helper method to apply one animation to either an objectmap for blending or directly to the * bones. */ protected static void applyAnimation( final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final Animation animation, final float time) { for (final NodeAnimation nodeAnim : animation.nodeAnimations) { final Node node = nodeAnim.node; node.isAnimated = true; // Find the keyframe(s) final int n = nodeAnim.keyframes.size - 1; int first = 0, second = -1; for (int i = 0; i < n; i++) { if (time >= nodeAnim.keyframes.get(i).keytime && time <= nodeAnim.keyframes.get(i + 1).keytime) { first = i; second = i + 1; break; } } // Apply the first keyframe: final Transform transform = tmpT; final NodeKeyframe firstKeyframe = nodeAnim.keyframes.get(first); transform.set(firstKeyframe.translation, firstKeyframe.rotation, firstKeyframe.scale); // Lerp the second keyframe if (second > first) { final NodeKeyframe secondKeyframe = nodeAnim.keyframes.get(second); final float t = (time - firstKeyframe.keytime) / (secondKeyframe.keytime - firstKeyframe.keytime); transform.lerp( secondKeyframe.translation, secondKeyframe.rotation, secondKeyframe.scale, t); } // Apply the transform, either directly to the bone or to out when blending if (out == null) transform.toMatrix4(node.localTransform); else { if (out.containsKey(node)) { if (alpha == 1.f) out.get(node).set(transform); else out.get(node).lerp(transform, alpha); } else { out.put(node, pool.obtain().set(transform)); } } } }
/** * Adds an animation to be played delay seconds after the current or last queued animation. * * @param delay May be <= 0 to use duration of previous animation minus any mix duration plus the * negative delay. */ public TrackEntry addAnimation(int trackIndex, Animation animation, boolean loop, float delay) { TrackEntry entry = trackEntryPool.obtain(); entry.animation = animation; entry.loop = loop; entry.endTime = animation.getDuration(); TrackEntry last = expandToIndex(trackIndex); if (last != null) { while (last.next != null) last = last.next; last.next = entry; } else tracks.set(trackIndex, entry); if (delay <= 0) { if (last != null) delay += last.endTime - data.getMix(last.animation, animation); else delay = 0; } entry.delay = delay; return entry; }
public static void getShapeParts( final Node node, final boolean applyTransform, final Array<ShapePart> out, final int offset, final Pool<ShapePart> pool) { final Matrix4 transform = applyTransform ? node.localTransform : idt; if (node.parts.size > 0) { ShapePart part = null; for (int i = offset, n = out.size; i < n; i++) { final ShapePart p = out.get(i); if (Arrays.equals(p.transform.val, transform.val)) { part = p; break; } } if (part == null) { part = pool.obtain(); part.parts.clear(); part.transform.set(transform); out.add(part); } for (int i = 0, n = node.parts.size; i < n; i++) part.parts.add(node.parts.get(i).meshPart); } if (node.hasChildren()) { final boolean transformed = applyTransform && !Arrays.equals(transform.val, idt.val); final int o = transformed ? out.size : offset; getShapeParts(node.getChildren(), out, o, pool); if (transformed) { for (int i = o, n = out.size; i < n; i++) { final ShapePart part = out.get(i); tmpM.set(part.transform); part.transform.set(transform).mul(tmpM); } } } }
@Override public boolean onKey(View v, int keyCode, android.view.KeyEvent e) { for (int i = 0, n = keyListeners.size(); i < n; i++) if (keyListeners.get(i).onKey(v, keyCode, e)) return true; synchronized (this) { KeyEvent event = null; if (e.getKeyCode() == android.view.KeyEvent.KEYCODE_UNKNOWN && e.getAction() == android.view.KeyEvent.ACTION_MULTIPLE) { String chars = e.getCharacters(); for (int i = 0; i < chars.length(); i++) { event = usedKeyEvents.obtain(); event.keyCode = 0; event.keyChar = chars.charAt(i); event.type = KeyEvent.KEY_TYPED; keyEvents.add(event); } return false; } char character = (char) e.getUnicodeChar(); // Android doesn't report a unicode char for back space. hrm... if (keyCode == 67) character = '\b'; switch (e.getAction()) { case android.view.KeyEvent.ACTION_DOWN: event = usedKeyEvents.obtain(); event.keyChar = 0; event.keyCode = e.getKeyCode(); event.type = KeyEvent.KEY_DOWN; // Xperia hack for circle key. gah... if (keyCode == android.view.KeyEvent.KEYCODE_BACK && e.isAltPressed()) { keyCode = Keys.BUTTON_CIRCLE; event.keyCode = keyCode; } keyEvents.add(event); keys.put(event.keyCode, null); break; case android.view.KeyEvent.ACTION_UP: event = usedKeyEvents.obtain(); event.keyChar = 0; event.keyCode = e.getKeyCode(); event.type = KeyEvent.KEY_UP; // Xperia hack for circle key. gah... if (keyCode == android.view.KeyEvent.KEYCODE_BACK && e.isAltPressed()) { keyCode = Keys.BUTTON_CIRCLE; event.keyCode = keyCode; } keyEvents.add(event); event = usedKeyEvents.obtain(); event.keyChar = character; event.keyCode = 0; event.type = KeyEvent.KEY_TYPED; keyEvents.add(event); if (keyCode == Keys.BUTTON_CIRCLE) keys.remove(Keys.BUTTON_CIRCLE); else keys.remove(e.getKeyCode()); } app.getGraphics().requestRendering(); } // circle button on Xperia Play shouldn't need catchBack == true if (keyCode == Keys.BUTTON_CIRCLE) return true; if (catchBack && keyCode == android.view.KeyEvent.KEYCODE_BACK) return true; if (catchMenu && keyCode == android.view.KeyEvent.KEYCODE_MENU) return true; return false; }
/** * Reuses a previous freed instance or creates a new instance and set it to reflect the specified * native object */ public static btManifoldPoint obtain(long cPtr, boolean own) { final btManifoldPoint result = pool.obtain(); result.reset(cPtr, own); return result; }
@Override public EnemyWeapon invoke() { return POOL.obtain(); }
/** * Returns a pooled debug rect that is automatically freed after drawing. The pool can be {@link * #debugRectPool accessed directly} to obtain debug rects that are not freed after drawing. */ public static DebugRect obtainRect() { DebugRect rect = debugRectPool.obtain(); usedRects.add(rect); return rect; }
public static SmallFish obtainSmallFish(TextureRegion region) { SmallFish fish = pool.obtain(); fish.setRegion(region); fish.setPosition(0, 0); return fish; }
private Vector3 tmp(float x, float y, float z) { final Vector3 result = vectorPool.obtain().set(x, y, z); vectorArray.add(result); return result; }