💿🐜 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.

77 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 "ecs/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 "astro/coordinates.hpp"
  28. #include "astro/orbit.hpp"
  29. #include <cmath>
  30. namespace ecs {
  31. static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
  32. weather_system::weather_system(ecs::registry& registry):
  33. entity_system(registry),
  34. sky_pass(nullptr),
  35. shadow_map_pass(nullptr),
  36. material_pass(nullptr),
  37. universal_time(0.0),
  38. days_per_timestep(1.0 / seconds_per_day)
  39. {}
  40. void weather_system::update(double t, double dt)
  41. {
  42. // Add scaled timestep to current time
  43. set_universal_time(universal_time + dt * days_per_timestep);
  44. }
  45. void weather_system::set_sky_pass(::sky_pass* pass)
  46. {
  47. sky_pass = pass;
  48. }
  49. void weather_system::set_shadow_map_pass(::shadow_map_pass* pass)
  50. {
  51. shadow_map_pass = pass;
  52. }
  53. void weather_system::set_material_pass(::material_pass* pass)
  54. {
  55. material_pass = pass;
  56. material_pass->set_shadow_strength(0.5f);
  57. }
  58. void weather_system::set_universal_time(double time)
  59. {
  60. universal_time = time;
  61. }
  62. void weather_system::set_time_scale(double scale)
  63. {
  64. days_per_timestep = scale / seconds_per_day;
  65. }
  66. } // namespace ecs