diff --git a/src/game/context.hpp b/src/game/context.hpp index a885b1c..473e90b 100644 --- a/src/game/context.hpp +++ b/src/game/context.hpp @@ -195,7 +195,6 @@ struct context gl::vertex_buffer* billboard_vbo; gl::vertex_array* billboard_vao; render::material* fallback_material; - // Compositing render::clear_pass* ui_clear_pass; @@ -216,15 +215,12 @@ struct context // Scene utilities scene::collection* active_scene; - geom::aabb no_cull; // UI scene scene::collection* ui_scene; scene::camera* ui_camera; scene::billboard* camera_flash_billboard; - scene::text* title_text; - scene::text* title_press_any_key_text; - scene::text* credits_text; + float font_size; bool dyslexia_font; ui::mouse_tracker* menu_mouse_tracker; @@ -235,9 +231,10 @@ struct context std::vector> menu_item_texts; std::unordered_map menu_item_indices; int* menu_item_index; - animation* menu_fade_animation; - animation* title_fade_animation; scene::billboard* menu_bg_billboard; + animation* menu_fade_animation; + animation* menu_bg_fade_in_animation; + animation* menu_bg_fade_out_animation; // Surface scene scene::collection* surface_scene; @@ -261,14 +258,6 @@ struct context animation* equip_tool_animation; animation* unequip_tool_animation; animation* camera_flash_animation; - animation* title_fade_in_animation; - animation* title_fade_out_animation; - animation* title_press_any_key_animation; - animation* main_menu_fade_animation; - animation* credits_fade_in_animation; - animation* credits_scroll_animation; - animation* menu_bg_fade_in_animation; - animation* menu_bg_fade_out_animation; // Sound float master_volume; diff --git a/src/game/state/boot.cpp b/src/game/state/boot.cpp index 401ef03..2d78c4b 100644 --- a/src/game/state/boot.cpp +++ b/src/game/state/boot.cpp @@ -632,10 +632,6 @@ void boot::setup_scenes() const auto& viewport_dimensions = ctx.rasterizer->get_default_framebuffer().get_dimensions(); const float viewport_aspect_ratio = static_cast(viewport_dimensions[0]) / static_cast(viewport_dimensions[1]); - // Create infinite culling mask - const float inf = std::numeric_limits::infinity(); - ctx.no_cull = {{-inf, -inf, -inf}, {inf, inf, inf}}; - // Setup UI camera ctx.ui_camera = new scene::camera(); ctx.ui_camera->set_compositor(ctx.ui_compositor); diff --git a/src/game/state/credits.cpp b/src/game/state/credits.cpp index b488c03..9a3779b 100644 --- a/src/game/state/credits.cpp +++ b/src/game/state/credits.cpp @@ -36,17 +36,17 @@ credits::credits(game::context& ctx): ctx.logger->push_task("Entering credits state"); // Construct credits text - ctx.credits_text = new scene::text(); - ctx.credits_text->set_material(&ctx.menu_font_material); - ctx.credits_text->set_font(&ctx.menu_font); - ctx.credits_text->set_color({1.0f, 1.0f, 1.0f, 0.0f}); - ctx.credits_text->set_content((*ctx.strings)["credits"]); + credits_text.set_material(&ctx.menu_font_material); + credits_text.set_font(&ctx.menu_font); + credits_text.set_color({1.0f, 1.0f, 1.0f, 0.0f}); + credits_text.set_content((*ctx.strings)["credits"]); // Align credits text - const auto& credits_aabb = static_cast&>(ctx.credits_text->get_local_bounds()); + const auto& credits_aabb = static_cast&>(credits_text.get_local_bounds()); float credits_w = credits_aabb.max_point.x - credits_aabb.min_point.x; float credits_h = credits_aabb.max_point.y - credits_aabb.min_point.y; - ctx.credits_text->set_translation({std::round(-credits_w * 0.5f), std::round(-credits_h * 0.5f), 0.0f}); + credits_text.set_translation({std::round(-credits_w * 0.5f), std::round(-credits_h * 0.5f), 0.0f}); + credits_text.update_tweens(); // Load animation timing configuration double credits_fade_in_duration = 0.0; @@ -56,47 +56,33 @@ credits::credits(game::context& ctx): if (ctx.config->contains("credits_scroll_duration")) credits_scroll_duration = (*ctx.config)["credits_scroll_duration"].get(); - auto set_credits_opacity = [&ctx](int channel, const float& opacity) + auto set_credits_opacity = [this](int channel, const float& opacity) { - ctx.credits_text->set_color({1.0f, 1.0f, 1.0f, opacity}); + this->credits_text.set_color({1.0f, 1.0f, 1.0f, opacity}); }; // Build credits fade in animation - ctx.credits_fade_in_animation = new animation(); - animation_channel* credits_fade_in_opacity_channel = ctx.credits_fade_in_animation->add_channel(0); - ctx.credits_fade_in_animation->set_interpolator(ease::in_quad); + credits_fade_in_animation.set_interpolator(ease::in_quad); + animation_channel* credits_fade_in_opacity_channel = credits_fade_in_animation.add_channel(0); credits_fade_in_opacity_channel->insert_keyframe({0.0, 0.0f}); credits_fade_in_opacity_channel->insert_keyframe({credits_fade_in_duration, 1.0f}); - ctx.credits_fade_in_animation->set_frame_callback(set_credits_opacity); - - // Build credits scroll in animation - ctx.credits_scroll_animation = new animation(); - - // Trigger credits scroll animation after credits fade in animation ends - ctx.credits_fade_in_animation->set_end_callback - ( - [&ctx]() - { - ctx.credits_scroll_animation->play(); - } - ); + credits_fade_in_animation.set_frame_callback(set_credits_opacity); // Add credits animations to animator - ctx.animator->add_animation(ctx.credits_fade_in_animation); - ctx.animator->add_animation(ctx.credits_scroll_animation); + ctx.animator->add_animation(&credits_fade_in_animation); // Start credits fade in animation - ctx.credits_fade_in_animation->play(); + credits_fade_in_animation.play(); // Set up credits skipper ctx.input_listener->set_callback ( - [&ctx](const event_base& event) + [this, &ctx](const event_base& event) { auto id = event.get_event_type_id(); if (id != mouse_moved_event::event_type_id && id != mouse_wheel_scrolled_event::event_type_id && id != gamepad_axis_moved_event::event_type_id) { - if (ctx.credits_text->get_color()[3] > 0.0f) + if (this->credits_text.get_color()[3] > 0.0f) { ctx.input_listener->set_enabled(false); @@ -109,8 +95,7 @@ credits::credits(game::context& ctx): ); ctx.input_listener->set_enabled(true); - ctx.ui_scene->add_object(ctx.credits_text); - ctx.credits_text->update_tweens(); + ctx.ui_scene->add_object(&credits_text); ctx.logger->pop_task(EXIT_SUCCESS); } @@ -124,17 +109,10 @@ credits::~credits() ctx.input_listener->set_callback(nullptr); // Destruct credits text - ctx.ui_scene->remove_object(ctx.credits_text); - delete ctx.credits_text; - ctx.credits_text = nullptr; + ctx.ui_scene->remove_object(&credits_text); // Destruct credits animations - ctx.animator->remove_animation(ctx.credits_fade_in_animation); - ctx.animator->remove_animation(ctx.credits_scroll_animation); - delete ctx.credits_fade_in_animation; - delete ctx.credits_scroll_animation; - ctx.credits_fade_in_animation = nullptr; - ctx.credits_scroll_animation = nullptr; + ctx.animator->remove_animation(&credits_fade_in_animation); ctx.logger->pop_task(EXIT_SUCCESS); } diff --git a/src/game/state/credits.hpp b/src/game/state/credits.hpp index c8da4fe..a51378a 100644 --- a/src/game/state/credits.hpp +++ b/src/game/state/credits.hpp @@ -21,6 +21,8 @@ #define ANTKEEPER_GAME_STATE_CREDITS_HPP #include "game/state/base.hpp" +#include "scene/text.hpp" +#include "animation/animation.hpp" namespace game { namespace state { @@ -30,6 +32,11 @@ class credits: public game::state::base public: credits(game::context& ctx); virtual ~credits(); + +private: + scene::text credits_text; + animation credits_fade_in_animation; + animation credits_scroll_animation; }; } // namespace state diff --git a/src/game/state/main-menu.cpp b/src/game/state/main-menu.cpp index d188aec..289cce6 100644 --- a/src/game/state/main-menu.cpp +++ b/src/game/state/main-menu.cpp @@ -45,36 +45,34 @@ main_menu::main_menu(game::context& ctx, bool fade_in): ctx.ui_clear_pass->set_cleared_buffers(true, true, false); // Construct title text - ctx.title_text = new scene::text(); - ctx.title_text->set_material(&ctx.title_font_material); - ctx.title_text->set_font(&ctx.title_font); - ctx.title_text->set_color({1.0f, 1.0f, 1.0f, 1.0f}); - ctx.title_text->set_content((*ctx.strings)["title_antkeeper"]); + title_text.set_material(&ctx.title_font_material); + title_text.set_color({1.0f, 1.0f, 1.0f, (fade_in) ? 1.0f : 0.0f}); + title_text.set_font(&ctx.title_font); + title_text.set_content((*ctx.strings)["title_antkeeper"]); // Align title text - const auto& title_aabb = static_cast&>(ctx.title_text->get_local_bounds()); + const auto& title_aabb = static_cast&>(title_text.get_local_bounds()); float title_w = title_aabb.max_point.x - title_aabb.min_point.x; float title_h = title_aabb.max_point.y - title_aabb.min_point.y; - ctx.title_text->set_translation({std::round(-title_w * 0.5f), std::round(-title_h * 0.5f + (ctx.app->get_viewport_dimensions().y / 3.0f) / 2.0f), 0.0f}); - ctx.title_text->update_tweens(); + title_text.set_translation({std::round(-title_w * 0.5f), std::round(-title_h * 0.5f + (ctx.app->get_viewport_dimensions().y / 3.0f) / 2.0f), 0.0f}); + title_text.update_tweens(); // Add title text to UI - ctx.ui_scene->add_object(ctx.title_text); + ctx.ui_scene->add_object(&title_text); // Construct title fade animation - ctx.title_fade_animation = new animation(); - animation_channel* opacity_channel = ctx.title_fade_animation->add_channel(0); - - ctx.title_fade_animation->set_frame_callback + title_fade_animation.set_interpolator(ease::out_cubic); + animation_channel* opacity_channel = title_fade_animation.add_channel(0); + title_fade_animation.set_frame_callback ( - [&ctx](int channel, const float& opacity) + [this, &ctx](int channel, const float& opacity) { - float4 color = ctx.title_text->get_color(); + float4 color = this->title_text.get_color(); color[3] = opacity; - ctx.title_text->set_color(color); + this->title_text.set_color(color); } ); - ctx.animator->add_animation(ctx.title_fade_animation); + ctx.animator->add_animation(&title_fade_animation); // Construct menu item texts scene::text* start_text = new scene::text(); @@ -218,16 +216,13 @@ main_menu::main_menu(game::context& ctx, bool fade_in): if (fade_in) { + // Fade in from black ctx.fade_transition->transition(0.5f, true, ease::out_cubic); } else { - // Fade in title - ctx.title_text->set_color({1.0f, 1.0f, 1.0f, 0.0f}); - ctx.title_text->update_tweens(); + // Fade in text fade_in_title(); - - // Fade in menu game::menu::fade_in(ctx, nullptr); } @@ -246,38 +241,32 @@ main_menu::~main_menu() game::menu::delete_text(ctx); // Destruct title animation - ctx.animator->remove_animation(ctx.title_fade_animation); - delete ctx.title_fade_animation; - ctx.title_fade_animation = nullptr; + ctx.animator->remove_animation(&title_fade_animation); // Destruct title text - ctx.ui_scene->remove_object(ctx.title_text); - delete ctx.title_text; - ctx.title_text = nullptr; + ctx.ui_scene->remove_object(&title_text); ctx.logger->pop_task(EXIT_SUCCESS); } void main_menu::fade_in_title() { - ctx.title_fade_animation->set_interpolator(ease::out_cubic); - animation_channel* opacity_channel = ctx.title_fade_animation->get_channel(0); + animation_channel* opacity_channel = title_fade_animation.get_channel(0); opacity_channel->remove_keyframes(); opacity_channel->insert_keyframe({0.0, 0.0f}); opacity_channel->insert_keyframe({game::menu::fade_in_duration, 1.0f}); - ctx.title_fade_animation->stop(); - ctx.title_fade_animation->play(); + title_fade_animation.stop(); + title_fade_animation.play(); } void main_menu::fade_out_title() { - ctx.title_fade_animation->set_interpolator(ease::out_cubic); - animation_channel* opacity_channel = ctx.title_fade_animation->get_channel(0); + animation_channel* opacity_channel = title_fade_animation.get_channel(0); opacity_channel->remove_keyframes(); opacity_channel->insert_keyframe({0.0, 1.0f}); opacity_channel->insert_keyframe({game::menu::fade_out_duration, 0.0f}); - ctx.title_fade_animation->stop(); - ctx.title_fade_animation->play(); + title_fade_animation.stop(); + title_fade_animation.play(); } } // namespace state diff --git a/src/game/state/main-menu.hpp b/src/game/state/main-menu.hpp index 1b0b59a..0dbee8e 100644 --- a/src/game/state/main-menu.hpp +++ b/src/game/state/main-menu.hpp @@ -21,6 +21,8 @@ #define ANTKEEPER_GAME_STATE_MAIN_MENU_HPP #include "game/state/base.hpp" +#include "scene/text.hpp" +#include "animation/animation.hpp" namespace game { namespace state { @@ -34,6 +36,9 @@ public: private: void fade_in_title(); void fade_out_title(); + + scene::text title_text; + animation title_fade_animation; }; } // namespace state