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

113 lines
3.5 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 "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 "input/input-listener.hpp"
  26. #include "event/input-events.hpp"
  27. #include "rasterizer/rasterizer.hpp"
  28. #include "game/states/game-states.hpp"
  29. #include "renderer/passes/sky-pass.hpp"
  30. #include "scene/billboard.hpp"
  31. #include "scene/scene.hpp"
  32. #include <functional>
  33. void splash_state_enter(game_context* ctx)
  34. {
  35. logger* logger = ctx->logger;
  36. logger->push_task("Entering splash state");
  37. //ctx->app->set_window_opacity(0.5f);
  38. // Disable sky pass
  39. ctx->overworld_sky_pass->set_enabled(false);
  40. // Add splash billboard to UI scene
  41. ctx->ui_scene->add_object(ctx->splash_billboard);
  42. // Setup timing
  43. const float splash_fade_in_duration = 0.5f;
  44. const float splash_hang_duration = 2.0f;
  45. const float splash_fade_out_duration = 0.5f;
  46. // Start fade in
  47. ctx->fade_transition->transition(splash_fade_in_duration, true, ease<float>::in_quad);
  48. // Crate fade out function
  49. auto fade_out = [ctx, splash_fade_out_duration]()
  50. {
  51. ctx->fade_transition->transition(splash_fade_out_duration, false, ease<float>::out_quad);
  52. };
  53. // Create change state function
  54. auto change_state = [ctx]()
  55. {
  56. ctx->app->change_state({std::bind(play_state_enter, ctx), std::bind(play_state_exit, ctx)});
  57. };
  58. // Schedule fade out and change state events
  59. timeline* timeline = ctx->timeline;
  60. float t = timeline->get_position();
  61. timeline::sequence splash_sequence =
  62. {
  63. {t + splash_fade_in_duration + splash_hang_duration, fade_out},
  64. {t + splash_fade_in_duration + splash_hang_duration + splash_fade_out_duration, change_state}
  65. };
  66. timeline->add_sequence(splash_sequence);
  67. // Set up splash skipper
  68. ctx->input_listener->set_callback
  69. (
  70. [ctx](const event_base& event)
  71. {
  72. auto id = event.get_event_type_id();
  73. if (id != mouse_moved_event::event_type_id && id != mouse_wheel_scrolled_event::event_type_id && id != game_controller_axis_moved_event::event_type_id)
  74. {
  75. ctx->timeline->clear();
  76. ctx->fade_transition->get_animation()->stop();
  77. ctx->rasterizer->set_clear_color(0.0f, 0.0f, 0.0f, 1.0f);
  78. ctx->rasterizer->clear_framebuffer(true, false, false);
  79. ctx->app->swap_buffers();
  80. ctx->app->change_state({std::bind(play_state_enter, ctx), std::bind(play_state_exit, ctx)});
  81. }
  82. }
  83. );
  84. ctx->input_listener->set_enabled(true);
  85. logger->pop_task(EXIT_SUCCESS);
  86. }
  87. void splash_state_exit(game_context* ctx)
  88. {
  89. logger* logger = ctx->logger;
  90. logger->push_task("Exiting splash state");
  91. // Disable splash skipper
  92. ctx->input_listener->set_enabled(false);
  93. ctx->input_listener->set_callback(nullptr);
  94. // Remove splash billboard from UI scene
  95. ctx->ui_scene->remove_object(ctx->splash_billboard);
  96. logger->pop_task(EXIT_SUCCESS);
  97. }