本文整理了Java中com.badlogic.gdx.utils.Pool
类的一些代码示例,展示了Pool
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pool
类的具体详情如下:
包路径:com.badlogic.gdx.utils.Pool
类名称:Pool
[英]A pool of objects that can be reused to avoid allocation.
[中]可以重用以避免分配的对象池。
代码示例来源:origin: libgdx/libgdx
public Node<E> obtain (Node<E> p, Node<E> n, E value, int index) {
Node<E> newNode = super.obtain();
newNode.p = p;
newNode.n = n;
newNode.value = value;
newNode.index = index;
return newNode;
}
}
代码示例来源:origin: libgdx/libgdx
/** Removes the tail of the list regardless of iteration status */
public T removeLast () {
if (tail == null) {
return null;
}
T payload = tail.payload;
size--;
Item<T> p = tail.prev;
pool.free(tail);
if (size == 0) {
head = null;
tail = null;
} else {
tail = p;
tail.next = null;
}
return payload;
}
代码示例来源:origin: libgdx/libgdx
private void clearDebugRects () {
if (debugRects == null) return;
DebugRect.pool.freeAll(debugRects);
debugRects.clear();
}
代码示例来源:origin: libgdx/libgdx
public void renderSkeleton (final Vector3 from, final Node node) {
final Vector3 pos = vectorPool.obtain();
node.globalTransform.getTranslation(pos);
shapeRenderer.setColor(node.isAnimated ? Color.RED : Color.YELLOW);
shapeRenderer.box(pos.x, pos.y, pos.z, 0.5f, 0.5f, 0.5f);
shapeRenderer.setColor(Color.WHITE);
shapeRenderer.line(from.x, from.y, from.z, pos.x, pos.y, pos.z);
for (Node child : node.getChildren())
renderSkeleton(pos, child);
vectorPool.free(pos);
}
代码示例来源:origin: libgdx/libgdx
private void getTiles (int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {
TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get("walls");
rectPool.freeAll(tiles);
tiles.clear();
for (int y = startY; y <= endY; y++) {
for (int x = startX; x <= endX; x++) {
Cell cell = layer.getCell(x, y);
if (cell != null) {
Rectangle rect = rectPool.obtain();
rect.set(x, y, 1, 1);
tiles.add(rect);
}
}
}
}
代码示例来源:origin: libgdx/libgdx
/** Removes all actors and cells from the table. */
public void clearChildren () {
Array<Cell> cells = this.cells;
for (int i = cells.size - 1; i >= 0; i--) {
Cell cell = cells.get(i);
Actor actor = cell.actor;
if (actor != null) actor.remove();
}
cellPool.freeAll(cells);
cells.clear();
rows = 0;
columns = 0;
if (rowDefaults != null) cellPool.free(rowDefaults);
rowDefaults = null;
implicitEndRow = false;
super.clearChildren();
}
代码示例来源:origin: libgdx/libgdx
@Override
public void clear () {
// Dispose every allocated instance because the templates may be changed
for (int i = 0, free = pool.getFree(); i < free; ++i) {
pool.obtain().dispose();
}
super.clear();
}
}
代码示例来源:origin: libgdx/libgdx
public void layout () {
BitmapFont font = style.font;
Drawable selectedDrawable = style.selection;
itemHeight = font.getCapHeight() - font.getDescent() * 2;
itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
prefWidth = 0;
Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
GlyphLayout layout = layoutPool.obtain();
for (int i = 0; i < items.size; i++) {
layout.setText(font, toString(items.get(i)));
prefWidth = Math.max(layout.width, prefWidth);
}
layoutPool.free(layout);
prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
prefHeight = items.size * itemHeight;
Drawable background = style.background;
if (background != null) {
prefWidth += background.getLeftWidth() + background.getRightWidth();
prefHeight += background.getTopHeight() + background.getBottomHeight();
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public void beforeGroup (int group, Array<Decal> contents) {
if (group == GROUP_BLEND) {
Gdx.gl.glEnable(GL20.GL_BLEND);
contents.sort(cameraSorter);
} else {
for (int i = 0, n = contents.size; i < n; i++) {
Decal decal = contents.get(i);
Array<Decal> materialGroup = materialGroups.get(decal.material);
if (materialGroup == null) {
materialGroup = arrayPool.obtain();
materialGroup.clear();
usedArrays.add(materialGroup);
materialGroups.put(decal.material, materialGroup);
}
materialGroup.add(decal);
}
contents.clear();
for (Array<Decal> materialGroup : materialGroups.values()) {
contents.addAll(materialGroup);
}
materialGroups.clear();
arrayPool.freeAll(usedArrays);
usedArrays.clear();
}
}
代码示例来源:origin: libgdx/libgdx
/** Removes all actors and cells from the table. */
public void clearChildren () {
Array<Cell> cells = this.cells;
for (int i = cells.size - 1; i >= 0; i--) {
Cell cell = cells.get(i);
Actor actor = cell.actor;
if (actor != null) actor.remove();
}
cellPool.freeAll(cells);
cells.clear();
rows = 0;
columns = 0;
if (rowDefaults != null) cellPool.free(rowDefaults);
rowDefaults = null;
implicitEndRow = false;
super.clearChildren();
}
代码示例来源:origin: libgdx/libgdx
@Override
public void clear () {
// Dispose every allocated instance because the templates may be changed
for (int i = 0, free = pool.getFree(); i < free; ++i) {
pool.obtain().dispose();
}
super.clear();
}
}
代码示例来源:origin: libgdx/libgdx
public Node<E> obtain (Node<E> p, Node<E> n, E value, int index) {
Node<E> newNode = super.obtain();
newNode.p = p;
newNode.n = n;
newNode.value = value;
newNode.index = index;
return newNode;
}
}
代码示例来源:origin: libgdx/libgdx
/** Removes the tail of the list regardless of iteration status */
public T removeLast () {
if (tail == null) {
return null;
}
T payload = tail.payload;
size--;
Item<T> p = tail.prev;
pool.free(tail);
if (size == 0) {
head = null;
tail = null;
} else {
tail = p;
tail.next = null;
}
return payload;
}
代码示例来源:origin: libgdx/libgdx
public void layout () {
BitmapFont font = style.font;
Drawable selectedDrawable = style.selection;
itemHeight = font.getCapHeight() - font.getDescent() * 2;
itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
prefWidth = 0;
Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class);
GlyphLayout layout = layoutPool.obtain();
for (int i = 0; i < items.size; i++) {
layout.setText(font, toString(items.get(i)));
prefWidth = Math.max(layout.width, prefWidth);
}
layoutPool.free(layout);
prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
prefHeight = items.size * itemHeight;
Drawable background = style.background;
if (background != null) {
prefWidth += background.getLeftWidth() + background.getRightWidth();
prefHeight += background.getTopHeight() + background.getBottomHeight();
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public void beforeGroup (int group, Array<Decal> contents) {
if (group == GROUP_BLEND) {
Gdx.gl.glEnable(GL20.GL_BLEND);
contents.sort(cameraSorter);
} else {
for (int i = 0, n = contents.size; i < n; i++) {
Decal decal = contents.get(i);
Array<Decal> materialGroup = materialGroups.get(decal.material);
if (materialGroup == null) {
materialGroup = arrayPool.obtain();
materialGroup.clear();
usedArrays.add(materialGroup);
materialGroups.put(decal.material, materialGroup);
}
materialGroup.add(decal);
}
contents.clear();
for (Array<Decal> materialGroup : materialGroups.values()) {
contents.addAll(materialGroup);
}
materialGroups.clear();
arrayPool.freeAll(usedArrays);
usedArrays.clear();
}
}
代码示例来源:origin: libgdx/libgdx
public void flush () {
super.freeAll(obtained);
obtained.clear();
}
}
代码示例来源:origin: libgdx/libgdx
private AnimationDesc obtain (final Animation anim, float offset, float duration, int loopCount, float speed,
final AnimationListener listener) {
if (anim == null) return null;
final AnimationDesc result = animationPool.obtain();
result.animation = anim;
result.listener = listener;
result.loopCount = loopCount;
result.speed = speed;
result.offset = offset;
result.duration = duration < 0 ? (anim.duration - offset) : duration;
result.time = speed < 0 ? result.duration : 0.f;
return result;
}
代码示例来源:origin: libgdx/libgdx
@Override
public void free (T object) {
obtained.removeValue(object, true);
super.free(object);
}
代码示例来源:origin: libgdx/libgdx
colors.add(colorPool.obtain().set(hits.get(i).getColor()));
hits.get(i).setColor(Color.RED);
colors.add(colorPool.obtain().set(contacts.get(i).getColor()));
contacts.get(i).setColor(Color.BLUE);
for (int i = 0; i < contacts.size; i++)
contacts.get(i).setColor(colors.get(hits.size + i));
colorPool.freeAll(colors);
colors.clear();
代码示例来源:origin: libgdx/libgdx
@Override
public void freeAll (Array<T> objects) {
obtained.removeAll(objects, true);
super.freeAll(objects);
}
}
内容来源于网络,如有侵权,请联系作者删除!