Skip to content

Commit

Permalink
Celeste render no longer prepares canvases in draw
Browse files Browse the repository at this point in the history
Added delayProcessing helper to tasks
Fixed copy paste mistake in tasks statistic variables
  • Loading branch information
Cruor committed Oct 11, 2019
1 parent b8358e9 commit b95d9e2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
36 changes: 20 additions & 16 deletions src/celeste_render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -572,26 +572,32 @@ local function drawRoomFromBatches(room, viewport, selected)
end
end

-- Return the canvas if it is ready, otherwise make a task for it
local function getRoomCanvas(room, viewport, selected)
roomCache[room.name] = roomCache[room.name] or {}
local orderedBatches = celesteRender.getRoomBatches(room, viewport)

if not roomCache[room.name].canvas then
local orderedBatches = celesteRender.getRoomBatches(room, viewport)
roomCache[room.name] = roomCache[room.name] or {}

if orderedBatches then
local canvas = love.graphics.newCanvas(room.width or 0, room.height or 0)
if orderedBatches and not roomCache[room.name].canvas then
roomCache[room.name].canvas = tasks.newTask(
function(task)
local canvas = love.graphics.newCanvas(room.width or 0, room.height or 0)

canvas:renderTo(function()
for depth, batch <- orderedBatches do
batch:draw()
end
end)

roomCache[room.name].canvas = canvas
end
canvas:renderTo(function()
for depth, batch <- orderedBatches do
batch:draw()
end
end)

tasks.update(canvas)
end,
nil,
batchingTasks,
{room = room}
)
end

return roomCache[room.name].canvas
return roomCache[room.name].canvas and roomCache[room.name].canvas.result
end

function celesteRender.drawRoom(room, viewport, selected)
Expand Down Expand Up @@ -646,8 +652,6 @@ function celesteRender.drawFiller(filler, viewport)
end)
end

-- TODO - Move canvas rendering operations into a update function
-- Currently it visually breaks wipes, and shouldn't be in the render function regardless
function celesteRender.drawMap(state)
if state.map then
local map = state.map
Expand Down
2 changes: 0 additions & 2 deletions src/loaded_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ function state.loadFile(filename)
end
)

print("Loaded binary data")

else
-- TODO - Toast the user, failed to load
end
Expand Down
47 changes: 31 additions & 16 deletions src/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,42 @@ function tasksHandler.update(...)
coroutine.yield("update", ...)
end

function tasksHandler.delayProcessing()
coroutine.yield("delayProcessing")
end

-- Returns completion status, if the process needs to wait for a different process, and the time it spent processing
function tasksHandler.processTask(task, time)
local timeSpent = 0
local calcTime = time or math.huge

while coroutine.status(task.coroutine) ~= "dead" do
local waiting = waitingForResume[task] and waitingForResume[task] > 0

-- Can't process if we are over the time limit, or waiting for another task
if timeSpent >= calcTime or waitingForResume[task] then
if timeSpent >= calcTime or waiting then
task.processedCount += 1

return false, timeSpent
return false, waiting, timeSpent
end

local start = love.timer.getTime()
local success, status, res = coroutine.resume(task.coroutine, task)

if success then
if status == "waitFor" then
task.processedYieldCount = 0
task.processedYieldCount += 1
task.processedWaitingCount += 1

addWaitingFor(task, res)

elseif status == "update" then
task.result = res

elseif status == "delayProcessing" then
task.processedWaitingCount += 1

return false, true, timeSpent
end

else
Expand All @@ -100,7 +113,7 @@ function tasksHandler.processTask(task, time)

task:callback()

return true, timeSpent
return true, false, timeSpent
end

-- Processes tasks from table for at around calcTime (default until done) and atmost maxTasks (default all)
Expand All @@ -118,29 +131,27 @@ function tasksHandler.processTasks(time, maxTasks, customTasks)

while #tasks > 0 and tasksDone < tasksAllowed and timeSpent < calcTime do
local task = tasks[taskIndex]
local finished, delayProcessing, taskTime = tasksHandler.processTask(task, calcTime - timeSpent)

timeSpent += taskTime

if waitingForResume[task] then
if delayProcessing then
local lastIndex = taskIndex
taskIndex = utils.mod1(taskIndex + 1, #tasks)

-- If this doesn't update the index then we should exit out, there are no tasks ready to run
if lastIndex == taskIndex then
break
end
end

else
local finished, taskTime = tasksHandler.processTask(task, calcTime - timeSpent)

timeSpent += taskTime

if finished then
table.remove(tasks, taskIndex)
updateWaitingForTaskDone(task)
if finished then
table.remove(tasks, taskIndex)
updateWaitingForTaskDone(task)

tasksDone += 1
tasksDone += 1

taskIndex = utils.mod1(taskIndex, #tasks)
end
taskIndex = utils.mod1(taskIndex, #tasks)
end
end

Expand All @@ -163,6 +174,10 @@ function taskMt.__index:yield()
tasksHandler.yield()
end

function taskMt.__index:delayProcessing()
tasksHandler.delayProcessing()
end

taskMt.__index.process = tasksHandler.processTask

-- TODO - Unwrap lambda properly
Expand Down

0 comments on commit b95d9e2

Please sign in to comment.