Blitz3D+ Command Reference

JobProgressDone:Long ( job )

Parameters

job - a Job handle returned by StartJob

Description

Returns the raw completed-work count from the worker's latest progress snapshot.

Where JobProgress gives you a normalized 0-1000 value for a bar, this gives you the worker's actual number - the done argument of its latest SetJobProgress call, as a Long. Pair it with JobProgressTotal to show real counts: "3,410 of 12,000 tiles". It returns 0 until the worker publishes its first snapshot.

Unlike the normalized value, the raw numbers are not smoothed or clamped between snapshots - a worker that starts a new phase with a fresh total may make done jump backwards. That is fine for display; just do not build logic on it. Progress is advisory either way: completion belongs to JobFinished, PollJob, and JobState.

For the full story, see the Using Background Jobs guide.

Requires Extended mode.

See also: JobProgressTotal, JobProgress, JobProgressText, SetJobProgress.

Example

; JobProgressDone Example
; -----------------------
; Requires Extended mode.

Graphics 640,480,0,2
SetBuffer BackBuffer()

; The worker carves a dungeon level on a background thread
Worker Function CarveDungeon(inputBank)
    rooms=PeekInt(inputBank,0)
    For room=1 To rooms
        ; Busy digging loop standing in for real level generation
        For dig=1 To 700000
            noise#=Sin(dig)*Sqr(dig)
        Next
        ; Each snapshot's raw done value is what JobProgressDone reports
        SetJobProgress room,rooms,"Carving room "+room
    Next
    Return CreateBank()
End Function

inputBank=CreateBank(4)
PokeInt inputBank,0,30
job=StartJob(CarveDungeon,inputBank,1L)
FreeBank inputBank

While Not KeyDown(1)

    Cls

    ; JobProgressDone returns the latest raw completed-work value
    done:Long=JobProgressDone(job)
    total:Long=JobProgressTotal(job)

    ; Draw one tick per finished room
    Color 90,200,120
    For tick=1 To done
        Rect 70+(tick-1)*16,220,12,24,True
    Next
    Color 255,255,255
    Rect 66,216,488,32,False

    Text 0,0,"Esc: exit"
    Text 70,190,"Generating dungeon on a worker thread..."
    Text 70,258,"JobProgressDone(job) = "+done+" rooms carved of "+total
    If JobFinished(job) Then Text 70,278,"Dungeon complete!"

    Flip

Wend

FreeJob job
End

Index