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

85 lines
2.6 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 "animation/ease.hpp"
  20. #include "animation/screen-transition.hpp"
  21. #include "animation/timeline.hpp"
  22. #include "application.hpp"
  23. #include "debug/logger.hpp"
  24. #include "game/game-context.hpp"
  25. #include "game/states/game-states.hpp"
  26. #include "renderer/passes/sky-pass.hpp"
  27. #include "scene/billboard.hpp"
  28. #include "scene/scene.hpp"
  29. #include <functional>
  30. void splash_state_enter(game_context* ctx)
  31. {
  32. logger* logger = ctx->logger;
  33. logger->push_task("Entering splash state");
  34. // Disable sky pass
  35. ctx->overworld_sky_pass->set_enabled(false);
  36. // Add splash billboard to UI scene
  37. ctx->ui_scene->add_object(ctx->splash_billboard);
  38. // Setup timing
  39. const float splash_fade_in_duration = 0.5f;
  40. const float splash_hang_duration = 2.0f;
  41. const float splash_fade_out_duration = 0.5f;
  42. // Start fade in
  43. ctx->fade_transition->transition(splash_fade_in_duration, true, ease<float>::in_quad);
  44. // Crate fade out function
  45. auto fade_out = [ctx, splash_fade_out_duration]()
  46. {
  47. ctx->fade_transition->transition(splash_fade_out_duration, false, ease<float>::out_quad);
  48. };
  49. // Create change state function
  50. auto change_state = [ctx]()
  51. {
  52. ctx->app->change_state({std::bind(play_state_enter, ctx), std::bind(play_state_exit, ctx)});
  53. };
  54. // Schedule fade out and change state events
  55. timeline* timeline = ctx->timeline;
  56. float t = timeline->get_position();
  57. timeline::sequence splash_sequence =
  58. {
  59. {t + splash_fade_in_duration + splash_hang_duration, fade_out},
  60. {t + splash_fade_in_duration + splash_hang_duration + splash_fade_out_duration, change_state}
  61. };
  62. timeline->add_sequence(splash_sequence);
  63. logger->pop_task(EXIT_SUCCESS);
  64. }
  65. void splash_state_exit(game_context* ctx)
  66. {
  67. logger* logger = ctx->logger;
  68. logger->push_task("Exiting splash state");
  69. // Remove splash billboard from UI scene
  70. ctx->ui_scene->remove_object(ctx->splash_billboard);
  71. logger->pop_task(EXIT_SUCCESS);
  72. }