Java 类com.badlogic.gdx.utils.Pools 实例源码

项目:Mindustry    文件:Renderer.java   
void drawPlayerNames(){
GlyphLayout layout = Pools.obtain(GlyphLayout.class);

      Draw.tscl(0.25f/2);
   for(Player player : Vars.control.playerGroup.all()){
      if(!player.isLocal){
        layout.setText(Core.font, player.name);
        Draw.color(0f, 0f, 0f, 0.3f);
        Draw.rect("blank", player.x, player.y + 8 - layout.height/2, layout.width + 2, layout.height + 2);
        Draw.color();
        Draw.tcolor(NetClient.colorArray[player.id % NetClient.colorArray.length]);
           Draw.text(player.name, player.x, player.y + 8);
           Draw.tcolor();
          }
      }
Pools.free(layout);
      Draw.tscl(Vars.fontscale);
  }
项目:gdx-controllerutils    文件:ControllerMenuStage.java   
protected boolean fireEventOnActor(Actor actor, InputEvent.Type type, int pointer, Actor related) {
    if (actor == null || !isActorFocussable(actor) || !isActorHittable(actor))
        return false;

    InputEvent event = Pools.obtain(InputEvent.class);
    event.setType(type);
    event.setStage(this);
    event.setRelatedActor(related);
    event.setPointer(pointer);
    event.setButton(-1);

    actor.fire(event);

    boolean handled = event.isHandled();
    Pools.free(event);
    return handled;
}
项目:gdxjam-ugg    文件:EngineController.java   
public void removeGameEntity(GameEntity gameEntity){
    final Entity entity = gameEntity.entity;
    final PhysicsComponent phyC = Mappers.physics.get(entity);
    final RenderableComponent renderableC = Mappers.renderable.get(entity);
    final LifeBarComponent lifeBarComponent = Mappers.lifeBar.get(entity);
    if(renderableC != null){
        renderableC.renderable.remove();
    }
    if(lifeBarComponent != null){
        lifeBarComponent.lifeBar.remove();
    }
    if(phyC != null){
        final Body body = phyC.body;
        physicsCtrl.destroyBody(body);
    }
    Pools.free(gameEntity);
}
项目:kreativity-ui    文件:KrComboBox.java   
@Override
protected void drawSelf(KrRenderer renderer) {
    if (popupMenu.isShowing()) {
        renderer.setBrush(((KrComboBoxStyle) getStyle()).pressedBackground);
    } else {
        renderer.setBrush(((KrComboBoxStyle) getStyle()).background);
    }

    renderer.fillRect(0, 0, getWidth(), getHeight());

    rectangles(0, 0, getWidth(), getHeight()).shrink(getPadding()).value(tmpRect);
    Vector2 pTextPosition = KrAlignmentTool.alignRectangles(text.getBounds(), tmpRect, KrAlignment.MIDDLE_LEFT);

    renderer.setPen(1, getForeground());
    renderer.drawText(text.getString(), pTextPosition);

    Pools.free(pTextPosition);
}
项目:kreativity-ui    文件:KrSplitPanel.java   
@Override
protected void drawSelf(KrRenderer renderer) {
    Drawable grip = ((KrSplitPanelStyle) KrSplitPanel.this.getStyle()).splitterGrip;

    Rectangle gripRectangle = Pools.obtain(Rectangle.class).set(0, 0, grip.getMinWidth(), grip.getMinHeight());
    Rectangle geometryRectangle = Pools.obtain(Rectangle.class).set(0, 0, getWidth(), getHeight());
    Vector2 gripPosition = alignRectangles(gripRectangle, geometryRectangle, MIDDLE_CENTER);
    gripRectangle.setPosition(gripPosition);

    renderer.setBrush(grip);
    renderer.fillRect(gripRectangle);

    Pools.free(getGeometry());
    Pools.free(geometryRectangle);
    Pools.free(gripRectangle);
}
项目:kreativity-ui    文件:KrLabel.java   
@Override
protected void drawSelf(KrRenderer renderer) {
    boolean componentClip = renderer.beginClip(0, 0, getWidth(), getHeight());

    renderer.setBrush(getStyle().background);
    renderer.fillRect(0, 0, getWidth(), getHeight());

    text.getBounds(tmpRect);
    Rectangle alignmentReference = rectangles(0.0f, 0.0f, getWidth(), getHeight()).shrink(getPadding()).value();
    Vector2 textPosition = KrAlignmentTool.alignRectangles(tmpRect, alignmentReference, getTextAlignment());
    renderer.setPen(1, getStyle().foregroundColor);
    renderer.setFont(getStyle().font);
    renderer.drawText(text.getString(), textPosition);

    if (componentClip) {
        renderer.endClip();
    }

    Pools.free(textPosition);
    Pools.free(alignmentReference);
}
项目:kreativity-ui    文件:KrTextField.java   
@ReturnsPooledObject
private Rectangle getSelectionRect(float textPositionX) {

    KrFontMetrics metrics = getDefaultToolkit().fontMetrics();
    String text = textDocument.getText();

    float selectionStartX = textPositionX + metrics.bounds(getStyle().font, text.substring(0, textDocument.getSelectionBegin()), tmpRect).getWidth();
    float selectionEndX = textPositionX + metrics.bounds(getStyle().font, text.substring(0, textDocument.getSelectionEnd()), tmpRect).getWidth();
    float selectionWidth = selectionEndX - selectionStartX;

    return Pools.obtain(Rectangle.class).set(
            selectionStartX,
            CARET_TOP_OFFSET,
            selectionWidth + 1,
            CARET_HEIGHT);
}
项目:kreativity-ui    文件:KrTextField.java   
private void recalculateTextOffset() {
    KrFontMetrics metrics = getDefaultToolkit().fontMetrics();
    float textPositionX = getX() + getPadding().left - textOffset;
    float caretXPosition = textPositionX + metrics.bounds(getStyle().font, textDocument.getTextBeforeCaret(), tmpRect).width;
    float textWidth = metrics.bounds(getStyle().font, textDocument.getText(), tmpRect).width;

    Rectangle innerViewport = rectangles(getGeometry(tmpRect)).shrink(getPadding()).value();
    if (innerViewport.getWidth() > textWidth) {
        textOffset = 0;
        return;
    }

    if (caretXPosition <= innerViewport.x) {
        textOffset -= innerViewport.x - caretXPosition;
    }

    if (caretXPosition >= innerViewport.x + innerViewport.width) {
        textOffset += caretXPosition - (innerViewport.x + innerViewport.width) + 1;
    }

    Pools.free(innerViewport);
}
项目:kreativity-ui    文件:KrGridLayout.java   
private void layoutInsideCell(KrWidget widget, Rectangle cellBounds) {
    Constraint constraint = constraints.get(widget);
    Vector2 widgetPreferredSize = widget.getPreferredSize();

    int widgetWidth = (widgetPreferredSize.x >= cellBounds.width) ? (int) cellBounds.width : (int) widgetPreferredSize.x;
    int widgetHeight = (widgetPreferredSize.y >= cellBounds.height) ? (int) cellBounds.height : (int) widgetPreferredSize.y;

    if (constraint.stretchHorizontal) {
        widgetWidth = (int) cellBounds.width;
    }

    if (constraint.stretchVertical) {
        widgetHeight = (int) cellBounds.height;
    }

    Vector2 widgetPosition = KrAlignmentTool.alignRectangles(new Rectangle(0, 0, widgetWidth, widgetHeight), cellBounds, constraint.alignment);

    widget.setGeometry((int) widgetPosition.x, (int) widgetPosition.y, widgetWidth, widgetHeight);
    Pools.free(widgetPosition);
}
项目:space-travels-3    文件:GameScreen.java   
private void updateShipProjection()
{
    if (this.shipProjection != null)
    {
        Pools.free(this.shipProjection);
    }

    if (this.level.getGameState() == GameState.PLAY
        || this.level.getGameState() == GameState.COUNTDOWN
        || this.level.getGameState() == GameState.PAUSE
        )
    {
        ArrayList<ProjectionPoint> projectionPoints = PhysicsEngine.gravityProjection(
            this.level.getShip().physicsComponent,
            this.level.getTrajectorySeconds(),
            Constants.Visual.HUD.TrajectoryLine.POINTS_TIME);

        this.shipProjection = this.level.processProjection(projectionPoints);
    }
    else
    {
        this.shipProjection = null;
    }
}
项目:space-travels-3    文件:GameScreen.java   
@Override
public void dispose()
{
    BackgroundPositionManager.setBackgroundPositionController(new RandomBackgroundPositionController());
    GameEntityManager.dispose();
    Constants.General.EVENT_BUS.unregister(this);
    ScreenManager.removeScreen(this.hudScreen);

    this.level.dispose();

    AssMan.getGameAssMan().clear();

    PhysicsEngine.dispose();

    if (this.shipProjection != null)
    {
        Pools.free(this.shipProjection);
    }
}
项目:dice-heroes    文件:DiceHeroes.java   
Array<RewardResult> applyLevelResult(BaseLevelDescription level, LevelResult result, boolean isWin) {
    Array<RewardResult> results = new Array<RewardResult>();
    if (isWin) {
        boolean isFirstPass = !userData.isPassed(level);
        Array<Reward> rewards = isFirstPass ? level.passRewards : level.confirmRewards;
        for (Reward reward : rewards) {
            results.add(reward.apply(userData));
        }
        userData.addLevelToPassed(level);
    }
    for (Die die : result.addedExperience.keys()) {
        die.exp += result.addedExperience.get(die, 0);
    }
    Config.achievements.fire(
        EventType.endLevel,
        Pools.obtain(EndLevelEvent.class).level(level).win(isWin).result(result)
    );
    for (Item item : result.viewer.earnedItems.keys()) {
        int count = result.viewer.earnedItems.get(item, 0);
        userData.incrementItemCount(item, count);
        Config.achievements.fire(EventType.earnItem, Pools.obtain(EarnEvent.class).item(item).count(count));
    }
    userData.setPotions(result.viewer.potions);
    save();
    return results;
}
项目:dice-heroes    文件:GameServicesMultiplayer.java   
@SuppressWarnings("unchecked")
public void loadInvitations(InvitationBuffer invitations) {
    ObjectSet<String> tmp = Pools.obtain(ObjectSet.class);
    tmp.addAll(invites);
    invites.clear();
    for (Invitation invitation : invitations) {
        invites.add(invitation.getInvitationId());
        if (!tmp.contains(invitation.getInvitationId())) {
            showInvitation(invitation);
        }
    }
    tmp.clear();
    Pools.free(tmp);
    Gdx.app.postRunnable(new Runnable() {
        @Override public void run() {
            invitesDispatcher.setState(invites.size);
        }
    });
}
项目:RavTech    文件:RavChainLight.java   
/** Draws a polygon, using ray start and end points as vertices */
public void debugRender (PolygonShapeRenderer shapeRenderer) {
    shapeRenderer.setColor(Color.BLUE);
    FloatArray vertices = Pools.obtain(FloatArray.class);
    vertices.clear();
    for (int i = 0; i < rayNum; i++) {
        vertices.addAll(mx[i], my[i]);
    }
    for (int i = rayNum - 1; i > -1; i--) {
        vertices.addAll(startX[i], startY[i]);
    }
    vertices.add(vertices.get(0));
    vertices.add(vertices.get(1));
    shapeRenderer.polyline(vertices.shrink());
    Pools.free(vertices);
}
项目:cocos-ui-libgdx    文件:ProgressBar.java   
/**
 * Sets the progress bar position, rounded to the nearest step size and clamped to the minumum and maximim values.
 * {@link #clamp(float)} can be overidden to allow values outside of the progress bars min/max range.
 *
 * @return false if the value was not changed because the progress bar already had the value or it was canceled by a listener.
 */
public boolean setValue(float value) {
    value = snap(clamp(Math.round(value / stepSize) * stepSize));
    float oldValue = this.value;
    if (value == oldValue) {
        return false;
    }
    float oldVisualValue = getVisualValue();
    this.value = value;
    ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
    boolean cancelled = fire(changeEvent);
    if (cancelled) {
        this.value = oldValue;
    } else if (animateDuration > 0) {
        animateFromValue = oldVisualValue;
        animateTime = animateDuration;
    }
    Pools.free(changeEvent);
    return !cancelled;
}
项目:libgdxjam    文件:AnimationStatePR.java   
/** 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 = Pools.obtain(TrackEntry.class);
    entry.animation = animation;
    entry.loop = loop;
    entry.endTime = animation != null ? animation.getDuration() : data.defaultMix;

    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) {
            float mix = animation != null ? data.getMix(last.animation, animation) : data.defaultMix;
            delay += last.endTime - mix;
        } else
            delay = 0;
    }
    entry.delay = delay;

    return entry;
}
项目:SpaceShooter    文件:AnimationStatePR.java   
/** 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 = Pools.obtain(TrackEntry.class);
    entry.animation = animation;
    entry.loop = loop;
    entry.endTime = animation != null ? animation.getDuration() : data.defaultMix;

    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) {
            float mix = animation != null ? data.getMix(last.animation, animation) : data.defaultMix;
            delay += last.endTime - mix;
        } else
            delay = 0;
    }
    entry.delay = delay;

    return entry;
}
项目:libgdxcn    文件:ProgressBar.java   
/** Sets the progress bar position, rounded to the nearest step size and clamped to the minimum and maximum values.
 * {@link #clamp(float)} can be overridden to allow values outside of the progress bar's min/max range.
 * @return false if the value was not changed because the progress bar already had the value or it was canceled by a listener. */
public boolean setValue (float value) {
    value = clamp(Math.round(value / stepSize) * stepSize);
    if (!shiftIgnoresSnap || (!Gdx.input.isKeyPressed(Keys.SHIFT_LEFT) && !Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT)))
        value = snap(value);
    float oldValue = this.value;
    if (value == oldValue) return false;
    float oldVisualValue = getVisualValue();
    this.value = value;
    ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
    boolean cancelled = fire(changeEvent);
    if (cancelled)
        this.value = oldValue;
    else if (animateDuration > 0) {
        animateFromValue = oldVisualValue;
        animateTime = animateDuration;
    }
    Pools.free(changeEvent);
    return !cancelled;
}
项目:libgdxcn    文件:Stage.java   
private Actor fireEnterAndExit (Actor overLast, int screenX, int screenY, int pointer) {
    // Find the actor under the point.
    screenToStageCoordinates(tempCoords.set(screenX, screenY));
    Actor over = hit(tempCoords.x, tempCoords.y, true);
    if (over == overLast) return overLast;

    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(this);
    event.setStageX(tempCoords.x);
    event.setStageY(tempCoords.y);
    event.setPointer(pointer);
    // Exit overLast.
    if (overLast != null) {
        event.setType(InputEvent.Type.exit);
        event.setRelatedActor(over);
        overLast.fire(event);
    }
    // Enter over.
    if (over != null) {
        event.setType(InputEvent.Type.enter);
        event.setRelatedActor(overLast);
        over.fire(event);
    }
    Pools.free(event);
    return over;
}
项目:libgdxcn    文件:Stage.java   
/** Applies a mouse moved event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the event.
 * This event only occurs on the desktop. */
public boolean mouseMoved (int screenX, int screenY) {
    if (screenX < viewport.getScreenX() || screenX >= viewport.getScreenX() + viewport.getScreenWidth()) return false;
    if (Gdx.graphics.getHeight() - screenY < viewport.getScreenY()
        || Gdx.graphics.getHeight() - screenY >= viewport.getScreenY() + viewport.getScreenHeight()) return false;

    mouseScreenX = screenX;
    mouseScreenY = screenY;

    screenToStageCoordinates(tempCoords.set(screenX, screenY));

    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(this);
    event.setType(Type.mouseMoved);
    event.setStageX(tempCoords.x);
    event.setStageY(tempCoords.y);

    Actor target = hit(tempCoords.x, tempCoords.y, true);
    if (target == null) target = root;

    target.fire(event);
    boolean handled = event.isHandled();
    Pools.free(event);
    return handled;
}
项目:libgdxcn    文件:Stage.java   
/** Applies a mouse scroll event to the stage and returns true if an actor in the scene {@link Event#handle() handled} the
 * event. This event only occurs on the desktop. */
public boolean scrolled (int amount) {
    Actor target = scrollFocus == null ? root : scrollFocus;

    screenToStageCoordinates(tempCoords.set(mouseScreenX, mouseScreenY));

    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(this);
    event.setType(InputEvent.Type.scrolled);
    event.setScrollAmount(amount);
    event.setStageX(tempCoords.x);
    event.setStageY(tempCoords.y);
    target.fire(event);
    boolean handled = event.isHandled();
    Pools.free(event);
    return handled;
}
项目:libgdxcn    文件:Stage.java   
/** Sets the actor that will receive key events.
 * @param actor May be null. */
public void setKeyboardFocus (Actor actor) {
    if (keyboardFocus == actor) return;
    FocusEvent event = Pools.obtain(FocusEvent.class);
    event.setStage(this);
    event.setType(FocusEvent.Type.keyboard);
    Actor oldKeyboardFocus = keyboardFocus;
    if (oldKeyboardFocus != null) {
        event.setFocused(false);
        event.setRelatedActor(actor);
        oldKeyboardFocus.fire(event);
    }
    if (!event.isCancelled()) {
        keyboardFocus = actor;
        if (actor != null) {
            event.setFocused(true);
            event.setRelatedActor(oldKeyboardFocus);
            actor.fire(event);
            if (event.isCancelled()) setKeyboardFocus(oldKeyboardFocus);
        }
    }
    Pools.free(event);
}
项目:libgdxcn    文件:Stage.java   
/** Sets the actor that will receive scroll events.
 * @param actor May be null. */
public void setScrollFocus (Actor actor) {
    if (scrollFocus == actor) return;
    FocusEvent event = Pools.obtain(FocusEvent.class);
    event.setStage(this);
    event.setType(FocusEvent.Type.scroll);
    Actor oldScrollFocus = keyboardFocus;
    if (oldScrollFocus != null) {
        event.setFocused(false);
        event.setRelatedActor(actor);
        oldScrollFocus.fire(event);
    }
    if (!event.isCancelled()) {
        scrollFocus = actor;
        if (actor != null) {
            event.setFocused(true);
            event.setRelatedActor(oldScrollFocus);
            actor.fire(event);
            if (event.isCancelled()) setScrollFocus(oldScrollFocus);
        }
    }
    Pools.free(event);
}
项目:droidtowers    文件:TutorialEngine.java   
@Override
protected void complete(Achievement achievement) {
    TutorialStep tutorialStep = (TutorialStep) achievement;

    if (tutorialStep.isLocked() || tutorialStep.hasGivenReward() || tutorialStep.hasShownNotification()) {
        return;
    }

    tutorialStep.setCompleted(true);

    if (!tutorialStep.requiresTapToGiveReward()) {
        tutorialStep.giveReward();
    }

    if (enabled) {
        tutorialStep.shownNotification();
        new TutorialStepNotification(tutorialStep).show();

        AchievementCompletionEvent event = Pools.obtain(AchievementCompletionEvent.class);
        event.setAchievement(tutorialStep);
        eventBus.post(event);
        Pools.free(event);
    }
}
项目:droidtowers    文件:GameGrid.java   
public boolean addObject(GridObject gridObject) {

    Gdx.app.debug(TAG, "Adding new GridObject: " + gridObject);

    gridObjects.add(gridObject);

    int objectYPos = gridObject.getPosition().y;
    if (objectYPos > highestPoint) {
        highestPoint = objectYPos;
        if (highestPoint + TowerConsts.GAME_GRID_EXPAND_LAND_SIZE > gridSize.y) {
            gridSize.y = highestPoint + TowerConsts.GAME_GRID_EXPAND_LAND_SIZE;
            updateWorldSize(true);
        }
    }

    GridObjectAddedEvent event = Pools.obtain(GridObjectAddedEvent.class);
    event.setGridObject(gridObject);
    events().post(event);
    // Pools.free(event);
    gridObjects.getInstances().sort(GridObjectSort.byZIndex);

    return true;
}
项目:droidtowers    文件:MemoryTrackingAssetManager.java   
public MemoryTrackingAssetManager(FileResolverMultiplexer fileResolverMultiplexer) {
    super(fileResolverMultiplexer);

    currentMemory = 0;
    memoryPerFile = new HashMap<String, Integer>();
    eventBus = new SafeEventBus(MemoryTrackingAssetManager.class.getSimpleName());

    setErrorListener(new AssetErrorListener() {
        @Override
        public void error(AssetDescriptor asset, Throwable throwable) {
            AssetLoadErrorEvent event = Pools.obtain(AssetLoadErrorEvent.class);
            event.setFileName(asset.fileName);
            event.setType(asset.type);
            events().post(event);
            Pools.free(event);
        }
    });
}
项目:droidtowers    文件:ExpandLandOverlay.java   
private void expandLandToEast() {
    gameGrid.events().unregister(DroidTowersGame.getSoundController());
    gameGrid.getGridSize().x += GAME_GRID_EXPAND_LAND_SIZE;
    gameGrid.updateWorldSize(false);

    for (GridObject gridObject : gameGrid.getObjects()) {
        GridObjectBoundsChangeEvent event = Pools.obtain(GridObjectBoundsChangeEvent.class);
        event.setGridObject(gridObject);

        gridObject.setPosition(gridObject.getPosition());

        gridObject.broadcastEvent(event);
        Pools.free(event);
    }

    cameraController.panTo(gameGrid.getWorldSize().x, cameraController.getCamera().position.y, true);
    gameGrid.events().register(DroidTowersGame.getSoundController());
}
项目:Simple-Isometric-Game    文件:GeometryUtils.java   
/** @see #intersectSegments(float, float, float, float, float[], boolean, com.badlogic.gdx.utils.FloatArray) */
public static void intersectSegments(Vector2 a, Vector2 b, float[] segments, boolean polygon, Array<Vector2> intersections) {
    FloatArray fa = Pools.obtain(FloatArray.class);
    intersectSegments(a.x, a.y, b.x, b.y, segments, polygon, fa);
    if(fa.size < 1) {
        intersections.clear();
        Pools.free(fa);
        return;
    }
    intersections.ensureCapacity(fa.size / 2 - intersections.size);
    for(int i = 1; i < fa.size; i += 2)
        if(intersections.size > i / 2)
            intersections.get(i / 2).set(fa.get(i - 1), fa.get(i));
        else
            intersections.add(new Vector2(fa.get(i - 1), fa.get(i)));
    Pools.free(fa);
}
项目:Simple-Isometric-Game    文件:GeometryUtils.java   
/** @param segments the segments
 *  @param polygon if the segments represent a closed polygon
 *  @param intersections the array to store the intersections in */
public static void intersectSegments(float x1, float y1, float x2, float y2, float[] segments, boolean polygon, FloatArray intersections) {
    if(polygon && segments.length < 6)
        throw new IllegalArgumentException("a polygon consists of at least 3 points: " + segments.length);
    else if(segments.length < 4)
        throw new IllegalArgumentException("segments does not contain enough vertices to represent at least one segment: " + segments.length);
    if(segments.length % 2 != 0)
        throw new IllegalArgumentException("malformed segments; the number of vertices is not dividable by 2: " + segments.length);
    intersections.clear();
    Vector2 tmp = Pools.obtain(Vector2.class);
    for(int i = 0, n = segments.length - (polygon ? 0 : 2); i < n; i += 2) {
        float x3 = segments[i], y3 = segments[i + 1], x4 = wrapIndex(i + 2, segments), y4 = wrapIndex(i + 3, segments);
        if(Intersector.intersectSegments(x1, y1, x2, y2, x3, y3, x4, y4, tmp)) {
            intersections.add(tmp.x);
            intersections.add(tmp.y);
        }
    }
    Pools.free(tmp);
}
项目:Vloxlands    文件:DProgressBar.java   
public boolean setValue(float value) {
    value = clamp(Math.round(value / stepSize) * stepSize);
    if (!shiftIgnoresSnap || (!Gdx.input.isKeyPressed(Keys.SHIFT_LEFT) && !Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT))) value = snap(value);
    float oldValue = this.value;
    if (value == oldValue) return false;
    float oldVisualValue = getVisualValue();
    this.value = value;
    ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
    boolean cancelled = fire(changeEvent);
    if (cancelled) this.value = oldValue;
    else if (animateDuration > 0) {
        animateFromValue = oldVisualValue;
        animateTime = animateDuration;
    }
    Pools.free(changeEvent);
    return !cancelled;
}
项目:ingress-indonesia-dev    文件:Stage.java   
public boolean touchDown(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
{
  screenToStageCoordinates(this.stageCoords.set(paramInt1, paramInt2));
  InputEvent localInputEvent = (InputEvent)Pools.obtain(InputEvent.class);
  localInputEvent.setType(InputEvent.Type.touchDown);
  localInputEvent.setStage(this);
  localInputEvent.setStageX(this.stageCoords.x);
  localInputEvent.setStageY(this.stageCoords.y);
  localInputEvent.setPointer(paramInt3);
  localInputEvent.setButton(paramInt4);
  Object localObject = hit(this.stageCoords.x, this.stageCoords.y);
  if (localObject == null)
    localObject = this.root;
  ((Actor)localObject).fire(localInputEvent);
  boolean bool = localInputEvent.isHandled();
  Pools.free(localInputEvent);
  return bool;
}
项目:OverdriveGDX    文件:ShipEventHandler.java   
@SuppressWarnings("unchecked")
@Override
public void disposeEvent( OVDEvent e ) {
    if ( e.getClass() == ShipCreationEvent.class ) {
        Pools.get( ShipCreationEvent.class ).free( (ShipCreationEvent)e );
    }
    else if ( e.getClass() == ShipPropertyEvent.class ) {
        Pools.get( ShipPropertyEvent.class ).free( (ShipPropertyEvent)e );
    }
    else if ( e.getClass() == ShipRoomCreationEvent.class ) {
        Pools.get( ShipRoomCreationEvent.class ).free( (ShipRoomCreationEvent)e );
    }
    else if ( e.getClass() == ShipRoomImageChangeEvent.class ) {
        Pools.get( ShipRoomImageChangeEvent.class ).free( (ShipRoomImageChangeEvent)e );
    }
    else if ( e.getClass() == ShipLayoutRoomAddEvent.class ) {
        Pools.get( ShipLayoutRoomAddEvent.class ).free( (ShipLayoutRoomAddEvent)e );
    }
}
项目:ead    文件:CircleWrapper.java   
@Override
protected boolean intersectToSegment(Vector2 start, Vector2 end,
        Vector2 intersection) {
    Vector2 v = Pools.obtain(Vector2.class);
    if (circle.contains(start) && !circle.contains(end)) {
        v.set(end);
        v.sub(start);
    } else if (!circle.contains(start) && circle.contains(end)) {
        v.set(start);
        v.sub(end);
    } else {
        return false;
    }

    v.scl(circle.radius / v.len());

    getCenter(intersection);
    intersection.add(v);
    Pools.free(v);
    return true;
}
项目:ead    文件:BoundingAreaBuilder.java   
private static boolean processRenderer(EngineEntity entity,
        Group sceneContentGroup, Group group, Vector2 x, Vector2 y) {
    boolean hasRenderer = false;
    Vector2 tmp = Pools.obtain(Vector2.class);
    for (Polygon polygon : getColliders(entity)) {
        for (int i = 0; i < polygon.getVertices().length; i += 2) {
            tmp.set(polygon.getVertices()[i], polygon.getVertices()[i + 1]);
            group.localToAscendantCoordinates(sceneContentGroup, tmp);
            x.set(Math.min(tmp.x, x.x), Math.max(tmp.x, x.y));
            y.set(Math.min(tmp.y, y.x), Math.max(tmp.y, y.y));
            hasRenderer = true;
        }
    }
    Pools.free(tmp);
    return hasRenderer;
}
项目:ead    文件:DefaultGameView.java   
private void initKeyboardListener() {
    addListener(new InputListener() {
        final ComponentMapper<KeyPressedComponent> keyPressed = ComponentMapper
                .getFor(KeyPressedComponent.class);

        public boolean keyDown(InputEvent event, int keycode) {
            EngineEntity entity = getLayer(Layer.SCENE);
            if (!keyPressed.has(entity)) {
                entity.add(gameLoop
                        .createComponent(KeyPressedComponent.class));
            }
            KeyPressedComponent keyPressedComponent = entity
                    .getComponent(KeyPressedComponent.class);
            RuntimeKey runtimeKeyEvent = Pools.obtain(RuntimeKey.class);
            runtimeKeyEvent.setKeycode(keycode);
            runtimeKeyEvent.setAlt(UIUtils.alt());
            runtimeKeyEvent.setCtrl(UIUtils.ctrl());
            runtimeKeyEvent.setShift(UIUtils.shift());
            keyPressedComponent.getKeyEvents().add(runtimeKeyEvent);
            return true;
        }
    });

}
项目:ead    文件:EngineUtils.java   
/**
 * For a given actor computes and applies the transformation to keep the
 * same screen transformation in a new group
 * 
 * @param actor
 * @param parent
 */
public static void computeTransformFor(Actor actor, Group parent) {
    Vector2 tmp1 = Pools.obtain(Vector2.class);
    Vector2 tmp2 = Pools.obtain(Vector2.class);
    Vector2 tmp3 = Pools.obtain(Vector2.class);
    Vector2 tmp4 = Pools.obtain(Vector2.class);
    Vector2 tmp5 = Pools.obtain(Vector2.class);

    calculateBounds(actor, tmp4, tmp5);
    Vector2 o = tmp1.set(tmp4.x, tmp4.y);
    Vector2 t = tmp2.set(tmp4.x + tmp5.x, tmp4.y);
    Vector2 n = tmp3.set(tmp4.x, tmp4.y + tmp5.y);
    actor.localToAscendantCoordinates(parent, o);
    actor.localToAscendantCoordinates(parent, t);
    actor.localToAscendantCoordinates(parent, n);
    actor.setRotation(actor.getRotation() + actor.getParent().getRotation());
    applyTransformation(actor, o, t, n);

    Pools.free(tmp1);
    Pools.free(tmp2);
    Pools.free(tmp3);
    Pools.free(tmp4);
    Pools.free(tmp5);
}
项目:ead    文件:Accessor.java   
/**
 * Gets a wrapper for the given {@code parent} object, which must be of type
 * {@link Array} or {@link List}.
 * 
 * @param parent
 *            An {@link Array} or {@link List}.
 * @param fullId
 *            The fullId representing the object being resolved (e.g.
 *            "scene.children[2].scaleX"). For building accurate exception
 *            messages only.
 * @param start
 *            The current position being parsed at {@code fullId}. For
 *            building accurate exception messages only.
 * @return The wrapper
 */
private AbstractArrayWrapper obtainArrayWrapper(Object parent,
        String fullId, int start) {
    // Check parent is a List
    if (!(parent instanceof List) && !(parent instanceof Array)) {
        throw new AccessorException(
                fullId,
                "Object before position "
                        + start
                        + " should be of class java.util.List or com.badlogic.gdx.utils.Array. Otherwise the operator "
                        + LIST_SEPARATOR[0] + LIST_SEPARATOR[1]
                        + " cannot be used.");
    }

    AbstractArrayWrapper wrapper = null;
    if (parent instanceof List) {
        List list = (List) parent;
        wrapper = Pools.obtain(ListWrapper.class);
        ((ListWrapper) wrapper).set(list);
    } else if (parent instanceof Array) {
        Array array = (Array) parent;
        wrapper = Pools.obtain(ArrayWrapper.class);
        ((ArrayWrapper) wrapper).set(array);
    }
    return wrapper;
}
项目:ead    文件:NodeSystem.java   
@Override
public void processEntity(Entity entity, float delta) {
    NodeComponent nodeComponent = entity.getComponent(NodeComponent.class);

    if (!nodeComponent.isStarted()) {
        nodeComponent.start();

        nodeComponent.setCurrentNode(createNode(entity,
                nodeComponent.getConversation(),
                nodeComponent.getStartingNode()));
    }

    RuntimeNode runtimeNode = nodeComponent.getRuntimeNode();
    if (runtimeNode == null) {
        entity.remove(NodeComponent.class);
    } else if (runtimeNode.update(delta)) {
        int nextNode = runtimeNode.nextNode();
        nodeComponent.setCurrentNode(createNode(entity,
                nodeComponent.getConversation(), nextNode));
        Pools.free(runtimeNode);
    }
}
项目:ead    文件:NodeSystem.java   
private RuntimeNode createNode(Entity entity, Conversation conversation,
        int nodeId) {
    Node node = getNode(conversation, nodeId);
    Class runtimeClass = node == null ? null : nodeClasses.get(node
            .getClass());
    if (runtimeClass == null) {
        if (node != null) {
            Gdx.app.error("NodeSystem", "No node for " + node.getClass()
                    + ". Conversation will end.");
        }
        return null;
    }

    RuntimeNode runtimeNode = (RuntimeNode) Pools.obtain(runtimeClass);
    runtimeNode.setGameLoop(gameLoop);
    runtimeNode.setEntity(entity);
    runtimeNode.setConversation(conversation);
    runtimeNode.setNode(node);

    return runtimeNode;
}
项目:ead    文件:ChaseEntitySystem.java   
private void moveTowards(ChaseEntityComponent chaseEntityComponent,
        EngineEntity entity) {
    /*
     * Calculate target's velocity. Needed just in case the chase effect has
     * relative speed configured.
     */
    Vector2 targetVelocity = Pools.obtain(Vector2.class);
    getSpeedOfTrackedEntity(chaseEntityComponent, targetVelocity);

    // Calculate scalar speed
    float relSpeedX = targetVelocity.x * chaseEntityComponent.getSpeedX();
    float relSpeedY = targetVelocity.y * chaseEntityComponent.getSpeedY();
    Pools.free(targetVelocity);
    boolean isRelative = chaseEntityComponent.isRelativeSpeed()
            && (!MathUtils.isEqual(relSpeedX, 0, 0.05f) || !MathUtils
                    .isEqual(relSpeedY, 0, 0.05f));
    float speedX = Math.abs(isRelative ? relSpeedX : chaseEntityComponent
            .getSpeedX());
    float speedY = Math.abs(isRelative ? relSpeedY : chaseEntityComponent
            .getSpeedY());

    // Move
    move(entity, chaseEntityComponent.getTrackedEntity(), speedX, speedY,
            !chaseEntityComponent.isCenterDistance());
}