rts-sim-module/simulation/simulation.go
2023-09-21 15:21:06 +08:00

42 lines
758 B
Go

package simulation
import (
"joylink.club/ecs"
"joylink.club/rtsssimulation/repository"
)
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, config *WorldConfig) int {
world := InitializeWorld(config)
sim := &Simulation{
world: world,
repo: repo,
}
simulationManager[world.Id()] = sim
return int(world.Id())
}
func DestroySimulation(id ecs.WorldId) {
delete(simulationManager, id)
}
func FindSimulation(id ecs.WorldId) *Simulation {
return simulationManager[id]
}