From ba027fd5579c333f6ff7049995f712c1237e9e07 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 1 Oct 2013 13:11:43 +0200 Subject: [PATCH] Initial conversion to SDL2. Color keys and alpha blending is not working correctly yet. --- makefile | 4 ++-- src/CConfig.cpp | 4 ++-- src/CEngine.cpp | 49 ++++++++++++++++++++++---------------------- src/CEngine.h | 2 +- src/CGraphics.cpp | 51 ++++++++++++++++++++++------------------------ src/CGraphics.h | 3 +++ src/CKeyboard.cpp | 22 ++++++++++---------- src/cutscene.cpp | 6 +++--- src/galdov.cpp | 4 ++-- src/game.cpp | 23 ++++++++------------- src/headers.h | 10 ++++----- src/hub.cpp | 2 +- src/init.cpp | 43 +++++++++++++++++---------------------- src/intro.cpp | 2 +- src/map.cpp | 4 ++-- src/mapData.cpp | 2 +- src/mapEditor.cpp | 52 +++++++++++++++++++++++------------------------ src/mission.cpp | 2 +- src/options.cpp | 20 ++++++++++-------- src/player.cpp | 12 +++++------ src/title.cpp | 14 ++++++------- 21 files changed, 161 insertions(+), 170 deletions(-) diff --git a/makefile b/makefile index 104ef0a..3e69cbf 100755 --- a/makefile +++ b/makefile @@ -18,11 +18,11 @@ LOCALEDIR ?= $(PREFIX)/share/locale/ MEDAL_SERVER_HOST = www.parallelrealities.co.uk MEDAL_SERVER_PORT = 80 -CXXFLAGS += `sdl-config --cflags` -DVERSION=$(VERSION) -DRELEASE=$(RELEASE) -DUSEPAK=$(USEPAK) +CXXFLAGS += `pkg-config --cflags sdl2 SDL2_mixer SDL2_image SDL2_ttf SDL2_net` -DVERSION=$(VERSION) -DRELEASE=$(RELEASE) -DUSEPAK=$(USEPAK) CXXFLAGS += -DPAKNAME=\"$(PAKNAME)\" -DPAKLOCATION=\"$(DATADIR)\" -DUNIX -DGAMEPLAYMANUAL=\"$(DOCDIR)index.html\" -Wall CXXFLAGS += -DLOCALEDIR=\"$(LOCALEDIR)\" -DMEDAL_SERVER_HOST=\"$(MEDAL_SERVER_HOST)\" -DMEDAL_SERVER_PORT=$(MEDAL_SERVER_PORT) CXXFLAGS += $(CFLAGS) -Werror -LIBS = `sdl-config --libs` -lSDL_mixer -lSDL_image -lSDL_ttf -lSDL_net -lz +LIBS = `pkg-config --libs sdl2 SDL2_mixer SDL2_image SDL2_ttf SDL2_net` -lz PAKLIBS = -lz OBJS += CAudio.o diff --git a/src/CConfig.cpp b/src/CConfig.cpp index 5121c7f..ea4eff4 100644 --- a/src/CConfig.cpp +++ b/src/CConfig.cpp @@ -77,11 +77,11 @@ void Config::doPause() } else { - if ((engine->keyState[keyboard.control[CONTROL::PAUSE]]) || (engine->keyState[SDLK_ESCAPE])) + if ((engine->keyState[keyboard.control[CONTROL::PAUSE]]) || (engine->keyState[SDL_SCANCODE_ESCAPE])) { engine->paused = false; engine->keyState[keyboard.control[CONTROL::PAUSE]] = 0; - engine->keyState[SDLK_ESCAPE] = 0; + engine->keyState[SDL_SCANCODE_ESCAPE] = 0; } } } diff --git a/src/CEngine.cpp b/src/CEngine.cpp index b5c0b15..3d8a48e 100644 --- a/src/CEngine.cpp +++ b/src/CEngine.cpp @@ -20,18 +20,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "headers.h" #include +extern Graphics graphics; Engine::Engine() { - for (int i = 0 ; i < 350 ; i++) - { - keyState[i] = 0; - } - - for (int i = 0 ; i < 32 ; i++) - { - joystickState[i] = 0; - } + memset(keyState, 0, sizeof keyState); + + memset(joystickState, 0, sizeof joystickState); joyX = joyY = 0; @@ -186,7 +181,7 @@ void Engine::getInput() if (waitForButton) { - if (event.key.keysym.sym == SDLK_ESCAPE) + if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { lastButtonPressed = -1; *highlightedWidget->value = abs(*highlightedWidget->value) - 1000; @@ -195,7 +190,7 @@ void Engine::getInput() allowJoypad = false; } - if (event.key.keysym.sym == SDLK_BACKSPACE) + if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) { lastButtonPressed = -2; *highlightedWidget->value = -2; @@ -209,13 +204,13 @@ void Engine::getInput() if (waitForKey) { - if (event.key.keysym.sym == SDLK_ESCAPE) + if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) { *highlightedWidget->value = -*highlightedWidget->value; } else { - *highlightedWidget->value = event.key.keysym.sym; + *highlightedWidget->value = event.key.keysym.scancode; } lastButtonPressed = -1; @@ -227,13 +222,13 @@ void Engine::getInput() return; } - keyState[event.key.keysym.sym] = 1; - strlcpy(lastKeyPressed, SDL_GetKeyName(event.key.keysym.sym), sizeof lastKeyPressed); + keyState[event.key.keysym.scancode] = 1; + strlcpy(lastKeyPressed, SDL_GetKeyName(event.key.keysym.scancode), sizeof lastKeyPressed); addKeyEvent(); break; case SDL_KEYUP: - keyState[event.key.keysym.sym] = 0; + keyState[event.key.keysym.scancode] = 0; break; case SDL_JOYAXISMOTION: @@ -267,6 +262,11 @@ void Engine::getInput() joystickState[event.jbutton.button] = 0; break; + case SDL_WINDOWEVENT: + if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) + paused = true; + break; + default: break; } @@ -285,12 +285,12 @@ int Engine::getMouseY() const void Engine::setMouse(int x, int y) { - SDL_WarpMouse(x, y); + SDL_WarpMouseInWindow(graphics.window, x, y); } bool Engine::userAccepts() { - if ((keyState[SDLK_SPACE]) || (keyState[SDLK_ESCAPE]) || (keyState[SDLK_LCTRL]) || (keyState[SDLK_RCTRL]) || (keyState[SDLK_RETURN]) || (keyState[SDLK_LCTRL])) + if ((keyState[SDL_SCANCODE_SPACE]) || (keyState[SDL_SCANCODE_ESCAPE]) || (keyState[SDL_SCANCODE_LCTRL]) || (keyState[SDL_SCANCODE_RCTRL]) || (keyState[SDL_SCANCODE_RETURN]) || (keyState[SDL_SCANCODE_LCTRL])) { return true; } @@ -305,8 +305,7 @@ void Engine::flushInput() void Engine::clearInput() { - for (int i = 0 ; i < 350 ; i++) - keyState[i] = 0; + memset(keyState, 0, sizeof keyState); mouseLeft = mouseRight = 0; } @@ -732,21 +731,21 @@ int Engine::processWidgets() { int update = 0; - if (keyState[SDLK_UP]) + if (keyState[SDL_SCANCODE_UP]) { highlightWidget(-1); update = 1; clearInput(); } - if (keyState[SDLK_DOWN]) + if (keyState[SDL_SCANCODE_DOWN]) { highlightWidget(1); update = 1; clearInput(); } - if (keyState[SDLK_LEFT] && (highlightedWidget->type != WG_BUTTON && highlightedWidget->type != WG_JOYPAD)) + if (keyState[SDL_SCANCODE_LEFT] && (highlightedWidget->type != WG_BUTTON && highlightedWidget->type != WG_JOYPAD)) { SDL_Delay(1); @@ -763,7 +762,7 @@ int Engine::processWidgets() clearInput(); } - if (keyState[SDLK_RIGHT] && (highlightedWidget->type != WG_BUTTON && highlightedWidget->type != WG_JOYPAD)) + if (keyState[SDL_SCANCODE_RIGHT] && (highlightedWidget->type != WG_BUTTON && highlightedWidget->type != WG_JOYPAD)) { SDL_Delay(1); @@ -780,7 +779,7 @@ int Engine::processWidgets() clearInput(); } - if ((keyState[SDLK_RETURN]) || (keyState[SDLK_SPACE]) || (keyState[SDLK_LCTRL])) + if ((keyState[SDL_SCANCODE_RETURN]) || (keyState[SDL_SCANCODE_SPACE]) || (keyState[SDL_SCANCODE_LCTRL])) { if (highlightedWidget->value == NULL) { diff --git a/src/CEngine.h b/src/CEngine.h index bd0d0d2..1a723b5 100644 --- a/src/CEngine.h +++ b/src/CEngine.h @@ -44,7 +44,7 @@ class Engine { int extremeAvailable; - char keyState[350]; + char keyState[SDL_NUM_SCANCODES]; char mouseLeft, mouseRight; int joyX, joyY; diff --git a/src/CGraphics.cpp b/src/CGraphics.cpp index d9e45fa..93c2de8 100644 --- a/src/CGraphics.cpp +++ b/src/CGraphics.cpp @@ -140,8 +140,6 @@ void Graphics::mapColors() fontForeground.r = fontForeground.g = fontForeground.b = 0xff; fontBackground.r = fontBackground.g = fontBackground.b = 0x00; - fontForeground.unused = fontBackground.unused = 0; - fadeBlack = alphaRect(640, 480, 0x00, 0x00, 0x00); infoBar = alphaRect(640, 25, 0x00, 0x00, 0x00); @@ -156,7 +154,7 @@ Sprite *Graphics::getSpriteHead() void Graphics::setTransparent(SDL_Surface *sprite) { - SDL_SetColorKey(sprite, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(sprite->format, 0, 0, 0)); + SDL_SetColorKey(sprite, SDL_RLEACCEL, SDL_MapRGB(sprite->format, 0, 0, 0)); } bool Graphics::canShowMedalMessage() const @@ -187,8 +185,9 @@ void Graphics::updateScreen() } } - SDL_Flip(screen); - SDL_Delay(1); + SDL_UpdateTexture(texture, NULL, screen->pixels, screen->w * 4); + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); if (takeRandomScreenShots) { @@ -202,21 +201,21 @@ void Graphics::updateScreen() SDL_Delay(16); } - if (engine->keyState[SDLK_F12]) + if (engine->keyState[SDL_SCANCODE_F12]) { snprintf(screenshot, sizeof screenshot, "screenshots/screenshot%.3d.bmp", screenShotNumber); SDL_SaveBMP(screen, screenshot); screenShotNumber++; - engine->keyState[SDLK_F12] = 0; + engine->keyState[SDL_SCANCODE_F12] = 0; } - if ((engine->keyState[SDLK_F10]) || ((engine->keyState[SDLK_RETURN]) && (engine->keyState[SDLK_LALT]))) + if ((engine->keyState[SDL_SCANCODE_F10]) || ((engine->keyState[SDL_SCANCODE_RETURN]) && (engine->keyState[SDL_SCANCODE_LALT]))) { - SDL_WM_ToggleFullScreen(screen); engine->fullScreen = !engine->fullScreen; + SDL_SetWindowFullscreen(window, engine->fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); - engine->keyState[SDLK_F10] = engine->keyState[SDLK_LALT] = engine->keyState[SDLK_RETURN] = 0; + engine->keyState[SDL_SCANCODE_F10] = engine->keyState[SDL_SCANCODE_LALT] = engine->keyState[SDL_SCANCODE_RETURN] = 0; } } @@ -224,7 +223,7 @@ void Graphics::delay(int time) { unsigned long then = SDL_GetTicks(); - engine->keyState[SDLK_ESCAPE] = 0; + engine->keyState[SDL_SCANCODE_ESCAPE] = 0; while (true) { @@ -238,7 +237,7 @@ void Graphics::delay(int time) engine->getInput(); /* - if (engine->keyState[SDLK_ESCAPE]) + if (engine->keyState[SDL_SCANCODE_ESCAPE]) { break; } @@ -358,7 +357,7 @@ SDL_Surface *Graphics::loadImage(const char *filename, bool srcalpha) if (!image) showErrorAndExit(ERR_FILE, filename); - newImage = SDL_DisplayFormat(image); + newImage = SDL_ConvertSurface(image, screen->format, 0); if (newImage) { @@ -371,7 +370,7 @@ SDL_Surface *Graphics::loadImage(const char *filename, bool srcalpha) } if(srcalpha) - SDL_SetAlpha(newImage, SDL_SRCALPHA, 255); + SDL_SetSurfaceAlphaMod(newImage, 255); else setTransparent(newImage); @@ -431,7 +430,7 @@ SDL_Surface *Graphics::loadImage(const char *filename, int hue, int sat, int val } } - newImage = SDL_DisplayFormat(image); + newImage = SDL_ConvertSurface(image, screen->format, 0); if (newImage) { @@ -458,7 +457,7 @@ SDL_Surface *Graphics::quickSprite(const char *name, SDL_Surface *image) void Graphics::fade(int amount) { - SDL_SetAlpha(fadeBlack, SDL_SRCALPHA|SDL_RLEACCEL, amount); + SDL_SetSurfaceAlphaMod(fadeBlack, amount); blit(fadeBlack, 0, 0, screen, false); } @@ -468,7 +467,7 @@ void Graphics::fadeToBlack() while (start < 50) { - SDL_SetAlpha(fadeBlack, SDL_SRCALPHA|SDL_RLEACCEL, start); + SDL_SetSurfaceAlphaMod(fadeBlack, start); blit(fadeBlack, 0, 0, screen, false); delay(60); start++; @@ -520,7 +519,7 @@ void Graphics::loadMapTiles(const char *baseDir) { if ((i < MAP_EXITSIGN) || (i >= MAP_WATERANIM)) { - SDL_SetAlpha(tile[i], SDL_SRCALPHA|SDL_RLEACCEL, 130); + SDL_SetSurfaceAlphaMod(tile[i], 130); } } else @@ -863,8 +862,6 @@ void Graphics::setFontColor(int red, int green, int blue, int red2, int green2, fontBackground.r = red2; fontBackground.g = green2; fontBackground.b = blue2; - - fontForeground.unused = fontBackground.unused = 0; } void Graphics::setFontSize(int size) @@ -1067,7 +1064,7 @@ SDL_Surface *Graphics::createSurface(int width, int height) if (surface == NULL) showErrorAndExit("CreateRGBSurface failed: %s\n", SDL_GetError()); - newImage = SDL_DisplayFormat(surface); + newImage = SDL_ConvertSurface(surface, screen->format, 0); SDL_FreeSurface(surface); @@ -1080,7 +1077,7 @@ SDL_Surface *Graphics::alphaRect(int width, int height, Uint8 red, Uint8 green, SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, red, green, blue)); - SDL_SetAlpha(surface, SDL_SRCALPHA|SDL_RLEACCEL, 130); + SDL_SetSurfaceAlphaMod(surface, 130); return surface; } @@ -1091,7 +1088,7 @@ void Graphics::colorize(SDL_Surface *image, int red, int green, int blue) blit(alpha, 0, 0, image, false); - SDL_SetColorKey(image, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(image->format, red / 2, green / 2, blue / 2)); + SDL_SetColorKey(image, SDL_RLEACCEL, SDL_MapRGB(image->format, red / 2, green / 2, blue / 2)); } void Graphics::lock(SDL_Surface *surface) @@ -1156,7 +1153,7 @@ void Graphics::showLicenseErrorAndExit() { updateScreen(); engine->getInput(); - if (engine->keyState[SDLK_ESCAPE]) + if (engine->keyState[SDL_SCANCODE_ESCAPE]) exit(1); SDL_Delay(16); } @@ -1203,7 +1200,7 @@ void Graphics::showErrorAndExit(const char *error, const char *param) { updateScreen(); engine->getInput(); - if (engine->keyState[SDLK_ESCAPE]) + if (engine->keyState[SDL_SCANCODE_ESCAPE]) { exit(1); } @@ -1232,11 +1229,11 @@ void Graphics::showRootWarning() updateScreen(); engine->getInput(); - if (engine->keyState[SDLK_ESCAPE]) + if (engine->keyState[SDL_SCANCODE_ESCAPE]) { return; } - else if (engine->keyState[SDLK_SPACE]) + else if (engine->keyState[SDL_SCANCODE_SPACE]) { exit(0); } diff --git a/src/CGraphics.h b/src/CGraphics.h index 14df0ef..2070ce5 100644 --- a/src/CGraphics.h +++ b/src/CGraphics.h @@ -57,6 +57,9 @@ class Graphics { bool takeRandomScreenShots; + SDL_Window *window; + SDL_Renderer *renderer; + SDL_Texture *texture; SDL_Surface *screen, *background; SDL_Surface *tile[MAX_TILES]; diff --git a/src/CKeyboard.cpp b/src/CKeyboard.cpp index 8f2287a..ddc0eca 100644 --- a/src/CKeyboard.cpp +++ b/src/CKeyboard.cpp @@ -27,15 +27,15 @@ Keyboard::Keyboard() void Keyboard::setDefaultKeys() { - control[CONTROL::LEFT] = SDLK_LEFT; - control[CONTROL::RIGHT] = SDLK_RIGHT; - control[CONTROL::DOWN] = SDLK_DOWN; - control[CONTROL::JUMP] = SDLK_UP; + control[CONTROL::LEFT] = SDL_SCANCODE_LEFT; + control[CONTROL::RIGHT] = SDL_SCANCODE_RIGHT; + control[CONTROL::DOWN] = SDL_SCANCODE_DOWN; + control[CONTROL::JUMP] = SDL_SCANCODE_UP; control[CONTROL::UP] = 0; - control[CONTROL::FIRE] = SDLK_LCTRL; - control[CONTROL::JETPACK] = SDLK_SPACE; - control[CONTROL::PAUSE] = SDLK_p; - control[CONTROL::MAP] = SDLK_TAB; + control[CONTROL::FIRE] = SDL_SCANCODE_LCTRL; + control[CONTROL::JETPACK] = SDL_SCANCODE_SPACE; + control[CONTROL::PAUSE] = SDL_SCANCODE_P; + control[CONTROL::MAP] = SDL_SCANCODE_TAB; } const char *Keyboard::translateKey(int key) @@ -49,7 +49,7 @@ const char *Keyboard::translateKey(int key) return "..."; } - strlcpy(keyName, _(SDL_GetKeyName((SDLKey)key)), sizeof keyName); + strlcpy(keyName, _(SDL_GetKeyName(key)), sizeof keyName); /* This is not really neccessary, but it just makes @@ -63,7 +63,7 @@ const char *Keyboard::translateKey(int key) while (*c != '\0') { - if ((*c >= SDLK_a) && (*c <= SDLK_z)) + if ((*c >= SDL_SCANCODE_A) && (*c <= SDL_SCANCODE_Z)) { if (uppercase) { @@ -71,7 +71,7 @@ const char *Keyboard::translateKey(int key) uppercase = false; } } - else if (*c == SDLK_SPACE) + else if (*c == SDL_SCANCODE_SPACE) { uppercase = true; } diff --git a/src/cutscene.cpp b/src/cutscene.cpp index 3a1a30a..75baa4d 100644 --- a/src/cutscene.cpp +++ b/src/cutscene.cpp @@ -135,7 +135,7 @@ void showScene(bool allowSkip) float panelAlpha = 0; - SDL_SetAlpha(panel, SDL_SRCALPHA|SDL_RLEACCEL, 0); + SDL_SetSurfaceAlphaMod(panel, 0); engine.clearInput(); engine.flushInput(); @@ -164,10 +164,10 @@ void showScene(bool allowSkip) if (panelAlpha < 256) { panelAlpha += (1 * engine.getTimeDifference()); - SDL_SetAlpha(panel, SDL_SRCALPHA|SDL_RLEACCEL, (int)panelAlpha); + SDL_SetSurfaceAlphaMod(panel, panelAlpha); if (image != NULL) { - SDL_SetAlpha(image, SDL_SRCALPHA|SDL_RLEACCEL, (int)panelAlpha); + SDL_SetSurfaceAlphaMod(image, panelAlpha); graphics.blit(image, 0, 0, graphics.screen, false); } graphics.blit(panel, 0, 390, graphics.screen, false); diff --git a/src/galdov.cpp b/src/galdov.cpp index c4bb3f5..22f936e 100644 --- a/src/galdov.cpp +++ b/src/galdov.cpp @@ -474,8 +474,8 @@ void galdovInit() Math::addBit(&map.boss[0]->flags, ENT_AIMS); - SDL_SetAlpha(graphics.getSprite("GaldovInvsLeft", true)->image[0], SDL_SRCALPHA|SDL_RLEACCEL, 100); - SDL_SetAlpha(graphics.getSprite("GaldovInvsRight", true)->image[0], SDL_SRCALPHA|SDL_RLEACCEL, 100); + SDL_SetSurfaceAlphaMod(graphics.getSprite("GaldovInvsLeft", true)->image[0], 100); + SDL_SetSurfaceAlphaMod(graphics.getSprite("GaldovInvsRight", true)->image[0], 100); for (int i = 1 ; i < 10 ; i++) { diff --git a/src/game.cpp b/src/game.cpp index b003da3..6f5a970 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -99,9 +99,9 @@ void showInGameOptions() engine.getInput(); config.populate(); - if ((config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDLK_ESCAPE])) + if ((config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDL_SCANCODE_ESCAPE])) { - engine.keyState[SDLK_ESCAPE] = 0; + engine.keyState[SDL_SCANCODE_ESCAPE] = 0; config.resetControl(CONTROL::PAUSE); break; } @@ -276,11 +276,6 @@ void doGameStuff() doParticles(); - if ((SDL_GetAppState() & SDL_APPINPUTFOCUS) == 0) - { - engine.paused = true; - } - replayData.set(config.command); replayData.commit(); } @@ -386,7 +381,7 @@ void showMissionInformation() SDL_Surface *panel = graphics.createSurface(400, 300); SDL_Surface *panelBack = graphics.alphaRect(400, 300, 0x00, 0x00, 0x00); - SDL_SetColorKey(panel, (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(panel->format, 0, 0, 0)); + SDL_SetColorKey(panel, SDL_RLEACCEL, SDL_MapRGB(panel->format, 0, 0, 0)); graphics.drawRect(1, 1, 398, 298, graphics.black, graphics.white, panelBack); @@ -689,7 +684,7 @@ int doGame() doStatusBar(); doMusicInfo(cur - start); - if ((engine.keyState[SDLK_ESCAPE]) && (game.missionOver == 0)) + if ((engine.keyState[SDL_SCANCODE_ESCAPE]) && (game.missionOver == 0)) { if (replayData.replayMode == REPLAY_MODE::NONE) { @@ -810,15 +805,15 @@ int doGame() SDL_Delay(16); } - if ((engine.keyState[SDLK_F3]) && (engine.cheatSkipLevel)) + if ((engine.keyState[SDL_SCANCODE_F3]) && (engine.cheatSkipLevel)) { autoCompleteAllObjectives(true); - engine.keyState[SDLK_F3] = 0; + engine.keyState[SDL_SCANCODE_F3] = 0; engine.setInfoMessage("Skipping Mission...", 2, INFO_OBJECTIVE); } #if DEBUG - if (engine.keyState[SDLK_F1]) + if (engine.keyState[SDL_SCANCODE_F1]) { autoCompleteAllObjectives(false); } @@ -833,10 +828,10 @@ int doGame() engine.delay(frameLimit); } - if (engine.keyState[SDLK_F5]) + if (engine.keyState[SDL_SCANCODE_F5]) { replayData.fast = !replayData.fast; - engine.keyState[SDLK_F5] = 0; + engine.keyState[SDL_SCANCODE_F5] = 0; } frameLimit = SDL_GetTicks() + 16; diff --git a/src/headers.h b/src/headers.h index 0d620e1..510447e 100644 --- a/src/headers.h +++ b/src/headers.h @@ -37,11 +37,11 @@ extern C_LINKAGE void openHelpURL(); extern DECLSPEC int SDLCALL SDL_GetGamma(float *red, float *green, float *blue); #endif #else -#include "SDL/SDL.h" -#include "SDL/SDL_image.h" -#include "SDL/SDL_mixer.h" -#include "SDL/SDL_ttf.h" -#include "SDL/SDL_net.h" +#include "SDL2/SDL.h" +#include "SDL2/SDL_image.h" +#include "SDL2/SDL_mixer.h" +#include "SDL2/SDL_ttf.h" +#include "SDL2/SDL_net.h" #endif #ifndef WIN32 diff --git a/src/hub.cpp b/src/hub.cpp index 6d99f7c..859c23c 100644 --- a/src/hub.cpp +++ b/src/hub.cpp @@ -742,7 +742,7 @@ int doHub() // Collisions for Panel Buttons if ((showMIAs) || (showStats)) { - // SDLK_LCTRL is the "fire" button. + // SDL_SCANCODE_LCTRL is the "fire" button. if (engine.mouseLeft || config.isControl(CONTROL::FIRE)) { if (Collision::collision(engine.getMouseX(), engine.getMouseY(), 1, 1, 270, 310, 32, 32)) diff --git a/src/init.cpp b/src/init.cpp index bf5fa20..126fb79 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -80,7 +80,7 @@ void showLicense() graphics.updateScreen(); engine.getInput(); config.populate(); - if (engine.keyState[SDLK_SPACE]) + if (engine.keyState[SDL_SCANCODE_SPACE]) break; SDL_Delay(16); } @@ -278,16 +278,15 @@ void initSystem() exit(1); } - if (!engine.fullScreen) - { - graphics.screen = SDL_SetVideoMode(640, 480, 0, SDL_DOUBLEBUF | SDL_HWPALETTE); - } - else - { - graphics.screen = SDL_SetVideoMode(640, 480, 0, SDL_DOUBLEBUF | SDL_HWPALETTE | SDL_FULLSCREEN); - } + graphics.screen = SDL_CreateRGBSurface(0, 640, 480, 32, 0xff0000, 0xff00, 0xff, 0xff000000); - if (graphics.screen == NULL) + graphics.window = SDL_CreateWindow("Blobwars: Metal Blob Solid", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, graphics.screen->w, graphics.screen->h, 0); + SDL_SetWindowFullscreen(graphics.window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + graphics.renderer = SDL_CreateRenderer(graphics.window, -1, 0); + SDL_RenderSetLogicalSize(graphics.renderer, graphics.screen->w, graphics.screen->h); + graphics.texture = SDL_CreateTexture(graphics.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, graphics.screen->w, graphics.screen->h); + + if (graphics.window == NULL) { printf("Couldn't set 640x480 video mode: %s\n", SDL_GetError()); exit(1); @@ -295,12 +294,14 @@ void initSystem() // This (attempts to) set the gamma correction. We attempt to catch an error here // in case someone has done something really stupid in the config file(!!) - if (game.brightness != -1) { - Math::limitInt(&game.brightness, 1, 20); - float brightness = game.brightness; - brightness /= 10; - SDL_SetGamma(brightness, brightness, brightness); - } + if (game.brightness != -1) { + Math::limitInt(&game.brightness, 1, 20); + float brightness = game.brightness; + brightness /= 10; + uint16_t ramp[256]; + SDL_CalculateGammaRamp(brightness, ramp); + SDL_SetWindowGammaRamp(graphics.window, ramp, ramp, ramp); + } if (TTF_Init() < 0) { @@ -383,12 +384,6 @@ void initSystem() SDL_Surface *device = graphics.loadImage("gfx/main/alienDevice.png"); -#ifndef FRAMEWORK_SDL - SDL_WM_SetIcon(device, NULL); -#endif - SDL_WM_SetCaption("Blob Wars : Metal Blob Solid", "Blob Wars"); - SDL_EnableKeyRepeat(350, 80); - SDL_FreeSurface(device); if (strstr(engine.userHomeDirectory, "/root")) @@ -411,7 +406,7 @@ void initSystem() } else { - SDL_Thread *thread = SDL_CreateThread(initMedalService, NULL); + SDL_Thread *thread = SDL_CreateThread(initMedalService, "MedalService", NULL); if (thread == NULL) { @@ -475,7 +470,7 @@ void cleanup() SDL_JoystickEventState(SDL_DISABLE); for (int i = 0 ; i < SDL_NumJoysticks() ; i++) { - debug(("Closing Joystick #%d - %s...\n", i, SDL_JoystickName(i))); + debug(("Closing Joystick #%d\n", i)); SDL_JoystickClose(config.sdlJoystick); } } diff --git a/src/intro.cpp b/src/intro.cpp index d111330..2f12f42 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -109,7 +109,7 @@ void showIntroError() graphics.updateScreen(); engine.getInput(); config.populate(); - if (engine.keyState[SDLK_ESCAPE]) + if (engine.keyState[SDL_SCANCODE_ESCAPE]) break; SDL_Delay(16); } diff --git a/src/map.cpp b/src/map.cpp index 4a72b85..07eb4aa 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -293,7 +293,7 @@ void showMap(int centerX, int centerY) SDL_Surface *panel = graphics.createSurface(320, 240); SDL_Surface *background = graphics.loadImage("gfx/main/mapBackground.png"); - SDL_SetAlpha(background, SDL_SRCALPHA|SDL_RLEACCEL, 130); + SDL_SetSurfaceAlphaMod(background, 130); graphics.blit(background, 0, 0, panel, false); @@ -412,7 +412,7 @@ void showMap(int centerX, int centerY) graphics.drawRect(160, 120, 320, 240, graphics.black, graphics.white, graphics.screen); graphics.blit(panel, 160, 120, graphics.screen, false); - if ((config.isControl(CONTROL::MAP)) || (config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDLK_ESCAPE])) + if ((config.isControl(CONTROL::MAP)) || (config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDL_SCANCODE_ESCAPE])) { break; } diff --git a/src/mapData.cpp b/src/mapData.cpp index 571632b..a617a02 100644 --- a/src/mapData.cpp +++ b/src/mapData.cpp @@ -284,7 +284,7 @@ void getMapTokens() debug(("Setting Alpha for Tile %d\n", param[0])); - SDL_SetAlpha(graphics.tile[param[0]], SDL_SRCALPHA|SDL_RLEACCEL, 130); + SDL_SetSurfaceAlphaMod(graphics.tile[param[0]], 130); while (true) { diff --git a/src/mapEditor.cpp b/src/mapEditor.cpp index bffe1c7..a74ee7a 100644 --- a/src/mapEditor.cpp +++ b/src/mapEditor.cpp @@ -61,7 +61,7 @@ void showMap(int *mapX, int *mapY) { SDL_FillRect(graphics.screen, NULL, graphics.black); - engine.keyState[SDLK_SPACE] = 0; + engine.keyState[SDL_SCANCODE_SPACE] = 0; int moveTimer = 0; while (true) @@ -70,7 +70,7 @@ void showMap(int *mapX, int *mapY) engine.getInput(); config.populate(); - if (engine.keyState[SDLK_SPACE]) + if (engine.keyState[SDL_SCANCODE_SPACE]) break; for (int x = 0 ; x < MAPWIDTH ; x++) @@ -100,16 +100,16 @@ void showMap(int *mapX, int *mapY) if (moveTimer == 0) { - if (engine.keyState[SDLK_LEFT]) + if (engine.keyState[SDL_SCANCODE_LEFT]) *mapX -= 1; - if (engine.keyState[SDLK_RIGHT]) + if (engine.keyState[SDL_SCANCODE_RIGHT]) *mapX += 1; - if (engine.keyState[SDLK_UP]) + if (engine.keyState[SDL_SCANCODE_UP]) *mapY -= 1; - if (engine.keyState[SDLK_DOWN]) + if (engine.keyState[SDL_SCANCODE_DOWN]) *mapY += 1; } @@ -124,7 +124,7 @@ void showMap(int *mapX, int *mapY) SDL_Delay(16); } - engine.keyState[SDLK_SPACE] = 0; + engine.keyState[SDL_SCANCODE_SPACE] = 0; } int nextBlock(int current, int dir) @@ -364,7 +364,7 @@ void addTileDecoration() } } - engine.keyState[SDLK_F1] = 0; + engine.keyState[SDL_SCANCODE_F1] = 0; } void fillHorizontal(int block, int x, int y) @@ -551,26 +551,26 @@ int main(int argc, char *argv[]) if (allowMove == 0) { - if (engine.keyState[SDLK_UP]) {mapY--; allowMove = MOVESPEED;} - if (engine.keyState[SDLK_DOWN]) {mapY++; allowMove = MOVESPEED;} - if (engine.keyState[SDLK_LEFT]) {mapX--; allowMove = MOVESPEED;} - if (engine.keyState[SDLK_RIGHT]) {mapX++; allowMove = MOVESPEED;} + if (engine.keyState[SDL_SCANCODE_UP]) {mapY--; allowMove = MOVESPEED;} + if (engine.keyState[SDL_SCANCODE_DOWN]) {mapY++; allowMove = MOVESPEED;} + if (engine.keyState[SDL_SCANCODE_LEFT]) {mapX--; allowMove = MOVESPEED;} + if (engine.keyState[SDL_SCANCODE_RIGHT]) {mapX++; allowMove = MOVESPEED;} - if (engine.keyState[SDLK_PAGEDOWN]) {mapY += 10; allowMove = MOVESPEED;} - if (engine.keyState[SDLK_PAGEUP]) {mapY -= 10; allowMove = MOVESPEED;} + if (engine.keyState[SDL_SCANCODE_PAGEDOWN]) {mapY += 10; allowMove = MOVESPEED;} + if (engine.keyState[SDL_SCANCODE_PAGEUP]) {mapY -= 10; allowMove = MOVESPEED;} - if (engine.keyState[SDLK_1]) editing = 0; - if (engine.keyState[SDLK_2]) editing = 1; - if (engine.keyState[SDLK_3]) editing = 2; + if (engine.keyState[SDL_SCANCODE_1]) editing = 0; + if (engine.keyState[SDL_SCANCODE_2]) editing = 1; + if (engine.keyState[SDL_SCANCODE_3]) editing = 2; - if (engine.keyState[SDLK_0]) fillHorizontal(currentBlock, mapX + x, mapY + y); + if (engine.keyState[SDL_SCANCODE_0]) fillHorizontal(currentBlock, mapX + x, mapY + y); - if (engine.keyState[SDLK_F1]) addTileDecoration(); + if (engine.keyState[SDL_SCANCODE_F1]) addTileDecoration(); - if (engine.keyState[SDLK_ESCAPE]) break; + if (engine.keyState[SDL_SCANCODE_ESCAPE]) break; } - if (engine.keyState[SDLK_PERIOD]) + if (engine.keyState[SDL_SCANCODE_PERIOD]) { switch (editing) { @@ -585,10 +585,10 @@ int main(int argc, char *argv[]) break; } - engine.keyState[SDLK_PERIOD] = 0; + engine.keyState[SDL_SCANCODE_PERIOD] = 0; } - if (engine.keyState[SDLK_COMMA]) + if (engine.keyState[SDL_SCANCODE_COMMA]) { switch (editing) { @@ -603,7 +603,7 @@ int main(int argc, char *argv[]) break; } - engine.keyState[SDLK_COMMA] = 0; + engine.keyState[SDL_SCANCODE_COMMA] = 0; } Math::limitInt(¤tMonster, 0, MAX_ENEMIES - 1); @@ -615,9 +615,9 @@ int main(int argc, char *argv[]) if (defItem[currentItem].sprite[0] == NULL) currentItem = 0; - if (engine.keyState[SDLK_SPACE]) {showMap(&mapX, &mapY);} + if (engine.keyState[SDL_SCANCODE_SPACE]) {showMap(&mapX, &mapY);} - if (engine.keyState[SDLK_s]) {saveMap(game.mapName); engine.keyState[SDLK_s] = 0;} + if (engine.keyState[SDL_SCANCODE_s]) {saveMap(game.mapName); engine.keyState[SDL_SCANCODE_s] = 0;} if (mapX < 0) mapX = 0; if (mapY < 0) mapY = 0; diff --git a/src/mission.cpp b/src/mission.cpp index 8b362a5..983b47b 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -162,7 +162,7 @@ void showMissionClear() graphics.loadBackground("gfx/main/areaClearBackGround.jpg"); SDL_Surface *panel = graphics.alphaRect(550, 420, 0x00, 0x00, 0x00); - SDL_SetAlpha(panel, SDL_SRCALPHA|SDL_RLEACCEL, 180); + SDL_SetSurfaceAlphaMod(panel, 180); graphics.drawRect(1, 1, panel->w - 2, panel->h - 2 , graphics.black, graphics.white, panel); graphics.blit(panel, (640 - panel->w) / 2, (480 - panel->h) / 2, graphics.background, false); diff --git a/src/options.cpp b/src/options.cpp index b1989bb..3d5014a 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -75,7 +75,7 @@ void showCheatConfig() drawWidgets(); } - if (engine.keyState[SDLK_ESCAPE]) + if (engine.keyState[SDL_SCANCODE_ESCAPE]) { engine.clearInput(); engine.flushInput(); @@ -163,7 +163,7 @@ void showKeyConfig() defaults = 0; } - if (engine.keyState[SDLK_ESCAPE]) + if (engine.keyState[SDL_SCANCODE_ESCAPE]) { engine.clearInput(); engine.flushInput(); @@ -247,7 +247,7 @@ void showJoystickConfig() graphics.blit(header, 320, 25, graphics.screen, true); drawWidgets(); - if (engine.keyState[SDLK_ESCAPE]) + if (engine.keyState[SDL_SCANCODE_ESCAPE]) { engine.clearInput(); engine.flushInput(); @@ -365,15 +365,17 @@ void showOptions() audio.setMusicVolume(game.musicVol); if (engine.widgetChanged("fullscreen")) - SDL_WM_ToggleFullScreen(graphics.screen); + SDL_SetWindowFullscreen(graphics.window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); if (engine.widgetChanged("gamma")) { brightness = game.brightness; - if (brightness > 0) { - brightness /= 10; - SDL_SetGamma(brightness, brightness, brightness); - } + if (brightness > 0) { + brightness /= 10; + uint16_t ramp[256]; + SDL_CalculateGammaRamp(brightness, ramp); + SDL_SetWindowGammaRamp(graphics.window, ramp, ramp, ramp); + } } if ((joysticks) || (cheats) || (keys)) @@ -428,7 +430,7 @@ void showOptions() drawWidgets(); } - if (engine.keyState[SDLK_ESCAPE]) + if (engine.keyState[SDL_SCANCODE_ESCAPE]) { engine.clearInput(); engine.flushInput(); diff --git a/src/player.cpp b/src/player.cpp index 34aeaa8..8a0c36f 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -68,7 +68,7 @@ void presentPlayerMedal(const char *tname) char *data = new char[128]; strlcpy(data, tname, 128); - SDL_Thread *thread = SDL_CreateThread(medalWorker, (void*)data); + SDL_Thread *thread = SDL_CreateThread(medalWorker, "MedalWorker", (void*)data); if (thread == NULL) { @@ -430,15 +430,15 @@ void doPlayer() } #if DEBUG - if (engine.keyState[SDLK_1]) + if (engine.keyState[SDL_SCANCODE_1]) player.currentWeapon = &weapon[WP_PISTOL]; - else if (engine.keyState[SDLK_2]) + else if (engine.keyState[SDL_SCANCODE_2]) player.currentWeapon = &weapon[WP_MACHINEGUN]; - else if (engine.keyState[SDLK_3]) + else if (engine.keyState[SDL_SCANCODE_3]) player.currentWeapon = &weapon[WP_GRENADES]; - else if (engine.keyState[SDLK_4]) + else if (engine.keyState[SDL_SCANCODE_4]) player.currentWeapon = &weapon[WP_LASER]; - else if (engine.keyState[SDLK_5]) + else if (engine.keyState[SDL_SCANCODE_5]) player.currentWeapon = &weapon[WP_SPREAD]; #endif diff --git a/src/title.cpp b/src/title.cpp index db3faa8..7b5e050 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -197,12 +197,12 @@ int title() snprintf(v, sizeof v, _("Version %s"), STRINGIFY_VALUE(VERSION)); SDL_Surface *version = graphics.quickSprite("Version", graphics.getString(v, true)); - SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, 0); + SDL_SetSurfaceAlphaMod(title, 0); audio.loadMusic("music/title"); graphics.loadBackground("gfx/main/CircuitBoard.jpg"); - SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, 0); + SDL_SetSurfaceAlphaMod(graphics.background, 0); int startNewGame, options, quit, help, easy, normal, hard, extreme, back, practice; int load, cont, save[5], slot[6]; @@ -268,8 +268,8 @@ int title() engine.clearInput(); backAlpha = 255; titleAlpha = 255; - SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, (int)backAlpha); - SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, (int)titleAlpha); + SDL_SetSurfaceAlphaMod(graphics.background, backAlpha); + SDL_SetSurfaceAlphaMod(title, titleAlpha); } } @@ -278,7 +278,7 @@ int title() if (backAlpha < 255) { backAlpha++; - SDL_SetAlpha(graphics.background, SDL_SRCALPHA|SDL_RLEACCEL, (int)backAlpha); + SDL_SetSurfaceAlphaMod(graphics.background, backAlpha); } } @@ -287,7 +287,7 @@ int title() if (titleAlpha < 255) { titleAlpha++; - SDL_SetAlpha(title, SDL_SRCALPHA|SDL_RLEACCEL, (int)titleAlpha); + SDL_SetSurfaceAlphaMod(title, titleAlpha); } else { @@ -389,7 +389,7 @@ int title() if (save[3]) {load = 4; break;} if (save[4]) {load = 5; break;} - if (engine.keyState[SDLK_ESCAPE]) + if (engine.keyState[SDL_SCANCODE_ESCAPE]) { audio.playMenuSound(2); back = 1; -- 2.39.5