@ -22,10 +22,17 @@ static CVECTOR colors[] =
} ;
static const int numColors = sizeof ( colors ) / sizeof ( CVECTOR ) ;
/ / Set data pointers directly from an in - memory byte buffer
# define LOAD_CHUNK(type, dst, num, src, entry) \
dst = ( type * ) ( ( src ) + ( entry ) . offset ) ; \
num = ( entry ) . size / sizeof ( type ) ;
/ / Allocate memory per chunk and copy data from a byte buffer
/ / # define LOAD_CHUNK ( type , dst , num , src , entry ) \
/ / dst = ( type * ) malloc ( ( entry ) . size ) ; \
/ / memcpy ( dst , ( src ) + ( entry ) . offset , ( entry ) . size ) ; \
/ / num = ( entry ) . size / sizeof ( type ) ;
void world_load ( const u_long * data , world_t * world )
{
const char * bytes = ( const char * ) data ;
@ -214,12 +221,11 @@ static INLINE void drawface_quad_strip(const ps1bsp_face_t *face, SVECTOR *vecs)
}
}
static void world_drawface ( const world_t * world , const ps1bsp_face_t * face , u_char * scratchptr )
static void world_drawface ( const world_t * world , const ps1bsp_face_t * face )
{
const CVECTOR * col = & colors [ ( u_long ) face % numColors ] ;
SVECTOR * vecs = ( SVECTOR * ) scratchptr ;
/ / scratchptr + = sizeof ( SVECTOR ) * face - > numFaceVertices ; / / No need to move the scratchpad pointer right now
SVECTOR * vecs = ( SVECTOR * ) ( scratchpad + 256 ) ;
/ / Copy this face ' s vertices into scratch RAM for fast reuse
/ / TODO : this is the main performance bottleneck right now !
@ -237,7 +243,7 @@ static void world_drawface(const world_t *world, const ps1bsp_face_t *face, u_ch
drawface_quad_strip ( face , vecs ) ;
}
static void world_drawnode ( const world_t * world , short nodeIdx , u_char * pvs , u_char * scratchptr )
static void world_drawnode ( const world_t * world , short nodeIdx , u_char * pvs )
{
u_long frameNum = time_getFrameNumber ( ) ;
@ -259,7 +265,7 @@ static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs, u_c
if ( face - > drawFrame = = frameNum )
continue ;
world_drawface ( world , face , scratchptr ) ;
world_drawface ( world , face ) ;
face - > drawFrame = frameNum ;
}
@ -276,7 +282,7 @@ static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs, u_c
/ / if ( face - > drawFrame = = frameNum )
/ / continue ;
/ / world_drawface ( world , face , scratchptr ) ;
/ / world_drawface ( world , face ) ;
/ / face - > drawFrame = frameNum ;
/ / }
@ -286,21 +292,21 @@ static void world_drawnode(const world_t *world, short nodeIdx, u_char *pvs, u_c
/ / Draw child nodes in front - to - back order ; adding faces to the OT will reverse the drawing order
if ( dist > 0 )
{
world_drawnode ( world , node - > front , pvs , scratchptr ) ;
world_drawnode ( world , node - > back , pvs , scratchptr ) ;
world_drawnode ( world , node - > front , pvs ) ;
world_drawnode ( world , node - > back , pvs ) ;
}
else
{
world_drawnode ( world , node - > back , pvs , scratchptr ) ;
world_drawnode ( world , node - > front , pvs , scratchptr ) ;
world_drawnode ( world , node - > back , pvs ) ;
world_drawnode ( world , node - > front , pvs ) ;
}
}
/ / Decompress PVS data for the given leaf ID and store it in scratch RAM at the given scratch pointer location .
/ / Returns the memory location of decompressed PVS data , and moves the scratch pointer forward .
static u_char * world_loadVisData ( const world_t * world , u_short leafIdx , u_char * * scratchpt r)
/ / Decompress PVS data for the given leaf ID and store it in RAM at the given buffer pointer location .
/ / Returns the memory location of decompressed PVS data , and moves the buffer pointer forward .
static u_char * world_loadVisData ( const world_t * world , u_short leafIdx , u_char * * buffe r)
{
u_char * head = * scratchpt r;
u_char * head = * buffe r;
u_char * tail = head ;
const ps1bsp_leaf_t * leaf = & world - > leaves [ leafIdx ] ;
@ -324,13 +330,13 @@ static u_char *world_loadVisData(const world_t *world, u_short leafIdx, u_char *
}
}
* scratchpt r = tail ;
* buffe r = tail ;
return head ;
}
static u_char * world_noVisData ( const world_t * world , u_char * * scratchpt r)
static u_char * world_noVisData ( const world_t * world , u_char * * buffe r)
{
u_char * head = * scratchpt r;
u_char * head = * buffe r;
u_char * tail = head ;
for ( int l = 1 ; l < world - > numLeaves ; l + = 8 )
@ -338,7 +344,7 @@ static u_char *world_noVisData(const world_t *world, u_char **scratchptr)
* tail + + = 0xFF ;
}
* scratchpt r = tail ;
* buffe r = tail ;
return head ;
}
@ -369,9 +375,9 @@ void world_draw(const world_t *world)
cam_leaf = world_leafAtPoint ( world , & cam_pos ) ;
u_char * scratchptr = scratchpad_root ;
u_char * pvs = world_loadVisData ( world , cam_leaf , & scratchptr ) ;
/ / u_char * pvs = world_noVisData ( world , & scratchptr ) ;
u_char * pvsbuf = scratchpad ;
u_char * pvs = world_loadVisData ( world , cam_leaf , & pvsbuf ) ;
/ / u_char * pvs = world_noVisData ( world , & pvsbuf ) ;
world_drawnode ( world , 0 , pvs , scratchptr ) ;
world_drawnode ( world , 0 , pvs ) ;
}