仿真初始化

This commit is contained in:
xzb 2023-09-13 10:05:42 +08:00
parent f2553240b4
commit 3155ad8eb3
8 changed files with 92 additions and 38 deletions

27
entities/common_entity.go Normal file
View 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
View 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
View 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
View 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
View 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
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}