整理代码

This commit is contained in:
MrZ626
2021-07-25 02:19:18 +08:00
parent 27cede0fad
commit 61946fe52e
4 changed files with 57 additions and 45 deletions

View File

@@ -45,7 +45,7 @@ THEME= require'Zframework.theme'
local ms,kb=love.mouse,love.keyboard
local gc=love.graphics
local gc_push,gc_pop,gc_clear=gc.push,gc.pop,gc.clear
local gc_push,gc_pop,gc_clear,gc_discard=gc.push,gc.pop,gc.clear,gc.discard
local gc_replaceTransform,gc_present=gc.replaceTransform,gc.present
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_draw,gc_line,gc_print=gc.draw,gc.line,gc.print
@@ -522,18 +522,21 @@ local cursor_holdImg=DOGC{16,16,
function love.run()
local love=love
local VOC,BG,SYSFX=VOC,BG,SYSFX
local TASK,TEXT=TASK,TEXT
local TEXTURE,TIME=TEXTURE,TIME
local SETTING,VERSION=SETTING,VERSION
local BG=BG
local TEXT_update,TEXT_draw=TEXT.update,TEXT.draw
local MES_update,MES_draw=MES.update,MES.draw
local WS_update=WS.update
local TASK_update=TASK.update
local SYSFX_update,SYSFX_draw=SYSFX.update,SYSFX.draw
local WIDGET_update,WIDGET_draw=WIDGET.update,WIDGET.draw
local STEP,WAIT=love.timer.step,love.timer.sleep
local FPS,MINI=love.timer.getFPS,love.window.isMinimized
local PUMP,POLL=love.event.pump,love.event.poll
local frameTimeList={}
local TIME,SETTING,VERSION=TIME,SETTING,VERSION
local frameTimeList={}
local lastFrame=TIME()
local lastFreshPow=lastFrame
local FCT=0--Framedraw counter, from 0~99
@@ -567,14 +570,14 @@ function love.run()
STEP()
VOC.update()
BG.update(dt)
TEXT.update()
MES.update(dt)
WS.update(dt)
TASK.update()
SYSFX.update(dt)
TEXT_update()
MES_update(dt)
WS_update(dt)
TASK_update()
SYSFX_update(dt)
if SCN.update then SCN.update(dt)end
if SCN.swapping then SCN.swapUpdate()end
WIDGET.update()
WIDGET_update()
--DRAW
if not MINI()then
@@ -582,14 +585,15 @@ function love.run()
if FCT>=100 then
FCT=FCT-100
local safeX=SCR.safeX
gc_replaceTransform(SCR.origin)
gc_setColor(1,1,1)
BG.draw()
gc_replaceTransform(SCR.xOy)
if SCN.draw then SCN.draw()end
WIDGET.draw()
SYSFX.draw()
TEXT.draw()
WIDGET_draw()
SYSFX_draw()
TEXT_draw()
--Draw cursor
if mouseShow then
@@ -602,12 +606,12 @@ function love.run()
gc_draw(ms.isDown(1)and cursor_holdImg or cursorImg,mx,my,nil,nil,nil,8,8)
end
gc_replaceTransform(SCR.xOy_ul)
MES.draw()
MES_draw()
gc_replaceTransform(SCR.origin)
--Draw power info.
if SETTING.powerInfo then
gc_setColor(1,1,1)
gc_draw(infoCanvas,SCR.safeX,0,0,SCR.k)
gc_draw(infoCanvas,safeX,0,0,SCR.k)
end
--Draw scene swapping animation
@@ -625,16 +629,16 @@ function love.run()
--Draw FPS
setFont(15)
gc_setColor(1,1,1)
gc_print(FPS(),SCR.safeX+5,-20)
gc_print(FPS(),safeX+5,-20)
--Debug info.
if devMode then
--Left-down infos
gc_setColor(devColor[devMode])
gc_print("MEM "..gcinfo(),SCR.safeX+5,-40)
gc_print("Lines "..FREEROW.getCount(),SCR.safeX+5,-60)
gc_print("Tasks "..TASK.getCount(),SCR.safeX+5,-80)
gc_print("Voices "..VOC.getQueueCount(),SCR.safeX+5,-100)
gc_print("MEM "..gcinfo(),safeX+5,-40)
gc_print("Lines "..FREEROW.getCount(),safeX+5,-60)
gc_print("Tasks "..TASK.getCount(),safeX+5,-80)
gc_print("Voices "..VOC.getQueueCount(),safeX+5,-100)
--Update & draw frame time
ins(frameTimeList,1,dt)rem(frameTimeList,126)
@@ -680,7 +684,7 @@ function love.run()
gc_present()
--SPEED UPUPUP!
if SETTING.cleanCanvas then gc.discard()end
if SETTING.cleanCanvas then gc_discard()end
end
end
@@ -696,8 +700,12 @@ function love.run()
end
--Slow devmode
if devMode==3 then WAIT(.1)
elseif devMode==4 then WAIT(.5)
if devMode then
if devMode==3 then
WAIT(.1)
elseif devMode==4 then
WAIT(.5)
end
end
--Keep 60fps

View File

@@ -488,17 +488,17 @@ do
list[i][12]=a;list[i][21]=b;list[i][32]=b;list[i][23]=a
end
BRS=TABLE.new(function(P,d,ifpre)
local cur=P.cur
local idir=(cur.dir+d)%4
local kickList=list[cur.id][cur.dir*10+idir]
local icb=BLOCKS[cur.id][idir]
local isc=SCS[cur.id][idir]
local ix,iy=P.curX+cur.sc[2]-isc[2],P.curY+cur.sc[1]-isc[1]
local C=P.cur
local idir=(C.dir+d)%4
local kickList=list[C.id][C.dir*10+idir]
local icb=BLOCKS[C.id][idir]
local isc=SCS[C.id][idir]
local ix,iy=P.curX+C.sc[2]-isc[2],P.curY+C.sc[1]-isc[1]
local dx,dy=0,0 do
local pressing=P.keyPressing
if pressing[1]and P:ifoverlap(cur.bk,P.curX-1,P.curY)then dx=dx-1 end
if pressing[2]and P:ifoverlap(cur.bk,P.curX+1,P.curY)then dx=dx+1 end
if pressing[7]and P:ifoverlap(cur.bk,P.curX,P.curY-1)then dy=-1 end
if pressing[1]and P:ifoverlap(C.bk,P.curX-1,P.curY)then dx=dx-1 end
if pressing[2]and P:ifoverlap(C.bk,P.curX+1,P.curY)then dx=dx+1 end
if pressing[7]and P:ifoverlap(C.bk,P.curX,P.curY-1)then dy=-1 end
end
while true do
for test=1,#kickList do
@@ -514,8 +514,8 @@ do
if P.gameEnv.moveFX and P.gameEnv.block then
P:createMoveFX()
end
P.curX,P.curY,cur.dir=x,y,idir
cur.sc,cur.bk=isc,icb
P.curX,P.curY,C.dir=x,y,idir
C.sc,C.bk=isc,icb
P.spinLast=test==2 and 0 or 1
local t=P.freshTime

View File

@@ -547,8 +547,9 @@ function draw.drawNext_norm(P)
gc_push('transform')
gc_translate(62,40)
gc_setShader(shader_blockSatur)
while N<=ENV.nextCount and P.nextQueue[N]do
local bk,sprite=P.nextQueue[N].bk,texture[P.nextQueue[N].color]
local queue=P.nextQueue
while N<=ENV.nextCount and queue[N]do
local bk,sprite=queue[N].bk,texture[queue[N].color]
local k=#bk>2 and 2.2/#bk or 1
gc_scale(k)
for i=1,#bk do for j=1,#bk[1]do
@@ -678,18 +679,19 @@ function draw.norm(P)
--Draw current block
if P.cur and P.waiting==-1 then
local curColor=P.cur.color
local C=P.cur
local curColor=C.color
local trans=P.lockDelay/ENV.lock
local centerX=30*(P.curX+P.cur.sc[2])-15
local centerX=30*(P.curX+C.sc[2])-15
--Draw ghost & rotation center
local centerDisp=ENV.center and P.RS.centerDisp[P.cur.id]
local centerDisp=ENV.center and P.RS.centerDisp[C.id]
if ENV.ghost then
drawGhost[ENV.ghostType](P,curColor,ENV.ghost)
if centerDisp then
gc_setColor(1,1,1,ENV.center)
gc_draw(spinCenterImg,centerX,-30*(P.ghoY+P.cur.sc[1])+15,nil,nil,nil,4,4)
gc_draw(spinCenterImg,centerX,-30*(P.ghoY+C.sc[1])+15,nil,nil,nil,4,4)
end
elseif GAME.replaying then
drawGhost.gray(P,nil,.15)
@@ -703,7 +705,7 @@ function draw.norm(P)
drawBlock(P,curColor)
if centerDisp then
gc_setColor(1,1,1,ENV.center)
gc_draw(spinCenterImg,centerX,-30*(P.curY+P.cur.sc[1])+15,nil,nil,nil,4,4)
gc_draw(spinCenterImg,centerX,-30*(P.curY+C.sc[1])+15,nil,nil,nil,4,4)
end
elseif GAME.replaying then
drawBlockShade(P,trans*.3)

View File

@@ -58,6 +58,8 @@ return STRING.split([=[
代码:
重构WS模块,可能解决部分联网游戏中的概率thread error问题
升级BGM/IMG/SKIN模块,资源不再需要启动时加载好,提升加载速度节约资源占用
优化游戏场景性能,移除回放按钮hideF函数
主循环略微优化
修复:
只有屏幕宽度异常时自动刷新窗口尺寸 #120
20G不会禁用各种软降n格键
@@ -70,7 +72,7 @@ return STRING.split([=[
触屏设置在窗口非默认长宽比时边缘网格缺失
有屏幕滚动的场景鼠标拖动时控件失焦
导入设置(包括剪切板和云存档)时部分设置不生效
小程序cubefield的碰撞判定移出draw解决低绘制帧率导致漏判定的问题 #138
小程序cubefield的碰撞判定移出draw,解决低绘制帧率导致漏判定的问题 #138
序列和任务超长导致渲染开销太大卡死 #137
0.15.6: 强化装甲 Reinforced Armor