Java Code Examples for com.badlogic.gdx.utils.Pool#obtain()
The following examples show how to use
com.badlogic.gdx.utils.Pool#obtain() .
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: RainRenderer.java From Cubes with MIT License | 5 votes |
@Override public void getRenderables(Array<Renderable> renderables, Pool<Renderable> pool) { Renderable renderable = pool.obtain(); ((CubesRenderable) renderable).name = "RainMesh"; renderable.material = Assets.blockItemSheet.getMaterial(); // not actually used renderable.meshPart.set(meshPart); if (SHADER == null) { SHADER = new RainShader(renderable); SHADER.init(); } renderable.shader = SHADER; renderables.add(renderable); }
Example 2
Source File: Pools.java From Cubes with MIT License | 5 votes |
public static <T> void registerType(Class<? extends T> c, Pool<T> pool) { T obj = pool.obtain(); Class<?> objClass = obj.getClass(); pool.free(obj); if (objClass.equals(c)) { synchronized (pools) { if (!pools.containsKey(c)) { pools.put(c, pool); } } } else { throw new CubesException("Calling obtain on " + pool + " does not return " + c.getName()); } }
Example 3
Source File: Pools.java From Cubes with MIT License | 5 votes |
public static <T> T obtain(Class<T> c) { Pool<T> pool = pool(c); if (pool == null) return null; synchronized (pool) { return pool.obtain(); } }
Example 4
Source File: Pools.java From Cubes with MIT License | 5 votes |
public static AreaReference obtainAreaReference() { Pool<AreaReference> pool = pool(AreaReference.class); if (pool == null) return null; synchronized (pool) { return pool.obtain(); } }
Example 5
Source File: Pools.java From Cubes with MIT License | 5 votes |
public static BlockReference obtainBlockReference() { Pool<BlockReference> pool = pool(BlockReference.class); if (pool == null) return null; synchronized (pool) { return pool.obtain(); } }
Example 6
Source File: Actions3d.java From Scene3d with Apache License 2.0 | 5 votes |
/** Returns a new or pooled action of the specified type. */ static public <T extends Action3d> T action3d (Class<T> type) { Pool<T> pool = Pools.get(type); T action = pool.obtain(); action.setPool(pool); return action; }
Example 7
Source File: PooledBehaviorTreeLibrary.java From gdx-ai with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T> BehaviorTree<T> createBehaviorTree(String treeReference, T blackboard) { Pool<BehaviorTree> pool = getPool(treeReference); BehaviorTree<T> tree = (BehaviorTree<T>)pool.obtain(); tree.setObject(blackboard); return tree; }
Example 8
Source File: HighlightTextArea.java From vis-ui with Apache License 2.0 | 4 votes |
@Override protected void calculateOffsets () { super.calculateOffsets(); if (chunkUpdateScheduled == false) return; 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(); }
Example 9
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 4 votes |
@Override protected void calculateOffsets () { super.calculateOffsets(); if (!this.text.equals(lastText)) { this.lastText = text; BitmapFont font = style.font; 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(); } }