1 Star 0 Fork 0

wuzpdev/goworld

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
test_game.go 1.44 KB
Copy Edit Raw Blame History
seis authored 2018-06-13 23:58 +08:00 . create service entity
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.6

Search