Java Code Examples for com.badlogic.gdx.utils.Pools#free()

The following examples show how to use com.badlogic.gdx.utils.Pools#free() . 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: ControllerMenuStage.java    From gdx-controllerutils with Apache License 2.0 6 votes vote down vote up
protected boolean fireEventOnActor(Actor actor, InputEvent.Type type, int pointer, Actor related) {
    if (actor == null || !isActorFocusable(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(pointer);
    event.setStageX(0);
    event.setStageY(0);

    actor.fire(event);

    boolean handled = event.isHandled();
    Pools.free(event);
    return handled;
}
 
Example 2
Source File: Scene2dUtils.java    From gdx-vfx with Apache License 2.0 6 votes vote down vote up
public static void simulateClickGlobal(Actor actor, int button, int pointer, float stageX, float stageY) {
    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(actor.getStage());
    event.setRelatedActor(actor);
    event.setTarget(actor);
    event.setStageX(stageX);
    event.setStageY(stageY);
    event.setButton(button);
    event.setPointer(pointer);

    event.setType(InputEvent.Type.touchDown);
    actor.notify(event, false);
    event.setType(InputEvent.Type.touchUp);
    actor.notify(event, false);

    Pools.free(event);
}
 
Example 3
Source File: GameServicesMultiplayer.java    From dice-heroes with GNU General Public License v3.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example 4
Source File: ProgressBar.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: SeekBar.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Called by {@link SeekBarModel}. Notifies when underlying model value has changed and text field and slider must update.
 * Typically there is no need to call this method manually.
 * @param fireEvent if true then {@link ChangeListener.ChangeEvent} will be fired
 */
public void notifyValueChanged (boolean updateTextField, boolean updateSlider, boolean fireEvent) {
    if (updateTextField) {
        VisValidatableTextField textField = getTextField();
        int cursor = textField.getCursorPosition();
        textField.setCursorPosition(0);
        this.setListenTextChangeEvents(false);
        textField.setText(model.prepareTextValue());
        this.setListenTextChangeEvents(true);
        textField.setCursorPosition(cursor);
    }

    if (updateSlider) {
        VisSlider slider = getSlider();
        this.setListenSliderChangeEvents(false);
        slider.setValue(model.prepareSliderValue());
        this.setListenSliderChangeEvents(true);
    }

    if (fireEvent) {
        ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class);
        fire(changeEvent);
        Pools.free(changeEvent);
    }
}
 
Example 6
Source File: Scene2dUtils.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public static void simulateClickGlobal(Actor actor, int button, int pointer, float stageX, float stageY) {
    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(actor.getStage());
    event.setRelatedActor(actor);
    event.setTarget(actor);
    event.setStageX(stageX);
    event.setStageY(stageY);
    event.setButton(button);
    event.setPointer(pointer);

    event.setType(InputEvent.Type.touchDown);
    actor.notify(event, false);
    event.setType(InputEvent.Type.touchUp);
    actor.notify(event, false);

    Pools.free(event);
}
 
Example 7
Source File: EventUtils.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public static boolean click(Button button) {
  if (button.isDisabled()) return false;
  InputEvent event = Pools.obtain(InputEvent.class);
  event.setType(InputEvent.Type.touchDown);
  event.setStage(button.getStage());
  event.setStageX(0);
  event.setStageY(0);
  event.setPointer(0);
  event.setButton(Input.Buttons.LEFT);
  event.setListenerActor(button);
  button.fire(event);

  event.setType(InputEvent.Type.touchUp);
  button.fire(event);
  Pools.free(event);
  return true;
}
 
Example 8
Source File: TabbedPane.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Sends a ChangeEvent, with this TabbedPane as the target, to each registered listener. This method is called each time there
 * is a change to the selected index. */
protected void fireStateChanged () {
	ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
	changeEvent.setBubbles(false);
	fire(changeEvent);
	Pools.free(changeEvent);
}
 
Example 9
Source File: ChainLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contains(float x, float y) {
	// fast fail
	if (!this.chainLightBounds.contains(x, y))
		return false;
	// actual check
	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]);
	}
	
	int intersects = 0;
	for (int i = 0; i < vertices.size; i += 2) {
		float x1 = vertices.items[i];
		float y1 = vertices.items[i + 1];
		float x2 = vertices.items[(i + 2) % vertices.size];
		float y2 = vertices.items[(i + 3) % vertices.size];
		if (((y1 <= y && y < y2) || (y2 <= y && y < y1)) &&
				x < ((x2 - x1) / (y2 - y1) * (y - y1) + x1))
			intersects++;
	}
	boolean result = (intersects & 1) == 1;

	Pools.free(vertices);
	return result;
}
 
Example 10
Source File: ChainLight.java    From box2dlights with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a polygon, using ray start and end points as vertices
 */
public void debugRender(ShapeRenderer shapeRenderer) {
	shapeRenderer.setColor(Color.YELLOW);
	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]);
	}
	shapeRenderer.polygon(vertices.shrink());
	Pools.free(vertices);
}
 
Example 11
Source File: ChannelBar.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void updateValueFromTouch (float x) {
	int newValue = (int) (x / BasicColorPicker.BAR_WIDTH * maxValue / sizes.scaleFactor);
	setValue(newValue);

	ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
	fire(changeEvent);
	Pools.free(changeEvent);
}
 
Example 12
Source File: Palette.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void updateValueFromTouch (float touchX, float touchY) {
	int newV = (int) (touchX / BasicColorPicker.PALETTE_SIZE * maxValue / sizes.scaleFactor);
	int newS = (int) (touchY / BasicColorPicker.PALETTE_SIZE * maxValue / sizes.scaleFactor);

	setValue(newS, newV);

	ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
	fire(changeEvent);
	Pools.free(changeEvent);
}
 
Example 13
Source File: VerticalChannelBar.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
private void updateValueFromTouch (float y) {
	int newValue = (int) (y / BasicColorPicker.PALETTE_SIZE * maxValue / sizes.scaleFactor);
	setValue(newValue);

	ChangeEvent changeEvent = Pools.obtain(ChangeEvent.class);
	fire(changeEvent);
	Pools.free(changeEvent);
}
 
Example 14
Source File: Spinner.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Called by {@link SpinnerModel}. Notifies when underlying model value has changed and spinner text field must updated.
 * Typically there is no need to call this method manually.
 * @param fireEvent if true then {@link ChangeListener.ChangeEvent} will be fired
 */
public void notifyValueChanged (boolean fireEvent) {
	VisValidatableTextField textField = getTextField();
	int cursor = textField.getCursorPosition();
	textField.setCursorPosition(0);
	textField.setText(model.getText());
	textField.setCursorPosition(cursor);

	if (fireEvent) {
		ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class);
		fire(changeEvent);
		Pools.free(changeEvent);
	}
}
 
Example 15
Source File: RenderedConsole.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void render(Batch b) {
  if (!visible || font == null) return;

  b.draw(modalBackground, 0, consoleY - 4, clientWidth, consoleHeight + 4);

  final int x = 2;
  String inputContents = in.getContents();
  GlyphLayout glyphs = font.draw(b, BUFFER_PREFIX + inputContents, x, bufferY - 2);
  b.draw(cursorTexture, x, bufferY, clientWidth, 2);
  if (showCaret) {
    final int caret = in.getCaretPosition();
    if (caret != in.length()) {
      glyphs.setText(font, BUFFER_PREFIX + inputContents.substring(0, caret));
    }

    b.draw(cursorTexture, x + glyphs.width, consoleY - 2, 2, textHeight);
  }
  Pools.free(glyphs);

  final float outputOffset = scrollOffset * lineHeight;
  if (outputOffset < outputHeight) {
    // offsets output to always appear that it starts at top of console window
    scrollOffset = Math.max(scrollOffset, scrollOffsetMin);
  }

  float position = outputY;
  final int outputSize = OUTPUT.size;
  if (scrollOffset > outputSize) {
    scrollOffset = outputSize;
    position += ((scrollOffsetMin - scrollOffset) * lineHeight);
  }

  for (int i = scrollOffset - 1; i >= 0; i--) {
    if (position > clientHeight) break;
    String line = OUTPUT.get(i);
    font.draw(b, line, x, position);
    position += lineHeight;
  }
}
 
Example 16
Source File: ParticleActor.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    effect.setPosition(getX(), getY());
    Color c = getColor();
    batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
    effect.draw(batch, Gdx.graphics.getDeltaTime());
    if (effect.isComplete()) {
        ChangeListener.ChangeEvent event = Pools.obtain(ChangeListener.ChangeEvent.class);
        fire(event);
        Pools.free(event);
    }
}
 
Example 17
Source File: SpawnController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void autoPlace() {
    if (placed.size > 0) {
        ObjectSet<Creature> tmp = Pools.obtain(ObjectSet.class);
        tmp.addAll(placed);
        for (Creature c : tmp) {
            removeFromPlaced(c);
        }
        tmp.clear();
        Pools.free(tmp);
    }
    Array<Grid2D.Coordinate> coordinates = Pools.obtain(Array.class);
    Set<Map.Entry<Grid2D.Coordinate, Fraction>> spawns = world.level.getElements(LevelElementType.spawn);
    for (Map.Entry<Grid2D.Coordinate, Fraction> e : spawns) {
        if (e.getValue() == world.viewer.fraction) {
            coordinates.add(e.getKey());
        }
    }
    coordinates.shuffle();
    int usedCount = Math.min(creatures.size, coordinates.size);
    Array<Creature> toPlace = Pools.obtain(Array.class);
    toPlace.addAll(creatures);
    toPlace.shuffle();
    toPlace.truncate(usedCount);
    for (Creature creature : toPlace) {
        Grid2D.Coordinate coordinate = coordinates.pop();
        place(creature, coordinate.x(), coordinate.y());
    }
    toPlace.clear();
    coordinates.clear();
    Pools.free(toPlace);
    Pools.free(coordinates);
}
 
Example 18
Source File: MenuItem.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
void fireChangeEvent () {
	ChangeListener.ChangeEvent changeEvent = Pools.obtain(ChangeListener.ChangeEvent.class);
	fire(changeEvent);
	Pools.free(changeEvent);
}
 
Example 19
Source File: Entity.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public void drawDebugStatus(PaletteIndexedBatch batch, ShapeRenderer shapes) {
  float x = screen.x;
  float y = screen.y;
  if (animation != null && isSelectable()) animation.drawDebug(shapes, x, y);

  shapes.setColor(Color.WHITE);
  DebugUtils.drawDiamond(shapes, x, y, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);
  //shapes.ellipse(x - Tile.SUBTILE_WIDTH50, y - Tile.SUBTILE_HEIGHT50, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);

  final float R = 32;
  shapes.setColor(Color.RED);
  shapes.line(x, y, x + MathUtils.cos(angle) * R, y + MathUtils.sin(angle) * R);

  if (animation != null) {
    int numDirs = animation.getNumDirections();
    float rounded = Direction.snapToDirection(angle, numDirs);
    shapes.setColor(Color.GREEN);
    shapes.line(x, y, x + MathUtils.cos(rounded) * R * 0.5f, y + MathUtils.sin(rounded) * R * 0.5f);
  }

  shapes.end();
  batch.begin();
  batch.setShader(null);
  StringBuilder builder = new StringBuilder(64)
      .append(classname).append('\n')
      .append(token).append(' ').append(type.MODE[mode]).append(' ').append(WCLASS[wclass]).append('\n');
  if (animation != null) {
    builder
        .append(StringUtils.leftPad(Integer.toString(animation.getFrame()), 2))
        .append('/')
        .append(StringUtils.leftPad(Integer.toString(animation.getNumFramesPerDir() - 1), 2))
        .append(' ')
        .append(animation.getFrameDelta())
        .append('\n');
  }
  appendToStatus(builder);
  GlyphLayout layout = Riiablo.fonts.consolas12.draw(batch, builder.toString(), x, y - Tile.SUBTILE_HEIGHT50, 0, Align.center, false);
  Pools.free(layout);
  batch.end();
  batch.setShader(Riiablo.shader);
  shapes.begin(ShapeRenderer.ShapeType.Line);
}
 
Example 20
Source File: AStar.java    From dice-heroes with GNU General Public License v3.0 4 votes vote down vote up
private static void cleanUp() {
    for (Node n : nodes.values()) {
        Pools.free(n);
    }
    nodes.clear();
}