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

87 lines
2.7 KiB

  1. /*
  2. * Copyright (C) 2020 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 "application-states.hpp"
  20. #include "application.hpp"
  21. #include "scene/billboard.hpp"
  22. #include "renderer/material.hpp"
  23. #include "renderer/material-property.hpp"
  24. #include "animation/animation.hpp"
  25. #include "animation/animator.hpp"
  26. #include "animation/ease.hpp"
  27. #include "animation/screen-transition.hpp"
  28. #include "renderer/passes/sky-pass.hpp"
  29. #include <functional>
  30. #include <iostream>
  31. void enter_splash_state(application* app)
  32. {
  33. logger* logger = app->get_logger();
  34. logger->push_task("Entering splash state");
  35. // Disable sky pass
  36. app->get_sky_pass()->set_enabled(false);
  37. // Add splash billboard to UI scene
  38. app->get_ui_scene()->add_object(app->get_splash_billboard());
  39. // Setup timing
  40. const float splash_fade_in_duration = 0.5f;
  41. const float splash_hang_duration = 2.0f;
  42. const float splash_fade_out_duration = 0.5f;
  43. // Start fade in
  44. app->get_fade_transition()->transition(splash_fade_in_duration, true, ease<float>::in_quad);
  45. // Crate fade out function
  46. auto fade_out = [app, splash_fade_out_duration]()
  47. {
  48. app->get_fade_transition()->transition(splash_fade_out_duration, false, ease<float>::out_quad);
  49. };
  50. // Create change state function
  51. auto change_state = [app]()
  52. {
  53. app->get_state_machine()->change_state(app->get_play_state());
  54. };
  55. // Schedule fade out and change state events
  56. timeline* timeline = app->get_timeline();
  57. float t = timeline->get_position();
  58. timeline::sequence splash_sequence =
  59. {
  60. {t + splash_fade_in_duration + splash_hang_duration, fade_out},
  61. {t + splash_fade_in_duration + splash_hang_duration + splash_fade_out_duration, change_state}
  62. };
  63. timeline->add_sequence(splash_sequence);
  64. logger->pop_task(EXIT_SUCCESS);
  65. }
  66. void exit_splash_state(application* app)
  67. {
  68. logger* logger = app->get_logger();
  69. logger->push_task("Exiting splash state");
  70. // Remove splash billboard from UI scene
  71. app->get_ui_scene()->remove_object(app->get_splash_billboard());
  72. logger->pop_task(EXIT_SUCCESS);
  73. }