调整model结构

This commit is contained in:
walker 2023-08-29 16:08:32 +08:00
parent 7630338c3e
commit d3c51f1d00
3 changed files with 39 additions and 29 deletions

View File

@ -2,17 +2,15 @@ package main
import (
"fmt"
"time"
"joylink.club/ecs"
system "joylink.club/ecs/examples/rtss/sys"
"joylink.club/rtsssimulation/repository/model"
"joylink.club/rtsssimulation/repository/model/proto"
)
func main() {
fmt.Println("基础测试")
w := ecs.NewWorld(1000)
w.AddSystem(system.NewTurnoutSys())
w.StartUp()
link := model.NewLink("1")
fmt.Println(link)
time.Sleep(5 * time.Second)
lp := model.NewLinkPort(&link, proto.Port_A)
fmt.Println(lp)
}

View File

@ -9,8 +9,8 @@ type Link struct {
bRelation LinkNodePort
}
func NewLink(model Model) Link {
return Link{Model: model}
func NewLink(id string) Link {
return Link{Model: modelInfo{id: id}}
}
// link位置
@ -27,6 +27,11 @@ type LinkNode struct {
cRelation LinkPort
}
func (ln LinkNode) Id() string {
return ln.turnout.Id()
}
// link端口
type LinkPort struct {
DevicePort
@ -34,9 +39,31 @@ type LinkPort struct {
port proto.Port
}
func NewLinkPort(link *Link, port proto.Port) LinkPort {
return LinkPort{
link: link,
port: port,
}
}
func (lp LinkPort) Device() Model {
return lp.link
}
type LinkNodePort struct {
DevicePort
node *LinkNode
port proto.Port
}
func NewLinkNodePort(node *LinkNode, port proto.Port) LinkNodePort {
return LinkNodePort{
node: node,
port: port,
}
}
func (lp LinkNodePort) Device() Model {
return lp.node
}

View File

@ -2,34 +2,19 @@ package model
import "joylink.club/rtsssimulation/repository/model/proto"
type ModelType int
type Model interface {
Id() string
Type() ModelType
}
// Model 所有模型的共同父类
type model struct {
id string
modelType ModelType
// Model 模型公共属性
type modelInfo struct {
id string
}
func NewModel(id string, modelType ModelType) Model {
return model{
id: id,
modelType: modelType,
}
}
func (m model) Id() string {
func (m modelInfo) Id() string {
return m.id
}
func (m model) Type() ModelType {
return m.modelType
}
type Signal struct {
Model
km proto.Kilometer