Documentation
¶
Index ¶
- Constants
- Variables
- func Clamp(x, min, max float64) float64
- func NewWorld(e *Engine) *ecs.World
- func RegisterComponentSystem(cs ComponentSystem)
- func RepeatSpriteSystemExec(ctx Context)
- func SetupSystem(w *ecs.World, cs ComponentSystem)
- func SpriteAnimationLinkSystemExec(ctx Context)
- func SpriteAnimationSystemExec(ctx Context)
- func SpriteSystemExec(ctx Context)
- func TransformSpriteSystemExec(ctx Context)
- func TransformSystemExec(ctx Context)
- func UpsertComponent(w ecs.Worlder, comp ecs.NewComponentInput) *ecs.Component
- type AnimClipMode
- type Archetype
- type BaseComponentSystem
- type BasicCS
- func (cs *BasicCS) BasicCS() int
- func (cs *BasicCS) Components(w ecs.Worlder) []*ecs.Component
- func (cs *BasicCS) SystemExec() SystemExecFn
- func (cs *BasicCS) SystemInit() SystemInitFn
- func (cs *BasicCS) SystemName() string
- func (cs *BasicCS) SystemPriority() int
- func (cs *BasicCS) SystemTags() []string
- type ComponentSystem
- type Context
- type Dict
- type Engine
- func (e *Engine) AddWorld(w *ecs.World, priority int)
- func (e *Engine) Default() *ecs.World
- func (e *Engine) FS() fs.Filesystem
- func (e *Engine) Get(key string) interface{}
- func (e *Engine) RemoveWorld(w *ecs.World) bool
- func (e *Engine) Run() error
- func (e *Engine) Set(key string, value interface{})
- type EngineOptions
- type Matrix
- func (m Matrix) Chained(next Matrix) Matrix
- func (m Matrix) Moved(delta Vec) Matrix
- func (m Matrix) Project(u Vec) Vec
- func (m Matrix) Rotated(around Vec, angle float64) Matrix
- func (m Matrix) Scaled(around Vec, scale float64) Matrix
- func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix
- func (m Matrix) String() string
- func (m Matrix) Unproject(u Vec) Vec
- type Middleware
- type NewEngineInput
- type Rect
- func (r Rect) Area() float64
- func (r Rect) Center() Vec
- func (r Rect) Contains(u Vec) bool
- func (r Rect) H() float64
- func (r Rect) Intersect(s Rect) Rect
- func (r Rect) Moved(delta Vec) Rect
- func (r Rect) Norm() Rect
- func (r Rect) Resized(anchor, size Vec) Rect
- func (r Rect) ResizedMin(size Vec) Rect
- func (r Rect) Size() Vec
- func (r Rect) String() string
- func (r Rect) Union(s Rect) Rect
- func (r Rect) W() float64
- type RepeatSprite
- type RepeatSpriteComponentSystem
- func (cs *RepeatSpriteComponentSystem) Components(w ecs.Worlder) []*ecs.Component
- func (cs *RepeatSpriteComponentSystem) SystemExec() SystemExecFn
- func (cs *RepeatSpriteComponentSystem) SystemName() string
- func (cs *RepeatSpriteComponentSystem) SystemPriority() int
- func (cs *RepeatSpriteComponentSystem) SystemTags() []string
- type Sprite
- type SpriteAnimation
- type SpriteAnimationClip
- type SpriteAnimationComponentSystem
- type SpriteAnimationLinkComponentSystem
- func (cs *SpriteAnimationLinkComponentSystem) Components(w ecs.Worlder) []*ecs.Component
- func (cs *SpriteAnimationLinkComponentSystem) SystemExec() SystemExecFn
- func (cs *SpriteAnimationLinkComponentSystem) SystemName() string
- func (cs *SpriteAnimationLinkComponentSystem) SystemPriority() int
- func (cs *SpriteAnimationLinkComponentSystem) SystemTags() []string
- type SpriteComponentSystem
- func (cs *SpriteComponentSystem) Components(w ecs.Worlder) []*ecs.Component
- func (cs *SpriteComponentSystem) SystemExec() SystemExecFn
- func (cs *SpriteComponentSystem) SystemInit() SystemInitFn
- func (cs *SpriteComponentSystem) SystemName() string
- func (cs *SpriteComponentSystem) SystemPriority() int
- func (cs *SpriteComponentSystem) SystemTags() []string
- type SystemExecFn
- type SystemInitFn
- type Transform
- type TransformComponentSystem
- func (cs *TransformComponentSystem) Components(w ecs.Worlder) []*ecs.Component
- func (cs *TransformComponentSystem) SystemExec() SystemExecFn
- func (cs *TransformComponentSystem) SystemInit() SystemInitFn
- func (cs *TransformComponentSystem) SystemName() string
- func (cs *TransformComponentSystem) SystemPriority() int
- type TransformSpriteComponentSystem
- type Vec
- func (u Vec) Add(v Vec) Vec
- func (u Vec) Angle() float64
- func (u Vec) Cross(v Vec) float64
- func (u Vec) Dot(v Vec) float64
- func (u Vec) Len() float64
- func (u Vec) Map(f func(float64) float64) Vec
- func (u Vec) Normal() Vec
- func (u Vec) Project(v Vec) Vec
- func (u Vec) Rotated(angle float64) Vec
- func (u Vec) Scaled(c float64) Vec
- func (u Vec) ScaledXY(v Vec) Vec
- func (u Vec) String() string
- func (u Vec) Sub(v Vec) Vec
- func (u Vec) To(v Vec) Vec
- func (u Vec) Unit() Vec
- func (u Vec) XY() (x, y float64)
- type WorldTag
Constants ¶
const ( SNRepeatSprite string = "tau.RepeatSpriteSystem" CNRepeatSprite string = "tau.RepeatSpriteComponent" )
const ( SNSprite = "tau.SpriteSystem" CNSprite = "tau.SpriteComponent" )
const ( SNSpriteAnimation = "tau.SpriteAnimationSystem" SNSpriteAnimationLink = "tau.SpriteAnimationLinkSystem" CNSpriteAnimation = "tau.SpriteAnimationComponent" )
const ( SNTransform = "tau.TransformSystem" SNTransformSprite = "tau.TransformSpriteSystem" CNTransform = "tau.TransformComponent" )
const ( // DefaultImageOptions key passed to the default world (&ebiten.DrawImageOptions{}) DefaultImageOptions string = "default_image_options" )
const TagDelta = "delta"
TagDelta is the key set of the time taken between frames (in seconds)
Variables ¶
var ( SpriteAnimationCS *SpriteAnimationComponentSystem = new(SpriteAnimationComponentSystem) SpriteAnimationLinkCS *SpriteAnimationLinkComponentSystem = new(SpriteAnimationLinkComponentSystem) )
var IM = Matrix{1, 0, 0, 1, 0, 0}
IM stands for identity matrix. Does nothing, no transformation.
var ZV = Vec{0, 0}
ZV is a zero vector.
Functions ¶
func Clamp ¶
Clamp returns x clamped to the interval [min, max].
If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is returned.
func RegisterComponentSystem ¶
func RegisterComponentSystem(cs ComponentSystem)
func RepeatSpriteSystemExec ¶
func RepeatSpriteSystemExec(ctx Context)
RepeatSpriteSystemExec is the function executed every frame
func SetupSystem ¶
func SetupSystem(w *ecs.World, cs ComponentSystem)
func SpriteAnimationLinkSystemExec ¶
func SpriteAnimationLinkSystemExec(ctx Context)
SpriteAnimationLinkSystemExec is what glues the animation and sprite together
func SpriteAnimationSystemExec ¶
func SpriteAnimationSystemExec(ctx Context)
SpriteAnimationSystemExec is the main function of the SpriteSystem
func SpriteSystemExec ¶
func SpriteSystemExec(ctx Context)
SpriteSystemExec is the main function of the SpriteSystem
func TransformSpriteSystemExec ¶
func TransformSpriteSystemExec(ctx Context)
TransformSpriteSystemExec is the main function of the TransformSpriteSystem
func TransformSystemExec ¶
func TransformSystemExec(ctx Context)
TransformSystemExec is the main function of the TransformSystem
func UpsertComponent ¶
Types ¶
type AnimClipMode ¶
type AnimClipMode byte
AnimClipMode determines how time is treated outside of the keyframed range of an animation clip.
const ( // AnimOnce - When time reaches the end of the animation clip, the clip will automatically // stop playing and time will be reset to beginning of the clip. AnimOnce AnimClipMode = 0 // AnimLoop - When time reaches the end of the animation clip, time will continue at the beginning. AnimLoop AnimClipMode = 1 // AnimPingPong - When time reaches the end of the animation clip, time will ping pong back between beginning // and end. AnimPingPong AnimClipMode = 2 // AnimClampForever - Plays back the animation. When it reaches the end, it will keep playing the last frame // and never stop playing. // // When playing backwards it will reach the first frame and will keep playing that. This is useful for code // that uses the Playing bool to avoid activating said trigger. AnimClampForever AnimClipMode = 3 )
type Archetype ¶
Archetype is a recipe to create entities with a preset of components.
func NewArchetype ¶
NewArchetype returns a new archetype. This func unsures that no duplicated components are added.
func RepeatSpriteArchetype ¶
RepeatSpriteArchetype order: SpriteComponent(w) RepeatSpriteComponent(w)
type BaseComponentSystem ¶
type BaseComponentSystem struct {
}
func (*BaseComponentSystem) SystemExec ¶
func (cs *BaseComponentSystem) SystemExec() SystemExecFn
func (*BaseComponentSystem) SystemInit ¶
func (cs *BaseComponentSystem) SystemInit() SystemInitFn
func (*BaseComponentSystem) SystemPriority ¶
func (cs *BaseComponentSystem) SystemPriority() int
func (*BaseComponentSystem) SystemTags ¶
func (cs *BaseComponentSystem) SystemTags() []string
type BasicCS ¶
type BasicCS struct {
SysName string
SysPriority int
SysInit SystemInitFn
SysExec SystemExecFn
SysTags []string
GetComponents func(w ecs.Worlder) []*ecs.Component
}
func (*BasicCS) SystemExec ¶
func (cs *BasicCS) SystemExec() SystemExecFn
func (*BasicCS) SystemInit ¶
func (cs *BasicCS) SystemInit() SystemInitFn
func (*BasicCS) SystemName ¶
func (*BasicCS) SystemPriority ¶
func (*BasicCS) SystemTags ¶
type ComponentSystem ¶
type ComponentSystem interface {
SystemName() string
SystemPriority() int
SystemInit() SystemInitFn
SystemExec() SystemExecFn
SystemTags() []string
Components(w ecs.Worlder) []*ecs.Component
}
type Context ¶
type Context interface {
ecs.Context
Engine() *Engine
FPS() float64
Frame() int64
IsDrawingSkipped() bool
DefaultDrawImageOptions() *ebiten.DrawImageOptions
Screen() *ebiten.Image
}
Context is the context passed to every system update function.
type Dict ¶
type Dict struct {
// contains filtered or unexported fields
}
Dict is a concurrency-safe map.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is what controls the ECS of tau.
func (*Engine) AddWorld ¶
AddWorld adds a world to the engine. The priority is used to sort world execution, from hight to low.
func (*Engine) RemoveWorld ¶
RemoveWorld removes a *World
type EngineOptions ¶
EngineOptions is used to setup Ebiten @ Engine.boot
type Matrix ¶
type Matrix [6]float64
Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such as movement, scaling and rotations.
Matrix has a handful of useful methods, each of which adds a transformation to the matrix. For example:
pixel.IM.Moved(pixel.V(100, 200)).Rotated(pixel.ZV, math.Pi/2)
This code creates a Matrix that first moves everything by 100 units horizontally and 200 units vertically and then rotates everything by 90 degrees around the origin.
Layout is: [0] [2] [4] [1] [3] [5]
0 0 1 (implicit row)
func (Matrix) Chained ¶
Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied after the transformations of this Matrix.
func (Matrix) Project ¶
Project applies all transformations added to the Matrix to a vector u and returns the result.
Time complexity is O(1).
func (Matrix) Rotated ¶
Rotated rotates everything around a given point by the given angle in radians.
func (Matrix) ScaledXY ¶
ScaledXY scales everything around a given point by the scale factor in each axis respectively.
func (Matrix) String ¶
String returns a string representation of the Matrix.
m := pixel.IM fmt.Println(m) // Matrix(1 0 0 | 0 1 0)
func (Matrix) Unproject ¶
Unproject does the inverse operation to Project.
It turns out that multiplying a vector by the inverse matrix of m can be nearly-accomplished by subtracting the translate part of the matrix and multplying by the inverse of the top-left 2x2 matrix, and the inverse of a 2x2 matrix is simple enough to just be inlined in the computation.
Time complexity is O(1).
type Middleware ¶
type Middleware func(next SystemExecFn) SystemExecFn
Middleware is a system middleware
type NewEngineInput ¶
NewEngineInput is the input data of NewEngine
func (*NewEngineInput) Options ¶
func (i *NewEngineInput) Options() EngineOptions
Options will create a EngineOptions struct to be used in an *Engine
type Rect ¶
type Rect struct {
Min, Max Vec
}
Rect is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.
The invariant should hold, that Max's components are greater or equal than Min's components respectively.
func R ¶
R returns a new Rect with given the Min and Max coordinates.
Note that the returned rectangle is not automatically normalized.
func (Rect) Contains ¶
Contains checks whether a vector u is contained within this Rect (including it's borders).
func (Rect) Intersect ¶
Intersect returns the maximal Rect which is covered by both r and s. Rects r and s must be normalized.
If r and s don't overlap, this function returns R(0, 0, 0, 0).
func (Rect) Norm ¶
Norm returns the Rect in normal form, such that Max is component-wise greater or equal than Min.
func (Rect) Resized ¶
Resized returns the Rect resized to the given size while keeping the position of the given anchor.
r.Resized(r.Min, size) // resizes while keeping the position of the lower-left corner r.Resized(r.Max, size) // same with the top-right corner r.Resized(r.Center(), size) // resizes around the center
This function does not make sense for resizing a rectangle of zero area and will panic. Use ResizedMin in the case of zero area.
func (Rect) ResizedMin ¶
ResizedMin returns the Rect resized to the given size while keeping the position of the Rect's Min.
Sizes of zero area are safe here.
func (Rect) String ¶
String returns the string representation of the Rect.
r := pixel.R(100, 50, 200, 300) r.String() // returns "Rect(100, 50, 200, 300)" fmt.Println(r) // Rect(100, 50, 200, 300)
type RepeatSprite ¶
RepeatSprite is the component data of a RepeatSpriteComponent
type RepeatSpriteComponentSystem ¶
type RepeatSpriteComponentSystem struct {
BaseComponentSystem
}
func (*RepeatSpriteComponentSystem) Components ¶
func (cs *RepeatSpriteComponentSystem) Components(w ecs.Worlder) []*ecs.Component
func (*RepeatSpriteComponentSystem) SystemExec ¶
func (cs *RepeatSpriteComponentSystem) SystemExec() SystemExecFn
func (*RepeatSpriteComponentSystem) SystemName ¶
func (cs *RepeatSpriteComponentSystem) SystemName() string
func (*RepeatSpriteComponentSystem) SystemPriority ¶
func (cs *RepeatSpriteComponentSystem) SystemPriority() int
func (*RepeatSpriteComponentSystem) SystemTags ¶
func (cs *RepeatSpriteComponentSystem) SystemTags() []string
type Sprite ¶
type Sprite struct {
X float64
Y float64
Angle float64
ScaleX float64
ScaleY float64
OriginX float64
OriginY float64
Bounds image.Rectangle // Bounds for drawing subimage
Options *ebiten.DrawImageOptions
Image *ebiten.Image
DrawDisabled bool // if true, the SpriteSystem will not draw this
// contains filtered or unexported fields
}
Sprite is the data of a sprite component.
func (*Sprite) GetPrecomputedImage ¶
GetPrecomputedImage returns the last precomputed image
func (*Sprite) GetPrecomputedImageDim ¶
GetPrecomputedImageDim returns the last precomputed image dimmensions
type SpriteAnimation ¶
type SpriteAnimation struct {
Enabled bool
Playing bool
ActiveClip int
ActiveFrame int
Clips []SpriteAnimationClip
T float64
// Default fps for clips with no fps specified
Fps float64
// contains filtered or unexported fields
}
SpriteAnimation holds the data of a sprite animation (and clips)
func (*SpriteAnimation) PlayClip ¶
func (a *SpriteAnimation) PlayClip(name string)
PlayClip sets the animation to play a clip by name
type SpriteAnimationClip ¶
type SpriteAnimationClip struct {
// The name of an animation is not allowed to be changed during runtime
// but since this is part of a component (and components shouldn't have logic),
// it is a public member.
Name string
Frames []image.Rectangle
Fps float64
ClipMode AnimClipMode
}
SpriteAnimationClip is an animation clip, like a character walk cycle.
type SpriteAnimationComponentSystem ¶
type SpriteAnimationComponentSystem struct {
BaseComponentSystem
}
func (*SpriteAnimationComponentSystem) Components ¶
func (cs *SpriteAnimationComponentSystem) Components(w ecs.Worlder) []*ecs.Component
func (*SpriteAnimationComponentSystem) SystemExec ¶
func (cs *SpriteAnimationComponentSystem) SystemExec() SystemExecFn
func (*SpriteAnimationComponentSystem) SystemName ¶
func (cs *SpriteAnimationComponentSystem) SystemName() string
func (*SpriteAnimationComponentSystem) SystemPriority ¶
func (cs *SpriteAnimationComponentSystem) SystemPriority() int
type SpriteAnimationLinkComponentSystem ¶
type SpriteAnimationLinkComponentSystem struct {
BaseComponentSystem
}
func (*SpriteAnimationLinkComponentSystem) Components ¶
func (cs *SpriteAnimationLinkComponentSystem) Components(w ecs.Worlder) []*ecs.Component
func (*SpriteAnimationLinkComponentSystem) SystemExec ¶
func (cs *SpriteAnimationLinkComponentSystem) SystemExec() SystemExecFn
func (*SpriteAnimationLinkComponentSystem) SystemName ¶
func (cs *SpriteAnimationLinkComponentSystem) SystemName() string
func (*SpriteAnimationLinkComponentSystem) SystemPriority ¶
func (cs *SpriteAnimationLinkComponentSystem) SystemPriority() int
func (*SpriteAnimationLinkComponentSystem) SystemTags ¶
func (cs *SpriteAnimationLinkComponentSystem) SystemTags() []string
type SpriteComponentSystem ¶
type SpriteComponentSystem struct {
BaseComponentSystem
}
var (
SpriteCS *SpriteComponentSystem = new(SpriteComponentSystem)
)
func (*SpriteComponentSystem) Components ¶
func (cs *SpriteComponentSystem) Components(w ecs.Worlder) []*ecs.Component
func (*SpriteComponentSystem) SystemExec ¶
func (cs *SpriteComponentSystem) SystemExec() SystemExecFn
func (*SpriteComponentSystem) SystemInit ¶
func (cs *SpriteComponentSystem) SystemInit() SystemInitFn
func (*SpriteComponentSystem) SystemName ¶
func (cs *SpriteComponentSystem) SystemName() string
func (*SpriteComponentSystem) SystemPriority ¶
func (cs *SpriteComponentSystem) SystemPriority() int
func (*SpriteComponentSystem) SystemTags ¶
func (cs *SpriteComponentSystem) SystemTags() []string
type SystemExecFn ¶
type SystemExecFn func(ctx Context)
func SystemWrap ¶
func SystemWrap(fn SystemExecFn, mid ...Middleware) SystemExecFn
SystemWrap wraps middlewares into a SystemExecFn
type Transform ¶
type Transform struct {
Parent *Transform
X float64
Y float64
Angle float64
ScaleX float64
ScaleY float64
// calculated transform matrix
M Matrix
// contains filtered or unexported fields
}
Transform is a hierarchy based matrix
func NewTransform ¶
func NewTransform() *Transform
NewTransform returns a new transform with ScaleX = 1 and ScaleY = 1
type TransformComponentSystem ¶
type TransformComponentSystem struct {
BaseComponentSystem
}
func (*TransformComponentSystem) Components ¶
func (cs *TransformComponentSystem) Components(w ecs.Worlder) []*ecs.Component
func (*TransformComponentSystem) SystemExec ¶
func (cs *TransformComponentSystem) SystemExec() SystemExecFn
func (*TransformComponentSystem) SystemInit ¶
func (cs *TransformComponentSystem) SystemInit() SystemInitFn
func (*TransformComponentSystem) SystemName ¶
func (cs *TransformComponentSystem) SystemName() string
func (*TransformComponentSystem) SystemPriority ¶
func (cs *TransformComponentSystem) SystemPriority() int
type TransformSpriteComponentSystem ¶
type TransformSpriteComponentSystem struct {
BaseComponentSystem
}
func (*TransformSpriteComponentSystem) Components ¶
func (cs *TransformSpriteComponentSystem) Components(w ecs.Worlder) []*ecs.Component
func (*TransformSpriteComponentSystem) SystemExec ¶
func (cs *TransformSpriteComponentSystem) SystemExec() SystemExecFn
func (*TransformSpriteComponentSystem) SystemName ¶
func (cs *TransformSpriteComponentSystem) SystemName() string
func (*TransformSpriteComponentSystem) SystemPriority ¶
func (cs *TransformSpriteComponentSystem) SystemPriority() int
type Vec ¶
type Vec struct {
X, Y float64
}
Vec is a 2D vector type with X and Y coordinates.
Create vectors with the V constructor:
u := pixel.V(1, 2) v := pixel.V(8, -3)
Use various methods to manipulate them:
w := u.Add(v)
fmt.Println(w) // Vec(9, -1)
fmt.Println(u.Sub(v)) // Vec(-7, 5)
u = pixel.V(2, 3)
v = pixel.V(8, 1)
if u.X < 0 {
fmt.Println("this won't happen")
}
x := u.Unit().Dot(v.Unit())
func Lerp ¶
Lerp returns a linear interpolation between vectors a and b.
This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.
func (Vec) Angle ¶
Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].
func (Vec) Map ¶
Map applies the function f to both x and y components of the vector u and returns the modified vector.
u := pixel.V(10.5, -1.5) v := u.Map(math.Floor) // v is Vec(10, -2), both components of u floored
func (Vec) Normal ¶
Normal returns a vector normal to u. Equivalent to u.Rotated(math.Pi / 2), but faster.
func (Vec) Project ¶
Project returns a projection (or component) of vector u in the direction of vector v.
Behaviour is undefined if v is a zero vector.
func (Vec) String ¶
String returns the string representation of the vector u.
u := pixel.V(4.5, -1.3) u.String() // returns "Vec(4.5, -1.3)" fmt.Println(u) // Vec(4.5, -1.3)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
sprite-utils/packer
command
|
|
|
sprite-utils/sprcenter
command
|
|
|
tcli
command
|
|
|
examples
|
|
|
animation
command
|
|
|
hello
command
|
|
|
sprites
command
|
|
|
transform_sprites
command
|
|
|
internal
|
|
|
sets
Package sets contains implementations of sets.
|
Package sets contains implementations of sets. |
|
smid
Package smid provides common middlewares for systems.
|
Package smid provides common middlewares for systems. |