Documentation
¶
Overview ¶
Package perception provides server-side AI perception primitives: sight cones with line-of-sight predicates, hearing radii driven by caller-emitted stimuli, and a threat ring with TTL-based decay.
Each Sensor is per-entity and owns a small ring buffer of recent stimuli. Sight uses a spatial index to gather candidates within range, applies a cone test (FOV half-angle + range), then defers to a caller-supplied LOSFn (typically backed by navmesh or world collision) for final visibility resolution.
Game-AI-specific; lives under kit/game/.
Index ¶
- type Config
- type EntityID
- type LOSFn
- type Sensor
- func (s *Sensor[T]) Hear(stim Stimulus)
- func (s *Sensor[T]) RecentStimuli(now time.Time) []Stimulus
- func (s *Sensor[T]) Threat() (EntityID, bool)
- func (s *Sensor[T]) Tick(now time.Time)
- func (s *Sensor[T]) UpdateOwner(eye, facing geometry.Vec3, cone SightCone, hearingR float32)
- func (s *Sensor[T]) Visible() []EntityID
- type SightCone
- type Stimulus
- type Targetable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MemoryTTL is how long a stimulus or last-seen target lingers in
// the threat ring before decaying. Defaults to 5s.
MemoryTTL time.Duration
// MaxStimuli bounds the in-memory stimulus ring. Defaults to 16.
MaxStimuli int
// Clock supplies the current time; defaults to time.Now.
Clock func() time.Time
}
Config configures a Sensor.
type LOSFn ¶
LOSFn is the caller-supplied line-of-sight predicate. Returns true when `from` can see `to` (no occluders).
type Sensor ¶
type Sensor[T Targetable] struct { // contains filtered or unexported fields }
Sensor is a per-entity perception state. Not safe for concurrent access; typical owner is the per-entity actor goroutine.
func NewSensor ¶
NewSensor constructs a Sensor over a spatial index with the given LOS predicate (nil ⇒ always visible).
func (*Sensor[T]) Hear ¶
Hear records a stimulus heard by this sensor. Out-of-range stimuli are dropped silently.
func (*Sensor[T]) RecentStimuli ¶
RecentStimuli returns recent stimuli within MemoryTTL, newest first.
func (*Sensor[T]) Threat ¶
Threat returns the current top-priority threat, or (0, false) if the sensor has no live target.
func (*Sensor[T]) UpdateOwner ¶
UpdateOwner refreshes the sensor's eye position, facing direction (unit vector), sight cone, and hearing radius.
type SightCone ¶
type SightCone struct {
// Range is the maximum sight distance, in world units.
Range float32
// HalfAngleRads is half the cone's apex angle, in radians (0..π).
HalfAngleRads float32
}
SightCone defines a sensor's visual frustum.
type Stimulus ¶
type Stimulus struct {
Source EntityID
Position geometry.Vec3
// Loudness is 0..1; the sensor compares against (distance/hearingRadius).
Loudness float32
At time.Time
}
Stimulus is one perceptible event (a sound, a movement, a hit).
type Targetable ¶
Targetable is anything a Sensor can perceive: a spatial.Locatable with an EntityID().