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

311 lines
8.6 KiB

2 years 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 <queue>
  46. #include "resources/json.hpp"
  47. #include "type/typeface.hpp"
  48. #include "type/bitmap-font.hpp"
  49. #include "render/material.hpp"
  50. #include "render/material-property.hpp"
  51. #include "ui/mouse-tracker.hpp"
  52. #include "application.hpp"
  53. // Forward declarations
  54. class animator;
  55. class application;
  56. class resource_manager;
  57. class screen_transition;
  58. class timeline;
  59. template <typename T> class animation;
  60. namespace debug
  61. {
  62. class cli;
  63. class logger;
  64. }
  65. namespace entity
  66. {
  67. namespace system
  68. {
  69. class subterrain;
  70. class terrain;
  71. class vegetation;
  72. class spatial;
  73. class painting;
  74. class astronomy;
  75. class blackbody;
  76. class atmosphere;
  77. class orbit;
  78. class behavior;
  79. class collision;
  80. class constraint;
  81. class locomotion;
  82. class snapping;
  83. class camera;
  84. class nest;
  85. class render;
  86. class samara;
  87. class proteome;
  88. }
  89. }
  90. namespace render
  91. {
  92. class bloom_pass;
  93. class clear_pass;
  94. class compositor;
  95. class final_pass;
  96. class material_pass;
  97. class renderer;
  98. class outline_pass;
  99. class shadow_map_pass;
  100. class simple_render_pass;
  101. class sky_pass;
  102. }
  103. namespace game {
  104. /// Container for data that is shared between game states.
  105. struct context
  106. {
  107. application* app;
  108. debug::logger* logger;
  109. std::ofstream log_filestream;
  110. // Command-line options
  111. std::optional<bool> option_continue;
  112. std::optional<std::string> option_data;
  113. std::optional<bool> option_fullscreen;
  114. std::optional<bool> option_new_game;
  115. std::optional<bool> option_quick_start;
  116. std::optional<bool> option_reset;
  117. std::optional<int> option_v_sync;
  118. std::optional<bool> option_windowed;
  119. // Paths
  120. std::string data_path;
  121. std::string config_path;
  122. std::string mods_path;
  123. std::string saves_path;
  124. std::string screenshots_path;
  125. std::string controls_path;
  126. std::string data_package_path;
  127. // Configuration
  128. json* config;
  129. // Resources
  130. resource_manager* resource_manager;
  131. // Localization
  132. std::string language_code;
  133. int language_count;
  134. int language_index;
  135. string_table* string_table;
  136. string_table_map string_table_map;
  137. std::unordered_map<std::string, std::string>* strings;
  138. std::unordered_map<std::string, type::typeface*> typefaces;
  139. type::bitmap_font debug_font;
  140. type::bitmap_font menu_font;
  141. type::bitmap_font title_font;
  142. render::material debug_font_material;
  143. render::material menu_font_material;
  144. render::material title_font_material;
  145. // Framebuffers
  146. gl::texture_2d* hdr_color_texture;
  147. gl::texture_2d* hdr_depth_texture;
  148. gl::framebuffer* hdr_framebuffer;
  149. gl::texture_2d* bloom_color_texture;
  150. gl::framebuffer* bloom_framebuffer;
  151. gl::texture_2d* shadow_map_depth_texture;
  152. gl::framebuffer* shadow_map_framebuffer;
  153. // Rendering
  154. gl::rasterizer* rasterizer;
  155. render::renderer* renderer;
  156. int2 render_resolution;
  157. float render_resolution_scale;
  158. gl::vertex_buffer* billboard_vbo;
  159. gl::vertex_array* billboard_vao;
  160. render::material* fallback_material;
  161. render::material* splash_billboard_material;
  162. // Compositing
  163. render::clear_pass* ui_clear_pass;
  164. render::material_pass* ui_material_pass;
  165. render::compositor* ui_compositor;
  166. render::bloom_pass* common_bloom_pass;
  167. render::final_pass* common_final_pass;
  168. render::clear_pass* underground_clear_pass;
  169. render::material_pass* underground_material_pass;
  170. render::compositor* underground_compositor;
  171. render::clear_pass* surface_shadow_map_clear_pass;
  172. render::shadow_map_pass* surface_shadow_map_pass;
  173. render::clear_pass* surface_clear_pass;
  174. render::sky_pass* surface_sky_pass;
  175. render::material_pass* surface_material_pass;
  176. render::outline_pass* surface_outline_pass;
  177. render::compositor* surface_compositor;
  178. // Scene utilities
  179. scene::collection* active_scene;
  180. geom::aabb<float> no_cull;
  181. // UI scene
  182. scene::collection* ui_scene;
  183. scene::camera* ui_camera;
  184. scene::billboard* splash_billboard;
  185. scene::billboard* camera_flash_billboard;
  186. scene::text* title_text;
  187. scene::text* title_press_any_key_text;
  188. scene::text* credits_text;
  189. float font_size;
  190. bool dyslexia_font;
  191. ui::mouse_tracker* menu_mouse_tracker;
  192. std::vector<std::function<void()>> menu_select_callbacks;
  193. std::vector<std::function<void()>> menu_left_callbacks;
  194. std::vector<std::function<void()>> menu_right_callbacks;
  195. std::function<void()> menu_back_callback;
  196. std::vector<std::tuple<scene::text*, scene::text*>> menu_item_texts;
  197. std::unordered_map<std::string, int> menu_item_indices;
  198. int* menu_item_index;
  199. animation<float>* menu_fade_animation;
  200. animation<float>* title_fade_animation;
  201. scene::billboard* menu_bg_billboard;
  202. // Surface scene
  203. scene::collection* surface_scene;
  204. scene::camera* surface_camera;
  205. // Underground scene
  206. scene::collection* underground_scene;
  207. scene::camera* underground_camera;
  208. scene::ambient_light* underground_ambient_light;
  209. scene::spot_light* flashlight_spot_light;
  210. // Animation
  211. timeline* timeline;
  212. animator* animator;
  213. animation<float>* radial_transition_in;
  214. animation<float>* radial_transition_out;
  215. screen_transition* fade_transition;
  216. render::material_property<float3>* fade_transition_color;
  217. screen_transition* radial_transition_inner;
  218. screen_transition* radial_transition_outer;
  219. animation<float>* equip_tool_animation;
  220. animation<float>* unequip_tool_animation;
  221. animation<float>* camera_flash_animation;
  222. animation<float>* splash_fade_in_animation;
  223. animation<float>* splash_fade_out_animation;
  224. animation<float>* title_fade_in_animation;
  225. animation<float>* title_fade_out_animation;
  226. animation<float>* title_press_any_key_animation;
  227. animation<float>* main_menu_fade_animation;
  228. animation<float>* credits_fade_in_animation;
  229. animation<float>* credits_scroll_animation;
  230. animation<float>* menu_bg_fade_in_animation;
  231. animation<float>* menu_bg_fade_out_animation;
  232. // Controls
  233. input::event_router* input_event_router;
  234. input::mapper* input_mapper;
  235. input::listener* input_listener;
  236. std::unordered_map<std::string, input::control*> controls;
  237. bool mouse_look;
  238. // Sound
  239. float master_volume;
  240. float ambience_volume;
  241. float effects_volume;
  242. bool mono_audio;
  243. bool captions;
  244. float captions_size;
  245. // Parallel processes
  246. std::unordered_map<std::string, std::function<void(double, double)>> processes;
  247. // Entities
  248. entity::registry* entity_registry;
  249. std::unordered_map<std::string, entity::id> entities;
  250. // Systems
  251. entity::system::behavior* behavior_system;
  252. entity::system::camera* camera_system;
  253. entity::system::collision* collision_system;
  254. entity::system::constraint* constraint_system;
  255. entity::system::locomotion* locomotion_system;
  256. entity::system::snapping* snapping_system;
  257. entity::system::render* render_system;
  258. entity::system::samara* samara_system;
  259. entity::system::subterrain* subterrain_system;
  260. entity::system::terrain* terrain_system;
  261. entity::system::vegetation* vegetation_system;
  262. entity::system::spatial* spatial_system;
  263. entity::system::painting* painting_system;
  264. entity::system::blackbody* blackbody_system;
  265. entity::system::atmosphere* atmosphere_system;
  266. entity::system::astronomy* astronomy_system;
  267. entity::system::orbit* orbit_system;
  268. entity::system::proteome* proteome_system;
  269. // State management
  270. std::optional<application::state> paused_state;
  271. // Misc
  272. std::queue<std::function<void()>> function_queue;
  273. // Debug
  274. debug::cli* cli;
  275. };
  276. } // namespace game
  277. #endif // ANTKEEPER_GAME_CONTEXT_HPP