Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify archetype graph to a single list of neighbors per node #433

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading