Skip to content

Commit

Permalink
实验添加mmorpg功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ubuntu committed Jul 5, 2018
1 parent 030ae09 commit f764a13
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 32 deletions.
4 changes: 1 addition & 3 deletions lualib/faci/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ local function init()
--模块
module.init_modules()
module.fire_event("awake")
skynet.timeout(100, function()
module.fire_event("start")
end)
module.fire_event("start")
log.debug("start ok "..name.."...")
end

Expand Down
Binary file added mod/scene_mgr/.scene_mgr_dispatch.lua.swp
Binary file not shown.
49 changes: 49 additions & 0 deletions mod/scene_mgr/scene_mgr_dispatch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local skynet = require "skynet"
local tool = require "tool"
local faci = require "faci.module"
local libsetup = require "libsetup"
local cluster = require "cluster"

local runconf = require(skynet.getenv("runconfig"))
local local_nodename = skynet.getenv("nodename")

local module, static = faci.get_module("SceneMgr")
local dispatch = module.dispatch
local forward = module.forward
local event = module.event

local servconf = runconf.service

local function get_node_name(scene_id)
local scene_nodes = servconf.scene
assert(type(scene_nodes) == "table")

local scene_node_num = #servconf.scene
local id = scene_id % scene_node_num + 1
local node_name = scene_nodes[id]
assert(type(node_name) == "string")

return node_name
end

function dispatch.start()

local scene_conf = libsetup.scene

for i, v in pairs(scene_conf) do
local node_name = get_node_name(i)
local name = string.format("scene%d", i)
if local_nodename == node_name then
skynet.newservice("scene", "scene", i)
else
local proxy = cluster.proxy(node_name, name)
skynet.name(name, proxy)
end
end

log.debug("start scene mgr success~~")

end



27 changes: 0 additions & 27 deletions mod/scene_mgr/scene_mgr_event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,8 @@ local event = module.event
local servconf = runconf.service
local local_nodename = skynet.getenv("nodename")

local function get_node_name(scene_id)
local scene_nodes = servconf.scene
assert(type(scene_nodes) == "table")

local scene_node_num = #servconf.scene
local id = scene_id % scene_node_num + 1
local node_name = scene_nodes[id]
assert(type(node_name) == "string")

return node_name
end

function event.start()

local scene_conf = libsetup.scene
for i, v in pairs(scene_conf) do
local node_name = get_node_name(i)
local name = string.format("scene%d", i)
if local_nodename == node_name then
skynet.newservice("scene", "scene", i)
else
local proxy = cluster.proxy(node_name, name)
skynet.name(name, proxy)
end
end

log.debug("start scene mgr success~~")
skynet.exit()

end


Expand Down
3 changes: 3 additions & 0 deletions proto/pb/player.pb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


player.proto
2 changes: 1 addition & 1 deletion proto/pbfile

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion service/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ end

local function start_scene_mgr()
if servconf.scene then
skynet.uniqueservice("scene_mgr", "scene_mgr")
local p = skynet.uniqueservice("scene_mgr", "scene_mgr")
skynet.call(p, "lua", "start")
else
log.debug("not scene conf, so not start scene mgr")
end
Expand Down

0 comments on commit f764a13

Please sign in to comment.