Skip to content

Commit dc66bb1

Browse files
joye-ramonexrSimpodin
authored andcommitted
Поддержка ЗП формата для файлов описания текстур texture_desc. Они удобнее - можно кучу текстур описать в одном файле. Так же автозагрузка описаний по пути ui\\textures_descr\\*.xml
1 parent 907f5ef commit dc66bb1

File tree

2 files changed

+88
-21
lines changed

2 files changed

+88
-21
lines changed

ogsr_engine/xrGame/MainMenu.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ void CMainMenu::ReadTextureInfo()
8383
CUITextureMaster::ParseShTexInfo(single_item);
8484
}
8585
}
86+
87+
// autoload
88+
FS_FileSet fset;
89+
FS.file_list(fset, "$game_config$", FS_ListFiles, "ui\\textures_descr\\*.xml");
90+
FS_FileSetIt fit = fset.begin();
91+
FS_FileSetIt fit_e = fset.end();
92+
93+
for (; fit != fit_e; ++fit)
94+
{
95+
string_path fn1, fn2, fn3;
96+
_splitpath((*fit).name.c_str(), fn1, fn2, fn3, 0);
97+
98+
xr_strcpy(fn1, "textures_descr\\");
99+
xr_strcat(fn1, fn3);
100+
xr_strcat(fn1, ".xml");
101+
102+
//xr_string fn1 = (*fit).name;
103+
104+
CUITextureMaster::ParseShTexInfo(fn1);
105+
}
86106
}
87107

88108
extern ENGINE_API BOOL bShowPauseString;

ogsr_engine/xrGame/ui/UITextureMaster.cpp

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,76 @@ void CUITextureMaster::ParseShTexInfo(LPCSTR xml_file)
2727
{
2828
CUIXml xml;
2929
xml.Init(CONFIG_PATH, UI_PATH, xml_file);
30-
shared_str file = xml.Read("file_name", 0, "");
31-
32-
// shared_textures_it sht_it = m_shTex.find(texture);
33-
// if (m_shTex.end() == sht_it)
34-
// {
35-
int num = xml.GetNodesNum("", 0, "texture");
36-
// regions regs;
37-
for (int i = 0; i < num; i++)
38-
{
39-
TEX_INFO info;
40-
41-
info.file = file;
4230

43-
info.rect.x1 = xml.ReadAttribFlt("texture", i, "x");
44-
info.rect.x2 = xml.ReadAttribFlt("texture", i, "width") + info.rect.x1;
45-
info.rect.y1 = xml.ReadAttribFlt("texture", i, "y");
46-
info.rect.y2 = xml.ReadAttribFlt("texture", i, "height") + info.rect.y1;
47-
shared_str id = xml.ReadAttrib("texture", i, "id");
48-
49-
m_textures.insert(mk_pair(id, info));
31+
int files_num = xml.GetNodesNum("", 0, "file");
32+
if (files_num > 0)
33+
{
34+
// ЗП формат
35+
for (int fi = 0; fi < files_num; ++fi)
36+
{
37+
XML_NODE* root_node = xml.GetLocalRoot();
38+
39+
shared_str file = xml.ReadAttrib("file", fi, "name");
40+
41+
XML_NODE* node = xml.NavigateToNode("file", fi);
42+
int num = xml.GetNodesNum(node, "texture");
43+
for (int i = 0; i < num; i++)
44+
{
45+
TEX_INFO info;
46+
47+
info.file = file;
48+
49+
info.rect.x1 = xml.ReadAttribFlt(node, "texture", i, "x");
50+
info.rect.x2 = xml.ReadAttribFlt(node, "texture", i, "width") + info.rect.x1;
51+
info.rect.y1 = xml.ReadAttribFlt(node, "texture", i, "y");
52+
info.rect.y2 = xml.ReadAttribFlt(node, "texture", i, "height") + info.rect.y1;
53+
54+
shared_str id = xml.ReadAttrib(node, "texture", i, "id");
55+
56+
/* avo: fix issue when values were not updated (silently skipped) when same key is encountered more than once. This is how std::map is designed.
57+
/* Also used more efficient C++11 std::map::emplace method instead of outdated std::pair::make_pair */
58+
/* XXX: avo: note that xxx.insert(mk_pair(v1,v2)) pattern is used extensively throughout solution so there is a good potential for other bug fixes/improvements */
59+
if (m_textures.find(id) == m_textures.end())
60+
m_textures.emplace(id, info);
61+
else
62+
m_textures[id] = info;
63+
// m_textures.insert(mk_pair(id,info)); // original GSC insert call
64+
/* avo: end */
65+
}
66+
67+
xml.SetLocalRoot(root_node);
68+
}
69+
}
70+
else
71+
{
72+
// ТЧ формат
73+
shared_str file = xml.Read("file_name", 0, "");
74+
75+
int num = xml.GetNodesNum("", 0, "texture");
76+
for (int i = 0; i < num; i++)
77+
{
78+
TEX_INFO info;
79+
80+
info.file = file;
81+
82+
info.rect.x1 = xml.ReadAttribFlt("texture", i, "x");
83+
info.rect.x2 = xml.ReadAttribFlt("texture", i, "width") + info.rect.x1;
84+
info.rect.y1 = xml.ReadAttribFlt("texture", i, "y");
85+
info.rect.y2 = xml.ReadAttribFlt("texture", i, "height") + info.rect.y1;
86+
87+
shared_str id = xml.ReadAttrib("texture", i, "id");
88+
89+
/* avo: fix issue when values were not updated (silently skipped) when same key is encountered more than once. This is how std::map is designed.
90+
/* Also used more efficient C++11 std::map::emplace method instead of outdated std::pair::make_pair */
91+
/* XXX: avo: note that xxx.insert(mk_pair(v1,v2)) pattern is used extensively throughout solution so there is a good potential for other bug fixes/improvements */
92+
if (m_textures.find(id) == m_textures.end())
93+
m_textures.emplace(id, info);
94+
else
95+
m_textures[id] = info;
96+
// m_textures.insert(mk_pair(id,info)); // original GSC insert call
97+
/* avo: end */
98+
}
5099
}
51-
// m_shTex.insert(mk_pair(texture, regs));
52-
// }
53100
}
54101

55102
void CUITextureMaster::InitTexture(const char* texture_name, IUISimpleTextureControl* tc)

0 commit comments

Comments
 (0)