This commit is contained in:
xzb 2023-09-26 10:49:22 +08:00
parent 842a37077a
commit aa728e1b32
3 changed files with 48 additions and 3 deletions

View File

@ -2,8 +2,8 @@ package sjzdj9
import (
"fmt"
"joylink.club/rtsssimulation/examples/test1/tinit"
"joylink.club/rtsssimulation/repository/model/proto"
world2 "joylink.club/rtsssimulation/simulation/world"
"time"
"github.com/yohamta/donburi/filter"
@ -22,13 +22,13 @@ func Test() {
addSwitchs(modelStorage)
worldStorage := &tstorages.WorldModelStorage{Share: modelStorage, Links: tstorages.NewModelStorage()}
//
worldConfig := world2.WorldConfig{
worldConfig := tinit.WorldConfig{
ModelManager: worldStorage,
Systems: []ecs.ISystem{system.NewSwitch2jZdj9System(), system.NewRelaySystem(), system.NewDebugSystem()},
Tick: 200,
InitTime: time.Now(),
}
world := world2.InitializeWorld(&worldConfig)
world := tinit.InitializeWorld(&worldConfig)
addEntities(world, modelStorage)
initComponents(world)
//

View File

@ -0,0 +1,20 @@
package tinit
import (
"joylink.club/rtsssimulation/system"
"time"
"joylink.club/ecs"
)
// WorldConfig 仿真world配置
type WorldConfig struct {
//模型管理器,接收模型仓库管理器实例的指针
ModelManager system.IModelManager
//world 系统
Systems []ecs.ISystem
//world tick
Tick int
//world 起始时间
InitTime time.Time
}

View File

@ -0,0 +1,25 @@
package tinit
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/entities"
"joylink.club/rtsssimulation/system"
)
// InitializeWorld 初始化仿真world
func InitializeWorld(config *WorldConfig) ecs.World {
world := ecs.NewWorld(config.Tick)
// 添加系统
world.AddSystem(system.NewTimerSystem())
world.AddSystem(system.NewPercentageMovableSystem())
for _, sys := range config.Systems {
world.AddSystem(sys)
}
// 添加内置实体
entities.CreateSystemTimerEntity(world, config.InitTime)
if config.ModelManager != nil {
entities.CreateModelStorageEntity(world, config.ModelManager)
}
//
return world
}