From b95d9e28bc8c9741e1b229e18be36ae47ecf85b0 Mon Sep 17 00:00:00 2001 From: Cruor Date: Fri, 11 Oct 2019 13:23:14 +0200 Subject: [PATCH] Celeste render no longer prepares canvases in draw Added delayProcessing helper to tasks Fixed copy paste mistake in tasks statistic variables --- src/celeste_render.lua | 36 ++++++++++++++++++-------------- src/loaded_state.lua | 2 -- src/task.lua | 47 ++++++++++++++++++++++++++++-------------- 3 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/celeste_render.lua b/src/celeste_render.lua index dca8023b..58e861f8 100644 --- a/src/celeste_render.lua +++ b/src/celeste_render.lua @@ -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) @@ -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 diff --git a/src/loaded_state.lua b/src/loaded_state.lua index d8bc480f..625d1803 100644 --- a/src/loaded_state.lua +++ b/src/loaded_state.lua @@ -32,8 +32,6 @@ function state.loadFile(filename) end ) - print("Loaded binary data") - else -- TODO - Toast the user, failed to load end diff --git a/src/task.lua b/src/task.lua index 02a2d40a..1f760a89 100644 --- a/src/task.lua +++ b/src/task.lua @@ -54,16 +54,23 @@ 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() @@ -71,12 +78,18 @@ function tasksHandler.processTask(task, time) 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 @@ -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) @@ -118,8 +131,11 @@ 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) @@ -127,20 +143,15 @@ function tasksHandler.processTasks(time, maxTasks, customTasks) 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 @@ -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