Skip to content

Commit

Permalink
Code cleanup and refactoring. Use range-based for. Save fix for edito…
Browse files Browse the repository at this point in the history
…r_environment_effects_effect.cpp.
  • Loading branch information
intorr committed Jan 5, 2018
1 parent f1379ec commit f135e31
Show file tree
Hide file tree
Showing 45 changed files with 339 additions and 452 deletions.
69 changes: 28 additions & 41 deletions src/xrEngine/editor_environment_ambients_ambient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using editor::environment::effects::effect;

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

template <>
void property_collection<ambient::sound_container_type, ambient>::display_name(
u32 const& item_index, LPSTR const& buffer, u32 const& buffer_size)
u32 const& item_index, pstr const& buffer, u32 const& buffer_size)
{
xr_strcpy(buffer, buffer_size, m_container[item_index]->id().c_str());
}
Expand Down Expand Up @@ -85,7 +85,7 @@ void ambient::load(

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

{
VERIFY(m_sound_channels_ids.empty());
LPCSTR sounds_string = READ_IF_EXISTS(&ambients_config, r_string, m_load_section, "sound_channels", "");
pcstr sounds_string = READ_IF_EXISTS(&ambients_config, r_string, m_load_section, "sound_channels", "");
for (u32 i = 0, n = _GetItemCount(sounds_string); i < n; ++i)
{
string_path temp;
Expand All @@ -111,25 +111,19 @@ void ambient::load(
void ambient::save(CInifile& config)
{
u32 count = 1;
LPSTR temp = 0;
pstr temp = 0;
{
sound_container_type::const_iterator b = m_sound_channels_ids.begin(), i = b;
sound_container_type::const_iterator e = m_sound_channels_ids.end();
for (; i != e; ++i)
count += (*i)->id().size() + 2;

temp = (LPSTR)_alloca(count * sizeof(char));
*temp = 0;
for (i = b; i != e; ++i)
for (const auto &i : m_sound_channels_ids)
count += i->id().size() + 2;

temp = (pstr)_alloca(count * sizeof(char));
*temp = '\0';
for (const auto &i : m_sound_channels_ids)
{
if (i == b)
{
xr_strcpy(temp, count, (*i)->id().c_str());
continue;
}

xr_strcat(temp, count, ", ");
xr_strcat(temp, count, (*i)->id().c_str());
xr_strcat(temp, count, i->id().c_str());

if (&i != &m_sound_channels_ids.back())
xr_strcat(temp, count, ", ");
}
}

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

{
count = 1;
effect_container_type::const_iterator b = m_effects_ids.begin(), i = b;
effect_container_type::const_iterator e = m_effects_ids.end();
for (; i != e; ++i)
count += (*i)->id().size() + 2;

temp = (LPSTR)_alloca(count * sizeof(char));
*temp = 0;
for (i = b; i != e; ++i)
for (const auto &i : m_effects_ids)
count += i->id().size() + 2;

temp = (pstr)_alloca(count * sizeof(char));
*temp = '\0';
for (const auto &i : m_effects_ids)
{
if (i == b)
{
xr_strcpy(temp, count, (*i)->id().c_str());
continue;
}

xr_strcat(temp, count, ", ");
xr_strcat(temp, count, (*i)->id().c_str());
xr_strcat(temp, count, i->id().c_str());
if (&i != &m_effects_ids.back())
xr_strcat(temp, count, ", ");
}
}
config.w_string(m_load_section.c_str(), "effects", temp);
}

LPCSTR ambient::id_getter() const { return (m_load_section.c_str()); }
void ambient::id_setter(LPCSTR value_)
pcstr ambient::id_getter() const { return (m_load_section.c_str()); }
void ambient::id_setter(pcstr value_)
{
shared_str value = value_;
if (m_load_section._get() == value._get())
Expand Down Expand Up @@ -211,15 +198,15 @@ ::editor::environment::sound_channels::manager const& ambient::sounds_manager()
return (m_manager.sounds_manager());
}

ambient::SEffect* ambient::create_effect(CInifile& config, LPCSTR id)
ambient::SEffect* ambient::create_effect(CInifile& config, pcstr id)
{
effect* result = new effect(m_manager.effects_manager(), id);
result->load(config);
result->fill(m_effects_collection);
return (result);
}

ambient::SSndChannel* ambient::create_sound_channel(CInifile& config, LPCSTR id)
ambient::SSndChannel* ambient::create_sound_channel(CInifile& config, pcstr id)
{
channel* result = new channel(m_manager.sounds_manager(), id);
result->load(config);
Expand Down
8 changes: 4 additions & 4 deletions src/xrEngine/editor_environment_ambients_ambient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class ambient : public CEnvAmbient, public XRay::Editor::property_holder_holder,
void save(CInifile& config);
void fill(XRay::Editor::property_holder_collection* collection);
inline shared_str const& id() const { return m_load_section; }
virtual SEffect* create_effect(CInifile& config, LPCSTR id);
virtual SSndChannel* create_sound_channel(CInifile& config, LPCSTR id);
virtual SEffect* create_effect(CInifile& config, pcstr id);
virtual SSndChannel* create_sound_channel(CInifile& config, pcstr id);
virtual EffectVec& effects();
virtual SSndChannelVec& get_snd_channels();

private:
LPCSTR xr_stdcall id_getter() const;
void xr_stdcall id_setter(LPCSTR value);
pcstr xr_stdcall id_getter() const;
void xr_stdcall id_setter(pcstr value);

public:
effects::manager const& effects_manager() const;
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/editor_environment_ambients_effect_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ effect_id::~effect_id()
::ide().destroy(m_property_holder);
}

LPCSTR const* effect_id::collection() { return (&*m_manager.effects_ids().begin()); }
pcstr const* effect_id::collection() { return (&*m_manager.effects_ids().begin()); }
u32 effect_id::collection_size() { return (m_manager.effects_ids().size()); }
void effect_id::fill(XRay::Editor::property_holder_collection* collection)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/editor_environment_ambients_effect_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class effect_id : public XRay::Editor::property_holder_holder, private Noncopyab
virtual property_holder_type* object();

private:
LPCSTR const* xr_stdcall collection();
pcstr const* xr_stdcall collection();
u32 xr_stdcall collection_size();

private:
Expand Down
36 changes: 13 additions & 23 deletions src/xrEngine/editor_environment_ambients_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using editor::environment::detail::logical_string_predicate;

template <>
void property_collection<manager::ambient_container_type, manager>::display_name(
u32 const& item_index, LPSTR const& buffer, u32 const& buffer_size)
u32 const& item_index, pstr const& buffer, u32 const& buffer_size)
{
xr_strcpy(buffer, buffer_size, m_container[item_index]->id().c_str());
}
Expand Down Expand Up @@ -60,13 +60,10 @@ void manager::load()
typedef CInifile::Root sections_type;
sections_type& sections = m_manager.m_ambients_config->sections();
m_ambients.reserve(sections.size());
sections_type::const_iterator i = sections.begin();
sections_type::const_iterator e = sections.end();
for (; i != e; ++i)
for (const auto &i : sections)
{
ambient* object = new ambient(*this, (*i)->Name);
object->load(
*m_manager.m_ambients_config, *m_manager.m_sound_channels_config, *m_manager.m_effects_config, (*i)->Name);
ambient* object = new ambient(*this, i->Name);
object->load(*m_manager.m_ambients_config, *m_manager.m_sound_channels_config, *m_manager.m_effects_config, i->Name);
object->fill(m_collection);
m_ambients.push_back(object);
}
Expand All @@ -75,13 +72,10 @@ void manager::load()
void manager::save()
{
string_path file_name;
CInifile* config =
new CInifile(FS.update_path(file_name, "$game_config$", "environment\\ambients.ltx"), FALSE, FALSE, TRUE);
CInifile* config = new CInifile(FS.update_path(file_name, "$game_config$", "environment\\ambients.ltx"), false, false, true);

ambient_container_type::iterator i = m_ambients.begin();
ambient_container_type::iterator e = m_ambients.end();
for (; i != e; ++i)
(*i)->save(*config);
for (const auto &i : m_ambients)
i->save(*config);

xr_delete(config);
}
Expand Down Expand Up @@ -117,11 +111,9 @@ manager::ambients_ids_type const& manager::ambients_ids() const

m_ambients_ids.resize(m_ambients.size());

ambient_container_type::const_iterator i = m_ambients.begin();
ambient_container_type::const_iterator e = m_ambients.end();
ambients_ids_type::iterator j = m_ambients_ids.begin();
for (; i != e; ++i, ++j)
*j = xr_strdup((*i)->id().c_str());
auto j = m_ambients_ids.begin();
for (const auto &i : m_ambients)
*j++ = xr_strdup(i->id().c_str());

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

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

ambient* manager::get_ambient(shared_str const& id) const
{
ambient_container_type::const_iterator i = m_ambients.begin();
ambient_container_type::const_iterator e = m_ambients.end();
for (; i != e; ++i)
if ((*i)->id() == id)
return (*i);
for (const auto &i : m_ambients)
if (i->id() == id)
return i;

NODEFAULT;
#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/editor_environment_ambients_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class manager : private Noncopyable

public:
typedef xr_vector<ambient*> ambient_container_type;
typedef xr_vector<LPSTR> ambients_ids_type;
typedef xr_vector<pstr> ambients_ids_type;

public:
ambients_ids_type const& ambients_ids() const;
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/editor_environment_ambients_sound_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sound_id::~sound_id()
::ide().destroy(m_property_holder);
}

LPCSTR const* sound_id::collection() { return (&*m_manager.channels_ids().begin()); }
pcstr const* sound_id::collection() { return (&*m_manager.channels_ids().begin()); }
u32 sound_id::collection_size() { return (m_manager.channels_ids().size()); }
void sound_id::fill(XRay::Editor::property_holder_collection* collection)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/editor_environment_ambients_sound_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class sound_id : public XRay::Editor::property_holder_holder, private Noncopyabl
virtual property_holder_type* object();

private:
LPCSTR const* xr_stdcall collection();
pcstr const* xr_stdcall collection();
u32 xr_stdcall collection_size();

private:
Expand Down
6 changes: 3 additions & 3 deletions src/xrEngine/editor_environment_detail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using editor::environment::detail::logical_string_predicate;

static HRESULT AnsiToUnicode(LPCSTR pszA, LPVOID buffer, u32 const& buffer_size)
static HRESULT AnsiToUnicode(pcstr pszA, LPVOID buffer, u32 const& buffer_size)
{
VERIFY(pszA);
VERIFY(buffer);
Expand All @@ -31,7 +31,7 @@ static HRESULT AnsiToUnicode(LPCSTR pszA, LPVOID buffer, u32 const& buffer_size)
return (HRESULT_FROM_WIN32(GetLastError()));
}

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

shared_str editor::environment::detail::real_path(LPCSTR folder, LPCSTR path)
shared_str editor::environment::detail::real_path(pcstr folder, pcstr path)
{
string_path result;
FS.update_path(result, folder, path);
Expand Down
4 changes: 2 additions & 2 deletions src/xrEngine/editor_environment_detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace detail
{
struct logical_string_predicate
{
bool operator()(LPCSTR const& first, LPCSTR const& second) const;
bool operator()(pcstr const& first, pcstr const& second) const;
bool operator()(shared_str const& first, shared_str const& second) const;
}; // struct logical_string_predicate

shared_str real_path(LPCSTR folder, LPCSTR path);
shared_str real_path(pcstr folder, pcstr path);

} // namespace detail
} // namespace environment
Expand Down
12 changes: 8 additions & 4 deletions src/xrEngine/editor_environment_effects_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void effect::load(CInifile& config)
particles = config.r_string(m_id, "particles");
m_sound = config.r_string(m_id, "sound");
wind_gust_factor = config.r_float(m_id, "wind_gust_factor");
wind_blast_in_time = config.r_float(m_id, "wind_blast_in_time");
wind_blast_out_time = config.r_float(m_id, "wind_blast_out_time");
wind_blast_strength = config.r_float(m_id, "wind_blast_strength");
wind_blast_direction.setHP(deg2rad(config.r_float(m_id, "wind_blast_longitude")), 0.f);
}

void effect::save(CInifile& config)
Expand All @@ -56,8 +60,8 @@ void effect::save(CInifile& config)
config.w_float(m_id.c_str(), "wind_blast_longitude", rad2deg(wind_blast_direction.getH()));
}

LPCSTR effect::id_getter() const { return (m_id.c_str()); }
void effect::id_setter(LPCSTR value_)
pcstr effect::id_getter() const { return (m_id.c_str()); }
void effect::id_setter(pcstr value_)
{
shared_str value = value_;
if (m_id._get() == value._get())
Expand All @@ -66,8 +70,8 @@ void effect::id_setter(LPCSTR value_)
m_id = m_manager.unique_id(value);
}

LPCSTR effect::sound_getter() { return (m_sound.c_str()); }
void effect::sound_setter(LPCSTR value)
pcstr effect::sound_getter() { return (m_sound.c_str()); }
void effect::sound_setter(pcstr value)
{
m_sound = value;
sound.destroy();
Expand Down
10 changes: 5 additions & 5 deletions src/xrEngine/editor_environment_effects_effect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class effect : public CEnvAmbient::SEffect, public XRay::Editor::property_holder
void load(CInifile& config);
void save(CInifile& config);
void fill(XRay::Editor::property_holder_collection* collection);
inline LPCSTR id() const { return m_id.c_str(); }
inline pcstr id() const { return m_id.c_str(); }
private:
LPCSTR xr_stdcall id_getter() const;
void xr_stdcall id_setter(LPCSTR value);
pcstr xr_stdcall id_getter() const;
void xr_stdcall id_setter(pcstr value);

float xr_stdcall wind_blast_longitude_getter() const;
void xr_stdcall wind_blast_longitude_setter(float value);

LPCSTR xr_stdcall sound_getter();
void xr_stdcall sound_setter(LPCSTR value);
pcstr xr_stdcall sound_getter();
void xr_stdcall sound_setter(pcstr value);

private:
typedef XRay::Editor::property_holder_base property_holder_type;
Expand Down
Loading

0 comments on commit f135e31

Please sign in to comment.