Skip to content

Commit

Permalink
Убрал проверки if, else-if, заменил на маппинг
Browse files Browse the repository at this point in the history
  • Loading branch information
OldSerpskiStalker committed Dec 9, 2024
1 parent 85bab4b commit 19651d7
Showing 1 changed file with 82 additions and 59 deletions.
141 changes: 82 additions & 59 deletions src/xrEngine/Rain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CEffect_Rain::~CEffect_Rain()
// Born
void CEffect_Rain::Born(Item& dest, float radius, shared_str rainType)
{
Fvector axis{};
Fvector axis= {};
axis.set(0.f, -1.f, 0.f);

auto computeDirection = [&](float variation)
Expand All @@ -54,72 +54,95 @@ void CEffect_Rain::Born(Item& dest, float radius, shared_str rainType)

Fvector& view = Device.vCameraPosition;

if (rainType == "default")
{
float angle = ::Random.randF(0.f, PI_MUL_2);
float dist = _sqrt(::Random.randF()) * radius;
float x = dist * _cos(angle);
float z = dist * _sin(angle);

computeDirection(10.f);
using rainHandler = std::function<void()>;

dest.P.set(x + view.x - dest.D.x * g_pGamePersistent->Environment().source_offset,
g_pGamePersistent->Environment().source_offset + view.y,
z + view.z - dest.D.z * g_pGamePersistent->Environment().source_offset);

dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max);
}
else if (rainType == "drizzle")
std::unordered_map<xr_string, rainHandler> rainBehaviors =
{
float angle = ::Random.randF(0.f, PI_MUL_2);
float dist = _sqrt(::Random.randF()) * radius;
float x = dist * _cos(angle);
float z = dist * _sin(angle);

computeDirection(10.f);

dest.P.set(x + view.x - dest.D.x * g_pGamePersistent->Environment().source_offset,
g_pGamePersistent->Environment().source_offset + view.y,
z + view.z - dest.D.z * g_pGamePersistent->Environment().source_offset);
{
"default", [&]()
{
float angle = ::Random.randF(0.f, PI_MUL_2);
float dist = _sqrt(::Random.randF()) * radius;
float x = dist * _cos(angle);
float z = dist * _sin(angle);

computeDirection(10.f);

dest.P.set(x + view.x - dest.D.x * g_pGamePersistent->Environment().source_offset,
g_pGamePersistent->Environment().source_offset + view.y,
z + view.z - dest.D.z * g_pGamePersistent->Environment().source_offset);

dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max);
}
},
{
"drizzle", [&]()
{
float angle = ::Random.randF(0.f, PI_MUL_2);
float dist = _sqrt(::Random.randF()) * radius;
float x = dist * _cos(angle);
float z = dist * _sin(angle);

computeDirection(10.f);

dest.P.set(x + view.x - dest.D.x * g_pGamePersistent->Environment().source_offset,
g_pGamePersistent->Environment().source_offset + view.y,
z + view.z - dest.D.z * g_pGamePersistent->Environment().source_offset);

dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min * 0.5f,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max * 0.7f);
}
},
{
"dense", [&]()
{
float angle = ::Random.randF(0.f, PI_MUL_2);
float dist = _sqrt(::Random.randF()) * (radius * 0.5f);
float x = dist * _cos(angle);
float z = dist * _sin(angle);

computeDirection(5.f);

dest.P.set(x + view.x - dest.D.x * g_pGamePersistent->Environment().source_offset,
g_pGamePersistent->Environment().source_offset + view.y,
z + view.z - dest.D.z * g_pGamePersistent->Environment().source_offset);

dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max);
}
},
{
"spherical", [&]()
{
float theta = ::Random.randF(0.f, PI_MUL_2);
float phi = ::Random.randF(0.f, PI_DIV_2);
float r = ::Random.randF() * radius;

float x = r * sinf(phi) * cosf(theta);
float y = r * cosf(phi);
float z = r * sinf(phi) * sinf(theta);

computeDirection(15.f);

dest.P.set(x + view.x, y + view.y, z + view.z);
dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max);
}
}
};

dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min * 0.5f,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max * 0.7f);
}
else if (rainType == "dense")
if (rainBehaviors.count(rainType.c_str()))
{
float angle = ::Random.randF(0.f, PI_MUL_2);
float dist = _sqrt(::Random.randF()) * (radius * 0.5f);
float x = dist * _cos(angle);
float z = dist * _sin(angle);

computeDirection(5.f);

dest.P.set(x + view.x - dest.D.x * g_pGamePersistent->Environment().source_offset,
g_pGamePersistent->Environment().source_offset + view.y,
z + view.z - dest.D.z * g_pGamePersistent->Environment().source_offset);

dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max);
rainBehaviors[rainType.c_str()]();
}
else if (rainType == "spherical")
else
{
float theta = ::Random.randF(0.f, PI_MUL_2);
float phi = ::Random.randF(0.f, PI_DIV_2);
float r = ::Random.randF() * radius;

float x = r * sinf(phi) * cosf(theta);
float y = r * cosf(phi);
float z = r * sinf(phi) * sinf(theta);

computeDirection(15.f);

dest.P.set(x + view.x, y + view.y, z + view.z);
dest.fSpeed = ::Random.randF(g_pGamePersistent->Environment().CurrentEnv->rain_speed_min,
g_pGamePersistent->Environment().CurrentEnv->rain_speed_max);
rainBehaviors["default"]();
}

float height = g_pGamePersistent->Environment().max_distance + g_pGamePersistent->Environment().add_const_dist_coefficient;
float height =
g_pGamePersistent->Environment().max_distance + g_pGamePersistent->Environment().add_const_dist_coefficient;

RenewItem(dest, height, RayPick(dest.P, dest.D, height, collide::rqtBoth));
}
Expand Down

0 comments on commit 19651d7

Please sign in to comment.