-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replaces some fields of `EntityEvent` by a bitmask of triggered event types * Allows filtering events by a subscriptions mask * Introduces a `Listener` interface * Splits out subscriptions and default `Listener` implementation into packages # Commits * implement simple listener with subscription for different events * use a bit mask to encode event types and subscriptions * remove redundant event fields * move subscriptions and default listener to separate packages * run CI on merge requests against any branch * tweak listener description, add example * add benchmarks for having a listener that does not subscribe * update changelog * replace EntityEvent getters by a Contains method, tweak EntityEvent docs * add a dispatched listener implementation
- Loading branch information
Showing
19 changed files
with
822 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ on: | |
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Package event contains a mask type and bit switches for listener subscriptions. | ||
// | ||
// See also ecs.Listener and ecs.EntityEvent. | ||
package event | ||
|
||
// Subscription bits for individual events | ||
const ( | ||
// EntityCreated subscription bit | ||
EntityCreated Subscription = 0b00000001 | ||
// EntityRemoved subscription bit | ||
EntityRemoved Subscription = 0b00000010 | ||
// ComponentAdded subscription bit | ||
ComponentAdded Subscription = 0b00000100 | ||
// ComponentRemoved subscription bit | ||
ComponentRemoved Subscription = 0b000001000 | ||
// RelationChanged subscription bit | ||
RelationChanged Subscription = 0b000010000 | ||
// TargetChanged subscription bit | ||
TargetChanged Subscription = 0b000100000 | ||
) | ||
|
||
// Subscription bits for groups of events | ||
const ( | ||
// Entities subscription for entity creation or removal | ||
Entities Subscription = EntityCreated | EntityRemoved | ||
// Components subscription for component addition or removal | ||
Components Subscription = ComponentAdded | ComponentRemoved | ||
// Relations subscription for relation and target changes | ||
Relations Subscription = RelationChanged | TargetChanged | ||
// All subscriptions | ||
All Subscription = Entities | Components | Relations | ||
) | ||
|
||
// Subscription bits for an ecs.Listener | ||
type Subscription uint8 | ||
|
||
// Contains checks whether all the argument's bits are contained in this Subscription. | ||
func (s Subscription) Contains(bits Subscription) bool { | ||
return (bits & s) == bits | ||
} | ||
|
||
// ContainsAny checks whether any of the argument's bits are contained in this Subscription. | ||
func (s Subscription) ContainsAny(bits Subscription) bool { | ||
return (bits & s) != 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package event_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mlange-42/arche/ecs/event" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSubscriptions(t *testing.T) { | ||
m1 := event.EntityCreated | event.TargetChanged | ||
|
||
assert.True(t, m1.Contains(event.EntityCreated)) | ||
assert.False(t, m1.Contains(event.EntityRemoved)) | ||
|
||
assert.True(t, m1.ContainsAny(event.ComponentAdded|event.TargetChanged)) | ||
assert.False(t, m1.Contains(event.ComponentAdded|event.RelationChanged)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.