This is a snapshot of my vertex array work. It uses vertex arrays for
the whole map, but only updates colours at the moment. Cybersphinx
wanted a copy of this. It does not work correctly yet, though. Colour
diffusion is wrong, as can be seen in the blocky colours that end up
on the drawn map.

  - Per
Index: src/display3d.c
===================================================================
--- src/display3d.c	(revision 3071)
+++ src/display3d.c	(working copy)
@@ -600,6 +600,9 @@
 		pie_BeginLighting(&theSun);
 	}
 
+	// flush the old, in with the new
+	pie_TerrainNewFrame();
+
 	/* ---------------------------------------------------------------- */
 	/* Rotate and project all the tiles within the grid                 */
 	/* ---------------------------------------------------------------- */
@@ -609,7 +612,6 @@
 		for (j = 0; j < (SDWORD)visibleTiles.x+1; j++)
 		{
 			Vector2i screen;
-			PIELIGHT TileIllum = WZCOL_BLACK;
 			int shiftVal = 0;
 
 			tileScreenInfo[i][j].pos.x = world_coord(j - terrainMidX);
@@ -636,19 +638,24 @@
 
 				if (getRevealStatus() && !godMode)
 				{
-					TileIllum = pal_SetBrightness(psTile->level == UBYTE_MAX ? 1 : psTile->level);
+					// Tile is darkened by Fog of War. Notice that we temporarily darken
+					// vertices for Fog of War, rather than permanently change them to their
+					// real colour upon discovery - this moves fog of war processing to the
+					// early part of the game, where we do not have so many others things to draw.
+					PIELIGHT TileIllum = pal_SetBrightness(psTile->level == UBYTE_MAX ? 1 : psTile->level);
+
+					pie_TerrainSetColour(playerXTile + j, playerZTile + i, TileIllum, TCOL_TILE | TCOL_DIFFUSE);
 				}
-				else
-				{
-					TileIllum = pal_SetBrightness(psTile->illumination);
-				}
 
 				// Real fog of war - darken where we cannot see enemy units moving around
 				if (bDisplaySensorRange && !psTile->activeSensor)
 				{
+					PIELIGHT TileIllum = pie_TerrainGetColour(playerXTile + j, playerZTile + i);
+
 					TileIllum.byte.r = TileIllum.byte.r / 2;
 					TileIllum.byte.g = TileIllum.byte.g / 2;
 					TileIllum.byte.b = TileIllum.byte.b / 2;
+					pie_TerrainSetColour(playerXTile + j, playerZTile + i, TileIllum, TCOL_TILE | TCOL_DIFFUSE);
 				}
 
 				if ( playerXTile+j <= 1 ||
@@ -665,10 +672,6 @@
 					// Push the terrain down for the river bed.
 					shiftVal = WATER_DEPTH + environGetData(playerXTile+j, playerZTile+i) * 1.5f;
 					tileScreenInfo[i][j].pos.y -= shiftVal;
-					// And darken it.
-					TileIllum.byte.r = (TileIllum.byte.r * 2) / 3;
-					TileIllum.byte.g = (TileIllum.byte.g * 2) / 3;
-					TileIllum.byte.b = (TileIllum.byte.b * 2) / 3;
 					pushedDown = TRUE;
 				}
 
@@ -704,7 +707,6 @@
 					tileScreenInfo[i][j].water = tileScreenInfo[i][j].screen;
 					tileScreenInfo[i][j].water_height = tileScreenInfo[i][j].pos.y;
 				}
-				setTileColour(playerXTile + j, playerZTile + i, TileIllum);
 			}
 			// hack since tileScreenInfo[i][j].screen is Vector3i and pie_RotateProject takes Vector2i as 2nd param
 			screen.x = tileScreenInfo[i][j].screen.x;
@@ -747,7 +749,8 @@
 			drawTerrainTile(i, j, FALSE);
 		}
 	}
-	pie_DrawTerrainDone(MIN(visibleTiles.x, mapWidth),  MIN(visibleTiles.y, mapHeight));
+	pie_TerrainDraw(MAX(0, playerXTile), MAX(0, playerZTile), 
+	                MIN(playerXTile + visibleTiles.x, mapWidth - 1),  MIN(playerZTile + visibleTiles.y, mapHeight - 1));
 
 	// Draw water edges
 	pie_SetDepthOffset(-2.0);
@@ -853,6 +856,8 @@
 
 BOOL init3DView(void)
 {
+	int i, j;
+
 	// the world centre - used for decaying lighting etc
 	gridCentreX = player.p.x + world_coord(visibleTiles.x / 2);
 	gridCentreZ = player.p.z + world_coord(visibleTiles.y / 2);
@@ -871,6 +876,9 @@
 	/* Make sure and change these to comply with map.c */
 	imdRot.x = -35;
 
+	/* Initialize vertex arrays */
+	pie_TerrainInit(mapWidth, mapHeight);
+
 	/* Get all the init stuff out of here? */
 	initWarCam();
 
@@ -898,6 +906,35 @@
 
 	memset(directionSet, FALSE, sizeof(directionSet));
 
+	/* Initialize vertex colours */
+	for (i = 0; i < mapWidth; i++)
+	{
+		/* Go through the x's */
+		for (j = 0; j < mapHeight; j++)
+		{
+			MAPTILE *psTile = mapTile(i, j);
+			PIELIGHT TileIllum = WZCOL_BLACK;
+			BOOL bEdgeTile = FALSE;
+
+			TileIllum = pal_SetBrightness(psTile->illumination);
+
+			if (j <= 1 || i <= 1 || i >= mapWidth - 2 || j >= mapHeight - 2)
+			{
+				bEdgeTile = TRUE;
+			}
+
+			// If it's the main water tile (has water texture) then darken it
+			if (TileNumber_tile(psTile->texture) == WATER_TILE && !bEdgeTile)
+			{
+				TileIllum.byte.r = (TileIllum.byte.r * 2) / 3;
+				TileIllum.byte.g = (TileIllum.byte.g * 2) / 3;
+				TileIllum.byte.b = (TileIllum.byte.b * 2) / 3;
+			}
+
+			pie_TerrainSetColour(i, j, TileIllum, TCOL_TILE | TCOL_PERMANENT | TCOL_DIFFUSE);
+		}
+	}
+
 	return TRUE;
 }
 
@@ -3705,7 +3742,6 @@
 	/* Get the correct tile index for the x/y coordinates */
 	SDWORD actualX = playerXTile + j, actualY = playerZTile + i;
 	MAPTILE *psTile = NULL;
-	BOOL bOutlined = FALSE;
 	UDWORD tileNumber = 0;
 	TERRAIN_VERTEX vertices[3];
 #if defined(SHOW_ZONES) || defined(SHOW_GATEWAYS)
@@ -3730,19 +3766,6 @@
 	{
 		psTile = mapTile(actualX, actualY);
 
-		colour[0][0] = psTile->colour;
-		if (actualY + 1 < mapHeight - 1)
-		{
-			colour[1][0] = mapTile(actualX, actualY + 1)->colour;
-		}
-		if (actualX + 1 < mapWidth - 1)
-		{
-			colour[0][1] = mapTile(actualX + 1, actualY)->colour;
-		}
-		if (actualX + 1 < mapWidth - 1 && actualY + 1 < mapHeight - 1)
-		{
-			colour[1][1] = mapTile(actualX + 1, actualY + 1)->colour;
-		}
 #if defined(SHOW_ZONES)
 		if (!fpathBlockingTile(actualX, actualY) ||
 			terrainType(psTile) == TER_WATER)
@@ -3784,23 +3807,20 @@
 	{
 		/* Clear it for next time round */
 		CLEAR_TILE_HIGHLIGHT(psTile);
-		bOutlined = TRUE;
-		//set tilenumber
 		if ( i < (LAND_XGRD-1) && j < (LAND_YGRD-1) ) // FIXME
 		{
 			if (outlineTile)
 			{
-				colour[0][0] = pal_SetBrightness(255);
-				colour[1][0] = pal_SetBrightness(255);
-				colour[0][1] = pal_SetBrightness(255);
-				colour[1][1] = pal_SetBrightness(255);
+				PIELIGHT colour = pal_SetBrightness(255);
+
+				pie_TerrainSetColour(actualX, actualY, colour, TCOL_TILE);
 			}
 			else
 			{
-				colour[0][0].byte.r = 255;
-				colour[1][0].byte.r = 255;
-				colour[0][1].byte.r = 255;
-				colour[1][1].byte.r = 255;
+				PIELIGHT colour = pie_TerrainGetColour(actualX, actualY);
+
+				colour.byte.r = 255;
+				pie_TerrainSetColour(actualX, actualY, colour, TCOL_TILE);
 			}
 		}
 	}
@@ -3811,8 +3831,6 @@
 	/* The first triangle */
 	vertices[0] = tileScreenInfo[i + 0][j + 0];
 	vertices[1] = tileScreenInfo[i + 0][j + 1];
-	vertices[0].light = colour[0][0];
-	vertices[1].light = colour[0][1];
 	if (onWaterEdge)
 	{
 		vertices[0].pos.y = tileScreenInfo[i + 0][j + 0].water_height;
@@ -3822,7 +3840,6 @@
 	if (psTile && TRI_FLIPPED(psTile))
 	{
 		vertices[2] = tileScreenInfo[i + 1][j + 0];
-		vertices[2].light = colour[1][0];
 		if (onWaterEdge)
 		{
 			vertices[2].pos.y = tileScreenInfo[i + 1][j + 0].water_height;
@@ -3831,7 +3848,6 @@
 	else
 	{
 		vertices[2] = tileScreenInfo[i + 1][j + 1];
-		vertices[2].light = colour[1][1];
 		if (onWaterEdge)
 		{
 			vertices[2].pos.y = tileScreenInfo[i + 1][j + 1].water_height;
@@ -3842,16 +3858,15 @@
 	{
 		pie_DrawWaterTriangle(vertices);
 	}
-	else
+	else if (tileOnMap(actualX, actualY))
 	{
-		pie_DrawTerrainTriangle(i * 2 + j * VISIBLE_XTILES * 2, vertices);
+		pie_DrawTerrainTriangle(actualX, actualY, 0, vertices, TRI_FLIPPED(psTile));
 	}
 
 	/* The second triangle */
 	if (psTile && TRI_FLIPPED(psTile))
 	{
 		vertices[0] = tileScreenInfo[i + 0][j + 1];
-		vertices[0].light = colour[0][1];
 		if (onWaterEdge)
 		{
 			vertices[0].pos.y = tileScreenInfo[i + 0][j + 1].water_height;
@@ -3860,7 +3875,6 @@
 	else
 	{
 		vertices[0] = tileScreenInfo[i + 0][j + 0];
-		vertices[0].light = colour[0][0];
 		if (onWaterEdge)
 		{
 			vertices[0].pos.y = tileScreenInfo[i + 0][j + 0].water_height;
@@ -3869,8 +3883,6 @@
 
 	vertices[1] = tileScreenInfo[i + 1][j + 1];
 	vertices[2] = tileScreenInfo[i + 1][j + 0];
-	vertices[1].light = colour[1][1];
-	vertices[2].light = colour[1][0];
 	if ( onWaterEdge )
 	{
 		vertices[1].pos.y = tileScreenInfo[i + 1][j + 1].water_height;
@@ -3881,9 +3893,9 @@
 	{
 		pie_DrawWaterTriangle(vertices);
 	}
-	else
+	else if (tileOnMap(actualX, actualY))
 	{
-		pie_DrawTerrainTriangle(i * 2 + j * VISIBLE_XTILES * 2 + 1, vertices);
+		pie_DrawTerrainTriangle(actualX, actualY, 1, vertices, TRI_FLIPPED(psTile));
 	}
 }
 
@@ -3946,26 +3958,18 @@
 
 		vertices[0] = tileScreenInfo[i + 0][j + 0];
 		vertices[0].pos.y = tileScreenInfo[i + 0][j + 0].water_height;
-		vertices[0].light = colour[0][0];
-		vertices[0].light.byte.a = WATER_ALPHA_LEVEL;
 
 		vertices[1] = tileScreenInfo[i + 0][j + 1];
 		vertices[1].pos.y = tileScreenInfo[i + 0][j + 1].water_height;
-		vertices[1].light = colour[0][1];
-		vertices[1].light.byte.a = WATER_ALPHA_LEVEL;
 
 		vertices[2] = tileScreenInfo[i + 1][j + 1];
 		vertices[2].pos.y = tileScreenInfo[i + 1][j + 1].water_height;
-		vertices[2].light = colour[1][1];
-		vertices[2].light.byte.a = WATER_ALPHA_LEVEL;
 
 		pie_DrawWaterTriangle(vertices);
 
 		vertices[1] = vertices[2];
 		vertices[2] = tileScreenInfo[i + 1][j + 0];
 		vertices[2].pos.y = tileScreenInfo[i + 1][j + 0].water_height;
-		vertices[2].light = colour[1][0];
-		vertices[2].light.byte.a = WATER_ALPHA_LEVEL;
 
 		pie_DrawWaterTriangle(vertices);
 	}
Index: lib/ivis_common/piedef.h
===================================================================
--- lib/ivis_common/piedef.h	(revision 3071)
+++ lib/ivis_common/piedef.h	(working copy)
@@ -76,6 +76,18 @@
 #define pie_MAX_POLYGONS		512
 #define pie_MAX_VERTICES_PER_POLYGON	6
 
+#define TCOL_UPPER_LEFT		0x001
+#define	TCOL_LOWER_LEFT		0x002
+#define TCOL_LOWER_RIGHT	0x004
+#define TCOL_UPPER_RIGHT	0x008
+#define TCOL_TILE		0x00F	// set all corners
+#define TCOL_DIFFUSE		0x010	// bleed the vertex colours into neighbouring tiles
+#define TCOL_PERMANENT		0x020	// change is permanent
+#define TCOL_LEFT		(TCOL_UPPER_LEFT | TCOL_LOWER_LEFT)
+#define TCOL_RIGHT		(TCOL_LOWER_RIGHT | TCOL_UPPER_RIGHT)
+#define TCOL_UPPER		(TCOL_UPPER_LEFT | TCOL_UPPER_RIGHT)
+#define TCOL_LOWER		(TCOL_LOWER_LEFT | TCOL_LOWER_RIGHT)
+
 /***************************************************************************/
 /*
  *	Global Definitions (STRUCTURES)
@@ -116,8 +128,13 @@
 extern void pie_Draw3DShape(iIMDShape *shape, int frame, int team, PIELIGHT colour, PIELIGHT specular, int pieFlag, int pieData);
 extern void pie_DrawImage(PIEIMAGE *image, PIERECT *dest, PIESTYLE *style);
 
-void pie_DrawTerrainDone(int mapx, int mapy);
-void pie_DrawTerrainTriangle(int index, const TERRAIN_VERTEX *aVrts);
+void pie_TerrainInit(int sizex, int sizey);
+void pie_TerrainNewFrame(void);
+void pie_TerrainDraw(int x1, int y1, int x2, int y2);
+void pie_TerrainSetColour(int x, int y, PIELIGHT colour, int flags);
+PIELIGHT pie_TerrainGetColour(int x, int y);
+
+void pie_DrawTerrainTriangle(int x, int y, int triangle, const TERRAIN_VERTEX *aVrts, BOOL flips);
 void pie_DrawWaterTriangle(const TERRAIN_VERTEX *aVrts);
 
 extern void pie_GetResetCounts(unsigned int* pPieCount, unsigned int* pTileCount, unsigned int* pPolyCount, unsigned int* pStateCount);
Index: lib/ivis_opengl/piedraw.c
===================================================================
--- lib/ivis_opengl/piedraw.c	(revision 3071)
+++ lib/ivis_opengl/piedraw.c	(working copy)
@@ -45,12 +45,15 @@
 #define COLOUR_COMPONENTS 4
 #define TEXCOORD_COMPONENTS 2
 #define VERTEX_COMPONENTS 3
-#define MAP_TRIANGLES (64 * 64 * 2) // two triangles per tile
-#define MAP_VERTICES (VERTICES_PER_TRIANGLE * MAP_TRIANGLES)
+#define TRIANGLES_PER_TILE 2
+#define VERTICES_PER_TILE (TRIANGLES_PER_TILE * VERTICES_PER_TRIANGLE)
 
-static GLubyte aColour[COLOUR_COMPONENTS * MAP_VERTICES];
-static GLfloat aTexCoord[TEXCOORD_COMPONENTS * MAP_VERTICES];
-static GLfloat aVertex[VERTEX_COMPONENTS * MAP_VERTICES];
+static GLubyte *aColour[2] = { NULL, NULL };
+static GLfloat *aTexCoord = NULL;
+static GLfloat *aVertex = NULL;
+static uint8_t *aFlips = NULL; // waste only 7 bits
+static Vector2i mapSize; // length of one array table row in tiles
+static int mapColourFirst, mapColourLast; // range modified
 
 extern BOOL drawing_interface;
 
@@ -968,37 +971,180 @@
  *
  ***************************************************************************/
 
-void pie_DrawTerrainDone(int mapx, int mapy)
+void pie_TerrainInit(int sizex, int sizey)
 {
+	int size = sizex * sizey;
+	int colSize = size * sizeof(GLubyte) * COLOUR_COMPONENTS * VERTICES_PER_TILE;
+
+	assert(sizex > 0 && sizey > 0);
+	aColour[0] = realloc(aColour[0], colSize);
+	aColour[1] = realloc(aColour[1], colSize);
+	aTexCoord = realloc(aTexCoord, size * sizeof(GLfloat) * TEXCOORD_COMPONENTS * VERTICES_PER_TILE);
+	aVertex = realloc(aVertex, size * sizeof(GLfloat) * VERTEX_COMPONENTS * VERTICES_PER_TILE);
+	aFlips = realloc(aFlips, size);
+	mapSize.x = sizex;
+	mapSize.y = sizey;
+	mapColourFirst = size;
+	mapColourLast = -1;
+}
+
+void pie_TerrainNewFrame()
+{
+/*	if (mapColourLast != -1)
+	{
+		// Recreate the final array by only copying over the changed range
+		memcpy(aColour[1] + mapColourFirst * COLOUR_COMPONENTS,
+		       aColour[0] + mapColourFirst * COLOUR_COMPONENTS,
+		       sizeof(*aColour[0]) * (mapColourLast - mapColourFirst + 1) * VERTICES_PER_TILE * COLOUR_COMPONENTS);
+	}*/
+	memcpy(aColour[1], aColour[0], sizeof(*aColour[0]) * mapSize.x * mapSize.y * VERTICES_PER_TILE * COLOUR_COMPONENTS);
+	mapColourLast = -1;
+	mapColourFirst = mapSize.x * mapSize.y;
+}
+
+static void vertexColour(int index, PIELIGHT colour, BOOL permanent)
+{
+	UDWORD *col0 = ((UDWORD*)aColour[0]) + index;
+	UDWORD *col1 = ((UDWORD*)aColour[1]) + index;
+
+	*col1 = colour.argb;
+	if (permanent)
+	{
+		*col0 = colour.argb;
+	}
+}
+
+void pie_TerrainSetColour(int x, int y, PIELIGHT colour, int flags)
+{
+	const int index = y * mapSize.x + x;
+	const BOOL flipped = aFlips[index];
+	const int colindex = index * VERTICES_PER_TILE;
+	int permanent = flags & TCOL_PERMANENT;
+
+	if (x < 0 || y < 0 || x > mapSize.x - 1 || y > mapSize.y - 1)
+	{
+		return; // an expected "error"
+	}
+
+	// This got complicated since we have to deal with flipped triangles
+	if (flags & TCOL_UPPER_LEFT)
+	{
+		vertexColour(colindex, colour, permanent);
+	}
+	if (flags & TCOL_UPPER_LEFT && flipped)
+	{
+		vertexColour(colindex + VERTICES_PER_TRIANGLE, colour, permanent);
+	}
+	if (flags & TCOL_UPPER_RIGHT && flipped)
+	{
+		vertexColour(colindex + 2, colour, permanent);
+	}
+	if (flags & TCOL_UPPER_RIGHT && !flipped)
+	{
+		vertexColour(colindex + VERTICES_PER_TRIANGLE, colour, permanent);
+	}
+	if (flags & TCOL_LOWER_RIGHT && !flipped)
+	{
+		vertexColour(colindex + 2, colour, permanent);
+	}
+	if (flags & TCOL_LOWER_RIGHT)
+	{
+		vertexColour(colindex + VERTICES_PER_TRIANGLE + 1, colour, permanent);
+	}
+	if (flags & TCOL_LOWER_LEFT)
+	{
+		vertexColour(colindex + 1, colour, permanent);
+		vertexColour(colindex + VERTICES_PER_TRIANGLE + 2, colour, permanent);
+	}
+
+	if (flags & TCOL_DIFFUSE)
+	{
+		if (flags & TCOL_UPPER_LEFT)
+		{
+			pie_TerrainSetColour(x - 1, y, colour, TCOL_RIGHT | permanent);
+			pie_TerrainSetColour(x - 1, y - 1, colour, TCOL_LOWER_RIGHT | permanent);
+			pie_TerrainSetColour(x, y - 1, colour, TCOL_LOWER | permanent);
+		}
+		if (flags & TCOL_UPPER_RIGHT)
+		{
+			pie_TerrainSetColour(x + 1, y, colour, TCOL_LEFT | permanent);
+			pie_TerrainSetColour(x + 1, y - 1, colour, TCOL_LOWER_LEFT | permanent);
+			pie_TerrainSetColour(x, y - 1, colour, TCOL_LOWER | permanent);
+		}
+		if (flags & TCOL_LOWER_LEFT)
+		{
+			pie_TerrainSetColour(x - 1, y, colour, TCOL_RIGHT | permanent);
+			pie_TerrainSetColour(x - 1, y + 1, colour, TCOL_UPPER_RIGHT | permanent);
+			pie_TerrainSetColour(x, y + 1, colour, TCOL_UPPER | permanent);
+		}
+		if (flags & TCOL_LOWER_RIGHT)
+		{
+			pie_TerrainSetColour(x + 1, y, colour, TCOL_LEFT | permanent);
+			pie_TerrainSetColour(x + 1, y + 1, colour, TCOL_UPPER_LEFT | permanent);
+			pie_TerrainSetColour(x, y + 1, colour, TCOL_UPPER | permanent);
+		}
+	}
+
+	// figure out if we need to copy more data
+	mapColourLast = MAX(mapColourLast, colindex * sizeof(UDWORD));
+	mapColourFirst = MIN(mapColourFirst, colindex * sizeof(UDWORD));
+}
+
+PIELIGHT pie_TerrainGetColour(int x, int y)
+{
+	PIELIGHT colour;
+	const int mult = VERTICES_PER_TILE * COLOUR_COMPONENTS * sizeof(*aColour[0]);
+	GLubyte *colByte = aColour[1] + y * mapSize.x * mult + x * mult;
+
+	assert(x >= 0 && y >= 0 && x < mapSize.x && y < mapSize.y);
+
+	colour.byte.r = *colByte++;
+	colour.byte.g = *colByte++;
+	colour.byte.b = *colByte++;
+	colour.byte.a = *colByte++;
+
+	return colour;
+}
+
+void pie_TerrainDraw(int x1, int y1, int x2, int y2)
+{
+	int y;
+
+	assert(x1 < x2 && y1 < y2);
+	assert(x2 < mapSize.x);
+	assert(x2 - x1 > 0);
+
 	glEnableClientState(GL_COLOR_ARRAY);
 	glEnableClientState(GL_VERTEX_ARRAY);
 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-	glColorPointer(COLOUR_COMPONENTS, GL_UNSIGNED_BYTE, 0, aColour);
+	glColorPointer(COLOUR_COMPONENTS, GL_UNSIGNED_BYTE, 0, aColour[1]);
 	glTexCoordPointer(TEXCOORD_COMPONENTS, GL_FLOAT, 0, aTexCoord);
 	glVertexPointer(VERTEX_COMPONENTS, GL_FLOAT, 0, aVertex);
 	glMatrixMode(GL_TEXTURE);
-	glLoadIdentity();
-	glDrawArrays(GL_TRIANGLES, 0, VERTICES_PER_TRIANGLE * mapx * mapy * 2);
+	glLoadIdentity(); // because we use 0.0f -> 1.0f texture coordinates
+
+	for (y = y1; y < y2; y++)
+	{
+		glDrawArrays(GL_TRIANGLES, (y * mapSize.x + x1) * VERTICES_PER_TILE, (x2 - x1) * VERTICES_PER_TILE);
+	}
+
 	glDisableClientState(GL_COLOR_ARRAY);
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 }
 
-// index gives us the triangle
-void pie_DrawTerrainTriangle(int index, const TERRAIN_VERTEX *aVrts)
+void pie_DrawTerrainTriangle(int x, int y, int triangle, const TERRAIN_VERTEX *aVrts, BOOL flips)
 {
-	unsigned int i = 0, j = index * VERTICES_PER_TRIANGLE;
+	unsigned int i = 0, j = (y * mapSize.x + x) * VERTICES_PER_TILE + triangle * VERTICES_PER_TRIANGLE;
 
-	assert(index < MAP_TRIANGLES);
-	assert(j < MAP_VERTICES);
+	assert(triangle < TRIANGLES_PER_TILE && triangle >= 0 && x >= 0 && y >= 0);
+	assert(x < mapSize.x);
+
 	tileCount++;
 
+	aFlips[y * mapSize.x + x] = flips;
 	for ( i = 0; i < 3; i++ )
 	{
-		aColour[j * COLOUR_COMPONENTS + 0] = aVrts[i].light.byte.r;
-		aColour[j * COLOUR_COMPONENTS + 1] = aVrts[i].light.byte.g;
-		aColour[j * COLOUR_COMPONENTS + 2] = aVrts[i].light.byte.b;
-		aColour[j * COLOUR_COMPONENTS + 3] = aVrts[i].light.byte.a;
 		aTexCoord[j * TEXCOORD_COMPONENTS + 0] = aVrts[i].u;
 		aTexCoord[j * TEXCOORD_COMPONENTS + 1] = aVrts[i].v;
 		aVertex[j * VERTEX_COMPONENTS + 0] = aVrts[i].pos.x;
_______________________________________________
Warzone-dev mailing list
[email protected]
https://mail.gna.org/listinfo/warzone-dev

Reply via email to