/* * Copyright (C) 2023 Christopher J. Howard * * This file is part of Antkeeper source code. * * Antkeeper source code is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Antkeeper source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Antkeeper source code. If not, see . */ #ifndef ANTKEEPER_GAME_HPP #define ANTKEEPER_GAME_HPP #include "game/ecoregion.hpp" #include "game/states/game-state.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Forward declarations class animator; class resource_manager; class screen_transition; class timeline; template class animation; namespace debug { class cli; } namespace render { class bloom_pass; class compositor; class final_pass; class resample_pass; class material_pass; class renderer; class simple_render_pass; class sky_pass; } // Forward declarations of system types. class astronomy_system; class atmosphere_system; class behavior_system; class blackbody_system; class camera_system; class collision_system; class constraint_system; class locomotion_system; class animation_system; class nest_system; class orbit_system; class render_system; class spatial_system; class steering_system; class reproductive_system; class metabolic_system; class metamorphosis_system; class physics_system; class subterrain_system; class terrain_system; class ik_system; struct control_profile; class game { public: /** * Boots up the game. * * @param argc Command line argument count. * @param argv Command line argument vector. */ game(int argc, const char* const* argv); /** * Boots down the game. */ ~game(); /** * Executes the game. */ void execute(); // Command-line options std::optional option_continue; std::optional option_data; std::optional option_fullscreen; std::optional option_new_game; std::optional option_quick_start; std::optional option_reset; std::optional option_v_sync; std::optional option_windowed; // Resource management and paths std::unique_ptr resource_manager; std::filesystem::path data_package_path; std::filesystem::path mods_path; std::filesystem::path local_config_path; std::filesystem::path shared_config_path; std::filesystem::path saves_path; std::filesystem::path screenshots_path; std::filesystem::path controls_path; // Persistent settings std::shared_ptr> settings; // Window management and window event handling std::unique_ptr window_manager; std::shared_ptr window; bool closed; std::shared_ptr<::event::subscription> window_closed_subscription; std::shared_ptr<::event::subscription> window_resized_subscription; // Input management and input event handling std::unique_ptr input_manager; std::shared_ptr<::event::subscription> application_quit_subscription; std::shared_ptr<::event::subscription> gamepad_axis_moved_subscription; std::shared_ptr<::event::subscription> gamepad_button_pressed_subscription; std::shared_ptr<::event::subscription> mouse_button_pressed_subscription; std::shared_ptr<::event::subscription> mouse_moved_subscription; std::shared_ptr<::event::subscription> mouse_scrolled_subscription; bool gamepad_active; // Localization and internationalization std::string language_tag; std::shared_ptr string_map; // Fonts std::unordered_map> typefaces; type::bitmap_font debug_font; type::bitmap_font menu_font; type::bitmap_font title_font; std::shared_ptr debug_font_material; std::shared_ptr menu_font_material; std::shared_ptr title_font_material; // Action maps, actions, and action event handling std::string control_profile_filename; std::shared_ptr<::control_profile> control_profile; std::unordered_map actions; input::action_map window_action_map; input::action fullscreen_action; input::action screenshot_action; input::action_map menu_action_map; input::action menu_up_action; input::action menu_down_action; input::action menu_left_action; input::action menu_right_action; input::action menu_select_action; input::action menu_back_action; input::action menu_modifier_action; input::action_map movement_action_map; input::mapper input_mapper; input::action move_forward_action; input::action move_back_action; input::action move_left_action; input::action move_right_action; input::action move_up_action; input::action move_down_action; input::action move_fast_action; input::action move_slow_action; input::action pause_action; input::action_map camera_action_map; input::action camera_mouse_pick_action; input::action camera_mouse_look_action; input::action camera_mouse_drag_action; input::action camera_mouse_zoom_action; input::action camera_zoom_in_action; input::action camera_zoom_out_action; input::action camera_orbit_left_action; input::action camera_orbit_right_action; input::action camera_orbit_up_action; input::action camera_orbit_down_action; input::action camera_look_ahead_action; input::action camera_preset_1_action; input::action camera_preset_2_action; input::action camera_preset_3_action; input::action camera_preset_4_action; input::action camera_preset_5_action; input::action camera_preset_6_action; input::action camera_preset_7_action; input::action camera_preset_8_action; input::action camera_preset_9_action; input::action camera_preset_10_action; input::action camera_save_preset_action; input::action_map ant_action_map; input::action ant_move_forward_action; input::action ant_move_back_action; input::action ant_move_left_action; input::action ant_move_right_action; input::action ant_move_fast_action; input::action ant_move_slow_action; input::action ant_interact_action; input::action ant_oviposit_action; input::action_map debug_action_map; input::action toggle_debug_ui_action; input::action adjust_exposure_action; input::action adjust_time_action; std::vector> event_subscriptions; std::vector> menu_action_subscriptions; std::vector> menu_mouse_subscriptions; std::vector> movement_action_subscriptions; // Mouse settings double mouse_radians_per_pixel{math::radians(0.1)}; double mouse_pan_sensitivity{1.0}; double mouse_tilt_sensitivity{1.0}; bool mouse_invert_pan{false}; bool mouse_invert_tilt{false}; double mouse_pan_factor{1.0}; double mouse_tilt_factor{1.0}; bool toggle_mouse_look{false}; bool toggle_mouse_grip{false}; bool toggle_mouse_zoom{false}; float zoom_steps{6.0}; // Gamepad settings double gamepad_radians_per_second{math::radians(180.0)}; double gamepad_pan_sensitivity{1.0}; double gamepad_tilt_sensitivity{1.0}; bool gamepad_invert_pan{false}; bool gamepad_invert_tilt{false}; double gamepad_pan_factor{1.0}; double gamepad_tilt_factor{1.0}; // Debugging bool debug_ui_visible{false}; std::unique_ptr frame_time_text; std::unique_ptr cli; // Hierarchichal state machine hsm::state_machine state_machine; std::function resume_callback; // Queue for scheduling "next frame" function calls std::queue> function_queue; // Framebuffers std::shared_ptr hdr_color_texture; std::shared_ptr hdr_depth_texture; std::shared_ptr hdr_framebuffer; std::shared_ptr ldr_color_texture_a; std::shared_ptr ldr_framebuffer_a; std::shared_ptr ldr_color_texture_b; std::shared_ptr ldr_framebuffer_b; std::shared_ptr shadow_map_depth_texture; std::shared_ptr shadow_map_framebuffer; // Rendering math::ivec2 render_resolution; float render_scale; int shadow_map_resolution; std::unique_ptr ui_material_pass; std::unique_ptr ui_compositor; std::unique_ptr bloom_pass; std::unique_ptr common_final_pass; std::unique_ptr resample_pass; std::unique_ptr underground_material_pass; std::unique_ptr underground_compositor; std::unique_ptr sky_pass; std::unique_ptr surface_material_pass; std::unique_ptr surface_compositor; std::unique_ptr renderer; // UI std::unique_ptr ui_scene; std::unique_ptr ui_camera; std::unique_ptr menu_bg_billboard; std::shared_ptr menu_bg_material; std::unique_ptr> menu_fade_animation; std::unique_ptr> menu_bg_fade_in_animation; std::unique_ptr> menu_bg_fade_out_animation; float font_scale; bool dyslexia_font; float debug_font_size_pt; float menu_font_size_pt; float title_font_size_pt; std::vector> menu_select_callbacks; std::vector> menu_left_callbacks; std::vector> menu_right_callbacks; std::function menu_back_callback; std::vector> menu_item_texts; std::unordered_map menu_item_indices; int* menu_item_index; // Scene std::unique_ptr surface_scene; std::shared_ptr surface_camera; std::unique_ptr sun_light; std::unique_ptr moon_light; std::unique_ptr underground_scene; std::shared_ptr underground_camera; std::unique_ptr underground_directional_light; std::unique_ptr underground_rectangle_light; scene::collection* active_scene; // Animation std::unique_ptr timeline; std::unique_ptr animator; std::unique_ptr> radial_transition_in; std::unique_ptr> radial_transition_out; std::unique_ptr fade_transition; std::shared_ptr fade_transition_color; std::unique_ptr radial_transition_inner; std::unique_ptr radial_transition_outer; std::unique_ptr> equip_tool_animation; std::unique_ptr> unequip_tool_animation; // Sound ALCdevice* alc_device; ALCcontext* alc_context; float master_volume; float ambience_volume; float effects_volume; bool mono_audio; bool captions; float captions_size; // Random number generation std::mt19937 rng; // Entities std::unique_ptr entity_registry; std::unordered_map entities; entity::id controlled_ant_eid{entt::null}; entity::id active_camera_eid{entt::null}; // Systems std::unique_ptr<::behavior_system> behavior_system; std::unique_ptr<::camera_system> camera_system; std::unique_ptr<::collision_system> collision_system; std::unique_ptr<::constraint_system> constraint_system; std::unique_ptr<::steering_system> steering_system; std::unique_ptr<::reproductive_system> reproductive_system; std::unique_ptr<::metabolic_system> metabolic_system; std::unique_ptr<::metamorphosis_system> metamorphosis_system; std::unique_ptr<::locomotion_system> locomotion_system; std::unique_ptr<::ik_system> ik_system; std::unique_ptr<::animation_system> animation_system; std::unique_ptr<::physics_system> physics_system; std::unique_ptr<::render_system> render_system; std::unique_ptr<::subterrain_system> subterrain_system; std::unique_ptr<::terrain_system> terrain_system; std::unique_ptr<::spatial_system> spatial_system; std::unique_ptr<::blackbody_system> blackbody_system; std::unique_ptr<::atmosphere_system> atmosphere_system; std::unique_ptr<::astronomy_system> astronomy_system; std::unique_ptr<::orbit_system> orbit_system; // Frame timing float fixed_update_rate{60.0}; float max_frame_rate{120.0}; bool limit_frame_rate{false}; ::frame_scheduler frame_scheduler; math::moving_average average_frame_duration; std::shared_ptr active_ecoregion; render::anti_aliasing_method anti_aliasing_method; private: void parse_options(int argc, const char* const* argv); void setup_resources(); void load_settings(); void setup_window(); void setup_input(); void load_strings(); void setup_rendering(); void setup_audio(); void setup_scenes(); void setup_animation(); void setup_ui(); void setup_rng(); void setup_entities(); void setup_systems(); void setup_controls(); void setup_debugging(); void setup_timing(); void shutdown_audio(); void fixed_update(::frame_scheduler::duration_type fixed_update_time, ::frame_scheduler::duration_type fixed_update_interval); void variable_update(::frame_scheduler::duration_type fixed_update_time, ::frame_scheduler::duration_type fixed_update_interval, ::frame_scheduler::duration_type accumulated_time); }; #endif // ANTKEEPER_GAME_HPP