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

Query Orderable Issue #144

Closed
edwinsyarief opened this issue Aug 29, 2024 · 5 comments
Closed

Query Orderable Issue #144

edwinsyarief opened this issue Aug 29, 2024 · 5 comments

Comments

@edwinsyarief
Copy link

I have this component:

type OrderableData struct {
	Index int
}

func (o OrderableData) Order() int {
	return o.Index
}

var Orderable = donburi.NewComponentType[OrderableData]()

and then I called all entries as follows:

orderedEntitiesQuery := donburi.NewOrderedQuery[components.OrderableData](
		filter.Contains(
			components.Orderable,
			components.Bounds,
			...)
orderedEntities := orderedEntitiesQuery.IterOrdered(ecs.World, components.Orderable)

println("start ---")
	for entry := range orderedEntities {
		order := components.Orderable.Get(entry)
		println(order.Index)
		DrawAnimationEntry(entry, viewportEntry, gameplayBuffer)
	}
	println("end ---")

I got these results:

image

You can see that the value is not correctly ordered. Does my implementation is wrong?

@yohamta
Copy link
Owner

yohamta commented Aug 29, 2024

Hi @edwinsyarief, thank you very much for reporting the detailed issue. This is really helpful. The issue is fixed in v1.15.2 now. Could you please check it and let me know if there're still any issues.

@edwinsyarief
Copy link
Author

edwinsyarief commented Aug 29, 2024

Hi @yohamta , thank you very much for the fast response. The result are now better, but some of them still not consistent, I only changed one object's index, some of them in the world is changing when not moving. Here is the showcase:
https://imgur.com/a/EqhJBpA

But the result is consistent when I am using the manual way like this:

        query := donburi.NewQuery(filter.Contains(components.RenderableEntity))
	sorted := []*donburi.Entry{}
	for entry := range query.Iter(ecs.World) {
		sorted = append(sorted, entry)
	}

	slices.SortStableFunc(sorted, func(a, b *donburi.Entry) int {
		orderA := components.Orderable.Get(a)
		orderB := components.Orderable.Get(b)
		return cmp.Compare(orderA.Index, orderB.Index)
	})

Here is the showcase when using slices.SortStableFunc:
https://imgur.com/a/PKm3p9J

@yohamta
Copy link
Owner

yohamta commented Aug 29, 2024

Oh thank you very much. Yes, I agree that I should have used the stable sort. Let me update again.

@yohamta
Copy link
Owner

yohamta commented Aug 29, 2024

Hi @edwinsyarief, it should be fixed now in v1.15.3.

@edwinsyarief
Copy link
Author

Yes, it is fixed.

Thank you very much

@yohamta yohamta closed this as completed Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants