删除组件Each、First等方法(使用时查不到东西,固需要查询的地方调用ecs.NewQuery自己构建查询对象)
This commit is contained in:
parent
200352eb58
commit
7ce0d9aa7b
28
component.go
28
component.go
@ -1,8 +1,6 @@
|
|||||||
package ecs
|
package ecs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/yohamta/donburi"
|
"github.com/yohamta/donburi"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,32 +18,6 @@ func (c *ComponentType[T]) Set(entry *Entry, component *T) {
|
|||||||
c.ComponentType.Set(entry.Entry, component)
|
c.ComponentType.Set(entry.Entry, component)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each iterates over the entities that have the component.
|
|
||||||
// 使用Each方法时必须在World线程中执行,即调用World.Execute执行
|
|
||||||
func (c *ComponentType[T]) Each(w World, callback func(*Entry)) {
|
|
||||||
c.ComponentType.Each(w.(*world).world, func(entry *donburi.Entry) {
|
|
||||||
callback(&Entry{Entry: entry})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// First returns the first entity that has the component.
|
|
||||||
// 使用First方法时必须在World线程中执行,即调用World.Execute执行
|
|
||||||
func (c *ComponentType[T]) First(w World) (*Entry, bool) {
|
|
||||||
entry, ok := c.ComponentType.First(w.(*world).world)
|
|
||||||
return &Entry{entry}, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// MustFirst returns the first entity that has the component or panics.
|
|
||||||
// 使用MustFirst方法时必须在World线程中执行,即调用World.Execute执行
|
|
||||||
func (c *ComponentType[T]) MustFirst(w World) *Entry {
|
|
||||||
e, ok := c.First(w)
|
|
||||||
if !ok {
|
|
||||||
panic(fmt.Sprintf("no entity has the component %s", c.ComponentType.Name()))
|
|
||||||
}
|
|
||||||
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetValue sets the value of the component.
|
// SetValue sets the value of the component.
|
||||||
func (c *ComponentType[T]) SetValue(entry *Entry, value T) {
|
func (c *ComponentType[T]) SetValue(entry *Entry, value T) {
|
||||||
c.ComponentType.SetValue(entry.Entry, value)
|
c.ComponentType.SetValue(entry.Entry, value)
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// w := ecs.NewWorld(20)
|
// w := ecs.NewWorld(20)
|
||||||
@ -43,10 +39,14 @@ func main() {
|
|||||||
// }
|
// }
|
||||||
// time.Sleep(5 * time.Second)
|
// time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
f := 2.1
|
// f := 2.1
|
||||||
i := math.Floor(f)
|
// i := math.Floor(f)
|
||||||
d := f - i
|
// d := f - i
|
||||||
fmt.Println(f, i, d)
|
// fmt.Println(f, i, d)
|
||||||
f1, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", d), 64)
|
// f1, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", d), 64)
|
||||||
fmt.Println(f1)
|
// fmt.Println(f1)
|
||||||
|
|
||||||
|
var a []int
|
||||||
|
len := len(a)
|
||||||
|
fmt.Println(len)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user