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

342 lines
9.5 KiB

2 years ago
2 years ago
1 year ago
1 year ago
  1. /*
  2. * Copyright (C) 2023 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. #ifndef ANTKEEPER_GAME_CONTEXT_HPP
  20. #define ANTKEEPER_GAME_CONTEXT_HPP
  21. #include "animation/tween.hpp"
  22. #include "app/window-manager.hpp"
  23. #include "app/input-manager.hpp"
  24. #include "debug/performance-sampler.hpp"
  25. #include "entity/id.hpp"
  26. #include "entity/registry.hpp"
  27. #include "event/subscription.hpp"
  28. #include "game/ecoregion.hpp"
  29. #include "game/loop.hpp"
  30. #include "game/state/base.hpp"
  31. #include "geom/aabb.hpp"
  32. #include "gl/framebuffer.hpp"
  33. #include "gl/rasterizer.hpp"
  34. #include "gl/texture-2d.hpp"
  35. #include "gl/vertex-array.hpp"
  36. #include "gl/vertex-buffer.hpp"
  37. #include "input/control-map.hpp"
  38. #include "input/control.hpp"
  39. #include "input/mapper.hpp"
  40. #include "render/anti-aliasing-method.hpp"
  41. #include "render/material-property.hpp"
  42. #include "render/material.hpp"
  43. #include "resources/json.hpp"
  44. #include "scene/scene.hpp"
  45. #include "utility/state-machine.hpp"
  46. #include "type/bitmap-font.hpp"
  47. #include "type/typeface.hpp"
  48. #include "utility/dict.hpp"
  49. #include "utility/fundamental-types.hpp"
  50. #include "i18n/string-table.hpp"
  51. #include "i18n/string-map.hpp"
  52. #include <AL/al.h>
  53. #include <AL/alc.h>
  54. #include <entt/entt.hpp>
  55. #include <filesystem>
  56. #include <forward_list>
  57. #include <memory>
  58. #include <optional>
  59. #include <queue>
  60. #include <string>
  61. #include <unordered_map>
  62. #include <vector>
  63. // Forward declarations
  64. class animator;
  65. class resource_manager;
  66. class screen_transition;
  67. class timeline;
  68. template <typename T> class animation;
  69. namespace debug
  70. {
  71. class cli;
  72. }
  73. namespace game
  74. {
  75. namespace system
  76. {
  77. class subterrain;
  78. class terrain;
  79. class vegetation;
  80. class spatial;
  81. class astronomy;
  82. class blackbody;
  83. class atmosphere;
  84. class orbit;
  85. class behavior;
  86. class collision;
  87. class constraint;
  88. class locomotion;
  89. class camera;
  90. class nest;
  91. class render;
  92. class steering;
  93. class spring;
  94. }
  95. }
  96. namespace render
  97. {
  98. class bloom_pass;
  99. class clear_pass;
  100. class compositor;
  101. class final_pass;
  102. class fxaa_pass;
  103. class resample_pass;
  104. class material_pass;
  105. class renderer;
  106. class outline_pass;
  107. class shadow_map_pass;
  108. class simple_render_pass;
  109. class sky_pass;
  110. class ground_pass;
  111. }
  112. namespace game {
  113. /// Container for data shared between game states.
  114. struct context
  115. {
  116. // Command-line options
  117. std::optional<bool> option_continue;
  118. std::optional<std::string> option_data;
  119. std::optional<bool> option_fullscreen;
  120. std::optional<bool> option_new_game;
  121. std::optional<bool> option_quick_start;
  122. std::optional<bool> option_reset;
  123. std::optional<bool> option_v_sync;
  124. std::optional<bool> option_windowed;
  125. // Resource management and paths
  126. resource_manager* resource_manager;
  127. std::filesystem::path data_path;
  128. std::filesystem::path local_config_path;
  129. std::filesystem::path shared_config_path;
  130. std::filesystem::path mods_path;
  131. std::filesystem::path saves_path;
  132. std::filesystem::path screenshots_path;
  133. std::filesystem::path controls_path;
  134. std::filesystem::path data_package_path;
  135. // Persistent settings
  136. dict<std::uint32_t>* settings;
  137. // Window management and event handling
  138. app::window_manager* window_manager;
  139. app::window* window;
  140. bool closed;
  141. std::shared_ptr<::event::subscription> window_closed_subscription;
  142. // Input management and event handling
  143. app::input_manager* input_manager;
  144. std::shared_ptr<::event::subscription> application_quit_subscription;
  145. // Localization and internationalization
  146. std::uint16_t language_index;
  147. std::uint16_t language_count;
  148. i18n::string_table* string_table;
  149. std::vector<i18n::string_map> string_maps;
  150. // Fonts
  151. std::unordered_map<std::string, type::typeface*> typefaces;
  152. type::bitmap_font debug_font;
  153. type::bitmap_font menu_font;
  154. type::bitmap_font title_font;
  155. render::material debug_font_material;
  156. render::material menu_font_material;
  157. render::material title_font_material;
  158. // Hierarchichal state machine
  159. hsm::state_machine<game::state::base> state_machine;
  160. std::function<void()> resume_callback;
  161. // Debugging
  162. debug::performance_sampler performance_sampler;
  163. debug::cli* cli;
  164. // Queue for scheduling "next frame" function calls
  165. std::queue<std::function<void()>> function_queue;
  166. // Parallel processes
  167. std::unordered_map<std::string, std::function<void(double, double)>> processes;
  168. // Controls
  169. input::mapper input_mapper;
  170. std::forward_list<std::shared_ptr<::event::subscription>> control_subscriptions;
  171. input::control_map window_controls;
  172. input::control fullscreen_control;
  173. input::control screenshot_control;
  174. input::control_map menu_controls;
  175. input::control menu_up_control;
  176. input::control menu_down_control;
  177. input::control menu_left_control;
  178. input::control menu_right_control;
  179. input::control menu_select_control;
  180. input::control menu_back_control;
  181. input::control menu_modifier_control;
  182. bool mouse_look;
  183. /// Game loop
  184. game::loop loop;
  185. // Framebuffers
  186. gl::texture_2d* hdr_color_texture;
  187. gl::texture_2d* hdr_depth_texture;
  188. gl::framebuffer* hdr_framebuffer;
  189. gl::texture_2d* ldr_color_texture_a;
  190. gl::framebuffer* ldr_framebuffer_a;
  191. gl::texture_2d* ldr_color_texture_b;
  192. gl::framebuffer* ldr_framebuffer_b;
  193. gl::texture_2d* shadow_map_depth_texture;
  194. gl::framebuffer* shadow_map_framebuffer;
  195. // Rendering
  196. gl::rasterizer* rasterizer;
  197. render::renderer* renderer;
  198. int2 render_resolution;
  199. float render_scale;
  200. int shadow_map_resolution;
  201. gl::vertex_buffer* billboard_vbo;
  202. gl::vertex_array* billboard_vao;
  203. render::material* fallback_material;
  204. // Compositing
  205. render::clear_pass* ui_clear_pass;
  206. render::material_pass* ui_material_pass;
  207. render::compositor* ui_compositor;
  208. render::bloom_pass* bloom_pass;
  209. render::final_pass* common_final_pass;
  210. render::fxaa_pass* fxaa_pass;
  211. render::resample_pass* resample_pass;
  212. render::clear_pass* underground_clear_pass;
  213. render::material_pass* underground_material_pass;
  214. render::compositor* underground_compositor;
  215. render::clear_pass* surface_shadow_map_clear_pass;
  216. render::shadow_map_pass* surface_shadow_map_pass;
  217. render::clear_pass* surface_clear_pass;
  218. render::sky_pass* sky_pass;
  219. render::material_pass* surface_material_pass;
  220. render::outline_pass* surface_outline_pass;
  221. render::compositor* surface_compositor;
  222. render::ground_pass* ground_pass;
  223. // Scene utilities
  224. scene::collection* active_scene;
  225. // UI
  226. scene::collection* ui_scene;
  227. scene::camera* ui_camera;
  228. scene::billboard* camera_flash_billboard;
  229. float font_scale;
  230. bool dyslexia_font;
  231. float debug_font_size_pt;
  232. float menu_font_size_pt;
  233. float title_font_size_pt;
  234. std::vector<std::function<void()>> menu_select_callbacks;
  235. std::vector<std::function<void()>> menu_left_callbacks;
  236. std::vector<std::function<void()>> menu_right_callbacks;
  237. std::function<void()> menu_back_callback;
  238. std::vector<std::tuple<scene::text*, scene::text*>> menu_item_texts;
  239. std::unordered_map<std::string, int> menu_item_indices;
  240. int* menu_item_index;
  241. scene::billboard* menu_bg_billboard;
  242. animation<float>* menu_fade_animation;
  243. animation<float>* menu_bg_fade_in_animation;
  244. animation<float>* menu_bg_fade_out_animation;
  245. // Surface scene
  246. scene::collection* surface_scene;
  247. scene::camera* surface_camera;
  248. // Underground scene
  249. scene::collection* underground_scene;
  250. scene::camera* underground_camera;
  251. scene::ambient_light* underground_ambient_light;
  252. scene::spot_light* flashlight_spot_light;
  253. // Animation
  254. timeline* timeline;
  255. animator* animator;
  256. animation<float>* radial_transition_in;
  257. animation<float>* radial_transition_out;
  258. screen_transition* fade_transition;
  259. render::material_property<float3>* fade_transition_color;
  260. screen_transition* radial_transition_inner;
  261. screen_transition* radial_transition_outer;
  262. animation<float>* equip_tool_animation;
  263. animation<float>* unequip_tool_animation;
  264. animation<float>* camera_flash_animation;
  265. // Sound
  266. ALCdevice* alc_device;
  267. ALCcontext* alc_context;
  268. float master_volume;
  269. float ambience_volume;
  270. float effects_volume;
  271. bool mono_audio;
  272. bool captions;
  273. float captions_size;
  274. // Entities
  275. entity::registry* entity_registry;
  276. std::unordered_map<std::string, entity::id> entities;
  277. // Systems
  278. game::system::behavior* behavior_system;
  279. game::system::camera* camera_system;
  280. game::system::collision* collision_system;
  281. game::system::constraint* constraint_system;
  282. game::system::locomotion* locomotion_system;
  283. game::system::steering* steering_system;
  284. game::system::render* render_system;
  285. game::system::subterrain* subterrain_system;
  286. game::system::terrain* terrain_system;
  287. game::system::vegetation* vegetation_system;
  288. game::system::spring* spring_system;
  289. game::system::spatial* spatial_system;
  290. game::system::blackbody* blackbody_system;
  291. game::system::atmosphere* atmosphere_system;
  292. game::system::astronomy* astronomy_system;
  293. game::system::orbit* orbit_system;
  294. double3 rgb_wavelengths;
  295. const ecoregion* active_ecoregion;
  296. render::anti_aliasing_method anti_aliasing_method;
  297. std::shared_ptr<::event::subscription> ui_resize_subscription;
  298. };
  299. } // namespace game
  300. #endif // ANTKEEPER_GAME_CONTEXT_HPP