diff --git a/.vscode/settings.json b/.vscode/settings.json index 9e5718a..bf7332a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,6 +13,8 @@ "downscaling", "DPMM", "executables", + "framebuffer", + "framebuffers", "Fullscreen", "goarch", "gridify", diff --git a/files/capture.lua b/files/capture.lua index f28e621..edbc332 100644 --- a/files/capture.lua +++ b/files/capture.lua @@ -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. diff --git a/init.lua b/init.lua index 2c1b484..41309c0 100644 --- a/init.lua +++ b/init.lua @@ -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.