/* * 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/loop.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 // 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 clear_pass; class compositor; class final_pass; class fxaa_pass; class resample_pass; class material_pass; class renderer; class outline_pass; class shadow_map_pass; class simple_render_pass; class sky_pass; class ground_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 nest_system; class orbit_system; class render_system; class spatial_system; class spring_system; class steering_system; class subterrain_system; class terrain_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; i18n::string_map* string_map; // Fonts std::unordered_map typefaces; type::bitmap_font debug_font; type::bitmap_font menu_font; type::bitmap_font title_font; render::material debug_font_material; render::material menu_font_material; render::material title_font_material; // Action maps, actions, and action event handling std::string control_profile_filename; ::control_profile* control_profile; std::unordered_map actions; input::action_map window_action_map; input::action_map menu_action_map; input::action_map movement_action_map; input::action_map nuptial_flight_action_map; input::mapper input_mapper; input::action fullscreen_action; input::action screenshot_action; 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 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 pause_action; input::action pick_mate_action; std::vector> window_action_subscriptions; std::vector> menu_action_subscriptions; std::vector> menu_mouse_subscriptions; std::vector> movement_action_subscriptions; // Debugging math::moving_average average_frame_time; 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; // Parallel processes std::unordered_map> processes; bool mouse_look; /// Game loop ::loop loop; // Framebuffers gl::texture_2d* hdr_color_texture; gl::texture_2d* hdr_depth_texture; gl::framebuffer* hdr_framebuffer; gl::texture_2d* ldr_color_texture_a; gl::framebuffer* ldr_framebuffer_a; gl::texture_2d* ldr_color_texture_b; gl::framebuffer* ldr_framebuffer_b; gl::texture_2d* shadow_map_depth_texture; gl::framebuffer* shadow_map_framebuffer; // Rendering //gl::rasterizer* rasterizer; int2 render_resolution; float render_scale; int shadow_map_resolution; std::unique_ptr billboard_vbo; std::unique_ptr billboard_vao; render::material* fallback_material; std::unique_ptr ui_clear_pass; 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 fxaa_pass; std::unique_ptr resample_pass; std::unique_ptr underground_clear_pass; std::unique_ptr underground_material_pass; std::unique_ptr underground_compositor; std::unique_ptr surface_shadow_map_clear_pass; std::unique_ptr surface_shadow_map_pass; std::unique_ptr surface_clear_pass; std::unique_ptr sky_pass; std::unique_ptr surface_material_pass; std::unique_ptr surface_outline_pass; std::unique_ptr surface_compositor; std::unique_ptr ground_pass; std::unique_ptr renderer; // Scene utilities scene::collection* active_scene; // UI std::unique_ptr ui_scene; std::unique_ptr ui_camera; std::unique_ptr menu_bg_billboard; render::material 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::unique_ptr surface_camera; std::unique_ptr underground_scene; std::unique_ptr underground_camera; std::unique_ptr underground_ambient_light; std::unique_ptr flashlight_spot_light; // 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; render::material_property* 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; // Entities std::unique_ptr entity_registry; std::unordered_map entities; // 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<::locomotion_system> locomotion_system; std::unique_ptr<::steering_system> steering_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<::spring_system> spring_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; double3 rgb_wavelengths; const ecoregion* 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_entities(); void setup_systems(); void setup_controls(); void setup_debugging(); void setup_loop(); void shutdown_audio(); }; #endif // ANTKEEPER_GAME_HPP