整理代码,微调debug模式输出点击位置的格式和widget模块的一个方法名
This commit is contained in:
@@ -106,28 +106,27 @@ function love.mousepressed(x,y,k,touch)
|
|||||||
mouseShow=true
|
mouseShow=true
|
||||||
mx,my=xOy:inverseTransformPoint(x,y)
|
mx,my=xOy:inverseTransformPoint(x,y)
|
||||||
if devMode==1 then
|
if devMode==1 then
|
||||||
DBP(("(%d,%d), D=(%d,%d)~~(%d,%d)(%d,%d)"):format(
|
DBP(("(%d,%d)<-%d,%d ~~(%d,%d)<-%d,%d"):format(
|
||||||
mx,my,
|
mx,my,
|
||||||
mx-lastX,my-lastY,
|
mx-lastX,my-lastY,
|
||||||
int(mx/10)*10,int(my/10)*10,
|
int(mx/10)*10,int(my/10)*10,
|
||||||
int((mx-lastX)/10)*10,int((my-lastY)/10)*10
|
int((mx-lastX)/10)*10,int((my-lastY)/10)*10
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
if not SCN.swapping then
|
if SCN.swapping then return end
|
||||||
if SCN.mouseDown then
|
if SCN.mouseDown then
|
||||||
SCN.mouseDown(mx,my,k)
|
SCN.mouseDown(mx,my,k)
|
||||||
elseif k==2 then
|
elseif k==2 then
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
|
||||||
if k==1 then
|
|
||||||
WIDGET.press(mx,my)
|
|
||||||
end
|
|
||||||
lastX,lastY=mx,my
|
|
||||||
SYSFX.newTap(3,mx,my,30)
|
|
||||||
end
|
end
|
||||||
|
if k==1 then
|
||||||
|
WIDGET.press(mx,my)
|
||||||
|
end
|
||||||
|
lastX,lastY=mx,my
|
||||||
|
SYSFX.newTap(3,mx,my,30)
|
||||||
end
|
end
|
||||||
function love.mousemoved(x,y,dx,dy,t)
|
function love.mousemoved(x,y,dx,dy,touch)
|
||||||
if t then return end
|
if touch then return end
|
||||||
mouseShow=true
|
mouseShow=true
|
||||||
mx,my=xOy:inverseTransformPoint(x,y)
|
mx,my=xOy:inverseTransformPoint(x,y)
|
||||||
if SCN.swapping then return end
|
if SCN.swapping then return end
|
||||||
@@ -136,16 +135,15 @@ function love.mousemoved(x,y,dx,dy,t)
|
|||||||
if ms.isDown(1) then
|
if ms.isDown(1) then
|
||||||
WIDGET.drag(mx,my,dx,dy)
|
WIDGET.drag(mx,my,dx,dy)
|
||||||
else
|
else
|
||||||
WIDGET.moveCursor(mx,my)
|
WIDGET.cursorMove(mx,my)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function love.mousereleased(x,y,k,touch)
|
function love.mousereleased(x,y,k,touch)
|
||||||
if touch or SCN.swapping then return end
|
if touch or SCN.swapping then return end
|
||||||
mx,my=xOy:inverseTransformPoint(x,y)
|
mx,my=xOy:inverseTransformPoint(x,y)
|
||||||
WIDGET.release(mx,my)
|
WIDGET.release(mx,my)
|
||||||
WIDGET.moveCursor(mx,my)
|
|
||||||
if SCN.mouseUp then SCN.mouseUp(mx,my,k)end
|
if SCN.mouseUp then SCN.mouseUp(mx,my,k)end
|
||||||
if lastX and SCN.mouseClick and(mx-lastX)^2+(my-lastY)^2<42 then
|
if lastX and SCN.mouseClick and(mx-lastX)^2+(my-lastY)^2<62 then
|
||||||
SCN.mouseClick(mx,my,k)
|
SCN.mouseClick(mx,my,k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -175,7 +173,7 @@ function love.touchmoved(id,x,y,dx,dy)
|
|||||||
WIDGET.drag(x,y,dx,dy)
|
WIDGET.drag(x,y,dx,dy)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WIDGET.moveCursor(x,y)
|
WIDGET.cursorMove(x,y)
|
||||||
if not WIDGET.sel then
|
if not WIDGET.sel then
|
||||||
touching=false
|
touching=false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,143 +1,141 @@
|
|||||||
local clock = os.clock
|
local clock=os.clock
|
||||||
|
|
||||||
local profile = {}
|
local profile={}
|
||||||
|
|
||||||
local _labeled = {} -- function labels
|
local _labeled={} -- function labels
|
||||||
local _defined = {} -- function definitions
|
local _defined={} -- function definitions
|
||||||
local _tcalled = {} -- time of last call
|
local _tcalled={} -- time of last call
|
||||||
local _telapsed = {}-- total execution time
|
local _telapsed={}-- total execution time
|
||||||
local _ncalls = {} -- number of calls
|
local _ncalls={} -- number of calls
|
||||||
local _internal = {}-- list of internal profiler functions
|
local _internal={}-- list of internal profiler functions
|
||||||
|
|
||||||
local getInfo = debug.getinfo
|
local getInfo=debug.getinfo
|
||||||
function profile.hooker(event, line, info)
|
function profile.hooker(event,line,info)
|
||||||
info = info or getInfo(2, 'fnS')
|
info=info or getInfo(2,"fnS")
|
||||||
local f = info.func
|
local f=info.func
|
||||||
if _internal[f] then return end-- ignore the profiler itself
|
if _internal[f]then return end-- ignore the profiler itself
|
||||||
if info.name then _labeled[f] = info.name end-- get the function name if available
|
if info.name then _labeled[f]=info.name end-- get the function name if available
|
||||||
-- find the line definition
|
-- find the line definition
|
||||||
if not _defined[f] then
|
if not _defined[f]then
|
||||||
_defined[f] = info.short_src .. ":" .. info.linedefined
|
_defined[f]=info.short_src..":"..info.linedefined
|
||||||
_ncalls[f] = 0
|
_ncalls[f]=0
|
||||||
_telapsed[f] = 0
|
_telapsed[f]=0
|
||||||
end
|
end
|
||||||
if _tcalled[f] then
|
if _tcalled[f]then
|
||||||
local dt = clock() - _tcalled[f]
|
local dt=clock()-_tcalled[f]
|
||||||
_telapsed[f] = _telapsed[f] + dt
|
_telapsed[f]=_telapsed[f]+dt
|
||||||
_tcalled[f] = nil
|
_tcalled[f]=nil
|
||||||
end
|
end
|
||||||
if event == "tail call" then
|
if event=="tail call"then
|
||||||
local prev = getInfo(3, 'fnS')
|
local prev=getInfo(3,"fnS")
|
||||||
profile.hooker("return", line, prev)
|
profile.hooker("return",line,prev)
|
||||||
profile.hooker("call", line, info)
|
profile.hooker("call",line,info)
|
||||||
elseif event == 'call' then
|
elseif event=="call"then
|
||||||
_tcalled[f] = clock()
|
_tcalled[f]=clock()
|
||||||
else
|
else
|
||||||
_ncalls[f] = _ncalls[f] + 1
|
_ncalls[f]=_ncalls[f]+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Starts collecting data.
|
--- Starts collecting data.
|
||||||
function profile.start()
|
function profile.start()
|
||||||
if rawget(_G, 'jit') then
|
if jit then
|
||||||
jit.off()
|
jit.off()
|
||||||
jit.flush()
|
jit.flush()
|
||||||
end
|
end
|
||||||
debug.sethook(profile.hooker, "cr")
|
debug.sethook(profile.hooker,"cr")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Stops collecting data.
|
--- Stops collecting data.
|
||||||
function profile.stop()
|
function profile.stop()
|
||||||
debug.sethook()
|
debug.sethook()
|
||||||
for f in next, _tcalled do
|
for f in next,_tcalled do
|
||||||
local dt = clock() - _tcalled[f]
|
local dt=clock()-_tcalled[f]
|
||||||
_telapsed[f] = _telapsed[f] + dt
|
_telapsed[f]=_telapsed[f]+dt
|
||||||
_tcalled[f] = nil
|
_tcalled[f]=nil
|
||||||
end
|
end
|
||||||
-- merge closures
|
-- merge closures
|
||||||
local lookup = {}
|
local lookup={}
|
||||||
for f, d in next, _defined do
|
for f,d in next,_defined do
|
||||||
local id = (_labeled[f] or '?') .. d
|
local id=(_labeled[f]or"?")..d
|
||||||
local f2 = lookup[id]
|
local f2=lookup[id]
|
||||||
if f2 then
|
if f2 then
|
||||||
_ncalls[f2] = _ncalls[f2] + (_ncalls[f] or 0)
|
_ncalls[f2]=_ncalls[f2]+(_ncalls[f]or 0)
|
||||||
_telapsed[f2] = _telapsed[f2] + (_telapsed[f] or 0)
|
_telapsed[f2]=_telapsed[f2]+(_telapsed[f]or 0)
|
||||||
_defined[f], _labeled[f] = nil, nil
|
_defined[f],_labeled[f]=nil,nil
|
||||||
_ncalls[f], _telapsed[f] = nil, nil
|
_ncalls[f],_telapsed[f]=nil,nil
|
||||||
else
|
else
|
||||||
lookup[id] = f
|
lookup[id]=f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
collectgarbage('collect')
|
collectgarbage("collect")
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Resets all collected data.
|
--- Resets all collected data.
|
||||||
function profile.reset()
|
function profile.reset()
|
||||||
for f in next, _ncalls do
|
for f in next,_ncalls do
|
||||||
_ncalls[f] = 0
|
_ncalls[f]=0
|
||||||
_telapsed[f] = 0
|
_telapsed[f]=0
|
||||||
_tcalled[f] = nil
|
_tcalled[f]=nil
|
||||||
end
|
end
|
||||||
collectgarbage('collect')
|
collectgarbage("collect")
|
||||||
end
|
end
|
||||||
|
|
||||||
function profile.comp(a, b)
|
local function _comp(a,b)
|
||||||
local dt = _telapsed[b] - _telapsed[a]
|
local dt=_telapsed[b]-_telapsed[a]
|
||||||
return dt == 0 and _ncalls[b] < _ncalls[a] or dt < 0
|
return dt==0 and _ncalls[b]<_ncalls[a]or dt<0
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Iterates all functions that have been called since the profile was started.
|
--- Iterates all functions that have been called since the profile was started.
|
||||||
function profile.query(limit)
|
function profile.query(limit)
|
||||||
local t = {}
|
local t={}
|
||||||
for f, n in next, _ncalls do
|
for f,n in next,_ncalls do
|
||||||
if n > 0 then
|
if n>0 then
|
||||||
t[#t + 1] = f
|
t[#t+1]=f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(t, profile.comp)
|
table.sort(t,_comp)
|
||||||
if limit then
|
|
||||||
while #t > limit do
|
if limit then while #t>limit do table.remove(t)end end
|
||||||
table.remove(t)
|
|
||||||
|
for i,f in ipairs(t)do
|
||||||
|
local dt=0
|
||||||
|
if _tcalled[f]then
|
||||||
|
dt=clock()-_tcalled[f]
|
||||||
end
|
end
|
||||||
end
|
t[i]={i,_labeled[f]or"?",math.floor((_telapsed[f]+dt)*1e6)/1e6,_ncalls[f],_defined[f]}
|
||||||
for i, f in ipairs(t) do
|
|
||||||
local dt = 0
|
|
||||||
if _tcalled[f] then
|
|
||||||
dt = clock() - _tcalled[f]
|
|
||||||
end
|
|
||||||
t[i] = {i, _labeled[f] or '?', math.floor((_telapsed[f] + dt) * 1e6) / 1e6, _ncalls[f], _defined[f]}
|
|
||||||
end
|
end
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local cols = {3, 20, 8, 6, 32}
|
local cols={3,20,8,6,32}
|
||||||
function profile.report(n)
|
function profile.report(n)
|
||||||
local out = {}
|
local out={}
|
||||||
local report = profile.query(n)
|
local report=profile.query(n)
|
||||||
for i, row in ipairs(report) do
|
for i,row in ipairs(report)do
|
||||||
for j = 1, 5 do
|
for j=1,5 do
|
||||||
local s = tostring(row[j])
|
local s=tostring(row[j])
|
||||||
local l1, l2 = #s, cols[j]
|
local l1,l2=#s,cols[j]
|
||||||
if l1 < l2 then
|
if l1<l2 then
|
||||||
s = s .. (' '):rep(l2 - l1)
|
s=s..(" "):rep(l2-l1)
|
||||||
elseif l1 > l2 then
|
elseif l1>l2 then
|
||||||
s = s:sub(l1 - l2 + 1, l1)
|
s=s:sub(l1-l2+1,l1)
|
||||||
end
|
end
|
||||||
row[j] = s
|
row[j]=s
|
||||||
end
|
end
|
||||||
out[i] = table.concat(row, ' | ')
|
out[i]=table.concat(row," | ")
|
||||||
end
|
end
|
||||||
|
|
||||||
local row = " +-----+----------------------+----------+--------+----------------------------------+ \n"
|
local row=" +-----+----------------------+----------+--------+----------------------------------+ \n"
|
||||||
local col = " | # | Function | Time | Calls | Code | \n"
|
local col=" | # | Function | Time | Calls | Code | \n"
|
||||||
local sz = row .. col .. row
|
local sz=row..col..row
|
||||||
if #out > 0 then
|
if #out>0 then
|
||||||
sz = sz .. ' | ' .. table.concat(out, ' | \n | ') .. ' | \n'
|
sz=sz.." | "..table.concat(out," | \n | ").." | \n"
|
||||||
end
|
end
|
||||||
return '\n' .. sz .. row
|
return"\n"..sz..row
|
||||||
end
|
end
|
||||||
|
|
||||||
local switch = false
|
local switch=false
|
||||||
function profile.switch()
|
function profile.switch()
|
||||||
if switch then
|
if switch then
|
||||||
profile.stop()
|
profile.stop()
|
||||||
@@ -148,12 +146,12 @@ function profile.switch()
|
|||||||
PROFILE.start()
|
PROFILE.start()
|
||||||
LOG.print("profile start!")
|
LOG.print("profile start!")
|
||||||
end
|
end
|
||||||
switch = not switch
|
switch=not switch
|
||||||
end
|
end
|
||||||
|
|
||||||
-- store all internal profiler functions
|
-- store all internal profiler functions
|
||||||
for _, v in next, profile do
|
for _,v in next,profile do
|
||||||
_internal[v] = type(v) == "function"
|
_internal[v]=type(v)=="function"
|
||||||
end
|
end
|
||||||
|
|
||||||
return profile
|
return profile
|
||||||
|
|||||||
@@ -1002,7 +1002,7 @@ function WIDGET.setLang(widgetText)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function WIDGET.moveCursor(x,y)
|
function WIDGET.cursorMove(x,y)
|
||||||
for _,W in next,WIDGET.active do
|
for _,W in next,WIDGET.active do
|
||||||
if not(W.hide==true or W.hide and W.hide())and W.resCtr and W:isAbove(x,y)then
|
if not(W.hide==true or W.hide and W.hide())and W.resCtr and W:isAbove(x,y)then
|
||||||
WIDGET.sel=W
|
WIDGET.sel=W
|
||||||
|
|||||||
@@ -1198,7 +1198,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
createRoom:
|
createRoom:
|
||||||
if res.message=="OK" then
|
if res.message=="OK"then
|
||||||
LOG.print(text.createRoomSuccessed)
|
LOG.print(text.createRoomSuccessed)
|
||||||
enterRoom(res.room.id)
|
enterRoom(res.room.id)
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user