Documentation
¶
Overview ¶
Package vision gives entities a narrowed view of the world: a Sight cone sees what falls inside it, within range and not hidden behind something nearer. Each step fills the Sighted of the observers something reads and runs the rules of a Sighting.
Sight and Sighted ¶
Sight is where an entity looks and how far, a knob vision only reads and an effect may Alter; how wide it sees and from how high is its world.Eye, without which it is never scanned. What the last scan found is its Sighted: at most MaxSeen entities, nearest first. Only an observer something reads is scanned: one a hosted rule of a Sighting is for (it plays the rule's role), one carrying SightOutline, or one carrying Watched, which a game puts on a kind whose Sighted it reads itself; Plugin.WithScanAll scans every observer. Another's Sighted is cleared once, as it stops being read; a log (Plugin.WithLog) reads nobody and shows what is scanned. An observer read is scanned every step, or Plugin.WithFrequency times a second of game time, the scan shared among goroutines (Plugin.WithWorkers). Only an observer within two levels of the finest level any observer camera sees looks, every step (lod.Contact): farther off it sees nothing.
Transparency ¶
Every entity cuts sight unless it carries a Transparency: 1 as if absent, 0 cutting, between them dimming. The world's cover (the board's veiled cells) dims or cuts a ray the same way and is never seen. Sight.Blockers are the world.Layers that cut or dim a sight at all; an entity on none of them is looked over and still seen.
Heights ¶
In a world with heights (Plugin.WithBoard; Plugin.WithHeights and Plugin.WithCover for a ground and a cover of one's own) sight follows geometry: the eye is at the observer's world.Eye, every entity spans its world.Z, and the ground is read along every ray: off its corners inside aabbworld's scan where the ground has them (the relief's lattice), else exactly off a ground.Profile, else sampled every Plugin.WithGroundStep. With a world.Scale the ground sinks under the observer's level as far off as it lies. An Eye with a Vertical field sees up and down within it alone, turned up or down by its Tilt (a rider's head): a sentinel on a wall looking down sees the wall's foot, not the distance; the view drawn is the ground the field meets. Eye.Height and Eye.Vertical are refused in a flat world.
Sighting ¶
A rule of a Sighting (act.Branch[vision.Sighting]{When: cond.Other.If(role), …}) runs once a step per observer playing the rule's role, on everything in view playing the role of Other as Seen values nearest first, even when nothing is. Its Subject is the nearest seen, so an Aimed command is about it and fails with none in view. Its words: SeesNobody of the observer, Closing of the other — the nearest seen on a collision course with the observer.
SightOutline and Renderer ¶
The Renderer draws the views. Through a camera with Rays and in the default style it draws every observer's view on the GPU on [ViewTier], the ground out of sight veiled in a Shadow (Plugin.WithShadow). Otherwise an observer carrying SightOutline has its view's shape computed ([Band]s of hidden ground per angle in a world with heights) and drawn as a ring of [ConePoint]s in a ConeStyle (Plugin.WithStyle). Which views are drawn is the scene's, through world.Show rules (Plugin.WithViews); none, every one. The views drawn on the GPU read no scan: an observer nothing reads has its view drawn all the same.
The views start hidden: the settings screen (Cones) shows and hides them, Write.ShowCones, Write.HideCones and Read.ConesShown do the same from code. A look, not saved; the scan goes on either way.
Vocabulary ¶
Moments, for a role's rules: Sighting (a pair grouped by observer, host.Met, its subject the nearest seen; its words SeesNobody, Closing of the other). Knobs, for an effect's Alter: Sight. Commands: Cones (a player's, a look). Styles, for a figure's Look on the world's atlas (Slot.Styled): Cone, the colour a kind's view is edged in, DefaultCone without; Plugin.WithStyle replaces every kind's with a composer of its own, Plugin.WithShadow the veil over the ground out of sight.
Index ¶
- Constants
- Variables
- func Closing() cond.Word[Sighting]
- func SeesNobody() cond.Word[Sighting]
- type Band
- type Cone
- type ConePoint
- type ConeStyle
- type ConeStyleFn
- type Cones
- type Plugin
- func (p *Plugin) DefaultBindings() []control.Binding
- func (p *Plugin) EventHandler() control.EventHandler
- func (p *Plugin) Install(ctx plugin.Installer) error
- func (p *Plugin) Name() string
- func (p *Plugin) Queues() []command.CommandQueue
- func (p *Plugin) Read(int) *Read
- func (p *Plugin) Restore()
- func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)
- func (p *Plugin) Serializable() plugin.Serializable
- func (p *Plugin) Settings() []control.Setting
- func (p *Plugin) WithBoard(brd *board.Plugin) *Plugin
- func (p *Plugin) WithCover(cover func() ground.Cover) *Plugin
- func (p *Plugin) WithFrequency(perSecond float64) *Plugin
- func (p *Plugin) WithGroundStep(step float32) *Plugin
- func (p *Plugin) WithHeights(heights func() ground.Heights) *Plugin
- func (p *Plugin) WithLog(l *log.Logger) *Plugin
- func (p *Plugin) WithScanAll() *Plugin
- func (p *Plugin) WithShadow(shadow Shadow) *Plugin
- func (p *Plugin) WithStyle(style ConeStyle) *Plugin
- func (p *Plugin) WithViews(rules ...world.Rule) *Plugin
- func (p *Plugin) WithWorkers(n int) *Plugin
- func (p *Plugin) Write() *Write
- type Read
- type Renderer
- func (r *Renderer) Compose(f *render.Frame, cam camera.Camera)
- func (r *Renderer) Draw(t render.Target, cam camera.Camera, _ render.Uniforms)
- func (r *Renderer) Hidden() bool
- func (r *Renderer) Hide(hidden bool)
- func (r *Renderer) Init(si *goke.SysInit)
- func (r *Renderer) Publish()
- func (r *Renderer) Style() ConeStyle
- func (r *Renderer) Swap()
- func (r *Renderer) WithCover(coverOf func() ground.Cover) *Renderer
- func (r *Renderer) WithDrawing(rules *world.Rules) *Renderer
- func (r *Renderer) WithGround(groundOf func() ground.Heights) *Renderer
- func (r *Renderer) WithGroundStep(step float32) *Renderer
- func (r *Renderer) WithInView(inView func(uid.UID64) bool) *Renderer
- func (r *Renderer) WithScale(scale world.Scale) *Renderer
- func (r *Renderer) WithSeen(seen func(camera.Camera) *view.View) *Renderer
- func (r *Renderer) WithShadow(shadow Shadow) *Renderer
- func (r *Renderer) WithStyle(style ConeStyle) *Renderer
- func (r *Renderer) WithStyles(styles func() *render.Styles) *Renderer
- type Resources
- type ScanSystem
- type Seen
- type Settings
- type Shadow
- type Sight
- type SightOutline
- type Sighted
- type Sighting
- type Transparency
- type Watched
- type Write
Constants ¶
const ( // MaxSightRadius is the longest range the outline is sized for; a longer Radius still sees, // its outline is only coarser. MaxSightRadius = 600 // MaxHalfAngleMilli is the widest half-angle the sizing assumes, in milliradians (pi/6). MaxHalfAngleMilli = 524 // EdgeTolerance is how far a shadow edge may land from its true angle at full range. EdgeTolerance = 5 MaxSamples = (arcMilli+gapMilli-1)/gapMilli + 1 )
Sizing of the outline buffer: the first three decide MaxSamples.
const MaxSeen = 8
MaxSeen caps how many entities one scan records, nearest first.
const MaxShadowsPerSample = 2
MaxShadowsPerSample caps the stretches of hidden ground kept per angle of an outline; the nearest are kept.
Variables ¶
var DefaultCone = Cone{Color: color.RGBA{R: 255, G: 220, B: 90, A: 160}}
DefaultCone is a pale yellow edge.
var DefaultShadow = Shadow{Color: color.RGBA{R: 10, G: 10, B: 20, A: 110}, Fade: 6}
DefaultShadow is a dark veil fading in over a few units.
Functions ¶
func Closing ¶ added in v0.3.0
Closing is the word of the nearest one seen being on a collision course with the observer, of the other.
func SeesNobody ¶ added in v0.3.0
SeesNobody is the word of an observer with nobody in view.
Types ¶
type Band ¶ added in v0.3.0
type Band struct{ From, To float32 }
Band is a stretch along one angle of a view, From to To away from the observer; zero is none.
type Cone ¶ added in v0.3.0
Cone is how the view of a kind of observer is drawn: its edge stroked in Color, a pixel wide, the inside clear. A figure declares it on the world's atlas (Slot.Styled); a kind without one is drawn in DefaultCone.
type ConePoint ¶ added in v0.3.0
ConePoint is a point of a view's outline on screen, where the view lies there over the ground (At) and how many screen units a world unit spans there (camera.ScaleAt; 0 not in front of the eye).
type ConeStyle ¶
ConeStyle composes one entity's view from its outline: a closed ring starting at the observer, out along one edge of the cone, round its boundary and back along the other edge. Each point lies where the view does over the ground under it.
type ConeStyleFn ¶
ConeStyleFn adapts a plain function to ConeStyle.
type Cones ¶ added in v0.3.0
type Cones struct{ Shown bool }
Cones shows every view drawn — the cones of sight and the ground out of sight — or hides them (Settings.Cones). A look at the world, like the camera's turn: at once, in the pause too. The settings screen alone.
type Plugin ¶
Plugin wires vision into a Stage over the world's space. It publishes what entities can see; what to do about it is a rule's business.
func NewPlugin ¶
NewPlugin builds the vision plugin over worldPlugin's space; the views drawn start hidden.
func (*Plugin) DefaultBindings ¶ added in v0.3.0
DefaultBindings are none: the cones are the settings screen's.
func (*Plugin) EventHandler ¶
func (p *Plugin) EventHandler() control.EventHandler
EventHandler is nil: the Cones command comes from a player's bindings.
func (*Plugin) Queues ¶ added in v0.3.0
func (p *Plugin) Queues() []command.CommandQueue
Queues are where Cones lands.
func (*Plugin) Read ¶ added in v0.4.0
Read reads vision's settings on worker w of the game's pool, 0 the game's own goroutine.
func (*Plugin) Restore ¶ added in v0.3.0
func (p *Plugin) Restore()
Restore takes the Settings loaded and shows the views as they say.
func (*Plugin) RunPlan ¶
RunPlan carries out the commands and runs the scan; call it after the world's RunPlan.
func (*Plugin) Serializable ¶
func (p *Plugin) Serializable() plugin.Serializable
Serializable is vision's Settings, kept whole; its components go with the entities.
func (*Plugin) Settings ¶ added in v0.3.0
Settings is the one setting, the views drawn (plugin.Tunable).
func (*Plugin) WithBoard ¶ added in v0.3.0
WithBoard has sight follow brd's ground and be held back by its cover, and the views drawn over the ground as the frame drawn holds it; call before Use.
func (*Plugin) WithCover ¶ added in v0.3.0
WithCover has sight held back by the cover cover gives when a scan starts, on every goroutine the scan is shared among; nil, nothing.
func (*Plugin) WithFrequency ¶ added in v0.3.0
WithFrequency has the observers scanned perSecond times a second of game time in place of every step (0), their rules going on with what each saw last between scans; call before Use.
func (*Plugin) WithGroundStep ¶ added in v0.3.0
WithGroundStep sets how far apart a scan with heights samples a ground without a ground.Profile along a ray, in place of the board's cell; call before Use.
func (*Plugin) WithHeights ¶ added in v0.3.0
WithHeights has sight follow the ground heights gives when a scan starts; nil, flat.
func (*Plugin) WithLog ¶ added in v0.3.0
WithLog has vision write a line to l the first time one entity sees another; call before Use.
func (*Plugin) WithScanAll ¶ added in v0.6.0
WithScanAll has every observer scanned, whether anything reads its Sighted or not; call before Use.
func (*Plugin) WithShadow ¶ added in v0.3.0
WithShadow sets how the ground out of sight is shaded, in place of DefaultShadow.
func (*Plugin) WithStyle ¶
WithStyle sets how every cone is drawn in place of the kinds' Cones: a composer of its own, on the CPU.
func (*Plugin) WithViews ¶ added in v0.3.0
WithViews has only the views of the observers a world.Show rule picks drawn; with none, every one is. Call it in the scene, before the first frame.
func (*Plugin) WithWorkers ¶ added in v0.3.0
WithWorkers sets how many goroutines of the game's pool at most share a scan: 0 (as it starts) all, 1 none. Call before Use.
type Read ¶ added in v0.4.0
type Read struct {
// contains filtered or unexported fields
}
Read reads vision's settings, the same on every goroutine.
func (*Read) ConesShown ¶ added in v0.4.0
ConesShown reports whether the views drawn are shown.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer draws the views, lying over the ground under what stands on it: through a camera with Rays and in the default style every observer's on the GPU, the ground out of sight veiled in a Shadow; otherwise, as a render.Source, the outline of every entity carrying SightOutline in a ConeStyle. The observers are published once a frame.
func NewRenderer ¶
NewRenderer builds a Renderer drawing every kind in DefaultCone and DefaultShadow over space.
func (*Renderer) Compose ¶ added in v0.3.0
Compose hands f every view in sight of cam, or notes them for Draw; nothing while hidden.
func (*Renderer) Draw ¶
Draw draws the views Compose noted on the GPU; nothing where it composed them.
func (*Renderer) Publish ¶ added in v0.5.0
func (r *Renderer) Publish()
Publish takes every observer some camera sees whose view is drawn, and the cover where any is, for the frame drawn next; none while hidden.
func (*Renderer) Swap ¶ added in v0.5.0
func (r *Renderer) Swap()
Swap has what was published last drawn.
func (*Renderer) WithCover ¶ added in v0.3.0
WithCover has the views drawn on the GPU dimmed by the cover coverOf gives.
func (*Renderer) WithDrawing ¶ added in v0.3.0
WithDrawing has only the views of the observers a world.Show rule picks drawn; with none, every one is.
func (*Renderer) WithGround ¶ added in v0.3.0
WithGround has the views follow the ground groundOf gives.
func (*Renderer) WithGroundStep ¶ added in v0.3.0
WithGroundStep drapes the views over the ground every step world units, in place of the ground's own step.
func (*Renderer) WithInView ¶ added in v0.5.0
WithInView has only the observers some camera sees published, as inView says.
func (*Renderer) WithScale ¶ added in v0.3.0
WithScale sinks the ground under an eye's level as far off as it lies, as scale's sight does.
func (*Renderer) WithSeen ¶ added in v0.3.0
WithSeen has the views drawn only of the observers in what a camera sees, as seen says.
func (*Renderer) WithShadow ¶ added in v0.3.0
WithShadow replaces how the ground out of sight is shaded.
type Resources ¶ added in v0.3.0
type Resources struct {
Settings Settings
}
Resources is what vision publishes: its Settings.
type ScanSystem ¶
type ScanSystem struct {
// contains filtered or unexported fields
}
ScanSystem fills in what every observer something reads sees, and the outline of those carrying SightOutline, then runs the rules of a Sighting over what each saw.
func (*ScanSystem) Every ¶ added in v0.3.0
func (s *ScanSystem) Every(perSecond float64)
Every has each observer scanned perSecond times a second, 0 every step. Call it before Init.
func (*ScanSystem) Init ¶
func (s *ScanSystem) Init(si *goke.SysInit)
func (*ScanSystem) Paced ¶ added in v0.3.0
func (s *ScanSystem) Paced(pace goke.Opt) *ScanSystem
Paced has the system scan each block of observers as pace, an option of its query, says; set before Init.
func (*ScanSystem) Pool ¶ added in v0.4.0
func (s *ScanSystem) Pool(p *parallel.Pool)
Pool sets the goroutines a scan is shared among; nil, one. Call it before Init.
func (*ScanSystem) Workers ¶ added in v0.3.0
func (s *ScanSystem) Workers(n int)
Workers sets how many goroutines of the pool at most share a scan: 0 all, 1 none. Call it before Init.
type Settings ¶ added in v0.3.0
type Settings struct {
Cones bool
}
Settings is what vision lets the players adjust, saved with the game.
type Shadow ¶ added in v0.3.0
Shadow is how the ground out of sight is shaded: a veil of Color over it, fading in over Fade world units wherever it meets ground in sight.
type Sight ¶
type Sight struct {
Facing geom.Vec // unit vector
Radius float32 // world units
// Blockers are the world.Layers whose entities and cover cut or dim this sight, every one for
// zero; one on none of them is looked over and still seen.
Blockers world.Layers
// Ahead has the sight look the way the entity moves, Facing only while it has no heading.
Ahead bool
}
Sight is where an entity looks and how far, a knob vision only reads and an effect may Alter. How wide it sees and from how high is its world.Eye, which the scan needs beside it.
type SightOutline ¶
type SightOutline struct {
Depths [MaxSamples]float32
Shadows [MaxSamples][MaxShadowsPerSample]Band
Count uint8
}
SightOutline is the shape of one entity's view: a reach per evenly spaced angle across the cone and, in a world with heights, the stretches of ground out of sight along each. Only an entity carrying it has its outline computed.
type Sighted ¶
Sighted is what an observer's last scan found, nearest first; vision gives one to an observer that has none. Count says how many of the arrays are in use.
type Sighting ¶
Sighting is one observer and everything in its view carrying the rule's second tag, nearest first, possibly none.
type Transparency ¶ added in v0.3.0
type Transparency struct{ Value float32 }
Transparency is how see-through an entity is to a Sight: 0 cuts sight as an entity without it does, 1 is as if absent, between them a ray through it spends 1/Value of its reach per unit.
type Watched ¶ added in v0.6.0
type Watched struct{}
Watched marks an observer whose Sighted the game reads itself, in a system, a plan or a fact: vision scans it though no rule of a Sighting is for it.