package simulation import ( "sync" "joylink.club/ecs" "joylink.club/rtsssimulation/repository" ) var ( simulationManager = make(map[ecs.WorldId]*Simulation) ) type Simulation struct { world ecs.World repo *repository.Repository entityMap sync.Map } func (s *Simulation) World() ecs.World { return s.world } func (s *Simulation) Repo() *repository.Repository { return s.repo } func (s *Simulation) AddEntry(id string, entity *ecs.Entry) { s.entityMap.Store(id, entity) } func (s *Simulation) GetEntry(id string) *ecs.Entry { e, ok := s.entityMap.Load(id) if ok { return e.(*ecs.Entry) } return nil } func CreateSimulation(repo *repository.Repository, world ecs.World) *Simulation { sim := &Simulation{ world: world, repo: repo, } simulationManager[world.Id()] = sim return sim } func DestroySimulation(id ecs.WorldId) { delete(simulationManager, id) } func FindSimulation(id ecs.WorldId) *Simulation { return simulationManager[id] }