删除组件Each、First等方法(使用时查不到东西,固需要查询的地方调用ecs.NewQuery自己构建查询对象)

This commit is contained in:
walker 2023-09-28 15:37:20 +08:00
parent 200352eb58
commit 7ce0d9aa7b
3 changed files with 12 additions and 40 deletions

View File

@ -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)

View File

@ -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)
} }

View File

@ -45,7 +45,7 @@ type (
Resume() Resume()
SetSpeed(speed float64) error SetSpeed(speed float64) error
AddSystem(sys ...ISystem) AddSystem(sys ...ISystem)
// 在世界线程执行 // 在世界中执行逻辑(在世界运行线程中)
Execute(fn ExecuteFunc) Execute(fn ExecuteFunc)
Close() Close()
// 世界时间间隔 // 世界时间间隔