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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
_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")
_G["frame"] = 0
local thread = nil
local socket = nil
jin.core.onLoad = function()
---- 网络测试
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)
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()
log.info(_G["frame"] .. "fps")
-- EventMsgCenter.sendMsg(Events.Player_Move, _G["frame"])
_G["frame"] = 0
end)
timer.after(4.0, function()
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
if e.key == "Escape" then
jin.core.stop()
end
end
end
jin.core.onUpdate = function(dt)
_G["frame"] = _G["frame"] + 1
timer.update(dt)
end
jin.core.onDraw = function()
end
|