forked from xiaonanln/goworld
/
test_game.go
68 lines (55 loc) · 1.44 KB
/
test_game.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
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"time"
"github.com/xiaonanln/goTimer"
"github.com/xiaonanln/goworld"
"github.com/xiaonanln/goworld/engine/gwlog"
"github.com/xiaonanln/goworld/ext/pubsub"
)
var (
_SERVICE_NAMES = []string{
"OnlineService",
"SpaceService",
"MailService",
pubsub.ServiceName,
}
)
func init() {
}
func main() {
goworld.RegisterSpace(&MySpace{}) // Register the space type
// Register each entity types
goworld.RegisterEntity("Account", &Account{})
goworld.RegisterService("OnlineService", &OnlineService{})
goworld.RegisterService("SpaceService", &SpaceService{})
goworld.RegisterService("MailService", &MailService{})
pubsub.RegisterService()
// Register Monster type and define attributes
goworld.RegisterEntity("Monster", &Monster{})
// Register Avatar type and define attributes
goworld.RegisterEntity("Avatar", &Avatar{})
// Run the game server
goworld.Run()
}
func checkServerStarted() {
ok := isAllServicesReady()
gwlog.Infof("checkServerStarted: %v", ok)
if ok {
onAllServicesReady()
} else {
timer.AddCallback(time.Millisecond*1000, checkServerStarted)
}
}
func isAllServicesReady() bool {
for _, serviceName := range _SERVICE_NAMES {
if goworld.GetServiceEntityID(serviceName).IsNil() {
gwlog.Infof("%s is not ready ...", serviceName)
return false
}
}
return true
}
func onAllServicesReady() {
gwlog.Infof("ALL SERVICES ARE READY!!!")
goworld.CallNilSpaces("TestCallNilSpaces", 1, "abc", true, 2.3)
}