engine

package
v0.0.0-...-a545287 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const NoParent = -1

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionFn

type ActionFn func(e *Engine) error

type AnimationComponent

type AnimationComponent interface {
	Update(dt time.Duration)
}

type AnimationEngine

type AnimationEngine struct{}

func NewAnimationEngine

func NewAnimationEngine() *AnimationEngine

func (AnimationEngine) CalculateIntermediatePoses

func (e AnimationEngine) CalculateIntermediatePoses(bucket *EntityBucket, dt time.Duration)

play animation (ie: depending on time only)

func (AnimationEngine) FinalizePoseAndMatrixPalette

func (e AnimationEngine) FinalizePoseAndMatrixPalette(bucket *EntityBucket)

correct animation parameters with previous effects

type CollisionComponent

type CollisionComponent interface {
	UpdateCollision(dt time.Duration)
}

type CollisionEngine

type CollisionEngine struct{}

func NewCollisionEngine

func NewCollisionEngine() *CollisionEngine

func (CollisionEngine) DetectAndResolveCollisions

func (e CollisionEngine) DetectAndResolveCollisions(bucket *EntityBucket, dt time.Duration)

fix moves and produces fixed NextPositions

type ControllerComponent

type ControllerComponent interface {
	ConsumeGamepadEvents(events *[]controller.GamepadEvent, projection controller.GamepadProjection)
	ConsumeKeyboardEvents(events *[]controller.KeyboardEvent, projection controller.KeyboardProjection)
	ProcessActions(*Engine) error
}

type ControllerComponentBase

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

func NewControllerComponentBase

func NewControllerComponentBase(values *EntityValues) *ControllerComponentBase

func (*ControllerComponentBase) AddAction

func (b *ControllerComponentBase) AddAction(action ActionFn)

func (*ControllerComponentBase) ClearActions

func (b *ControllerComponentBase) ClearActions()

func (*ControllerComponentBase) GetValue

func (b *ControllerComponentBase) GetValue(ref ValueRef) interface{}

func (*ControllerComponentBase) ProcessActions

func (b *ControllerComponentBase) ProcessActions(e *Engine) error

func (*ControllerComponentBase) SetValue

func (b *ControllerComponentBase) SetValue(ref ValueRef, value interface{})

type ControllerEngine

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

func NewControllerEngine

func NewControllerEngine(keyboardChannel *controller.KeyboardEventChannel) *ControllerEngine

func (*ControllerEngine) ConsumeGamepadEvents

func (e *ControllerEngine) ConsumeGamepadEvents(_ time.Duration)

func (*ControllerEngine) ConsumeKeyboardEvents

func (e *ControllerEngine) ConsumeKeyboardEvents(_ time.Duration)

func (*ControllerEngine) ProcessActions

func (e *ControllerEngine) ProcessActions(engine *Engine, duration time.Duration)

func (*ControllerEngine) SetActiveController

func (e *ControllerEngine) SetActiveController(controller ControllerComponent)

func (*ControllerEngine) Start

func (e *ControllerEngine) Start()

func (*ControllerEngine) Stop

func (e *ControllerEngine) Stop()

type Engine

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

func NewGameEngine

func NewGameEngine(canvas canvas.Canvas, keyboardEventChannel *controller.KeyboardEventChannel) *Engine

func (*Engine) Exit

func (e *Engine) Exit()

func (*Engine) GetEntity

func (e *Engine) GetEntity(ref EntityRef) Entity

func (*Engine) LoadGame

func (e *Engine) LoadGame(game Game)

func (*Engine) Run

func (e *Engine) Run(matrixDone chan struct{})

func (*Engine) SetActiveController

func (e *Engine) SetActiveController(controllerComponent ControllerComponent)

func (*Engine) UpdateBucket

func (e *Engine) UpdateBucket(bucket *EntityBucket, dt time.Duration) bool

type Entity

type Entity interface {
	Parent() EntityRef
	// Update consumes controller gamepadEvents & set directions/velocity
	Update(engine *Engine, dt time.Duration) bool
	// FinalUpdate apply computed positions to entities, if any
	FinalUpdate(dt time.Duration) bool
	Enable()
	Disable()
	GetController() ControllerComponent
}

type EntityBase

type EntityBase struct {
	Values    EntityValues
	ParentRef EntityRef
}

func NewEntityBase

func NewEntityBase() *EntityBase

func (EntityBase) GetValue

func (b EntityBase) GetValue(ref ValueRef) interface{}

func (EntityBase) Parent

func (b EntityBase) Parent() EntityRef

func (EntityBase) SetValue

func (b EntityBase) SetValue(ref ValueRef, value interface{})

type EntityBucket

type EntityBucket struct {
	Entities             map[EntityRef]Entity
	ControllerComponents []ControllerComponent
	AnimationComponents  []AnimationComponent
	PhysicsComponents    []PhysicsComponent
	CollisionComponents  []CollisionComponent
	GraphicComponents    []GraphicComponent
}

type EntityRef

type EntityRef int

type EntityValues

type EntityValues map[ValueRef]interface{}

func (EntityValues) Get

func (v EntityValues) Get(ref ValueRef) interface{}

func (EntityValues) Set

func (v EntityValues) Set(ref ValueRef, value interface{})

type Game

type Game interface {
	Name() string
	// InitializeBuckets allow loading game components into engine
	InitializeBuckets() []EntityBucket
	// InitializeGame lets you load 1st scene (enable entity)
	InitializeGame(engine *Engine)
}

Game describes a complete game content (graphics, controller, etc...)

type GraphicComponent

type GraphicComponent interface {
	Enable()
	Disable()
	Show()
	Hide()
	Draw(canvas canvas.Canvas) error
	IsEnabled() bool
	IsVisible() bool
}

type GraphicComponentBase

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

func NewGraphicComponentBase

func NewGraphicComponentBase(values *EntityValues, graphic *components.Graphic, enabled, visible bool) *GraphicComponentBase

func (*GraphicComponentBase) Disable

func (b *GraphicComponentBase) Disable()

func (*GraphicComponentBase) DisableDrawable

func (b *GraphicComponentBase) DisableDrawable(drawable components.Drawable)

func (*GraphicComponentBase) Draw

func (b *GraphicComponentBase) Draw(canvas canvas.Canvas) error

func (*GraphicComponentBase) Enable

func (b *GraphicComponentBase) Enable()

func (*GraphicComponentBase) EnableDrawable

func (b *GraphicComponentBase) EnableDrawable(drawable components.Drawable)

func (*GraphicComponentBase) GetValue

func (b *GraphicComponentBase) GetValue(ref ValueRef) interface{}

func (*GraphicComponentBase) Hide

func (b *GraphicComponentBase) Hide()

func (*GraphicComponentBase) IsEnabled

func (b *GraphicComponentBase) IsEnabled() bool

func (*GraphicComponentBase) IsVisible

func (b *GraphicComponentBase) IsVisible() bool

func (*GraphicComponentBase) RegisterDrawable

func (b *GraphicComponentBase) RegisterDrawable(drawable components.Drawable)

func (*GraphicComponentBase) SetValue

func (b *GraphicComponentBase) SetValue(ref ValueRef, value interface{})

func (*GraphicComponentBase) Show

func (b *GraphicComponentBase) Show()

type GraphicEngine

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

func NewGraphicEngine

func NewGraphicEngine(canvas canvas.Canvas) *GraphicEngine

func (GraphicEngine) RenderSceneAndSwapBuffers

func (e GraphicEngine) RenderSceneAndSwapBuffers(buckets *[]EntityBucket)

type PhysicsComponent

type PhysicsComponent interface {
	UpdatePhysics(dt time.Duration)
}

type PhysicsEngine

type PhysicsEngine struct{}

func NewPhysicsEngine

func NewPhysicsEngine() *PhysicsEngine

func (PhysicsEngine) Simulate

func (e PhysicsEngine) Simulate(bucket *EntityBucket, dt time.Duration)

Simulate apply physics (compute next positions & velocities)

type ValueRef

type ValueRef int

Jump to

Keyboard shortcuts

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