Fix minimap textures overwrite (#14349)

This commit is contained in:
cx384 2024-02-15 21:52:41 +01:00 committed by GitHub
parent 4843890c56
commit 9ac6d330b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 36 deletions

@ -206,25 +206,6 @@ Minimap::Minimap(Client *client)
data->minimap_shape_round = g_settings->getBool("minimap_shape_round"); 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); setModeIndex(0);
// Create mesh buffer for minimap // Create mesh buffer for minimap
@ -243,8 +224,10 @@ Minimap::~Minimap()
m_meshbuffer->drop(); m_meshbuffer->drop();
data->minimap_mask_round->drop(); if (data->minimap_mask_round)
data->minimap_mask_square->drop(); data->minimap_mask_round->drop();
if (data->minimap_mask_square)
data->minimap_mask_square->drop();
driver->removeTexture(data->texture); driver->removeTexture(data->texture);
driver->removeTexture(data->heightmap_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() video::ITexture *Minimap::getMinimapTexture()
{ {
// update minimap textures when new scan is ready // update minimap textures when new scan is ready
@ -509,16 +515,13 @@ video::ITexture *Minimap::getMinimapTexture()
map_image->copyToScaling(minimap_image); map_image->copyToScaling(minimap_image);
map_image->drop(); map_image->drop();
video::IImage *minimap_mask = data->minimap_shape_round ? video::IImage *minimap_mask = getMinimapMask();
data->minimap_mask_round : data->minimap_mask_square;
if (minimap_mask) { for (s16 y = 0; y < MINIMAP_MAX_SY; y++)
for (s16 y = 0; y < MINIMAP_MAX_SY; y++) for (s16 x = 0; x < MINIMAP_MAX_SX; x++) {
for (s16 x = 0; x < MINIMAP_MAX_SX; x++) { const video::SColor &mask_col = minimap_mask->getPixel(x, y);
const video::SColor &mask_col = minimap_mask->getPixel(x, y); if (!mask_col.getAlpha())
if (!mask_col.getAlpha()) minimap_image->setPixel(x, y, video::SColor(0,0,0,0));
minimap_image->setPixel(x, y, video::SColor(0,0,0,0));
}
} }
if (data->texture) if (data->texture)
@ -571,14 +574,22 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
return buf; 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(); video::ITexture *minimap_texture = getMinimapTexture();
if (!minimap_texture) if (!minimap_texture)
return; return;
if (!data->textures_initialised) {
if (data->mode.type == MINIMAP_TYPE_OFF) data->minimap_overlay_round = m_tsrc->getTexture("minimap_overlay_round.png");
return; 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(); updateActiveMarkers();
@ -689,8 +700,7 @@ void Minimap::removeMarker(MinimapMarker **m)
void Minimap::updateActiveMarkers() void Minimap::updateActiveMarkers()
{ {
video::IImage *minimap_mask = data->minimap_shape_round ? video::IImage *minimap_mask = getMinimapMask();
data->minimap_mask_round : data->minimap_mask_square;
m_active_markers.clear(); m_active_markers.clear();
v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS); v3f cam_offset = intToFloat(client->getCamera()->getOffset(), BS);

@ -79,6 +79,7 @@ struct MinimapData {
video::IImage *minimap_mask_square = nullptr; video::IImage *minimap_mask_square = nullptr;
video::ITexture *texture = nullptr; video::ITexture *texture = nullptr;
video::ITexture *heightmap_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_round = nullptr;
video::ITexture *minimap_overlay_square = nullptr; video::ITexture *minimap_overlay_square = nullptr;
video::ITexture *player_marker = nullptr; video::ITexture *player_marker = nullptr;
@ -140,6 +141,7 @@ public:
MinimapModeDef getModeDef() const { return data->mode; } MinimapModeDef getModeDef() const { return data->mode; }
video::IImage *getMinimapMask();
video::ITexture *getMinimapTexture(); video::ITexture *getMinimapTexture();
void blitMinimapPixelsToImageRadar(video::IImage *map_image); void blitMinimapPixelsToImageRadar(video::IImage *map_image);