Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/MapIO.cpp
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | Status ParseHeightmapImage(const shared_ptr<u8>& fileData, size_t fileSize, std::vector<u16>& heightmap) | ||||
// Copy image data into the heightmap | // Copy image data into the heightmap | ||||
heightmap.resize(SQR(tileSize + 1)); | heightmap.resize(SQR(tileSize + 1)); | ||||
for (ssize_t y = 0; y < tileSize + 1; ++y) | for (ssize_t y = 0; y < tileSize + 1; ++y) | ||||
for (ssize_t x = 0; x < tileSize + 1; ++x) | for (ssize_t x = 0; x < tileSize + 1; ++x) | ||||
{ | { | ||||
// Repeat the last pixel of the image for the last vertex of the heightmap | // Repeat the last pixel of the image for the last vertex of the heightmap | ||||
int offset = std::min(y, tileSize - 1) * mapLineSkip + std::min(x, tileSize - 1) * bytesPP; | int offset = std::min(y, tileSize - 1) * mapLineSkip + std::min(x, tileSize - 1) * bytesPP; | ||||
// Pick color channel with highest value | heightmap[(tileSize - y) * (tileSize + 1) + x] = 256 * std::max({ mapdata[offset], | ||||
elexis: +\n (so that each item is on a separate line symmetrically) | |||||
u16 value = std::max({mapdata[offset], mapdata[offset + bytesPP], mapdata[offset + bytesPP * 2]}); | mapdata[offset + bytesPP], | ||||
Not Done Inline ActionsOne could also keep that to an explicitly named variable to increase readability. Stan: One could also keep that to an explicitly named variable to increase readability. | |||||
value = mapdata[offset]; | mapdata[offset + bytesPP * 2] }); | ||||
Not Done Inline ActionsClamp. vladislavbelov: `Clamp`. | |||||
heightmap[(tileSize - y) * (tileSize + 1) + x] = clamp(value * 256, 0, 65535); | |||||
} | } | ||||
return INFO::OK; | return INFO::OK; | ||||
} | } |
Wildfire Games · Phabricator
+\n (so that each item is on a separate line symmetrically)