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

304 lines
8.2 KiB

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