diff --git a/lib/ivis_common/ivisdef.h b/lib/ivis_common/ivisdef.h index 0436ad53f..c54b0b040 100644 --- a/lib/ivis_common/ivisdef.h +++ b/lib/ivis_common/ivisdef.h @@ -113,8 +113,8 @@ typedef struct iIMDShape { Sint32 oradius, sradius, radius, visRadius, xmin, xmax, ymin, ymax, zmin, zmax; Vector3i ocen; - UWORD numFrames; - UWORD animInterval; + UWORD numFrames; + UWORD animInterval; int npoints; int npolys; // After BSP this number is not updated - it stays the number of pre-bsp polys int nconnectors; // After BSP this number is not updated - it stays the number of pre-bsp polys diff --git a/lib/ivis_opengl/piedraw.c b/lib/ivis_opengl/piedraw.c index 49e63de48..611501cec 100644 --- a/lib/ivis_opengl/piedraw.c +++ b/lib/ivis_opengl/piedraw.c @@ -307,50 +307,59 @@ static transluscent_shape_t* tshapes = NULL; static unsigned int tshapes_size = 0; static unsigned int nb_tshapes = 0; -static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT specular, - int pieFlag, int pieFlagData) +static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT specular, int pieFlag, int pieFlagData) { - Sint32 tempY; + Sint32 tempY; int i, n; - Vector3i *pVertices; - Vector3f *pPixels; - iIMDPoly *pPolys; - PIEPOLY piePoly; - VERTEXID *index; - BOOL light = lighting; + Vector3i *pVertices; + Vector3f *pPixels; + iIMDPoly *pPolys; + PIEPOLY piePoly; + VERTEXID *index; + BOOL light = lighting; /* Set tranlucency */ - if (pieFlag & pie_ADDITIVE) { //Assume also translucent + if (pieFlag & pie_ADDITIVE) + { //Assume also translucent pie_SetFogStatus(FALSE); pie_SetRendMode(REND_ADDITIVE_TEX); colour.byte.a = (UBYTE)pieFlagData; pie_SetBilinear(TRUE); light = FALSE; - } else if (pieFlag & pie_TRANSLUCENT) { + } + else if (pieFlag & pie_TRANSLUCENT) + { pie_SetFogStatus(FALSE); pie_SetRendMode(REND_ALPHA_TEX); colour.byte.a = (UBYTE)pieFlagData; pie_SetBilinear(FALSE);//never bilinear with constant alpha, gives black edges light = FALSE; - } else { + } + else + { if (pieFlag & pie_BUTTON) { pie_SetFogStatus(FALSE); pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON); - } else { + } + else + { pie_SetFogStatus(TRUE); } pie_SetRendMode(REND_GOURAUD_TEX); //if hardware fog then alpha is set else unused in decal mode - //colour.byte.a = MAX_UB_LIGHT; - if (pieFlag & pie_NO_BILINEAR) { + if (pieFlag & pie_NO_BILINEAR) + { pie_SetBilinear(FALSE); - } else { + } + else + { pie_SetBilinear(TRUE); } } - if (pieFlag & pie_RAISE) { + if (pieFlag & pie_RAISE) + { pieFlagData = (shape->ymax * (pie_RAISE_SCALE - pieFlagData))/pie_RAISE_SCALE; } @@ -358,25 +367,24 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI //now draw the shape //rotate and project points from shape->points to scrPoints - pVertices = shape->points; - pPixels = &scrPoints[0]; - - //-- - for (i=0; inpoints; i++, pVertices++, pPixels++) { + for (i = 0, pVertices = shape->points, pPixels = scrPoints; + i < shape->npoints; + i++, pVertices++, pPixels++) + { tempY = pVertices->y; if (pieFlag & pie_RAISE) { tempY = pVertices->y - pieFlagData; - if (tempY < 0) tempY = 0; + if (tempY < 0) + tempY = 0; } else if (pieFlag & pie_HEIGHT_SCALED) { - if(pVertices->y>0) + if(pVertices->y > 0) { - tempY = (pVertices->y * pieFlagData)/pie_RAISE_SCALE; + tempY = (pVertices->y * pieFlagData) / pie_RAISE_SCALE; } - //if (tempY < 0) tempY = 0; } pPixels->x = pVertices->x; pPixels->y = tempY; @@ -424,7 +432,7 @@ static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELI /// returns true if the edges are adjacent -static int compare_edge (EDGE *A, EDGE *B, Vector3i *pVertices ) +static int compare_edge (EDGE *A, EDGE *B, const Vector3i *pVertices ) { if(A->from == B->to) { @@ -451,13 +459,11 @@ static int compare_edge (EDGE *A, EDGE *B, Vector3i *pVertices ) /// Makes sure only silhouette edges are present static void addToEdgeList(int a, int b, EDGE *edgelist, int *edge_count, Vector3i *pVertices) { - EDGE newEdge; + EDGE newEdge = {a, b}; int i; BOOL foundMatching = FALSE; - newEdge.from = a; - newEdge.to = b; - for(i=0;i<*edge_count;i++) + for(i = 0; i < *edge_count; i++) { if(edgelist[i].from < 0) { @@ -496,9 +502,9 @@ static inline float scale_y(float y, int flag, int flag_data) /// Draw the shadow for a shape static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* light) { - int i,j, n; - Vector3i *pVertices; - iIMDPoly *pPolys; + int i, j, n; + Vector3i *pVertices; + iIMDPoly *pPolys; int edge_count = 0; static EDGE *edgelist = NULL; static int edgelistsize = 256; @@ -517,11 +523,11 @@ static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* } else { - pPolys = shape->polys; - for (i = 0; i < shape->npolys; ++i, ++pPolys) { + + for (i = 0, pPolys = shape->polys; i < shape->npolys; ++i, ++pPolys) { Vector3f p[3], v[2], normal; VERTEXID current, first; - for(j=0;j<3;j++) + for(j = 0; j < 3; j++) { current = pPolys->pindex[j]; Vector3f_Set(&p[j], pVertices[current].x, scale_y(pVertices[current].y, flag, flag_data), pVertices[current].z); @@ -549,7 +555,7 @@ static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* } } // back to the first - addToEdgeList(pPolys->pindex[ pPolys->npnts-1 ], first, edgelist, &edge_count, pVertices); + addToEdgeList(pPolys->pindex[pPolys->npnts-1], first, edgelist, &edge_count, pVertices); } } //debug(LOG_WARNING, "we have %i edges", edge_count); @@ -558,10 +564,9 @@ static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* if(flag & pie_STATIC_SHADOW) { // first compact the current edgelist - j = 0; - for(i=0;ishadowEdgeList = malloc(sizeof(EDGE)*edge_count); - memcpy(shape->shadowEdgeList, edgelist, sizeof(EDGE)*edge_count); shape->nShadowEdges = edge_count; + shape->shadowEdgeList = malloc(sizeof(EDGE) * shape->nShadowEdges); + memcpy(shape->shadowEdgeList, edgelist, sizeof(EDGE) * shape->nShadowEdges); } } @@ -580,13 +585,11 @@ static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* glBegin(GL_QUADS); for(i=0;ix, scale_y(pVertices[b].y, flag, flag_data)+light->y, pVertices[b].z+light->z); @@ -599,13 +602,16 @@ static void pie_DrawShadow(iIMDShape *shape, int flag, int flag_data, Vector3f* glDisable(GL_DEPTH_TEST); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glColor4ub(0xFF,0,0,0xFF); + glColor4ub(0xFF, 0, 0, 0xFF); glBegin(GL_LINES); - for(i=0;ix == b->x && a->y == b->y && a->z == b->z; +} + + //************************************************************************* diff --git a/src/display3d.c b/src/display3d.c index de6051a94..62754ccf3 100644 --- a/src/display3d.c +++ b/src/display3d.c @@ -248,15 +248,14 @@ static BOOL mouseLocated = TRUE; /* The box used for multiple selection - present screen coordinates */ /* The game palette */ -iPalette gamePal; -UDWORD currentGameFrame; -static UDWORD numTiles = 0; -static SDWORD tileZ = 8000; -static QUAD dragQuad; -//UDWORD averageHeight; +iPalette gamePal; +UDWORD currentGameFrame; +static UDWORD numTiles = 0; +static SDWORD tileZ = 8000; +static QUAD dragQuad; /* temporary buffer used for flattening IMDs */ -static Vector3i alteredPoints[iV_IMD_MAX_POINTS]; +static Vector3i alteredPoints[iV_IMD_MAX_POINTS]; //number of tiles visible UDWORD visibleXTiles; @@ -1726,7 +1725,7 @@ void renderFeature(FEATURE *psFeature) UDWORD brightness, specular; Vector3i dv; Vector3i *vecTemp; - BOOL bForceDraw = ( !getRevealStatus() && psFeature->psStats->visibleAtStart); + BOOL bForceDraw = ( !getRevealStatus() && psFeature->psStats->visibleAtStart); int shadowFlags = 0; if (psFeature->visible[selectedPlayer] || godMode || demoGetStatus() || bForceDraw) @@ -1763,12 +1762,8 @@ void renderFeature(FEATURE *psFeature) iV_MatrixRotateY(-rotation); - -// centreX = ( player.p.x + ((visibleXTiles/2)<sDisplay.imd->ymax>300) if(psFeature->psStats->subType == FEAT_SKYSCRAPER) { objectShimmy((BASE_OBJECT*)psFeature); @@ -1783,7 +1778,7 @@ void renderFeature(FEATURE *psFeature) brightness = avGetObjLightLevel((BASE_OBJECT*)psFeature,brightness); } - brightness = lightDoFogAndIllumination(brightness,getCentreX()-featX,getCentreZ()-featY, &specular); + brightness = lightDoFogAndIllumination(brightness, getCentreX() - featX, getCentreZ() - featY, &specular); if(psFeature->psStats->subType == FEAT_BUILDING || psFeature->psStats->subType == FEAT_SKYSCRAPER || psFeature->psStats->subType == FEAT_OIL_DRUM) @@ -1794,7 +1789,7 @@ void renderFeature(FEATURE *psFeature) if(psFeature->psStats->subType == FEAT_OIL_RESOURCE) { vecTemp = psFeature->sDisplay.imd->points; - flattenImd(psFeature->sDisplay.imd,psFeature->x,psFeature->y,0); + flattenImd(psFeature->sDisplay.imd, psFeature->x, psFeature->y, 0); /* currentGameFrame/2 set anim running - GJ hack */ pie_Draw3DShape(psFeature->sDisplay.imd, currentGameFrame/2, 0, brightness, specular, 0, 0); psFeature->sDisplay.imd->points = vecTemp; @@ -2065,7 +2060,7 @@ void renderStructure(STRUCTURE *psStructure) rz = player.p.z & (TILE_UNITS-1); /* Translate */ - iV_TRANSLATE(rx,0,-rz); + iV_TRANSLATE(rx, 0, -rz); /* OK - here is where we establish which IMD to draw for the building - luckily static objects, * buildings in other words are NOT made up of components - much quicker! */ @@ -2107,7 +2102,7 @@ void renderStructure(STRUCTURE *psStructure) /* Draw the building's base first */ baseImd = psStructure->pStructureType->pBaseIMD; - if(baseImd!=NULL) + if(baseImd != NULL) { pie_Draw3DShape(baseImd, 0, 0, buildingBrightness, specular, 0,0); } @@ -2120,16 +2115,16 @@ void renderStructure(STRUCTURE *psStructure) imd = psStructure->sDisplay.imd; - if(imd!=NULL && bHitByElectronic) + if(imd != NULL && bHitByElectronic) { // Get a copy of the points - memcpy(alteredPoints,imd->points,imd->npoints*sizeof(Vector3i)); + memcpy(alteredPoints, imd->points, imd->npoints * sizeof(Vector3i)); for(i=0; inpoints; i++) { SDWORD yVar = (10 - rand() % 20); - alteredPoints[i].x +=yVar - (rand()%2*yVar); - alteredPoints[i].z +=yVar - (rand()%2*yVar); + alteredPoints[i].x += yVar - (rand()%2*yVar); + alteredPoints[i].z += yVar - (rand()%2*yVar); } temp = imd->points; imd->points = alteredPoints; @@ -2467,7 +2462,6 @@ void renderDeliveryPoint(FLAG_POSITION *psPosition) Vector3i dv; SDWORD x, y, r; Vector3i *temp = NULL; -// SDWORD centreX, centreZ; SDWORD buildingBrightness, specular; //store the frame number for when deciding what has been clicked on psPosition->frameNumber = currentGameFrame; @@ -2489,7 +2483,6 @@ void renderDeliveryPoint(FLAG_POSITION *psPosition) iV_TRANSLATE(rx,0,-rz); //quick check for invalid data - //ASSERT( psPosition->factoryType < NUM_FACTORY_TYPES && ASSERT( psPosition->factoryType < NUM_FLAG_TYPES && psPosition->factoryInc < MAX_FACTORY, "Invalid assembly point" ); if(!psPosition->selected) @@ -2499,20 +2492,12 @@ void renderDeliveryPoint(FLAG_POSITION *psPosition) psPosition->coords.x, psPosition->coords.y,0); } - pie_MatScale(50); //they are all big now so make this one smaller too + pie_MatScale(50); // they are all big now so make this one smaller too -// centreX = ( player.p.x + ((visibleXTiles/2)<coords.x, getCentreZ() - psPosition->coords.y, (UDWORD*)&specular); - buildingBrightness = pie_MAX_BRIGHT_LEVEL; - - buildingBrightness = lightDoFogAndIllumination((UBYTE)buildingBrightness, - getCentreX()-psPosition->coords.x,getCentreZ()-psPosition->coords.y, (UDWORD*)&specular); - -// pie_Draw3DShape(pAssemblyPointIMDs[psPosition->factoryInc], 0, 0, - // buildingBrightness, 0, pie_TRANSLUCENT | pie_NO_BILINEAR, EFFECT_DELIVERY_POINT_TRANSPARENCY); - pie_Draw3DShape(pAssemblyPointIMDs[psPosition->factoryType][psPosition->factoryInc], - 0, 0, buildingBrightness, specular, pie_NO_BILINEAR, 0); + pie_Draw3DShape(pAssemblyPointIMDs[psPosition->factoryType][psPosition->factoryInc], 0, 0, buildingBrightness, specular, pie_NO_BILINEAR, 0); if(!psPosition->selected) { @@ -2589,7 +2574,7 @@ static BOOL renderWallSection(STRUCTURE *psStructure) fit tightly to the ground and to neighbours. */ imd = psStructure->pStructureType->pBaseIMD; - if(imd!=NULL) + if(imd != NULL) { UDWORD centreHeight; @@ -2628,8 +2613,8 @@ static BOOL renderWallSection(STRUCTURE *psStructure) rotation = DEG( (int)psStructure->direction ); iV_MatrixRotateY(-rotation); - // objectShimmy((BASE_OBJECT*)psStructure); - if(imd!=NULL) + + if(imd != NULL) { // Make the imd pointer to the vertex list point to ours temp = imd->points; @@ -2703,8 +2688,6 @@ void renderShadow( DROID *psDroid, iIMDShape *psShadowIMD ) Vector3i *pVecTemp; SDWORD shadowScale; UDWORD brightness, specular; -// SDWORD centreX, centreZ; - dv.x = (psDroid->x - player.p.x) - terrainMidX*TILE_UNITS; if(psDroid->droidType == DROID_TRANSPORTER) @@ -4142,11 +4125,10 @@ static iIMDShape *flattenImd(iIMDShape *imd, UDWORD structX, UDWORD structY, UDW { UDWORD i, centreHeight; - ASSERT( imd->npoints < iV_IMD_MAX_POINTS, - "flattenImd: too many points in the PIE to flatten it" ); + ASSERT( imd->npoints < iV_IMD_MAX_POINTS, "flattenImd: too many points in the PIE to flatten it" ); /* Get a copy of the points */ - memcpy(alteredPoints,imd->points,imd->npoints*sizeof(Vector3i)); + memcpy(alteredPoints, imd->points, imd->npoints * sizeof(Vector3i)); /* Get the height of the centre point for reference */ centreHeight = map_Height(structX,structY); @@ -4161,7 +4143,7 @@ static iIMDShape *flattenImd(iIMDShape *imd, UDWORD structX, UDWORD structY, UDW switch(direction) { case 0: - for(i=0; i<(UDWORD)imd->npoints; i++) + for(i = 0; i < (UDWORD)imd->npoints; i++) { if (abs(alteredPoints[i].x) >= 63 || abs(alteredPoints[i].z) >= 63) { diff --git a/src/structure.c b/src/structure.c index 0c7b46270..ce0966d88 100644 --- a/src/structure.c +++ b/src/structure.c @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /*! - * \file Structure.c + * \file structure.c * * Store Structure stats. * WARNING!!!!!! @@ -3954,8 +3954,8 @@ static BOOL canSmoke(STRUCTURE *psStruct) /* The main update routine for all Structures */ void structureUpdate(STRUCTURE *psBuilding) { - UDWORD widthScatter,breadthScatter; - UDWORD percentDamage, emissionInterval, iPointsToAdd, iPointsRequired; + UDWORD widthScatter,breadthScatter; + UDWORD percentDamage, emissionInterval, iPointsToAdd, iPointsRequired; Vector3i dv; ASSERT( psBuilding != NULL, @@ -3975,8 +3975,6 @@ void structureUpdate(STRUCTURE *psBuilding) } } - //-- - /* Only add smoke if they're visible and they can 'burn' */ if(psBuilding->visible[selectedPlayer] && canSmoke(psBuilding)) { @@ -4073,7 +4071,8 @@ void structureUpdate(STRUCTURE *psBuilding) //add the blue flashing effect for multiPlayer if(bMultiPlayer && ONEINTEN) { - Vector3i position, *point; + Vector3i position; + Vector3i *point; SDWORD realY; UDWORD pointIndex; @@ -4085,8 +4084,8 @@ void structureUpdate(STRUCTURE *psBuilding) position.z = psBuilding->y - point->z; effectSetSize(30); - addEffect(&position,EFFECT_EXPLOSION,EXPLOSION_TYPE_SPECIFIED,TRUE, - getImdFromIndex(MI_PLASMA),0); + addEffect(&position, EFFECT_EXPLOSION, EXPLOSION_TYPE_SPECIFIED, TRUE, + getImdFromIndex(MI_PLASMA), 0); } if (iPointsToAdd)