Move coroutine wakeup back into OnWorldPreUpdate

This commit is contained in:
David Vogel 2024-01-05 18:42:31 +01:00
parent d5cd88a30e
commit 44605b9633
3 changed files with 13 additions and 12 deletions

View File

@ -13,6 +13,8 @@
"downscaling",
"DPMM",
"executables",
"framebuffer",
"framebuffers",
"Fullscreen",
"goarch",
"gridify",

View File

@ -1,4 +1,4 @@
-- Copyright (c) 2019-2023 David Vogel
-- Copyright (c) 2019-2024 David Vogel
--
-- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT
@ -108,9 +108,13 @@ local function captureScreenshot(pos, ensureLoaded, dontOverwrite, ctx, outputPi
-- Suspend UI drawing for 1 frame.
UI:SuspendDrawing(1)
--wait(0)
-- First we wait one frame for the current state to be drawn.
wait(0)
-- At this point the needed frame is fully drawn, but the framebuffers are swapped.
-- Recalculate capture position and rectangle if we are not forcing any capture position.
-- We are in the `OnWorldPreUpdate` hook, this means that `CameraAPI.GetPos` return the position of the last frame.
if not pos then
topLeftCapture, bottomRightCapture, topLeftWorld, bottomRightWorld = calculateCaptureRectangle(pos)
if outputPixelScale > 0 then
@ -120,8 +124,9 @@ local function captureScreenshot(pos, ensureLoaded, dontOverwrite, ctx, outputPi
end
end
-- Wait for two frames.
wait(1)
-- Wait another frame.
-- After this `wait` the framebuffer will be swapped again, and we can grab the correct frame.
wait(0)
-- The top left world position needs to be upscaled by the pixel scale.
-- Otherwise it's not possible to stitch the images correctly.

View File

@ -1,4 +1,4 @@
-- Copyright (c) 2022 David Vogel
-- Copyright (c) 2022-2024 David Vogel
--
-- This software is released under the MIT License.
-- https://opensource.org/licenses/MIT
@ -109,19 +109,13 @@ end
function OnWorldPreUpdate()
Message:CatchException("OnWorldPreUpdate", function()
-- Coroutines aren't run every frame in this lua sandbox, do it manually here.
--wake_up_waiting_threads(1)
wake_up_waiting_threads(1)
end)
end
---Called *every* time the game has finished updating the world.
function OnWorldPostUpdate()
Message:CatchException("OnWorldPreUpdate", function()
-- Coroutines aren't run every frame in this lua sandbox, do it manually here.
wake_up_waiting_threads(1)
end)
Message:CatchException("OnWorldPostUpdate", function()
-- Reload mod every 60 frames.
-- This allows live updates to the mod while Noita is running.