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

129 lines
4.8 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/control.hpp"
  24. #include "entity/systems/camera.hpp"
  25. #include "entity/components/observer.hpp"
  26. #include "entity/components/camera-follow.hpp"
  27. #include "entity/components/transform.hpp"
  28. #include "entity/components/terrain.hpp"
  29. #include "entity/commands.hpp"
  30. #include "renderer/material-property.hpp"
  31. #include "animation/screen-transition.hpp"
  32. #include "animation/ease.hpp"
  33. #include "resources/config-file.hpp"
  34. #include "resources/resource-manager.hpp"
  35. namespace game {
  36. namespace state {
  37. namespace nuptial_flight {
  38. void enter(game::context* ctx)
  39. {
  40. // Switch to surface camera
  41. ctx->underground_camera->set_active(false);
  42. ctx->surface_camera->set_active(true);
  43. // Find planet EID by name
  44. auto planet_eid = entity::command::find(*ctx->entity_registry, "planet");
  45. // Remove terrain component from planet (if any)
  46. if (ctx->entity_registry->has<entity::component::terrain>(planet_eid))
  47. ctx->entity_registry->remove<entity::component::terrain>(planet_eid);
  48. // Enable clouds in sky pass
  49. ctx->surface_sky_pass->set_clouds_model(ctx->resource_manager->load<model>("cloud-plane.mdl"));
  50. // Create observer
  51. auto observer_eid = ctx->entity_registry->create();
  52. {
  53. entity::component::observer observer;
  54. observer.reference_body_eid = planet_eid;
  55. observer.elevation = 2000.0;
  56. observer.latitude = 0.0;
  57. observer.longitude = 0.0;
  58. observer.camera = ctx->surface_camera;
  59. ctx->entity_registry->assign<entity::component::observer>(observer_eid, observer);
  60. // Set reference location of astronomy system
  61. ctx->astronomy_system->set_reference_body(planet_eid);
  62. ctx->astronomy_system->set_observer_location(double3{observer.elevation, observer.latitude, observer.longitude});
  63. }
  64. // Create wing
  65. entity::archetype* ant_forewing_archetype = ctx->resource_manager->load<entity::archetype>("ant-forewing.ent");
  66. auto forewing_eid = ctx->entity_registry->create();
  67. //ant_forewing_archetype->assign(*ctx->entity_registry, forewing_eid);
  68. // Create eye
  69. entity::archetype* ant_round_eye_archetype = ctx->resource_manager->load<entity::archetype>("ant-round-eye.ent");
  70. auto ant_round_eye_eid = ctx->entity_registry->create();
  71. ant_round_eye_archetype->assign(*ctx->entity_registry, ant_round_eye_eid);
  72. entity::command::assign_render_layers(*ctx->entity_registry, ant_round_eye_eid, 0b10);
  73. // Create green orb ring
  74. entity::archetype* orb_ring_archetype = ctx->resource_manager->load<entity::archetype>("orb-ring.ent");
  75. auto orb_ring_eid = ctx->entity_registry->create();
  76. //orb_ring_archetype->assign(*ctx->entity_registry, orb_ring_eid);
  77. // Create camera focal point
  78. {
  79. entity::component::transform focal_point_transform;
  80. focal_point_transform.local = math::identity_transform<float>;
  81. focal_point_transform.warp = true;
  82. ctx->entity_registry->assign_or_replace<entity::component::transform>(ctx->focal_point_entity, focal_point_transform);
  83. entity::component::camera_follow focal_point_follow;
  84. ctx->entity_registry->assign_or_replace<entity::component::camera_follow>(ctx->focal_point_entity, focal_point_follow);
  85. }
  86. // Setup camera
  87. ctx->surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
  88. ctx->surface_camera->set_exposure(-14.5f);
  89. ctx->camera_system->set_camera(ctx->surface_camera);
  90. entity::system::control* control_system = ctx->control_system;
  91. control_system->update(0.0, 0.0);
  92. ctx->surface_scene->update_tweens();
  93. // Pause motion of celestial objects
  94. ctx->astronomy_system->set_time_scale(0.0);
  95. ctx->orbit_system->set_time_scale(0.0);
  96. // Start fade in from white
  97. ctx->fade_transition_color->set_value({1, 1, 1});
  98. ctx->fade_transition->transition(2.0f, true, ease<float>::in_quad);
  99. }
  100. void exit(game::context* ctx)
  101. {
  102. // Resume motion of celestial objects
  103. const double time_scale = ctx->config->get<double>("time_scale");
  104. ctx->astronomy_system->set_time_scale(time_scale);
  105. ctx->orbit_system->set_time_scale(time_scale);
  106. }
  107. } // namespace nuptial_flight
  108. } // namespace state
  109. } // namespace game