diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2d6af8a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,77 @@ +cmake_minimum_required(VERSION 3.20) + +project( + davegnukem + LANGUAGES CXX + VERSION 1.0.3) + +set(CMAKE_CXX_STANDARD 14) + +include(GNUInstallDirs) +include(FetchContent) + +# default to same version for data repo +set(DATA_TAG + ${PROJECT_VERSION} + CACHE STRING "default") + +FetchContent_Declare( + data + GIT_REPOSITORY https://github.com/davidjoffe/gnukem_data + GIT_TAG ${DATA_TAG}) + +# default to same version for datasrc repo +set(DATASRC_TAG + ${PROJECT_VERSION} + CACHE STRING "default") + +FetchContent_Declare( + datasrc + GIT_REPOSITORY https://github.com/davidjoffe/gnukem_datasrc + GIT_TAG ${DATASRC_TAG}) + +FetchContent_MakeAvailable(data datasrc) + +add_subdirectory(src) + +install(FILES debian/appstream/com.djoffe.davegnukem.metainfo.xml + DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo) +install(FILES debian/desktop/davegnukem.desktop + DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) +install(DIRECTORY debian/icons DESTINATION ${CMAKE_INSTALL_DATADIR}) +install(FILES HISTORY.txt README.md DESTINATION ${CMAKE_INSTALL_DOCDIR}) + +install(DIRECTORY locale DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}) + +install( + DIRECTORY ${data_SOURCE_DIR}/ + DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} + PATTERN .git EXCLUDE + PATTERN .gitignore EXCLUDE + PATTERN README.md EXCLUDE PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ + WORLD_READ) +install(FILES ${data_SOURCE_DIR}/README.md + DESTINATION ${CMAKE_INSTALL_DOCDIR}-data) + +install( + DIRECTORY ${datasrc_SOURCE_DIR}/ + DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} + PATTERN .git EXCLUDE + PATTERN .gitignore EXCLUDE + PATTERN README.md EXCLUDE + PATTERN "*.psd" EXCLUDE) +install(FILES ${datasrc_SOURCE_DIR}/README.md + DESTINATION ${CMAKE_INSTALL_DOCDIR}-datasrc) + +file(READ debian/davegnukem.6 TEXT) +string(REPLACE "VERSION" "${PROJECT_VERSION}" TEXT "${TEXT}") +file( + GENERATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/davegnukem.6 + CONTENT "${TEXT}") +set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS main.cpp) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/davegnukem.6 + DESTINATION ${CMAKE_INSTALL_MANDIR}/man6) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..7c459f3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,24 @@ +file(GLOB_RECURSE HEADERS "*.h") +file(GLOB SOURCES "*.cpp") +file(GLOB SOURCES_LOC "localization/*.cpp") +file(GLOB SOURCES_SDL "sdl/*.cpp") + +if(WIN32) + file(GLOB SOURCES_WIN "win32/*.cpp") + list(APPEND SOURCES ${SOURCES_WIN}) +endif() + +find_package(SDL3 REQUIRED) +find_package(SDL3_ttf REQUIRED) +find_package(SDL3_image REQUIRED) +find_package(SDL3_mixer REQUIRED) + +add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE + ${HEADERS} ${SOURCES} ${SOURCES_LOC} ${SOURCES_SDL}) +target_compile_definitions( + ${PROJECT_NAME} + PRIVATE DATA_DIR="${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}") +target_link_libraries( + ${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf SDL3_image::SDL3_image + SDL3_mixer::SDL3_mixer) +install(TARGETS ${PROJECT_NAME}) diff --git a/src/config.h b/src/config.h index a266092..4102111 100644 --- a/src/config.h +++ b/src/config.h @@ -140,7 +140,7 @@ extern bool g_bBigViewportMode;//dj2019-06. //Can't have both bigviewport and la /*--------------------------------------------------------------------------*/ // Enable Unicode support [BETA] dj2022-11 (EARLY DEV - NOT ready for production do NOT yet enable in a real release - dj2022-11) #ifndef djUNICODE_SUPPORT -//#define djUNICODE_SUPPORT +#define djUNICODE_SUPPORT #endif #ifdef djUNICODE_SUPPORT #define djUNICODE_TTF @@ -153,7 +153,7 @@ extern bool g_bBigViewportMode;//dj2019-06. //Can't have both bigviewport and la /*--------------------------------------------------------------------------*/ // [dj2023-02] Tentative new libpng support (not yet enabled by default as it's not yet used in the actual Dave Gnukem currently, at least yet - but since we updated to SDL2 this now becomes an easier possibility to use SDL2 png loading) -//#define djUSE_SDLIMAGE +#define djUSE_SDLIMAGE /*--------------------------------------------------------------------------*/ diff --git a/src/djfonts.cpp b/src/djfonts.cpp index 903cc18..e4aaf5d 100644 --- a/src/djfonts.cpp +++ b/src/djfonts.cpp @@ -10,12 +10,6 @@ #ifdef djUNICODE_TTF // /#include "datadir.h"//Don't actually want just for font rasterize? -// hm to move obcviously not meant to be in hiscores -#if defined(WIN32) && defined(_MSC_VER) -// Microsoft compiler stuff .. hmm not sure where best .. unless cmake etc. -#pragma comment(lib, "SDL2_ttf.lib") -#endif - /*--------------------------------------------------------------------------*/ // djFontList /*--------------------------------------------------------------------------*/ @@ -170,11 +164,7 @@ TTF_Font* djUnicodeFontHelpers::FindBestMatchingFontMostCharsStr(const djFontLis // [dj2022-11] Hmm SDL documentation says "This is the same as TTF_GlyphIsProvided(), but takes a 32-bit character instead of 16-bit, and thus can query a larger range. If you are sure you'll have an SDL_ttf that's version 2.0.18 or newer, there's no reason not to use this function exclusively." // That means we may have a problem here supporting specifically (just) the Unicode SURROGATE PAIRS range IF (and only if) a platform has SDL older than this .. is that worth worrying about? [seems low prio to me dj2022-11 .. a few days ago we had no Unicode support at all so full Unicode support on 2.0.18+ and everything but surrogate pairs on older SDL's seems OK] // We *definitely* want to use the 32-bit version when and where available as otherwise SURROGATE PAIRS won't work. -#if SDL_VERSION_ATLEAST(2, 0, 18) - if (c > 0 && TTF_GlyphIsProvided32(pFont, c)) -#else - if (c > 0 && TTF_GlyphIsProvided(pFont, c)) -#endif + if (c > 0 && TTF_FontHasGlyph(pFont, c)) { ++nMatches; if (nMatches > nMatchesMost) @@ -258,13 +248,14 @@ void djRasterizeTTFFontHelper(const std::string& sFilename, int nCharW=8, int nC TTF_Font *font = TTF_OpenFont(sFilename.c_str(), FONT_SIZE); if (!font) { - printf("TTF_OpenFont: %s\n", TTF_GetError()); + printf("TTF_OpenFont: %s\n", SDL_GetError()); return; } // Create 32-bit with alpha channel printf("Create 32-bit with alpha channel\n"); - SDL_Surface *sprite_map = SDL_CreateRGBSurface(0, SPRITE_MAP_WIDTH, SPRITE_MAP_HEIGHT, 32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000); + auto format = SDL_GetPixelFormatForMasks(32, 0xFF, 0xFF00, 0xFF0000, 0xFF000000); + SDL_Surface *sprite_map = SDL_CreateSurface(SPRITE_MAP_WIDTH, SPRITE_MAP_HEIGHT, format); if (!sprite_map) { printf("SDL_CreateRGBSurface: %s\n", SDL_GetError()); @@ -287,13 +278,8 @@ void djRasterizeTTFFontHelper(const std::string& sFilename, int nCharW=8, int nC // all the texture memory filled up with thousands of characters we maybe don't need for a language? // We could/should also have some sort of 'fallback rendering' system(s) in future, e.g. if we were writing some sort of massively multiplayer online game with this // then we want a system that allows people of all languages to enter text and chat and see the text. -#if SDL_VERSION_ATLEAST(2, 0, 18) - if (!TTF_GlyphIsProvided32(font, i)) + if (!TTF_FontHasGlyph(font, i)) continue; -#else - if (!TTF_GlyphIsProvided(font, i)) - continue; -#endif utf8_len = 0; utf8_buf[0] = 0; @@ -303,10 +289,10 @@ void djRasterizeTTFFontHelper(const std::string& sFilename, int nCharW=8, int nC if (utf8_len == 0) continue; - SDL_Surface *character = TTF_RenderUTF8_Solid(font, utf8_buf, color); + SDL_Surface *character = TTF_RenderText_Solid(font, utf8_buf, utf8_len, color); if (!character) { - printf("TTF_RenderUTF8_Solid: %s\n", TTF_GetError()); + printf("TTF_RenderUTF8_Solid: %s\n", SDL_GetError()); // return; } if (character) @@ -333,7 +319,7 @@ void djRasterizeTTFFontHelper(const std::string& sFilename, int nCharW=8, int nC } //*/ - SDL_FreeSurface(character); + SDL_DestroySurface(character); } } @@ -343,7 +329,7 @@ void djRasterizeTTFFontHelper(const std::string& sFilename, int nCharW=8, int nC SDL_SaveBMP(sprite_map, (sFilename + "-raster.bmp").c_str()); // Can use e.g. imagemagick + optipng on the generated .bmp to convert to .png and compress - SDL_FreeSurface(sprite_map); + SDL_DestroySurface(sprite_map); TTF_CloseFont(font); } /* diff --git a/src/djfonts.h b/src/djfonts.h index e4a5f17..d1a7fde 100644 --- a/src/djfonts.h +++ b/src/djfonts.h @@ -14,11 +14,7 @@ // forward? keep definition for .cpp backend? //struct TTF_Font; -#ifdef __OS2__ -#include -#else -#include -#endif +#include diff --git a/src/djgraph.h b/src/djgraph.h index 79fe4ed..dca8706 100644 --- a/src/djgraph.h +++ b/src/djgraph.h @@ -27,7 +27,7 @@ Copyright (C) 1998-2024 David Joffe // [todo tidy this all up and simplify and maybe add a small simple light wrapper helper .h (or more than one) to help with this stuff] // Want to try be slightly smarter with __has_include (but it's C++17 only) so don't want to uncomment these things yet until I've tested it better so leaving it commented for now // All our includes are done like "SDL.h" and I've seen samples online that do it but it seems wrong because "" means check current directory first, which is davegnukem which obviously does not have SDL.h so shouldn't these all be etc.? I think if we're on C++7 or higher it's a good idea to maybe try detect and do fallbacks etc. -#include "SDL.h" +#include //#endif #endif @@ -72,7 +72,7 @@ class djVisual width = 0; height = 0; stride = 0; - bpp = 0; + format = SDL_PIXELFORMAT_ABGR8888; pixwidth = 0; m_bFullscreen = false; } @@ -85,7 +85,7 @@ class djVisual int width; int height; int stride; - int bpp; // 32 ... 24? (pixsize) pixdepth=24, pixsize=32 width=4 + SDL_PixelFormat format; // 32 ... 24? (pixsize) pixdepth=24, pixsize=32 width=4 int pixwidth; // 4 bool m_bFullscreen; }; diff --git a/src/djimage.cpp b/src/djimage.cpp index 768c05e..19f0d2b 100644 --- a/src/djimage.cpp +++ b/src/djimage.cpp @@ -16,11 +16,8 @@ dj2022-11 Note that since we're now on SDL2 we could potentially use e.g. SDLima #include "djgraph.h" #include "sys_error.h" #include - #ifdef __OS2__ - #include - #else - #include - #endif +#include + /*--------------------------------------------------------------------------*/ // TGA types enum EfdTGAType @@ -252,12 +249,12 @@ int djImage::Load( const char * szFilename ) if (szFilename == NULL) return -1; // NULL string if (szFilename[0] == 0) return -1; // empty string - std::string filename = szFilename; - std::string extension = filename.substr(filename.find_last_of(".") + 1); + std::string filename = szFilename; + std::string extension = filename.substr(filename.find_last_of(".") + 1); extern void djStrToLowerTmpHelper( std::string& s ); - djStrToLowerTmpHelper(extension); + djStrToLowerTmpHelper(extension); - // For TGA files pass to our own old TGA loader + // For TGA files pass to our own old TGA loader if (extension == "tga") { // fixme why are we bothering with all this? we only load TGA diff --git a/src/djimageload.cpp b/src/djimageload.cpp index 9fcab63..5db8d26 100644 --- a/src/djimageload.cpp +++ b/src/djimageload.cpp @@ -6,18 +6,15 @@ Copyright (C) 1998-2024 David Joffe */ /*--------------------------------------------------------------------------*/ +#include "djimageload.h" #include "config.h" #include "djimage.h" -#include "djimageload.h" +#include #include -#ifdef __OS2__ -#include -#else -#include -#endif + #ifdef djUSE_SDLIMAGE // Hm not 100% sure if we should best put here 'SDL2/SDL_image.h' or just 'SDL_image.h' and let makefiles etc. pass the folder in .. -#include +#include #endif //----------------------------------------- @@ -213,21 +210,22 @@ int djImageLoad::LoadImage(djImage* pImg, const char *szFilename) return -1; } // if small endian am i supposed to reverse the masks here? not sure .. - printf("CreateImage:%d %d %d pitch=%d rgba %08x %08x %08x %08x\n", (int)surface->w, (int)surface->h, (int)surface->format->BitsPerPixel, (int)surface->pitch, - (int)surface->format->Rmask, - (int)surface->format->Gmask, - (int)surface->format->Bmask, - (int)surface->format->Amask); - pImg->CreateImage(surface->w, surface->h, surface->format->BitsPerPixel, surface->pitch, surface->pixels, - surface->format->Rmask, - surface->format->Gmask, - surface->format->Bmask, - surface->format->Amask + auto f = SDL_GetPixelFormatDetails(surface->format); + printf("CreateImage:%d %d %d pitch=%d rgba %08x %08x %08x %08x\n", (int)surface->w, (int)surface->h, (int)f->bits_per_pixel, (int)surface->pitch, + (int)f->Rmask, + (int)f->Gmask, + (int)f->Bmask, + (int)f->Amask); + pImg->CreateImage(surface->w, surface->h, f->bits_per_pixel, surface->pitch, surface->pixels, + f->Rmask, + f->Gmask, + f->Bmask, + f->Amask ); printf("CreateImage:DONE\n"); // Clean up - SDL_FreeSurface(surface); + SDL_DestroySurface(surface); return 0; #else return -1;//unhandled format diff --git a/src/djinput.h b/src/djinput.h index 270cb7c..9219562 100644 --- a/src/djinput.h +++ b/src/djinput.h @@ -9,11 +9,7 @@ #ifndef _DJINPUT_H_ #define _DJINPUT_H_ /*--------------------------------------------------------------------------*/ -#ifdef __OS2__ -#include -#else -#include -#endif +#include #define DJKEY_MAX 256 extern int g_iKeys[DJKEY_MAX]; diff --git a/src/ed_common.cpp b/src/ed_common.cpp index 020941e..48cca75 100644 --- a/src/ed_common.cpp +++ b/src/ed_common.cpp @@ -39,11 +39,10 @@ static djImage *g_pEdFont = NULL; void ED_CommonInit () { - SDL_FreeSurface(pVisMain->pSurface); + SDL_DestroySurface(pVisMain->pSurface); SDL_DestroyTexture(pVisMain->pTexture); - SDL_RenderSetLogicalSize(pVisMain->pRenderer, pVisMain->width, pVisMain->height); - pVisMain->pSurface = SDL_CreateRGBSurface(0, pVisMain->width, pVisMain->height, pVisMain->bpp, - 0, 0, 0, 0); + SDL_SetRenderLogicalPresentation(pVisMain->pRenderer, pVisMain->width, pVisMain->height, SDL_LOGICAL_PRESENTATION_STRETCH); + pVisMain->pSurface = SDL_CreateSurface(pVisMain->width, pVisMain->height, pVisMain->pSurface->format); pVisMain->pTexture = SDL_CreateTextureFromSurface(pVisMain->pRenderer, pVisMain->pSurface); // rtfb: @@ -51,7 +50,8 @@ void ED_CommonInit () // but when i first tried to put my hands on Editor, // this was my main headache. In short, sprites just // *won't* display correctly if this is not set. - pVisMain->stride = pVisMain->width * (pVisMain->bpp/8); + auto f = SDL_GetPixelFormatDetails(pVisMain->format); + pVisMain->stride = pVisMain->width * (f->bytes_per_pixel); // pVisMain->stride = 640*2; if (!LoadMacros()) @@ -61,7 +61,7 @@ void ED_CommonInit () g_pEdFont->Load( djDATAPATHc( "simplefont.tga" )); djCreateImageHWSurface(g_pEdFont); - SDL_ShowCursor ( 1 ); + SDL_ShowCursor (); djiInit(); } @@ -69,7 +69,7 @@ void ED_CommonInit () void ED_CommonKill () { djiInit(); - SDL_ShowCursor(0); + SDL_HideCursor(); djDestroyImageHWSurface(g_pEdFont); if (g_pEdFont) { @@ -79,11 +79,10 @@ void ED_CommonKill () DeleteMacros (); djiClearBuffer (); - SDL_FreeSurface(pVisMain->pSurface); + SDL_DestroySurface(pVisMain->pSurface); SDL_DestroyTexture(pVisMain->pTexture); - SDL_RenderSetLogicalSize(pVisMain->pRenderer, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H); - pVisMain->pSurface = SDL_CreateRGBSurface(0, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, pVisMain->bpp, - 0, 0, 0, 0); + SDL_SetRenderLogicalPresentation(pVisMain->pRenderer, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, SDL_LOGICAL_PRESENTATION_STRETCH); + pVisMain->pSurface = SDL_CreateSurface(CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, pVisMain->format); pVisMain->pTexture = SDL_CreateTextureFromSurface(pVisMain->pRenderer, pVisMain->pSurface); } diff --git a/src/ed_spred.cpp b/src/ed_spred.cpp index ffc07f2..030315a 100644 --- a/src/ed_spred.cpp +++ b/src/ed_spred.cpp @@ -18,13 +18,8 @@ #include "block.h" #include "sys_error.h" -#include // sprintf (NB don't use sprintf anymore, use sprintfs etc.!) -#ifdef __OS2__ -#include //dj2022-11 for SDL_Delay (which may change eg cf. emscripten issues) .. -#else -#include //dj2022-11 for SDL_Delay (which may change eg cf. emscripten issues) .. -#endif - +#include //dj2022-11 for SDL_Delay (which may change eg cf. emscripten issues) .. +#include // sprintf (NB don't use sprintf anymore, use sprintfs etc.!) #define POS_FLAGS ((POS_SPRITES_Y + 8 * 16) + 8) #define POS_INSTRUCTIONS_X 420 diff --git a/src/game.cpp b/src/game.cpp index 3b58b7f..ff7da42 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1359,10 +1359,10 @@ int game_startup(bool bLoadGame) { switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: for ( i=0; i' keys) [dj2017-06-24] - if ( (Event.key.keysym.mod & KMOD_LSHIFT)!=0 || - (Event.key.keysym.mod & KMOD_RSHIFT)!=0) + if ( (Event.key.mod & SDL_KMOD_LSHIFT)!=0 || + (Event.key.mod & SDL_KMOD_RSHIFT)!=0) { // Ctrl+Shift? - if ( (Event.key.keysym.mod & KMOD_LCTRL)!=0 || - (Event.key.keysym.mod & KMOD_RCTRL)!=0) + if ( (Event.key.mod & SDL_KMOD_LCTRL)!=0 || + (Event.key.mod & SDL_KMOD_RCTRL)!=0) { // Ctrl+Shift+G: Enable debug commands (e.g. H for health self-damage etc.) - if (Event.key.keysym.sym==SDLK_g) + if (Event.key.key==SDLK_G) { g_bEnableDebugStuff = true; ShowGameMessage("DebugStuff Enabled", 64); } #ifdef djINGAME_FULLSCREEN_TOGGLE//dj2022-11 //dj2022 do we really need to waste yet another key shortcut etc. just for live fullscreen toggle we can do from the ingame menu? what if porters using 'f' and its causing conflict? -/* else if (Event.key.keysym.sym == SDLK_f) +/* else if (Event.key.key == SDLK_f) { //dj2022-11 experimental toggle fullscreen probably going to crash a lot djGraphicsSystem::ToggleFullscreen(); @@ -1404,7 +1404,7 @@ int game_startup(bool bLoadGame) }*/ #endif//djINGAME_FULLSCREEN_TOGGLE #ifdef DAVEGNUKEM_CHEATS_ENABLED - else if (Event.key.keysym.sym==SDLK_w) + else if (Event.key.key==SDLK_W) { // For now regard large-viewport-mode as a cheat but think about it [dj2017-08] if (g_bEnableDebugStuff) @@ -1421,10 +1421,10 @@ int game_startup(bool bLoadGame) { /*{ char buf[1024]={0}; - snprintf(buf,sizeof(buf),"%08x,%08x,%08x",(int)Event.key.keysym.sym, (int)Event.key.keysym.mod, (int)Event.key.keysym.scancode); + snprintf(buf,sizeof(buf),"%08x,%08x,%08x",(int)Event.key.key, (int)Event.key.mod, (int)Event.key.keysym.scancode); ShowGameMessage(buf, 32); }*/ - if (Event.key.keysym.sym==SDLK_F6) + if (Event.key.key==SDLK_F6) { //ShowEndGameSequence(); //RedrawEverythingHelper(); @@ -1437,7 +1437,7 @@ int game_startup(bool bLoadGame) snprintf(buf,sizeof(buf),"Dec framerate %.2f",g_fFrameRate); ShowGameMessage(buf, 32); } - else if (Event.key.keysym.sym==SDLK_F7) + else if (Event.key.key==SDLK_F7) { g_fFrameRate += 1.0f; fTIMEFRAME = (1.0f / g_fFrameRate); @@ -1445,11 +1445,11 @@ int game_startup(bool bLoadGame) snprintf(buf,sizeof(buf),"Inc framerate %.2f",g_fFrameRate); ShowGameMessage(buf, 32); } - else if (Event.key.keysym.sym==SDLK_F8) + else if (Event.key.key==SDLK_F8) { g_bAutoShadows = !g_bAutoShadows; } - else if (Event.key.keysym.sym==SDLK_F9) + else if (Event.key.key==SDLK_F9) { g_bSpriteDropShadows = !g_bSpriteDropShadows; } @@ -1459,14 +1459,14 @@ int game_startup(bool bLoadGame) // F10? Screenshot and auto-screenshot stuff - if (Event.key.keysym.sym==SDLK_F10) + if (Event.key.key==SDLK_F10) { // Ctrl+Shift+F10? Start/stop screenshot recording [dj2018-04-01] - if (((Event.key.keysym.mod & KMOD_LSHIFT)!=0 || - (Event.key.keysym.mod & KMOD_RSHIFT)!=0)/* + if (((Event.key.mod & SDL_KMOD_LSHIFT)!=0 || + (Event.key.mod & SDL_KMOD_RSHIFT)!=0)/* && - ((Event.key.keysym.mod & KMOD_LCTRL)!=0 || - (Event.key.keysym.mod & KMOD_RCTRL)!=0)*/) + ((Event.key.mod & SDL_KMOD_LCTRL)!=0 || + (Event.key.mod & SDL_KMOD_RCTRL)!=0)*/) { if (!g_sAutoScreenshotFolder.empty()) { @@ -1521,7 +1521,7 @@ int game_startup(bool bLoadGame) // [dj2017-06] DEBUG/CHEAT/DEV KEYS /* - if (Event.key.keysym.sym==SDLK_F8) + if (Event.key.key==SDLK_F8) { g_bSmoothVerticalMovementTest = !g_bSmoothVerticalMovementTest; y_offset = 0; @@ -1540,17 +1540,17 @@ int game_startup(bool bLoadGame) { // Get localized string for "Volume" const std::string sVolume = pgettext("sound", "Volume"); - if (Event.key.keysym.sym==SDLK_7)//SDLK_PAGEUP) + if (Event.key.key==SDLK_7)//SDLK_PAGEUP) { djSoundAdjustVolume(4); djConsoleMessage::SetConsoleMessage(sVolume + ": " + std::to_string(static_cast((100.f * (static_cast(djSoundGetVolume()) / 128.f))))); } - else if (Event.key.keysym.sym==SDLK_6)//SDLK_PAGEDOWN) + else if (Event.key.key==SDLK_6)//SDLK_PAGEDOWN) { djSoundAdjustVolume(-4); djConsoleMessage::SetConsoleMessage(sVolume + ": " + std::to_string(static_cast((100.f * (static_cast(djSoundGetVolume()) / 128.f))))); } - else if (Event.key.keysym.sym==SDLK_INSERT) + else if (Event.key.key==SDLK_INSERT) { if (djSoundEnabled()) djSoundDisable(); @@ -1560,10 +1560,10 @@ int game_startup(bool bLoadGame) } } break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: for ( i=0; ipSurface, &rect, SDL_MapRGB(pVisView->pSurface->format, 0, 0, 0)); + auto f = SDL_GetPixelFormatDetails(pVisView->pSurface->format); + SDL_FillSurfaceRect(pVisView->pSurface, &rect, SDL_MapRGB(f, nullptr, 0, 0, 0)); //djgClear(pVisView); } diff --git a/src/gameending.cpp b/src/gameending.cpp index dd053b2..9278f41 100644 --- a/src/gameending.cpp +++ b/src/gameending.cpp @@ -144,23 +144,23 @@ void ShowEndGameSequence() { switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: if ( - (Event.key.keysym.sym==SDLK_SPACE - || Event.key.keysym.sym==SDLK_RETURN) + (Event.key.key==SDLK_SPACE + || Event.key.key==SDLK_RETURN) ) { bRunning = false; } - else if (Event.key.keysym.sym==SDLK_ESCAPE - || Event.key.keysym.sym==SDLK_SPACE - || Event.key.keysym.sym==SDLK_RETURN + else if (Event.key.key==SDLK_ESCAPE + || Event.key.key==SDLK_SPACE + || Event.key.key==SDLK_RETURN ) { bRunning = false;//Exit screen } break; - case SDL_QUIT: + case SDL_EVENT_QUIT: bRunning=false; break; } diff --git a/src/graph.cpp b/src/graph.cpp index 220d43f..aa0762e 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -13,28 +13,21 @@ Copyright (C) 1998-2024 David Joffe #ifdef WIN32 #include //for workaround #endif +#include #include #include -#include #include -#ifdef __OS2__ -#include -#else -#include "SDL.h" -#endif +#include #ifdef djUNICODE_TTF -#ifdef __OS2__ - #include //TTF_Init -#else// !__OS2__ - #include //TTF_Init -#endif// __OS2__ +#include //TTF_Init + #include "djfonts.h" #include "datadir.h"//LoadFont #endif//#ifdef djUNICODE_TTF #ifdef djUSE_SDLIMAGE//d2023-02 -#include +#include #endif #include "console.h"//dj2022-11 refactoring @@ -116,11 +109,7 @@ void GraphFlip(bool bScaleView) // leaving text looking messed up [dj2016-10] if (pVisBack!=NULL && g_pFont8x8!=NULL && (!djConsoleMessage::m_sMsg.empty() || bShowFrameRate)) { - pVisTemp = SDL_CreateRGBSurface(0, CFG_APPLICATION_RENDER_RES_W, 8, pVisBack->pSurface->format->BitsPerPixel, - pVisBack->pSurface->format->Rmask, - pVisBack->pSurface->format->Gmask, - pVisBack->pSurface->format->Bmask, - 0); + pVisTemp = SDL_CreateSurface(CFG_APPLICATION_RENDER_RES_W, 8, pVisBack->pSurface->format); if (pVisTemp) { SDL_Rect Rect; @@ -174,7 +163,7 @@ void GraphFlip(bool bScaleView) SDL_BlitSurface(pVisTemp, &Rect, pVisBack->pSurface, &Rect); // inefficient .. do this once not every frame .. - SDL_FreeSurface(pVisTemp); + SDL_DestroySurface(pVisTemp); } } @@ -204,12 +193,6 @@ bool djSDLInit() // Initialize graphics library SDL_Init(SDL_INIT_VIDEO); -#ifdef djUSE_SDLIMAGE//dj2023-02 - // Initialize SDL_image for PNG loading - const int nImgFlags = IMG_INIT_PNG|IMG_INIT_JPG; - /*int nRet = */IMG_Init(nImgFlags/*|IMG_INIT_TIF*/); -#endif - #ifdef djUNICODE_TTF TTF_Init();//dj2022-11 #endif @@ -221,10 +204,6 @@ bool djSDLDone() TTF_Quit();//dj2022-11 #endif -#ifdef djUSE_SDLIMAGE - IMG_Quit(); -#endif - SDL_Quit(); return true; } @@ -259,15 +238,14 @@ bool djGraphicsSystem::GraphInit( bool bFullScreen, int iWidth, int iHeight, int // tries to set a 'true' 320x200 fullscreen display mode, IIRC - dj2017-08.) // No that doesn't seem to be what happens, press F5 when running with "-f" and see. // [low/future] - if 2 monitors, will this behave 'correct' - SDL_DisplayMode dm; - int err = SDL_GetCurrentDisplayMode(0, &dm); + auto dm = SDL_GetCurrentDisplayMode(0); int max_w = -1; int max_h = -1; - if (!err) + if (dm) { // THIS MUST BE TESTED ON LINUX [dj2016-10] - max_w = dm.w; - max_h = dm.h; + max_w = dm->w; + max_h = dm->h; if (max_w>iWidth && max_h>iHeight) { int nMultiple = djMAX(1, djMIN( max_w / iWidth, max_h / iHeight ) ); @@ -288,7 +266,7 @@ bool djGraphicsSystem::GraphInit( bool bFullScreen, int iWidth, int iHeight, int // Hide mouse cursor - SDL_ShowCursor(0); + SDL_HideCursor(); std::string sIcon = djDATAPATHs("icon.bmp"); #ifdef __APPLE__ @@ -304,8 +282,10 @@ bool djGraphicsSystem::GraphInit( bool bFullScreen, int iWidth, int iHeight, int printf( "GraphInit(): COULDN'T CREATE MAIN WINDOW\n" ); return false; } - djLog::LogFormatStr( "GraphInit(): Display bytes per pixel %d\n", (int)pVisMain->bpp) ; - int imode = pVisMain->bpp; + + auto f = SDL_GetPixelFormatDetails(pVisMain->format); + djLog::LogFormatStr( "GraphInit(): Display bytes per pixel %d\n", (int)f->bits_per_pixel) ; + int imode = f->bits_per_pixel; // Set the 32<->16 pixel conversion atributes, so the // images would be displayed correctly with any pixel format @@ -542,7 +522,7 @@ void DrawStringUnicodeHelper(djVisual* pVis, int x, int y, SDL_Color Color, cons //SDL_Surface* sur = TTF_RenderUNICODE_Blended_Wrapped(pFont, (const Uint16*)text.c_str(), SDL_Color{ 255, 255, 255, 255 }, CFG_APPLICATION_RENDER_RES_W - nXPOS); //SDL_Surface* sur = TTF_RenderUNICODE_Blended(pFont, (const Uint16*)text.c_str(), SDL_Color{ 255, 255, 255, 255 }, CFG_APPLICATION_RENDER_RES_W - nXPOS); //SDL_Surface* sur = TTF_RenderUTF8_Blended(pFont, sText.c_str(), SDL_Color{ 0, 0, 0, 255 });//black for +1 offset underline 'shadow' effect - SDL_Surface* sur = TTF_RenderUTF8_Solid(pFont, szTextUTF8, SDL_Color{ 0, 0, 0, 255 });//black for +1 offset underline 'shadow' effect + SDL_Surface* sur = TTF_RenderText_Solid(pFont, szTextUTF8, uLen, SDL_Color{ 0, 0, 0, 255 });//black for +1 offset underline 'shadow' effect //SDL_Texture* tex = SDL_CreateTextureFromSurface(pVis->pRenderer, sur); if (sur) { @@ -550,11 +530,11 @@ void DrawStringUnicodeHelper(djVisual* pVis, int x, int y, SDL_Color Color, cons CdjRect rcSrc(0, 0, sur->w, sur->h); SDL_BlitSurface(sur, &rcSrc, pVis->pSurface, &rcDest);//blit [is this best way?] SDL_BlitSurface(sur, &rcSrc, pVis->pSurface, &rcDest);//blit [is this best way?] - //SDL_FreeSurface(sur);// why does this SDL_FreeSurface crash?SDL_FreeSurface(sur); [dj2022-11 fixme] + //SDL_DestroySurface(sur);// why does this SDL_DestroySurface crash?SDL_DestroySurface(sur); [dj2022-11 fixme] sur = nullptr; } //sur = TTF_RenderUTF8_Blended(pFont, sText.c_str(), SDL_Color{ 255, 255, 255, 255 }); - sur = TTF_RenderUTF8_Blended(pFont, szTextUTF8, Color); + sur = TTF_RenderText_Blended(pFont, szTextUTF8, uLen, Color); //SDL_Texture* tex = SDL_CreateTextureFromSurface(pVis->pRenderer, sur); if (sur) { @@ -563,7 +543,7 @@ void DrawStringUnicodeHelper(djVisual* pVis, int x, int y, SDL_Color Color, cons SDL_BlitSurface(sur, &rcSrc, pVis->pSurface, &rcDest);//blit [is this best way?] SDL_BlitSurface(sur, &rcSrc, pVis->pSurface, &rcDest);//blit [is this best way?] //SDL_BlitSurface(sur, &rcSrc, pVis->pSurface, &rcDest);//blit [is this best way?] - //SDL_FreeSurface(sur);// why does this SDL_FreeSurface crash?SDL_FreeSurface(sur); [dj2022-11 fixme] + //SDL_DestroySurface(sur);// why does this SDL_DestroySurface crash?SDL_DestroySurface(sur); [dj2022-11 fixme] sur = nullptr; } //SDL_RenderCopy(pVisBack->pRenderer, tex, NULL, &rect); diff --git a/src/hiscores.cpp b/src/hiscores.cpp index 05c3466..5fe8588 100644 --- a/src/hiscores.cpp +++ b/src/hiscores.cpp @@ -125,8 +125,6 @@ void ShowHighScores() GraphDrawStringUTF8(pVisBack, pImg, nXPOS, nYSTART + i * nHEIGHTPERROW, 8, 8, sText.c_str(), sText.length()); } #else - if (bNEW) - { // dj2022-11 though it's not so easy to do the same cheesey gradient we have on our 8x8 font, I grabbed the colors from that font to create a sort of a gradient anyway across the list of names that matches the visual color look .. not wonderful but not awful std::vector< SDL_Color > aColorGrad; aColorGrad.push_back(SDL_Color{ 221, 69, 69, 255 }); @@ -140,7 +138,6 @@ void ShowHighScores() aColorGrad.push_back(SDL_Color{ 233, 185, 139, 255 }); aColorGrad.push_back(SDL_Color{ 237, 217, 158, 255 }); DrawStringUnicodeHelper(pVisBack, nXPOS, nYSTART + i * nHEIGHTPERROW - 6, aColorGrad[i % aColorGrad.size()], sText.c_str(), sText.length()); - } #endif//#ifndef djUNICODE_TTF }//i diff --git a/src/instructions.cpp b/src/instructions.cpp index bb95e97..2546d45 100644 --- a/src/instructions.cpp +++ b/src/instructions.cpp @@ -284,17 +284,17 @@ void DoShow(const std::string& sLinesOrigText, const std::vector& a { switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: if (!bTypingFinished && - (Event.key.keysym.sym==SDLK_SPACE - || Event.key.keysym.sym==SDLK_RETURN) + (Event.key.key==SDLK_SPACE + || Event.key.key==SDLK_RETURN) ) { bFinishTyping = true;//Insta-finish typing } - else if (Event.key.keysym.sym==SDLK_ESCAPE - || Event.key.keysym.sym==SDLK_SPACE - || Event.key.keysym.sym==SDLK_RETURN + else if (Event.key.key==SDLK_ESCAPE + || Event.key.key==SDLK_SPACE + || Event.key.key==SDLK_RETURN ) { if (!bTypingFinished) @@ -303,7 +303,7 @@ void DoShow(const std::string& sLinesOrigText, const std::vector& a bRunning = false;//Exit instruction screen } break; - case SDL_QUIT: + case SDL_EVENT_QUIT: bRunning=false; break; } diff --git a/src/keys.cpp b/src/keys.cpp index 16dfcaa..054b954 100644 --- a/src/keys.cpp +++ b/src/keys.cpp @@ -8,13 +8,9 @@ Created: 09/2001 #include "keys.h" #include "settings.h" -#ifdef __OS2__ -#include -#else -#include "SDL.h" -#endif -#include +#include #include +#include // dj2022-11 [low prio] we might want to give porters more control over these default keys (some consolde platforms have needed to hardcode oddly specific things like 'j' etc. here, can't recall which right now but I saw it in a Dave Gnukem fork recently) .. // Also to think about is that a slightly rude user reported to me that these keys can interfere with default keys for some window managers like MATE etc. apparently for things like desktop switching? Or something like that @@ -105,11 +101,11 @@ void InitialiseGameKeySystem() //g_anValidGameKeys.push_back(SDLK_ESCAPE); g_anValidGameKeys.push_back(SDLK_SPACE); g_anValidGameKeys.push_back(SDLK_EXCLAIM); - g_anValidGameKeys.push_back(SDLK_QUOTEDBL); + g_anValidGameKeys.push_back(SDLK_DBLAPOSTROPHE); g_anValidGameKeys.push_back(SDLK_HASH); g_anValidGameKeys.push_back(SDLK_DOLLAR); g_anValidGameKeys.push_back(SDLK_AMPERSAND); - g_anValidGameKeys.push_back(SDLK_QUOTE); + g_anValidGameKeys.push_back(SDLK_APOSTROPHE); g_anValidGameKeys.push_back(SDLK_LEFTPAREN); g_anValidGameKeys.push_back(SDLK_RIGHTPAREN); g_anValidGameKeys.push_back(SDLK_ASTERISK); @@ -140,33 +136,33 @@ void InitialiseGameKeySystem() g_anValidGameKeys.push_back(SDLK_RIGHTBRACKET); g_anValidGameKeys.push_back(SDLK_CARET); g_anValidGameKeys.push_back(SDLK_UNDERSCORE); - g_anValidGameKeys.push_back(SDLK_BACKQUOTE); - g_anValidGameKeys.push_back(SDLK_a); - g_anValidGameKeys.push_back(SDLK_b); - g_anValidGameKeys.push_back(SDLK_c); - g_anValidGameKeys.push_back(SDLK_d); - g_anValidGameKeys.push_back(SDLK_e); - g_anValidGameKeys.push_back(SDLK_f); - g_anValidGameKeys.push_back(SDLK_g); - g_anValidGameKeys.push_back(SDLK_h); - g_anValidGameKeys.push_back(SDLK_i); - g_anValidGameKeys.push_back(SDLK_j); - g_anValidGameKeys.push_back(SDLK_k); - g_anValidGameKeys.push_back(SDLK_l); - g_anValidGameKeys.push_back(SDLK_m); - g_anValidGameKeys.push_back(SDLK_n); - g_anValidGameKeys.push_back(SDLK_o); - g_anValidGameKeys.push_back(SDLK_p); - g_anValidGameKeys.push_back(SDLK_q); - g_anValidGameKeys.push_back(SDLK_r); - g_anValidGameKeys.push_back(SDLK_s); - g_anValidGameKeys.push_back(SDLK_t); - g_anValidGameKeys.push_back(SDLK_u); - g_anValidGameKeys.push_back(SDLK_v); - g_anValidGameKeys.push_back(SDLK_w); - g_anValidGameKeys.push_back(SDLK_x); - g_anValidGameKeys.push_back(SDLK_y); - g_anValidGameKeys.push_back(SDLK_z); + g_anValidGameKeys.push_back(SDLK_GRAVE); + g_anValidGameKeys.push_back(SDLK_A); + g_anValidGameKeys.push_back(SDLK_B); + g_anValidGameKeys.push_back(SDLK_C); + g_anValidGameKeys.push_back(SDLK_D); + g_anValidGameKeys.push_back(SDLK_E); + g_anValidGameKeys.push_back(SDLK_F); + g_anValidGameKeys.push_back(SDLK_G); + g_anValidGameKeys.push_back(SDLK_H); + g_anValidGameKeys.push_back(SDLK_I); + g_anValidGameKeys.push_back(SDLK_J); + g_anValidGameKeys.push_back(SDLK_K); + g_anValidGameKeys.push_back(SDLK_L); + g_anValidGameKeys.push_back(SDLK_M); + g_anValidGameKeys.push_back(SDLK_N); + g_anValidGameKeys.push_back(SDLK_O); + g_anValidGameKeys.push_back(SDLK_P); + g_anValidGameKeys.push_back(SDLK_Q); + g_anValidGameKeys.push_back(SDLK_R); + g_anValidGameKeys.push_back(SDLK_S); + g_anValidGameKeys.push_back(SDLK_T); + g_anValidGameKeys.push_back(SDLK_U); + g_anValidGameKeys.push_back(SDLK_V); + g_anValidGameKeys.push_back(SDLK_W); + g_anValidGameKeys.push_back(SDLK_X); + g_anValidGameKeys.push_back(SDLK_Y); + g_anValidGameKeys.push_back(SDLK_Z); g_anValidGameKeys.push_back(SDLK_DELETE); g_anValidGameKeys.push_back(SDLK_KP_0); g_anValidGameKeys.push_back(SDLK_KP_1); diff --git a/src/main.cpp b/src/main.cpp index b59ad19..6ff2b2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -786,10 +786,10 @@ void RedefineKeys() { switch (Event.type) { - //case SDL_KEYDOWN: + //case SDL_EVENT_KEY_DOWN: //break; - case SDL_KEYDOWN://UP: - switch (Event.key.keysym.sym) + case SDL_EVENT_KEY_DOWN://UP: + switch (Event.key.key) { case SDLK_ESCAPE: bLoop = false; @@ -797,7 +797,7 @@ void RedefineKeys() default: if (bFinished) { - if (Event.key.keysym.sym==SDLK_RETURN) + if (Event.key.key==SDLK_RETURN) { bLoop = false; // Commit changes @@ -810,9 +810,9 @@ void RedefineKeys() StoreGameKeys(); } } - else if (IsGameKey(Event.key.keysym.sym) && !IsKeyUsed(anKeys, Event.key.keysym.sym)) + else if (IsGameKey(Event.key.key) && !IsKeyUsed(anKeys, Event.key.key)) { - anKeys[nCurrent] = Event.key.keysym.sym; + anKeys[nCurrent] = Event.key.key; nCurrent++; if (nCurrent==KEY_NUM_MAIN_REDEFINABLE_KEYS) { @@ -822,7 +822,7 @@ void RedefineKeys() break; } break; - case SDL_QUIT: + case SDL_EVENT_QUIT: bLoop = false; break; } @@ -891,6 +891,9 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel #ifdef djALLOW_UNICODE_TEXT_ENTRY //SDL_EnableUNICODE(1); + auto window = SDL_GL_GetCurrentWindow(); + if (window) + SDL_StartTextInput(window); #endif std::string sInput; @@ -917,15 +920,15 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel switch (Event.type) { #ifdef djALLOW_UNICODE_TEXT_ENTRY - case SDL_TEXTINPUT://dj2022-11 NB for Unicode input (what platforms are supported here?) + case SDL_EVENT_TEXT_INPUT://dj2022-11 NB for Unicode input (what platforms are supported here?) sInput += Event.text.text; break; - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: { - if (((ModState & KMOD_SHIFT)==0) && ((ModState & KMOD_CTRL)!=0)) + if (((ModState & SDL_KMOD_SHIFT)==0) && ((ModState & SDL_KMOD_CTRL)!=0)) { // Ctrl+V paste text? - if (Event.key.keysym.sym == SDLK_v && SDL_HasClipboardText()) + if (Event.key.key == SDLK_B && SDL_HasClipboardText()) { char* sz = SDL_GetClipboardText(); if (sz) @@ -946,7 +949,7 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel } - switch (Event.key.keysym.sym) + switch (Event.key.key) { case SDLK_BACKSPACE: // Backspace is slightly non-trivial to handle if we're dealing with utf8 strings but technically we can probably use if (!sInput.empty()) @@ -982,23 +985,23 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel } break; #else - case SDL_KEYDOWN: - if (Event.key.keysym.sym>=SDLK_a && Event.key.keysym.sym<=SDLK_z) + case SDL_EVENT_KEY_DOWN: + if (Event.key.key>=SDLK_a && Event.key.key<=SDLK_z) { // I'm assuming these constants are linearly increasing, hopefully they are - AppendCharacter(sInput, ((char)Event.key.keysym.sym - SDLK_a) + ((ModState & KMOD_SHIFT) ? 'A' : 'a'), nMaxLen); + AppendCharacter(sInput, ((char)Event.key.key - SDLK_a) + ((ModState & SDL_KMOD_SHIFT) ? 'A' : 'a'), nMaxLen); } - else if (Event.key.keysym.sym>=SDLK_0 && Event.key.keysym.sym<=SDLK_9) + else if (Event.key.key>=SDLK_0 && Event.key.key<=SDLK_9) { const char* acShifted = ")!@#$%^&*("; - if (ModState & KMOD_SHIFT) - AppendCharacter(sInput, acShifted[(char)Event.key.keysym.sym - SDLK_0], nMaxLen); + if (ModState & SDL_KMOD_SHIFT) + AppendCharacter(sInput, acShifted[(char)Event.key.key - SDLK_0], nMaxLen); else - AppendCharacter(sInput, ((char)Event.key.keysym.sym - SDLK_0) + '0', nMaxLen); + AppendCharacter(sInput, ((char)Event.key.key - SDLK_0) + '0', nMaxLen); } else { - switch (Event.key.keysym.sym) + switch (Event.key.key) { case SDLK_SPACE: AppendCharacter(sInput, ' ', nMaxLen); break; case SDLK_PLUS: AppendCharacter(sInput, '+', nMaxLen); break; @@ -1015,7 +1018,7 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel } } break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: break; #endif } @@ -1055,12 +1058,14 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel #else #ifdef djALLOW_UNICODE_TEXT_ENTRY extern djSprite* g_pFont2; - djImage* pImg = g_pFont2->GetImage(); - std::string sText = sInput; - if ((SDL_GetTicks() % 700) < 400) // Draw flashing cursor - sText += "|";//<- simple 'fake cursor' (vertical bar/pipe character) - GraphDrawStringUTF8( pVisBack, pImg, nXLeft - 2, 104, 8, 8, sText.c_str(), sText.length() ); - //DrawStringUnicodeHelper(pVisBack, nXLeft - 2, 104, SDL_Color{ 255, 255, 255, 255 }, sText.c_str(), sText.length()); + if (g_pFont2 && g_pFont2->IsLoaded()) { + djImage* pImg = g_pFont2->GetImage(); + std::string sText = sInput; + if ((SDL_GetTicks() % 700) < 400) // Draw flashing cursor + sText += "|";//<- simple 'fake cursor' (vertical bar/pipe character) + GraphDrawStringUTF8( pVisBack, pImg, nXLeft - 2, 104, 8, 8, sText.c_str(), sText.length() ); + //DrawStringUnicodeHelper(pVisBack, nXLeft - 2, 104, SDL_Color{ 255, 255, 255, 255 }, sText.c_str(), sText.length()); + } #else//ASCII: GraphDrawString( pVisBack, g_pFont8x8, nXLeft-2, 104, (unsigned char*)sInput.c_str() ); if ((SDL_GetTicks() % 700) < 400) // Draw flashing cursor @@ -1086,6 +1091,8 @@ bool djGetTextInput(std::string& sReturnString, int nMaxLen, unsigned int uPixel sReturnString = sInput; #ifdef djALLOW_UNICODE_TEXT_ENTRY //SDL_EnableUNICODE(0); + if (window) + SDL_StartTextInput(window); #endif return bRet; diff --git a/src/menu.cpp b/src/menu.cpp index d2ce289..c37a5c8 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -112,24 +112,24 @@ void do_menu_pump() { switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: // 'Global' shortcut keys for adjusting volume [dj2016-10] // Get localized string for "Volume" const std::string sVolume = pgettext("sound", "Volume"); - if (Event.key.keysym.sym==SDLK_7)//SDLK_PAGEUP) + if (Event.key.key==SDLK_7)//SDLK_PAGEUP) { djSoundAdjustVolume(4); SetConsoleMessage(sVolume + ": " + std::to_string(static_cast(100.f * (static_cast(djSoundGetVolume()) / 128.f)))); } - else if (Event.key.keysym.sym==SDLK_6)//SDLK_PAGEDOWN) + else if (Event.key.key==SDLK_6)//SDLK_PAGEDOWN) { djSoundAdjustVolume(-4); SetConsoleMessage(sVolume + ": " + std::to_string(static_cast(100.f * (static_cast(djSoundGetVolume()) / 128.f)))); } - else if (Event.key.keysym.sym==SDLK_INSERT) + else if (Event.key.key==SDLK_INSERT) { if (djSoundEnabled()) djSoundDisable(); @@ -139,34 +139,34 @@ void do_menu_pump() } // up arrow - else if (Event.key.keysym.sym==SDLK_UP) + else if (Event.key.key==SDLK_UP) menu_move( menuPumpInfo.pMenu, menuPumpInfo.option, -1, *menuPumpInfo.szCursor ); // down arrow - else if (Event.key.keysym.sym==SDLK_DOWN) + else if (Event.key.key==SDLK_DOWN) menu_move( menuPumpInfo.pMenu, menuPumpInfo.option, 1, *menuPumpInfo.szCursor ); // home key - else if (Event.key.keysym.sym==SDLK_HOME)//g_iKeys[DJKEY_HOME]) + else if (Event.key.key==SDLK_HOME)//g_iKeys[DJKEY_HOME]) menu_move( menuPumpInfo.pMenu, menuPumpInfo.option, -menuPumpInfo.option + menuPumpInfo.pMenu->getSize() - 1, *menuPumpInfo.szCursor ); // end key - else if (Event.key.keysym.sym==SDLK_END)//if (g_iKeys[DJKEY_END]) + else if (Event.key.key==SDLK_END)//if (g_iKeys[DJKEY_END]) menu_move( menuPumpInfo.pMenu, menuPumpInfo.option, -menuPumpInfo.option, *menuPumpInfo.szCursor ); // enter - else if (Event.key.keysym.sym==SDLK_RETURN)//if (g_iKeys[DJKEY_ENTER]) + else if (Event.key.key==SDLK_RETURN)//if (g_iKeys[DJKEY_ENTER]) menuPumpInfo.bmenurunning = 0; // escape - else if (Event.key.keysym.sym==SDLK_ESCAPE)//if (g_iKeys[DJKEY_ESC]) + else if (Event.key.key==SDLK_ESCAPE)//if (g_iKeys[DJKEY_ESC]) { menuPumpInfo.option = -1; menuPumpInfo.bmenurunning = 0; } break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: break; case SDL_QUIT: menuPumpInfo.bmenurunning=0; @@ -453,20 +453,20 @@ int do_menu( CMenu *pMenu ) { switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: // 'Global' shortcut keys for adjusting volume [dj2016-10] - if (Event.key.keysym.sym==SDLK_7)//SDLK_PAGEUP) + if (Event.key.key==SDLK_7)//SDLK_PAGEUP) { djSoundAdjustVolume(4); djConsoleMessage::SetConsoleMessage(std::string("Volume: ") + std::to_string(static_cast(100.f * (static_cast(djSoundGetVolume()) / 128.f)))); } - else if (Event.key.keysym.sym==SDLK_6)//SDLK_PAGEDOWN) + else if (Event.key.key==SDLK_6)//SDLK_PAGEDOWN) { djSoundAdjustVolume(-4); djConsoleMessage::SetConsoleMessage(std::string("Volume: ") + std::to_string(static_cast(100.f * (static_cast(djSoundGetVolume()) / 128.f)))); } - else if (Event.key.keysym.sym==SDLK_INSERT) + else if (Event.key.key==SDLK_INSERT) { if (djSoundEnabled()) djSoundDisable(); @@ -476,42 +476,42 @@ int do_menu( CMenu *pMenu ) } // up arrow - else if (Event.key.keysym.sym==SDLK_UP) + else if (Event.key.key==SDLK_UP) menu_move( pMenu, option, -1, *szCursor, iFirstSelectable, iLastSelectable); // down arrow - else if (Event.key.keysym.sym==SDLK_DOWN) + else if (Event.key.key==SDLK_DOWN) menu_move( pMenu, option, 1, *szCursor, iFirstSelectable, iLastSelectable); // home key - else if (Event.key.keysym.sym==SDLK_HOME || + else if (Event.key.key==SDLK_HOME || // Numlock OFF + keypad7 = Home (at least on my laptop), make it also act as 'home' here [dj2023] - ( ( (SDL_GetModState() & KMOD_NUM)==0) && Event.key.keysym.sym==SDLK_KP_7 ) + ( ( (SDL_GetModState() & SDL_KMOD_NUM)==0) && Event.key.key==SDLK_KP_7 ) ) menu_move( pMenu, option, -option + pMenu->getSize() - 1, *szCursor, iFirstSelectable, iLastSelectable); // end key - else if (Event.key.keysym.sym==SDLK_END || + else if (Event.key.key==SDLK_END || // Numlock OFF + keypad1 = End (at least on my laptop), make it also act as 'end' here [dj2023] - ( ( (SDL_GetModState() & KMOD_NUM)==0) && Event.key.keysym.sym==SDLK_KP_1 ) + ( ( (SDL_GetModState() & SDL_KMOD_NUM)==0) && Event.key.key==SDLK_KP_1 ) ) menu_move( pMenu, option, -option, *szCursor, iFirstSelectable, iLastSelectable); // enter - else if (Event.key.keysym.sym==SDLK_RETURN)//if (g_iKeys[DJKEY_ENTER]) + else if (Event.key.key==SDLK_RETURN)//if (g_iKeys[DJKEY_ENTER]) bmenurunning = 0; // escape - else if (Event.key.keysym.sym==SDLK_ESCAPE)//if (g_iKeys[DJKEY_ESC]) + else if (Event.key.key==SDLK_ESCAPE)//if (g_iKeys[DJKEY_ESC]) { option = -1; bmenurunning = 0; } // dj2022-11 If an A-Z key pressed, see if we can find a selectable menu item that starts with that letter and select that (Duke Nukem did similar) - else if (bAllowMenuKeyLetterShortcuts && Event.key.keysym.sym>=SDLK_a && Event.key.keysym.sym<=SDLK_z && option>=0) + else if (bAllowMenuKeyLetterShortcuts && Event.key.key>=SDLK_A && Event.key.key<=SDLK_Z && option>=0) { - const char cPressed = 'a' + (Event.key.keysym.sym - SDLK_a); + const char cPressed = 'a' + (Event.key.key - SDLK_A); int nCurPos = option; const SMenuItem* paItems = pMenu->getItems(); for (auto i = 0; i < pMenu->getSize(); ++i) @@ -543,9 +543,9 @@ int do_menu( CMenu *pMenu ) } break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: break; - case SDL_QUIT: + case SDL_EVENT_QUIT: bmenurunning=0; option = -1;//Exit break; diff --git a/src/sdl/djgraph.cpp b/src/sdl/djgraph.cpp index aa1496c..e8641ff 100644 --- a/src/sdl/djgraph.cpp +++ b/src/sdl/djgraph.cpp @@ -18,13 +18,8 @@ Copyright (C) 1997-2024 David Joffe #include "../djgraph.h" #include "../djtypes.h" #include "../sys_log.h" -#ifdef __OS2__ -#include -#include -#else -#include "SDL.h" -#include -#endif +#include +#include #include //for uint32_t @@ -93,13 +88,13 @@ djVisual* djgOpenVisual( const char *vistype, int w, int h, int bpp, bool bBackb //dj2016-10 fixmelow_tocheck i am wondering if the below is doing speed optimal way of doing everything as this hasn't been looked at in years + auto format = SDL_GetPixelFormatForMasks(bpp, 0, 0, 0, 0); // Create a default visual: a resizable window or fullscreen //static SDL_Surface *p = NULL; if (NULL == vistype || pVis->m_bFullscreen) { // dj2022-11 slightly changing Matteo Bini's recent SDL2 code changes here to pass in the window title and bitmap as parameters (so this codebase could be more generically used for other games) - SDL_Window* win = SDL_CreateWindow(szWindowTitle == nullptr ? "Window" : szWindowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, - pVis->m_bFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE); + SDL_Window* win = SDL_CreateWindow(szWindowTitle == nullptr ? "Window" : szWindowTitle, w, h, pVis->m_bFullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY); pVis->pWindow = win;//<- dj2022-11 added storing this pWindow pointer so we can cleanup with corresponding SDL_DestroyWindow (for in-game fullscreen toggle etc.) if (szWindowIconFile != nullptr) { @@ -108,15 +103,15 @@ djVisual* djgOpenVisual( const char *vistype, int w, int h, int bpp, bool bBackb djImage* pImage = djImageLoad::LoadImage(szWindowIconFile); if (pImage) { + format = SDL_GetPixelFormatForMasks(pImage->BPP(), pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask); //printf("APPLE2 %s\n", szWindowIconFile); // Convert the djImage temporarily to a SDL_Surface - SDL_Surface* pSurface = ::SDL_CreateRGBSurfaceFrom( - pImage->Data(), + SDL_Surface* pSurface = ::SDL_CreateSurfaceFrom( pImage->Width(), pImage->Height(), - pImage->BPP(), - pImage->Pitch(), - pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask + format, + pImage->Data(), + pImage->Pitch() ); SDL_SetWindowIcon(win, pSurface); } @@ -128,11 +123,10 @@ djVisual* djgOpenVisual( const char *vistype, int w, int h, int bpp, bool bBackb SDL_SetWindowIcon(win, SDL_LoadBMP(szWindowIconFile)); #endif } - pVis->pRenderer = SDL_CreateRenderer(win, -1, 0); - SDL_RenderSetLogicalSize(pVis->pRenderer, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); - pVis->pSurface = SDL_CreateRGBSurface(0, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, bpp, - 0, 0, 0, 0); + pVis->pRenderer = SDL_CreateRenderer(win, nullptr); + SDL_SetRenderLogicalPresentation(pVis->pRenderer, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, SDL_LOGICAL_PRESENTATION_STRETCH); + //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); + pVis->pSurface = SDL_CreateSurface(CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, format); pVis->pTexture = SDL_CreateTextureFromSurface(pVis->pRenderer, pVis->pSurface); // to check/merge emsdk-build changes -> //// pVis->pSurface = SDL_DisplayFormat(pSurface); => @@ -148,15 +142,15 @@ djVisual* djgOpenVisual( const char *vistype, int w, int h, int bpp, bool bBackb // previously if we were at say 'scale 2' then the game base resolution is e.g. 320x200 but w,h would be e.g. 640x400 at scale 2 (and so on for higher scale values) - // .. the below by Matto Bini seems probably more 'correct' (and probably better performance in some aspects) but just adding a correcton here to also set // "pVis->width = CFG_APPLICATION_RENDER_RES_W" etc. otherwise the actual pSurface resolution (320x200) doesn't match what pVis reports which cause menu rendering funnies and possible crasshes this should fix. - pVis->pSurface = SDL_CreateRGBSurface(0, CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, bpp, - 0, 0, 0, 0); + pVis->pSurface = SDL_CreateSurface(CFG_APPLICATION_RENDER_RES_W, CFG_APPLICATION_RENDER_RES_H, format); pVis->width = CFG_APPLICATION_RENDER_RES_W; pVis->height = CFG_APPLICATION_RENDER_RES_H; pVis->stride = CFG_APPLICATION_RENDER_RES_W * (bpp/8); } - pVis->bpp = pVis->pSurface->format->BitsPerPixel; - switch (pVis->bpp) + auto f = SDL_GetPixelFormatDetails(pVis->pSurface->format); + pVis->format = pVis->pSurface->format; + switch (f->bits_per_pixel) { case 8: pVis->pixwidth = 1; break; case 16: pVis->pixwidth = 2; break; @@ -169,7 +163,7 @@ djVisual* djgOpenVisual( const char *vistype, int w, int h, int bpp, bool bBackb void djgCloseVisual( djVisual * pVis ) { - SDL_FreeSurface(pVis->pSurface); + SDL_DestroySurface(pVis->pSurface); pVis->pSurface = NULL;//?<- dj2017-01 not sure if this is all that's necessary for cleanup here ... //dj2022-11 adding this SDL_DestroyWindow here as I think it may help fix the in-game fullscreen toggle issues @@ -220,7 +214,8 @@ void djgFlip( djVisual * pVisDest, djVisual * pVisSrc, bool bScaleView ) { djgLock(pVisSrc); djgLock(pVisDest); - unsigned int uBPP = pVisSrc->pSurface->format->BytesPerPixel; + auto f = SDL_GetPixelFormatDetails(pVisSrc->pSurface->format); + unsigned int uBPP = f->bits_per_pixel; unsigned int *pSurfaceMem = (unsigned int*)pVisSrc->pSurface->pixels; unsigned int uMemOffsetRow = 0; @@ -280,8 +275,9 @@ void djgFlip( djVisual * pVisDest, djVisual * pVisSrc, bool bScaleView ) } */ - nPixel = SDL_MapRGB(pVisDest->pSurface->format,pPalette[nClosest].r,pPalette[nClosest].g,pPalette[nClosest].b); - SDL_FillRect(pVisDest->pSurface, &rc, nPixel); + auto f = SDL_GetPixelFormatDetails(pVisDest->pSurface->format); + nPixel = SDL_MapRGB(f, nullptr, pPalette[nClosest].r,pPalette[nClosest].g,pPalette[nClosest].b); + SDL_FillSurfaceRect(pVisDest->pSurface, &rc, nPixel); ++pSurfaceMem; ++rc.x; }//x @@ -300,7 +296,7 @@ void djgFlip( djVisual * pVisDest, djVisual * pVisSrc, bool bScaleView ) } SDL_UpdateTexture(pVisDest->pTexture, NULL, pVisDest->pSurface->pixels, pVisDest->pSurface->pitch); SDL_RenderClear(pVisDest->pRenderer); - SDL_RenderCopy(pVisDest->pRenderer, pVisDest->pTexture, NULL, NULL); + SDL_RenderTexture(pVisDest->pRenderer, pVisDest->pTexture, NULL, NULL); SDL_RenderPresent(pVisDest->pRenderer); } @@ -311,18 +307,18 @@ void djgClear( djVisual * pVis ) rc.y = 0; rc.w = pVis->width; rc.h = pVis->height; - SDL_FillRect(pVis->pSurface, &rc, SDL_MapRGB(pVis->pSurface->format, 0, 0, 0));//black + SDL_FillSurfaceRect(pVis->pSurface, &rc, SDL_MapRGB(SDL_GetPixelFormatDetails(pVis->pSurface->format), nullptr, 0, 0, 0));//black } void djgPutPixel( djVisual * pVis, int x, int y, int r, int g, int b ) { - const uint32_t pixel = SDL_MapRGB(pVis->pSurface->format, r, g, b); + const uint32_t pixel = SDL_MapRGB(SDL_GetPixelFormatDetails(pVis->pSurface->format), nullptr, r, g, b); SDL_Rect rc; rc.x = x; rc.y = y; rc.w = 1; rc.h = 1; - SDL_FillRect(pVis->pSurface, &rc, pixel); + SDL_FillSurfaceRect(pVis->pSurface, &rc, pixel); } //[low prio] these types of functions could/should ideally be sped up with inlining? [dj2022-11] [and/or avoid for sensitive performance bottleneck areas] @@ -366,9 +362,10 @@ void djgDrawRectangle( djVisual * pVis, int x, int y, int w, int h ) void djgDrawBox( djVisual * pVis, int x, int y, int w, int h ) { - const uint32_t pixel = SDL_MapRGB(pVis->pSurface->format, pVis->colorfore.r, pVis->colorfore.g, pVis->colorfore.b); + auto f = SDL_GetPixelFormatDetails(pVis->pSurface->format); + const uint32_t pixel = SDL_MapRGB(f, nullptr, pVis->colorfore.r, pVis->colorfore.g, pVis->colorfore.b); CdjRect rc(x, y, w, h); - SDL_FillRect(pVis->pSurface, &rc, pixel); + SDL_FillSurfaceRect(pVis->pSurface, &rc, pixel); } void djgDrawHLine( djVisual * pVis, int x, int y, int n ) @@ -378,7 +375,8 @@ void djgDrawHLine( djVisual * pVis, int x, int y, int n ) if (x+n>pVis->width) { n=pVis->width-x; } if (n<=0) return; - const uint32_t pixel = SDL_MapRGB(pVis->pSurface->format, pVis->colorfore.r, pVis->colorfore.g, pVis->colorfore.b); + auto f = SDL_GetPixelFormatDetails(pVis->pSurface->format); + const uint32_t pixel = SDL_MapRGB(f, nullptr, pVis->colorfore.r, pVis->colorfore.g, pVis->colorfore.b); djgLock( pVis ); for ( int i=0; ipVis->height) { n=pVis->height-y; } if (n<=0) return; - const uint32_t pixel = SDL_MapRGB(pVis->pSurface->format, pVis->colorfore.r, pVis->colorfore.g, pVis->colorfore.b); + const uint32_t pixel = SDL_MapRGB(SDL_GetPixelFormatDetails(pVis->pSurface->format), nullptr, pVis->colorfore.r, pVis->colorfore.g, pVis->colorfore.b); djgLock( pVis ); for ( int i=0; ipSurface, &rectDest); else - SDL_BlitScaled(pHWSurface, &rectSrc, pVis->pSurface, &rectDest); + SDL_BlitSurfaceScaled(pHWSurface, &rectSrc, pVis->pSurface, &rectDest, SDL_SCALEMODE_LINEAR); return; } @@ -484,8 +482,9 @@ void djgDrawImage( djVisual *pVis, djImage *pImage, int xS, int yS, int xD, int if (xD<0) { w=w+xD; if (w<=0) return; xD=0; } if (yD<0) { h=h+yD; if (h<=0) return; yD=0; } + auto f = SDL_GetPixelFormatDetails(pVis->format); // If same pixel formats, just copy - if (pVis->bpp==pImage->BPP()) + if (f->bits_per_pixel==pImage->BPP()) { djgLock(pVis); @@ -503,13 +502,13 @@ void djgDrawImage( djVisual *pVis, djImage *pImage, int xS, int yS, int xD, int } // 32-bit, no transparency - if (pVis->bpp==32) + if (f->bytes_per_pixel==32) { if (pImage->BPP()==16) { } } - if (pVis->bpp==16) + if (f->bytes_per_pixel==16) { // 32-bit, no transparency if (pImage->BPP()==32) @@ -630,8 +629,9 @@ void djgDrawImageAlpha( djVisual *pVis, djImage *pImage, int xS, int yS, int xD, if (xD<0) { w=w+xD; if (w<=0) return; xD=0; } if (yD<0) { h=h+yD; if (h<=0) return; yD=0; } + auto f = SDL_GetPixelFormatDetails(pVis->format); // 32-bit, alpha map - if (pVis->bpp==32) + if (f->bits_per_pixel==32) { if (pImage->BPP()==32) { @@ -660,7 +660,7 @@ void djgDrawImageAlpha( djVisual *pVis, djImage *pImage, int xS, int yS, int xD, return; } } - if (pVis->bpp==16) + if (f->bits_per_pixel==16) { if (pImage->BPP()==32) { @@ -701,7 +701,8 @@ void djgDrawVisual( djVisual *pDest, djVisual *pSrc, int xD, int yD, int xS, int void SetPixelConversion ( djVisual *vis ) { - SDL_PixelFormat *f = vis->pSurface->format; + auto pf = vis->pSurface->format; + auto f = SDL_GetPixelFormatDetails(pf); djLOGSTR( "Setting up pixel conversion attributes...:\n" ); rMask = f->Rmask; @@ -736,7 +737,7 @@ void djImageHardwareSurfaceCache::ClearHardwareSurfaces() SDL_Surface* pHardwareSurface = iter.second; if (pHardwareSurface) { - SDL_FreeSurface(pHardwareSurface); + SDL_DestroySurface(pHardwareSurface); // fixme check if the above leaks? g_SurfaceMap[pImage] = nullptr; } @@ -763,7 +764,7 @@ void djDestroyImageHWSurface( djImage* pImage ) SDL_Surface* pHardwareSurface = iter->second; if (pHardwareSurface) { - SDL_FreeSurface(pHardwareSurface); + SDL_DestroySurface(pHardwareSurface); //? ?delete pHardwareSurface; pHardwareSurface = NULL; } @@ -818,21 +819,15 @@ void* djCreateImageHWSurface( djImage* pImage/*, djVisual* pVisDisplayBuffer*/ ) https://wiki.libsdl.org/CategoryEndian https://wiki.libsdl.org/SDL_CreateRGBSurface */ + auto format = SDL_GetPixelFormatForMasks(pImage->BPP(), pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask); if (pImage->BPP()==24)//3 bytes = RGB with NO alpha .. ? { - pSurfaceHardware = ::SDL_CreateRGBSurfaceFrom( - pImage->Data(), + pSurfaceHardware = ::SDL_CreateSurfaceFrom( pImage->Width(), pImage->Height(), - pImage->BPP(), - pImage->Pitch(), - //// R,G,B,A masks (dj2018-03 specify different masks here on PPC etc. - see https://github.com/davidjoffe/dave_gnukem/issues/100 - thanks to @BeWorld2018 for report and patch suggestion) - // Above fix/patch moved to inside TGA loading code (in order to accommodate also new .png loading more smoothly) - todo check it doesn't accidentally break big endian platforms again etc. - //#if SDL_BYTEORDER==SDL_BIG_ENDIAN - //pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask - //#else - pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask - //#endif + format, + pImage->Data(), + pImage->Pitch() ); } else @@ -842,34 +837,20 @@ void* djCreateImageHWSurface( djImage* pImage/*, djVisual* pVisDisplayBuffer*/ ) // or generically handle more cases here .. or both I suppose, to help make sure this stuff works on all platforms etc. #ifdef djUSE_SDLIMAGE //pImage-> - pSurfaceHardware = ::SDL_CreateRGBSurfaceFrom( - pImage->Data(), + pSurfaceHardware = ::SDL_CreateSurfaceFrom( pImage->Width(), pImage->Height(), - pImage->BPP(), - pImage->Pitch(), - // R,G,B,A masks (dj2018-03 specify different masks here on PPC etc. - see https://github.com/davidjoffe/dave_gnukem/issues/100 - thanks to @BeWorld2018 for report and patch suggestion) - // Above fix/patch moved to inside TGA loading code (in order to accommodate also new .png loading more smoothly) - todo check it doesn't accidentally break big endian platforms again etc. - pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask + format, + pImage->Data(), + pImage->Pitch() ); #else - pSurfaceHardware = ::SDL_CreateRGBSurfaceFrom( - pImage->Data(), + pSurfaceHardware = ::SDL_CreateSurfaceFrom( pImage->Width(), pImage->Height(), - 32,//pImage->BPP(), - pImage->Pitch(), - // R,G,B,A masks (dj2018-03 specify different masks here on PPC etc. - see https://github.com/davidjoffe/dave_gnukem/issues/100 - thanks to @BeWorld2018 for report and patch suggestion) - //#if SDL_BYTEORDER==SDL_BIG_ENDIAN - //0x0000FF00, 0X00FF0000, 0xFF000000, 0x000000FF - //#else - pImage->m_Rmask, pImage->m_Gmask, pImage->m_Bmask, pImage->m_Amask - /*was hardcoded as: - 0xFF0000, - 0xFF00, - 0xFF, - 0xFF000000*/// - //#endif + format, + pImage->Data(), + pImage->Pitch() ); #endif @@ -952,7 +933,7 @@ SDL_SWSURFACE, SDL_SetSurfaceAlphaMod(pSurface, 0); //SDL_UnlockSurface(pSurfaceImg); - //SDL_FreeSurface(pSurfaceImg); + //SDL_DestroySurface(pSurfaceImg); //delete pSurface;//? } return (void*)pSurface; diff --git a/src/sdl/djinclude_sdlmixer.h b/src/sdl/djinclude_sdlmixer.h index b9791a1..223e6e9 100644 --- a/src/sdl/djinclude_sdlmixer.h +++ b/src/sdl/djinclude_sdlmixer.h @@ -7,47 +7,7 @@ //#include "config.h"//For NOSOUND //#ifndef NOSOUND - -#ifdef __OS2__ - #include -#else - - #if defined(__has_include) - - #ifdef WIN32 - - // [dj2023-11] vcpkg starts to have this new sdl2-mixer-ext instead of the usual sdl2-mixer (for libvorbis especially I think we may need it) but I don't see it in Ubuntu WSL etc. so for now just on Windows start trying to sort of auto-figure out whether to use sdl2-mixer-ext or sdl2-mixer - #if __has_include() - // [dj2023] add this define so we know we are using the ext lib for things like #pragma link setting on MSVC platforms - #define djUSING_SDL_MIXER_EXT - #include - #elif __has_include() - #define djUSING_SDL_MIXER_EXT - #include - #elif __has_include() - #include - #else - #include - #endif - - #else - - #if __has_include() - #include - //#if __has_include() - // #include - #else - #include - #endif - - #endif - - #else - // No __has_include, just go the old way (except __OS2__ path which we already set up) .. this may all have to change and be tweaked again I'm sure .. - #include - #endif - -#endif//#ifdef __OS2__ +#include //#endif//#ifndef NOSOUND #endif//_DJINCLUDE_SDLMIXER_H_ diff --git a/src/sdl/djinput.cpp b/src/sdl/djinput.cpp index e3451c8..1bf3e05 100644 --- a/src/sdl/djinput.cpp +++ b/src/sdl/djinput.cpp @@ -11,11 +11,7 @@ Created: '95/07/20 (originally as a test keyboard interrupt hook) #include #include "../djinput.h" #include "../djlog.h" -#ifdef __OS2__ -#include //dj2022-11 for SDL_Delay (which may change eg cf. emscripten issues) .. -#else -#include //dj2022-11 for SDL_Delay (which may change eg cf. emscripten issues) .. -#endif +#include //dj2022-11 for SDL_Delay (which may change eg cf. emscripten issues) .. int g_iKeys[DJKEY_MAX] = { 0 }; @@ -70,58 +66,58 @@ SdjKeyMapping key_pairs[] = { DJKEY_ALT, SDLK_LALT }, { DJKEY_CTRL, SDLK_RCTRL }, { DJKEY_CTRL, SDLK_LCTRL }, - { DJKEY_A, SDLK_a }, - { DJKEY_A, SDLK_a }, - { DJKEY_B, SDLK_b }, - { DJKEY_B, SDLK_b }, - { DJKEY_C, SDLK_c }, - { DJKEY_C, SDLK_c }, - { DJKEY_D, SDLK_d }, - { DJKEY_D, SDLK_d }, - { DJKEY_E, SDLK_e }, - { DJKEY_E, SDLK_e }, - { DJKEY_F, SDLK_f }, - { DJKEY_F, SDLK_f }, - { DJKEY_G, SDLK_g }, - { DJKEY_G, SDLK_g }, - { DJKEY_H, SDLK_h }, - { DJKEY_H, SDLK_h }, - { DJKEY_I, SDLK_i }, - { DJKEY_I, SDLK_i }, - { DJKEY_J, SDLK_j }, - { DJKEY_J, SDLK_j }, - { DJKEY_K, SDLK_k }, - { DJKEY_K, SDLK_k }, - { DJKEY_L, SDLK_l }, - { DJKEY_L, SDLK_l }, - { DJKEY_M, SDLK_m }, - { DJKEY_M, SDLK_m }, - { DJKEY_N, SDLK_n }, - { DJKEY_N, SDLK_n }, - { DJKEY_O, SDLK_o }, - { DJKEY_O, SDLK_o }, - { DJKEY_P, SDLK_p }, - { DJKEY_P, SDLK_p }, - { DJKEY_Q, SDLK_q }, - { DJKEY_Q, SDLK_q }, - { DJKEY_R, SDLK_r }, - { DJKEY_R, SDLK_r }, - { DJKEY_S, SDLK_s }, - { DJKEY_S, SDLK_s }, - { DJKEY_T, SDLK_t }, - { DJKEY_T, SDLK_t }, - { DJKEY_U, SDLK_u }, - { DJKEY_U, SDLK_u }, - { DJKEY_V, SDLK_v }, - { DJKEY_V, SDLK_v }, - { DJKEY_W, SDLK_w }, - { DJKEY_W, SDLK_w }, - { DJKEY_X, SDLK_x }, - { DJKEY_X, SDLK_x }, - { DJKEY_Y, SDLK_y }, - { DJKEY_Y, SDLK_y }, - { DJKEY_Z, SDLK_z }, - { DJKEY_Z, SDLK_z }, + { DJKEY_A, SDLK_A }, + { DJKEY_A, SDLK_A }, + { DJKEY_B, SDLK_B }, + { DJKEY_B, SDLK_B }, + { DJKEY_C, SDLK_C }, + { DJKEY_C, SDLK_C }, + { DJKEY_D, SDLK_D }, + { DJKEY_D, SDLK_D }, + { DJKEY_E, SDLK_E }, + { DJKEY_E, SDLK_E }, + { DJKEY_F, SDLK_F }, + { DJKEY_F, SDLK_F }, + { DJKEY_G, SDLK_G }, + { DJKEY_G, SDLK_G }, + { DJKEY_H, SDLK_H }, + { DJKEY_H, SDLK_H }, + { DJKEY_I, SDLK_I }, + { DJKEY_I, SDLK_I }, + { DJKEY_J, SDLK_J }, + { DJKEY_J, SDLK_J }, + { DJKEY_K, SDLK_K }, + { DJKEY_K, SDLK_K }, + { DJKEY_L, SDLK_L }, + { DJKEY_L, SDLK_L }, + { DJKEY_M, SDLK_M }, + { DJKEY_M, SDLK_M }, + { DJKEY_N, SDLK_N }, + { DJKEY_N, SDLK_N }, + { DJKEY_O, SDLK_O }, + { DJKEY_O, SDLK_O }, + { DJKEY_P, SDLK_P }, + { DJKEY_P, SDLK_P }, + { DJKEY_Q, SDLK_Q }, + { DJKEY_Q, SDLK_Q }, + { DJKEY_R, SDLK_R }, + { DJKEY_R, SDLK_R }, + { DJKEY_S, SDLK_S }, + { DJKEY_S, SDLK_S }, + { DJKEY_T, SDLK_T }, + { DJKEY_T, SDLK_T }, + { DJKEY_U, SDLK_U }, + { DJKEY_U, SDLK_U }, + { DJKEY_V, SDLK_V }, + { DJKEY_V, SDLK_V }, + { DJKEY_W, SDLK_W }, + { DJKEY_W, SDLK_W }, + { DJKEY_X, SDLK_X }, + { DJKEY_X, SDLK_X }, + { DJKEY_Y, SDLK_Y }, + { DJKEY_Y, SDLK_Y }, + { DJKEY_Z, SDLK_Z }, + { DJKEY_Z, SDLK_Z }, { DJKEY_0, SDLK_0 }, { DJKEY_1, SDLK_1 }, { DJKEY_2, SDLK_2 }, @@ -148,11 +144,11 @@ const char *GetKeyString(int nSDLKeyCode) case SDLK_ESCAPE: return "ESCAPE"; case SDLK_SPACE: return "SPACE"; case SDLK_EXCLAIM: return "EXCLAIM"; - case SDLK_QUOTEDBL: return "QUOTEDBL"; + case SDLK_DBLAPOSTROPHE: return "QUOTEDBL"; case SDLK_HASH: return "#"; case SDLK_DOLLAR: return "$"; case SDLK_AMPERSAND: return "&"; - case SDLK_QUOTE: return "QUOTE"; + case SDLK_APOSTROPHE: return "QUOTE"; case SDLK_LEFTPAREN: return "("; case SDLK_RIGHTPAREN: return ")"; case SDLK_ASTERISK: return "*"; @@ -183,33 +179,33 @@ const char *GetKeyString(int nSDLKeyCode) case SDLK_RIGHTBRACKET: return ")"; case SDLK_CARET: return "^"; case SDLK_UNDERSCORE: return "_"; - case SDLK_BACKQUOTE: return "BACKQUOTE"; - case SDLK_a: return "A"; - case SDLK_b: return "B"; - case SDLK_c: return "C"; - case SDLK_d: return "D"; - case SDLK_e: return "E"; - case SDLK_f: return "F"; - case SDLK_g: return "G"; - case SDLK_h: return "H"; - case SDLK_i: return "I"; - case SDLK_j: return "J"; - case SDLK_k: return "K"; - case SDLK_l: return "L"; - case SDLK_m: return "M"; - case SDLK_n: return "N"; - case SDLK_o: return "O"; - case SDLK_p: return "P"; - case SDLK_q: return "Q"; - case SDLK_r: return "R"; - case SDLK_s: return "S"; - case SDLK_t: return "T"; - case SDLK_u: return "U"; - case SDLK_v: return "V"; - case SDLK_w: return "W"; - case SDLK_x: return "X"; - case SDLK_y: return "Y"; - case SDLK_z: return "Z"; + case SDLK_GRAVE: return "BACKQUOTE"; + case SDLK_A: return "A"; + case SDLK_B: return "B"; + case SDLK_C: return "C"; + case SDLK_D: return "D"; + case SDLK_E: return "E"; + case SDLK_F: return "F"; + case SDLK_G: return "G"; + case SDLK_H: return "H"; + case SDLK_I: return "I"; + case SDLK_J: return "J"; + case SDLK_K: return "K"; + case SDLK_L: return "L"; + case SDLK_M: return "M"; + case SDLK_N: return "N"; + case SDLK_O: return "O"; + case SDLK_P: return "P"; + case SDLK_Q: return "Q"; + case SDLK_R: return "R"; + case SDLK_S: return "S"; + case SDLK_T: return "T"; + case SDLK_U: return "U"; + case SDLK_V: return "V"; + case SDLK_W: return "W"; + case SDLK_X: return "X"; + case SDLK_Y: return "Y"; + case SDLK_Z: return "Z"; case SDLK_DELETE: return "DEL"; case SDLK_KP_0: return "KEYPAD0"; case SDLK_KP_1: return "KEYPAD1"; @@ -284,42 +280,42 @@ bool djiPollEvents(SDL_Event &Event) { // [dj2016-10] Prevent distinguishing between left and right control/alt, i.e. treat both left-ctrl and right-ctrl as just 'ctrl' // and likewise for alt .. I think this makes for slightly more user-friendlier experience with default keys etc. - if (Event.type==SDL_KEYDOWN||Event.type==SDL_KEYUP) + if (Event.type==SDL_EVENT_KEY_DOWN||Event.type==SDL_EVENT_KEY_UP) { - if (Event.key.keysym.sym==SDLK_LCTRL) - Event.key.keysym.sym = SDLK_RCTRL; - else if (Event.key.keysym.sym==SDLK_LALT) - Event.key.keysym.sym = SDLK_RALT; + if (Event.key.key==SDLK_LCTRL) + Event.key.key = SDLK_RCTRL; + else if (Event.key.key==SDLK_LALT) + Event.key.key = SDLK_RALT; } int i; // Handle some basic events switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: for ( i=0; key_pairs[i].m_iScanCode!=-1; i++ ) { - if (Event.key.keysym.sym==(int)key_pairs[i].m_iPlatformCode) + if (Event.key.key==(int)key_pairs[i].m_iPlatformCode) g_iKeys[key_pairs[i].m_iScanCode] = 1; } break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: for ( i=0; key_pairs[i].m_iScanCode!=-1; i++ ) { - if (Event.key.keysym.sym==(int)key_pairs[i].m_iPlatformCode) + if (Event.key.key==(int)key_pairs[i].m_iPlatformCode) g_iKeys[key_pairs[i].m_iScanCode] = 0; } break; - case SDL_MOUSEMOTION: + case SDL_EVENT_MOUSE_MOTION: djMouse::x = Event.motion.x; djMouse::y = Event.motion.y; break; - case SDL_MOUSEBUTTONDOWN: + case SDL_EVENT_MOUSE_BUTTON_DOWN: if (Event.button.button==1) djMouse::b |= 1; if (Event.button.button==3) djMouse::b |= 2; djMouse::x = Event.button.x; djMouse::y = Event.button.y; break; - case SDL_MOUSEBUTTONUP: + case SDL_EVENT_MOUSE_BUTTON_UP: if (Event.button.button==1) djMouse::b &= ~1; if (Event.button.button==3) djMouse::b &= ~2; djMouse::x = Event.button.x; @@ -354,33 +350,33 @@ void djiPoll() int i; switch (Event.type) { - case SDL_KEYDOWN: + case SDL_EVENT_KEY_DOWN: for ( i=0; key_pairs[i].m_iScanCode!=-1; i++ ) { - if (Event.key.keysym.sym==(int)key_pairs[i].m_iPlatformCode) + if (Event.key.key==(int)key_pairs[i].m_iPlatformCode) g_iKeys[key_pairs[i].m_iScanCode] = 1; } break; - case SDL_KEYUP: + case SDL_EVENT_KEY_UP: for ( i=0; key_pairs[i].m_iScanCode!=-1; i++ ) { - if (Event.key.keysym.sym==(int)key_pairs[i].m_iPlatformCode) + if (Event.key.key==(int)key_pairs[i].m_iPlatformCode) g_iKeys[key_pairs[i].m_iScanCode] = 0; } break; - case SDL_QUIT: + case SDL_EVENT_QUIT: break; - case SDL_MOUSEMOTION: + case SDL_EVENT_MOUSE_MOTION: djMouse::x = Event.motion.x; djMouse::y = Event.motion.y; break; - case SDL_MOUSEBUTTONDOWN: + case SDL_EVENT_MOUSE_BUTTON_DOWN: if (Event.button.button==1) djMouse::b |= 1; if (Event.button.button==3) djMouse::b |= 2; djMouse::x = Event.button.x; djMouse::y = Event.button.y; break; - case SDL_MOUSEBUTTONUP: + case SDL_EVENT_MOUSE_BUTTON_UP: if (Event.button.button==1) djMouse::b &= ~1; if (Event.button.button==3) djMouse::b &= ~2; djMouse::x = Event.button.x; diff --git a/src/sdl/djsound.cpp b/src/sdl/djsound.cpp index 80372df..42ce7f8 100644 --- a/src/sdl/djsound.cpp +++ b/src/sdl/djsound.cpp @@ -8,21 +8,10 @@ Copyright (C) 1999-2024 David Joffe and Kent Mein #include "../djsound.h" #include "../djstring.h" #include "../djlog.h" -#ifdef __OS2__ -#include -#include -#else - - #if defined(__has_include) - #include - #include - #else - #include - #include - #endif +#include +#include -#endif #ifndef NOSOUND #include "djinclude_sdlmixer.h" #endif//#ifndef NOSOUND @@ -33,26 +22,6 @@ Copyright (C) 1999-2024 David Joffe and Kent Mein #include #endif -#if defined(WIN32) && defined(_MSC_VER) -// Microsoft compiler stuff .. hmm not sure where best .. unless cmake etc. -#ifdef _DEBUG - - #ifdef djUSING_SDL_MIXER_EXT - #pragma comment(lib, "SDL2_mixer_ext.lib") - #else//djUSING_SDL_MIXER_EXT - // Should this be SDL2_mixerd.lib? - #pragma comment(lib, "SDL2_mixer.lib") - #endif//djUSING_SDL_MIXER_EXT - -#else//_DEBUG - #ifdef djUSING_SDL_MIXER_EXT - #pragma comment(lib, "SDL2_mixer_ext.lib") - #else//djUSING_SDL_MIXER_EXT - #pragma comment(lib, "SDL2_mixer.lib") - #endif//djUSING_SDL_MIXER_EXT -#endif//_DEBUG -#endif//#if defined(WIN32) && defined(_MSC_VER) - //#define NOSOUND //For now [dj2016-10] just make background music some relative percentage of the main volume (so background is a bit softer so as not to get too annoying) - later could add a separate setting for background music volume @@ -139,7 +108,12 @@ int djSoundInit() //{ numsounds = 0; int audio_channels=2; - if (Mix_OpenAudio(22050, AUDIO_S16, audio_channels, 1024) < 0) { + SDL_AudioSpec spec = { + SDL_AUDIO_S16, + audio_channels, + 22050 + }; + if (!Mix_OpenAudio(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec)) { fprintf(stderr, "Warning: Couldn't set 22050 Hz 16-bit audio\n- Reason : %s\n", SDL_GetError()); diff --git a/src/sdl/djtime.cpp b/src/sdl/djtime.cpp index a489a45..552d919 100644 --- a/src/sdl/djtime.cpp +++ b/src/sdl/djtime.cpp @@ -6,11 +6,8 @@ Copyright (C) 1999-2024 David Joffe #include "../config.h" #include "../djtime.h" -#ifdef __OS2__ -#include -#else -#include "SDL.h" -#endif +#include + #ifdef WIN32 #include #include @@ -45,10 +42,6 @@ float djTimeGetTime() uint64_t djTimeGetTicks64() { -#if SDL_VERSION_ATLEAST(2, 0, 18) - return SDL_GetTicks64(); -#else // Re "SDL_GetTicks": *This function is not recommended as of SDL 2.0.18; use SDL_GetTicks64() instead, where the value doesn't wrap every ~49 days" return SDL_GetTicks(); -#endif }