El joc ja reinicia correctament
This commit is contained in:
@@ -46,13 +46,6 @@
|
||||
#include <pwd.h> // para getpwuid, passwd
|
||||
#endif
|
||||
|
||||
// Inicia la semilla aleatoria
|
||||
void initRand()
|
||||
{
|
||||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
std::srand(seed);
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Director::Director(int argc, const char *argv[])
|
||||
{
|
||||
@@ -74,42 +67,36 @@ Director::Director(int argc, const char *argv[])
|
||||
|
||||
std::cout << "Game start" << std::endl;
|
||||
|
||||
initRand();
|
||||
// Inicia la semilla aleatoria
|
||||
unsigned int seed = static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count());
|
||||
std::srand(seed);
|
||||
|
||||
// Comprueba los parametros del programa
|
||||
checkProgramArguments(argc, argv);
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
// Crea la carpeta del sistema donde guardar los datos persistentes
|
||||
createSystemFolder("jailgames");
|
||||
createSystemFolder("jailgames/coffee_crisis_arcade_edition");
|
||||
|
||||
// Crea el objeto que controla los ficheros de recursos
|
||||
Asset::init(executable_path_);
|
||||
init();
|
||||
}
|
||||
|
||||
// Crea el indice de ficheros
|
||||
setFileList();
|
||||
Director::~Director()
|
||||
{
|
||||
close();
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
}
|
||||
|
||||
// Carga el fichero de configuración
|
||||
loadOptionsFile(Asset::get()->get("config.txt"));
|
||||
// Inicializa todo
|
||||
void Director::init()
|
||||
{
|
||||
Asset::init(executable_path_); // Crea el objeto que controla los ficheros de recursos
|
||||
setFileList(); // Crea el indice de ficheros
|
||||
loadOptionsFile(Asset::get()->get("config.txt")); // Carga el fichero de configuración
|
||||
loadParams(); // Carga los parametros
|
||||
loadScoreFile(); // Carga el fichero de puntuaciones
|
||||
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParamsFromFile(paramFilePath);
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
{
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||
if (overrides.clear_hi_score_table)
|
||||
manager->clear();
|
||||
else
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
|
||||
// Inicializa todo
|
||||
// Inicializa y crea el resto de objetos
|
||||
initSDL();
|
||||
initJailAudio();
|
||||
dbg_init(renderer_);
|
||||
@@ -123,7 +110,8 @@ Director::Director(int argc, const char *argv[])
|
||||
globalInputs::init();
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
// Cierra todo
|
||||
void Director::close()
|
||||
{
|
||||
saveOptionsFile(Asset::get()->get("config.txt"));
|
||||
|
||||
@@ -134,12 +122,38 @@ Director::~Director()
|
||||
Notifier::destroy();
|
||||
OnScreenHelp::destroy();
|
||||
|
||||
JA_Quit();
|
||||
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
SDL_DestroyWindow(window_);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
std::cout << "\nBye!" << std::endl;
|
||||
// Carga los parametros
|
||||
void Director::loadParams()
|
||||
{
|
||||
// Carga los parametros para configurar el juego
|
||||
#ifdef ANBERNIC
|
||||
const std::string paramFilePath = asset->get("param_320x240.txt");
|
||||
#else
|
||||
const std::string paramFilePath = overrides.param_file == "--320x240" ? Asset::get()->get("param_320x240.txt") : Asset::get()->get("param_320x256.txt");
|
||||
#endif
|
||||
loadParamsFromFile(paramFilePath);
|
||||
}
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
void Director::loadScoreFile()
|
||||
{
|
||||
auto manager = std::make_unique<ManageHiScoreTable>(options.game.hi_score_table);
|
||||
if (overrides.clear_hi_score_table)
|
||||
{
|
||||
manager->clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager->loadFromFile(Asset::get()->get("score.bin"));
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna los botones y teclas al objeto Input
|
||||
@@ -664,6 +678,7 @@ int Director::run()
|
||||
switch (section::name)
|
||||
{
|
||||
case section::Name::INIT:
|
||||
Resource::get()->reload();
|
||||
section::name = section::Name::LOGO;
|
||||
break;
|
||||
case section::Name::LOGO:
|
||||
|
||||
@@ -74,6 +74,18 @@ private:
|
||||
void shutdownSystem();
|
||||
#endif
|
||||
|
||||
// Inicializa todo
|
||||
void init();
|
||||
|
||||
// Cierra todo
|
||||
void close();
|
||||
|
||||
// Carga los parametros
|
||||
void loadParams();
|
||||
|
||||
// Carga el fichero de puntuaciones
|
||||
void loadScoreFile();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Director(int argc, const char *argv[]);
|
||||
|
||||
@@ -83,14 +83,28 @@ namespace globalInputs
|
||||
case lang::Code::es_ES:
|
||||
return Asset::get()->get("es_ES.txt");
|
||||
break;
|
||||
case lang::Code::en_UK:
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
break;
|
||||
default:
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
break;
|
||||
}
|
||||
|
||||
return Asset::get()->get("en_UK.txt");
|
||||
}
|
||||
|
||||
// Obtiene una cadena a partir de un lang::Code
|
||||
std::string getLangName(lang::Code code)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case lang::Code::ba_BA:
|
||||
return "ba_BA";
|
||||
break;
|
||||
case lang::Code::es_ES:
|
||||
return "es_ES";
|
||||
break;
|
||||
default:
|
||||
return "en_UK";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia el idioma
|
||||
@@ -99,7 +113,7 @@ namespace globalInputs
|
||||
options.game.language = lang::change(options.game.language);
|
||||
lang::loadFromFile(getLangFile(static_cast<lang::Code>(options.game.language)));
|
||||
section::name = section::Name::INIT;
|
||||
Notifier::get()->showText({"Reset"});
|
||||
Notifier::get()->showText({getLangName(options.game.language)});
|
||||
}
|
||||
|
||||
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
|
||||
|
||||
@@ -34,6 +34,24 @@ Resource *Resource::get()
|
||||
|
||||
// Constructor
|
||||
Resource::Resource()
|
||||
{
|
||||
load();
|
||||
}
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void Resource::clear()
|
||||
{
|
||||
sounds_.clear();
|
||||
musics_.clear();
|
||||
textures_.clear();
|
||||
text_files_.clear();
|
||||
texts_.clear();
|
||||
animations_.clear();
|
||||
demos_.clear();
|
||||
}
|
||||
|
||||
// Carga todos los recursos
|
||||
void Resource::load()
|
||||
{
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
loadSounds();
|
||||
@@ -48,6 +66,13 @@ Resource::Resource()
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
}
|
||||
|
||||
// Recarga todos los recursos
|
||||
void Resource::reload()
|
||||
{
|
||||
clear();
|
||||
load();
|
||||
}
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t *Resource::getSound(const std::string &name)
|
||||
{
|
||||
|
||||
@@ -117,6 +117,12 @@ private:
|
||||
// Crea los objetos de texto
|
||||
void createText();
|
||||
|
||||
// Vacia todos los vectores de recursos
|
||||
void clear();
|
||||
|
||||
// Carga todos los recursos
|
||||
void load();
|
||||
|
||||
// [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos resource desde fuera
|
||||
|
||||
// Constructor
|
||||
@@ -155,4 +161,7 @@ public:
|
||||
|
||||
// Obtiene el fichero con los datos para el modo demostración a partir de un çindice
|
||||
DemoData &getDemoData(int index);
|
||||
|
||||
// Recarga todos los recursos
|
||||
void reload();
|
||||
};
|
||||
Reference in New Issue
Block a user