canvi de pc

This commit is contained in:
2025-02-21 19:45:29 +01:00
parent 5f68c6256f
commit 7a0bc5c9ae
18 changed files with 918 additions and 889 deletions

View File

@@ -53,6 +53,7 @@ Director::Director(int argc, const char *argv[])
#ifdef DEBUG
section->name = SECTION_TITLE;
#endif
Asset::init(argv[0]); // Crea el objeto que controla los ficheros de recursos
// Crea e inicializa las opciones del programa
@@ -88,13 +89,13 @@ Director::Director(int argc, const char *argv[])
initJailAudio();
// Crea los objetos
resource = new Resource(renderer, Asset::get(), options);
input = new Input(Asset::get()->get("gamecontrollerdb.txt"));
Screen::init(window_, renderer_);
Screen::get()->setBorderColor(borderColor);
resource_ = new Resource(options);
Input::init(Asset::get()->get("gamecontrollerdb.txt"));
initInput();
screen = new Screen(window, renderer, Asset::get(), options);
screen->setBorderColor(borderColor);
debug = new Debug(renderer, screen, Asset::get());
music = JA_LoadMusic(Asset::get()->get("title.ogg").c_str());
debug_ = new Debug();
title_music_ = JA_LoadMusic(Asset::get()->get("title.ogg").c_str());
}
Director::~Director()
@@ -105,14 +106,12 @@ Director::~Director()
// Libera la memoria
delete section;
delete options;
delete input;
delete screen;
delete debug;
delete resource;
JA_DeleteMusic(music);
delete debug_;
delete resource_;
JA_DeleteMusic(title_music_);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer_);
SDL_DestroyWindow(window_);
SDL_Quit();
std::cout << "\nBye!" << std::endl;
@@ -172,7 +171,7 @@ void Director::initOptions()
void Director::checkProgramArguments(int argc, const char *argv[])
{
// Establece la ruta del programa
executablePath = argv[0];
executable_path_ = argv[0];
// Comprueba el resto de parametros
for (int i = 1; i < argc; ++i)
@@ -413,7 +412,7 @@ bool Director::saveConfig()
void Director::createSystemFolder(const std::string &folder)
{
#ifdef _WIN32
systemFolder = std::string(getenv("APPDATA")) + "/" + folder;
system_folder_ = std::string(getenv("APPDATA")) + "/" + folder;
#elif __APPLE__
struct passwd *pw = getpwuid(getuid());
const char *homedir = pw->pw_dir;
@@ -436,11 +435,11 @@ void Director::createSystemFolder(const std::string &folder)
#endif
struct stat st = {0};
if (stat(systemFolder.c_str(), &st) == -1)
if (stat(system_folder_.c_str(), &st) == -1)
{
errno = 0;
#ifdef _WIN32
int ret = mkdir(systemFolder.c_str());
int ret = mkdir(system_folder_.c_str());
#else
int ret = mkdir(systemFolder.c_str(), S_IRWXU);
#endif
@@ -483,7 +482,7 @@ void Director::loadResources(section_t *section)
textureList.push_back("jailgames.png");
textureList.push_back("since_1998.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
}
else if (section->name == SECTION_LOADING_SCREEN)
@@ -494,7 +493,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_->loadTextures(textureList);
}
else if (section->name == SECTION_TITLE)
@@ -507,14 +506,14 @@ void Director::loadResources(section_t *section)
textureList.push_back("notify.png");
textureList.push_back("title_logo.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
offsetsList.push_back("subatomic.txt");
resource->loadOffsets(offsetsList);
resource_->loadOffsets(offsetsList);
}
else if (section->name == SECTION_CREDITS)
@@ -524,19 +523,19 @@ void Director::loadResources(section_t *section)
textureList.push_back("shine.png");
textureList.push_back("smb2.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
animationList.push_back("shine.ani");
resource->loadAnimations(animationList);
resource_->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource->loadOffsets(offsetsList);
resource_->loadOffsets(offsetsList);
}
else if (section->name == SECTION_ENDING)
@@ -555,13 +554,13 @@ void Director::loadResources(section_t *section)
textureList.push_back("ending5_zxarne.png");
textureList.push_back("smb2.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource->loadOffsets(offsetsList);
resource_->loadOffsets(offsetsList);
}
else if (section->name == SECTION_ENDING2)
@@ -630,7 +629,7 @@ void Director::loadResources(section_t *section)
// Player
textureList.push_back("player.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
@@ -693,13 +692,13 @@ void Director::loadResources(section_t *section)
// Player
animationList.push_back("player.ani");
resource->loadAnimations(animationList);
resource_->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource->loadOffsets(offsetsList);
resource_->loadOffsets(offsetsList);
}
else if (section->name == SECTION_GAME_OVER)
@@ -710,20 +709,20 @@ void Director::loadResources(section_t *section)
textureList.push_back("player_game_over.png");
textureList.push_back("tv.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
animationList.push_back("player_game_over.ani");
animationList.push_back("tv.ani");
resource->loadAnimations(animationList);
resource_->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource->loadOffsets(offsetsList);
resource_->loadOffsets(offsetsList);
}
else if (section->name == SECTION_GAME || section->name == SECTION_DEMO)
@@ -811,7 +810,7 @@ void Director::loadResources(section_t *section)
textureList.push_back("smb2.png");
textureList.push_back("debug.png");
resource->loadTextures(textureList);
resource_->loadTextures(textureList);
// Animaciones
std::vector<std::string> animationList;
@@ -885,14 +884,14 @@ void Director::loadResources(section_t *section)
animationList.push_back("wave.ani");
animationList.push_back("z80.ani");
resource->loadAnimations(animationList);
resource_->loadAnimations(animationList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
offsetsList.push_back("debug.txt");
resource->loadOffsets(offsetsList);
resource_->loadOffsets(offsetsList);
// TileMaps
std::vector<std::string> tileMapList;
@@ -957,7 +956,7 @@ void Director::loadResources(section_t *section)
tileMapList.push_back("59.tmx");
tileMapList.push_back("60.tmx");
resource->loadTileMaps(tileMapList);
resource_->loadTileMaps(tileMapList);
// Habitaciones
std::vector<std::string> roomList;
@@ -1022,7 +1021,7 @@ void Director::loadResources(section_t *section)
roomList.push_back("59.room");
roomList.push_back("60.room");
resource->loadRooms(roomList);
resource_->loadRooms(roomList);
}
if (options->console)
@@ -1194,68 +1193,68 @@ bool Director::setOptions(options_t *options, std::string var, std::string value
void Director::initInput()
{
// Establece si ha de mostrar mensajes
input->setVerbose(options->console);
Input::get()->setVerbose(options->console);
// Busca si hay un mando conectado
input->discoverGameController();
Input::get()->discoverGameController();
// Teclado - Movimiento
if (options->keys == ctrl_cursor)
{
input->bindKey(input_jump, SDL_SCANCODE_UP);
input->bindKey(input_left, SDL_SCANCODE_LEFT);
input->bindKey(input_right, SDL_SCANCODE_RIGHT);
input->bindKey(input_up, SDL_SCANCODE_UP);
input->bindKey(input_down, SDL_SCANCODE_DOWN);
Input::get()->bindKey(input_jump, SDL_SCANCODE_UP);
Input::get()->bindKey(input_left, SDL_SCANCODE_LEFT);
Input::get()->bindKey(input_right, SDL_SCANCODE_RIGHT);
Input::get()->bindKey(input_up, SDL_SCANCODE_UP);
Input::get()->bindKey(input_down, SDL_SCANCODE_DOWN);
}
else if (options->keys == ctrl_opqa)
{
input->bindKey(input_jump, SDL_SCANCODE_Q);
input->bindKey(input_left, SDL_SCANCODE_O);
input->bindKey(input_right, SDL_SCANCODE_P);
input->bindKey(input_up, SDL_SCANCODE_Q);
input->bindKey(input_down, SDL_SCANCODE_A);
Input::get()->bindKey(input_jump, SDL_SCANCODE_Q);
Input::get()->bindKey(input_left, SDL_SCANCODE_O);
Input::get()->bindKey(input_right, SDL_SCANCODE_P);
Input::get()->bindKey(input_up, SDL_SCANCODE_Q);
Input::get()->bindKey(input_down, SDL_SCANCODE_A);
}
else if (options->keys == ctrl_wasd)
{
input->bindKey(input_jump, SDL_SCANCODE_W);
input->bindKey(input_left, SDL_SCANCODE_A);
input->bindKey(input_right, SDL_SCANCODE_D);
input->bindKey(input_up, SDL_SCANCODE_W);
input->bindKey(input_down, SDL_SCANCODE_S);
Input::get()->bindKey(input_jump, SDL_SCANCODE_W);
Input::get()->bindKey(input_left, SDL_SCANCODE_A);
Input::get()->bindKey(input_right, SDL_SCANCODE_D);
Input::get()->bindKey(input_up, SDL_SCANCODE_W);
Input::get()->bindKey(input_down, SDL_SCANCODE_S);
}
// Teclado - Otros
input->bindKey(input_accept, SDL_SCANCODE_RETURN);
input->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
input->bindKey(input_pause, SDL_SCANCODE_H);
input->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
input->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
input->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
input->bindKey(input_toggle_videomode, SDL_SCANCODE_F3);
input->bindKey(input_toggle_shaders, SDL_SCANCODE_F4);
input->bindKey(input_toggle_palette, SDL_SCANCODE_F5);
input->bindKey(input_toggle_music, SDL_SCANCODE_M);
input->bindKey(input_toggle_border, SDL_SCANCODE_B);
Input::get()->bindKey(input_accept, SDL_SCANCODE_RETURN);
Input::get()->bindKey(input_cancel, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(input_pause, SDL_SCANCODE_H);
Input::get()->bindKey(input_exit, SDL_SCANCODE_ESCAPE);
Input::get()->bindKey(input_window_dec_size, SDL_SCANCODE_F1);
Input::get()->bindKey(input_window_inc_size, SDL_SCANCODE_F2);
Input::get()->bindKey(input_toggle_videomode, SDL_SCANCODE_F3);
Input::get()->bindKey(input_toggle_shaders, SDL_SCANCODE_F4);
Input::get()->bindKey(input_toggle_palette, SDL_SCANCODE_F5);
Input::get()->bindKey(input_toggle_music, SDL_SCANCODE_M);
Input::get()->bindKey(input_toggle_border, SDL_SCANCODE_B);
// Mando - Movimiento
input->bindGameControllerButton(input_jump, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(input_left, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
input->bindGameControllerButton(input_right, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
Input::get()->bindGameControllerButton(input_jump, SDL_CONTROLLER_BUTTON_B);
Input::get()->bindGameControllerButton(input_left, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
Input::get()->bindGameControllerButton(input_right, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
// Mando - Otros
input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A);
Input::get()->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_B);
Input::get()->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A);
#ifdef GAME_CONSOLE
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_BACK);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_START);
Input::get()->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_BACK);
Input::get()->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_START);
#else
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_START);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK);
Input::get()->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_START);
Input::get()->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK);
#endif
input->bindGameControllerButton(input_toggle_palette, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
input->bindGameControllerButton(input_toggle_music, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
input->bindGameControllerButton(input_toggle_border, SDL_CONTROLLER_BUTTON_X);
Input::get()->bindGameControllerButton(input_toggle_palette, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
Input::get()->bindGameControllerButton(input_toggle_music, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
Input::get()->bindGameControllerButton(input_toggle_border, SDL_CONTROLLER_BUTTON_X);
}
// Inicializa JailAudio
@@ -1308,8 +1307,8 @@ bool Director::initSDL()
incH = options->borderHeight * 2;
}
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->gameWidth + incW) * options->windowSize, (options->gameHeight + incH) * options->windowSize, SDL_WINDOW_HIDDEN);
if (window == nullptr)
window_ = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, (options->gameWidth + incW) * options->windowSize, (options->gameHeight + incH) * options->windowSize, SDL_WINDOW_HIDDEN);
if (window_ == nullptr)
{
if (options->console)
{
@@ -1325,9 +1324,9 @@ bool Director::initSDL()
{
flags = flags | SDL_RENDERER_PRESENTVSYNC;
}
renderer = SDL_CreateRenderer(window, -1, flags);
renderer_ = SDL_CreateRenderer(window_, -1, flags);
if (renderer == nullptr)
if (renderer_ == nullptr)
{
if (options->console)
{
@@ -1338,13 +1337,13 @@ bool Director::initSDL()
else
{
// Inicializa el color de renderizado
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_SetRenderDrawColor(renderer_, 0x00, 0x00, 0x00, 0xFF);
// Establece el tamaño del buffer de renderizado
SDL_RenderSetLogicalSize(renderer, options->gameWidth, options->gameHeight);
SDL_RenderSetLogicalSize(renderer_, options->gameWidth, options->gameHeight);
// Establece el modo de mezcla
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
}
}
}
@@ -1383,10 +1382,10 @@ bool Director::setFileList()
Asset::get()->add(prefix + "/data/input/gamecontrollerdb.txt", t_data);
// Ficheros de sistema
Asset::get()->add(systemFolder + "/config.txt", t_data, false, true);
Asset::get()->add(systemFolder + "/stats_buffer.csv", t_data, false, true);
Asset::get()->add(systemFolder + "/stats.csv", t_data, false, true);
Asset::get()->add(systemFolder + "/cheevos.bin", t_data, false, true);
Asset::get()->add(system_folder_ + "/config.txt", t_data, false, true);
Asset::get()->add(system_folder_ + "/stats_buffer.csv", t_data, false, true);
Asset::get()->add(system_folder_ + "/stats.csv", t_data, false, true);
Asset::get()->add(system_folder_ + "/cheevos.bin", t_data, false, true);
// Notificaciones
Asset::get()->add(prefix + "/data/notifications/notify.png", t_bitmap);
@@ -1724,9 +1723,9 @@ void Director::runLogo()
std::cout << "\n* SECTION: LOGO" << std::endl;
}
loadResources(section);
auto logo = std::make_unique<Logo>(renderer, screen, resource, Asset::get(), input, options, section);
auto logo = std::make_unique<Logo>(resource_, options, section);
logo->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion de juego de la pantalla de carga
@@ -1737,9 +1736,9 @@ void Director::runLoadingScreen()
std::cout << "\n* SECTION: INTRO" << std::endl;
}
loadResources(section);
auto loadingScreen = std::make_unique<LoadingScreen>(renderer, screen, resource, Asset::get(), input, options, section);
auto loadingScreen = std::make_unique<LoadingScreen>(resource_, options, section);
loadingScreen->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion de juego con el titulo y los menus
@@ -1751,12 +1750,12 @@ void Director::runTitle()
}
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(music);
JA_PlayMusic(title_music_);
}
loadResources(section);
auto title = std::make_unique<Title>(renderer, screen, resource, input, options, section);
auto title = std::make_unique<Title>(resource_, options, section);
title->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion de los creditos del juego
@@ -1767,9 +1766,9 @@ void Director::runCredits()
std::cout << "\n* SECTION: CREDITS" << std::endl;
}
loadResources(section);
auto credits = std::make_unique<Credits>(renderer, screen, resource, Asset::get(), input, options, section);
auto credits = std::make_unique<Credits>(resource_, options, section);
credits->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
@@ -1780,9 +1779,9 @@ void Director::runDemo()
std::cout << "\n* SECTION: DEMO" << std::endl;
}
loadResources(section);
auto demo = std::make_unique<Demo>(renderer, screen, resource, Asset::get(), input, options, section, debug);
auto demo = std::make_unique<Demo>(resource_, options, section, debug_);
demo->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion del final del juego
@@ -1793,9 +1792,9 @@ void Director::runEnding()
std::cout << "\n* SECTION: ENDING" << std::endl;
}
loadResources(section);
auto ending = std::make_unique<Ending>(renderer, screen, resource, Asset::get(), input, options, section);
auto ending = std::make_unique<Ending>(resource_, options, section);
ending->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion del final del juego
@@ -1806,9 +1805,9 @@ void Director::runEnding2()
std::cout << "\n* SECTION: ENDING2" << std::endl;
}
loadResources(section);
auto ending2 = std::make_unique<Ending2>(renderer, screen, resource, Asset::get(), input, options, section);
auto ending2 = std::make_unique<Ending2>(resource_, options, section);
ending2->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion del final de la partida
@@ -1819,9 +1818,9 @@ void Director::runGameOver()
std::cout << "\n* SECTION: GAME OVER" << std::endl;
}
loadResources(section);
auto gameOver = std::make_unique<GameOver>(renderer, screen, resource, Asset::get(), input, options, section);
auto gameOver = std::make_unique<GameOver>(resource_, options, section);
gameOver->run();
resource->free();
resource_->free();
}
// Ejecuta la seccion de juego donde se juega
@@ -1833,9 +1832,9 @@ void Director::runGame()
}
JA_StopMusic();
loadResources(section);
auto game = std::make_unique<Game>(renderer, screen, resource, Asset::get(), options, input, section, debug);
auto game = std::make_unique<Game>(resource_, options, section, debug_);
game->run();
resource->free();
resource_->free();
}
int Director::run()