List of usage examples for com.badlogic.gdx.utils Pool obtain
public T obtain()
From source file:com.andgate.ikou.render.FloorRender.java
License:Open Source License
@Override public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) { for (int i = 0; i < sectorMeshes.length; i++) { for (int j = 0; j < sectorMeshes[i].length; j++) { Mesh mesh = sectorMeshes[i][j].getMesh(); if (inFrustum(i, j) && (mesh != null)) { Renderable renderable = pool.obtain(); renderable.material = TileStack.TILE_MATERIAL; renderable.meshPartOffset = 0; renderable.meshPartSize = mesh.getNumIndices(); renderable.primitiveType = GL20.GL_TRIANGLES; renderable.mesh = mesh;/*from ww w. j a v a2 s . c o m*/ renderables.add(renderable); renderable.worldTransform.set(floorTransform); } } } }
From source file:com.andgate.ikou.render.PlayerRender.java
License:Open Source License
@Override public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) { Renderable renderable = pool.obtain(); renderable.material = material;/*from www. ja v a2 s .c o m*/ renderable.meshPartOffset = 0; renderable.meshPartSize = tileMesh.getMesh().getNumIndices(); renderable.primitiveType = GL20.GL_TRIANGLES; renderable.mesh = tileMesh.getMesh(); renderables.add(renderable); renderable.worldTransform.set(tileMesh.getTransform()); }
From source file:com.badlogic.gdx.tests.g3d.voxel.VoxelWorld.java
License:Apache License
@Override public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) { renderedChunks = 0;/*from w w w. j a v a 2s . c om*/ for (int i = 0; i < chunks.length; i++) { VoxelChunk chunk = chunks[i]; Mesh mesh = meshes[i]; if (dirty[i]) { int numVerts = chunk.calculateVertices(vertices); numVertices[i] = numVerts / 4 * 6; mesh.setVertices(vertices, 0, numVerts * VoxelChunk.VERTEX_SIZE); dirty[i] = false; } if (numVertices[i] == 0) continue; Renderable renderable = pool.obtain(); renderable.material = materials[i]; renderable.mesh = mesh; renderable.meshPartOffset = 0; renderable.meshPartSize = numVertices[i]; renderable.primitiveType = GL20.GL_TRIANGLES; renderables.add(renderable); renderedChunks++; } }
From source file:com.badlydrawngames.general.Pools.java
License:Apache License
/** Creates an array from a pool, freeing its items if it already exists. * @param <T> the type of item allocated in the array. * @param array the array of items to (re)create. * @param pool the pool that the items are to be allocated from / released to. * @param size the array's capacity.//from ww w. j a v a 2 s. co m * @return the input array */ @SuppressWarnings("unchecked") public static <T> Array<T> makeArrayFromPool(Array<T> array, Pool<T> pool, int size) { if (array == null) { // Do this so that array.items can be used. T t = pool.obtain(); array = new Array<T>(false, size, (Class<T>) t.getClass()); pool.free(t); } else { freeArrayToPool(array, pool); } return array; }
From source file:com.github.antag99.retinazer.Mapper.java
License:Open Source License
/** Returns a component instance which is safe to keep around, outside of the entity system. * No guarantees are placed on which data does the component obtain. * Component must have no-arg constructor for this to work. */ public T createComponent() { final Pool<T> pool = this.componentPool; if (pool != null) { return pool.obtain(); }//from ww w .j a va 2 s. c om if (constructor == null) { throw new RetinazerException( "Component type " + type.getName() + " does not expose a zero-argument constructor"); } try { @SuppressWarnings("unchecked") T instance = (T) constructor.newInstance(); return instance; } catch (ReflectionException ex) { // GWT compatibility hack - no InvocationTargetException emulation if ("java.lang.reflect.InvocationTargetException".equals(ex.getCause().getClass().getName())) throw Internal.sneakyThrow(ex.getCause().getCause()); throw new AssertionError(ex); } }
From source file:com.kotcrab.vis.ui.widget.HighlightTextArea.java
License:Apache License
@Override protected void calculateOffsets() { super.calculateOffsets(); if (chunkUpdateScheduled == false) return;//w w w .j a v a2s.c om chunkUpdateScheduled = false; highlights.sort(); renderChunks.clear(); String text = getText(); Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class); GlyphLayout layout = layoutPool.obtain(); boolean carryHighlight = false; for (int lineIdx = 0, highlightIdx = 0; lineIdx < linesBreak.size; lineIdx += 2) { int lineStart = linesBreak.items[lineIdx]; int lineEnd = linesBreak.items[lineIdx + 1]; int lineProgress = lineStart; float chunkOffset = 0; for (; highlightIdx < highlights.size;) { Highlight highlight = highlights.get(highlightIdx); if (highlight.getStart() > lineEnd) { break; } if (highlight.getStart() == lineProgress || carryHighlight) { renderChunks.add(new Chunk(text.substring(lineProgress, Math.min(highlight.getEnd(), lineEnd)), highlight.getColor(), chunkOffset, lineIdx)); lineProgress = Math.min(highlight.getEnd(), lineEnd); if (highlight.getEnd() > lineEnd) { carryHighlight = true; } else { carryHighlight = false; highlightIdx++; } } else { //protect against overlapping highlights boolean noMatch = false; while (highlight.getStart() <= lineProgress) { highlightIdx++; if (highlightIdx >= highlights.size) { noMatch = true; break; } highlight = highlights.get(highlightIdx); if (highlight.getStart() > lineEnd) { noMatch = true; break; } } if (noMatch) break; renderChunks.add(new Chunk(text.substring(lineProgress, highlight.getStart()), defaultColor, chunkOffset, lineIdx)); lineProgress = highlight.getStart(); } Chunk chunk = renderChunks.peek(); layout.setText(style.font, chunk.text); chunkOffset += layout.width; //current highlight needs to be applied to next line meaning that there is no other highlights that can be applied to currently parsed line if (carryHighlight) break; } if (lineProgress < lineEnd) { renderChunks .add(new Chunk(text.substring(lineProgress, lineEnd), defaultColor, chunkOffset, lineIdx)); } } maxAreaWidth = 0; for (String line : text.split("\\n")) { layout.setText(style.font, line); maxAreaWidth = Math.max(maxAreaWidth, layout.width + 30); } layoutPool.free(layout); updateScrollLayout(); }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
@Override protected void calculateOffsets() { super.calculateOffsets(); if (!this.text.equals(lastText)) { this.lastText = text; BitmapFont font = style.font;/*from w ww. j a v a 2 s.c o m*/ float maxWidthLine = this.getWidth() - (style.background != null ? style.background.getLeftWidth() + style.background.getRightWidth() : 0); linesBreak.clear(); int lineStart = 0; int lastSpace = 0; char lastCharacter; Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class); GlyphLayout layout = layoutPool.obtain(); for (int i = 0; i < text.length(); i++) { lastCharacter = text.charAt(i); if (lastCharacter == ENTER_DESKTOP || lastCharacter == ENTER_ANDROID) { linesBreak.add(lineStart); linesBreak.add(i); lineStart = i + 1; } else { lastSpace = (continueCursor(i, 0) ? lastSpace : i); layout.setText(font, text.subSequence(lineStart, i + 1)); if (layout.width > maxWidthLine && softwrap) { if (lineStart >= lastSpace) { lastSpace = i - 1; } linesBreak.add(lineStart); linesBreak.add(lastSpace + 1); lineStart = lastSpace + 1; lastSpace = lineStart; } } } layoutPool.free(layout); // Add last line if (lineStart < text.length()) { linesBreak.add(lineStart); linesBreak.add(text.length()); } showCursor(); } }
From source file:com.ridiculousRPG.util.BitmapFontCachePool.java
License:Apache License
/** * Returns an object from this pool. The object may be new or reused * (previously {@link #free(Object) freed}).<br> * You have to dispose the fonts by yourself. * // w w w .ja v a2 s . co m * @param font * @return */ public BitmapFontCache obtain(final BitmapFont font) { Pool<BitmapFontCache> fontCache = pool.get(font); if (fontCache == null) { fontCache = new Pool<BitmapFontCache>(64, 256) { @Override protected BitmapFontCache newObject() { return new BitmapFontCache(font); } }; pool.put(font, fontCache); } return fontCache.obtain(); }
From source file:de.longri.cachebox3.gui.map.layer.SharedModel.java
License:Open Source License
protected void getRenderables(Node node, Array<Renderable> renderables, Pool<Renderable> pool) { if (node.parts.size > 0) { for (NodePart nodePart : node.parts) { renderables.add(getRenderable(pool.obtain(), node, nodePart)); }//w w w .ja v a 2 s . com } for (Node child : node.getChildren()) { getRenderables(child, renderables, pool); } }
From source file:es.eucm.ead.engine.factories.GameObjectFactory.java
License:Open Source License
private T getInstance(Class<?> clazz) { Pool<T> pool = pools.get(clazz); if (pool == null) { pool = new GameObjectPool(clazz); pools.put(clazz, pool);//from w ww . j av a 2 s . c om } return pool.obtain(); }