-
Notifications
You must be signed in to change notification settings - Fork 37
/
manager.go
65 lines (52 loc) · 2.09 KB
/
manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gamestate
import (
"context"
"encoding/json"
"pkg.world.dev/world-engine/cardinal/iterators"
"pkg.world.dev/world-engine/cardinal/search/filter"
"pkg.world.dev/world-engine/cardinal/types"
"pkg.world.dev/world-engine/cardinal/types/txpool"
)
type Reader interface {
// One Component One Entity
GetComponentForEntity(cType types.ComponentMetadata, id types.EntityID) (any, error)
GetComponentForEntityInRawJSON(cType types.ComponentMetadata, id types.EntityID) (json.RawMessage, error)
// Many Components One Entity
GetComponentTypesForEntity(id types.EntityID) ([]types.ComponentMetadata, error)
// One Archetype Many Components
GetComponentTypesForArchID(archID types.ArchetypeID) ([]types.ComponentMetadata, error)
GetArchIDForComponents(components []types.ComponentMetadata) (types.ArchetypeID, error)
// One Archetype Many Entities
GetEntitiesForArchID(archID types.ArchetypeID) ([]types.EntityID, error)
// Misc
SearchFrom(filter filter.ComponentFilter, start int) *iterators.ArchetypeIterator
ArchetypeCount() int
}
type Writer interface {
// One Entity
RemoveEntity(id types.EntityID) error
// Many Components
CreateEntity(comps ...types.ComponentMetadata) (types.EntityID, error)
CreateManyEntities(num int, comps ...types.ComponentMetadata) ([]types.EntityID, error)
// One Component One Entity
SetComponentForEntity(cType types.ComponentMetadata, id types.EntityID, value any) error
AddComponentToEntity(cType types.ComponentMetadata, id types.EntityID) error
RemoveComponentFromEntity(cType types.ComponentMetadata, id types.EntityID) error
// Misc
Close() error
RegisterComponents([]types.ComponentMetadata) error
}
type TickStorage interface {
GetTickNumbers() (start, end uint64, err error)
StartNextTick(txs []types.Message, pool *txpool.TxPool) error
FinalizeTick(ctx context.Context) error
Recover(txs []types.Message) (*txpool.TxPool, error)
}
// Manager represents all the methods required to track Component, Entity, and Archetype information
// which powers the ECS dbStorage layer.
type Manager interface {
TickStorage
Reader
Writer
ToReadOnly() Reader
}