Fixes two crashers for games, with GHOST under SDL:
authorAlex Fraser <alex@phatcore.com>
Mon, 2 Jan 2012 12:35:06 +0000 (12:35 +0000)
committerAlex Fraser <alex@phatcore.com>
Mon, 2 Jan 2012 12:35:06 +0000 (12:35 +0000)
- Fixes SDL fullscreen mode for game engine (blenderplayer). Mode switching (resolution changes) not supported yet though.
- Fixes embedded game engine exit.
See patch tracker [#29748].

intern/ghost/intern/GHOST_DisplayManagerSDL.cpp
intern/ghost/intern/GHOST_DisplayManagerSDL.h
source/gameengine/GameLogic/CMakeLists.txt
source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp

index 1b73329f8bb317b4c96392cf7c52b454d2284150..4c67616a4c464b2650d9b5badafc4e73483f535b 100644 (file)
@@ -36,7 +36,7 @@ GHOST_DisplayManagerSDL::GHOST_DisplayManagerSDL(GHOST_SystemSDL *system)
 }
 
 GHOST_TSuccess
-GHOST_DisplayManagerSDL::getNumDisplays(GHOST_TUns8& numDisplays)
+GHOST_DisplayManagerSDL::getNumDisplays(GHOST_TUns8& numDisplays) const
 {
        numDisplays=  SDL_GetNumVideoDisplays();
        return GHOST_kSuccess;
@@ -44,7 +44,7 @@ GHOST_DisplayManagerSDL::getNumDisplays(GHOST_TUns8& numDisplays)
 
 
 GHOST_TSuccess GHOST_DisplayManagerSDL::getNumDisplaySettings(GHOST_TUns8 display,
-                                                              GHOST_TInt32& numSettings)
+                                                              GHOST_TInt32& numSettings) const
 {
        GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
        numSettings= GHOST_TInt32(1);
@@ -54,7 +54,7 @@ GHOST_TSuccess GHOST_DisplayManagerSDL::getNumDisplaySettings(GHOST_TUns8 displa
 GHOST_TSuccess
 GHOST_DisplayManagerSDL::getDisplaySetting(GHOST_TUns8 display,
                                            GHOST_TInt32 index,
-                                           GHOST_DisplaySetting& setting)
+                                           GHOST_DisplaySetting& setting) const
 {
 
        GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
@@ -74,7 +74,7 @@ GHOST_DisplayManagerSDL::getDisplaySetting(GHOST_TUns8 display,
 
 GHOST_TSuccess
 GHOST_DisplayManagerSDL::getCurrentDisplaySetting(GHOST_TUns8 display,
-                                                  GHOST_DisplaySetting& setting)
+                                                  GHOST_DisplaySetting& setting) const
 {
        return getDisplaySetting(display,GHOST_TInt32(0),setting);
 }
index ff8ab13c4fa8d6768dede4b97dad9c004521a9e7..297a61f41ff096968bb011cca0e870a1342278be 100644 (file)
@@ -46,20 +46,20 @@ public:
        GHOST_DisplayManagerSDL(GHOST_SystemSDL *system);
 
        GHOST_TSuccess
-       getNumDisplays(GHOST_TUns8& numDisplays);
+       getNumDisplays(GHOST_TUns8& numDisplays) const;
 
        GHOST_TSuccess
        getNumDisplaySettings(GHOST_TUns8 display,
-                             GHOST_TInt32& numSettings);
+                             GHOST_TInt32& numSettings) const;
 
        GHOST_TSuccess
        getDisplaySetting(GHOST_TUns8 display,
                          GHOST_TInt32 index,
-                         GHOST_DisplaySetting& setting);
+                         GHOST_DisplaySetting& setting) const;
 
        GHOST_TSuccess
        getCurrentDisplaySetting(GHOST_TUns8 display,
-                                GHOST_DisplaySetting& setting);
+                                GHOST_DisplaySetting& setting) const;
 
        GHOST_TSuccess
        setCurrentDisplaySetting(GHOST_TUns8 display,
index 64c2af9031bfd62872fc56c2fe06bb29fec3187f..98255bb8b97b9fe9384bdb9e331a23fb88233ce2 100644 (file)
@@ -132,6 +132,10 @@ if(WITH_SDL)
        )
 
        add_definitions(-DWITH_SDL)
+
+       if(WITH_GHOST_SDL)
+               add_definitions(-DWITH_GHOST_SDL)
+       endif()
 endif()
 
 blender_add_lib(ge_logic "${SRC}" "${INC}" "${INC_SYS}")
index 0547d97285dff59bec977f89d1747b745d13b6fe..15aeef242b756585abe93327a41f5c2b2a946b3d 100644 (file)
@@ -88,8 +88,14 @@ SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex )
        if (m_refCount == 0) 
        {
                int i;
-               // do this once only
+               // The video subsystem is required for joystick input to work. However,
+               // when GHOST is running under SDL, video is initialised elsewhere.
+               // Do this once only.
+#  ifdef WITH_GHOST_SDL
+               if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1 ){
+#  else
                if(SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) == -1 ){
+#  endif
                        echo("Error-Initializing-SDL: " << SDL_GetError());
                        return NULL;
                }
@@ -124,7 +130,14 @@ void SCA_Joystick::ReleaseInstance()
                        m_instance[i]= NULL;
                }
 
+               // The video subsystem is required for joystick input to work. However,
+               // when GHOST is running under SDL, video is freed elsewhere.
+               // Do this once only.
+#  ifdef WITH_GHOST_SDL
+               SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
+#  else
                SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
+#  endif
 #endif /* WITH_SDL */
        }
 }