Research Tank Royale debug drawing API #148

Closed
opened 2026-09-12 11:37:08 +02:00 by SirStone · 1 comment
Owner

Question

What drawing primitives does the Tank Royale bot API expose for debug visualization? Specifically: what procs are available (drawLine, drawCircle, drawText, etc.), what coordinate system do they use, are they per-tick, and what are the limitations? This determines how the SNN debug overlay is designed.

Parent map: #147

## Question What drawing primitives does the Tank Royale bot API expose for debug visualization? Specifically: what procs are available (drawLine, drawCircle, drawText, etc.), what coordinate system do they use, are they per-tick, and what are the limitations? This determines how the SNN debug overlay is designed. Parent map: #147
Author
Owner

Tank Royale Debug Drawing API — Research Summary

Drawing Primitives Available:
The Tank Royale bot API (Nim) exposes these SVG-based debug drawing procs in the graphics module:

  • drawLine(x1, y1, x2, y2) — line from point to point
  • drawRectangle(x, y, w, h) — outline rectangle
  • fillRectangle(x, y, w, h) — filled rectangle
  • drawCircle(x, y, r) — outline circle
  • fillCircle(x, y, r) — filled circle
  • drawPolygon(points: seq[(float, float)]) — outline polygon
  • fillPolygon(points: seq[(float, float)]) — filled polygon
  • drawText(text, x, y) — text at position

Coordinate System:

  • Arena coordinates: bot absolute position (same as getX(), getY())
  • Y=0 is south, Y increases northward (standard Tank Royale frame)
  • All coordinates are float

Per-Tick Behavior:

  • Graphics are cleared automatically each tick after being flushed to BotIntent
  • The SVG buffer is wrapped in <g> tags and sent as debugGraphics JSON field
  • After each go() call, clearGraphics() resets:
    • SVG buffer (empty string)
    • Stroke color (WHITE)
    • Fill color (WHITE)
    • Stroke width (1.0)
    • Font family ("Arial")
    • Font size (12.0)

Style Control (persistent within tick):

  • setStrokeColor(color) — outline/line color
  • setFillColor(color) — fill color
  • setStrokeWidth(width) — line thickness
  • setFont(family, size) — text font and size

Color Support:

  • 141 named color constants (Java Color class palette): RED, BLUE, GREEN, YELLOW, GRAY, CYAN, MAGENTA, etc.
  • Custom colors via fromRgb(r, g, b) or fromRgba(r, g, b, a) where r,g,b,a are uint8
  • Hex parsing via fromHex("#RRGGBB") or fromHex("#RRGGBBAA")
  • Alpha channel support for transparency (0 = fully transparent, 255 = opaque)

Limitations:

  • SVG-based rendering (client-side browser display, not server-side)
  • Primitives accumulate in memory each tick (buffer-only, no batching)
  • No hardware acceleration; suitable for debug visualization, not real-time heavy graphics
  • Text rendering limited to browser-supported SVG text (basic styling only)

Usage Pattern:
All draw calls within a single run() iteration accumulate in a buffer. When go() is called, the SVG is serialized into BotIntent and sent to the server, then the buffer is cleared for the next tick.


Example (from GotoTest.nim):

for i, (wx, wy) in waypoints:
  if i == bot.waypointIdx:
    setStrokeColor(RED)
  else:
    setStrokeColor(GRAY)
  drawCircle(wx, wy, 10.0)
setStrokeColor(YELLOW)
drawLine(bx, by, tx, ty)
go()  # sends SVG, clears buffer

This answers the SNN debug overlay design requirements: use stroked primitives + text for lightweight visualization, with per-tick refresh guaranteed by automatic clearing.

## Tank Royale Debug Drawing API — Research Summary **Drawing Primitives Available:** The Tank Royale bot API (Nim) exposes these SVG-based debug drawing procs in the `graphics` module: - `drawLine(x1, y1, x2, y2)` — line from point to point - `drawRectangle(x, y, w, h)` — outline rectangle - `fillRectangle(x, y, w, h)` — filled rectangle - `drawCircle(x, y, r)` — outline circle - `fillCircle(x, y, r)` — filled circle - `drawPolygon(points: seq[(float, float)])` — outline polygon - `fillPolygon(points: seq[(float, float)])` — filled polygon - `drawText(text, x, y)` — text at position **Coordinate System:** - Arena coordinates: bot absolute position (same as `getX()`, `getY()`) - Y=0 is south, Y increases northward (standard Tank Royale frame) - All coordinates are `float` **Per-Tick Behavior:** - Graphics are **cleared automatically each tick** after being flushed to BotIntent - The SVG buffer is wrapped in `<g>` tags and sent as `debugGraphics` JSON field - After each `go()` call, `clearGraphics()` resets: - SVG buffer (empty string) - Stroke color (WHITE) - Fill color (WHITE) - Stroke width (1.0) - Font family ("Arial") - Font size (12.0) **Style Control (persistent within tick):** - `setStrokeColor(color)` — outline/line color - `setFillColor(color)` — fill color - `setStrokeWidth(width)` — line thickness - `setFont(family, size)` — text font and size **Color Support:** - 141 named color constants (Java Color class palette): RED, BLUE, GREEN, YELLOW, GRAY, CYAN, MAGENTA, etc. - Custom colors via `fromRgb(r, g, b)` or `fromRgba(r, g, b, a)` where r,g,b,a are `uint8` - Hex parsing via `fromHex("#RRGGBB")` or `fromHex("#RRGGBBAA")` - Alpha channel support for transparency (0 = fully transparent, 255 = opaque) **Limitations:** - SVG-based rendering (client-side browser display, not server-side) - Primitives accumulate in memory each tick (buffer-only, no batching) - No hardware acceleration; suitable for debug visualization, not real-time heavy graphics - Text rendering limited to browser-supported SVG text (basic styling only) **Usage Pattern:** All draw calls within a single `run()` iteration accumulate in a buffer. When `go()` is called, the SVG is serialized into BotIntent and sent to the server, then the buffer is cleared for the next tick. --- **Example (from GotoTest.nim):** ```nim for i, (wx, wy) in waypoints: if i == bot.waypointIdx: setStrokeColor(RED) else: setStrokeColor(GRAY) drawCircle(wx, wy, 10.0) setStrokeColor(YELLOW) drawLine(bx, by, tx, ty) go() # sends SVG, clears buffer ``` This answers the SNN debug overlay design requirements: use stroked primitives + text for lightweight visualization, with per-tick refresh guaranteed by automatic clearing.
SirStone added the wayfinder:research label 2026-09-12 12:22:06 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SirStone/SirRoboGarage#148