Go to the documentation of this file.
52 bool shouldDraw =
false;
62 image->setPixel(x, y, col);
98 m_tileBlocks[i].clear();
106 const Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
118 const Point blockOff = getBlockOffset(mapRect.
topLeft());
123 if(y < 0 || y >= 65536)
127 if(x < 0 || x >= 65536)
131 if(!hasBlock(blockPos))
154 if(screenRect.
isEmpty() || pos.
z != mapCenter.
z)
155 return Point(-1, -1);
157 const Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
160 return posoff + screenRect.
topLeft() - off + (
Point(1, 1) * scale) / 2;
168 const Rect mapRect = calcMapRect(screenRect, mapCenter, scale);
176 if(screenRect.
isEmpty() || pos.
z != mapCenter.
z)
179 const int tileSize = 32 * scale;
180 Rect tileRect(0, 0, tileSize, tileSize);
185 Rect Minimap::calcMapRect(
const Rect& screenRect,
const Position& mapCenter,
float scale)
187 const 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));
203 minimapTile.
speed = std::min<int>(
static_cast<int>(std::ceil(tile->
getGroundSpeed() / 10.0f)), 255);
208 const Point offsetPos = getBlockOffset(
Point(pos.
x, pos.
y));
209 block.
updateTile(pos.
x - offsetPos.
x, pos.
y - offsetPos.
y, minimapTile);
219 const Point offsetPos = getBlockOffset(
Point(pos.
x, pos.
y));
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);
285 const Point offsetPos = getBlockOffset(
Point(pos.
x, pos.
y));
336 std::vector<uchar> compressBuffer(compressBound(blockSize));
337 std::vector<uchar> decompressBuffer(blockSize);
351 ulong destLen = blockSize;
352 fin->
read(compressBuffer.data(), len);
353 const int ret = uncompress(decompressBuffer.data(), &destLen, compressBuffer.data(), len);
354 if(ret != Z_OK || destLen != blockSize)
357 memcpy((
uchar*)&block.
getTiles(), decompressBuffer.data(), blockSize);
397 std::vector<uchar> compressBuffer(compressBound(blockSize));
398 const int COMPRESS_LEVEL = 3;
401 for(
auto& it : m_tileBlocks[
z]) {
402 const int index = it.first;
407 const Position pos = getIndexPosition(index,
z);
412 ulong len = blockSize;
413 const int ret = compress2(compressBuffer.data(), &len, (
uchar*)&block.
getTiles(), blockSize, COMPRESS_LEVEL);
416 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)