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#include "Graphics/Texture.h"
24
25using serializables_dictionary = std::unordered_map<std::string,
26 std::unique_ptr<th::AnySerializable>>;
27
28
29namespace th
30{
32{
33public:
34 Library() = default;
35 ~Library() = default;
36 Library(const Library& other) = delete;
37 Library(Library&& other) noexcept = delete;
38 auto operator=(const Library& other) -> Library& = delete;
39 auto operator=(Library&& other) noexcept -> Library& = delete;
40
41
48 template <typename T>
49 static auto get(const std::string& name) -> T*
50 {
51 auto found = findObject(name);
52 T* result = boost::type_erasure::any_cast<T*>(found);
53 return result;
54 }
55
63 template <>
64 auto get<GameObject>(const std::string& name) -> GameObject*
65 {
66 auto found = findObject(name);
67 auto result = static_cast<GameObject*>(boost::type_erasure::any_cast<void*>(found));
68 // A slightly hacky assert to check for garbage data
69 assert(
70 result->destroyed() == false &&
71 "Library tried to get an object as a gameobject* but it failed when casting");
72 return result;
73 }
74
78 static auto flush() -> void;
79
80private:
81#pragma region helper_functions
82
88 static auto findObject(const std::string& name) -> AnySerializable*;
94 static auto addObject(const std::string& name) -> AnySerializable*;
95
96#pragma endregion
97
98#pragma region static_variables
99
104
105#pragma endregion
106
107
108};
109}
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:25
A object to hold and manage meshes in opengl.
holds and manages textures for use with meshes in sprites
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:49
~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:103
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:62
boost::type_erasure::any< boost::type_erasure::serializable<>, boost::type_erasure::_self > AnySerializable
Definition Any_Serializable.h:53