Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Query Unique #60

Open
Difficulty-in-naming opened this issue Jan 31, 2023 · 4 comments
Open

Add Query Unique #60

Difficulty-in-naming opened this issue Jan 31, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@Difficulty-in-naming
Copy link

Difficulty-in-naming commented Jan 31, 2023

We need a method to query singleton components. We will use this method in many scenarios, such as Player Input, making the code look more concise and readable.

    private QueryDescription mDescription = new QueryDescription{Any = new ComponentType[]{typeof(C_PlayerInput)}};
    public void Query()
    {
        world.Query(mDescription, (ref C_PlayerInput input) =>
        {
            if (input.IsClicked)
            {
                //Query another entity....
            }
        });
    }
    public void QueryUnique()
    {
        var playerInput = world.QueryUnique<C_PlayerInput>();
        //Query another entity...
    }
@genaray genaray added the enhancement New feature or request label Jan 31, 2023
@genaray
Copy link
Owner

genaray commented Jan 31, 2023

We need a method to query singleton components. We will use this method in many scenarios, such as Player Input, making the code look more concise and readable.

    private QueryDescription mDescription = new QueryDescription{Any = new ComponentType[]{typeof(C_PlayerInput)}};
    public void Query()
    {
        world.Query(mDescription, (ref C_PlayerInput input) =>
        {
            if (input.IsClicked)
            {
                //Query another entity....
            }
        });
    }
    public void QueryUnique()
    {
        var playerInput = world.QueryUnique<C_PlayerInput>();
        //Query another entity...
    }

Thanks and that's actually a great idea! :)
Im gonna think about different ways of realizing this. I think combining this with the current Query-API is not possible since that would require checks every call which would result in a decreased performance. However the world.QueryUnique approach is probably fine, so we could set components directly on the world itself.

Im gonna take a look at how other ecs solve this problem, or if they actually solve it at all ^^

@Difficulty-in-naming
Copy link
Author

We need a method to query singleton components. We will use this method in many scenarios, such as Player Input, making the code look more concise and readable.

    private QueryDescription mDescription = new QueryDescription{Any = new ComponentType[]{typeof(C_PlayerInput)}};
    public void Query()
    {
        world.Query(mDescription, (ref C_PlayerInput input) =>
        {
            if (input.IsClicked)
            {
                //Query another entity....
            }
        });
    }
    public void QueryUnique()
    {
        var playerInput = world.QueryUnique<C_PlayerInput>();
        //Query another entity...
    }

Thanks and that's actually a great idea! :) Im gonna think about different ways of realizing this. I think combining this with the current Query-API is not possible since that would require checks every call which would result in a decreased performance. However the world.QueryUnique approach is probably fine, so we could set components directly on the world itself.

Im gonna take a look at how other ecs solve this problem, or if they actually solve it at all ^^

The idea of attaching components to the world is an unusual concept. To my knowledge, both Unity ECS and Svelto ECS are attached to entities. Do you want to view the world as a root entity?

@Difficulty-in-naming
Copy link
Author

Mounting components on the world may produce another way that is independent of the current architecture. Perhaps we need a dictionary with component type as the key and entity as the value. This way, when we call QueryUnique, we can also determine if the component type is unique (singleton) to ensure that user actions do not produce unexpected results.

@genaray
Copy link
Owner

genaray commented Feb 6, 2023

Mounting components on the world may produce another way that is independent of the current architecture. Perhaps we need a dictionary with component type as the key and entity as the value. This way, when we call QueryUnique, we can also determine if the component type is unique (singleton) to ensure that user actions do not produce unexpected results.

That could work aswell. This could also be a bit optimized by avoiding the dictionary and replacing it with an array for faster access. Dictionarys normally have a small overhead, which is noticeable for large amounts of acess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants