Singletonejant

Borrat menu.cpp que no estava gastantse...mmm.. desde mai
This commit is contained in:
2025-02-22 18:27:23 +01:00
parent e361d295c1
commit fc01676df2
38 changed files with 440 additions and 1751 deletions

View File

@@ -84,11 +84,11 @@ Director::Director(int argc, const char *argv[])
// Crea los objetos
Screen::init(window_, renderer_);
Screen::get()->setBorderColor(borderColor);
Resource::init();
Notifier::init(Asset::get()->get("notify.png"), Asset::get()->get("smb2.png"), Asset::get()->get("smb2.txt"), Asset::get()->get("notify.wav"));
resource_ = new Resource();
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
initInput();
debug_ = new Debug();
Debug::init();
title_music_ = JA_LoadMusic(Asset::get()->get("title.ogg").c_str());
}
@@ -97,13 +97,14 @@ Director::~Director()
// Guarda las opciones a un fichero
saveOptionsFromFile(Asset::get()->get("config.txt"));
// Libera la memoria
// Destruye los singletones
Asset::destroy();
Input::destroy();
Screen::destroy();
Notifier::destroy();
delete debug_;
delete resource_;
Debug::destroy();
Resource::destroy();
JA_DeleteMusic(title_music_);
SDL_DestroyRenderer(renderer_);
@@ -223,7 +224,7 @@ void Director::loadResources(section_t section)
textureList.push_back("jailgames.png");
textureList.push_back("since_1998.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
}
else if (options.section.name == SECTION_LOADING_SCREEN)
@@ -234,7 +235,7 @@ void Director::loadResources(section_t section)
textureList.push_back("loading_screen_bn_zxarne.png");
textureList.push_back("loading_screen_color_zxarne.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
}
else if (options.section.name == SECTION_TITLE)
@@ -247,14 +248,14 @@ void Director::loadResources(section_t section)
textureList.push_back("notify.png");
textureList.push_back("title_logo.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
offsetsList.push_back("subatomic.txt");
resource_->loadOffsets(offsetsList);
Resource::get()->loadOffsets(offsetsList);
}
else if (options.section.name == SECTION_CREDITS)
@@ -264,19 +265,19 @@ void Director::loadResources(section_t section)
textureList.push_back("shine.png");
textureList.push_back("smb2.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
animationList.push_back("shine.ani");
resource_->loadAnimations(animationList);
Resource::get()->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource_->loadOffsets(offsetsList);
Resource::get()->loadOffsets(offsetsList);
}
else if (options.section.name == SECTION_ENDING)
@@ -295,13 +296,13 @@ void Director::loadResources(section_t section)
textureList.push_back("ending5_zxarne.png");
textureList.push_back("smb2.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource_->loadOffsets(offsetsList);
Resource::get()->loadOffsets(offsetsList);
}
else if (options.section.name == SECTION_ENDING2)
@@ -370,7 +371,7 @@ void Director::loadResources(section_t section)
// Player
textureList.push_back("player.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
@@ -433,13 +434,13 @@ void Director::loadResources(section_t section)
// Player
animationList.push_back("player.ani");
resource_->loadAnimations(animationList);
Resource::get()->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource_->loadOffsets(offsetsList);
Resource::get()->loadOffsets(offsetsList);
}
else if (options.section.name == SECTION_GAME_OVER)
@@ -450,20 +451,20 @@ void Director::loadResources(section_t section)
textureList.push_back("player_game_over.png");
textureList.push_back("tv.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
animationList.push_back("player_game_over.ani");
animationList.push_back("tv.ani");
resource_->loadAnimations(animationList);
Resource::get()->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource_->loadOffsets(offsetsList);
Resource::get()->loadOffsets(offsetsList);
}
else if (options.section.name == SECTION_GAME || options.section.name == SECTION_DEMO)
@@ -551,7 +552,7 @@ void Director::loadResources(section_t section)
textureList.push_back("smb2.png");
textureList.push_back("debug.png");
resource_->loadTextures(textureList);
Resource::get()->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
@@ -625,14 +626,14 @@ void Director::loadResources(section_t section)
animationList.push_back("wave.ani");
animationList.push_back("z80.ani");
resource_->loadAnimations(animationList);
Resource::get()->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
offsetsList.push_back("debug.txt");
resource_->loadOffsets(offsetsList);
Resource::get()->loadOffsets(offsetsList);
// TileMaps
std::vector<std::string> tileMapList;
@@ -697,7 +698,7 @@ void Director::loadResources(section_t section)
tileMapList.push_back("59.tmx");
tileMapList.push_back("60.tmx");
resource_->loadTileMaps(tileMapList);
Resource::get()->loadTileMaps(tileMapList);
// Habitaciones
std::vector<std::string> roomList;
@@ -762,7 +763,7 @@ void Director::loadResources(section_t section)
roomList.push_back("59.room");
roomList.push_back("60.room");
resource_->loadRooms(roomList);
Resource::get()->loadRooms(roomList);
}
if (options.console)
@@ -1305,9 +1306,9 @@ void Director::runLogo()
std::cout << "\n* SECTION: LOGO" << std::endl;
}
loadResources(options.section);
auto logo = std::make_unique<Logo>(resource_);
auto logo = std::make_unique<Logo>();
logo->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion de juego de la pantalla de carga
@@ -1318,9 +1319,9 @@ void Director::runLoadingScreen()
std::cout << "\n* SECTION: INTRO" << std::endl;
}
loadResources(options.section);
auto loadingScreen = std::make_unique<LoadingScreen>(resource_);
auto loadingScreen = std::make_unique<LoadingScreen>();
loadingScreen->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion de juego con el titulo y los menus
@@ -1335,9 +1336,9 @@ void Director::runTitle()
JA_PlayMusic(title_music_);
}
loadResources(options.section);
auto title = std::make_unique<Title>(resource_);
auto title = std::make_unique<Title>();
title->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion de los creditos del juego
@@ -1348,9 +1349,9 @@ void Director::runCredits()
std::cout << "\n* SECTION: CREDITS" << std::endl;
}
loadResources(options.section);
auto credits = std::make_unique<Credits>(resource_);
auto credits = std::make_unique<Credits>();
credits->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
@@ -1361,9 +1362,9 @@ void Director::runDemo()
std::cout << "\n* SECTION: DEMO" << std::endl;
}
loadResources(options.section);
auto demo = std::make_unique<Demo>(resource_, debug_);
auto demo = std::make_unique<Demo>();
demo->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion del final del juego
@@ -1374,9 +1375,9 @@ void Director::runEnding()
std::cout << "\n* SECTION: ENDING" << std::endl;
}
loadResources(options.section);
auto ending = std::make_unique<Ending>(resource_);
auto ending = std::make_unique<Ending>();
ending->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion del final del juego
@@ -1387,9 +1388,9 @@ void Director::runEnding2()
std::cout << "\n* SECTION: ENDING2" << std::endl;
}
loadResources(options.section);
auto ending2 = std::make_unique<Ending2>(resource_);
auto ending2 = std::make_unique<Ending2>();
ending2->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion del final de la partida
@@ -1400,9 +1401,9 @@ void Director::runGameOver()
std::cout << "\n* SECTION: GAME OVER" << std::endl;
}
loadResources(options.section);
auto gameOver = std::make_unique<GameOver>(resource_);
auto gameOver = std::make_unique<GameOver>();
gameOver->run();
resource_->free();
Resource::get()->free();
}
// Ejecuta la seccion de juego donde se juega
@@ -1414,9 +1415,9 @@ void Director::runGame()
}
JA_StopMusic();
loadResources(options.section);
auto game = std::make_unique<Game>(resource_, debug_);
auto game = std::make_unique<Game>();
game->run();
resource_->free();
Resource::get()->free();
}
int Director::run()