Giter Site home page Giter Site logo

Comments (11)

Prastiwar avatar Prastiwar commented on May 9, 2024 3
struct Group
{
    public int Length;
    public EntityArray Entities;
    public ComponentDataArray<Foo> Foos;
    public ComponentDataArray<Bar> Bars;
}

Group is group of all Entities in active world that have Foo and Bar component
It's like array of entities with references to specific given components.
So - Group is like EntityArray but with references to components, EntityArray itself is just array of Entities (and entity is just an index used in map)
Length is length of EntityArray, so also Length of Foos and Bars, because each entity has Foo and Bar component

It's more obvious in this case

for(int i; i < m_group.Length; i++) // iterate over all entities
{
    // It's safe to iterate like that, because every array in group has the same length
    // and indexing is also injected in that way to use it like this:
    var actualEntity = m_group.Entities[i];  // Actual iterating Entity
    var actualFoo    = m_group.Foos[i];      // Foo component "attached" to actualEntity
    var actualBar    = m_group.Bards[i];     // Bar component "attached" to actualEntity
}

Using m_group.Foos.Length or m_group.Bar.Length would be a bit confusing in this case.

Summary - every array in injected group would have same Length, because it's length of Entities and each entity has every given component

from entitycomponentsystemsamples.

darbotron avatar darbotron commented on May 9, 2024 1

I'm 99% sure this is because the [Inject] attribute expects whatever struct it's injecting to be a struct of arrays (SoA) where all the contained ComponentDataArray have the same length.

The generalised usage of the [Inject] idiom (e.g. see the struct used by other classes derived from ComponentSystem) makes more obvious sense since the injected structs typically have multiple ComponentDataArray with different component types.

from entitycomponentsystemsamples.

NVentimiglia avatar NVentimiglia commented on May 9, 2024 1

@starikcetin


struct PlayerData
        {            
            // SEE THIS LINE
            public int Length;

            public ComponentDataArray<PlayerInput> Input;
        }

I assume PlayerData.Length and PlayerData.Input.Length are the same value. They both describe the number of PlayerInput's, no ? Competing and confusing. Would suggest removing PlayerData.Length.

from entitycomponentsystemsamples.

NVentimiglia avatar NVentimiglia commented on May 9, 2024

Not sure I like the competing values. Will confuse others.

Maybe an interface defining why we need this? Will exclusion break things?

from entitycomponentsystemsamples.

starikcetin avatar starikcetin commented on May 9, 2024

@NVentimiglia
What do you mean by competing values?

from entitycomponentsystemsamples.

starikcetin avatar starikcetin commented on May 9, 2024

@NVentimiglia
I still don't understand why you think they are competing.

When you are injecting multiple arrays in the same struct, they are all injected in parallel in terms of entities. Therefore they all have the same length. Instead of checking the length of every single array (which would be the same for all of them), I, personally, very much prefer injecting a single length variable.

from entitycomponentsystemsamples.

NVentimiglia avatar NVentimiglia commented on May 9, 2024

@starikcetin

Maybe I am confused. So it is possible for these values to be different if we have multiple arrays? Are the rules defining what this 'Length' value means documented somewhere?

from entitycomponentsystemsamples.

starikcetin avatar starikcetin commented on May 9, 2024

@NVentimiglia

Say you have this:

struct Group
{
    public int Length;

    public ComponentDataArray<Foo> Foos;
    public ComponentDataArray<Bar> Bars;
}

The Length is the amount of entities that matched.

When you do Foos[2] it will, say, give you the Foo on the entity # 2. When you do Bars[2] it will give you the Bar on the entity # 2.

Therefore the indexes of those arrays are each a different matched entity, and you get different components of the same entity when you apply the same index to different arrays.

There is not much of a documentation yet, but you may watch the talks from Unite Austin, they delve deep into how the ECS operates.

from entitycomponentsystemsamples.

NVentimiglia avatar NVentimiglia commented on May 9, 2024

Gotcha, so if Foos is 3 and Bars is 2, Length will be 3? Is that possible with how groups work? I was assuming that If I requested a group with Foo and Bar, I would get only entities with both (both 3).

from entitycomponentsystemsamples.

starikcetin avatar starikcetin commented on May 9, 2024

@NVentimiglia

Your assumption is correct. You only get entities that has both of the components. Hence why the arrays are parallel, and that they have the same length.

So no, the scenario you proposed is not possible, Length of Foos cannot be 2 while Bars is 3. They both will either be 3 or 2.

from entitycomponentsystemsamples.

NVentimiglia avatar NVentimiglia commented on May 9, 2024

@Prastiwar Super helpful

from entitycomponentsystemsamples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.