simulator

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 1 Imported by: 0

README

Simulator 模块架构

该目录提供运行循环的辅助组件,拆分后的结构如下:

Simulator
  ├─ Runner (周期推进)
  ├─ CommandLoop (命令管理)
  └─ VisualBridge (可视化桥接)
  • Runner:封装命令循环与可视化桥接,供主循环统一调度。
  • CommandLoop:抽象命令来源与处理逻辑,负责串行消费控制指令。
  • VisualBridge:对接可视化通道,集中管理 headless 状态与帧发布。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandler

type CommandHandler[T any] interface {
	HandleCommand(T) bool
}

CommandHandler consumes control commands and determines whether processing should continue.

type CommandHandlerFunc

type CommandHandlerFunc[T any] func(T) bool

CommandHandlerFunc adapts a function into a CommandHandler.

func (CommandHandlerFunc[T]) HandleCommand

func (f CommandHandlerFunc[T]) HandleCommand(cmd T) bool

HandleCommand calls the underlying function.

type CommandLoop

type CommandLoop[T any] struct {
	// contains filtered or unexported fields
}

CommandLoop drains and dispatches control commands.

func NewCommandLoop

func NewCommandLoop[T any](source CommandSource[T], handler CommandHandler[T]) *CommandLoop[T]

NewCommandLoop creates a command loop with the given source and handler.

func (*CommandLoop[T]) DrainPending

func (c *CommandLoop[T]) DrainPending() bool

DrainPending pulls all currently available commands from the source until exhaustion or handler termination.

func (*CommandLoop[T]) WaitAndHandle

func (c *CommandLoop[T]) WaitAndHandle(ctx context.Context) bool

WaitAndHandle blocks until a command is available (or context cancellation) and dispatches it.

type CommandSource

type CommandSource[T any] interface {
	NextCommand() (T, bool)
	WaitCommand(context.Context) (T, bool)
}

CommandSource provides control commands from an external producer.

type Runner

type Runner[TCommand any, Frame any] struct {
	// contains filtered or unexported fields
}

Runner glues command handling and visualization helpers for the main simulator loop.

func NewRunner

func NewRunner[TCommand any, Frame any](loop *CommandLoop[TCommand], visual *VisualBridge[Frame]) *Runner[TCommand, Frame]

NewRunner creates a new Runner instance.

func (*Runner[TCommand, Frame]) DrainPendingCommands

func (r *Runner[TCommand, Frame]) DrainPendingCommands() bool

DrainPendingCommands pulls all queued commands through the underlying command loop.

func (*Runner[TCommand, Frame]) PublishFrame

func (r *Runner[TCommand, Frame]) PublishFrame(frame Frame)

PublishFrame emits a frame through the visual bridge if visualization is enabled.

func (*Runner[TCommand, Frame]) UpdateCommandLoop

func (r *Runner[TCommand, Frame]) UpdateCommandLoop(loop *CommandLoop[TCommand])

UpdateCommandLoop swaps the command loop reference.

func (*Runner[TCommand, Frame]) UpdateVisualBridge

func (r *Runner[TCommand, Frame]) UpdateVisualBridge(visual *VisualBridge[Frame])

UpdateVisualBridge swaps the visual bridge reference (e.g., after reset).

func (*Runner[TCommand, Frame]) VisualEnabled

func (r *Runner[TCommand, Frame]) VisualEnabled() bool

VisualEnabled reports whether visualization bridge is active.

func (*Runner[TCommand, Frame]) WaitForCommand

func (r *Runner[TCommand, Frame]) WaitForCommand(ctx context.Context) bool

WaitForCommand blocks on the command loop until a command arrives or context is cancelled.

type VisualBridge

type VisualBridge[Frame any] struct {
	// contains filtered or unexported fields
}

VisualBridge coordinates optional visualization publishing.

func NewVisualBridge

func NewVisualBridge[Frame any](headless bool, publish func(Frame)) *VisualBridge[Frame]

NewVisualBridge constructs a bridge with headless flag and publish callback.

func (*VisualBridge[Frame]) IsHeadless

func (v *VisualBridge[Frame]) IsHeadless() bool

IsHeadless reports whether visualization output is disabled.

func (*VisualBridge[Frame]) Publish

func (v *VisualBridge[Frame]) Publish(frame Frame)

Publish emits a frame when visualization is enabled.

func (*VisualBridge[Frame]) SetHeadless

func (v *VisualBridge[Frame]) SetHeadless(headless bool)

SetHeadless updates the headless flag.

func (*VisualBridge[Frame]) UpdatePublisher

func (v *VisualBridge[Frame]) UpdatePublisher(publish func(Frame))

UpdatePublisher resets the publish callback.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL