59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
#include "resource.h"
|
|
#include <iostream>
|
|
|
|
// Constructor
|
|
Resource::Resource(SDL_Renderer *renderer, Asset *asset, options_t *options)
|
|
{
|
|
this->renderer = renderer;
|
|
this->asset = asset;
|
|
this->options = options;
|
|
}
|
|
|
|
// Carga todos los recursos necesarios
|
|
void Resource::loadTextures(std::vector<std::string> list)
|
|
{
|
|
std::cout << "** LOAD RESOURCES" << std::endl;
|
|
for (auto l : list)
|
|
{
|
|
texture_t t;
|
|
t.name = l;
|
|
t.texture = new Texture(renderer, asset->get(t.name));
|
|
textures.push_back(t);
|
|
}
|
|
std::cout << "** RESOURCES LOADED" << std::endl;
|
|
}
|
|
|
|
// Recarga las texturas
|
|
void Resource::reLoadTextures()
|
|
{
|
|
for (auto texture : textures)
|
|
{
|
|
texture.texture->reLoad();
|
|
}
|
|
}
|
|
|
|
// Libera las texturas
|
|
void Resource::freeTextures()
|
|
{
|
|
for (auto texture : textures)
|
|
{
|
|
delete texture.texture;
|
|
}
|
|
textures.clear();
|
|
}
|
|
|
|
// Obtiene una textura
|
|
Texture *Resource::getTexture(std::string name)
|
|
{
|
|
for (auto texture : textures)
|
|
{
|
|
if (texture.name.find(name) != std::string::npos)
|
|
{
|
|
std::cout << "CACHE: " << name << std::endl;
|
|
return texture.texture;
|
|
}
|
|
}
|
|
|
|
std::cout << "NOT FOUND: " << name << std::endl;
|
|
return nullptr;
|
|
} |