game.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "github.com/mhaya"
  4. mhayaCron "github.com/mhaya/components/cron"
  5. mhayaGops "github.com/mhaya/components/gops"
  6. mhayaMongo "github.com/mhaya/components/mongo"
  7. mhayaSnowflake "github.com/mhaya/extend/snowflake"
  8. cstring "github.com/mhaya/extend/string"
  9. mhayaUtils "github.com/mhaya/extend/utils"
  10. checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
  11. "github.com/mhaya/game/game_cluster/internal/data"
  12. "github.com/mhaya/game/game_cluster/internal/mdb"
  13. "github.com/mhaya/game/game_cluster/nodes/game/module/player"
  14. )
  15. func main() {
  16. nodeId := "10001"
  17. if mhayaUtils.IsNumeric(nodeId) == false {
  18. panic("node parameter must is number.")
  19. }
  20. // snowflake global id
  21. serverId, _ := cstring.ToInt64(nodeId)
  22. mhayaSnowflake.SetDefaultNode(serverId)
  23. // 配置mhaya引擎
  24. app := mhaya.Configure("./game/config/profile-gc.json", nodeId, false, mhaya.Cluster)
  25. // diagnose
  26. app.Register(mhayaGops.New())
  27. // 注册调度组件
  28. app.Register(mhayaCron.New())
  29. // 注册数据配置组件
  30. app.Register(data.New())
  31. // 注册检测中心节点组件,确认中心节点启动后,再启动当前节点
  32. app.Register(checkCenter.New())
  33. // 注册db组件
  34. app.Register(mhayaMongo.NewComponent())
  35. app.AddActors(
  36. &player.ActorPlayers{},
  37. &mdb.ActorDB{},
  38. )
  39. app.Startup()
  40. }