January 15, 2021, 04:54:03 PM

Author Topic: [bb] Blitz Plus Dirty Rects System by Grey Alien [ 1+ years ago ]  (Read 512 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Blitz Plus Dirty Rects System
Author : Grey Alien
Posted : 1+ years ago

Description : Here is the Dirty Rects Type and supporting functions that I used in Easter Bonus.  I actually used this type in a 5-buffer system to maximise the speed of RAM and VRAM and avoid any crappy RAM to VRAM (and vice versa) slow transfer rates.

Code :
Code: BlitzBasic
  1. Type RectType2 
  2.         Field RLeft%, RTop%, Width%, Height%, id%
  3. End Type
  4.  
  5. Const MAX_DIRTY_RECTS = 1000
  6. Type DirtyRects
  7.         Field Items.RectType2[MAX_DIRTY_RECTS]
  8.         Field Count
  9. End Type
  10.  
  11. Function DirtyRectsCreate.DirtyRects()
  12.         d.DirtyRects = New DirtyRects
  13.         For i = 0 To MAX_DIRTY_RECTS
  14.                 dItems[i] = New RectType2                              
  15.         Next
  16.         dCount = 0
  17.         Return d
  18. End Function
  19.  
  20. Function DirtyRectsDelete(d.DirtyRects)
  21.         If d = Null Then Return 0
  22.         For i = 0 To MAX_DIRTY_RECTS
  23.                 Delete ditems[i]
  24.         Next   
  25.         Delete d
  26.         Return 1
  27. End Function
  28.  
  29. Function DirtyRectsAdd(d.DirtyRects, x, y, w, h)
  30.         Local i = dCount
  31.         ditems[i]RLeft = x
  32.         ditems[i]RTop = y
  33.         ditems[i]Width = w
  34.         ditems[i]Height = h
  35.         ditems[i]id = 0
  36.         dCount = dCount + 1                    
  37. End Function
  38.  
  39. Function DirtyRectsAddImage(d.DirtyRects, x, y, image)
  40.         Local w = ImageWidth(image)
  41.         Local h = ImageHeight(image)
  42.         Local i = dCount
  43.         ditems[i]RLeft = x
  44.         ditems[i]RTop = y
  45.         ditems[i]Width = w
  46.         ditems[i]Height = h
  47.         ditems[i]id = 0
  48.         dCount = dCount + 1                    
  49. End Function
  50.  
  51. Function DirtyRectsAddSpecial(d.DirtyRects, x, y, w, h, id%)
  52.         Local i = dCount
  53.         ditems[i]RLeft = x
  54.         ditems[i]RTop = y
  55.         ditems[i]Width = w
  56.         ditems[i]Height = h
  57.         ditems[i]id = id
  58.         dCount = dCount + 1                    
  59. End Function
  60.  
  61. Function DirtyRectsDrawAll(d.DirtyRects, background%)
  62.         ;pass in background image, it draws on current buffer
  63.         ib = ImageBuffer(background)
  64.         For i = 0 To dcount-1          
  65.                 Local r.RectType2 = ditems[i]
  66.                 CopyRect(rRLeft, rRTop, rWidth, rHeight, rRLeft, rRTop, ib) ;dest buffer not specified                 
  67.         Next
  68. End Function
  69.  
  70. Function DirtyRectsDrawSpecial(d.DirtyRects, background%, id%)
  71.         ;pass in background image, it draws on current buffer
  72.         ib = ImageBuffer(background)
  73.         For i = 0 To dcount-1          
  74.                 Local r.RectType2 = ditems[i]
  75.                 If rid = id Then                       
  76.                         CopyRect(rRLeft, rRTop, rWidth, rHeight, rRLeft, rRTop, ib) ;dest buffer not specified
  77.                         ;move everything in the list above this down                   
  78.                         dCount = dcount-1
  79.                         For j = i To dCount-1
  80.                                 dest.RectType2 = ditems[j]
  81.                                 s.RectType2 = ditems[j+1]
  82.                                 destRLeft = sRLeft
  83.                                 destRTop = sRTop
  84.                                 destWidth = sWidth
  85.                                 destHeight = sHeight
  86.                                 destid = sid
  87.                         Next                   
  88.                 EndIf
  89.         Next
  90. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal