-
Notifications
You must be signed in to change notification settings - Fork 56
What about supporting singleton components #9
Comments
I'm not sure I like the idea of having a singleton entity as part of this library. You can easily implement that without touching the library code by creating an entity and storing it wherever you store the |
I did that before and definitely it worked, but I had to access them as the other non-singleton components by methods like I'm only a student, and I'm not dare to change your codes at low level. I just told you what I need to see whether you would like to implement it. |
If you do it the way I suggested: // These should be stored somewhere accessible
World* myWorld = World::createWorld();
Entity* mySingletonEntity = myWorld->create();
mySingletonEntity->assign<SomeComponent>(); You can access components on ComponentHandle<SomeComponent> someComponent = mySingletonEntity->get<SomeComponent>();
// alternatively, use auto:
auto someComponent = mySingletonEntity->get<SomeComponent>(); Assuming you store |
Yeah I did that like: Entity* singletons = world->create();
singletons->assign<CameraInfoSingletonComponent>(); In systems' virtual void tick(class World* world, float deltaTime) override {
world->each<CameraInfoSingletonComponent>([&](Entity* ent, ComponentHandle<CameraInfoSingletonComponent> cameraCHandle) -> void {
// do something with cameraCHandle...
});
} It works, just not neat. Actually there's only one If I could do that like this, my team members could easily know that there's only one virtual void tick(class World* world, float deltaTime) override {
auto cameraCHandle = world->getSingletonComponent<CameraInfoSingletonComponent>();
// do something with cameraCHandle...
} |
You are right, it's not necessary, just few more lines. Feel free to close this issue. |
I do suggest considering other options. Closed. |
What about a signature matching system? When a component is added or removed, use a container to trance the component, so the system can loop over the container instead of all the entities on each tick. |
I'm not quite sure what you mean, can you give an example? |
For example, when I try to loop over entities with SomeComponent1 and SomeComponent2 using this: world->each<SomeComponent1,SomeComponent2>(...) and there are very few entities having these components, so I don't want to loop over all the entities to get the result due to low performance. for(auto pair : world->component_recorder_SomeComponent1_SomeComponent2)
do some thing with pair ........ The question is, should this done by the framework itself or an extra system based on the framework? |
I suggest creating a new issue, what you are asking for doesn't have anything to do with singleton components. I'm going to lock this issue but feel free to open a new one with your idea. As for the idea itself, yes Additionally, if you request multiple components then you'd still pay the cost of iterating entities (albeit a smaller set than the entire world) or you'd have to do a union of each set of entities with one of the requested components. I'm not convinced that in general this operation would be fast. The last option would be to have some sort of structure you can register with the world that always contains a list of all entities with specified components - something like I think out of the options, I prefer the last one but I don't know if I'll get around to implementing it or not. Anyway, create a new issue if you're interested and hopefully I'll get to it or someone else will. |
I'm using your library to write a simple game. Your library is wonderful and it helps me a lot. But I hope that you could add APIs to support to create singleton components (came from GDC2017 'Overwatch Gameplay Architecture and Netcode', I'm sorry that I didn't find the video), which is like global variables that directly belong to the world instead of entities. I think they are helpful when you need components with camera position, window width and height, time, etc, that need to share between systems but does not logically belong to any entity.
I add some codes to complement a simple version, using a singleton entity to store the singleton components, but it's not gentle at all:
I hope you could write these APIs in your way.
The text was updated successfully, but these errors were encountered: