diff options
author | chai <chaifix@163.com> | 2018-08-12 21:51:38 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-08-12 21:51:38 +0800 |
commit | ac0de268b46b136a6cdd6bbf096d93c1ff126329 (patch) | |
tree | 0e4f4305b3aded2c9ae59da3e33e141178d3e9c1 /main.lua | |
parent | dbb4af0ea10640d062e1bc9e170be4a657c93d9d (diff) |
update
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 79 |
1 files changed, 53 insertions, 26 deletions
@@ -1,49 +1,78 @@ -require("global") -local loghelper = require("loghelper") -loghelper.strict(loghelper.LEVEL.INFO) +_require = require +require = function(name) + return _require("jin-modules." .. name) +end +local jnet = require("jnet") +local log = require("loghelper") +log.strict(log.LEVEL.INFO) local EventMsgCenter = require("EventMsgCenter.EventMsgCenter") local Events = require("EventMsgCenter.Events") local timer = require("timer.timer") -local channels = require("channels") _G["frame"] = 0 local thread = nil - +local socket = nil jin.core.onLoad = function() - thread = jin.thread.Thread("Test", [[ -require("global") -local channels = require("channels") +---- 网络测试 + jin.net.init() + socket = jin.net.Socket("TCP", 8807) + local Skill = { + id = jnet.DataType.INT, + damage = jnet.DataType.FLOAT, + name = jnet.DataType.STRING, + description = jnet.DataType.STRING, + -- bonus = { + -- damage = FLOAT, + -- range = FLOAT, + -- cd = BOOL + -- } + cd = jnet.DataType.BOOL + } + local buf = jin.net.Buffer(0) + local mySkill = { + id = 12, + name = "Hell fire!!!", + damage = 3.4, + description = "1234", + -- bonus = { + -- damage = FLOAT, + -- range = FLOAT, + -- cd = BOOL + -- } + cd = true + } + jnet.serialize(mySkill, buf) + local msg = jnet.deserialize(Skill, buf, 0) + print(msg.name) -local t = jin.thread.getThread() -local str = t:demand(channels.PROGRESS) -print(str) -t:send(3, "back data") -while true do - jin.time.sleep(1) -end - ]] ) + thread = jin.thread.Thread("Test", [[ + local thread = jin.thread.getThread() + local socket = thread:demand(1) + while true do + local client = socket:accept() + local buf = client:receive() + local str = buf:grabString(0) + print(str) + end + ]]) thread:start() + thread:send(1, socket) EventMsgCenter.registerMsg(Events.Player_Move, function(msg) print(msg) end) timer.every(1.0, function() - loghelper.log(loghelper.LEVEL.INFO, _G["frame"] .. "fps") - EventMsgCenter.sendMsg(Events.Player_Move, _G["frame"]) + log.info(_G["frame"] .. "fps") + -- EventMsgCenter.sendMsg(Events.Player_Move, _G["frame"]) _G["frame"] = 0 - if thread:receive(3) then - print(thread:fetch(3)) - end end) timer.after(4.0, function() - thread:send(channels.PROGRESS, "test thread data") EventMsgCenter.unregisterAllMsgByEvent(Events.Player_Move) end) end jin.core.onEvent = function(e) if e.type == "quit" then - jin.core.stop() - elseif e.type == "keydown" then + jin.core.stop() elseif e.type == "keydown" then if e.key == "Escape" then jin.core.stop() end @@ -53,8 +82,6 @@ end jin.core.onUpdate = function(dt) _G["frame"] = _G["frame"] + 1 timer.update(dt) - - -- loghelper.log(loghelper.LEVEL.WARN, "版本" .. jin.revision()) end jin.core.onDraw = function() |