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

370 lines
12 KiB

2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
  1. /*
  2. * Copyright (C) 2021 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 "utility/fundamental-types.hpp"
  22. #include "resources/string-table.hpp"
  23. #include "entity/id.hpp"
  24. #include "entity/registry.hpp"
  25. #include "geom/aabb.hpp"
  26. #include "gl/vertex-array.hpp"
  27. #include "gl/vertex-buffer.hpp"
  28. #include "gl/texture-2d.hpp"
  29. #include "gl/rasterizer.hpp"
  30. #include "gl/framebuffer.hpp"
  31. #include "input/control.hpp"
  32. #include "input/control-set.hpp"
  33. #include "input/listener.hpp"
  34. #include "input/mapper.hpp"
  35. #include "input/event-router.hpp"
  36. #include "animation/tween.hpp"
  37. #include "scene/scene.hpp"
  38. #include <optional>
  39. #include <entt/entt.hpp>
  40. #include <fstream>
  41. #include <queue>
  42. #include <string>
  43. #include <unordered_map>
  44. #include <vector>
  45. #include "resources/json.hpp"
  46. #include "type/typeface.hpp"
  47. #include "type/bitmap-font.hpp"
  48. #include "render/material.hpp"
  49. #include "render/material-property.hpp"
  50. #include "ui/mouse-tracker.hpp"
  51. // Forward declarations
  52. class animator;
  53. class application;
  54. class resource_manager;
  55. class screen_transition;
  56. class timeline;
  57. template <typename T> class animation;
  58. namespace debug
  59. {
  60. class cli;
  61. class logger;
  62. }
  63. namespace entity
  64. {
  65. namespace system
  66. {
  67. class subterrain;
  68. class terrain;
  69. class vegetation;
  70. class spatial;
  71. class painting;
  72. class astronomy;
  73. class blackbody;
  74. class atmosphere;
  75. class orbit;
  76. class behavior;
  77. class collision;
  78. class constraint;
  79. class locomotion;
  80. class snapping;
  81. class camera;
  82. class nest;
  83. class render;
  84. class samara;
  85. class proteome;
  86. }
  87. }
  88. namespace render
  89. {
  90. class bloom_pass;
  91. class clear_pass;
  92. class compositor;
  93. class final_pass;
  94. class material_pass;
  95. class renderer;
  96. class outline_pass;
  97. class shadow_map_pass;
  98. class simple_render_pass;
  99. class sky_pass;
  100. }
  101. namespace game {
  102. /// Structure containing the state of a game.
  103. struct context
  104. {
  105. application* app;
  106. debug::logger* logger;
  107. std::ofstream log_filestream;
  108. // Command-line options
  109. std::optional<bool> option_continue;
  110. std::optional<std::string> option_data;
  111. std::optional<bool> option_fullscreen;
  112. std::optional<bool> option_new_game;
  113. std::optional<bool> option_quick_start;
  114. std::optional<bool> option_reset;
  115. std::optional<int> option_v_sync;
  116. std::optional<bool> option_windowed;
  117. // Paths
  118. std::string data_path;
  119. std::string config_path;
  120. std::string mods_path;
  121. std::string saves_path;
  122. std::string screenshots_path;
  123. std::string controls_path;
  124. std::string data_package_path;
  125. // Configuration
  126. json* config;
  127. // Resources
  128. resource_manager* resource_manager;
  129. // Localization
  130. std::string language_code;
  131. int language_count;
  132. int language_index;
  133. string_table* string_table;
  134. string_table_map string_table_map;
  135. std::unordered_map<std::string, std::string>* strings;
  136. std::unordered_map<std::string, type::typeface*> typefaces;
  137. type::bitmap_font debug_font;
  138. type::bitmap_font menu_font;
  139. type::bitmap_font title_font;
  140. render::material debug_font_material;
  141. render::material menu_font_material;
  142. render::material title_font_material;
  143. // Framebuffers
  144. gl::framebuffer* shadow_map_framebuffer;
  145. gl::texture_2d* shadow_map_depth_texture;
  146. gl::framebuffer* framebuffer_hdr;
  147. gl::texture_2d* framebuffer_hdr_color;
  148. gl::texture_2d* framebuffer_hdr_depth;
  149. gl::framebuffer* framebuffer_bloom; // General purpose framebuffer A
  150. gl::texture_2d* bloom_texture;
  151. // Rendering
  152. gl::rasterizer* rasterizer;
  153. render::renderer* renderer;
  154. float render_resolution_scale;
  155. gl::vertex_buffer* billboard_vbo;
  156. gl::vertex_array* billboard_vao;
  157. render::material* fallback_material;
  158. render::material* splash_billboard_material;
  159. // Compositing
  160. render::clear_pass* ui_clear_pass;
  161. render::material_pass* ui_material_pass;
  162. render::compositor* ui_compositor;
  163. render::bloom_pass* common_bloom_pass;
  164. render::final_pass* common_final_pass;
  165. render::clear_pass* underground_clear_pass;
  166. render::material_pass* underground_material_pass;
  167. render::compositor* underground_compositor;
  168. render::clear_pass* surface_shadow_map_clear_pass;
  169. render::shadow_map_pass* surface_shadow_map_pass;
  170. render::clear_pass* surface_clear_pass;
  171. render::sky_pass* surface_sky_pass;
  172. render::material_pass* surface_material_pass;
  173. render::outline_pass* surface_outline_pass;
  174. render::compositor* surface_compositor;
  175. // Scene utilities
  176. scene::collection* active_scene;
  177. geom::aabb<float> no_cull;
  178. // UI scene
  179. scene::collection* ui_scene;
  180. scene::camera* ui_camera;
  181. scene::billboard* splash_billboard;
  182. scene::billboard* camera_flash_billboard;
  183. scene::text* title_text;
  184. scene::text* title_press_any_key_text;
  185. scene::text* main_menu_start_text;
  186. scene::text* main_menu_options_text;
  187. scene::text* main_menu_credits_text;
  188. scene::text* main_menu_quit_text;
  189. std::vector<scene::text*> main_menu_texts;
  190. int main_menu_index;
  191. scene::text* credits_text;
  192. scene::text* options_menu_controls_text;
  193. scene::text* options_menu_graphics_text;
  194. scene::text* options_menu_sound_text;
  195. scene::text* options_menu_language_text;
  196. scene::text* options_menu_back_text;
  197. std::vector<scene::text*> options_menu_texts;
  198. std::vector<std::function<void()>> options_menu_callbacks;
  199. int options_menu_index;
  200. scene::text* controls_menu_configure_keyboard_mouse_label_text;
  201. scene::text* controls_menu_configure_game_controller_label_text;
  202. scene::text* controls_menu_back_label_text;
  203. std::vector<scene::text*> controls_menu_label_texts;
  204. std::vector<scene::text*> controls_menu_value_texts;
  205. int controls_menu_index;
  206. std::vector<std::function<void()>> controls_menu_select_callbacks;
  207. std::vector<std::function<void()>> controls_menu_left_callbacks;
  208. std::vector<std::function<void()>> controls_menu_right_callbacks;
  209. scene::text* language_menu_language_text;
  210. scene::text* language_menu_back_text;
  211. std::vector<scene::text*> language_menu_texts;
  212. std::vector<std::function<void()>> language_menu_callbacks;
  213. int language_menu_index;
  214. scene::text* sound_menu_master_volume_label_text;
  215. scene::text* sound_menu_master_volume_value_text;
  216. scene::text* sound_menu_ambience_volume_label_text;
  217. scene::text* sound_menu_ambience_volume_value_text;
  218. scene::text* sound_menu_effects_volume_label_text;
  219. scene::text* sound_menu_effects_volume_value_text;
  220. scene::text* sound_menu_mono_audio_label_text;
  221. scene::text* sound_menu_mono_audio_value_text;
  222. scene::text* sound_menu_captions_label_text;
  223. scene::text* sound_menu_captions_value_text;
  224. scene::text* sound_menu_captions_size_label_text;
  225. scene::text* sound_menu_captions_size_value_text;
  226. scene::text* sound_menu_back_label_text;
  227. std::vector<scene::text*> sound_menu_label_texts;
  228. std::vector<scene::text*> sound_menu_value_texts;
  229. int sound_menu_index;
  230. std::vector<std::function<void()>> sound_menu_select_callbacks;
  231. std::vector<std::function<void()>> sound_menu_left_callbacks;
  232. std::vector<std::function<void()>> sound_menu_right_callbacks;
  233. scene::text* graphics_menu_display_mode_label_text;
  234. scene::text* graphics_menu_display_mode_value_text;
  235. scene::text* graphics_menu_render_resolution_label_text;
  236. scene::text* graphics_menu_render_resolution_value_text;
  237. scene::text* graphics_menu_v_sync_label_text;
  238. scene::text* graphics_menu_v_sync_value_text;
  239. scene::text* graphics_menu_font_size_label_text;
  240. scene::text* graphics_menu_font_size_value_text;
  241. scene::text* graphics_menu_dyslexia_font_label_text;
  242. scene::text* graphics_menu_dyslexia_font_value_text;
  243. scene::text* graphics_menu_back_label_text;
  244. std::vector<scene::text*> graphics_menu_label_texts;
  245. std::vector<scene::text*> graphics_menu_value_texts;
  246. int graphics_menu_index;
  247. std::vector<std::function<void()>> graphics_menu_select_callbacks;
  248. std::vector<std::function<void()>> graphics_menu_left_callbacks;
  249. std::vector<std::function<void()>> graphics_menu_right_callbacks;
  250. std::vector<scene::text*> keyboard_config_menu_label_texts;
  251. std::vector<scene::text*> keyboard_config_menu_value_texts;
  252. int keyboard_config_menu_index;
  253. std::vector<std::function<void()>> keyboard_config_menu_select_callbacks;
  254. std::vector<std::function<void()>> keyboard_config_menu_left_callbacks;
  255. std::vector<std::function<void()>> keyboard_config_menu_right_callbacks;
  256. float font_size;
  257. bool dyslexia_font;
  258. ui::mouse_tracker* menu_mouse_tracker;
  259. std::vector<std::function<void()>> menu_select_callbacks;
  260. std::vector<std::function<void()>> menu_left_callbacks;
  261. std::vector<std::function<void()>> menu_right_callbacks;
  262. std::function<void()> menu_back_callback;
  263. std::vector<std::tuple<scene::text*, scene::text*>> menu_item_texts;
  264. std::unordered_map<std::string, int> menu_item_indices;
  265. int* menu_item_index;
  266. // Surface scene
  267. scene::collection* surface_scene;
  268. scene::camera* surface_camera;
  269. // Underground scene
  270. scene::collection* underground_scene;
  271. scene::camera* underground_camera;
  272. scene::ambient_light* underground_ambient_light;
  273. scene::spot_light* flashlight_spot_light;
  274. // Animation
  275. timeline* timeline;
  276. animator* animator;
  277. animation<float>* radial_transition_in;
  278. animation<float>* radial_transition_out;
  279. screen_transition* fade_transition;
  280. render::material_property<float3>* fade_transition_color;
  281. screen_transition* radial_transition_inner;
  282. screen_transition* radial_transition_outer;
  283. animation<float>* equip_tool_animation;
  284. animation<float>* unequip_tool_animation;
  285. animation<float>* camera_flash_animation;
  286. animation<float>* splash_fade_in_animation;
  287. animation<float>* splash_fade_out_animation;
  288. animation<float>* title_fade_in_animation;
  289. animation<float>* title_fade_out_animation;
  290. animation<float>* title_press_any_key_animation;
  291. animation<float>* main_menu_fade_animation;
  292. animation<float>* credits_fade_in_animation;
  293. animation<float>* credits_scroll_animation;
  294. // Controls
  295. input::event_router* input_event_router;
  296. input::mapper* input_mapper;
  297. input::listener* input_listener;
  298. std::unordered_map<std::string, input::control*> controls;
  299. bool mouse_look;
  300. // Sound
  301. float master_volume;
  302. float ambience_volume;
  303. float effects_volume;
  304. bool mono_audio;
  305. bool captions;
  306. float captions_size;
  307. // Parallel processes
  308. std::unordered_map<std::string, std::function<void(double, double)>> processes;
  309. // Entities
  310. entity::registry* entity_registry;
  311. std::unordered_map<std::string, entity::id> entities;
  312. // Systems
  313. entity::system::behavior* behavior_system;
  314. entity::system::camera* camera_system;
  315. entity::system::collision* collision_system;
  316. entity::system::constraint* constraint_system;
  317. entity::system::locomotion* locomotion_system;
  318. entity::system::snapping* snapping_system;
  319. entity::system::render* render_system;
  320. entity::system::samara* samara_system;
  321. entity::system::subterrain* subterrain_system;
  322. entity::system::terrain* terrain_system;
  323. entity::system::vegetation* vegetation_system;
  324. entity::system::spatial* spatial_system;
  325. entity::system::painting* painting_system;
  326. entity::system::blackbody* blackbody_system;
  327. entity::system::atmosphere* atmosphere_system;
  328. entity::system::astronomy* astronomy_system;
  329. entity::system::orbit* orbit_system;
  330. entity::system::proteome* proteome_system;
  331. // Debug
  332. debug::cli* cli;
  333. };
  334. } // namespace game
  335. #endif // ANTKEEPER_GAME_CONTEXT_HPP