forked from Mirrorlandia_minetest/minetest
Fix minimap textures overwrite (#14349)
This commit is contained in:
parent
4843890c56
commit
9ac6d330b4
@ -206,25 +206,6 @@ Minimap::Minimap(Client *client)
|
||||
|
||||
data->minimap_shape_round = g_settings->getBool("minimap_shape_round");
|
||||
|
||||
// Get round minimap textures
|
||||
data->minimap_mask_round = driver->createImage(
|
||||
m_tsrc->getTexture("minimap_mask_round.png"),
|
||||
core::position2d<s32>(0, 0),
|
||||
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
||||
data->minimap_overlay_round = m_tsrc->getTexture("minimap_overlay_round.png");
|
||||
|
||||
// Get square minimap textures
|
||||
data->minimap_mask_square = driver->createImage(
|
||||
m_tsrc->getTexture("minimap_mask_square.png"),
|
||||
core::position2d<s32>(0, 0),
|
||||
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
||||
data->minimap_overlay_square = m_tsrc->getTexture("minimap_overlay_square.png");
|
||||
|
||||
// Create player marker texture
|
||||
data->player_marker = m_tsrc->getTexture("player_marker.png");
|
||||
// Create object marker texture
|
||||
data->object_marker_red = m_tsrc->getTexture("object_marker_red.png");
|
||||
|
||||
setModeIndex(0);
|
||||
|
||||
// Create mesh buffer for minimap
|
||||
@ -243,8 +224,10 @@ Minimap::~Minimap()
|
||||
|
||||
m_meshbuffer->drop();
|
||||
|
||||
data->minimap_mask_round->drop();
|
||||
data->minimap_mask_square->drop();
|
||||
if (data->minimap_mask_round)
|
||||
data->minimap_mask_round->drop();
|
||||
if (data->minimap_mask_square)
|
||||
data->minimap_mask_square->drop();
|
||||
|
||||
driver->removeTexture(data->texture);
|
||||
driver->removeTexture(data->heightmap_texture);
|
||||
@ -461,6 +444,29 @@ void Minimap::blitMinimapPixelsToImageSurface(
|
||||
}
|
||||
}
|
||||
|
||||
video::IImage *Minimap::getMinimapMask()
|
||||
{
|
||||
if (data->minimap_shape_round) {
|
||||
if (!data->minimap_mask_round) {
|
||||
// Get round minimap textures
|
||||
data->minimap_mask_round = driver->createImage(
|
||||
m_tsrc->getTexture("minimap_mask_round.png"),
|
||||
core::position2d<s32>(0, 0),
|
||||
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
||||
}
|
||||
return data->minimap_mask_round;
|
||||
}
|
||||
|
||||
if (!data->minimap_mask_square) {
|
||||
// Get square minimap textures
|
||||
data->minimap_mask_square = driver->createImage(
|
||||
m_tsrc->getTexture("minimap_mask_square.png"),
|
||||
core::position2d<s32>(0, 0),
|
||||
core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
|
||||
}
|
||||
return data->minimap_mask_square;
|
||||
}
|
||||
|
||||
video::ITexture *Minimap::getMinimapTexture()
|
||||
{
|
||||
// update minimap textures when new scan is ready
|
||||
@ -509,16 +515,13 @@ video::ITexture *Minimap::getMinimapTexture()
|
||||
map_image->copyToScaling(minimap_image);
|
||||
map_image->drop();
|
||||
|
||||
video::IImage *minimap_mask = data->minimap_shape_round ?
|
||||
data->minimap_mask_round : data->minimap_mask_square;
|
||||
video::IImage *minimap_mask = getMinimapMask();
|
||||
|
||||
if (minimap_mask) {
|
||||
for (s16 y = 0; y < MINIMAP_MAX_SY; y++)
|
||||
for (s16 x = 0; x < MINIMAP_MAX_SX; x++) {
|
||||
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));
|
||||
}
|
||||
for (s16 y = 0; y < MINIMAP_MAX_SY; y++)
|
||||
for (s16 x = 0; x < MINIMAP_MAX_SX; x++) {
|
||||
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));
|
||||
}
|
||||
|
||||
if (data->texture)
|
||||
@ -571,14 +574,22 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
|
||||
return buf;
|
||||
}
|
||||
|
||||
void Minimap::drawMinimap(core::rect<s32> rect) {
|
||||
void Minimap::drawMinimap(core::rect<s32> rect)
|
||||
{
|
||||
if (data->mode.type == MINIMAP_TYPE_OFF)
|
||||
return;
|
||||
|
||||
// Get textures
|
||||
video::ITexture *minimap_texture = getMinimapTexture();
|
||||
if (!minimap_texture)
|
||||
return;
|
||||
|
||||
if (data->mode.type == MINIMAP_TYPE_OFF)
|
||||
return;
|
||||
if (!data->textures_initialised) {
|
||||
data->minimap_overlay_round = m_tsrc->getTexture("minimap_overlay_round.png");
|
||||
data->minimap_overlay_square = m_tsrc->getTexture("minimap_overlay_square.png");
|
||||
data->player_marker = m_tsrc->getTexture("player_marker.png");
|
||||
data->object_marker_red = m_tsrc->getTexture("object_marker_red.png");
|
||||
data->textures_initialised = true;
|
||||
}
|
||||
|
||||
updateActiveMarkers();
|
||||
|
||||
@ -689,8 +700,7 @@ void Minimap::removeMarker(MinimapMarker **m)
|
||||
|
||||
void Minimap::updateActiveMarkers()
|
||||
{
|
||||
video::IImage *minimap_mask = data->minimap_shape_round ?
|
||||
data->minimap_mask_round : data->minimap_mask_square;
|
||||
video::IImage *minimap_mask = getMinimapMask();
|
||||
|
||||
m_active_markers.clear();
|
||||
v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS);
|
||||
|
@ -79,6 +79,7 @@ struct MinimapData {
|
||||
video::IImage *minimap_mask_square = nullptr;
|
||||
video::ITexture *texture = nullptr;
|
||||
video::ITexture *heightmap_texture = nullptr;
|
||||
bool textures_initialised = false; // True if the following textures are not nullptrs.
|
||||
video::ITexture *minimap_overlay_round = nullptr;
|
||||
video::ITexture *minimap_overlay_square = nullptr;
|
||||
video::ITexture *player_marker = nullptr;
|
||||
@ -140,6 +141,7 @@ public:
|
||||
|
||||
MinimapModeDef getModeDef() const { return data->mode; }
|
||||
|
||||
video::IImage *getMinimapMask();
|
||||
video::ITexture *getMinimapTexture();
|
||||
|
||||
void blitMinimapPixelsToImageRadar(video::IImage *map_image);
|
||||
|
Loading…
Reference in New Issue
Block a user