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

1097 lines
39 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
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. #include "game/states/boot.hpp"
  20. #include "animation/animation.hpp"
  21. #include "animation/animator.hpp"
  22. #include "animation/ease.hpp"
  23. #include "animation/screen-transition.hpp"
  24. #include "animation/timeline.hpp"
  25. #include "application.hpp"
  26. #include "debug/cli.hpp"
  27. #include "debug/console-commands.hpp"
  28. #include "debug/logger.hpp"
  29. #include "game/context.hpp"
  30. #include "gl/framebuffer.hpp"
  31. #include "gl/pixel-format.hpp"
  32. #include "gl/pixel-type.hpp"
  33. #include "gl/rasterizer.hpp"
  34. #include "gl/texture-2d.hpp"
  35. #include "gl/texture-filter.hpp"
  36. #include "gl/texture-wrapping.hpp"
  37. #include "gl/vertex-array.hpp"
  38. #include "gl/vertex-attribute.hpp"
  39. #include "gl/vertex-buffer.hpp"
  40. #include "render/material-flags.hpp"
  41. #include "render/material-property.hpp"
  42. #include "render/passes/bloom-pass.hpp"
  43. #include "render/passes/clear-pass.hpp"
  44. #include "render/passes/final-pass.hpp"
  45. #include "render/passes/material-pass.hpp"
  46. #include "render/passes/outline-pass.hpp"
  47. #include "render/passes/shadow-map-pass.hpp"
  48. #include "render/passes/sky-pass.hpp"
  49. #include "render/passes/simple-pass.hpp"
  50. #include "render/vertex-attribute.hpp"
  51. #include "render/compositor.hpp"
  52. #include "render/renderer.hpp"
  53. #include "resources/resource-manager.hpp"
  54. #include "resources/file-buffer.hpp"
  55. #include "scene/scene.hpp"
  56. #include "game/states/loading.hpp"
  57. #include "entity/systems/behavior.hpp"
  58. #include "entity/systems/camera.hpp"
  59. #include "entity/systems/collision.hpp"
  60. #include "entity/systems/constraint.hpp"
  61. #include "entity/systems/locomotion.hpp"
  62. #include "entity/systems/snapping.hpp"
  63. #include "entity/systems/render.hpp"
  64. #include "entity/systems/samara.hpp"
  65. #include "entity/systems/subterrain.hpp"
  66. #include "entity/systems/terrain.hpp"
  67. #include "entity/systems/vegetation.hpp"
  68. #include "entity/systems/spatial.hpp"
  69. #include "entity/systems/painting.hpp"
  70. #include "entity/systems/astronomy.hpp"
  71. #include "entity/systems/blackbody.hpp"
  72. #include "entity/systems/atmosphere.hpp"
  73. #include "entity/systems/orbit.hpp"
  74. #include "entity/systems/proteome.hpp"
  75. #include "entity/commands.hpp"
  76. #include "utility/paths.hpp"
  77. #include "event/event-dispatcher.hpp"
  78. #include "input/event-router.hpp"
  79. #include "input/mapper.hpp"
  80. #include "input/listener.hpp"
  81. #include "input/gamepad.hpp"
  82. #include "input/mouse.hpp"
  83. #include "input/keyboard.hpp"
  84. #include "configuration.hpp"
  85. #include "input/scancode.hpp"
  86. #include <cxxopts.hpp>
  87. #include <dirent.h>
  88. #include <entt/entt.hpp>
  89. #include <filesystem>
  90. #include <functional>
  91. #include <string>
  92. #include <vector>
  93. #include <execution>
  94. #include <algorithm>
  95. namespace game {
  96. namespace state {
  97. namespace boot {
  98. static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
  99. static void parse_options(game::context* ctx, int argc, char** argv);
  100. static void setup_resources(game::context* ctx);
  101. static void load_config(game::context* ctx);
  102. static void load_strings(game::context* ctx);
  103. static void setup_window(game::context* ctx);
  104. static void setup_rendering(game::context* ctx);
  105. static void setup_sound(game::context* ctx);
  106. static void setup_scenes(game::context* ctx);
  107. static void setup_animation(game::context* ctx);
  108. static void setup_entities(game::context* ctx);
  109. static void setup_systems(game::context* ctx);
  110. static void setup_controls(game::context* ctx);
  111. static void setup_ui(game::context* ctx);
  112. static void setup_cli(game::context* ctx);
  113. static void setup_callbacks(game::context* ctx);
  114. void enter(application* app, int argc, char** argv)
  115. {
  116. // Get application logger
  117. debug::logger* logger = app->get_logger();
  118. // Allocate game context
  119. game::context* ctx = new game::context();
  120. ctx->app = app;
  121. ctx->logger = logger;
  122. // Init game context
  123. try
  124. {
  125. parse_options(ctx, argc, argv);
  126. setup_resources(ctx);
  127. load_config(ctx);
  128. load_strings(ctx);
  129. setup_window(ctx);
  130. setup_rendering(ctx);
  131. setup_sound(ctx);
  132. setup_scenes(ctx);
  133. setup_animation(ctx);
  134. setup_entities(ctx);
  135. setup_systems(ctx);
  136. setup_controls(ctx);
  137. setup_ui(ctx);
  138. setup_cli(ctx);
  139. setup_callbacks(ctx);
  140. }
  141. catch (const std::exception& e)
  142. {
  143. logger->error("Caught exception: \"" + std::string(e.what()) + "\"");
  144. logger->pop_task(EXIT_FAILURE);
  145. return;
  146. }
  147. // Set update rate
  148. if (ctx->config->contains("update_rate"))
  149. {
  150. app->set_update_rate((*ctx->config)["update_rate"].get<double>());
  151. }
  152. // Queue next application state
  153. application::state next_state;
  154. next_state.name = "loading";
  155. next_state.enter = std::bind(game::state::loading::enter, ctx);
  156. next_state.exit = std::bind(game::state::loading::exit, ctx);
  157. app->queue_state(next_state);
  158. }
  159. void exit(application* app)
  160. {}
  161. void parse_options(game::context* ctx, int argc, char** argv)
  162. {
  163. debug::logger* logger = ctx->logger;
  164. logger->push_task("Parsing command line options");
  165. try
  166. {
  167. cxxopts::Options options("Antkeeper", "Ant colony simulation game");
  168. options.add_options()
  169. ("c,continue", "Continues from the last save")
  170. ("d,data", "Sets the data package path", cxxopts::value<std::string>())
  171. ("f,fullscreen", "Starts in fullscreen mode")
  172. ("n,new-game", "Starts a new game")
  173. ("q,quick-start", "Skips to the main menu")
  174. ("r,reset", "Restores all settings to default")
  175. ("v,vsync", "Enables or disables v-sync", cxxopts::value<int>())
  176. ("w,windowed", "Starts in windowed mode");
  177. auto result = options.parse(argc, argv);
  178. // --continue
  179. if (result.count("continue"))
  180. ctx->option_continue = true;
  181. // --data
  182. if (result.count("data"))
  183. ctx->option_data = result["data"].as<std::string>();
  184. // --fullscreen
  185. if (result.count("fullscreen"))
  186. ctx->option_fullscreen = true;
  187. // --new-game
  188. if (result.count("new-game"))
  189. ctx->option_new_game = true;
  190. // --quick-start
  191. if (result.count("quick-start"))
  192. ctx->option_quick_start = true;
  193. // --reset
  194. if (result.count("reset"))
  195. ctx->option_reset = true;
  196. // --vsync
  197. if (result.count("vsync"))
  198. ctx->option_vsync = (result["vsync"].as<int>()) ? true : false;
  199. // --windowed
  200. if (result.count("windowed"))
  201. ctx->option_windowed = true;
  202. }
  203. catch (const std::exception& e)
  204. {
  205. logger->error("Exception caught: \"" + std::string(e.what()) + "\"");
  206. logger->pop_task(EXIT_FAILURE);
  207. return;
  208. }
  209. logger->pop_task(EXIT_SUCCESS);
  210. }
  211. void setup_resources(game::context* ctx)
  212. {
  213. debug::logger* logger = ctx->logger;
  214. // Setup resource manager
  215. ctx->resource_manager = new resource_manager(logger);
  216. // Determine application name
  217. std::string application_name;
  218. #if defined(_WIN32) || defined(__APPLE__)
  219. application_name = "Antkeeper";
  220. #else
  221. application_name = "antkeeper";
  222. #endif
  223. // Detect paths
  224. ctx->data_path = get_data_path(application_name);
  225. ctx->config_path = get_config_path(application_name);
  226. ctx->mods_path = ctx->config_path + "mods/";
  227. ctx->saves_path = ctx->config_path + "saves/";
  228. ctx->screenshots_path = ctx->config_path + "gallery/";
  229. ctx->controls_path = ctx->config_path + "controls/";
  230. // Log resource paths
  231. logger->log("Detected data path as \"" + ctx->data_path + "\"");
  232. logger->log("Detected config path as \"" + ctx->config_path + "\"");
  233. // Create nonexistent config directories
  234. std::vector<std::string> config_paths;
  235. config_paths.push_back(ctx->config_path);
  236. config_paths.push_back(ctx->mods_path);
  237. config_paths.push_back(ctx->saves_path);
  238. config_paths.push_back(ctx->screenshots_path);
  239. config_paths.push_back(ctx->controls_path);
  240. for (const std::string& path: config_paths)
  241. {
  242. if (!path_exists(path))
  243. {
  244. logger->push_task("Creating directory \"" + path + "\"");
  245. if (create_directory(path))
  246. {
  247. logger->pop_task(EXIT_SUCCESS);
  248. }
  249. else
  250. {
  251. logger->pop_task(EXIT_FAILURE);
  252. }
  253. }
  254. }
  255. // Redirect logger output to log file on non-debug builds
  256. #if defined(NDEBUG)
  257. std::string log_filename = ctx->config_path + "log.txt";
  258. ctx->log_filestream.open(log_filename.c_str());
  259. ctx->log_filestream << logger->get_history();
  260. logger->redirect(&ctx->log_filestream);
  261. #endif
  262. // Scan for mods
  263. std::vector<std::string> mods;
  264. struct dirent** files = nullptr;
  265. if (int n = scandir(ctx->mods_path.c_str(), &files, NULL, alphasort); n >= 0)
  266. {
  267. for (int i = 0; i < n; ++i)
  268. {
  269. struct dirent* file = files[i];
  270. switch (file->d_type)
  271. {
  272. case DT_REG:
  273. case DT_DIR:
  274. {
  275. std::string mod_name = file->d_name;
  276. // Skip hidden files and directories
  277. if (mod_name.front() == '.')
  278. break;
  279. mods.push_back(mod_name);
  280. }
  281. default:
  282. break;
  283. }
  284. }
  285. }
  286. // Determine data package path
  287. if (ctx->option_data.has_value())
  288. {
  289. ctx->data_package_path = ctx->option_data.value();
  290. if (std::filesystem::path(ctx->data_package_path).is_relative())
  291. ctx->data_package_path = ctx->data_path + ctx->data_package_path;
  292. }
  293. else
  294. {
  295. ctx->data_package_path = ctx->data_path + "data.zip";
  296. }
  297. // Mount mods
  298. for (const std::string& mod_name: mods)
  299. ctx->resource_manager->mount(ctx->mods_path + mod_name);
  300. // Mount config path
  301. ctx->resource_manager->mount(ctx->config_path);
  302. // Mount data package
  303. ctx->resource_manager->mount(ctx->data_package_path);
  304. // Include resource search paths in order of priority
  305. ctx->resource_manager->include("/shaders/");
  306. ctx->resource_manager->include("/models/");
  307. ctx->resource_manager->include("/images/");
  308. ctx->resource_manager->include("/textures/");
  309. ctx->resource_manager->include("/materials/");
  310. ctx->resource_manager->include("/entities/");
  311. ctx->resource_manager->include("/behaviors/");
  312. ctx->resource_manager->include("/controls/");
  313. ctx->resource_manager->include("/localization/");
  314. ctx->resource_manager->include("/localization/fonts/");
  315. ctx->resource_manager->include("/biomes/");
  316. ctx->resource_manager->include("/traits/");
  317. ctx->resource_manager->include("/");
  318. }
  319. void load_config(game::context* ctx)
  320. {
  321. debug::logger* logger = ctx->logger;
  322. logger->push_task("Loading config");
  323. // Load config file
  324. ctx->config = ctx->resource_manager->load<json>("config.json");
  325. if (!ctx->config)
  326. {
  327. logger->pop_task(EXIT_FAILURE);
  328. return;
  329. }
  330. logger->pop_task(EXIT_SUCCESS);
  331. }
  332. void load_strings(game::context* ctx)
  333. {
  334. debug::logger* logger = ctx->logger;
  335. logger->push_task("Loading strings");
  336. ctx->string_table = ctx->resource_manager->load<string_table>("strings.csv");
  337. build_string_table_map(&ctx->string_table_map, *ctx->string_table);
  338. ctx->language_code = (*ctx->config)["language"].get<std::string>();
  339. ctx->language_index = -1;
  340. for (int i = 2; i < (*ctx->string_table)[0].size(); ++i)
  341. {
  342. if ((*ctx->string_table)[0][i] == ctx->language_code)
  343. ctx->language_index = i - 2;
  344. }
  345. ctx->language_count = (*ctx->string_table)[0].size() - 2;
  346. logger->log("language count: " + std::to_string(ctx->language_count));
  347. logger->log("language index: " + std::to_string(ctx->language_index));
  348. logger->log("language code: " + ctx->language_code);
  349. ctx->strings = &ctx->string_table_map[ctx->language_code];
  350. logger->pop_task(EXIT_SUCCESS);
  351. }
  352. void setup_window(game::context* ctx)
  353. {
  354. debug::logger* logger = ctx->logger;
  355. logger->push_task("Setting up window");
  356. application* app = ctx->app;
  357. json* config = ctx->config;
  358. // Set fullscreen or windowed mode
  359. bool fullscreen = true;
  360. if (ctx->option_fullscreen.has_value())
  361. fullscreen = true;
  362. else if (ctx->option_windowed.has_value())
  363. fullscreen = false;
  364. else if (config->contains("fullscreen"))
  365. fullscreen = (*config)["fullscreen"].get<bool>();
  366. app->set_fullscreen(fullscreen);
  367. // Set resolution
  368. const auto& display_dimensions = ctx->app->get_display_dimensions();
  369. int2 resolution = {display_dimensions[0], display_dimensions[1]};
  370. if (fullscreen)
  371. {
  372. if (config->contains("fullscreen_resolution"))
  373. {
  374. resolution.x = (*config)["fullscreen_resolution"][0].get<int>();
  375. resolution.y = (*config)["fullscreen_resolution"][1].get<int>();
  376. }
  377. }
  378. else
  379. {
  380. if (config->contains("windowed_resolution"))
  381. {
  382. resolution.x = (*config)["windowed_resolution"][0].get<int>();
  383. resolution.y = (*config)["windowed_resolution"][1].get<int>();
  384. }
  385. }
  386. app->resize_window(resolution.x, resolution.y);
  387. // Set v-sync
  388. bool vsync = true;
  389. if (ctx->option_vsync.has_value())
  390. vsync = (ctx->option_vsync.value() != 0);
  391. else if (config->contains("vsync"))
  392. vsync = (*config)["vsync"].get<bool>();
  393. app->set_vsync(vsync);
  394. // Set title
  395. app->set_title((*ctx->strings)["application_title"]);
  396. // Show window
  397. ctx->app->get_rasterizer()->set_clear_color(0.0f, 0.0f, 0.0f, 1.0f);
  398. ctx->app->get_rasterizer()->clear_framebuffer(true, false, false);
  399. app->show_window();
  400. ctx->app->swap_buffers();
  401. logger->pop_task(EXIT_SUCCESS);
  402. }
  403. void setup_rendering(game::context* ctx)
  404. {
  405. debug::logger* logger = ctx->logger;
  406. logger->push_task("Setting up rendering");
  407. // Get rasterizer from application
  408. ctx->rasterizer = ctx->app->get_rasterizer();
  409. // Load render resolution
  410. ctx->render_resolution_scale = 1.0f;
  411. if (ctx->config->contains("render_resolution"))
  412. ctx->render_resolution_scale = (*ctx->config)["render_resolution"].get<float>();
  413. // Get default framebuffer
  414. const gl::framebuffer& default_framebuffer = ctx->rasterizer->get_default_framebuffer();
  415. const auto& viewport_dimensions = default_framebuffer.get_dimensions();
  416. // Create HDR framebuffer (32F color, 32F depth)
  417. ctx->framebuffer_hdr_color = new gl::texture_2d(viewport_dimensions[0], viewport_dimensions[1], gl::pixel_type::float_32, gl::pixel_format::rgb);
  418. ctx->framebuffer_hdr_color->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend);
  419. ctx->framebuffer_hdr_color->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
  420. ctx->framebuffer_hdr_color->set_max_anisotropy(0.0f);
  421. ctx->framebuffer_hdr_depth = new gl::texture_2d(viewport_dimensions[0], viewport_dimensions[1], gl::pixel_type::float_32, gl::pixel_format::ds);
  422. ctx->framebuffer_hdr_depth->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend);
  423. ctx->framebuffer_hdr_depth->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
  424. ctx->framebuffer_hdr_depth->set_max_anisotropy(0.0f);
  425. ctx->framebuffer_hdr = new gl::framebuffer(viewport_dimensions[0], viewport_dimensions[1]);
  426. ctx->framebuffer_hdr->attach(gl::framebuffer_attachment_type::color, ctx->framebuffer_hdr_color);
  427. ctx->framebuffer_hdr->attach(gl::framebuffer_attachment_type::depth, ctx->framebuffer_hdr_depth);
  428. ctx->framebuffer_hdr->attach(gl::framebuffer_attachment_type::stencil, ctx->framebuffer_hdr_depth);
  429. // Create shadow map framebuffer
  430. int shadow_map_resolution = 4096;
  431. if (ctx->config->contains("shadow_map_resolution"))
  432. {
  433. shadow_map_resolution = (*ctx->config)["shadow_map_resolution"].get<int>();
  434. }
  435. ctx->shadow_map_depth_texture = new gl::texture_2d(shadow_map_resolution, shadow_map_resolution, gl::pixel_type::float_32, gl::pixel_format::d);
  436. ctx->shadow_map_depth_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend);
  437. ctx->shadow_map_depth_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
  438. ctx->shadow_map_depth_texture->set_max_anisotropy(0.0f);
  439. ctx->shadow_map_framebuffer = new gl::framebuffer(shadow_map_resolution, shadow_map_resolution);
  440. ctx->shadow_map_framebuffer->attach(gl::framebuffer_attachment_type::depth, ctx->shadow_map_depth_texture);
  441. // Create bloom pingpong framebuffers (16F color, no depth)
  442. int bloom_width = viewport_dimensions[0] >> 1;
  443. int bloom_height = viewport_dimensions[1] >> 1;
  444. ctx->bloom_texture = new gl::texture_2d(bloom_width, bloom_height, gl::pixel_type::float_16, gl::pixel_format::rgb);
  445. ctx->bloom_texture->set_wrapping(gl::texture_wrapping::extend, gl::texture_wrapping::extend);
  446. ctx->bloom_texture->set_filters(gl::texture_min_filter::linear, gl::texture_mag_filter::linear);
  447. ctx->bloom_texture->set_max_anisotropy(0.0f);
  448. ctx->framebuffer_bloom = new gl::framebuffer(bloom_width, bloom_height);
  449. ctx->framebuffer_bloom->attach(gl::framebuffer_attachment_type::color, ctx->bloom_texture);
  450. // Load blue noise texture
  451. gl::texture_2d* blue_noise_map = ctx->resource_manager->load<gl::texture_2d>("blue-noise.tex");
  452. // Load fallback material
  453. ctx->fallback_material = ctx->resource_manager->load<render::material>("fallback.mtl");
  454. // Setup common render passes
  455. {
  456. ctx->common_bloom_pass = new render::bloom_pass(ctx->rasterizer, ctx->framebuffer_bloom, ctx->resource_manager);
  457. ctx->common_bloom_pass->set_source_texture(ctx->framebuffer_hdr_color);
  458. ctx->common_bloom_pass->set_brightness_threshold(1.0f);
  459. ctx->common_bloom_pass->set_blur_iterations(5);
  460. ctx->common_final_pass = new render::final_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
  461. ctx->common_final_pass->set_color_texture(ctx->framebuffer_hdr_color);
  462. ctx->common_final_pass->set_bloom_texture(ctx->bloom_texture);
  463. ctx->common_final_pass->set_blue_noise_texture(blue_noise_map);
  464. }
  465. // Setup UI compositor
  466. {
  467. ctx->ui_clear_pass = new render::clear_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer());
  468. ctx->ui_clear_pass->set_cleared_buffers(false, true, false);
  469. ctx->ui_clear_pass->set_clear_depth(0.0f);
  470. ctx->ui_material_pass = new render::material_pass(ctx->rasterizer, &ctx->rasterizer->get_default_framebuffer(), ctx->resource_manager);
  471. ctx->ui_material_pass->set_fallback_material(ctx->fallback_material);
  472. ctx->ui_compositor = new render::compositor();
  473. ctx->ui_compositor->add_pass(ctx->ui_clear_pass);
  474. ctx->ui_compositor->add_pass(ctx->ui_material_pass);
  475. }
  476. // Setup underground compositor
  477. {
  478. ctx->underground_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
  479. ctx->underground_clear_pass->set_cleared_buffers(true, true, false);
  480. ctx->underground_clear_pass->set_clear_color({1, 0, 1, 0});
  481. ctx->underground_clear_pass->set_clear_depth(0.0f);
  482. ctx->underground_material_pass = new render::material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
  483. ctx->underground_material_pass->set_fallback_material(ctx->fallback_material);
  484. ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->underground_material_pass);
  485. ctx->underground_compositor = new render::compositor();
  486. ctx->underground_compositor->add_pass(ctx->underground_clear_pass);
  487. ctx->underground_compositor->add_pass(ctx->underground_material_pass);
  488. ctx->underground_compositor->add_pass(ctx->common_bloom_pass);
  489. ctx->underground_compositor->add_pass(ctx->common_final_pass);
  490. }
  491. // Setup surface compositor
  492. {
  493. ctx->surface_shadow_map_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->shadow_map_framebuffer);
  494. ctx->surface_shadow_map_clear_pass->set_cleared_buffers(false, true, false);
  495. ctx->surface_shadow_map_clear_pass->set_clear_depth(1.0f);
  496. ctx->surface_shadow_map_pass = new render::shadow_map_pass(ctx->rasterizer, ctx->shadow_map_framebuffer, ctx->resource_manager);
  497. ctx->surface_shadow_map_pass->set_split_scheme_weight(0.75f);
  498. ctx->surface_clear_pass = new render::clear_pass(ctx->rasterizer, ctx->framebuffer_hdr);
  499. ctx->surface_clear_pass->set_cleared_buffers(true, true, true);
  500. ctx->surface_clear_pass->set_clear_depth(0.0f);
  501. ctx->surface_sky_pass = new render::sky_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
  502. ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->surface_sky_pass);
  503. ctx->surface_material_pass = new render::material_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
  504. ctx->surface_material_pass->set_fallback_material(ctx->fallback_material);
  505. ctx->surface_material_pass->shadow_map_pass = ctx->surface_shadow_map_pass;
  506. ctx->surface_material_pass->shadow_map = ctx->shadow_map_depth_texture;
  507. ctx->app->get_event_dispatcher()->subscribe<mouse_moved_event>(ctx->surface_material_pass);
  508. ctx->surface_outline_pass = new render::outline_pass(ctx->rasterizer, ctx->framebuffer_hdr, ctx->resource_manager);
  509. ctx->surface_outline_pass->set_outline_width(0.25f);
  510. ctx->surface_outline_pass->set_outline_color(float4{1.0f, 1.0f, 1.0f, 1.0f});
  511. ctx->surface_compositor = new render::compositor();
  512. ctx->surface_compositor->add_pass(ctx->surface_shadow_map_clear_pass);
  513. ctx->surface_compositor->add_pass(ctx->surface_shadow_map_pass);
  514. ctx->surface_compositor->add_pass(ctx->surface_clear_pass);
  515. ctx->surface_compositor->add_pass(ctx->surface_sky_pass);
  516. ctx->surface_compositor->add_pass(ctx->surface_material_pass);
  517. //ctx->surface_compositor->add_pass(ctx->surface_outline_pass);
  518. ctx->surface_compositor->add_pass(ctx->common_bloom_pass);
  519. ctx->surface_compositor->add_pass(ctx->common_final_pass);
  520. }
  521. // Create billboard VAO
  522. {
  523. const float billboard_vertex_data[] =
  524. {
  525. -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
  526. -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
  527. 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
  528. 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,
  529. -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
  530. 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f
  531. };
  532. std::size_t billboard_vertex_size = 8;
  533. std::size_t billboard_vertex_stride = sizeof(float) * billboard_vertex_size;
  534. std::size_t billboard_vertex_count = 6;
  535. ctx->billboard_vbo = new gl::vertex_buffer(sizeof(float) * billboard_vertex_size * billboard_vertex_count, billboard_vertex_data);
  536. ctx->billboard_vao = new gl::vertex_array();
  537. std::size_t attribute_offset = 0;
  538. // Define position vertex attribute
  539. gl::vertex_attribute position_attribute;
  540. position_attribute.buffer = ctx->billboard_vbo;
  541. position_attribute.offset = attribute_offset;
  542. position_attribute.stride = billboard_vertex_stride;
  543. position_attribute.type = gl::vertex_attribute_type::float_32;
  544. position_attribute.components = 3;
  545. attribute_offset += position_attribute.components * sizeof(float);
  546. // Define UV vertex attribute
  547. gl::vertex_attribute uv_attribute;
  548. uv_attribute.buffer = ctx->billboard_vbo;
  549. uv_attribute.offset = attribute_offset;
  550. uv_attribute.stride = billboard_vertex_stride;
  551. uv_attribute.type = gl::vertex_attribute_type::float_32;
  552. uv_attribute.components = 2;
  553. attribute_offset += uv_attribute.components * sizeof(float);
  554. // Define barycentric vertex attribute
  555. gl::vertex_attribute barycentric_attribute;
  556. barycentric_attribute.buffer = ctx->billboard_vbo;
  557. barycentric_attribute.offset = attribute_offset;
  558. barycentric_attribute.stride = billboard_vertex_stride;
  559. barycentric_attribute.type = gl::vertex_attribute_type::float_32;
  560. barycentric_attribute.components = 3;
  561. attribute_offset += barycentric_attribute.components * sizeof(float);
  562. // Bind vertex attributes to VAO
  563. ctx->billboard_vao->bind(render::vertex_attribute::position, position_attribute);
  564. ctx->billboard_vao->bind(render::vertex_attribute::uv, uv_attribute);
  565. ctx->billboard_vao->bind(render::vertex_attribute::barycentric, barycentric_attribute);
  566. }
  567. // Create renderer
  568. ctx->renderer = new render::renderer();
  569. ctx->renderer->set_billboard_vao(ctx->billboard_vao);
  570. logger->pop_task(EXIT_SUCCESS);
  571. }
  572. void setup_sound(game::context* ctx)
  573. {
  574. debug::logger* logger = ctx->logger;
  575. logger->push_task("Setting up sound");
  576. // Load master volume config
  577. ctx->master_volume = 1.0f;
  578. if (ctx->config->contains("master_volume"))
  579. ctx->master_volume = (*ctx->config)["master_volume"].get<float>();
  580. // Load ambience volume config
  581. ctx->ambience_volume = 1.0f;
  582. if (ctx->config->contains("ambience_volume"))
  583. ctx->ambience_volume = (*ctx->config)["ambience_volume"].get<float>();
  584. // Load effects volume config
  585. ctx->effects_volume = 1.0f;
  586. if (ctx->config->contains("effects_volume"))
  587. ctx->effects_volume = (*ctx->config)["effects_volume"].get<float>();
  588. // Load mono audio config
  589. ctx->mono_audio = false;
  590. if (ctx->config->contains("mono_audio"))
  591. ctx->mono_audio = (*ctx->config)["mono_audio"].get<bool>();
  592. // Load captions config
  593. ctx->captions = false;
  594. if (ctx->config->contains("captions"))
  595. ctx->captions = (*ctx->config)["captions"].get<bool>();
  596. // Load captions size config
  597. ctx->captions_size = 1.0f;
  598. if (ctx->config->contains("captions_size"))
  599. ctx->captions_size = (*ctx->config)["captions_size"].get<float>();
  600. logger->pop_task(EXIT_SUCCESS);
  601. }
  602. void setup_scenes(game::context* ctx)
  603. {
  604. debug::logger* logger = ctx->logger;
  605. logger->push_task("Setting up scenes");
  606. // Get default framebuffer
  607. const auto& viewport_dimensions = ctx->rasterizer->get_default_framebuffer().get_dimensions();
  608. const float viewport_aspect_ratio = static_cast<float>(viewport_dimensions[0]) / static_cast<float>(viewport_dimensions[1]);
  609. // Create infinite culling mask
  610. const float inf = std::numeric_limits<float>::infinity();
  611. ctx->no_cull = {{-inf, -inf, -inf}, {inf, inf, inf}};
  612. // Setup UI camera
  613. ctx->ui_camera = new scene::camera();
  614. ctx->ui_camera->set_compositor(ctx->ui_compositor);
  615. auto viewport = ctx->app->get_viewport_dimensions();
  616. float clip_left = -viewport[0] * 0.5f;
  617. float clip_right = viewport[0] * 0.5f;
  618. float clip_top = -viewport[1] * 0.5f;
  619. float clip_bottom = viewport[1] * 0.5f;
  620. float clip_near = 0.0f;
  621. float clip_far = 1000.0f;
  622. ctx->ui_camera->set_orthographic(clip_left, clip_right, clip_top, clip_bottom, clip_near, clip_far);
  623. // Setup underground camera
  624. ctx->underground_camera = new scene::camera();
  625. ctx->underground_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
  626. ctx->underground_camera->set_compositor(ctx->underground_compositor);
  627. ctx->underground_camera->set_composite_index(0);
  628. ctx->underground_camera->set_active(false);
  629. // Setup surface camera
  630. ctx->surface_camera = new scene::camera();
  631. ctx->surface_camera->set_perspective(math::radians<float>(45.0f), viewport_aspect_ratio, 0.1f, 1000.0f);
  632. ctx->surface_camera->set_compositor(ctx->surface_compositor);
  633. ctx->surface_camera->set_composite_index(0);
  634. ctx->surface_camera->set_active(false);
  635. // Setup UI scene
  636. {
  637. ctx->ui_scene = new scene::collection();
  638. const gl::texture_2d* splash_texture = ctx->resource_manager->load<gl::texture_2d>("splash.tex");
  639. auto splash_dimensions = splash_texture->get_dimensions();
  640. ctx->splash_billboard_material = new render::material();
  641. ctx->splash_billboard_material->set_flags(MATERIAL_FLAG_TRANSLUCENT);
  642. ctx->splash_billboard_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
  643. ctx->splash_billboard_material->add_property<const gl::texture_2d*>("background")->set_value(splash_texture);
  644. ctx->splash_billboard_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
  645. ctx->splash_billboard_material->update_tweens();
  646. ctx->splash_billboard = new scene::billboard();
  647. ctx->splash_billboard->set_material(ctx->splash_billboard_material);
  648. ctx->splash_billboard->set_scale({(float)std::get<0>(splash_dimensions) * 0.5f, (float)std::get<1>(splash_dimensions) * 0.5f, 1.0f});
  649. ctx->splash_billboard->set_translation({0.0f, 0.0f, 0.0f});
  650. ctx->splash_billboard->update_tweens();
  651. // Create camera flash billboard
  652. render::material* flash_material = new render::material();
  653. flash_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-untextured.glsl"));
  654. auto flash_tint = flash_material->add_property<float4>("tint");
  655. flash_tint->set_value(float4{1, 1, 1, 1});
  656. //flash_tint->set_tween_interpolator(ease<float4>::out_quad);
  657. flash_material->set_flags(MATERIAL_FLAG_TRANSLUCENT);
  658. flash_material->update_tweens();
  659. ctx->camera_flash_billboard = new scene::billboard();
  660. ctx->camera_flash_billboard->set_material(flash_material);
  661. ctx->camera_flash_billboard->set_scale({(float)viewport_dimensions[0] * 0.5f, (float)viewport_dimensions[1] * 0.5f, 1.0f});
  662. ctx->camera_flash_billboard->set_translation({0.0f, 0.0f, 0.0f});
  663. ctx->camera_flash_billboard->update_tweens();
  664. // Create depth debug billboard
  665. /*
  666. material* depth_debug_material = new material();
  667. depth_debug_material->set_shader_program(ctx->resource_manager->load<gl::shader_program>("ui-element-textured.glsl"));
  668. depth_debug_material->add_property<const gl::texture_2d*>("background")->set_value(shadow_map_depth_texture);
  669. depth_debug_material->add_property<float4>("tint")->set_value(float4{1, 1, 1, 1});
  670. billboard* depth_debug_billboard = new billboard();
  671. depth_debug_billboard->set_material(depth_debug_material);
  672. depth_debug_billboard->set_scale({128, 128, 1});
  673. depth_debug_billboard->set_translation({-960 + 128, 1080 * 0.5f - 128, 0});
  674. depth_debug_billboard->update_tweens();
  675. ui_system->get_scene()->add_object(depth_debug_billboard);
  676. */
  677. ctx->ui_scene->add_object(ctx->ui_camera);
  678. }
  679. // Setup underground scene
  680. {
  681. ctx->underground_scene = new scene::collection();
  682. ctx->underground_ambient_light = new scene::ambient_light();
  683. ctx->underground_ambient_light->set_color({1, 1, 1});
  684. ctx->underground_ambient_light->set_intensity(0.1f);
  685. ctx->underground_ambient_light->update_tweens();
  686. ctx->flashlight_spot_light = new scene::spot_light();
  687. ctx->flashlight_spot_light->set_color({1, 1, 1});
  688. ctx->flashlight_spot_light->set_intensity(1.0f);
  689. ctx->flashlight_spot_light->set_attenuation({1.0f, 0.0f, 0.0f});
  690. ctx->flashlight_spot_light->set_cutoff({math::radians(10.0f), math::radians(19.0f)});
  691. ctx->underground_scene->add_object(ctx->underground_camera);
  692. ctx->underground_scene->add_object(ctx->underground_ambient_light);
  693. //ctx->underground_scene->add_object(ctx->flashlight_spot_light);
  694. }
  695. // Setup surface scene
  696. {
  697. ctx->surface_scene = new scene::collection();
  698. ctx->surface_scene->add_object(ctx->surface_camera);
  699. }
  700. // Clear active scene
  701. ctx->active_scene = nullptr;
  702. logger->pop_task(EXIT_SUCCESS);
  703. }
  704. void setup_animation(game::context* ctx)
  705. {
  706. // Setup timeline system
  707. ctx->timeline = new timeline();
  708. ctx->timeline->set_autoremove(true);
  709. // Setup animator
  710. ctx->animator = new animator();
  711. // Create fade transition
  712. ctx->fade_transition = new screen_transition();
  713. ctx->fade_transition->get_material()->set_shader_program(ctx->resource_manager->load<gl::shader_program>("fade-transition.glsl"));
  714. ctx->fade_transition_color = ctx->fade_transition->get_material()->add_property<float3>("color");
  715. ctx->fade_transition_color->set_value({0, 0, 0});
  716. ctx->ui_scene->add_object(ctx->fade_transition->get_billboard());
  717. ctx->animator->add_animation(ctx->fade_transition->get_animation());
  718. // Create inner radial transition
  719. ctx->radial_transition_inner = new screen_transition();
  720. ctx->radial_transition_inner->get_material()->set_shader_program(ctx->resource_manager->load<gl::shader_program>("radial-transition-inner.glsl"));
  721. //ctx->ui_scene->add_object(ctx->radial_transition_inner->get_billboard());
  722. //ctx->animator->add_animation(ctx->radial_transition_inner->get_animation());
  723. // Create outer radial transition
  724. ctx->radial_transition_outer = new screen_transition();
  725. ctx->radial_transition_outer->get_material()->set_shader_program(ctx->resource_manager->load<gl::shader_program>("radial-transition-outer.glsl"));
  726. //ctx->ui_scene->add_object(ctx->radial_transition_outer->get_billboard());
  727. //ctx->animator->add_animation(ctx->radial_transition_outer->get_animation());
  728. // Create camera flash animation
  729. ctx->camera_flash_animation = new animation<float>();
  730. {
  731. ctx->camera_flash_animation->set_interpolator(ease<float>::out_sine);
  732. const float duration = 0.5f;
  733. animation_channel<float>* channel = ctx->camera_flash_animation->add_channel(0);
  734. channel->insert_keyframe({0.0f, 1.0f});
  735. channel->insert_keyframe({duration, 0.0f});
  736. }
  737. }
  738. void setup_entities(game::context* ctx)
  739. {
  740. // Create entity registry
  741. ctx->entity_registry = new entt::registry();
  742. }
  743. void setup_systems(game::context* ctx)
  744. {
  745. event_dispatcher* event_dispatcher = ctx->app->get_event_dispatcher();
  746. const auto& viewport_dimensions = ctx->app->get_viewport_dimensions();
  747. float4 viewport = {0.0f, 0.0f, static_cast<float>(viewport_dimensions[0]), static_cast<float>(viewport_dimensions[1])};
  748. // RGB wavelengths determined by matching wavelengths to XYZ, transforming XYZ to ACEScg, then selecting the max wavelengths for R, G, and B.
  749. const double3 rgb_wavelengths_nm = {602.224, 541.069, 448.143};
  750. // Setup terrain system
  751. ctx->terrain_system = new entity::system::terrain(*ctx->entity_registry);
  752. ctx->terrain_system->set_patch_subdivisions(30);
  753. ctx->terrain_system->set_patch_scene_collection(ctx->surface_scene);
  754. ctx->terrain_system->set_max_error(200.0);
  755. // Setup vegetation system
  756. //ctx->vegetation_system = new entity::system::vegetation(*ctx->entity_registry);
  757. //ctx->vegetation_system->set_terrain_patch_size(TERRAIN_PATCH_SIZE);
  758. //ctx->vegetation_system->set_vegetation_patch_resolution(VEGETATION_PATCH_RESOLUTION);
  759. //ctx->vegetation_system->set_vegetation_density(1.0f);
  760. //ctx->vegetation_system->set_vegetation_model(ctx->resource_manager->load<model>("grass-tuft.mdl"));
  761. //ctx->vegetation_system->set_scene(ctx->surface_scene);
  762. // Setup camera system
  763. ctx->camera_system = new entity::system::camera(*ctx->entity_registry);
  764. ctx->camera_system->set_viewport(viewport);
  765. event_dispatcher->subscribe<window_resized_event>(ctx->camera_system);
  766. // Setup subterrain system
  767. ctx->subterrain_system = new entity::system::subterrain(*ctx->entity_registry, ctx->resource_manager);
  768. ctx->subterrain_system->set_scene(ctx->underground_scene);
  769. // Setup collision system
  770. ctx->collision_system = new entity::system::collision(*ctx->entity_registry);
  771. // Setup samara system
  772. ctx->samara_system = new entity::system::samara(*ctx->entity_registry);
  773. // Setup snapping system
  774. ctx->snapping_system = new entity::system::snapping(*ctx->entity_registry);
  775. // Setup behavior system
  776. ctx->behavior_system = new entity::system::behavior(*ctx->entity_registry);
  777. // Setup locomotion system
  778. ctx->locomotion_system = new entity::system::locomotion(*ctx->entity_registry);
  779. // Setup spatial system
  780. ctx->spatial_system = new entity::system::spatial(*ctx->entity_registry);
  781. // Setup constraint system
  782. ctx->constraint_system = new entity::system::constraint(*ctx->entity_registry);
  783. // Setup painting system
  784. ctx->painting_system = new entity::system::painting(*ctx->entity_registry, event_dispatcher, ctx->resource_manager);
  785. ctx->painting_system->set_scene(ctx->surface_scene);
  786. // Setup orbit system
  787. ctx->orbit_system = new entity::system::orbit(*ctx->entity_registry);
  788. // Setup blackbody system
  789. ctx->blackbody_system = new entity::system::blackbody(*ctx->entity_registry);
  790. ctx->blackbody_system->set_rgb_wavelengths(rgb_wavelengths_nm);
  791. // Setup atmosphere system
  792. ctx->atmosphere_system = new entity::system::atmosphere(*ctx->entity_registry);
  793. ctx->atmosphere_system->set_rgb_wavelengths(rgb_wavelengths_nm);
  794. // Setup astronomy system
  795. ctx->astronomy_system = new entity::system::astronomy(*ctx->entity_registry);
  796. ctx->astronomy_system->set_sky_pass(ctx->surface_sky_pass);
  797. // Setup proteome system
  798. ctx->proteome_system = new entity::system::proteome(*ctx->entity_registry);
  799. // Set time scale
  800. double time_scale = 60.0;
  801. if (ctx->config->contains("time_scale"))
  802. {
  803. time_scale = (*ctx->config)["time_scale"].get<double>();
  804. }
  805. ctx->orbit_system->set_time_scale(time_scale / seconds_per_day);
  806. ctx->astronomy_system->set_time_scale(time_scale / seconds_per_day);
  807. // Setup render system
  808. ctx->render_system = new entity::system::render(*ctx->entity_registry);
  809. ctx->render_system->add_layer(ctx->underground_scene);
  810. ctx->render_system->add_layer(ctx->surface_scene);
  811. ctx->render_system->add_layer(ctx->ui_scene);
  812. ctx->render_system->set_renderer(ctx->renderer);
  813. }
  814. void setup_controls(game::context* ctx)
  815. {
  816. event_dispatcher* event_dispatcher = ctx->app->get_event_dispatcher();
  817. // Setup input event routing
  818. ctx->input_event_router = new input::event_router();
  819. ctx->input_event_router->set_event_dispatcher(event_dispatcher);
  820. // Setup input mapper
  821. ctx->input_mapper = new input::mapper();
  822. ctx->input_mapper->set_event_dispatcher(event_dispatcher);
  823. // Setup input listener
  824. ctx->input_listener = new input::listener();
  825. ctx->input_listener->set_event_dispatcher(event_dispatcher);
  826. // Load SDL game controller mappings database
  827. ctx->logger->push_task("Loading SDL game controller mappings from database");
  828. file_buffer* game_controller_db = ctx->resource_manager->load<file_buffer>("gamecontrollerdb.txt");
  829. if (!game_controller_db)
  830. {
  831. ctx->logger->pop_task(EXIT_FAILURE);
  832. }
  833. else
  834. {
  835. ctx->app->add_game_controller_mappings(game_controller_db->data(), game_controller_db->size());
  836. ctx->resource_manager->unload("gamecontrollerdb.txt");
  837. ctx->logger->pop_task(EXIT_SUCCESS);
  838. }
  839. }
  840. void setup_ui(game::context* ctx)
  841. {
  842. // Load font size config
  843. ctx->font_size = 1.0f;
  844. if (ctx->config->contains("font_size"))
  845. ctx->font_size = (*ctx->config)["font_size"].get<float>();
  846. // Load dyslexia font config
  847. ctx->dyslexia_font = false;
  848. if (ctx->config->contains("dyslexia_font"))
  849. ctx->dyslexia_font = (*ctx->config)["dyslexia_font"].get<bool>();
  850. ctx->main_menu_index = 0;
  851. ctx->options_menu_index = 0;
  852. ctx->graphics_menu_index = 0;
  853. ctx->sound_menu_index = 0;
  854. ctx->language_menu_index = 0;
  855. }
  856. void setup_cli(game::context* ctx)
  857. {
  858. ctx->cli = new debug::cli();
  859. ctx->cli->register_command("echo", debug::cc::echo);
  860. ctx->cli->register_command("exit", std::function<std::string()>(std::bind(&debug::cc::exit, ctx)));
  861. ctx->cli->register_command("scrot", std::function<std::string()>(std::bind(&debug::cc::scrot, ctx)));
  862. ctx->cli->register_command("cue", std::function<std::string(float, std::string)>(std::bind(&debug::cc::cue, ctx, std::placeholders::_1, std::placeholders::_2)));
  863. //std::string cmd = "cue 20 exit";
  864. //logger->log(cmd);
  865. //logger->log(cli.interpret(cmd));
  866. }
  867. void setup_callbacks(game::context* ctx)
  868. {
  869. // Set update callback
  870. ctx->app->set_update_callback
  871. (
  872. [ctx](double t, double dt)
  873. {
  874. // Update controls
  875. for (const auto& control: ctx->controls)
  876. control.second->update();
  877. // Update processes
  878. std::for_each
  879. (
  880. std::execution::par,
  881. ctx->processes.begin(),
  882. ctx->processes.end(),
  883. [t, dt](const auto& process)
  884. {
  885. process.second(t, dt);
  886. }
  887. );
  888. // Update tweens
  889. ctx->surface_sky_pass->update_tweens();
  890. ctx->surface_scene->update_tweens();
  891. ctx->underground_scene->update_tweens();
  892. ctx->ui_scene->update_tweens();
  893. ctx->timeline->advance(dt);
  894. ctx->terrain_system->update(t, dt);
  895. //ctx->vegetation_system->update(t, dt);
  896. ctx->snapping_system->update(t, dt);
  897. ctx->subterrain_system->update(t, dt);
  898. ctx->collision_system->update(t, dt);
  899. ctx->samara_system->update(t, dt);
  900. ctx->behavior_system->update(t, dt);
  901. ctx->locomotion_system->update(t, dt);
  902. ctx->camera_system->update(t, dt);
  903. ctx->orbit_system->update(t, dt);
  904. ctx->blackbody_system->update(t, dt);
  905. ctx->atmosphere_system->update(t, dt);
  906. ctx->astronomy_system->update(t, dt);
  907. ctx->spatial_system->update(t, dt);
  908. ctx->constraint_system->update(t, dt);
  909. ctx->painting_system->update(t, dt);
  910. ctx->proteome_system->update(t, dt);
  911. ctx->render_system->update(t, dt);
  912. ctx->animator->animate(dt);
  913. }
  914. );
  915. // Set render callback
  916. ctx->app->set_render_callback
  917. (
  918. [ctx](double alpha)
  919. {
  920. ctx->render_system->draw(alpha);
  921. }
  922. );
  923. }
  924. } // namespace boot
  925. } // namespace state
  926. } // namespace game