CountParticlesAsync ( emitter )
Parameters
| emitter - an existing CPU or GPU particle emitter entity |
Description
|
Returns the latest completed live-particle count without waiting for the GPU. For a GPU emitter the result is the latest completed count, or -1 when no completed count is available. Creation and clear can report the known value 0 immediately. On a CPU emitter, it returns the exact current count. This query never waits for a GPU fence. It requests an asynchronous counter readback when needed, and can return an older completed count while newer work is pending. Requests also progress without RenderWorld or Flip. Display -1 as pending; do not treat it as an empty emitter. Clear, resize and emitter lifetime changes invalidate incompatible cached results. Use this query for HUDs and diagnostics. Use CountParticles for an exact completion decision, accepting a possible synchronization wait. Queries do not clear ParticleError. In the example E takes an exact sample; it is not called in the normal throughput loop. Requires Extended mode. See also: CountParticles, CreateGPUParticleEmitter, ParticleError. |
Example
; CountParticlesAsync - Extended mode, DX12. Graphics3D 800,600,0,2 SetBuffer BackBuffer() If GPUParticlesSupported()=0 Then RuntimeError "GPU particles are unavailable." VSync 0 FrameLimit 60 camera=CreateCamera() PositionEntity camera,0,1,-5 CameraClsColor camera,10,15,30 emitter=CreateGPUParticleEmitter(10000) If emitter=0 Then RuntimeError ParticleError$() exact_count=-1 ParticlePreset emitter,1 timer=CreateTimer(60) paused=False While Not KeyHit(1) If KeyHit(25) paused=Not paused PauseParticles emitter,paused EndIf If KeyHit(57) Then EmitParticles emitter,100 If KeyHit(19) Then ClearParticles emitter If KeyHit(18) Then exact_count=CountParticles(emitter) ticks=WaitTimer(timer) If ticks>15 Then ticks=15 For tick=1 To ticks UpdateWorld Next RenderWorld live=CountParticlesAsync(emitter) live_text$="pending" If live>=0 Then live_text$=Str$(live) Color 255,255,255 Text 16,16,"CountParticlesAsync | P Pause | Space Burst | R Clear | Esc Exit" Text 16,38,"Latest GPU count: "+live_text$+" Paused: "+paused Text 16,60,"E: take an exact count (may wait). Last exact sample: "+exact_count Flip Wend FreeTimer timer FreeEntity emitter End
Index