Skip to content

Commit

Permalink
tweak docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 committed Jan 16, 2024
1 parent 243cbfa commit 5316561
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions ecs/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import "github.com/mlange-42/arche/ecs/event"
// This allows the [World] to be in an unlocked state, and notifies after potential entity initialization.
type EntityEvent struct {
Entity Entity // The entity that was changed.
Changed Mask // Mask indicating changed components.
Changed Mask // Mask indicating changed components (additions and removals).
Added, Removed []ID // Components added and removed. DO NOT MODIFY! Get the current components with [World.Ids].
OldRelation, NewRelation *ID // Old and new relation component ID. No relation is indicated by nil.
OldTarget Entity // Old relation target entity. Get the new target with [World.Relations] and [Relations.Get].
EventTypes event.Subscription // Bit mask of event types. See [Subscription].
EventTypes event.Subscription // Bit mask of event types. See [event.Subscription].
}

// Contains returns whether the event's types contain the given type/subscription bit.
Expand Down Expand Up @@ -62,17 +62,18 @@ func newTestListener(callback func(e EntityEvent)) testListener {
}
}

// Notify the listener
// Notify the listener.
func (l *testListener) Notify(e EntityEvent) {
l.Callback(e)
}

// Subscriptions of the listener
// Subscriptions of the listener in terms of event types.
func (l *testListener) Subscriptions() event.Subscription {
return l.Subscribe
}

// Components the listener subscribes to.
// Will be notified about changes on any (not all!) of the components in the mask.
func (l *testListener) Components() *Mask {
return nil
}
1 change: 1 addition & 0 deletions ecs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func subscription(entityCreated, entityRemoved, componentAdded, componentRemoved
return bits
}

// Returns whether a listener that subscribes to an event is also interested in terms of component subscription.
func subscribes(evtType event.Subscription, changed *Mask, subs *Mask, oldRel *ID, newRel *ID) bool {
if event.Relations.Contains(evtType) {
return subs == nil || (oldRel != nil && subs.Get(*oldRel)) || (newRel != nil && subs.Get(*newRel))
Expand Down
3 changes: 2 additions & 1 deletion listener/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
// Dispatch event listener.
//
// Dispatches events to sub-listeners and manages subscription automatically.
//
// Sub-listeners should not alter their subscriptions or components after adding them.
//
// To make it possible for systems to add listeners, Dispatch should be added to the [ecs.World] as a resource.
type Dispatch struct {
listeners []ecs.Listener
events event.Subscription
Expand Down

0 comments on commit 5316561

Please sign in to comment.