Skip to content

Commit 59088a6

Browse files
committed
Multithread .thm files loading
1 parent c101668 commit 59088a6

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

src/Layers/xrRender/ResourceManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void CResourceManager::DeferredUpload()
349349
return;
350350

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

354354
CTimer timer;
355355
timer.Start();
@@ -363,7 +363,7 @@ void CResourceManager::DeferredUpload()
363363
#endif
364364

365365
#ifndef MASTER_GOLD
366-
Msg("%s, texture loading time = %d", __FUNCTION__, timer.GetElapsed_ms());
366+
Msg("%s, texture loading time: %d ms", __FUNCTION__, timer.GetElapsed_ms());
367367
#endif
368368
}
369369
/*

src/Layers/xrRender/TextureDescrManager.cpp

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "stdafx.h"
2-
#pragma hdrstop
2+
3+
#include <tbb/parallel_for_each.h>
4+
35
#include "TextureDescrManager.h"
46
#include "ETextureParams.h"
57

@@ -28,27 +30,25 @@ void CTextureDescrMngr::LoadTHM(LPCSTR initial)
2830
{
2931
FS_FileSet flist;
3032
FS.file_list(flist, initial, FS_ListFiles, "*.thm");
31-
#ifdef DEBUG
32-
Msg("count of .thm files=%d", flist.size());
33-
#endif // #ifdef DEBUG
34-
auto It = flist.begin();
35-
auto It_e = flist.end();
36-
STextureParams tp;
37-
string_path fn;
38-
for (; It != It_e; ++It)
33+
#ifndef MASTER_GOLD
34+
Msg("%s, count of .thm files: %d", __FUNCTION__, flist.size());
35+
#endif
36+
37+
tbb::parallel_for_each(flist, [&](auto& it)
3938
{
40-
#ifdef DEBUG
39+
#if 0//def DEBUG // XXX: make it as an option
4140
//Alundaio: Print list of *.thm to find bad .thms!
42-
Msg("%s", (*It).name.c_str());
41+
Msg("%s", it.name.c_str());
4342
#endif
44-
FS.update_path(fn, initial, (*It).name.c_str());
43+
string_path fn;
44+
FS.update_path(fn, initial, it.name.c_str());
4545
IReader* F = FS.r_open(fn);
46-
xr_strcpy(fn, (*It).name.c_str());
46+
xr_strcpy(fn, it.name.c_str());
4747
fix_texture_thm_name(fn);
4848

4949
R_ASSERT(F->find_chunk(THM_CHUNK_TYPE));
5050
F->r_u32();
51-
tp.Clear();
51+
STextureParams tp;
5252
tp.Load(*F);
5353
FS.r_close(F);
5454
if (STextureParams::ttImage == tp.type || STextureParams::ttTerrain == tp.type ||
@@ -95,43 +95,38 @@ void CTextureDescrMngr::LoadTHM(LPCSTR initial)
9595
desc.m_spec->m_use_steep_parallax = true;
9696
}
9797
}
98-
}
98+
});
9999
}
100100

101101
void CTextureDescrMngr::Load()
102102
{
103-
#ifdef DEBUG
104-
CTimer TT;
105-
TT.Start();
103+
#ifndef MASTER_GOLD
104+
CTimer timer;
105+
timer.Start();
106106
#endif // #ifdef DEBUG
107107

108108
LoadTHM("$game_textures$");
109109
LoadTHM("$level$");
110110

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

116116
void CTextureDescrMngr::UnLoad()
117117
{
118-
map_TD::iterator I = m_texture_details.begin();
119-
map_TD::iterator E = m_texture_details.end();
120-
for (; I != E; ++I)
118+
for (auto& it : m_texture_details)
121119
{
122-
xr_delete(I->second.m_assoc);
123-
xr_delete(I->second.m_spec);
120+
xr_delete(it.second.m_assoc);
121+
xr_delete(it.second.m_spec);
124122
}
125123
m_texture_details.clear();
126124
}
127125

128126
CTextureDescrMngr::~CTextureDescrMngr()
129127
{
130-
map_CS::iterator I = m_detail_scalers.begin();
131-
map_CS::iterator E = m_detail_scalers.end();
132-
133-
for (; I != E; ++I)
134-
xr_delete(I->second);
128+
for (auto& it : m_detail_scalers)
129+
xr_delete(it.second);
135130

136131
m_detail_scalers.clear();
137132
}

0 commit comments

Comments
 (0)