{"modulePath":"github.com/nsgo-dev/game","version":"v0.2.2","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package debug\n\nPackage debug holds development-only tooling and overlays for NSGo games: a frame-time graph, collision and sprite-bounds wireframes, a live scene inspector, a behavior tree and state machine inspector with steering guides, an interactive dev console with typed tunables, named timing scopes with Chrome/Perfetto trace export, an asset memory tracker with budgets, and a GC/allocation monitor.\n\nIn default builds every feature is compiled in and Enabled reports true. Building with -tags release swaps the implementation for empty no-ops where Enabled reports false and Overlay.View returns nil, so release binaries link none of the overlay UI, graph, AI inspector, steering guides, console, profiler, memory tracker, GC monitor, or wireframe code.\n\n## Constants\n\n```go\nconst FrameHistory = 120\n```\nFrameHistory is the number of frames retained in a FrameStats ring buffer.\n\n## Functions\n\n```go\nfunc AssertZeroAllocs(t testing.TB, runs int, fn func())\n```\nAssertZeroAllocs fails t if fn allocates on the heap during runs iterations, for use in CI hot-path regression tests.\n\n```go\nfunc ConsoleView(cx *core.Scope, c *Console) core.View\n```\nConsoleView returns a native NSGo view bound to c, composable inside Overlay or any game view tree.\n\n```go\nfunc Enabled() bool\n```\nEnabled reports whether debug overlays are compiled into this build. It is true in default builds and false with -tags release.\n\n```go\nfunc EstimateImageBytes(w, h int) int64\n```\nEstimateImageBytes returns the uncompressed RGBA8 memory footprint (w \\* h \\* 4) for an image of size w by h, or 0 if either dimension is non-positive.\n\n```go\nfunc EstimatePCMBytes(samples, channels, bytesPerSample int) int64\n```\nEstimatePCMBytes returns the uncompressed PCM memory footprint (samples \\* channels \\* bytesPerSample), or 0 if any parameter is non-positive.\n\n```go\nfunc MeasureAllocs(runs int, fn func()) float64\n```\nMeasureAllocs wraps testing.AllocsPerRun and returns the average heap allocations per execution of fn over runs iterations (defaulting to 100 when runs \\\u003c= 0).\n\n## Types\n\n```go\ntype AISnapshot struct {\n\t// Agent identifies the inspected agent (for example, \"guard-1\" or \"boss\").\n\tAgent string\n\t// Tree holds the behavior tree's pre-order node traces (for example, from ai.BTInspector.Walk or WalkInto).\n\tTree []ai.BTNodeTrace\n\t// Machine holds a flow.Machine's current state and bounded transition history (for example, from m.Inspect()).\n\tMachine *flow.MachineInspection\n}\n```\nAISnapshot describes a chosen agent's live AI state for the debug overlay panel. Set Tree to inspect a behavior tree, Machine to inspect a flow.Machine, or both.\n\n```go\nfunc BehaviorTreeSnapshot(agent string, ins *ai.BTInspector) AISnapshot\n```\nBehaviorTreeSnapshot builds an AISnapshot for agent by walking ins. Under -tags release, BehaviorTreeSnapshot returns a zero AISnapshot without walking ins.\n\n```go\nfunc StateMachineSnapshot(agent string, m flow.MachineInspector) AISnapshot\n```\nStateMachineSnapshot builds an AISnapshot for agent from m's current state and transition history. Under -tags release, StateMachineSnapshot returns a zero AISnapshot without snapshotting m.\n\n```go\ntype AssetKind uint8\n```\nAssetKind classifies tracked asset memory in a MemoryTracker.\n\n```go\nconst (\n\t// AssetImage identifies standalone decoded images and textures.\n\tAssetImage AssetKind = iota\n\t// AssetAtlas identifies sprite atlases and sheets.\n\tAssetAtlas\n\t// AssetAudio identifies decoded audio buffers and sound banks.\n\tAssetAudio\n\t// AssetOther identifies any other asset category.\n\tAssetOther\n)\n```\n\n```go\nfunc (k AssetKind) String() string\n```\nString returns a lowercase label for k.\n\n```go\ntype CommandInfo struct {\n\t// Name is the command name as typed on the console.\n\tName string\n\t// Help is the command's usage or description text.\n\tHelp string\n\t// Builtin reports whether the command is built into Console.\n\tBuiltin bool\n}\n```\nCommandInfo describes one command available on a Console.\n\n```go\ntype Console struct {\n\t// contains filtered or unexported fields\n}\n```\nConsole is an interactive development console supporting custom commands, range-checked typed tunables, history navigation, tab completion, and Storage persistence.\n\n```go\nfunc NewConsole() *Console\n```\nNewConsole returns an empty development Console with built-in commands enabled.\n\n```go\nfunc (c *Console) Commands() []CommandInfo\n```\nCommands returns all built-in and registered console commands sorted by name.\n\n```go\nfunc (c *Console) Complete(prefix string) []string\n```\nComplete returns sorted completion candidates for prefix, completing command names and tunable names for get/set/help.\n\n```go\nfunc (c *Console) Entries() []ConsoleEntry\n```\nEntries returns a copy of the current console output log.\n\n```go\nfunc (c *Console) Exec(line string) (string, error)\n```\nExec parses and executes one command line, updating history and output entries.\n\n```go\nfunc (c *Console) History() []string\n```\nHistory returns a copy of executed command lines, oldest first.\n\n```go\nfunc (c *Console) HistoryNext() string\n```\nHistoryNext steps forward through command history, returning \"\" once past the most recent entry.\n\n```go\nfunc (c *Console) HistoryPrev() string\n```\nHistoryPrev steps backward through command history and returns the selected command line.\n\n```go\nfunc (c *Console) LoadTunables(st core.Storage, key string) error\n```\nLoadTunables restores registered tunables from st under key. Missing entries are a no-op; unknown keys are ignored; out-of-range values return an error without mutating the tunable.\n\nIts errors are \\*loaderr.Error values that name key as the file, with the line of the tunable at fault and how to fix it.\n\n```go\nfunc (c *Console) RegisterBool(name string, ptr *bool)\n```\nRegisterBool registers a bool tunable bound to ptr.\n\n```go\nfunc (c *Console) RegisterCommand(name, help string, fn func(args []string) (string, error))\n```\nRegisterCommand registers a named console command and its help text.\n\n```go\nfunc (c *Console) RegisterFloat(name string, minVal, maxVal float64, ptr *float64)\n```\nRegisterFloat registers a range-checked float64 tunable bound to ptr.\n\n```go\nfunc (c *Console) RegisterInt(name string, minVal, maxVal int, ptr *int)\n```\nRegisterInt registers a range-checked int tunable bound to ptr.\n\n```go\nfunc (c *Console) RegisterString(name string, ptr *string)\n```\nRegisterString registers a string tunable bound to ptr.\n\n```go\nfunc (c *Console) SaveTunables(st core.Storage, key string) error\n```\nSaveTunables persists all registered tunables into st under key as JSON.\n\n```go\nfunc (c *Console) SetTunable(name string, value any, clamp bool) (TunableChange, error)\n```\nSetTunable updates the named tunable to value after checking its type and numeric range, and returns the previous value with a snapshot of the tunable after the change, both taken under the same lock as the write. A float tunable takes any Go integer or float; an int tunable takes any Go integer. With clamp, a number outside the tunable's range, including an integer beyond int's range, is stored as the nearest bound and TunableChange.Clamped is set; without clamp it is refused. On error the tunable is left unchanged.\n\n```go\nfunc (c *Console) Tunable(name string) (TunableInfo, bool)\n```\nTunable returns a snapshot of the named tunable and reports whether it is registered.\n\n```go\nfunc (c *Console) Tunables() []TunableInfo\n```\nTunables returns a snapshot of all registered tunables sorted by name.\n\n```go\ntype ConsoleEntry struct {\n\t// Input is the raw command line that was executed.\n\tInput string\n\t// Output is the returned text or error message.\n\tOutput string\n\t// IsError reports whether the command returned an error.\n\tIsError bool\n}\n```\nConsoleEntry is one recorded command execution in a dev Console log.\n\n```go\ntype DrawStats struct {\n\t// DrawCalls is the number of draw calls submitted in the frame.\n\tDrawCalls int\n\t// Sprites is the number of sprites drawn in the frame.\n\tSprites int\n\t// Batches is the number of sprite or instanced draw batches submitted in the frame.\n\tBatches int\n\t// Triangles is the number of triangles submitted in the frame.\n\tTriangles uint64\n\t// Vertices is the number of vertices submitted in the frame.\n\tVertices uint64\n}\n```\nDrawStats captures per-frame draw submission counts for overlay display and MCP performance readouts.\n\n```go\ntype FrameSample struct {\n\t// Total is the elapsed time of the frame.\n\tTotal time.Duration\n\t// Update is the time spent in fixed-step updates during the frame.\n\tUpdate time.Duration\n\t// Draw is the time spent drawing the frame.\n\tDraw time.Duration\n\t// GCHitch reports whether a GC pause occurred during this frame.\n\tGCHitch bool\n\t// Cause is an optional short explanation of a frame-time spike (such as shader compilation or asset streaming) when known by the game.\n\tCause string\n}\n```\nFrameSample holds the measured durations of one rendered frame.\n\n```go\ntype FrameStats struct {\n\t// contains filtered or unexported fields\n}\n```\nFrameStats keeps the last FrameHistory frame timings in a fixed-size ring buffer without per-frame heap allocations.\n\n```go\nfunc (s *FrameStats) At(i int) FrameSample\n```\nAt returns sample i in chronological order, where 0 is the oldest retained frame and Len()-1 is the newest. Out-of-range indices return the zero FrameSample.\n\n```go\nfunc (s *FrameStats) Average() FrameSample\n```\nAverage returns the mean Total, Update and Draw durations across the retained samples.\n\n```go\nfunc (s *FrameStats) DrawGraph(d *core.Drawing, size core.Size, targetFPS float64)\n```\nDrawGraph records a stacked update+draw bar graph of the retained frame samples into d, filling size, with a reference line at targetFPS (60 when 0 or less).\n\n```go\nfunc (s *FrameStats) FPS() float64\n```\nFPS returns the average frame rate in frames per second across the retained samples, or 0 when empty.\n\n```go\nfunc (s *FrameStats) Latest() FrameSample\n```\nLatest returns the most recently recorded sample, or the zero FrameSample when empty.\n\n```go\nfunc (s *FrameStats) Len() int\n```\nLen returns how many samples are currently stored, up to FrameHistory.\n\n```go\nfunc (s *FrameStats) MaxTotal() time.Duration\n```\nMaxTotal returns the longest Total frame duration among the retained samples.\n\n```go\nfunc (s *FrameStats) Record(total, update, draw time.Duration)\n```\nRecord appends one frame's timings to the ring buffer, overwriting the oldest sample once full.\n\nNegative durations are clamped to zero. When total is zero and update or draw is positive, total defaults to update+draw.\n\n```go\nfunc (s *FrameStats) Reset()\n```\nReset clears all recorded samples.\n\n```go\nfunc (s *FrameStats) Samples(dst []FrameSample) []FrameSample\n```\nSamples appends the retained samples in chronological order to dst and returns the resulting slice.\n\n```go\ntype GCFrameSample struct {\n\t// FrameDuration is the frame duration passed to SampleFrame.\n\tFrameDuration time.Duration\n\t// CyclesDelta is the number of GC cycles completed since the previous sample.\n\tCyclesDelta uint64\n\t// Pause is the estimated total GC pause time observed during this frame.\n\tPause time.Duration\n\t// HeapObjectsBytes is the live heap object bytes reported by /memory/classes/heap/objects:bytes.\n\tHeapObjectsBytes uint64\n\t// AllocsDelta is the number of heap objects allocated during this frame (/gc/heap/allocs:objects).\n\tAllocsDelta uint64\n\t// AllocBytesDelta is the number of heap bytes allocated during this frame (/gc/heap/allocs:bytes).\n\tAllocBytesDelta uint64\n\t// Hitched reports whether a GC pause occurred during this frame.\n\tHitched bool\n}\n```\nGCFrameSample records GC metrics sampled for one frame by a GCMonitor.\n\n```go\ntype GCMonitor struct {\n\t// contains filtered or unexported fields\n}\n```\nGCMonitor samples Go runtime/metrics GC counters, heap allocations and pause histograms once per frame with zero steady-state allocations, flagging frames hitched by garbage collection.\n\n```go\nfunc NewGCMonitor(historyLen int) *GCMonitor\n```\nNewGCMonitor returns a GCMonitor retaining up to historyLen recent frame samples (defaulting to FrameHistory when \\\u003c= 0).\n\n```go\nfunc (m *GCMonitor) AllocBytesPerFrame() float64\n```\nAllocBytesPerFrame returns the average number of heap bytes allocated per frame across the retained history window, or 0 when empty.\n\n```go\nfunc (m *GCMonitor) AllocsPerFrame() float64\n```\nAllocsPerFrame returns the average number of heap objects allocated per frame across the retained history window, or 0 when empty.\n\n```go\nfunc (m *GCMonitor) At(i int) GCFrameSample\n```\nAt returns sample i in chronological order (0 is oldest, Len()-1 is newest).\n\n```go\nfunc (m *GCMonitor) HeapObjectsBytes() uint64\n```\nHeapObjectsBytes returns the most recently sampled /memory/classes/heap/objects:bytes value.\n\n```go\nfunc (m *GCMonitor) LastPause() time.Duration\n```\nLastPause returns the most recent non-zero GC pause observed by this monitor.\n\n```go\nfunc (m *GCMonitor) Latest() GCFrameSample\n```\nLatest returns the most recently sampled GCFrameSample, or the zero value when empty.\n\n```go\nfunc (m *GCMonitor) Len() int\n```\nLen returns how many frame samples are currently retained in history.\n\n```go\nfunc (m *GCMonitor) MaxPause() time.Duration\n```\nMaxPause returns the longest per-frame GC pause observed by this monitor.\n\n```go\nfunc (m *GCMonitor) RecentHitches() int\n```\nRecentHitches returns how many frames in the retained history ring buffer experienced a GC pause.\n\n```go\nfunc (m *GCMonitor) Reset()\n```\nReset clears retained GC frame history, hitch counts and peak pause timings, and re-baselines runtime/metrics counters to the current point in time.\n\n```go\nfunc (m *GCMonitor) SampleFrame(frameDur time.Duration) GCFrameSample\n```\nSampleFrame reads runtime/metrics for the completed frame and returns its GCFrameSample without heap allocations in steady state.\n\n```go\nfunc (m *GCMonitor) TotalCycles() uint64\n```\nTotalCycles returns the cumulative GC cycle count reported by /gc/cycles/total:gc-cycles.\n\n```go\ntype GroupMemory struct {\n\t// Group is the asset group name, such as \"level1\" or \"ui\".\n\tGroup string\n\t// TotalBytes is the total tracked bytes across all assets in the group.\n\tTotalBytes int64\n\t// Budget is the configured byte budget for the group, or 0 when unbounded.\n\tBudget int64\n\t// OverBudget reports whether Budget \u003e 0 and TotalBytes \u003e Budget.\n\tOverBudget bool\n\t// Count is the number of tracked assets currently in the group.\n\tCount int\n\t// ByKind maps each AssetKind present in the group to its tracked byte total.\n\tByKind map[AssetKind]int64\n}\n```\nGroupMemory reports the tracked memory for one asset group.\n\n```go\ntype LayerSnapshot struct {\n\t// Name identifies the layer, such as \"terrain\", \"actors\" or \"hud\".\n\tName string\n\t// Space is the coordinate space the layer draws in, such as \"world\" or \"screen\".\n\tSpace string\n\t// Objects is the number of live objects on the layer.\n\tObjects int\n}\n```\nLayerSnapshot describes one layer within a SceneSnapshot.\n\n```go\ntype MemoryTracker struct {\n\t// contains filtered or unexported fields\n}\n```\nMemoryTracker accounts for decoded asset memory grouped by owner (such as level or scene) and validates per-group and total byte budgets.\n\n```go\nfunc NewMemoryTracker() *MemoryTracker\n```\nNewMemoryTracker returns an empty asset MemoryTracker.\n\n```go\nfunc (m *MemoryTracker) CheckAllBudgets() error\n```\nCheckAllBudgets validates the total budget and every configured per-group budget, returning a joined error if any are exceeded.\n\n```go\nfunc (m *MemoryTracker) CheckBudget(group string) error\n```\nCheckBudget returns an error if group has a configured budget and its tracked bytes exceed that budget.\n\n```go\nfunc (m *MemoryTracker) GroupBytes(group string) int64\n```\nGroupBytes returns the total tracked bytes currently held by group.\n\n```go\nfunc (m *MemoryTracker) Groups() []GroupMemory\n```\nGroups returns a sorted snapshot of all groups with tracked assets and their per-kind byte breakdowns.\n\n```go\nfunc (m *MemoryTracker) ReleaseGroup(group string)\n```\nReleaseGroup drops all tracked assets and bytes belonging to group. Any configured budget for group is retained.\n\n```go\nfunc (m *MemoryTracker) SetBudget(group string, maxBytes int64)\n```\nSetBudget sets the maximum allowed bytes for group. Passing maxBytes \\\u003c= 0 removes the budget for group.\n\n```go\nfunc (m *MemoryTracker) SetTotalBudget(maxBytes int64)\n```\nSetTotalBudget sets the maximum allowed total bytes across all groups. Passing maxBytes \\\u003c= 0 removes the total budget.\n\n```go\nfunc (m *MemoryTracker) TotalBudget() int64\n```\nTotalBudget returns the configured total byte budget, or 0 when none is set.\n\n```go\nfunc (m *MemoryTracker) TotalBytes() int64\n```\nTotalBytes returns the total tracked bytes across all asset groups.\n\n```go\nfunc (m *MemoryTracker) Track(group, name string, kind AssetKind, bytes int64)\n```\nTrack records or updates an asset named name in group with its AssetKind and size in bytes. Negative byte counts are clamped to 0.\n\n```go\nfunc (m *MemoryTracker) Untrack(group, name string)\n```\nUntrack removes a previously tracked asset from group.\n\n```go\ntype NetChannelStats struct {\n\t// Channel is the transport delivery channel (ChannelReliableOrdered or ChannelUnreliable).\n\tChannel netplay.Channel\n\t// BytesPerSec is the combined send and receive byte rate on this channel.\n\tBytesPerSec float64\n\t// PacketsPerSec is the combined send and receive packet rate on this channel.\n\tPacketsPerSec float64\n\t// SendBytesPerSec is the outbound byte rate on this channel.\n\tSendBytesPerSec float64\n\t// RecvBytesPerSec is the inbound byte rate on this channel.\n\tRecvBytesPerSec float64\n\t// SendPacketsPerSec is the outbound packet rate on this channel.\n\tSendPacketsPerSec float64\n\t// RecvPacketsPerSec is the inbound packet rate on this channel.\n\tRecvPacketsPerSec float64\n}\n```\nNetChannelStats reports live throughput rates for one netplay.Channel.\n\n```go\ntype NetMessageEvent struct {\n\t// Dir is netplay.CaptureSend (\"send\") or netplay.CaptureRecv (\"recv\").\n\tDir netplay.CaptureDirection\n\t// Peer is the remote peer ID.\n\tPeer netplay.PeerID\n\t// Channel is the transport delivery channel.\n\tChannel netplay.Channel\n\t// Type is the decoded wire message type (such as \"replication.delta\", \"rollback.single_input\", \"relay.members\", or \"raw\").\n\tType string\n\t// Bytes is the payload size in bytes.\n\tBytes int\n}\n```\nNetMessageEvent records one recently sent or received packet's decoded wire message type.\n\n```go\ntype NetMonitor struct {\n\t// contains filtered or unexported fields\n}\n```\nNetMonitor tracks per-channel and per-peer throughput rates, Transport InboxStats, and recent decoded wire message types using reused buffers so per-frame updates perform zero heap allocations in steady state.\n\n```go\nfunc NewNetMonitor(recentLimit int) *NetMonitor\n```\nNewNetMonitor creates a NetMonitor retaining up to recentLimit recent message types (defaulting to 12 when \\\u003c= 0).\n\n```go\nfunc (m *NetMonitor) ObserveRecv(pkt netplay.Packet)\n```\nObserveRecv records one inbound packet and decodes its wire message type into reused buffers without steady-state allocations.\n\n```go\nfunc (m *NetMonitor) ObserveSend(to netplay.PeerID, ch netplay.Channel, payload []byte)\n```\nObserveSend records one outbound packet and decodes its wire message type into reused buffers without steady-state allocations.\n\n```go\nfunc (m *NetMonitor) Reset()\n```\nReset clears all accumulated traffic counters, peer trackers, and recent message history while keeping allocated slice capacities.\n\n```go\nfunc (m *NetMonitor) SampleFrame(dt time.Duration)\n```\nSampleFrame commits the current frame's packet/byte counts into the sliding rate window, polls InboxStats from any wrapped InboxReporter, and refreshes the cached NetSnapshot without steady-state heap allocations.\n\n```go\nfunc (m *NetMonitor) Snapshot() NetSnapshot\n```\nSnapshot returns the most recent NetSnapshot built by SampleFrame, backed by m's reused buffers so calling it in Options.Net allocates zero bytes.\n\n```go\nfunc (m *NetMonitor) Wrap(inner netplay.Transport) netplay.Transport\n```\nWrap wraps inner so every successful Send and every Recv packet is observed by m with zero steady-state heap allocations. If inner implements netplay.InboxReporter, SampleFrame polls its InboxStats automatically and the wrapper forwards InboxReporter calls.\n\n```go\ntype NetPeerStats struct {\n\t// Peer identifies the remote peer (or netplay.PeerBroadcast for broadcast sends).\n\tPeer netplay.PeerID\n\t// BytesPerSec is the combined send and receive byte rate with this peer.\n\tBytesPerSec float64\n\t// PacketsPerSec is the combined send and receive packet rate with this peer.\n\tPacketsPerSec float64\n\t// SendBytesPerSec is the outbound byte rate to this peer.\n\tSendBytesPerSec float64\n\t// RecvBytesPerSec is the inbound byte rate from this peer.\n\tRecvBytesPerSec float64\n\t// SendPacketsPerSec is the outbound packet rate to this peer.\n\tSendPacketsPerSec float64\n\t// RecvPacketsPerSec is the inbound packet rate from this peer.\n\tRecvPacketsPerSec float64\n}\n```\nNetPeerStats reports live throughput rates for one remote peer.\n\n```go\ntype NetSnapshot struct {\n\t// Inbox holds the transport's InboxStats counters.\n\tInbox netplay.InboxStats\n\t// Channels holds per-channel throughput rates.\n\tChannels []NetChannelStats\n\t// Peers holds per-peer throughput rates.\n\tPeers []NetPeerStats\n\t// Recent holds the most recent N decoded message events, oldest to newest.\n\tRecent []NetMessageEvent\n}\n```\nNetSnapshot describes live network traffic rates, inbox counters, and recent message types for the debug overlay panel.\n\n```go\ntype Options struct {\n\t// ToggleKey is the key binding that shows and hides the overlay; \"F3\" when empty.\n\tToggleKey string\n\t// Visible sets whether the overlay starts shown.\n\tVisible bool\n\t// TargetFPS is the reference frame rate drawn on the frame-time graph; 60 when 0 or less.\n\tTargetFPS float64\n\t// LineWidth is the base stroke width, in screen points, for collision and bounds wireframes; 1 when 0 or less.\n\tLineWidth float32\n\t// Scenes, when set, supplies the active scenes and layers shown by the scene inspector. If it reads NSGo signals, the inspector updates as those signals change; otherwise it refreshes on recorded frames and RefreshScenes.\n\tScenes func() []SceneSnapshot\n\t// Now is the clock WrapLoop uses to measure Update and Draw durations; time.Now when nil.\n\tNow func() time.Time\n\t// Console, when set, renders an interactive dev console alongside the overlay.\n\tConsole *Console\n\t// Profiler, when set, displays top named timing scopes inside the overlay.\n\tProfiler *Profiler\n\t// Memory, when set, displays asset memory usage and budget status inside the overlay.\n\tMemory *MemoryTracker\n\t// GC, when set, samples GC pauses each frame and highlights GC-hitched frames in the overlay.\n\tGC *GCMonitor\n\t// DrawStats, when set, supplies live per-frame draw statistics displayed in the overlay and exposed to MCP performance readouts.\n\tDrawStats func() DrawStats\n\t// AI, when set, supplies the chosen agent's behavior tree or state machine snapshot shown in the AI inspector panel.\n\t// If it reads NSGo signals, the panel updates reactively; otherwise it refreshes on recorded frames and RefreshAI.\n\tAI func() AISnapshot\n\t// Net, when set, supplies live network traffic rates, InboxStats counters, and recent decoded message types shown in the network inspector panel.\n\t// Callers can build NetSnapshot without per-frame allocations using NetMonitor.\n\tNet func() NetSnapshot\n}\n```\nOptions configures an Overlay. Every field is optional and takes a sensible default when zero.\n\n```go\ntype Overlay struct {\n\t// contains filtered or unexported fields\n}\n```\nOverlay coordinates the development debug HUD: a key-toggled panel with a frame-time graph and scene inspector, plus world-space collision and sprite-bounds wireframes.\n\n```go\nfunc New(opts Options) *Overlay\n```\nNew returns a configured debug overlay.\n\n```go\nfunc (o *Overlay) AISnapshot() AISnapshot\n```\nAISnapshot returns the currently displayed AI snapshot from Options.AI if configured, or the most recent SetAI value.\n\n```go\nfunc (o *Overlay) Attach(cx *core.Scope)\n```\nAttach wires the overlay's reactive signals and toggle key onto cx. Calling Attach more than once on the same scope is a no-op; View calls Attach automatically.\n\n```go\nfunc (o *Overlay) ClearAI()\n```\nClearAI clears the pushed AI snapshot and hides the AI inspector panel when Options.AI is nil.\n\n```go\nfunc (o *Overlay) ClearNet()\n```\nClearNet clears the pushed network snapshot and hides the network inspector panel when Options.Net is nil.\n\n```go\nfunc (o *Overlay) Console() *Console\n```\nConsole returns the Console attached to the overlay via Options.Console, or nil.\n\n```go\nfunc (o *Overlay) DrawBatchBounds(d *core.Drawing, batch *sprite.Batch, col core.Color)\n```\nDrawBatchBounds draws the untrimmed bounding wireframes of all sprites in batch under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawBox(d *core.Drawing, b core.Bounds, col core.Color)\n```\nDrawBox draws a wireframe box under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawCircle(d *core.Drawing, x, y, r float32, col core.Color)\n```\nDrawCircle draws a wireframe circle under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawFighterBoxes(d *core.Drawing, f *framedata.Fighter, hurt, hit core.Color)\n```\nDrawFighterBoxes draws f's active hurtboxes and hitboxes as wireframes under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawPath(d *core.Drawing, path []core.Point, col core.Color)\n```\nDrawPath draws a waypoint polyline under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawShapes(d *core.Drawing, fn func(*ShapeOverlay))\n```\nDrawShapes calls fn with the overlay's ShapeOverlay only while the overlay is visible. When called inside a core.Canvas.Draw callback, toggling the overlay automatically redraws the canvas.\n\n```go\nfunc (o *Overlay) DrawSpriteBounds(d *core.Drawing, s *sprite.Sprite, col core.Color)\n```\nDrawSpriteBounds draws the untrimmed bounding wireframe of s under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawStats() DrawStats\n```\nDrawStats returns the current per-frame draw statistics from Options.DrawStats if configured, or the most recent SetDrawStats value.\n\n```go\nfunc (o *Overlay) DrawSteering(d *core.Drawing, info SteeringDebug)\n```\nDrawSteering draws steering agent guides (velocity, desired velocity, target, path) under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawTarget(d *core.Drawing, target core.Point, col core.Color)\n```\nDrawTarget draws a target reticle under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) DrawVector(d *core.Drawing, origin, vec core.Point, col core.Color)\n```\nDrawVector draws a directional vector arrow under d's active transform while the overlay is visible.\n\n```go\nfunc (o *Overlay) GC() *GCMonitor\n```\nGC returns the GCMonitor attached to the overlay via Options.GC, or nil.\n\n```go\nfunc (o *Overlay) HasDrawStats() bool\n```\nHasDrawStats reports whether draw statistics have been configured via Options.DrawStats or pushed via SetDrawStats.\n\n```go\nfunc (o *Overlay) Memory() *MemoryTracker\n```\nMemory returns the MemoryTracker attached to the overlay via Options.Memory, or nil.\n\n```go\nfunc (o *Overlay) NetSnapshot() NetSnapshot\n```\nNetSnapshot returns the currently displayed network snapshot from Options.Net if configured, or the most recent SetNet value.\n\n```go\nfunc (o *Overlay) NoteFrameCause(cause string)\n```\nNoteFrameCause attaches a short explanation (for example \"first use of torch\\_glow compiled its shader\") to the next frame recorded by RecordFrame. Calling it with an empty string is a no-op; calling it again before RecordFrame replaces the pending cause.\n\n```go\nfunc (o *Overlay) Profiler() *Profiler\n```\nProfiler returns the Profiler attached to the overlay via Options.Profiler, or nil.\n\n```go\nfunc (o *Overlay) RecordFrame(total, update, draw time.Duration)\n```\nRecordFrame records one frame's total, update and draw durations into the ring buffer, samples the attached GCMonitor (if any), and refreshes the visible overlay graph.\n\n```go\nfunc (o *Overlay) RefreshAI()\n```\nRefreshAI tells the AI inspector panel to re-read Options.AI immediately.\n\n```go\nfunc (o *Overlay) RefreshNet()\n```\nRefreshNet tells the network inspector panel to re-read Options.Net immediately.\n\n```go\nfunc (o *Overlay) RefreshScenes()\n```\nRefreshScenes tells the scene inspector to re-read Options.Scenes immediately.\n\n```go\nfunc (o *Overlay) ResetStats()\n```\nResetStats clears the overlay's recorded frame timings and pushed draw statistics and refreshes the visible overlay.\n\n```go\nfunc (o *Overlay) SetAI(snap AISnapshot)\n```\nSetAI updates the AI inspector panel's pushed snapshot and immediately refreshes the panel. It is used when Options.AI is nil.\n\n```go\nfunc (o *Overlay) SetDrawStats(s DrawStats)\n```\nSetDrawStats updates the overlay's pushed per-frame draw statistics and refreshes the visible overlay. It is used when Options.DrawStats is nil.\n\n```go\nfunc (o *Overlay) SetNet(snap NetSnapshot)\n```\nSetNet updates the network inspector panel's pushed snapshot and immediately refreshes the panel. It is used when Options.Net is nil.\n\n```go\nfunc (o *Overlay) SetScenes(scenes []SceneSnapshot)\n```\nSetScenes updates the scene inspector's snapshot list and immediately refreshes the inspector view. It is used when Options.Scenes is nil.\n\n```go\nfunc (o *Overlay) SetVisible(v bool)\n```\nSetVisible shows or hides the overlay and its world-space wireframes.\n\n```go\nfunc (o *Overlay) Stats() *FrameStats\n```\nStats returns the overlay's frame-time ring buffer.\n\n```go\nfunc (o *Overlay) Toggle()\n```\nToggle flips the overlay's visibility.\n\n```go\nfunc (o *Overlay) View(cx *core.Scope) core.Node\n```\nView attaches the overlay to cx and returns a non-intrusive native NSGo overlay node positioned over the game view.\n\n```go\nfunc (o *Overlay) Visible() bool\n```\nVisible reports whether the overlay is currently shown. Read inside a reactive NSGo view or drawing, it subscribes to visibility toggles.\n\n```go\nfunc (o *Overlay) WrapLoop(l *game.Loop)\n```\nWrapLoop wraps l.Update and l.Draw so every frame automatically times Update and Draw and calls RecordFrame.\n\n```go\ntype Profiler struct {\n\t// contains filtered or unexported fields\n}\n```\nProfiler records named timing scopes per frame with zero steady-state allocations, produces top-scope summaries for Overlay, emits optional runtime/trace regions, and exports Chrome/Perfetto Trace Event Format JSON.\n\n```go\nfunc NewProfiler(maxRecordedFrames int) *Profiler\n```\nNewProfiler returns a Profiler capable of recording up to maxRecordedFrames frames (defaulting to 300 when \\\u003c= 0).\n\n```go\nfunc (p *Profiler) Begin(name string) ScopeToken\n```\nBegin opens a named timing scope and returns a ScopeToken to pass to End.\n\n```go\nfunc (p *Profiler) BeginFrame()\n```\nBeginFrame resets per-frame scope accumulators for the next frame.\n\n```go\nfunc (p *Profiler) End(tok ScopeToken)\n```\nEnd closes a timing scope started by Begin or Scope.\n\n```go\nfunc (p *Profiler) EndFrame()\n```\nEndFrame finalizes the current frame's scope timings and advances active recording if enabled.\n\n```go\nfunc (p *Profiler) RecordedFrames() int\n```\nRecordedFrames returns the number of completed frames captured in the current or most recent recording.\n\n```go\nfunc (p *Profiler) Recording() bool\n```\nRecording reports whether trace recording is currently active.\n\n```go\nfunc (p *Profiler) Reset()\n```\nReset clears every scope's accumulated timings and frame history, so TopScopes reports nothing until scopes run again. Scope names keep their IDs, so a ScopeToken opened before Reset and ended after it is still charged to its own scope, and an active or finished trace recording (StartRecording, WriteChromeTrace) is left as it is.\n\n```go\nfunc (p *Profiler) Scope(name string) ScopeToken\n```\nScope opens a named timing scope for use with defer: \\`defer p.Scope(\"physics\").End()\\`.\n\n```go\nfunc (p *Profiler) SetNow(fn func() time.Time)\n```\nSetNow overrides the clock used to timestamp scopes, primarily for deterministic tests. Passing nil restores time.Now.\n\n```go\nfunc (p *Profiler) SetTraceContext(ctx context.Context)\n```\nSetTraceContext sets the context passed to runtime/trace.StartRegion when Go execution tracing is active.\n\n```go\nfunc (p *Profiler) StartRecording(frames int)\n```\nStartRecording begins recording scope events for up to frames frames (capped by maxRecordedFrames).\n\n```go\nfunc (p *Profiler) StopRecording()\n```\nStopRecording ends an active trace recording early, keeping already recorded frames.\n\n```go\nfunc (p *Profiler) TopScopes(limit int) []ScopeSummary\n```\nTopScopes returns up to limit scope summaries sorted descending by per-frame Total duration (then Avg, then Name). If limit \\\u003c= 0, all scopes are returned.\n\n```go\nfunc (p *Profiler) WriteChromeTrace(w io.Writer) error\n```\nWriteChromeTrace writes recorded scope events in Chrome/Perfetto Trace Event Format JSON to w. Each distinct scope name is assigned its own tid track and thread\\_name metadata event so Perfetto displays one track per scope.\n\n```go\ntype SceneSnapshot struct {\n\t// Name identifies the scene, such as \"title\" or \"world\".\n\tName string\n\t// Layers are the scene's layers in draw order.\n\tLayers []LayerSnapshot\n}\n```\nSceneSnapshot describes one active scene for the scene inspector.\n\n```go\ntype ScopeSummary struct {\n\t// Name is the scope identifier passed to Begin or Scope.\n\tName string\n\t// Total is the total duration spent in this scope during the most recent frame.\n\tTotal time.Duration\n\t// Avg is the rolling average per-frame duration across recent frames.\n\tAvg time.Duration\n\t// Max is the longest per-frame duration observed across recent frames.\n\tMax time.Duration\n\t// Calls is the number of times this scope ran during the most recent frame.\n\tCalls int\n}\n```\nScopeSummary summarizes a named timing scope's cost for overlay display.\n\n```go\ntype ScopeToken struct {\n\t// contains filtered or unexported fields\n}\n```\nScopeToken is returned by Profiler.Begin or Profiler.Scope and passed to End to close a timing scope without heap allocations.\n\n```go\nfunc (t ScopeToken) End()\n```\nEnd closes the timing scope associated with t. It is safe to call on a zero ScopeToken.\n\n```go\ntype ShapeOverlay struct {\n\t// LineWidth is the desired stroke width in screen points; 1 when 0 or less.\n\tLineWidth float32\n}\n```\nShapeOverlay draws collision shapes and sprite bounds as wireframes into a core.Drawing under whatever camera or viewport transform is already active on it.\n\nStroke widths are automatically divided by the drawing's active scale so wireframes keep a steady thickness at any camera zoom.\n\n```go\nfunc (s *ShapeOverlay) DrawBatchBounds(d *core.Drawing, batch *sprite.Batch, col core.Color)\n```\nDrawBatchBounds strokes the untrimmed bounding box of every visible sprite in batch in col under d's active transform.\n\n```go\nfunc (s *ShapeOverlay) DrawBox(d *core.Drawing, b core.Bounds, col core.Color)\n```\nDrawBox strokes the axis-aligned rectangle b in col under d's active transform, leaving d's state unchanged.\n\n```go\nfunc (s *ShapeOverlay) DrawCircle(d *core.Drawing, x, y, r float32, col core.Color)\n```\nDrawCircle strokes a circle centered at (x, y) with radius r in col under d's active transform, leaving d's state unchanged.\n\n```go\nfunc (s *ShapeOverlay) DrawFighterBoxes(d *core.Drawing, f *framedata.Fighter, hurt, hit core.Color)\n```\nDrawFighterBoxes strokes the boxes f's current move has active on its current frame under d's active transform: hurtboxes in hurt, then hitboxes in hit on top, mirrored as the fighter faces.\n\n```go\nfunc (s *ShapeOverlay) DrawPath(d *core.Drawing, path []core.Point, col core.Color)\n```\nDrawPath strokes a waypoint polyline and small waypoint markers in col under d's active transform.\n\n```go\nfunc (s *ShapeOverlay) DrawSpriteBounds(d *core.Drawing, sp *sprite.Sprite, col core.Color)\n```\nDrawSpriteBounds strokes the untrimmed bounding box of sp in col, respecting its origin, scale, flip and rotation, under d's active transform.\n\n```go\nfunc (s *ShapeOverlay) DrawSteering(d *core.Drawing, info SteeringDebug)\n```\nDrawSteering draws world-space debug guides for a 2D steering agent under d's active transform: its waypoint path, target reticle and sightline, body radius, desired velocity arrow, and current velocity arrow.\n\n```go\nfunc (s *ShapeOverlay) DrawTarget(d *core.Drawing, target core.Point, col core.Color)\n```\nDrawTarget strokes a crosshair reticle at target in col under d's active transform.\n\n```go\nfunc (s *ShapeOverlay) DrawVector(d *core.Drawing, origin, vec core.Point, col core.Color)\n```\nDrawVector strokes a directional arrow from origin to origin+vec in col under d's active transform, keeping line width and arrowhead size steady in screen points across camera zooms.\n\n```go\ntype SteeringColors struct {\n\t// Agent colors the agent's collision-radius wireframe (default: 0xE2E8F0).\n\tAgent core.Color\n\t// Velocity colors the current velocity vector arrow (default: 0x22C55E).\n\tVelocity core.Color\n\t// Desired colors the desired velocity vector arrow (default: 0x38BDF8).\n\tDesired core.Color\n\t// Target colors the target reticle and sightline (default: 0xF59E0B).\n\tTarget core.Color\n\t// Path colors the waypoint polyline and waypoint markers (default: 0xA78BFA).\n\tPath core.Color\n}\n```\nSteeringColors customizes the colors used by DrawSteering. Zero fields take high-contrast defaults.\n\n```go\ntype SteeringDebug struct {\n\t// Agent is the steering agent whose position, radius, and current velocity are drawn.\n\tAgent ai.Agent\n\t// DesiredVelocity is the agent's desired velocity vector (drawn when non-zero).\n\tDesiredVelocity core.Point\n\t// Target is the agent's current target position (drawn when HasTarget is true).\n\tTarget core.Point\n\t// HasTarget reports whether Target should be drawn, allowing (0, 0) as a valid target.\n\tHasTarget bool\n\t// Path is an optional sequence of world-space waypoints being followed.\n\tPath []core.Point\n\t// WaypointIndex highlights Path[WaypointIndex] as the active waypoint when in [0, len(Path)); set negative to omit active highlighting.\n\tWaypointIndex int\n\t// VelocityScale scales Velocity and DesiredVelocity into world drawing units (1 when 0 or less).\n\tVelocityScale float32\n\t// Colors overrides default colors for any non-zero color field.\n\tColors SteeringColors\n}\n```\nSteeringDebug holds the debug visualization inputs for one 2D steering agent.\n\n```go\ntype TunableChange struct {\n\t// Old is the tunable's value before the change.\n\tOld any\n\t// Tunable describes the tunable after the change; its Value is the value stored.\n\tTunable TunableInfo\n\t// Clamped reports whether the requested value lay outside the tunable's range and was stored as the nearest bound.\n\tClamped bool\n}\n```\nTunableChange is the result of Console.SetTunable.\n\n```go\ntype TunableInfo struct {\n\t// Name is the tunable's registered name.\n\tName string\n\t// Type is \"float\", \"int\", \"bool\" or \"string\".\n\tType string\n\t// Value is the tunable's current value (float64, int, bool or string).\n\tValue any\n\t// Default is the value captured when the tunable was registered.\n\tDefault any\n\t// Min is the inclusive lower bound for numeric tunables (\"float\" or \"int\"), or nil for other types.\n\tMin any\n\t// Max is the inclusive upper bound for numeric tunables (\"float\" or \"int\"), or nil for other types.\n\tMax any\n}\n```\nTunableInfo describes one registered tunable variable on a Console.\n\n","path":"github.com/nsgo-dev/game/pkg/debug","name":"debug","synopsis":"Package debug holds development-only tooling and overlays for NSGo games: a frame-time graph, collision and sprite-bounds wireframes, a live scene inspector, a behavior tree and state machine inspector with steering guides, an interactive dev console with typed tunables, named timing scopes with Chrome/Perfetto trace export, an asset memory tracker with budgets, and a GC/allocation monitor.","isRedistributable":true}
