Trabajando en la recarga de texturas

This commit is contained in:
2022-10-27 07:25:59 +02:00
parent 02cc3b3527
commit 32dd85525b
7 changed files with 93 additions and 20 deletions

View File

@@ -21,13 +21,20 @@ void Resource::loadTextures(std::vector<std::string> list)
} }
} }
// Libera los recursos // Recarga las texturas
void Resource::freeTextures() void Resource::reLoadTextures()
{
for (auto texture : textures)
{
texture.texture->reLoad();
}
}
// Libera las texturas
void Resource::freeTextures()
{ {
// Libera las texturas
for (auto texture : textures) for (auto texture : textures)
{ {
texture.texture->unload();
delete texture.texture; delete texture.texture;
} }
textures.clear(); textures.clear();
@@ -36,18 +43,15 @@ void Resource::freeTextures()
// Obtiene una textura // Obtiene una textura
Texture *Resource::getTexture(std::string name) Texture *Resource::getTexture(std::string name)
{ {
//std::cout << "BUSCANDO TEXTURA" << std::endl;
for (auto texture : textures) for (auto texture : textures)
{ {
//std::cout << "COMPROBANDO: " << texture.name << " - " << name << std::endl;
if (texture.name.find(name) != std::string::npos) if (texture.name.find(name) != std::string::npos)
{ {
std::cout << "CACHE: " << name << std::endl; std::cout << "CACHE: " << name << std::endl;
return texture.texture; return texture.texture;
} }
} }
std::cout << "NO ENCONTRADA: " << name << std::endl;
std::cout << "NO ENCONTRADA: " << name << std::endl;
return nullptr; return nullptr;
} }

View File

@@ -34,7 +34,10 @@ public:
// Carga todos los recursos necesarios // Carga todos los recursos necesarios
void loadTextures(std::vector<std::string> textureList); void loadTextures(std::vector<std::string> textureList);
// Libera los recursos // Recarga las texturas
void reLoadTextures();
// Libera las texturas
void freeTextures(); void freeTextures();
// Obtiene una textura // Obtiene una textura

View File

@@ -9,7 +9,7 @@ Director::Director(std::string path)
section.name = SECTION_PROG_LOGO; section.name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_INTRO; section.subsection = SUBSECTION_LOGO_TO_INTRO;
section.name = SECTION_PROG_GAME; section.name = SECTION_PROG_TITLE;
// Crea el objeto que controla los ficheros de recursos // Crea el objeto que controla los ficheros de recursos
asset = new Asset(path.substr(0, path.find_last_of("\\/"))); asset = new Asset(path.substr(0, path.find_last_of("\\/")));

View File

@@ -14,13 +14,13 @@ Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
if (options->palette == p_zxspectrum) if (options->palette == p_zxspectrum)
{ {
loadingScreenTexture1 =resource->getTexture("loading_screen_bn.png"); loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png");
loadingScreenTexture2 =resource->getTexture("loading_screen_color.png"); loadingScreenTexture2 = resource->getTexture("loading_screen_color.png");
} }
else if (options->palette == p_zxarne) else if (options->palette == p_zxarne)
{ {
loadingScreenTexture1 =resource->getTexture("loading_screen_bn_zxarne.png"); loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png");
loadingScreenTexture2 =resource->getTexture("loading_screen_color_zxarne.png"); loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png");
} }
sprite1 = new Sprite(0, 0, loadingScreenTexture1->getWidth(), loadingScreenTexture1->getHeight(), loadingScreenTexture1, renderer); sprite1 = new Sprite(0, 0, loadingScreenTexture1->getWidth(), loadingScreenTexture1->getHeight(), loadingScreenTexture1, renderer);
sprite2 = new Sprite(0, 0, loadingScreenTexture2->getWidth(), loadingScreenTexture2->getHeight(), loadingScreenTexture2, renderer); sprite2 = new Sprite(0, 0, loadingScreenTexture2->getWidth(), loadingScreenTexture2->getHeight(), loadingScreenTexture2, renderer);
@@ -97,8 +97,46 @@ void Intro::checkEventHandler()
// Cualquier tecla pulsada // Cualquier tecla pulsada
if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN)) if ((eventHandler->type == SDL_KEYDOWN) || (eventHandler->type == SDL_JOYBUTTONDOWN))
{ {
section.name = SECTION_PROG_TITLE; switch (eventHandler->key.keysym.scancode)
section.subsection = 0; {
case SDL_SCANCODE_B:
screen->switchBorder();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F:
screen->switchVideoMode();
resource->reLoadTextures();
break;
case SDL_SCANCODE_F1:
screen->setWindowSize(1);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F2:
screen->setWindowSize(2);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F3:
screen->setWindowSize(3);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F4:
screen->setWindowSize(4);
resource->reLoadTextures();
break;
case SDL_SCANCODE_F5:
switchPalette();
break;
default:
section.name = SECTION_PROG_TITLE;
break;
}
} }
} }
} }
@@ -248,3 +286,20 @@ section_t Intro::run()
return section; return section;
} }
// Cambia la paleta
void Intro::switchPalette()
{
if (options->palette == p_zxspectrum)
{
options->palette = p_zxarne;
loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png");
loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png");
}
else
{
options->palette = p_zxspectrum;
loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png");
loadingScreenTexture2 = resource->getTexture("loading_screen_color.png");
}
}

View File

@@ -64,6 +64,9 @@ private:
// Dibuja la pantalla de carga // Dibuja la pantalla de carga
void renderLoad(); void renderLoad();
// Cambia la paleta
void switchPalette();
public: public:
// Constructor // Constructor
Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options); Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);

View File

@@ -783,8 +783,9 @@ void Room::reLoadTexture()
{ {
texture->loadFromFile(asset->get("standard_zxarne.png"), renderer); texture->loadFromFile(asset->get("standard_zxarne.png"), renderer);
} }
// texture->reLoad();
fillMapTexture(); fillMapTexture();
for (auto enemy : enemies) for (auto enemy : enemies)
{ {
enemy->reLoadTexture(); enemy->reLoadTexture();

View File

@@ -14,11 +14,11 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
eventHandler = new SDL_Event(); eventHandler = new SDL_Event();
if (options->palette == p_zxspectrum) if (options->palette == p_zxspectrum)
{ {
texture =resource->getTexture("loading_screen_color.png"); texture = resource->getTexture("loading_screen_color.png");
} }
else if (options->palette == p_zxarne) else if (options->palette == p_zxarne)
{ {
texture =resource->getTexture("loading_screen_color_zxarne.png"); texture = resource->getTexture("loading_screen_color_zxarne.png");
} }
sprite = new Sprite(0, 0, texture->getWidth(), texture->getHeight(), texture, renderer); sprite = new Sprite(0, 0, texture->getWidth(), texture->getHeight(), texture, renderer);
text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer); text = new Text(asset->get("smb2.png"), asset->get("smb2.txt"), renderer);
@@ -107,7 +107,7 @@ void Title::checkEventHandler()
case SDL_SCANCODE_F5: case SDL_SCANCODE_F5:
switchPalette(); switchPalette();
reLoadTextures(); // reLoadTextures();
break; break;
default: default:
@@ -247,12 +247,19 @@ void Title::switchPalette()
if (options->palette == p_zxspectrum) if (options->palette == p_zxspectrum)
{ {
options->palette = p_zxarne; options->palette = p_zxarne;
texture = resource->getTexture("loading_screen_color_zxarne.png");
sprite->setTexture(texture);
} }
else else
{ {
options->palette = p_zxspectrum; options->palette = p_zxspectrum;
texture = resource->getTexture("loading_screen_color.png");
sprite->setTexture(texture);
} }
// resource->reLoadTextures();
// reLoadTextures();
// Cambia el color del borde // Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "bright_blue")); screen->setBorderColor(stringToColor(options->palette, "bright_blue"));
} }