rts-sim-module/simulation/simulation.go

40 lines
686 B
Go
Raw Normal View History

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
}
2023-09-26 10:25:00 +08:00
func (s *Simulation) World() ecs.World {
return s.world
}
2023-09-26 10:25:00 +08:00
func (s *Simulation) Repo() *repository.Repository {
return s.repo
}
2023-09-26 10:25:00 +08:00
func CreateSimulation(repo *repository.Repository, world ecs.World) {
sim := &Simulation{
world: world,
repo: repo,
}
simulationManager[world.Id()] = sim
}
func DestroySimulation(id ecs.WorldId) {
delete(simulationManager, id)
}
func FindSimulation(id ecs.WorldId) *Simulation {
return simulationManager[id]
}