diff --git a/src/noggit/AsyncLoader.cpp b/src/noggit/AsyncLoader.cpp index 0c3a0ca8..eacbd618 100644 --- a/src/noggit/AsyncLoader.cpp +++ b/src/noggit/AsyncLoader.cpp @@ -8,6 +8,26 @@ #include #include +bool AsyncLoader::is_loading() +{ + std::lock_guard const lock (_guard); + if (_currently_loading.empty()) + { + return false; + } + else + { + for (auto async_obj : _currently_loading) + { + if (!async_obj->loading_failed() && async_obj->filename.length()) // the filename check is a hack + { + return true; + } + } + } + return false; +} + void AsyncLoader::process() { AsyncObject* object = nullptr; diff --git a/src/noggit/AsyncLoader.h b/src/noggit/AsyncLoader.h index 033a6a1a..85638f3c 100644 --- a/src/noggit/AsyncLoader.h +++ b/src/noggit/AsyncLoader.h @@ -26,6 +26,8 @@ public: void ensure_deletable (AsyncObject*); + bool is_loading(); + AsyncLoader(int numThreads); ~AsyncLoader(); diff --git a/src/noggit/MapView.cpp b/src/noggit/MapView.cpp index 29d6d6ef..06e3bcd9 100644 --- a/src/noggit/MapView.cpp +++ b/src/noggit/MapView.cpp @@ -1534,17 +1534,46 @@ void MapView::paintGL() if (Saving) { - // std::this_thread::sleep_for(std::chrono::seconds {10}); - _world->saveMinimap(512, 512, tile_index (_camera.position)); - Saving = false; - return; + // increment tile indices here + if (mmap_render_success) + { + mmap_render_index++; + } + + tile_index tile = tile_index(mmap_render_index / 64, mmap_render_index % 64); + + if (_world->mapIndex.hasTile(tile)) + { + mmap_render_success = _world->saveMinimap(512, 512, tile); + } + else + { + do + { + mmap_render_index++; + tile.x = mmap_render_index / 64; + tile.z = mmap_render_index % 64; + + } while (!_world->mapIndex.hasTile(tile) && mmap_render_index != 4095); + } + + if (mmap_render_success && mmap_render_index == 4095) + { + Saving = false; + mmap_render_index = 0; + mmap_render_success = false; + } } const qreal now(_startup_time.elapsed() / 1000.0); _last_frame_durations.emplace_back (now - _last_update); - tick (now - _last_update); + if (!Saving) + { + tick (now - _last_update); + } + _last_update = now; gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -1556,12 +1585,13 @@ void MapView::paintGL() _uid_duplicate_warning_shown = true; QMessageBox::critical( this - , "UID ALREADY IN USE" - , "Please enable 'Always check for max UID', mysql uid store or synchronize your " - "uid.ini file if you're sharing the map between several mappers.\n\n" - "Use 'Editor > Force uid check on next opening' to fix the issue." - ); + , "UID ALREADY IN USE" + , "Please enable 'Always check for max UID', mysql uid store or synchronize your " + "uid.ini file if you're sharing the map between several mappers.\n\n" + "Use 'Editor > Force uid check on next opening' to fix the issue." + ); } + } void MapView::resizeGL (int width, int height) diff --git a/src/noggit/MapView.h b/src/noggit/MapView.h index 6c483970..fbcc3127 100644 --- a/src/noggit/MapView.h +++ b/src/noggit/MapView.h @@ -140,6 +140,9 @@ private: bool leftClicked = false; bool rightMouse = false; + bool mmap_render_success = false; + int mmap_render_index = 0; + // Vars for the ground editing toggle mode store the status of some // view settings when the ground editing mode is switched on to // restore them if switch back again diff --git a/src/noggit/World.cpp b/src/noggit/World.cpp index b71795fb..c8c58683 100644 --- a/src/noggit/World.cpp +++ b/src/noggit/World.cpp @@ -1861,11 +1861,6 @@ void World::drawMinimap ( MapTile *tile mcnk_shader.uniform("wireframe_color", wireframe_color); mcnk_shader.uniform("draw_fog", 0); - mcnk_shader.uniform("fog_color", math::vector_4d(skies->color_set[FOG_COLOR], 1)); - // !\ todo use light dbcs values - mcnk_shader.uniform("fog_end", fogdistance); - mcnk_shader.uniform("fog_start", 0.5f); - mcnk_shader.uniform("camera", camera_pos); mcnk_shader.uniform("light_dir", terrain_light_dir); mcnk_shader.uniform("diffuse_color", diffuse_color); @@ -1895,7 +1890,7 @@ void World::drawMinimap ( MapTile *tile tile_index m_tile = tile_index (camera_pos); m_tile.z -= 1; - bool unload = !mapIndex.tileLoaded(m_tile) && !mapIndex.tileAwaitingLoading(m_tile); + bool unload = !mapIndex.has_unsaved_changes(m_tile); MapTile* mTile = mapIndex.loadTile(m_tile); if (mTile) @@ -1908,6 +1903,11 @@ void World::drawMinimap ( MapTile *tile ); } + if (unload) + { + mapIndex.unloadTile(m_tile); + } + gl.bindVertexArray(0); gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -2049,7 +2049,7 @@ void World::saveMinimap (int width, int height) } -void World::saveMinimap(int width, int height, tile_index const& tile_idx) +bool World::saveMinimap(int width, int height, tile_index const& tile_idx) { // Setup framebuffer QOpenGLFramebufferObjectFormat fmt; @@ -2065,7 +2065,7 @@ void World::saveMinimap(int width, int height, tile_index const& tile_idx) gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Load tile - bool unload = !mapIndex.tileLoaded(tile_idx) && !mapIndex.tileAwaitingLoading(tile_idx); + bool unload = !mapIndex.has_unsaved_changes(tile_idx); MapTile* mTile = mapIndex.loadTile(tile_idx); if (mTile) @@ -2073,6 +2073,11 @@ void World::saveMinimap(int width, int height, tile_index const& tile_idx) mTile->wait_until_loaded(); wait_for_all_tile_updates(); + if (AsyncLoader::instance().is_loading()) + { + return false; + } + float max_height = getMaxTileHeight(tile_idx); // setup view matrices @@ -2092,7 +2097,7 @@ void World::saveMinimap(int width, int height, tile_index const& tile_idx) drawMinimap(mTile, look_at.transposed(), projection.transposed(), math::vector_3d(TILESIZE * tile_idx.x + TILESIZE / 2.0f, max_height + 15.0f, TILESIZE * tile_idx.z + TILESIZE / 2.0f)); QImage image = pixel_buffer.toImage(); - image.save("/Users/sshumakov/Desktop/test_minimap.png"); + image.save(("/Users/sshumakov/Desktop/MinimapGenTest/test_" + std::to_string(tile_idx.x) + "_" + std::to_string(tile_idx.z) + ".png").c_str()); if (unload) { @@ -2101,6 +2106,8 @@ void World::saveMinimap(int width, int height, tile_index const& tile_idx) } pixel_buffer.release(); + + return true; } void World::deleteModelInstance(int pUniqueID) diff --git a/src/noggit/World.h b/src/noggit/World.h index 8e7422d4..8b33f72d 100644 --- a/src/noggit/World.h +++ b/src/noggit/World.h @@ -49,6 +49,8 @@ private: std::unordered_map> _models_by_filename; noggit::world_model_instances_storage _model_instance_storage; noggit::world_tile_update_queue _tile_update_queue; + std::mutex _guard; + public: MapIndex mapIndex; noggit::map_horizon horizon; @@ -261,7 +263,7 @@ public: void wait_for_all_tile_updates(); void saveMinimap (int width, int height); - void saveMinimap (int width, int height, tile_index const& tile_idx); + bool saveMinimap (int width, int height, tile_index const& tile_idx); void drawMinimap ( MapTile *tile , math::matrix_4x4 const& model_view , math::matrix_4x4 const& projection