Use SDL2 to handle window creation
This commit is contained in:
parent
4298e686d0
commit
2eaca2091e
@ -59,8 +59,6 @@ if (IOS)
|
||||
endif()
|
||||
|
||||
if((UNIX AND NOT APPLE) AND NOT SERVER_ONLY)
|
||||
option(ENABLE_WAYLAND_DEVICE "Enable Wayland device for linux build" ON)
|
||||
|
||||
if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm") OR
|
||||
(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
|
||||
option(USE_GLES2 "Use OpenGL ES2 renderer" ON)
|
||||
|
@ -27,7 +27,7 @@ if(NOT SERVER_ONLY)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT APPLE AND (USE_GLES2 OR ENABLE_WAYLAND_DEVICE))
|
||||
if(NOT APPLE AND USE_GLES2)
|
||||
find_package(EGL)
|
||||
|
||||
if(EGL_FOUND)
|
||||
@ -35,24 +35,10 @@ if(NOT SERVER_ONLY)
|
||||
else()
|
||||
if(USE_GLES2 AND NOT APPLE)
|
||||
message(FATAL_ERROR "EGL not found.")
|
||||
elseif(ENABLE_WAYLAND_DEVICE)
|
||||
message(WARNING "EGL not found. Disable wayland support.")
|
||||
set(ENABLE_WAYLAND_DEVICE OFF)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_WAYLAND_DEVICE)
|
||||
find_package(Wayland)
|
||||
|
||||
if(WAYLAND_FOUND AND NOT (WAYLAND_VERSION VERSION_LESS "1.14"))
|
||||
include_directories(${WAYLAND_INCLUDE_DIR})
|
||||
add_definitions(-D_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
|
||||
else()
|
||||
message(WARNING "Wayland not found. Disable wayland support.")
|
||||
set(ENABLE_WAYLAND_DEVICE OFF)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../src")
|
||||
@ -69,6 +55,7 @@ else()
|
||||
add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_)
|
||||
add_definitions(-DNO_IRR_COMPILE_WITH_X11_)
|
||||
add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND_DEVICE_)
|
||||
add_definitions(-DNO_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
endif()
|
||||
|
||||
if(APPLE AND NOT IOS)
|
||||
@ -87,14 +74,8 @@ if(WIN32)
|
||||
add_definitions(-D_IRR_STATIC_LIB_)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS) # Shut up about unsafe stuff
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pipe -O3 -fstrict-aliasing")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pipe -O3 -fstrict-aliasing")
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexpensive-optimizations")
|
||||
endif()
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexpensive-optimizations")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pipe -fstrict-aliasing")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pipe -fstrict-aliasing")
|
||||
endif()
|
||||
|
||||
if(USE_GLES2)
|
||||
@ -165,7 +146,6 @@ source/Irrlicht/CIrrDeviceAndroid.cpp
|
||||
source/Irrlicht/CIrrDeviceLinux.cpp
|
||||
source/Irrlicht/CIrrDeviceSDL.cpp
|
||||
source/Irrlicht/CIrrDeviceStub.cpp
|
||||
source/Irrlicht/CIrrDeviceWayland.cpp
|
||||
source/Irrlicht/CIrrDeviceWin32.cpp
|
||||
source/Irrlicht/CLightSceneNode.cpp
|
||||
source/Irrlicht/CLimitReadFile.cpp
|
||||
@ -297,7 +277,6 @@ source/Irrlicht/CIrrDeviceAndroid.h
|
||||
source/Irrlicht/CIrrDeviceLinux.h
|
||||
source/Irrlicht/CIrrDeviceSDL.h
|
||||
source/Irrlicht/CIrrDeviceStub.h
|
||||
source/Irrlicht/CIrrDeviceWayland.h
|
||||
source/Irrlicht/CIrrDeviceWin32.h
|
||||
source/Irrlicht/CLightSceneNode.h
|
||||
source/Irrlicht/CLimitReadFile.h
|
||||
@ -571,14 +550,6 @@ include/vector2d.h
|
||||
include/vector3d.h
|
||||
)
|
||||
|
||||
if(NOT SERVER_ONLY AND ENABLE_WAYLAND_DEVICE)
|
||||
set(IRRLICHT_SOURCES
|
||||
${IRRLICHT_SOURCES}
|
||||
source/Irrlicht/xdg_decoration_unstable_v1_protocol.c
|
||||
source/Irrlicht/xdg_shell_protocol.c)
|
||||
endif()
|
||||
|
||||
|
||||
if(APPLE AND NOT IOS)
|
||||
set(IRRLICHT_SOURCES
|
||||
${IRRLICHT_SOURCES}
|
||||
@ -620,13 +591,10 @@ if(NOT SERVER_ONLY)
|
||||
target_link_libraries(stkirrlicht ${X11_X11_LIB} ${X11_Xrandr_LIB})
|
||||
endif()
|
||||
|
||||
if(NOT APPLE AND (USE_GLES2 OR ENABLE_WAYLAND_DEVICE))
|
||||
if(NOT APPLE AND USE_GLES2)
|
||||
target_link_libraries(stkirrlicht ${EGL_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(ENABLE_WAYLAND_DEVICE)
|
||||
target_link_libraries(stkirrlicht ${WAYLAND_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
|
@ -56,8 +56,13 @@
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
|
||||
#define _IRR_WINDOWS_
|
||||
#define _IRR_WINDOWS_API_
|
||||
#ifndef NO_IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#define _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#undef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
|
||||
#else
|
||||
#define _IRR_COMPILE_WITH_WINDOWS_DEVICE_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1300)
|
||||
@ -87,9 +92,14 @@
|
||||
#define _IRR_COMPILE_WITH_IOS_DEVICE_
|
||||
#define _IRR_COMPILE_WITH_OGLES2_
|
||||
#else
|
||||
#ifndef NO_IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#define _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#undef _IRR_COMPILE_WITH_OSX_DEVICE_
|
||||
#else
|
||||
#define _IRR_COMPILE_WITH_OSX_DEVICE_
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Disable macOS/OSX device
|
||||
#ifdef NO_IRR_COMPILE_WITH_OSX_DEVICE_
|
||||
@ -107,24 +117,25 @@
|
||||
#define _IRR_COMPILE_ANDROID_ASSET_READER_
|
||||
#endif
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_OGLES2_) && !defined(_IRR_COMPILE_WITH_IOS_DEVICE_)
|
||||
#define _IRR_COMPILE_WITH_EGL_
|
||||
#endif
|
||||
|
||||
#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
|
||||
#ifndef _IRR_SOLARIS_PLATFORM_
|
||||
#define _IRR_LINUX_PLATFORM_
|
||||
#endif
|
||||
#define _IRR_POSIX_API_
|
||||
#ifndef NO_IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#define _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#else
|
||||
// For server only STK
|
||||
#define _IRR_COMPILE_WITH_X11_DEVICE_
|
||||
//#define _IRR_COMPILE_WITH_WAYLAND_DEVICE_
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NO_IRR_COMPILE_WITH_WAYLAND_DEVICE_
|
||||
#undef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_WAYLAND_DEVICE_
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_OGLES2_) && !defined(_IRR_COMPILE_WITH_IOS_DEVICE_) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
#define _IRR_COMPILE_WITH_EGL_
|
||||
#endif
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,8 +16,8 @@
|
||||
#include "IImagePresenter.h"
|
||||
#include "ICursorControl.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_syswm.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_syswm.h>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
@ -101,6 +101,8 @@ namespace irr
|
||||
return EIDT_SDL;
|
||||
}
|
||||
|
||||
SDL_Window* getWindow() const { return Window; }
|
||||
|
||||
//! Implementation of the linux cursor control
|
||||
class CCursorControl : public gui::ICursorControl
|
||||
{
|
||||
@ -148,7 +150,7 @@ namespace irr
|
||||
//! Sets the new position of the cursor.
|
||||
virtual void setPosition(s32 x, s32 y)
|
||||
{
|
||||
SDL_WarpMouse( x, y );
|
||||
SDL_WarpMouseGlobal( x, y );
|
||||
}
|
||||
|
||||
//! Returns the current position of the mouse cursor.
|
||||
@ -201,18 +203,14 @@ namespace irr
|
||||
|
||||
void createKeyMap();
|
||||
|
||||
SDL_Surface* Screen;
|
||||
int SDL_Flags;
|
||||
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
|
||||
core::array<SDL_Joystick*> Joysticks;
|
||||
#endif
|
||||
SDL_Window* Window;
|
||||
SDL_GLContext Context;
|
||||
|
||||
s32 MouseX, MouseY;
|
||||
u32 MouseButtonStates;
|
||||
|
||||
u32 Width, Height;
|
||||
|
||||
bool Resizable;
|
||||
bool WindowHasFocus;
|
||||
bool WindowMinimized;
|
||||
|
||||
@ -235,6 +233,7 @@ namespace irr
|
||||
|
||||
core::array<SKeyMap> KeyMap;
|
||||
SDL_SysWMinfo Info;
|
||||
void tryCreateOpenGLContext(u32 flags);
|
||||
};
|
||||
|
||||
} // end namespace irr
|
||||
|
@ -33,6 +33,10 @@
|
||||
#include "CIrrDeviceWayland.h"
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#include "CIrrDeviceSDL.h"
|
||||
#endif
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video
|
||||
@ -134,7 +138,6 @@ namespace video
|
||||
m_device = device;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//! destructor
|
||||
COGLES2Driver::~COGLES2Driver()
|
||||
@ -156,8 +159,23 @@ namespace video
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
COGLES2Driver::COGLES2Driver(const SIrrlichtCreationParameters& params,
|
||||
io::IFileSystem* io, CIrrDeviceSDL* device)
|
||||
: CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(),
|
||||
BridgeCalls(0), CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
|
||||
Transformation3DChanged(true), AntiAlias(params.AntiAlias),
|
||||
RenderTargetTexture(0), CurrentRendertargetSize(0, 0),
|
||||
ColorFormat(ECF_R8G8B8), Params(params)
|
||||
{
|
||||
genericDriverInit(params.WindowSize, params.Stencilbuffer);
|
||||
m_device = device;
|
||||
}
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// METHODS
|
||||
// -----------------------------------------------------------------------
|
||||
@ -472,6 +490,8 @@ namespace video
|
||||
}
|
||||
#elif defined(_IRR_COMPILE_WITH_IOS_DEVICE_)
|
||||
static_cast<CIrrDeviceiOS*>(m_device)->swapBuffers();
|
||||
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
SDL_GL_SwapWindow(static_cast<CIrrDeviceSDL*>(m_device)->getWindow());
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@ -2909,5 +2929,21 @@ namespace video
|
||||
}
|
||||
#endif // _IRR_COMPILE_WITH_OSX_DEVICE_
|
||||
|
||||
// -----------------------------------
|
||||
// SDL VERSION
|
||||
// -----------------------------------
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params,
|
||||
io::IFileSystem* io, CIrrDeviceSDL* device)
|
||||
{
|
||||
#ifdef _IRR_COMPILE_WITH_OGLES2_
|
||||
return new COGLES2Driver(params, io, device);
|
||||
#else
|
||||
return 0;
|
||||
#endif // _IRR_COMPILE_WITH_OGLES2_
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
@ -18,6 +18,11 @@
|
||||
#include "CIrrDeviceWayland.h"
|
||||
#endif
|
||||
|
||||
namespace irr
|
||||
{
|
||||
class CIrrDeviceSDL;
|
||||
}
|
||||
|
||||
#include "SIrrCreationParameters.h"
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_OGLES2_
|
||||
@ -75,6 +80,10 @@ namespace video
|
||||
io::IFileSystem* io, CIrrDeviceMacOSX *device);
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
COGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device);
|
||||
#endif
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_)
|
||||
COGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io,
|
||||
IrrlichtDevice* device, u32 default_fb);
|
||||
|
@ -20,7 +20,7 @@ extern bool GLContextDebugBit;
|
||||
#include "IrrlichtDevice.h"
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#include <SDL/SDL.h>
|
||||
#include "CIrrDeviceSDL.h"
|
||||
#endif
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
|
||||
@ -1014,7 +1014,7 @@ bool COpenGLDriver::endScene()
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
if (DeviceType == EIDT_SDL)
|
||||
{
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_GL_SwapWindow(SDLDevice->getWindow());
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
@ -13,7 +13,19 @@
|
||||
#include "irrTypes.h"
|
||||
#include "os.h"
|
||||
|
||||
#if defined(_IRR_WINDOWS_API_)
|
||||
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
|
||||
#define GL_GLEXT_LEGACY 1
|
||||
#define GLX_GLXEXT_LEGACY 1
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#define GLX_GLXEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#define NO_SDL_GLEXT
|
||||
#include <SDL_video.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include "glext.h"
|
||||
#elif defined(_IRR_WINDOWS_API_)
|
||||
// include windows headers for HWND
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
@ -39,35 +51,6 @@
|
||||
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
|
||||
#include "glext.h"
|
||||
#endif
|
||||
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_) && !defined(_IRR_COMPILE_WITH_X11_DEVICE_)
|
||||
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
|
||||
#define GL_GLEXT_LEGACY 1
|
||||
#define GLX_GLXEXT_LEGACY 1
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#define GLX_GLXEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#define NO_SDL_GLEXT
|
||||
#include <SDL/SDL_video.h>
|
||||
#include <SDL/SDL_opengl.h>
|
||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
||||
#include "glext.h"
|
||||
#else
|
||||
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
|
||||
#define GL_GLEXT_LEGACY 1
|
||||
#define GLX_GLXEXT_LEGACY 1
|
||||
#else
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
#define GLX_GLXEXT_PROTOTYPES 1
|
||||
#endif
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#if defined(_IRR_OPENGL_USE_EXTPOINTER_)
|
||||
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
|
||||
#include <GL/glext.h>
|
||||
#undef GLX_ARB_get_proc_address // avoid problems with local glxext.h
|
||||
#include <GL/glxext.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef GL_ARB_shader_objects
|
||||
@ -2388,7 +2371,7 @@ inline void COpenGLExtensionHandler::extGlProgramParameteri(GLhandleARB program,
|
||||
pGlProgramParameteriEXT(program, pname, value);
|
||||
}
|
||||
#elif defined(GL_ARB_geometry_shader4)
|
||||
glProgramParameteriARB(program, pname, value);
|
||||
glProgramParameteriARB((size_t)program, pname, value);
|
||||
#elif defined(GL_EXT_geometry_shader4)
|
||||
#ifdef __clang__
|
||||
glProgramParameteriEXT((long)program, pname, value);
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include <OpenGL/gl.h>
|
||||
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
#define NO_SDL_GLEXT
|
||||
#include <SDL/SDL_video.h>
|
||||
#include <SDL/SDL_opengl.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL_opengl.h>
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
|
@ -29,8 +29,8 @@
|
||||
#include <OpenGL/gl.h>
|
||||
#elif defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
#define NO_SDL_GLEXT
|
||||
#include <SDL/SDL_video.h>
|
||||
#include <SDL/SDL_opengl.h>
|
||||
#include <SDL_video.h>
|
||||
#include <SDL_opengl.h>
|
||||
#else
|
||||
#if defined(_IRR_OSX_PLATFORM_)
|
||||
#include <OpenGL/gl.h>
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "irrMath.h"
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
#include <SDL/SDL_endian.h>
|
||||
#include <SDL_endian.h>
|
||||
#define bswap_16(X) SDL_Swap16(X)
|
||||
#define bswap_32(X) SDL_Swap32(X)
|
||||
#elif defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && (_MSC_VER > 1298)
|
||||
|
@ -1030,6 +1030,10 @@ void IrrDriver::applyResolutionSettings(bool recreate_device)
|
||||
|
||||
font_manager = new FontManager();
|
||||
font_manager->loadFonts();
|
||||
|
||||
input_manager = new InputManager();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
// Input manager set first so it recieves SDL joystick event
|
||||
// Re-init GUI engine
|
||||
GUIEngine::init(m_device, m_video_driver, StateManager::get());
|
||||
|
||||
@ -1037,8 +1041,6 @@ void IrrDriver::applyResolutionSettings(bool recreate_device)
|
||||
//material_manager->reInit();
|
||||
material_manager = new MaterialManager();
|
||||
material_manager->loadMaterial();
|
||||
input_manager = new InputManager ();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
powerup_manager = new PowerupManager();
|
||||
attachment_manager = new AttachmentManager();
|
||||
|
||||
|
@ -34,7 +34,6 @@
|
||||
#ifndef SERVER_ONLY
|
||||
#include "input/sdl_controller.hpp"
|
||||
#include <array>
|
||||
#include <SDL.h>
|
||||
|
||||
static_assert(SDL_CONTROLLER_BUTTON_MAX - 1 == SDL_CONTROLLER_BUTTON_DPAD_RIGHT, "non continous name");
|
||||
enum AxisWithDirection
|
||||
|
@ -87,7 +87,7 @@ InputManager::InputManager() : m_mode(BOOTSTRAP),
|
||||
m_timer_in_use = false;
|
||||
m_master_player_only = false;
|
||||
m_timer = 0;
|
||||
#ifndef SERVER_ONLY
|
||||
#if !defined(SERVER_ONLY) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
SDL_SetMainReady();
|
||||
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
@ -98,6 +98,81 @@ InputManager::InputManager() : m_mode(BOOTSTRAP),
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
#ifndef SERVER_ONLY
|
||||
// For CIrrDeviceSDL
|
||||
extern "C" void handle_joystick(SDL_Event& event)
|
||||
{
|
||||
if (input_manager)
|
||||
input_manager->handleJoystick(event);
|
||||
} // handle_joystick
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void InputManager::handleJoystick(SDL_Event& event)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
#if !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
case SDL_QUIT:
|
||||
{
|
||||
exit(-1);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case SDL_JOYDEVICEADDED:
|
||||
{
|
||||
std::unique_ptr<SDLController> c(
|
||||
new SDLController(event.jdevice.which));
|
||||
SDL_JoystickID id = c->getInstanceID();
|
||||
m_sdl_controller[id] = std::move(c);
|
||||
break;
|
||||
}
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
{
|
||||
m_sdl_controller.erase(event.jdevice.which);
|
||||
break;
|
||||
}
|
||||
case SDL_JOYAXISMOTION:
|
||||
{
|
||||
auto& controller = m_sdl_controller.at(event.jaxis.which);
|
||||
if (m_mode == INPUT_SENSE_GAMEPAD)
|
||||
controller->handleAxisInputSense(event);
|
||||
if (controller->handleAxis(event) &&
|
||||
!UserConfigParams::m_gamepad_visualisation)
|
||||
input(controller->getEvent());
|
||||
break;
|
||||
}
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
auto& controller = m_sdl_controller.at(event.jhat.which);
|
||||
if (controller->handleHat(event) &&
|
||||
!UserConfigParams::m_gamepad_visualisation)
|
||||
input(controller->getEvent());
|
||||
break;
|
||||
}
|
||||
case SDL_JOYBUTTONUP:
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
{
|
||||
auto& controller = m_sdl_controller.at(event.jbutton.which);
|
||||
if (controller->handleButton(event) &&
|
||||
!UserConfigParams::m_gamepad_visualisation)
|
||||
input(controller->getEvent());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
Log::error("SDLController", "%s", e.what());
|
||||
}
|
||||
} // handleJoystick
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void InputManager::update(float dt)
|
||||
{
|
||||
@ -106,68 +181,10 @@ void InputManager::update(float dt)
|
||||
wiimote_manager->update();
|
||||
#endif
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
#if !defined(SERVER_ONLY) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
{
|
||||
exit(-1);
|
||||
break;
|
||||
}
|
||||
case SDL_JOYDEVICEADDED:
|
||||
{
|
||||
std::unique_ptr<SDLController> c(
|
||||
new SDLController(event.jdevice.which));
|
||||
SDL_JoystickID id = c->getInstanceID();
|
||||
m_sdl_controller[id] = std::move(c);
|
||||
break;
|
||||
}
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
{
|
||||
m_sdl_controller.erase(event.jdevice.which);
|
||||
break;
|
||||
}
|
||||
case SDL_JOYAXISMOTION:
|
||||
{
|
||||
auto& controller = m_sdl_controller.at(event.jaxis.which);
|
||||
if (m_mode == INPUT_SENSE_GAMEPAD)
|
||||
controller->handleAxisInputSense(event);
|
||||
if (controller->handleAxis(event) &&
|
||||
!UserConfigParams::m_gamepad_visualisation)
|
||||
input(controller->getEvent());
|
||||
break;
|
||||
}
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
auto& controller = m_sdl_controller.at(event.jhat.which);
|
||||
if (controller->handleHat(event) &&
|
||||
!UserConfigParams::m_gamepad_visualisation)
|
||||
input(controller->getEvent());
|
||||
break;
|
||||
}
|
||||
case SDL_JOYBUTTONUP:
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
{
|
||||
auto& controller = m_sdl_controller.at(event.jbutton.which);
|
||||
if (controller->handleButton(event) &&
|
||||
!UserConfigParams::m_gamepad_visualisation)
|
||||
input(controller->getEvent());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
Log::error("SDLController", "%s", e.what());
|
||||
}
|
||||
}
|
||||
handleJoystick(event);
|
||||
#endif
|
||||
|
||||
if(m_timer_in_use)
|
||||
@ -193,10 +210,11 @@ InputManager::~InputManager()
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
m_sdl_controller.clear();
|
||||
#endif
|
||||
delete m_device_manager;
|
||||
#if !defined(SERVER_ONLY) && !defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
|
||||
SDL_Quit();
|
||||
#endif
|
||||
|
||||
delete m_device_manager;
|
||||
} // ~InputManager
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -30,6 +30,10 @@
|
||||
#include "input/input.hpp"
|
||||
#include "utils/no_copy.hpp"
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
#include <SDL_events.h>
|
||||
#endif
|
||||
|
||||
class DeviceManager;
|
||||
class SDLController;
|
||||
|
||||
@ -115,6 +119,8 @@ public:
|
||||
size_t getGamepadCount() const { return m_sdl_controller.size(); }
|
||||
/** Returns irrlicht joystick for gamepad visualization. */
|
||||
const irr::SEvent& getEventForGamePad(unsigned i) const;
|
||||
|
||||
void handleJoystick(SDL_Event& event);
|
||||
#endif
|
||||
|
||||
void dispatchInput(Input::InputType, int deviceID, int btnID,
|
||||
|
@ -20,7 +20,9 @@
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
|
||||
#include <SDL.h>
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_gamecontroller.h>
|
||||
#include <SDL_joystick.h>
|
||||
#include <IEventReceiver.h>
|
||||
#include <bitset>
|
||||
#include "utils/types.hpp"
|
||||
|
@ -1748,12 +1748,12 @@ void initRest()
|
||||
delete tmp_skin;
|
||||
GUIEngine::setSkin(NULL);
|
||||
|
||||
GUIEngine::init(device, driver, StateManager::get());
|
||||
|
||||
GUIEngine::renderLoading(true, true, false);
|
||||
input_manager = new InputManager();
|
||||
// Get into menu mode initially.
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
// Input manager set first so it recieves SDL joystick event
|
||||
GUIEngine::init(device, driver, StateManager::get());
|
||||
GUIEngine::renderLoading(true, true, false);
|
||||
|
||||
stk_config->initMusicFiles();
|
||||
// This only initialises the non-network part of the add-ons manager. The
|
||||
|
Loading…
x
Reference in New Issue
Block a user