rain_manager.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "game/map/map_definition.h"
  3. #include <cstdint>
  4. #include <functional>
  5. namespace Game::Systems {
  6. enum class RainState { Clear, FadingIn, Active, FadingOut };
  7. class RainManager {
  8. public:
  9. RainManager();
  10. ~RainManager() = default;
  11. void configure(const Game::Map::RainSettings &settings,
  12. std::uint32_t map_seed);
  13. void reset();
  14. void update(float delta_time);
  15. [[nodiscard]] auto is_enabled() const -> bool { return m_settings.enabled; }
  16. [[nodiscard]] auto get_state() const -> RainState { return m_state; }
  17. [[nodiscard]] auto get_intensity() const -> float {
  18. return m_current_intensity;
  19. }
  20. [[nodiscard]] auto get_cycle_time() const -> float { return m_cycle_time; }
  21. [[nodiscard]] auto get_cycle_duration() const -> float {
  22. return m_settings.cycle_duration;
  23. }
  24. [[nodiscard]] auto is_raining() const -> bool {
  25. return m_state == RainState::Active || m_state == RainState::FadingIn ||
  26. m_state == RainState::FadingOut;
  27. }
  28. [[nodiscard]] auto get_weather_type() const -> Game::Map::WeatherType {
  29. return m_settings.type;
  30. }
  31. [[nodiscard]] auto get_wind_strength() const -> float {
  32. return m_settings.wind_strength;
  33. }
  34. using StateChangeCallback = std::function<void(RainState new_state)>;
  35. void set_state_change_callback(StateChangeCallback callback) {
  36. m_state_callback = std::move(callback);
  37. }
  38. private:
  39. void transition_to(RainState new_state);
  40. void update_intensity(float delta_time);
  41. Game::Map::RainSettings m_settings;
  42. std::uint32_t m_seed = 0;
  43. RainState m_state = RainState::Clear;
  44. float m_cycle_time = 0.0F;
  45. float m_state_time = 0.0F;
  46. float m_current_intensity = 0.0F;
  47. StateChangeCallback m_state_callback;
  48. };
  49. } // namespace Game::Systems