Skip to content

Commit

Permalink
shared_str replacement (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-dex committed Dec 3, 2017
1 parent e494114 commit 2823fad
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 175 deletions.
13 changes: 4 additions & 9 deletions code/engine/editor/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
// Description : engine interface class
////////////////////////////////////////////////////////////////////////////

#ifndef EDITOR_ENGINE_HPP_INCLUDED
#define EDITOR_ENGINE_HPP_INCLUDED

class shared_str;
#pragma once

namespace editor {

Expand All @@ -24,9 +21,9 @@ class engine {
virtual void pause(bool const& value) = 0;
virtual void capture_input(bool const& value) = 0;
virtual void disconnect() = 0;
// shared_str support
virtual void value(LPCSTR value, shared_str& result) = 0;
virtual LPCSTR value(shared_str const& value) = 0;
// std::string support
virtual void value(const char* value, std::string& result) = 0;
virtual const char* value(std::string const& value) = 0;

// weather editor

Expand Down Expand Up @@ -72,5 +69,3 @@ class engine {
}; // class engine

} // namespace editor

#endif // ifndef EDITOR_ENGINE_HPP_INCLUDED
65 changes: 30 additions & 35 deletions code/engine/xrEngine/Environment.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "stdafx.h"
#pragma hdrstop

#ifndef _EDITOR
#include "render.h"
Expand Down Expand Up @@ -43,16 +42,15 @@ const float MAX_DIST_FACTOR = 0.95f;

//////////////////////////////////////////////////////////////////////////
// environment
CEnvironment::CEnvironment() : CurrentEnv(0), m_ambients_config(0) {
CEnvironment::CEnvironment() : CurrentEnv(nullptr), m_ambients_config(nullptr) {
bNeed_re_create_env = FALSE;
bWFX = false;
Current[0] = 0;
Current[1] = 0;
CurrentWeather = 0;
CurrentWeatherName = 0;
eff_Rain = 0;
eff_LensFlare = 0;
eff_Thunderbolt = 0;
Current[0] = nullptr;
Current[1] = nullptr;
CurrentWeather = nullptr;
eff_Rain = nullptr;
eff_LensFlare = nullptr;
eff_Thunderbolt = nullptr;
OnDeviceCreate();
#ifdef _EDITOR
ed_from_time = 0.f;
Expand Down Expand Up @@ -212,17 +210,17 @@ float CEnvironment::NormalizeTime(float tm) {
return tm;
}

void CEnvironment::SetWeather(shared_str name, bool forced) {
void CEnvironment::SetWeather(const std::string& name, bool forced) {
//. static BOOL bAlready = FALSE;
//. if(bAlready) return;
if (name.size()) {
//. bAlready = TRUE;
auto it = WeatherCycles.find(name);
if (it == WeatherCycles.end()) {
Msg("! Invalid weather name: %s", name.c_str());
LogMsg("! Invalid weather name: {}", name);
return;
}
R_ASSERT3(it != WeatherCycles.end(), "Invalid weather name.", *name);
R_ASSERT3(it != WeatherCycles.end(), "Invalid weather name.", name.c_str());
CurrentCycleName = it->first;
if (forced) {
Invalidate();
Expand All @@ -235,7 +233,7 @@ void CEnvironment::SetWeather(shared_str name, bool forced) {
SelectEnvs(fGameTime);
}
#ifdef WEATHER_LOGGING
Msg("Starting Cycle: %s [%s]", *name, forced ? "forced" : "deferred");
LogMsg("Starting Cycle: {0} [{1}]", name, forced ? "forced"sv : "deferred"sv);
#endif
} else {
#ifndef _EDITOR
Expand All @@ -244,12 +242,12 @@ void CEnvironment::SetWeather(shared_str name, bool forced) {
}
}

bool CEnvironment::SetWeatherFX(shared_str name) {
bool CEnvironment::SetWeatherFX(const std::string& name) {
if (bWFX)
return false;
if (name.size()) {
auto it = WeatherFXs.find(name);
R_ASSERT3(it != WeatherFXs.end(), "Invalid weather effect name.", *name);
R_ASSERT3(it != WeatherFXs.end(), "Invalid weather effect name.", name.c_str());
EnvVec* PrevWeather = CurrentWeather;
VERIFY(PrevWeather);
CurrentWeather = &it->second;
Expand Down Expand Up @@ -310,7 +308,7 @@ bool CEnvironment::SetWeatherFX(shared_str name) {
return true;
}

bool CEnvironment::StartWeatherFXFromTime(shared_str name, float time) {
bool CEnvironment::StartWeatherFXFromTime(const std::string& name, float time) {
if (!SetWeatherFX(name))
return false;

Expand All @@ -322,7 +320,7 @@ bool CEnvironment::StartWeatherFXFromTime(shared_str name, float time) {
}

void CEnvironment::StopWFX() {
VERIFY(CurrentCycleName.size());
VERIFY(!CurrentCycleName.empty());
bWFX = false;
SetWeather(CurrentCycleName, false);
Current[0] = WFX_end_desc[0];
Expand Down Expand Up @@ -465,10 +463,10 @@ void CEnvironment::OnFrame() {
wind_strength_factor =
clampr(PerlinNoise1D->GetContinious(Device.fTimeGlobal) + 0.5f, 0.f, 1.f);

shared_str l_id =
const auto& l_id =
(current_weight < 0.5f) ? Current[0]->lens_flare_id : Current[1]->lens_flare_id;
eff_LensFlare->OnFrame(l_id);
shared_str t_id = (current_weight < 0.5f) ? Current[0]->tb_id : Current[1]->tb_id;
const auto& t_id = (current_weight < 0.5f) ? Current[0]->tb_id : Current[1]->tb_id;
eff_Thunderbolt->OnFrame(t_id, CurrentEnv->bolt_period, CurrentEnv->bolt_duration);
eff_Rain->OnFrame();

Expand Down Expand Up @@ -563,38 +561,35 @@ SThunderboltCollection* CEnvironment::thunderbolt_collection(CInifile* pIni, CIn
LPCSTR section) {
SThunderboltCollection* result = xr_new<SThunderboltCollection>();
result->load(pIni, thunderbolts, section);
return (result);
return result;
}

SThunderboltCollection*
CEnvironment::thunderbolt_collection(xr_vector<SThunderboltCollection*>& collection,
shared_str const& id) {
typedef xr_vector<SThunderboltCollection*> Container;
Container::iterator i = collection.begin();
Container::iterator e = collection.end();
for (; i != e; ++i)
if ((*i)->section == id)
return (*i);
const std::string& id) {
for (auto* item : collection) {
if (item->section == id)
return item;
}

NODEFAULT;
#ifdef DEBUG
return (0);
return nullptr;
#endif // #ifdef DEBUG
}

CLensFlareDescriptor* CEnvironment::add_flare(xr_vector<CLensFlareDescriptor*>& collection,
shared_str const& id) {
const std::string& id) {
typedef xr_vector<CLensFlareDescriptor*> Flares;

Flares::const_iterator i = collection.begin();
Flares::const_iterator e = collection.end();
for (; i != e; ++i) {
if ((*i)->section == id)
return (*i);
for (auto* flare : collection) {
if (flare->section == id)
return flare;
}

CLensFlareDescriptor* result = xr_new<CLensFlareDescriptor>();
// TODO: [imdex] remove shared_str (ini)
result->load(m_suns_config, id.c_str());
collection.push_back(result);
return (result);
return result;
}
75 changes: 33 additions & 42 deletions code/engine/xrEngine/Environment.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef EnvironmentH
#define EnvironmentH
#pragma once

// refs
class ENGINE_API IRender_Visual;
Expand Down Expand Up @@ -53,7 +52,7 @@ class ENGINE_API CEnvAmbient {
struct SEffect {
u32 life_time;
ref_sound sound;
shared_str particles;
std::string particles;
Fvector offset;
float wind_gust_factor;
float wind_blast_in_time;
Expand All @@ -65,7 +64,7 @@ class ENGINE_API CEnvAmbient {
};
using EffectVec = xr_vector<SEffect*>;
struct SSndChannel {
shared_str m_load_section;
std::string m_load_section;
Fvector2 m_sound_dist;
Ivector4 m_sound_period;

Expand All @@ -87,50 +86,50 @@ class ENGINE_API CEnvAmbient {
return (m_sound_dist.x < m_sound_dist.y) ? Random.randF(m_sound_dist.x, m_sound_dist.y)
: 0;
}
INGAME_EDITOR_VIRTUAL ~SSndChannel() {}
inline INGAME_EDITOR_VIRTUAL sounds_type& sounds() { return m_sounds; }
INGAME_EDITOR_VIRTUAL ~SSndChannel() = default;
INGAME_EDITOR_VIRTUAL sounds_type& sounds() { return m_sounds; }

protected:
xr_vector<ref_sound> m_sounds;
};
using SSndChannelVec = xr_vector<SSndChannel*>;

protected:
shared_str m_load_section;
std::string m_load_section;

EffectVec m_effects;
Ivector2 m_effect_period;

SSndChannelVec m_sound_channels;
shared_str m_ambients_config_filename;
std::string m_ambients_config_filename;

public:
IC const shared_str& name() { return m_load_section; }
IC const shared_str& get_ambients_config_filename() { return m_ambients_config_filename; }
const std::string& name() const { return m_load_section; }
const std::string& get_ambients_config_filename() const { return m_ambients_config_filename; }

INGAME_EDITOR_VIRTUAL void load(CInifile& ambients_config, CInifile& sound_channels_config,
CInifile& effects_config, const shared_str& section);
IC SEffect* get_rnd_effect() {
CInifile& effects_config, std::string section);
SEffect* get_rnd_effect() {
return effects().empty() ? 0 : effects()[Random.randI(effects().size())];
}
IC u32 get_rnd_effect_time() { return Random.randI(m_effect_period.x, m_effect_period.y); }
u32 get_rnd_effect_time() { return Random.randI(m_effect_period.x, m_effect_period.y); }

INGAME_EDITOR_VIRTUAL SEffect* create_effect(CInifile& config, LPCSTR id);
INGAME_EDITOR_VIRTUAL SSndChannel* create_sound_channel(CInifile& config, LPCSTR id);
INGAME_EDITOR_VIRTUAL ~CEnvAmbient();
void destroy();
inline INGAME_EDITOR_VIRTUAL EffectVec& effects() { return m_effects; }
inline INGAME_EDITOR_VIRTUAL SSndChannelVec& get_snd_channels() { return m_sound_channels; }
INGAME_EDITOR_VIRTUAL EffectVec& effects() { return m_effects; }
INGAME_EDITOR_VIRTUAL SSndChannelVec& get_snd_channels() { return m_sound_channels; }
};

class ENGINE_API CEnvDescriptor {
public:
float exec_time;
float exec_time_loaded;

shared_str sky_texture_name;
shared_str sky_texture_env_name;
shared_str clouds_texture_name;
std::string sky_texture_name;
std::string sky_texture_env_name;
std::string clouds_texture_name;

BENCH_SEC_SCRAMBLEMEMBER1

Expand Down Expand Up @@ -169,12 +168,12 @@ class ENGINE_API CEnvDescriptor {

// int lens_flare_id;
// int tb_id;
shared_str lens_flare_id;
shared_str tb_id;
std::string lens_flare_id;
std::string tb_id;

CEnvAmbient* env_ambient;

CEnvDescriptor(shared_str const& identifier);
CEnvDescriptor(std::string identifier);

void load(CEnvironment& environment, CInifile& config);
void copy(const CEnvDescriptor& src) {
Expand All @@ -188,7 +187,7 @@ class ENGINE_API CEnvDescriptor {
void on_device_create();
void on_device_destroy();

shared_str m_identifier;
std::string m_identifier;
};

class ENGINE_API CEnvDescriptorMixer : public CEnvDescriptor {
Expand All @@ -205,7 +204,7 @@ class ENGINE_API CEnvDescriptorMixer : public CEnvDescriptor {
float fog_far;

public:
CEnvDescriptorMixer(shared_str const& identifier);
CEnvDescriptorMixer(std::string identifier);
INGAME_EDITOR_VIRTUAL void lerp(CEnvironment* parent, CEnvDescriptor& A, CEnvDescriptor& B,
float f, CEnvModifier& M, float m_power);
void clear();
Expand All @@ -214,16 +213,10 @@ class ENGINE_API CEnvDescriptorMixer : public CEnvDescriptor {

class ENGINE_API CEnvironment {
friend class dxEnvironmentRender;
struct str_pred {
IC bool operator()(const shared_str& x, const shared_str& y) const {
return xr_strcmp(x, y) < 0;
}
};

public:
using EnvAmbVec = xr_vector<CEnvAmbient*>;
using EnvVec = xr_vector<CEnvDescriptor*>;
using EnvsMap = xr_map<shared_str, EnvVec, str_pred>;
using EnvsMap = xr_map<std::string, EnvVec>;

private:
// clouds
Expand Down Expand Up @@ -277,8 +270,8 @@ class ENGINE_API CEnvironment {
CEnvDescriptor* WFX_end_desc[2];

EnvVec* CurrentWeather;
shared_str CurrentWeatherName;
shared_str CurrentCycleName;
std::string CurrentWeatherName;
std::string CurrentCycleName;

EnvsMap WeatherCycles;
EnvsMap WeatherFXs;
Expand All @@ -294,7 +287,7 @@ class ENGINE_API CEnvironment {
void SelectEnvs(float gt);

void UpdateAmbient();
INGAME_EDITOR_VIRTUAL CEnvAmbient* AppendEnvAmb(const shared_str& sect);
INGAME_EDITOR_VIRTUAL CEnvAmbient* AppendEnvAmb(std::string sect);

void Invalidate();

Expand All @@ -317,13 +310,13 @@ class ENGINE_API CEnvironment {
void RenderFlares();
void RenderLast();

bool SetWeatherFX(shared_str name);
bool StartWeatherFXFromTime(shared_str name, float time);
bool SetWeatherFX(const std::string& name);
bool StartWeatherFXFromTime(const std::string& name, float time);
bool IsWFXPlaying() { return bWFX; }
void StopWFX();

void SetWeather(shared_str name, bool forced = false);
shared_str GetWeather() { return CurrentWeatherName; }
void SetWeather(const std::string& name, bool forced = false);
const std::string& GetWeather() const { return CurrentWeatherName; }
void ChangeGameTime(float game_time);
void SetGameTime(float game_time, float time_factor);

Expand Down Expand Up @@ -355,7 +348,7 @@ class ENGINE_API CEnvironment {
CInifile* m_thunderbolts_config;

protected:
INGAME_EDITOR_VIRTUAL CEnvDescriptor* create_descriptor(shared_str const& identifier,
INGAME_EDITOR_VIRTUAL CEnvDescriptor* create_descriptor(std::string identifier,
CInifile* config);
INGAME_EDITOR_VIRTUAL void load_weathers();
INGAME_EDITOR_VIRTUAL void load_weather_effects();
Expand All @@ -370,9 +363,9 @@ class ENGINE_API CEnvironment {
INGAME_EDITOR_VIRTUAL SThunderboltCollection*
thunderbolt_collection(CInifile* pIni, CInifile* thunderbolts, LPCSTR section);
INGAME_EDITOR_VIRTUAL SThunderboltCollection*
thunderbolt_collection(xr_vector<SThunderboltCollection*>& collection, shared_str const& id);
thunderbolt_collection(xr_vector<SThunderboltCollection*>& collection, const std::string& id);
INGAME_EDITOR_VIRTUAL CLensFlareDescriptor*
add_flare(xr_vector<CLensFlareDescriptor*>& collection, shared_str const& id);
add_flare(xr_vector<CLensFlareDescriptor*>& collection, const std::string& id);

public:
float p_var_alt;
Expand All @@ -389,5 +382,3 @@ class ENGINE_API CEnvironment {

ENGINE_API extern Flags32 psEnvFlags;
ENGINE_API extern float psVisDistance;

#endif // EnvironmentH
Loading

0 comments on commit 2823fad

Please sign in to comment.