BSP Loader | RLE Dekompression, bits in Byte Array

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

marcelkroener

Betreff: BSP Loader | RLE Dekompression, bits in Byte Array

BeitragSo, Mai 25, 2008 21:30
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi.
Ich verzweifel leider wieder an einem Problem mit meinem BSP Loader.
Das Sichtbarkeits System scheint zu funktionieren, das Dekomprimieren der Daten noch nicht ganz.
Ich habe C Code zum dekomprimieren eines bit arrays in ein Byte array.
Ich weis nicht genau ob ich ihn richtig übersetzt habe.

Beschreibung:
The rest of the visibility lump is the actual visibility information. For every cluster the visibility state (either visible or occluded) is stored for every other cluster in the world. Clusters are always visible from within themselves. Because this is such a massive amount of data, this array is stored as a bit vector (one bit per element) and 0's are run-length-encoded. Here's an example of a C-routine to decompress the PVS into a byte array (this was adapted from the "Quake Specifications" document):
C Code:
Code: [AUSKLAPPEN]

int v = offset;

memset(cluster_visible, 0, num_clusters);

for (int c = 0; c < num_clusters; v++) {
 
   if (pvs_buffer[v] == 0) {
      v++;     
      c += 8 * pvs_buffer[v];
   } else {
      for (uint8 bit = 1; bit != 0; bit *= 2, c++) {
         if (pvs_buffer[v] & bit) {
            cluster_visible[c] = 1;
         }
      }
   }   

}


Hier mein BB Code:

Code: [AUSKLAPPEN]

Function lump_visiblity()
bf=FilePos(file)
debug("---------- Vis Data (Lump 4) ----------")
   num_clusters=ReadInt(file)
   cluster_count = num_clusters ;
   debug("Num Clusters: "+num_clusters)
   Dim visiblity_offset(num_clusters-1,1)
   Dim visiblity_buffer(num_clusters-1)
   Dim visiblity(num_clusters^2-1)
   For i=0 To num_clusters-1
      visiblity_offset(i,0)=ReadInt(file) ;PVS offset
      visiblity_offset(i,1)=ReadInt(file) ;PAS offset
      debug("Cluster "+i+": PVS offset "+visiblity_offset(i,0)+" | PAS offset: "+visiblity_offset(i,1))
   Next
   debug("")
   debug("..::Visiblity Data::..")
   For i=0 To num_clusters-1
      SeekFile(file,bf+visiblity_offset(i,0))
      visiblity_buffer(i)=ReadByte(file)
      debug(i+" :"+visiblity_buffer(i))
   Next
   
For i=0 To num_clusters-1   ;Decompress Visdata into a byte Array
   debug("Cluster "+i+":")
   c=0
   v=i   ;start at cluster 0
   While c<num_clusters
      If visiblity_buffer(v) = 0 Then
         v=v+1
         DebugLog "v: "+v+" | c: "+c
         skip = 8 * visiblity_buffer(v)
         debug("Skipped "+skip+" Clusters!")
         c=c+skip
      Else
         buffer = visiblity_buffer(v)
         bit=1
         While Not bit=0
            If (buffer And bit) Then
               visiblity(c+i*num_clusters)=1
            EndIf
            bit=bit Shl 1
            If bit > $FF Then bit = 0 ;
            c=c+1
         Wend
      EndIf
      v=v+1
   Wend
Next
   
   ;For i=0 To num_clusters^2-1
      ;debug("Vis: "+visiblity(i))
   ;Next
   
   
   visiblity_count=i
   debug("")
End Function


ich bekomme ein "Array Index out of bounds" beim überspringen von Clustern.
(Zeile: skip = 8 * visiblity_buffer(v))
Ich habe den Code vom ganzen visiblity Lump gepostet, vieleicht liegt mein Fehler doch woanders.

(artikel & erklärung zum dateiformat: http://www.geocities.com/cofrdrbob/bspformat.html)

mfg mk

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group