From ad86410c992ef179f9ec60566c43e02c47c1e01b Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 15 Dec 2023 16:42:45 +0800 Subject: [PATCH] =?UTF-8?q?ISCS=20AFC=E7=B3=BB=E7=BB=9Fecs=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/iscs_afc.go | 52 ++++++++++++++++++++++++++++++++ entity/iscs_afc.go | 70 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 component/iscs_afc.go create mode 100644 entity/iscs_afc.go diff --git a/component/iscs_afc.go b/component/iscs_afc.go new file mode 100644 index 0000000..06a5833 --- /dev/null +++ b/component/iscs_afc.go @@ -0,0 +1,52 @@ +package component + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/consts" +) + +// AfcGate AFC闸机 +type AfcGate struct { + State AgsState //闸机状态 + Exception consts.DeviceExceptionEnum //具体异常-故障、异常、通信中断 +} + +// AgsState AFC闸机状态定义 +type AgsState = uint8 + +const ( + AgsNormal AgsState = iota //正常 + AgsOutService //闸机未开放 +) + +////////////////////////////////////////// + +// TicketMachine 票机(自动售票机、半自动售票机、验票机) +type TicketMachine struct { + State TmState //票机状态 + Exception consts.DeviceExceptionEnum //具体异常-故障、通信中断 +} + +// TmState 票机状态定义 +type TmState = uint8 + +const ( + TmNormal TmState = iota //正常 + TmOutService //暂停服务 +) + +////////////////////////////////////////////////////// + +var ( + AfcGateType = ecs.NewComponentType[AfcGate]() + + EntranceGateTag = ecs.NewTag() //进闸机 + ExitGateTag = ecs.NewTag() //出闸机 + TwoWayGateTag = ecs.NewTag() //双向闸机 + + TicketMachineType = ecs.NewComponentType[TicketMachine]() + + TicketVendingMachineTag = ecs.NewTag() //自动售票机 + SemiAutoTicketMachineTag = ecs.NewTag() //半自动售票机 + TicketCheckingMachineTag = ecs.NewTag() //验票机 +) diff --git a/entity/iscs_afc.go b/entity/iscs_afc.go new file mode 100644 index 0000000..c04b17b --- /dev/null +++ b/entity/iscs_afc.go @@ -0,0 +1,70 @@ +package entity + +import ( + "joylink.club/ecs" + "joylink.club/rtsssimulation/component" +) + +func newAfcGateEntity(w ecs.World, id string) *ecs.Entry { + wd := GetWorldData(w) + e, ok := wd.EntityMap[id] + if !ok { + e := w.Entry(w.Create(component.UidType, component.AfcGateType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} + +// NewEntranceGateEntity 创建进闸机实体 +func NewEntranceGateEntity(w ecs.World, id string) *ecs.Entry { + entry := newAfcGateEntity(w, id) + entry.AddComponent(component.EntranceGateTag) + return entry +} + +// NewExitGateEntity 创建出闸机实体 +func NewExitGateEntity(w ecs.World, id string) *ecs.Entry { + entry := newAfcGateEntity(w, id) + entry.AddComponent(component.ExitGateTag) + return entry +} + +// NewTwoWayGateEntity 创建双向闸机实体 +func NewTwoWayGateEntity(w ecs.World, id string) *ecs.Entry { + entry := newAfcGateEntity(w, id) + entry.AddComponent(component.TwoWayGateTag) + return entry +} + +func newTicketMachineEntity(w ecs.World, id string) *ecs.Entry { + wd := GetWorldData(w) + e, ok := wd.EntityMap[id] + if !ok { + e := w.Entry(w.Create(component.UidType, component.TicketMachineType)) + component.UidType.SetValue(e, component.Uid{Id: id}) + wd.EntityMap[id] = e + } + return e +} + +// NewTicketVendingMachineEntity 创建自动售票机实体 +func NewTicketVendingMachineEntity(w ecs.World, id string) *ecs.Entry { + entry := newTicketMachineEntity(w, id) + entry.AddComponent(component.TicketVendingMachineTag) + return entry +} + +// NewSemiAutoTicketMachineEntity 创建半自动售票机实体 +func NewSemiAutoTicketMachineEntity(w ecs.World, id string) *ecs.Entry { + entry := newTicketMachineEntity(w, id) + entry.AddComponent(component.SemiAutoTicketMachineTag) + return entry +} + +// NewTicketCheckingMachineEntity 创建验票机实体 +func NewTicketCheckingMachineEntity(w ecs.World, id string) *ecs.Entry { + entry := newTicketMachineEntity(w, id) + entry.AddComponent(component.TicketCheckingMachineTag) + return entry +}