该目录

This commit is contained in:
xzb 2023-08-16 17:17:20 +08:00
parent f82926827e
commit 2135a0728e
37 changed files with 392 additions and 42 deletions

View File

@ -28,3 +28,15 @@ var ComSignalState = ecs.NewComponentType[state.SignalState]()
// 信号机显示操作组件
var ComSignalDisplayOperating = ecs.NewComponentType[state.SignalDisplayOperating]()
// 单个屏蔽门状态组件
var ComPsdCellState = ecs.NewComponentType[state.PsdCellState]()
// 单个屏蔽门操作组件
var ComPsdCellOperating = ecs.NewComponentType[state.PsdCellOperating]()
// 站台单侧所有单个屏蔽门状态组件
var ComPsdState = ecs.NewComponentType[state.PsdState]()
// 标记
var ComPsdStateTag = ecs.NewComponentType[ecs.ComponentType[state.PsdState]]()

View File

@ -49,11 +49,11 @@ func main() {
func initDevicesStatus(world ecs.World) {
//当组件未显式set值时world会初始化组件的零值
switch1Entry := world.Create(components.ComDeviceIdentity, components.ComSwitchState)
switch1Entry := memory.CreateSwitchEntity(world)
components.ComDeviceIdentity.Set(switch1Entry, &state.DeviceIdentity{Id: "switch1"})
components.ComSwitchState.Set(switch1Entry, &state.SwitchState{NormalRelay: false, ReverseRelay: false, NormalTable: true, ReverseTable: false})
//
signal1Entry := world.Create(components.ComDeviceIdentity, components.ComSignalState)
signal1Entry := memory.CreateSignalEntity(world)
components.ComDeviceIdentity.Set(signal1Entry, &state.DeviceIdentity{Id: "siganl1"})
components.ComSignalState.Set(signal1Entry, &state.SignalState{Display: state.SignalAspect_No})
}

View File

@ -2,5 +2,5 @@ go 1.20
use (
./jl-ecs-go
./simulation
.
)

55
memory/init_world.go Normal file
View File

@ -0,0 +1,55 @@
package memory
import (
"time"
"github.com/yohamta/donburi/component"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/state"
"joylink.club/rtsssimulation/system"
)
// 实体标签
type EntityTag = component.IComponentType
// 初始化world添加一些内置的组件和系统
func InitializeWorld(w ecs.World, worldTime time.Time) *system.FaceSystem {
//初始化world时钟
timeEntry := w.Create(components.ComSystemTimer)
components.ComSystemTimer.Set(timeEntry, state.NewSystemTimer(&worldTime))
w.AddSystem(system.NewTimerSystem())
//初始化world与外界交互的门面
faceSystem := system.NewFaceSystem(w)
w.AddSystem(faceSystem)
//添加调试系统
w.AddSystem(system.NewDebugSystem())
//
return faceSystem
}
// 创建道岔实体
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComSwitchState)
}
// 创建信号机实体
func CreateSignalEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComSignalState)
}
// 创建物理区段实体
func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComPhysicalSectionState)
}
// 创建站台单侧屏蔽门实体
func CreatePsdEntity(w ecs.World) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComPsdState)
}
// 创建单个屏蔽门实体
// psdTag标记该cell是哪个站的哪侧屏蔽门
func CreatePsdCellEntity(w ecs.World, psdTag EntityTag) *ecs.Entry {
return w.Create(components.ComDeviceIdentity, components.ComPsdCellState, psdTag)
}

View File

@ -104,4 +104,36 @@ enum SignalAspect{
WF=14;
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//
message PsdCellState{
//,[0,100],0-100-
int32 closeRate = 1;
//,
bool locked = 2;
}
//
message PsdState{
//
bool allClosed = 1;
//
bool allOpened = 2;
//ATS不关注该侧屏蔽门的状态
bool interlockReleased = 3;
}
//
message PsdCellOperating{
//
bool start = 1;
//
//true-false-
bool closeOperate = 2;
//
int64 sumTime = 3;
//
int64 operateTime = 4;
}
////////////////////////////////////////////////////////

View File

@ -1,25 +0,0 @@
package memory
import (
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/state"
"joylink.club/rtsssimulation/system"
)
// 初始化world添加一些内置的组件和系统
func InitializeWorld(w ecs.World, worldTime time.Time) *system.FaceSystem {
//初始化world时钟
timeEntry := w.Create(components.ComSystemTimer)
components.ComSystemTimer.Set(timeEntry, state.NewSystemTimer(&worldTime))
w.AddSystem(system.NewTimerSystem())
//初始化world与外界交互的门面
faceSystem := system.NewFaceSystem(w)
w.AddSystem(faceSystem)
//添加调试系统
w.AddSystem(system.NewDebugSystem())
//
return faceSystem
}

View File

@ -558,6 +558,208 @@ func (x *SignalDisplayOperating) GetTargetAspect() SignalAspect {
return SignalAspect_No
}
// 单个屏蔽门状态
type PsdCellState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 门关百分比,值范围[0,100],0-全开100-全关
CloseRate int32 `protobuf:"varint,1,opt,name=closeRate,proto3" json:"closeRate,omitempty"`
// 是否锁闭,当门关上且锁闭才是安全的
Locked bool `protobuf:"varint,2,opt,name=locked,proto3" json:"locked,omitempty"`
}
func (x *PsdCellState) Reset() {
*x = PsdCellState{}
if protoimpl.UnsafeEnabled {
mi := &file_status_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PsdCellState) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PsdCellState) ProtoMessage() {}
func (x *PsdCellState) ProtoReflect() protoreflect.Message {
mi := &file_status_proto_msgTypes[7]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PsdCellState.ProtoReflect.Descriptor instead.
func (*PsdCellState) Descriptor() ([]byte, []int) {
return file_status_proto_rawDescGZIP(), []int{7}
}
func (x *PsdCellState) GetCloseRate() int32 {
if x != nil {
return x.CloseRate
}
return 0
}
func (x *PsdCellState) GetLocked() bool {
if x != nil {
return x.Locked
}
return false
}
// 站台一侧所有单个屏蔽门状态
type PsdState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 所有单个屏蔽门是否全关
AllClosed bool `protobuf:"varint,1,opt,name=allClosed,proto3" json:"allClosed,omitempty"`
// 所有单个屏蔽门是否全开
AllOpened bool `protobuf:"varint,2,opt,name=allOpened,proto3" json:"allOpened,omitempty"`
// 是否互锁解除当互锁解除时ATS不关注该侧屏蔽门的状态
InterlockReleased bool `protobuf:"varint,3,opt,name=interlockReleased,proto3" json:"interlockReleased,omitempty"`
}
func (x *PsdState) Reset() {
*x = PsdState{}
if protoimpl.UnsafeEnabled {
mi := &file_status_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PsdState) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PsdState) ProtoMessage() {}
func (x *PsdState) ProtoReflect() protoreflect.Message {
mi := &file_status_proto_msgTypes[8]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PsdState.ProtoReflect.Descriptor instead.
func (*PsdState) Descriptor() ([]byte, []int) {
return file_status_proto_rawDescGZIP(), []int{8}
}
func (x *PsdState) GetAllClosed() bool {
if x != nil {
return x.AllClosed
}
return false
}
func (x *PsdState) GetAllOpened() bool {
if x != nil {
return x.AllOpened
}
return false
}
func (x *PsdState) GetInterlockReleased() bool {
if x != nil {
return x.InterlockReleased
}
return false
}
// 单个屏蔽门操作
type PsdCellOperating struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// 是否启动操作
Start bool `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"`
// 是否关门动作
// true-关门动作false-开门动作
CloseOperate bool `protobuf:"varint,2,opt,name=closeOperate,proto3" json:"closeOperate,omitempty"`
// 本次操作共需要多长时间
SumTime int64 `protobuf:"varint,3,opt,name=sumTime,proto3" json:"sumTime,omitempty"`
// 动作剩余时间
OperateTime int64 `protobuf:"varint,4,opt,name=operateTime,proto3" json:"operateTime,omitempty"`
}
func (x *PsdCellOperating) Reset() {
*x = PsdCellOperating{}
if protoimpl.UnsafeEnabled {
mi := &file_status_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PsdCellOperating) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PsdCellOperating) ProtoMessage() {}
func (x *PsdCellOperating) ProtoReflect() protoreflect.Message {
mi := &file_status_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PsdCellOperating.ProtoReflect.Descriptor instead.
func (*PsdCellOperating) Descriptor() ([]byte, []int) {
return file_status_proto_rawDescGZIP(), []int{9}
}
func (x *PsdCellOperating) GetStart() bool {
if x != nil {
return x.Start
}
return false
}
func (x *PsdCellOperating) GetCloseOperate() bool {
if x != nil {
return x.CloseOperate
}
return false
}
func (x *PsdCellOperating) GetSumTime() int64 {
if x != nil {
return x.SumTime
}
return 0
}
func (x *PsdCellOperating) GetOperateTime() int64 {
if x != nil {
return x.OperateTime
}
return 0
}
var File_status_proto protoreflect.FileDescriptor
var file_status_proto_rawDesc = []byte{
@ -605,17 +807,37 @@ var file_status_proto_rawDesc = []byte{
0x65, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x37, 0x0a, 0x0c, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41,
0x73, 0x70, 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x73, 0x74,
0x61, 0x74, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x41, 0x73, 0x70, 0x65, 0x63, 0x74,
0x52, 0x0c, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41, 0x73, 0x70, 0x65, 0x63, 0x74, 0x2a, 0x81,
0x01, 0x0a, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x41, 0x73, 0x70, 0x65, 0x63, 0x74, 0x12,
0x06, 0x0a, 0x02, 0x4e, 0x6f, 0x10, 0x00, 0x12, 0x05, 0x0a, 0x01, 0x52, 0x10, 0x01, 0x12, 0x05,
0x0a, 0x01, 0x47, 0x10, 0x02, 0x12, 0x05, 0x0a, 0x01, 0x59, 0x10, 0x03, 0x12, 0x05, 0x0a, 0x01,
0x57, 0x10, 0x04, 0x12, 0x05, 0x0a, 0x01, 0x42, 0x10, 0x05, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x59,
0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x57, 0x10, 0x07, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x47,
0x10, 0x08, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x59, 0x10, 0x09, 0x12, 0x06, 0x0a, 0x02, 0x59, 0x59,
0x10, 0x0a, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x46, 0x10, 0x0b, 0x12, 0x06, 0x0a, 0x02, 0x59, 0x46,
0x10, 0x0c, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x46, 0x10, 0x0d, 0x12, 0x06, 0x0a, 0x02, 0x57, 0x46,
0x10, 0x0e, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
0x52, 0x0c, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x41, 0x73, 0x70, 0x65, 0x63, 0x74, 0x22, 0x44,
0x0a, 0x0c, 0x50, 0x73, 0x64, 0x43, 0x65, 0x6c, 0x6c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1c,
0x0a, 0x09, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x09, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x52, 0x61, 0x74, 0x65, 0x12, 0x16, 0x0a, 0x06,
0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6c, 0x6f,
0x63, 0x6b, 0x65, 0x64, 0x22, 0x74, 0x0a, 0x08, 0x50, 0x73, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65,
0x12, 0x1c, 0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x08, 0x52, 0x09, 0x61, 0x6c, 0x6c, 0x43, 0x6c, 0x6f, 0x73, 0x65, 0x64, 0x12, 0x1c,
0x0a, 0x09, 0x61, 0x6c, 0x6c, 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
0x08, 0x52, 0x09, 0x61, 0x6c, 0x6c, 0x4f, 0x70, 0x65, 0x6e, 0x65, 0x64, 0x12, 0x2c, 0x0a, 0x11,
0x69, 0x6e, 0x74, 0x65, 0x72, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65,
0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6c, 0x6f,
0x63, 0x6b, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x22, 0x88, 0x01, 0x0a, 0x10, 0x50,
0x73, 0x64, 0x43, 0x65, 0x6c, 0x6c, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x12,
0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05,
0x73, 0x74, 0x61, 0x72, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6c, 0x6f, 0x73, 0x65, 0x4f, 0x70,
0x65, 0x72, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x63, 0x6c, 0x6f,
0x73, 0x65, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d,
0x54, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x73, 0x75, 0x6d, 0x54,
0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x65, 0x54, 0x69,
0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
0x65, 0x54, 0x69, 0x6d, 0x65, 0x2a, 0x81, 0x01, 0x0a, 0x0c, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c,
0x41, 0x73, 0x70, 0x65, 0x63, 0x74, 0x12, 0x06, 0x0a, 0x02, 0x4e, 0x6f, 0x10, 0x00, 0x12, 0x05,
0x0a, 0x01, 0x52, 0x10, 0x01, 0x12, 0x05, 0x0a, 0x01, 0x47, 0x10, 0x02, 0x12, 0x05, 0x0a, 0x01,
0x59, 0x10, 0x03, 0x12, 0x05, 0x0a, 0x01, 0x57, 0x10, 0x04, 0x12, 0x05, 0x0a, 0x01, 0x42, 0x10,
0x05, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x59, 0x10, 0x06, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x57, 0x10,
0x07, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x47, 0x10, 0x08, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x59, 0x10,
0x09, 0x12, 0x06, 0x0a, 0x02, 0x59, 0x59, 0x10, 0x0a, 0x12, 0x06, 0x0a, 0x02, 0x52, 0x46, 0x10,
0x0b, 0x12, 0x06, 0x0a, 0x02, 0x59, 0x46, 0x10, 0x0c, 0x12, 0x06, 0x0a, 0x02, 0x47, 0x46, 0x10,
0x0d, 0x12, 0x06, 0x0a, 0x02, 0x57, 0x46, 0x10, 0x0e, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x73,
0x74, 0x61, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -631,7 +853,7 @@ func file_status_proto_rawDescGZIP() []byte {
}
var file_status_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_status_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_status_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_status_proto_goTypes = []interface{}{
(SignalAspect)(0), // 0: state.SignalAspect
(*DeviceIdentity)(nil), // 1: state.DeviceIdentity
@ -641,6 +863,9 @@ var file_status_proto_goTypes = []interface{}{
(*PhysicalSectionState)(nil), // 5: state.PhysicalSectionState
(*SignalState)(nil), // 6: state.SignalState
(*SignalDisplayOperating)(nil), // 7: state.SignalDisplayOperating
(*PsdCellState)(nil), // 8: state.PsdCellState
(*PsdState)(nil), // 9: state.PsdState
(*PsdCellOperating)(nil), // 10: state.PsdCellOperating
}
var file_status_proto_depIdxs = []int32{
0, // 0: state.SignalState.display:type_name -> state.SignalAspect
@ -742,6 +967,42 @@ func file_status_proto_init() {
return nil
}
}
file_status_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PsdCellState); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_status_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PsdState); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_status_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PsdCellOperating); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -749,7 +1010,7 @@ func file_status_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_status_proto_rawDesc,
NumEnums: 1,
NumMessages: 7,
NumMessages: 10,
NumExtensions: 0,
NumServices: 0,
},

15
system/psd_system.go Normal file
View File

@ -0,0 +1,15 @@
package system
import "joylink.club/ecs"
type PsdSystem struct {
}
func NewPsdSystem() *PsdSystem {
return &PsdSystem{}
}
// world 执行
func (me *PsdSystem) Update(world ecs.World) {
}