chore(deps): update vendored tankroyale botapi to v1.0.1
Syncs libs/tankroyale_botapi with SirStone/robocode_tankroyale_botapi v1.0.1 (extracted from tank-royale nim branch @ 03195a814). The local SIGSEGV fixes (static event queue/SVG/intent buffers) were already ported upstream in issue #24 — content is otherwise identical. New capability (upstream #23): opponent name exposure for ticket #49. - bot.nim: gBotNames id→name table + getBotName(id) / updateBotNames() - umbrella module: dispatch BotListUpdate messages to updateBotNames() Vendored layout and wiring unchanged (--path via config.nims, module name stays tankroyale_botapi).
This commit is contained in:
@@ -209,6 +209,8 @@ proc runReceiveLoop*(ws: SyncWebSocket; info: BotInfo; secret: string; serverUrl
|
||||
of "SkippedTurnEvent":
|
||||
let e = node.to(SkippedTurnEvent)
|
||||
gBot.onSkippedTurn(e)
|
||||
of "BotListUpdate":
|
||||
updateBotNames(node)
|
||||
else:
|
||||
discard # unknown message type — ignore
|
||||
except Exception as e:
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
## tickChan main → bot (true = new tick ready; false = stop)
|
||||
## intentChan bot → sender (JSON string to send to server; "" = stop)
|
||||
|
||||
import std/[json, locks, math, os, posix, syncio]
|
||||
import std/[json, locks, math, os, posix, syncio, tables]
|
||||
import ./constants
|
||||
import ./schemas
|
||||
import ./color
|
||||
@@ -68,6 +68,7 @@ var gGameSetup {.guard: gLock.}: GameSetup
|
||||
var gTeammateIds{.guard: gLock.}: seq[int]
|
||||
var gVariant {.guard: gLock.}: string
|
||||
var gServerVersion {.guard: gLock.}: string
|
||||
var gBotNames {.guard: gLock.}: Table[int, string]
|
||||
# Events handed main -> bot thread. Channel move, NOT a locked shared seq:
|
||||
# the old locked seq[BotEvent] copied GC'd payloads (strings/teamMessages)
|
||||
# across threads on every tick -> refcount churn under ORC + --threads:on ->
|
||||
@@ -166,6 +167,28 @@ proc getTurnRemaining*(): float = gTurnRemaining
|
||||
proc getGunTurnRemaining*(): float = gGunTurnRemaining
|
||||
proc getRadarTurnRemaining*(): float = gRadarTurnRemaining
|
||||
|
||||
proc getBotName*(id: int): string =
|
||||
## Lookup bot name by id from the last BotListUpdate. Returns "" if unknown.
|
||||
withLock(gLock): result = gBotNames.getOrDefault(id, "")
|
||||
|
||||
proc updateBotNames*(node: JsonNode) =
|
||||
## Update the id → name table from a BotListUpdate message (full replacement).
|
||||
withLock(gLock):
|
||||
gBotNames.clear()
|
||||
if node.isNil: return
|
||||
let botsNode = node{"bots"}
|
||||
if botsNode.isNil or botsNode.kind != JArray: return
|
||||
for b in botsNode:
|
||||
let name = b{"name"}.getStr("")
|
||||
if name.len == 0: continue
|
||||
var id = -1
|
||||
if not b{"id"}.isNil:
|
||||
id = b{"id"}.getInt(-1)
|
||||
if id == -1 and not b{"botId"}.isNil:
|
||||
id = b{"botId"}.getInt(-1)
|
||||
if id == -1: continue
|
||||
gBotNames[id] = name
|
||||
|
||||
proc getMaxSpeed*(): float = gMaxSpeed
|
||||
proc getMaxTurnRate*(): float = gMaxTurnRate
|
||||
proc getMaxGunTurnRate*(): float = gMaxGunTurnRate
|
||||
@@ -862,6 +885,8 @@ proc initGlobals*() =
|
||||
gEventChan.open(8)
|
||||
initLock(gLock)
|
||||
gEventQueue = initEventQueue()
|
||||
withLock(gLock):
|
||||
gBotNames = initTable[int, string]()
|
||||
# Debug log is opt-in: it is written every tick from two threads, so leaving
|
||||
# it on by default is a disk hog and an I/O stall source. Enable with
|
||||
# PPOB_DEBUG_LOG=1 to debug; starts fresh (truncated) each run.
|
||||
|
||||
Reference in New Issue
Block a user