删除通用组件,调整example代码

This commit is contained in:
walker 2023-08-14 14:48:37 +08:00
parent a6dc0c0023
commit 3c3dd9f408
4 changed files with 14 additions and 14 deletions

View File

@ -1,9 +0,0 @@
package ecs
type Id string
var IdComp = NewComponentType[Id]()
// func IdComp() *ComponentType[Id] {
// return NewComponentType[Id]()
// }

View File

@ -0,0 +1,7 @@
package component
import "joylink.club/ecs"
type Id string
var IdComp = ecs.NewComponentType[Id]()

View File

@ -5,6 +5,7 @@ import (
"time"
"joylink.club/ecs"
"joylink.club/ecs/examples/rtss/component"
system "joylink.club/ecs/examples/rtss/sys"
)
@ -15,10 +16,10 @@ func main() {
w := ecs.NewWorld(20)
turnoutSys := system.NewTurnoutSys()
w.AddSystem(turnoutSys)
idcomp := ecs.IdComp
idcomp := component.IdComp
entities := w.CreateMany(10, idcomp, system.TurnoutStateComp)
for i, entry := range entities {
idcomp.SetValue(entry, ecs.Id(fmt.Sprintf("%d", i)))
idcomp.SetValue(entry, component.Id(fmt.Sprintf("%d", i)))
var db bool
var fb bool
if i%2 == 0 {

View File

@ -5,6 +5,7 @@ import (
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/ecs/examples/rtss/component"
)
type TurnoutState struct {
@ -40,11 +41,11 @@ func (sys *TurnoutSys) Update(w ecs.World) {
// 道岔定操
func DingCao(w ecs.World, id string) {
query := ecs.NewQuery(filter.Contains(ecs.IdComp, TurnoutStateComp))
query := ecs.NewQuery(filter.Contains(component.IdComp, TurnoutStateComp))
query.Each(w, func(entry *ecs.Entry) {
// log.Println("存在id组件")
idcomp := ecs.IdComp.Get(entry)
if *idcomp == ecs.Id(id) {
idcomp := component.IdComp.Get(entry)
if *idcomp == component.Id(id) {
ts := TurnoutStateComp.Get(entry)
ts.Dc = true
log.Println("id=", w.Id(), "的仿真", "道岔定操: id=", id)