Properly wait while resource is pending in ResourceManager

This commit is contained in:
mrkubax10 2024-04-21 14:39:49 +02:00
parent 4a6e086c0e
commit ea46b48eee
2 changed files with 14 additions and 10 deletions

View File

@ -196,7 +196,7 @@ polygun::renderer::Surface& ResourceManager::get_surface(const std::string& reso
} }
// Check if resource is loaded // Check if resource is loaded
if(m_textures.count(resource_id)) { if(m_surfaces.count(resource_id)) {
LoadedResource<renderer::Surface>& resource = m_surfaces[resource_id]; LoadedResource<renderer::Surface>& resource = m_surfaces[resource_id];
resource.m_last_used = std::chrono::steady_clock::now(); resource.m_last_used = std::chrono::steady_clock::now();
release(); release();

View File

@ -79,6 +79,19 @@ void TextureAtlas::construct_thread_func() {
std::string texture_filename = m_content_registry.get_node_def(i).m_texture_filename; std::string texture_filename = m_content_registry.get_node_def(i).m_texture_filename;
if(texture_filename.empty()) if(texture_filename.empty())
continue; continue;
m_resource_manager.get_surface(texture_filename);
const std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
while(m_resource_manager.is_pending()) {
const std::chrono::time_point<std::chrono::system_clock> tm = std::chrono::system_clock::now();
const std::chrono::duration<double> interval = tm-start;
if(interval.count()>30) {
LOG_WARNING("Waiting for node texture '%s' took too long, stopping", texture_filename.c_str());
break;
}
}
renderer::Surface& surf = m_resource_manager.get_surface(texture_filename); renderer::Surface& surf = m_resource_manager.get_surface(texture_filename);
surfaces[i-1] = &surf; surfaces[i-1] = &surf;
if(surf.get_width()>max_texture_width) if(surf.get_width()>max_texture_width)
@ -86,15 +99,6 @@ void TextureAtlas::construct_thread_func() {
if(surf.get_height()>max_texture_height) if(surf.get_height()>max_texture_height)
max_texture_height = surf.get_height(); max_texture_height = surf.get_height();
} }
const std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
while(m_resource_manager.is_pending()) {
const std::chrono::time_point<std::chrono::system_clock> tm = std::chrono::system_clock::now();
const std::chrono::duration<double> interval = tm-start;
if(interval.count()>30) {
LOG_WARNING("Waiting for node textures took too long, stopping");
break;
}
}
acquire(); acquire();
m_atlas_surface.reset(new renderer::Surface(max_texture_width*surface_count, max_texture_height)); m_atlas_surface.reset(new renderer::Surface(max_texture_width*surface_count, max_texture_height));