@@ -170,14 +170,12 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
170170{
171171 int i ;
172172 int z ;
173- u_int spriteColour ;
174- u_int lightdd ;
173+ u_int spriteColour , lightdd ;
175174 u_char lightLevel ;
176175 MODEL * model ;
177176 PACKED_CELL_OBJECT * pco ;
178177 PACKED_CELL_OBJECT * * list ;
179178 int numShadows ;
180- int count ;
181179
182180#if 0 //def PSX
183181 MVERTEX5x5 & subdiVerts = * (MVERTEX5x5 * )(u_char * )getScratchAddr (0 );
@@ -219,8 +217,7 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
219217 shadowMatrix .m [i ][0 ] = inv_camera_matrix .m [i ][2 ];
220218 shadowMatrix .m [i ][1 ] = - inv_camera_matrix .m [i ][0 ];
221219 shadowMatrix .m [i ][2 ] = inv_camera_matrix .m [i ][0 ];
222- i -- ;
223- } while (i >= 0 );
220+ } while (i -- );
224221
225222
226223 plotContext .primptr = current -> primptr ;
@@ -235,9 +232,8 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
235232 plotContext .current = current ;
236233
237234 numShadows = 0 ;
238- count = numFound - 1 ;
239235
240- while (count != -1 )
236+ while (numFound -- )
241237 {
242238 pco = * list ;
243239 list ++ ;
@@ -303,8 +299,6 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
303299 plotContext .ot += 133 ;
304300 }
305301
306- count -- ;
307-
308302#ifdef PSX
309303#define MAX_TREE_SHADOW_DISTANCE 7000
310304#else
@@ -334,9 +328,7 @@ void DrawSprites(PACKED_CELL_OBJECT** sprites, int numFound)
334328// [D] [T]
335329void SetupPlaneColours (u_int ambient )
336330{
337- u_int r ;
338- u_int g ;
339- u_int b ;
331+ u_int r , g , b ;
340332
341333 if ((gWeather - 1U > 1 ) && gTimeOfDay != 0 && gTimeOfDay != 2 )
342334 {
@@ -585,10 +577,7 @@ void DrawAllTheCars(int view)
585577// [D] [T]
586578u_int normalIndex (SVECTOR * verts , u_int vidx )
587579{
588- SVECTOR * v0 ;
589- SVECTOR * v1 ;
590- SVECTOR * v2 ;
591-
580+ SVECTOR * v0 , * v1 , * v2 ;
592581 int x , y ;
593582 int th23 ;
594583
@@ -650,31 +639,32 @@ u_int normalIndex(SVECTOR* verts, u_int vidx)
650639 return th23 | 0x80 ;
651640}
652641
653- void PlotBuildingModel (MODEL * model , int rot , _pct * pc )
642+ // [A]
643+ void ConvertPolygonTypes (MODEL * model , _pct * pc )
654644{
655- int opz ;
656- int Z ;
645+ SVECTOR * srcVerts ;
657646 PL_POLYFT4 * polys ;
647+ u_char temp , ptype ;
658648 int i ;
659- int r ;
660- u_char temp ;
661- u_char ptype ;
662- POLY_FT4 * prims ;
663- SVECTOR * srcVerts ;
664- int combo ;
649+
650+ // [A] we are storing the processing flag here
651+ if (model -> tri_verts & 0x8000 )
652+ {
653+ return ;
654+ }
655+
656+ model -> tri_verts |= 0x8000 ;
665657
666658 srcVerts = (SVECTOR * )model -> vertices ;
667659 polys = (PL_POLYFT4 * )model -> poly_block ;
668-
669- combo = combointensity ;
670-
671660 i = model -> num_polys ;
672- while (i > 0 )
661+
662+ // pre-process vertices
663+ while (i -- > 0 )
673664 {
674- // iterate through polygons
675- // with skipping
676665 ptype = polys -> id & 0x1f ;
677666
667+ // convert poly types
678668 if ((ptype & 0x1 ) == 0 && ptype != 8 ) // is FT3 triangle?
679669 {
680670 temp = polys -> uv2 .v ;
@@ -690,7 +680,44 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
690680 if (ptype != 11 && ptype != 21 && ptype != 23 )
691681 {
692682 polys = (PL_POLYFT4 * )((char * )polys + pc -> polySizes [ptype ]);
693- i -- ;
683+ continue ;
684+ }
685+
686+ // also precalculate normal index
687+ if (ptype != 21 && (polys -> th & 0x80 ) == 0 )
688+ {
689+ polys -> th = normalIndex (srcVerts , * (u_int * )& polys -> v0 );
690+ }
691+ polys = (PL_POLYFT4 * )((char * )polys + pc -> polySizes [ptype ]);
692+ }
693+ }
694+
695+ void PlotBuildingModel (MODEL * model , int rot , _pct * pc )
696+ {
697+ int opz , Z , r ;
698+ PL_POLYFT4 * polys ;
699+ int i ;
700+ u_char ptype ;
701+ POLY_FT4 * prims ;
702+ SVECTOR * srcVerts ;
703+ int combo ;
704+
705+ srcVerts = (SVECTOR * )model -> vertices ;
706+ polys = (PL_POLYFT4 * )model -> poly_block ;
707+
708+ combo = combointensity ;
709+
710+ ConvertPolygonTypes (model , pc );
711+
712+ i = model -> num_polys ;
713+ while (i -- > 0 )
714+ {
715+ ptype = polys -> id & 0x1f ;
716+
717+ // skip certain polygons
718+ if (ptype != 11 && ptype != 21 && ptype != 23 )
719+ {
720+ polys = (PL_POLYFT4 * )((char * )polys + pc -> polySizes [ptype ]);
694721 continue ;
695722 }
696723
@@ -710,26 +737,14 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
710737 }
711738 else
712739 {
713- temp = polys -> th ;
714-
715- if ((polys -> th & 0x80 ) == 0 ) // cache normal index if it were not
716- temp = polys -> th = normalIndex (srcVerts , * (u_int * )& polys -> v0 );
717-
718- pc -> colour = pc -> f4colourTable [(r >> 3 ) * 4 - temp & 31 ];
740+ pc -> colour = pc -> f4colourTable [(r >> 3 ) * 4 - polys -> th & 31 ];
719741 }
720742
721743 if (opz > 0 )
722744 {
723745 pc -> tpage = (* pc -> ptexture_pages )[polys -> texture_set ];
724746 pc -> clut = (* pc -> ptexture_cluts )[polys -> texture_set ][polys -> texture_id ];
725747
726- ushort uv0 , uv1 , uv2 , uv3 ;
727-
728- uv0 = * (ushort * )& polys -> uv0 ;
729- uv1 = * (ushort * )& polys -> uv1 ;
730- uv2 = * (ushort * )& polys -> uv2 ;
731- uv3 = * (ushort * )& polys -> uv3 ;
732-
733748 prims = (POLY_FT4 * )pc -> primptr ;
734749
735750 setPolyFT4 (prims );
@@ -750,31 +765,27 @@ void PlotBuildingModel(MODEL* model, int rot, _pct* pc)
750765 prims -> tpage = pc -> tpage ;
751766 prims -> clut = pc -> clut ;
752767
753- * (ushort * )& prims -> u0 = uv0 ;
754- * (ushort * )& prims -> u1 = uv1 ;
755- * (ushort * )& prims -> u2 = uv3 ;
756- * (ushort * )& prims -> u3 = uv2 ;
768+ * (ushort * )& prims -> u0 = * ( ushort * ) & polys -> uv0 ;
769+ * (ushort * )& prims -> u1 = * ( ushort * ) & polys -> uv1 ;
770+ * (ushort * )& prims -> u2 = * ( ushort * ) & polys -> uv3 ;
771+ * (ushort * )& prims -> u3 = * ( ushort * ) & polys -> uv2 ;
757772
758773 addPrim (pc -> ot + (Z >> 1 ), prims );
759774
760775 pc -> primptr += sizeof (POLY_FT4 );
761776 }
762777
763778 polys = (PL_POLYFT4 * )((char * )polys + pc -> polySizes [ptype ]);
764- i -- ;
765779 }
766780}
767781
768782// [D] [T] [A] custom
769783void PlotBuildingModelSubdivNxN (MODEL * model , int rot , _pct * pc , int n )
770784{
771- int opz ;
785+ int opz , Z , r ;
772786 int diff , minZ , maxZ ;
773- int Z ;
774787 PL_POLYFT4 * polys ;
775788 int i ;
776- int r ;
777- u_char temp ;
778789 u_char ptype ;
779790 POLY_FT4 * prims ;
780791 SVECTOR * srcVerts ;
@@ -791,29 +802,18 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
791802
792803 combo = combointensity ;
793804
805+ ConvertPolygonTypes (model , pc );
806+
794807 i = model -> num_polys ;
795- while (i > 0 )
808+ while (i -- > 0 )
796809 {
797810 // iterate through polygons
798811 // with skipping
799812 ptype = polys -> id & 0x1f ;
800813
801- if ((ptype & 0x1 ) == 0 && ptype != 8 ) // is FT3 triangle?
802- {
803- temp = polys -> uv2 .v ;
804- polys -> uv3 .u = polys -> uv2 .u ;
805- polys -> uv3 .v = temp ;
806-
807- polys -> v3 = polys -> v2 ;
808-
809- polys -> id |= 1 ;
810- ptype |= 1 ;
811- }
812-
813814 if (ptype != 11 && ptype != 21 && ptype != 23 )
814815 {
815816 polys = (PL_POLYFT4 * )((char * )polys + pc -> polySizes [ptype ]);
816- i -- ;
817817 continue ;
818818 }
819819
@@ -833,12 +833,7 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
833833 }
834834 else
835835 {
836- temp = polys -> th ;
837-
838- if ((polys -> th & 0x80 ) == 0 ) // cache normal index if it were not
839- temp = polys -> th = normalIndex (srcVerts , * (u_int * )& polys -> v0 );
840-
841- pc -> colour = pc -> f4colourTable [(r >> 3 ) * 4 - temp & 31 ];
836+ pc -> colour = pc -> f4colourTable [(r >> 3 ) * 4 - polys -> th & 31 ];
842837 }
843838
844839 if (opz > 0 )
@@ -942,23 +937,19 @@ void PlotBuildingModelSubdivNxN(MODEL* model, int rot, _pct* pc, int n)
942937 }
943938
944939 polys = (PL_POLYFT4 * )((char * )polys + pc -> polySizes [ptype ]);
945- i -- ;
946940 }
947941}
948942
949943
950944// [D] [T]
951945int DrawAllBuildings (CELL_OBJECT * * objects , int num_buildings )
952946{
953- int mat ;
954- int zbias ;
947+ int i , mat , prev_mat ;
948+ int Z , zbias ;
955949 int drawlimit ;
956950 MODEL * model ;
957951 OTTYPE * ot ;
958952 CELL_OBJECT * cop ;
959- int i ;
960- int Z ;
961- int prev_mat ;
962953
963954 prev_mat = -1 ;
964955
@@ -979,9 +970,7 @@ int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
979970
980971 ot = plotContext .current -> ot + 8 ;
981972
982- i = 0 ;
983-
984- while (i < num_buildings )
973+ while (num_buildings -- )
985974 {
986975 cop = (CELL_OBJECT * )* objects ;
987976 mat = cop -> yang ;
@@ -992,8 +981,7 @@ int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
992981 }
993982 else
994983 {
995- Z = Apply_InvCameraMatrixAndSetMatrix (& cop -> pos , & CompoundMatrix [mat ]);
996- prev_mat = mat ;
984+ Z = Apply_InvCameraMatrixAndSetMatrix (& cop -> pos , & CompoundMatrix [prev_mat = mat ]);
997985 }
998986
999987 model = Z > DRAW_LOD_DIST_LOW ? pLodModels [cop -> type ] : modelpointers [cop -> type ];
@@ -1014,8 +1002,6 @@ int DrawAllBuildings(CELL_OBJECT** objects, int num_buildings)
10141002
10151003 if (PRIMTAB_SIZE - drawlimit < 60000 )
10161004 break ;
1017-
1018- i ++ ;
10191005 objects ++ ;
10201006 }
10211007
@@ -1387,10 +1373,10 @@ void DrawMapPSX(int* comp_val)
13871373 else
13881374 distScale = goFaster & 31 ;
13891375
1390- i = (gDrawDistance >> distScale ) - 1 ; // [A]
1376+ i = (gDrawDistance >> distScale ); // [A]
13911377
13921378 // walk through all cells
1393- while ( i >= 0 )
1379+ do
13941380 {
13951381 if (ABS (hloop ) + ABS (vloop ) < 21 )
13961382 {
@@ -1516,49 +1502,32 @@ void DrawMapPSX(int* comp_val)
15161502 drawData .leftPlane += drawData .leftcos ;
15171503 drawData .backPlane += drawData .backcos ;
15181504 drawData .rightPlane += drawData .rightcos ;
1519-
1520- hloop ++ ;
1521-
1522- if (hloop + vloop == 1 )
1523- dir = 1 ;
1505+ dir = (++ hloop + vloop == 1 ) ? 1 : dir ;
15241506 }
15251507 else if (dir == 1 )
15261508 {
15271509 drawData .leftPlane += drawData .leftsin ;
15281510 drawData .backPlane += drawData .backsin ;
15291511 drawData .rightPlane += drawData .rightsin ;
1530- vloop ++ ;
1531-
15321512 //PVS_ptr += pvs_square;
1533-
1534- if (hloop == vloop )
1535- dir = 2 ;
1513+ dir = (hloop == ++ vloop ) ? 2 : dir ;
15361514 }
15371515 else if (dir == 2 )
15381516 {
1539- hloop -- ;
15401517 drawData .leftPlane -= drawData .leftcos ;
15411518 drawData .backPlane -= drawData .backcos ;
15421519 drawData .rightPlane -= drawData .rightcos ;
1543-
1544- if (hloop + vloop == 0 )
1545- dir = 3 ;
1520+ dir = (-- hloop + vloop == 0 ) ? 3 : dir ;
15461521 }
15471522 else
15481523 {
15491524 drawData .leftPlane -= drawData .leftsin ;
15501525 drawData .backPlane -= drawData .backsin ;
15511526 drawData .rightPlane -= drawData .rightsin ;
1552- vloop -- ;
1553-
15541527 //PVS_ptr -= pvs_square;
1555-
1556- if (hloop == vloop )
1557- dir = 0 ;
1528+ dir = (hloop == -- vloop ) ? 0 : dir ;
15581529 }
1559-
1560- i -- ;
1561- }
1530+ }while (i -- > 0 );
15621531
15631532#if 0
15641533 char tempBuf [512 ];
0 commit comments