core

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package core contains lower level component systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOrigin added in v0.7.2

func ApplyOrigin(length, origin float64) float64

func Clamp

func Clamp(x, min, max float64) float64

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 Intmax added in v0.7.2

func Intmax(a, b int) int

func Lerpc added in v0.6.0

func Lerpc(a, b color.RGBA, t float64) color.RGBA

func Lerpf added in v0.6.0

func Lerpf(a, b, t float64) float64

func Nonzeroval added in v0.7.2

func Nonzeroval(vals ...float64) float64

Nonzeroval will return the first non zero value. It will return 0 if all input values are 0

func Scaleb added in v0.6.0

func Scaleb(b uint8, scale float64) uint8

func Scalef added in v0.6.0

func Scalef(f, scale float64) float64

Types

type Context

type Context interface {
	Frame() int64
	DT() float64
	TPS() float64
	Engine() Engine
}

type DrawCtx added in v0.5.0

type DrawCtx interface {
	Context
	Renderer() DrawManager
}

DrawCtx is the context passed to every system update function.

func NewDrawCtx added in v0.5.0

func NewDrawCtx(e Engine, frame int64, dt, tps float64, m DrawManager) DrawCtx

type DrawManager added in v0.4.0

type DrawManager interface {
	DrawImage(image *ebiten.Image, opt *ebiten.DrawImageOptions, drawmask DrawMask)
	Screen() *ebiten.Image
	DrawTarget(id DrawTargetID) DrawTarget
}

type DrawMask added in v0.7.2

type DrawMask uint64

DrawMask is a flag to choose the draw target(s) of a drawable component

const (
	// DrawMaskNone sets all bits to 0
	DrawMaskNone DrawMask = 0
	// DrawMaskAll sets all bits to 1
	DrawMaskAll DrawMask = 0xffffffffffffffff
)
var (
	// DrawMaskDefault can be changed to make all new drawable components
	// start with a different value.
	//
	// The initial value of DrawMaskDefault is DrawMaskAll
	DrawMaskDefault DrawMask = DrawMaskAll
)

type DrawTarget added in v0.7.2

type DrawTarget interface {
	ID() DrawTargetID
	DrawMask() DrawMask
	Image() *ebiten.Image
	//DrawToScreen(screen *ebiten.Image)
	DrawImage(image *ebiten.Image, opt *ebiten.DrawImageOptions, mask DrawMask)
	Size() geom.Vec
	Translate(v geom.Vec)
	Scale(v geom.Vec)
	Rotate(rad float64)
	ResetTransform()
}

type DrawTargetID added in v0.7.2

type DrawTargetID uint64

func (DrawTargetID) String added in v0.7.2

func (d DrawTargetID) String() string

type Engine

type Engine interface {
	AddModule(module Module, priority int)
	NewWorld(priority int) World
	NewWorldWithDefaults(priority int) World
	RemoveWorld(w World)
	Run() error
	Ready() <-chan struct{}
	UpdateFrame() int64
	DrawFrame() int64
	Width() int
	Height() int
	SizeVec() geom.Vec
	AddEventListener(eventName string, fn EventFn) EventID
	RemoveEventListener(id EventID) bool
	DispatchEvent(eventName string, data interface{})
	SetDebugTPS(v bool)
	SetDebugFPS(v bool)
	SetScreenScale(scale float64)
}

type EntitySet

type EntitySet interface {
	Add(elements ...ecs.Entity)
	Remove(elements ...ecs.Entity)
	Contains(elements ...ecs.Entity) bool
	Values() []ecs.Entity
	SetBase
}

func NewEntitySet

func NewEntitySet(values ...ecs.Entity) EntitySet

NewEntitySet instantiates a new empty set and adds the entities (if present)

type EntitySortedList

type EntitySortedList struct {
	// contains filtered or unexported fields
}

func NewEntitySortedList

func NewEntitySortedList(mincap int) *EntitySortedList

func (*EntitySortedList) AddOrUpdate

func (sl *EntitySortedList) AddOrUpdate(key ecs.Entity, value SLVal) bool

func (*EntitySortedList) Delete

func (sl *EntitySortedList) Delete(key ecs.Entity) bool

func (*EntitySortedList) Each

func (sl *EntitySortedList) Each(fn func(key ecs.Entity, value SLVal) bool)

Each iterates on all entries, sorted.

Do not delete or add entries while looping (it is read locked while looping).

func (*EntitySortedList) FirstValue

func (sl *EntitySortedList) FirstValue() SLVal

func (*EntitySortedList) Get

func (sl *EntitySortedList) Get(key ecs.Entity) (SLVal, bool)

func (*EntitySortedList) LastValue

func (sl *EntitySortedList) LastValue() SLVal

func (*EntitySortedList) Reset

func (sl *EntitySortedList) Reset()

Reset clears the list.

type Event

type Event struct {
	Engine Engine
	Data   interface{}
}

type EventFn

type EventFn func(eventName string, e Event)

type EventID

type EventID int64

type EventManager

type EventManager struct {
	// contains filtered or unexported fields
}

func (*EventManager) Deregister

func (m *EventManager) Deregister(id EventID) bool

func (*EventManager) Dispatch

func (m *EventManager) Dispatch(eventName string, engine Engine, data interface{})

func (*EventManager) Register

func (m *EventManager) Register(eventName string, fn EventFn) EventID

type GameWorld added in v0.5.0

type GameWorld struct {
	*ecs.World
	// contains filtered or unexported fields
}

func NewWorld

func NewWorld(e Engine) *GameWorld

func (*GameWorld) Enabled added in v0.6.1

func (w *GameWorld) Enabled() bool

Enabled gets if this world is enabled or not

func (*GameWorld) Engine added in v0.5.0

func (w *GameWorld) Engine() Engine

func (*GameWorld) SetEnabled added in v0.6.1

func (w *GameWorld) SetEnabled(enabled bool)

SetEnabled is very useful to prevent weird behavior if you're using a goroutine to create entities (and components) inside a scene loader.

type Module added in v0.7.2

type Module interface {
	BeforeUpdate(ctx UpdateCtx)
	AfterUpdate(ctx UpdateCtx)
	BeforeDraw(ctx DrawCtx)
	AfterDraw(ctx DrawCtx)
}

Module defines a Primen Engine module

type Observer

type Observer interface {
	EventName() string
	OnEvent(e Event)
}

type SLVal

type SLVal interface {
	Less(v interface{}) bool
	Destroy()
}

type SetBase

type SetBase interface {
	Empty() bool
	Size() int
	Clear()
}

type System added in v0.5.0

type System interface {
	DrawPriority(ctx DrawCtx)
	Draw(ctx DrawCtx)
	UpdatePriority(ctx UpdateCtx)
	Update(ctx UpdateCtx)
}

type UpdateCtx added in v0.5.0

type UpdateCtx interface {
	Context
}

UpdateCtx is the context passed to every system update function.

func NewUpdateCtx added in v0.5.0

func NewUpdateCtx(e Engine, frame int64, dt, tps float64) UpdateCtx

type World added in v0.5.0

type World interface {
	ecs.BaseWorld
	Engine() Engine
	SetEnabled(enabled bool)
	Enabled() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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