diff --git a/CMakeLists.txt b/CMakeLists.txt index f6bdd6ed..38bc6dff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ option(ENABLE_HTTP_SERVER "Enable HTTP server. Used for Discord bot support" OFF option(ENABLE_DISCORD_RPC "Compile with Discord RPC support (disabled by default)" ON) option(ENABLE_LUAJIT "Enable scripting with the Lua programming language" ON) option(ENABLE_QT_GUI "Enable the Qt GUI. If not selected then the emulator uses a minimal SDL-based UI instead" OFF) +option(ENABLE_GIT_VERSIONING "Enables querying git for the emulator version" ON) option(BUILD_HYDRA_CORE "Build a Hydra core" OFF) option(BUILD_LIBRETRO_CORE "Build a Libretro core" OFF) @@ -60,6 +61,37 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND ENABLE_USER_BUILD) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS-") endif() +# Generate versioning files +find_package(Git) +set(PANDA3DS_VERSION "0.8") + +if(NOT EXISTS ${CMAKE_BINARY_DIR}/include/version.hpp.in) + file(WRITE ${CMAKE_BINARY_DIR}/include/version.hpp.in "#define PANDA3DS_VERSION \"\${PANDA3DS_VERSION}\"") +endif() + +if(GIT_FOUND AND ENABLE_GIT_VERSIONING) + execute_process( + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 + OUTPUT_VARIABLE PANDA3DS_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --tags + OUTPUT_VARIABLE git_version_tag OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT PANDA3DS_VERSION STREQUAL git_version_tag) + execute_process( + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} describe --always --abbrev=7 + OUTPUT_VARIABLE git_version_rev OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(PANDA3DS_VERSION "${PANDA3DS_VERSION}.${git_version_rev}") + unset(git_version_rev) + endif() + string(REGEX REPLACE "^v" "" PANDA3DS_VERSION "${PANDA3DS_VERSION}") + unset(git_version_tag) +endif() +configure_file(${CMAKE_BINARY_DIR}/include/version.hpp.in ${CMAKE_BINARY_DIR}/include/version.hpp) +include_directories(${CMAKE_BINARY_DIR}/include/) + add_library(AlberCore STATIC) include_directories(${PROJECT_SOURCE_DIR}/include/) diff --git a/include/config.hpp b/include/config.hpp index 52be1af7..8833e4b3 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -40,6 +40,9 @@ struct EmulatorConfig { bool audioEnabled = false; bool vsyncEnabled = true; + bool printAppVersion = true; + bool appVersionOnWindow = false; + bool chargerPlugged = true; // Default to 3% battery to make users suffer int batteryPercentage = 3; diff --git a/src/config.cpp b/src/config.cpp index dae5a0ab..e1bbf2e4 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -41,6 +41,9 @@ void EmulatorConfig::load() { discordRpcEnabled = toml::find_or(general, "EnableDiscordRPC", false); usePortableBuild = toml::find_or(general, "UsePortableBuild", false); defaultRomPath = toml::find_or(general, "DefaultRomPath", ""); + + printAppVersion = toml::find_or(general, "PrintAppVersion", true); + appVersionOnWindow = toml::find_or(general, "AppVersionOnWindow", false); } } @@ -127,6 +130,8 @@ void EmulatorConfig::save() { data["General"]["EnableDiscordRPC"] = discordRpcEnabled; data["General"]["UsePortableBuild"] = usePortableBuild; data["General"]["DefaultRomPath"] = defaultRomPath.string(); + data["General"]["PrintAppVersion"] = printAppVersion; + data["General"]["AppVersionOnWindow"] = appVersionOnWindow; data["GPU"]["EnableShaderJIT"] = shaderJitEnabled; data["GPU"]["Renderer"] = std::string(Renderer::typeToString(rendererType)); diff --git a/src/hydra_core.cpp b/src/hydra_core.cpp index acbf30a8..04fcdbdb 100644 --- a/src/hydra_core.cpp +++ b/src/hydra_core.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -150,7 +151,7 @@ HC_API const char* getInfo(hydra::InfoType type) { case hydra::InfoType::SystemName: return "Nintendo 3DS"; case hydra::InfoType::Description: return "HLE 3DS emulator. There's a little Alber in your computer and he runs Nintendo 3DS games."; case hydra::InfoType::Author: return "wheremyfoodat (Peach)"; - case hydra::InfoType::Version: return "0.7"; + case hydra::InfoType::Version: return PANDA3DS_VERSION; case hydra::InfoType::License: return "GPLv3"; case hydra::InfoType::Website: return "https://panda3ds.com/"; case hydra::InfoType::Extensions: return "3ds,cci,cxi,app,3dsx,elf,axf"; diff --git a/src/libretro_core.cpp b/src/libretro_core.cpp index 304314ba..cd0e9747 100644 --- a/src/libretro_core.cpp +++ b/src/libretro_core.cpp @@ -4,6 +4,7 @@ #include +#include #include #include @@ -200,7 +201,7 @@ static void ConfigCheckVariables() { void retro_get_system_info(retro_system_info* info) { info->need_fullpath = true; info->valid_extensions = "3ds|3dsx|elf|axf|cci|cxi|app"; - info->library_version = "0.8"; + info->library_version = PANDA3DS_VERSION; info->library_name = "Panda3DS"; info->block_extract = true; } diff --git a/src/panda_qt/about_window.cpp b/src/panda_qt/about_window.cpp index 67767198..60a91272 100644 --- a/src/panda_qt/about_window.cpp +++ b/src/panda_qt/about_window.cpp @@ -1,4 +1,5 @@ #include "panda_qt/about_window.hpp" +#include "version.hpp" #include #include @@ -17,6 +18,8 @@ AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { QStringLiteral(R"(

Panda3DS

+

v%VERSION_STRING%

+

%ABOUT_PANDA3DS%
%SUPPORT%
@@ -26,6 +29,7 @@ AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { %AUTHORS%

)") + .replace(QStringLiteral("%VERSION_STRING%"), PANDA3DS_VERSION) .replace(QStringLiteral("%ABOUT_PANDA3DS%"), tr("Panda3DS is a free and open source Nintendo 3DS emulator, for Windows, MacOS and Linux")) .replace(QStringLiteral("%SUPPORT%"), tr("Visit panda3ds.com for help with Panda3DS and links to our official support sites.")) .replace( diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index 6bdffb7e..45690da7 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -7,6 +7,7 @@ #include #include +#include "version.hpp" #include "cheats.hpp" #include "input_mappings.hpp" #include "sdl_sensors.hpp" @@ -98,6 +99,14 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) } } + if (emu->getConfig().appVersionOnWindow) { + setWindowTitle("Alber v" PANDA3DS_VERSION); + } + + if (emu->getConfig().printAppVersion) { + printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION); + } + // The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work emuThread = std::thread([this]() { const RendererType rendererType = emu->getConfig().rendererType; diff --git a/src/panda_sdl/frontend_sdl.cpp b/src/panda_sdl/frontend_sdl.cpp index 90166899..c892c3c5 100644 --- a/src/panda_sdl/frontend_sdl.cpp +++ b/src/panda_sdl/frontend_sdl.cpp @@ -1,4 +1,5 @@ #include "panda_sdl/frontend_sdl.hpp" +#include "version.hpp" #include @@ -33,13 +34,18 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp needOpenGL = needOpenGL || (config.rendererType == RendererType::OpenGL); #endif + const char* windowTitle = config.appVersionOnWindow ? ("Alber v" PANDA3DS_VERSION) : "Alber"; + if (config.printAppVersion) { + printf("Welcome to Panda3DS v%s!\n", PANDA3DS_VERSION); + } + if (needOpenGL) { // Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS) // MacOS gets mad if we don't explicitly demand a core profile SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, config.rendererType == RendererType::Software ? 3 : 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, config.rendererType == RendererType::Software ? 3 : 1); - window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); if (window == nullptr) { Helpers::panic("Window creation failed: %s", SDL_GetError()); @@ -59,7 +65,7 @@ FrontendSDL::FrontendSDL() : keyboardMappings(InputMappings::defaultKeyboardMapp #ifdef PANDA3DS_ENABLE_VULKAN if (config.rendererType == RendererType::Vulkan) { - window = SDL_CreateWindow("Alber", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); + window = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 480, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE); if (window == nullptr) { Helpers::warn("Window creation failed: %s", SDL_GetError());