Trick - Barrier broken! Up to 2700 % Faster Plot()

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Trick - Barrier broken! Up to 2700 % Faster Plot()
Mhhhh... Very cool news for you... The speed barrier with PureBasic Plot() has been broken! Some of you (like me) are not really happy with the speed when using Plot()! Btw for normal things the speed of Plot() itself is ok... The only problem why it slows so very down is the use of FrontColour()

Yes, this is not a bad joke! You dont need any inline asm, new libs or dll calls! You need only the normal included PureBasic commands and with a small nice trick we will speed up our Plot() command up to 2700 percent (two-thousand-seven-hundret)!

I wrote a small "Animation-Precalculation-System" for my 32k game! The complete animation sequence (small one) needed on my system 1.7 - 1.75 seconds... Then i have had an idea how to speed it up... Now the same stuff needed 1.48-1.49 seconds...

Some time ago i have had an idea how it could be possible to speed up the Plot() mutch more... So i tried to code my small experience... and YES - it works very fine... The same stuff was now very fast and the stuff was finished in only 0.22 - 0.24 seconds on my system... YEAH!!!

I tried my trick on a 640x480 screen and the complete screen was filled in ONLY 1.7 seconds... The Original Plot() command need for this resolution 46.41 seconds!!!

How does it work?
Its really easy to understand... If you want plot any graphic to the screen,
you may know in most sence how does this palette looks like... If you want to plot an image with a size of 200x200 in 256 clours, you have to do folling steps:

You need your palette data and do something like following [basic-code]:

Code: Select all

    ;-------- Generating PaletteBrush --------
    ;    
    StartDrawing(ScreenOutput())
        For x=0 To 255
          FrontColour (x,x,x)  	         ; x = here you can store your real palette data too  
          Plot (x,0)
        Next   
    StopDrawing()
    ;      
    GrabSprite (100,0,0,400,1)           ; Now we have our PaletteBrush, hehe
    ;
    ;-------- Drawing our Image -------
    ;
    For x = 0 to 63
        For y = 0 to 63
          newcol = Random(0,255)         ; Just randomize some colours! 
          ClipSprite(100,newcol,0,1,1)   ; Use our PaletteBrush and set to 1x1 pixel
          DisplaySprite(100,x,y)         ; 
        Next
    Next
This is only just a small code snip to explain you how does my mehode works! Hope you understand this nice trick... Maybe i will add a small working example soon.... first i have to fix a very strange bug in my texture-generation-engine (but seems that it´s a bug of PB or so!? Btw Fred and me dont really know until now why does the PB version not really work ;(((





PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten

Edited by - MrVainSCL on 17 March 2002 18:44:35
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

What happens if you use 16 Millions colors ?
16 Millions Sprites ?
Try to poke directly to the graphicsmemory.
This method is the fastest i know.
Btw, the trick is cool for 256 Colors Screens.

Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi Rings
I posted this small code snip only for guys who want to experience a bit :wink: You may be right, to write directly to the gfx buffer (peek/poke) would be another way... In 16 bit you have always rgb up to 255 and if want to precalc any 16 bit stuff i.e, you have to precalcuate some different in 256 colours textures and then you can add/sub/mul or whatever you want to get a 16 bit result :wink: Sure, my way is nice for 256 colours stuff...

Btw we dont need longer any tricks to have fast drawing operations with the next PB version as i know :wink: Be patienced...

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
Post Reply