Refactoring (2)

This commit is contained in:
sfan5
2018-03-25 15:19:48 +02:00
parent 2ebc3afc7c
commit 2f78c39d9c
5 changed files with 193 additions and 121 deletions

35
include/BlockDecoder.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef BLOCKDECODER_H
#define BLOCKDECODER_H
#if __cplusplus >= 201103L
#include <unordered_map>
#else
#include <map>
#endif
#include "types.h"
class BlockDecoder {
public:
BlockDecoder();
void reset();
void decode(const ustring &data);
bool isEmpty() const;
std::string getNode(u8 x, u8 y, u8 z) const; // returns "" for air, ignore and invalid nodes
private:
#if __cplusplus >= 201103L
typedef std::unordered_map<int, std::string> NameMap;
#else
typedef std::map<int, std::string> NameMap;
#endif
NameMap m_nameMap;
int m_blockAirId;
int m_blockIgnoreId;
u8 m_version;
ustring m_mapData;
};
#endif // BLOCKDECODER_H

View File

@ -14,7 +14,9 @@
#endif
#include <stdint.h>
#include <string>
#include "PixelAttributes.h"
#include "BlockDecoder.h"
#include "Image.h"
#include "db.h"
#include "types.h"
@ -43,11 +45,9 @@ class TileGenerator
private:
#if __cplusplus >= 201103L
typedef std::unordered_map<std::string, ColorEntry> ColorMap;
typedef std::unordered_map<int, std::string> NameMap;
typedef std::unordered_set<std::string> NameSet;
#else
typedef std::map<std::string, ColorEntry> ColorMap;
typedef std::map<int, std::string> NameMap;
typedef std::set<std::string> NameSet;
#endif
@ -80,7 +80,7 @@ private:
void createImage();
void renderMap();
std::list<int> getZValueList() const;
void renderMapBlock(const ustring &mapBlock, const BlockPos &pos, int version);
void renderMapBlock(const BlockDecoder &blk, const BlockPos &pos);
void renderMapBlockBottom(const BlockPos &pos);
void renderShading(int zPos);
void renderScale();
@ -121,7 +121,6 @@ private:
int m_mapWidth;
int m_mapHeight;
std::list<std::pair<int, int> > m_positions;
NameMap m_nameMap;
ColorMap m_colorMap;
uint16_t m_readPixels[16];
uint16_t m_readInfo[16];
@ -129,8 +128,6 @@ private:
Color m_color[16][16];
uint8_t m_thickness[16][16];
int m_blockAirId;
int m_blockIgnoreId;
int m_zoom;
uint m_scales;
}; // class TileGenerator