diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef228e..bc007ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC") endif() # Establecer estándar de C++ -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) # Configuración global de flags de compilación diff --git a/Makefile b/Makefile index ba8e94c..bbeaaa8 100644 --- a/Makefile +++ b/Makefile @@ -11,15 +11,18 @@ macosIntelRelease = $(executable)-$(version)-macos-intel.dmg macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg linuxRelease = $(executable)-$(version)-linux.tar.gz +# Specify the C++ standard +cpp_standard = c++20 + windows: @echo off windres release/coffee.rc -O coff -o $(resource_file) - g++ $(source) $(resource_file) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe" + g++ $(source) $(resource_file) -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe" strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded windows_debug: @echo off - g++ $(source) -D DEBUG -D PAUSE -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe" + g++ $(source) -D DEBUG -D PAUSE -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe" strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded windows_release: @@ -38,7 +41,7 @@ windows_release: powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)" # Build - g++ $(source) $(resource_file) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe" + g++ $(source) $(resource_file) -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe" strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded # Create ZIP @@ -49,10 +52,10 @@ windows_release: powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force} macos: - clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)" + clang++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)" macos_debug: - clang++ $(source) -D DEBUG -D PAUSE -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug" + clang++ $(source) -D DEBUG -D PAUSE -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug" macos_release: # Remove data and possible data from previous builds @@ -83,7 +86,7 @@ macos_release: ln -s /Applications "$(releaseFolder)"/Applications # Build INTEL - clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12 + clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12 # Build INTEL DMG hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)" @@ -91,7 +94,7 @@ macos_release: rm -f tmp.dmg # Build APPLE SILICON - clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11 + clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11 # Build APPLE SILICON DMG hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)" @@ -103,11 +106,11 @@ macos_release: rm -rdf "$(releaseFolder)" linux: - g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)" + g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)" strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded linux_debug: - g++ $(source) -D DEBUG -D PAUSE -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug" + g++ $(source) -D DEBUG -D PAUSE -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug" strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded linux_release: @@ -123,7 +126,7 @@ linux_release: cp README.md "$(releaseFolder)" # Build - g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)" + g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)" strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded # Pack files diff --git a/source/director.cpp b/source/director.cpp index 950462c..76102da 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -18,6 +18,7 @@ #include // for cout #include // for basic_string, operator+, char_t... #include // for vector +#include #include "asset.h" // for Asset, assetType #include "const.h" // for SECTION_PROG_LOGO, GAMECANVAS_H... #include "game.h" // for Game @@ -35,8 +36,9 @@ #endif // Constructor -Director::Director(int argc, char *argv[]) +Director::Director(int argc, const char *argv[]) { + std::cout << "Game start" << std::endl; // Inicializa variables section = new section_t(); section->name = SECTION_PROG_LOGO; @@ -99,6 +101,8 @@ Director::~Director() SDL_DestroyWindow(window); SDL_Quit(); + + std::cout << "\nBye!" << std::endl; } // Inicializa el objeto input @@ -416,7 +420,7 @@ void Director::initOptions() } // Comprueba los parametros del programa -void Director::checkProgramArguments(int argc, char *argv[]) +void Director::checkProgramArguments(int argc, const char *argv[]) { // Establece la ruta del programa executablePath = argv[0]; @@ -639,34 +643,30 @@ bool Director::saveConfigFile() void Director::runLogo() { - logo = new Logo(renderer, screen, asset, input, section); + auto logo = std::make_unique(renderer, screen, asset, input, section); logo->run(); - delete logo; } void Director::runIntro() { - intro = new Intro(renderer, screen, asset, input, lang, section); + auto intro = std::make_unique(renderer, screen, asset, input, lang, section); intro->run(); - delete intro; } void Director::runTitle() { - title = new Title(renderer, screen, input, asset, options, lang, section); + auto title = std::make_unique(renderer, screen, input, asset, options, lang, section); title->run(); - delete title; } void Director::runGame() { const int numPlayers = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2; - game = new Game(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section); + auto game = std::make_unique<Game>(numPlayers, 0, renderer, screen, asset, lang, input, false, options, section); game->run(); - delete game; } -void Director::run() +int Director::run() { // Bucle principal while (section->name != SECTION_PROG_QUIT) @@ -690,6 +690,8 @@ void Director::run() break; } } + + return 0; } // Asigna variables a partir de dos cadenas diff --git a/source/director.h b/source/director.h index 603639e..3a7926f 100644 --- a/source/director.h +++ b/source/director.h @@ -24,10 +24,6 @@ private: SDL_Window *window; // La ventana donde dibujamos SDL_Renderer *renderer; // El renderizador de la ventana Screen *screen; // Objeto encargado de dibujar en pantalla - Logo *logo; // Objeto para la sección del logo - Intro *intro; // Objeto para la sección de la intro - Title *title; // Objeto para la sección del titulo y el menu de opciones - Game *game; // Objeto para la sección del juego Input *input; // Objeto Input para gestionar las entradas Lang *lang; // Objeto para gestionar los textos en diferentes idiomas Asset *asset; // Objeto que gestiona todos los ficheros de recursos @@ -63,7 +59,7 @@ private: bool saveConfigFile(); // Comprueba los parametros del programa - void checkProgramArguments(int argc, char *argv[]); + void checkProgramArguments(int argc, const char *argv[]); // Crea la carpeta del sistema donde guardar datos void createSystemFolder(const std::string &folder); @@ -82,11 +78,11 @@ private: public: // Constructor - Director(int argc, char *argv[]); + Director(int argc, const char *argv[]); // Destructor ~Director(); // Bucle principal - void run(); + int run(); }; diff --git a/source/main.cpp b/source/main.cpp index 97a2454..a3246a3 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -39,24 +39,14 @@ Reescribiendo el código el 27/09/2022 */ -#include <iostream> // for char_traits, basic_ostream, operator<<, endl -#include "director.h" // for Director +#include <memory> +#include "director.h" int main(int argc, char *argv[]) { - std::cout << "Starting the game..." << std::endl - << std::endl; - // Crea el objeto Director - Director *director = new Director(argc, argv); + auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv)); // Bucle principal - director->run(); - - // Destruye el objeto Director - delete director; - - std::cout << "\nShutting down the game..." << std::endl; - - return 0; -} + return director->run(); +} \ No newline at end of file