void MinimapUpdateThread::doUpdate() { QueuedMinimapUpdate update; while (popBlockUpdate(&update)) { if (update.data) { // Swap two values in the map using single lookup std::pair<std::map<v3s16, MinimapMapblock*>::iterator, bool> result = m_blocks_cache.insert(std::make_pair(update.pos, update.data)); if (result.second == false) { delete result.first->second; result.first->second = update.data; } } else { std::map<v3s16, MinimapMapblock *>::iterator it; it = m_blocks_cache.find(update.pos); if (it != m_blocks_cache.end()) { delete it->second; m_blocks_cache.erase(it); } } } if (data->map_invalidated && data->mode != MINIMAP_MODE_OFF) { getMap(data->pos, data->map_size, data->scan_height, data->is_radar); data->map_invalidated = false; } }
void MinimapUpdateThread::doUpdate() { ScopeProfiler sp(g_profiler, "Client: minimap"); QueuedMinimapUpdate update; while (popBlockUpdate(&update)) { getmap_cache.erase(v2POS(update.pos.X, update.pos.Z)); if (update.data) { // Swap two values in the map using single lookup auto result = m_blocks_cache.insert(std::make_pair(update.pos, update.data)); if (result.second == false) { delete result.first->second; result.first->second = update.data; } } else { auto it = m_blocks_cache.find(update.pos); if (it != m_blocks_cache.end()) { delete it->second; m_blocks_cache.erase(it); } } } auto now = porting::getTimeMs(); if (next_update < now) { next_update = now + 333; } else { return; } bool do_update; { MutexAutoLock lock(data->m_mutex); do_update = data->map_invalidated && data->mode != MINIMAP_MODE_OFF; } if (do_update) { getMap(data->pos, data->map_size, data->scan_height, data->is_radar); data->map_invalidated = false; } }