组件定义调整

道岔命名调整,道岔实体构建重构
This commit is contained in:
walker 2024-01-02 18:22:28 +08:00
parent 80585dbf7a
commit 7751d9d926
14 changed files with 154 additions and 59 deletions

View File

@ -2,19 +2,25 @@ package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component/component_data"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/consts"
)
var BitType = ecs.NewComponentType[bool]()
var (
UidType = ecs.NewComponentType[Uid]()
// 固定位置转换组件类型
FixedPositionTransformType = ecs.NewComponentType[FixedPositionTransform]()
// 电机状态组件类型
MotorStateType = ecs.NewComponentType[component_data.Motor]()
BitStateType = ecs.NewComponentType[BitState]()
)
// 唯一ID组件
type Uid struct {
Id string
}
var UidType = ecs.NewComponentType[Uid]()
// 两个稳态位置转换组件
// type TwoPositionTransform struct {
// Pos int // 当前位置百分比,[0, 10000],两位小数
@ -30,11 +36,9 @@ func (tp *FixedPositionTransform) Percentage() float32 {
return float32(tp.Pos) / consts.TwoPosMax
}
// 固定位置转换组件类型
var FixedPositionTransformType = ecs.NewComponentType[FixedPositionTransform]()
// 计算两位置动作的平均速度
// 总时间t和tick的单位都应该是ms
// t - 总时间tick - 执行间隔
func CalculateTwoPositionAvgSpeed(t int, tick int) int32 {
return int32(consts.TwoPosMax / (t / tick))
}
@ -44,8 +48,6 @@ type BitState struct {
Val bool
}
var BitStateType = ecs.NewComponentType[BitState]()
// 倒数/倒计时组件
type CounterDown struct {
Val int // 当前值

22
component/points.go Normal file
View File

@ -0,0 +1,22 @@
package component
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component/component_data"
"joylink.club/rtsssimulation/component/relation"
)
var (
// 道岔标签
PointsTag = ecs.NewTag()
// 道岔模型数据引用组件类型
PointsModelRelaType = relation.PointsModelRelaType
// 道岔转辙机关系组件类型
PointsZzjRelaType = relation.PointsZzjRelaType
// 道岔ZDJ9双机电路元器件组件类型
Zdj9TwoElectronicType = relation.Zdj9TwoElectronicType
// 道岔转辙机自动开闭器状态组件类型
PointsZzjKbqStateType = ecs.NewComponentType[component_data.PointsZzjKbqState]()
// 道岔位置组件类型
PointsPositionType = ecs.NewComponentType[component_data.PointsPosition]()
)

View File

@ -16,10 +16,10 @@ var (
// 道岔模型数据引用
type PointsModelRela struct {
M model.Turnout
M model.Points
}
func NewPointsModelRela(m model.Turnout) *PointsModelRela {
func NewPointsModelRela(m model.Points) *PointsModelRela {
return &PointsModelRela{
M: m,
}
@ -27,13 +27,13 @@ func NewPointsModelRela(m model.Turnout) *PointsModelRela {
// 道岔转辙机关系组件
type PointsZzjRela struct {
Turnout *ecs.Entry
Points *ecs.Entry
Zzjs []*ecs.Entry
}
func NewPointsZzjRela(t *ecs.Entry, zzjs ...*ecs.Entry) *PointsZzjRela {
return &PointsZzjRela{
Turnout: t,
Points: t,
Zzjs: zzjs,
}
}

View File

@ -208,12 +208,12 @@ func (te *Zdj9TwoElectronic) HasNilReference() bool {
// }
var (
// ZDJ9双机电路元器件组件类型
Zdj9TwoElectronicType = ecs.NewComponentType[Zdj9TwoElectronic]()
// // ZDJ9双机驱动状态组件类型
// Zdj9TwoDriveType = ecs.NewComponentType[Zdj9TwoDrive]()
// // ZDJ9双机采集状态组件类型
// Zdj9TwoCollectType = ecs.NewComponentType[Zdj9TwoCollect]()
// ZDJ9双机电路元器件组件类型
// Zdj9TwoElectronicType = ecs.NewComponentType[Zdj9TwoElectronic]()
// // ZDJ9双机驱动状态组件类型
// Zdj9TwoDriveType = ecs.NewComponentType[Zdj9TwoDrive]()
// // ZDJ9双机采集状态组件类型
// Zdj9TwoCollectType = ecs.NewComponentType[Zdj9TwoCollect]()
)
// 转辙机状态

View File

@ -17,6 +17,11 @@ func Loading(w ecs.World, repo modelrepo.Repo) error {
return nil
}
func loadTurnouts(w ecs.World, turnout []model.Turnout) {
panic("unimplemented")
func loadTurnouts(w ecs.World, points []model.Points) {
for _, p := range points {
switch p.GetTractionType() {
case model.PTT_ZDJ9_2:
}
}
}

36
entity/points.go Normal file
View File

@ -0,0 +1,36 @@
package entity
import (
"fmt"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/relation"
"joylink.club/rtsssimulation/modelrepo/model"
)
func NewPoints(w ecs.World, p model.Points) *ecs.Entry {
id := p.Uid().Id()
// 创建道岔实体
e := w.Entry(w.Create(component.UidType, component.TurnoutTag, component.PointsModelRelaType, component.PointsZzjRelaType,
component.PointsPositionType))
c := p.GetZzjCount()
if c <= 0 {
panic(fmt.Errorf("道岔转辙机数量必须大于0。id=%s, zzjCount=%d", id, c))
}
// 创建转辙机实体
entities := w.CreateMany(c, component.PointsZzjRelaType, component.PointsZzjKbqStateType, component.FixedPositionTransformType)
pzr := &relation.PointsZzjRela{
Points: e,
}
// 关系状态初始化
component.UidType.Set(e, &component.Uid{Id: id})
component.PointsModelRelaType.Set(e, &relation.PointsModelRela{M: p})
component.PointsZzjRelaType.Set(e, pzr)
for _, ez := range entities {
zzj := w.Entry(ez)
pzr.Zzjs = append(pzr.Zzjs, zzj)
component.PointsZzjRelaType.Set(zzj, pzr)
}
return e
}

View File

@ -16,13 +16,13 @@ type Link interface {
// Link总长度
GetLength() int64
// 获取端口A关联的道岔
GetPaTurnout() Turnout
GetPaTurnout() Points
// 获取端口B关联的道岔
GetPbTurnout() Turnout
GetPbTurnout() Points
// 下一个link及端口
// port - 当前link端口
// tpos - 当前道岔位置
Next(port Link_Port, tpos TurnoutPosition) *LinkPort
Next(port Link_Port, tpos PointsPosition) *LinkPort
}
type LinkPort struct {

View File

@ -15,7 +15,7 @@ type Station interface {
type EcStation interface {
Station
// 获取所有道岔
GetTurnouts() []Turnout
GetTurnouts() []Points
// 获取所有信号机
GetSignals() []Signal
// 获取所有站台屏蔽门

View File

@ -1,15 +1,15 @@
package model
// 道岔位置
type TurnoutPosition int
type PointsPosition int
const (
// 失表
TPos_Lost TurnoutPosition = 0
TPos_Lost PointsPosition = 0
// 定位
TPos_DW TurnoutPosition = 1
TPos_DW PointsPosition = 1
// 反位
TPos_FW TurnoutPosition = 2
TPos_FW PointsPosition = 2
)
// 道岔端口
@ -22,17 +22,17 @@ const (
)
// 道岔牵引类型
type TurnoutTractionType int
type PointsTractionType int
const (
// ZDJ9单机牵引
TTT_ZDJ9_1 TurnoutTractionType = 1
PTT_ZDJ9_1 PointsTractionType = 1
// ZDJ9双机牵引
TTT_ZDJ9_2 TurnoutTractionType = 2
PTT_ZDJ9_2 PointsTractionType = 2
)
// 道岔
type Turnout interface {
type Points interface {
Model
// 获取A方向连接的link端口
GetALinkPort() *LinkPort
@ -41,5 +41,7 @@ type Turnout interface {
// 获取C方向连接的link端口
GetCLinkPort() *LinkPort
// 获取牵引类型
GetTractionType() TurnoutTractionType
GetTractionType() PointsTractionType
// 获取转辙机数量
GetZzjCount() int
}

View File

@ -30,17 +30,17 @@ func (l *Link) GetLength() int64 {
}
// GetPaTurnout implements model.Link.
func (l *Link) GetPaTurnout() model.Turnout {
func (l *Link) GetPaTurnout() model.Points {
return l.PaTurnout
}
// GetPbTurnout implements model.Link.
func (l *Link) GetPbTurnout() model.Turnout {
func (l *Link) GetPbTurnout() model.Points {
return l.PbTurnout
}
// Next implements model.Link.
func (*Link) Next(port model.Link_Port, tpos model.TurnoutPosition) *model.LinkPort {
func (*Link) Next(port model.Link_Port, tpos model.PointsPosition) *model.LinkPort {
panic("unimplemented")
}

View File

@ -2,7 +2,7 @@ package modelimpl
import "joylink.club/rtsssimulation/modelrepo/model"
var _turnout model.Turnout = (*Turnout)(nil)
var _turnout model.Points = (*Turnout)(nil)
type Turnout struct {
uid string
@ -23,8 +23,13 @@ type Turnout struct {
cdLink *Link
}
// GetZzjCount implements model.Points.
func (*Turnout) GetZzjCount() int {
panic("unimplemented")
}
// GetTractionType implements model.Turnout.
func (t *Turnout) GetTractionType() model.TurnoutTractionType {
func (t *Turnout) GetTractionType() model.PointsTractionType {
panic("unimplemented")
}

View File

@ -8,7 +8,7 @@ type Repo interface {
// 获取所有设备集中站
GetEcses() []model.EcStation
// 获取所有道岔
GetTurnouts() []model.Turnout
GetTurnouts() []model.Points
// 获取所有信号机
GetSignals() []model.Signal
// 获取所有站台屏蔽门

View File

@ -5,16 +5,38 @@ package component;
option go_package = "./component/component_data";
//
message Motor {
message MotorState {
//
bool powerUp = 1;
//
bool forward = 2;
}
// (81,3,1),1,2
// ,,
// 2DQJ,1,2;3,4
// false表示落下//,true表示吸起//
// ,0.3s以上的继电器()()
// ,
//
message RelayState {
//
bool powerUp = 1;
//
bool qq = 2;
//
bool q = 3;
}
//
message SwitchState {
// (true表示按下,true非常态位)
bool pressed = 2;
}
//
message FixedPositionTransform {
int32 pos = 1; // ,[0, 10000],
int32 pos = 1; // ,[0, 100]
int32 speed = 2;
}

View File

@ -7,6 +7,7 @@ import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/component/relation"
"joylink.club/rtsssimulation/consts"
"joylink.club/rtsssimulation/entity"
)
@ -82,7 +83,7 @@ func (zdj9 *ZDJ9TwoDragSys) handleCiQdRelay(entry *ecs.Entry, wd *component.Worl
}
// 处理驱动电路励磁相关继电器
func (zdj9 *ZDJ9TwoDragSys) exciteDriveElectronic(entry *ecs.Entry, elec *component.Zdj9TwoElectronic, wd *component.WorldData) {
func (zdj9 *ZDJ9TwoDragSys) exciteDriveElectronic(entry *ecs.Entry, elec *relation.Zdj9TwoElectronic, wd *component.WorldData) {
if entry.HasComponent(component.TurnoutFaultCiqdType) { // 联锁驱动失效
return
}
@ -92,7 +93,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteDriveElectronic(entry *ecs.Entry, elec *compon
}
// 总定表、反表继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteZDFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteZDFBJ(entry *ecs.Entry, elec *relation.Zdj9TwoElectronic) {
tdfj1_dbj := component.BitStateType.Get(elec.TDFJ1_DBJ)
tdfj2_dbj := component.BitStateType.Get(elec.TDFJ2_DBJ)
tdfj1_fbj := component.BitStateType.Get(elec.TDFJ1_FBJ)
@ -137,7 +138,7 @@ func isZfbjDrive(entry *ecs.Entry, tdfj1_fbj *component.BitState, tdfj2_fbj *com
// 二极管整流电路为继电器励磁电路提供半波整流电源
// 转辙机一定表/反表继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *relation.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
zzj := component.GetTurnoutZzj1State(entry)
@ -147,7 +148,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ1_DFBJ(entry *ecs.Entry, elec *componen
}
// 转辙机二定表/反表继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ1_DFBJ(entry *ecs.Entry, elec *relation.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
zzj := component.GetTurnoutZzj2State(entry)
@ -181,7 +182,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteDFBJ(_1dqj *component.BitState, _2dqj *compone
}
// 切断继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, elec *relation.Zdj9TwoElectronic) {
tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ)
tdfj2_bhj := component.BitStateType.Get(elec.TDFJ2_BHJ)
tdfj1_zbhj := component.BitStateType.Get(elec.TDFJ1_ZBHJ)
@ -211,7 +212,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_QDJ(w ecs.World, entry *ecs.Entry, ele
}
// 总保护继电器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_ZBHJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_ZBHJ(elec *relation.Zdj9TwoElectronic) {
tdfj1_bhj := component.BitStateType.Get(elec.TDFJ1_BHJ)
tdfj2_bhj := component.BitStateType.Get(elec.TDFJ2_BHJ)
tdfj1_zbhj := component.RelayDriveType.Get(elec.TDFJ1_ZBHJ)
@ -227,7 +228,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_ZBHJ(elec *component.Zdj9TwoElectronic
}
// 转辙机一断相保护器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *relation.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
_2dqj := component.BitStateType.Get(elec.TDFJ1_2DQJ)
@ -237,7 +238,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, ele
}
// 转辙机二断相保护器控制
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_DBQ(w ecs.World, entry *ecs.Entry, elec *relation.Zdj9TwoElectronic) {
_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
_2dqj := component.BitStateType.Get(elec.TDFJ2_2DQJ)
@ -275,14 +276,14 @@ func (zdj9 *ZDJ9TwoDragSys) exciteDBQ(i int, _1dqj *component.BitState, _1dqjf *
}
// 转辙机一TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_BHJ(elec *relation.Zdj9TwoElectronic) {
dbq := component.DBQStateType.Get(elec.TDFJ1_DBQ)
bhj := component.RelayDriveType.Get(elec.TDFJ1_BHJ)
zdj9.exciteBHJ(dbq, bhj)
}
// 转辙机二TDFJ_BHJ保护继电器励磁状态控制
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_BHJ(elec *relation.Zdj9TwoElectronic) {
dbq := component.DBQStateType.Get(elec.TDFJ2_DBQ)
bhj := component.RelayDriveType.Get(elec.TDFJ2_BHJ)
zdj9.exciteBHJ(dbq, bhj)
@ -298,14 +299,14 @@ func (zdj9 *ZDJ9TwoDragSys) exciteBHJ(dbq *component.DBQState, bhj *component.Re
}
// 转辙机一TDFJ_1DQJF励磁电路逻辑
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJF(elec *relation.Zdj9TwoElectronic) {
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ1_1DQJ)
tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ1_1DQJF)
zdj9.excite1DQJF(tdfj_1dqj, tdfj_1dqjf_drive)
}
// 转辙机二TDFJ_1DQJF励磁电路逻辑
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJF(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJF(elec *relation.Zdj9TwoElectronic) {
tdfj_1dqj := component.BitStateType.Get(elec.TDFJ2_1DQJ)
tdfj_1dqjf_drive := component.RelayDriveType.Get(elec.TDFJ2_1DQJF)
zdj9.excite1DQJF(tdfj_1dqj, tdfj_1dqjf_drive)
@ -325,7 +326,7 @@ func (zdj9 *ZDJ9TwoDragSys) excite1DQJF(_1dqj *component.BitState, _1dqjf_drive
}
// 转辙机一TDFJ_1DQJ励磁电路逻辑
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJ(elec *relation.Zdj9TwoElectronic) {
// 暂时先实现非应急按钮操作
ycj := component.BitStateType.Get(elec.TDC_YCJ)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
@ -351,7 +352,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic
}
// 转辙机二TDFJ_1DQJ励磁电路逻辑
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJ(elec *relation.Zdj9TwoElectronic) {
// 暂时先实现非应急按钮操作
ycj := component.BitStateType.Get(elec.TDC_YCJ)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
@ -376,7 +377,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_1DQJ(elec *component.Zdj9TwoElectronic
}
// 转辙机一TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_2DQJ(elec *relation.Zdj9TwoElectronic) {
_1dqjf := component.BitStateType.Get(elec.TDFJ1_1DQJF)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
fcj := component.BitStateType.Get(elec.TDC_FCJ)
@ -385,7 +386,7 @@ func (zdj9 *ZDJ9TwoDragSys) exciteM1_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic
}
// 转辙机二TDFJ_2DQJ励磁电路逻辑(暂时未考虑应急盘操作按钮电路)
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_2DQJ(elec *component.Zdj9TwoElectronic) {
func (zdj9 *ZDJ9TwoDragSys) exciteM2_TDFJ_2DQJ(elec *relation.Zdj9TwoElectronic) {
_1dqjf := component.BitStateType.Get(elec.TDFJ2_1DQJF)
dcj := component.BitStateType.Get(elec.TDC_DCJ)
fcj := component.BitStateType.Get(elec.TDC_FCJ)