Trabajando en la precarga de habitaciones

This commit is contained in:
2022-10-30 13:27:30 +01:00
parent d1c27c4639
commit c11f5d2622
74 changed files with 1028 additions and 754 deletions

View File

@@ -14,7 +14,7 @@ void Resource::loadTextures(std::vector<std::string> list)
{
for (auto l : list)
{
texture_t t;
res_texture_t t;
t.name = l;
t.texture = new Texture(renderer, asset->get(l));
textures.push_back(t);
@@ -26,7 +26,7 @@ void Resource::loadAnimations(std::vector<std::string> list)
{
for (auto l : list)
{
animation_t as;
res_animation_t as;
as.name = l + ".ani";
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(l + ".png"), asset->get(l + ".ani")));
animations.push_back(as);
@@ -38,13 +38,48 @@ void Resource::loadOffsets(std::vector<std::string> list)
{
for (auto l : list)
{
textOffset_t to;
res_textOffset_t to;
to.name = l;
to.textFile = new textFile_t(LoadTextFile(asset->get(l)));
offsets.push_back(to);
}
}
// Carga los mapas de tiles desde una lista
void Resource::loadTileMaps(std::vector<std::string> list)
{
for (auto l : list)
{
res_tileMap_t tm;
tm.name = l;
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(l)));
tileMaps.push_back(tm);
}
}
// Carga las habitaciones desde una lista
void Resource::loadRooms(std::vector<std::string> list)
{
for (auto l : list)
{
res_room_t r;
r.name = l;
r.room = new room_t(loadRoomFile(asset->get(l)));
r.room->tileMap = getTileMap(r.room->tileMapFile);
for (auto &e:r.room->enemies)
{
e.animation = getAnimation(e.animationString);
}
for (auto &i:r.room->items)
{
i.texture = getTexture(i.tileSetFile);
}
r.room->textureA = getTexture("standard.png");
r.room->textureB = getTexture("standard_zxarne.png");
rooms.push_back(r);
}
}
// Recarga las texturas
void Resource::reLoadTextures()
{
@@ -84,12 +119,34 @@ void Resource::freeOffsets()
offsets.clear();
}
// Libera los mapas de tiles
void Resource::freeTileMaps()
{
for (auto t : tileMaps)
{
delete t.tileMap;
}
tileMaps.clear();
}
// Libera las habitaciones
void Resource::freeRooms()
{
for (auto r : rooms)
{
delete r.room;
}
rooms.clear();
}
// Libera todos los recursos
void Resource::free()
{
freeTextures();
freeAnimations();
freeOffsets();
freeTileMaps();
freeRooms();
}
// Obtiene una textura
@@ -99,12 +156,11 @@ Texture *Resource::getTexture(std::string name)
{
if (texture.name.find(name) != std::string::npos)
{
std::cout << "CACHE: " << name << std::endl;
return texture.texture;
}
}
std::cout << "NOT FOUND: " << name << std::endl;
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
@@ -115,12 +171,11 @@ animatedSprite_t *Resource::getAnimation(std::string name)
{
if (animation.name.find(name) != std::string::npos)
{
std::cout << "CACHE: " << name << std::endl;
return animation.animation;
}
}
std::cout << "NOT FOUND: " << name << std::endl;
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
@@ -131,11 +186,40 @@ textFile_t *Resource::getOffset(std::string name)
{
if (offset.name.find(name) != std::string::npos)
{
std::cout << "CACHE: " << name << std::endl;
return offset.textFile;
}
}
std::cout << "NOT FOUND: " << name << std::endl;
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
// Obtiene un mapa de tiles
std::vector<int> *Resource::getTileMap(std::string name)
{
for (auto tileMap : tileMaps)
{
if (tileMap.name.find(name) != std::string::npos)
{
return tileMap.tileMap;
}
}
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}
// Obtiene una habitacion
room_t *Resource::getRoom(std::string name)
{
for (auto room : rooms)
{
if (room.name.find(name) != std::string::npos)
{
return room.room;
}
}
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
return nullptr;
}