Game Project
Loading...
Searching...
No Matches
ResourceManager.h
1#pragma once
2#include <string>
3#include <unordered_map>
4#include <SFML/Graphics.hpp>
5#include <SFML/Audio.hpp>
6#include <json.hpp>
7
8#include "../utils/Common.h"
9
10/*
11* Could remove singleton and reuse the class:
12* Core resources for the menu, menu font, etc
13* Scene resources for the scene coming up, meaning that everything will be deleted when the scene is gone
14*
15* For the time being, audio is not being handled, as there is more to look into for sounds, music, sound buffers, etc.
16* + Priority task
17*/
18
22class ResourceManager
23{
24public:
29 static ResourceManager& GetInstance()
30 {
31 static ResourceManager instance;
32 return instance;
33 }
34
35 // Texture
36 void LoadTexture(const std::string& id, const std::string& file_path);
37 const sf::Texture* GetTexture(const std::string& id) const;
38 void UnloadTexture(const std::string& id);
39
40 // Font
41 void LoadFont(const std::string& id, const std::string& file_path);
42 const sf::Font* GetFont(const std::string& id) const;
43 void UnloadFont(const std::string& id);
44
45 // Cleanup
46 void UnloadAll();
47
48private:
49 // Singleton class.
50 ResourceManager() = default; // Private constructor.
51 ResourceManager(const ResourceManager&) = delete; // Delete copy constructor.
52 ResourceManager& operator=(const ResourceManager&) = delete; // Delete assignment operator.
53 ResourceManager(ResourceManager&&) = delete; // Delete move constructor.
54 ResourceManager& operator=(ResourceManager&&) = delete; // Delete move assignment operator.
55
56 // Maps of the resources
57 std::unordered_map<std::string, sf::Texture> textures_;
58 std::unordered_map<std::string, sf::Font> fonts_;
59};
Loads and returns the assets from file paths, and stores them in a map. Singleton.
Definition ResourceManager.h:23
static ResourceManager & GetInstance()
Returns instance of the singleton class.
Definition ResourceManager.h:29