The next issue I found was in the iterative function BSP_RenderNode which is used to walk the Nodes of the BSP Tree, searching for Leaves to render.
It detects Leaves based on the sign of the nodeNum param.
I had defined the param type as DWORD, and thus we were never detecting negative values using the highlevel .if < 0 directive. When I used an AND mask of bit 31 the test succeeded and I realized what I'd done, so I removed the AND mask check again and changed the type of nodeNum to SDWORD instead. Now the function correctly detects leaf nodes and attempts to call BSP_RenderLeaf, where we crash :tongue: Well, any progress is good progress.
"Perfection is attained not when there is nothing left to add, but when there is nothing left to take away."
It detects Leaves based on the sign of the nodeNum param.
I had defined the param type as DWORD, and thus we were never detecting negative values using the highlevel .if < 0 directive. When I used an AND mask of bit 31 the test succeeded and I realized what I'd done, so I removed the AND mask check again and changed the type of nodeNum to SDWORD instead. Now the function correctly detects leaf nodes and attempts to call BSP_RenderLeaf, where we crash :tongue: Well, any progress is good progress.
"Perfection is attained not when there is nothing left to add, but when there is nothing left to take away."
Uh-oh: traced the next problem down to the BSP_ReadClusters procedure, which is examining the 17th LumpsDirectory Header to find the size and offset of the 17th Lump (the last one in the Lumps Directory), which is our VisData Lump, it's telling me the offset of the Lump's data in the file, but its telling me the Size is zero.
This leads me to not load the cluster-to-cluster visibility data, and sets clusters.p_Bits to NULL, which screws me in the Render code.
It looks like the bsp file itself may be bad !!
Here's an update, it's the complete project, embedded in the old Particles demo since I've embedded in the bsp code in its working skeleton.
Due to size I've made a split rar that contains a zip. Two part rar. Get both parts before you try to extract, then only extract from part one since this is joined.
This leads me to not load the cluster-to-cluster visibility data, and sets clusters.p_Bits to NULL, which screws me in the Render code.
It looks like the bsp file itself may be bad !!
Here's an update, it's the complete project, embedded in the old Particles demo since I've embedded in the bsp code in its working skeleton.
Due to size I've made a split rar that contains a zip. Two part rar. Get both parts before you try to extract, then only extract from part one since this is joined.
Part two of the above rar archive..
Just tried loading a more substantial bsp and got the same result - conclusion is theres a problem in my ReadClusters procedure. Gonna take another look at it.
Having revisited ReadClusters once more, it turns out that BOTH of the above were true, I've now got it (I think) correctly loading the "Clusters Visibility BitPattern", but the "test.bsp" file still reports a NULL size for the 17th Lump. When loading a larger bsp I found on the web, it reports a believeable Lump size and file offset, and when loaded, that Lump reports a believable #Clusters, ClusterSize and the BitPattern that follows seems to load ok.
Here is the updated ReadClusters function:
Here is the updated ReadClusters function:
;Last edited by Homer 17 Jan 2004
;(see [url]http://graphics.stanford.edu/~kekoa/q3/#Visdata[/url])
BSP_ReadClusters proc uses ebx ecx
local ErrBuf[256]:BYTE
local _offset:DWORD
local _size:DWORD
local t:FLOAT
local num:DWORD
local me:DWORD
mov me,ecx
; // Clusters have variable length so we need to read them specially
lea ebx,[ecx].BSP.lumps ;where we loaded the "lumps directory" is an actual array of structs, not ptrs
mov eax,sizeof BSPLump
imul eax,EBSPClusters ;calculate offset of specific lump directory entry
add ebx,eax ;add offset to base address
m2m _offset, [ebx].BSPLump._offset ;fetch offset to lump data , relative to start of file
m2m _size, [ebx].BSPLump._size
DebugValue addr ErrBuf,CTEXT("Clusters lump is at offset %lu,"),_offset
DebugValue addr ErrBuf,CTEXT(" size=%lu",13,10),_size
mov ebx,_offset
;// Check if they exist
.if _size== 0
mov [ecx].BSP.clusters.numClusters,0
mov [ecx].BSP.clusters.p_Bits,NULL
invoke MessageBox,0,CTEXT("BSP_ReadClusters : Clusters Directory Lump in Header says size of visdata lump is NULL"),CTEXT(" Potential Problem"),MB_OK
.else
;Replacement code added 17 Jan 2004 by Homer
invoke _Read, pTemp,_offset, sizeof BSPCluster, addr [ecx].BSP.clusters ;<-- Load the Clusters Struct
lea ebx, [ecx].BSP.clusters
DebugValue addr ErrBuf,CTEXT("NumClusters=%lu,"),[ebx].BSPCluster.numClusters
DebugValue addr ErrBuf,CTEXT(" size=%lu",13,10),[ebx].BSPCluster._size
mov eax,_size ;Calculate sizeof Clusters Visibility Bits (new method)
sub eax,sizeof BSPLump ;Its the Lump Size, minus the Lump Header fields
push eax ;and comes to the same value as ClusterSize * numClusters
DebugValue addr ErrBuf,CTEXT("bitpattern size=%lu",13,10),eax
malloc eax
mov ecx,me
mov [ecx].BSP.clusters.p_Bits,eax ;Allocate memory for visibility bitpattern
pop ebx
add _offset,sizeof BSPCluster-4
invoke _Read, pTemp, _offset, ebx, [ecx].BSP.clusters.p_Bits
.endif
DebugValue addr ErrBuf,CTEXT("Found %lu Clusters",13,10),[ecx].BSP.clusters.numClusters
ret
BSP_ReadClusters endp
Now there's a new problem, almost certainly introduced in the new ReadClusters - the field BSP.surfacesVisibleSize is being overwritten.
Here is a partial extract of my Debug Log
Found 18061 Vertices
Found 34449 Indices
surfacesVisibleSize=425 <--- This is in BSP_ReadSurfaces
Found 3393 Surfaces
Found 64 Textures
...
Found and Processed 7 LightMaps
Found 2099 Nodes
Found 2110 Leaves
Found 5811 LeafSurface Indices
Found 4807 LeafBrush Indices
Found 2656 Planes
Clusters lump is at offset 1529400, size=100024
NumClusters=893, size=112
bitpattern size=100016
Found 893 Clusters
Found 1738 Brushes
Found 11753 BrushesSides
BSP File Maps\devdm3.bsp Read OK
Returned to CApp_WndProc from 'InitParticles'
CPrimitive_SetupRendering Completed
surfacesVisibleSize = 1699000 <--- this is in BSP_Render3D
As you can see, ReadSurfaces reports a reasonable surfacesVisibleSize,
then further down we see the stuff from ReadClusters, then when we get to Rendering our surfacesVisibleSize value has changed to something big, which causes a problem when we try to zero the associated memory.
Here is a partial extract of my Debug Log
Found 18061 Vertices
Found 34449 Indices
surfacesVisibleSize=425 <--- This is in BSP_ReadSurfaces
Found 3393 Surfaces
Found 64 Textures
...
Found and Processed 7 LightMaps
Found 2099 Nodes
Found 2110 Leaves
Found 5811 LeafSurface Indices
Found 4807 LeafBrush Indices
Found 2656 Planes
Clusters lump is at offset 1529400, size=100024
NumClusters=893, size=112
bitpattern size=100016
Found 893 Clusters
Found 1738 Brushes
Found 11753 BrushesSides
BSP File Maps\devdm3.bsp Read OK
Returned to CApp_WndProc from 'InitParticles'
CPrimitive_SetupRendering Completed
surfacesVisibleSize = 1699000 <--- this is in BSP_Render3D
As you can see, ReadSurfaces reports a reasonable surfacesVisibleSize,
then further down we see the stuff from ReadClusters, then when we get to Rendering our surfacesVisibleSize value has changed to something big, which causes a problem when we try to zero the associated memory.