goecs

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 5 Imported by: 12

README

go-ecs

An Entity Component System, ConcurrentEnabled

Documentation

Overview

Package that describe an Entity-Component-System World

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	Id   Identifier  `json:"id"`
	Data interface{} `json:"data"`
}

func CreateComponent

func CreateComponent(id Identifier, data interface{}) *Component

func (*Component) GetData

func (p *Component) GetData() interface{}

func (*Component) GetId

func (p *Component) GetId() Identifier

func (*Component) GetStructure

func (p *Component) GetStructure() *Component

func (*Component) SetData

func (p *Component) SetData(v interface{})

type Composition

type Composition struct {
	Id    Identifier
	Value []string
}

func (Composition) Equals

func (source Composition) Equals(target Composition) bool

func (Composition) Len

func (source Composition) Len() int

type Entity

type Entity struct {
	Id          uuid.UUID `json:"id"`
	OwnerID     uuid.UUID `json:"ownerId"` // ClientID
	TypeID      Identifier
	PossessedID uuid.UUID `json:"possessedId"`
	World       *IWorld
	Components  []*Component `json:"components"`
}

func EntityNoCycleArrayToEntityArray

func EntityNoCycleArrayToEntityArray(world IWorld, entitiesNoCycle []EntityNoCycle) (entities []Entity)

func (*Entity) AddComponent

func (entity *Entity) AddComponent(cmp Component) error

func (*Entity) GetComponent

func (entity *Entity) GetComponent(id Identifier) (cmp *Component)

func (*Entity) GetComponents

func (entity *Entity) GetComponents() (components []*Component)

func (*Entity) GetComposition

func (entity *Entity) GetComposition() (composition []string)

func (*Entity) GetId

func (entity *Entity) GetId() uuid.UUID

func (*Entity) GetOwnerID

func (entity *Entity) GetOwnerID() uuid.UUID

func (*Entity) GetPossessedID

func (entity *Entity) GetPossessedID() uuid.UUID

func (*Entity) GetStructure

func (entity *Entity) GetStructure() *Entity

func (*Entity) GetTypeID

func (entity *Entity) GetTypeID() Identifier

func (*Entity) GetWorld

func (entity *Entity) GetWorld() *IWorld

func (*Entity) HaveComponent

func (entity *Entity) HaveComponent(cn Identifier) bool

func (*Entity) HaveComponentByIdString

func (entity *Entity) HaveComponentByIdString(cn string) bool

func (*Entity) HaveComposition

func (entity *Entity) HaveComposition(composition []string) bool

func (*Entity) UpdateComponents

func (entity *Entity) UpdateComponents(components []*Component)

Si un composant spécifié dans l'argument n'existe pas alors on en crée un sur l'entité cible

type EntityNoCycle

type EntityNoCycle struct {
	Id          uuid.UUID    `json:"id"`
	OwnerID     uuid.UUID    `json:"ownerId"`
	PossessedID uuid.UUID    `json:"possessedId"`
	Components  []*Component `json:"components"`
}

Remove Cyclique Structure from type Entity caused by *World qui contient lui même l'entité

func EntityToNoCycle

func EntityToNoCycle(entity *IEntity) EntityNoCycle

type FeedBack

type FeedBack struct {
	Host    string // Le nom du bloc ou plus précisément le nom de la fonction qui host les jobs
	Job     string // Le nom de la fonction qui a provoqué le feedback
	Label   string
	Type    FeedBackType
	Comment string
	Data    interface{}
}

func (*FeedBack) String

func (fb *FeedBack) String() string

type FeedBackType

type FeedBackType string
var (
	FB_ERROR   FeedBackType = "FB_ERROR"
	FB_SUCCESS FeedBackType = "FB_SUCCESS"
)

type IComponent

type IComponent interface {
	GetId() Identifier
	GetData() interface{}
	SetData(v interface{})
	GetStruct() *Component
}

type IEntity

type IEntity interface {
	GetTypeID() Identifier
	GetWorld() *IWorld
	GetId() uuid.UUID
	GetOwnerID() uuid.UUID
	GetPossessedID() uuid.UUID
	AddComponent(cmp Component) error
	HaveComponent(cn Identifier) bool
	HaveComponentByIdString(cn string) bool
	GetComponent(id Identifier) *Component
	GetComponents() []*Component
	GetComposition() []string
	UpdateComponents([]*Component)
	HaveComposition([]string) bool
	GetStructure() *Entity
}

func CEntity

func CEntity(world *IWorld, id uuid.UUID, components []*Component) *IEntity

func CEntityPossessed

func CEntityPossessed(world *IWorld, id uuid.UUID, possessedByID uuid.UUID, components []*Component) *IEntity

func CEntityWithOwner

func CEntityWithOwner(world *IWorld, id uuid.UUID, ownerId uuid.UUID, components []*Component) *IEntity

func EntityNoCycleToEntity

func EntityNoCycleToEntity(world *IWorld, entityNoCycle EntityNoCycle) *IEntity

type ISystem

type ISystem interface {
	GetName() string
	GetId() Identifier
	// Retourne si le système est un système HYBRID, CLIENT, SERVER
	GetSide() SIDE
	UpdateClient()
	UpdateServer()
	Init(*IWorld)
	Listen(string, func(...interface{}) error) error
	Call(string, ...interface{}) error
}

type IWorld

type IWorld interface {
	GetId() Identifier

	// Ajoute une entité
	AddEntity(*IEntity) *FeedBack
	// Ajoute une liste d'entité
	AddEntities([]Entity) *FeedBack

	// Retourne une entité par son instance ID
	GetEntity(uuid.UUID) *IEntity
	// Get all entities instantiated in the world
	GetEntities() []*IEntity

	// Return des une copie de toute les entité sans cycle (sans référence au monde qui référence encore toute les entité, c'est infini pour type *IEntity)
	GetEntitiesNoCycle() []EntityNoCycle
	// Add entities in the world from an array of Entity without cycle reference
	AddEntitiesFromEntitiesNoCycle(entitiesNoCycle []EntityNoCycle)
	// UUID should be an external ID maybe a ClientID
	GetEntitiesPossessedBy(uuid.UUID) []*IEntity
	GetEntitiesByComponentId(Identifier) []*IEntity
	// EN: Get entities which have at least the specified components name.
	//     Returns a slice of IEntity pointers.
	// FR: Obtiens les entités qui ont au moins les composants spécifiés.
	//     Retourne une tranche de pointeurs IEntity.
	GetEntitiesWithComponents(...Identifier) []*IEntity
	GetEntitiesWithComponentsIdString(...string) []*IEntity
	// Get entities wich have the components specified by the array of component name.
	GetEntitiesWithStrictComposition(Composition) []*IEntity
	// EN: Get entities which at least the specified composition
	// 		Returns a slice of IEntity pointers
	// FR: Obtiens les entités qui ont au moins la composition spécifié
	//     Retourne une tranche de pointeurs IEntity.
	GetEntitiesWithComposition(Composition) []*IEntity
	// Update a list of component of the entity
	UpdateEntityComponents(uuid.UUID, []*Component) *FeedBack
	// Remove an entity by his instanceId
	RemoveEntity(uuid.UUID) *FeedBack

	// Ajoute un système, veuillez ajouter une structure Système qui implémente l'interface ISystem
	AddSystem(*ISystem)
	//
	GetSystemById(Identifier) *ISystem
	RemoveSystem(Identifier) *FeedBack

	// Execute toutes les methods UpdateClient des systèmes lié à ce monde
	UpdateClient()
	// Execute toutes les methods UpdateServer des systèmes lié à ce monde
	UpdateServer()
}

type Identifier

type Identifier struct {
	Namespace string `json:"namespace"`
	Path      string `json:"path"`
}

Identifier enable the possibility to have two object with the same path but with a different namespace

Example, a mod could add "mymod:position" and "anothermod:position"
You can call World.GetEntityByComponentId("mymod:position")

func (Identifier) Equals

func (id Identifier) Equals(other Identifier) bool

func (Identifier) String

func (id Identifier) String() string

type SIDE

type SIDE string
const (
	SERVER SIDE = "SERVER"
	CLIENT SIDE = "CLIENT"
	HYBRID SIDE = "HYBRID"
)

type System

type System struct {
	Id    Identifier
	Name  string
	Type  SIDE
	World *IWorld
	// contains filtered or unexported fields
}

func (*System) Call

func (ss *System) Call(id string, args ...interface{}) error

func (*System) GetId

func (ss *System) GetId() Identifier

func (*System) GetName

func (ss *System) GetName() string

func (*System) GetType

func (ss *System) GetType() SIDE

func (*System) Init

func (ss *System) Init(world *IWorld)

func (*System) Listen

func (ss *System) Listen(id string, handler func(...interface{}) error) error

type World

type World struct {
	Id       Identifier
	Entities []*IEntity
	Systems  []*ISystem
	// contains filtered or unexported fields
}

func (*World) AddEntities

func (world *World) AddEntities(entities []Entity) (fb *FeedBack)

func (*World) AddEntitiesFromEntitiesNoCycle

func (world *World) AddEntitiesFromEntitiesNoCycle(entitiesNoCycle []EntityNoCycle)

func (*World) AddEntity

func (world *World) AddEntity(entity *IEntity) (err *FeedBack)

func (*World) AddSystem

func (world *World) AddSystem(sys *ISystem)

func (*World) GetEntities

func (world *World) GetEntities() (entities []*IEntity)

func (*World) GetEntitiesByComponentId

func (world *World) GetEntitiesByComponentId(id Identifier) (entities []*IEntity)

func (*World) GetEntitiesNoCycle

func (world *World) GetEntitiesNoCycle() (entities []EntityNoCycle)

func (*World) GetEntitiesPossessedBy

func (world *World) GetEntitiesPossessedBy(possessedId uuid.UUID) (entities []*IEntity)

func (*World) GetEntitiesWithComponents

func (world *World) GetEntitiesWithComponents(v ...Identifier) (entities []*IEntity)

func (*World) GetEntitiesWithComponentsIdString

func (world *World) GetEntitiesWithComponentsIdString(v ...string) (entities []*IEntity)

func (*World) GetEntitiesWithComposition

func (world *World) GetEntitiesWithComposition(composition Composition) (entities []*IEntity)

func (*World) GetEntitiesWithStrictComposition

func (world *World) GetEntitiesWithStrictComposition(composition Composition) (entities []*IEntity)

func (*World) GetEntity

func (world *World) GetEntity(id uuid.UUID) (ent *IEntity)

func (*World) GetId

func (world *World) GetId() Identifier

func (*World) GetSystemById

func (world *World) GetSystemById(id Identifier) *ISystem

func (*World) GetSystems

func (world *World) GetSystems() []*ISystem

func (*World) RemoveEntity

func (world *World) RemoveEntity(id uuid.UUID) (err *FeedBack)

func (*World) RemoveSystem

func (world *World) RemoveSystem(id Identifier) (err *FeedBack)

func (*World) UpdateClient

func (world *World) UpdateClient()

func (*World) UpdateEntityComponents

func (world *World) UpdateEntityComponents(id uuid.UUID, components []*Component) *FeedBack

func (*World) UpdateServer

func (world *World) UpdateServer()

Jump to

Keyboard shortcuts

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