particle

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefType = Type{
	EmissionShape: Point{},

	Color: lerpc.Const(mat.White),
	Mask:  lerpc.Const(mat.White),

	ScaleMultiplier:   lerp.Const(1),
	Acceleration:      lerp.Const(0),
	TwerkAcceleration: lerp.Const(0),

	Velocity: lerp.Const(0),
	Livetime: lerp.Const(1),
	Rotation: lerp.Const(0),
	Spread:   lerp.Const(0),
	ScaleX:   lerp.Const(1),
	ScaleY:   lerp.Const(1),

	Gravity: mat.V(0, -300),
	// contains filtered or unexported fields
}

DefType contains default configuration ro Type

Functions

This section is empty.

Types

type Assets

type Assets struct {
	ColorTweens     map[string]lerpc.Tween
	ColorGenerators map[string]lerpc.Generator
	FloatTweens     map[string]lerp.Tween
	FloatGenerators map[string]lerp.Generator
	Drawers         map[string]Drawer
	EmissionShapes  map[string]EmissionShape
}

Assets can contain custom Objects that Parser uses to load the Type

type Circle

type Circle struct {
	drw.Circle
}

Circle extends dw circle to implement the Drawer interface

func (*Circle) Copy

func (c *Circle) Copy() Drawer

Copy implements Drawer interface

func (*Circle) Metrics

func (c *Circle) Metrics() (indices, vertexes int)

Metrics implements Drawer interface

type Circular

type Circular struct {
	Radius, Spread float64
}

Circular spawns particles in specified arc, possibly circle

func (Circular) Gen

func (c Circular) Gen(dir float64) mat.Vec

Gen implements EmissionShape interface

type Drawer

type Drawer interface {
	ggl.Drawer
	Copy() Drawer
	Metrics() (indices, vertexes int)
}

Drawer is a particle drawer, core is a ggl.Drawer but it also has to be able to copy it self and provide how math indices and vertexes one draw takes

type EmissionShape

type EmissionShape interface {
	Gen(direction float64) mat.Vec
}

EmissionShape is a vector generator, usefull for particle system (determining particle spawn position)

type Parser

type Parser struct {
	Assets

	Parser goss.Parser
	Styles goss.Styles
}

Parser performs parsing of goss into particle Tapes

func (*Parser) AddGoss

func (p *Parser) AddGoss(source []byte) error

AddGoss parses the goss source and adds all results to Styles

func (*Parser) Construct

func (p *Parser) Construct(name string) *Type

Construct constructs the Type under given name and returns it if there is no goss style defining this Type, nil is returned

type Point

type Point struct{}

Point is most basic emission shape, all particles will get spawned o a same position

func (Point) Gen

func (p Point) Gen(t float64) mat.Vec

Gen implements EmissionShape interface

type RawStyle

type RawStyle struct {
	load.RawStyle
}

RawStyle extends load.Rawstile by particle specific functionality

func WrapStyle

func WrapStyle(s goss.Style) RawStyle

WrapStyle wraps a goss.Style into Raw Style

func (RawStyle) ColorGen

func (r RawStyle) ColorGen(key string, custom map[string]lerpc.Generator, def lerpc.Generator) (e lerpc.Generator)

ColorGen parses a color generator, syntax documented on RawStyle.color method applies

func (RawStyle) ColorTween

func (r RawStyle) ColorTween(key string, custom map[string]lerpc.Tween, def lerpc.Tween) (e lerpc.Tween)

ColorTween parses a color tween, syntax documented on RawStyle.color method applies

func (RawStyle) Drawer

func (r RawStyle) Drawer(key string, custom map[string]Drawer, def Drawer) (e Drawer)

Drawer parses drawer under the key, if parsing fails, def is returned

syntax:

circle radius outline resolution - if you prefix property with 'circle' and provide two numbers

circular drawer will be used

rect width height - if you prefix property with 'rect' and provide 2 values, rectangle drawer

will be used

name - providing neather rect nor circle prefix, custom drawer will be searched

func (RawStyle) EmissionShape

func (r RawStyle) EmissionShape(key string, custom map[string]EmissionShape, def EmissionShape) (e EmissionShape)

EmissionShape parses emission shape under given key, if parsing fails def is returned

syntax:

circle radius spread - if you prefix property with 'circle' and provide two numbers

circular shape will be used, if you omit second value, circle will fall back to default (math.Pi)

rect width height - if you prefix property with 'rect' and provide 2 values, rectangle shape

will be used, if you omit height, width is used for both dimension

name - if you provide neither rect nor circle prefix, custom shape will be searched

func (RawStyle) FloatGen

func (r RawStyle) FloatGen(key string, custom map[string]lerp.Generator, def lerp.Generator) (e lerp.Generator)

FloatGen returns float generator, returns def if process failed

syntax:

	number - returns lerp.Constant(number)
 random number number - if you prefix field with 'random' and provide two numbers lerp.Random(number, number)

is returned

name - if name is not equal random it will search for custom generator with this name

func (RawStyle) FloatTween

func (r RawStyle) FloatTween(key string, custom map[string]lerp.Tween, def lerp.Tween) (e lerp.Tween)

FloatTween returns float tween, returns def if process failed

syntax:

	number - returns lerp.Constant(number)
 linear start end - if you prefix field with 'linear' and provide two numbers lerp.Linear(number, number)

is returned

bezier start startHandle endHandle end - if you prefix field with 'bezier' and provide four numbers

lerp.Bezier(start, startHandle, endHandle, end) is returned

name - if name is not equal 'random' of 'bezier' it will search for custom tween with this name

type Rectangle

type Rectangle struct {
	Width, Height float64
}

Rectangle spans particles in a rectangle area

func (Rectangle) Gen

func (r Rectangle) Gen(dir float64) mat.Vec

Gen implements EmissionShape interface

type Request

type Request struct {
	Pos    mat.Vec
	Dir    float64
	Amount int
	Mask   mat.RGBA
	*Type
}

Request holds data for particle spawning

type Sprite

type Sprite struct {
	ggl.Sprite
}

Sprite extends ggl.Sprite to implement Drawer

func Square

func Square(size float64) *Sprite

Square creates a square particle drawer

func (*Sprite) Copy

func (s *Sprite) Copy() Drawer

Copy implements Drawer interface

func (*Sprite) Metrics

func (s *Sprite) Metrics() (indices, vertexes int)

Metrics implements Drawer interface

type System

type System struct {
	ggl.Data
	// contains filtered or unexported fields
}

System is a particle renderer and updater. Its designed to be updated from multiple threads, and also to spawn particles off thread. System has its own goroutine that is reused for spawning so Drop is necessary to prevent a memory leak

func (*System) Drop

func (s *System) Drop()

Drop drops the particle system (spawner disposing)

func (*System) RunSpawner

func (s *System) RunSpawner()

RunSpawner spawns all spawn requests on separate thread

func (*System) SetThreads

func (s *System) SetThreads(count int)

SetThreads sets the thread count the System is targetting

func (*System) Spawn

func (s *System) Spawn()

Spawn spawns all particles on current thread

func (*System) Thread

func (s *System) Thread(threadIndex int) *Thread

Thread returns handle to one of used threads, you have to call update, but you can call it form different thread

func (*System) Wait

func (s *System) Wait()

Wait waits for spawner to finish

type Thread

type Thread struct {
	*System
	// contains filtered or unexported fields
}

Thread collects requests and updates its fraction of particles

func (*Thread) Request

func (t *Thread) Request(r Request)

Request requests particle spawn, particles should be spawned within frame of this call

method panics if system is spawning

func (*Thread) Update

func (t *Thread) Update(delta float64)

Update updates particle state of one fraction of particles threads split particle processing equally

panics if system is spawning

type Type

type Type struct {
	EmissionShape

	Color lerpc.Tween
	Mask  lerpc.Generator

	ScaleMultiplier, Acceleration, TwerkAcceleration lerp.Tween

	Velocity, Livetime, Twerk, Rotation, Spread, ScaleX, ScaleY lerp.Generator

	Friction, OriginGravity float64

	Gravity mat.Vec

	RotationRelativeToVelocity bool
	// contains filtered or unexported fields
}

Type defines behavior of a particles

func (*Type) Parse

func (d *Type) Parse(r RawStyle, a *Assets)

Parse performs the Type parsing, DefType is used as template, if some field is missing or un-parsable Value from defaults is used

func (*Type) SetDrawer

func (d *Type) SetDrawer(drw Drawer)

SetDrawer sets the Data drawer

Jump to

Keyboard shortcuts

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