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

94 lines
3.2 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/states/nuptial-flight.hpp"
  20. #include "entity/archetype.hpp"
  21. #include "entity/systems/astronomy.hpp"
  22. #include "entity/systems/orbit.hpp"
  23. #include "entity/systems/camera.hpp"
  24. #include "entity/components/observer.hpp"
  25. #include "entity/components/transform.hpp"
  26. #include "entity/components/terrain.hpp"
  27. #include "entity/commands.hpp"
  28. #include "animation/screen-transition.hpp"
  29. #include "animation/ease.hpp"
  30. #include "resources/resource-manager.hpp"
  31. namespace game {
  32. namespace state {
  33. namespace nuptial_flight {
  34. void enter(game::context* ctx)
  35. {
  36. // Switch to surface camera
  37. ctx->underground_camera->set_active(false);
  38. ctx->surface_camera->set_active(true);
  39. // Find planet EID by name
  40. entity::id planet_eid = ctx->entities["planet"];
  41. // Remove terrain component from planet (if any)
  42. if (ctx->entity_registry->has<entity::component::terrain>(planet_eid))
  43. ctx->entity_registry->remove<entity::component::terrain>(planet_eid);
  44. // Enable clouds in sky pass
  45. ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load<render::model>("cloud-plane.mdl"));
  46. // Create observer
  47. entity::id observer_eid = ctx->entity_registry->create();
  48. {
  49. entity::component::observer observer;
  50. observer.reference_body_eid = planet_eid;
  51. observer.elevation = 2000.0;
  52. observer.latitude = 0.0;
  53. observer.longitude = 0.0;
  54. observer.camera = ctx->surface_camera;
  55. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  56. // Set reference location of astronomy system
  57. ctx->astronomy_system->set_reference_body(planet_eid);
  58. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  59. }
  60. // Setup camera
  61. ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  62. ctx->surface_camera->set_exposure(-14.5f);
  63. ctx->surface_scene->update_tweens();
  64. // Pause motion of celestial objects
  65. ctx->astronomy_system->set_time_scale(0.0);
  66. ctx->orbit_system->set_time_scale(0.0);
  67. // Start fade in from white
  68. ctx->fade_transition_color->set_value({1, 1, 1});
  69. ctx->fade_transition->transition(5.0f, true, math::lerp<float, float>);
  70. }
  71. void exit(game::context* ctx)
  72. {
  73. // Resume motion of celestial objects
  74. const double time_scale = (*ctx->config)["time_scale"].get<double>();
  75. ctx->astronomy_system->set_time_scale(time_scale);
  76. ctx->orbit_system->set_time_scale(time_scale);
  77. }
  78. } // namespace nuptial_flight
  79. } // namespace state
  80. } // namespace game