src/ligthing.cpp 182 line

Code: Select all

```
static void calcTileIllum(UDWORD tileX, UDWORD tileY)
{
/* The number or normals that we got is in numNormals*/
Vector3f finalVector(0.0f, 0.0f, 0.0f);
unsigned int numNormals = 0; // How many normals have we got?
Vector3f normals[8]; // Maximum 8 possible normals
/* Quadrants look like:-
*
*
0 * 1
*
*
**********V**********
*
*
3 * 2
*
*
*/
/* Do quadrant 0 - tile that's above and left*/
normalsOnTile(tileX - 1, tileY - 1, 0, &numNormals, normals);
/* Do quadrant 1 - tile that's above and right*/
normalsOnTile(tileX, tileY - 1, 1, &numNormals, normals);
/* Do quadrant 2 - tile that's down and right*/
normalsOnTile(tileX, tileY, 2, &numNormals, normals);
/* Do quadrant 3 - tile that's down and left*/
normalsOnTile(tileX - 1, tileY, 3, &numNormals, normals);
for (unsigned int i = 0; i < numNormals; i++)
{
finalVector = finalVector + normals[i];
}
/* // same old code
int dotProduct = 0;
unsigned int val = 0;
dotProduct = glm::dot(normalise(finalVector), theSun_ForTileIllumination);
val = abs(dotProduct) / 16;
*/
unsigned int val = abs((int)glm::dot(normalise(finalVector), theSun_ForTileIllumination)) >> 4;
if (val == 0)
{
val = 1;
}
else if (val > 254)
{
val = 254;
}
mapTile(tileX, tileY)->illumination = val;
}
```

I rewrote the function. Checked, played, like no errors. I use shift instead of division, Threw out local variables which are used once.