This commit is contained in:
weizhihong 2023-10-16 09:55:52 +08:00
commit 511045e2a2
8 changed files with 336 additions and 20 deletions

View File

@ -0,0 +1,152 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc v4.23.1
// source: component/psd.proto
package component_proto
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type PsdState struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Km4 bool `protobuf:"varint,1,opt,name=km4,proto3" json:"km4,omitempty"`
Km8 bool `protobuf:"varint,2,opt,name=km8,proto3" json:"km8,omitempty"`
}
func (x *PsdState) Reset() {
*x = PsdState{}
if protoimpl.UnsafeEnabled {
mi := &file_component_psd_proto_msgTypes[0]
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_component_psd_proto_msgTypes[0]
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_component_psd_proto_rawDescGZIP(), []int{0}
}
func (x *PsdState) GetKm4() bool {
if x != nil {
return x.Km4
}
return false
}
func (x *PsdState) GetKm8() bool {
if x != nil {
return x.Km8
}
return false
}
var File_component_psd_proto protoreflect.FileDescriptor
var file_component_psd_proto_rawDesc = []byte{
0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x2f, 0x70, 0x73, 0x64, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74,
0x22, 0x2e, 0x0a, 0x08, 0x50, 0x73, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03,
0x6b, 0x6d, 0x34, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x6b, 0x6d, 0x34, 0x12, 0x10,
0x0a, 0x03, 0x6b, 0x6d, 0x38, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x6b, 0x6d, 0x38,
0x42, 0x1d, 0x5a, 0x1b, 0x2e, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x2f,
0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_component_psd_proto_rawDescOnce sync.Once
file_component_psd_proto_rawDescData = file_component_psd_proto_rawDesc
)
func file_component_psd_proto_rawDescGZIP() []byte {
file_component_psd_proto_rawDescOnce.Do(func() {
file_component_psd_proto_rawDescData = protoimpl.X.CompressGZIP(file_component_psd_proto_rawDescData)
})
return file_component_psd_proto_rawDescData
}
var file_component_psd_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_component_psd_proto_goTypes = []interface{}{
(*PsdState)(nil), // 0: component.PsdState
}
var file_component_psd_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_component_psd_proto_init() }
func file_component_psd_proto_init() {
if File_component_psd_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_component_psd_proto_msgTypes[0].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
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_component_psd_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_component_psd_proto_goTypes,
DependencyIndexes: file_component_psd_proto_depIdxs,
MessageInfos: file_component_psd_proto_msgTypes,
}.Build()
File_component_psd_proto = out.File
file_component_psd_proto_rawDesc = nil
file_component_psd_proto_goTypes = nil
file_component_psd_proto_depIdxs = nil
}

29
component/mkx.go Normal file
View File

@ -0,0 +1,29 @@
package component
import "joylink.club/ecs"
var MkxCircuitType = ecs.NewComponentType[MkxCircuit]()
type MkxCircuit struct {
Pcb []*ecs.Entry
Pcbj *ecs.Entry
Pob1 []*ecs.Entry
Pobj *ecs.Entry
Pab1 []*ecs.Entry
Pabj *ecs.Entry
}
type Pcb struct {
PcbBtn *ecs.Entry
MkxplBtn *ecs.Entry
}
type Pob struct {
PobBtn *ecs.Entry
MkxplBtn *ecs.Entry
}
type Pab struct {
PabBtn *ecs.Entry
MkxplBtn *ecs.Entry
}

View File

@ -1,8 +1,13 @@
package component
import "joylink.club/ecs"
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/component/component_proto"
"joylink.club/rtsssimulation/consts"
)
var PsdTag = ecs.NewTag()
var PsdStateType = ecs.NewComponentType[component_proto.PsdState]()
var PsdCircuitType = ecs.NewComponentType[PsdCircuit]()
@ -16,23 +21,33 @@ type PsdCircuit struct {
MPLJ *ecs.Entry
}
var PsdMotorType = ecs.NewComponentType[ecs.Entry]()
var PsdMotorStateType = ecs.NewComponentType[PsdMotorState]()
// PsdMotorState 屏蔽门电机状态
type PsdMotorState struct {
//4编组开门通电
Km4 bool
Km4_Td bool
//8编组开门通电
Km8 bool
Km8_Td bool
//关门通电
Gm bool
Gm_Td bool
//4编组开门进度
Km4 int32
//8编组与4编组差集的门的开门进度
Km8_4 int32
//开关门速度
Speed int32
}
var PsdPositionType = ecs.NewComponentType[PsdPosition]()
// Is4Km 是否4编组开门不用开到位
func (p *PsdMotorState) Is4Km() bool {
return p.Km4 != consts.TwoPosMin && p.Km8_4 == consts.TwoPosMin
}
type PsdPosition struct {
km bool
gm bool
// Is4Km 是否4编组开门不用开到位
func (p *PsdMotorState) Is8Km() bool {
return p.Km4 != consts.TwoPosMin && p.Km8_4 != consts.TwoPosMin
}
var PsdDriveCircuitType = ecs.NewComponentType[PsdDriveCircuit]()

1
entity/mkx.go Normal file
View File

@ -0,0 +1 @@
package entity

View File

@ -41,10 +41,12 @@ func loadPsdCircuit(world ecs.World, entry *ecs.Entry, psd *repository.Psd, entr
func NewPsdEntry(world ecs.World, uid string, worldData *component.WorldData) *ecs.Entry {
entry, ok := worldData.EntityMap[uid]
if !ok {
entry := world.Entry(world.Create(component.PsdTag, component.UidType, component.TwoPositionTransformType,
component.PsdCircuitType, component.PsdDriveCircuitType, component.PsdCollectionCircuitType))
component.UidType.SetValue(entry, component.Uid{Id: uid})
worldData.EntityMap[uid] = entry
psd := world.Entry(world.Create(component.PsdTag, component.UidType, component.PsdStateType,
component.PsdCircuitType, component.PsdDriveCircuitType, component.PsdCollectionCircuitType, component.PsdMotorType))
component.UidType.SetValue(psd, component.Uid{Id: uid})
psdMotor := world.Entry(world.Create(component.PsdMotorStateType))
component.PsdMotorType.Set(psd, psdMotor)
worldData.EntityMap[uid] = psd
}
return entry
}

View File

@ -0,0 +1,10 @@
syntax = "proto3";
package component;
option go_package = "./component/component_proto";
message PsdState {
bool km4 = 1;
bool km8 = 2;
}

View File

@ -18,15 +18,34 @@ func NewPsdSys() *PsdSys {
func (p *PsdSys) Update(world ecs.World) {
p.query.Each(world, func(entry *ecs.Entry) {
psdMotorState := component.PsdMotorStateType.Get(entry)
psdMotor := component.PsdMotorType.Get(entry)
psdMotorState := component.PsdMotorStateType.Get(psdMotor)
psd := component.PsdCircuitType.Get(entry)
psdDrive := component.PsdDriveCircuitType.Get(entry)
p.exciteByDrive(psd, psdDrive)
p.exciteGMJ(psdMotorState, psd, psdDrive)
p.exciteKMJ4(psdMotorState, psd, psdDrive)
p.exciteKMJ8(psdMotorState, psd, psdDrive)
p.exciteMGJ(entry, psdMotorState)
p.updatePsdState(entry, psdMotorState)
})
}
func (p *PsdSys) exciteByDrive(psd *component.PsdCircuit, drive *component.PsdDriveCircuit) {
if drive.GMJ {
component.RelayDriveType.Get(psd.GMJ).Td = true
component.BitStateType.Get(psd.GMJ).Val = true
}
if drive.KMJ4 {
component.RelayDriveType.Get(psd.KMJ4).Td = true
component.BitStateType.Get(psd.KMJ4).Val = true
}
if drive.KMJ8 {
component.RelayDriveType.Get(psd.KMJ8).Td = true
component.BitStateType.Get(psd.KMJ8).Val = true
}
}
func (p *PsdSys) exciteGMJ(state *component.PsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) {
gmj := component.BitStateType.Get(psd.GMJ)
kmj4 := component.BitStateType.Get(psd.KMJ4)
@ -43,7 +62,7 @@ func (p *PsdSys) exciteGMJ(state *component.PsdMotorState, psd *component.PsdCir
}
}
if gmj.Val && !kmj4.Val && !kmj8.Val {
state.Gm = true
state.Gm_Td = true
}
}
@ -63,18 +82,18 @@ func (p *PsdSys) exciteKMJ4(state *component.PsdMotorState, psd *component.PsdCi
}
}
if kmj4.Val && !gmj.Val && !kmj8.Val {
state.Km4_Td = true
}
}
func (p *PsdSys) exciteKMJ8(state *component.PsdMotorState, psd *component.PsdCircuit, psdDrive *component.PsdDriveCircuit) {
kmj8 := component.BitStateType.Get(psd.KMJ8)
gmj := component.BitStateType.Get(psd.GMJ)
kmj4 := component.BitStateType.Get(psd.KMJ4)
if psdDrive.KMJ4 {
component.RelayDriveType.Get(psd.KMJ8).Td = true
kmj8.Val = true
} else if kmj8.Val {
gmj := component.BitStateType.Get(psd.GMJ)
kmj4 := component.BitStateType.Get(psd.KMJ4)
if !gmj.Val && !kmj4.Val {
component.RelayDriveType.Get(psd.KMJ8).Td = true
} else {
@ -82,4 +101,32 @@ func (p *PsdSys) exciteKMJ8(state *component.PsdMotorState, psd *component.PsdCi
kmj8.Val = false
}
}
if kmj8.Val && !gmj.Val && !kmj4.Val {
state.Km8_Td = true
}
}
func (p *PsdSys) exciteMGJ(entry *ecs.Entry, state *component.PsdMotorState) {
psdCircuit := component.PsdCircuitType.Get(entry)
if state.Is4Km() || state.Is8Km() {
component.RelayDriveType.Get(psdCircuit.MGJ).Td = false
component.BitStateType.Get(psdCircuit.MGJ).Val = false
} else {
component.RelayDriveType.Get(psdCircuit.MGJ).Td = true
component.BitStateType.Get(psdCircuit.MGJ).Val = true
}
}
func (p *PsdSys) updatePsdState(entry *ecs.Entry, psdMotorState *component.PsdMotorState) {
psdState := component.PsdStateType.Get(entry)
if psdMotorState.Is8Km() {
psdState.Km8 = true
psdState.Km4 = false
} else if psdMotorState.Is4Km() {
psdState.Km4 = true
psdState.Km8 = false
} else {
psdState.Km4 = false
psdState.Km8 = false
}
}

View File

@ -4,6 +4,7 @@ import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/consts"
)
type PsdMotorSys struct {
@ -12,10 +13,69 @@ type PsdMotorSys struct {
func NewPsdMotorSys() *PsdMotorSys {
return &PsdMotorSys{
query: ecs.NewQuery(filter.Contains(component.PsdMotorStateType, component.TwoPositionTransformType)),
query: ecs.NewQuery(filter.Contains(component.PsdMotorStateType)),
}
}
func (s *PsdMotorSys) Update(w ecs.World) {
func (s *PsdMotorSys) Update(world ecs.World) {
var rate int32 = 10000 / 4
s.query.Each(world, func(entry *ecs.Entry) {
psdMotorState := component.PsdMotorStateType.Get(entry)
if psdMotorState.Gm_Td {
gm(psdMotorState, rate)
} else if psdMotorState.Km4_Td {
km4(psdMotorState, rate)
} else if psdMotorState.Km8_Td {
km8(psdMotorState, rate)
}
})
}
func gm(psdMotorState *component.PsdMotorState, rate int32) {
if psdMotorState.Km4 != consts.TwoPosMin {
newRate := psdMotorState.Km4 - rate
if newRate < consts.TwoPosMin {
psdMotorState.Km4 = consts.TwoPosMin
} else {
psdMotorState.Km4 = newRate
}
}
if psdMotorState.Km8_4 != consts.TwoPosMin {
newRate := psdMotorState.Km8_4 - rate
if newRate < consts.TwoPosMin {
psdMotorState.Km8_4 = consts.TwoPosMin
} else {
psdMotorState.Km8_4 = newRate
}
}
}
func km4(psdMotorState *component.PsdMotorState, rate int32) {
if psdMotorState.Km4 != consts.TwoPosMax {
newRate := psdMotorState.Km4 + rate
if newRate > consts.TwoPosMax {
psdMotorState.Km4 = consts.TwoPosMax
} else {
psdMotorState.Km4 = newRate
}
}
}
func km8(psdMotorState *component.PsdMotorState, rate int32) {
if psdMotorState.Km4 != consts.TwoPosMax {
newRate := psdMotorState.Km4 + rate
if newRate > consts.TwoPosMax {
psdMotorState.Km4 = consts.TwoPosMax
} else {
psdMotorState.Km4 = newRate
}
}
if psdMotorState.Km8_4 != consts.TwoPosMax {
newRate := psdMotorState.Km8_4 + rate
if newRate > consts.TwoPosMax {
psdMotorState.Km8_4 = consts.TwoPosMax
} else {
psdMotorState.Km8_4 = newRate
}
}
}