Update the Capture.dll

- Increase hardcoded number of workers to 8.
- Export images temporarily, and then move them once they are fully exported. This prevents corrupt images.
This commit is contained in:
David Vogel 2024-02-05 19:00:39 +01:00
parent 9e51538f3f
commit 15e2b88ed5
2 changed files with 20 additions and 8 deletions

View File

@ -22,6 +22,10 @@ Structure GLViewportDims
height.i height.i
EndStructure EndStructure
Structure WorkerInfo
workerNumber.i
EndStructure
; Returns the size of the main OpenGL rendering output. ; Returns the size of the main OpenGL rendering output.
ProcedureDLL GetGLViewportSize(*dims.GLViewportDims) ProcedureDLL GetGLViewportSize(*dims.GLViewportDims)
If Not *dims If Not *dims
@ -57,12 +61,15 @@ ProcedureDLL AttachProcess(Instance)
CreateDirectory("mods/noita-mapcap/output/") CreateDirectory("mods/noita-mapcap/output/")
For i = 1 To 6 Static Workers = 8
CreateThread(@Worker(), #Null) Dim WorkerInfos.WorkerInfo(Workers-1)
For i = 0 To Workers-1
WorkerInfos(i)\workerNumber = i
CreateThread(@Worker(), @WorkerInfos(i))
Next Next
EndProcedure EndProcedure
Procedure Worker(*Dummy) Procedure Worker(*workerInfo.WorkerInfo)
Protected img, x, y Protected img, x, y
Repeat Repeat
@ -82,8 +89,12 @@ Procedure Worker(*Dummy)
ResizeImage(img, sx, sy) ResizeImage(img, sx, sy)
EndIf EndIf
SaveImage(img, "mods/noita-mapcap/output/" + x + "," + y + ".png", #PB_ImagePlugin_PNG) ; Save image temporary, and only move it once it's fully exported.
;SaveImage(img, "" + x + "," + y + ".png", #PB_ImagePlugin_PNG) ; Test ; 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) FreeImage(img)
ForEver ForEver
@ -171,11 +182,12 @@ EndProcedure
; IDE Options = PureBasic 6.04 LTS (Windows - x64) ; IDE Options = PureBasic 6.04 LTS (Windows - x64)
; ExecutableFormat = Shared dll ; ExecutableFormat = Shared dll
; CursorPosition = 126 ; CursorPosition = 94
; FirstLine = 98 ; FirstLine = 51
; Folding = - ; Folding = -
; Optimizer ; Optimizer
; EnableThread ; EnableThread
; EnableXP ; EnableXP
; Executable = capture.dll ; Executable = capture.dll
; Compiler = PureBasic 6.04 LTS (Windows - x86) ; DisableDebugger
; Compiler = PureBasic 6.04 LTS - C Backend (Windows - x86)

Binary file not shown.