Skip to main content
added 768 characters in body
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83

Update

I have wrote Theraot.ECS inspired by Fastest way to look up an entity with a set of components?.

However this answer motivated me to allow to specify custom containers for particular types. It would be necesary to provide an adapter to the interface IIntKeyCollection<TValue> exposed in the project. Which would in theory allow the ECS to use a quadtree internally, just for some types of componets, for example some third party Vector2.

The project is free and open source software, feel free to study it, use it, whatever. MIT license.


Original Answer


Update

I have wrote Theraot.ECS inspired by Fastest way to look up an entity with a set of components?.

However this answer motivated me to allow to specify custom containers for particular types. It would be necesary to provide an adapter to the interface IIntKeyCollection<TValue> exposed in the project. Which would in theory allow the ECS to use a quadtree internally, just for some types of componets, for example some third party Vector2.

The project is free and open source software, feel free to study it, use it, whatever. MIT license.


Original Answer

added 2069 characters in body
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83

Addendum: On the server both the physics (for collisions) and the network (to know what things are near the players, so it can send them only notification about their surrounding) would need the quadtree. On the client, both physics and rendering (to have a quick approximation of what is in camera to send to the GPU) would need the quadtree.

  • Have smart position components, such that systems can subscribe to changes of these components. Then the system that updates the quadtree can subscribe.

    This is similar to the idea above, except the quadtree is not directly referenced in the component.

    The ECS are not meant to have notification for changed components (and I do not mean events for added and removed components, but events for modified values), and having them is detrimental for performance※.

    If the ECS does not have the means to subscribe to changes of a component - and I do not think they should have it, at least not out of the box※※ - we can make a not very pure component that has this ability.

    Perhaps having each component handle its own events does not sound as a great idea, then we could consider to centrilize these notification in a... wait, I'm adding a dependency to the components. We could just make that dependency the quadtree and we are back at idea above.

  • Have smart position components, such that systems can subscribe to changes of these components. Then the system that updates the quadtree can subscribe.

    This is similar to the idea above, except the quadtree is not directly referenced in the component.

    The ECS are not meant to have notification for changed components (and I do not mean events for added and removed components, but events for modified values), and having them is detrimental for performance※.

    If the ECS does not have the means to subscribe to changes of a component - and I do not think they should have it, at least not out of the box※※ - we can make a not very pure component that has this ability.

    Perhaps having each component handle its own events does not sound as a great idea, then we could consider to centrilize these notification in a... wait, I'm adding a dependency to the components.

Addendum: On the server both the physics (for collisions) and the network (to know what things are near the players, so it can send them only notification about their surrounding) would need the quadtree. On the client, both physics and rendering (to have a quick approximation of what is in camera to send to the GPU) would need the quadtree.

  • Have smart position components, such that systems can subscribe to changes of these components. Then the system that updates the quadtree can subscribe.

    This is similar to the idea above, except the quadtree is not directly referenced in the component.

    The ECS are not meant to have notification for changed components (and I do not mean events for added and removed components, but events for modified values), and having them is detrimental for performance※.

    If the ECS does not have the means to subscribe to changes of a component - and I do not think they should have it, at least not out of the box※※ - we can make a not very pure component that has this ability.

    Perhaps having each component handle its own events does not sound as a great idea, then we could consider to centrilize these notification in a... wait, I'm adding a dependency to the components. We could just make that dependency the quadtree and we are back at idea above.

added 2069 characters in body
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83
 
 

Fancy commercial game engines can have the luxury of making a ECS that spatially aware. On one hand it has performance benefits. On the other it couples the ECS to a particular geometry, and a particular geometry library... which makes it very hard to reuse separete from the game engine. Fancy commercial game engines can have the luxury of making a ECS that spatially aware. On one hand it has performance benefits. On the other it couples the ECS to a particular geometry, and a particular geometry library... which makes it very hard to reuse separete from the game engine.

Addendum: I believe it is possible to develop an ECS solution that allows to specify custom containers. Either for the whole or just for particular component types. We could tell such ECS to use (an adapter around) a quadtree that would be alike to the deeply woven one in the fancy ECS, except it was injected.


※: On one hand, we can have only entities that move have a velocity component, or alternatively we can add a component to mark entities that do not move. In either case, the systems would be able to iterate over and only over the entities that move, being sure that all of them moved since last tick. On the other hand, ECS often optimize for cache locality and fast access and iteration, in fact, a tighly managed ECS could even provide - temporary - direct references to components allowing to modify them quickly but with no means to rise an event to notify that they were (well, we could assume they were modified if the developer took the references).

※※: I haven't seen anIf the ECS that lets youallows to specify that it should use a custom container, either for the whole or just forin particular for specific component types (I conceptualize it as dependency injection). If an ECS allows you to specify the container, we could tell itthe ECS to use one that has events for value changed. However, heckif that is possible, we could tell itjust use (an adapter around) a quadtree that would be alike to the deeply woven one in the fancy ECS, except it was injectedquadtree. I am interested in developing such ECS.

Fancy commercial game engines can have the luxury of making a ECS that spatially aware. On one hand it has performance benefits. On the other it couples the ECS to a particular geometry, and a particular geometry library... which makes it very hard to reuse separete from the game engine.

※: On one hand, we can have only entities that move have a velocity component, or alternatively we can add a component to mark entities that do not move. In either case, the systems would be able to iterate over and only over the entities that move, being sure that all of them moved. On the other hand, ECS often optimize for cache locality and fast access and iteration, in fact, a tighly managed ECS could even provide - temporary - direct references to components allowing to modify them quickly but with no means to rise an event to notify that they were (well, we could assume they were modified if the developer took the references).

※※: I haven't seen an ECS that lets you specify that it should use a custom container, either for the whole or just for particular component types (I conceptualize it as dependency injection). If an ECS allows you to specify the container, we could tell it use one that has events for value changed, heck, we could tell it use (an adapter around) a quadtree that would be alike to the deeply woven one in the fancy ECS, except it was injected. I am interested in developing such ECS.

 
 

Fancy commercial game engines can have the luxury of making a ECS that spatially aware. On one hand it has performance benefits. On the other it couples the ECS to a particular geometry, and a particular geometry library... which makes it very hard to reuse separete from the game engine.

Addendum: I believe it is possible to develop an ECS solution that allows to specify custom containers. Either for the whole or just for particular component types. We could tell such ECS to use (an adapter around) a quadtree that would be alike to the deeply woven one in the fancy ECS, except it was injected.


※: On one hand, we can have only entities that move have a velocity component, or alternatively we can add a component to mark entities that do not move. In either case, the systems would be able to iterate over and only over the entities that move, being sure that all of them moved since last tick. On the other hand, ECS often optimize for cache locality and fast access and iteration, in fact, a tighly managed ECS could even provide - temporary - direct references to components allowing to modify them quickly but with no means to rise an event to notify that they were (well, we could assume they were modified if the developer took the references).

※※: If the ECS allows to specify a custom container, in particular for specific component types, we could tell the ECS to use one that has events for value changed. However, if that is possible, we could just use the quadtree.

added 2069 characters in body
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83
Loading
added 2069 characters in body
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83
Loading
Source Link
Theraot
  • 28.3k
  • 4
  • 55
  • 83
Loading