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

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