@@ -20,26 +20,28 @@ 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_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 | ||||
dnl if test "x${ac_cv_my_have_sdl}" = xno; then | |||||
dnl PKG_CHECK_MODULES(SDL2, sdl2, | |||||
dnl [ac_cv_my_have_sdl="yes" | |||||
dnl PKG_CHECK_MODULES(SDL2MIXER, SDL2_mixer, | |||||
dnl [ac_cv_my_have_sdl_mixer="yes" | |||||
dnl AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)], | |||||
dnl [:]) | |||||
dnl PKG_CHECK_MODULES(SDL2IMAGE, SDL2_image, | |||||
dnl [ac_cv_my_have_sdl_image="yes" | |||||
dnl AC_DEFINE(HAVE_SDL_IMAGE_H, 1, Define to 1 to use SDL_image.h)], | |||||
dnl [:]) | |||||
dnl SDL_CFLAGS="${SDL2_CFLAGS} ${SDL2MIXER_CFLAGS} ${SDL2IMAGE_CFLAGS}" | |||||
dnl SDL_LIBS="${SDL2_LIBS} ${SDL2MIXER_LIBS} ${SDL2IMAGE_LIBS}" | |||||
dnl AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)], | |||||
dnl [:]) | |||||
dnl fi | |||||
if test "x${ac_cv_my_have_sdl}" = xno; then | |||||
PKG_CHECK_MODULES(SDL2, sdl2, | |||||
[ac_cv_my_have_sdl="yes" | |||||
ac_cv_my_have_sdl2="yes" | |||||
PKG_CHECK_MODULES(SDL2MIXER, SDL2_mixer, | |||||
[ac_cv_my_have_sdl_mixer="yes" | |||||
AC_DEFINE(HAVE_SDL_MIXER_H, 1, Define to 1 to use SDL_mixer.h)], | |||||
[:]) | |||||
PKG_CHECK_MODULES(SDL2IMAGE, SDL2_image, | |||||
[ac_cv_my_have_sdl_image="yes" | |||||
AC_DEFINE(HAVE_SDL_IMAGE_H, 1, Define to 1 to use SDL_image.h)], | |||||
[:]) | |||||
SDL_CFLAGS="${SDL2_CFLAGS} ${SDL2MIXER_CFLAGS} ${SDL2IMAGE_CFLAGS}" | |||||
SDL_LIBS="${SDL2_LIBS} ${SDL2MIXER_LIBS} ${SDL2IMAGE_LIBS}" | |||||
AC_DEFINE(HAVE_SDL_H, 1, Define to 1 to use SDL.h)], | |||||
[:]) | |||||
fi | |||||
dnl Then, try the proper pkg-config check for SDL 1.x | dnl Then, try the proper pkg-config check for SDL 1.x | ||||
if test "x${ac_cv_my_have_sdl}" = xno; then | if test "x${ac_cv_my_have_sdl}" = xno; then | ||||
@@ -105,6 +107,11 @@ else | |||||
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 | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | // This program is free software; you can redistribute it and/or | ||||
// modify it under the terms of the Do What The Fuck You Want To | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -10,13 +10,13 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#if defined USE_SDL | |||||
# if defined HAVE_SDL_SDL_H | |||||
#if USE_SDL | |||||
# if HAVE_SDL_SDL_H | |||||
# include <SDL/SDL.h> | # include <SDL/SDL.h> | ||||
# else | # else | ||||
# include <SDL.h> | # include <SDL.h> | ||||
# endif | # endif | ||||
# if defined USE_D3D9 | |||||
# if USE_D3D9 | |||||
# include <d3d9.h> | # include <d3d9.h> | ||||
# include <SDL_syswm.h> | # include <SDL_syswm.h> | ||||
# endif | # endif | ||||
@@ -25,11 +25,11 @@ | |||||
#include "lolgl.h" | #include "lolgl.h" | ||||
#include "platform/sdl/sdlapp.h" | #include "platform/sdl/sdlapp.h" | ||||
#include "platform/sdl/sdlinput.h" | #include "platform/sdl/sdlinput.h" | ||||
#if defined USE_XINPUT | |||||
#if USE_XINPUT | |||||
# include "platform/d3d9/d3d9input.h" | # include "platform/d3d9/d3d9input.h" | ||||
#endif | #endif | ||||
#if defined USE_SDL && defined USE_D3D9 | |||||
#if USE_SDL && USE_D3D9 | |||||
HWND g_hwnd = nullptr; | HWND g_hwnd = nullptr; | ||||
#endif | #endif | ||||
@@ -45,7 +45,12 @@ class SdlAppData | |||||
friend class SdlApp; | friend class SdlApp; | ||||
private: | private: | ||||
int unused; | |||||
#if USE_SDL2 | |||||
SDL_Window *m_window; | |||||
SDL_GLContext m_glcontext; | |||||
#else | |||||
SDL_Surface *m_window; | |||||
#endif | |||||
}; | }; | ||||
/* | /* | ||||
@@ -55,55 +60,77 @@ 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 defined USE_SDL | |||||
#if USE_SDL | |||||
ivec2 window_size = res; | |||||
ivec2 screen_size = res; | |||||
/* Initialise SDL */ | /* Initialise SDL */ | ||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) | |||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) < 0) | |||||
{ | { | ||||
Log::Error("cannot initialise SDL: %s\n", SDL_GetError()); | Log::Error("cannot initialise SDL: %s\n", SDL_GetError()); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
#if USE_SDL2 | |||||
data->m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, | |||||
SDL_WINDOWPOS_UNDEFINED, | |||||
window_size.x, window_size.y, | |||||
SDL_WINDOW_OPENGL); | |||||
if (!data->m_window) | |||||
{ | |||||
Log::Error("cannot create rendering window: %s\n", SDL_GetError()); | |||||
SDL_Quit(); | |||||
exit(EXIT_FAILURE); | |||||
} | |||||
SDL_GetWindowSize(data->m_window, &res.x, &res.y); | |||||
data->m_glcontext = SDL_GL_CreateContext(data->m_window); | |||||
#else | |||||
const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo(); | const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo(); | ||||
int screen_w = vidinfo->current_w; | |||||
int screen_h = vidinfo->current_h; | |||||
screen_size = ivec2(vidinfo->current_w, vidinfo->current_h); | |||||
SDL_WM_SetCaption(title, nullptr); | |||||
# if defined USE_D3D9 | |||||
# if USE_D3D9 | |||||
SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 16, 0); | SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 16, 0); | ||||
SDL_SysWMinfo wminfo; | SDL_SysWMinfo wminfo; | ||||
SDL_VERSION(&wminfo.version); | SDL_VERSION(&wminfo.version); | ||||
SDL_GetWMInfo(&wminfo); | SDL_GetWMInfo(&wminfo); | ||||
g_hwnd = wminfo.window; | g_hwnd = wminfo.window; | ||||
# elif SDL_VERSION_ATLEAST(2,0,0) | |||||
TODO | |||||
# else | # else | ||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | ||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); | ||||
// TODO: when implementing fullscreen, be sure to overwrite screen_w and screen_h with the value of vidinfo after the call to SDL_SetVideoMode | |||||
SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); | |||||
// TODO: when implementing fullscreen, be sure to overwrite screen_w | |||||
// and screen_h with the value of vidinfo after the call to | |||||
// SDL_SetVideoMode. | |||||
data->m_window = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); | |||||
# endif | # endif | ||||
if (!video) | |||||
if (!data->m_window) | |||||
{ | { | ||||
Log::Error("cannot create rendering window: %s\n", SDL_GetError()); | Log::Error("cannot create rendering window: %s\n", SDL_GetError()); | ||||
SDL_Quit(); | SDL_Quit(); | ||||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | ||||
} | } | ||||
SDL_WM_SetCaption(title, nullptr); | |||||
res = ivec2(data->m_window->w, data->m_window->h); | |||||
#endif | |||||
/* Initialise everything */ | /* Initialise everything */ | ||||
Ticker::Setup(fps); | Ticker::Setup(fps); | ||||
Video::Setup(ivec2(video->w, video->h)); | |||||
Video::Setup(res); | |||||
Audio::Setup(2); | Audio::Setup(2); | ||||
/* Autoreleased objects */ | /* Autoreleased objects */ | ||||
# if defined USE_XINPUT | |||||
#if defined USE_XINPUT | |||||
/* Prefer D3d9 for joysticks on Windows, because the X360 pads are not | /* Prefer D3d9 for joysticks on Windows, because the X360 pads are not | ||||
* advertised with the proper number of axes. */ | * advertised with the proper number of axes. */ | ||||
new D3d9Input(); | new D3d9Input(); | ||||
# endif | |||||
#endif | |||||
new SdlInput(video->w, video->h, screen_w, screen_h); | |||||
new SdlInput(res.x, res.y, screen_size.x, screen_size.y); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -127,23 +154,36 @@ 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 defined USE_SDL && defined USE_D3D9 | |||||
#if USE_SDL2 | |||||
SDL_GL_SwapWindow(data->m_window); | |||||
#elif USE_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 defined USE_SDL | |||||
#elif USE_SDL | |||||
SDL_GL_SwapBuffers(); | SDL_GL_SwapBuffers(); | ||||
#endif | #endif | ||||
} | } | ||||
SdlApp::~SdlApp() | SdlApp::~SdlApp() | ||||
{ | { | ||||
#if defined USE_SDL | |||||
#if USE_SDL | |||||
if (data->m_window) | |||||
{ | |||||
# if USE_SDL2 | |||||
SDL_GL_DeleteContext(data->m_glcontext); | |||||
SDL_DestroyWindow(data->m_window); | |||||
# else | |||||
SDL_DestroySurface(data->m_window); | |||||
# endif | |||||
} | |||||
SDL_Quit(); | SDL_Quit(); | ||||
#endif | #endif | ||||
delete data; | delete data; | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | // This program is free software; you can redistribute it and/or | ||||
// modify it under the terms of the Do What The Fuck You Want To | // modify it under the terms of the Do What The Fuck You Want To | ||||
// Public License, Version 2, as published by Sam Hocevar. See | // Public License, Version 2, as published by Sam Hocevar. See | ||||
@@ -76,10 +76,12 @@ SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h) | |||||
: 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 | |||||
#if USE_SDL && !USE_SDL2 | |||||
/* Enable Unicode translation of keyboard events */ | /* Enable Unicode translation of keyboard events */ | ||||
SDL_EnableUNICODE(1); | SDL_EnableUNICODE(1); | ||||
#endif | |||||
#if USE_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(); | ||||
@@ -102,7 +104,11 @@ 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 | |||||
char const *name = SDL_JoystickName(sdlstick); | |||||
# else | |||||
char const *name = SDL_JoystickName(i); | char const *name = SDL_JoystickName(i); | ||||
# endif | |||||
if (strstr(name, "HDAPS") | if (strstr(name, "HDAPS") | ||||
# if USE_XINPUT | # if USE_XINPUT | ||||
|| strstr(name, "XBOX 360 For Windows") | || strstr(name, "XBOX 360 For Windows") | ||||
@@ -196,10 +202,12 @@ void SdlInputData::Tick(float seconds) | |||||
case SDL_MOUSEBUTTONDOWN: | case SDL_MOUSEBUTTONDOWN: | ||||
case SDL_MOUSEBUTTONUP: | case SDL_MOUSEBUTTONUP: | ||||
{ | { | ||||
# if !USE_SDL2 | |||||
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 | ||||
m_mouse->SetAxis(4, (event.button.button != SDL_BUTTON_WHEELUP) ? (1) : (-1)); | m_mouse->SetAxis(4, (event.button.button != SDL_BUTTON_WHEELUP) ? (1) : (-1)); | ||||
# endif | |||||
// TODO: mouse wheel as axis | // TODO: mouse wheel as axis | ||||
break; | break; | ||||
} | } | ||||
@@ -222,7 +230,11 @@ 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 | |||||
SDL_SetRelativeMouseMode(m_mousecapture ? SDL_TRUE : SDL_FALSE); | |||||
# else | |||||
SDL_WM_GrabInput(m_mousecapture ? SDL_GRAB_ON : SDL_GRAB_OFF); | SDL_WM_GrabInput(m_mousecapture ? SDL_GRAB_ON : SDL_GRAB_OFF); | ||||
# endif | |||||
mouse = (ivec2)m_app / 2; | mouse = (ivec2)m_app / 2; | ||||
SdlInputData::SetMousePos(mouse); | SdlInputData::SetMousePos(mouse); | ||||
//SDL_ShowCursor(m_mousecapture ? SDL_DISABLE : SDL_ENABLE); | //SDL_ShowCursor(m_mousecapture ? SDL_DISABLE : SDL_ENABLE); | ||||
@@ -246,9 +258,11 @@ 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 | |||||
# if !EMSCRIPTEN && !USE_SDL2 | |||||
m_mouse->SetKey(3, !!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)); | m_mouse->SetKey(3, !!(SDL_GetAppState() & SDL_APPMOUSEFOCUS)); | ||||
#else //Emscripten doesn't seem to handle SDL_APPMOUSEFOCUS | |||||
#else | |||||
// Emscripten doesn't seem to handle SDL_APPMOUSEFOCUS | |||||
// SDL2 doesn't have SDL_APPMOUSEFOCUS either | |||||
m_mouse->SetKey(3, true); | m_mouse->SetKey(3, true); | ||||
#endif | #endif | ||||
@@ -260,8 +274,8 @@ void SdlInputData::Tick(float seconds) | |||||
m_prevmouse = mouse; | m_prevmouse = mouse; | ||||
# if SDL_VERSION_ATLEAST(1,3,0) | |||||
Uint8 *sdlstate = SDL_GetKeyboardState(nullptr); | |||||
# if USE_SDL2 | |||||
Uint8 const *sdlstate = SDL_GetKeyboardState(nullptr); | |||||
# else | # else | ||||
Uint8 *sdlstate = SDL_GetKeyState(nullptr); | Uint8 *sdlstate = SDL_GetKeyState(nullptr); | ||||
# endif | # endif | ||||
@@ -285,7 +299,7 @@ ivec2 SdlInputData::GetMousePos() | |||||
ivec2 ret(-1, -1); | ivec2 ret(-1, -1); | ||||
#if USE_SDL | #if USE_SDL | ||||
# if !EMSCRIPTEN | |||||
# if !EMSCRIPTEN && !USE_SDL2 | |||||
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) | if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) | ||||
# endif | # endif | ||||
{ | { | ||||
@@ -298,7 +312,9 @@ ivec2 SdlInputData::GetMousePos() | |||||
void SdlInputData::SetMousePos(ivec2 position) | void SdlInputData::SetMousePos(ivec2 position) | ||||
{ | { | ||||
#if USE_SDL | |||||
#if USE_SDL2 | |||||
// FIXME: how do I warped mouse? | |||||
#elif USE_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); | ||||