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");
// 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,7 +224,9 @@ Minimap::~Minimap()
m_meshbuffer->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);
@ -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,17 +515,14 @@ 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));
}
}
if (data->texture)
driver->removeTexture(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);