Skip to content

Commit

Permalink
Add change weather type from environment
Browse files Browse the repository at this point in the history
Можно переключать ТЧ\ЗП погоду скриптом.
```lua
local fs = getFS()
fs:append_path('$game_weathers$', fs:update_path('$game_config$', 'environment\\weathers'), '', 1)
fs:append_path('$game_weather_effects$', fs:update_path('$game_config$', 'environment\\weather_effects'), '', 1)
level.environment():reinit()
```
  • Loading branch information
Graff46 committed Jun 5, 2023
1 parent 3dd1201 commit 5f993f9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
11 changes: 10 additions & 1 deletion ogsr_engine/xrGame/level_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,14 @@ void run_xrdemo(LPCSTR xrdemoName)
g_pGameLevel->Cameras().AddCamEffector(xr_new<CDemoPlay>(fn, 1.0f, loops));
}

void reinit(CEnvironment* self)
{
self->init();

self->load_weathers();
self->load_weather_effects();
}

#pragma optimize("s", on)
void CLevel::script_register(lua_State* L)
{
Expand All @@ -881,7 +889,8 @@ void CLevel::script_register(lua_State* L)
class_<CEnvironment>("CEnvironment")
.def("current", current_environment)
.def("ForceReselectEnvs", &CEnvironment::ForceReselectEnvs)
.def("getCurrentWeather", &CEnvironment::getCurrentWeather),
.def("getCurrentWeather", &CEnvironment::getCurrentWeather)
.def("reinit", reinit),

class_<CPHCall>("CPHCall").def("set_pause", &CPHCall::setPause),

Expand Down
41 changes: 29 additions & 12 deletions ogsr_engine/xr_3da/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ const float MAX_DIST_FACTOR = 0.95f;
// environment
CEnvironment::CEnvironment()
{
USED_COP_WEATHER = FS.path_exist("$game_weathers$");

m_last_weather_shift = 0;
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;
Expand Down Expand Up @@ -84,6 +79,21 @@ CEnvironment::CEnvironment()
PerlinNoise1D->SetOctaves(2);
PerlinNoise1D->SetAmplitude(0.66666f);

init();
}

void CEnvironment::init(bool condCOPWeather)
{
clearIniFiles();

WeatherCycles.clear();
Current[0] = 0;
Current[1] = 0;
CurrentWeather = 0;
CurrentWeatherName = 0;

USED_COP_WEATHER = condCOPWeather && FS.path_exist("$game_weathers$");

if (USED_COP_WEATHER)
{
string_path file_name;
Expand Down Expand Up @@ -124,12 +134,8 @@ CEnvironment::CEnvironment()
}
}

CEnvironment::~CEnvironment()
void CEnvironment::clearIniFiles()
{
xr_delete(PerlinNoise1D);

OnDeviceDestroy();

if (m_ambients_config)
CInifile::Destroy(m_ambients_config);

Expand All @@ -147,6 +153,15 @@ CEnvironment::~CEnvironment()

if (m_thunderbolts_config)
CInifile::Destroy(m_thunderbolts_config);
}

CEnvironment::~CEnvironment()
{
xr_delete(PerlinNoise1D);

OnDeviceDestroy();

clearIniFiles();

destroy_mixer();
}
Expand Down Expand Up @@ -380,6 +395,7 @@ void CEnvironment::SelectEnvs(EnvVec* envs, CEnvDescriptor*& e0, CEnvDescriptor*
void CEnvironment::SelectEnvs(float gt)
{
VERIFY(CurrentWeather);

if ((Current[0] == Current[1]) && (Current[0] == 0))
{
VERIFY(!bWFX);
Expand Down Expand Up @@ -454,8 +470,9 @@ void CEnvironment::lerp(float& current_weight)

void CEnvironment::OnFrame()
{
if (!g_pGameLevel)
if ((!g_pGameLevel) || (!CurrentWeather))
return;

float current_weight;
lerp(current_weight);

Expand Down
8 changes: 6 additions & 2 deletions ogsr_engine/xr_3da/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class ENGINE_API CEnvironment
void SelectEnv(EnvVec* envs, CEnvDescriptor*& e, float tm);

void calculate_dynamic_sun_dir();
void clearIniFiles();

public:
static bool sort_env_pred(const CEnvDescriptor* x, const CEnvDescriptor* y) { return x->exec_time < y->exec_time; }
Expand Down Expand Up @@ -306,6 +307,8 @@ class ENGINE_API CEnvironment
public:
CEnvironment();

void init(bool condCOPWeather = true);

INGAME_EDITOR_VIRTUAL ~CEnvironment();

INGAME_EDITOR_VIRTUAL void load();
Expand Down Expand Up @@ -351,11 +354,12 @@ class ENGINE_API CEnvironment
CInifile* m_thunderbolts_config{};
bool m_dynamic_sun_movement{};

INGAME_EDITOR_VIRTUAL void load_weathers();
INGAME_EDITOR_VIRTUAL void load_weather_effects();

protected:
INGAME_EDITOR_VIRTUAL CEnvDescriptor* create_descriptor(shared_str const& identifier, CInifile* config);
INGAME_EDITOR_VIRTUAL CEnvDescriptor* create_descriptor_shoc(LPCSTR exec_tm, LPCSTR S);
INGAME_EDITOR_VIRTUAL void load_weathers();
INGAME_EDITOR_VIRTUAL void load_weather_effects();
INGAME_EDITOR_VIRTUAL void create_mixer();
void destroy_mixer();
void load_level_specific_ambients();
Expand Down
2 changes: 1 addition & 1 deletion ogsr_engine/xr_3da/Environment_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ void CEnvironment::load_weathers()
if (!WeatherCycles.empty())
return;

if (FS.path_exist("$game_weathers$"))
if (USED_COP_WEATHER)
{
auto file_list = FS.file_list_open("$game_weathers$", "");

Expand Down

0 comments on commit 5f993f9

Please sign in to comment.