package simulation import ( "joylink.club/ecs" "joylink.club/rtsssimulation/entities" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/system" "time" ) var ( simulationManager = make(map[ecs.WorldId]*Simulation) ) type Simulation struct { world ecs.World repo *repository.Repository } func (s *Simulation) GetWorld() ecs.World { return s.world } func (s *Simulation) GetRepo() *repository.Repository { return s.repo } func CreateSimulation(repo *repository.Repository, systemTypes ...system.Type) int { var systems []ecs.ISystem systemTypeMap := make(map[system.Type]bool) for _, systemType := range systemTypes { switch systemType { case system.SWITCH_ZDJ9_2: systems = append(systems, system.NewSwitch2jZdj9System()) case system.RELAY: systems = append(systems, system.NewRelaySystem()) case system.DEBUG: systems = append(systems, system.NewDebugSystem()) } systemTypeMap[systemType] = true } wc := &WorldConfig{ Systems: systems, Tick: 200, InitTime: time.Now(), } world := InitializeWorld(wc) sim := &Simulation{ world: world, repo: repo, } simulationManager[world.Id()] = sim //添加实体 entities.CreateTurnoutEntries(world, repo.TurnoutList(), systemTypeMap) //初始化组件 initComponent(world) //启动 world.StartUp() return int(world.Id()) } func DestroySimulation(id ecs.WorldId) { delete(simulationManager, id) } func FindSimulation(id ecs.WorldId) *Simulation { return simulationManager[id] } func initComponent(world ecs.World) { }