-
Why does package main
import (
"fmt"
"github.com/yohamta/donburi"
)
func main() {
w := donburi.NewWorld()
health := donburi.NewComponentType[float64]()
e := w.Entry(w.Create(health))
health.SetValue(e, 5.0)
fmt.Printf("%T\n", health.Get(e))
// *float64
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hello, it's because donburi stores component data as pointer. I think we can add |
Beta Was this translation helpful? Give feedback.
-
I changed my mind. I don't think it will affect speed for a few thousand Entities. In terms of syntax, it would be nice to have
A helper function can be added for the singleton component. For example, when package main
import (
"fmt"
"github.com/yohamta/donburi"
)
func main() {
a := "A"
w := donburi.NewWorld()
Str := donburi.NewComponentType[string]()
e1 := w.Entry(w.Create(Str))
e2 := w.Entry(w.Create(Str))
Str.Set(e1, &a)
Str.Set(e2, &a)
Str.SetValue(e1, "B")
fmt.Println(*Str.Get(e1))
fmt.Println(*Str.Get(e2))
// B
// B
}
Pseudo code in my mind Str := donburi.NewSingletonComponentType[string]("A")
e1 := world.Entry(world.Create(Str))
e2 := world.Entry(world.Create(Str))
Str.SetValue(e1, "B")
fmt.Println(*Str.Get(e1))
fmt.Println(*Str.Get(e2))
// B
// B |
Beta Was this translation helpful? Give feedback.
Hello, it's because donburi stores component data as pointer. I think we can add
GetValue()
method to get value instead of pointer. What do you think?