2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Neirokan on 09.05.2020
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_RESOURCEMANAGER_H
|
|
|
|
#define ENGINE_RESOURCEMANAGER_H
|
|
|
|
|
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
#include <SFML/Audio.hpp>
|
|
|
|
#include <memory>
|
2021-10-18 06:44:04 +03:00
|
|
|
#include "Mesh.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
class ResourceManager final {
|
|
|
|
private:
|
|
|
|
std::map<std::string, std::shared_ptr<sf::Texture>> _textures;
|
|
|
|
std::map<std::string, std::shared_ptr<sf::Font>> _fonts;
|
|
|
|
std::map<std::string, std::shared_ptr<sf::SoundBuffer>> _soundBuffers;
|
2021-10-18 06:44:04 +03:00
|
|
|
std::map<std::string, std::vector<std::shared_ptr<Mesh>>> _objects;
|
2021-10-17 19:38:16 +03:00
|
|
|
|
|
|
|
static ResourceManager* _instance;
|
2021-10-29 23:44:37 +03:00
|
|
|
static bool _validInstance;
|
2021-10-17 19:38:16 +03:00
|
|
|
|
|
|
|
ResourceManager() = default;
|
2021-09-13 15:53:43 +03:00
|
|
|
// Unloads all currently loaded textures.
|
2021-10-18 06:44:04 +03:00
|
|
|
static void unloadObjects();
|
2021-10-17 19:38:16 +03:00
|
|
|
static void unloadTextures();
|
|
|
|
static void unloadSoundBuffers();
|
|
|
|
static void unloadFonts();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-29 23:44:37 +03:00
|
|
|
public:
|
|
|
|
ResourceManager(const ResourceManager&) = delete;
|
|
|
|
ResourceManager& operator=(ResourceManager&) = delete;
|
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
static void unloadAllResources();
|
|
|
|
|
|
|
|
static void init();
|
|
|
|
static void free();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
// Try to load texture from file.
|
|
|
|
// If success returns pointer to texture.
|
|
|
|
// Otherwise returns nullptr.
|
2021-10-18 09:21:09 +03:00
|
|
|
static std::vector<std::shared_ptr<Mesh>> loadObjects(const std::string& filename);
|
2021-10-17 19:38:16 +03:00
|
|
|
static std::shared_ptr<sf::Texture> loadTexture(const std::string& filename);
|
|
|
|
static std::shared_ptr<sf::Font> loadFont(const std::string& filename);
|
|
|
|
static std::shared_ptr<sf::SoundBuffer> loadSoundBuffer(const std::string& filename);
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //PSEUDO3DENGINE_RESOURCEMANAGER_H
|