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

297 lines
8.1 KiB

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