Documentation
¶
Index ¶
- Constants
- Variables
- func DespawnOnEnterState[S comparable](state S) despawnOnEnterStateComponent[S]
- func DespawnOnExitState[S comparable](state S) despawnOnExitStateComponent[S]
- func EventType[E any]() eventType
- func ResourceExists[T any](res ResOption[T]) bool
- func ResourceMissing[T any](res ResOption[T]) bool
- func ResourceOf[T any](w *World) (*T, bool)
- func ValidateComponent[C IsComponent[C]]() struct{}
- type Added
- type AnyPtr
- type AnySystem
- type App
- func (a *App) AddEvent(newEvent eventType)
- func (a *App) AddPlugin(plugin Plugin)
- func (a *App) AddSystems(scheduleId ScheduleId, system AnySystem, systems ...AnySystem)
- func (a *App) ConfigureSystemSets(scheduleId ScheduleId, sets ...*SystemSet)
- func (a *App) InitState(newState stateType)
- func (a *App) InsertResource(res any)
- func (a *App) MustRun()
- func (a *App) Run() error
- func (a *App) RunWorld(run Runner)
- func (a *App) World() *World
- type Changed
- type ChildOf
- type Children
- type Command
- type CommandFn
- type Commands
- func (c *Commands) Entity(entityId EntityId) EntityCommands
- func (c *Commands) InsertResource(resource any) *Commands
- func (c *Commands) Queue(command Command) *Commands
- func (c *Commands) RunSystem(system AnySystem) *Commands
- func (c *Commands) RunSystemWith(system AnySystem, inValue any) *Commands
- func (c *Commands) Spawn(components ...ErasedComponent) EntityCommands
- func (c *Commands) Trigger(eventValue any) *Commands
- type ComparableComponent
- type Component
- type EntityCommand
- type EntityCommands
- func (e EntityCommands) Despawn()
- func (e EntityCommands) Id() EntityId
- func (e EntityCommands) Insert(components ...ErasedComponent) EntityCommands
- func (e EntityCommands) Observe(system AnySystem) EntityCommands
- func (e EntityCommands) Trigger(eventValue any) EntityCommands
- func (e EntityCommands) Update(commands ...EntityCommand) EntityCommands
- type EntityId
- type ErasedComponent
- type EventId
- type EventReader
- type EventWithId
- type EventWriter
- type Events
- type FixedTime
- type Has
- type ImmutableComponent
- type In
- type IsComparableComponent
- type IsComponent
- type IsImmutableComponent
- type IsRelationshipComponent
- type IsRelationshipTargetComponent
- type Local
- type Name
- type NextState
- type Observer
- type On
- type Option
- type OptionMut
- type Or
- type OrStruct
- type Plugin
- type Query
- type Relationship
- type RelationshipTarget
- type RemovedComponents
- type Res
- type ResOption
- type Runner
- type ScheduleId
- type Single
- type State
- type StateTransitionEvent
- type StateType
- type SystemId
- type SystemParam
- type SystemParamState
- type SystemSet
- type Systems
- type Timer
- func (t *Timer) Duration() time.Duration
- func (t *Timer) Elapsed() time.Duration
- func (t *Timer) Finished() bool
- func (t *Timer) Fraction() float64
- func (t *Timer) FractionRemaining() float64
- func (t *Timer) JustFinished() bool
- func (t *Timer) Remaining() time.Duration
- func (t *Timer) Reset()
- func (t *Timer) Tick(delta time.Duration) *Timer
- func (t *Timer) TimesFinishedThisTick() int
- type TimerMode
- type TimingStats
- type TimingStopwatch
- type Timings
- type VirtualTime
- type With
- type Without
- type World
- func (w *World) AddObserver(observer Observer) EntityId
- func (w *World) AddSystems(scheduleId ScheduleId, firstSystem AnySystem, systems ...AnySystem)
- func (w *World) ConfigureSystemSets(scheduleId ScheduleId, systemSets ...*SystemSet)
- func (w *World) Despawn(entityId EntityId)
- func (w *World) InsertResource(resource any)
- func (w *World) RemoveResource(resourceType reflect.Type)
- func (w *World) Resource(ty reflect.Type) (AnyPtr, bool)
- func (w *World) RunSchedule(scheduleId ScheduleId)
- func (w *World) RunSystem(system AnySystem)
- func (w *World) RunSystemWithInValue(system AnySystem, inValue any)
- func (w *World) Spawn(components []ErasedComponent) EntityId
- func (w *World) TriggerObserver(targetId EntityId, eventValue any)
Constants ¶
const NoEntityId = EntityId(0)
Variables ¶
var ( // Main is the main schedule that executes all other schedules in the correct order. Main = MakeScheduleId("Main") RunFixedMainLoop = MakeScheduleId("RunFixedMainLoop") // FixedMain is the fixed time step main schedule that // executes the other fixed step schedules in the correct order. FixedMain = MakeScheduleId("FixedMain") PreStartup = MakeScheduleId("PreStartup") Startup = MakeScheduleId("Startup") PostStartup = MakeScheduleId("PostStartup") First = MakeScheduleId("First") PreUpdate = MakeScheduleId("PreUpdate") StateTransition = MakeScheduleId("StateTransition") Update = MakeScheduleId("Update") PostUpdate = MakeScheduleId("PostUpdate") PreRender = MakeScheduleId("PreRender") Render = MakeScheduleId("Render") PostRender = MakeScheduleId("PostRender") Last = MakeScheduleId("Last") FixedFirst = MakeScheduleId("FixedFirst") FixedPreUpdate = MakeScheduleId("FixedPreUpdate") FixedUpdate = MakeScheduleId("FixedUpdate") FixedPostUpdate = MakeScheduleId("FixedPostUpdate") FixedLast = MakeScheduleId("FixedLast") )
var ErrSkipSystem = errors.New("skip system")
Functions ¶
func DespawnOnEnterState ¶
func DespawnOnEnterState[S comparable](state S) despawnOnEnterStateComponent[S]
func DespawnOnExitState ¶
func DespawnOnExitState[S comparable](state S) despawnOnExitStateComponent[S]
func ResourceExists ¶
ResourceExists is a system predicate that can be passed to Systems.RunIf to only run a system if a given resource does exist in the world. Use it as a reference:
app.AddSystems(Update, System(doSomething).RunIf(ResourceExists[MyResource]))
func ResourceMissing ¶
ResourceMissing is a system predicate thtat can be passed to Systems.RunIf to only run a system if a given resource does not exist in the world. Use it as a reference:
app.AddSystems(Update, System(doSomething).RunIf(ResourceMissing[MyResource]))
func ResourceOf ¶
ResourceOf is a typed version of World.Resource.
func ValidateComponent ¶
func ValidateComponent[C IsComponent[C]]() struct{}
ValidateComponent should be called to verify that the IsComponent interface is correctly implemented.
type Position struct {
Component[Position]
X, Y float64
}
var _ = ValidateComponent[Position]()
This identifies mistakes in the type passed to Component during compile time.
Types ¶
type Added ¶
type Added[C IsComponent[C]] = query.Added[C]
Added is a query filter that constraints the entities matched to include only entities that have added a component of type C since the last tick that the system owning the Query ran.
type AnySystem ¶
type AnySystem any
AnySystem can be anything that can be coerced into a system.
func InState ¶
func InState[S comparable](expectedState S) AnySystem
InState is a system predicate that can be passed to Systems.RunIf to only run a system if a given state has the expected value.
app.AddSystems(Update, System(doSomething).RunIf(InState(MenuStateTitle)))
func NotInState ¶
func NotInState[S comparable](stateValue S) AnySystem
NotInState is a system predicate that can be passed to Systems.RunIf to only run a system if a given state does not have a specific value.
app.AddSystems(Update, System(doSomething).RunIf(NotInState(MenuStateTitle)))
func TimerJustFinished ¶
TimerJustFinished is a system predicate that can be passed to Systems.RunIf to only run a system if the provided timer has just finished.
type App ¶
type App struct {
// contains filtered or unexported fields
}
App provides an entry point to your application.
func (*App) AddEvent ¶
func (a *App) AddEvent(newEvent eventType)
AddEvent configures a new event in the World. Use EventType to acquire a value implementing eventType.
func (*App) AddSystems ¶
func (a *App) AddSystems(scheduleId ScheduleId, system AnySystem, systems ...AnySystem)
AddSystems adds one or more systems to the World.
func (*App) ConfigureSystemSets ¶
func (a *App) ConfigureSystemSets(scheduleId ScheduleId, sets ...*SystemSet)
ConfigureSystemSets configures sets in a schedule.
func (*App) InitState ¶
func (a *App) InitState(newState stateType)
InitState configures a new state in the World. Use StateType to acquire a value implementing stateType.
func (*App) InsertResource ¶
InsertResource inserts a resource into the World. See World.InsertResource.
type Changed ¶
type Changed[C spoke.IsSupportsChangeDetectionComponent[C]] = query.Changed[C]
Changed is a query filter that constraints the entities matched to include only entities that have a changed Component value of type C since the last tick that the system owning the Query ran.
Change detection currently works by hashing the component value. As such, matching for changed component values is not 100% foolproof in case of hash collisions.
type ChildOf ¶
type ChildOf struct {
ImmutableComponent[ChildOf]
Relationship[Children]
Parent EntityId
}
func (ChildOf) RelationshipEntityId ¶
type Children ¶
type Children struct {
ImmutableComponent[Children]
RelationshipTarget[ChildOf]
}
type Commands ¶
type Commands struct {
// contains filtered or unexported fields
}
Commands is a SystemParam that allows you to send commands to a world. It allows you to spawn and despawn entities and to add and remove components. It must be injected as a pointer into a system.
func (*Commands) Entity ¶
func (c *Commands) Entity(entityId EntityId) EntityCommands
func (*Commands) InsertResource ¶
func (*Commands) RunSystemWith ¶
func (*Commands) Spawn ¶
func (c *Commands) Spawn(components ...ErasedComponent) EntityCommands
type ComparableComponent ¶
type ComparableComponent[T IsComparableComponent[T]] = spoke.ComparableComponent[T]
ComparableComponent is a zero sized type that may be embedded into a struct to turn that struct into a comparable component (see IsComponent).
type Component ¶
type Component[T IsComponent[T]] = spoke.Component[T]
Component is a zero sized type that may be embedded into a struct to turn that struct into a component (see IsComponent).
type EntityCommand ¶
func InsertComponent ¶
func InsertComponent[C IsComponent[C]](optionalValue ...C) EntityCommand
func RemoveComponent ¶
func RemoveComponent[C IsComponent[C]]() EntityCommand
type EntityCommands ¶
type EntityCommands struct {
// contains filtered or unexported fields
}
func (EntityCommands) Despawn ¶
func (e EntityCommands) Despawn()
func (EntityCommands) Id ¶
func (e EntityCommands) Id() EntityId
func (EntityCommands) Insert ¶
func (e EntityCommands) Insert(components ...ErasedComponent) EntityCommands
func (EntityCommands) Observe ¶
func (e EntityCommands) Observe(system AnySystem) EntityCommands
func (EntityCommands) Trigger ¶
func (e EntityCommands) Trigger(eventValue any) EntityCommands
func (EntityCommands) Update ¶
func (e EntityCommands) Update(commands ...EntityCommand) EntityCommands
type ErasedComponent ¶
type ErasedComponent = spoke.ErasedComponent
ErasedComponent indicates a type erased Component value.
Values given to the consumer of byke of this type are usually pointers, even though the interface is actually implemented directly on the component type.
func BundleOf ¶
func BundleOf(components ...ErasedComponent) ErasedComponent
func SpawnChild ¶
func SpawnChild(components ...ErasedComponent) ErasedComponent
type EventReader ¶
type EventReader[E any] struct { // contains filtered or unexported fields }
func (*EventReader[E]) Read ¶
func (r *EventReader[E]) Read() []E
type EventWithId ¶
type EventWriter ¶
type EventWriter[E any] struct { // contains filtered or unexported fields }
func (*EventWriter[E]) Write ¶
func (w *EventWriter[E]) Write(event E)
type Events ¶
type Events[E any] struct { // contains filtered or unexported fields }
func (*Events[E]) AppendTo ¶
func (e *Events[E]) AppendTo(target []EventWithId[E]) []EventWithId[E]
func (*Events[E]) Reader ¶
func (e *Events[E]) Reader() *EventReader[E]
func (*Events[E]) Writer ¶
func (e *Events[E]) Writer() *EventWriter[E]
type FixedTime ¶
type FixedTime struct {
Elapsed time.Duration
Delta time.Duration
DeltaSecs float64
StepInterval time.Duration
// contains filtered or unexported fields
}
FixedTime should be used in fixed step systems to measure the progression of time.
FixedTime will be updated using the value delta provided by VirtualTime, which might be scaled. In this case, time might accumulate more slowly and FixedTime steps will also be executed less often. To counteract this, you can decrement the StepInterval to executed fixed time step systems more often.
The default value of StepInterval is taken from bevy and is 1/64s.
type Has ¶
type Has[C IsComponent[C]] = query.Has[C]
Has is a query parameter that does not fetch the actual Component value of type T, but rather just indicates if a component of such type exists on the type. Currently it does not provide a performance boost over using an Option.
type ImmutableComponent ¶
type ImmutableComponent[T spoke.IsImmutableComponent[T]] = spoke.ImmutableComponent[T]
ImmutableComponent is a zero sized type that may be embedded into a struct to turn that struct into an immutable component (see IsComponent).
type In ¶
type In[T any] struct { Value T }
In describes an input parameter of a system. A system can only accept exactly one input parameter.
type IsComparableComponent ¶
type IsComparableComponent[T IsComponent[T]] = spoke.IsComparableComponent[T]
IsComparableComponent indicates that a component is comparable. Only comparable components and immutable components can be used with the Changed query filter. At the time of writing, comparable components have a performance overhead when queried by pointer.
To implement the IsComparableComponent interface for a type, you must embed the ComparableComponent type.
type IsComponent ¶
type IsComponent[T any] = spoke.IsComponent[T]
IsComponent can be used in a type parameter to ensure that type T is a Component type.
To implement the IsComponent interface for a type, you must embed the Component type.
type IsImmutableComponent ¶
type IsImmutableComponent[T IsComponent[T]] = spoke.IsImmutableComponent[T]
IsImmutableComponent indicates that a component is immutable and can not be queried using pointer access. Immutable components can be updated by inserting a new copy of the same component into an entity using Command.
To implement the IsImmutableComponent interface for a type, you must embed the ImmutableComponent type.
type IsRelationshipComponent ¶
type IsRelationshipComponent[T IsImmutableComponent[T]] interface { IsImmutableComponent[T] // contains filtered or unexported methods }
type IsRelationshipTargetComponent ¶
type IsRelationshipTargetComponent[T IsImmutableComponent[T]] interface { IsImmutableComponent[T] // contains filtered or unexported methods }
type Local ¶
type Local[T any] struct { Value T // contains filtered or unexported fields }
Local is a SystemParam that provides a value local to a system. It must be injected as a pointer value.
A system can have multiple independent Local parameters even with the same type T.
type Name ¶
type Name struct {
spoke.ImmutableComponent[Name]
Name string
}
Name assigns a non unique name to an entity. Adding a name can be helpful for debugging.
type NextState ¶
type NextState[S comparable] struct { // contains filtered or unexported fields }
type Option ¶
type Option[C IsComponent[C]] = query.Option[C]
Option is a query parameter that fetches a given Component of type T if it exists on an entity.
type OptionMut ¶
type OptionMut[C IsComponent[C]] = query.OptionMut[C]
OptionMut is a query parameter that fetches for a pointer to a Component of type T if it exists on an entity.
type Or ¶
Or is a query filter that allows you to combine two query filters with a local 'or'. Simply adding multiple filters to a query requires all filters to match. Using Or you can build a query, where just one of multiple filter need to match
type OrStruct ¶
OrStruct combines a struct of multiple filters with a logical Or. The type parameter S must be a struct type that contains only fields of type EmbeddableFilter named with an underscore.
type Plugin ¶
type Plugin func(app *App)
Plugin for an App. Call App.AddPlugin to add a Plugin to an App.
type Relationship ¶
type Relationship[Parent IsImmutableComponent[Parent]] struct{}
Relationship must be embedded on the client side of a relationship
func (Relationship[Parent]) RelationshipTargetType ¶
func (Relationship[Parent]) RelationshipTargetType() *spoke.ComponentType
type RelationshipTarget ¶
type RelationshipTarget[Child IsImmutableComponent[Child]] struct { // contains filtered or unexported fields }
RelationshipTarget must be embedded on the parent side of a relationship
func (*RelationshipTarget[Child]) Children ¶
func (p *RelationshipTarget[Child]) Children() []EntityId
Children returns the children in this component. You **must not** modify the returned slice.
func (*RelationshipTarget[Child]) RelationshipType ¶
func (*RelationshipTarget[Child]) RelationshipType() *spoke.ComponentType
type RemovedComponents ¶
type RemovedComponents[C IsComponent[C]] struct { // contains filtered or unexported fields }
type Res ¶
type Res[T any] struct { Value T // contains filtered or unexported fields }
Res provides a SystemParam to inject a resource at runtime.
This is currently the same as just declaring the resource type directly as a parameter. In the future, the Res type may offer additional information, such as resource change tracking.
type ResOption ¶
type ResOption[T any] struct { Value *T // contains filtered or unexported fields }
ResOption allows to inject a resource as a system param if it exists in the world. If the resource does not exist, the system will still run but a zero ResOption is injected.
type ScheduleId ¶
ScheduleId identifies a schedule. All implementing types must be comparable.
func MakeScheduleId ¶
func MakeScheduleId(name string) ScheduleId
MakeScheduleId creates a new unique ScheduleId. The name passed to the schedule is used for debugging
func OnEnter ¶
func OnEnter[S comparable](stateValue S) ScheduleId
func OnExit ¶
func OnExit[S comparable](stateValue S) ScheduleId
func OnTransition ¶
func OnTransition[S comparable](previousStateValue, currentStateValue S) ScheduleId
type State ¶
type State[S comparable] struct { // contains filtered or unexported fields }
type StateTransitionEvent ¶
type StateTransitionEvent[S comparable] struct { PreviousState S CurrentState S }
func (*StateTransitionEvent[S]) IsIdentity ¶
func (t *StateTransitionEvent[S]) IsIdentity() bool
type StateType ¶
type StateType[S comparable] struct { InitialValue S }
type SystemId ¶
SystemId uniquely identifies a system.
Implementation note: this currently uses the function pointer. A function pointer in go has two layers of indirection to be able to handle closures correctly. The function pointer points to a small memory region holding a pointer to the actual function, as well as all data closed over by a closure. The SystemId currently points to this outer region of memory, not to the function code itself.
type SystemParam ¶
type SystemParam interface {
// contains filtered or unexported methods
}
SystemParam is an interface to give a type special behaviour when it is used as a parameter to a system.
While a system is being prepared, byke will check each parameter if it fulfills the SystemParam interface. If a parameter type does, a new instance will be allocate and the init method will be called.
See Local, ResOption or Query for some implementations of SystemParam.
type SystemParamState ¶
type SystemParamState interface {
// contains filtered or unexported methods
}
SystemParamState is the state produced by SystemParam. TODO i need to check this interface & the assumptions,
maybe it makes sense to merge it into SystemParam.
type SystemSet ¶
type SystemSet struct {
// contains filtered or unexported fields
}
SystemSet groups multiple systems together within one ScheduleId. SystemSet instances can be ordered between each other
type Systems ¶
type Systems struct {
// contains filtered or unexported fields
}
Systems wrap one or more systems. See System for more details.
func System ¶
System wraps one or multiple systems (raw functions, other Systems) as a Systems instance. The Systems instance can then be used to configure inter system ordering or run predicates.
func (Systems) After ¶
After adds an ordering constraint to require all systems to run after the provided systems.
func (Systems) Before ¶
Before adds an ordering constraint to require all systems to run before the provided systems.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is either a one of or a repeating timer with a specific duration.
func NewTimerWithFrequency ¶
NewTimerWithFrequency creates a new repeating timer with the given frequency
func (*Timer) Finished ¶
Finished returns true if the timer has finished. In case this is a timer with mode TimerModeRepeating, this method will never return true.
func (*Timer) Fraction ¶
Fraction returns the fraction to that this timer has finished. A freshly started timer will have a Fraction value of 0.
func (*Timer) FractionRemaining ¶
FractionRemaining is the inverse of Fraction.
func (*Timer) JustFinished ¶
JustFinished returns true if the timer has reached its duration at the previous call to Tick.
func (*Timer) TimesFinishedThisTick ¶
TimesFinishedThisTick returns the number of times this timer has finished at the previous call to Tick. E.g. if you tick a 1 second timer with a 3.5 second delta, the timer will have finished three times in this tick.
type TimerMode ¶
type TimerMode uint8
const TimerModeOnce TimerMode = 0
const TimerModeRepeating TimerMode = 1
type TimingStats ¶
type TimingStats struct {
Visible bool
BySchedule map[ScheduleId]Timings
ScheduleOrder []ScheduleId
BySystem map[*preparedSystem]Timings
}
func NewTimingStats ¶
func NewTimingStats() TimingStats
func (*TimingStats) MeasureSchedule ¶
func (t *TimingStats) MeasureSchedule(scheduleId ScheduleId) TimingStopwatch
func (*TimingStats) MeasureSystem ¶
func (t *TimingStats) MeasureSystem(system *preparedSystem) TimingStopwatch
type TimingStopwatch ¶
type TimingStopwatch struct {
Stop func()
}
type Timings ¶
type VirtualTime ¶
type VirtualTime struct {
Elapsed time.Duration
Delta time.Duration
DeltaSecs float64
Scale float64
}
VirtualTime tracks time.
The progression of time can be scaled by setting the Scale field. This will scale the Delta and DeltaSecs values starting at the next frame.
type With ¶
type With[C IsComponent[C]] = query.With[C]
With is a query filter that constraints the entities queried to include only entities that have a Component of type T.
type Without ¶
type Without[C IsComponent[C]] = query.Without[C]
Without is a query filter that constraints the entities queried to include only entities that do not have a Component of type T.
type World ¶
type World struct {
// contains filtered or unexported fields
}
World holds all entities and resources, schedules, systems, etc. While an empty World can be created using NewWorld, it is normally created and configured by using the App api.
func NewWorld ¶
func NewWorld() *World
NewWorld creates a new empty world. You probably want to use the App api instead.
func (*World) AddObserver ¶
AddObserver adds a new observer. Observers are entities containing the Observer component.
func (*World) AddSystems ¶
func (w *World) AddSystems(scheduleId ScheduleId, firstSystem AnySystem, systems ...AnySystem)
AddSystems adds systems to a schedule within the world.
func (*World) ConfigureSystemSets ¶
func (w *World) ConfigureSystemSets(scheduleId ScheduleId, systemSets ...*SystemSet)
func (*World) InsertResource ¶
InsertResource inserts a new resource into the world. The resource should be provided as a non-pointer type.
If the resource does not yet exist, a new value of the resources type will be allocated on the heap and the value provided will be copied into that memory location.
If the world already contains a resource of the same type, this value will just be updated with the newly provided one.
func (*World) RemoveResource ¶
RemoveResource removes a resource previously added with InsertResource.
func (*World) Resource ¶
Resource returns a pointer to the resource of the given reflect type. The type must be the non-pointer type of the resource, i.e. the type of the resource as it was passed to InsertResource.
func (*World) RunSchedule ¶
func (w *World) RunSchedule(scheduleId ScheduleId)
RunSchedule runs the schedule identified by the given ScheduleId. If no schedule with this id exists, no action is performed.
func (*World) RunSystemWithInValue ¶
func (*World) Spawn ¶
func (w *World) Spawn(components []ErasedComponent) EntityId
Spawn spawns a new entity with the given components.
func (*World) TriggerObserver ¶
TriggerObserver triggers all observers listening on the given target (or all targets) for the given event value.
TODO observer event propagation is not yet implemented.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples/asteroids
command
|
|
|
examples/camera
command
|
|
|
examples/manysprites
command
|
|
|
examples/polygons
command
|
|
|
examples/shader
command
|
|
|
examples/starter
command
|
|
|
examples/transform
command
|
|
|
examples/vectors
command
|
|
|
internal/earcut/viewer
command
|
|
|
Package gm (stands for geometry math) provides some geometry primitives.
|
Package gm (stands for geometry math) provides some geometry primitives. |
|
internal
|
|