仿真初始化
This commit is contained in:
parent
f2553240b4
commit
3155ad8eb3
27
entities/common_entity.go
Normal file
27
entities/common_entity.go
Normal file
@ -0,0 +1,27 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
// 创建模型仓库实体
|
||||
func CreateModelStorageEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(system.ModelStorageComponent)
|
||||
}
|
||||
|
||||
// 创建继电器实体
|
||||
func CreateRelayEntity(w ecs.World, relayId string) *ecs.Entry {
|
||||
e := w.Create(system.EntityIdentityComponent, system.RelayStateComponent)
|
||||
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: relayId})
|
||||
return e
|
||||
}
|
||||
|
||||
// 创建系统时钟实体
|
||||
func CreateSystemTimerEntity(w ecs.World, systemTime time.Time) *ecs.Entry {
|
||||
e := w.Create(system.SystemTimerComponent)
|
||||
system.SystemTimerComponent.Set(e, system.NewSystemTimer(&systemTime))
|
||||
return e
|
||||
}
|
13
entities/signal_entity.go
Normal file
13
entities/signal_entity.go
Normal file
@ -0,0 +1,13 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
func CreateSignal3XH1Entity(w ecs.World, signalId string) *ecs.Entry {
|
||||
e := w.Create(system.EntityIdentityComponent, system.Signal3XH1StateComponent)
|
||||
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: signalId})
|
||||
system.Signal3XH1StateComponent.Set(e, system.NewSignal3XH1State())
|
||||
return e
|
||||
}
|
13
entities/switch_entity.go
Normal file
13
entities/switch_entity.go
Normal file
@ -0,0 +1,13 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
// 双机zdj9
|
||||
func CreateSwitch2jzdj9Entity(w ecs.World, switchId string) *ecs.Entry {
|
||||
e := w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent)
|
||||
system.EntityIdentityComponent.Set(e, &system.EntityIdentity{Id: switchId})
|
||||
return e
|
||||
}
|
20
simulation/config.go
Normal file
20
simulation/config.go
Normal file
@ -0,0 +1,20 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/umi"
|
||||
)
|
||||
|
||||
// 仿真world配置
|
||||
type WorldConfig struct {
|
||||
//模型管理器,接收模型仓库管理器实例的指针
|
||||
ModelManager umi.IModelManager
|
||||
//world 系统
|
||||
Systems []ecs.ISystem
|
||||
//world tick
|
||||
Tick int
|
||||
//world 起始时间
|
||||
InitTime time.Time
|
||||
}
|
19
simulation/init.go
Normal file
19
simulation/init.go
Normal file
@ -0,0 +1,19 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/entities"
|
||||
)
|
||||
|
||||
// 初始化仿真world
|
||||
func InitializeWorld(config *WorldConfig) ecs.World {
|
||||
world := ecs.NewWorld(config.Tick)
|
||||
// 初始化系统
|
||||
for _, sys := range config.Systems {
|
||||
world.AddSystem(sys)
|
||||
}
|
||||
// 初始化系统时间
|
||||
entities.CreateSystemTimerEntity(world, config.InitTime)
|
||||
//
|
||||
return world
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
// 创建模型仓库实体
|
||||
func CreateModelStorageEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(system.ModelStorageComponent)
|
||||
}
|
||||
|
||||
// 创建继电器实体
|
||||
func CreateRelayEntity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(system.EntityIdentityComponent, system.RelayStateComponent)
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
func CreateSignal3XH1Entity(w ecs.World) *ecs.Entry {
|
||||
e := w.Create(system.EntityIdentityComponent, system.Signal3XH1StateComponent)
|
||||
return e
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"joylink.club/ecs"
|
||||
"joylink.club/rtsssimulation/system"
|
||||
)
|
||||
|
||||
// 双机zdj9
|
||||
func CreateSwitch2jzdj9Entity(w ecs.World) *ecs.Entry {
|
||||
return w.Create(system.EntityIdentityComponent, system.Switch2jZdj9StateComponent)
|
||||
}
|
Loading…
Reference in New Issue
Block a user