Documentation ¶
Index ¶
- func AddToWorld(w *GameWorld, obj any) int
- func AddToWorldSpecific(w *GameWorld, entity int, obj any) int
- func AreBigTileOriginPositionsAdjacent(pos1 Pos, pos2 Pos, tileWidth int) bool
- func ArePositionsAdjacent(pos1 Pos, pos2 Pos) bool
- func ArrayIntersectionWithContext(ctx *QueryContext, nums1, nums2 []int) []int
- func CalculateWorldStateRootHash(w *GameWorld) string
- func ContainsPositions(posList []Pos, pos Pos) bool
- func ConvertStructToString(inputStruct interface{}) string
- func CreateTypeRegistrationMapping() map[string]reflect.Type
- func EncodeTableUpdateArrayToBytes(tableUpdates []TableUpdate) ([]byte, error)
- func Filter[T any](w *GameWorld, filter T, fieldNames []string) []int
- func HashStringsTogether(str1, str2 string) string
- func IncludesString(arr []string, value string) bool
- func SamePos(pos1 Pos, pos2 Pos) bool
- func Set[T any](w *GameWorld, entity int, obj T) int
- func SortInts(input []int) []int
- func SortStrings(input []string) []string
- func WithinDistance(pos1 Pos, pos2 Pos, distance int) bool
- type EntityManager
- type GameWorld
- func (w *GameWorld) Add(obj interface{}, tableName string) int
- func (w *GameWorld) AddEntity() int
- func (w *GameWorld) AddSpecific(entity int, obj interface{}, tableName string) int
- func (w *GameWorld) AddSpecificEntity(entity int)
- func (w *GameWorld) AddTable(table ITable)
- func (w *GameWorld) AddTableUpdate(tableUpdate TableUpdate)
- func (w *GameWorld) AddTables(tables ...ITable)
- func (w *GameWorld) ClearTableUpdates()
- func (w *GameWorld) Delete(entity int, tableName string) int
- func (w *GameWorld) Entities(tableName string) []int
- func (w *GameWorld) Filter(filter interface{}, fieldNames []string, tableName string) []int
- func (w *GameWorld) Get(entity int, tableName string) (any, bool)
- func (w *GameWorld) GetAndClearTableUpdates() []TableUpdate
- func (w *GameWorld) GetTableUpdates() TableUpdateArray
- func (w *GameWorld) Set(entity int, obj interface{}, tableName string) interface{}
- type ITable
- type IWorld
- type Pos
- type QueryContext
- type SparseSet
- type Table
- type TableBaseAccessor
- func (c *TableBaseAccessor[T]) Add(w IWorld, obj T) int
- func (c *TableBaseAccessor[T]) AddSpecific(w IWorld, entity int, obj T) int
- func (c *TableBaseAccessor[T]) Entities(w IWorld) []int
- func (c *TableBaseAccessor[T]) Filter(w IWorld, filter T, fieldNames []string) []int
- func (c *TableBaseAccessor[T]) Get(w IWorld, entity int) T
- func (c *TableBaseAccessor[T]) Name() string
- func (c *TableBaseAccessor[T]) RemoveEntity(w IWorld, entity int) int
- func (c *TableBaseAccessor[T]) Set(w IWorld, entity int, value T) T
- func (c *TableBaseAccessor[T]) Type() reflect.Type
- type TableOperationType
- type TableUpdate
- type TableUpdateArray
- type WorldUpdateBuffer
- func (w *WorldUpdateBuffer) Add(obj interface{}, tableName string) int
- func (w *WorldUpdateBuffer) AddSpecific(entity int, obj interface{}, tableName string) int
- func (w *WorldUpdateBuffer) ApplyUpdates()
- func (w *WorldUpdateBuffer) Delete(entity int, tableName string) int
- func (w *WorldUpdateBuffer) Entities(tableName string) []int
- func (w *WorldUpdateBuffer) Filter(filter interface{}, fieldNames []string, tableName string) []int
- func (w *WorldUpdateBuffer) Get(entity int, tableName string) (any, bool)
- func (w *WorldUpdateBuffer) GetTableUpdates() TableUpdateArray
- func (w *WorldUpdateBuffer) Set(entity int, obj interface{}, tableName string) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToWorld ¶
Adds a filled schema to the world. Creates the proper entity, etc.
func AddToWorldSpecific ¶
Core add a struct to a world on a specific entity
func ArePositionsAdjacent ¶
func ArrayIntersectionWithContext ¶
func ArrayIntersectionWithContext(ctx *QueryContext, nums1, nums2 []int) []int
func CalculateWorldStateRootHash ¶ added in v0.1.11
func ContainsPositions ¶
func ConvertStructToString ¶ added in v0.1.11
func ConvertStructToString(inputStruct interface{}) string
func CreateTypeRegistrationMapping ¶
Create type map registration
func EncodeTableUpdateArrayToBytes ¶
func EncodeTableUpdateArrayToBytes(tableUpdates []TableUpdate) ([]byte, error)
func HashStringsTogether ¶ added in v0.1.11
func IncludesString ¶
func SortStrings ¶ added in v0.1.11
deep copy and sort array of strings
Types ¶
type EntityManager ¶
type EntityManager struct { *SparseSet // contains filtered or unexported fields }
func NewEntityMananger ¶
func NewEntityMananger() *EntityManager
func (*EntityManager) GetNextAvailableEntity ¶ added in v0.1.0
func (e *EntityManager) GetNextAvailableEntity() int
type GameWorld ¶
type GameWorld struct { // all tables that stores data Tables map[string]Table // array of all table updates TableUpdates TableUpdateArray // contains filtered or unexported fields }
Master game world holding entities and tables All data belong to a table (aka component in ECS) that have different schemas (ex: Cat{}, Dog{})
func (*GameWorld) AddEntity ¶ added in v0.1.0
Add entity to world. Fetches the next available entity
func (*GameWorld) AddSpecific ¶
func (*GameWorld) AddSpecificEntity ¶ added in v0.1.0
Add a specific entity to the world This is useful in debugging and assigning constant entities to constant numbers
func (*GameWorld) AddTableUpdate ¶
func (w *GameWorld) AddTableUpdate(tableUpdate TableUpdate)
Add table updates to game world
func (*GameWorld) ClearTableUpdates ¶
func (w *GameWorld) ClearTableUpdates()
Clear game world's table updates
func (*GameWorld) GetAndClearTableUpdates ¶
func (w *GameWorld) GetAndClearTableUpdates() []TableUpdate
Get and clear game world's table updates
func (*GameWorld) GetTableUpdates ¶
func (w *GameWorld) GetTableUpdates() TableUpdateArray
type IWorld ¶
type IWorld interface { Add(obj interface{}, name string) int AddSpecific(entity int, obj interface{}, name string) int Get(entity int, tableName string) (any, bool) Set(entity int, obj interface{}, name string) interface{} Delete(entity int, tableName string) int Filter(filter interface{}, fieldNames []string, name string) []int Entities(string) []int GetTableUpdates() TableUpdateArray }
The World Interface Implemented by base world state and buffer world to enable atomic transactions
type QueryContext ¶
type QueryContext struct {
// contains filtered or unexported fields
}
func NewQueryContext ¶
func NewQueryContext() *QueryContext
func (*QueryContext) Clear ¶
func (ctx *QueryContext) Clear()
type SparseSet ¶
type SparseSet struct {
// contains filtered or unexported fields
}
func ArrayToSparseSet ¶
func NewSparseSet ¶
func NewSparseSet() *SparseSet
func (*SparseSet) GetRandomElement ¶
type Table ¶
type Table struct { GameWorld *GameWorld // table name Name string // table type Type reflect.Type // entities Entities *SparseSet // entity int => value EntityToValue map[int]any // fieldName => fieldVal => entities sparse set // // ex: Person {name string, age int} // "name" => "Alice" => [1, 2, 3] // "age" => "20" => [3, 5, 11] // json representation of int Indexes map[string]map[string]*SparseSet // TODO create a struct that locks this // contains filtered or unexported fields }
Each table corresponds to a schema (ex: Player, Animal, Tile)
func (*Table) RemoveEntity ¶
Remove entity from world
func (*Table) TableInterface ¶
type TableBaseAccessor ¶
Table accessors are used to access table data with proper types of its schema
func NewTableAccessor ¶
func NewTableAccessor[T any]() *TableBaseAccessor[T]
Initialize new table accessor
func (*TableBaseAccessor[T]) Add ¶
func (c *TableBaseAccessor[T]) Add(w IWorld, obj T) int
Add the object to the world and returns the assigned entity number
func (*TableBaseAccessor[T]) AddSpecific ¶
func (c *TableBaseAccessor[T]) AddSpecific(w IWorld, entity int, obj T) int
Adds the object to the world with a specific entity ID
func (*TableBaseAccessor[T]) Entities ¶
func (c *TableBaseAccessor[T]) Entities(w IWorld) []int
Get all entities for a schema table
func (*TableBaseAccessor[T]) Filter ¶
func (c *TableBaseAccessor[T]) Filter(w IWorld, filter T, fieldNames []string) []int
Query by filtering the fields. returns list of entities
func (*TableBaseAccessor[T]) Get ¶
func (c *TableBaseAccessor[T]) Get(w IWorld, entity int) T
Get object using entity from a world
func (*TableBaseAccessor[T]) RemoveEntity ¶
func (c *TableBaseAccessor[T]) RemoveEntity(w IWorld, entity int) int
Remove entity from world
func (*TableBaseAccessor[T]) Set ¶
func (c *TableBaseAccessor[T]) Set(w IWorld, entity int, value T) T
Set entity and its object value to world
func (*TableBaseAccessor[T]) Type ¶
func (c *TableBaseAccessor[T]) Type() reflect.Type
Receive the reflect.Type value of a table's schema
type TableOperationType ¶
type TableOperationType string
var ( // key indicating that the entity is being removed RemovalOP TableOperationType = "removal" // key indicating that the entity value is being set UpdateOP TableOperationType = "set" // key indicating that the entity is being added AddEntityOP TableOperationType = "add" )
Available op codes to indicate what type of update it is
type TableUpdate ¶
type TableUpdate struct { // "op codes" that represent what type of operation it is OP TableOperationType `json:"op"` // the entity Entity int `json:"entity"` // the name of the table Table string `json:"table"` // the value that's being updated Value interface{} `json:"value"` // unix timestamp Time int64 `json:"time"` }
func CopyTableUpdates ¶
func CopyTableUpdates(updates []TableUpdate) []TableUpdate
Deep copy table table updates
type TableUpdateArray ¶
type TableUpdateArray []TableUpdate
"table update" represents 1 single table update to the state
type WorldUpdateBuffer ¶
type WorldUpdateBuffer struct {
// contains filtered or unexported fields
}
func NewWorldUpdateBuffer ¶
func NewWorldUpdateBuffer(currentWorld *GameWorld) *WorldUpdateBuffer
TODO we can also make the register tables function a part of IWorld
func (*WorldUpdateBuffer) Add ¶
func (w *WorldUpdateBuffer) Add(obj interface{}, tableName string) int
func (*WorldUpdateBuffer) AddSpecific ¶
func (w *WorldUpdateBuffer) AddSpecific(entity int, obj interface{}, tableName string) int
func (*WorldUpdateBuffer) ApplyUpdates ¶
func (w *WorldUpdateBuffer) ApplyUpdates()
func (*WorldUpdateBuffer) Delete ¶
func (w *WorldUpdateBuffer) Delete(entity int, tableName string) int
func (*WorldUpdateBuffer) Entities ¶
func (w *WorldUpdateBuffer) Entities(tableName string) []int
func (*WorldUpdateBuffer) Filter ¶
func (w *WorldUpdateBuffer) Filter(filter interface{}, fieldNames []string, tableName string) []int
func (*WorldUpdateBuffer) Get ¶
func (w *WorldUpdateBuffer) Get(entity int, tableName string) (any, bool)
func (*WorldUpdateBuffer) GetTableUpdates ¶
func (w *WorldUpdateBuffer) GetTableUpdates() TableUpdateArray
func (*WorldUpdateBuffer) Set ¶
func (w *WorldUpdateBuffer) Set(entity int, obj interface{}, tableName string) interface{}