From 345581c9ac33240c8150f1e1a5bc772b5416130b Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Mon, 16 Apr 2007 19:09:09 +0000 Subject: [PATCH] Fix a bug introduced in r1469, which produced gaps where the buildings should be and made the terrain jump around. (display3d.c) Additionaly: - Cleanup indention - Remove an unused, commented out function - Make code a bit more readable - Insert suggestion into display3d.h (playerXTiles and rx are only use in one otehr file each, so maybe we could wrap them into a function for the purpose of encapsulation. The comment is ugly, I know.) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1479 4a71c877-e1ca-e34f-864e-861f7616d084 --- src/display3d.c | 8 ++--- src/display3d.h | 12 ++++--- src/lighting.c | 87 +++---------------------------------------------- src/map.h | 3 +- 4 files changed, 17 insertions(+), 93 deletions(-) diff --git a/src/display3d.c b/src/display3d.c index 67295f61c..0f7a0c81c 100644 --- a/src/display3d.c +++ b/src/display3d.c @@ -180,7 +180,7 @@ BOOL godMode; static UWORD WaterTileID = WATER_TILE; static UWORD RiverBedTileID = BED_TILE; -static FRACT waterRealValue = 0.0f; +static float waterRealValue = 0.0f; #define WAVE_SPEED 4 static SWORD vOffset = 1; #define MAX_FIRE_STAGE 32 @@ -689,7 +689,7 @@ static void drawTiles(iView *camera, iView *player) if(vOffset >= 64/2) { vOffset = 0; - waterRealValue = 0; + waterRealValue = 0.0f; } } /* Is the scene spinning? - showcase demo stuff */ @@ -707,8 +707,8 @@ static void drawTiles(iView *camera, iView *player) SetBSPCameraPos(BSPCamera.x, BSPCamera.y, BSPCamera.z); /* Find our position in tile coordinates */ - playerXTile = player->p.x / TILE_UNITS; - playerZTile = player->p.z / TILE_UNITS; + playerXTile = player->p.x >> TILE_SHIFT; + playerZTile = player->p.z >> TILE_SHIFT; /* Get the x,z translation components */ rx = (player->p.x) & (TILE_UNITS-1); diff --git a/src/display3d.h b/src/display3d.h index 0fdc9e3a2..3a84273b7 100644 --- a/src/display3d.h +++ b/src/display3d.h @@ -72,22 +72,24 @@ extern void setProximityDraw(BOOL val); extern void renderShadow( DROID *psDroid, iIMDShape *psShadowIMD ); -extern UDWORD getSuggestedPitch ( void ); +extern UDWORD getSuggestedPitch( void ); extern BOOL clipXY ( SDWORD x, SDWORD y); extern BOOL init3DView(void); extern void initViewPosition(void); extern iView player,camera; -extern UDWORD distance; -extern UDWORD terrainOutline; +extern UDWORD distance; +extern UDWORD terrainOutline; extern UDWORD xOffset,yOffset; -extern BOOL selectAttempt; +extern BOOL selectAttempt; extern BOOL draggingTile; extern struct iIMDShape *g_imd; extern BOOL droidSelected; extern UDWORD terrainMidX,terrainMidY; -extern Sint32 playerXTile, playerZTile, rx, rz; + // FIXME This only used in one location outside of display3d.c, maybe create a wrapper function instead? -> +extern Sint32 playerXTile, playerZTile, // -> lighting.c + rx, rz; // -> atmos.c extern SDWORD scrollSpeed; extern iBitmap **tilesRAW; diff --git a/src/lighting.c b/src/lighting.c index 2f4af22fd..bfe1b12ac 100644 --- a/src/lighting.c +++ b/src/lighting.c @@ -417,83 +417,6 @@ void normalsOnTile(UDWORD tileX, UDWORD tileY, UDWORD quadrant) } // end switch } -#if 0 -/* Processes a light into the tileScreenInfo structure - this needs - to be optimised and profiled as it's costly to perform -*/ -void processLight(LIGHT *psLight) -{ -SDWORD i,j; -UDWORD tileX,tileY; -UDWORD offset; -UDWORD distToCorner; -UDWORD percent; -UDWORD xIndex,yIndex; -SDWORD xUpper,yUpper,xLower,yLower; -SDWORD gridMinX,gridMinY,gridMaxX,gridMaxY; - - /* Firstly - there's no point processing lights that are off the grid */ - if(clipXY(psLight->position.x,psLight->position.z) == FALSE) - { - return; - } - - tileX = (psLight->position.x/TILE_UNITS); - tileY = (psLight->position.z/TILE_UNITS); - offset = psLight->range/TILE_UNITS; - - if(player.p.x>=0) - { - gridMinX = player.p.x/TILE_UNITS; - } - else - { - gridMinX = 0; - } - if(player.p.z >=0) - { - gridMinY = player.p.z/TILE_UNITS; - } - else - { - gridMinY = 0; - } - gridMaxX = gridMinX + visibleXTiles; - gridMaxY = gridMinY + visibleYTiles; - - xLower = tileX - offset; - xUpper = tileX + offset; - yLower = tileY - offset; - yUpper = tileY + offset; - - for(i=xLower; igridMinX && igridMinY && jposition); - /* If we're inside the range of the light */ - if(distToCornerrange) - { - /* Find how close we are to it */ - percent = 100 - PERCENT(distToCorner,psLight->range); - - xIndex = i - playerXTile; - yIndex = j - playerZTile; - colourTile(xIndex,yIndex,psLight->colour, (UBYTE)percent); - } - } - } - } -} - -#endif - void processLight(LIGHT *psLight) { SDWORD tileX,tileY; @@ -568,7 +491,7 @@ UDWORD percent; { distToCorner = calcDistToTile(i,j,&psLight->position); /* If we're inside the range of the light */ - if(distToCorner<(SDWORD)psLight->range) + if (distToCorner<(SDWORD)psLight->range) { /* Find how close we are to it */ percent = 100 - PERCENT(distToCorner,psLight->range); @@ -576,11 +499,11 @@ UDWORD percent; yIndex = j - playerZTile; // Might go off the grid for light ranges > one tile // if(i=0 && j>=0) - if(xIndex >= 0 && yIndex >= 0 && - xIndex < (SDWORD)visibleXTiles && - yIndex < (SDWORD)visibleYTiles) + if ( xIndex >= 0 && yIndex >= 0 && + xIndex < (SDWORD)visibleXTiles && + yIndex < (SDWORD)visibleYTiles ) { - colourTile(xIndex,yIndex,psLight->colour, (UBYTE)(2*percent)); + colourTile(xIndex, yIndex, psLight->colour, (UBYTE)(2*percent)); } } diff --git a/src/map.h b/src/map.h index 87aeb4e1f..01c27fe6f 100644 --- a/src/map.h +++ b/src/map.h @@ -200,13 +200,12 @@ extern void mapWaterProcess( void ); /* Return a pointer to the tile structure at x,y */ static inline MAPTILE *mapTile(UDWORD x, UDWORD y) { - ASSERT( x < mapWidth, "mapTile: x coordinate bigger than map width" ); ASSERT( y < mapHeight, "mapTile: y coordinate bigger than map height" ); - return psMapTiles + x + (y * mapWidth); + return &psMapTiles[x + (y * mapWidth)]; } /* Return height of tile at x,y */