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

109 lines
3.9 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/systems/astronomy.hpp"
  21. #include "entity/systems/orbit.hpp"
  22. #include "entity/systems/control.hpp"
  23. #include "entity/systems/camera.hpp"
  24. #include "entity/components/observer.hpp"
  25. #include "entity/components/camera-follow.hpp"
  26. #include "entity/components/transform.hpp"
  27. #include "entity/components/terrain.hpp"
  28. #include "renderer/material-property.hpp"
  29. #include "animation/screen-transition.hpp"
  30. #include "animation/ease.hpp"
  31. #include "resources/config-file.hpp"
  32. #include "resources/resource-manager.hpp"
  33. namespace game {
  34. namespace state {
  35. namespace nuptial_flight {
  36. void enter(game::context* ctx)
  37. {
  38. // Find planet EID by name
  39. entity::id planet_eid = entt::null;
  40. if (auto it = ctx->named_entities.find("planet"); it != ctx->named_entities.end())
  41. {
  42. planet_eid = it->second;
  43. }
  44. // Replace planet terrain material with cloud material
  45. entity::component::terrain planet_terrain = ctx->entity_registry->get<entity::component::terrain>(planet_eid);
  46. planet_terrain.patch_material = ctx->resource_manager->load<material>("cloud.mtl");
  47. ctx->entity_registry->replace<entity::component::terrain>(planet_eid, planet_terrain);
  48. // Create observer
  49. auto observer_eid = ctx->entity_registry->create();
  50. {
  51. entity::component::observer observer;
  52. observer.reference_body_eid = planet_eid;
  53. observer.elevation = 2000.0;
  54. observer.latitude = 0.0;
  55. observer.longitude = 0.0;
  56. observer.camera = ctx->overworld_camera;
  57. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  58. // Set reference location of astronomy system
  59. ctx->astronomy_system->set_reference_body(planet_eid);
  60. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  61. }
  62. // Create camera focal point
  63. {
  64. entity::component::transform focal_point_transform;
  65. focal_point_transform.local = math::identity_transform<float>;
  66. focal_point_transform.warp = true;
  67. ctx->entity_registry->assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
  68. entity::component::camera_follow focal_point_follow;
  69. ctx->entity_registry->assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
  70. }
  71. // Setup camera
  72. ctx->overworld_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  73. ctx->overworld_camera->set_exposure(-14.5f);
  74. ctx->camera_system->set_camera(ctx->overworld_camera);
  75. entity::system::control* control_system = ctx->control_system;
  76. control_system->update(0.0, 0.0);
  77. ctx->overworld_scene->update_tweens();
  78. // Pause motion of celestial objects
  79. ctx->astronomy_system->set_time_scale(0.0);
  80. ctx->orbit_system->set_time_scale(0.0);
  81. // Start fade in from white
  82. ctx->fade_transition_color->set_value({1, 1, 1});
  83. ctx->fade_transition->transition(2.0f, true, ease<float>::in_quad);
  84. }
  85. void exit(game::context* ctx)
  86. {
  87. // Resume motion of celestial objects
  88. const double time_scale = ctx->config->get<double>("time_scale");
  89. ctx->astronomy_system->set_time_scale(time_scale);
  90. ctx->orbit_system->set_time_scale(time_scale);
  91. }
  92. } // namespace nuptial_flight
  93. } // namespace state
  94. } // namespace game