💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1 KiB

  1. /*
  2. * Copyright (C) 2021 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "game/systems/weather-system.hpp"
  20. #include "scene/directional-light.hpp"
  21. #include "scene/ambient-light.hpp"
  22. #include "renderer/passes/sky-pass.hpp"
  23. #include "renderer/passes/shadow-map-pass.hpp"
  24. #include "renderer/passes/material-pass.hpp"
  25. #include "utility/gamma.hpp"
  26. #include "resources/image.hpp"
  27. #include "game/astronomy/celestial-coordinates.hpp"
  28. #include "game/astronomy/celestial-mechanics.hpp"
  29. #include <cmath>
  30. static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
  31. weather_system::weather_system(entt::registry& registry):
  32. entity_system(registry),
  33. sky_pass(nullptr),
  34. shadow_map_pass(nullptr),
  35. material_pass(nullptr),
  36. universal_time(0.0),
  37. days_per_timestep(1.0 / seconds_per_day)
  38. {}
  39. void weather_system::update(double t, double dt)
  40. {
  41. // Add scaled timestep to current time
  42. set_universal_time(universal_time + dt * days_per_timestep);
  43. }
  44. void weather_system::set_sky_pass(::sky_pass* pass)
  45. {
  46. sky_pass = pass;
  47. }
  48. void weather_system::set_shadow_map_pass(::shadow_map_pass* pass)
  49. {
  50. shadow_map_pass = pass;
  51. }
  52. void weather_system::set_material_pass(::material_pass* pass)
  53. {
  54. material_pass = pass;
  55. material_pass->set_shadow_strength(0.5f);
  56. }
  57. void weather_system::set_universal_time(double time)
  58. {
  59. universal_time = time;
  60. }
  61. void weather_system::set_time_scale(double scale)
  62. {
  63. days_per_timestep = scale / seconds_per_day;
  64. }