- more efficient drawing of buildings and tiles for PSX

This commit is contained in:
InspirationByte 2022-02-03 23:18:36 +03:00
parent 6d0ff639f7
commit 277d391add
3 changed files with 119 additions and 177 deletions

View File

@ -170,14 +170,12 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
{
int i;
int z;
u_int spriteColour;
u_int lightdd;
u_int spriteColour, lightdd;
u_char lightLevel;
MODEL* model;
PACKED_CELL_OBJECT* pco;
PACKED_CELL_OBJECT** list;
int numShadows;
int count;
#if 0 //def PSX
MVERTEX5x5& subdiVerts = *(MVERTEX5x5*)(u_char*)getScratchAddr(0);
@ -219,8 +217,7 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
shadowMatrix.m[i][0] = inv_camera_matrix.m[i][2];
shadowMatrix.m[i][1] = -inv_camera_matrix.m[i][0];
shadowMatrix.m[i][2] = inv_camera_matrix.m[i][0];
i--;
} while (i >= 0);
} while (i--);
plotContext.primptr = current->primptr;
@ -235,9 +232,8 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
plotContext.current = current;
numShadows = 0;
count = numFound - 1;
while (count != -1)
while (numFound--)
{
pco = *list;
list++;
@ -303,8 +299,6 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
plotContext.ot += 133;
}
count--;
#ifdef PSX
#define MAX_TREE_SHADOW_DISTANCE 7000
#else
@ -334,9 +328,7 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
// [D] [T]
void SetupPlaneColours(u_int ambient)
{
u_int r;
u_int g;
u_int b;
u_int r, g, b;
if ((gWeather - 1U > 1) && gTimeOfDay != 0 && gTimeOfDay != 2)
{
@ -585,10 +577,7 @@ void DrawAllTheCars(int view)
// [D] [T]
u_int normalIndex(SVECTOR* verts, u_int vidx)
{
SVECTOR* v0;
SVECTOR* v1;
SVECTOR* v2;
SVECTOR* v0, *v1, *v2;
int x, y;
int th23;
@ -650,31 +639,32 @@ u_int normalIndex(SVECTOR* verts, u_int vidx)
return th23 | 0x80;
}
void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
// [A]
void ConvertPolygonTypes(MODEL* model, _pct* pc)
{
int opz;
int Z;
PL_POLYFT4* polys;
int i;
int r;
u_char temp;
u_char ptype;
POLY_FT4* prims;
SVECTOR* srcVerts;
int combo;
PL_POLYFT4* polys;
u_char temp, ptype;
int i;
// [A] we are storing the processing flag here
if (model->tri_verts & 0x8000)
{
return;
}
model->tri_verts |= 0x8000;
srcVerts = (SVECTOR*)model->vertices;
polys = (PL_POLYFT4*)model->poly_block;
combo = combointensity;
i = model->num_polys;
while (i > 0)
// pre-process vertices
while (i-- > 0)
{
// iterate through polygons
// with skipping
ptype = polys->id & 0x1f;
// convert poly types
if ((ptype & 0x1) == 0 && ptype != 8) // is FT3 triangle?
{
temp = polys->uv2.v;
@ -690,7 +680,44 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
if (ptype != 11 && ptype != 21 && ptype != 23)
{
polys = (PL_POLYFT4*)((char*)polys + pc->polySizes[ptype]);
i--;
continue;
}
// also precalculate normal index
if (ptype != 21 && (polys->th & 0x80) == 0)
{
polys->th = normalIndex(srcVerts, *(u_int*)&polys->v0);
}
polys = (PL_POLYFT4*)((char*)polys + pc->polySizes[ptype]);
}
}
void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
{
int opz, Z, r;
PL_POLYFT4* polys;
int i;
u_char ptype;
POLY_FT4* prims;
SVECTOR* srcVerts;
int combo;
srcVerts = (SVECTOR*)model->vertices;
polys = (PL_POLYFT4*)model->poly_block;
combo = combointensity;
ConvertPolygonTypes(model, pc);
i = model->num_polys;
while (i-- > 0)
{
ptype = polys->id & 0x1f;
// skip certain polygons
if (ptype != 11 && ptype != 21 && ptype != 23)
{
polys = (PL_POLYFT4*)((char*)polys + pc->polySizes[ptype]);
continue;
}
@ -710,12 +737,7 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
}
else
{
temp = polys->th;
if ((polys->th & 0x80) == 0) // cache normal index if it were not
temp = polys->th = normalIndex(srcVerts, *(u_int*)&polys->v0);
pc->colour = pc->f4colourTable[(r >> 3) * 4 - temp & 31];
pc->colour = pc->f4colourTable[(r >> 3) * 4 - polys->th & 31];
}
if (opz > 0)
@ -723,13 +745,6 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
pc->tpage = (*pc->ptexture_pages)[polys->texture_set];
pc->clut = (*pc->ptexture_cluts)[polys->texture_set][polys->texture_id];
ushort uv0, uv1, uv2, uv3;
uv0 = *(ushort*)&polys->uv0;
uv1 = *(ushort*)&polys->uv1;
uv2 = *(ushort*)&polys->uv2;
uv3 = *(ushort*)&polys->uv3;
prims = (POLY_FT4*)pc->primptr;
setPolyFT4(prims);
@ -750,10 +765,10 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
prims->tpage = pc->tpage;
prims->clut = pc->clut;
*(ushort*)&prims->u0 = uv0;
*(ushort*)&prims->u1 = uv1;
*(ushort*)&prims->u2 = uv3;
*(ushort*)&prims->u3 = uv2;
*(ushort*)&prims->u0 = *(ushort*)&polys->uv0;
*(ushort*)&prims->u1 = *(ushort*)&polys->uv1;
*(ushort*)&prims->u2 = *(ushort*)&polys->uv3;
*(ushort*)&prims->u3 = *(ushort*)&polys->uv2;
addPrim(pc->ot + (Z >> 1), prims);
@ -761,20 +776,16 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
}
polys = (PL_POLYFT4*)((char*)polys + pc->polySizes[ptype]);
i--;
}
}
// [D] [T] [A] custom
void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
{
int opz;
int opz, Z, r;
int diff, minZ, maxZ;
int Z;
PL_POLYFT4* polys;
int i;
int r;
u_char temp;
u_char ptype;
POLY_FT4* prims;
SVECTOR* srcVerts;
@ -791,29 +802,18 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
combo = combointensity;
ConvertPolygonTypes(model, pc);
i = model->num_polys;
while (i > 0)
while (i-- > 0)
{
// iterate through polygons
// with skipping
ptype = polys->id & 0x1f;
if ((ptype & 0x1) == 0 && ptype != 8) // is FT3 triangle?
{
temp = polys->uv2.v;
polys->uv3.u = polys->uv2.u;
polys->uv3.v = temp;
polys->v3 = polys->v2;
polys->id |= 1;
ptype |= 1;
}
if (ptype != 11 && ptype != 21 && ptype != 23)
{
polys = (PL_POLYFT4*)((char*)polys + pc->polySizes[ptype]);
i--;
continue;
}
@ -833,12 +833,7 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
}
else
{
temp = polys->th;
if ((polys->th & 0x80) == 0) // cache normal index if it were not
temp = polys->th = normalIndex(srcVerts, *(u_int*)&polys->v0);
pc->colour = pc->f4colourTable[(r >> 3) * 4 - temp & 31];
pc->colour = pc->f4colourTable[(r >> 3) * 4 - polys->th & 31];
}
if (opz > 0)
@ -942,7 +937,6 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
}
polys = (PL_POLYFT4*)((char*)polys + pc->polySizes[ptype]);
i--;
}
}
@ -950,15 +944,12 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
// [D] [T]
int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
{
int mat;
int zbias;
int i, mat, prev_mat;
int Z, zbias;
int drawlimit;
MODEL* model;
OTTYPE* ot;
CELL_OBJECT* cop;
int i;
int Z;
int prev_mat;
prev_mat = -1;
@ -979,9 +970,7 @@ int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
ot = plotContext.current->ot + 8;
i = 0;
while (i < num_buildings)
while (num_buildings--)
{
cop = (CELL_OBJECT*)*objects;
mat = cop->yang;
@ -992,8 +981,7 @@ int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
}
else
{
Z = Apply_InvCameraMatrixAndSetMatrix(&cop->pos, &CompoundMatrix[mat]);
prev_mat = mat;
Z = Apply_InvCameraMatrixAndSetMatrix(&cop->pos, &CompoundMatrix[prev_mat = mat]);
}
model = Z > DRAW_LOD_DIST_LOW ? pLodModels[cop->type] : modelpointers[cop->type];
@ -1014,8 +1002,6 @@ int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
if (PRIMTAB_SIZE - drawlimit < 60000)
break;
i++;
objects++;
}
@ -1387,10 +1373,10 @@ void DrawMapPSX(int* comp_val)
else
distScale = goFaster & 31;
i = (gDrawDistance >> distScale) - 1; // [A]
i = (gDrawDistance >> distScale); // [A]
// walk through all cells
while (i >= 0)
do
{
if (ABS(hloop) + ABS(vloop) < 21)
{
@ -1516,49 +1502,32 @@ void DrawMapPSX(int* comp_val)
drawData.leftPlane += drawData.leftcos;
drawData.backPlane += drawData.backcos;
drawData.rightPlane += drawData.rightcos;
hloop++;
if (hloop + vloop == 1)
dir = 1;
dir = (++hloop + vloop == 1) ? 1 : dir;
}
else if (dir == 1)
{
drawData.leftPlane += drawData.leftsin;
drawData.backPlane += drawData.backsin;
drawData.rightPlane += drawData.rightsin;
vloop++;
//PVS_ptr += pvs_square;
if (hloop == vloop)
dir = 2;
dir = (hloop == ++vloop) ? 2 : dir;
}
else if (dir == 2)
{
hloop--;
drawData.leftPlane -= drawData.leftcos;
drawData.backPlane -= drawData.backcos;
drawData.rightPlane -= drawData.rightcos;
if (hloop + vloop == 0)
dir = 3;
dir = (--hloop + vloop == 0) ? 3 : dir;
}
else
{
drawData.leftPlane -= drawData.leftsin;
drawData.backPlane -= drawData.backsin;
drawData.rightPlane -= drawData.rightsin;
vloop--;
//PVS_ptr -= pvs_square;
if (hloop == vloop)
dir = 0;
dir = (hloop == --vloop) ? 0 : dir;
}
i--;
}
}while (i-- > 0);
#if 0
char tempBuf[512];

View File

@ -417,21 +417,6 @@ void DrawAllAnimatingObjects(CELL_OBJECT** objects, int num_animated)
// [A] optimized
animate_object(cop, aop[model->normals].internal_id);
#if 0
type = model->instance_number == -1 ? type : model->instance_number;
for (j = 0; j < num_anim_objects; j++)
{
if (type == aop->model_num)
{
animate_object(cop, aop->internal_id);
aop -= j;
break;
}
aop++;
}
#endif
}
}

View File

@ -11,8 +11,7 @@
// [D] [T] [A]
void Tile1x1(MODEL *model)
{
int opz;
int Z;
int opz, Z;
int ofse;
PL_POLYFT4* polys;
int i;
@ -34,7 +33,7 @@ void Tile1x1(MODEL *model)
#endif
i = model->num_polys;
while (i > 0)
while (i-- > 0)
{
// iterate through polygons
// with skipping
@ -81,7 +80,6 @@ void Tile1x1(MODEL *model)
}
polys = (PL_POLYFT4*)((char*)polys + plotContext.polySizes[ptype]);
i--;
}
#ifdef USE_PGXP
@ -97,11 +95,9 @@ void DrawTILES(PACKED_CELL_OBJECT** tiles, int tile_amount)
{
MODEL* pModel;
PACKED_CELL_OBJECT *ppco;
int yang, dofse;
PACKED_CELL_OBJECT** tilePointers;
int previous_matrix, yang, dofse, Z;
int model_number;
PACKED_CELL_OBJECT **tilePointers;
int previous_matrix;
int Z;
if (gTimeOfDay > -1)
{
@ -124,8 +120,6 @@ void DrawTILES(PACKED_CELL_OBJECT** tiles, int tile_amount)
plotContext.colour = col * 0x30000 | col * 0x300 | col * 3 | 0x2C000000;
}
tile_amount--;
plotContext.ot = current->ot;
plotContext.current = current;
plotContext.primptr = current->primptr;
@ -137,16 +131,14 @@ void DrawTILES(PACKED_CELL_OBJECT** tiles, int tile_amount)
tilePointers = (PACKED_CELL_OBJECT **)tiles;
while (tile_amount != -1)
while (tile_amount--)
{
ppco = *tilePointers;
ppco = *tilePointers++;
plotContext.f4colourTable[6] = ppco->pos.vx;
plotContext.f4colourTable[7] = (ppco->pos.vy << 0x10) >> 0x11;
plotContext.f4colourTable[8] = ppco->pos.vz;
tilePointers++;
yang = ppco->value & 0x3f;
model_number = (ppco->value >> 6) | (ppco->pos.vy & 1) << 10;
@ -156,8 +148,7 @@ void DrawTILES(PACKED_CELL_OBJECT** tiles, int tile_amount)
}
else
{
Z = Apply_InvCameraMatrixAndSetMatrix((VECTOR_NOPAD *)(plotContext.f4colourTable + 6), &CompoundMatrix[yang]);
previous_matrix = yang;
Z = Apply_InvCameraMatrixAndSetMatrix((VECTOR_NOPAD *)(plotContext.f4colourTable + 6), &CompoundMatrix[previous_matrix = yang]);
}
if (Z <= DRAW_LOD_DIST_HIGH)
@ -165,10 +156,12 @@ void DrawTILES(PACKED_CELL_OBJECT** tiles, int tile_amount)
if (Low2HighDetailTable[model_number] != 0xffff)
model_number = Low2HighDetailTable[model_number];
pModel = modelpointers[model_number];
if (Z < 2000)
TileNxN(modelpointers[model_number], 4, 75);
TileNxN(pModel, 4, 75);
else
TileNxN(modelpointers[model_number], 2, 35);
TileNxN(pModel, 2, 35);
}
else
{
@ -176,8 +169,6 @@ void DrawTILES(PACKED_CELL_OBJECT** tiles, int tile_amount)
Tile1x1(pModel);
}
tile_amount--;
}
current->primptr = plotContext.primptr;
}
@ -300,8 +291,7 @@ void makeMesh(MVERTEX(*VSP)[5][5], int m, int n)
void drawMesh(MVERTEX(*VSP)[5][5], int m, int n, _pct *pc)
{
POLY_FT4* prim;
int z;
int opz;
int z, opz;
prim = (POLY_FT4*)pc->primptr;
@ -401,18 +391,15 @@ void SubdivNxM(char *polys, int n, int m, int ofse)
// [D] [T]
void TileNxN(MODEL *model, int levels, int Dofse)
{
u_int ttype;
u_int ttype, tileTypes;
u_char *polys;
u_int tileTypes;
int i;
int ofse;
ttype = 0;
polys = (u_char *)model->poly_block;
plotContext.verts = (SVECTOR *)model->vertices;
// tile types comes right after model header it seems
// WEIRD: tile types comes right after model header it seems
tileTypes = *(u_int *)(model + 1) >> 2;
// grass should be under pavements and other things
@ -421,38 +408,39 @@ void TileNxN(MODEL *model, int levels, int Dofse)
else
ofse = 133;
i = 0;
int _m[5] = {
levels, levels, 0, 1, levels
};
int _ofse[5] = {
ofse, ofse, 0, Dofse, 133
};
while (i < model->num_polys)
i = model->num_polys;
ttype = 0;
while (i--)
{
switch (ttype)
#ifdef USE_PGXP
switch (ttype)
{
case 0:
case 1:
#ifdef USE_PGXP
PGXP_SetZOffsetScale(0.0f, ofse > 200 ? 1.008f : 0.995f);
#endif
SubdivNxM((char *)polys, levels, levels, ofse);
break;
case 3:
#ifdef USE_PGXP
PGXP_SetZOffsetScale(0.0f, ofse < 40 ? 1.0f : 0.991f);
#endif
SubdivNxM((char *)polys, levels, 1, Dofse);
break;
case 4:
#ifdef USE_PGXP
PGXP_SetZOffsetScale(0.0f, 1.0f);
#endif
SubdivNxM((char *)polys, levels, levels, 133);
break;
case 0:
case 1:
PGXP_SetZOffsetScale(0.0f, ofse > 200 ? 1.008f : 0.995f);
break;
case 3:
PGXP_SetZOffsetScale(0.0f, ofse < 40 ? 1.0f : 0.991f);
break;
case 4:
PGXP_SetZOffsetScale(0.0f, 1.0f);
break;
}
#endif
SubdivNxM((char*)polys, levels, _m[ttype], _ofse[ttype]);
ttype = tileTypes & 7;
tileTypes >>= 3;
polys += plotContext.polySizes[*polys];
i++;
}
#ifdef USE_PGXP