删除组件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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yohamta/donburi"
|
||||
)
|
||||
|
||||
|
@ -20,32 +18,6 @@ func (c *ComponentType[T]) Set(entry *Entry, component *T) {
|
|||
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.
|
||||
func (c *ComponentType[T]) SetValue(entry *Entry, value T) {
|
||||
c.ComponentType.SetValue(entry.Entry, value)
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
)
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
// w := ecs.NewWorld(20)
|
||||
|
@ -43,10 +39,14 @@ func main() {
|
|||
// }
|
||||
// time.Sleep(5 * time.Second)
|
||||
|
||||
f := 2.1
|
||||
i := math.Floor(f)
|
||||
d := f - i
|
||||
fmt.Println(f, i, d)
|
||||
f1, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", d), 64)
|
||||
fmt.Println(f1)
|
||||
// f := 2.1
|
||||
// i := math.Floor(f)
|
||||
// d := f - i
|
||||
// fmt.Println(f, i, d)
|
||||
// f1, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", d), 64)
|
||||
// fmt.Println(f1)
|
||||
|
||||
var a []int
|
||||
len := len(a)
|
||||
fmt.Println(len)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue