diff --git a/src/electricity_effect.cc b/src/electricity_effect.cc index aee5014..aae4247 100644 --- a/src/electricity_effect.cc +++ b/src/electricity_effect.cc @@ -1,5 +1,8 @@ #include "electricity_effect.h" +// standard library includes +#include + // third party includes #include #include @@ -18,54 +21,28 @@ ElectricityEffect::ElectricityEffect(Vector3 center, float radius, cylinders.reserve(line_count); // Generate cylinders. - int sub_count = 0; - Vector3 dir, pos; - for (; line_count > 0; --line_count) { - if (sub_count == 0) { - dir.x = call_js_get_random() * 2.0F - 1.0F; - dir.y = call_js_get_random() * 2.0F - 1.0F; - dir.z = call_js_get_random() * 2.0F - 1.0F; + std::queue positions; + Vector3 next, dir; + for (unsigned int idx = 0; idx < CYLINDER_SPLIT_COUNT; ++idx) { + positions.push(center); + } + while (line_count-- > 0 && !positions.empty()) { + next = positions.front(); + positions.pop(); - dir = Vector3Normalize(dir); + dir = Vector3Normalize(Vector3{call_js_get_random() * 2.0F - 1.0F, + call_js_get_random() * 2.0F - 1.0F, + call_js_get_random() * 2.0F - 1.0F}); - pos = center + dir * (radius * 0.7F); + auto coll = GetRayCollisionSphere(Ray{.position = next, .direction = dir}, + center, radius); - dir.x = call_js_get_random() * 2.0F - 1.0F; - dir.y = call_js_get_random() * 2.0F - 1.0F; - dir.z = call_js_get_random() * 2.0F - 1.0F; + cylinders.push_back(Cylinder{.start = next, .end = coll.point}); - dir = Vector3Normalize(dir); - - auto coll = GetRayCollisionSphere( - Ray{.position = center, .direction = dir}, center, radius); - - cylinders.push_back(Cylinder{.start = pos, .end = coll.point}); - - pos = coll.point; - } else { - dir = Vector3Normalize(center - pos); - - pos = pos + dir * (radius * CYLINDER_EDGE_OFFSET); - - for (unsigned int idx = 0; idx < CYLINDER_SPLIT_COUNT; ++idx) { - dir.x = call_js_get_random() * 2.0F - 1.0F; - dir.y = call_js_get_random() * 2.0F - 1.0F; - dir.z = call_js_get_random() * 2.0F - 1.0F; - - dir = Vector3Normalize(dir); - - auto coll = GetRayCollisionSphere( - Ray{.position = pos, .direction = dir}, center, radius); - - cylinders.push_back(Cylinder{.start = pos, .end = coll.point}); - - if (idx == CYLINDER_SPLIT_COUNT - 1) { - pos = coll.point; - } - } - } - if (++sub_count >= CYLINDER_SUB_COUNT_MAX) { - sub_count = 0; + dir = Vector3Normalize(center - coll.point); + coll.point = coll.point + dir * (radius * CYLINDER_EDGE_OFFSET); + for (unsigned int idx = 0; idx < CYLINDER_SPLIT_COUNT; ++idx) { + positions.push(coll.point); } } } diff --git a/src/electricity_effect.h b/src/electricity_effect.h index ca5e8c7..1ffcf76 100644 --- a/src/electricity_effect.h +++ b/src/electricity_effect.h @@ -7,7 +7,6 @@ // third party includes #include -constexpr int CYLINDER_SUB_COUNT_MAX = 3; constexpr int CYLINDER_SPLIT_COUNT = 3; constexpr int CYLINDER_SIDES = 3; constexpr float CYLINDER_MAX_RADIUS = 0.03F; diff --git a/src/screen_trunner.cc b/src/screen_trunner.cc index 967e7d8..1b9e472 100644 --- a/src/screen_trunner.cc +++ b/src/screen_trunner.cc @@ -101,8 +101,8 @@ bool TRunnerScreen::update(float dt, bool is_resized) { if (walker_hack_success && controlled_walker_idx.has_value()) { walkers[controlled_walker_idx.value()].set_player_controlled(true); electricityEffects.push_back(ElectricityEffect( - walkers[controlled_walker_idx.value()].get_body_pos(), 1.7F, 15, - 1.0F)); + walkers[controlled_walker_idx.value()].get_body_pos(), 1.7F, + ELECTRICITY_EFFECT_LINE_COUNT, 1.0F)); } else { controlled_walker_idx.reset(); diff --git a/src/screen_trunner.h b/src/screen_trunner.h index 7a47347..c1cbdce 100644 --- a/src/screen_trunner.h +++ b/src/screen_trunner.h @@ -29,6 +29,8 @@ constexpr float SURFACE_RESET_TIME = 4.0F; constexpr float SURFACE_RESET_TIME_TRI_DRAW = 3.0F; constexpr float SURFACE_RESET_Y_OFFSET = 40.0F; +constexpr int ELECTRICITY_EFFECT_LINE_COUNT = 50; + class TRunnerScreen : public Screen { public: struct SurfaceUnit {