cross-posted from: https://programming.dev/post/1086370

This time on my arbitrary blog: Entity component systems.

Also, highlight.js should degrade more gracefully without JS activated than last time. Note that I can’t process syntax highlighting in my build step, because I don’t have a build step.

EDIT: improved phrasing

  • TheCee@programming.devOP
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    The next example which seems to create two bubbles on the same entity is just as confusing to me. If I were to query for those bubbles, would I iterate over each of those bubbles in separate iterations, but all other components that are part of this query are the same?

    No that would be crazy.

    No, but seriously, the find operator is supposed to take only one type and not merge the types. ECS seems close enough to relational databases, but not that close.

    • TehPers@beehaw.org
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      In this case, would the components be combined into a list? Basically you’d have a BubbleComponent[] attached to the entity instead of just a BubbleComponent? Maybe I’m misunderstanding what the system is, is click_handler in the post a system, and if so, do systems only declare a single component of an entity as their input? From my experience, you often want to work with multiple components of the same entity in a system, for example:

      -- Mark characters with 0 or less life as dead
      function mark_dead(character: BoundaryComponent) {
          with character as movement: MovementComponent {
              character.x += movement.velocity.x * delta_secs;
              character.y += movement.velocity.y * delta_secs;
          }
      }
      

      Would there be a simpler way to query these components in the system, and what if I wanted to query for both BoundaryComponent and BubbleComponent, what would that look like?

      • TheCee@programming.devOP
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        Maybe I’m misunderstanding what the system is, is click_handler in the post a system, and if so, do systems only declare a single component of an entity as their input?

        The way I figured would make sense was that, in the engine/game itself, the BoundaryComponent would have an additional field for registered scripts or that there would be an additional component just for registered scripts, to keep components lean. Not sure if that actually worked out in reality.

        Then there would be a system for clicking on boundaries that would call such a script, if available. It’s probably a poor example, but since that system doesn’t touch much else, only the boundary component gets passed into the script. That’s not supposed to be a rule, though. I probably should clarify that on the post later on…

      • TheCee@programming.devOP
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        this case, would the components be combined into a list? Basically you’d have a BubbleComponent[] attached to the entity instead of just a BubbleComponent?

        Yes.