Skip to content

Commit

Permalink
Move coroutine wakeup back into OnWorldPreUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadido3 committed Jan 5, 2024
1 parent d5cd88a commit 44605b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"downscaling",
"DPMM",
"executables",
"framebuffer",
"framebuffers",
"Fullscreen",
"goarch",
"gridify",
Expand Down
13 changes: 9 additions & 4 deletions files/capture.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
10 changes: 2 additions & 8 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 44605b9

Please sign in to comment.