Closed vmwxiong closed 3 years ago
I think I experimented with this before, but was not able to get it entirely right (also asking around). But I think I just saw one missing piece in the puzzle to a struct-less System in your code. I will play around with it. However, I don't think I will change how a system looks entirely. I would like systems to ideally
Systems being functions would be a counter to that end imho. It may also be just my preference. I will give this another go and see if I can make the current API simpler, ideally removing the extra struct :)
Yeah going with fully functional Systems would definitely be a pretty specific take on things.
You might want to check out the API that Ape-ECS is going with if you haven't already, might give you some ideas: https://github.com/fritzy/ape-ecs/blob/master/docs/System.md
It's a very different direction, but basically the idea is to think about whether or not you want the notion of multiple Queries vs a single, purely matched system. Both approaches have their pros and cons. Multiple queries allows for easier to implement batching of functionality by interacting with multiple types of entities in one go. On the other hand, it drastically alters separation of concerns, and makes it immediately more difficult to tell what components a system is even capable of "messing up". Just food for thought.
I messed around a bit with the type system, and still was not able to come up with a good way to statically type a generic query without generics. While going functional, like in your example, might work, it still does not provide any way for a system to build a cache or be optimized, especially when running in a distributed way - which is the ultimate goal. So I think it is best left to ape-ecs to go down that route, while I try another direction 😉
If you or anyone else comes up with a better plan on how to achieve all goals, then I'm all for merging a PR and make it happen!
Hi @vmwxiong , wanted to update you on what I am working on right now, since you may be interested in the change! I am reworking how querying a world works. I finally found a satisfying alternative to the type boilerplate, which may even lead to very simple queries you can easily use everywhere with caching benefits (but sans the life-cycle). The new queries come with better type support, less typing and allow for some new good stuff under the hood. The status is: WIP. I still have to update some under-the-hood things to make it all work, but the Query class has come a long way, so I feel comfortable to share a bit :)
Also, I want to get some feedback from you, if the below demo code is closer to what you would love to work with.
Say goodbye to type boilerplate for Systems:
Deverloper convenience is still a goal:
iter()
methodOoooh, very interesting. I like the direction for sure.
I think I'd personally want to be using some kind of syntax that would still look like a callback in the end, sort of like
this.query.execute(({info, test}) => {
info.count++;
console.log(test);
});
But that might just be me. This would probably be some syntactic sugar on top of what you already provide here, since there may be occasions when you would want to halt prematurely. I just think this kind of format is easier to understand semantically, given my preconceived notions of what a query is and does in general.
Looking good!
Your snippet is a nice idea and solves the problem with the field order and type. Writing a method for a callback is simple and straight forward, now So, I did it and will include it as alternative :)
Thank you for the feedback!
Had an idea for a potential syntax that might be able to simplify how you access components. Essentially the idea was to allow a system to process components as parameters to some sort of callback function. Hopped on the Typescript discord and they came up with this snippet. You can see the usage at the very bottom, and the stuff above that is an example of how you would implement the types. Think this or something like it might be a reasonable direction to go in instead of creating a separate
data
object like in the main readme example for Systems.