gecs

package module
v0.0.0-...-29d751b Latest Latest
Warning

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

Go to latest
Published: May 16, 2022 License: MIT Imports: 4 Imported by: 2

README

Go Report Card CodeCov GoDoc

Work in progress

Backward compatibility between versions is not guaranteed!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface{}

Component ecs interface. Used for better readability.

type Entity

type Entity interface {
	ID() uint64

	// Destroy removes all components and removes the entity from the world.
	// In case someone holds a reference to the entity and adds a new component, the entity will be restored.
	Destroy()

	// Get gets an existing component with the type of the passed component.
	// If the component doesn't exist and is not nil passed, the component will be added to entity.
	Get(c Component) Component

	// Has returns true if there is a component with the passed type on entity.
	Has(c Component) bool

	// Replace adds a component to the entity if it doesn't exist, or replaces it if it exists.
	// If the type is nil, it does nothing.
	Replace(c Component)

	// Delete removes the component with the passed type.
	Delete(c Component)

	// Components returns all entity component.
	Components() []Component
}

Entity ecs interface.

type System

type System interface {
	// GetFilters returns filters with a list of components.
	GetFilters() []SystemFilter

	// Update is called on every tick.
	// delta - time elapsed from the previous tick.
	// filtered - filtered entity list by filters from the GetFilters method.
	// Always contains the same number of elements as the GetFilters method returns, in the same filter order.
	// filtered - [FilterIndex][EntityIndex]Entity
	Update(delta time.Duration, filtered [][]Entity)
}

System ecs interface.

func NewOneFrame

func NewOneFrame(c Component) System

NewOneFrame returns a system that, when called, removes the component from all entities. Takes in a component whose type is to be removed.

The use of this system involves adding it at the very end of the list of systems, so that the deletion occurs at the end of the cycle.

type SystemDestroyer

type SystemDestroyer interface {
	System

	Destroy()
}

SystemDestroyer ecs interface.

type SystemFilter

type SystemFilter struct {
	Include []Component
	Exclude []Component
}

SystemFilter contains components for filtering entity when calling System.Update method on the system.

Include - the components that should be on the entity.
Exclude - the components of which should not be on the entity.

type SystemFull

type SystemFull interface {
	SystemIniter
	SystemDestroyer
}

SystemFull ecs interface.

type SystemIniter

type SystemIniter interface {
	System

	Init() error
}

SystemIniter ecs interface.

type World

type World interface {
	NewEntity() Entity

	AddSystem(s System)
	RemoveSystem(s System)

	SystemsInit() error
	// SystemsUpdate calls an update on all systems. Takes in the time elapsed from the previous call.
	SystemsUpdate(delta time.Duration)
	SystemsDestroy()

	// Run calls the Update method with a TPS (Tick per second) rate. Blocking method!
	Run(tps uint) error
	Stop()
}

World ecs interface.

func NewWorld

func NewWorld() World

NewWorld creates new ecs world instance.

Directories

Path Synopsis
examples
console Module
sdl2 Module

Jump to

Keyboard shortcuts

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