42 lines
758 B
Go
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]
|
||
|
}
|