Raytracer
Loading...
Searching...
No Matches
Manager.hpp
1#include <functional>
2#include <libconfig.hh>
3#include <memory>
4#include <optional>
5#include <string>
6#include <variant>
7#include "Common.hpp"
8#include "core/Camera.hpp"
9#include "core/Scene.hpp"
10#include "interfaces/IArguments.hpp"
11#include "interfaces/IHittable.hpp"
12#include "interfaces/IMaterial.hpp"
13#include "interfaces/ITexture.hpp"
14#include "libconfig.h++"
15#include <type_traits>
16#include <unordered_map>
17
18#ifndef __CFG_MANAGER_HPP__
19 #define __CFG_MANAGER_HPP__
20
21namespace Raytracer::Config
22{
23 template <typename I>
24 using ManagerMap = std::unordered_map<std::string, std::shared_ptr<I>>;
25
26 using KeyTypes = std::tuple<double, int, int, int, Raytracer::Utils::Color,
29
30 template <int I> using KeyType = std::tuple_element_t<I, KeyTypes>;
31
32 using CameraTypes = std::variant<int, double, Raytracer::Utils::Vec3>;
33
34 class Manager {
35 private:
38 std::vector<std::string> _ids;
39 ManagerMap<Interfaces::ITexture> _textures;
40 ManagerMap<Interfaces::IHittable> _effects;
41 ManagerMap<Interfaces::IMaterial> _materials;
42 ManagerMap<Interfaces::IHittable> _shapes;
43 std::unordered_map<std::string,
44 std::function<std::shared_ptr<Interfaces::IArguments>(
45 libconfig::Setting &)>>
46 _argumentMap;
47 std::unordered_map<std::string,
48 std::function<void(Raytracer::Core::Camera &, CameraTypes &)>>
49 _cameraMap;
50
51 public:
52 Manager();
53 bool parse(std::string path);
54 void bootstrap();
55 void render(bool fast);
56 GET_SET(Raytracer::Core::Scene, world);
57 GET_SET(Raytracer::Core::Camera, camera);
58
59 private:
60 template <typename I, typename E>
61 requires std::is_enum_v<E>
62 void genericParse(
63 const libconfig::Setting &arguments, ManagerMap<I> &containerMap);
64 static Utils::Color parseColor(const libconfig::Setting &color);
65 template <typename I>
66 std::shared_ptr<I> retrieve(const libconfig::Setting &arguments,
67 ManagerMap<I> &containerMap, const std::string &name);
68 std::shared_ptr<Raytracer::Interfaces::IArguments> create(
69 const std::string &type, libconfig::Setting &args);
70 void parseCamera(const libconfig::Setting &camera);
71 void parseImports(const libconfig::Setting &imports);
72 template <typename T>
73 requires std::is_arithmetic_v<T>
74 std::optional<T> parseOptional(
75 const libconfig::Setting &setting, std::string &name);
76 template <typename T>
77 requires std::is_same_v<T, Raytracer::Utils::Vec3>
78 std::optional<T> parseOptional(
79 const libconfig::Setting &setting, std::string &name);
80 template <std::size_t I>
81 void extract(const libconfig::Setting &setting,
82 std::array<std::string, 10> &keys);
83 template <std::size_t... Is>
84 void parseCameraHelper(const libconfig::Setting &camera,
85 std::array<std::string, 10> &keys, std::index_sequence<Is...>);
86 };
87} // namespace Raytracer::Config
88
89#endif /* __CFG_MANAGER_HPP__ */
Definition Manager.hpp:34
void bootstrap()
Bootstrap the configuration.
Definition Manager.cpp:845
void render(bool fast)
Render the scene.
Definition Manager.cpp:863
Manager()
Construct a new Manager:: Manager object.
Definition Manager.cpp:36
bool parse(std::string path)
Parse the configuration file.
Definition Manager.cpp:502
Definition Camera.hpp:12
Definition Scene.hpp:10
Definition VecN.hpp:40