passant Asset a singleton de tota la vida
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "utils.h"
|
||||
|
||||
// Tipos de recursos gestionados por Asset
|
||||
@@ -23,18 +24,14 @@ enum class AssetType : int
|
||||
class Asset
|
||||
{
|
||||
public:
|
||||
// Obtención de la instancia única (Meyers Singleton)
|
||||
static Asset &get()
|
||||
{
|
||||
static Asset instance;
|
||||
return instance;
|
||||
}
|
||||
// Inicializa la instancia única del singleton
|
||||
static void init(const std::string &executable_path);
|
||||
|
||||
// Inicializa el gestor de recursos con la ruta del ejecutable
|
||||
void init(const std::string &executable_path)
|
||||
{
|
||||
executable_path_ = getPath(executable_path);
|
||||
}
|
||||
// Libera la instancia única
|
||||
static void destroy();
|
||||
|
||||
// Obtiene la instancia única
|
||||
static Asset *get();
|
||||
|
||||
// Añade un recurso a la lista
|
||||
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
|
||||
@@ -70,8 +67,11 @@ private:
|
||||
std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso
|
||||
|
||||
// Patrón Singleton: constructor y destructor privados, sin copia ni asignación
|
||||
Asset() = default;
|
||||
Asset(const std::string &executable_path)
|
||||
: executable_path_(executable_path) {};
|
||||
~Asset() = default;
|
||||
Asset(const Asset &) = delete;
|
||||
Asset &operator=(const Asset &) = delete;
|
||||
|
||||
static std::unique_ptr<Asset> instance_;
|
||||
};
|
||||
Reference in New Issue
Block a user