fix async issues with minimap rendering
This commit is contained in:
@@ -8,6 +8,26 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
|
bool AsyncLoader::is_loading()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> 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()
|
void AsyncLoader::process()
|
||||||
{
|
{
|
||||||
AsyncObject* object = nullptr;
|
AsyncObject* object = nullptr;
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public:
|
|||||||
|
|
||||||
void ensure_deletable (AsyncObject*);
|
void ensure_deletable (AsyncObject*);
|
||||||
|
|
||||||
|
bool is_loading();
|
||||||
|
|
||||||
AsyncLoader(int numThreads);
|
AsyncLoader(int numThreads);
|
||||||
~AsyncLoader();
|
~AsyncLoader();
|
||||||
|
|
||||||
|
|||||||
@@ -1534,17 +1534,46 @@ void MapView::paintGL()
|
|||||||
|
|
||||||
if (Saving)
|
if (Saving)
|
||||||
{
|
{
|
||||||
// std::this_thread::sleep_for(std::chrono::seconds {10});
|
// increment tile indices here
|
||||||
_world->saveMinimap(512, 512, tile_index (_camera.position));
|
if (mmap_render_success)
|
||||||
Saving = false;
|
{
|
||||||
return;
|
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);
|
const qreal now(_startup_time.elapsed() / 1000.0);
|
||||||
|
|
||||||
_last_frame_durations.emplace_back (now - _last_update);
|
_last_frame_durations.emplace_back (now - _last_update);
|
||||||
|
|
||||||
tick (now - _last_update);
|
if (!Saving)
|
||||||
|
{
|
||||||
|
tick (now - _last_update);
|
||||||
|
}
|
||||||
|
|
||||||
_last_update = now;
|
_last_update = now;
|
||||||
|
|
||||||
gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
@@ -1556,12 +1585,13 @@ void MapView::paintGL()
|
|||||||
_uid_duplicate_warning_shown = true;
|
_uid_duplicate_warning_shown = true;
|
||||||
|
|
||||||
QMessageBox::critical( this
|
QMessageBox::critical( this
|
||||||
, "UID ALREADY IN USE"
|
, "UID ALREADY IN USE"
|
||||||
, "Please enable 'Always check for max UID', mysql uid store or synchronize your "
|
, "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"
|
"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."
|
"Use 'Editor > Force uid check on next opening' to fix the issue."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapView::resizeGL (int width, int height)
|
void MapView::resizeGL (int width, int height)
|
||||||
|
|||||||
@@ -140,6 +140,9 @@ private:
|
|||||||
bool leftClicked = false;
|
bool leftClicked = false;
|
||||||
bool rightMouse = 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
|
// Vars for the ground editing toggle mode store the status of some
|
||||||
// view settings when the ground editing mode is switched on to
|
// view settings when the ground editing mode is switched on to
|
||||||
// restore them if switch back again
|
// restore them if switch back again
|
||||||
|
|||||||
@@ -1861,11 +1861,6 @@ void World::drawMinimap ( MapTile *tile
|
|||||||
mcnk_shader.uniform("wireframe_color", wireframe_color);
|
mcnk_shader.uniform("wireframe_color", wireframe_color);
|
||||||
|
|
||||||
mcnk_shader.uniform("draw_fog", 0);
|
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("light_dir", terrain_light_dir);
|
||||||
mcnk_shader.uniform("diffuse_color", diffuse_color);
|
mcnk_shader.uniform("diffuse_color", diffuse_color);
|
||||||
@@ -1895,7 +1890,7 @@ void World::drawMinimap ( MapTile *tile
|
|||||||
tile_index m_tile = tile_index (camera_pos);
|
tile_index m_tile = tile_index (camera_pos);
|
||||||
m_tile.z -= 1;
|
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);
|
MapTile* mTile = mapIndex.loadTile(m_tile);
|
||||||
|
|
||||||
if (mTile)
|
if (mTile)
|
||||||
@@ -1908,6 +1903,11 @@ void World::drawMinimap ( MapTile *tile
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unload)
|
||||||
|
{
|
||||||
|
mapIndex.unloadTile(m_tile);
|
||||||
|
}
|
||||||
|
|
||||||
gl.bindVertexArray(0);
|
gl.bindVertexArray(0);
|
||||||
gl.bindBuffer(GL_ELEMENT_ARRAY_BUFFER, 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
|
// Setup framebuffer
|
||||||
QOpenGLFramebufferObjectFormat fmt;
|
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);
|
gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// Load tile
|
// 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);
|
MapTile* mTile = mapIndex.loadTile(tile_idx);
|
||||||
|
|
||||||
if (mTile)
|
if (mTile)
|
||||||
@@ -2073,6 +2073,11 @@ void World::saveMinimap(int width, int height, tile_index const& tile_idx)
|
|||||||
mTile->wait_until_loaded();
|
mTile->wait_until_loaded();
|
||||||
wait_for_all_tile_updates();
|
wait_for_all_tile_updates();
|
||||||
|
|
||||||
|
if (AsyncLoader::instance().is_loading())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
float max_height = getMaxTileHeight(tile_idx);
|
float max_height = getMaxTileHeight(tile_idx);
|
||||||
|
|
||||||
// setup view matrices
|
// 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));
|
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();
|
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)
|
if (unload)
|
||||||
{
|
{
|
||||||
@@ -2101,6 +2106,8 @@ void World::saveMinimap(int width, int height, tile_index const& tile_idx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pixel_buffer.release();
|
pixel_buffer.release();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::deleteModelInstance(int pUniqueID)
|
void World::deleteModelInstance(int pUniqueID)
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ private:
|
|||||||
std::unordered_map<std::string, std::vector<ModelInstance*>> _models_by_filename;
|
std::unordered_map<std::string, std::vector<ModelInstance*>> _models_by_filename;
|
||||||
noggit::world_model_instances_storage _model_instance_storage;
|
noggit::world_model_instances_storage _model_instance_storage;
|
||||||
noggit::world_tile_update_queue _tile_update_queue;
|
noggit::world_tile_update_queue _tile_update_queue;
|
||||||
|
std::mutex _guard;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MapIndex mapIndex;
|
MapIndex mapIndex;
|
||||||
noggit::map_horizon horizon;
|
noggit::map_horizon horizon;
|
||||||
@@ -261,7 +263,7 @@ public:
|
|||||||
void wait_for_all_tile_updates();
|
void wait_for_all_tile_updates();
|
||||||
|
|
||||||
void saveMinimap (int width, int height);
|
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
|
void drawMinimap ( MapTile *tile
|
||||||
, math::matrix_4x4 const& model_view
|
, math::matrix_4x4 const& model_view
|
||||||
, math::matrix_4x4 const& projection
|
, math::matrix_4x4 const& projection
|
||||||
|
|||||||
Reference in New Issue
Block a user