static PIELIGHT appliedRadarColour(RADAR_DRAW_MODE radarDrawMode, MAPTILE *WTile) { PIELIGHT WScr = WZCOL_BLACK; // squelch warning // draw radar on/off feature if (!getRevealStatus() && !TEST_TILE_VISIBLE(selectedPlayer, WTile)) { return WZCOL_RADAR_BACKGROUND; } switch (radarDrawMode) { case RADAR_MODE_TERRAIN: { // draw radar terrain on/off feature PIELIGHT col = tileColours[TileNumber_tile(WTile->texture)]; col.byte.r = sqrtf(col.byte.r * WTile->illumination); col.byte.b = sqrtf(col.byte.b * WTile->illumination); col.byte.g = sqrtf(col.byte.g * WTile->illumination); if (terrainType(WTile) == TER_CLIFFFACE) { col.byte.r /= 2; col.byte.g /= 2; col.byte.b /= 2; } if (!hasSensorOnTile(WTile, selectedPlayer)) { col.byte.r = col.byte.r * 2 / 3; col.byte.g = col.byte.g * 2 / 3; col.byte.b = col.byte.b * 2 / 3; } if (!TEST_TILE_VISIBLE(selectedPlayer, WTile)) { col.byte.r /= 2; col.byte.g /= 2; col.byte.b /= 2; } WScr = col; } break; case RADAR_MODE_COMBINED: { // draw radar terrain on/off feature PIELIGHT col = tileColours[TileNumber_tile(WTile->texture)]; col.byte.r = sqrtf(col.byte.r * (WTile->illumination + WTile->height / ELEVATION_SCALE) / 2); col.byte.b = sqrtf(col.byte.b * (WTile->illumination + WTile->height / ELEVATION_SCALE) / 2); col.byte.g = sqrtf(col.byte.g * (WTile->illumination + WTile->height / ELEVATION_SCALE) / 2); if (terrainType(WTile) == TER_CLIFFFACE) { col.byte.r /= 2; col.byte.g /= 2; col.byte.b /= 2; } if (!hasSensorOnTile(WTile, selectedPlayer)) { col.byte.r = col.byte.r * 2 / 3; col.byte.g = col.byte.g * 2 / 3; col.byte.b = col.byte.b * 2 / 3; } if (!TEST_TILE_VISIBLE(selectedPlayer, WTile)) { col.byte.r /= 2; col.byte.g /= 2; col.byte.b /= 2; } WScr = col; } break; case RADAR_MODE_HEIGHT_MAP: { WScr.byte.r = WScr.byte.g = WScr.byte.b = WTile->height / ELEVATION_SCALE; } break; case RADAR_MODE_NO_TERRAIN: { WScr = WZCOL_RADAR_BACKGROUND; } break; case NUM_RADAR_MODES: { assert(false); } break; } return WScr; }
/// Set up the texture coordinates for a tile static void getTileTexCoords(Vector2f *uv, unsigned int tileNumber) { /* unmask proper values from compressed data */ const unsigned short texture = TileNumber_texture(tileNumber); const unsigned short tile = TileNumber_tile(tileNumber); /* Used to calculate texture coordinates */ const float xMult = 1.0f / TILES_IN_PAGE_COLUMN; const float yMult = 1.0f / TILES_IN_PAGE_ROW; float texsize = (float)getTextureSize(); float centertile, shiftamount, one; Vector2f sP1, sP2, sP3, sP4, sPTemp; // the decals are 128x128 (at this time), we should not go above this value. See note above if (texsize > MAX_TILE_TEXTURE_SIZE) { texsize = MAX_TILE_TEXTURE_SIZE; } centertile = 0.5f / texsize; //compute center of tile shiftamount = (texsize -1.0) / texsize; // 1 pixel border one = 1.0f / (TILES_IN_PAGE_COLUMN * texsize); // bump the texture coords, for 1 pixel border, so our range is [.5,(texsize - .5)] one += centertile * shiftamount; /* * Points for flipping the texture around if the tile is flipped or rotated * Store the source rect as four points */ sP1.x = one; sP1.y = one; sP2.x = xMult - one; sP2.y = one; sP3.x = xMult - one; sP3.y = yMult - one; sP4.x = one; sP4.y = yMult - one; if (texture & TILE_XFLIP) { sPTemp = sP1; sP1 = sP2; sP2 = sPTemp; sPTemp = sP3; sP3 = sP4; sP4 = sPTemp; } if (texture & TILE_YFLIP) { sPTemp = sP1; sP1 = sP4; sP4 = sPTemp; sPTemp = sP2; sP2 = sP3; sP3 = sPTemp; } switch ((texture & TILE_ROTMASK) >> TILE_ROTSHIFT) { case 1: sPTemp = sP1; sP1 = sP4; sP4 = sP3; sP3 = sP2; sP2 = sPTemp; break; case 2: sPTemp = sP1; sP1 = sP3; sP3 = sPTemp; sPTemp = sP4; sP4 = sP2; sP2 = sPTemp; break; case 3: sPTemp = sP1; sP1 = sP2; sP2 = sP3; sP3 = sP4; sP4 = sPTemp; break; } uv[0 + 0].x = tileTexInfo[tile].uOffset + sP1.x; uv[0 + 0].y = tileTexInfo[tile].vOffset + sP1.y; uv[0 + 2].x = tileTexInfo[tile].uOffset + sP2.x; uv[0 + 2].y = tileTexInfo[tile].vOffset + sP2.y; uv[1 + 2].x = tileTexInfo[tile].uOffset + sP3.x; uv[1 + 2].y = tileTexInfo[tile].vOffset + sP3.y; uv[1 + 0].x = tileTexInfo[tile].uOffset + sP4.x; uv[1 + 0].y = tileTexInfo[tile].vOffset + sP4.y; }
/// Set up the texture coordinates for a tile static Vector2f getTileTexCoords(Vector2f *uv, unsigned int tileNumber) { /* unmask proper values from compressed data */ const unsigned short texture = TileNumber_texture(tileNumber); const unsigned short tile = TileNumber_tile(tileNumber); /* Used to calculate texture coordinates */ const float xMult = 1.0f / TILES_IN_PAGE_COLUMN; const float yMult = 1.0f / TILES_IN_PAGE_ROW; float texsize = (float)getTextureSize(); // the decals are 128x128 (at this time), we should not go above this value. See note above if (texsize > MAX_TILE_TEXTURE_SIZE) { texsize = MAX_TILE_TEXTURE_SIZE; } const float centertile = 0.5f / texsize; // compute center of tile const float shiftamount = (texsize - 1.0) / texsize; // 1 pixel border // bump the texture coords, for 1 pixel border, so our range is [.5,(texsize - .5)] const float one = 1.0f / (TILES_IN_PAGE_COLUMN * texsize) + centertile * shiftamount; /* * Points for flipping the texture around if the tile is flipped or rotated * Store the source rect as four points */ Vector2f sP1 { one, one }; Vector2f sP2 { xMult - one, one }; Vector2f sP3 { xMult - one, yMult - one }; Vector2f sP4 { one, yMult - one }; if (texture & TILE_XFLIP) { std::swap(sP1, sP2); std::swap(sP3, sP4); } if (texture & TILE_YFLIP) { std::swap(sP1, sP4); std::swap(sP2, sP3); } Vector2f sPTemp; switch ((texture & TILE_ROTMASK) >> TILE_ROTSHIFT) { case 1: sPTemp = sP1; sP1 = sP4; sP4 = sP3; sP3 = sP2; sP2 = sPTemp; break; case 2: sPTemp = sP1; sP1 = sP3; sP3 = sPTemp; sPTemp = sP4; sP4 = sP2; sP2 = sPTemp; break; case 3: sPTemp = sP1; sP1 = sP2; sP2 = sP3; sP3 = sP4; sP4 = sPTemp; break; } const Vector2f offset { tileTexInfo[tile].uOffset, tileTexInfo[tile].vOffset }; uv[0 + 0] = offset + sP1; uv[0 + 2] = offset + sP2; uv[1 + 2] = offset + sP3; uv[1 + 0] = offset + sP4; /// Calculate the average texture coordinates of 4 points return Vector2f { (uv[0].x + uv[1].x + uv[2].x + uv[3].x) / 4, (uv[0].y + uv[1].y + uv[2].y + uv[3].y) / 4 }; }