-
-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SOC style texture descriptions support (#392)
And refactored TextureDescrManager a bit.
- Loading branch information
1 parent
aec38d6
commit 50a4548
Showing
2 changed files
with
113 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,32 +29,120 @@ void fix_texture_thm_name(LPSTR fn) | |
} | ||
|
||
#ifdef SINGLETHREADED_TEXTURES_DESCR | ||
#define LOCK_DESCR(lock) | ||
#define UNLOCK_DESCR(lock) | ||
#define DECLARE_DESCR_LOCK | ||
#define LOCK_DESCR() | ||
#define UNLOCK_DESCR() | ||
#define PROCESS_DESCR(processable, function) \ | ||
for (const auto& item : processable) \ | ||
function(item) | ||
#else | ||
#define LOCK_DESCR(lock) lock.Enter() | ||
#define UNLOCK_DESCR(lock) lock.Leave() | ||
#define DECLARE_DESCR_LOCK Lock descrLock | ||
#define LOCK_DESCR() descrLock.Enter() | ||
#define UNLOCK_DESCR() descrLock.Leave() | ||
#define PROCESS_DESCR(processable, function) \ | ||
tbb::parallel_for_each(processable, function) | ||
#endif | ||
|
||
void CTextureDescrMngr::LoadTHM(LPCSTR initial) | ||
void CTextureDescrMngr::LoadLTX(pcstr initial, bool listTHM) | ||
{ | ||
FS_FileSet flist; | ||
FS.file_list(flist, initial, FS_ListFiles, "*.thm"); | ||
string_path fname; | ||
FS.update_path(fname, initial, "textures.ltx"); | ||
|
||
if (!FS.exist(fname)) | ||
return; | ||
|
||
#ifndef MASTER_GOLD | ||
Msg("%s, count of .thm files: %d", __FUNCTION__, flist.size()); | ||
Msg("Processing textures.ltx in [%s]", initial); | ||
#endif | ||
DECLARE_DESCR_LOCK; | ||
|
||
CInifile ini(fname); | ||
|
||
#ifndef SINGLETHREADED_TEXTURES_DESCR | ||
Lock lock; | ||
if (ini.section_exist("association")) | ||
{ | ||
CInifile::Sect& data = ini.r_section("association"); | ||
#ifndef MASTER_GOLD | ||
Msg("\tsection [%s] has %d lines", data.Name.c_str(), data.Data.size()); | ||
#endif | ||
const auto processAssociation = [&](const CInifile::Item& item) | ||
{ | ||
if (listTHM) | ||
Msg("\t\t%s = %s", item.first.c_str(), item.second.c_str()); | ||
|
||
LOCK_DESCR(); | ||
texture_desc& desc = m_texture_details[item.first]; | ||
cl_dt_scaler*& dts = m_detail_scalers[item.first]; | ||
desc.m_assoc = new texture_assoc(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Xottab-DUTY
Author
Member
|
||
UNLOCK_DESCR(); | ||
|
||
string_path T; | ||
float s; | ||
|
||
int res = sscanf(*item.second, "%[^,],%f", T, &s); | ||
R_ASSERT(res == 2); | ||
desc.m_assoc->detail_name = T; | ||
dts = new cl_dt_scaler(s); | ||
desc.m_assoc->usage = 0; | ||
if (strstr(item.second.c_str(), "usage[diffuse_or_bump]")) | ||
desc.m_assoc->usage = (1 << 0) | (1 << 1); | ||
else if (strstr(item.second.c_str(), "usage[bump]")) | ||
desc.m_assoc->usage = (1 << 1); | ||
else if (strstr(item.second.c_str(), "usage[diffuse]")) | ||
desc.m_assoc->usage = (1 << 0); | ||
}; | ||
PROCESS_DESCR(data.Data, processAssociation); | ||
} // "association" | ||
|
||
if (ini.section_exist("specification")) | ||
{ | ||
CInifile::Sect& data = ini.r_section("specification"); | ||
#ifndef MASTER_GOLD | ||
Msg("\tsection [%s] has %d lines", data.Name.c_str(), data.Data.size()); | ||
#endif | ||
const auto processSpecification = [&](const CInifile::Item& item) | ||
{ | ||
if (listTHM) | ||
Msg("\t\t%s = %s", item.first.c_str(), item.second.c_str()); | ||
|
||
const bool listTHM = strstr(Core.Params, "-list_thm"); | ||
LOCK_DESCR(); | ||
texture_desc& desc = m_texture_details[item.first]; | ||
UNLOCK_DESCR(); | ||
|
||
desc.m_spec = new texture_spec(); | ||
|
||
string_path bmode; | ||
const int res = | ||
sscanf(item.second.c_str(), "bump_mode[%[^]]], material[%f]", bmode, &desc.m_spec->m_material); | ||
R_ASSERT(res == 2); | ||
if ((bmode[0] == 'u') && (bmode[1] == 's') && (bmode[2] == 'e') && (bmode[3] == ':')) | ||
{ | ||
// bump-map specified | ||
desc.m_spec->m_bump_name = bmode + 4; | ||
} | ||
}; | ||
PROCESS_DESCR(data.Data, processSpecification); | ||
} // "specification" | ||
} | ||
|
||
void CTextureDescrMngr::LoadTHM(LPCSTR initial, bool listTHM) | ||
{ | ||
FS_FileSet flist; | ||
FS.file_list(flist, initial, FS_ListFiles, "*.thm"); | ||
|
||
if (flist.empty()) | ||
return; | ||
|
||
#ifndef MASTER_GOLD | ||
Msg("Processing %d .thm files in [%s]", flist.size(), initial); | ||
#endif | ||
|
||
DECLARE_DESCR_LOCK; | ||
|
||
const auto processFile = [&](const FS_File& it) | ||
{ | ||
// Alundaio: Print list of *.thm to find bad .thms! | ||
if (listTHM) | ||
Log(it.name.c_str()); | ||
Log("\t", it.name.c_str()); | ||
|
||
string_path fn; | ||
FS.update_path(fn, initial, it.name.c_str()); | ||
|
@@ -70,10 +158,10 @@ void CTextureDescrMngr::LoadTHM(LPCSTR initial) | |
if (STextureParams::ttImage == tp.type || STextureParams::ttTerrain == tp.type || | ||
STextureParams::ttNormalMap == tp.type) | ||
{ | ||
LOCK_DESCR(lock); | ||
LOCK_DESCR(); | ||
texture_desc& desc = m_texture_details[fn]; | ||
cl_dt_scaler*& dts = m_detail_scalers[fn]; | ||
UNLOCK_DESCR(lock); | ||
UNLOCK_DESCR(); | ||
|
||
if (tp.detail_name.size() && | ||
tp.flags.is_any(STextureParams::flDiffuseDetail | STextureParams::flBumpDetail)) | ||
|
@@ -115,12 +203,7 @@ void CTextureDescrMngr::LoadTHM(LPCSTR initial) | |
} | ||
}; | ||
|
||
#ifdef SINGLETHREADED_TEXTURES_DESCR | ||
for (auto& it : flist) | ||
processFile(it); | ||
#else | ||
tbb::parallel_for_each(flist, processFile); | ||
#endif | ||
PROCESS_DESCR(flist, processFile); | ||
} | ||
|
||
void CTextureDescrMngr::Load() | ||
|
@@ -130,11 +213,16 @@ void CTextureDescrMngr::Load() | |
timer.Start(); | ||
#endif // #ifdef DEBUG | ||
|
||
LoadTHM("$game_textures$"); | ||
LoadTHM("$level$"); | ||
const bool listTHM = strstr(Core.Params, "-list_thm"); | ||
|
||
LoadLTX("$game_textures$", listTHM); | ||
LoadLTX("$level$", listTHM); | ||
|
||
LoadTHM("$game_textures$", listTHM); | ||
LoadTHM("$level$", listTHM); | ||
|
||
#ifndef MASTER_GOLD | ||
Msg("%s, .thm loading time: %d ms", __FUNCTION__, timer.GetElapsed_ms()); | ||
Msg("%s, texture descriptions loaded for %d ms", __FUNCTION__, timer.GetElapsed_ms()); | ||
#endif | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maybe add R_ASSERT(desc.m_assoc == nullptr)? And could the same item be processed in more than 1 thread in the same time (in case of parallel mode)?