summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-21 14:37:03 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-24 21:08:14 +0300
commitec1beaa2ee07368368e9bd45fe400eedc57419eb (patch)
treec8f4792dc2316c7cc852bcf6738dff7557d9b872 /src
parent8d4af08b165e10d7e82380074ce733ee9d068c6a (diff)
downloadManaVerse-ec1beaa2ee07368368e9bd45fe400eedc57419eb.tar.gz
ManaVerse-ec1beaa2ee07368368e9bd45fe400eedc57419eb.tar.bz2
ManaVerse-ec1beaa2ee07368368e9bd45fe400eedc57419eb.tar.xz
ManaVerse-ec1beaa2ee07368368e9bd45fe400eedc57419eb.zip
first part of fixes for compilation with SDL2
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp15
-rw-r--r--src/compoundsprite.cpp5
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/graphics.cpp14
-rw-r--r--src/gui/gui.cpp5
-rw-r--r--src/gui/sdlfont.cpp8
-rw-r--r--src/gui/viewport.cpp1
-rw-r--r--src/gui/whoisonline.cpp5
-rw-r--r--src/keyboardconfig.h1
-rw-r--r--src/net/download.cpp4
-rw-r--r--src/net/ea/network.cpp4
-rw-r--r--src/net/sdltcpnet.cpp2
-rw-r--r--src/net/sdltcpnet.h2
-rw-r--r--src/resources/atlasmanager.cpp4
-rw-r--r--src/resources/image.cpp7
-rw-r--r--src/resources/imagehelper.cpp4
-rw-r--r--src/resources/openglimagehelper.cpp4
-rw-r--r--src/resources/sdlimagehelper.cpp13
-rw-r--r--src/resources/sdlmusic.cpp4
-rw-r--r--src/utils/copynpaste.cpp3
20 files changed, 102 insertions, 5 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 5551bd312..38fc440f9 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -296,8 +296,13 @@ Client::Client(const Options &options) :
mState(STATE_CHOOSE_SERVER),
mOldState(STATE_START),
mIcon(nullptr),
+#ifdef USE_SDL2
+ mLogicCounterId(0),
+ mSecondsCounterId(0),
+#else
mLogicCounterId(nullptr),
mSecondsCounterId(nullptr),
+#endif
mCaption(),
mFpsManager(),
mSkin(nullptr),
@@ -452,11 +457,15 @@ void Client::gameInit()
atexit(SDL_Quit);
initPacketLimiter();
+#ifndef USE_SDL2
SDL_EnableUNICODE(1);
+#endif
applyKeyRepeat();
// disable unused SDL events
+#ifndef USE_SDL2
SDL_EventState(SDL_VIDEOEXPOSE, SDL_IGNORE);
+#endif
SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE);
SDL_EventState(SDL_USEREVENT, SDL_IGNORE);
@@ -575,7 +584,11 @@ void Client::gameInit()
mIcon = IMG_Load(iconFile.c_str());
if (mIcon)
{
+#ifdef USE_SDL2
+ SDL_SetSurfaceAlphaMod(mIcon, 255);
+#else
SDL_SetAlpha(mIcon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
+#endif
SDL_WM_SetIcon(mIcon, nullptr);
}
#endif
@@ -2874,8 +2887,10 @@ void Client::applyVSync()
void Client::applyKeyRepeat()
{
+#ifndef USE_SDL2
SDL_EnableKeyRepeat(config.getIntValue("repeateDelay"),
config.getIntValue("repeateInterval"));
+#endif
}
void Client::setIsMinimized(const bool n)
diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp
index 0d649e48e..d0bf9bc31 100644
--- a/src/compoundsprite.cpp
+++ b/src/compoundsprite.cpp
@@ -31,6 +31,7 @@
#include "map.h"
#include "sdlgraphics.h"
+#include "sdlshared.h"
#include "resources/image.h"
#include "resources/imagehelper.h"
@@ -363,7 +364,11 @@ void CompoundSprite::redraw() const
SDL_Surface *const surfaceA = SDL_CreateRGBSurface(SDL_HWSURFACE,
BUFFER_WIDTH, BUFFER_HEIGHT, 32, rmask, gmask, bmask, amask);
+#ifdef USE_SDL2
+ SDL_SetSurfaceAlphaMod(surface, 255);
+#else
SDL_SetAlpha(surface, 0, SDL_ALPHA_OPAQUE);
+#endif
SDL_BlitSurface(surface, nullptr, surfaceA, nullptr);
delete mImage;
diff --git a/src/defaults.cpp b/src/defaults.cpp
index b9a522bff..2aa3e8ad5 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -271,9 +271,11 @@ DefaultsData* getConfigDefaults()
#endif
AddDEF("audioFrequency", 22010);
AddDEF("audioChannels", 2);
+#ifndef USE_SDL2
AddDEF("repeateDelay", SDL_DEFAULT_REPEAT_DELAY);
AddDEF("repeateInterval", SDL_DEFAULT_REPEAT_INTERVAL);
AddDEF("repeateInterval2", SDL_DEFAULT_REPEAT_DELAY);
+#endif
AddDEF("compresstextures", 0);
AddDEF("rectangulartextures", true);
AddDEF("networksleep", 0);
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 0b4e9be15..51c2c4a24 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -106,6 +106,11 @@ void Graphics::setMainFlags(const int w, const int h, const int bpp,
int Graphics::getOpenGLFlags() const
{
#ifdef USE_OPENGL
+#ifdef USE_SDL2
+ int displayFlags = SDL_WINDOW_OPENGL;
+ if (mFullscreen)
+ displayFlags |= SDL_WINDOW_FULLSCREEN;
+#else
int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
if (mFullscreen)
@@ -126,6 +131,7 @@ int Graphics::getOpenGLFlags() const
displayFlags |= SDL_NOFRAME;
return displayFlags;
+#endif
#else
return 0;
#endif
@@ -193,6 +199,12 @@ bool Graphics::setOpenGLMode()
int Graphics::getSoftwareFlags() const
{
+#ifdef USE_SDL2
+ int displayFlags = 0;
+
+ if (mFullscreen)
+ displayFlags |= SDL_FULLSCREEN;
+#else
int displayFlags = SDL_ANYFORMAT;
if (mFullscreen)
@@ -207,7 +219,7 @@ int Graphics::getSoftwareFlags() const
if (mNoFrame)
displayFlags |= SDL_NOFRAME;
-
+#endif
return displayFlags;
}
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2a838069b..8d96cfde3 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -437,8 +437,13 @@ void Gui::draw()
int mouseX, mouseY;
const uint8_t button = SDL_GetMouseState(&mouseX, &mouseY);
+#ifdef USE_SDL2
+ if (button & SDL_BUTTON(1) && mMouseCursors && mCustomCursor
+ && mMouseCursorAlpha > 0.0f)
+#else
if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1))
&& mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0f)
+#endif
{
Graphics *g2 = static_cast<Graphics*>(mGraphics);
const Image *const image = dragDrop.getItemImage();
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index 2e974f6d8..b1e0092d7 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -137,7 +137,11 @@ void SDLTextChunk::generate(TTF_Font *const font, const float alpha)
sdlCol.b = static_cast<uint8_t>(color.b);
sdlCol.r = static_cast<uint8_t>(color.r);
sdlCol.g = static_cast<uint8_t>(color.g);
+#ifdef USE_SDL2
+ sdlCol.a = 0;
+#else
sdlCol.unused = 0;
+#endif
getSafeUtf8String(text, strBuf);
@@ -170,7 +174,11 @@ void SDLTextChunk::generate(TTF_Font *const font, const float alpha)
sdlCol2.b = static_cast<uint8_t>(color2.b);
sdlCol2.r = static_cast<uint8_t>(color2.r);
sdlCol2.g = static_cast<uint8_t>(color2.g);
+#ifdef USE_SDL2
+ sdlCol2.a = 0;
+#else
sdlCol2.unused = 0;
+#endif
SDL_Surface *const surface2 = TTF_RenderUTF8_Blended(
font, strBuf, sdlCol2);
if (!surface2)
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 34a24e2aa..fe5238e41 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -31,6 +31,7 @@
#include "keyboardconfig.h"
#include "localplayer.h"
#include "playerinfo.h"
+#include "sdlshared.h"
#include "textmanager.h"
#include "gui/beingpopup.h"
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index 741e1e771..7036ac7d0 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -581,7 +581,12 @@ void WhoIsOnline::download()
SDL_WaitThread(mThread, nullptr);
mDownloadComplete = false;
+#ifdef USE_SDL2
+ mThread = SDL_CreateThread(WhoIsOnline::downloadThread,
+ "whoisonline", this);
+#else
mThread = SDL_CreateThread(WhoIsOnline::downloadThread, this);
+#endif
if (mThread == nullptr)
mDownloadStatus = UPDATE_ERROR;
diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h
index 569ae95b5..0dbf19453 100644
--- a/src/keyboardconfig.h
+++ b/src/keyboardconfig.h
@@ -27,6 +27,7 @@
#include <SDL_keyboard.h>
#include "inputevent.h"
+#include "sdlshared.h"
#include <map>
#include <string>
diff --git a/src/net/download.cpp b/src/net/download.cpp
index a8f0e1c0c..f469a3258 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -169,7 +169,11 @@ bool Download::start()
{
logger->log("Starting download: %s", mUrl.c_str());
+#ifdef USE_SDL2
+ mThread = SDL_CreateThread(downloadThread, "download", this);
+#else
mThread = SDL_CreateThread(downloadThread, this);
+#endif
if (!mThread)
{
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 5214cf7e4..3bcda3db3 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -114,7 +114,11 @@ bool Network::connect(ServerInfo server)
mToSkip = 0;
mState = CONNECTING;
+#ifdef USE_SDL2
+ mWorkerThread = SDL_CreateThread(networkThread, "network", this);
+#else
mWorkerThread = SDL_CreateThread(networkThread, this);
+#endif
if (!mWorkerThread)
{
setError("Unable to create network worker thread");
diff --git a/src/net/sdltcpnet.cpp b/src/net/sdltcpnet.cpp
index 7b0d2700f..cb6d6145e 100644
--- a/src/net/sdltcpnet.cpp
+++ b/src/net/sdltcpnet.cpp
@@ -75,7 +75,7 @@ int TcpNet::send(const TcpNet::Socket sock, const void *const data,
return SDLNet_TCP_Send(sock, data, len);
}
-char *TcpNet::getError()
+const char *TcpNet::getError()
{
return SDLNet_GetError();
}
diff --git a/src/net/sdltcpnet.h b/src/net/sdltcpnet.h
index 1d83b04fc..e8772b4bd 100644
--- a/src/net/sdltcpnet.h
+++ b/src/net/sdltcpnet.h
@@ -40,7 +40,7 @@ namespace TcpNet
int send(const TcpNet::Socket sock, const void *const data, const int len);
- char *getError();
+ const char *getError();
int resolveHost(IPaddress *const address, const char *const host,
const Uint16 port);
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp
index 1d7147d72..1292baeb7 100644
--- a/src/resources/atlasmanager.cpp
+++ b/src/resources/atlasmanager.cpp
@@ -239,7 +239,11 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
if (image)
{
+#ifdef USE_SDL2
+ SDL_SetSurfaceAlphaMod(image->mSDLSurface, 255);
+#else
SDL_SetAlpha(image->mSDLSurface, 0, SDL_ALPHA_OPAQUE);
+#endif
graphics->drawImage(image, item->x, item->y);
}
}
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index c19d92d2d..f6d80e61e 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -245,8 +245,13 @@ void Image::setAlpha(const float alpha)
if (!mHasAlphaChannel)
{
// Set the alpha value this image is drawn at
+#ifdef USE_SDL2
+ SDL_SetSurfaceAlphaMod(mSDLSurface,
+ static_cast<unsigned char>(255 * mAlpha));
+#else
SDL_SetAlpha(mSDLSurface, SDL_SRCALPHA,
- static_cast<unsigned char>(255 * mAlpha));
+ static_cast<unsigned char>(255 * mAlpha));
+#endif
}
else
{
diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp
index 6a4a47505..cdd1672f6 100644
--- a/src/resources/imagehelper.cpp
+++ b/src/resources/imagehelper.cpp
@@ -62,8 +62,10 @@ SDL_Surface* ImageHelper::convertTo32Bit(SDL_Surface *const tmpImage)
return nullptr;
SDL_PixelFormat RGBAFormat;
RGBAFormat.palette = nullptr;
+#ifndef USE_SDL2
RGBAFormat.colorkey = 0;
RGBAFormat.alpha = 0;
+#endif
RGBAFormat.BitsPerPixel = 32;
RGBAFormat.BytesPerPixel = 4;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
@@ -102,7 +104,9 @@ void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image) const
{
const SDL_PixelFormat * const format = image->format;
logger->log("Bytes per pixel: %d", format->BytesPerPixel);
+#ifndef USE_SDL2
logger->log("Alpha: %d", format->alpha);
+#endif
logger->log("Loss: %02x, %02x, %02x, %02x",
static_cast<int>(format->Rloss), static_cast<int>(format->Gloss),
static_cast<int>(format->Bloss), static_cast<int>(format->Aloss));
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index 1180135a0..6aed74113 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -151,8 +151,12 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage,
tmpImage->w, tmpImage->h);
}
+#ifdef USE_SDL2
+ SDL_SetSurfaceAlphaMod(tmpImage, 255);
+#else
// Make sure the alpha channel is not used, but copied to destination
SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
+#endif
// Determine 32-bit masks based on byte order
uint32_t rmask, gmask, bmask, amask;
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index ab0b0663b..8f9d8b396 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -51,8 +51,10 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const
rgba.palette = nullptr;
rgba.BitsPerPixel = 32;
rgba.BytesPerPixel = 4;
+#ifndef USE_SDL2
rgba.colorkey = 0;
rgba.alpha = 255;
+#endif
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rgba.Rmask = 0x000000FF;
@@ -117,6 +119,10 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
Image *img;
bool hasAlpha = false;
+#ifdef USE_SDL2
+ uint8_t *alphaChannel = nullptr;
+ SDL_Surface *image = SDLDuplicateSurface(tmpImage);
+#else
const int sz = tmpImage->w * tmpImage->h;
// The alpha channel to be filled with alpha values
@@ -170,6 +176,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
delete [] alphaChannel;
return nullptr;
}
+#endif
img = new Image(image, hasAlpha, alphaChannel);
img->mAlpha = alpha;
@@ -190,6 +197,10 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const
return nullptr;
bool hasAlpha = false;
+#ifdef USE_SDL2
+ uint8_t *alphaChannel = nullptr;
+ SDL_Surface *image = tmpImage;
+#else
bool converted = false;
if (tmpImage->format->BitsPerPixel != 32)
@@ -269,7 +280,7 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const
if (converted)
SDL_FreeSurface(tmpImage);
-
+#endif
return new Image(image, hasAlpha, alphaChannel);
}
diff --git a/src/resources/sdlmusic.cpp b/src/resources/sdlmusic.cpp
index 5cadbd620..5f18d30d6 100644
--- a/src/resources/sdlmusic.cpp
+++ b/src/resources/sdlmusic.cpp
@@ -39,7 +39,11 @@ SDLMusic::~SDLMusic()
Resource *SDLMusic::load(SDL_RWops *const rw)
{
+#ifdef USE_SDL2
+ if (Mix_Music *const music = Mix_LoadMUS_RW(rw, 1))
+#else
if (Mix_Music *const music = Mix_LoadMUS_RW(rw))
+#endif
{
return new SDLMusic(music);
}
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp
index b2d241f16..1d4297fd5 100644
--- a/src/utils/copynpaste.cpp
+++ b/src/utils/copynpaste.cpp
@@ -339,6 +339,8 @@ static char* getSelection(Display *const dpy, Window us, Atom selection)
bool retrieveBuffer(std::string& text, size_t& pos)
{
+// +++ need use SDL_GetWindowWMInfo
+#ifndef USE_SDL2
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
@@ -376,6 +378,7 @@ bool retrieveBuffer(std::string& text, size_t& pos)
return true;
}
}
+#endif
return false;
}