table

package module
v0.0.0-...-9d26b0d Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2025 License: MIT Imports: 10 Imported by: 2

README

Overview

The table package implements a high-performance Entity Component System (ECS) focused on efficient data organization and processing.

Note: for more in depth documentation please see: bappa-docs

Key Features

  • Schema-based component organization
  • Safe and unsafe memory access modes
  • Efficient entity recycling
  • Cache-friendly memory layout
  • Type-safe component access

Use Cases

  • Game Development (physics engines, behavior systems, particle effects, etc)
  • Simulations (ecosystem modeling, vehicle traffic, etc)
  • Real-time Systems (trading systems, sensor processing, etc)

Example Usage

// Define components
type Position struct { X, Y float64 }
type Velocity struct { X, Y float64 }

// Create table
schema := table.Factory.NewSchema()
entryIndex := table.Factory.NewEntryIndex()
posType := table.FactoryNewElementType[Position]()
velType := table.FactoryNewElementType[Velocity]()

tbl, _ := table.Factory.NewTable(schema, entryIndex, posType, velType)

// Add entities
tbl.NewEntries(1000)

// Access components
posAccessor := table.FactoryNewAccessor[Position](posType)
velAccessor := table.FactoryNewAccessor[Velocity](velType)

// Process entities
for i := 0; i < tbl.Length(); i++ {
    pos := posAccessor.Get(i, table)
    vel := velAccessor.Get(i, table)
    pos.X += vel.X * dt
    pos.Y += vel.Y * dt
}

Configuration

// Build tags for optimization
//go:build unsafe         // Enable unsafe pointer operations
//go:build schema_enabled // Enable flexible schemas
//go:build m256          // Configure mask size up to 1024

Performance Characteristics

  • O(1) component access
  • Cache-coherent iteration
  • Low memory fragmentation

When to Use

  • Need component-based architecture
  • Performance critical systems
  • Large numbers of similar entities
  • Frequent batch processing
  • Cache-sensitive operations

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config config = config{
	AutoElementTypeRegistrationTableCreation: true,
}
View Source
var Stats stats = stats{}

Functions

This section is empty.

Types

type AccessError

type AccessError struct {
	Index      int
	UpperBound int
}

func (AccessError) Error

func (e AccessError) Error() string

type Accessor

type Accessor[T any] struct {
	// contains filtered or unexported fields
}

Warning: internal Dependencies abound!

func FactoryNewAccessor

func FactoryNewAccessor[T any](elementType ElementType) Accessor[T]

Warning: Internal dependency abound!

func (Accessor[T]) Check

func (accessor Accessor[T]) Check(table Table) bool

func (Accessor[T]) Get

func (accessor Accessor[T]) Get(idx int, table Table) *T

type BatchDeletionError

type BatchDeletionError struct {
	BatchOperationError
	Capacity int
}

func (BatchDeletionError) Error

func (e BatchDeletionError) Error() string

type BatchOperationError

type BatchOperationError struct {
	Count int
}

func (BatchOperationError) Error

func (e BatchOperationError) Error() string

type DefaultTableEvents

type DefaultTableEvents struct{}

func (*DefaultTableEvents) OnAfterEntriesCreated

func (e *DefaultTableEvents) OnAfterEntriesCreated(entries []Entry)

func (*DefaultTableEvents) OnAfterEntriesDeleted

func (e *DefaultTableEvents) OnAfterEntriesDeleted(ids []EntryID)

func (*DefaultTableEvents) OnBeforeEntriesCreated

func (e *DefaultTableEvents) OnBeforeEntriesCreated(count int) error

func (*DefaultTableEvents) OnBeforeEntriesDeleted

func (e *DefaultTableEvents) OnBeforeEntriesDeleted(indices []int) error

type ElementType

type ElementType interface {
	ID() ElementTypeID
	Type() reflect.Type
	Size() uint32
}

func FactoryNewElementType

func FactoryNewElementType[T any]() ElementType

type ElementTypeID

type ElementTypeID uint32

type Entry

type Entry interface {
	ID() EntryID
	Recycled() int
	Index() int
	Table() Table
}

type EntryID

type EntryID uint32

type EntryIndex

type EntryIndex interface {
	Entry(idx int) (Entry, error)
	NewEntries(count, previousTableLength int, tbl Table) ([]Entry, error)
	UpdateIndex(EntryID, int) error
	RecycleEntries(...EntryID) error
	Reset() error
	Entries() []Entry
	Recyclable() []Entry
}

type InvalidElementAccessError

type InvalidElementAccessError struct {
	ElementType       ElementType
	ValidElementTypes []ElementType
}

func (InvalidElementAccessError) Error

type InvalidEntryAccessError

type InvalidEntryAccessError struct{}

func (InvalidEntryAccessError) Error

func (e InvalidEntryAccessError) Error() string

type LockedAccessor

type LockedAccessor[T any] struct {
	// contains filtered or unexported fields
}

func (LockedAccessor[T]) Check

func (lAccessor LockedAccessor[T]) Check(table Table) bool

func (LockedAccessor[T]) Get

func (lAccessor LockedAccessor[T]) Get(idx int, table Table) *T

type MaskComparer

type MaskComparer interface {
	ContainsAll(mask.Mask) bool
	ContainsAny(mask.Mask) bool
	ContainsNone(mask.Mask) bool
}

type Row

type Row reflect.Value

func (Row) CanAddr

func (r Row) CanAddr() bool

func (Row) Interface

func (r Row) Interface() any

func (Row) Type

func (r Row) Type() reflect.Type

func (Row) UnsafePointer

func (r Row) UnsafePointer() unsafe.Pointer

type RowIndex

type RowIndex uint32

type Schema

type Schema interface {
	Register(...ElementType)
	Registered() int
	Contains(ElementType) bool
	ContainsAll(...ElementType) bool
	RowIndexFor(ElementType) uint32
	RowIndexForID(ElementTypeID) uint32
}

type Table

type TableBuilder

type TableBuilder interface {
	WithSchema(Schema) TableBuilder
	WithEntryIndex(EntryIndex) TableBuilder
	WithElementTypes(...ElementType) TableBuilder
	WithEvents(TableEvents) TableBuilder
	Build() (Table, error)
}

func NewTableBuilder

func NewTableBuilder() TableBuilder

type TableEvents

type TableEvents interface {
	OnBeforeEntriesCreated(count int) error
	OnAfterEntriesCreated(entries []Entry)
	OnBeforeEntriesDeleted(indices []int) error
	OnAfterEntriesDeleted(ids []EntryID)
}

type TableFactory

type TableFactory interface {
	NewEntryIndex() EntryIndex
	// contains filtered or unexported methods
}
var (
	Factory TableFactory = initTableFactory()
)

type TableInstantiationNilElementTypesError

type TableInstantiationNilElementTypesError struct{}

func (TableInstantiationNilElementTypesError) Error

type TableInstantiationNilSchemaError

type TableInstantiationNilSchemaError struct{}

func (TableInstantiationNilSchemaError) Error

type TableIterator

type TableIterator interface {
	Rows() iter.Seq2[int, Row]
	ElementTypes() iter.Seq[ElementType]
}

type TableQuerier

type TableQuerier interface {
	Contains(ElementType) bool
	ContainsAll(...ElementType) bool
	ContainsAny(...ElementType) bool
	ContainsNone(...ElementType) bool
}

type TableReader

type TableReader interface {
	Entry(int) (Entry, error)
	Get(ElementType, int) (reflect.Value, error)
	Row(ElementType) (Row, error)
	Length() int
	RowCount() int
}

type TableSetter

type TableSetter []struct {
	ElementType
	Values []any
}

func (TableSetter) Unpack

func (ts TableSetter) Unpack(s Schema, ei EntryIndex, t *testing.T) (Table, error)

type TableWriter

type TableWriter interface {
	Set(ElementType, reflect.Value, int) error
	NewEntries(int) ([]Entry, error)
	DeleteEntries(...int) ([]EntryID, error)
	TransferEntries(Table, ...int) error
	Clear() error
}

type TransferEntryIndexMismatchError

type TransferEntryIndexMismatchError struct{}

func (TransferEntryIndexMismatchError) Error

Jump to

Keyboard shortcuts

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