-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.go
44 lines (39 loc) · 1.2 KB
/
simulation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package simulation
import (
"github.com/soupstore/coda-world/simulation/model"
"go.uber.org/zap"
)
// Simulation is the engine of the world.
// It holds rooms, characters, items etc...
// It exposes a number of interfaces to manipulate the simulation.
type Simulation struct {
logger *zap.Logger
nextRoomID model.RoomID
nextCharacterID model.CharacterID
spawnRoom *model.Room
rooms map[model.RoomID]*model.Room
items map[model.ItemID]*model.Item
characters map[model.CharacterID]*model.Character
}
// NewSimulation returns a Simulation with default params.
func NewSimulation(logger *zap.Logger) *Simulation {
return &Simulation{
logger: logger,
nextRoomID: 0,
nextCharacterID: 0,
spawnRoom: nil,
rooms: make(map[model.RoomID]*model.Room),
items: make(map[model.ItemID]*model.Item),
characters: make(map[model.CharacterID]*model.Character),
}
}
func (s *Simulation) getNextRoomID() model.RoomID {
roomID := s.nextRoomID
s.nextRoomID = roomID + 1
return roomID
}
func (s *Simulation) getNextCharacterID() model.CharacterID {
id := s.nextCharacterID
s.nextCharacterID = s.nextCharacterID + 1
return id
}