-
Notifications
You must be signed in to change notification settings - Fork 12
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
event system? #34
Comments
I wanted to get events into sim-ecs for quiet a while, and I have been thinking about ways to make them a reality. sim-ecs is not built the same way bevy_ecs works (for a number of reasons), so there are some design concerns I have and I can't find a good solution. So, let me just brainstorm: Option 1
class MyEvent {
constructor(
public message: string,
) {}
}
const query = new Query({
event: ReadEvent(MyEvent),
eventWriter: WriteEvent(MyEvent),
});
for (const {eventReader, eventWriter} of query.iter()) {
console.log(event.message); // <- ref is constant for all items in query
setTimeout(eventWriter.send(new MyEvent('Hello World')), 100); // <- ref is constant for all items in query
} Option 2
class MyEvent {
constructor(
public message: string,
) {}
}
class MyEventSystem<T extends MyEvent> extends EventSystem<T> {
readonly query = new Query({ counterObj: Write(Counter) });
run(actions: ISystemActions, event: T) {
console.log(event.message);
actions.sendEvent(new MyEvent('Hello World'));
}
} Option 3
class MyEvent {
constructor(
public message: string,
) {}
}
class MySystem extends System {
readonly query = new Query({ counterObj: Write(Counter) });
run(actions: ISystemActions) {
for (const event of actions.getEvents(MyEvent)) {
console.log(event.message);
}
actions.sendEvent(new MyEvent('Hello World'));
}
} Option 4
// this is fantasy code!
class MyEvent {
constructor(
public message: string,
) {}
}
const MySystem = System
.withParams([
new Query({
counterObj: Read(Counter),
}),
EventWriter(MyEvent),
EventReader(MyEvent),
ReadResource(GlobalStore),
WriteResource(SomethingEelse),
// ...
])
.build((query, eventWriter, eventReader, globalStore, somethingElse) => {
if (eventReader.empty()) return;
for (const event of eventReader.events()) {
console.log(event.message);
}
eventWriter.send(new MyEvent('Hello World'));
query.execute(({counterObj}) => {
// ...
});
}); |
After creating a PoC with option 4, it seems to be a good move forward, so I will implement centralized pipelines, now, and after that work on stageless, System builder and finally events. Might take a while, but I'll try to work on it quickly and release it as a package in 0.5.0 |
Merged in #43 and will be part of v0.5 |
refer to bevy: https://github.com/bevyengine/bevy/blob/latest/examples/ecs/event.rs
The text was updated successfully, but these errors were encountered: