ISCS AFC系统ecs定义

This commit is contained in:
xzb 2023-12-15 16:42:45 +08:00
parent a7dba63f4e
commit ad86410c99
2 changed files with 122 additions and 0 deletions

52
component/iscs_afc.go Normal file
View File

@ -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() //验票机
)

70
entity/iscs_afc.go Normal file
View File

@ -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
}