ecs接口变化,实体创建接口相应调整

This commit is contained in:
walker 2023-10-09 14:24:53 +08:00
parent 6592c42a0c
commit 1dc64115db
6 changed files with 12 additions and 7 deletions

View File

@ -9,7 +9,7 @@ import (
func NewDBQEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry {
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.DBQTag, component.UidType, component.DBQStateType, component.CounterType)
entry = w.Entry(w.Create(component.DBQTag, component.UidType, component.DBQStateType, component.CounterType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
entityMap[uid] = entry
}

View File

@ -15,7 +15,7 @@ func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]*
model := proto.Relay_Model_name[int32(relay.Model())]
entry, ok := entityMap[uid]
if !ok {
entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType)
entry = w.Entry(w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
if strings.Contains(model, "Y") { // 有极继电器
entry.AddComponent(component.YjRelayTag)

View File

@ -2,6 +2,7 @@ package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
@ -65,7 +66,7 @@ func LoadSignals(w ecs.World) error {
func newSignalEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
entry, ok := worldData.EntityMap[uid]
if !ok {
entry = w.Create(component.UidType)
entry = w.Entry(w.Create(component.UidType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
worldData.EntityMap[uid] = entry
}

View File

@ -14,7 +14,7 @@ func LoadWorldData(w ecs.World, repo *repository.Repository) {
if repo == nil {
panic("repo不能为nil")
}
entry := w.Create(component.WorldDataType)
entry := w.Entry(w.Create(component.WorldDataType))
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,
Time: time.Now().UnixMilli(),

View File

@ -41,7 +41,7 @@ func LoadTurnoutZdj9One(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent
// 加载道岔ZDJ9双机转辙机
func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry, entityMap map[string]*ecs.Entry) error {
// 加载转辙机
entrys := w.CreateMany(2, component.ZzjStateType, component.TwoPositionTransformType)
entrys := ecs.Entries(w, w.CreateMany(2, component.ZzjStateType, component.TwoPositionTransformType))
// 给道岔添加转辙机引用组件
entry.AddComponent(component.TurnoutZzjType, unsafe.Pointer(&component.TurnoutZzj{
ZzjList: entrys,
@ -144,7 +144,7 @@ func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent
func NewTurnoutEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
entry, ok := worldData.EntityMap[uid]
if !ok {
entry = w.Create(component.TurnoutTag, component.UidType, component.TurnoutPositionType)
entry = w.Entry(w.Create(component.TurnoutTag, component.UidType, component.TurnoutPositionType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
worldData.EntityMap[uid] = entry
}

View File

@ -1,10 +1,14 @@
package main
import (
"fmt"
rtss_simulation "joylink.club/rtsssimulation"
"joylink.club/rtsssimulation/repository"
)
func main() {
rtss_simulation.NewSimulation(&repository.Repository{})
sim := rtss_simulation.NewSimulation(&repository.Repository{})
fmt.Println(sim.Id())
sim.StartUp()
}