Skip to content

Commit

Permalink
Update the Capture.dll
Browse files Browse the repository at this point in the history
- Increase hardcoded number of workers to 8.
- Export images temporarily, and then move them once they are fully exported. This prevents corrupt images.
  • Loading branch information
Dadido3 committed Feb 5, 2024
1 parent 9e51538 commit 15e2b88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions bin/capture-b/Capture.pb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Structure GLViewportDims
height.i
EndStructure

Structure WorkerInfo
workerNumber.i
EndStructure

; Returns the size of the main OpenGL rendering output.
ProcedureDLL GetGLViewportSize(*dims.GLViewportDims)
If Not *dims
Expand Down Expand Up @@ -57,12 +61,15 @@ ProcedureDLL AttachProcess(Instance)

CreateDirectory("mods/noita-mapcap/output/")

For i = 1 To 6
CreateThread(@Worker(), #Null)
Static Workers = 8
Dim WorkerInfos.WorkerInfo(Workers-1)
For i = 0 To Workers-1
WorkerInfos(i)\workerNumber = i
CreateThread(@Worker(), @WorkerInfos(i))
Next
EndProcedure

Procedure Worker(*Dummy)
Procedure Worker(*workerInfo.WorkerInfo)
Protected img, x, y

Repeat
Expand All @@ -82,8 +89,12 @@ Procedure Worker(*Dummy)
ResizeImage(img, sx, sy)
EndIf

SaveImage(img, "mods/noita-mapcap/output/" + x + "," + y + ".png", #PB_ImagePlugin_PNG)
;SaveImage(img, "" + x + "," + y + ".png", #PB_ImagePlugin_PNG) ; Test
; Save image temporary, and only move it once it's fully exported.
; This prevents images getting corrupted when the main process crashes.
If SaveImage(img, "mods/noita-mapcap/output/worker_" + *workerInfo\workerNumber + ".tmp", #PB_ImagePlugin_PNG)
RenameFile("mods/noita-mapcap/output/worker_" + *workerInfo\workerNumber + ".tmp", "mods/noita-mapcap/output/" + x + "," + y + ".png")
; We can't really do anything when either SaveImage or RenameFile fails, so just silently fail.
EndIf

FreeImage(img)
ForEver
Expand Down Expand Up @@ -171,11 +182,12 @@ EndProcedure

; IDE Options = PureBasic 6.04 LTS (Windows - x64)
; ExecutableFormat = Shared dll
; CursorPosition = 126
; FirstLine = 98
; CursorPosition = 94
; FirstLine = 51
; Folding = -
; Optimizer
; EnableThread
; EnableXP
; Executable = capture.dll
; Compiler = PureBasic 6.04 LTS (Windows - x86)
; DisableDebugger
; Compiler = PureBasic 6.04 LTS - C Backend (Windows - x86)
Binary file modified bin/capture-b/capture.dll
Binary file not shown.

0 comments on commit 15e2b88

Please sign in to comment.