From e6caae702f5f20f04db13f436ca2be7cad9f8ca7 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Fri, 27 Oct 2023 00:21:02 +0200 Subject: [PATCH 1/7] Make Episode 2 support optional This code is basically unmaintained since 2014, not easy to reach for gamers and crashes if used nowadays. It was more a proof of concept even back then. There is a dedicated project to bring Jazz2 back to life, which has already advanced further and is actively developed: https://github.com/deathkiller/jazz2-native --- CMakeLists.txt | 31 ++++++++++++++++++------------- openjazz.mk | 13 +------------ src/game/game.cpp | 24 ++++++++++++++++++++---- src/io/gfx/paletteeffects.cpp | 4 ++++ src/jj2/level/jj2levelload.cpp | 6 +++--- src/level/level.h | 2 ++ src/main.cpp | 5 +++++ src/player/player.cpp | 13 +++++++++++++ src/player/player.h | 6 ++++++ 9 files changed, 72 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95f13798..7c5519dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,19 +98,7 @@ add_executable(OpenJazz src/jj1/planet/jj1planet.h src/jj1/scene/jj1scene.cpp src/jj1/scene/jj1scene.h - src/jj1/scene/jj1sceneload.cpp - # episode 2 - src/jj2/level/event/jj2event.cpp - src/jj2/level/event/jj2event.h - src/jj2/level/event/jj2eventframe.cpp - src/jj2/level/jj2layer.cpp - src/jj2/level/jj2level.cpp - src/jj2/level/jj2level.h - src/jj2/level/jj2levelframe.cpp - src/jj2/level/jj2levelload.cpp - src/jj2/level/jj2levelplayer.cpp - src/jj2/level/jj2levelplayer.h - src/jj2/level/jj2levelplayerframe.cpp) + src/jj1/scene/jj1sceneload.cpp) target_include_directories(OpenJazz PUBLIC src) # portable mode @@ -192,6 +180,23 @@ elseif(NOT LEGACY_SDL) set(SCALE_STATUS "Disabled (currently broken in SDL2 port)") endif() +option(ENABLE_JJ2 "Enable experimental Episode 2 support (not recommended)" OFF) +if(ENABLE_JJ2) + target_sources(OpenJazz PRIVATE + src/jj2/level/event/jj2event.cpp + src/jj2/level/event/jj2event.h + src/jj2/level/event/jj2eventframe.cpp + src/jj2/level/jj2layer.cpp + src/jj2/level/jj2level.cpp + src/jj2/level/jj2level.h + src/jj2/level/jj2levelframe.cpp + src/jj2/level/jj2levelload.cpp + src/jj2/level/jj2levelplayer.cpp + src/jj2/level/jj2levelplayer.h + src/jj2/level/jj2levelplayerframe.cpp) + target_compile_definitions(OpenJazz PRIVATE ENABLE_JJ2) +endif() + target_link_libraries(OpenJazz argparse miniz psmplug ${OJ_LIBS_SCALE} ${OJ_LIBS_SDL} ${OJ_LIBS_NET} ${OJ_LIBS_HOST}) diff --git a/openjazz.mk b/openjazz.mk index 31a0b478..e9508324 100644 --- a/openjazz.mk +++ b/openjazz.mk @@ -64,15 +64,4 @@ OJ1OBJS = \ src/jj1/scene/jj1scene.o \ src/jj1/scene/jj1sceneload.o -# episode 2 -OJ2OBJS = \ - src/jj2/level/event/jj2event.o \ - src/jj2/level/event/jj2eventframe.o \ - src/jj2/level/jj2layer.o \ - src/jj2/level/jj2level.o \ - src/jj2/level/jj2levelframe.o \ - src/jj2/level/jj2levelload.o \ - src/jj2/level/jj2levelplayer.o \ - src/jj2/level/jj2levelplayerframe.o - -OBJS = $(OJEXTLIBOBJ) $(OJOBJS) $(OJ1OBJS) $(OJ2OBJS) +OBJS = $(OJEXTLIBOBJ) $(OJOBJS) $(OJ1OBJS) diff --git a/src/game/game.cpp b/src/game/game.cpp index c24b1cb6..86b10d45 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -31,11 +31,15 @@ #include "jj1/bonuslevel/jj1bonuslevel.h" #include "jj1/level/jj1level.h" #include "jj1/planet/jj1planet.h" +#ifdef ENABLE_JJ2 #include "jj2/level/jj2level.h" +#endif #include "player/player.h" #include "util.h" +#include "io/log.h" #include +#include /** @@ -217,6 +221,8 @@ int Game::playLevel (char* fileName, bool intro, bool checkpoint) { delete bonus; baseLevel = NULL; +#ifdef ENABLE_JJ2 + } else if (levelType == LT_JJ2) { try { @@ -234,6 +240,8 @@ int Game::playLevel (char* fileName, bool intro, bool checkpoint) { delete jj2Level; baseLevel = jj2Level = NULL; +#endif + } else { try { @@ -303,11 +311,10 @@ int Game::playLevel (char* fileName, bool intro, bool checkpoint) { */ LevelType Game::getLevelType (const char* fileName) { - int length; - - length = strlen(fileName); - +#ifdef ENABLE_JJ2 + int length = strlen(fileName); if ((length > 4) && isFileType(fileName + length - 4, ".j2l", 4)) return LT_JJ2; +#endif if (isFileType(fileName, "bonusmap", 8)) return LT_JJ1BONUS; return LT_JJ1; @@ -438,6 +445,8 @@ void Game::addLevelPlayer (Player *player) { player->createLevelPlayer(levelType, pAnims, NULL, checkX, checkY); +#ifdef ENABLE_JJ2 + } else if (jj2Level) { Anim* pAnims[JJ2PANIMS]; @@ -452,6 +461,13 @@ void Game::addLevelPlayer (Player *player) { player->createLevelPlayer(levelType, pAnims, pFlippedAnims, checkX, checkY); +#endif + + } else { + + LOG_WARN("Cannot create level player!"); + assert(false); + } } diff --git a/src/io/gfx/paletteeffects.cpp b/src/io/gfx/paletteeffects.cpp index fee5d606..25794b54 100644 --- a/src/io/gfx/paletteeffects.cpp +++ b/src/io/gfx/paletteeffects.cpp @@ -25,7 +25,9 @@ #include "video.h" #include "jj1/level/jj1level.h" +#ifdef ENABLE_JJ2 #include "jj2/level/jj2level.h" +#endif #include "level/levelplayer.h" #include "player/player.h" @@ -649,7 +651,9 @@ void WaterPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, currentPalette = video.getPalette(); if (level) position = localPlayer->getLevelPlayer()->getY() - level->getWaterLevel(); +#ifdef ENABLE_JJ2 else if (jj2Level) position = localPlayer->getLevelPlayer()->getY() - jj2Level->getWaterLevel(); +#endif else return; if (position <= 0) return; diff --git a/src/jj2/level/jj2levelload.cpp b/src/jj2/level/jj2levelload.cpp index e7515bab..6f9e3d95 100644 --- a/src/jj2/level/jj2levelload.cpp +++ b/src/jj2/level/jj2levelload.cpp @@ -612,7 +612,7 @@ int JJ2Level::load (char *fileName, bool checkpoint) { // Load tile set from given file - ret = loadTiles(reinterpret_cast(aBuffer) + 51); + ret = loadTiles(reinterpret_cast(aBuffer + 51)); if (ret < 0) { @@ -632,14 +632,14 @@ int JJ2Level::load (char *fileName, bool checkpoint) { // Next level - string = reinterpret_cast(aBuffer) + 115; + string = reinterpret_cast(aBuffer + 115); if (fileExists(string, PATH_TYPE_GAME)) nextLevel = createString(string); else nextLevel = createString(string, ".j2l"); // Music file - string = reinterpret_cast(aBuffer) + 179; + string = reinterpret_cast(aBuffer + 179); if (fileExists(string, PATH_TYPE_GAME)) musicFile = createString(string); else musicFile = createString(string, ".j2b"); diff --git a/src/level/level.h b/src/level/level.h index e13269d8..834fd168 100644 --- a/src/level/level.h +++ b/src/level/level.h @@ -51,7 +51,9 @@ enum LevelType { LT_JJ1 = 0, ///< JJ1 level LT_JJ1BONUS = 1, ///< JJ1 bonus level +#ifdef ENABLE_JJ2 LT_JJ2 = 2 ///< JJ2 level +#endif }; diff --git a/src/main.cpp b/src/main.cpp index e8795c54..d55d8fa4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,7 +34,9 @@ #include "io/gfx/video.h" #include "io/network.h" #include "io/sound.h" +#ifdef ENABLE_JJ2 #include "jj2/level/jj2level.h" +#endif #include "jj1/level/jj1level.h" #include "menu/menu.h" #include "player/player.h" @@ -319,7 +321,10 @@ void startUp (const char *argv0, int pathCount, char *paths[]) { level = NULL; + +#ifdef ENABLE_JJ2 jj2Level = NULL; +#endif } diff --git a/src/player/player.cpp b/src/player/player.cpp index a7732f53..bfe17ce4 100644 --- a/src/player/player.cpp +++ b/src/player/player.cpp @@ -29,7 +29,9 @@ #include "jj1/bonuslevel/jj1bonuslevelplayer.h" #include "jj1/level/jj1levelplayer.h" +#ifdef ENABLE_JJ2 #include "jj2/level/jj2levelplayer.h" +#endif #include "level/levelplayer.h" #include "game/game.h" @@ -167,6 +169,10 @@ void Player::reset (int x, int y) { void Player::createLevelPlayer (LevelType levelType, Anim** anims, Anim** flippedAnims, unsigned char x, unsigned char y) { +#ifndef ENABLE_JJ2 + (void)flippedAnims; +#endif + if (levelPlayer) { flockSize = levelPlayer->countBirds(); @@ -190,12 +196,16 @@ void Player::createLevelPlayer (LevelType levelType, Anim** anims, break; +#ifdef ENABLE_JJ2 + case LT_JJ2: levelPlayer = new JJ2LevelPlayer(this, anims, flippedAnims, x, y, flockSize); break; +#endif + } for (int i = 0; i < PCONTROLS; i++) pcontrols[i] = false; @@ -266,6 +276,7 @@ JJ1LevelPlayer* Player::getJJ1LevelPlayer () { } +#ifdef ENABLE_JJ2 /** * Get the player's JJ2 level player. @@ -280,6 +291,8 @@ JJ2LevelPlayer* Player::getJJ2LevelPlayer () { } +#endif + /** * Set the state of the specified control. diff --git a/src/player/player.h b/src/player/player.h index 06c48893..7374398b 100644 --- a/src/player/player.h +++ b/src/player/player.h @@ -76,7 +76,9 @@ enum PlayerColour { class Anim; class JJ1LevelPlayer; class JJ1BonusLevelPlayer; +#ifdef ENABLE_JJ2 class JJ2LevelPlayer; +#endif class LevelPlayer; /// Game player @@ -115,7 +117,9 @@ class Player { LevelPlayer* getLevelPlayer (); JJ1BonusLevelPlayer* getJJ1BonusLevelPlayer (); JJ1LevelPlayer* getJJ1LevelPlayer (); +#ifdef ENABLE_JJ2 JJ2LevelPlayer* getJJ2LevelPlayer (); +#endif void addLife (); void addScore (int addedScore); @@ -137,7 +141,9 @@ class Player { void receive (unsigned char* buffer); friend class JJ1LevelPlayer; +#ifdef ENABLE_JJ2 friend class JJ2LevelPlayer; +#endif }; From 5388ba2ba8aa1e62b95dda70a04de9001e8d9e0c Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Fri, 27 Oct 2023 01:27:17 +0200 Subject: [PATCH 2/7] Load jump height and animation speed --- src/jj1/level/jj1levelload.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/jj1/level/jj1levelload.cpp b/src/jj1/level/jj1levelload.cpp index 8cd097cc..d3724f06 100644 --- a/src/jj1/level/jj1levelload.cpp +++ b/src/jj1/level/jj1levelload.cpp @@ -40,6 +40,7 @@ #include "io/sound.h" #include "loop.h" #include "util.h" +#include "io/log.h" #include @@ -403,7 +404,8 @@ int JJ1Level::load (char* fileName, bool checkpoint) { int tiles; int count, x, y, type; unsigned char startX, startY; - + // FIXME: actually use these + int animSpeed, jumpHeight; // Load font @@ -853,17 +855,26 @@ int JJ1Level::load (char* fileName, bool checkpoint) { y = file->loadChar(); setNext(x, y); + // jump height + jumpHeight = (file->loadShort() - 0xFFFF) / 2; + if (jumpHeight != -5) + LOG_TRACE("Uncommon jumpHeight: %i", jumpHeight); - // Skip jump height (FIXME) and some unknown level - file->seek(4, false); + // skip some unknown level + file->seek(2, false); // Thanks to Doubble Dutch for the water level bytes waterLevelTarget = ITOF(file->loadShort() + 17); waterLevel = waterLevelTarget - F8; waterLevelSpeed = -80000; - // Skip Jazz animation speed(FIXME) and an unknown value (end marker?) - file->seek(3, false); + // Jazz animation speed + animSpeed = file->loadChar(); + if (animSpeed != 119) + LOG_TRACE("Uncommon animationSpeed: %i", animSpeed); + + // Skip an unknown value (end marker?) + file->seek(2, false); // Thanks to Feline and the JCS94 team for the next bits: From 5f8ecf234870be09243ee797efb17af07a000bb2 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Fri, 27 Oct 2023 01:13:31 +0200 Subject: [PATCH 3/7] CMake: Show compiler warnings, allow ccache CMake: Fix disappearing analysis targets --- builds/cmake/OJ-misc.cmake | 109 +++++++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/builds/cmake/OJ-misc.cmake b/builds/cmake/OJ-misc.cmake index 5238007e..a2d4c25b 100644 --- a/builds/cmake/OJ-misc.cmake +++ b/builds/cmake/OJ-misc.cmake @@ -13,9 +13,35 @@ if(CMAKE_VERSION VERSION_LESS "3.24") endif() endif() + +# compiler cache +option(WANT_CCACHE "Use ccache to speed up rebuilds" OFF) +if(WANT_CCACHE) + if(NOT FOUND_CCACHE) + find_program(CCACHE_EXECUTABLE ccache) + + if(CCACHE_EXECUTABLE) + message(STATUS "Using ccache as CXX compiler launcher") + set(FOUND_CCACHE 1 CACHE INTERNAL "Ccache has been found") + endif() + endif() + + if(CCACHE_EXECUTABLE) + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}") + endif() +endif() + +# warnings +if(MSVC) + add_compile_options(/W4) +else() + add_compile_options(-Wall -Wextra) +endif() + # global scope, since ASAN needs to catch all targets -option(WANT_ASAN "build with adress sanitizer" OFF) +option(WANT_ASAN "build with address sanitizer" OFF) if(WANT_ASAN) + message(STATUS "Building with address sanitizer") add_compile_options(-fno-omit-frame-pointer -fsanitize=address) add_link_options(-fno-omit-frame-pointer -fsanitize=address) endif() @@ -30,57 +56,58 @@ if(NOT FOUND_ASTYLE) if(ASTYLE_EXECUTABLE) message(STATUS "Found source code formatter: astyle") - - list(APPEND ASTYLE_ARGS - --suffix=none - --style=attach - --indent=tab=4 - --pad-oper - --pad-header - --unpad-paren - --max-code-length=100 - --break-after-logical - --attach-closing-while - --align-pointer=type - --align-reference=name - --indent-classes - --indent-preproc-block - --indent-switches - --min-conditional-indent=0) - - add_custom_target(format - COMMAND ${ASTYLE_EXECUTABLE} ${ASTYLE_ARGS} ${ALL_SRC} - COMMENT "Running astyle to format source code" - VERBATIM) - set(FOUND_ASTYLE 1 CACHE INTERNAL "Astyle has been found") endif() endif() +if(ASTYLE_EXECUTABLE) + list(APPEND ASTYLE_ARGS + --suffix=none + --style=attach + --indent=tab=4 + --pad-oper + --pad-header + --unpad-paren + --max-code-length=100 + --break-after-logical + --attach-closing-while + --align-pointer=type + --align-reference=name + --indent-classes + --indent-preproc-block + --indent-switches + --min-conditional-indent=0) + + add_custom_target(format + COMMAND ${ASTYLE_EXECUTABLE} ${ASTYLE_ARGS} ${ALL_SRC} + COMMENT "Running astyle to format source code" + VERBATIM) +endif() if(NOT FOUND_CPPCHECK) find_program(CPPCHECK_EXECUTABLE cppcheck) - if(CPPCHECK_EXECUTABLE) message(STATUS "Found static analysis tool: cppcheck") - - list(APPEND CPPCHECK_ARGS - --enable=warning,style,performance,portability,unusedFunction - #--std=c++11 - --std=c++03 - --language=c++ - -I${CMAKE_CURRENT_SOURCE_DIR}/src - -U__SYMBIAN32__ -UUIQ3 # unmaintained - #--enable=information - ) - - add_custom_target(cppcheck - COMMAND ${CPPCHECK_EXECUTABLE} ${CPPCHECK_ARGS} ${ALL_SRC} - COMMENT "Running cppcheck for static analysis" - USES_TERMINAL VERBATIM) - set(FOUND_CPPCHECK 1 CACHE INTERNAL "Cppcheck has been found") endif() endif() +if(CPPCHECK_EXECUTABLE) + list(APPEND CPPCHECK_ARGS + --enable=warning,style,performance,portability,unusedFunction + --std=c++11 + --language=c++ + -I${CMAKE_CURRENT_SOURCE_DIR}/src + -U__SYMBIAN32__ -UUIQ3 -UENABLE_JJ2 # unmaintained + -UGP2X -UWIZ -UDINGOO -UCAANOO -UGAMESHELL # contributed + -UPSP -U__vita__ -U_3DS -U__wii__ # homebrew + -U__riscos__ + #--enable=information + ) + + add_custom_target(cppcheck + COMMAND ${CPPCHECK_EXECUTABLE} ${CPPCHECK_ARGS} ${ALL_SRC} + COMMENT "Running cppcheck for static analysis" + USES_TERMINAL VERBATIM) +endif() if(NOT FOUND_ASTYLE AND NOT FOUND_CPPCHECK) message(STATUS "No source code formatter or static analysis tool enabled.") From bc786d1e2fd606e692b2a8e2afe60cc79a8cf5b4 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Sat, 28 Oct 2023 01:08:14 +0200 Subject: [PATCH 4/7] CMake: Add build presets and use them for CI --- .github/workflows/ci.yml | 24 +-- .gitignore | 1 + CMakePresets.json | 363 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 371 insertions(+), 17 deletions(-) create mode 100644 CMakePresets.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 916ee4d8..6f4263f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,6 @@ jobs: - name: Prepare Environment run: | echo "SHORT_SHA=${GITHUB_SHA:0:10}" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 @@ -95,19 +94,17 @@ jobs: - name: Prepare Environment run: | echo "SHORT_SHA=${GITHUB_SHA:0:10}" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 - name: Build OpenJazz run: | - cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=Release - cmake --build build + cmake --workflow --preset release - name: Prepare artifact run: | - cmake --install build --prefix $PWD + cmake --install build-release --prefix $PWD cp /mingw64/bin/SDL2.dll dist/ asciidoctor -o OpenJazzManual.html -a oj_version=${SHORT_SHA} res/unix/OpenJazz.6.adoc w3m -dump -cols 2147483647 -s OpenJazzManual.html > dist/Manual.txt @@ -136,15 +133,13 @@ jobs: - name: Prepare Environment run: | echo "SHORT_SHA=${GITHUB_SHA:0:10}" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 - name: Build OpenJazz run: | - export CXXFLAGS="-Wall -g -O2" - $DEVKITPRO/portlibs/wii/bin/powerpc-eabi-cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=Release + $DEVKITPRO/portlibs/wii/bin/powerpc-eabi-cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build build - name: Prepare artifact @@ -177,15 +172,13 @@ jobs: - name: Prepare Environment run: | echo "SHORT_SHA=${GITHUB_SHA:0:10}" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 - name: Build OpenJazz run: | - export CXXFLAGS="-Wall -g -O2" - $DEVKITPRO/portlibs/3ds/bin/arm-none-eabi-cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=Release + $DEVKITPRO/portlibs/3ds/bin/arm-none-eabi-cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=RelWithDebInfo cmake --build build - name: Prepare artifact @@ -218,7 +211,6 @@ jobs: - name: Prepare Environment run: | echo "SHORT_SHA=${GITHUB_SHA:0:10}" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Prepare GCCSDK autobuilder and build SDL run: | @@ -263,20 +255,18 @@ jobs: - name: Prepare Environment run: | echo "SHORT_SHA=${GITHUB_SHA:0:10}" >> $GITHUB_ENV - echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout uses: actions/checkout@v4 - name: Build OpenJazz run: | - export CXXFLAGS="-Wall -g -O2" - psp-cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=Release -DNETWORK=OFF - cmake --build build + cmake --preset=psp-release -DNETWORK=OFF + cmake --build --preset=psp-release - name: Prepare artifact run: | - cmake --install build --prefix $PWD + cmake --install build-psp-release --prefix $PWD asciidoctor -o OpenJazzManual.html -a oj_version=${SHORT_SHA} res/unix/OpenJazz.6.adoc w3m -dump -cols 2147483647 -s OpenJazzManual.html > OpenJazz/Manual.txt cp README.md OpenJazz/README.txt diff --git a/.gitignore b/.gitignore index 4954bb84..b94fc272 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ CMakeFiles/ !/builds/cmake/*.cmake ext/Makefile build.ninja +CMakeUserPresets.json # homebrew *.elf diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..1c6bdb6d --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,363 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "base", + "displayName": "Comment: base preset, all inherit from it", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build-${presetName}", + "cacheVariables": { + "WANT_CCACHE": "ON" + } + }, + { + "name": "type-debug", + "displayName": "Comment: build type debug preset", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "type-release", + "displayName": "Comment: build type release preset", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "parent", + "inherits": "base", + "displayName": "Comment: platform/special preset", + "description": "Default build using Ninja generator", + "hidden": true + }, + { + "name": "debug", + "displayName": "Native (Debug)", + "inherits": [ + "parent", + "type-debug" + ] + }, + { + "name": "release", + "displayName": "Native (Release)", + "inherits": [ + "parent", + "type-release" + ] + }, + { + "name": "asan-parent", + "inherits": "base", + "displayName": "Comment: platform/special preset", + "description": "ASAN build using Ninja generator", + "cacheVariables": { + "WANT_ASAN": "ON" + }, + "hidden": true + }, + { + "name": "asan-debug", + "displayName": "ASAN (Debug)", + "inherits": [ + "asan-parent", + "type-debug" + ] + }, + { + "name": "3ds-parent", + "inherits": "base", + "displayName": "Comment: platform/special preset", + "description": "Homebrew build using Ninja generator", + "toolchainFile": "$env{DEVKITPRO}/cmake/3DS.cmake", + "hidden": true + }, + { + "name": "3ds-debug", + "displayName": "Nintendo 3DS (Debug)", + "inherits": [ + "3ds-parent", + "type-debug" + ] + }, + { + "name": "3ds-release", + "displayName": "Nintendo 3DS (Release)", + "inherits": [ + "3ds-parent", + "type-release" + ] + }, + { + "name": "wii-parent", + "inherits": "base", + "displayName": "Comment: platform/special preset", + "description": "Homebrew build using Ninja generator", + "toolchainFile": "$env{DEVKITPRO}/cmake/Wii.cmake", + "hidden": true + }, + { + "name": "wii-debug", + "displayName": "Nintendo Wii (Debug)", + "inherits": [ + "wii-parent", + "type-debug" + ] + }, + { + "name": "wii-release", + "displayName": "Nintendo Wii (Release)", + "inherits": [ + "wii-parent", + "type-release" + ] + }, + { + "name": "psp-parent", + "inherits": "base", + "displayName": "Comment: platform/special preset", + "description": "Homebrew build using Ninja generator", + "toolchainFile": "$env{PSPDEV}/psp/share/pspdev.cmake", + "hidden": true + }, + { + "name": "psp-debug", + "displayName": "Sony PSP (Debug)", + "inherits": [ + "psp-parent", + "type-debug" + ] + }, + { + "name": "psp-release", + "displayName": "Sony PSP (Release)", + "inherits": [ + "psp-parent", + "type-release" + ] + } + ], + "buildPresets": [ + { + "name": "debug", + "configurePreset": "debug" + }, + { + "name": "release", + "configurePreset": "release" + }, + { + "name": "asan-debug", + "configurePreset": "asan-debug" + }, + { + "name": "3ds-debug", + "configurePreset": "3ds-debug" + }, + { + "name": "3ds-release", + "configurePreset": "3ds-release" + }, + { + "name": "wii-debug", + "configurePreset": "wii-debug" + }, + { + "name": "wii-release", + "configurePreset": "wii-release" + }, + { + "name": "psp-debug", + "configurePreset": "psp-debug" + }, + { + "name": "psp-release", + "configurePreset": "psp-release" + } + ], + "packagePresets": [ + { + "name": "debug", + "configurePreset": "debug" + }, + { + "name": "release", + "configurePreset": "release" + }, + { + "name": "asan-debug", + "configurePreset": "asan-debug" + }, + { + "name": "3ds-debug", + "configurePreset": "3ds-debug" + }, + { + "name": "3ds-release", + "configurePreset": "3ds-release" + }, + { + "name": "wii-debug", + "configurePreset": "wii-debug" + }, + { + "name": "wii-release", + "configurePreset": "wii-release" + }, + { + "name": "psp-debug", + "configurePreset": "psp-debug" + }, + { + "name": "psp-release", + "configurePreset": "psp-release" + } + ], + "workflowPresets": [ + { + "name": "debug", + "steps": [ + { + "type": "configure", + "name": "debug" + }, + { + "type": "build", + "name": "debug" + } + ] + }, + { + "name": "release", + "steps": [ + { + "type": "configure", + "name": "release" + }, + { + "type": "build", + "name": "release" + } + ] + }, + { + "name": "asan-debug", + "steps": [ + { + "type": "configure", + "name": "asan-debug" + }, + { + "type": "build", + "name": "asan-debug" + } + ] + }, + { + "name": "3ds-debug", + "steps": [ + { + "type": "configure", + "name": "3ds-debug" + }, + { + "type": "build", + "name": "3ds-debug" + }, + { + "type": "package", + "name": "3ds-debug" + } + ] + }, + { + "name": "3ds-release", + "steps": [ + { + "type": "configure", + "name": "3ds-release" + }, + { + "type": "build", + "name": "3ds-release" + }, + { + "type": "package", + "name": "3ds-release" + } + ] + }, + { + "name": "wii-debug", + "steps": [ + { + "type": "configure", + "name": "wii-debug" + }, + { + "type": "build", + "name": "wii-debug" + }, + { + "type": "package", + "name": "wii-debug" + } + ] + }, + { + "name": "wii-release", + "steps": [ + { + "type": "configure", + "name": "wii-release" + }, + { + "type": "build", + "name": "wii-release" + }, + { + "type": "package", + "name": "wii-release" + } + ] + }, + { + "name": "psp-debug", + "steps": [ + { + "type": "configure", + "name": "psp-debug" + }, + { + "type": "build", + "name": "psp-debug" + }, + { + "type": "package", + "name": "psp-debug" + } + ] + }, + { + "name": "psp-release", + "steps": [ + { + "type": "configure", + "name": "psp-release" + }, + { + "type": "build", + "name": "psp-release" + }, + { + "type": "package", + "name": "psp-release" + } + ] + } + ] +} From 84ead4c508f4d8c7f9691fddd02dead434c9aa61 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Sat, 28 Oct 2023 01:35:47 +0200 Subject: [PATCH 5/7] Add EditorConfig file to fix some code formatting --- .editorconfig | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..2c4e6559 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,31 @@ +# https://EditorConfig.org + +root = true + +[*] +trim_trailing_whitespace = true +insert_final_newline = true + +[{CMakeLists.txt,*.cmake,Makefile}] +indent_style = tab +indent_size = 4 + +[{*.cpp,*.h}] +indent_style = tab +indent_size = 4 + +[ext/**/{*.cpp,*.h}] +indent_style = ignore +indent_size = ignore + +[*.json,*.yml,*.rc,*.adoc] +indent_style = space +indent_size = 2 + +[*.md] +indent_style = space +indent_size = 4 + +[*.xml] +indent_style = tab +indent_size = 4 From b19e6556f704ae460376893ff1856d6c3aba2490 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Sat, 28 Oct 2023 03:52:10 +0200 Subject: [PATCH 6/7] CMake: Add version information and URLs --- CMakeLists.txt | 53 +++- builds/cmake/GetGitRevisionDescription.cmake | 285 ++++++++++++++++++ .../cmake/GetGitRevisionDescription.cmake.in | 46 +++ openjazz.mk | 3 +- src/OpenJazz.h | 12 - src/main.cpp | 16 +- src/menu/mainmenu.cpp | 4 +- src/version.cpp | 35 +++ src/version.h | 25 ++ 9 files changed, 460 insertions(+), 19 deletions(-) create mode 100644 builds/cmake/GetGitRevisionDescription.cmake create mode 100644 builds/cmake/GetGitRevisionDescription.cmake.in create mode 100644 src/version.cpp create mode 100644 src/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c5519dd..11d9148c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16...3.27) project(OpenJazz VERSION 20231027 LANGUAGES CXX - HOMEPAGE_URL http://www.alister.eu/jazz/oj/) + HOMEPAGE_URL http://alister.eu/jazz/oj/) # Extra CMake Module files @@ -71,6 +71,8 @@ add_executable(OpenJazz src/setup.h src/util.cpp src/util.h + src/version.cpp + src/version.h # episode 1 src/jj1/bonuslevel/jj1bonuslevel.cpp src/jj1/bonuslevel/jj1bonuslevel.h @@ -197,6 +199,49 @@ if(ENABLE_JJ2) target_compile_definitions(OpenJazz PRIVATE ENABLE_JJ2) endif() +# version + +string(TIMESTAMP OJ_DATE "%Y-%m-%d") +include(GetGitRevisionDescription) +git_get_exact_tag(GIT_TAG) +# Do not include a hash, if we are building a release tag +if(NOT GIT_TAG) + # otherwise concatenate a version with hash + git_describe(GIT_DESCRIPTION) + if(GIT_DESCRIPTION) + string(REPLACE "-" ";" GIT_DESCRIPTION ${GIT_DESCRIPTION}) + list(LENGTH GIT_DESCRIPTION GIT_DESCRIPTION_PARTS) + if(GIT_DESCRIPTION_PARTS EQUAL 3) + list(GET GIT_DESCRIPTION 0 GIT_TAG) + list(GET GIT_DESCRIPTION 1 GIT_COMMITS) + list(GET GIT_DESCRIPTION 2 GIT_HASH) + set(GIT_STATUS "${GIT_COMMITS} commits since tag \"${GIT_TAG}\", ") + string(PREPEND GIT_COMMITS "+") + else() + # no tags found, only hash + list(GET GIT_DESCRIPTION 0 GIT_HASH) + endif() + # strip the g prefix + string(SUBSTRING ${GIT_HASH} 1 -1 GIT_HASH) + set(OJ_VERSION_GIT "git${GIT_COMMITS}@${GIT_HASH}") + string(APPEND GIT_STATUS "object hash is ${GIT_HASH}") + git_local_changes(GIT_DIRTY) + if(GIT_DIRTY STREQUAL "DIRTY") + string(APPEND OJ_VERSION_GIT "-dirty") + string(APPEND GIT_STATUS ", with uncommitted changes") + endif() + endif() +endif() +set_property(SOURCE src/version.cpp PROPERTY COMPILE_DEFINITIONS + OJ_VERSION="${PROJECT_VERSION}"; OJ_DATE="${OJ_DATE}"; + $<$:OJ_VERSION_GIT="${OJ_VERSION_GIT}">) + +# project links + +set(OJ_BUGREPORT "https://github.com/AlisterT/openjazz/issues") +set_property(SOURCE src/main.cpp PROPERTY COMPILE_DEFINITIONS + OJ_URL="${PROJECT_HOMEPAGE_URL}"; OJ_BUGREPORT="${OJ_BUGREPORT}") + target_link_libraries(OpenJazz argparse miniz psmplug ${OJ_LIBS_SCALE} ${OJ_LIBS_SDL} ${OJ_LIBS_NET} ${OJ_LIBS_HOST}) @@ -359,6 +404,10 @@ unset(MAN_PATH) message(STATUS "") message(STATUS "OpenJazz") message(STATUS "========") +message(STATUS "Version: ${PROJECT_VERSION}") +if(GIT_STATUS) + message(STATUS "Git status: ${GIT_STATUS}") +endif() message(STATUS "Target system: ${OJ_HOST}") message(STATUS "Platform abstraction: ${SDL_STATUS}") if(ROMFS) @@ -372,5 +421,5 @@ endif() message(STATUS "Manual page: ${MANUAL_STATUS}") message(STATUS "Portable Engine: ${PORTABLE_STATUS}") message(STATUS "") -message(STATUS "In case something goes wrong, report bugs to https://github.com/AlisterT/openjazz/issues") +message(STATUS "In case something goes wrong, report bugs to ${OJ_BUGREPORT}") message(STATUS "") diff --git a/builds/cmake/GetGitRevisionDescription.cmake b/builds/cmake/GetGitRevisionDescription.cmake new file mode 100644 index 00000000..32cb7907 --- /dev/null +++ b/builds/cmake/GetGitRevisionDescription.cmake @@ -0,0 +1,285 @@ +# - Returns a version string from Git +# +# These functions force a re-configure on each git commit so that you can +# trust the values of the variables in your build system. +# +# get_git_head_revision( [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR]) +# +# Returns the refspec and sha hash of the current head revision +# +# git_describe( [ ...]) +# +# Returns the results of git describe on the source tree, and adjusting +# the output so that it tests false if an error occurs. +# +# git_describe_working_tree( [ ...]) +# +# Returns the results of git describe on the working tree (--dirty option), +# and adjusting the output so that it tests false if an error occurs. +# +# git_get_exact_tag( [ ...]) +# +# Returns the results of git describe --exact-match on the source tree, +# and adjusting the output so that it tests false if there was no exact +# matching tag. +# +# git_local_changes() +# +# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes. +# Uses the return code of "git diff-index --quiet HEAD --". +# Does not regard untracked files. +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2020 Ryan Pavlik +# http://academic.cleardefinition.com +# +# Copyright 2009-2013, Iowa State University. +# Copyright 2013-2020, Ryan Pavlik +# Copyright 2013-2020, Contributors +# SPDX-License-Identifier: BSL-1.0 +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__get_git_revision_description) + return() +endif() +set(__get_git_revision_description YES) + +# We must run the following at "include" time, not at function call time, +# to find the path to this module rather than the path to a calling list file +get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) + +# Function _git_find_closest_git_dir finds the next closest .git directory +# that is part of any directory in the path defined by _start_dir. +# The result is returned in the parent scope variable whose name is passed +# as variable _git_dir_var. If no .git directory can be found, the +# function returns an empty string via _git_dir_var. +# +# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and +# neither foo nor bar contain a file/directory .git. This wil return +# C:/bla/.git +# +function(_git_find_closest_git_dir _start_dir _git_dir_var) + set(cur_dir "${_start_dir}") + set(git_dir "${_start_dir}/.git") + while(NOT EXISTS "${git_dir}") + # .git dir not found, search parent directories + set(git_previous_parent "${cur_dir}") + get_filename_component(cur_dir "${cur_dir}" DIRECTORY) + if(cur_dir STREQUAL git_previous_parent) + # We have reached the root directory, we are not in git + set(${_git_dir_var} + "" + PARENT_SCOPE) + return() + endif() + set(git_dir "${cur_dir}/.git") + endwhile() + set(${_git_dir_var} + "${git_dir}" + PARENT_SCOPE) +endfunction() + +function(get_git_head_revision _refspecvar _hashvar) + _git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR) + + if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR") + set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE) + else() + set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE) + endif() + if(NOT "${GIT_DIR}" STREQUAL "") + file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}" + "${GIT_DIR}") + if("${_relative_to_source_dir}" MATCHES "[.][.]" + AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR) + # We've gone above the CMake root dir. + set(GIT_DIR "") + endif() + endif() + if("${GIT_DIR}" STREQUAL "") + set(${_refspecvar} + "GITDIR-NOTFOUND" + PARENT_SCOPE) + set(${_hashvar} + "GITDIR-NOTFOUND" + PARENT_SCOPE) + return() + endif() + + # Check if the current source dir is a git submodule or a worktree. + # In both cases .git is a file instead of a directory. + # + if(NOT IS_DIRECTORY ${GIT_DIR}) + # The following git command will return a non empty string that + # points to the super project working tree if the current + # source dir is inside a git submodule. + # Otherwise the command will return an empty string. + # + execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse + --show-superproject-working-tree + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE out + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT "${out}" STREQUAL "") + # If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule + file(READ ${GIT_DIR} submodule) + string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE + ${submodule}) + string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE) + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} + ABSOLUTE) + set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD") + else() + # GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree + file(READ ${GIT_DIR} worktree_ref) + # The .git directory contains a path to the worktree information directory + # inside the parent git repo of the worktree. + # + string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir + ${worktree_ref}) + string(STRIP ${git_worktree_dir} git_worktree_dir) + _git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR) + set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD") + endif() + else() + set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD") + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() + + if(NOT EXISTS "${HEAD_SOURCE_FILE}") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY) + + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" @ONLY) + include("${GIT_DATA}/grabRef.cmake") + + set(${_refspecvar} + "${HEAD_REF}" + PARENT_SCOPE) + set(${_hashvar} + "${HEAD_HASH}" + PARENT_SCOPE) +endfunction() + +function(git_describe _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} + "GIT-NOTFOUND" + PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} + "HEAD-HASH-NOTFOUND" + PARENT_SCOPE) + return() + endif() + + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() + + #message(STATUS "Arguments to execute_process: ${ARGN}") + + execute_process( + COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE res + OUTPUT_VARIABLE out + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + + set(${_var} + "${out}" + PARENT_SCOPE) +endfunction() + +function(git_describe_working_tree _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + if(NOT GIT_FOUND) + set(${_var} + "GIT-NOTFOUND" + PARENT_SCOPE) + return() + endif() + + execute_process( + COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE res + OUTPUT_VARIABLE out + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + + set(${_var} + "${out}" + PARENT_SCOPE) +endfunction() + +function(git_get_exact_tag _var) + git_describe(out --exact-match ${ARGN}) + set(${_var} + "${out}" + PARENT_SCOPE) +endfunction() + +function(git_local_changes _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} + "GIT-NOTFOUND" + PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} + "HEAD-HASH-NOTFOUND" + PARENT_SCOPE) + return() + endif() + + execute_process( + COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD -- + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE res + OUTPUT_VARIABLE out + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + if(res EQUAL 0) + set(${_var} + "CLEAN" + PARENT_SCOPE) + else() + set(${_var} + "DIRTY" + PARENT_SCOPE) + endif() +endfunction() diff --git a/builds/cmake/GetGitRevisionDescription.cmake.in b/builds/cmake/GetGitRevisionDescription.cmake.in new file mode 100644 index 00000000..462edb68 --- /dev/null +++ b/builds/cmake/GetGitRevisionDescription.cmake.in @@ -0,0 +1,46 @@ +# +# Internal file for GetGitRevisionDescription.cmake +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2023 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright 2009-2012, Iowa State University +# Copyright 2011-2023, Contributors +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# SPDX-License-Identifier: BSL-1.0 + +set(HEAD_HASH) + +file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) + +string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) +if(HEAD_CONTENTS MATCHES "ref") + # named branch + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") + if(EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + else() + if(EXISTS "@GIT_DIR@/packed-refs") + configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" + COPYONLY) + file(READ "@GIT_DATA@/packed-refs" PACKED_REFS) + if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}") + set(HEAD_HASH "${CMAKE_MATCH_1}") + endif() + endif() + endif() +else() + # detached HEAD + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) +endif() + +if(NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() diff --git a/openjazz.mk b/openjazz.mk index e9508324..81d3b918 100644 --- a/openjazz.mk +++ b/openjazz.mk @@ -42,7 +42,8 @@ OJOBJS = \ src/menu/setupmenu.o \ src/player/player.o \ src/setup.o \ - src/util.o + src/util.o \ + src/version.o # episode 1 OJ1OBJS = \ diff --git a/src/OpenJazz.h b/src/OpenJazz.h index 133aac5a..739f8f26 100644 --- a/src/OpenJazz.h +++ b/src/OpenJazz.h @@ -33,18 +33,6 @@ #ifndef _OPENJAZZ_H #define _OPENJAZZ_H -// Fallback version, should be defined by the build system -#ifndef OJ_VERSION -#define OJ_VERSION "git" -#define OJ_DATE __DATE__ -#endif - -// Fallback links, should be provided by the build system -#ifndef PACKAGE_BUGREPORT -#define PACKAGE_BUGREPORT "https://github.com/AlisterT/openjazz/issues" -#define PACKAGE_URL "http://www.alister.eu/jazz/oj/" -#endif - #ifndef EXTERN #define EXTERN extern #endif diff --git a/src/main.cpp b/src/main.cpp index d55d8fa4..6066663f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,7 @@ */ +// consume all external variables #define EXTERN #include "game/game.h" @@ -46,6 +47,7 @@ #include "util.h" #include "io/log.h" #include "platforms/platforms.h" +#include "version.h" #include #include @@ -56,6 +58,14 @@ #define PI 3.141592f +// Fallback links, should be provided by the build system +#ifndef OJ_BUGREPORT + #define OJ_BUGREPORT "https://github.com/AlisterT/openjazz/issues" +#endif +#ifndef OJ_URL + #define OJ_URL "http://alister.eu/jazz/oj/" +#endif + static struct CliOptions { bool muteAudio; int fullScreen; @@ -76,7 +86,7 @@ int display_mode_cb(struct argparse *, const struct argparse_option *option) { #endif int version_cb(struct argparse *, const struct argparse_option */*option*/) { - printf("OpenJazz %s, built on %s.\n", OJ_VERSION, OJ_DATE); + printf("OpenJazz %s, built on %s.\n", oj_version, oj_date); exit(EXIT_SUCCESS); } @@ -115,7 +125,7 @@ int checkOptions (int argc, char *argv[]) { argparse_init(&argparse, opt, usage, 0); argparse_describe(&argparse, "\nOpenJazz - Jack Jazzrabbit 1 game engine reimplementation", - "\nBug reports: " PACKAGE_BUGREPORT " - Homepage: " PACKAGE_URL); + "\nBug reports: " OJ_BUGREPORT " - Homepage: " OJ_URL); argc = argparse_parse(&argparse, argc, argv); // apply logger options @@ -566,7 +576,7 @@ int main(int argc, char *argv[]) { } // Log current version - LOG_INFO("This is OpenJazz %s, built on %s.", OJ_VERSION, OJ_DATE); + LOG_INFO("This is OpenJazz %s, built on %s.", oj_version, oj_date); // Initialise SDL diff --git a/src/menu/mainmenu.cpp b/src/menu/mainmenu.cpp index bc168232..7fc23bd1 100644 --- a/src/menu/mainmenu.cpp +++ b/src/menu/mainmenu.cpp @@ -36,6 +36,7 @@ #include "util.h" #include "io/log.h" #include "logo.h" +#include "version.h" #include #include @@ -431,7 +432,8 @@ int MainMenu::main () { } panelBigFont->mapPalette(0, MAX_PALETTE_COLORS, 8, 8); - panelBigFont->showString("OpenJazz " OJ_VERSION, 1, canvasH - 9); + panelBigFont->showString("OpenJazz", 1, canvasH - 9); + panelBigFont->showString(oj_version, 90, canvasH - 9); panelBigFont->restorePalette(); dst.x = (canvasW - SW) >> 1; diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 00000000..e9c46533 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,35 @@ + +/** + * + * @file version.cpp + * + * Part of the OpenJazz project + * + * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * + * OpenJazz is distributed under the terms of + * the GNU General Public License, version 2.0 + * + * @par Description: + * Contains version information. + * + */ + +#include "version.h" + +// Fallback version data, should be defined by the build system +#ifndef OJ_DATE + #define OJ_DATE __DATE__ +#endif +#ifndef OJ_VERSION + #define OJ_VERSION "git" +#endif + +const char *oj_date = OJ_DATE; + +#ifdef OJ_VERSION_GIT + const char *oj_version = OJ_VERSION " (" OJ_VERSION_GIT ")"; +#else + const char *oj_version = OJ_VERSION; +#endif diff --git a/src/version.h b/src/version.h new file mode 100644 index 00000000..46429337 --- /dev/null +++ b/src/version.h @@ -0,0 +1,25 @@ + +/** + * + * @file version.h + * + * Part of the OpenJazz project + * + * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * + * OpenJazz is distributed under the terms of + * the GNU General Public License, version 2.0 + * + */ + + +#ifndef OJ_VERSION_H +#define OJ_VERSION_H + +#include "OpenJazz.h" + +extern const char *oj_version; +extern const char *oj_date; + +#endif From d53b373675bb2f5dfad366bca93021a6943fc714 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Sat, 28 Oct 2023 21:52:34 +0200 Subject: [PATCH 7/7] Update copyright years --- .gitattributes | 5 +++++ README.md | 2 +- res/unix/OpenJazz.6.adoc | 2 +- res/wii/READMII.txt | 2 +- src/io/log.cpp | 2 +- src/io/log.h | 2 +- src/logo.h | 1 + src/platforms/3ds.cpp | 2 ++ src/platforms/3ds.h | 2 ++ src/platforms/haiku.cpp | 2 ++ src/platforms/haiku.h | 2 ++ src/platforms/platforms.h | 2 ++ src/platforms/psp.cpp | 2 ++ src/platforms/psp.h | 2 ++ src/platforms/psvita.cpp | 2 ++ src/platforms/psvita.h | 2 ++ src/platforms/riscos.cpp | 2 ++ src/platforms/riscos.h | 2 ++ src/platforms/wii.cpp | 2 ++ src/platforms/wii.h | 2 ++ src/platforms/xdg.cpp | 2 ++ src/platforms/xdg.h | 2 ++ 22 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.gitattributes b/.gitattributes index a3666fc6..b2422412 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,12 @@ * text=auto +# source files *.txt text *.cpp text *.h text CMakeLists.txt text *.cmake text +*.json text + +# distribution archives +/.github export-ignore diff --git a/README.md b/README.md index 5b34d16a..ee4ac00e 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,6 @@ Original author: Alister Thomson (alister_j_t at yahoo dot com) ## Homepage -http://www.alister.eu/jazz/oj/ +http://alister.eu/jazz/oj/ [logo]: res/unix/OpenJazz.png diff --git a/res/unix/OpenJazz.6.adoc b/res/unix/OpenJazz.6.adoc index 738b6e96..763a1d04 100644 --- a/res/unix/OpenJazz.6.adoc +++ b/res/unix/OpenJazz.6.adoc @@ -121,7 +121,7 @@ link:https://github.com/AlisterT/OpenJazz/issues[issue tracker]. *J1E* - level editor by Newspaz, *JJ1MOD* - graphic editor by Doubble Dutch -link:http://www.alister.eu/jazz/oj/[The OpenJazz Homepage] +link:http://alister.eu/jazz/oj/[The OpenJazz Homepage] == Authors diff --git a/res/wii/READMII.txt b/res/wii/READMII.txt index 34e85d43..e57ef92c 100644 --- a/res/wii/READMII.txt +++ b/res/wii/READMII.txt @@ -1,6 +1,6 @@ OpenJazz for Wii -Licensed under GPLv2. See included gpl.txt for details. +Licensed under GPLv2. See included licenses.txt for details. OpenJazz written by Alister Thomson http://alister.eu/jazz/oj/ Originally ported to the Wii by tehpola. diff --git a/src/io/log.cpp b/src/io/log.cpp index e00af2ac..58cdfa83 100644 --- a/src/io/log.cpp +++ b/src/io/log.cpp @@ -7,7 +7,7 @@ * * @par Licence: * Copyright (c) 2005-2017 Alister Thomson - * Copyright (c) 2015-2022 Carsten Teibes + * Copyright (c) 2015-2023 Carsten Teibes * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 diff --git a/src/io/log.h b/src/io/log.h index f5075557..030b1a29 100644 --- a/src/io/log.h +++ b/src/io/log.h @@ -7,7 +7,7 @@ * * @par Licence: * Copyright (c) 2005-2017 Alister Thomson - * Copyright (c) 2015-2022 Carsten Teibes + * Copyright (c) 2015-2023 Carsten Teibes * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 diff --git a/src/logo.h b/src/logo.h index 24b144eb..14163250 100644 --- a/src/logo.h +++ b/src/logo.h @@ -7,6 +7,7 @@ * * @par Licence: * Copyright (c) 2005-2017 Alister Thomson + * Copyright (c) 2015-2023 Carsten Teibes * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 diff --git a/src/platforms/3ds.cpp b/src/platforms/3ds.cpp index 4beb2d34..726cbdd1 100644 --- a/src/platforms/3ds.cpp +++ b/src/platforms/3ds.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/3ds.h b/src/platforms/3ds.h index c5a90742..b6f56ab0 100644 --- a/src/platforms/3ds.h +++ b/src/platforms/3ds.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/haiku.cpp b/src/platforms/haiku.cpp index 1d59e6d8..c195af9b 100644 --- a/src/platforms/haiku.cpp +++ b/src/platforms/haiku.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/haiku.h b/src/platforms/haiku.h index 585a1243..404dafa5 100644 --- a/src/platforms/haiku.h +++ b/src/platforms/haiku.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/platforms.h b/src/platforms/platforms.h index 84c36182..cda4aa17 100644 --- a/src/platforms/platforms.h +++ b/src/platforms/platforms.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/psp.cpp b/src/platforms/psp.cpp index 3d2162cf..7e02cfcb 100644 --- a/src/platforms/psp.cpp +++ b/src/platforms/psp.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/psp.h b/src/platforms/psp.h index 809347eb..73506f6a 100644 --- a/src/platforms/psp.h +++ b/src/platforms/psp.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/psvita.cpp b/src/platforms/psvita.cpp index a5155935..2ae571de 100644 --- a/src/platforms/psvita.cpp +++ b/src/platforms/psvita.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/psvita.h b/src/platforms/psvita.h index 8624ffb2..d764f7ec 100644 --- a/src/platforms/psvita.h +++ b/src/platforms/psvita.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/riscos.cpp b/src/platforms/riscos.cpp index 2a6303aa..aa6b22e7 100644 --- a/src/platforms/riscos.cpp +++ b/src/platforms/riscos.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/riscos.h b/src/platforms/riscos.h index 69c5f9c4..7b0039d3 100644 --- a/src/platforms/riscos.h +++ b/src/platforms/riscos.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/wii.cpp b/src/platforms/wii.cpp index ef7550cc..6f96dbc1 100644 --- a/src/platforms/wii.cpp +++ b/src/platforms/wii.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/wii.h b/src/platforms/wii.h index f5571b09..4236dfa2 100644 --- a/src/platforms/wii.h +++ b/src/platforms/wii.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/xdg.cpp b/src/platforms/xdg.cpp index 458b73a3..4226ac05 100644 --- a/src/platforms/xdg.cpp +++ b/src/platforms/xdg.cpp @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 * diff --git a/src/platforms/xdg.h b/src/platforms/xdg.h index 43efbf45..d6a86b64 100644 --- a/src/platforms/xdg.h +++ b/src/platforms/xdg.h @@ -6,6 +6,8 @@ * Part of the OpenJazz project * * @par Licence: + * Copyright (c) 2015-2023 Carsten Teibes + * * OpenJazz is distributed under the terms of * the GNU General Public License, version 2.0 *