Trabajando en la recarga de recursos

This commit is contained in:
2022-11-07 19:13:58 +01:00
parent 8ae821733c
commit a36378f98c
15 changed files with 95 additions and 38 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -27,6 +27,15 @@ void Resource::loadTextures(std::vector<std::string> list)
}
}
// Vuelve a cargar las texturas
void Resource::reLoadTextures()
{
for (auto texture : textures)
{
texture.texture->reLoad();
}
}
// Carga las animaciones desde una lista
void Resource::loadAnimations(std::vector<std::string> list)
{
@@ -50,6 +59,21 @@ void Resource::loadAnimations(std::vector<std::string> list)
}
}
// Vuelve a cargar las animaciones
void Resource::reLoadAnimations()
{
reLoadTextures();
for (auto a:animations)
{
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
const size_t lastIndex = a.name.find_last_of(".");
const std::string pngFile = a.name.substr(0, lastIndex) + ".png";
delete a.animation;
a.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(a.name), options->console));
}
}
// Carga los offsets desde una lista
void Resource::loadOffsets(std::vector<std::string> list)
{
@@ -62,6 +86,16 @@ void Resource::loadOffsets(std::vector<std::string> list)
}
}
// Vuelve a cargar los offsets
void Resource::reLoadOffsets()
{
for (auto o:offsets)
{
delete o.textFile;
o.textFile = new textFile_t(LoadTextFile(asset->get(o.name), options->console));
}
}
// Carga los mapas de tiles desde una lista
void Resource::loadTileMaps(std::vector<std::string> list)
{
@@ -74,6 +108,16 @@ void Resource::loadTileMaps(std::vector<std::string> list)
}
}
// Vuelve a cargar los mapas de tiles
void Resource::reLoadTileMaps()
{
for (auto tm:tileMaps)
{
delete tm.tileMap;
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(tm.name), options->console));
}
}
// Carga las habitaciones desde una lista
void Resource::loadRooms(std::vector<std::string> list)
{
@@ -97,18 +141,11 @@ void Resource::loadRooms(std::vector<std::string> list)
}
}
// Recarga las texturas
void Resource::reLoadTextures()
{
for (auto texture : textures)
{
texture.texture->reLoad();
}
}
// Recarga las habitaciones
// Vuelve a cargar las habitaciones
void Resource::reLoadRooms()
{
reLoadTileMaps();
for (auto r : rooms)
{
delete r.room;
@@ -127,6 +164,14 @@ void Resource::reLoadRooms()
}
}
// Vuelve a cargar todos los recursos
void Resource::reLoad()
{
reLoadAnimations();
reLoadOffsets();
reLoadRooms();
}
// Libera las texturas
void Resource::freeTextures()
{

View File

@@ -66,24 +66,36 @@ public:
// Carga las texturas de una lista
void loadTextures(std::vector<std::string> list);
// Vuelve a cargar las texturas
void reLoadTextures();
// Carga las animaciones desde una lista
void loadAnimations(std::vector<std::string> list);
// Vuelve a cargar las animaciones
void reLoadAnimations();
// Carga los offsets desde una lista
void loadOffsets(std::vector<std::string> list);
// Vuelve a cargar los offsets
void reLoadOffsets();
// Carga los mapas de tiles desde una lista
void loadTileMaps(std::vector<std::string> list);
// Vuelve a cargar los mapas de tiles
void reLoadTileMaps();
// Carga las habitaciones desde una lista
void loadRooms(std::vector<std::string> list);
// Recarga las texturas
void reLoadTextures();
// Recarga las habitaciones
// Vuelve a cargar las habitaciones
void reLoadRooms();
// Vuelve a cargar todos los recursos
void reLoad();
// Libera las texturas
void freeTextures();

View File

@@ -101,7 +101,7 @@ void Game::checkEventHandler()
break;
case SDL_SCANCODE_R:
resource->reLoadRooms();
resource->reLoad();
break;
case SDL_SCANCODE_M:

View File

@@ -402,7 +402,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
autoSurfaceDirection = room->autoSurfaceDirection;
textureA = room->textureA;
textureB = room->textureB;
tileMap = room->tileMap;
tileMap = *room->tileMap;
texture = (options->palette == p_zxspectrum) ? textureA : textureB;
this->jailEnabled = jailEnabled;
@@ -533,13 +533,13 @@ void Room::fillMapTexture()
// Al cargar el mapa en memoria, se resta uno, por tanto los tiles vacios son -1
// Tampoco hay que dibujar los tiles animados que estan en la fila 19 (indices)
const int index = (y * mapWidth) + x;
const bool a = (tileMap->at(index) >= 18 * tileSetWidth) && (tileMap->at(index) < 19 * tileSetWidth);
const bool b = tileMap->at(index) > -1;
const bool a = (tileMap.at(index) >= 18 * tileSetWidth) && (tileMap.at(index) < 19 * tileSetWidth);
const bool b = tileMap.at(index) > -1;
if (b && !a)
{
clip.x = (tileMap->at(index) % tileSetWidth) * tileSize;
clip.y = (tileMap->at(index) / tileSetWidth) * tileSize;
clip.x = (tileMap.at(index) % tileSetWidth) * tileSize;
clip.y = (tileMap.at(index) / tileSetWidth) * tileSize;
texture->render(renderer, x * tileSize, y * tileSize, &clip);
// ****
@@ -739,37 +739,37 @@ tile_e Room::getTile(int index)
if (index < maxTile)
{
// Las filas 0-8 son de tiles t_wall
if ((tileMap->at(index) >= 0) && (tileMap->at(index) < 9 * tileSetWidth))
if ((tileMap.at(index) >= 0) && (tileMap.at(index) < 9 * tileSetWidth))
{
return t_wall;
}
// Las filas 9-17 son de tiles t_passable
else if ((tileMap->at(index) >= 9 * tileSetWidth) && (tileMap->at(index) < 18 * tileSetWidth))
else if ((tileMap.at(index) >= 9 * tileSetWidth) && (tileMap.at(index) < 18 * tileSetWidth))
{
return t_passable;
}
// Las filas 18-20 es de tiles t_animated
else if ((tileMap->at(index) >= 18 * tileSetWidth) && (tileMap->at(index) < 21 * tileSetWidth))
else if ((tileMap.at(index) >= 18 * tileSetWidth) && (tileMap.at(index) < 21 * tileSetWidth))
{
return t_animated;
}
// La fila 21 es de tiles t_slope_r
else if ((tileMap->at(index) >= 21 * tileSetWidth) && (tileMap->at(index) < 22 * tileSetWidth))
else if ((tileMap.at(index) >= 21 * tileSetWidth) && (tileMap.at(index) < 22 * tileSetWidth))
{
return t_slope_r;
}
// La fila 22 es de tiles t_slope_l
else if ((tileMap->at(index) >= 22 * tileSetWidth) && (tileMap->at(index) < 23 * tileSetWidth))
else if ((tileMap.at(index) >= 22 * tileSetWidth) && (tileMap.at(index) < 23 * tileSetWidth))
{
return t_slope_l;
}
// La fila 23 es de tiles t_kill
else if ((tileMap->at(index) >= 23 * tileSetWidth) && (tileMap->at(index) < 24 * tileSetWidth))
else if ((tileMap.at(index) >= 23 * tileSetWidth) && (tileMap.at(index) < 24 * tileSetWidth))
{
return t_kill;
}
@@ -897,7 +897,7 @@ void Room::setBottomSurfaces()
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
// Hay que recorrer la habitación por filas (excepto los de la última fila)
for (int i = 0; i < (int)tileMap->size() - mapWidth; ++i)
for (int i = 0; i < (int)tileMap.size() - mapWidth; ++i)
{
if (getTile(i) == t_wall && getTile(i + mapWidth) != t_wall)
{
@@ -960,7 +960,7 @@ void Room::setTopSurfaces()
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tileMap->size(); ++i)
for (int i = mapWidth; i < (int)tileMap.size(); ++i)
{
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - mapWidth) != t_wall)
{
@@ -1117,7 +1117,7 @@ void Room::setLeftSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_l
std::vector<int> found;
for (int i = 0; i < (int)tileMap->size(); ++i)
for (int i = 0; i < (int)tileMap.size(); ++i)
{
if (getTile(i) == t_slope_l)
{
@@ -1158,7 +1158,7 @@ void Room::setRightSlopes()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_slope_r
std::vector<int> found;
for (int i = 0; i < (int)tileMap->size(); ++i)
for (int i = 0; i < (int)tileMap.size(); ++i)
{
if (getTile(i) == t_slope_r)
{
@@ -1201,7 +1201,7 @@ void Room::setAutoSurfaces()
// Busca todos los tiles de tipo animado
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tileMap->size(); ++i)
for (int i = mapWidth; i < (int)tileMap.size(); ++i)
{
if (getTile(i) == t_animated)
{
@@ -1258,7 +1258,7 @@ void Room::setAutoSurfaces()
void Room::setAnimatedTiles()
{
// Recorre la habitación entera por filas buscando tiles de tipo t_animated
for (int i = 0; i < (int)tileMap->size(); ++i)
for (int i = 0; i < (int)tileMap.size(); ++i)
{
if (getTile(i) == t_animated)
{
@@ -1266,9 +1266,9 @@ void Room::setAnimatedTiles()
const int x = (i % mapWidth) * tileSize;
const int y = (i / mapWidth) * tileSize;
// TileMap->at(i) es el tile a poner
const int xc = (tileMap->at(i) % tileSetWidth) * tileSize;
const int yc = (tileMap->at(i) / tileSetWidth) * tileSize;
// TileMap.at(i) es el tile a poner
const int xc = (tileMap.at(i) % tileSetWidth) * tileSize;
const int yc = (tileMap.at(i) / tileSetWidth) * tileSize;
aTile_t at;
at.sprite = new Sprite(x, y, 8, 8, texture, renderer);
@@ -1499,7 +1499,7 @@ void Room::openTheJail()
// Abre las puertas
const int tileA = 16 + (13 * 32);
const int tileB = 16 + (14 * 32);
tileMap->at(tileA) = -1;
tileMap->at(tileB) = -1;
tileMap.at(tileA) = -1;
tileMap.at(tileB) = -1;
}
}

View File

@@ -76,7 +76,6 @@ private:
// Objetos y punteros
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación
std::vector<Item *> items; // Listado con los items que hay en la habitación
std::vector<int> *tileMap; // Indice de los tiles a dibujar en la habitación
Texture *texture; // Textura con los graficos de la habitación
Texture *textureA; // Textura con los graficos de la habitación
Texture *textureB; // Textura con los graficos de la habitación
@@ -101,6 +100,7 @@ private:
std::string roomRight; // Identificador de la habitación que se encuentra a la derecha
std::string tileSetFile; // Imagen con los graficos para la habitación
std::string tileMapFile; // Fichero con el mapa de indices de tile
std::vector<int> tileMap; // Indice de los tiles a dibujar en la habitación
int autoSurfaceDirection; // Sentido en el que arrastran las superficies automáticas de la habitación
JA_Sound itemSound; // Sonido producido al coger un objeto
std::vector<h_line_t> bottomSurfaces; // Lista con las superficies inferiores de la habitación