diff --git a/FindSDL2.cmake b/FindSDL2.cmake new file mode 100644 index 000000000..614426ccc --- /dev/null +++ b/FindSDL2.cmake @@ -0,0 +1,180 @@ +# Locate SDL2 library +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2_main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDL2main.h and SDL2main.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2DIR is an environment variable that would +# correspond to the ./configure --prefix=$SDL2DIR +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL2 guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL2 convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). +# +# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake +# module with the minor edit of changing "SDL" to "SDL2" where necessary. This +# was not created for redistribution, and exists temporarily pending official +# SDL2 CMake modules. + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PATH(SDL2_INCLUDE_DIR SDL.h + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES include/SDL2 include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local/include/SDL2 + /usr/include/SDL2 + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) +#MESSAGE("SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIR}") + +FIND_LIBRARY(SDL2_LIBRARY_TEMP + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt +) + +#MESSAGE("SDL2_LIBRARY_TEMP is ${SDL2_LIBRARY_TEMP}") + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib + PATHS + /sw + /opt/local + /opt/csw + /opt + ) + ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2_BUILDING_LIBRARY) + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +SET(SDL2_FOUND "NO") +IF(SDL2_LIBRARY_TEMP) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIBRARY) + SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(SDL2MAIN_LIBRARY) + ENDIF(NOT SDL2_BUILDING_LIBRARY) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") + + SET(SDL2_FOUND "YES") +ENDIF(SDL2_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 + REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8b924bd50..397a96ca6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,19 +191,6 @@ else( WIN32 ) set( NO_GTK ON ) endif( GTK2_FOUND ) endif( NOT NO_GTK ) - - # Check for Xcursor library and header files - find_library( XCURSOR_LIB Xcursor ) - if( XCURSOR_LIB ) - find_file( XCURSOR_HEADER "X11/Xcursor/Xcursor.h" ) - if( XCURSOR_HEADER ) - add_definitions( -DUSE_XCURSOR=1 ) - message( STATUS "Found Xcursor at ${XCURSOR_LIB}" ) - set( ZDOOM_LIBS ${ZDOOM_LIBS} ${XCURSOR_LIB} ) - else( XCURSOR_HEADER ) - unset( XCURSOR_LIB ) - endif( XCURSOR_HEADER ) - endif( XCURSOR_LIB ) endif( APPLE ) set( NASM_NAMES nasm ) @@ -212,14 +199,11 @@ else( WIN32 ) endif( NO_GTK ) # Non-Windows version also needs SDL - find_package( SDL ) - if( NOT SDL_FOUND ) - message( SEND_ERROR "SDL is required for building." ) - endif( NOT SDL_FOUND ) + find_package( SDL2 REQUIRED ) if( NOT APPLE OR NOT OSX_COCOA_BACKEND ) - set( ZDOOM_LIBS ${ZDOOM_LIBS} "${SDL_LIBRARY}" ) + set( ZDOOM_LIBS ${ZDOOM_LIBS} "${SDL2_LIBRARY}" ) endif( NOT APPLE OR NOT OSX_COCOA_BACKEND ) - include_directories( "${SDL_INCLUDE_DIR}" ) + include_directories( "${SDL2_INCLUDE_DIR}" ) find_path( FPU_CONTROL_DIR fpu_control.h ) if( FPU_CONTROL_DIR ) @@ -579,8 +563,8 @@ set( PLAT_SDL_SPECIAL_SOURCES sdl/i_joystick.cpp sdl/i_timer.cpp ) set( PLAT_MAC_SOURCES - sdl/iwadpicker_cocoa.mm - sdl/i_system_cocoa.mm ) + cocoa/iwadpicker_cocoa.mm + cocoa/i_system_cocoa.mm ) set( PLAT_COCOA_SOURCES cocoa/HID_Config_Utilities.c cocoa/HID_Error_Handler.c @@ -600,8 +584,9 @@ if( APPLE ) if( OSX_COCOA_BACKEND ) set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_COCOA_SOURCES} ) + add_definitions( -DUSE_NATIVE_COCOA ) else( OSX_COCOA_BACKEND ) - set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_SDL_SPECIAL_SOURCES} sdl/SDLMain.m ) + set( PLAT_MAC_SOURCES ${PLAT_MAC_SOURCES} ${PLAT_SDL_SPECIAL_SOURCES} ) endif( OSX_COCOA_BACKEND ) set_source_files_properties( cocoa/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) diff --git a/src/cocoa/i_backend_cocoa.mm b/src/cocoa/i_backend_cocoa.mm index 9085d92db..8828a1d78 100644 --- a/src/cocoa/i_backend_cocoa.mm +++ b/src/cocoa/i_backend_cocoa.mm @@ -1710,102 +1710,26 @@ void SDL_Quit() } -char* SDL_GetError() +const char* SDL_GetError() { static char empty[] = {0}; return empty; } -char* SDL_VideoDriverName(char* namebuf, int maxlen) +const char* SDL_GetCurrentVideoDriver() { - return strncpy(namebuf, "Native OpenGL", maxlen); + return "Native OpenGL"; } -const SDL_VideoInfo* SDL_GetVideoInfo() +int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode *mode) { - // NOTE: Only required fields are assigned - - static SDL_PixelFormat pixelFormat; - memset(&pixelFormat, 0, sizeof(pixelFormat)); - - pixelFormat.BitsPerPixel = 32; - - static SDL_VideoInfo videoInfo; - memset(&videoInfo, 0, sizeof(videoInfo)); - + // NOTE: Only required fields are assigned const NSRect displayRect = [[NSScreen mainScreen] frame]; - videoInfo.current_w = displayRect.size.width; - videoInfo.current_h = displayRect.size.height; - videoInfo.vfmt = &pixelFormat; + mode->w = displayRect.size.width; + mode->h = displayRect.size.height; - return &videoInfo; -} - -SDL_Rect** SDL_ListModes(SDL_PixelFormat* format, Uint32 flags) -{ - ZD_UNUSED(format); - ZD_UNUSED(flags); - - static std::vector resolutions; - - if (resolutions.empty()) - { -#define DEFINE_RESOLUTION(WIDTH, HEIGHT) \ - static SDL_Rect resolution_##WIDTH##_##HEIGHT = { 0, 0, WIDTH, HEIGHT }; \ - resolutions.push_back(&resolution_##WIDTH##_##HEIGHT); - - DEFINE_RESOLUTION( 640, 480); - DEFINE_RESOLUTION( 720, 480); - DEFINE_RESOLUTION( 800, 480); - DEFINE_RESOLUTION( 800, 600); - DEFINE_RESOLUTION(1024, 600); - DEFINE_RESOLUTION(1024, 640); - DEFINE_RESOLUTION(1024, 768); - DEFINE_RESOLUTION(1152, 720); - DEFINE_RESOLUTION(1152, 864); - DEFINE_RESOLUTION(1280, 720); - DEFINE_RESOLUTION(1280, 768); - DEFINE_RESOLUTION(1280, 800); - DEFINE_RESOLUTION(1280, 854); - DEFINE_RESOLUTION(1280, 960); - DEFINE_RESOLUTION(1280, 1024); - DEFINE_RESOLUTION(1366, 768); - DEFINE_RESOLUTION(1400, 1050); - DEFINE_RESOLUTION(1440, 900); - DEFINE_RESOLUTION(1440, 960); - DEFINE_RESOLUTION(1440, 1080); - DEFINE_RESOLUTION(1600, 900); - DEFINE_RESOLUTION(1600, 1200); - DEFINE_RESOLUTION(1680, 1050); - DEFINE_RESOLUTION(1920, 1080); - DEFINE_RESOLUTION(1920, 1200); - DEFINE_RESOLUTION(2048, 1080); - DEFINE_RESOLUTION(2048, 1536); - DEFINE_RESOLUTION(2560, 1080); - DEFINE_RESOLUTION(2560, 1440); - DEFINE_RESOLUTION(2560, 1600); - DEFINE_RESOLUTION(2560, 2048); - DEFINE_RESOLUTION(2880, 1800); - DEFINE_RESOLUTION(3200, 1800); - DEFINE_RESOLUTION(3440, 1440); - DEFINE_RESOLUTION(3840, 2160); - DEFINE_RESOLUTION(3840, 2400); - DEFINE_RESOLUTION(4096, 2160); - DEFINE_RESOLUTION(5120, 2880); - -#undef DEFINE_RESOLUTION - - resolutions.push_back(NULL); - } - - return &resolutions[0]; -} - -int SDL_ShowCursor(int) -{ - // Does nothing return 0; } @@ -1828,73 +1752,151 @@ static SDL_PixelFormat* GetPixelFormat() result.Rmask = 0x000000FF; result.Gmask = 0x0000FF00; result.Bmask = 0x00FF0000; - result.Amask = 0xFF000000; - result.colorkey = 0; - result.alpha = 0xFF; + result.Amask = 0xFF000000; return &result; } - -SDL_Surface* SDL_SetVideoMode(int width, int height, int, Uint32 flags) +SDL_bool SDL_PixelFormatEnumToMasks(Uint32 format, int* bpp, Uint32* Rmask, Uint32* Gmask, Uint32* Bmask, Uint32* Amask) { - [appCtrl changeVideoResolution:(SDL_FULLSCREEN & flags) + assert(format == SDL_PIXELFORMAT_ABGR8888); + + *bpp = 32; + *Rmask = 0x000000FF; + *Gmask = 0x0000FF00; + *Bmask = 0x00FF0000; + *Amask = 0xFF000000; + + return SDL_TRUE; +} + +struct SDL_Window +{ + Uint32 flags; + int w, h; + int pitch; + void *pixels; +}; + +struct SDL_Renderer { SDL_Window *window; }; +struct SDL_Texture { SDL_Window *window; }; + +SDL_Window* SDL_CreateWindow(const char* title, int x, int y, int width, int height, Uint32 flags) +{ + [appCtrl changeVideoResolution:(SDL_WINDOW_FULLSCREEN_DESKTOP & flags) width:width height:height useHiDPI:vid_hidpi]; - static SDL_Surface result; + static SDL_Window result; - if (!(SDL_OPENGL & flags)) + if (!(SDL_WINDOW_OPENGL & flags)) { [appCtrl setupSoftwareRenderingWithWidth:width height:height]; } result.flags = flags; - result.format = GetPixelFormat(); result.w = width; result.h = height; result.pitch = width * BYTES_PER_PIXEL; result.pixels = [appCtrl softwareRenderingBuffer]; - result.refcount = 1; - - result.clip_rect.x = 0; - result.clip_rect.y = 0; - result.clip_rect.w = width; - result.clip_rect.h = height; - + return &result; } - - -void SDL_WM_SetCaption(const char* title, const char* icon) +void SDL_DestroyWindow(SDL_Window *window) { - ZD_UNUSED(title); - ZD_UNUSED(icon); - - // Window title is set in SDL_SetVideoMode() + ZD_UNUSED(window); } -int SDL_WM_ToggleFullScreen(SDL_Surface* surface) +Uint32 SDL_GetWindowFlags(SDL_Window *window) { - if (surface->flags & SDL_FULLSCREEN) + return window->flags; +} + +SDL_Surface *SDL_GetWindowSurface(SDL_Window *window) +{ + ZD_UNUSED(window); + return NULL; +} + +void SDL_GetWindowSize(SDL_Window *window, int *w, int *h) +{ + *w = window->w; + *h = window->h; +} + +void SDL_SetWindowSize(SDL_Window *window, int w, int h) +{ + // Currently this is used for handling the fullscreen->windowed transition. + // We can just no-op this for now. + ZD_UNUSED(window); + ZD_UNUSED(w); + ZD_UNUSED(h); +} + +int SDL_SetWindowFullscreen(SDL_Window* window, Uint32 flags) +{ + if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == (flags & SDL_WINDOW_FULLSCREEN_DESKTOP)) + return 0; + + if (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) { - surface->flags &= ~SDL_FULLSCREEN; + window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP; } else { - surface->flags |= SDL_FULLSCREEN; + window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } - [appCtrl changeVideoResolution:(SDL_FULLSCREEN & surface->flags) - width:surface->w - height:surface->h + [appCtrl changeVideoResolution:(SDL_WINDOW_FULLSCREEN_DESKTOP & flags) + width:window->w + height:window->h useHiDPI:vid_hidpi]; - return 1; + return 0; } +SDL_Renderer *SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags) +{ + ZD_UNUSED(index); + ZD_UNUSED(flags); + + static SDL_Renderer result; + result.window = window; + + return &result; +} +void SDL_DestroyRenderer(SDL_Renderer *renderer) +{ + ZD_UNUSED(renderer); +} + +SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h) +{ + ZD_UNUSED(format); + ZD_UNUSED(access); + ZD_UNUSED(w); + ZD_UNUSED(h); + + static SDL_Texture result; + result.window = renderer->window; + + return &result; +} +void SDL_DestroyTexture(SDL_Texture *texture) +{ + ZD_UNUSED(texture); +} + +int SDL_QueryTexture(SDL_Texture *texture, Uint32* format, int* access, int* w, int* h) +{ + if(format) *format = SDL_PIXELFORMAT_ABGR8888; + if(access) *access = SDL_TEXTUREACCESS_STREAMING; + if(w) *w = texture->window->w; + if(h) *h = texture->window->h; + return 0; +} void SDL_GL_SwapBuffers() { @@ -1926,18 +1928,22 @@ void SDL_UnlockSurface(SDL_Surface* surface) ZD_UNUSED(surface); } -int SDL_BlitSurface(SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect) +int SDL_LockTexture(SDL_Texture* texture, const SDL_Rect *rect, void** pixels, int *pitch) { - ZD_UNUSED(src); - ZD_UNUSED(srcrect); - ZD_UNUSED(dst); - ZD_UNUSED(dstrect); - + assert(NULL == rect); + + *pixels = texture->window->pixels; + *pitch = texture->window->pitch; + return 0; } +void SDL_UnlockTexture(SDL_Texture *texture) +{ + ZD_UNUSED(texture); +} -int SDL_Flip(SDL_Surface* screen) +int SDL_UpdateWindowSurface(SDL_Window *screen) { assert(NULL != screen); @@ -1984,10 +1990,24 @@ int SDL_Flip(SDL_Surface* screen) return 0; } -int SDL_SetPalette(SDL_Surface* surface, int flags, SDL_Color* colors, int firstcolor, int ncolors) +int SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) { - ZD_UNUSED(surface); - ZD_UNUSED(flags); + ZD_UNUSED(renderer); + ZD_UNUSED(texture); + ZD_UNUSED(srcrect); + ZD_UNUSED(dstrect); + + return 0; +} + +void SDL_RenderPresent(SDL_Renderer *renderer) +{ + SDL_UpdateWindowSurface(renderer->window); +} + +int SDL_SetPaletteColors(SDL_Palette* palette, const SDL_Color* colors, int firstcolor, int ncolors) +{ + ZD_UNUSED(palette); ZD_UNUSED(colors); ZD_UNUSED(firstcolor); ZD_UNUSED(ncolors); @@ -2127,10 +2147,6 @@ DarwinVersion GetDarwinVersion() const DarwinVersion darwinVersion = GetDarwinVersion(); -#ifdef main -#undef main -#endif // main - int main(int argc, char** argv) { gettimeofday(&s_startTicks, NULL); diff --git a/src/sdl/i_system_cocoa.mm b/src/cocoa/i_system_cocoa.mm similarity index 100% rename from src/sdl/i_system_cocoa.mm rename to src/cocoa/i_system_cocoa.mm diff --git a/src/sdl/iwadpicker_cocoa.mm b/src/cocoa/iwadpicker_cocoa.mm similarity index 100% rename from src/sdl/iwadpicker_cocoa.mm rename to src/cocoa/iwadpicker_cocoa.mm diff --git a/src/menu/videomenu.cpp b/src/menu/videomenu.cpp index 1d1d02383..5e44bbfd4 100644 --- a/src/menu/videomenu.cpp +++ b/src/menu/videomenu.cpp @@ -247,8 +247,12 @@ static void BuildModesList (int hiwidth, int hiheight, int hi_bits) if (Video != NULL) { while ((haveMode = Video->NextMode (&width, &height, &letterbox)) && - (ratiomatch >= 0 && CheckRatio (width, height) != ratiomatch)) + ratiomatch >= 0) { + int ratio; + CheckRatio (width, height, &ratio); + if (ratio == ratiomatch) + break; } } diff --git a/src/sdl/i_gui.cpp b/src/sdl/i_gui.cpp index b40fb7517..c2b91b39c 100644 --- a/src/sdl/i_gui.cpp +++ b/src/sdl/i_gui.cpp @@ -9,61 +9,11 @@ #include "v_palette.h" #include "textures.h" -extern SDL_Surface *cursorSurface; -extern SDL_Rect cursorBlit; - -#ifdef USE_XCURSOR -// Xlib has its own GC, so don't let it interfere. -#define GC XGC -#include -#undef GC - -bool UseXCursor; -SDL_Cursor *X11Cursor; -SDL_Cursor *FirstCursor; - -// Hack! Hack! SDL does not provide a clean way to get the XDisplay. -// On the other hand, there are no more planned updates for SDL 1.2, -// so we should be fine making assumptions. -struct SDL_PrivateVideoData -{ - int local_X11; - Display *X11_Display; -}; - -struct SDL_VideoDevice -{ - const char *name; - int (*functions[9])(); - SDL_VideoInfo info; - SDL_PixelFormat *displayformatalphapixel; - int (*morefuncs[9])(); - Uint16 *gamma; - int (*somefuncs[9])(); - unsigned int texture; // Only here if SDL was compiled with OpenGL support. Ack! - int is_32bit; - int (*itsafuncs[13])(); - SDL_Surface *surfaces[3]; - SDL_Palette *physpal; - SDL_Color *gammacols; - char *wm_strings[2]; - int offsets[2]; - SDL_GrabMode input_grab; - int handles_any_size; - SDL_PrivateVideoData *hidden; // Why did they have to bury this so far in? -}; - -extern SDL_VideoDevice *current_video; -#define SDL_Display (current_video->hidden->X11_Display) - -SDL_Cursor *CreateColorCursor(FTexture *cursorpic) -{ - return NULL; -} -#endif - bool I_SetCursor(FTexture *cursorpic) { + static SDL_Cursor *cursor; + static SDL_Surface *cursorSurface; + if (cursorpic != NULL && cursorpic->UseType != FTexture::TEX_Null) { // Must be no larger than 32x32. @@ -72,25 +22,9 @@ bool I_SetCursor(FTexture *cursorpic) return false; } -#ifdef USE_XCURSOR - if (UseXCursor) - { - if (FirstCursor == NULL) - { - FirstCursor = SDL_GetCursor(); - } - X11Cursor = CreateColorCursor(cursorpic); - if (X11Cursor != NULL) - { - SDL_SetCursor(X11Cursor); - return true; - } - } -#endif if (cursorSurface == NULL) cursorSurface = SDL_CreateRGBSurface (0, 32, 32, 32, MAKEARGB(0,255,0,0), MAKEARGB(0,0,255,0), MAKEARGB(0,0,0,255), MAKEARGB(255,0,0,0)); - SDL_ShowCursor(0); SDL_LockSurface(cursorSurface); BYTE buffer[32*32*4]; memset(buffer, 0, 32*32*4); @@ -98,24 +32,25 @@ bool I_SetCursor(FTexture *cursorpic) cursorpic->CopyTrueColorPixels(&bmp, 0, 0); memcpy(cursorSurface->pixels, bmp.GetPixels(), 32*32*4); SDL_UnlockSurface(cursorSurface); + + if (cursor) + SDL_FreeCursor (cursor); + cursor = SDL_CreateColorCursor (cursorSurface, 0, 0); + SDL_SetCursor (cursor); } else { - SDL_ShowCursor(1); - + if (cursor) + { + SDL_SetCursor (NULL); + SDL_FreeCursor (cursor); + cursor = NULL; + } if (cursorSurface != NULL) { SDL_FreeSurface(cursorSurface); cursorSurface = NULL; } -#ifdef USE_XCURSOR - if (X11Cursor != NULL) - { - SDL_SetCursor(FirstCursor); - SDL_FreeCursor(X11Cursor); - X11Cursor = NULL; - } -#endif } return true; } diff --git a/src/sdl/i_input.cpp b/src/sdl/i_input.cpp index bf676db70..210cf2e2c 100644 --- a/src/sdl/i_input.cpp +++ b/src/sdl/i_input.cpp @@ -18,6 +18,8 @@ #include "templates.h" #include "s_sound.h" +void ScaleWithAspect (int &w, int &h, int Width, int Height); + static void I_CheckGUICapture (); static void I_CheckNativeMouse (); @@ -29,31 +31,27 @@ extern int paused; CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_filter, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR (Bool, sdl_nokeyrepeat, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) EXTERN_CVAR (Bool, fullscreen) extern int WaitingForKey, chatmodeon; extern constate_e ConsoleState; -extern SDL_Surface *cursorSurface; -extern SDL_Rect cursorBlit; +static bool DownState[SDL_NUM_SCANCODES]; -static BYTE KeySymToDIK[SDLK_LAST], DownState[SDLK_LAST]; - -static WORD DIKToKeySym[256] = +static const SDL_Keycode DIKToKeySym[256] = { - 0, SDLK_ESCAPE, '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', '-', '=', SDLK_BACKSPACE, SDLK_TAB, - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', SDLK_RETURN, SDLK_LCTRL, 'a', 's', - 'd', 'f', 'g', 'h', 'j', 'k', 'l', SDLK_SEMICOLON, - '\'', '`', SDLK_LSHIFT, '\\', 'z', 'x', 'c', 'v', - 'b', 'n', 'm', ',', '.', '/', SDLK_RSHIFT, SDLK_KP_MULTIPLY, - SDLK_LALT, ' ', SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, - SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_NUMLOCK, SDLK_SCROLLOCK, SDLK_KP7, - SDLK_KP8, SDLK_KP9, SDLK_KP_MINUS, SDLK_KP4, SDLK_KP5, SDLK_KP6, SDLK_KP_PLUS, SDLK_KP1, - SDLK_KP2, SDLK_KP3, SDLK_KP0, SDLK_KP_PERIOD, 0, 0, 0, SDLK_F11, + 0, SDLK_ESCAPE, SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, + SDLK_7, SDLK_8, SDLK_9, SDLK_0,SDLK_MINUS, SDLK_EQUALS, SDLK_BACKSPACE, SDLK_TAB, + SDLK_q, SDLK_w, SDLK_e, SDLK_r, SDLK_t, SDLK_y, SDLK_u, SDLK_i, + SDLK_o, SDLK_p, SDLK_LEFTBRACKET, SDLK_RIGHTBRACKET, SDLK_RETURN, SDLK_LCTRL, SDLK_a, SDLK_s, + SDLK_d, SDLK_f, SDLK_g, SDLK_h, SDLK_j, SDLK_k, SDLK_l, SDLK_SEMICOLON, + SDLK_QUOTE, SDLK_BACKQUOTE, SDLK_LSHIFT, SDLK_BACKSLASH, SDLK_z, SDLK_x, SDLK_c, SDLK_v, + SDLK_b, SDLK_n, SDLK_m, SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_RSHIFT, SDLK_KP_MULTIPLY, + SDLK_LALT, SDLK_SPACE, SDLK_CAPSLOCK, SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, + SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_NUMLOCKCLEAR, SDLK_SCROLLLOCK, SDLK_KP_7, + SDLK_KP_8, SDLK_KP_9, SDLK_KP_MINUS, SDLK_KP_4, SDLK_KP_5, SDLK_KP_6, SDLK_KP_PLUS, SDLK_KP_1, + SDLK_KP_2, SDLK_KP_3, SDLK_KP_0, SDLK_KP_PERIOD, 0, 0, 0, SDLK_F11, SDLK_F12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SDLK_F13, SDLK_F14, SDLK_F15, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -65,24 +63,58 @@ static WORD DIKToKeySym[256] = 0, 0, 0, 0, SDLK_KP_ENTER, SDLK_RCTRL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, SDLK_KP_DIVIDE, 0, SDLK_SYSREQ, + 0, 0, 0, SDLK_KP_COMMA, 0, SDLK_KP_DIVIDE, 0, SDLK_SYSREQ, SDLK_RALT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SDLK_PAUSE, 0, SDLK_HOME, SDLK_UP, SDLK_PAGEUP, 0, SDLK_LEFT, 0, SDLK_RIGHT, 0, SDLK_END, SDLK_DOWN, SDLK_PAGEDOWN, SDLK_INSERT, SDLK_DELETE, 0, 0, 0, 0, - 0, 0, 0, SDLK_LSUPER, SDLK_RSUPER, SDLK_MENU, SDLK_POWER, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, SDLK_LGUI, SDLK_RGUI, SDLK_MENU, SDLK_POWER, SDLK_SLEEP, + 0, 0, 0, 0, 0, SDLK_AC_SEARCH, SDLK_AC_BOOKMARKS, SDLK_AC_REFRESH, + SDLK_AC_STOP, SDLK_AC_FORWARD, SDLK_AC_BACK, SDLK_COMPUTER, SDLK_MAIL, SDLK_MEDIASELECT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static void FlushDIKState (int low=0, int high=NUM_KEYS-1) +static const SDL_Scancode DIKToKeyScan[256] = { -} + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, + SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0 ,SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, + SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, + SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, + SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, + SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, + SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_KP_MULTIPLY, + SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, + SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_KP_7, + SDL_SCANCODE_KP_8, SDL_SCANCODE_KP_9, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_KP_4, SDL_SCANCODE_KP_5, SDL_SCANCODE_KP_6, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_KP_1, + SDL_SCANCODE_KP_2, SDL_SCANCODE_KP_3, SDL_SCANCODE_KP_0, SDL_SCANCODE_KP_PERIOD, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F11, + SDL_SCANCODE_F12, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_EQUALS, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_ENTER, SDL_SCANCODE_RCTRL, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_COMMA, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_KP_DIVIDE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_SYSREQ, + SDL_SCANCODE_RALT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_HOME, + SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_END, + SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_MENU, SDL_SCANCODE_POWER, SDL_SCANCODE_SLEEP, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_AC_SEARCH, SDL_SCANCODE_AC_BOOKMARKS, SDL_SCANCODE_AC_REFRESH, + SDL_SCANCODE_AC_STOP, SDL_SCANCODE_AC_FORWARD, SDL_SCANCODE_AC_BACK, SDL_SCANCODE_COMPUTER, SDL_SCANCODE_MAIL, SDL_SCANCODE_MEDIASELECT, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, + SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN +}; -static void InitKeySymMap () +static TMap InitKeySymMap () { + TMap KeySymToDIK; + for (int i = 0; i < 256; ++i) { KeySymToDIK[DIKToKeySym[i]] = i; @@ -92,16 +124,28 @@ static void InitKeySymMap () KeySymToDIK[SDLK_RCTRL] = DIK_LCONTROL; KeySymToDIK[SDLK_RALT] = DIK_LMENU; // Depending on your Linux flavor, you may get SDLK_PRINT or SDLK_SYSREQ - KeySymToDIK[SDLK_PRINT] = DIK_SYSRQ; + KeySymToDIK[SDLK_PRINTSCREEN] = DIK_SYSRQ; + + return KeySymToDIK; } +static const TMap KeySymToDIK(InitKeySymMap()); + +static TMap InitKeyScanMap () +{ + TMap KeyScanToDIK; + + for (int i = 0; i < 256; ++i) + { + KeyScanToDIK[DIKToKeyScan[i]] = i; + } + + return KeyScanToDIK; +} +static const TMap KeyScanToDIK(InitKeyScanMap()); static void I_CheckGUICapture () { bool wantCapt; - bool repeat; - int oldrepeat, interval; - - SDL_GetKeyRepeat(&oldrepeat, &interval); if (menuactive == MENU_Off) { @@ -117,56 +161,21 @@ static void I_CheckGUICapture () GUICapture = wantCapt; if (wantCapt) { - int x, y; - SDL_GetMouseState (&x, &y); - cursorBlit.x = x; - cursorBlit.y = y; - - FlushDIKState (); memset (DownState, 0, sizeof(DownState)); - repeat = !sdl_nokeyrepeat; - SDL_EnableUNICODE (1); - } - else - { - repeat = false; - SDL_EnableUNICODE (0); - } - } - if (wantCapt) - { - repeat = !sdl_nokeyrepeat; - } - else - { - repeat = false; - } - if (repeat != (oldrepeat != 0)) - { - if (repeat) - { - SDL_EnableKeyRepeat (SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - } - else - { - SDL_EnableKeyRepeat (0, 0); } } } void I_SetMouseCapture() { + // Clear out any mouse movement. + SDL_GetRelativeMouseState (NULL, NULL); + SDL_SetRelativeMouseMode (SDL_TRUE); } void I_ReleaseMouseCapture() { -} - -static void CenterMouse () -{ - SDL_WarpMouse (screen->GetWidth()/2, screen->GetHeight()/2); - SDL_PumpEvents (); - SDL_GetRelativeMouseState (NULL, NULL); + SDL_SetRelativeMouseMode (SDL_FALSE); } static void PostMouseMove (int x, int y) @@ -210,33 +219,10 @@ static void MouseRead () } if (x | y) { - CenterMouse (); PostMouseMove (x, -y); } } -static void WheelMoved(event_t *event) -{ - if (GUICapture) - { - if (event->type != EV_KeyUp) - { - SDLMod mod = SDL_GetModState(); - event->type = EV_GUI_Event; - event->subtype = event->data1 == KEY_MWHEELUP ? EV_GUI_WheelUp : EV_GUI_WheelDown; - event->data1 = 0; - event->data3 = ((mod & KMOD_SHIFT) ? GKM_SHIFT : 0) | - ((mod & KMOD_CTRL) ? GKM_CTRL : 0) | - ((mod & KMOD_ALT) ? GKM_ALT : 0); - D_PostEvent(event); - } - } - else - { - D_PostEvent(event); - } -} - CUSTOM_CVAR(Int, mouse_capturemode, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) { if (self < 0) self = 0; @@ -259,26 +245,19 @@ static bool inGame() static void I_CheckNativeMouse () { - bool focus = (SDL_GetAppState() & (SDL_APPINPUTFOCUS|SDL_APPACTIVE)) - == (SDL_APPINPUTFOCUS|SDL_APPACTIVE); - bool fs = (SDL_GetVideoSurface ()->flags & SDL_FULLSCREEN) != 0; + bool focus = SDL_GetKeyboardFocus() != NULL; + bool fs = screen->IsFullscreen(); bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !inGame()); if (wantNative != NativeMouse) { NativeMouse = wantNative; - SDL_ShowCursor (wantNative ? cursorSurface == NULL : 0); + SDL_ShowCursor (wantNative); if (wantNative) - { - SDL_WM_GrabInput (SDL_GRAB_OFF); - FlushDIKState (KEY_MOUSE1, KEY_MOUSE8); - } + I_ReleaseMouseCapture (); else - { - SDL_WM_GrabInput (SDL_GRAB_ON); - CenterMouse (); - } + I_SetMouseCapture (); } } @@ -293,14 +272,13 @@ void MessagePump (const SDL_Event &sev) case SDL_QUIT: exit (0); - case SDL_ACTIVEEVENT: - if (sev.active.state == SDL_APPINPUTFOCUS) + case SDL_WINDOWEVENT: + switch (sev.window.event) { - if (sev.active.gain == 0) - { // kill focus - FlushDIKState (); - } - S_SetSoundPaused(sev.active.gain); + case SDL_WINDOWEVENT_FOCUS_GAINED: + case SDL_WINDOWEVENT_FOCUS_LOST: + S_SetSoundPaused(sev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED); + break; } break; @@ -320,32 +298,20 @@ void MessagePump (const SDL_Event &sev) */ switch (sev.button.button) { - case 1: event.data1 = KEY_MOUSE1; break; - case 2: event.data1 = KEY_MOUSE3; break; - case 3: event.data1 = KEY_MOUSE2; break; - case 4: event.data1 = KEY_MWHEELUP; break; - case 5: event.data1 = KEY_MWHEELDOWN; break; - case 6: event.data1 = KEY_MOUSE4; break; /* dunno; not generated by my mouse */ - case 7: event.data1 = KEY_MOUSE5; break; /* ditto */ - case 8: event.data1 = KEY_MOUSE4; break; + case SDL_BUTTON_LEFT: event.data1 = KEY_MOUSE1; break; + case SDL_BUTTON_MIDDLE: event.data1 = KEY_MOUSE3; break; + case SDL_BUTTON_RIGHT: event.data1 = KEY_MOUSE2; break; + case 8: event.data1 = KEY_MOUSE4; break; // For whatever reason my side mouse buttons are here. case 9: event.data1 = KEY_MOUSE5; break; - case 10: event.data1 = KEY_MOUSE6; break; - case 11: event.data1 = KEY_MOUSE7; break; - case 12: event.data1 = KEY_MOUSE8; break; + case SDL_BUTTON_X1: event.data1 = KEY_MOUSE6; break; // And these don't exist + case SDL_BUTTON_X2: event.data1 = KEY_MOUSE7; break; + case 6: event.data1 = KEY_MOUSE8; break; default: printf("SDL mouse button %s %d\n", sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break; } if (event.data1 != 0) { - //DIKState[ActiveDIKState][event.data1] = (event.type == EV_KeyDown); - if (event.data1 == KEY_MWHEELUP || event.data1 == KEY_MWHEELDOWN) - { - WheelMoved(&event); - } - else - { - D_PostEvent(&event); - } + D_PostEvent(&event); } } } @@ -354,8 +320,35 @@ void MessagePump (const SDL_Event &sev) int x, y; SDL_GetMouseState (&x, &y); - cursorBlit.x = event.data1 = x; - cursorBlit.y = event.data2 = y; + // Detect if we're doing scaling in the Window and adjust the mouse + // coordinates accordingly. This could be more efficent, but I + // don't think performance is an issue in the menus. + SDL_Window *focus; + if (screen->IsFullscreen() && (focus = SDL_GetMouseFocus ())) + { + int w, h; + SDL_GetWindowSize (focus, &w, &h); + int realw = w, realh = h; + ScaleWithAspect (realw, realh, SCREENWIDTH, SCREENHEIGHT); + if (realw != SCREENWIDTH || realh != SCREENHEIGHT) + { + double xratio = (double)SCREENWIDTH/realw; + double yratio = (double)SCREENHEIGHT/realh; + if (realw < w) + { + x = (x - (w - realw)/2)*xratio; + y *= yratio; + } + else + { + y = (y - (h - realh)/2)*yratio; + x *= xratio; + } + } + } + + event.data1 = x; + event.data2 = y; event.type = EV_GUI_Event; if(sev.type == SDL_MOUSEMOTION) event.subtype = EV_GUI_MouseMove; @@ -368,15 +361,38 @@ void MessagePump (const SDL_Event &sev) } break; + case SDL_MOUSEWHEEL: + if (GUICapture) + { + event.type = EV_GUI_Event; + event.subtype = sev.wheel.y > 0 ? EV_GUI_WheelUp : EV_GUI_WheelDown; + D_PostEvent (&event); + } + else + { + event.type = EV_KeyDown; + event.data1 = sev.wheel.y > 0 ? KEY_MWHEELUP : KEY_MWHEELDOWN; + D_PostEvent (&event); + event.type = EV_KeyUp; + D_PostEvent (&event); + } + break; + case SDL_KEYDOWN: case SDL_KEYUP: - if (sev.key.keysym.sym >= SDLK_LAST) - break; - if (!GUICapture) { event.type = sev.type == SDL_KEYDOWN ? EV_KeyDown : EV_KeyUp; - event.data1 = KeySymToDIK[sev.key.keysym.sym]; + + // Try to look up our key mapped key for conversion to DirectInput. + // If that fails, then we'll do a lookup against the scan code, + // which may not return the right key, but at least the key should + // work in the game. + if (const BYTE *dik = KeySymToDIK.CheckKey (sev.key.keysym.sym)) + event.data1 = *dik; + else if (const BYTE *dik = KeyScanToDIK.CheckKey (sev.key.keysym.scancode)) + event.data1 = *dik; + if (event.data1) { if (sev.key.keysym.sym < 256) @@ -394,20 +410,17 @@ void MessagePump (const SDL_Event &sev) ((sev.key.keysym.mod & KMOD_CTRL) ? GKM_CTRL : 0) | ((sev.key.keysym.mod & KMOD_ALT) ? GKM_ALT : 0); - if (sev.key.keysym.sym < SDLK_LAST) + if (event.subtype == EV_GUI_KeyDown) { - if (event.subtype == EV_GUI_KeyDown) + if (DownState[sev.key.keysym.scancode]) { - if (DownState[sev.key.keysym.sym]) - { - event.subtype = EV_GUI_KeyRepeat; - } - DownState[sev.key.keysym.sym] = 1; - } - else - { - DownState[sev.key.keysym.sym] = 0; + event.subtype = EV_GUI_KeyRepeat; } + DownState[sev.key.keysym.scancode] = 1; + } + else + { + DownState[sev.key.keysym.scancode] = 0; } switch (sev.key.keysym.sym) @@ -442,20 +455,21 @@ void MessagePump (const SDL_Event &sev) } break; } - event.data2 = sev.key.keysym.unicode & 0xff; if (event.data1 < 128) { event.data1 = toupper(event.data1); D_PostEvent (&event); } - if (!iscntrl(event.data2) && event.subtype != EV_GUI_KeyUp) - { - event.subtype = EV_GUI_Char; - event.data1 = event.data2; - event.data2 = sev.key.keysym.mod & KMOD_ALT; - event.data3 = 0; - D_PostEvent (&event); - } + } + break; + + case SDL_TEXTINPUT: + if (GUICapture) + { + event.type = EV_GUI_Event; + event.subtype = EV_GUI_Char; + event.data1 = sev.text.text[0]; + D_PostEvent (&event); } break; @@ -496,10 +510,5 @@ void I_StartTic () void I_ProcessJoysticks (); void I_StartFrame () { - if (KeySymToDIK[SDLK_BACKSPACE] == 0) - { - InitKeySymMap (); - } - I_ProcessJoysticks(); } diff --git a/src/sdl/i_joystick.cpp b/src/sdl/i_joystick.cpp index 7a529861f..9b1d326ae 100644 --- a/src/sdl/i_joystick.cpp +++ b/src/sdl/i_joystick.cpp @@ -35,7 +35,7 @@ public: FString GetName() { - return SDL_JoystickName(DeviceIndex); + return SDL_JoystickName(Device); } float GetSensitivity() { diff --git a/src/sdl/i_main.cpp b/src/sdl/i_main.cpp index 7a18fb05f..33395e0f1 100644 --- a/src/sdl/i_main.cpp +++ b/src/sdl/i_main.cpp @@ -85,10 +85,6 @@ void Mac_I_FatalError(const char* errortext); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- -#ifdef USE_XCURSOR -extern bool UseXCursor; -#endif - // PUBLIC DATA DEFINITIONS ------------------------------------------------- #ifndef NO_GTK @@ -241,7 +237,11 @@ void I_ShutdownJoysticks(); const char* I_GetBackEndName(); +#ifdef USE_NATIVE_COCOA +int SDL_main (int argc, char **argv) +#else int main (int argc, char **argv) +#endif { #if !defined (__APPLE__) { @@ -278,27 +278,13 @@ int main (int argc, char **argv) } atterm (SDL_Quit); - { - char viddriver[80]; - - if (SDL_VideoDriverName(viddriver, sizeof(viddriver)) != NULL) - { - printf("Using video driver %s\n", viddriver); -#ifdef USE_XCURSOR - UseXCursor = (strcmp(viddriver, "x11") == 0); -#endif - } - printf("\n"); - } - - char caption[100]; - mysnprintf(caption, countof(caption), GAMESIG " %s (%s)", GetVersionString(), GetGitTime()); - SDL_WM_SetCaption(caption, caption); + printf("Using video driver %s\n", SDL_GetCurrentVideoDriver()); + printf("\n"); #ifdef __APPLE__ - - const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); - if ( NULL != videoInfo ) + EXTERN_CVAR( Int, vid_adapter ) + SDL_DisplayMode videoInfo = {}; + if ( SDL_GetDesktopDisplayMode (vid_adapter, &videoInfo) == 0 ) { EXTERN_CVAR( Int, vid_defwidth ) EXTERN_CVAR( Int, vid_defheight ) @@ -306,13 +292,11 @@ int main (int argc, char **argv) EXTERN_CVAR( Bool, vid_vsync ) EXTERN_CVAR( Bool, fullscreen ) - vid_defwidth = videoInfo->current_w; - vid_defheight = videoInfo->current_h; - vid_defbits = videoInfo->vfmt->BitsPerPixel; + vid_defwidth = videoInfo.w; + vid_defheight = videoInfo.h; vid_vsync = true; fullscreen = true; - } - + } #endif // __APPLE__ try diff --git a/src/sdl/sdlvideo.cpp b/src/sdl/sdlvideo.cpp index e4222633d..e477df526 100644 --- a/src/sdl/sdlvideo.cpp +++ b/src/sdl/sdlvideo.cpp @@ -12,6 +12,7 @@ #include "v_palette.h" #include "sdlvideo.h" #include "r_swrenderer.h" +#include "version.h" #include @@ -42,6 +43,7 @@ public: bool SetGamma (float gamma); bool SetFlash (PalEntry rgb, int amount); void GetFlash (PalEntry &rgb, int &amount); + void SetFullscreen (bool fullscreen); int GetPageCount (); bool IsFullscreen (); @@ -56,14 +58,23 @@ private: int FlashAmount; float Gamma; bool UpdatePending; - - SDL_Surface *Screen; - + + SDL_Window *Screen; + SDL_Renderer *Renderer; + union + { + SDL_Texture *Texture; + SDL_Surface *Surface; + }; + SDL_Rect UpdateRect; + + bool UsingRenderer; bool NeedPalUpdate; bool NeedGammaUpdate; bool NotPaletted; - + void UpdateColors (); + void ResetSDLRenderer (); SDLFB () {} }; @@ -83,9 +94,6 @@ struct MiniModeInfo extern IVideo *Video; extern bool GUICapture; -SDL_Surface *cursorSurface = NULL; -SDL_Rect cursorBlit = {0, 0, 32, 32}; - EXTERN_CVAR (Float, Gamma) EXTERN_CVAR (Int, vid_maxfps) EXTERN_CVAR (Bool, cl_capfps) @@ -93,11 +101,11 @@ EXTERN_CVAR (Bool, vid_vsync) // PUBLIC DATA DEFINITIONS ------------------------------------------------- -CVAR (Int, vid_displaybits, 8, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CVAR (Int, vid_adapter, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -// vid_asyncblit needs a restart to work. SDL doesn't seem to change if the -// frame buffer is changed at run time. -CVAR (Bool, vid_asyncblit, 1, CVAR_NOINITCALL|CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CVAR (Int, vid_displaybits, 32, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) + +CVAR (Bool, vid_forcesurface, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CUSTOM_CVAR (Float, rgamma, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { @@ -140,12 +148,14 @@ static MiniModeInfo WinModes[] = { 720, 480 }, // 16:10 { 720, 540 }, { 800, 450 }, // 16:9 + { 800, 480 }, { 800, 500 }, // 16:10 { 800, 600 }, { 848, 480 }, // 16:9 { 960, 600 }, // 16:10 { 960, 720 }, { 1024, 576 }, // 16:9 + { 1024, 600 }, // 17:10 { 1024, 640 }, // 16:10 { 1024, 768 }, { 1088, 612 }, // 16:9 @@ -153,16 +163,33 @@ static MiniModeInfo WinModes[] = { 1152, 720 }, // 16:10 { 1152, 864 }, { 1280, 720 }, // 16:9 + { 1280, 854 }, { 1280, 800 }, // 16:10 { 1280, 960 }, + { 1280, 1024 }, // 5:4 { 1360, 768 }, // 16:9 + { 1366, 768 }, { 1400, 787 }, // 16:9 { 1400, 875 }, // 16:10 { 1400, 1050 }, + { 1440, 900 }, + { 1440, 960 }, + { 1440, 1080 }, { 1600, 900 }, // 16:9 { 1600, 1000 }, // 16:10 { 1600, 1200 }, { 1920, 1080 }, + { 1920, 1200 }, + { 2048, 1536 }, + { 2560, 1440 }, + { 2560, 1600 }, + { 2560, 2048 }, + { 2880, 1800 }, + { 3200, 1800 }, + { 3840, 2160 }, + { 3840, 2400 }, + { 4096, 2160 }, + { 5120, 2880 } }; static cycle_t BlitCycles; @@ -170,10 +197,34 @@ static cycle_t SDLFlipCycles; // CODE -------------------------------------------------------------------- +void ScaleWithAspect (int &w, int &h, int Width, int Height) +{ + int resRatio = CheckRatio (Width, Height); + int screenRatio; + CheckRatio (w, h, &screenRatio); + if (resRatio == screenRatio) + return; + + double yratio; + switch(resRatio) + { + case 0: yratio = 4./3.; break; + case 1: yratio = 16./9.; break; + case 2: yratio = 16./10.; break; + case 3: yratio = 17./10.; break; + case 4: yratio = 5./4.; break; + default: return; + } + double y = w/yratio; + if (y > h) + w = h*yratio; + else + h = y; +} + SDLVideo::SDLVideo (int parm) { IteratorBits = 0; - IteratorFS = false; } SDLVideo::~SDLVideo () @@ -184,34 +235,19 @@ void SDLVideo::StartModeIterator (int bits, bool fs) { IteratorMode = 0; IteratorBits = bits; - IteratorFS = fs; } bool SDLVideo::NextMode (int *width, int *height, bool *letterbox) { if (IteratorBits != 8) return false; - - if (!IteratorFS) + + if ((unsigned)IteratorMode < sizeof(WinModes)/sizeof(WinModes[0])) { - if ((unsigned)IteratorMode < sizeof(WinModes)/sizeof(WinModes[0])) - { - *width = WinModes[IteratorMode].Width; - *height = WinModes[IteratorMode].Height; - ++IteratorMode; - return true; - } - } - else - { - SDL_Rect **modes = SDL_ListModes (NULL, SDL_FULLSCREEN|SDL_HWSURFACE); - if (modes != NULL && modes[IteratorMode] != NULL) - { - *width = modes[IteratorMode]->w; - *height = modes[IteratorMode]->h; - ++IteratorMode; - return true; - } + *width = WinModes[IteratorMode].Width; + *height = WinModes[IteratorMode].Height; + ++IteratorMode; + return true; } return false; } @@ -230,11 +266,11 @@ DFrameBuffer *SDLVideo::CreateFrameBuffer (int width, int height, bool fullscree if (fb->Width == width && fb->Height == height) { - bool fsnow = (fb->Screen->flags & SDL_FULLSCREEN) != 0; + bool fsnow = (SDL_GetWindowFlags (fb->Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0; if (fsnow != fullscreen) { - SDL_WM_ToggleFullScreen (fb->Screen); + fb->SetFullscreen (fullscreen); } return old; } @@ -313,32 +349,48 @@ SDLFB::SDLFB (int width, int height, bool fullscreen) UpdatePending = false; NotPaletted = false; FlashAmount = 0; - Screen = SDL_SetVideoMode (width, height, vid_displaybits, - (vid_asyncblit ? SDL_ASYNCBLIT : 0)|SDL_HWSURFACE|SDL_HWPALETTE|SDL_DOUBLEBUF|SDL_ANYFORMAT| - (fullscreen ? SDL_FULLSCREEN : 0)); + + FString caption; + caption.Format(GAMESIG " %s (%s)", GetVersionString(), GetGitTime()); + + Screen = SDL_CreateWindow (caption, + SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), SDL_WINDOWPOS_UNDEFINED_DISPLAY(vid_adapter), + width, height, (fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); if (Screen == NULL) return; + Renderer = NULL; + Texture = NULL; + ResetSDLRenderer (); + for (i = 0; i < 256; i++) { GammaTable[0][i] = GammaTable[1][i] = GammaTable[2][i] = i; } - if (Screen->format->palette == NULL) - { - NotPaletted = true; - GPfx.SetFormat (Screen->format->BitsPerPixel, - Screen->format->Rmask, - Screen->format->Gmask, - Screen->format->Bmask); - } + memcpy (SourcePalette, GPalette.BaseColors, sizeof(PalEntry)*256); UpdateColors (); + +#ifdef __APPLE__ SetVSync (vid_vsync); +#endif } + SDLFB::~SDLFB () { + if(Screen) + { + if (Renderer) + { + if (Texture) + SDL_DestroyTexture (Texture); + SDL_DestroyRenderer (Renderer); + } + + SDL_DestroyWindow (Screen); + } } bool SDLFB::IsValid () @@ -403,41 +455,60 @@ void SDLFB::Update () SDLFlipCycles.Reset(); BlitCycles.Clock(); - if (SDL_LockSurface (Screen) == -1) - return; + void *pixels; + int pitch; + if (UsingRenderer) + { + if (SDL_LockTexture (Texture, NULL, &pixels, &pitch)) + return; + } + else + { + if (SDL_LockSurface (Surface)) + return; + + pixels = Surface->pixels; + pitch = Surface->pitch; + } if (NotPaletted) { GPfx.Convert (MemBuffer, Pitch, - Screen->pixels, Screen->pitch, Width, Height, + pixels, pitch, Width, Height, FRACUNIT, FRACUNIT, 0, 0); } else { - if (Screen->pitch == Pitch) + if (pitch == Pitch) { - memcpy (Screen->pixels, MemBuffer, Width*Height); + memcpy (pixels, MemBuffer, Width*Height); } else { for (int y = 0; y < Height; ++y) { - memcpy ((BYTE *)Screen->pixels+y*Screen->pitch, MemBuffer+y*Pitch, Width); + memcpy ((BYTE *)pixels+y*pitch, MemBuffer+y*Pitch, Width); } } } - - SDL_UnlockSurface (Screen); - if (cursorSurface != NULL && GUICapture) + if (UsingRenderer) { - // SDL requires us to draw a surface to get true color cursors. - SDL_BlitSurface(cursorSurface, NULL, Screen, &cursorBlit); - } + SDL_UnlockTexture (Texture); - SDLFlipCycles.Clock(); - SDL_Flip (Screen); - SDLFlipCycles.Unclock(); + SDLFlipCycles.Clock(); + SDL_RenderCopy(Renderer, Texture, NULL, &UpdateRect); + SDL_RenderPresent(Renderer); + SDLFlipCycles.Unclock(); + } + else + { + SDL_UnlockSurface (Surface); + + SDLFlipCycles.Clock(); + SDL_UpdateWindowSurface (Screen); + SDLFlipCycles.Unclock(); + } BlitCycles.Unclock(); @@ -494,7 +565,7 @@ void SDLFB::UpdateColors () 256, GammaTable[2][Flash.b], GammaTable[1][Flash.g], GammaTable[0][Flash.r], FlashAmount); } - SDL_SetPalette (Screen, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); + SDL_SetPaletteColors (Surface->format->palette, colors, 0, 256); } } @@ -539,9 +610,95 @@ void SDLFB::GetFlashedPalette (PalEntry pal[256]) } } +void SDLFB::SetFullscreen (bool fullscreen) +{ + SDL_SetWindowFullscreen (Screen, fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + if (!fullscreen) + { + // Restore proper window size + SDL_SetWindowSize (Screen, Width, Height); + } + + ResetSDLRenderer (); +} + bool SDLFB::IsFullscreen () { - return (Screen->flags & SDL_FULLSCREEN) != 0; + return (SDL_GetWindowFlags (Screen) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0; +} + +void SDLFB::ResetSDLRenderer () +{ + if (Renderer) + { + if (Texture) + SDL_DestroyTexture (Texture); + SDL_DestroyRenderer (Renderer); + } + + UsingRenderer = !vid_forcesurface; + if (UsingRenderer) + { + Renderer = SDL_CreateRenderer (Screen, -1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_TARGETTEXTURE| + (vid_vsync ? SDL_RENDERER_PRESENTVSYNC : 0)); + if (!Renderer) + return; + + Uint32 fmt; + switch(vid_displaybits) + { + default: fmt = SDL_PIXELFORMAT_ARGB8888; break; + case 30: fmt = SDL_PIXELFORMAT_ARGB2101010; break; + case 24: fmt = SDL_PIXELFORMAT_RGB888; break; + case 16: fmt = SDL_PIXELFORMAT_RGB565; break; + case 15: fmt = SDL_PIXELFORMAT_ARGB1555; break; + } + Texture = SDL_CreateTexture (Renderer, fmt, SDL_TEXTUREACCESS_STREAMING, Width, Height); + + { + NotPaletted = true; + + Uint32 format; + SDL_QueryTexture(Texture, &format, NULL, NULL, NULL); + + Uint32 Rmask, Gmask, Bmask, Amask; + int bpp; + SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); + GPfx.SetFormat (bpp, Rmask, Gmask, Bmask); + } + } + else + { + Surface = SDL_GetWindowSurface (Screen); + + if (Surface->format->palette == NULL) + { + NotPaletted = true; + GPfx.SetFormat (Surface->format->BitsPerPixel, Surface->format->Rmask, Surface->format->Gmask, Surface->format->Bmask); + } + else + NotPaletted = false; + } + + // Calculate update rectangle + if (IsFullscreen ()) + { + int w, h; + SDL_GetWindowSize (Screen, &w, &h); + UpdateRect.w = w; + UpdateRect.h = h; + ScaleWithAspect (UpdateRect.w, UpdateRect.h, Width, Height); + UpdateRect.x = (w - UpdateRect.w)/2; + UpdateRect.y = (h - UpdateRect.h)/2; + } + else + { + // In windowed mode we just update the whole window. + UpdateRect.x = 0; + UpdateRect.y = 0; + UpdateRect.w = Width; + UpdateRect.h = Height; + } } void SDLFB::SetVSync (bool vsync) @@ -561,6 +718,8 @@ void SDLFB::SetVSync (bool vsync) const GLint value = vsync ? 1 : 0; CGLSetParameter(context, kCGLCPSwapInterval, &value); } +#else + ResetSDLRenderer (); #endif // __APPLE__ } @@ -568,6 +727,6 @@ ADD_STAT (blit) { FString out; out.Format ("blit=%04.1f ms flip=%04.1f ms", - BlitCycles.Time() * 1e-3, SDLFlipCycles.TimeMS()); + BlitCycles.TimeMS(), SDLFlipCycles.TimeMS()); return out; } diff --git a/src/sdl/sdlvideo.h b/src/sdl/sdlvideo.h index 3cd38a140..8869f6fa7 100644 --- a/src/sdl/sdlvideo.h +++ b/src/sdl/sdlvideo.h @@ -18,5 +18,4 @@ class SDLVideo : public IVideo private: int IteratorMode; int IteratorBits; - bool IteratorFS; };