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

266 lines
7.1 KiB

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 "resources/json.hpp"
  45. #include "type/typeface.hpp"
  46. #include "type/bitmap-font.hpp"
  47. #include "render/material.hpp"
  48. #include "render/material-property.hpp"
  49. // Forward declarations
  50. class animator;
  51. class application;
  52. class resource_manager;
  53. class screen_transition;
  54. class timeline;
  55. template <typename T> class animation;
  56. namespace debug
  57. {
  58. class cli;
  59. class logger;
  60. }
  61. namespace entity
  62. {
  63. namespace system
  64. {
  65. class subterrain;
  66. class terrain;
  67. class vegetation;
  68. class spatial;
  69. class painting;
  70. class astronomy;
  71. class blackbody;
  72. class atmosphere;
  73. class orbit;
  74. class behavior;
  75. class collision;
  76. class constraint;
  77. class locomotion;
  78. class snapping;
  79. class camera;
  80. class nest;
  81. class render;
  82. class samara;
  83. class proteome;
  84. }
  85. }
  86. namespace render
  87. {
  88. class bloom_pass;
  89. class clear_pass;
  90. class compositor;
  91. class final_pass;
  92. class material_pass;
  93. class renderer;
  94. class outline_pass;
  95. class shadow_map_pass;
  96. class simple_render_pass;
  97. class sky_pass;
  98. }
  99. namespace game {
  100. /// Structure containing the state of a game.
  101. struct context
  102. {
  103. application* app;
  104. debug::logger* logger;
  105. std::ofstream log_filestream;
  106. // Command-line options
  107. std::optional<bool> option_continue;
  108. std::optional<std::string> option_data;
  109. std::optional<bool> option_fullscreen;
  110. std::optional<bool> option_new_game;
  111. std::optional<bool> option_quick_start;
  112. std::optional<bool> option_reset;
  113. std::optional<int> option_vsync;
  114. std::optional<bool> option_windowed;
  115. // Paths
  116. std::string data_path;
  117. std::string config_path;
  118. std::string mods_path;
  119. std::string saves_path;
  120. std::string screenshots_path;
  121. std::string controls_path;
  122. std::string data_package_path;
  123. // Configuration
  124. json* config;
  125. // Resources
  126. resource_manager* resource_manager;
  127. // Localization
  128. std::string language_code;
  129. int language_index;
  130. string_table* string_table;
  131. string_table_map string_table_map;
  132. std::unordered_map<std::string, std::string>* strings;
  133. std::unordered_map<std::string, type::typeface*> typefaces;
  134. type::bitmap_font debug_font;
  135. type::bitmap_font menu_font;
  136. type::bitmap_font title_font;
  137. render::material debug_font_material;
  138. render::material menu_font_material;
  139. render::material title_font_material;
  140. // Framebuffers
  141. gl::framebuffer* shadow_map_framebuffer;
  142. gl::texture_2d* shadow_map_depth_texture;
  143. gl::framebuffer* framebuffer_hdr;
  144. gl::texture_2d* framebuffer_hdr_color;
  145. gl::texture_2d* framebuffer_hdr_depth;
  146. gl::framebuffer* framebuffer_bloom; // General purpose framebuffer A
  147. gl::texture_2d* bloom_texture;
  148. // Rendering
  149. gl::rasterizer* rasterizer;
  150. render::renderer* renderer;
  151. gl::vertex_buffer* billboard_vbo;
  152. gl::vertex_array* billboard_vao;
  153. render::material* fallback_material;
  154. render::material* splash_billboard_material;
  155. // Compositing
  156. render::clear_pass* ui_clear_pass;
  157. render::material_pass* ui_material_pass;
  158. render::compositor* ui_compositor;
  159. render::bloom_pass* common_bloom_pass;
  160. render::final_pass* common_final_pass;
  161. render::clear_pass* underground_clear_pass;
  162. render::material_pass* underground_material_pass;
  163. render::compositor* underground_compositor;
  164. render::clear_pass* surface_shadow_map_clear_pass;
  165. render::shadow_map_pass* surface_shadow_map_pass;
  166. render::clear_pass* surface_clear_pass;
  167. render::sky_pass* surface_sky_pass;
  168. render::material_pass* surface_material_pass;
  169. render::outline_pass* surface_outline_pass;
  170. render::compositor* surface_compositor;
  171. // Scene utilities
  172. scene::collection* active_scene;
  173. geom::aabb<float> no_cull;
  174. // UI scene
  175. scene::collection* ui_scene;
  176. scene::camera* ui_camera;
  177. scene::billboard* splash_billboard;
  178. scene::billboard* camera_flash_billboard;
  179. // Surface scene
  180. scene::collection* surface_scene;
  181. scene::camera* surface_camera;
  182. // Underground scene
  183. scene::collection* underground_scene;
  184. scene::camera* underground_camera;
  185. scene::ambient_light* underground_ambient_light;
  186. scene::spot_light* flashlight_spot_light;
  187. // Animation
  188. timeline* timeline;
  189. animator* animator;
  190. animation<float>* radial_transition_in;
  191. animation<float>* radial_transition_out;
  192. screen_transition* fade_transition;
  193. render::material_property<float3>* fade_transition_color;
  194. screen_transition* radial_transition_inner;
  195. screen_transition* radial_transition_outer;
  196. animation<float>* equip_tool_animation;
  197. animation<float>* unequip_tool_animation;
  198. animation<float>* camera_flash_animation;
  199. // Controls
  200. input::event_router* input_event_router;
  201. input::mapper* input_mapper;
  202. input::listener* input_listener;
  203. std::unordered_map<std::string, input::control*> controls;
  204. bool mouse_look;
  205. // Parallel processes
  206. std::unordered_map<std::string, std::function<void(double, double)>> processes;
  207. // Entities
  208. entity::registry* entity_registry;
  209. std::unordered_map<std::string, entity::id> entities;
  210. // Systems
  211. entity::system::behavior* behavior_system;
  212. entity::system::camera* camera_system;
  213. entity::system::collision* collision_system;
  214. entity::system::constraint* constraint_system;
  215. entity::system::locomotion* locomotion_system;
  216. entity::system::snapping* snapping_system;
  217. entity::system::render* render_system;
  218. entity::system::samara* samara_system;
  219. entity::system::subterrain* subterrain_system;
  220. entity::system::terrain* terrain_system;
  221. entity::system::vegetation* vegetation_system;
  222. entity::system::spatial* spatial_system;
  223. entity::system::painting* painting_system;
  224. entity::system::blackbody* blackbody_system;
  225. entity::system::atmosphere* atmosphere_system;
  226. entity::system::astronomy* astronomy_system;
  227. entity::system::orbit* orbit_system;
  228. entity::system::proteome* proteome_system;
  229. // Debug
  230. debug::cli* cli;
  231. };
  232. } // namespace game
  233. #endif // ANTKEEPER_GAME_CONTEXT_HPP