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

321 lines
8.7 KiB

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