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

Sort system and query result based on user sort function #112

Open
Avokadoen opened this issue May 29, 2023 · 3 comments
Open

Sort system and query result based on user sort function #112

Avokadoen opened this issue May 29, 2023 · 3 comments
Labels
proposal A *potential* improvement

Comments

@Avokadoen
Copy link
Owner

Allow user to submit an optional sorting functions that will be used to sort results BEFORE executing the system or iterating the query

    var world = try WorldStub.WithEvents(.{
        Event("onFoo", .{
            SortResult(sortFn, SystemStruct1.func1),
            SystemStruct1.func2,
            SystemStruct2,
        }, .{}),
    }).init(testing.allocator, .{});
@Avokadoen Avokadoen pinned this issue Jun 1, 2023
@Avokadoen Avokadoen added the proposal A *potential* improvement label Jun 13, 2023
@Avokadoen
Copy link
Owner Author

Avokadoen commented Jun 19, 2023

@matkve could you describe a scenario where this would be useful? It would help as the current proposal will probably be rejected otherwise

@Avokadoen Avokadoen unpinned this issue Jun 19, 2023
@Avokadoen
Copy link
Owner Author

Alternative to this which would have a bit less overhead would be to specify sorting of component types in the storage, but then the question is how would sorting of multiple component types work

@Avokadoen
Copy link
Owner Author

Maybe if we expose explicit archetype sorting?

Example:

const Number = struct {
 decimal: DecimalComp,
 fraction: FracComp,
};

const sortFn = struct {
 pub fn sort(num_a: Number, num_b: Number) bool {
    if (num_a.decimal == num_b.decimal) {
      return num_a.fraction < num_b.fraction;
    }

    return num_a.decimal < num_b.decimal;
 }
}.sort;



const World = World.WithComponents(.{DecimalComp, FracComp}).WithStorageSorting(.{
 StorageSort(Number, sortFn),
}).Build();

Then it can be specified that systems are guaranteed to be dispatched/iterated in order within the same archetype.
I guess that would make it a lot more limiting in how useful it will be 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal A *potential* improvement
Projects
None yet
Development

No branches or pull requests

1 participant