Comments (3)
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
ReadEvent and WriteEvent are part of the regular IAccessQuery interface, but Read only triggers the query when there is an event / the query only has data when there is an event
- does every data-instance of varying components get the same reference to the event data struct?
- how do we handle multiple events?
- sounds inconsistent with regular way queries work
- might need looping system execution to handle all events
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
Expose a new interface IEventSystem, which is a special System interface for handling events without touching the current Query APIs
- can only handle one event per system
- may need looping systems for multiple events
- extra interface with generics
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
Implement an API on the world interfaces which allows manually polling events at any point
- forgetting to poll events may lead to constant memory consumption
- cannot be prepared before the main loop starts
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
We go ahead with stageless, centralized pipeline planning, PLUS implement a system builder, which gets rid of the class boilerplate and makes systems look like a configurable function - which would work more like bevy_ecs.
- I like this approach the most, because it makes systems very flexible
- also it makes it easier to prepare systems under the hood (resources included!)
- I got a lot of feedback that people want functions as systems, this is rather close :)
- (as soon as decorators land, this could be decorated nicely)
// 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}) => {
// ...
});
});
from sim-ecs.
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
from sim-ecs.
Merged in #43 and will be part of v0.5
from sim-ecs.
Related Issues (20)
- Sync-Point ergonomics HOT 1
- Implement async error handling (when a system throws/rejects)
- Add Madge as post-build-step HOT 1
- Investigate Deno (again) HOT 3
- I really like this git repository ! Why is insertion very slow ? HOT 1
- Rename `findWorld()` to `getWorld()`
- Create shorthand aliases for long `with...()` methods
- Add convencience methods to Query, like `filter`, `sort`,... HOT 1
- Make components Objects-of-Arrays (like BitECS) HOT 1
- Add snapshots
- Investigate preformance regression on master HOT 1
- Update Benchmarks
- Implement HMR functionality
- It feels like benchmarks are missing the point HOT 6
- Integration with ecosystem HOT 4
- Implement Component Observers
- Run pipeline from pipeline HOT 4
- deno - publish fixed imports HOT 3
- Create more examples
- The runtime world hasn't initialized a scheduler executor! HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sim-ecs.