Browse Source

Improve state change transitions

master
C. J. Howard 2 years ago
parent
commit
6c55aceff5
7 changed files with 93 additions and 42 deletions
  1. +9
    -3
      src/animation/screen-transition.cpp
  2. +2
    -1
      src/animation/screen-transition.hpp
  3. +2
    -3
      src/game/context.hpp
  4. +4
    -1
      src/game/state/boot.cpp
  5. +18
    -11
      src/game/state/main-menu.cpp
  6. +29
    -2
      src/game/state/nuptial-flight.cpp
  7. +29
    -21
      src/game/state/pause-menu.cpp

+ 9
- 3
src/animation/screen-transition.cpp View File

@ -70,7 +70,7 @@ void screen_transition::set_visible(bool visible)
billboard.set_active(visible); billboard.set_active(visible);
} }
void screen_transition::transition(float duration, bool reverse, ::animation<float>::interpolator_type interpolator, bool hide)
void screen_transition::transition(float duration, bool reverse, ::animation<float>::interpolator_type interpolator, bool hide, const std::function<void()>& callback)
{ {
float initial_state = (reverse) ? 1.0f : 0.0f; float initial_state = (reverse) ? 1.0f : 0.0f;
float final_state = (reverse) ? 0.0f : 1.0f; float final_state = (reverse) ? 0.0f : 1.0f;
@ -83,17 +83,23 @@ void screen_transition::transition(float duration, bool reverse, ::animation
// Set transition animation interpolator // Set transition animation interpolator
animation.set_interpolator(interpolator); animation.set_interpolator(interpolator);
this->callback = callback;
if (hide) if (hide)
{ {
// Setup animation end callback to hide transition billboard // Setup animation end callback to hide transition billboard
animation.set_end_callback animation.set_end_callback
( (
std::bind(&scene::object_base::set_active, &billboard, false)
[this]()
{
this->billboard.set_active(false);
if (this->callback)
this->callback();
}
); );
} }
else else
{ {
animation.set_end_callback(nullptr);
animation.set_end_callback(callback);
} }
// Update tweens // Update tweens

+ 2
- 1
src/animation/screen-transition.hpp View File

@ -35,7 +35,7 @@ public:
void set_visible(bool visible); void set_visible(bool visible);
void transition(float duration, bool reverse, animation<float>::interpolator_type interpolator, bool hide = true);
void transition(float duration, bool reverse, animation<float>::interpolator_type interpolator, bool hide = true, const std::function<void()>& callback = nullptr);
scene::billboard* get_billboard(); scene::billboard* get_billboard();
render::material* get_material(); render::material* get_material();
@ -47,6 +47,7 @@ private:
render::material_property<float>* progress; render::material_property<float>* progress;
::animation<float> animation; ::animation<float> animation;
::animation<float>::channel* channel; ::animation<float>::channel* channel;
std::function<void()> callback;
}; };
inline scene::billboard* screen_transition::get_billboard() inline scene::billboard* screen_transition::get_billboard()

+ 2
- 3
src/game/context.hpp View File

@ -116,7 +116,7 @@ namespace render
namespace game { namespace game {
/// Container for data that is shared between game states.
/// Container for data shared between game states.
struct context struct context
{ {
/// Hierarchichal state machine /// Hierarchichal state machine
@ -216,11 +216,10 @@ struct context
// Scene utilities // Scene utilities
scene::collection* active_scene; scene::collection* active_scene;
// UI scene
// UI
scene::collection* ui_scene; scene::collection* ui_scene;
scene::camera* ui_camera; scene::camera* ui_camera;
scene::billboard* camera_flash_billboard; scene::billboard* camera_flash_billboard;
float font_size; float font_size;
bool dyslexia_font; bool dyslexia_font;
ui::mouse_tracker* menu_mouse_tracker; ui::mouse_tracker* menu_mouse_tracker;

+ 4
- 1
src/game/state/boot.cpp View File

@ -792,9 +792,12 @@ void boot::setup_animation()
ctx.menu_bg_fade_in_animation->set_frame_callback(menu_bg_frame_callback); ctx.menu_bg_fade_in_animation->set_frame_callback(menu_bg_frame_callback);
ctx.menu_bg_fade_in_animation->set_start_callback ctx.menu_bg_fade_in_animation->set_start_callback
( (
[&ctx = this->ctx]()
[&ctx = this->ctx, menu_bg_tint]()
{ {
ctx.ui_scene->add_object(ctx.menu_bg_billboard); ctx.ui_scene->add_object(ctx.menu_bg_billboard);
menu_bg_tint->set_value(float4{0.0f, 0.0f, 0.0f, 0.0f});
menu_bg_tint->update_tweens();
ctx.menu_bg_billboard->set_active(true); ctx.menu_bg_billboard->set_active(true);
} }
); );

+ 18
- 11
src/game/state/main-menu.cpp View File

@ -30,7 +30,6 @@
#include "animation/animator.hpp" #include "animation/animator.hpp"
#include "animation/screen-transition.hpp" #include "animation/screen-transition.hpp"
#include "animation/ease.hpp" #include "animation/ease.hpp"
#include "animation/timeline.hpp"
#include "application.hpp" #include "application.hpp"
#include <limits> #include <limits>
@ -102,7 +101,7 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
game::menu::add_text_to_ui(ctx); game::menu::add_text_to_ui(ctx);
game::menu::setup_animations(ctx); game::menu::setup_animations(ctx);
auto select_start_callback = [&ctx]()
auto select_start_callback = [this, &ctx]()
{ {
// Disable controls and menu callbacks // Disable controls and menu callbacks
game::menu::clear_controls(ctx); game::menu::clear_controls(ctx);
@ -122,17 +121,15 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
); );
}; };
// Set up timing
const float fade_out_duration = 1.0f;
// Fade out title
this->fade_out_title();
// Schedule state change
timeline* timeline = ctx.timeline;
float t = timeline->get_position();
timeline->add_sequence({{t + fade_out_duration, change_state_nuptial_flight}});
// Fade out menu
game::menu::fade_out(ctx, nullptr);
// Start fade out to white // Start fade out to white
ctx.fade_transition_color->set_value({1, 1, 1}); ctx.fade_transition_color->set_value({1, 1, 1});
ctx.fade_transition->transition(fade_out_duration, false, ease<float>::out_cubic, false);
ctx.fade_transition->transition(1.0f, false, ease<float>::out_cubic, false, change_state_nuptial_flight);
}; };
auto select_options_callback = [this, &ctx]() auto select_options_callback = [this, &ctx]()
{ {
@ -185,9 +182,19 @@ main_menu::main_menu(game::context& ctx, bool fade_in):
} }
); );
}; };
auto select_quit_callback = [&ctx]()
auto select_quit_callback = [this, &ctx]()
{ {
ctx.app->close();
// Disable controls
game::menu::clear_controls(ctx);
// Fade out title
this->fade_out_title();
// Fade out menu
game::menu::fade_out(ctx, nullptr);
// Fade to black then quit
ctx.fade_transition->transition(0.5f, false, ease<float>::out_cubic, false, std::bind(&application::close, ctx.app));
}; };
// Build list of menu select callbacks // Build list of menu select callbacks

+ 29
- 2
src/game/state/nuptial-flight.cpp View File

@ -78,6 +78,17 @@ nuptial_flight::nuptial_flight(game::context& ctx):
// Enable clouds in sky pass // Enable clouds in sky pass
//ctx.surface_sky_pass->set_clouds_model(ctx.resource_manager->load<render::model>("cloud-plane.mdl")); //ctx.surface_sky_pass->set_clouds_model(ctx.resource_manager->load<render::model>("cloud-plane.mdl"));
// Create biome terrain component
entity::component::terrain biome_terrain;
biome_terrain.max_lod = 18;
biome_terrain.patch_material = ctx.resource_manager->load<render::material>("desert-terrain.mtl");
biome_terrain.elevation = [](double, double) -> double
{
return 0.0;
};
// Replace planet terrain component with biome terrain component
ctx.entity_registry->replace<entity::component::terrain>(planet_eid, biome_terrain);
// Create observer // Create observer
entity::id observer_eid = ctx.entity_registry->create(); entity::id observer_eid = ctx.entity_registry->create();
{ {
@ -104,7 +115,7 @@ nuptial_flight::nuptial_flight(game::context& ctx):
// Queue fade in // Queue fade in
ctx.fade_transition_color->set_value({1, 1, 1}); ctx.fade_transition_color->set_value({1, 1, 1});
ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, 5.0f, true, math::lerp<float, float>, true));
ctx.function_queue.push(std::bind(&screen_transition::transition, ctx.fade_transition, 5.0f, true, math::lerp<float, float>, true, nullptr));
// Queue control setup // Queue control setup
ctx.function_queue.push(std::bind(&nuptial_flight::enable_controls, this)); ctx.function_queue.push(std::bind(&nuptial_flight::enable_controls, this));
@ -206,7 +217,7 @@ void nuptial_flight::setup_camera()
ctx.entity_registry->assign<entity::component::constraint_stack>(camera_eid, constraint_stack); ctx.entity_registry->assign<entity::component::constraint_stack>(camera_eid, constraint_stack);
} }
ctx.surface_camera->set_exposure(-12.0f);
ctx.surface_camera->set_exposure(-14.0f);
} }
void nuptial_flight::enable_controls() void nuptial_flight::enable_controls()
@ -537,6 +548,22 @@ void nuptial_flight::enable_controls()
void nuptial_flight::disable_controls() void nuptial_flight::disable_controls()
{ {
ctx.controls["move_forward"]->set_active_callback(nullptr);
ctx.controls["move_back"]->set_active_callback(nullptr);
ctx.controls["move_right"]->set_active_callback(nullptr);
ctx.controls["move_left"]->set_active_callback(nullptr);
ctx.controls["move_up"]->set_active_callback(nullptr);
ctx.controls["move_down"]->set_active_callback(nullptr);
ctx.controls["mouse_look"]->set_activated_callback(nullptr);
ctx.controls["mouse_look"]->set_deactivated_callback(nullptr);
ctx.controls["look_left_gamepad"]->set_active_callback(nullptr);
ctx.controls["look_left_mouse"]->set_active_callback(nullptr);
ctx.controls["look_right_gamepad"]->set_active_callback(nullptr);
ctx.controls["look_right_mouse"]->set_active_callback(nullptr);
ctx.controls["look_up_gamepad"]->set_active_callback(nullptr);
ctx.controls["look_up_mouse"]->set_active_callback(nullptr);
ctx.controls["look_down_gamepad"]->set_active_callback(nullptr);
ctx.controls["look_down_mouse"]->set_active_callback(nullptr);
ctx.controls["pause"]->set_activated_callback(nullptr); ctx.controls["pause"]->set_activated_callback(nullptr);
} }

+ 29
- 21
src/game/state/pause-menu.cpp View File

@ -28,6 +28,7 @@
#include "application.hpp" #include "application.hpp"
#include "scene/text.hpp" #include "scene/text.hpp"
#include "debug/logger.hpp" #include "debug/logger.hpp"
#include "animation/screen-transition.hpp"
namespace game { namespace game {
namespace state { namespace state {
@ -124,26 +125,29 @@ pause_menu::pause_menu(game::context& ctx):
// Disable menu controls // Disable menu controls
game::menu::clear_controls(ctx); game::menu::clear_controls(ctx);
// Clear paused state
//ctx.paused_state.reset();
// Clear resume callback
ctx.resume_callback = nullptr;
// Fade out pause menu then return to main menu
game::menu::fade_out
(
ctx,
[&ctx]()
{
// Queue change to main menu state
ctx.function_queue.push
(
[&ctx]()
{
ctx.state_machine.pop();
ctx.state_machine.emplace(new game::state::main_menu(ctx, true));
}
);
}
);
auto fade_out_callback = [&ctx]()
{
// Queue change to main menu state
ctx.function_queue.push
(
[&ctx]()
{
ctx.menu_bg_billboard->set_active(false);
ctx.state_machine.pop();
ctx.state_machine.emplace(new game::state::main_menu(ctx, true));
}
);
};
// Fade out pause menu
game::menu::fade_out(ctx, nullptr);
// Fade out to black then return to main menu
ctx.fade_transition_color->set_value({0, 0, 0});
ctx.fade_transition->transition(1.0f, false, ease<float>::out_cubic, false, fade_out_callback);
}; };
auto select_quit_callback = [&ctx]() auto select_quit_callback = [&ctx]()
{ {
@ -156,8 +160,12 @@ pause_menu::pause_menu(game::context& ctx):
// Clear paused state // Clear paused state
//ctx.paused_state.reset(); //ctx.paused_state.reset();
// Fade out then quit
game::menu::fade_out(ctx, std::bind(&application::close, ctx.app));
// Fade out pause menu
game::menu::fade_out(ctx, nullptr);
// Fade out to black then quit
ctx.fade_transition_color->set_value({0, 0, 0});
ctx.fade_transition->transition(1.0f, false, ease<float>::out_cubic, false, std::bind(&application::close, ctx.app));
}; };
// Build list of menu select callbacks // Build list of menu select callbacks

Loading…
Cancel
Save