diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 686c628b..916ee4d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ defaults: jobs: linux-gcc: - name: Build (Ubuntu 20.04 LTS x86_64, GCC) + name: Build (Ubuntu 20.04 LTS x86_64, GCC, SDL1.2) runs-on: ubuntu-20.04 steps: - name: Install dependencies @@ -30,7 +30,7 @@ jobs: echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz (normal) run: | @@ -38,14 +38,14 @@ jobs: ls -l OpenJazz linux-clang: - name: Build (Ubuntu 20.04 LTS x86_64, Clang) + name: Build (Ubuntu 20.04 LTS x86_64, Clang, SDL2) runs-on: ubuntu-20.04 steps: - name: Install dependencies run: | sudo apt-get update -yqq sudo apt-get install -yqq build-essential cmake ninja-build clang-10 \ - libsdl1.2-dev asciidoctor w3m + libsdl2-dev asciidoctor w3m - name: Prepare Environment run: | @@ -53,7 +53,7 @@ jobs: echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz (slim) run: | @@ -90,7 +90,7 @@ jobs: install: | base-devel dos2unix w3m pacboy: | - toolchain:p cmake:p ninja:p SDL:p asciidoctor:p + toolchain:p cmake:p ninja:p SDL2:p asciidoctor:p - name: Prepare Environment run: | @@ -98,18 +98,17 @@ jobs: echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz run: | - export LDFLAGS="-static" - export PKG_CONFIG="pkg-config --static" cmake -G Ninja -B build . -DCMAKE_BUILD_TYPE=Release cmake --build build - name: Prepare artifact run: | cmake --install build --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 cp README.md dist/README.txt @@ -140,7 +139,7 @@ jobs: echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz run: | @@ -181,7 +180,7 @@ jobs: echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz run: | @@ -231,7 +230,7 @@ jobs: ../autobuilder/build -v libsdl1.2debian # todo: cache? - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz run: | @@ -267,7 +266,7 @@ jobs: echo "MAKEFLAGS=-j$(nproc)" >> $GITHUB_ENV - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Build OpenJazz run: | diff --git a/BUILDING.md b/BUILDING.md index 0f8caff9..347075f0 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -2,10 +2,10 @@ # Building OpenJazz Needed: -- SDL 1.2.x library (https://libsdl.org/). +- SDL 2.x or SDL 1.2.x (deprecated) library (https://libsdl.org/) Optional: -- SDL_net 1.2.x library (https://www.libsdl.org/projects/SDL_net/) +- SDL_net library (https://www.libsdl.org/projects/SDL_net/) - CMake (https://cmake.org/) OpenJazz ships a basic Makefile that may be used and adapted to the specific @@ -40,5 +40,4 @@ Some ports have their own options, see (Platforms)[PLATFORMS.md] for details. ### advanced options -~~- `HOMEDIR` - use the user's home directory for data files~~ default on unix - `FULLSCREEN_ONLY` - disable window mode, useful for console ports diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d77fe05..f4154d27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,13 +20,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED OFF) include(Platform-Helpers) # Endianess check - -if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) - include(TestBigEndian) - test_big_endian(PLATFORM_BIGENDIAN) - if(PLATFORM_BIGENDIAN) - add_compile_definitions(WORDS_BIGENDIAN=1) - endif() +include(TestBigEndian) +test_big_endian(PLATFORM_BIGENDIAN) +if(PLATFORM_BIGENDIAN) + add_compile_definitions(WORDS_BIGENDIAN=1) endif() # OpenJazz @@ -130,7 +127,7 @@ target_include_directories(OpenJazz PUBLIC src) option(SCALE "Allow scaling" ${OJ_SCALE}) if(SCALE) target_compile_definitions(OpenJazz PRIVATE SCALE) - set(OJ_SCALE_LIBS scale2x) + set(OJ_LIBS_SCALE scale2x) endif() # path to game data @@ -142,8 +139,17 @@ endif() # libraries -find_package(SDL REQUIRED) -target_include_directories(OpenJazz PRIVATE ${SDL_INCLUDE_DIR}) +if(LEGACY_SDL) + find_package(SDL REQUIRED) + target_include_directories(OpenJazz PRIVATE ${SDL_INCLUDE_DIR}) + set(OJ_LIBS_SDL ${SDL_LIBRARY}) + set(OJ_SDL "SDL1.2 (legacy)") +else() + find_package(SDL2 REQUIRED) + target_include_directories(OpenJazz PRIVATE ${SDL2_INCLUDE_DIRS}) + set(OJ_LIBS_SDL ${SDL2_LIBRARIES}) + set(OJ_SDL "SDL2") +endif() # bundled libraries @@ -176,7 +182,7 @@ if(NETWORK) endif() target_link_libraries(OpenJazz - argparse miniz psmplug ${OJ_SCALE_LIBS} ${SDL_LIBRARY} ${OJ_LIBS_NET} ${OJ_LIBS_HOST}) + argparse miniz psmplug ${OJ_LIBS_SCALE} ${OJ_LIBS_SDL} ${OJ_LIBS_NET} ${OJ_LIBS_HOST}) # platform stuff @@ -332,6 +338,7 @@ message(STATUS "") message(STATUS "OpenJazz") message(STATUS "========") message(STATUS "Target system: ${OJ_HOST}") +message(STATUS "Platform abstraction: ${OJ_SDL}") if(ROMFS) message(STATUS "RomFS: Embedding directory \"${ROMFS_PATH}\"") endif() diff --git a/Makefile b/Makefile index 817e0b37..3a47810d 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,10 @@ ifeq ($(OS),Windows_NT) LIBS += -lws2_32 endif -# SDL -CXXFLAGS += $(shell sdl-config --cflags) -LIBS += $(shell sdl-config --libs) +# SDL1.2 or SDL2 +SDLCONFIG ?= sdl-config +CXXFLAGS += $(shell $(SDLCONFIG) --cflags) +LIBS += $(shell $(SDLCONFIG) --libs) LIBS += -lm diff --git a/PLATFORMS.md b/PLATFORMS.md index d3ef0965..5c9c8242 100644 --- a/PLATFORMS.md +++ b/PLATFORMS.md @@ -7,12 +7,12 @@ Use a cross-compiler, enable specific platform code with option: ## Embedded Linux systems - * Pandora: ´-DPANDORA=ON´ - * GP2X Canoo: ´-DCAANOO=ON´ - * GP2X Wiz: ´-DWIZ=ON´ - * GP2X: ´-DGP2X=ON´ - * Dingoo: ´-DDINGOO=ON´ - * GameShell: ´-DGAMESHELL=ON´ + * Pandora: `-DPANDORA=ON` + * GP2X Canoo: `-DCAANOO=ON` + * GP2X Wiz: `-DWIZ=ON` + * GP2X: `-DGP2X=ON` + * Dingoo: `-DDINGOO=ON` + * GameShell: `-DGAMESHELL=ON` ## RISC OS diff --git a/README.md b/README.md index 39eac371..5b34d16a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ OpenJazz can be compiled on a wide range of operating systems, including Windows, macOS, GNU/Linux and BSD flavors. Also ports are available for some -homebrew platforms, for example Wii and PSP. See [Platforms](PLATFORMS.md) for +homebrew platforms, consoles and handhelds. See [Platforms](PLATFORMS.md) for details. To play, you will need the files from one of the original games. @@ -62,7 +62,8 @@ command line argument. ## Authors -Original author: Alister Thomson (alister_j_t at yahoo dot com), +Original author: Alister Thomson (alister_j_t at yahoo dot com) + [Additional Authors](res/unix/OpenJazz.6.adoc#authors) (See manual) ## Homepage diff --git a/builds/cmake/Platform-Helpers.cmake b/builds/cmake/Platform-Helpers.cmake index e9b181b9..ac85ee81 100644 --- a/builds/cmake/Platform-Helpers.cmake +++ b/builds/cmake/Platform-Helpers.cmake @@ -12,13 +12,14 @@ option(GP2X "Build for GP2X" OFF) # arm-open2x-linux option(DINGOO "Build for Dingoo" OFF) # mipsel-linux* option(GAMESHELL "Build for GameShell" OFF) # armv7l-unknown-linux-gnueabihf option(RISCOS "Build for RISC OS" OFF) # arm-unknown-riscos -# "Official" Toolchain files define these + +# Official/Homebrew Toolchain files define these if(NINTENDO_3DS) set(3DS ON) set(OJ_HOST "3DS") list(APPEND PLATFORM_LIST ${OJ_HOST}) set(OJ_SCALE OFF) - option(ROMFS "Embedd a directory in the executable" OFF) + option(ROMFS "Embed a directory in the executable" OFF) set(ROMFS_PATH "romfs" CACHE PATH "Directory to include in executable as romfs:/ path") set(ROMFS_ARG "NO_ROMFS_IGNORE_ME") if(ROMFS) @@ -111,4 +112,9 @@ endif() if(${OJ_HOST} STREQUAL "Unknown") set(OJ_HOST ${CMAKE_SYSTEM_NAME}) + set(OJ_ALLOW_NEW_SDL TRUE) endif() + +# choose SDL library for Linux/Windows/Mac/etc., but not homebrew platforms +include(CMakeDependentOption) +cmake_dependent_option(LEGACY_SDL "Build for SDL 1.2" OFF "OJ_ALLOW_NEW_SDL" ON) diff --git a/licenses.txt b/licenses.txt index bc27046e..2d443e11 100644 --- a/licenses.txt +++ b/licenses.txt @@ -32,9 +32,10 @@ emulators. The Simple DirectMedia Layer library source code is available from: https://www.libsdl.org/ -This library is distributed under the terms of the GNU LGPL license: -https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html +Version 1.2 of this library is distributed under the terms of the GNU LGPL +license: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html +Version 2 uses the zlib license: https://www.libsdl.org/license.php ================================================================================ diff --git a/res/unix/OpenJazz.6.adoc b/res/unix/OpenJazz.6.adoc index 10a0f1d3..ae98bd6e 100644 --- a/res/unix/OpenJazz.6.adoc +++ b/res/unix/OpenJazz.6.adoc @@ -130,7 +130,7 @@ Alireza Nejati:: Menu plasma effect newspaz:: Bug fixes, enemy improvements Carsten Teibes (carstene1ns):: Maintenance, bug fixes, documentation + -Integrating the ports (Wii, 3DS, PSP, PSVita, ...) + +Integrating the ports (Wii, 3DS, PSP, PSVita, SDL2, ...) + Additional coding (logger, CLI, ...) + Modernizing + UI improvements @@ -144,4 +144,4 @@ pocketinsanity:: PocketPC port Ricerind:: Mac OS X port Slaanesh:: GP32 port GPF:: Dreamcast port -Cameron Cawley (ccawley2011):: RISC OS port +Cameron Cawley (ccawley2011):: RISC OS, SDL2 port diff --git a/src/OpenJazz.h b/src/OpenJazz.h index 1d56fe87..133aac5a 100644 --- a/src/OpenJazz.h +++ b/src/OpenJazz.h @@ -96,6 +96,7 @@ #define E_NONE 0 +#define MAX_PALETTE_COLORS 256 // Macros diff --git a/src/io/file.cpp b/src/io/file.cpp index e0ff3da6..98ed5c65 100644 --- a/src/io/file.cpp +++ b/src/io/file.cpp @@ -597,10 +597,10 @@ void File::loadPalette (SDL_Color* palette, bool rle) { unsigned char* buffer; int count; - if (rle) buffer = loadRLE(768); - else buffer = loadBlock(768); + if (rle) buffer = loadRLE(MAX_PALETTE_COLORS * 3); + else buffer = loadBlock(MAX_PALETTE_COLORS * 3); - for (count = 0; count < 256; count++) { + for (count = 0; count < MAX_PALETTE_COLORS; count++) { // Palette entries are 6-bit // Shift them upwards to 8-bit, and fill in the lower 2 bits diff --git a/src/io/gfx/font.cpp b/src/io/gfx/font.cpp index 0e1a1e3b..e172d2e6 100644 --- a/src/io/gfx/font.cpp +++ b/src/io/gfx/font.cpp @@ -100,7 +100,7 @@ Font::Font (const char* fileName) { } else characters[count] = createSurface(blank, 3, 1); - SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 0); + enableColorKey(characters[count], 0); } @@ -172,7 +172,7 @@ Font::Font (unsigned char* pixels, bool big) { characters[count] = createSurface(chrPixels, 8, lineHeight); - if (big) SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 31); + if (big) enableColorKey(characters[count], 31); } @@ -285,7 +285,7 @@ Font::Font (bool bonus) { pixels = file->loadPixels(width * height); characters[count] = createSurface(pixels, width, height); - SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 254); + enableColorKey(characters[count], 254); delete[] pixels; @@ -301,7 +301,7 @@ Font::Font (bool bonus) { pixels = new unsigned char[3]; memset(pixels, 254, 3); characters[nCharacters] = createSurface(pixels, 3, 1); - SDL_SetColorKey(characters[nCharacters], SDL_SRCCOLORKEY, 254); + enableColorKey(characters[nCharacters], 254); delete[] pixels; @@ -533,7 +533,7 @@ void Font::showNumber (int n, int x, int y) { */ void Font::mapPalette (int start, int length, int newStart, int newLength) { - SDL_Color palette[256]; + SDL_Color palette[MAX_PALETTE_COLORS]; int count; for (count = 0; count < length; count++) @@ -541,7 +541,7 @@ void Font::mapPalette (int start, int length, int newStart, int newLength) { (count * newLength / length) + newStart; for (count = 0; count < nCharacters; count++) - SDL_SetPalette(characters[count], SDL_LOGPAL, palette, start, length); + setLogicalPalette(characters[count], palette, start, length); } diff --git a/src/io/gfx/paletteeffects.cpp b/src/io/gfx/paletteeffects.cpp index 2b2386c4..fee5d606 100644 --- a/src/io/gfx/paletteeffects.cpp +++ b/src/io/gfx/paletteeffects.cpp @@ -102,13 +102,13 @@ void WhiteInPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf if (whiteness > F1) { - memset(shownPalette, 255, sizeof(SDL_Color) * 256); + memset(shownPalette, 255, sizeof(SDL_Color) * MAX_PALETTE_COLORS); if (!isStatic) whiteness -= ITOF(mspf) / duration; } else if (whiteness > 0) { - for (count = 0; count < 256; count++) { + for (count = 0; count < MAX_PALETTE_COLORS; count++) { shownPalette[count].r = 255 - FTOI((255 - shownPalette[count].r) * (F1 - whiteness)); @@ -123,7 +123,7 @@ void WhiteInPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf } - if (direct) video.changePalette(shownPalette, 0, 256); + if (direct) video.changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } @@ -161,13 +161,13 @@ void FadeInPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, if (blackness > F1) { - memset(shownPalette, 0, sizeof(SDL_Color) * 256); + memset(shownPalette, 0, sizeof(SDL_Color) * MAX_PALETTE_COLORS); if (!isStatic) blackness -= ITOF(mspf) / duration; } else if (blackness > 0) { - for (count = 0; count < 256; count++) { + for (count = 0; count < MAX_PALETTE_COLORS; count++) { shownPalette[count].r = FTOI(shownPalette[count].r * (F1 - blackness)); @@ -182,7 +182,7 @@ void FadeInPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, } - if (direct) video.changePalette(shownPalette, 0, 256); + if (direct) video.changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } @@ -218,13 +218,13 @@ void WhiteOutPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int msp if (whiteness > F1) { - memset(shownPalette, 255, sizeof(SDL_Color) * 256); + memset(shownPalette, 255, sizeof(SDL_Color) * MAX_PALETTE_COLORS); } else { if (whiteness > 0) { - for (int i = 0; i < 256; i++) { + for (int i = 0; i < MAX_PALETTE_COLORS; i++) { shownPalette[i].r = 255 - FTOI((255 - shownPalette[i].r) * (F1 - whiteness)); @@ -240,7 +240,7 @@ void WhiteOutPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int msp } - if (direct) video.changePalette(shownPalette, 0, 256); + if (direct) video.changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } @@ -275,13 +275,13 @@ void FadeOutPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf if (blackness > F1) { - memset(shownPalette, 0, sizeof(SDL_Color) * 256); + memset(shownPalette, 0, sizeof(SDL_Color) * MAX_PALETTE_COLORS); } else { if (blackness > 0) { - for (int i = 0; i < 256; i++) { + for (int i = 0; i < MAX_PALETTE_COLORS; i++) { shownPalette[i].r = FTOI(shownPalette[i].r * (F1 - blackness)); shownPalette[i].g = FTOI(shownPalette[i].g * (F1 - blackness)); @@ -295,7 +295,7 @@ void FadeOutPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf } - if (direct) video.changePalette(shownPalette, 0, 256); + if (direct) video.changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } @@ -340,7 +340,7 @@ void FlashPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, if (progress < 0) { - for (count = 0; count < 256; count++) { + for (count = 0; count < MAX_PALETTE_COLORS; count++) { shownPalette[count].r = FTOI((shownPalette[count].r * -progress) + (red * (progress + F1))); @@ -355,7 +355,7 @@ void FlashPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, } else if (progress < F1) { - for (count = 0; count < 256; count++) { + for (count = 0; count < MAX_PALETTE_COLORS; count++) { shownPalette[count].r = FTOI((shownPalette[count].r * progress) + (red * (F1 - progress))); @@ -370,7 +370,7 @@ void FlashPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, } - if (direct) video.changePalette(shownPalette, 0, 256); + if (direct) video.changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } @@ -656,7 +656,7 @@ void WaterPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, if (position < depth) { - for (int i = 0; i < 256; i++) { + for (int i = 0; i < MAX_PALETTE_COLORS; i++) { shownPalette[i].r = FTOI(currentPalette[i].r * (1023 - DIV(position, depth))); shownPalette[i].g = FTOI(currentPalette[i].g * (1023 - DIV(position, depth))); @@ -664,8 +664,8 @@ void WaterPaletteEffect::apply (SDL_Color* shownPalette, bool direct, int mspf, } - } else memset(shownPalette, 0, sizeof(SDL_Color) * 256); + } else memset(shownPalette, 0, sizeof(SDL_Color) * MAX_PALETTE_COLORS); - if (direct) video.changePalette(shownPalette, 0, 256); + if (direct) video.changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } diff --git a/src/io/gfx/sprite.cpp b/src/io/gfx/sprite.cpp index 9bbf24d3..0e859c22 100644 --- a/src/io/gfx/sprite.cpp +++ b/src/io/gfx/sprite.cpp @@ -60,7 +60,7 @@ void Sprite::clearPixels () { data = 0; pixels = createSurface(&data, 1, 1); - SDL_SetColorKey(pixels, SDL_SRCCOLORKEY, 0); + enableColorKey(pixels, 0); } @@ -86,7 +86,7 @@ void Sprite::setPixels (unsigned char *data, int width, int height, unsigned cha if (pixels) SDL_FreeSurface(pixels); pixels = createSurface(data, width, height); - SDL_SetColorKey(pixels, SDL_SRCCOLORKEY, key); + enableColorKey(pixels, key); } @@ -148,7 +148,7 @@ int Sprite::getYOffset () { */ void Sprite::setPalette (SDL_Color *palette, int start, int amount) { - SDL_SetPalette(pixels, SDL_LOGPAL, palette + start, start, amount); + setLogicalPalette(pixels, palette + start, start, amount); } @@ -160,13 +160,11 @@ void Sprite::setPalette (SDL_Color *palette, int start, int amount) { */ void Sprite::flashPalette (int index) { - SDL_Color palette[256]; - int count; + SDL_Color palette[MAX_PALETTE_COLORS]; + for (int i = 0; i < MAX_PALETTE_COLORS; i++) + palette[i].r = palette[i].g = palette[i].b = index; - for (count = 0; count < 256; count++) - palette[count].r = palette[count].g = palette[count].b = index; - - SDL_SetPalette(pixels, SDL_LOGPAL, palette, 0, 256); + setLogicalPalette(pixels, palette, 0, MAX_PALETTE_COLORS); } @@ -216,12 +214,11 @@ void Sprite::draw (int x, int y, bool includeOffsets) { */ void Sprite::drawScaled (int x, int y, fixed scale) { - unsigned char pixel, key; int width, height, fullWidth, fullHeight; int dstX, dstY; int srcX, srcY; - key = pixels->format->colorkey; + unsigned char key = getColorKey(pixels); fullWidth = FTOI(pixels->w * scale); if (x < -(fullWidth >> 1)) return; // Off-screen @@ -266,7 +263,7 @@ void Sprite::drawScaled (int x, int y, fixed scale) { while (srcX < width) { - pixel = srcRow[DIV(srcX, scale)]; + unsigned char pixel = srcRow[DIV(srcX, scale)]; if (pixel != key) dstRow[dstX] = pixel; srcX++; diff --git a/src/io/gfx/video.cpp b/src/io/gfx/video.cpp index dea923cc..b8ba9c08 100644 --- a/src/io/gfx/video.cpp +++ b/src/io/gfx/video.cpp @@ -49,8 +49,14 @@ */ SDL_Surface* createSurface (unsigned char * pixels, int width, int height) { +#if OJ_SDL2 + int surfaceFlag = 0; // flags are unused +#else + int surfaceFlag = SDL_HWSURFACE; +#endif + // Create the surface - SDL_Surface *ret = SDL_CreateRGBSurface(SDL_HWSURFACE, width, height, 8, 0, 0, 0, 0); + SDL_Surface *ret = SDL_CreateRGBSurface(surfaceFlag, width, height, 8, 0, 0, 0, 0); // Set the surface's palette video.restoreSurfacePalette(ret); @@ -79,7 +85,6 @@ SDL_Surface* createSurface (unsigned char * pixels, int width, int height) { Video::Video () { screen = NULL; - fakePalette = false; minW = maxW = screenW = DEFAULT_SCREEN_WIDTH; minH = maxH = screenH = DEFAULT_SCREEN_HEIGHT; #ifdef SCALE @@ -88,7 +93,7 @@ Video::Video () { fullscreen = false; // Generate the logical palette - for (int i = 0; i < 256; i++) + for (int i = 0; i < MAX_PALETTE_COLORS; i++) logicalPalette[i].r = logicalPalette[i].g = logicalPalette[i].b = i; currentPalette = logicalPalette; @@ -104,17 +109,34 @@ void Video::findResolutions () { #ifdef NO_RESIZE minW = maxW = DEFAULT_SCREEN_WIDTH; minH = maxH = DEFAULT_SCREEN_HEIGHT; + + // no need to sanitize + return; +#elif OJ_SDL2 + SDL_DisplayMode mode; + + minW = SW; + minH = SH; + + if (SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(window), &mode) >= 0) { + maxW = mode.w; + maxH = mode.h; + } else { + LOG_WARN("Could not query display mode, using defaults."); + + maxW = DEFAULT_SCREEN_WIDTH; + maxH = DEFAULT_SCREEN_HEIGHT; + } #else SDL_Rect **resolutions = SDL_ListModes(NULL, fullscreen? FULLSCREEN_FLAGS: WINDOWED_FLAGS); // All resolutions available, set to arbitrary limit if (resolutions == reinterpret_cast(-1)) { - + LOG_DEBUG("No display mode limit found."); minW = SW; minH = SH; maxW = MAX_SCREEN_WIDTH; maxH = MAX_SCREEN_HEIGHT; - } else { for (int i = 0; resolutions[i] != NULL; i++) { @@ -133,15 +155,17 @@ void Video::findResolutions () { } - // Sanitize - if (minW < SW) minW = SW; - if (minH < SH) minH = SH; - if (maxW > MAX_SCREEN_WIDTH) maxW = MAX_SCREEN_WIDTH; - if (maxH > MAX_SCREEN_HEIGHT) maxH = MAX_SCREEN_HEIGHT; - } #endif + // Sanitize + if (minW < SW) minW = SW; + if (minH < SH) minH = SH; + if (maxW > MAX_SCREEN_WIDTH) maxW = MAX_SCREEN_WIDTH; + if (maxH > MAX_SCREEN_HEIGHT) maxH = MAX_SCREEN_HEIGHT; + + LOG_TRACE("Allowing resolutions between %dx%d and %dx%d.", minW, minH, maxW, maxH); + } @@ -156,6 +180,20 @@ bool Video::init (SetupOptions cfg) { fullscreen = cfg.fullScreen; +#if OJ_SDL2 + window = SDL_CreateWindow("OpenJazz", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SW, SH, fullscreen? SDL_WINDOW_FULLSCREEN_DESKTOP: SDL_WINDOW_RESIZABLE); + if (!window) { + LOG_FATAL("Could not create window: %s", SDL_GetError()); + return false; + } + + renderer = SDL_CreateRenderer(window, -1, 0); + if (!renderer) { + LOG_FATAL("Could not create renderer: %s", SDL_GetError()); + return false; + } +#endif + if (fullscreen) SDL_ShowCursor(SDL_DISABLE); findResolutions(); @@ -167,11 +205,8 @@ bool Video::init (SetupOptions cfg) { #endif if (!reset(cfg.videoWidth, cfg.videoHeight)) { - LOG_FATAL("Could not set video mode: %s", SDL_GetError()); - return false; - } setTitle(NULL); @@ -180,6 +215,56 @@ bool Video::init (SetupOptions cfg) { } +/** + * Shared Deinitialisation code for reset() and deinit() + * + */ +void Video::commonDeinit () { + // canvas is used when scaling or built with SDL2 + if (canvas != screen && canvas) { + SDL_FreeSurface(canvas); + canvas = NULL; + } + +#if OJ_SDL2 + if(screen) { + SDL_FreeSurface(screen); + screen = NULL; + } + + if(textureSurface) { + SDL_FreeSurface(textureSurface); + textureSurface = NULL; + } + + if(texture) { + SDL_DestroyTexture(texture); + texture = NULL; + } +#endif +} + +/** + * Deinitialise video output. + * + */ +void Video::deinit () { + + commonDeinit(); + +#if OJ_SDL2 + if(renderer) { + SDL_DestroyRenderer(renderer); + renderer = NULL; + } + + if(window) { + SDL_DestroyWindow(window); + window = NULL; + } +#endif + +} /** * Sets the size of the video window or the resolution of the screen. @@ -200,22 +285,28 @@ bool Video::reset (int width, int height) { screenH = height; #endif -#ifdef SCALE - if (canvas != screen) SDL_FreeSurface(canvas); -#endif + commonDeinit(); // If video mode is not valid reset to low default if (screenW < minW || screenW > maxW || screenH< minH || screenH > maxH) { + LOG_WARN("Video mode invalid, resetting."); screenW = minW; screenH = minH; } +#if OJ_SDL2 + SDL_SetWindowSize(window, screenW, screenH); + SDL_SetWindowFullscreen(window, fullscreen? SDL_WINDOW_FULLSCREEN_DESKTOP: 0); +#else screen = SDL_SetVideoMode(screenW, screenH, 8, fullscreen? FULLSCREEN_FLAGS: WINDOWED_FLAGS); - if (!screen) return false; - +#endif #ifdef SCALE + // sanitize + if (scaleFactor < 1) scaleFactor = 1; + if (scaleFactor > 4) scaleFactor = 4; + // Check that the scale will fit in the current resolution while ( ((screenW/SW < scaleFactor) || (screenH/SH < scaleFactor)) && (scaleFactor > 1) ) { @@ -231,30 +322,51 @@ bool Video::reset (int width, int height) { } else #endif - { + { canvasW = screenW; canvasH = screenH; + +#if OJ_SDL2 + canvas = createSurface(NULL, canvasW, canvasH); +#else canvas = screen; +#endif } +#if OJ_SDL2 + screen = SDL_CreateRGBSurfaceFrom(canvas->pixels, canvasW, canvasH, canvas->format->BitsPerPixel, canvas->pitch, + canvas->format->Rmask, canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask); + + Uint32 format = SDL_PIXELFORMAT_RGB888; + SDL_RendererInfo info; + if (SDL_GetRendererInfo(renderer, &info) >= 0) { + for (Uint32 i = 0; i < info.num_texture_formats; i++) { + if (SDL_ISPIXELFORMAT_PACKED(info.texture_formats[i])) { + format = info.texture_formats[i]; + break; + } + } + } + + texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, canvasW, canvasH); + if (!texture) { + LOG_WARN("Could not create texture: %s\n", SDL_GetError()); + return false; + } + + textureSurface = SDL_CreateRGBSurfaceWithFormat(SDL_SWSURFACE, canvasW, canvasH, SDL_BITSPERPIXEL(format), format); + if (!textureSurface) { + LOG_WARN("Could not create surface: %s\n", SDL_GetError()); + return false; + } +#endif + #if !defined(WIZ) && !defined(GP2X) expose(); #endif - - /* A real 8-bit display is quite likely if the user has the right video - card, the right video drivers, the right version of DirectX/whatever, and - the right version of SDL. In other words, it's not likely enough. If a real - palette is assumed when - a) there really is a real palette, there will be an extremely small speed - gain. - b) the palette is emulated, there will be a HUGE speed loss. - Therefore, assume the palette is emulated. */ - /// @todo Find a better way to determine if palette is emulated - fakePalette = true; - return true; } @@ -271,7 +383,7 @@ void Video::setPalette (SDL_Color *palette) { clearScreen(SDL_MapRGB(screen->format, 0, 0, 0)); flip(0); - SDL_SetPalette(screen, SDL_PHYSPAL, palette, 0, 256); + changePalette(palette, 0, MAX_PALETTE_COLORS); currentPalette = palette; } @@ -298,7 +410,11 @@ SDL_Color* Video::getPalette () { */ void Video::changePalette (SDL_Color *palette, unsigned char first, unsigned int amount) { +#if OJ_SDL2 + SDL_SetPaletteColors(screen->format->palette, palette, first, amount); +#else SDL_SetPalette(screen, SDL_PHYSPAL, palette, first, amount); +#endif } @@ -310,7 +426,7 @@ void Video::changePalette (SDL_Color *palette, unsigned char first, unsigned int */ void Video::restoreSurfacePalette (SDL_Surface* surface) { - SDL_SetPalette(surface, SDL_LOGPAL, logicalPalette, 0, 256); + setLogicalPalette(surface, logicalPalette, 0, MAX_PALETTE_COLORS); } @@ -393,27 +509,25 @@ int Video::getHeight () { void Video::setTitle (const char *title) { const char titleBase[] = "OpenJazz"; - char *windowTitle = NULL; int titleLen = strlen(titleBase) + 1; if (title != NULL) { - titleLen = strlen(titleBase) + 3 + strlen(title) + 1; - } - windowTitle = new char[titleLen]; - + char *windowTitle = new char[titleLen]; strcpy(windowTitle, titleBase); if (title != NULL) { - strcat(windowTitle, " - "); strcat(windowTitle, title); - } +#if OJ_SDL2 + SDL_SetWindowTitle(window, windowTitle); +#else SDL_WM_SetCaption(windowTitle, NULL); +#endif delete[] windowTitle; @@ -472,8 +586,8 @@ bool Video::isFullscreen () { */ void Video::expose () { - SDL_SetPalette(screen, SDL_LOGPAL, logicalPalette, 0, 256); - SDL_SetPalette(screen, SDL_PHYSPAL, currentPalette, 0, 256); + setLogicalPalette(screen, logicalPalette, 0, MAX_PALETTE_COLORS); + changePalette(currentPalette, 0, MAX_PALETTE_COLORS); } @@ -508,21 +622,23 @@ void Video::update (SDL_Event *event) { } break; - #endif + #endif - #ifndef NO_RESIZE + #if !OJ_SDL2 + #ifndef NO_RESIZE case SDL_VIDEORESIZE: reset(event->resize.w, event->resize.h); break; - #endif + #endif case SDL_VIDEOEXPOSE: expose(); break; + #endif } #endif @@ -539,7 +655,7 @@ void Video::update (SDL_Event *event) { */ void Video::flip (int mspf, PaletteEffect* paletteEffects, bool effectsStopped) { - SDL_Color shownPalette[256]; + SDL_Color shownPalette[MAX_PALETTE_COLORS]; #ifdef SCALE if (canvas != NULL && canvas != screen) { @@ -558,30 +674,22 @@ void Video::flip (int mspf, PaletteEffect* paletteEffects, bool effectsStopped) // Apply palette effects if (paletteEffects) { - - /* If the palette is being emulated, compile all palette changes and - apply them all at once. - If the palette is being used directly, apply all palette effects - directly. */ - - if (fakePalette) { - - memcpy(shownPalette, currentPalette, sizeof(SDL_Color) * 256); - - paletteEffects->apply(shownPalette, false, mspf, effectsStopped); - - SDL_SetPalette(screen, SDL_PHYSPAL, shownPalette, 0, 256); - - } else { - - paletteEffects->apply(shownPalette, true, mspf, effectsStopped); - - } - + // The palette is emulated, compile all palette changes and apply at once. + memcpy(shownPalette, currentPalette, sizeof(SDL_Color) * MAX_PALETTE_COLORS); + paletteEffects->apply(shownPalette, false, mspf, effectsStopped); + changePalette(shownPalette, 0, MAX_PALETTE_COLORS); } // Show what has been drawn +#if OJ_SDL2 + SDL_BlitSurface(screen, NULL, textureSurface, NULL); + SDL_UpdateTexture(texture, NULL, textureSurface->pixels, textureSurface->pitch); + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); +#else SDL_Flip(screen); +#endif } @@ -626,3 +734,64 @@ void drawRect (int x, int y, int width, int height, int index) { SDL_FillRect(canvas, &dst, index); } + +/** + * Sets the Color key of provided surface. + * + * @param surface Surface to change + * @param index Color index + */ +void enableColorKey (SDL_Surface* surface, unsigned int index) { + +#if OJ_SDL2 + SDL_SetColorKey(surface, SDL_TRUE, index); +#else + SDL_SetColorKey(surface, SDL_SRCCOLORKEY, index); +#endif + +} + +/** + * Returns the Color key of provided surface. + * + * @param surface Surface to query + * + * @return color index + */ +unsigned int getColorKey (SDL_Surface* surface) { + +#if OJ_SDL2 + Uint32 key; + + if (SDL_GetColorKey(surface, &key) < 0) { + LOG_WARN("Could not get Color Key: %s\n", SDL_GetError()); + return -1; + } + + return key; +#else + return surface->format->colorkey; +#endif + +} + +/** + * Sets the palette colors of provided surface. + * + * @param surface Surface to change + * @param palette Palette to copy colors from + * @param start index of first color copy + * @param length number of colors to copy + */ +void setLogicalPalette (SDL_Surface* surface, SDL_Color *palette, int start, int length) { + +#if OJ_SDL2 + if (surface->format->palette) { + SDL_SetPaletteColors(surface->format->palette, palette, start, length); + } else + LOG_WARN("Could not change palette on surface without palette."); +#else + SDL_SetPalette(surface, SDL_LOGPAL, palette, start, length); +#endif + +} diff --git a/src/io/gfx/video.h b/src/io/gfx/video.h index 88a97cc4..6fa59338 100644 --- a/src/io/gfx/video.h +++ b/src/io/gfx/video.h @@ -25,7 +25,11 @@ #include "paletteeffects.h" #include - +#if SDL_VERSION_ATLEAST(2, 0, 0) + #define OJ_SDL2 1 +#else + #define OJ_SDL2 0 +#endif // Constants @@ -44,6 +48,8 @@ #define MAX_SCREEN_WIDTH (32 * 256 * MAX_SCALE) #define MAX_SCREEN_HEIGHT (32 * 64 * MAX_SCALE) +// Fullscreen and Window flags are only for SDL1.2 currently + #define WINDOWED_FLAGS (SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWPALETTE) #if defined(CAANOO) || defined(WIZ) || defined(GP2X) || defined(GAMESHELL) @@ -111,23 +117,28 @@ class Video { private: - SDL_Surface* screen; ///< Output surface +#if OJ_SDL2 + SDL_Window* window; ///< Output window + SDL_Renderer* renderer; ///< Output renderer + SDL_Texture* texture; ///< Output texture + SDL_Surface* textureSurface; +#endif + SDL_Surface* screen; ///< Output surface // Palettes - SDL_Color* currentPalette; ///< Current palette - SDL_Color logicalPalette[256]; ///< Logical palette (greyscale) - bool fakePalette; ///< Whether or not the palette mode is being emulated - - int minW; ///< Smallest possible width - int maxW; ///< Largest possible width - int minH; ///< Smallest possible height - int maxH; ///< Largest possible height - int screenW; ///< Real width - int screenH; ///< Real height + SDL_Color* currentPalette; ///< Current palette + SDL_Color logicalPalette[MAX_PALETTE_COLORS]; ///< Logical palette (greyscale) + + int minW; ///< Smallest possible width + int maxW; ///< Largest possible width + int minH; ///< Smallest possible height + int maxH; ///< Largest possible height + int screenW; ///< Real width + int screenH; ///< Real height #ifdef SCALE - int scaleFactor; ///< Scaling factor + int scaleFactor; ///< Scaling factor #endif - bool fullscreen; ///< Full-screen mode + bool fullscreen; ///< Full-screen mode void findResolutions (); void expose (); @@ -136,8 +147,9 @@ class Video { Video (); bool init (SetupOptions cfg); - + void deinit (); bool reset (int width, int height); + void commonDeinit (); void setPalette (SDL_Color *palette); SDL_Color* getPalette (); @@ -178,9 +190,10 @@ EXTERN Video video; ///< Video output // Functions -EXTERN SDL_Surface* createSurface (unsigned char* pixels, int width, int height); -EXTERN void drawRect (int x, int y, int width, int height, int index); +EXTERN SDL_Surface* createSurface (unsigned char* pixels, int width, int height); +EXTERN void drawRect (int x, int y, int width, int height, int index); +EXTERN void enableColorKey (SDL_Surface* surface, unsigned int index); +EXTERN unsigned int getColorKey (SDL_Surface* surface); +EXTERN void setLogicalPalette (SDL_Surface* surface, SDL_Color *palette, int start, int length); #endif - - diff --git a/src/jj1/bonuslevel/jj1bonuslevelplayer.cpp b/src/jj1/bonuslevel/jj1bonuslevelplayer.cpp index e3bf6fbf..9277f539 100644 --- a/src/jj1/bonuslevel/jj1bonuslevelplayer.cpp +++ b/src/jj1/bonuslevel/jj1bonuslevelplayer.cpp @@ -58,7 +58,7 @@ JJ1BonusLevelPlayer::JJ1BonusLevelPlayer (Player* parent, Anim **newAnims, unsig // Create the player's palette - for (int i = 0; i < 256; i++) + for (int i = 0; i < MAX_PALETTE_COLORS; i++) palette[i].r = palette[i].g = palette[i].b = i; /// @todo Custom colours diff --git a/src/jj1/level/jj1level.h b/src/jj1/level/jj1level.h index bbab0f66..5a2534a0 100644 --- a/src/jj1/level/jj1level.h +++ b/src/jj1/level/jj1level.h @@ -186,7 +186,7 @@ class JJ1Level : public Level { JJ1EventType eventSet[EVENTS]; ///< Event types char mask[240][64]; ///< Tile masks. At most 240 tiles, all with 8 * 8 masks GridElement grid[LH][LW]; ///< Level grid. All levels are the same size - SDL_Color skyPalette[256]; ///< Full palette for sky background + SDL_Color skyPalette[MAX_PALETTE_COLORS]; ///< Full palette for sky background bool sky; ///< Whether or not to use sky background unsigned char skyOrb; ///< The tile to use as the background sun/moon/etc. int levelNum; ///< Number of current level diff --git a/src/jj1/level/jj1levelload.cpp b/src/jj1/level/jj1levelload.cpp index 6d06893f..76bd21b8 100644 --- a/src/jj1/level/jj1levelload.cpp +++ b/src/jj1/level/jj1levelload.cpp @@ -374,7 +374,7 @@ int JJ1Level::loadTiles (char* fileName) { tiles = pos >> 10; tileSet = createSurface(buffer, TTOI(1), TTOI(tiles)); - SDL_SetColorKey(tileSet, SDL_SRCCOLORKEY, TKEY); + enableColorKey(tileSet, TKEY); delete[] buffer; diff --git a/src/jj1/level/jj1levelplayer.cpp b/src/jj1/level/jj1levelplayer.cpp index 683ba5ec..65b65ca2 100644 --- a/src/jj1/level/jj1levelplayer.cpp +++ b/src/jj1/level/jj1levelplayer.cpp @@ -70,7 +70,7 @@ JJ1LevelPlayer::JJ1LevelPlayer (Player* parent, Anim** newAnims, unsigned char s // Create the player's palette - for (count = 0; count < 256; count++) + for (count = 0; count < MAX_PALETTE_COLORS; count++) palette[count].r = palette[count].g = palette[count].b = count; diff --git a/src/jj1/planet/jj1planet.h b/src/jj1/planet/jj1planet.h index cccb4fb4..ecc5e20a 100644 --- a/src/jj1/planet/jj1planet.h +++ b/src/jj1/planet/jj1planet.h @@ -31,7 +31,7 @@ class JJ1Planet { private: - SDL_Color palette[256]; /// Palette + SDL_Color palette[MAX_PALETTE_COLORS]; /// Palette Sprite sprite; /// Planet image char* name; /// Planet name int id; /// World number diff --git a/src/jj1/scene/jj1scene.cpp b/src/jj1/scene/jj1scene.cpp index d80976fe..2bf2bd1d 100644 --- a/src/jj1/scene/jj1scene.cpp +++ b/src/jj1/scene/jj1scene.cpp @@ -610,7 +610,7 @@ int JJ1Scene::play () { } // Drop shadow - font->mapPalette(0, 256, 0, 1); + font->mapPalette(0, MAX_PALETTE_COLORS, 0, 1); font->showSceneString(text->text, xOffset + 1, yOffset + 1); font->restorePalette(); diff --git a/src/jj1/scene/jj1scene.h b/src/jj1/scene/jj1scene.h index e654661f..98181b3c 100644 --- a/src/jj1/scene/jj1scene.h +++ b/src/jj1/scene/jj1scene.h @@ -22,10 +22,8 @@ #ifndef _SCENE_H #define _SCENE_H - #include "io/file.h" - // Enums /** @@ -165,7 +163,7 @@ class JJ1ScenePalette { public: JJ1ScenePalette* next; - SDL_Color palette[256]; + SDL_Color palette[MAX_PALETTE_COLORS]; int id; explicit JJ1ScenePalette (JJ1ScenePalette* newNext); diff --git a/src/jj2/level/event/jj2eventframe.cpp b/src/jj2/level/event/jj2eventframe.cpp index ddea9af7..3c621638 100644 --- a/src/jj2/level/event/jj2eventframe.cpp +++ b/src/jj2/level/event/jj2eventframe.cpp @@ -414,7 +414,7 @@ void AmmoJJ2Event::draw (unsigned int ticks, int change) { */ void CoinGemJJ2Event::mapPalette (Anim* anim, int start) { - SDL_Color palette[256]; + SDL_Color palette[MAX_PALETTE_COLORS]; int count; for (count = 0; count < 112; count++) diff --git a/src/jj2/level/jj2levelload.cpp b/src/jj2/level/jj2levelload.cpp index 55b37eac..697c6f23 100644 --- a/src/jj2/level/jj2levelload.cpp +++ b/src/jj2/level/jj2levelload.cpp @@ -332,7 +332,7 @@ int JJ2Level::loadTiles (char* fileName) { // Load the palette - for (count = 0; count < 256; count++) { + for (count = 0; count < MAX_PALETTE_COLORS; count++) { palette[count].r = aBuffer[count << 2]; palette[count].g = aBuffer[(count << 2) + 1]; @@ -353,7 +353,7 @@ int JJ2Level::loadTiles (char* fileName) { } tileSet = createSurface(tileBuffer, TTOI(1), TTOI(tiles)); - SDL_SetColorKey(tileSet, SDL_SRCCOLORKEY, 0); + enableColorKey(tileSet, 0); // Flip tiles for (count = 0; count < TTOI(tiles); count++) { @@ -369,7 +369,7 @@ int JJ2Level::loadTiles (char* fileName) { } flippedTileSet = createSurface(tileBuffer, TTOI(1), TTOI(tiles)); - SDL_SetColorKey(flippedTileSet, SDL_SRCCOLORKEY, 0); + enableColorKey(flippedTileSet, 0); delete[] tileBuffer; diff --git a/src/jj2/level/jj2levelplayer.cpp b/src/jj2/level/jj2levelplayer.cpp index 6e2447c4..f5509c78 100644 --- a/src/jj2/level/jj2levelplayer.cpp +++ b/src/jj2/level/jj2levelplayer.cpp @@ -73,7 +73,7 @@ JJ2LevelPlayer::JJ2LevelPlayer (Player* parent, Anim** newAnims, // Create the player's palette - for (count = 0; count < 256; count++) + for (count = 0; count < MAX_PALETTE_COLORS; count++) palette[count].r = palette[count].g = palette[count].b = count; diff --git a/src/level/level.h b/src/level/level.h index e3a4c8d2..e13269d8 100644 --- a/src/level/level.h +++ b/src/level/level.h @@ -23,10 +23,8 @@ #ifndef _BASELEVEL_H #define _BASELEVEL_H - #include "menu/menu.h" - // Macros // For converting between tile positions and int/fixed values @@ -95,7 +93,7 @@ class Level { protected: Game* game; PaletteEffect* paletteEffects; ///< Palette effects in use while playing the level - SDL_Color palette[256]; ///< Palette in use while playing the level + SDL_Color palette[MAX_PALETTE_COLORS]; ///< Palette in use while playing the level int sprites; ///< The number of sprite that have been loaded unsigned int tickOffset; ///< Level time offset from system time unsigned int steps; ///< Number of steps taken diff --git a/src/level/levelplayer.h b/src/level/levelplayer.h index e38501f4..a794e695 100644 --- a/src/level/levelplayer.h +++ b/src/level/levelplayer.h @@ -43,7 +43,7 @@ class Player; class LevelPlayer : public Movable { protected: - SDL_Color palette[256]; ///< Palette (for custom colours) + SDL_Color palette[MAX_PALETTE_COLORS]; ///< Palette (for custom colours) public: Player* player; ///< Corresponding game player diff --git a/src/main.cpp b/src/main.cpp index 1b660236..08edc3bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -389,12 +389,9 @@ void shutDown () { delete fontmn1; delete fontmn2; -#ifdef SCALE - if (video.getScaleFactor() > 1) SDL_FreeSurface(canvas); -#endif - closeAudio(); + video.deinit(); // Save settings to config file setup.save(); @@ -650,6 +647,8 @@ int main(int argc, char *argv[]) { // Save configuration and shut down + LOG_DEBUG("Shutting down engine."); + shutDown(); PLATFORM_Exit(); diff --git a/src/menu/gamemenu.cpp b/src/menu/gamemenu.cpp index 0c83e682..ac7d4632 100644 --- a/src/menu/gamemenu.cpp +++ b/src/menu/gamemenu.cpp @@ -47,7 +47,7 @@ GameMenu::GameMenu (File *file) { // Load the difficulty graphics file->loadPalette(menuPalette); difficultyScreen = file->loadSurface(SW, SH); - SDL_SetColorKey(difficultyScreen, SDL_SRCCOLORKEY, 0); + enableColorKey(difficultyScreen, 0); // Load the episode pictures (max. 10 episodes + bonus level) @@ -55,7 +55,7 @@ GameMenu::GameMenu (File *file) { file->loadPalette(palette); // Generate a greyscale mapping - for (int i = 0; i < 256; i++) { + for (int i = 0; i < MAX_PALETTE_COLORS; i++) { int col = ((palette[i].r >> 1) + (palette[i].g << 1) + (palette[i].b >> 1)) >> 3; @@ -481,7 +481,7 @@ int GameMenu::newGameEpisode (GameModeType mode) { delete[] check; if (exists[count]) video.restoreSurfacePalette(episodeScreens[count]); - else SDL_SetPalette(episodeScreens[count], SDL_LOGPAL, greyPalette, 0, 256); + else setLogicalPalette(episodeScreens[count], greyPalette, 0, MAX_PALETTE_COLORS); } diff --git a/src/menu/mainmenu.cpp b/src/menu/mainmenu.cpp index f7780560..b0465b44 100644 --- a/src/menu/mainmenu.cpp +++ b/src/menu/mainmenu.cpp @@ -117,9 +117,9 @@ MainMenu::MainMenu () { } - SDL_SetColorKey(background, SDL_SRCCOLORKEY, 0); - SDL_SetColorKey(highlight, SDL_SRCCOLORKEY, 0); - if (logo) SDL_SetColorKey(logo, SDL_SRCCOLORKEY, 28); + enableColorKey(background, 0); + enableColorKey(highlight, 0); + if (logo) enableColorKey(logo, 28); gameMenu = new GameMenu(file); @@ -430,7 +430,7 @@ int MainMenu::main () { SDL_BlitSurface(logo, NULL, canvas, &dst); } - panelBigFont->mapPalette(0, 256, 8, 8); + panelBigFont->mapPalette(0, MAX_PALETTE_COLORS, 8, 8); panelBigFont->showString("OpenJazz " OJ_VERSION, 1, canvasH - 9); panelBigFont->restorePalette(); diff --git a/src/menu/menu.h b/src/menu/menu.h index 702a1920..129b9e80 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -56,8 +56,8 @@ class GameMenu : public Menu { private: SDL_Surface* episodeScreens[11]; ///< Episode images SDL_Surface* difficultyScreen; ///< 4 difficulty images - SDL_Color palette[256]; ///< Episode selection palette - SDL_Color greyPalette[256]; ///< Greyed-out episode selection palette + SDL_Color palette[MAX_PALETTE_COLORS]; ///< Episode selection palette + SDL_Color greyPalette[MAX_PALETTE_COLORS]; ///< Greyed-out episode selection palette int episodes; ///< Number of episodes unsigned char difficulty; ///< Difficulty setting (0 = easy, 1 = medium, 2 = hard, 3 = turbo (hard in JJ2 levels)) @@ -104,7 +104,7 @@ class MainMenu : public Menu { SDL_Surface* highlight; ///< Menu image with highlighted text SDL_Surface* logo; ///< OJ logo image GameMenu* gameMenu; ///< New game menu - SDL_Color palette[256]; ///< Menu palette + SDL_Color palette[MAX_PALETTE_COLORS]; ///< Menu palette MainMenu(const MainMenu&); // non construction-copyable MainMenu& operator=(const MainMenu&); // non copyable @@ -122,7 +122,7 @@ class MainMenu : public Menu { // Variables -EXTERN SDL_Color menuPalette[256]; /// Palette used by most menu screens +EXTERN SDL_Color menuPalette[MAX_PALETTE_COLORS]; /// Palette used by most menu screens #endif diff --git a/src/setup.cpp b/src/setup.cpp index 50e1a121..85b6f322 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -132,7 +132,7 @@ SetupOptions Setup::load () { // Read controls for (int i = 0; i < CONTROLS - 4; i++) - controls.setKey(i, (SDLKey)(file->loadInt())); + controls.setKey(i, file->loadInt()); for (int i = 0; i < CONTROLS; i++) controls.setButton(i, file->loadInt());