-
Notifications
You must be signed in to change notification settings - Fork 5
/
sys.go
57 lines (47 loc) · 1.53 KB
/
sys.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
45
46
47
48
49
50
51
52
53
54
55
56
57
package server
import (
"time"
"github.com/unitoftime/ecs"
"github.com/unitoftime/flow/tile"
"github.com/unitoftime/flow/phy2"
"github.com/unitoftime/mmo"
"github.com/unitoftime/mmo/serdes"
)
// Represents a logged in user on the server
type User struct {
// Name string // TODO - remove and put into a component called "DisplayName"
Id uint64
ProxyId uint64
}
// This is the tick that the client says they are on
type ClientTick struct {
Tick uint16 // This is the tick that the player is currently on
}
func CreateServerSystems(world *ecs.World, server *Server, networkChannel chan serdes.WorldUpdate, deleteList *DeleteList, tilemap *tile.Tilemap) []ecs.System {
serverSystems := []ecs.System{
CreatePollNetworkSystem(world, networkChannel),
}
// serverSystems = append(serverSystems,
// CreatePhysicsSystems(world)...)
serverSystems = append(serverSystems,
ecs.System{"MoveCharacters", func(dt time.Duration) {
ecs.Map3(world, func(id ecs.Id, input *mmo.Input, pos *phy2.Pos, collider *phy2.CircleCollider) {
mmo.MoveCharacter(input, pos, collider, tilemap, dt)
})
}},
ecs.System{"CheckCollisions", func(dt time.Duration) {
// Set the collider position
ecs.Map2(world, func(id ecs.Id, pos *phy2.Pos, col *phy2.CircleCollider) {
col.CenterX = pos.X
col.CenterY = pos.Y
})
mmo.CheckCollisions(world)
}},
)
serverSystems = append(serverSystems, []ecs.System{
ecs.System{"ServerSendUpdate", func(dt time.Duration) {
ServerSendUpdate(world, server, deleteList)
}},
}...)
return serverSystems
}