From 7ce0d9aa7bf6cbbf045ef3aa57ec14d43a742906 Mon Sep 17 00:00:00 2001 From: walker Date: Thu, 28 Sep 2023 15:37:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BB=84=E4=BB=B6Each?= =?UTF-8?q?=E3=80=81First=E7=AD=89=E6=96=B9=E6=B3=95=EF=BC=88=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E6=9F=A5=E4=B8=8D=E5=88=B0=E4=B8=9C=E8=A5=BF?= =?UTF-8?q?=EF=BC=8C=E5=9B=BA=E9=9C=80=E8=A6=81=E6=9F=A5=E8=AF=A2=E7=9A=84?= =?UTF-8?q?=E5=9C=B0=E6=96=B9=E8=B0=83=E7=94=A8ecs.NewQuery=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E6=9E=84=E5=BB=BA=E6=9F=A5=E8=AF=A2=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component.go | 28 ---------------------------- examples/rtss/main.go | 22 +++++++++++----------- world.go | 2 +- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/component.go b/component.go index 677efde..db27699 100644 --- a/component.go +++ b/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) diff --git a/examples/rtss/main.go b/examples/rtss/main.go index 0c20e5e..9fde78d 100644 --- a/examples/rtss/main.go +++ b/examples/rtss/main.go @@ -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) } diff --git a/world.go b/world.go index 9442efa..f0bc4ff 100644 --- a/world.go +++ b/world.go @@ -45,7 +45,7 @@ type ( Resume() SetSpeed(speed float64) error AddSystem(sys ...ISystem) - // 在世界线程执行 + // 在世界中执行逻辑(在世界运行线程中) Execute(fn ExecuteFunc) Close() // 世界时间间隔