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

Implement Go 1.23 iterators for queries and components #142

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.x
go-version: 1.23.x

- name: Check out code
uses: actions/checkout@v3
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ It aims to be a feature rich and high-performance [ECS](https://en.wikipedia.org
- [Getting Started](#getting-started)
- [Worlds](#worlds)
- [Queries](#queries)
- [Ordered Queries](#ordered-queries)
- [Tags](#tags)
- [Systems (Experimental)](#systems-experimental)
- [Debug](#debug)
Expand Down Expand Up @@ -127,7 +128,7 @@ if SomeLogic.IsDead(world, someEntity) {
}
```

Entities can be retrieved using the `First` and `Each` methods of Components as follows:
Entities can be retrieved using the `First` and `Iter` methods of Components as follows:

```go
// GameState Component
Expand All @@ -154,10 +155,10 @@ if entry, ok := GameState.First(world); ok {
}

// Query all Bullet entities
Bullet.Each(world, func(entry *donburi.Entry) {
for entry := range Bullet.Iter(world) {
bullet := Bullet.Get(entry)
// .. do stuff with the bullet entity
})
}
```

### Queries
Expand All @@ -169,14 +170,14 @@ Queries allow for high performance and expressive iteration through the entities
query := donburi.NewQuery(filter.Contains(Position, Velocity))

// Iterate through the entities found in the world
query.Each(world, func(entry *donburi.Entry) {
for entry := range query.Iter(world) {
// An entry is an accessor to entity and its components.
position := Position.Get(entry)
velocity := Velocity.Get(entry)

position.X += velocity.X
position.Y += velocity.Y
})
}
```

There are other types of filters such as `And`, `Or`, `Exact` and `Not`. Filters can be combined wth to find the target entities.
Expand Down Expand Up @@ -208,12 +209,11 @@ query := donburi.NewQuery(
)

// In our query we can check if the entity has some of the optional components before attempting to retrieve them
query.Each(world, func(entry *donburi.Entry) {
for entry := range query.Iter(world) {
// We'll always be able to access Position and Size
position := Position.Get(entry)
size := Size.Get(entry)


if entry.HasComponent(Sprite) {
sprite := Sprite.Get(entry)
// .. do sprite things
Expand All @@ -228,8 +228,7 @@ query.Each(world, func(entry *donburi.Entry) {
shape := Shape.Get(entry)
// .. do shape things
}

})
}
```

## Ordered Queries
Expand All @@ -247,9 +246,9 @@ Here we assume the `spatial.TransformComponent` implements `Order()`.
q := donburi.NewOrderedQuery[spatial.Transform](
filter.Contains(sprite.Component, spatial.TransformComponent))

q.EachOrdered(w, spatial.TransformComponent, func(entry *donburi.Entry) {
// This will be iterated according to the spatial.TransformComponent's Order() function.
})
for entry := range q.IterOrdered(w) {
// This will be iterated according to the spatial.TransformComponent's Order() function.
}
```

### Tags
Expand All @@ -271,7 +270,7 @@ var EnemyTag = donburi.NewTag("Enemy")
world.CreateMany(100, EnemyTag, Position, Velocity)

// Search entities with EnemyTag
EnemyTag.Each(world, func(entry *donburi.Entry) {
for entry := range EnemyTag.Iter(world) {
// Perform some operation on the Entities with the EnemyTag component.
}
```
Expand Down
6 changes: 6 additions & 0 deletions component.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package donburi

import (
"fmt"
"iter"
"reflect"
"unsafe"

Expand Down Expand Up @@ -59,6 +60,11 @@ func (c *ComponentType[T]) Each(w World, callback func(*Entry)) {
c.query.Each(w, callback)
}

// Iter returns an iterator for the entities that have the component.
func (c *ComponentType[T]) Iter(w World) iter.Seq[*Entry] {
return c.query.Iter(w)
}

// deprecated: use Each instead
func (c *ComponentType[T]) EachEntity(w World, callback func(*Entry)) {
c.Each(w, callback)
Expand Down
5 changes: 3 additions & 2 deletions examples/bunnymark/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/yohamta/donburi/examples/bunnymark

go 1.21
go 1.23

toolchain go1.23.0

replace github.com/yohamta/donburi => ../../

Expand All @@ -15,7 +17,6 @@ require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/ebitengine/purego v0.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/jezek/xgb v1.1.0 // indirect
Expand Down
25 changes: 5 additions & 20 deletions examples/bunnymark/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/ebitengine/purego v0.3.0 h1:BDv9pD98k6AuGNQf3IF41dDppGBOe0F4AofvhFtBXF4=
github.com/ebitengine/purego v0.3.0/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
github.com/ebitengine/purego v0.6.0 h1:Yo9uBc1x+ETQbfEaf6wcBsjrQfCEnh/gaGUg7lguEJY=
github.com/ebitengine/purego v0.6.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/hajimehoshi/bitmapfont/v2 v2.2.3 h1:jmq/TMNj352V062Tr5e3hAoipkoxCbY1JWTzor0zNps=
github.com/hajimehoshi/ebiten/v2 v2.5.3 h1:jizHI6ig5YnNP+wyERJvhDabz4lkhJn06bhIgHWJwUo=
github.com/hajimehoshi/ebiten/v2 v2.5.3/go.mod h1:mnHSOVysTr/nUZrN1lBTRqhK4NG+T9NR3JsJP2rCppk=
github.com/hajimehoshi/bitmapfont/v3 v3.0.0 h1:r2+6gYK38nfztS/et50gHAswb9hXgxXECYgE8Nczmi4=
github.com/hajimehoshi/bitmapfont/v3 v3.0.0/go.mod h1:+CxxG+uMmgU4mI2poq944i3uZ6UYFfAkj9V6WqmuvZA=
github.com/hajimehoshi/ebiten/v2 v2.6.6 h1:E5X87Or4VwKZIKjeC9+Vr4ComhZAz9h839myF4Q21kc=
github.com/hajimehoshi/ebiten/v2 v2.6.6/go.mod h1:gKgQI26zfoSb6j5QbrEz2L6nuHMbAYwrsXa5qsGrQKo=
github.com/jaypipes/ghw v0.10.0 h1:UHu9UX08Py315iPojADFPOkmjTsNzHj4g4adsNKKteY=
Expand All @@ -27,28 +21,23 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS
github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk=
github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/image v0.12.0 h1:w13vZbU4o5rKOFFR8y7M+c4A5jXDC0uXTdHYRP8X2DQ=
golang.org/x/image v0.12.0/go.mod h1:Lu90jvHG7GfemOIcldsh9A2hS01ocl6oNO7ype5mEnk=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c h1:Gk61ECugwEHL6IiyyNLXNzmu8XslmRP2dS0xjIYhbb4=
golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY=
golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57 h1:Q6NT8ckDYNcwmi/bmxe+XbiDMXqMRW1xFBtJ+bIpie4=
golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57/go.mod h1:wEyOn6VvNW7tcf+bW/wBz1sehi2s2BZ4TimyR7qZen4=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
Expand All @@ -62,7 +51,6 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
Expand All @@ -74,8 +62,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -85,8 +71,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand All @@ -96,9 +81,9 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
4 changes: 2 additions & 2 deletions examples/bunnymark/system/bounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewBounce(bounds *image.Rectangle) *Bounce {
}

func (b *Bounce) Update(w donburi.World) {
b.query.Each(w, func(entry *donburi.Entry) {
for entry := range b.query.Iter(w) {
position := component.Position.Get(entry)
velocity := component.Velocity.Get(entry)
sprite := component.Sprite.Get(entry)
Expand All @@ -52,5 +52,5 @@ func (b *Bounce) Update(w donburi.World) {
velocity.Y = 0
position.Y = 0
}
})
}
}
4 changes: 2 additions & 2 deletions examples/bunnymark/system/gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func NewGravity() *Gravity {
}

func (g *Gravity) Update(w donburi.World) {
g.query.Each(w, func(entry *donburi.Entry) {
for entry := range g.query.Iter(w) {
gravity := component.Gravity.Get(entry)
velocity := component.Velocity.Get(entry)

velocity.Y += gravity.Value
})
}
}
4 changes: 2 additions & 2 deletions examples/bunnymark/system/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewRender() *Render {
}

func (r *Render) Draw(w donburi.World, screen *ebiten.Image) {
r.query.Each(w, func(entry *donburi.Entry) {
for entry := range r.query.Iter(w) {
position := component.Position.Get(entry)
hue := component.Hue.Get(entry)
sprite := component.Sprite.Get(entry)
Expand All @@ -34,5 +34,5 @@ func (r *Render) Draw(w donburi.World, screen *ebiten.Image) {
op.ColorM.RotateHue(hue.Value)
}
screen.DrawImage(sprite.Image, op)
})
}
}
5 changes: 3 additions & 2 deletions examples/bunnymark/system/velocity.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ func NewVelocity() *Velocity {
}

func (v *Velocity) Update(w donburi.World) {
v.query.Each(w, func(entry *donburi.Entry) {
for entry := range v.query.Iter(w) {

position := component.Position.Get(entry)
velocity := component.Velocity.Get(entry)

position.X += velocity.X
position.Y += velocity.Y
})
}
}
4 changes: 3 additions & 1 deletion examples/bunnymark_ecs/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/yohamta/donburi/examples/bunnymark_ecs

go 1.21
go 1.23

toolchain go1.23.0

replace github.com/yohamta/donburi => ../../

Expand Down
4 changes: 2 additions & 2 deletions examples/bunnymark_ecs/system/bounce.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewBounce(bounds *image.Rectangle) *bounce {
}

func (b *bounce) Update(ecs *ecs.ECS) {
b.query.Each(ecs.World, func(entry *donburi.Entry) {
for entry := range b.query.Iter(ecs.World) {
position := component.Position.Get(entry)
velocity := component.Velocity.Get(entry)
sprite := component.Sprite.Get(entry)
Expand All @@ -55,5 +55,5 @@ func (b *bounce) Update(ecs *ecs.ECS) {
velocity.Y = 0
position.Y = 0
}
})
}
}
4 changes: 2 additions & 2 deletions examples/bunnymark_ecs/system/gravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ var Gravity *gravity = &gravity{
}

func (g *gravity) Update(ecs *ecs.ECS) {
g.query.Each(ecs.World, func(entry *donburi.Entry) {
for entry := range g.query.Iter(ecs.World) {
gravity := component.Gravity.Get(entry)
velocity := component.Velocity.Get(entry)

velocity.Y += gravity.Value
})
}
}
8 changes: 4 additions & 4 deletions examples/bunnymark_ecs/system/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Render = &render{

func (r *render) Draw(ecs *ecs.ECS, screen *ebiten.Image) {
if !UsePositionOrdering {
r.query.Each(ecs.World, func(entry *donburi.Entry) {
for entry := range r.query.Iter(ecs.World) {
position := component.Position.Get(entry)
hue := component.Hue.Get(entry)
sprite := component.Sprite.Get(entry)
Expand All @@ -43,9 +43,9 @@ func (r *render) Draw(ecs *ecs.ECS, screen *ebiten.Image) {
op.ColorM.RotateHue(hue.Value)
}
screen.DrawImage(sprite.Image, op)
})
}
} else {
r.orderedQuery.EachOrdered(ecs.World, component.Position, func(entry *donburi.Entry) {
for entry := range r.orderedQuery.IterOrdered(ecs.World, component.Position) {
position := component.Position.Get(entry)
hue := component.Hue.Get(entry)
sprite := component.Sprite.Get(entry)
Expand All @@ -57,6 +57,6 @@ func (r *render) Draw(ecs *ecs.ECS, screen *ebiten.Image) {
op.ColorM.RotateHue(hue.Value)
}
screen.DrawImage(sprite.Image, op)
})
}
}
}
4 changes: 2 additions & 2 deletions examples/bunnymark_ecs/system/velocity.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ var Velocity = &velocity{
}

func (v *velocity) Update(ecs *ecs.ECS) {
v.query.Each(ecs.World, func(entry *donburi.Entry) {
for entry := range v.query.Iter(ecs.World) {
position := component.Position.Get(entry)
velocity := component.Velocity.Get(entry)

position.X += velocity.X
position.Y += velocity.Y
})
}
}
4 changes: 3 additions & 1 deletion examples/platformer/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/yohamta/donburi/examples/platformer

go 1.21
go 1.23

toolchain go1.23.0

require (
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
Expand Down
Loading
Loading