@@ -6,13 +6,16 @@ AC_DEFUN([LOL_CHECK_SDL], | |||||
dnl Find which version of SDL to use (always required on Linux or Win32) | dnl Find which version of SDL to use (always required on Linux or Win32) | ||||
dnl | dnl | ||||
dnl Defined C/C++ macros: | dnl Defined C/C++ macros: | ||||
dnl USE_SDL -- whether SDL or SDL2 were found at all | |||||
dnl USE_SDL_IMAGE -- whether SDL_image was found | |||||
dnl USE_SDL_MIXER -- whether SDL_mixer was found | |||||
dnl HAVE_SDL_SDL_H -- whether to include <SDL/SDL.h> | |||||
dnl USE_SDL -- whether SDL v2 was found | |||||
dnl USE_OLD_SDL -- whether SDL v1 was found | |||||
dnl USE_SDL_IMAGE -- whether SDL_image (v1 or v2) was found | |||||
dnl USE_SDL_MIXER -- whether SDL_mixer (v1 or v2) was found | |||||
dnl HAVE_SDL_H -- whether to include <SDL.h> | dnl HAVE_SDL_H -- whether to include <SDL.h> | ||||
dnl HAVE_SDL_SDL_H -- whether to include <SDL/SDL.h> | |||||
dnl HAVE_SDL2_SDL_H -- whether to include <SDL2/SDL.h> | |||||
dnl Generated automake conditionals: | dnl Generated automake conditionals: | ||||
dnl USE_SDL -- whether SDL or SDL2 were found at all | |||||
dnl USE_SDL -- whether SDL v2 was found | |||||
dnl USE_OLD_SDL -- whether SDL v1 was found | |||||
dnl USE_SDL_IMAGE -- whether SDL_image was found | dnl USE_SDL_IMAGE -- whether SDL_image was found | ||||
dnl USE_SDL_MIXER -- whether SDL_mixer was found | dnl USE_SDL_MIXER -- whether SDL_mixer was found | ||||
dnl Generated shell variables: | dnl Generated shell variables: | ||||
@@ -20,15 +23,16 @@ dnl SDL_CFLAGS -- flags for SDL compilation | |||||
dnl SDL_LIBS -- flags for SDL linking | dnl SDL_LIBS -- flags for SDL linking | ||||
ac_cv_my_have_sdl="no" | ac_cv_my_have_sdl="no" | ||||
ac_cv_my_have_sdl2="no" | |||||
ac_cv_my_have_old_sdl="no" | |||||
ac_cv_my_have_sdl_image="no" | ac_cv_my_have_sdl_image="no" | ||||
ac_cv_my_have_sdl_mixer="no" | ac_cv_my_have_sdl_mixer="no" | ||||
dnl First, try the proper pkg-config check for SDL2 | dnl First, try the proper pkg-config check for SDL2 | ||||
if test "x${ac_cv_my_have_sdl}" = xno; then | if test "x${ac_cv_my_have_sdl}" = xno; then | ||||
PKG_CHECK_MODULES(SDL2, sdl2, | PKG_CHECK_MODULES(SDL2, sdl2, | ||||
[ac_cv_my_have_sdl="yes" | [ac_cv_my_have_sdl="yes" | ||||
ac_cv_my_have_sdl2="yes" | |||||
PKG_CHECK_MODULES(SDL2MIXER, SDL2_mixer, | PKG_CHECK_MODULES(SDL2MIXER, SDL2_mixer, | ||||
[ac_cv_my_have_sdl_mixer="yes" | [ac_cv_my_have_sdl_mixer="yes" | ||||
AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)], | AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)], | ||||
@@ -43,10 +47,45 @@ if test "x${ac_cv_my_have_sdl}" = xno; then | |||||
[:]) | [:]) | ||||
fi | fi | ||||
dnl Then, try the proper pkg-config check for SDL 1.x | |||||
dnl Maybe all this has failed, try direct inclusion instead | |||||
if test "x${ac_cv_my_have_sdl}" = xno; then | if test "x${ac_cv_my_have_sdl}" = xno; then | ||||
save_CPPFLAGS="${CPPFLAGS}" | |||||
save_LIBS="${LIBS}" | |||||
CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}" | |||||
LIBS="${LIBS} ${SDL_LIBS}" | |||||
AC_CHECK_HEADERS(SDL.h SDL/SDL.h SDL2/SDL.h, [ac_cv_my_have_sdl="yes"]) | |||||
if test "x${ac_cv_my_have_sdl}" != xno; then | |||||
AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h SDL2/SDL_mixer.h, | |||||
[ac_cv_my_have_sdl_mixer="yes"]) | |||||
AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h SDL2/SDL_image.h, | |||||
[ac_cv_my_have_sdl_image="yes"]) | |||||
AC_CHECK_LIB(SDL2, main, | |||||
[SDL_LIBS="${SDL_LIBS} -lSDL2"], | |||||
[ac_cv_my_have_sdl="no"]) | |||||
AC_CHECK_LIB(SDL2main, main, | |||||
[SDL_LIBS="${SDL_LIBS} -lSDL2main -lSDL2"]) | |||||
AC_CHECK_LIB(SDL2_mixer, main, | |||||
[SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL2_mixer"], | |||||
[ac_cv_my_have_sdl_mixer="no"]) | |||||
AC_CHECK_LIB(SDL2_image, main, | |||||
[SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL2_image"], | |||||
[ac_cv_my_have_sdl_image="no"]) | |||||
fi | |||||
SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}" | |||||
SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}" | |||||
CPPFLAGS="${save_CPPFLAGS}" | |||||
LIBS="${save_LIBS}" | |||||
fi | |||||
dnl Then, try the proper pkg-config check for SDL 1.x | |||||
if test "x${ac_cv_my_have_sdl}" = xno \ | |||||
-a "x${ac_cv_my_have_old_sdl}" = xno; then | |||||
PKG_CHECK_MODULES(SDL, sdl, | PKG_CHECK_MODULES(SDL, sdl, | ||||
[ac_cv_my_have_sdl="yes" | |||||
[ac_cv_my_have_old_sdl="yes" | |||||
PKG_CHECK_MODULES(SDLMIXER, SDL_mixer, | PKG_CHECK_MODULES(SDLMIXER, SDL_mixer, | ||||
[ac_cv_my_have_sdl_mixer="yes" | [ac_cv_my_have_sdl_mixer="yes" | ||||
AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)], | AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)], | ||||
@@ -61,51 +100,47 @@ if test "x${ac_cv_my_have_sdl}" = xno; then | |||||
[:]) | [:]) | ||||
fi | fi | ||||
dnl Then the old sdl-config method | dnl Then the old sdl-config method | ||||
if test "x${cross_compiling}" != xyes -a "x${ac_cv_my_have_sdl}" = xno; then | |||||
if test "x${ac_cv_my_have_sdl}" = xno \ | |||||
-a "x${ac_cv_my_have_old_sdl}" = xno \ | |||||
-a "x${cross_compiling}" != xyes; then | |||||
AC_PATH_PROG(SDL_CONFIG, sdl-config, no) | AC_PATH_PROG(SDL_CONFIG, sdl-config, no) | ||||
if test "${SDL_CONFIG}" != "no" && "${SDL_CONFIG}" --version >/dev/null; then | if test "${SDL_CONFIG}" != "no" && "${SDL_CONFIG}" --version >/dev/null; then | ||||
ac_cv_my_have_sdl="yes" | |||||
ac_cv_my_have_old_sdl="yes" | |||||
SDL_CFLAGS="${SDL_CFLAGS} `${SDL_CONFIG} --cflags`" | SDL_CFLAGS="${SDL_CFLAGS} `${SDL_CONFIG} --cflags`" | ||||
SDL_LIBS="${SDL_LIBS} `${SDL_CONFIG} --libs`" | SDL_LIBS="${SDL_LIBS} `${SDL_CONFIG} --libs`" | ||||
AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h) | AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h) | ||||
fi | fi | ||||
fi | fi | ||||
dnl Maybe all this has failed, try direct inclusion instead | |||||
if test "x${ac_cv_my_have_sdl}" = xno; then | |||||
dnl Finally, try direct inclusion | |||||
if test "x${ac_cv_my_have_sdl}" = xno \ | |||||
-a "x${ac_cv_my_have_old_sdl}" = xno; then | |||||
save_CPPFLAGS="${CPPFLAGS}" | save_CPPFLAGS="${CPPFLAGS}" | ||||
save_LIBS="${LIBS}" | save_LIBS="${LIBS}" | ||||
CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}" | CPPFLAGS="${CPPFLAGS} ${SDL_CFLAGS}" | ||||
LIBS="${LIBS} ${SDL_LIBS}" | LIBS="${LIBS} ${SDL_LIBS}" | ||||
AC_CHECK_HEADERS(SDL.h SDL/SDL.h, [ac_cv_my_have_sdl="yes"]) | |||||
if test "x${ac_cv_my_have_sdl}" != xno; then | |||||
AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h, [ac_cv_my_have_sdl_mixer="yes"]) | |||||
AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h, [ac_cv_my_have_sdl_image="yes"]) | |||||
AC_CHECK_HEADERS(SDL.h SDL/SDL.h, [ac_cv_my_have_old_sdl="yes"]) | |||||
if test "x${ac_cv_my_have_old_sdl}" != xno; then | |||||
AC_CHECK_HEADERS(SDL_mixer.h SDL/SDL_mixer.h, | |||||
[ac_cv_my_have_sdl_mixer="yes"]) | |||||
AC_CHECK_HEADERS(SDL_image.h SDL/SDL_image.h, | |||||
[ac_cv_my_have_sdl_image="yes"]) | |||||
AC_CHECK_LIB(SDL, main, | AC_CHECK_LIB(SDL, main, | ||||
[SDL_LIBS="${SDL_LIBS} -lSDL"], | [SDL_LIBS="${SDL_LIBS} -lSDL"], | ||||
[AC_CHECK_LIB(SDL2, main, | |||||
[SDL_LIBS="${SDL_LIBS} -lSDL2" | |||||
ac_cv_my_have_sdl2="yes"], | |||||
[ac_cv_my_have_sdl="no"])]) | |||||
[ac_cv_my_have_old_sdl="no"]) | |||||
AC_CHECK_LIB(SDLmain, main, | AC_CHECK_LIB(SDLmain, main, | ||||
[SDL_LIBS="${SDL_LIBS} -lSDLmain -lSDL"]) | [SDL_LIBS="${SDL_LIBS} -lSDLmain -lSDL"]) | ||||
AC_CHECK_LIB(SDL2main, main, | |||||
[SDL_LIBS="${SDL_LIBS} -lSDL2main -lSDL2"]) | |||||
AC_CHECK_LIB(SDL_mixer, main, | AC_CHECK_LIB(SDL_mixer, main, | ||||
[SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL_mixer"], | [SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL_mixer"], | ||||
[AC_CHECK_LIB(SDL2_mixer, main, | |||||
[SDLMIXER_LIBS="${SDLMIXER_LIBS} -lSDL2_mixer"], | |||||
[ac_cv_my_have_sdl_mixer="no"])]) | |||||
[ac_cv_my_have_sdl_mixer="no"]) | |||||
AC_CHECK_LIB(SDL_image, main, | AC_CHECK_LIB(SDL_image, main, | ||||
[SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL_image"], | [SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL_image"], | ||||
[AC_CHECK_LIB(SDL2_image, main, | |||||
[SDLIMAGE_LIBS="${SDLIMAGE_LIBS} -lSDL2_image"], | |||||
[ac_cv_my_have_sdl_image="no"])]) | |||||
[ac_cv_my_have_sdl_image="no"]) | |||||
fi | fi | ||||
SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}" | SDL_CFLAGS="${SDL_CFLAGS} ${SDLMIXER_CFLAGS} ${SDLIMAGE_CFLAGS}" | ||||
SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}" | SDL_LIBS="${SDL_LIBS} ${SDLMIXER_LIBS} ${SDLIMAGE_LIBS}" | ||||
@@ -113,18 +148,16 @@ if test "x${ac_cv_my_have_sdl}" = xno; then | |||||
LIBS="${save_LIBS}" | LIBS="${save_LIBS}" | ||||
fi | fi | ||||
dnl Convert all this into conditionals | |||||
if test "x${ac_cv_my_have_sdl}" = xno; then | if test "x${ac_cv_my_have_sdl}" = xno; then | ||||
AC_MSG_WARN([SDL not found]) | |||||
AC_MSG_WARN([SDL v2 not found]) | |||||
else | else | ||||
AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL) | AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL) | ||||
fi | fi | ||||
AM_CONDITIONAL(USE_SDL, test "x${ac_cv_my_have_sdl}" = xyes) | AM_CONDITIONAL(USE_SDL, test "x${ac_cv_my_have_sdl}" = xyes) | ||||
if test "x${ac_cv_my_have_sdl2}" != xno; then | |||||
AC_DEFINE(USE_SDL2, 1, Define to 1 to use SDL) | |||||
fi | |||||
AM_CONDITIONAL(USE_SDL2, test "x${ac_cv_my_have_sdl2}" = xyes) | |||||
if test "x${ac_cv_my_have_sdl_mixer}" = xno; then | if test "x${ac_cv_my_have_sdl_mixer}" = xno; then | ||||
AC_MSG_WARN([SDL_mixer not found]) | AC_MSG_WARN([SDL_mixer not found]) | ||||
else | else | ||||
@@ -139,6 +172,10 @@ else | |||||
fi | fi | ||||
AM_CONDITIONAL(USE_SDL_IMAGE, test "x${ac_cv_my_have_sdl_image}" = xyes) | AM_CONDITIONAL(USE_SDL_IMAGE, test "x${ac_cv_my_have_sdl_image}" = xyes) | ||||
if test "x${ac_cv_my_have_old_sdl}" != xno; then | |||||
AC_DEFINE(USE_OLD_SDL, 1, Define to 1 to use SDL) | |||||
fi | |||||
AM_CONDITIONAL(USE_OLD_SDL, test "x${ac_cv_my_have_old_sdl}" = xyes) | |||||
])# LOL_CHECK_SDL | ])# LOL_CHECK_SDL | ||||
@@ -17,7 +17,7 @@ | |||||
<SdlLibs Condition="'$(Platform)'=='x64'">$(SdlDir)\lib\x86_64-msvc;$(SdlImageDir)\lib\x86_64-msvc;$(SdlMixerDir)\lib\x86_64-msvc</SdlLibs> | <SdlLibs Condition="'$(Platform)'=='x64'">$(SdlDir)\lib\x86_64-msvc;$(SdlImageDir)\lib\x86_64-msvc;$(SdlMixerDir)\lib\x86_64-msvc</SdlLibs> | ||||
<SdlDeps Condition="'$(Platform)'=='Win32'">SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib</SdlDeps> | <SdlDeps Condition="'$(Platform)'=='Win32'">SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib</SdlDeps> | ||||
<SdlDeps Condition="'$(Platform)'=='x64'">SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib</SdlDeps> | <SdlDeps Condition="'$(Platform)'=='x64'">SDL2.lib;SDL2main.lib;SDL2_image.lib;SDL2_mixer.lib</SdlDeps> | ||||
<Win32Defines>HAVE_SDL_H;USE_SDL;USE_SDL2;$(Win32Defines)</Win32Defines> | |||||
<Win32Defines>HAVE_SDL_H;USE_SDL;$(Win32Defines)</Win32Defines> | |||||
<Win32Defines>USE_SDL_MIXER;USE_SDL_IMAGE;$(Win32Defines)</Win32Defines> | <Win32Defines>USE_SDL_MIXER;USE_SDL_IMAGE;$(Win32Defines)</Win32Defines> | ||||
<!-- GTK+ & GtkGl --> | <!-- GTK+ & GtkGl --> | ||||
@@ -24,7 +24,7 @@ | |||||
# include "platform/nacl/nacl-app.h" | # include "platform/nacl/nacl-app.h" | ||||
#elif __ANDROID__ | #elif __ANDROID__ | ||||
# include "platform/android/androidapp.h" | # include "platform/android/androidapp.h" | ||||
#elif USE_SDL | |||||
#elif USE_SDL || USE_OLD_SDL | |||||
# include "platform/sdl/sdlapp.h" | # include "platform/sdl/sdlapp.h" | ||||
# include "platform/sdl/sdlinput.h" | # include "platform/sdl/sdlinput.h" | ||||
#elif HAVE_GLES_2X | #elif HAVE_GLES_2X | ||||
@@ -50,7 +50,7 @@ class ApplicationData | |||||
NaClApp app; | NaClApp app; | ||||
#elif __ANDROID__ | #elif __ANDROID__ | ||||
AndroidApp app; | AndroidApp app; | ||||
#elif USE_SDL | |||||
#elif USE_SDL || USE_OLD_SDL | |||||
SdlApp app; | SdlApp app; | ||||
#elif HAVE_GLES_2X | #elif HAVE_GLES_2X | ||||
/* FIXME: this macro is only deactivated if we include "lolgl.h" */ | /* FIXME: this macro is only deactivated if we include "lolgl.h" */ | ||||
@@ -22,8 +22,10 @@ | |||||
# include <EGL/eglext.h> | # include <EGL/eglext.h> | ||||
#endif | #endif | ||||
#if defined USE_SDL | |||||
# if defined HAVE_SDL_SDL_H | |||||
#if USE_SDL || USE_OLD_SDL | |||||
# if HAVE_SDL2_SDL_H | |||||
# include <SDL2/SDL.h> | |||||
# elif HAVE_SDL_SDL_H | |||||
# include <SDL/SDL.h> | # include <SDL/SDL.h> | ||||
# else | # else | ||||
# include <SDL.h> | # include <SDL.h> | ||||
@@ -32,7 +34,7 @@ | |||||
#include "lolgl.h" | #include "lolgl.h" | ||||
#include "eglapp.h" | #include "eglapp.h" | ||||
#if defined USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
# include "platform/sdl/sdlinput.h" | # include "platform/sdl/sdlinput.h" | ||||
#endif | #endif | ||||
@@ -247,7 +249,7 @@ EglApp::EglApp(char const *title, ivec2 res, float fps) : | |||||
data->screen_size = uvec2(gwa.width, gwa.height); | data->screen_size = uvec2(gwa.width, gwa.height); | ||||
# endif | # endif | ||||
# if defined USE_SDL | |||||
# if USE_SDL || USE_OLD_SDL | |||||
new SdlInput(res.x, res.y, data->screen_size.x, data->screen_size.y); | new SdlInput(res.x, res.y, data->screen_size.x, data->screen_size.y); | ||||
# endif | # endif | ||||
@@ -105,7 +105,7 @@ Renderer::Renderer(ivec2 size) | |||||
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; | d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; | ||||
d3dpp.BackBufferCount = 1; | d3dpp.BackBufferCount = 1; | ||||
d3dpp.hDeviceWindow = g_hwnd; | d3dpp.hDeviceWindow = g_hwnd; | ||||
# if defined USE_SDL | |||||
# if USE_SDL || USE_OLD_SDL | |||||
d3dpp.Windowed = TRUE; | d3dpp.Windowed = TRUE; | ||||
# endif | # endif | ||||
d3dpp.EnableAutoDepthStencil = TRUE; | d3dpp.EnableAutoDepthStencil = TRUE; | ||||
@@ -28,7 +28,7 @@ | |||||
#endif | #endif | ||||
/* If using SDL on Windows or OS X, let it override main() */ | /* If using SDL on Windows or OS X, let it override main() */ | ||||
#if USE_SDL && (_WIN32 || __APPLE__) | |||||
#if (USE_SDL || USE_OLD_SDL) && (_WIN32 || __APPLE__) | |||||
# include <SDL_main.h> | # include <SDL_main.h> | ||||
#endif | #endif | ||||
@@ -23,7 +23,7 @@ | |||||
#endif | #endif | ||||
/* If using SDL on Windows or OS X, let it override main() */ | /* If using SDL on Windows or OS X, let it override main() */ | ||||
#if USE_SDL && (_WIN32 || __APPLE__) | |||||
#if (USE_SDL || USE_OLD_SDL) && (_WIN32 || __APPLE__) | |||||
# include <SDL_main.h> | # include <SDL_main.h> | ||||
#endif | #endif | ||||
@@ -10,8 +10,10 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#if USE_SDL | |||||
# if HAVE_SDL_SDL_H | |||||
#if USE_SDL || USE_OLD_SDL | |||||
# if HAVE_SDL2_SDL_H | |||||
# include <SDL2/SDL.h> | |||||
# elif HAVE_SDL_SDL_H | |||||
# include <SDL/SDL.h> | # include <SDL/SDL.h> | ||||
# else | # else | ||||
# include <SDL.h> | # include <SDL.h> | ||||
@@ -29,7 +31,7 @@ | |||||
# include "platform/d3d9/d3d9input.h" | # include "platform/d3d9/d3d9input.h" | ||||
#endif | #endif | ||||
#if USE_SDL && USE_D3D9 | |||||
#if (USE_SDL || USE_OLD_SDL) && USE_D3D9 | |||||
HWND g_hwnd = nullptr; | HWND g_hwnd = nullptr; | ||||
#endif | #endif | ||||
@@ -45,10 +47,10 @@ class SdlAppData | |||||
friend class SdlApp; | friend class SdlApp; | ||||
private: | private: | ||||
#if USE_SDL2 | |||||
#if USE_SDL | |||||
SDL_Window *m_window; | SDL_Window *m_window; | ||||
SDL_GLContext m_glcontext; | SDL_GLContext m_glcontext; | ||||
#else | |||||
#elif USE_OLD_SDL | |||||
SDL_Surface *m_window; | SDL_Surface *m_window; | ||||
#endif | #endif | ||||
}; | }; | ||||
@@ -60,7 +62,7 @@ private: | |||||
SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | ||||
data(new SdlAppData()) | data(new SdlAppData()) | ||||
{ | { | ||||
#if USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
ivec2 window_size = res; | ivec2 window_size = res; | ||||
ivec2 screen_size = res; | ivec2 screen_size = res; | ||||
@@ -71,7 +73,7 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | |||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
#if USE_SDL2 | |||||
#if USE_SDL | |||||
data->m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, | data->m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, | ||||
SDL_WINDOWPOS_UNDEFINED, | SDL_WINDOWPOS_UNDEFINED, | ||||
window_size.x, window_size.y, | window_size.x, window_size.y, | ||||
@@ -136,14 +138,14 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : | |||||
void SdlApp::ShowPointer(bool show) | void SdlApp::ShowPointer(bool show) | ||||
{ | { | ||||
#if defined USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
SDL_ShowCursor(show ? 1 : 0); | SDL_ShowCursor(show ? 1 : 0); | ||||
#endif | #endif | ||||
} | } | ||||
void SdlApp::Tick() | void SdlApp::Tick() | ||||
{ | { | ||||
#if defined USE_SDL && defined USE_D3D9 | |||||
#if (USE_SDL || USE_OLD_SDL) && defined USE_D3D9 | |||||
IDirect3DDevice9 *d3d_dev = (IDirect3DDevice9 *)g_renderer->GetDevice(); | IDirect3DDevice9 *d3d_dev = (IDirect3DDevice9 *)g_renderer->GetDevice(); | ||||
HRESULT hr; | HRESULT hr; | ||||
hr = d3d_dev->BeginScene(); | hr = d3d_dev->BeginScene(); | ||||
@@ -154,16 +156,16 @@ void SdlApp::Tick() | |||||
/* Tick the renderer, show the frame and clamp to desired framerate. */ | /* Tick the renderer, show the frame and clamp to desired framerate. */ | ||||
Ticker::TickDraw(); | Ticker::TickDraw(); | ||||
#if USE_SDL2 | |||||
#if USE_SDL | |||||
SDL_GL_SwapWindow(data->m_window); | SDL_GL_SwapWindow(data->m_window); | ||||
#elif USE_SDL && USE_D3D9 | |||||
#elif USE_OLD_SDL && USE_D3D9 | |||||
hr = d3d_dev->EndScene(); | hr = d3d_dev->EndScene(); | ||||
if (FAILED(hr)) | if (FAILED(hr)) | ||||
Abort(); | Abort(); | ||||
hr = d3d_dev->Present(nullptr, nullptr, nullptr, nullptr); | hr = d3d_dev->Present(nullptr, nullptr, nullptr, nullptr); | ||||
if (FAILED(hr)) | if (FAILED(hr)) | ||||
Abort(); | Abort(); | ||||
#elif USE_SDL | |||||
#elif USE_OLD_SDL | |||||
SDL_GL_SwapBuffers(); | SDL_GL_SwapBuffers(); | ||||
#endif | #endif | ||||
} | } | ||||
@@ -173,14 +175,13 @@ SdlApp::~SdlApp() | |||||
#if USE_SDL | #if USE_SDL | ||||
if (data->m_window) | if (data->m_window) | ||||
{ | { | ||||
# if USE_SDL2 | |||||
SDL_GL_DeleteContext(data->m_glcontext); | SDL_GL_DeleteContext(data->m_glcontext); | ||||
SDL_DestroyWindow(data->m_window); | SDL_DestroyWindow(data->m_window); | ||||
# else | |||||
SDL_DestroySurface(data->m_window); | |||||
# endif | |||||
} | } | ||||
SDL_Quit(); | |||||
#elif USE_OLD_SDL | |||||
if (data->m_window) | |||||
SDL_DestroySurface(data->m_window); | |||||
SDL_Quit(); | SDL_Quit(); | ||||
#endif | #endif | ||||
@@ -10,8 +10,10 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#if USE_SDL | |||||
# if HAVE_SDL_SDL_H | |||||
#if USE_SDL || USE_OLD_SDL | |||||
# if HAVE_SDL2_SDL_H | |||||
# include <SDL2/SDL.h> | |||||
# elif HAVE_SDL_SDL_H | |||||
# include <SDL/SDL.h> | # include <SDL/SDL.h> | ||||
# else | # else | ||||
# include <SDL.h> | # include <SDL.h> | ||||
@@ -48,7 +50,7 @@ private: | |||||
static ivec2 GetMousePos(); | static ivec2 GetMousePos(); | ||||
static void SetMousePos(ivec2 position); | static void SetMousePos(ivec2 position); | ||||
#if USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
SdlInputData(int app_w, int app_h, int screen_w, int screen_h) : | SdlInputData(int app_w, int app_h, int screen_w, int screen_h) : | ||||
m_prevmouse(ivec2::zero), | m_prevmouse(ivec2::zero), | ||||
m_app(vec2((float)app_w, (float)app_h)), | m_app(vec2((float)app_w, (float)app_h)), | ||||
@@ -72,16 +74,16 @@ private: | |||||
*/ | */ | ||||
SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | ||||
#if USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
: m_data(new SdlInputData(app_w, app_h, screen_w, screen_h)) | : m_data(new SdlInputData(app_w, app_h, screen_w, screen_h)) | ||||
#endif //USE_SDL | #endif //USE_SDL | ||||
{ | { | ||||
#if USE_SDL && !USE_SDL2 | |||||
#if USE_OLD_SDL | |||||
/* Enable Unicode translation of keyboard events */ | /* Enable Unicode translation of keyboard events */ | ||||
SDL_EnableUNICODE(1); | SDL_EnableUNICODE(1); | ||||
#endif | #endif | ||||
#if USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); | SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); | ||||
m_data->m_keyboard = InputDeviceInternal::CreateStandardKeyboard(); | m_data->m_keyboard = InputDeviceInternal::CreateStandardKeyboard(); | ||||
@@ -104,9 +106,9 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | |||||
* - HDAPS, it's not a real joystick. | * - HDAPS, it's not a real joystick. | ||||
* - X360 controllers, Xinput handles them better since | * - X360 controllers, Xinput handles them better since | ||||
* it won't think there is only one trigger axis. */ | * it won't think there is only one trigger axis. */ | ||||
# if USE_SDL2 | |||||
# if USE_SDL | |||||
char const *name = SDL_JoystickName(sdlstick); | char const *name = SDL_JoystickName(sdlstick); | ||||
# else | |||||
# elif USE_OLD_SDL | |||||
char const *name = SDL_JoystickName(i); | char const *name = SDL_JoystickName(i); | ||||
# endif | # endif | ||||
if (strstr(name, "HDAPS") | if (strstr(name, "HDAPS") | ||||
@@ -137,7 +139,7 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | |||||
SdlInput::~SdlInput() | SdlInput::~SdlInput() | ||||
{ | { | ||||
#if USE_SDL && !EMSCRIPTEN | |||||
#if (USE_SDL || USE_OLD_SDL) && !EMSCRIPTEN | |||||
/* Unregister all the joysticks we added */ | /* Unregister all the joysticks we added */ | ||||
while (m_data->m_joysticks.Count()) | while (m_data->m_joysticks.Count()) | ||||
{ | { | ||||
@@ -169,7 +171,7 @@ void SdlInput::TickDraw(float seconds, Scene &scene) | |||||
void SdlInputData::Tick(float seconds) | void SdlInputData::Tick(float seconds) | ||||
{ | { | ||||
#if USE_SDL | |||||
#if USE_SDL || USE_OLD_SDL | |||||
/* Pump all joystick events because no event is coming to us. */ | /* Pump all joystick events because no event is coming to us. */ | ||||
# if SDL_FORCE_POLL_JOYSTICK && !EMSCRIPTEN | # if SDL_FORCE_POLL_JOYSTICK && !EMSCRIPTEN | ||||
SDL_JoystickUpdate(); | SDL_JoystickUpdate(); | ||||
@@ -202,7 +204,7 @@ void SdlInputData::Tick(float seconds) | |||||
case SDL_MOUSEBUTTONDOWN: | case SDL_MOUSEBUTTONDOWN: | ||||
case SDL_MOUSEBUTTONUP: | case SDL_MOUSEBUTTONUP: | ||||
{ | { | ||||
# if !USE_SDL2 | |||||
# if USE_OLD_SDL | |||||
if (event.button.button != SDL_BUTTON_WHEELUP && event.button.button != SDL_BUTTON_WHEELDOWN) | if (event.button.button != SDL_BUTTON_WHEELUP && event.button.button != SDL_BUTTON_WHEELDOWN) | ||||
m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN); | m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN); | ||||
else | else | ||||
@@ -230,9 +232,9 @@ void SdlInputData::Tick(float seconds) | |||||
if (InputDeviceInternal::GetMouseCapture() != m_mousecapture) | if (InputDeviceInternal::GetMouseCapture() != m_mousecapture) | ||||
{ | { | ||||
m_mousecapture = InputDeviceInternal::GetMouseCapture(); | m_mousecapture = InputDeviceInternal::GetMouseCapture(); | ||||
# if USE_SDL2 | |||||
# if USE_SDL | |||||
SDL_SetRelativeMouseMode(m_mousecapture ? SDL_TRUE : SDL_FALSE); | SDL_SetRelativeMouseMode(m_mousecapture ? SDL_TRUE : SDL_FALSE); | ||||
# else | |||||
# elif USE_OLD_SDL | |||||
SDL_WM_GrabInput(m_mousecapture ? SDL_GRAB_ON : SDL_GRAB_OFF); | SDL_WM_GrabInput(m_mousecapture ? SDL_GRAB_ON : SDL_GRAB_OFF); | ||||
# endif | # endif | ||||
mouse = (ivec2)m_app / 2; | mouse = (ivec2)m_app / 2; | ||||
@@ -258,13 +260,13 @@ void SdlInputData::Tick(float seconds) | |||||
//Mouse is focused, Validate the InScreen Key | //Mouse is focused, Validate the InScreen Key | ||||
//Hardcoded 3, not very nice. | //Hardcoded 3, not very nice. | ||||
# if !EMSCRIPTEN && !USE_SDL2 | |||||
# if !EMSCRIPTEN && USE_OLD_SDL | |||||
m_mouse->SetKey(3, !!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)); | m_mouse->SetKey(3, !!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)); | ||||
#else | |||||
# else | |||||
// Emscripten doesn't seem to handle SDL_APPMOUSEFOCUS | // Emscripten doesn't seem to handle SDL_APPMOUSEFOCUS | ||||
// SDL2 doesn't have SDL_APPMOUSEFOCUS either | |||||
// FIXME: SDL2 doesn't have SDL_APPMOUSEFOCUS either | |||||
m_mouse->SetKey(3, true); | m_mouse->SetKey(3, true); | ||||
#endif | |||||
# endif | |||||
if (m_mousecapture) | if (m_mousecapture) | ||||
{ | { | ||||
@@ -274,9 +276,9 @@ void SdlInputData::Tick(float seconds) | |||||
m_prevmouse = mouse; | m_prevmouse = mouse; | ||||
# if USE_SDL2 | |||||
# if USE_SDL | |||||
Uint8 const *sdlstate = SDL_GetKeyboardState(nullptr); | Uint8 const *sdlstate = SDL_GetKeyboardState(nullptr); | ||||
# else | |||||
# elif USE_OLD_SDL | |||||
Uint8 *sdlstate = SDL_GetKeyState(nullptr); | Uint8 *sdlstate = SDL_GetKeyState(nullptr); | ||||
# endif | # endif | ||||
@@ -298,27 +300,27 @@ ivec2 SdlInputData::GetMousePos() | |||||
{ | { | ||||
ivec2 ret(-1, -1); | ivec2 ret(-1, -1); | ||||
#if USE_SDL | |||||
# if !EMSCRIPTEN && !USE_SDL2 | |||||
#if USE_SDL || USE_OLD_SDL | |||||
# if !EMSCRIPTEN && USE_OLD_SDL | |||||
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) | if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) | ||||
# endif | # endif | ||||
{ | { | ||||
SDL_GetMouseState(&ret.x, &ret.y); | SDL_GetMouseState(&ret.x, &ret.y); | ||||
ret.y = Video::GetSize().y - 1 - ret.y; | ret.y = Video::GetSize().y - 1 - ret.y; | ||||
} | } | ||||
#endif //USE_SDL | |||||
#endif | |||||
return ret; | return ret; | ||||
} | } | ||||
void SdlInputData::SetMousePos(ivec2 position) | void SdlInputData::SetMousePos(ivec2 position) | ||||
{ | { | ||||
#if USE_SDL2 | |||||
#if USE_SDL | |||||
// FIXME: how do I warped mouse? | // FIXME: how do I warped mouse? | ||||
#elif USE_SDL | |||||
#elif USE_OLD_SDL | |||||
SDL_WarpMouse((uint16_t)position.x, (uint16_t)position.y); | SDL_WarpMouse((uint16_t)position.x, (uint16_t)position.y); | ||||
#else | #else | ||||
UNUSED(position); | UNUSED(position); | ||||
#endif //USE_SDL | |||||
#endif | |||||
} | } | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||