整理代码,微调debug模式输出点击位置的格式和widget模块的一个方法名

This commit is contained in:
MrZ626
2021-03-17 13:51:49 +08:00
parent 210e602057
commit 7ec1688825
4 changed files with 107 additions and 111 deletions

View File

@@ -106,28 +106,27 @@ function love.mousepressed(x,y,k,touch)
mouseShow=true
mx,my=xOy:inverseTransformPoint(x,y)
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-lastX,my-lastY,
int(mx/10)*10,int(my/10)*10,
int((mx-lastX)/10)*10,int((my-lastY)/10)*10
))
end
if not SCN.swapping then
if SCN.mouseDown then
SCN.mouseDown(mx,my,k)
elseif k==2 then
SCN.back()
end
if k==1 then
WIDGET.press(mx,my)
end
lastX,lastY=mx,my
SYSFX.newTap(3,mx,my,30)
if SCN.swapping then return end
if SCN.mouseDown then
SCN.mouseDown(mx,my,k)
elseif k==2 then
SCN.back()
end
if k==1 then
WIDGET.press(mx,my)
end
lastX,lastY=mx,my
SYSFX.newTap(3,mx,my,30)
end
function love.mousemoved(x,y,dx,dy,t)
if t then return end
function love.mousemoved(x,y,dx,dy,touch)
if touch then return end
mouseShow=true
mx,my=xOy:inverseTransformPoint(x,y)
if SCN.swapping then return end
@@ -136,16 +135,15 @@ function love.mousemoved(x,y,dx,dy,t)
if ms.isDown(1) then
WIDGET.drag(mx,my,dx,dy)
else
WIDGET.moveCursor(mx,my)
WIDGET.cursorMove(mx,my)
end
end
function love.mousereleased(x,y,k,touch)
if touch or SCN.swapping then return end
mx,my=xOy:inverseTransformPoint(x,y)
WIDGET.release(mx,my)
WIDGET.moveCursor(mx,my)
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)
end
end
@@ -175,7 +173,7 @@ function love.touchmoved(id,x,y,dx,dy)
WIDGET.drag(x,y,dx,dy)
end
else
WIDGET.moveCursor(x,y)
WIDGET.cursorMove(x,y)
if not WIDGET.sel then
touching=false
end

View File

@@ -1,143 +1,141 @@
local clock = os.clock
local clock=os.clock
local profile = {}
local profile={}
local _labeled = {} -- function labels
local _defined = {} -- function definitions
local _tcalled = {} -- time of last call
local _telapsed = {}-- total execution time
local _ncalls = {} -- number of calls
local _internal = {}-- list of internal profiler functions
local _labeled={} -- function labels
local _defined={} -- function definitions
local _tcalled={} -- time of last call
local _telapsed={}-- total execution time
local _ncalls={} -- number of calls
local _internal={}-- list of internal profiler functions
local getInfo = debug.getinfo
function profile.hooker(event, line, info)
info = info or getInfo(2, 'fnS')
local f = info.func
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
local getInfo=debug.getinfo
function profile.hooker(event,line,info)
info=info or getInfo(2,"fnS")
local f=info.func
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
-- find the line definition
if not _defined[f] then
_defined[f] = info.short_src .. ":" .. info.linedefined
_ncalls[f] = 0
_telapsed[f] = 0
if not _defined[f]then
_defined[f]=info.short_src..":"..info.linedefined
_ncalls[f]=0
_telapsed[f]=0
end
if _tcalled[f] then
local dt = clock() - _tcalled[f]
_telapsed[f] = _telapsed[f] + dt
_tcalled[f] = nil
if _tcalled[f]then
local dt=clock()-_tcalled[f]
_telapsed[f]=_telapsed[f]+dt
_tcalled[f]=nil
end
if event == "tail call" then
local prev = getInfo(3, 'fnS')
profile.hooker("return", line, prev)
profile.hooker("call", line, info)
elseif event == 'call' then
_tcalled[f] = clock()
if event=="tail call"then
local prev=getInfo(3,"fnS")
profile.hooker("return",line,prev)
profile.hooker("call",line,info)
elseif event=="call"then
_tcalled[f]=clock()
else
_ncalls[f] = _ncalls[f] + 1
_ncalls[f]=_ncalls[f]+1
end
end
--- Starts collecting data.
function profile.start()
if rawget(_G, 'jit') then
if jit then
jit.off()
jit.flush()
end
debug.sethook(profile.hooker, "cr")
debug.sethook(profile.hooker,"cr")
end
--- Stops collecting data.
function profile.stop()
debug.sethook()
for f in next, _tcalled do
local dt = clock() - _tcalled[f]
_telapsed[f] = _telapsed[f] + dt
_tcalled[f] = nil
for f in next,_tcalled do
local dt=clock()-_tcalled[f]
_telapsed[f]=_telapsed[f]+dt
_tcalled[f]=nil
end
-- merge closures
local lookup = {}
for f, d in next, _defined do
local id = (_labeled[f] or '?') .. d
local f2 = lookup[id]
local lookup={}
for f,d in next,_defined do
local id=(_labeled[f]or"?")..d
local f2=lookup[id]
if f2 then
_ncalls[f2] = _ncalls[f2] + (_ncalls[f] or 0)
_telapsed[f2] = _telapsed[f2] + (_telapsed[f] or 0)
_defined[f], _labeled[f] = nil, nil
_ncalls[f], _telapsed[f] = nil, nil
_ncalls[f2]=_ncalls[f2]+(_ncalls[f]or 0)
_telapsed[f2]=_telapsed[f2]+(_telapsed[f]or 0)
_defined[f],_labeled[f]=nil,nil
_ncalls[f],_telapsed[f]=nil,nil
else
lookup[id] = f
lookup[id]=f
end
end
collectgarbage('collect')
collectgarbage("collect")
end
--- Resets all collected data.
function profile.reset()
for f in next, _ncalls do
_ncalls[f] = 0
_telapsed[f] = 0
_tcalled[f] = nil
for f in next,_ncalls do
_ncalls[f]=0
_telapsed[f]=0
_tcalled[f]=nil
end
collectgarbage('collect')
collectgarbage("collect")
end
function profile.comp(a, b)
local dt = _telapsed[b] - _telapsed[a]
return dt == 0 and _ncalls[b] < _ncalls[a] or dt < 0
local function _comp(a,b)
local dt=_telapsed[b]-_telapsed[a]
return dt==0 and _ncalls[b]<_ncalls[a]or dt<0
end
--- Iterates all functions that have been called since the profile was started.
function profile.query(limit)
local t = {}
for f, n in next, _ncalls do
if n > 0 then
t[#t + 1] = f
local t={}
for f,n in next,_ncalls do
if n>0 then
t[#t+1]=f
end
end
table.sort(t, profile.comp)
if limit then
while #t > limit do
table.remove(t)
table.sort(t,_comp)
if limit then while #t>limit do table.remove(t)end end
for i,f in ipairs(t)do
local dt=0
if _tcalled[f]then
dt=clock()-_tcalled[f]
end
end
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]}
t[i]={i,_labeled[f]or"?",math.floor((_telapsed[f]+dt)*1e6)/1e6,_ncalls[f],_defined[f]}
end
return t
end
local cols = {3, 20, 8, 6, 32}
local cols={3,20,8,6,32}
function profile.report(n)
local out = {}
local report = profile.query(n)
for i, row in ipairs(report) do
for j = 1, 5 do
local s = tostring(row[j])
local l1, l2 = #s, cols[j]
if l1 < l2 then
s = s .. (' '):rep(l2 - l1)
elseif l1 > l2 then
s = s:sub(l1 - l2 + 1, l1)
local out={}
local report=profile.query(n)
for i,row in ipairs(report)do
for j=1,5 do
local s=tostring(row[j])
local l1,l2=#s,cols[j]
if l1<l2 then
s=s..(" "):rep(l2-l1)
elseif l1>l2 then
s=s:sub(l1-l2+1,l1)
end
row[j] = s
row[j]=s
end
out[i] = table.concat(row, ' | ')
out[i]=table.concat(row," | ")
end
local row = " +-----+----------------------+----------+--------+----------------------------------+ \n"
local col = " | # | Function | Time | Calls | Code | \n"
local sz = row .. col .. row
if #out > 0 then
sz = sz .. ' | ' .. table.concat(out, ' | \n | ') .. ' | \n'
local row=" +-----+----------------------+----------+--------+----------------------------------+ \n"
local col=" | # | Function | Time | Calls | Code | \n"
local sz=row..col..row
if #out>0 then
sz=sz.." | "..table.concat(out," | \n | ").." | \n"
end
return '\n' .. sz .. row
return"\n"..sz..row
end
local switch = false
local switch=false
function profile.switch()
if switch then
profile.stop()
@@ -148,12 +146,12 @@ function profile.switch()
PROFILE.start()
LOG.print("profile start!")
end
switch = not switch
switch=not switch
end
-- store all internal profiler functions
for _, v in next, profile do
_internal[v] = type(v) == "function"
for _,v in next,profile do
_internal[v]=type(v)=="function"
end
return profile

View File

@@ -1002,7 +1002,7 @@ function WIDGET.setLang(widgetText)
end
end
function WIDGET.moveCursor(x,y)
function WIDGET.cursorMove(x,y)
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
WIDGET.sel=W

View File

@@ -1198,7 +1198,7 @@ do
end
createRoom:
if res.message=="OK" then
if res.message=="OK"then
LOG.print(text.createRoomSuccessed)
enterRoom(res.room.id)
else