From c0a9e8638432b6c7e04c5c1bb4764ae9cbe6b92c Mon Sep 17 00:00:00 2001 From: The Bearodactyl Date: Thu, 4 Jul 2024 14:26:13 -0500 Subject: [PATCH] move chaos code to trail_customization --- src/main.cpp | 61 ----------------------- src/trail_customization/chaos_trail.cpp | 64 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 61 deletions(-) create mode 100644 src/trail_customization/chaos_trail.cpp diff --git a/src/main.cpp b/src/main.cpp index 97bd615..85c9be4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include "Geode/loader/ModEvent.hpp" #include "Geode/modify/Modify.hpp" @@ -153,66 +152,6 @@ struct MyPlayLayer : Modify { } }; -struct MyHardStreak : Modify { - void addPoint(CCPoint p0) { - float max_wave_pulse_size = Mod::get()->getSettingValue("max-wave-pulse-size"); - float min_wave_pulse_size = Mod::get()->getSettingValue("min-wave-pulse-size"); - float max_wave_trail_size = Mod::get()->getSettingValue("max-wave-trail-size"); - float min_wave_trail_size = Mod::get()->getSettingValue("min-wave-trail-size"); - float min_y_pos_offset = Mod::get()->getSettingValue("min-y-pos-offset"); - float max_y_pos_offset = Mod::get()->getSettingValue("max-y-pos-offset"); - float min_x_pos_offset = Mod::get()->getSettingValue("min-x-pos-offset"); - float max_x_pos_offset = Mod::get()->getSettingValue("max-x-pos-offset"); - float skip_chance = Mod::get()->getSettingValue("skip-chance"); - - bool chaos = Mod::get()->getSettingValue("chaos"); - - if (chaos) { - std::mt19937 rng(std::time(nullptr)); - std::uniform_real_distribution dist_pulse(min_wave_pulse_size, max_wave_pulse_size); - std::uniform_real_distribution dist_trail(min_wave_trail_size, max_wave_trail_size); - - auto random_float_pulse = [&]() { return dist_pulse(rng); }; - auto random_float_trail = [&]() { return dist_trail(rng); }; - - std::vector> operations = { - [&]() { p0.x += random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.x -= random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.x *= random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.x /= random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.y += random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.y -= random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.y *= random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { p0.y /= random_float(min_x_pos_offset, max_y_pos_offset); }, - [&]() { m_waveSize += random_float_trail(); }, - [&]() { m_waveSize -= random_float_trail(); }, - [&]() { m_waveSize *= random_float_trail(); }, - [&]() { m_waveSize /= random_float_trail(); }, - [&]() { m_pulseSize += random_float_trail(); }, - [&]() { m_pulseSize -= random_float_trail(); }, - [&]() { m_pulseSize *= random_float_trail(); }, - [&]() { m_pulseSize /= random_float_trail(); }}; - - std::bernoulli_distribution enable_op(skip_chance); - - for (auto &op: operations) { - if (enable_op(rng)) { - op(); - } - } - } - - HardStreak::addPoint(p0); - } - - float random_float(float min = -25.f, float max = 25.f) { - static std::random_device rd; - static std::mt19937 gen(rd()); - std::uniform_real_distribution dis(min, max); - return dis(gen); - } -}; - $on_mod(Loaded) { Mod::get()->addCustomSetting("gaydient-section", "none"); Mod::get()->addCustomSetting("chaos-section", "none"); diff --git a/src/trail_customization/chaos_trail.cpp b/src/trail_customization/chaos_trail.cpp new file mode 100644 index 0000000..52e5e8f --- /dev/null +++ b/src/trail_customization/chaos_trail.cpp @@ -0,0 +1,64 @@ +#include +#include + +using namespace geode::prelude; + +struct MyHardStreak : Modify { + void addPoint(CCPoint p0) { + float max_wave_pulse_size = Mod::get()->getSettingValue("max-wave-pulse-size"); + float min_wave_pulse_size = Mod::get()->getSettingValue("min-wave-pulse-size"); + float max_wave_trail_size = Mod::get()->getSettingValue("max-wave-trail-size"); + float min_wave_trail_size = Mod::get()->getSettingValue("min-wave-trail-size"); + float min_y_pos_offset = Mod::get()->getSettingValue("min-y-pos-offset"); + float max_y_pos_offset = Mod::get()->getSettingValue("max-y-pos-offset"); + float min_x_pos_offset = Mod::get()->getSettingValue("min-x-pos-offset"); + float max_x_pos_offset = Mod::get()->getSettingValue("max-x-pos-offset"); + float skip_chance = Mod::get()->getSettingValue("skip-chance"); + + bool chaos = Mod::get()->getSettingValue("chaos"); + + if (chaos) { + std::mt19937 rng(std::time(nullptr)); + std::uniform_real_distribution dist_pulse(min_wave_pulse_size, max_wave_pulse_size); + std::uniform_real_distribution dist_trail(min_wave_trail_size, max_wave_trail_size); + + auto random_float_pulse = [&]() { return dist_pulse(rng); }; + auto random_float_trail = [&]() { return dist_trail(rng); }; + + std::vector> operations = { + [&]() { p0.x += random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.x -= random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.x *= random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.x /= random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.y += random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.y -= random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.y *= random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { p0.y /= random_float(min_x_pos_offset, max_y_pos_offset); }, + [&]() { m_waveSize += random_float_trail(); }, + [&]() { m_waveSize -= random_float_trail(); }, + [&]() { m_waveSize *= random_float_trail(); }, + [&]() { m_waveSize /= random_float_trail(); }, + [&]() { m_pulseSize += random_float_trail(); }, + [&]() { m_pulseSize -= random_float_trail(); }, + [&]() { m_pulseSize *= random_float_trail(); }, + [&]() { m_pulseSize /= random_float_trail(); }}; + + std::bernoulli_distribution enable_op(skip_chance); + + for (auto &op: operations) { + if (enable_op(rng)) { + op(); + } + } + } + + HardStreak::addPoint(p0); + } + + float random_float(float min = -25.f, float max = 25.f) { + static std::random_device rd; + static std::mt19937 gen(rd()); + std::uniform_real_distribution dis(min, max); + return dis(gen); + } +};