Brunot
Loading...
Searching...
No Matches
Library.h
Go to the documentation of this file.
1// File: Library.h
2// Description: A singleton that holds objects that can be loaded and saved.
3// returns references to them for use as shared resources, or to copy an instantiate
4// Author(s): Aidan Hartman (aidan.hartman@digipen.edu)
5// 2025 / 10 / 31
6// (C) Digipen 2025
7// Library.h
8// ____ __ __ __
9// /\__ _\/\ \ /\ \/\ \
10// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
11// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
12// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
13// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
14// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
15#pragma once
16
18
20
21#include "Graphics/Mesh.h"
22#include "Graphics/Shader.h"
23
24using serializables_dictionary = std::unordered_map<std::string,
25 std::unique_ptr<th::AnySerializable>>;
26
27
28namespace th
29{
31{
32public:
33 Library() = default;
34 ~Library() = default;
35 Library(const Library& other) = delete;
36 Library(Library&& other) noexcept = delete;
37 auto operator=(const Library& other) -> Library& = delete;
38 auto operator=(Library&& other) noexcept -> Library& = delete;
39
40
47 template <typename T>
48 static auto get(const std::string& name) -> T*
49 {
50 auto found = findObject(name);
51 T* result = boost::type_erasure::any_cast<T*>(found);
52 return result;
53 }
54
62 template <>
63 auto get<GameObject>(const std::string& name) -> GameObject*
64 {
65 auto found = findObject(name);
66 auto result = static_cast<GameObject*>(boost::type_erasure::any_cast<void*>(found));
67 // A slightly hacky assert to check for garbage data
68 assert(
69 result->destroyed() == false &&
70 "Library tried to get an object as a gameobject* but it failed when casting");
71 return result;
72 }
73
77 static auto flush() -> void;
78
79private:
80#pragma region helper_functions
81
87 static auto findObject(const std::string& name) -> AnySerializable*;
93 static auto addObject(const std::string& name) -> AnySerializable*;
94
95#pragma endregion
96
97#pragma region static_variables
98
103
104#pragma endregion
105
106
107};
108}
static FMOD_RESULT result
Definition AudioObject.cpp:27
the base class for the engine, most things inherit from this.
std::unordered_map< std::string, std::unique_ptr< th::AnySerializable > > serializables_dictionary
Definition Library.h:24
A object to hold and manage meshes in opengl.
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
auto operator=(Library &&other) noexcept -> Library &=delete
static auto get(const std::string &name) -> T *
get a pointer to an object in the library.
Definition Library.h:48
~Library()=default
Library()=default
static auto findObject(const std::string &name) -> AnySerializable *
helper function, finds an object in the objects library, if it doesn't exist, it creates it
Definition Library.cpp:37
Library(const Library &other)=delete
static auto flush() -> void
remove objects from the library, this will break anything that uses its resources
Definition Library.cpp:32
static serializables_dictionary objects
a static unordered map of objects in the library
Definition Library.h:102
Library(Library &&other) noexcept=delete
auto operator=(const Library &other) -> Library &=delete
static auto addObject(const std::string &name) -> AnySerializable *
adds an object that doesn't exist to the objects library
Definition Library.cpp:61
Definition Factory.cpp:59
boost::type_erasure::any< boost::type_erasure::serializable<>, boost::type_erasure::_self > AnySerializable
Definition Any_Serializable.h:53