计轴rssp 集成
This commit is contained in:
parent
f007453f53
commit
8ba6576eaf
@ -1 +1,13 @@
|
|||||||
package component
|
package component
|
||||||
|
|
||||||
|
import "joylink.club/ecs"
|
||||||
|
|
||||||
|
// TrainPositionInfo 列车当前位置信息
|
||||||
|
type TrainPositionInfo struct {
|
||||||
|
//列车所占的物理区段
|
||||||
|
SectionIds []string
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
TrainPositionInfoType = ecs.NewComponentType[TrainPositionInfo]()
|
||||||
|
)
|
||||||
|
15
entity/train.go
Normal file
15
entity/train.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewTrainEntity(w ecs.World, trainId string) *ecs.Entry {
|
||||||
|
data := GetWorldData(w)
|
||||||
|
te := w.Entry(w.Create(component.UidType, component.TrainPositionInfoType))
|
||||||
|
component.UidType.SetValue(te, component.Uid{Id: trainId})
|
||||||
|
component.TrainPositionInfoType.Set(te, &component.TrainPositionInfo{})
|
||||||
|
data.EntityMap[trainId] = te
|
||||||
|
return te
|
||||||
|
}
|
51
fi/train.go
Normal file
51
fi/train.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package fi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"joylink.club/ecs"
|
||||||
|
"joylink.club/rtsssimulation/component"
|
||||||
|
"joylink.club/rtsssimulation/entity"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddTrainToWorld 添加列车
|
||||||
|
func AddTrainToWorld(w ecs.World, trainId string) error {
|
||||||
|
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||||||
|
wd := entity.GetWorldData(w)
|
||||||
|
_, find := wd.EntityMap[trainId]
|
||||||
|
if !find {
|
||||||
|
entity.NewTrainEntity(w, trainId)
|
||||||
|
}
|
||||||
|
return ecs.NewOkEmptyResult()
|
||||||
|
})
|
||||||
|
return result.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveTrainFromWorld 移除列车
|
||||||
|
func RemoveTrainFromWorld(w ecs.World, trainId string) error {
|
||||||
|
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||||||
|
wd := entity.GetWorldData(w)
|
||||||
|
te, find := wd.EntityMap[trainId]
|
||||||
|
if find {
|
||||||
|
te.Remove()
|
||||||
|
delete(wd.EntityMap, trainId)
|
||||||
|
}
|
||||||
|
return ecs.NewOkEmptyResult()
|
||||||
|
})
|
||||||
|
return result.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTrainFromDynamics 更新列车所在的物理区段
|
||||||
|
func UpdateTrainFromDynamics(w ecs.World, trainId string, sectionIds []string) error {
|
||||||
|
result := <-ecs.Request[ecs.EmptyType](w, func() ecs.Result[ecs.EmptyType] {
|
||||||
|
wd := entity.GetWorldData(w)
|
||||||
|
te, find := wd.EntityMap[trainId]
|
||||||
|
if find {
|
||||||
|
tp := component.TrainPositionInfoType.Get(te)
|
||||||
|
tp.SectionIds = sectionIds
|
||||||
|
return ecs.NewOkEmptyResult()
|
||||||
|
} else {
|
||||||
|
return ecs.NewErrResult(fmt.Errorf("列车[%s]实体不存在", trainId))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result.Err
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user