Skip to content

Commit

Permalink
Multithread .thm files loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Feb 9, 2018
1 parent c101668 commit 59088a6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Layers/xrRender/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void CResourceManager::DeferredUpload()
return;

#ifndef MASTER_GOLD
Msg("%s, amount of textures = %d", __FUNCTION__, m_textures.size());
Msg("%s, amount of textures: %d", __FUNCTION__, m_textures.size());

CTimer timer;
timer.Start();
Expand All @@ -363,7 +363,7 @@ void CResourceManager::DeferredUpload()
#endif

#ifndef MASTER_GOLD
Msg("%s, texture loading time = %d", __FUNCTION__, timer.GetElapsed_ms());
Msg("%s, texture loading time: %d ms", __FUNCTION__, timer.GetElapsed_ms());
#endif
}
/*
Expand Down
57 changes: 26 additions & 31 deletions src/Layers/xrRender/TextureDescrManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "stdafx.h"
#pragma hdrstop

#include <tbb/parallel_for_each.h>

#include "TextureDescrManager.h"
#include "ETextureParams.h"

Expand Down Expand Up @@ -28,27 +30,25 @@ void CTextureDescrMngr::LoadTHM(LPCSTR initial)
{
FS_FileSet flist;
FS.file_list(flist, initial, FS_ListFiles, "*.thm");
#ifdef DEBUG
Msg("count of .thm files=%d", flist.size());
#endif // #ifdef DEBUG
auto It = flist.begin();
auto It_e = flist.end();
STextureParams tp;
string_path fn;
for (; It != It_e; ++It)
#ifndef MASTER_GOLD
Msg("%s, count of .thm files: %d", __FUNCTION__, flist.size());
#endif

tbb::parallel_for_each(flist, [&](auto& it)
{
#ifdef DEBUG
#if 0//def DEBUG // XXX: make it as an option
//Alundaio: Print list of *.thm to find bad .thms!
Msg("%s", (*It).name.c_str());
Msg("%s", it.name.c_str());
#endif
FS.update_path(fn, initial, (*It).name.c_str());
string_path fn;
FS.update_path(fn, initial, it.name.c_str());
IReader* F = FS.r_open(fn);
xr_strcpy(fn, (*It).name.c_str());
xr_strcpy(fn, it.name.c_str());
fix_texture_thm_name(fn);

R_ASSERT(F->find_chunk(THM_CHUNK_TYPE));
F->r_u32();
tp.Clear();
STextureParams tp;
tp.Load(*F);
FS.r_close(F);
if (STextureParams::ttImage == tp.type || STextureParams::ttTerrain == tp.type ||
Expand Down Expand Up @@ -95,43 +95,38 @@ void CTextureDescrMngr::LoadTHM(LPCSTR initial)
desc.m_spec->m_use_steep_parallax = true;
}
}
}
});
}

void CTextureDescrMngr::Load()
{
#ifdef DEBUG
CTimer TT;
TT.Start();
#ifndef MASTER_GOLD
CTimer timer;
timer.Start();
#endif // #ifdef DEBUG

LoadTHM("$game_textures$");
LoadTHM("$level$");

#ifdef DEBUG
Msg("load time=%d ms", TT.GetElapsed_ms());
#endif // #ifdef DEBUG
#ifndef MASTER_GOLD
Msg("%s, .thm loading time: %d ms", __FUNCTION__, timer.GetElapsed_ms());
#endif
}

void CTextureDescrMngr::UnLoad()
{
map_TD::iterator I = m_texture_details.begin();
map_TD::iterator E = m_texture_details.end();
for (; I != E; ++I)
for (auto& it : m_texture_details)
{
xr_delete(I->second.m_assoc);
xr_delete(I->second.m_spec);
xr_delete(it.second.m_assoc);
xr_delete(it.second.m_spec);
}
m_texture_details.clear();
}

CTextureDescrMngr::~CTextureDescrMngr()
{
map_CS::iterator I = m_detail_scalers.begin();
map_CS::iterator E = m_detail_scalers.end();

for (; I != E; ++I)
xr_delete(I->second);
for (auto& it : m_detail_scalers)
xr_delete(it.second);

m_detail_scalers.clear();
}
Expand Down

0 comments on commit 59088a6

Please sign in to comment.