Tidy up and modernize TileGenerator (Part 2)

This commit is contained in:
Unknown 2018-04-17 19:37:15 +02:00
parent 0bba4bccfe
commit 15a4ed2b1b
2 changed files with 8 additions and 9 deletions

View File

@ -73,9 +73,9 @@ static inline void readString(string &str, const unsigned char *data, size_t off
static inline void checkBlockNodeDataLimit(int version, size_t dataLength) static inline void checkBlockNodeDataLimit(int version, size_t dataLength)
{ {
int datapos = 16 * 16 * 16; constexpr const int datapos = 16 * 16 * 16;
if (version >= 24) { if (version >= 24) {
size_t index = datapos << 1; constexpr const size_t index = static_cast<size_t>(datapos) << 1;
checkDataLimit("node:24", index, 2, dataLength); checkDataLimit("node:24", index, 2, dataLength);
} }
else if (version >= 20) { else if (version >= 20) {
@ -91,7 +91,7 @@ static inline void checkBlockNodeDataLimit(int version, size_t dataLength)
static inline int readBlockContent(const unsigned char *mapData, int version, int datapos) static inline int readBlockContent(const unsigned char *mapData, int version, int datapos)
{ {
if (version >= 24) { if (version >= 24) {
size_t index = datapos << 1; size_t index = static_cast<size_t>(datapos) << 1;
return (mapData[index] << 8) | mapData[index + 1]; return (mapData[index] << 8) | mapData[index + 1];
} }
else if (version >= 20) { else if (version >= 20) {
@ -118,7 +118,6 @@ const BlockPos TileGenerator::BlockPosLimitMax(MAPBLOCK_MAX, MAPBLOCK_MAX, MAPBL
TileGenerator::TileGenerator() TileGenerator::TileGenerator()
{ {
memset(&m_databaseFormatFound, 0, sizeof(m_databaseFormatFound));
// Load default grey colors. // Load default grey colors.
m_heightMapColors.push_back(HeightMapColor(INT_MIN, Color(0,0,0), -129, Color(0,0,0))); m_heightMapColors.push_back(HeightMapColor(INT_MIN, Color(0,0,0), -129, Color(0,0,0)));
m_heightMapColors.push_back(HeightMapColor(-128, Color(0,0,0), 127, Color(255,255,255))); m_heightMapColors.push_back(HeightMapColor(-128, Color(0,0,0), 127, Color(255,255,255)));
@ -1540,9 +1539,8 @@ void TileGenerator::renderMap()
<< " (" << std::fixed << std::setprecision(0) << 100.0 * (m_zMax - pos.z()) / (m_zMax - m_zMin) << " (" << std::fixed << std::setprecision(0) << 100.0 * (m_zMax - pos.z()) / (m_zMax - m_zMin)
<< "%) \r" << std::flush; << "%) \r" << std::flush;
} }
for (int i = 0; i < 16; ++i) {
m_readedPixels[i] = 0; m_readedPixels.fill(0);
}
allReaded = false; allReaded = false;
currentPos = pos; currentPos = pos;
} }

View File

@ -9,6 +9,7 @@
#pragma once #pragma once
#include <array>
#include <climits> #include <climits>
#include <cstdint> #include <cstdint>
#include <iosfwd> #include <iosfwd>
@ -232,7 +233,7 @@ private:
bool m_databaseFormatSet{ false }; bool m_databaseFormatSet{ false };
BlockPos::StrFormat m_databaseFormat{ BlockPos::Unknown }; BlockPos::StrFormat m_databaseFormat{ BlockPos::Unknown };
std::string m_recommendedDatabaseFormat; std::string m_recommendedDatabaseFormat;
long long m_databaseFormatFound[BlockPos::STRFORMAT_MAX]; std::array<long long, BlockPos::STRFORMAT_MAX> m_databaseFormatFound{ { 0 } };
bool m_reportDatabaseFormat{ false }; bool m_reportDatabaseFormat{ false };
PaintEngine *paintEngine = nullptr; PaintEngine *paintEngine = nullptr;
PixelAttributes m_blockPixelAttributes; PixelAttributes m_blockPixelAttributes;
@ -286,7 +287,7 @@ private:
const ColorEntry *m_nodeIDColor[MAPBLOCK_MAXCOLORS]; const ColorEntry *m_nodeIDColor[MAPBLOCK_MAXCOLORS];
NodeColorMap m_nodeColors; NodeColorMap m_nodeColors;
HeightMapColorList m_heightMapColors; HeightMapColorList m_heightMapColors;
uint16_t m_readedPixels[16]; std::array<uint16_t, 16> m_readedPixels;
std::set<std::string> m_unknownNodes; std::set<std::string> m_unknownNodes;
std::vector<DrawObject> m_drawObjects; std::vector<DrawObject> m_drawObjects;
}; /* ----- end of class TileGenerator ----- */ }; /* ----- end of class TileGenerator ----- */