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

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