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

116 lines
3.5 KiB

  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/load.hpp"
  20. #include "application.hpp"
  21. #include "debug/logger.hpp"
  22. #include "resources/json.hpp"
  23. #include "resources/resource-manager.hpp"
  24. #include "render/model.hpp"
  25. #include "render/material.hpp"
  26. #include "render/passes/sky-pass.hpp"
  27. #include "render/passes/ground-pass.hpp"
  28. #include "entity/systems/astronomy.hpp"
  29. #include <fstream>
  30. namespace game {
  31. namespace load {
  32. void biome(game::context& ctx, const std::filesystem::path& path)
  33. {
  34. ctx.logger->push_task("Loading biome from \"" + path.string() + "\"");
  35. try
  36. {
  37. json* data = ctx.resource_manager->load<json>(path);
  38. // Load location
  39. if (auto location = data->find("location"); location != data->end())
  40. {
  41. double elevation = 0.0;
  42. double latitude = 0.0;
  43. double longitude = 0.0;
  44. if (auto location_ele = location->find("elevation"); location_ele != location->end())
  45. elevation = location_ele->get<double>();
  46. else
  47. ctx.logger->warning("Biome elevation undefined");
  48. if (auto location_lat = location->find("latitude"); location_lat != location->end())
  49. latitude = math::radians<double>(location_lat->get<double>());
  50. else
  51. ctx.logger->warning("Biome latitude undefined");
  52. if (auto location_lon = location->find("longitude"); location_lon != location->end())
  53. longitude = math::radians<double>(location_lon->get<double>());
  54. else
  55. ctx.logger->warning("Biome longitude undefined");
  56. ctx.astronomy_system->set_observer_location({elevation, latitude, longitude});
  57. }
  58. else
  59. {
  60. ctx.logger->warning("Biome location undefined");
  61. }
  62. // Setup sky
  63. ctx.sky_pass->set_sky_model(ctx.resource_manager->load<render::model>("celestial-hemisphere.mdl"));
  64. // Load terrain
  65. if (auto terrain = data->find("terrain"); terrain != data->end())
  66. {
  67. if (auto material = terrain->find("material"); material != terrain->end())
  68. {
  69. render::model* terrestrial_hemisphere_model = ctx.resource_manager->load<render::model>("terrestrial-hemisphere.mdl");
  70. (*terrestrial_hemisphere_model->get_groups())[0]->set_material(ctx.resource_manager->load<render::material>(material->get<std::string>()));
  71. ctx.ground_pass->set_ground_model(terrestrial_hemisphere_model);
  72. }
  73. else
  74. {
  75. ctx.logger->warning("Biome terrain material undefined");
  76. }
  77. }
  78. else
  79. {
  80. ctx.logger->warning("Biome terrain undefined");
  81. }
  82. }
  83. catch (...)
  84. {
  85. ctx.logger->pop_task(EXIT_FAILURE);
  86. }
  87. ctx.logger->pop_task(EXIT_SUCCESS);
  88. }
  89. void colony(game::context& ctx, const std::filesystem::path& path)
  90. {
  91. ctx.logger->push_task("Loading colony from \"" + path.string() + "\"");
  92. try
  93. {
  94. json* data = ctx.resource_manager->load<json>(path);
  95. }
  96. catch (...)
  97. {
  98. ctx.logger->pop_task(EXIT_FAILURE);
  99. }
  100. ctx.logger->pop_task(EXIT_SUCCESS);
  101. }
  102. } // namespace load
  103. } // namespace game