Go to the documentation of this file.
52 bool shouldDraw =
false;
62 image->setPixel(x, y, col);
98 m_tileBlocks[i].clear();
106 Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
123 if(y < 0 || y >= 65536)
127 if(x < 0 || x >= 65536)
131 if(!hasBlock(blockPos))
154 if(screenRect.
isEmpty() || pos.
z != mapCenter.
z)
157 Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
160 return posoff + screenRect.
topLeft() - off + (
Point(1,1)*scale)/2;
168 Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
176 if(screenRect.
isEmpty() || pos.
z != mapCenter.
z)
179 int tileSize = 32 * scale;
180 Rect tileRect(0,0,tileSize, tileSize);
185 Rect Minimap::calcMapRect(
const Rect& screenRect,
const Position& mapCenter,
float scale)
187 int w = screenRect.
width() / scale, h = std::ceil(screenRect.
height() / scale);
188 Rect mapRect(0,0,w,h);
189 mapRect.moveCenter(
Point(mapCenter.
x, mapCenter.
y));
209 block.
updateTile(pos.
x - offsetPos.
x, pos.
y - offsetPos.
y, minimapTile);
220 return block.
getTile(pos.
x - offsetPos.
x, pos.
y - offsetPos.
y);
227 if(colorFactor <= 0.01f)
236 Color nonPathableColors[] = {
237 std::string(
"#ffff00"),
241 Color nonWalkableColors[] = {
242 std::string(
"#000000"),
243 std::string(
"#006600"),
244 std::string(
"#ff3300"),
245 std::string(
"#666666"),
246 std::string(
"#ff6600"),
247 std::string(
"#00ff00"),
248 std::string(
"#ccffff"),
251 for(
int y=0;y<image->getHeight();++y) {
252 for(
int x=0;x<image->getWidth();++x) {
257 if(c == waterc || color.
a() == 0) {
263 for(
Color &col : nonWalkableColors) {
272 for(
Color &col : nonPathableColors) {
283 Position pos(topLeft.
x + x, topLeft.
y + y, topLeft.
z);
335 std::vector<uchar> compressBuffer(compressBound(blockSize));
336 std::vector<uchar> decompressBuffer(blockSize);
350 ulong destLen = blockSize;
351 fin->
read(compressBuffer.data(), len);
352 int ret = uncompress(decompressBuffer.data(), &destLen, compressBuffer.data(), len);
353 if(ret != Z_OK || destLen != blockSize)
356 memcpy((
uchar*)&block.
getTiles(), decompressBuffer.data(), blockSize);
396 std::vector<uchar> compressBuffer(compressBound(blockSize));
397 const int COMPRESS_LEVEL = 3;
400 for(
auto& it : m_tileBlocks[
z]) {
401 int index = it.first;
406 Position pos = getIndexPosition(index,
z);
411 ulong len = blockSize;
412 int ret = compress2(compressBuffer.data(), &len, (
uchar*)&block.
getTiles(), blockSize, COMPRESS_LEVEL);
415 fin->
write(compressBuffer.data(), len);
void write(const void *buffer, uint count)
virtual void setColor(const Color &color)
virtual void restoreSavedState()=0
MinimapTile & getTile(int x, int y)
bool loadOtmm(const std::string &fileName)
static ImagePtr load(std::string file)
bool isWalkable(bool ignoreCreatures=false)
void error(const std::string &what)
void saveImage(const std::string &fileName, const Rect &mapRect)
uint8 getMinimapColorByte()
void addString(const std::string &v)
ResourceManager g_resources
TPoint< T > topLeft() const
void updateTile(const Position &pos, const TilePtr &tile)
void uploadPixels(const ImagePtr &image, bool buildMipmaps=false, bool compress=false)
const MinimapTile & getTile(const Position &pos)
uint getTileIndex(int x, int y)
void moveCenter(const TPoint< T > &p)
bool isMapPosition() const
int read(void *buffer, uint size, uint nmemb=1)
stdext::shared_object_ptr< Texture > TexturePtr
Rect getTileRect(const Position &pos, const Rect &screenRect, const Position &mapCenter, float scale)
void throw_exception(const std::string &what)
Throws a generic exception.
Position getTilePosition(const Point &point, const Rect &screenRect, const Position &mapCenter, float scale)
FileStreamPtr openFile(const std::string &fileName)
virtual void setClipRect(const Rect &clipRect)=0
Point getTilePoint(const Position &pos, const Rect &screenRect, const Position &mapCenter, float scale)
virtual const char * what() const
virtual void setSmooth(bool smooth)
void updateTile(int x, int y, const MinimapTile &tile)
TPoint< T > toPoint() const
const TexturePtr & getTexture()
void saveOtmm(const std::string &fileName)
virtual void saveState()=0
static Color from8bit(int color)
static uint8 to8bit(const Color &color)
virtual void drawFilledRect(const Rect &dest)=0
FileStreamPtr createFile(const std::string &fileName)
std::array< MinimapTile, MMBLOCK_SIZE *MMBLOCK_SIZE > & getTiles()
void draw(const Rect &screenRect, const Position &mapCenter, float scale, const Color &color)
virtual void drawTexturedRect(const Rect &dest, const TexturePtr &texture, const Rect &src)=0
bool loadImage(const std::string &fileName, const Position &topLeft, float colorFactor)