News:

Function Finder  Find all the functions within source code files

Main Menu

Testing Single Pass Vs Multi Pass Sprite Scene

Started by kevin, December 26, 2018, 03:37:05 AM

Previous topic - Next topic

kevin

 Testing Single Pass Vs Multi Pass Sprite Scene


    CPU caches don't like fetching memory in random fashion, so what you could do is render your scene in strips..  the idea being is that the target and source images will cache better..  


   Enter = Toggle Single pass vs Multi Pass

  Space = Sprite Order
 


PlayBASIC Code: [Select]
; ===========================================================
; First Create fiveimages with Shaded Circle patterns on them
; ===========================================================

MaxImages=5
Dim Images(MaxImages)

; create a series of randomly colour images
For lp=1 to MaxImages
Images(lp)= CreateBallImage(50+(lp*10))
Next


; =========================================================
; Create 100 sprites and randomly position them around the screen
; ========================================================
For ThisSprite=1 To 1000

ThisIMage=rndrange(1,MaxIMages)

;CReate a new sprite
ThisSprite=newSprite(Rnd(GetScreenWidth()),_
Rnd(GetScreenHeight()),_
images(ThisImage))

SpriteDrawMode ThisSprite, 2+16+((Rnd(100)>50)*16)
; Set sprite to Automatically center it's image around the
; sprites axis.
AutoCenterSpriteHandle ThisSprite,True

; Randomly position this sprite within the screen,
; but at a Z depth of 100
PositionSpriteZ ThisSprite,500-(ThisImage*25)
Next





; Set Sprites Default Drawing Mode to "DrawOrderedSprites"
Sprites_DRaw_mode=1

Screen=NewFXImage(GetScreenWidth(),GEtScreenHeight())
; ---------------------------
; Programs Main (Do/loop)
; ---------------------------

Do


if TestMethod = 0
TEST_OnePass(Screen,Sprites_DRaw_mode)
endif

if TestMethod =1
TEST_MultiPass(Screen,Sprites_DRaw_mode,10)
endif



MoveAllSprites()
; Display a message

If Sprites_DRaw_mode=0
Print "Sprites render mode: DrawOrderedSprites"
Else
Print "Sprites render mode: DrawAllSprites"
EndIf


; Check if the Space key was pressed
If SpaceKey()=True
Sprites_DRaw_mode=1-Sprites_DRaw_mode
FlushKeys
EndIf


if EnterKey()
TestMethod=1-TestMethod
flushkeys
rendertoimage screen
cls 0
rendertoscreen
endif
print FPS()

; Display the screen and loop back to the DO statement
; to continue the loop
Sync
Loop


function TEST_OnePass(Screen,Sprites_DRaw_mode)

imageviewport Screen,0,0,GetImageWidth(Screen),GetImageHeight(Screen)

rendertoimage Screen
Cls RGB(25,30,45)

; Check what Sprite drawing mode to use
If Sprites_DRaw_mode=0
; Render The Sprites using their depths
DrawOrderedSprites
Else
; Tell PB to render All the Sprites now,
;and ignore their Z depths.
DrawAllSprites
EndIf

rendertoscreen
drawimage Screen,0,0,false


setcursor 0,0
Ink $ff0000
Print "SINGLE PASS"

EndFunction



function TEST_MultiPass(Screen,Sprites_DRaw_mode,passes)

Ih=GetImageHeight(Screen)

ChunkHeight=iH/passes

if ChunkHeight*Passes < Ih
Passes++
endif

rendertoimage Screen


ViewPortY1=0
ViewPortY2=ChunkHeight

for pass=0 to Passes -1

ViewPortY1=ChunkHeight*(Pass)
ViewPortY2=ChunkHeight*(Pass+1)

if ViewPortY1 < IH
imageviewport Screen,0,ViewPortY1,GetImageWidth(Screen),ViewPortY2

Cls RGB(25,30,45)

; Check what Sprite drawing mode to use
Login required to view complete source code




Video

   


 

Music By: https://bensound.com