BGE/ShapeComponentHelpers
Alias: BGE.ShapeComponentHelpers
Static Methods
getCacheUri(shapeType: string, cacheKey: string): string
Hashes a shape type plus its field values into a stable cachefs:/ filename - a cache hit for repeated/discrete values, but a continuously-varying value (e.g. an Animation-driven tween) hashes differently every frame. cachefs:/ (not tmp:/) is deliberate: the filename is a pure function of the shape's inputs, so it's always safe to keep permanently across app relaunches - unlike tmp:/, which is cleared every session, cachefs:/ persists until the OS evicts it under storage pressure (checked for existence on every use regardless, since the OS can evict it at any time - see checkShapeCache()).
Parameters
shapeType(string) — distinguishes shape components from each other (e.g. "Circle")cacheKey(string) — a string uniquely identifying this shape's current field values
Returns
string— acachefs:/bge_shape_<hash>.pngfile URI
startRoundTripTimer(): roTimespan
Wall-clock timer for a full field-change-to-visible round trip - bracket a component's whole redraw() with this and logRoundTrip().
Returns
roTimespan
logRoundTrip(shapeType: string, timer: roTimespan): integer
Prints and returns the elapsed time since startRoundTripTimer() - see there.
Parameters
shapeType(string) — distinguishes shape components from each other (e.g. "Circle")timer(roTimespan) — the result of startRoundTripTimer()
Returns
integer— elapsed milliseconds
checkShapeCache(
shapeType: string,
cacheKey: string,
): ShapeCacheCheck
Synchronous cache-hit check - computes the cache URI and reports whether it already exists, with no bitmap/renderer creation either way. Safe to call from a component's own script (the render thread) before ever touching a render Task - only spin up (or re-run) a ShapeRenderTask on a miss.
Parameters
shapeType(string) — distinguishes shape components from each other (e.g. "Circle")cacheKey(string) — a string uniquely identifying this shape's current field values
Returns
ShapeCacheCheck—{uri, hit}
createShapeRenderState(
shapeType: string,
uri: string,
width: integer,
height: integer,
): ShapeRenderState
Begins a cache-miss render: creates a fresh roBitmap/BGE.Renderer pair for the caller to draw into. Intended to run inside a ShapeRenderTask (off the render thread) after checkShapeCache() has already reported a miss - call finishShapeRender() with the result after drawing.
invalid when width/height are non-positive or the bitmap couldn't be created
Parameters
shapeType(string) — distinguishes shape components from each other (e.g. "Circle")uri(string) — the cache file URI to render into (fromcheckShapeCache())width(integer) — bitmap width in pixelsheight(integer) — bitmap height in pixels
Returns
ShapeRenderState—{uri, renderer, bitmap, shapeType, timer}-renderer/bitmapare
finishShapeRender(renderState: ShapeRenderState): boolean
Finishes a cache-miss render started by createShapeRenderState(): Finish() (sufficient alone - no roScreen needed, confirmed on hardware), encodes to PNG, writes to the cache URI.
Parameters
renderState(ShapeRenderState) — the result ofcreateShapeRenderState()
Returns
boolean— true if the file was written successfully
verticesFromField(verticesField: object): dynamic
Converts a SceneGraph vertices field value into BGE.Math.Vector[], as every Renderer.draw* polygon/triangle call expects. Accepts a vector2darray field (each point a 2-element Float array, index [0]/[1] - this is the XML-settable form, e.g. vertices="[[0,0],[100,0]]") as well as a plain roArray of {x, y} associative arrays (for callers setting it imperatively).
Parameters
verticesField(object) — the raw field value (may be invalid or empty)
Returns
dynamic— converted points, empty if the field was empty/invalid
defaultTriangleVertices(width: float, height: float): dynamic
A right triangle with its right angle at the bottom-left, sized to fill the given width/height - used by Triangle's render dispatch whenever its vertices field is empty.
Parameters
width(float)height(float)
Returns
dynamic— the three triangle points
Other
INodeShapeRenderTask
Extends: roSGNodeTask
Node-level interface for the shared ShapeRenderTask node (see ShapeRenderTask.xml) - declared here (not in ShapeRenderTask.bs) so every shape component's own renderTask field can be typed precisely too, without each one re-declaring it.
Properties
shapeType(string)uri(string)width(float)height(float)color(integer)outlineColor(integer)outlineWidth(integer)cornerRadius(float)outlineSegments(integer)vertices(object)resultUri(string)resultRoundTripMs(integer)
ShapeCacheCheck
Result of checkShapeCache() - see there.
Properties
uri(string)hit(boolean)
ShapeRenderState
Result of createShapeRenderState() - see there. renderer/bitmap may be invalid.
Properties
uri(string)renderer(BGE.Renderer)bitmap(roBitmap)shapeType(string)timer(roTimespan)