summaryrefslogtreecommitdiff
path: root/main.lua
blob: 9c78c599081d9f99fff7466b732d46ce03bfd60f (plain)
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
require("global")
local loghelper = require("loghelper")
loghelper.strict(loghelper.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

jin.core.onLoad = function()
	thread = jin.thread.Thread("Test", [[
require("global")
local channels = require("channels")

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:start()
	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"])
		_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 
		if e.key == "Escape" then 
			jin.core.stop()
		end 
	end 
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() 

end