X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fminimap.cpp;h=8b240b199302e1b6d0d10b7e811ea17667696b0c;hb=3caad3f3c9e319ca67d63231e8c64b2ace855fff;hp=cfc2c34b061a734fdbaacea11460bd36651adf7f;hpb=25a24c0cdf1467df51c41d0b24e2ab6318ba1850;p=oweals%2Fminetest.git diff --git a/src/minimap.cpp b/src/minimap.cpp index cfc2c34b0..8b240b199 100644 --- a/src/minimap.cpp +++ b/src/minimap.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "mapblock.h" #include +#include "client/renderingengine.h" //// @@ -105,7 +106,7 @@ void MinimapUpdateThread::doUpdate() // Swap two values in the map using single lookup std::pair::iterator, bool> result = m_blocks_cache.insert(std::make_pair(update.pos, update.data)); - if (result.second == false) { + if (!result.second) { delete result.first->second; result.first->second = update.data; } @@ -184,10 +185,10 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height) //// Mapper //// -Mapper::Mapper(IrrlichtDevice *device, Client *client) +Minimap::Minimap(Client *client) { this->client = client; - this->driver = device->getVideoDriver(); + this->driver = RenderingEngine::get_video_driver(); this->m_tsrc = client->getTextureSource(); this->m_shdrsrc = client->getShaderSource(); this->m_ndef = client->getNodeDefManager(); @@ -204,8 +205,6 @@ Mapper::Mapper(IrrlichtDevice *device, Client *client) data->mode = MINIMAP_MODE_OFF; data->is_radar = false; data->map_invalidated = true; - data->heightmap_image = NULL; - data->minimap_image = NULL; data->texture = NULL; data->heightmap_texture = NULL; data->minimap_shape_round = g_settings->getBool("minimap_shape_round"); @@ -238,7 +237,7 @@ Mapper::Mapper(IrrlichtDevice *device, Client *client) m_minimap_update_thread->start(); } -Mapper::~Mapper() +Minimap::~Minimap() { m_minimap_update_thread->stop(); m_minimap_update_thread->wait(); @@ -258,26 +257,43 @@ Mapper::~Mapper() delete m_minimap_update_thread; } -void Mapper::addBlock(v3s16 pos, MinimapMapblock *data) +void Minimap::addBlock(v3s16 pos, MinimapMapblock *data) { m_minimap_update_thread->enqueueBlock(pos, data); } -MinimapMode Mapper::getMinimapMode() +void Minimap::toggleMinimapShape() { - return data->mode; + MutexAutoLock lock(m_mutex); + + data->minimap_shape_round = !data->minimap_shape_round; + g_settings->setBool("minimap_shape_round", data->minimap_shape_round); + m_minimap_update_thread->deferUpdate(); } -void Mapper::toggleMinimapShape() +void Minimap::setMinimapShape(MinimapShape shape) { MutexAutoLock lock(m_mutex); - data->minimap_shape_round = !data->minimap_shape_round; + if (shape == MINIMAP_SHAPE_SQUARE) + data->minimap_shape_round = false; + else if (shape == MINIMAP_SHAPE_ROUND) + data->minimap_shape_round = true; + g_settings->setBool("minimap_shape_round", data->minimap_shape_round); m_minimap_update_thread->deferUpdate(); } -void Mapper::setMinimapMode(MinimapMode mode) +MinimapShape Minimap::getMinimapShape() +{ + if (data->minimap_shape_round) { + return MINIMAP_SHAPE_ROUND; + } else { + return MINIMAP_SHAPE_SQUARE; + } +} + +void Minimap::setMinimapMode(MinimapMode mode) { static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = { {false, 0, 0}, @@ -302,7 +318,7 @@ void Mapper::setMinimapMode(MinimapMode mode) m_minimap_update_thread->deferUpdate(); } -void Mapper::setPos(v3s16 pos) +void Minimap::setPos(v3s16 pos) { bool do_update = false; @@ -320,43 +336,47 @@ void Mapper::setPos(v3s16 pos) m_minimap_update_thread->deferUpdate(); } -void Mapper::setAngle(f32 angle) +void Minimap::setAngle(f32 angle) { m_angle = angle; } -void Mapper::blitMinimapPixelsToImageRadar(video::IImage *map_image) +void Minimap::blitMinimapPixelsToImageRadar(video::IImage *map_image) { + video::SColor c(240, 0, 0, 0); for (s16 x = 0; x < data->map_size; x++) for (s16 z = 0; z < data->map_size; z++) { MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->map_size]; - video::SColor c(240, 0, 0, 0); if (mmpixel->air_count > 0) c.setGreen(core::clamp(core::round32(32 + mmpixel->air_count * 8), 0, 255)); + else + c.setGreen(0); map_image->setPixel(x, data->map_size - z - 1, c); } } -void Mapper::blitMinimapPixelsToImageSurface( +void Minimap::blitMinimapPixelsToImageSurface( video::IImage *map_image, video::IImage *heightmap_image) { + // This variable creation/destruction has a 1% cost on rendering minimap + video::SColor tilecolor; for (s16 x = 0; x < data->map_size; x++) for (s16 z = 0; z < data->map_size; z++) { MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->map_size]; const ContentFeatures &f = m_ndef->get(mmpixel->n); const TileDef *tile = &f.tiledef[0]; + // Color of the 0th tile (mostly this is the topmost) - video::SColor tilecolor; if(tile->has_color) tilecolor = tile->color; else mmpixel->n.getColor(f, &tilecolor); + tilecolor.setRed(tilecolor.getRed() * f.minimap_color.getRed() / 255); - tilecolor.setGreen(tilecolor.getGreen() * f.minimap_color.getGreen() - / 255); + tilecolor.setGreen(tilecolor.getGreen() * f.minimap_color.getGreen() / 255); tilecolor.setBlue(tilecolor.getBlue() * f.minimap_color.getBlue() / 255); tilecolor.setAlpha(240); @@ -368,7 +388,7 @@ void Mapper::blitMinimapPixelsToImageSurface( } } -video::ITexture *Mapper::getMinimapTexture() +video::ITexture *Minimap::getMinimapTexture() { // update minimap textures when new scan is ready if (data->map_invalidated) @@ -396,7 +416,7 @@ video::ITexture *Mapper::getMinimapTexture() if (minimap_mask) { for (s16 y = 0; y < MINIMAP_MAX_SY; y++) for (s16 x = 0; x < MINIMAP_MAX_SX; x++) { - video::SColor mask_col = minimap_mask->getPixel(x, y); + const video::SColor &mask_col = minimap_mask->getPixel(x, y); if (!mask_col.getAlpha()) minimap_image->setPixel(x, y, video::SColor(0,0,0,0)); } @@ -418,7 +438,7 @@ video::ITexture *Mapper::getMinimapTexture() return data->texture; } -v3f Mapper::getYawVec() +v3f Minimap::getYawVec() { if (data->minimap_shape_round) { return v3f( @@ -430,12 +450,12 @@ v3f Mapper::getYawVec() } } -scene::SMeshBuffer *Mapper::getMinimapMeshBuffer() +scene::SMeshBuffer *Minimap::getMinimapMeshBuffer() { scene::SMeshBuffer *buf = new scene::SMeshBuffer(); buf->Vertices.set_used(4); buf->Indices.set_used(6); - video::SColor c(255, 255, 255, 255); + static const video::SColor c(255, 255, 255, 255); buf->Vertices[0] = video::S3DVertex(-1, -1, 0, 0, 0, 1, c, 0, 1); buf->Vertices[1] = video::S3DVertex(-1, 1, 0, 0, 0, 1, c, 0, 0); @@ -452,14 +472,14 @@ scene::SMeshBuffer *Mapper::getMinimapMeshBuffer() return buf; } -void Mapper::drawMinimap() +void Minimap::drawMinimap() { video::ITexture *minimap_texture = getMinimapTexture(); if (!minimap_texture) return; updateActiveMarkers(); - v2u32 screensize = porting::getWindowSize(); + v2u32 screensize = RenderingEngine::get_instance()->getWindowSize(); const u32 size = 0.25 * screensize.Y; core::rect oldViewPort = driver->getViewPort(); @@ -550,20 +570,18 @@ void Mapper::drawMinimap() } } -void Mapper::updateActiveMarkers () +void Minimap::updateActiveMarkers() { video::IImage *minimap_mask = data->minimap_shape_round ? data->minimap_mask_round : data->minimap_mask_square; - std::list *nametags = client->getCamera()->getNametags(); + const std::list &nametags = client->getCamera()->getNametags(); m_active_markers.clear(); - for (std::list::const_iterator - i = nametags->begin(); - i != nametags->end(); ++i) { - Nametag *nametag = *i; - v3s16 pos = floatToInt(nametag->parent_node->getPosition() + + for (std::list::const_iterator i = nametags.begin(); + i != nametags.end(); ++i) { + v3s16 pos = floatToInt((*i)->parent_node->getPosition() + intToFloat(client->getCamera()->getOffset(), BS), BS); pos -= data->pos - v3s16(data->map_size / 2, data->scan_height / 2, @@ -575,7 +593,7 @@ void Mapper::updateActiveMarkers () } pos.X = ((float)pos.X / data->map_size) * MINIMAP_MAX_SX; pos.Z = ((float)pos.Z / data->map_size) * MINIMAP_MAX_SY; - video::SColor mask_col = minimap_mask->getPixel(pos.X, pos.Z); + const video::SColor &mask_col = minimap_mask->getPixel(pos.X, pos.Z); if (!mask_col.getAlpha()) { continue; }