Simplify bucket3d.cpp.

master
Cyp 2010-12-06 16:54:47 +01:00
parent a22d920952
commit 49a85a0307
1 changed files with 11 additions and 32 deletions

View File

@ -34,6 +34,8 @@
#include "map.h" #include "map.h"
#include "miscimd.h" #include "miscimd.h"
#include <algorithm>
#define CLIP_LEFT ((SDWORD)0) #define CLIP_LEFT ((SDWORD)0)
#define CLIP_RIGHT ((SDWORD)pie_GetVideoBufferWidth()) #define CLIP_RIGHT ((SDWORD)pie_GetVideoBufferWidth())
#define CLIP_TOP ((SDWORD)0) #define CLIP_TOP ((SDWORD)0)
@ -43,25 +45,16 @@
// someone needs to take a good look at the radius calculation // someone needs to take a good look at the radius calculation
#define SCALE_DEPTH (FP12_MULTIPLIER*7) #define SCALE_DEPTH (FP12_MULTIPLIER*7)
typedef struct _bucket_tag struct BUCKET_TAG
{ {
bool operator <(BUCKET_TAG const &b) const { return actualZ > b.actualZ; } // Sort in reverse z order.
RENDER_TYPE objectType; //type of object held RENDER_TYPE objectType; //type of object held
void * pObject; //pointer to the object void * pObject; //pointer to the object
int32_t actualZ; int32_t actualZ;
} BUCKET_TAG; };
// C version of std::vector<BUCKET_TAG>. static std::vector<BUCKET_TAG> bucketArray;
static BUCKET_TAG *bucketArrayS = NULL;
static BUCKET_TAG *bucketArrayF = NULL;
static BUCKET_TAG *bucketArrayEOS = NULL;
// C version of BUCKET_TAG::operator <().
static int bucketArray_less_than(const void *av, const void *bv)
{
BUCKET_TAG *a = (BUCKET_TAG *)av;
BUCKET_TAG *b = (BUCKET_TAG *)bv;
return (a->actualZ < b->actualZ) - (a->actualZ > b->actualZ); // Sort in reverse z order.
}
static SDWORD bucketCalculateZ(RENDER_TYPE objectType, void* pObject) static SDWORD bucketCalculateZ(RENDER_TYPE objectType, void* pObject)
{ {
@ -519,29 +512,16 @@ void bucketAddTypeToList(RENDER_TYPE objectType, void* pObject)
newTag.actualZ = z; newTag.actualZ = z;
//add tag to bucketArray //add tag to bucketArray
// C version of std::vector<BUCKET_TAG>::push_back(). bucketArray.push_back(newTag);
if (bucketArrayF == bucketArrayEOS)
{
BUCKET_TAG *old = bucketArrayS;
size_t reserve = (bucketArrayEOS - old)*2 + 1;
bucketArrayS = (BUCKET_TAG *)realloc(old, reserve*sizeof(*old));
bucketArrayF = bucketArrayS + (bucketArrayF - old);
bucketArrayEOS = bucketArrayS + reserve;
}
*bucketArrayF++ = newTag;
} }
/* render Objects in list */ /* render Objects in list */
void bucketRenderCurrentList(void) void bucketRenderCurrentList(void)
{ {
BUCKET_TAG* thisTag; std::sort(bucketArray.begin(), bucketArray.end());
// C version of std::sort(). for (std::vector<BUCKET_TAG>::const_iterator thisTag = bucketArray.begin(); thisTag != bucketArray.end(); ++thisTag)
qsort(bucketArrayS, bucketArrayF - bucketArrayS, sizeof(*bucketArrayS), &bucketArray_less_than);
// C version of for (std::vector<BUCKET_TAG>::iterator thisTag = bucketArray.begin(); thisTag != bucketArray.end(); ++thisTag). C wins!
for (thisTag = bucketArrayS; thisTag != bucketArrayF; ++thisTag) // render from back to front
{ {
switch(thisTag->objectType) switch(thisTag->objectType)
{ {
@ -580,6 +560,5 @@ void bucketRenderCurrentList(void)
//reset the bucket array as we go //reset the bucket array as we go
//reset the tag array //reset the tag array
// C version of bucketArray.clear(). bucketArray.clear();
bucketArrayF = bucketArrayS;
} }