Skip to content

Commit

Permalink
Simplify archetype graph to a single list of neighbors per node (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Nov 25, 2024
1 parent ca9010a commit 6581381
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Adds an example for `World.Mask`, showing how to check whether a filter "contains" an entity (#428)
* Adds the [beecs](https://github.com/mlange-42/beecs) implementation of [BEEHAVE](https://beehave-model.net/) to the showcase (#429)

### Performance

* Simplifies the archetype graph to use only a single list of neighbors per node, saving a bit of memory (#433)

## [[v0.13.2]](https://github.com/mlange-42/arche/compare/v0.13.1...v0.13.2)

### Bugfixes
Expand Down
6 changes: 2 additions & 4 deletions ecs/archetype_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ type nodeData struct {
zeroValue []byte // Used as source for setting storage to zero
archetypes pagedSlice[archetype] // Storage for archetypes in nodes with entity relation
archetypeData pagedSlice[archetypeData]
TransitionAdd idMap[*archNode] // Mapping from component ID to add to the resulting archetype
TransitionRemove idMap[*archNode] // Mapping from component ID to remove to the resulting archetype
neighbors idMap[*archNode] // Mapping from component ID to add/remove, to the resulting archetype
capacityIncrement uint32 // Capacity increment
}

Expand Down Expand Up @@ -70,8 +69,7 @@ func newArchNode(mask Mask, data *nodeData, relation ID, hasRelation bool, capac
data.capacityIncrement = uint32(capacityIncrement)
data.zeroValue = zeroValue
data.zeroPointer = zeroPointer
data.TransitionAdd = newIDMap[*archNode]()
data.TransitionRemove = newIDMap[*archNode]()
data.neighbors = newIDMap[*archNode]()

return archNode{
nodeData: data,
Expand Down
12 changes: 6 additions & 6 deletions ecs/world_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,12 @@ func (w *World) findOrCreateArchetype(start *archetype, add []ID, rem []ID, targ
relation = ID{}
hasRelation = false
}
if next, ok := curr.TransitionRemove.Get(id.id); ok {
if next, ok := curr.neighbors.Get(id.id); ok {
curr = next
} else {
next, _ := w.findOrCreateArchetypeSlow(mask, relation, hasRelation)
next.TransitionAdd.Set(id.id, curr)
curr.TransitionRemove.Set(id.id, next)
next.neighbors.Set(id.id, curr)
curr.neighbors.Set(id.id, next)
curr = next
}
}
Expand All @@ -946,12 +946,12 @@ func (w *World) findOrCreateArchetype(start *archetype, add []ID, rem []ID, targ
relation = id
hasRelation = true
}
if next, ok := curr.TransitionAdd.Get(id.id); ok {
if next, ok := curr.neighbors.Get(id.id); ok {
curr = next
} else {
next, _ := w.findOrCreateArchetypeSlow(mask, relation, hasRelation)
next.TransitionRemove.Set(id.id, curr)
curr.TransitionAdd.Set(id.id, next)
next.neighbors.Set(id.id, curr)
curr.neighbors.Set(id.id, next)
curr = next
}
}
Expand Down

0 comments on commit 6581381

Please sign in to comment.