From d3c51f1d000537b4981bd912e594ec81c48c6da0 Mon Sep 17 00:00:00 2001 From: walker Date: Tue, 29 Aug 2023 16:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4model=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/basic/main.go | 14 ++++++-------- repository/model/link.go | 31 +++++++++++++++++++++++++++++-- repository/model/model.go | 23 ++++------------------- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/examples/basic/main.go b/examples/basic/main.go index f06fee3..7fe9c92 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -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) } diff --git a/repository/model/link.go b/repository/model/link.go index 3155534..8c704e4 100644 --- a/repository/model/link.go +++ b/repository/model/link.go @@ -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 +} diff --git a/repository/model/model.go b/repository/model/model.go index a9a1d14..e112ccc 100644 --- a/repository/model/model.go +++ b/repository/model/model.go @@ -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