#include "electricity_effect.h"
+// standard library includes
+#include <queue>
+
// third party includes
#include <raylib.h>
#include <raymath.h>
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;
-
- dir = Vector3Normalize(dir);
-
- pos = center + dir * (radius * 0.7F);
-
- 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 = 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;
+ std::queue<Vector3> 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});
- auto coll = GetRayCollisionSphere(
- Ray{.position = pos, .direction = dir}, center, radius);
+ auto coll = GetRayCollisionSphere(Ray{.position = next, .direction = dir},
+ center, radius);
- cylinders.push_back(Cylinder{.start = pos, .end = coll.point});
+ cylinders.push_back(Cylinder{.start = next, .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);
}
}
}
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();