fix: yield inside wedge rasteriser and between wedges; only redraw ball each spin frame
This commit is contained in:
@@ -181,8 +181,12 @@ local function drawWedge(slotIdx, rotorAngle, glowing)
|
|||||||
local by1 = math.ceil(CY + ro) + 1
|
local by1 = math.ceil(CY + ro) + 1
|
||||||
|
|
||||||
-- Normalise angle range to handle wrap-around
|
-- Normalise angle range to handle wrap-around
|
||||||
-- We scan row by row and fill runs for speed
|
-- We scan row by row and fill runs for speed.
|
||||||
|
-- Yield every 32 rows so CC:Tweaked doesn't kill us.
|
||||||
|
local rowCount = 0
|
||||||
for sy = by0, by1 do
|
for sy = by0, by1 do
|
||||||
|
rowCount = rowCount + 1
|
||||||
|
if rowCount % 32 == 0 then sleep(0) end
|
||||||
local runStart = nil
|
local runStart = nil
|
||||||
for sx = bx0, bx1 do
|
for sx = bx0, bx1 do
|
||||||
local dx = sx - CX
|
local dx = sx - CX
|
||||||
@@ -228,6 +232,8 @@ end
|
|||||||
local function drawAllWedges(rotorAngle, glowSlot)
|
local function drawAllWedges(rotorAngle, glowSlot)
|
||||||
for i = 1, NUM_POCKETS do
|
for i = 1, NUM_POCKETS do
|
||||||
drawWedge(i, rotorAngle, i == glowSlot)
|
drawWedge(i, rotorAngle, i == glowSlot)
|
||||||
|
-- yield between wedges so CC doesn't kill us during init
|
||||||
|
sleep(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -360,10 +366,10 @@ local function spin()
|
|||||||
ballR = (R_OUTER - 6 + R_POCKET_OUT + 2) / 2 * (1 - t) + R_SETTLE * t
|
ballR = (R_OUTER - 6 + R_POCKET_OUT + 2) / 2 * (1 - t) + R_SETTLE * t
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw frame
|
-- Erase old ball, draw new ball.
|
||||||
drawWheelStatic(rotorAngle, nil)
|
-- Repaint a small circle at the old position with the track colour,
|
||||||
|
-- then draw the ball at the new position.
|
||||||
-- Erase old ball area by redrawing wheel under it (handled by full redraw above)
|
px_circle(ballX, ballY, BALL_RADIUS + 3, COL_TRACK)
|
||||||
local bx, by = ballPosAt(ballR, ballAngle)
|
local bx, by = ballPosAt(ballR, ballAngle)
|
||||||
drawBallAt(bx, by)
|
drawBallAt(bx, by)
|
||||||
gpu.sync()
|
gpu.sync()
|
||||||
@@ -407,17 +413,17 @@ end
|
|||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
local function glowAnimation(slotIdx)
|
local function glowAnimation(slotIdx)
|
||||||
|
local R_SETTLE = (R_POCKET_IN + R_POCKET_OUT) / 2
|
||||||
|
local sa = slotAngle(slotIdx, rotorAngle)
|
||||||
|
local bx, by = ballPosAt(R_SETTLE, sa)
|
||||||
for flash = 1, 6 do
|
for flash = 1, 6 do
|
||||||
drawWheelStatic(rotorAngle, flash % 2 == 1 and slotIdx or nil)
|
drawWedge(slotIdx, rotorAngle, flash % 2 == 1)
|
||||||
local sa = slotAngle(slotIdx, rotorAngle)
|
|
||||||
local bx, by = ballPosAt((R_POCKET_IN + R_POCKET_OUT) / 2, sa)
|
|
||||||
drawBallAt(bx, by)
|
drawBallAt(bx, by)
|
||||||
gpu.sync()
|
gpu.sync()
|
||||||
sleep(0.18)
|
sleep(0.18)
|
||||||
end
|
end
|
||||||
drawWheelStatic(rotorAngle, slotIdx)
|
-- Leave glowing
|
||||||
local sa = slotAngle(slotIdx, rotorAngle)
|
drawWedge(slotIdx, rotorAngle, true)
|
||||||
local bx, by = ballPosAt((R_POCKET_IN + R_POCKET_OUT) / 2, sa)
|
|
||||||
drawBallAt(bx, by)
|
drawBallAt(bx, by)
|
||||||
gpu.sync()
|
gpu.sync()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user