ecs

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: GPL-3.0 Imports: 4 Imported by: 2

README

ecs

Import path: github.com/InsideGallery/core/ecs

Overview

ecs provides lightweight Entity-Component-System primitives: entity IDs, entity versioning, and small update interfaces for components and systems.

Main APIs

  • Registry owns isolated entity ID generation state.
  • NewRegistry, (*Registry).NewBaseEntity, (*Registry).NewBaseEntityWithID, and (*Registry).LatestID create and inspect registry-scoped entities.
  • BaseEntity stores an ID and version with GetID, SetID, GetVersion, SetVersion, and UpVersion.
  • Entity, Versionable, Component, and System are small contracts for consumers.
  • InstallDefaultEntityFactory temporarily replaces the package-level compatibility registry.
  • EntityFactory, NewEntityFactory, DefaultEntityFactory, NewBaseEntity, and NewBaseEntityWithID remain for backward compatibility.

Usage

registry := ecs.NewRegistry()

entity := registry.NewBaseEntity()
entity.UpVersion()

id := entity.GetID()
version := entity.GetVersion()

_ = id
_ = version

Notes

Prefer NewRegistry for new code so ID state is scoped to the caller. The package-level helpers use the global default registry for compatibility. BaseEntity version operations use atomics; UpVersion follows uint64 overflow behavior.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = NewRegistry()

Default is the package-level compatibility ECS registry used by legacy helpers.

Functions

This section is empty.

Types

type BaseEntity

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

BaseEntity contains required fields

func NewBaseEntity deprecated

func NewBaseEntity() *BaseEntity

NewBaseEntity return new entity.

Deprecated: use NewEntityFactory and EntityFactory.NewBaseEntity for explicit ID ownership.

func NewBaseEntityWithID deprecated

func NewBaseEntityWithID(id uint64) *BaseEntity

NewBaseEntityWithID return new entity with id.

Deprecated: use NewEntityFactory and EntityFactory.NewBaseEntityWithID for explicit ID ownership.

func (*BaseEntity) GetID

func (e *BaseEntity) GetID() uint64

GetID return id

func (*BaseEntity) GetVersion

func (e *BaseEntity) GetVersion() uint64

GetVersion return current version of object

func (*BaseEntity) SetID

func (e *BaseEntity) SetID(id uint64)

SetID set id

func (*BaseEntity) SetVersion

func (e *BaseEntity) SetVersion(v uint64)

SetVersion set current version

func (*BaseEntity) UpVersion

func (e *BaseEntity) UpVersion()

UpVersion increase current version

type Component

type Component interface {
	Update(ctx context.Context) error
}

Component is an interface which implements an ECS-System

type DefaultEntityFactoryHandle added in v1.1.0

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

DefaultEntityFactoryHandle restores a previous package-level entity factory.

func InstallDefaultEntityFactory added in v1.1.0

func InstallDefaultEntityFactory(factory *EntityFactory) *DefaultEntityFactoryHandle

InstallDefaultEntityFactory installs a scoped package-level entity factory.

func (*DefaultEntityFactoryHandle) Close added in v1.1.0

func (h *DefaultEntityFactoryHandle) Close() error

Close restores the previous package-level entity factory.

type Entity

type Entity interface {
	GetID() uint64
}

Entity describe entity

type EntityFactory deprecated added in v1.1.0

type EntityFactory = Registry

EntityFactory aliases Registry for backward compatibility.

Deprecated: use Registry.

func DefaultEntityFactory added in v1.1.0

func DefaultEntityFactory() *EntityFactory

DefaultEntityFactory returns the package-level compatibility entity factory.

func NewEntityFactory deprecated added in v1.1.0

func NewEntityFactory() *EntityFactory

NewEntityFactory returns an isolated ECS entity factory.

Deprecated: use NewRegistry.

type Registry added in v1.1.0

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

Registry owns ECS entity ID generation state for application composition.

func NewRegistry added in v1.1.0

func NewRegistry() *Registry

NewRegistry returns an isolated ECS registry.

func (*Registry) LatestID added in v1.1.0

func (r *Registry) LatestID() uint64

LatestID returns the latest generated entity ID for this registry.

func (*Registry) NewBaseEntity added in v1.1.0

func (r *Registry) NewBaseEntity() *BaseEntity

NewBaseEntity returns a new entity owned by this registry.

func (*Registry) NewBaseEntityWithID added in v1.1.0

func (r *Registry) NewBaseEntityWithID(id uint64) *BaseEntity

NewBaseEntityWithID returns a new entity with an explicit ID owned by this registry.

type System

type System interface {
	Update(ctx context.Context) error
}

System is an interface which implements an ECS-System

type Versionable

type Versionable interface {
	GetVersion() uint64
	UpVersion()
}

Versionable describe version for entity

Jump to

Keyboard shortcuts

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