Skip to content

Commit f135e31

Browse files
committed
Code cleanup and refactoring. Use range-based for. Save fix for editor_environment_effects_effect.cpp.
1 parent f1379ec commit f135e31

File tree

45 files changed

+339
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+339
-452
lines changed

src/xrEngine/editor_environment_ambients_ambient.cpp

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using editor::environment::effects::effect;
2727

2828
template <>
2929
void property_collection<ambient::effect_container_type, ambient>::display_name(
30-
u32 const& item_index, LPSTR const& buffer, u32 const& buffer_size)
30+
u32 const& item_index, pstr const& buffer, u32 const& buffer_size)
3131
{
3232
xr_strcpy(buffer, buffer_size, m_container[item_index]->id().c_str());
3333
}
@@ -42,7 +42,7 @@ XRay::Editor::property_holder_base* property_collection<ambient::effect_containe
4242

4343
template <>
4444
void property_collection<ambient::sound_container_type, ambient>::display_name(
45-
u32 const& item_index, LPSTR const& buffer, u32 const& buffer_size)
45+
u32 const& item_index, pstr const& buffer, u32 const& buffer_size)
4646
{
4747
xr_strcpy(buffer, buffer_size, m_container[item_index]->id().c_str());
4848
}
@@ -85,7 +85,7 @@ void ambient::load(
8585

8686
{
8787
VERIFY(m_effects_ids.empty());
88-
LPCSTR effects_string = READ_IF_EXISTS(&ambients_config, r_string, m_load_section, "effects", "");
88+
pcstr effects_string = READ_IF_EXISTS(&ambients_config, r_string, m_load_section, "effects", "");
8989
for (u32 i = 0, n = _GetItemCount(effects_string); i < n; ++i)
9090
{
9191
string_path temp;
@@ -97,7 +97,7 @@ void ambient::load(
9797

9898
{
9999
VERIFY(m_sound_channels_ids.empty());
100-
LPCSTR sounds_string = READ_IF_EXISTS(&ambients_config, r_string, m_load_section, "sound_channels", "");
100+
pcstr sounds_string = READ_IF_EXISTS(&ambients_config, r_string, m_load_section, "sound_channels", "");
101101
for (u32 i = 0, n = _GetItemCount(sounds_string); i < n; ++i)
102102
{
103103
string_path temp;
@@ -111,25 +111,19 @@ void ambient::load(
111111
void ambient::save(CInifile& config)
112112
{
113113
u32 count = 1;
114-
LPSTR temp = 0;
114+
pstr temp = 0;
115115
{
116-
sound_container_type::const_iterator b = m_sound_channels_ids.begin(), i = b;
117-
sound_container_type::const_iterator e = m_sound_channels_ids.end();
118-
for (; i != e; ++i)
119-
count += (*i)->id().size() + 2;
120-
121-
temp = (LPSTR)_alloca(count * sizeof(char));
122-
*temp = 0;
123-
for (i = b; i != e; ++i)
116+
for (const auto &i : m_sound_channels_ids)
117+
count += i->id().size() + 2;
118+
119+
temp = (pstr)_alloca(count * sizeof(char));
120+
*temp = '\0';
121+
for (const auto &i : m_sound_channels_ids)
124122
{
125-
if (i == b)
126-
{
127-
xr_strcpy(temp, count, (*i)->id().c_str());
128-
continue;
129-
}
130-
131-
xr_strcat(temp, count, ", ");
132-
xr_strcat(temp, count, (*i)->id().c_str());
123+
xr_strcat(temp, count, i->id().c_str());
124+
125+
if (&i != &m_sound_channels_ids.back())
126+
xr_strcat(temp, count, ", ");
133127
}
134128
}
135129

@@ -139,30 +133,23 @@ void ambient::save(CInifile& config)
139133

140134
{
141135
count = 1;
142-
effect_container_type::const_iterator b = m_effects_ids.begin(), i = b;
143-
effect_container_type::const_iterator e = m_effects_ids.end();
144-
for (; i != e; ++i)
145-
count += (*i)->id().size() + 2;
146-
147-
temp = (LPSTR)_alloca(count * sizeof(char));
148-
*temp = 0;
149-
for (i = b; i != e; ++i)
136+
for (const auto &i : m_effects_ids)
137+
count += i->id().size() + 2;
138+
139+
temp = (pstr)_alloca(count * sizeof(char));
140+
*temp = '\0';
141+
for (const auto &i : m_effects_ids)
150142
{
151-
if (i == b)
152-
{
153-
xr_strcpy(temp, count, (*i)->id().c_str());
154-
continue;
155-
}
156-
157-
xr_strcat(temp, count, ", ");
158-
xr_strcat(temp, count, (*i)->id().c_str());
143+
xr_strcat(temp, count, i->id().c_str());
144+
if (&i != &m_effects_ids.back())
145+
xr_strcat(temp, count, ", ");
159146
}
160147
}
161148
config.w_string(m_load_section.c_str(), "effects", temp);
162149
}
163150

164-
LPCSTR ambient::id_getter() const { return (m_load_section.c_str()); }
165-
void ambient::id_setter(LPCSTR value_)
151+
pcstr ambient::id_getter() const { return (m_load_section.c_str()); }
152+
void ambient::id_setter(pcstr value_)
166153
{
167154
shared_str value = value_;
168155
if (m_load_section._get() == value._get())
@@ -211,15 +198,15 @@ ::editor::environment::sound_channels::manager const& ambient::sounds_manager()
211198
return (m_manager.sounds_manager());
212199
}
213200

214-
ambient::SEffect* ambient::create_effect(CInifile& config, LPCSTR id)
201+
ambient::SEffect* ambient::create_effect(CInifile& config, pcstr id)
215202
{
216203
effect* result = new effect(m_manager.effects_manager(), id);
217204
result->load(config);
218205
result->fill(m_effects_collection);
219206
return (result);
220207
}
221208

222-
ambient::SSndChannel* ambient::create_sound_channel(CInifile& config, LPCSTR id)
209+
ambient::SSndChannel* ambient::create_sound_channel(CInifile& config, pcstr id)
223210
{
224211
channel* result = new channel(m_manager.sounds_manager(), id);
225212
result->load(config);

src/xrEngine/editor_environment_ambients_ambient.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class ambient : public CEnvAmbient, public XRay::Editor::property_holder_holder,
4949
void save(CInifile& config);
5050
void fill(XRay::Editor::property_holder_collection* collection);
5151
inline shared_str const& id() const { return m_load_section; }
52-
virtual SEffect* create_effect(CInifile& config, LPCSTR id);
53-
virtual SSndChannel* create_sound_channel(CInifile& config, LPCSTR id);
52+
virtual SEffect* create_effect(CInifile& config, pcstr id);
53+
virtual SSndChannel* create_sound_channel(CInifile& config, pcstr id);
5454
virtual EffectVec& effects();
5555
virtual SSndChannelVec& get_snd_channels();
5656

5757
private:
58-
LPCSTR xr_stdcall id_getter() const;
59-
void xr_stdcall id_setter(LPCSTR value);
58+
pcstr xr_stdcall id_getter() const;
59+
void xr_stdcall id_setter(pcstr value);
6060

6161
public:
6262
effects::manager const& effects_manager() const;

src/xrEngine/editor_environment_ambients_effect_id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ effect_id::~effect_id()
2929
::ide().destroy(m_property_holder);
3030
}
3131

32-
LPCSTR const* effect_id::collection() { return (&*m_manager.effects_ids().begin()); }
32+
pcstr const* effect_id::collection() { return (&*m_manager.effects_ids().begin()); }
3333
u32 effect_id::collection_size() { return (m_manager.effects_ids().size()); }
3434
void effect_id::fill(XRay::Editor::property_holder_collection* collection)
3535
{

src/xrEngine/editor_environment_ambients_effect_id.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class effect_id : public XRay::Editor::property_holder_holder, private Noncopyab
3939
virtual property_holder_type* object();
4040

4141
private:
42-
LPCSTR const* xr_stdcall collection();
42+
pcstr const* xr_stdcall collection();
4343
u32 xr_stdcall collection_size();
4444

4545
private:

src/xrEngine/editor_environment_ambients_manager.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using editor::environment::detail::logical_string_predicate;
2222

2323
template <>
2424
void property_collection<manager::ambient_container_type, manager>::display_name(
25-
u32 const& item_index, LPSTR const& buffer, u32 const& buffer_size)
25+
u32 const& item_index, pstr const& buffer, u32 const& buffer_size)
2626
{
2727
xr_strcpy(buffer, buffer_size, m_container[item_index]->id().c_str());
2828
}
@@ -60,13 +60,10 @@ void manager::load()
6060
typedef CInifile::Root sections_type;
6161
sections_type& sections = m_manager.m_ambients_config->sections();
6262
m_ambients.reserve(sections.size());
63-
sections_type::const_iterator i = sections.begin();
64-
sections_type::const_iterator e = sections.end();
65-
for (; i != e; ++i)
63+
for (const auto &i : sections)
6664
{
67-
ambient* object = new ambient(*this, (*i)->Name);
68-
object->load(
69-
*m_manager.m_ambients_config, *m_manager.m_sound_channels_config, *m_manager.m_effects_config, (*i)->Name);
65+
ambient* object = new ambient(*this, i->Name);
66+
object->load(*m_manager.m_ambients_config, *m_manager.m_sound_channels_config, *m_manager.m_effects_config, i->Name);
7067
object->fill(m_collection);
7168
m_ambients.push_back(object);
7269
}
@@ -75,13 +72,10 @@ void manager::load()
7572
void manager::save()
7673
{
7774
string_path file_name;
78-
CInifile* config =
79-
new CInifile(FS.update_path(file_name, "$game_config$", "environment\\ambients.ltx"), FALSE, FALSE, TRUE);
75+
CInifile* config = new CInifile(FS.update_path(file_name, "$game_config$", "environment\\ambients.ltx"), false, false, true);
8076

81-
ambient_container_type::iterator i = m_ambients.begin();
82-
ambient_container_type::iterator e = m_ambients.end();
83-
for (; i != e; ++i)
84-
(*i)->save(*config);
77+
for (const auto &i : m_ambients)
78+
i->save(*config);
8579

8680
xr_delete(config);
8781
}
@@ -117,11 +111,9 @@ manager::ambients_ids_type const& manager::ambients_ids() const
117111

118112
m_ambients_ids.resize(m_ambients.size());
119113

120-
ambient_container_type::const_iterator i = m_ambients.begin();
121-
ambient_container_type::const_iterator e = m_ambients.end();
122-
ambients_ids_type::iterator j = m_ambients_ids.begin();
123-
for (; i != e; ++i, ++j)
124-
*j = xr_strdup((*i)->id().c_str());
114+
auto j = m_ambients_ids.begin();
115+
for (const auto &i : m_ambients)
116+
*j++ = xr_strdup(i->id().c_str());
125117

126118
std::sort(m_ambients_ids.begin(), m_ambients_ids.end(), logical_string_predicate());
127119

@@ -130,11 +122,9 @@ manager::ambients_ids_type const& manager::ambients_ids() const
130122

131123
ambient* manager::get_ambient(shared_str const& id) const
132124
{
133-
ambient_container_type::const_iterator i = m_ambients.begin();
134-
ambient_container_type::const_iterator e = m_ambients.end();
135-
for (; i != e; ++i)
136-
if ((*i)->id() == id)
137-
return (*i);
125+
for (const auto &i : m_ambients)
126+
if (i->id() == id)
127+
return i;
138128

139129
NODEFAULT;
140130
#ifdef DEBUG

src/xrEngine/editor_environment_ambients_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class manager : private Noncopyable
5959

6060
public:
6161
typedef xr_vector<ambient*> ambient_container_type;
62-
typedef xr_vector<LPSTR> ambients_ids_type;
62+
typedef xr_vector<pstr> ambients_ids_type;
6363

6464
public:
6565
ambients_ids_type const& ambients_ids() const;

src/xrEngine/editor_environment_ambients_sound_id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ sound_id::~sound_id()
2525
::ide().destroy(m_property_holder);
2626
}
2727

28-
LPCSTR const* sound_id::collection() { return (&*m_manager.channels_ids().begin()); }
28+
pcstr const* sound_id::collection() { return (&*m_manager.channels_ids().begin()); }
2929
u32 sound_id::collection_size() { return (m_manager.channels_ids().size()); }
3030
void sound_id::fill(XRay::Editor::property_holder_collection* collection)
3131
{

src/xrEngine/editor_environment_ambients_sound_id.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class sound_id : public XRay::Editor::property_holder_holder, private Noncopyabl
3939
virtual property_holder_type* object();
4040

4141
private:
42-
LPCSTR const* xr_stdcall collection();
42+
pcstr const* xr_stdcall collection();
4343
u32 xr_stdcall collection_size();
4444

4545
private:

src/xrEngine/editor_environment_detail.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
using editor::environment::detail::logical_string_predicate;
1818

19-
static HRESULT AnsiToUnicode(LPCSTR pszA, LPVOID buffer, u32 const& buffer_size)
19+
static HRESULT AnsiToUnicode(pcstr pszA, LPVOID buffer, u32 const& buffer_size)
2020
{
2121
VERIFY(pszA);
2222
VERIFY(buffer);
@@ -31,7 +31,7 @@ static HRESULT AnsiToUnicode(LPCSTR pszA, LPVOID buffer, u32 const& buffer_size)
3131
return (HRESULT_FROM_WIN32(GetLastError()));
3232
}
3333

34-
bool logical_string_predicate::operator()(LPCSTR const& first, LPCSTR const& second) const
34+
bool logical_string_predicate::operator()(pcstr const& first, pcstr const& second) const
3535
{
3636
u32 buffer_size0 = (xr_strlen(first) + 1) * 2;
3737
LPCWSTR buffer0 = (LPCWSTR)_alloca(buffer_size0);
@@ -57,7 +57,7 @@ bool logical_string_predicate::operator()(shared_str const& first, shared_str co
5757
return (StrCmpLogicalW(buffer0, buffer1) < 0);
5858
}
5959

60-
shared_str editor::environment::detail::real_path(LPCSTR folder, LPCSTR path)
60+
shared_str editor::environment::detail::real_path(pcstr folder, pcstr path)
6161
{
6262
string_path result;
6363
FS.update_path(result, folder, path);

src/xrEngine/editor_environment_detail.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ namespace detail
1919
{
2020
struct logical_string_predicate
2121
{
22-
bool operator()(LPCSTR const& first, LPCSTR const& second) const;
22+
bool operator()(pcstr const& first, pcstr const& second) const;
2323
bool operator()(shared_str const& first, shared_str const& second) const;
2424
}; // struct logical_string_predicate
2525

26-
shared_str real_path(LPCSTR folder, LPCSTR path);
26+
shared_str real_path(pcstr folder, pcstr path);
2727

2828
} // namespace detail
2929
} // namespace environment

0 commit comments

Comments
 (0)