Skip to content

Commit

Permalink
Improve documentation on internal methods (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Oct 13, 2024
1 parent 38bc684 commit 24ab834
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ecs/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ func (a *archetype) Remove(index uint32) bool {
a.copy(src, dst, size)
}
}

// Zero the free memory to allow the garbage collector
// to take into account pointers in the removed component.
a.ZeroAll(old)
a.len--

Expand All @@ -197,7 +200,7 @@ func (a *archetype) ZeroAll(index uint32) {
}
}

// ZeroAll resets a block of storage in one buffer.
// Zero resets a block of storage in one buffer.
func (a *archetype) Zero(index uint32, id ID) {
lay := a.getLayout(id)
size := lay.itemSize
Expand Down
4 changes: 4 additions & 0 deletions ecs/world_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ func (w *World) assign(entity Entity, relation ID, hasRelation bool, target Enti
}

// exchange with relation target.
// Panics if adding a component already present or removing a component not present.
// Also panics if the same component ID is in the add or remove list twice.
func (w *World) exchange(entity Entity, add []ID, rem []ID, relation ID, hasRelation bool, target Entity) {
if w.listener != nil {
arch, oldMask, oldTarget, oldRel := w.exchangeNoNotify(entity, add, rem, relation, hasRelation, target)
Expand Down Expand Up @@ -520,6 +522,8 @@ func (w *World) notifyExchange(arch *archetype, oldMask *Mask, entity Entity, ad
}

// Modify a mask by adding and removing IDs.
// Panics if adding a component already present or removing a component not present.
// Also panics if the same component ID is in the add or remove list twice.
func (w *World) getExchangeMask(mask Mask, add []ID, rem []ID) Mask {
for _, comp := range rem {
if !mask.Get(comp) {
Expand Down

0 comments on commit 24ab834

Please sign in to comment.