2018-04-12 21:02:51 +00:00
|
|
|
// SDL interface layer for the Build Engine
|
2013-10-06 07:49:53 +00:00
|
|
|
// Use SDL 1.2 or 2.0 from http://www.libsdl.org
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-09-21 21:45:57 +00:00
|
|
|
#include <Windows.h>
|
2019-09-22 21:15:46 +00:00
|
|
|
#include <CommCtrl.h>
|
2009-08-03 22:15:53 +00:00
|
|
|
#include <signal.h>
|
2019-10-03 22:26:13 +00:00
|
|
|
#include <string>
|
2019-10-23 23:20:58 +00:00
|
|
|
#include <stdexcept>
|
2019-10-05 11:57:26 +00:00
|
|
|
# include "glad/glad.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "a.h"
|
|
|
|
#include "build.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "cache1d.h"
|
2019-09-19 21:02:57 +00:00
|
|
|
#include "common.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "compat.h"
|
2015-01-11 04:52:15 +00:00
|
|
|
#include "engine_priv.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "osd.h"
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "palette.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "renderlayer.h"
|
|
|
|
#include "sdl_inc.h"
|
2018-07-14 21:36:44 +00:00
|
|
|
#include "softsurface.h"
|
2019-09-23 17:29:25 +00:00
|
|
|
#include "m_argv.h"
|
2019-09-25 21:00:10 +00:00
|
|
|
#include "mmulti.h"
|
2019-10-03 22:26:13 +00:00
|
|
|
#include "scriptfile.h"
|
|
|
|
#include "zstring.h"
|
2019-10-26 11:16:32 +00:00
|
|
|
#include "gameconfigfile.h"
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "resourcefile.h"
|
|
|
|
#include "sc_man.h"
|
2019-10-26 11:41:42 +00:00
|
|
|
#include "i_specialpaths.h"
|
2019-10-28 00:12:31 +00:00
|
|
|
#include "inputstate.h"
|
2019-10-27 12:40:24 +00:00
|
|
|
#include "c_cvars.h"
|
2019-11-04 19:29:07 +00:00
|
|
|
#include "i_time.h"
|
2019-11-05 19:07:16 +00:00
|
|
|
#include "c_dispatch.h"
|
2019-11-07 19:31:16 +00:00
|
|
|
#include "d_gui.h"
|
2019-12-05 20:39:02 +00:00
|
|
|
#include "menu.h"
|
2019-11-07 19:31:16 +00:00
|
|
|
#include "utf8.h"
|
|
|
|
#include "imgui.h"
|
|
|
|
#include "imgui_impl_sdl.h"
|
|
|
|
#include "imgui_impl_opengl3.h"
|
2019-12-05 20:39:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-11-01 06:26:49 +00:00
|
|
|
#ifndef NETCODE_DISABLE
|
|
|
|
#include "enet.h"
|
|
|
|
#endif
|
2019-09-23 21:33:59 +00:00
|
|
|
#include "../../glbackend/glbackend.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
# include "glbuild.h"
|
2018-06-13 19:15:16 +00:00
|
|
|
# include "glsurface.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-22 11:19:45 +00:00
|
|
|
#if defined HAVE_GTK2
|
2006-04-13 20:47:06 +00:00
|
|
|
# include "gtkbits.h"
|
2014-07-22 11:19:45 +00:00
|
|
|
#endif
|
2018-11-18 18:09:48 +00:00
|
|
|
|
2019-09-10 17:06:20 +00:00
|
|
|
#if defined __APPLE__
|
2018-11-18 18:09:48 +00:00
|
|
|
# include "osxbits.h"
|
|
|
|
# include <mach/mach.h>
|
|
|
|
# include <mach/mach_time.h>
|
|
|
|
#elif defined _WIN32
|
2019-09-25 20:38:47 +00:00
|
|
|
# include "win32/winbits.h"
|
2014-12-17 13:01:13 +00:00
|
|
|
#endif
|
2011-07-20 23:04:20 +00:00
|
|
|
|
2019-10-27 12:40:24 +00:00
|
|
|
CVAR(Int, r_displayindex, 0, CVAR_ARCHIVE | CVAR_VIDEOCONFIG)
|
|
|
|
CVAR(Int, r_borderless, 2, CVAR_ARCHIVE | CVAR_VIDEOCONFIG)
|
|
|
|
CVAR(Int, maxrefreshfreq, 0, CVAR_ARCHIVE | CVAR_VIDEOCONFIG)
|
|
|
|
CVAR(Int, windowpos, 0, CVAR_ARCHIVE | CVAR_VIDEOCONFIG)
|
|
|
|
CVAR(Int, windowx, -1, CVAR_ARCHIVE | CVAR_VIDEOCONFIG)
|
|
|
|
CVAR(Int, windowy, -1, CVAR_ARCHIVE | CVAR_VIDEOCONFIG)
|
|
|
|
|
2016-12-26 06:01:44 +00:00
|
|
|
#if SDL_MAJOR_VERSION != 1
|
2016-10-20 06:26:17 +00:00
|
|
|
static SDL_version linked;
|
2016-12-26 06:01:44 +00:00
|
|
|
#endif
|
2016-10-20 06:26:17 +00:00
|
|
|
|
2019-11-10 10:42:25 +00:00
|
|
|
double g_beforeSwapTime;
|
2019-09-21 20:53:00 +00:00
|
|
|
GameInterface* gi;
|
2019-09-23 17:29:25 +00:00
|
|
|
FArgs* Args;
|
2019-09-21 20:53:00 +00:00
|
|
|
|
2014-10-20 07:37:29 +00:00
|
|
|
#if !defined STARTUP_SETUP_WINDOW
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t startwin_open(void) { return 0; }
|
|
|
|
int32_t startwin_close(void) { return 0; }
|
2011-12-09 19:08:29 +00:00
|
|
|
int32_t startwin_puts(const char *s) { UNREFERENCED_PARAMETER(s); return 0; }
|
|
|
|
int32_t startwin_idle(void *s) { UNREFERENCED_PARAMETER(s); return 0; }
|
|
|
|
int32_t startwin_settitle(const char *s) { UNREFERENCED_PARAMETER(s); return 0; }
|
2014-11-26 04:39:23 +00:00
|
|
|
int32_t startwin_run(void) { return 0; }
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-25 21:00:10 +00:00
|
|
|
int myconnectindex, numplayers;
|
|
|
|
int connecthead, connectpoint2[MAXMULTIPLAYERS];
|
|
|
|
unsigned char syncstate;
|
|
|
|
|
2010-05-18 05:14:17 +00:00
|
|
|
/// These can be useful for debugging sometimes...
|
|
|
|
//#define SDL_WM_GrabInput(x) SDL_WM_GrabInput(SDL_GRAB_OFF)
|
|
|
|
//#define SDL_ShowCursor(x) SDL_ShowCursor(SDL_ENABLE)
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#define SURFACE_FLAGS (SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWACCEL)
|
|
|
|
|
|
|
|
// undefine to restrict windowed resolutions to conventional sizes
|
|
|
|
#define ANY_WINDOWED_SIZE
|
|
|
|
|
2006-08-07 06:18:57 +00:00
|
|
|
// fix for mousewheel
|
2013-12-20 07:24:09 +00:00
|
|
|
int32_t inputchecked = 0;
|
2019-11-23 22:05:24 +00:00
|
|
|
bool screenshot_requested;
|
2006-08-07 06:18:57 +00:00
|
|
|
|
2019-12-01 08:02:17 +00:00
|
|
|
char appactive=1, novideo=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// video
|
2013-10-08 09:59:59 +00:00
|
|
|
static SDL_Surface *sdl_surface/*=NULL*/;
|
2014-04-12 08:45:26 +00:00
|
|
|
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
#if SDL_MAJOR_VERSION==2
|
2019-11-07 19:31:16 +00:00
|
|
|
SDL_Window *sdl_window=NULL;
|
|
|
|
SDL_GLContext sdl_context=NULL;
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
#endif
|
2014-04-12 08:45:26 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
void ImGui_Init_Backend()
|
|
|
|
{
|
|
|
|
ImGui_ImplSDL2_InitForOpenGL(sdl_window, sdl_context);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImGui_Begin_Frame()
|
|
|
|
{
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplSDL2_NewFrame(sdl_window);
|
|
|
|
ImGui::NewFrame();
|
|
|
|
}
|
|
|
|
|
2019-08-27 13:39:54 +00:00
|
|
|
int32_t xres=-1, yres=-1, bpp=0, fullscreen=0, bytesperline, refreshfreq=-1;
|
2008-02-16 22:27:08 +00:00
|
|
|
intptr_t frameplace=0;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t lockcount=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
char modechange=1;
|
|
|
|
char offscreenrendering=0;
|
|
|
|
char videomodereset = 0;
|
2009-01-09 09:29:17 +00:00
|
|
|
static uint16_t sysgamma[3][256];
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
// OpenGL stuff
|
2008-08-26 19:50:34 +00:00
|
|
|
char nogl=0;
|
2013-10-13 09:08:31 +00:00
|
|
|
#endif
|
2016-12-26 06:01:48 +00:00
|
|
|
static int32_t vsync_renderlayer;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-12-28 20:34:57 +00:00
|
|
|
// last gamma, contrast, brightness
|
|
|
|
|
2011-11-25 09:50:07 +00:00
|
|
|
//#define KEY_PRINT_DEBUG
|
|
|
|
|
2017-02-01 10:20:54 +00:00
|
|
|
#include "sdlkeytrans.cpp"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
static SDL_Surface *appicon = NULL;
|
2014-12-27 18:36:14 +00:00
|
|
|
#if !defined __APPLE__ && !defined EDUKE32_TOUCH_DEVICES
|
2011-01-16 02:50:27 +00:00
|
|
|
static SDL_Surface *loadappicon(void);
|
2014-10-16 21:03:24 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-10-21 02:20:40 +00:00
|
|
|
// Joystick dead and saturation zones
|
2019-08-13 09:15:49 +00:00
|
|
|
uint16_t joydead[9], joysatur[9];
|
2010-10-21 02:20:40 +00:00
|
|
|
|
2019-10-23 23:20:58 +00:00
|
|
|
#define MAX_ERRORTEXT 4096
|
|
|
|
|
2019-11-03 23:55:49 +00:00
|
|
|
|
2019-10-23 23:20:58 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// I_Error
|
|
|
|
//
|
|
|
|
// Throw an error that will send us to the console if we are far enough
|
|
|
|
// along in the startup process.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void I_Error(const char *error, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char errortext[MAX_ERRORTEXT];
|
|
|
|
|
|
|
|
va_start(argptr, error);
|
2019-10-27 07:14:58 +00:00
|
|
|
vsnprintf(errortext, MAX_ERRORTEXT, error, argptr);
|
2019-10-23 23:20:58 +00:00
|
|
|
va_end(argptr);
|
|
|
|
#ifdef _WIN32
|
|
|
|
OutputDebugStringA(errortext);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
throw std::runtime_error(errortext);
|
|
|
|
}
|
|
|
|
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifdef _WIN32
|
2014-11-29 03:07:33 +00:00
|
|
|
# if SDL_MAJOR_VERSION != 1
|
2012-11-24 09:13:29 +00:00
|
|
|
//
|
2013-10-07 10:05:03 +00:00
|
|
|
// win_gethwnd() -- gets the window handle
|
|
|
|
//
|
|
|
|
HWND win_gethwnd(void)
|
|
|
|
{
|
|
|
|
struct SDL_SysWMinfo wmInfo;
|
|
|
|
SDL_VERSION(&wmInfo.version);
|
|
|
|
|
2014-04-12 08:45:26 +00:00
|
|
|
if (SDL_GetWindowWMInfo(sdl_window, &wmInfo) != SDL_TRUE)
|
|
|
|
return 0;
|
|
|
|
|
2013-10-07 10:05:03 +00:00
|
|
|
if (wmInfo.subsystem == SDL_SYSWM_WINDOWS)
|
|
|
|
return wmInfo.info.win.window;
|
|
|
|
|
|
|
|
initprintf("win_gethwnd: Unknown WM subsystem?!\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-29 03:07:33 +00:00
|
|
|
# endif
|
2013-10-07 10:05:03 +00:00
|
|
|
//
|
2012-11-24 09:13:29 +00:00
|
|
|
// win_gethinstance() -- gets the application instance
|
|
|
|
//
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
HINSTANCE win_gethinstance(void)
|
2012-11-24 09:13:29 +00:00
|
|
|
{
|
Win64 support! (Meaning it works, not that we recommend it for everyday use.)
This includes a complete Windows header and library refresh, including the addition of 64-bit compiled libs:
*libogg 1.3.0
*libvorbis 1.3.3
*zlib 1.2.7
*libpng 1.5.13
*libvpx 9a3de881c0e681ba1a79a166a86308bbc84b4acd
*SDL_mixer 1.2.12 (for RENDERTYPE=SDL)
*DirectX import libraries: dsound and dxguid (now included)
To build in 64-bit, you essentially need MinGW's MSYS (but not MinGW itself) and MinGW-w64 at the top of your PATH. The target is automatically detected using `$(CC) -dumpmachine`. The EDukeWiki will get detailed instrucitons.
All compiler and linker warnings when building in 64-bit mode have been fixed.
Remaining 64-bit to-do:
- The ebacktrace dll does not build under 64-bit. It uses code specific to the format of 32-bit executables and will have to be ported to work with 64-bit executables. A future 64-bit version will be named ebacktrace1-64.dll.
- RENDERTYPE=SDL crashes in SDL_mixer's Mix_Linked_Version().
- DirectInput gives an error and does not function. This only affects joysticks, and the error never happens without any plugged in.
- Port the classic renderer ASM to 64-bit. (Just kidding, this is way out of my league.)
This commit includes a fair bit of Makefile development spanning all platforms, including simplifying the SDLCONFIG code, fixing build on Mac OS X (thanks rhoenie!), globally factoring Apple brew/port inclusion, enforcing that all -L come before all -l, and ensuring that $(shell ) is always :='d.
In addition, I have resurrected the old GCC_MAJOR and GCC_MINOR detection using `$(CC) -dumpversion`, but I have made it failsafe in case the command fails or the version is manually specified. I have applied this new fine-grained detection where applicable, including allowing LTO, and restraining -W's to versions that support them.
git-svn-id: https://svn.eduke32.com/eduke32@3278 1a8010ca-5511-0410-912e-c29ae57300e0
2012-12-13 02:37:20 +00:00
|
|
|
return (HINSTANCE)GetModuleHandle(NULL);
|
2012-11-24 09:13:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-17 12:35:03 +00:00
|
|
|
|
2014-07-28 06:43:16 +00:00
|
|
|
int32_t wm_msgbox(const char *name, const char *fmt, ...)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-21 20:10:51 +00:00
|
|
|
char buf[2048];
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-03-25 09:21:18 +00:00
|
|
|
UNREFERENCED_PARAMETER(name);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
va_start(va,fmt);
|
2013-10-27 21:12:25 +00:00
|
|
|
vsnprintf(buf,sizeof(buf),fmt,va);
|
2006-04-24 19:04:22 +00:00
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-01-25 12:16:10 +00:00
|
|
|
#if defined EDUKE32_OSX
|
2006-04-24 19:04:22 +00:00
|
|
|
return osx_msgbox(name, buf);
|
2014-01-12 14:06:15 +00:00
|
|
|
#elif defined _WIN32
|
2019-09-22 21:15:46 +00:00
|
|
|
MessageBoxA(win_gethwnd(),buf,name,MB_OK|MB_TASKMODAL);
|
2014-01-12 14:06:15 +00:00
|
|
|
return 0;
|
2014-12-27 18:36:14 +00:00
|
|
|
#elif defined EDUKE32_TOUCH_DEVICES
|
2014-04-15 19:02:48 +00:00
|
|
|
initprintf("wm_msgbox called. Message: %s: %s",name,buf);
|
|
|
|
return 0;
|
2014-12-18 18:15:26 +00:00
|
|
|
#elif defined GEKKO
|
|
|
|
puts(buf);
|
|
|
|
return 0;
|
2016-12-26 06:02:06 +00:00
|
|
|
#else
|
2016-12-29 02:57:33 +00:00
|
|
|
# if defined HAVE_GTK2
|
|
|
|
if (gtkbuild_msgbox(name, buf) >= 0)
|
|
|
|
return 0;
|
|
|
|
# endif
|
|
|
|
# if SDL_MAJOR_VERSION > 1
|
|
|
|
# if !defined _WIN32
|
|
|
|
// Replace all tab chars with spaces because the hand-rolled SDL message
|
|
|
|
// box diplays the former as N/L instead of whitespace.
|
|
|
|
for (size_t i=0; i<sizeof(buf); i++)
|
|
|
|
if (buf[i] == '\t')
|
|
|
|
buf[i] = ' ';
|
|
|
|
# endif
|
|
|
|
return SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, name, buf, NULL);
|
|
|
|
# else
|
2006-04-24 19:04:22 +00:00
|
|
|
puts(buf);
|
|
|
|
puts(" (press Return or Enter to continue)");
|
|
|
|
getchar();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2016-12-29 02:57:33 +00:00
|
|
|
# endif
|
2016-12-26 06:02:06 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 06:43:16 +00:00
|
|
|
int32_t wm_ynbox(const char *name, const char *fmt, ...)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-09-21 20:10:51 +00:00
|
|
|
char buf[2048];
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2008-03-25 09:21:18 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(name);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
va_start(va,fmt);
|
2016-12-29 02:57:33 +00:00
|
|
|
vsnprintf(buf,sizeof(buf),fmt,va);
|
2006-04-24 19:04:22 +00:00
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-01-25 12:16:10 +00:00
|
|
|
#if defined EDUKE32_OSX
|
2006-04-24 19:04:22 +00:00
|
|
|
return osx_ynbox(name, buf);
|
2014-01-12 14:06:15 +00:00
|
|
|
#elif defined _WIN32
|
2019-09-22 21:15:46 +00:00
|
|
|
return (MessageBoxA(win_gethwnd(),buf,name,MB_YESNO|MB_ICONQUESTION|MB_TASKMODAL) == IDYES);
|
2014-12-27 18:36:14 +00:00
|
|
|
#elif defined EDUKE32_TOUCH_DEVICES
|
2014-04-15 19:02:48 +00:00
|
|
|
initprintf("wm_ynbox called, this is bad! Message: %s: %s",name,buf);
|
|
|
|
initprintf("Returning false..");
|
|
|
|
return 0;
|
2016-12-29 02:57:33 +00:00
|
|
|
#elif defined GEKKO
|
|
|
|
puts(buf);
|
|
|
|
puts("Assuming yes...");
|
|
|
|
return 1;
|
2014-11-22 12:33:47 +00:00
|
|
|
#else
|
2016-12-29 02:57:33 +00:00
|
|
|
# if defined HAVE_GTK2
|
|
|
|
int ret = gtkbuild_ynbox(name, buf);
|
|
|
|
if (ret >= 0)
|
|
|
|
return ret;
|
|
|
|
# endif
|
|
|
|
# if SDL_MAJOR_VERSION > 1
|
|
|
|
int r = -1;
|
|
|
|
|
|
|
|
const SDL_MessageBoxButtonData buttons[] = {
|
|
|
|
{
|
|
|
|
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
|
|
|
|
0,
|
|
|
|
"No"
|
|
|
|
},{
|
|
|
|
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
|
|
|
|
1,
|
|
|
|
"Yes"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
SDL_MessageBoxData data = {
|
|
|
|
SDL_MESSAGEBOX_INFORMATION,
|
|
|
|
NULL, /* no parent window */
|
|
|
|
name,
|
|
|
|
buf,
|
|
|
|
2,
|
|
|
|
buttons,
|
|
|
|
NULL /* Default color scheme */
|
|
|
|
};
|
|
|
|
|
|
|
|
SDL_ShowMessageBox(&data, &r);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
# else
|
|
|
|
char c;
|
|
|
|
|
|
|
|
puts(buf);
|
|
|
|
puts(" (type 'Y' or 'N', and press Return or Enter to continue)");
|
|
|
|
do c = getchar(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n');
|
|
|
|
return c == 'Y' || c == 'y';
|
|
|
|
# endif
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-07-28 06:43:16 +00:00
|
|
|
void wm_setapptitle(const char *name)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-12-27 18:36:14 +00:00
|
|
|
#ifndef EDUKE32_TOUCH_DEVICES
|
2014-11-22 12:33:47 +00:00
|
|
|
if (name != apptitle)
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(apptitle, name, sizeof(apptitle));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
#if !defined(__APPLE__)
|
2014-11-29 03:07:33 +00:00
|
|
|
if (!appicon)
|
|
|
|
appicon = loadappicon();
|
2014-11-22 12:33:47 +00:00
|
|
|
#endif
|
|
|
|
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
#if SDL_MAJOR_VERSION == 1
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_WM_SetCaption(apptitle, NULL);
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2014-11-29 03:07:33 +00:00
|
|
|
if (appicon && sdl_surface)
|
2014-11-22 12:33:47 +00:00
|
|
|
SDL_WM_SetIcon(appicon, 0);
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
#else
|
2016-10-20 06:26:20 +00:00
|
|
|
if (sdl_window)
|
|
|
|
{
|
|
|
|
SDL_SetWindowTitle(sdl_window, apptitle);
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2016-10-20 06:26:20 +00:00
|
|
|
if (appicon)
|
|
|
|
{
|
|
|
|
#if defined _WIN32
|
|
|
|
if (!EDUKE32_SDL_LINKED_PREREQ(linked, 2, 0, 5))
|
|
|
|
#endif
|
|
|
|
SDL_SetWindowIcon(sdl_window, appicon);
|
|
|
|
}
|
|
|
|
}
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-12-27 18:36:14 +00:00
|
|
|
#else
|
|
|
|
UNREFERENCED_PARAMETER(name);
|
2014-11-22 12:33:47 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// System
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
/* XXX: libexecinfo could be used on systems without gnu libc. */
|
2014-12-27 18:36:14 +00:00
|
|
|
#if !defined _WIN32 && defined __GNUC__ && !defined __OpenBSD__ && !(defined __APPLE__ && defined __BIG_ENDIAN__) && !defined GEKKO && !defined EDUKE32_TOUCH_DEVICES && !defined __OPENDINGUX__
|
2014-11-22 12:33:47 +00:00
|
|
|
# define PRINTSTACKONSEGV 1
|
|
|
|
# include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline char grabmouse_low(char a);
|
|
|
|
|
2016-03-28 05:15:32 +00:00
|
|
|
#ifndef __ANDROID__
|
|
|
|
static void attach_debugger_here(void) {}
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
static void sighandler(int signum)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(signum);
|
|
|
|
// if (signum==SIGSEGV)
|
|
|
|
{
|
|
|
|
grabmouse_low(0);
|
|
|
|
#if PRINTSTACKONSEGV
|
|
|
|
{
|
|
|
|
void *addr[32];
|
|
|
|
int32_t errfd = fileno(stderr);
|
|
|
|
int32_t n=backtrace(addr, ARRAY_SIZE(addr));
|
|
|
|
backtrace_symbols_fd(addr, n, errfd);
|
|
|
|
}
|
|
|
|
// This is useful for attaching the debugger post-mortem. For those pesky
|
|
|
|
// cases where the program runs through happily when inspected from the start.
|
|
|
|
// usleep(15000000);
|
2014-07-28 06:42:28 +00:00
|
|
|
#endif
|
2014-11-22 12:33:47 +00:00
|
|
|
attach_debugger_here();
|
2019-11-01 18:25:42 +00:00
|
|
|
std::terminate();
|
|
|
|
// NOTE: It is not safe to call any of this from a signal handler!
|
|
|
|
//gi->app_crashhandler();
|
|
|
|
//uninitsystem();
|
|
|
|
//Bexit(EXIT_FAILURE);
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-28 05:15:32 +00:00
|
|
|
#endif
|
2014-07-28 06:42:28 +00:00
|
|
|
|
2019-11-05 19:07:16 +00:00
|
|
|
int GameMain();
|
2016-05-02 18:29:38 +00:00
|
|
|
|
2015-02-11 05:21:50 +00:00
|
|
|
#ifdef _WIN32
|
2019-09-21 21:45:57 +00:00
|
|
|
|
2019-09-23 17:29:25 +00:00
|
|
|
int WINAPI WinMain(HINSTANCE , HINSTANCE , LPSTR , int )
|
2015-02-11 05:21:50 +00:00
|
|
|
#else
|
2017-01-01 13:23:35 +00:00
|
|
|
int main(int argc, char *argv[])
|
2015-02-11 05:21:50 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2019-09-23 16:17:36 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
char* argvbuf;
|
2019-09-25 20:38:47 +00:00
|
|
|
int32_t buildargc = win_buildargs(&argvbuf);
|
2019-09-23 16:17:36 +00:00
|
|
|
const char** buildargv = (const char**)Xmalloc(sizeof(char*) * (buildargc + 1));
|
|
|
|
char* wp = argvbuf;
|
|
|
|
|
|
|
|
for (bssize_t i = 0; i < buildargc; i++, wp++)
|
|
|
|
{
|
|
|
|
buildargv[i] = wp;
|
|
|
|
while (*wp) wp++;
|
|
|
|
}
|
|
|
|
buildargv[buildargc] = NULL;
|
|
|
|
#else
|
|
|
|
auto buildargc = argc;
|
|
|
|
auto buildargv = argv;
|
|
|
|
#endif
|
|
|
|
|
2019-09-23 17:29:25 +00:00
|
|
|
Args = new FArgs(buildargc, buildargv);
|
|
|
|
|
2016-10-20 06:26:14 +00:00
|
|
|
#if defined _WIN32 && defined SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING
|
|
|
|
// Thread naming interferes with debugging using MinGW-w64's GDB.
|
|
|
|
SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
|
|
|
|
#endif
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t r;
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2019-10-23 19:11:37 +00:00
|
|
|
|
2017-09-21 04:32:14 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
setenv("__GL_THREADED_OPTIMIZATIONS", "1", 0);
|
2014-07-28 06:42:28 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
buildkeytranslationtable();
|
|
|
|
|
2019-09-23 17:29:25 +00:00
|
|
|
#ifndef _WIN32 // catching signals is not really helpful on Windows.
|
2014-11-22 12:33:47 +00:00
|
|
|
signal(SIGSEGV, sighandler);
|
|
|
|
signal(SIGILL, sighandler); /* clang -fcatch-undefined-behavior uses an ill. insn */
|
|
|
|
signal(SIGABRT, sighandler);
|
|
|
|
signal(SIGFPE, sighandler);
|
2015-02-11 05:22:29 +00:00
|
|
|
#endif
|
2014-04-19 02:51:33 +00:00
|
|
|
|
2015-02-11 05:21:50 +00:00
|
|
|
|
2019-09-23 17:29:25 +00:00
|
|
|
#if defined(HAVE_GTK2)
|
2014-11-22 12:33:47 +00:00
|
|
|
// Pre-initialize SDL video system in order to make sure XInitThreads() is called
|
|
|
|
// before GTK starts talking to X11.
|
2018-02-26 14:46:52 +00:00
|
|
|
uint32_t inited = SDL_WasInit(SDL_INIT_VIDEO);
|
|
|
|
if (inited == 0)
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
|
|
else if (!(inited & SDL_INIT_VIDEO))
|
|
|
|
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
2006-04-24 19:04:22 +00:00
|
|
|
gtkbuild_init(&argc, &argv);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-02 16:26:40 +00:00
|
|
|
if (initsystem()) Bexit(9);
|
2019-11-09 22:58:26 +00:00
|
|
|
SDL_StartTextInput();
|
2019-09-22 23:28:18 +00:00
|
|
|
|
2019-11-05 19:07:16 +00:00
|
|
|
r = GameMain();
|
2019-10-26 08:30:08 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_GTK2)
|
|
|
|
gtkbuild_exit(r);
|
|
|
|
#endif
|
|
|
|
return r;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 11:16:32 +00:00
|
|
|
// The resourge manager in cache1d is far too broken to add some arbitrary file without some adjustment.
|
|
|
|
// For now, keep this file here, until the resource management can be redone in a more workable fashion.
|
|
|
|
|
2014-11-28 08:30:31 +00:00
|
|
|
#if SDL_MAJOR_VERSION != 1
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoSetVsync(int32_t newSync)
|
2008-07-22 21:03:09 +00:00
|
|
|
{
|
2016-12-26 06:01:36 +00:00
|
|
|
if (vsync_renderlayer == newSync)
|
2016-11-15 21:55:30 +00:00
|
|
|
return newSync;
|
2013-10-13 09:08:31 +00:00
|
|
|
|
2016-11-15 21:55:30 +00:00
|
|
|
#ifdef USE_OPENGL
|
2013-10-08 10:00:25 +00:00
|
|
|
if (sdl_context)
|
2016-11-15 21:55:30 +00:00
|
|
|
{
|
|
|
|
int result = SDL_GL_SetSwapInterval(newSync);
|
|
|
|
|
|
|
|
if (result == -1)
|
|
|
|
{
|
|
|
|
if (newSync == -1)
|
|
|
|
{
|
|
|
|
newSync = 1;
|
|
|
|
result = SDL_GL_SetSwapInterval(newSync);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == -1)
|
|
|
|
{
|
|
|
|
newSync = 0;
|
2019-11-05 19:25:57 +00:00
|
|
|
Printf("Unable to enable VSync!\n");
|
2016-11-15 21:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 06:01:36 +00:00
|
|
|
vsync_renderlayer = newSync;
|
2016-11-15 21:55:30 +00:00
|
|
|
}
|
|
|
|
else
|
2008-07-22 21:03:09 +00:00
|
|
|
#endif
|
2016-11-15 21:55:30 +00:00
|
|
|
{
|
2019-09-23 21:33:59 +00:00
|
|
|
/*
|
2016-12-26 06:01:36 +00:00
|
|
|
vsync_renderlayer = newSync;
|
2016-11-15 21:55:30 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
videoResetMode();
|
2018-07-14 21:36:44 +00:00
|
|
|
if (videoSetGameMode(fullscreen, xres, yres, bpp, upscalefactor))
|
2016-11-15 21:55:30 +00:00
|
|
|
OSD_Printf("restartvid: Reset failed...\n");
|
2019-09-23 21:33:59 +00:00
|
|
|
*/
|
2016-11-15 21:55:30 +00:00
|
|
|
}
|
|
|
|
|
2016-12-26 06:01:40 +00:00
|
|
|
return newSync;
|
2016-11-15 21:55:30 +00:00
|
|
|
}
|
2014-11-28 08:30:31 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-28 08:12:40 +00:00
|
|
|
int32_t sdlayer_checkversion(void);
|
|
|
|
#if SDL_MAJOR_VERSION != 1
|
2014-11-22 12:33:47 +00:00
|
|
|
int32_t sdlayer_checkversion(void)
|
|
|
|
{
|
2019-11-05 19:07:16 +00:00
|
|
|
#if 0
|
2014-11-22 12:33:47 +00:00
|
|
|
SDL_version compiled;
|
2013-07-20 03:36:54 +00:00
|
|
|
|
2015-02-07 17:29:14 +00:00
|
|
|
SDL_GetVersion(&linked);
|
2014-11-22 12:33:47 +00:00
|
|
|
SDL_VERSION(&compiled);
|
2010-10-17 14:49:39 +00:00
|
|
|
|
2016-01-11 05:05:16 +00:00
|
|
|
if (!Bmemcmp(&compiled, &linked, sizeof(SDL_version)))
|
|
|
|
initprintf("Initializing SDL %d.%d.%d\n",
|
|
|
|
compiled.major, compiled.minor, compiled.patch);
|
|
|
|
else
|
|
|
|
initprintf("Initializing SDL %d.%d.%d"
|
2016-05-29 21:11:21 +00:00
|
|
|
" (built against SDL version %d.%d.%d)\n",
|
2016-01-11 05:05:16 +00:00
|
|
|
linked.major, linked.minor, linked.patch, compiled.major, compiled.minor, compiled.patch);
|
2013-10-08 09:59:59 +00:00
|
|
|
|
2015-02-07 17:29:14 +00:00
|
|
|
if (SDL_VERSIONNUM(linked.major, linked.minor, linked.patch) < SDL_REQUIREDVERSION)
|
2009-08-03 22:15:53 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
/*reject running under SDL versions older than what is stated in sdl_inc.h */
|
|
|
|
initprintf("You need at least v%d.%d.%d of SDL to run this game\n",SDL_MIN_X,SDL_MIN_Y,SDL_MIN_Z);
|
|
|
|
return -1;
|
2009-08-03 22:15:53 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2019-11-05 19:07:16 +00:00
|
|
|
#endif
|
2014-11-22 12:33:47 +00:00
|
|
|
return 0;
|
2009-08-03 22:15:53 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// initsystem() -- init SDL systems
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t initsystem(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
const int sdlinitflags = SDL_INIT_VIDEO;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
if (sdlayer_checkversion())
|
2008-04-25 01:46:19 +00:00
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-02-26 14:46:52 +00:00
|
|
|
int32_t err = 0;
|
|
|
|
uint32_t inited = SDL_WasInit(sdlinitflags);
|
|
|
|
if (inited == 0)
|
|
|
|
err = SDL_Init(sdlinitflags);
|
|
|
|
else if ((inited & sdlinitflags) != sdlinitflags)
|
|
|
|
err = SDL_InitSubSystem(sdlinitflags & ~inited);
|
|
|
|
|
|
|
|
if (err)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
initprintf("Initialization failed! (%s)\nNon-interactive mode enabled\n", SDL_GetError());
|
2011-02-27 22:11:39 +00:00
|
|
|
novideo = 1;
|
|
|
|
#ifdef USE_OPENGL
|
|
|
|
nogl = 1;
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-12-26 06:02:41 +00:00
|
|
|
#if SDL_MAJOR_VERSION > 1
|
|
|
|
SDL_StopTextInput();
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
atexit(uninitsystem);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
frameplace = 0;
|
|
|
|
lockcount = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
if (!novideo)
|
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-02-16 06:38:21 +00:00
|
|
|
if (SDL_GL_LoadLibrary(0))
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
initprintf("Failed loading OpenGL Driver. GL modes will be unavailable. Error: %s\n", SDL_GetError());
|
2014-11-22 12:33:47 +00:00
|
|
|
nogl = 1;
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-11 05:05:16 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
const char *drvname = SDL_GetVideoDriver(0);
|
|
|
|
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
if (drvname)
|
|
|
|
initprintf("Using \"%s\" video driver\n", drvname);
|
2016-01-11 05:05:16 +00:00
|
|
|
#endif
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-11-28 08:12:40 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitsystem() -- uninit SDL systems
|
|
|
|
//
|
|
|
|
void uninitsystem(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
uninitinput();
|
2018-04-12 21:02:51 +00:00
|
|
|
timerUninit();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-11-18 01:17:56 +00:00
|
|
|
if (appicon)
|
2009-12-05 09:22:43 +00:00
|
|
|
{
|
2009-11-18 01:17:56 +00:00
|
|
|
SDL_FreeSurface(appicon);
|
2009-12-05 09:22:43 +00:00
|
|
|
appicon = NULL;
|
|
|
|
}
|
2009-11-18 01:17:56 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_Quit();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2018-07-14 21:36:44 +00:00
|
|
|
# if SDL_MAJOR_VERSION!=1
|
2018-02-16 06:38:21 +00:00
|
|
|
SDL_GL_UnloadLibrary();
|
2018-07-14 21:36:44 +00:00
|
|
|
# endif
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 10:00:25 +00:00
|
|
|
//
|
|
|
|
// system_getcvars() -- propagate any cvars that are read post-initialization
|
|
|
|
//
|
|
|
|
void system_getcvars(void)
|
|
|
|
{
|
2019-10-23 19:11:37 +00:00
|
|
|
vid_vsync = videoSetVsync(vid_vsync);
|
2013-10-08 10:00:25 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// All things Input
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
// static int32_t joyblast=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
static SDL_Joystick *joydev = NULL;
|
2019-08-12 15:23:15 +00:00
|
|
|
#if SDL_MAJOR_VERSION >= 2
|
|
|
|
static SDL_GameController *controller = NULL;
|
|
|
|
|
|
|
|
static void LoadSDLControllerDB()
|
|
|
|
{
|
2019-10-20 22:13:17 +00:00
|
|
|
auto fh = fopenFileReader("gamecontrollerdb.txt", 0);
|
|
|
|
if (!fh.isOpen())
|
2019-08-12 15:23:15 +00:00
|
|
|
return;
|
|
|
|
|
2019-10-20 22:13:17 +00:00
|
|
|
int flen = fh.GetLength();
|
2019-08-12 15:23:15 +00:00
|
|
|
if (flen <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * dbuf = (char *)malloc(flen + 1);
|
|
|
|
if (!dbuf)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-20 22:13:17 +00:00
|
|
|
if (fh.Read(dbuf, flen) != flen)
|
2019-08-12 15:23:15 +00:00
|
|
|
{
|
|
|
|
free(dbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbuf[flen] = '\0';
|
|
|
|
|
|
|
|
SDL_RWops * rwops = SDL_RWFromConstMem(dbuf, flen);
|
|
|
|
if (!rwops)
|
|
|
|
{
|
|
|
|
free(dbuf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-19 23:42:24 +00:00
|
|
|
int i = SDL_GameControllerAddMappingsFromRW(rwops, 1);
|
|
|
|
|
2019-08-12 15:23:15 +00:00
|
|
|
free(dbuf);
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-08-14 03:03:52 +00:00
|
|
|
void joyScanDevices()
|
|
|
|
{
|
|
|
|
inputdevices &= ~4;
|
|
|
|
|
|
|
|
if (controller)
|
|
|
|
{
|
|
|
|
SDL_GameControllerClose(controller);
|
|
|
|
controller = nullptr;
|
|
|
|
}
|
|
|
|
if (joydev)
|
|
|
|
{
|
|
|
|
SDL_JoystickClose(joydev);
|
|
|
|
joydev = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-08-14 15:28:59 +00:00
|
|
|
int numjoysticks = SDL_NumJoysticks();
|
2019-08-14 03:03:52 +00:00
|
|
|
if (numjoysticks < 1)
|
|
|
|
{
|
2019-11-05 19:25:57 +00:00
|
|
|
initprintf("No game controllers found\n");
|
2019-08-14 03:03:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-05 19:25:57 +00:00
|
|
|
initprintf("Game controllers:\n");
|
2019-08-14 03:03:52 +00:00
|
|
|
for (int i = 0; i < numjoysticks; i++)
|
|
|
|
{
|
|
|
|
const char * name;
|
|
|
|
#if SDL_MAJOR_VERSION >= 2
|
|
|
|
if (SDL_IsGameController(i))
|
|
|
|
name = SDL_GameControllerNameForIndex(i);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
name = SDL_JoystickNameForIndex(i);
|
|
|
|
|
|
|
|
buildprintf(" %d. %s\n", i+1, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SDL_MAJOR_VERSION >= 2
|
|
|
|
for (int i = 0; i < numjoysticks; i++)
|
|
|
|
{
|
|
|
|
if ((controller = SDL_GameControllerOpen(i)))
|
|
|
|
{
|
|
|
|
buildprintf("Using controller %s\n", SDL_GameControllerName(controller));
|
|
|
|
|
|
|
|
joystick.numAxes = SDL_CONTROLLER_AXIS_MAX;
|
|
|
|
joystick.numButtons = SDL_CONTROLLER_BUTTON_MAX;
|
|
|
|
joystick.numHats = 0;
|
|
|
|
joystick.isGameController = 1;
|
|
|
|
|
|
|
|
Xfree(joystick.pAxis);
|
|
|
|
joystick.pAxis = (int32_t *)Xcalloc(joystick.numAxes, sizeof(int32_t));
|
|
|
|
Xfree(joystick.pHat);
|
|
|
|
joystick.pHat = nullptr;
|
|
|
|
|
|
|
|
inputdevices |= 4;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int i = 0; i < numjoysticks; i++)
|
|
|
|
{
|
|
|
|
if ((joydev = SDL_JoystickOpen(i)))
|
|
|
|
{
|
|
|
|
buildprintf("Using joystick %s\n", SDL_JoystickName(joydev));
|
|
|
|
|
|
|
|
// KEEPINSYNC duke3d/src/gamedefs.h, mact/include/_control.h
|
|
|
|
joystick.numAxes = min(9, SDL_JoystickNumAxes(joydev));
|
|
|
|
joystick.numButtons = min(32, SDL_JoystickNumButtons(joydev));
|
|
|
|
joystick.numHats = min((36-joystick.numButtons)/4,SDL_JoystickNumHats(joydev));
|
|
|
|
joystick.isGameController = 0;
|
|
|
|
|
|
|
|
initprintf("Joystick %d has %d axes, %d buttons, and %d hat(s).\n", i+1, joystick.numAxes, joystick.numButtons, joystick.numHats);
|
|
|
|
|
|
|
|
Xfree(joystick.pAxis);
|
|
|
|
joystick.pAxis = (int32_t *)Xcalloc(joystick.numAxes, sizeof(int32_t));
|
|
|
|
|
|
|
|
Xfree(joystick.pHat);
|
|
|
|
if (joystick.numHats)
|
|
|
|
joystick.pHat = (int32_t *)Xcalloc(joystick.numHats, sizeof(int32_t));
|
|
|
|
else
|
|
|
|
joystick.pHat = nullptr;
|
|
|
|
|
|
|
|
for (int j = 0; j < joystick.numHats; j++)
|
|
|
|
joystick.pHat[j] = -1; // center
|
|
|
|
|
|
|
|
SDL_JoystickEventState(SDL_ENABLE);
|
|
|
|
inputdevices |= 4;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-05 19:25:57 +00:00
|
|
|
initprintf("No controllers are usable\n");
|
2019-08-14 03:03:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// initinput() -- init input system
|
|
|
|
//
|
2019-08-14 15:28:59 +00:00
|
|
|
int32_t initinput(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-05-24 15:27:53 +00:00
|
|
|
|
2015-04-28 21:30:42 +00:00
|
|
|
#if defined EDUKE32_OSX
|
2006-04-24 19:04:22 +00:00
|
|
|
// force OS X to operate in >1 button mouse mode so that LMB isn't adulterated
|
2014-11-22 12:33:47 +00:00
|
|
|
if (!getenv("SDL_HAS3BUTTONMOUSE"))
|
2018-10-07 05:23:44 +00:00
|
|
|
{
|
|
|
|
static char sdl_has3buttonmouse[] = "SDL_HAS3BUTTONMOUSE=1";
|
2016-01-12 10:30:48 +00:00
|
|
|
putenv(sdl_has3buttonmouse);
|
2018-10-07 05:23:44 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
inputdevices = 1 | 2; // keyboard (1) and mouse (2)
|
2018-04-12 21:02:31 +00:00
|
|
|
g_mouseGrabbed = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2019-08-12 15:23:15 +00:00
|
|
|
if (!SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2019-08-12 15:23:15 +00:00
|
|
|
LoadSDLControllerDB();
|
2019-08-14 03:03:52 +00:00
|
|
|
joyScanDevices();
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitinput() -- uninit input system
|
|
|
|
//
|
|
|
|
void uninitinput(void)
|
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseUninit();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-08-12 15:23:15 +00:00
|
|
|
if (controller)
|
|
|
|
{
|
|
|
|
SDL_GameControllerClose(controller);
|
|
|
|
controller = NULL;
|
|
|
|
}
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (joydev)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_JoystickClose(joydev);
|
|
|
|
joydev = NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
const char *joyGetName(int32_t what, int32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
static char tmp[64];
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
switch (what)
|
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
case 0: // axis
|
2018-04-12 21:02:31 +00:00
|
|
|
if ((unsigned)num > (unsigned)joystick.numAxes)
|
2014-11-22 12:33:47 +00:00
|
|
|
return NULL;
|
2019-08-12 15:23:15 +00:00
|
|
|
|
|
|
|
if (controller)
|
|
|
|
{
|
|
|
|
static char const * axisStrings[] =
|
|
|
|
{
|
|
|
|
"Left Stick X-Axis",
|
|
|
|
"Left Stick Y-Axis",
|
|
|
|
"Right Stick X-Axis",
|
|
|
|
"Right Stick Y-Axis",
|
|
|
|
"Left Trigger",
|
|
|
|
"Right Trigger",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
return axisStrings[num];
|
|
|
|
}
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
Bsprintf(tmp, "Axis %d", num);
|
|
|
|
return (char *)tmp;
|
|
|
|
|
|
|
|
case 1: // button
|
2018-04-12 21:02:31 +00:00
|
|
|
if ((unsigned)num > (unsigned)joystick.numButtons)
|
2014-11-22 12:33:47 +00:00
|
|
|
return NULL;
|
2019-08-12 15:23:15 +00:00
|
|
|
|
|
|
|
if (controller)
|
|
|
|
{
|
|
|
|
static char const * buttonStrings[] =
|
|
|
|
{
|
|
|
|
"A",
|
|
|
|
"B",
|
|
|
|
"X",
|
|
|
|
"Y",
|
|
|
|
"Back",
|
|
|
|
"Guide",
|
|
|
|
"Start",
|
|
|
|
"Left Stick",
|
|
|
|
"Right Stick",
|
|
|
|
"Left Shoulder",
|
|
|
|
"Right Shoulder",
|
|
|
|
"D-Pad Up",
|
|
|
|
"D-Pad Down",
|
|
|
|
"D-Pad Left",
|
|
|
|
"D-Pad Right",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
return buttonStrings[num];
|
|
|
|
}
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
Bsprintf(tmp, "Button %d", num);
|
|
|
|
return (char *)tmp;
|
|
|
|
|
|
|
|
case 2: // hat
|
2018-04-12 21:02:31 +00:00
|
|
|
if ((unsigned)num > (unsigned)joystick.numHats)
|
2014-11-22 12:33:47 +00:00
|
|
|
return NULL;
|
|
|
|
Bsprintf(tmp, "Hat %d", num);
|
|
|
|
return (char *)tmp;
|
|
|
|
|
|
|
|
default: return NULL;
|
2012-05-01 12:38:43 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// initmouse() -- init mouse input
|
|
|
|
//
|
2018-11-18 18:08:53 +00:00
|
|
|
void mouseInit(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:08:53 +00:00
|
|
|
mouseGrabInput(g_mouseEnabled = g_mouseLockedToWindow); // FIXME - SA
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitmouse() -- uninit mouse input
|
|
|
|
//
|
2018-04-12 21:02:31 +00:00
|
|
|
void mouseUninit(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseGrabInput(0);
|
|
|
|
g_mouseEnabled = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 09:59:59 +00:00
|
|
|
//
|
|
|
|
// grabmouse_low() -- show/hide mouse cursor, lower level (doesn't check state).
|
|
|
|
// furthermore return 0 if successful.
|
|
|
|
//
|
|
|
|
|
|
|
|
static inline char grabmouse_low(char a)
|
|
|
|
{
|
|
|
|
/* FIXME: Maybe it's better to make sure that grabmouse_low
|
|
|
|
is called only when a window is ready? */
|
|
|
|
if (sdl_window)
|
|
|
|
SDL_SetWindowGrab(sdl_window, a ? SDL_TRUE : SDL_FALSE);
|
|
|
|
return SDL_SetRelativeMouseMode(a ? SDL_TRUE : SDL_FALSE);
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// grabmouse() -- show/hide mouse cursor
|
|
|
|
//
|
2018-04-23 06:35:52 +00:00
|
|
|
void mouseGrabInput(bool grab)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-04-12 21:02:31 +00:00
|
|
|
if (appactive && g_mouseEnabled)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2018-04-23 06:35:52 +00:00
|
|
|
if ((grab != g_mouseGrabbed) && !grabmouse_low(grab))
|
|
|
|
g_mouseGrabbed = grab;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else
|
2018-04-23 06:35:52 +00:00
|
|
|
g_mouseGrabbed = grab;
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2019-11-10 14:15:14 +00:00
|
|
|
inputState.MouseSetPos(0, 0);
|
2019-12-05 20:39:02 +00:00
|
|
|
SDL_ShowCursor(!grab ? SDL_ENABLE : SDL_DISABLE);
|
|
|
|
if (grab) GUICapture &= ~1;
|
|
|
|
else GUICapture |= 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// setjoydeadzone() -- sets the dead and saturation zones for the joystick
|
|
|
|
//
|
2018-04-12 21:02:31 +00:00
|
|
|
void joySetDeadZone(int32_t axis, uint16_t dead, uint16_t satur)
|
2008-03-23 00:06:42 +00:00
|
|
|
{
|
2010-10-21 02:20:40 +00:00
|
|
|
joydead[axis] = dead;
|
|
|
|
joysatur[axis] = satur;
|
2008-03-23 00:06:42 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// getjoydeadzone() -- gets the dead and saturation zones for the joystick
|
|
|
|
//
|
2018-04-12 21:02:31 +00:00
|
|
|
void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-10-21 02:20:40 +00:00
|
|
|
*dead = joydead[axis];
|
|
|
|
*satur = joysatur[axis];
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// All things Video
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// getvalidmodes() -- figure out what video modes are available
|
|
|
|
//
|
2013-09-21 13:38:44 +00:00
|
|
|
static int sortmodes(const void *a_, const void *b_)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2019-08-08 01:49:00 +00:00
|
|
|
auto a = (const struct validmode_t *)b_;
|
|
|
|
auto b = (const struct validmode_t *)a_;
|
2018-11-18 18:07:10 +00:00
|
|
|
|
|
|
|
int x;
|
2013-09-21 13:38:44 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((x = a->fs - b->fs) != 0) return x;
|
|
|
|
if ((x = a->bpp - b->bpp) != 0) return x;
|
|
|
|
if ((x = a->xdim - b->xdim) != 0) return x;
|
|
|
|
if ((x = a->ydim - b->ydim) != 0) return x;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-04-12 08:45:26 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
static char modeschecked=0;
|
2014-04-12 08:45:26 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
#if SDL_MAJOR_VERSION != 1
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoGetModes(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
int32_t i, maxx = 0, maxy = 0;
|
|
|
|
SDL_DisplayMode dispmode;
|
2019-08-29 20:06:31 +00:00
|
|
|
int const display = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
if (modeschecked || novideo)
|
|
|
|
return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
validmodecnt = 0;
|
2014-04-12 08:45:26 +00:00
|
|
|
// initprintf("Detecting video modes:\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// do fullscreen modes first
|
2019-08-29 20:06:31 +00:00
|
|
|
for (i = 0; i < SDL_GetNumDisplayModes(display); i++)
|
2013-10-08 09:59:59 +00:00
|
|
|
{
|
2019-08-29 20:06:31 +00:00
|
|
|
SDL_GetDisplayMode(display, i, &dispmode);
|
2017-08-27 10:20:41 +00:00
|
|
|
|
|
|
|
if (!SDL_CHECKMODE(dispmode.w, dispmode.h) ||
|
2016-02-13 21:06:12 +00:00
|
|
|
(maxrefreshfreq && (dispmode.refresh_rate > maxrefreshfreq)))
|
2014-11-22 12:33:47 +00:00
|
|
|
continue;
|
2013-10-08 09:59:59 +00:00
|
|
|
|
|
|
|
// HACK: 8-bit == Software, 32-bit == OpenGL
|
2014-11-22 12:33:47 +00:00
|
|
|
SDL_ADDMODE(dispmode.w, dispmode.h, 8, 1);
|
2013-10-08 09:59:59 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
if (!nogl)
|
2014-11-22 12:33:47 +00:00
|
|
|
SDL_ADDMODE(dispmode.w, dispmode.h, 32, 1);
|
2013-10-08 09:59:59 +00:00
|
|
|
#endif
|
2014-11-22 12:33:47 +00:00
|
|
|
if ((dispmode.w > maxx) || (dispmode.h > maxy))
|
2013-10-08 09:59:59 +00:00
|
|
|
{
|
|
|
|
maxx = dispmode.w;
|
|
|
|
maxy = dispmode.h;
|
|
|
|
}
|
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
SDL_CHECKFSMODES(maxx, maxy);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// add windowed modes next
|
2018-10-25 23:32:00 +00:00
|
|
|
// SDL sorts display modes largest to smallest, so we can just compare with mode 0
|
|
|
|
// to make sure we aren't adding modes that are larger than the actual screen res
|
2019-08-29 20:06:31 +00:00
|
|
|
SDL_GetDisplayMode(display, 0, &dispmode);
|
2018-10-25 23:32:00 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
for (i = 0; g_defaultVideoModes[i].x; i++)
|
2014-04-12 08:45:26 +00:00
|
|
|
{
|
2018-10-25 23:32:00 +00:00
|
|
|
auto const &mode = g_defaultVideoModes[i];
|
|
|
|
|
|
|
|
if (mode.x > dispmode.w || mode.y > dispmode.h || !SDL_CHECKMODE(mode.x, mode.y))
|
2014-11-22 12:33:47 +00:00
|
|
|
continue;
|
|
|
|
|
2018-10-25 23:32:00 +00:00
|
|
|
// 8-bit == Software, 32-bit == OpenGL
|
|
|
|
SDL_ADDMODE(mode.x, mode.y, 8, 0);
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2013-10-08 09:59:59 +00:00
|
|
|
#ifdef USE_OPENGL
|
2014-11-22 12:33:47 +00:00
|
|
|
if (nogl)
|
|
|
|
continue;
|
|
|
|
|
2018-10-25 23:32:00 +00:00
|
|
|
SDL_ADDMODE(mode.x, mode.y, 32, 0);
|
2013-10-08 09:59:59 +00:00
|
|
|
#endif
|
2014-04-12 08:45:26 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
qsort((void *)validmode, validmodecnt, sizeof(struct validmode_t), &sortmodes);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
modeschecked = 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-04-12 08:45:26 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// checkvideomode() -- makes sure the video mode passed is legal
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoCheckMode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, nearest=-1, dx, dy, odx=9999, ody=9999;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
videoGetModes();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (c>8
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
&& nogl
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
) return -1;
|
|
|
|
|
|
|
|
// fix up the passed resolution values to be multiples of 8
|
|
|
|
// and at least 320x200 or at most MAXXDIMxMAXYDIM
|
2014-11-22 12:33:47 +00:00
|
|
|
*x = clamp(*x, 320, MAXXDIM);
|
|
|
|
*y = clamp(*y, 200, MAXYDIM);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
for (i = 0; i < validmodecnt; i++)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
if (validmode[i].bpp != c || validmode[i].fs != fs)
|
|
|
|
continue;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
dx = klabs(validmode[i].xdim - *x);
|
|
|
|
dy = klabs(validmode[i].ydim - *y);
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (!(dx | dy))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
// perfect match
|
2006-04-24 19:04:22 +00:00
|
|
|
nearest = i;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if ((dx <= odx) && (dy <= ody))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
nearest = i;
|
2014-11-22 12:33:47 +00:00
|
|
|
odx = dx;
|
|
|
|
ody = dy;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
#ifdef ANY_WINDOWED_SIZE
|
2006-07-01 01:40:18 +00:00
|
|
|
if (!forced && (fs&1) == 0 && (nearest < 0 || (validmode[nearest].xdim!=*x || validmode[nearest].ydim!=*y)))
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0x7fffffffl;
|
2006-11-13 23:12:47 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (nearest < 0)
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
*x = validmode[nearest].xdim;
|
|
|
|
*y = validmode[nearest].ydim;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
return nearest;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 09:59:59 +00:00
|
|
|
static void destroy_window_resources()
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
/* We should NOT destroy the window surface. This is done automatically
|
|
|
|
when SDL_DestroyWindow or SDL_SetVideoMode is called. */
|
|
|
|
|
|
|
|
#if SDL_MAJOR_VERSION == 2
|
|
|
|
if (sdl_context)
|
|
|
|
SDL_GL_DeleteContext(sdl_context);
|
|
|
|
sdl_context = NULL;
|
|
|
|
if (sdl_window)
|
|
|
|
SDL_DestroyWindow(sdl_window);
|
|
|
|
sdl_window = NULL;
|
2013-10-07 10:06:09 +00:00
|
|
|
#endif
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
void sdlayer_setvideomode_opengl(int y)
|
2014-11-22 12:33:47 +00:00
|
|
|
{
|
2018-06-13 19:15:16 +00:00
|
|
|
glsurface_destroy();
|
2014-11-22 12:33:47 +00:00
|
|
|
polymost_glreset();
|
|
|
|
|
2019-09-23 21:33:59 +00:00
|
|
|
GLInterface.Deinit();
|
2019-11-07 19:31:16 +00:00
|
|
|
GLInterface.Init(y);
|
2019-10-10 19:05:10 +00:00
|
|
|
GLInterface.InitGLState(4, glmultisample);
|
2019-10-19 23:14:48 +00:00
|
|
|
|
2019-10-23 19:11:37 +00:00
|
|
|
GLInterface.mSamplers->SetTextureFilterMode(hw_texfilter, hw_anisotropy);
|
2019-09-23 21:33:59 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// setvideomode() -- set SDL video mode
|
|
|
|
//
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
int32_t setvideomode_sdlcommon(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t *regrab)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
if ((fs == fullscreen) && (*x == xres) && (*y == yres) && (c == bpp) && !videomodereset)
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
if (videoCheckMode(x, y, c, fs, 0) < 0)
|
2014-11-22 12:33:47 +00:00
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
if (g_mouseGrabbed)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
*regrab = 1;
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseGrabInput(0);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
while (lockcount) videoEndDrawing();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-06-13 19:15:16 +00:00
|
|
|
if (sdl_surface)
|
|
|
|
{
|
|
|
|
if (bpp > 8)
|
|
|
|
polymost_glreset();
|
2018-07-14 21:36:34 +00:00
|
|
|
}
|
|
|
|
if (!nogl)
|
|
|
|
{
|
|
|
|
if (bpp == 8)
|
2018-06-13 19:15:16 +00:00
|
|
|
glsurface_destroy();
|
2018-07-14 21:36:34 +00:00
|
|
|
if ((fs == fullscreen) && (*x == xres) && (*y == yres) && (bpp != 0) && !videomodereset)
|
|
|
|
return 0;
|
2018-06-13 19:15:16 +00:00
|
|
|
}
|
2018-07-14 21:36:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
softsurface_destroy();
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setvideomode_sdlcommonpost(int32_t x, int32_t y, int32_t c, int32_t fs, int32_t regrab)
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2018-06-13 19:15:16 +00:00
|
|
|
if (!nogl)
|
2019-11-07 19:31:16 +00:00
|
|
|
sdlayer_setvideomode_opengl(y);
|
2014-11-22 12:33:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
xres = x;
|
|
|
|
yres = y;
|
|
|
|
bpp = c;
|
|
|
|
fullscreen = fs;
|
|
|
|
// bytesperline = sdl_surface->pitch;
|
|
|
|
numpages = c > 8 ? 2 : 1;
|
|
|
|
frameplace = 0;
|
|
|
|
lockcount = 0;
|
|
|
|
modechange = 1;
|
|
|
|
videomodereset = 0;
|
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
videoFadePalette(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta);
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
if (regrab)
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseGrabInput(g_mouseLockedToWindow);
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if SDL_MAJOR_VERSION!=1
|
2016-02-13 21:06:12 +00:00
|
|
|
void setrefreshrate(void)
|
|
|
|
{
|
2019-08-29 20:06:31 +00:00
|
|
|
int const display = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : 0;
|
|
|
|
|
2016-02-13 21:06:12 +00:00
|
|
|
SDL_DisplayMode dispmode;
|
2019-08-29 20:06:31 +00:00
|
|
|
SDL_GetCurrentDisplayMode(display, &dispmode);
|
2016-02-13 21:06:12 +00:00
|
|
|
|
|
|
|
dispmode.refresh_rate = maxrefreshfreq;
|
|
|
|
|
|
|
|
SDL_DisplayMode newmode;
|
2019-08-29 20:06:31 +00:00
|
|
|
SDL_GetClosestDisplayMode(display, &dispmode, &newmode);
|
2016-02-13 21:06:12 +00:00
|
|
|
|
2019-08-27 13:39:54 +00:00
|
|
|
char error = 0;
|
|
|
|
|
2016-02-13 21:06:12 +00:00
|
|
|
if (dispmode.refresh_rate != newmode.refresh_rate)
|
|
|
|
{
|
|
|
|
initprintf("Refresh rate: %dHz\n", newmode.refresh_rate);
|
2019-08-27 13:39:54 +00:00
|
|
|
error = SDL_SetWindowDisplayMode(sdl_window, &newmode);
|
2016-02-13 21:06:12 +00:00
|
|
|
}
|
2018-02-22 23:25:56 +00:00
|
|
|
|
2018-04-12 21:04:07 +00:00
|
|
|
if (!newmode.refresh_rate)
|
|
|
|
newmode.refresh_rate = 60;
|
2019-08-27 13:39:54 +00:00
|
|
|
|
|
|
|
refreshfreq = error ? -1 : newmode.refresh_rate;
|
2016-02-13 21:06:12 +00:00
|
|
|
}
|
|
|
|
|
2019-09-23 21:33:59 +00:00
|
|
|
int called = 0;
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs)
|
2014-11-22 12:33:47 +00:00
|
|
|
{
|
|
|
|
int32_t regrab = 0, ret;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2019-10-26 18:47:37 +00:00
|
|
|
// SDL's fullscreen is a deadly trap in the debugger.
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (fs)
|
|
|
|
{
|
|
|
|
fs = false;
|
|
|
|
x -= 10;
|
|
|
|
y -= 10;
|
|
|
|
}
|
2019-09-23 21:33:59 +00:00
|
|
|
if (called++)
|
|
|
|
{
|
2019-10-27 12:40:24 +00:00
|
|
|
//assert(0);
|
|
|
|
return 0;
|
2019-09-23 21:33:59 +00:00
|
|
|
}
|
2019-10-27 12:40:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
ret = setvideomode_sdlcommon(&x, &y, c, fs, ®rab);
|
2018-07-14 21:36:34 +00:00
|
|
|
if (ret != 1)
|
|
|
|
{
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
setvideomode_sdlcommonpost(x, y, c, fs, regrab);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2013-10-08 09:59:59 +00:00
|
|
|
// deinit
|
|
|
|
destroy_window_resources();
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
initprintf("Setting video mode %dx%d (%d-bpp %s)\n", x, y, c, ((fs & 1) ? "fullscreen" : "windowed"));
|
|
|
|
|
2019-08-29 20:06:31 +00:00
|
|
|
int const display = r_displayindex < SDL_GetNumVideoDisplays() ? r_displayindex : 0;
|
|
|
|
|
2018-11-18 18:11:38 +00:00
|
|
|
SDL_DisplayMode desktopmode;
|
2019-08-29 20:06:31 +00:00
|
|
|
SDL_GetDesktopDisplayMode(display, &desktopmode);
|
2018-11-18 18:11:38 +00:00
|
|
|
|
2019-08-29 19:00:52 +00:00
|
|
|
int const matchedResolution = (desktopmode.w == x && desktopmode.h == y);
|
2019-08-29 20:06:31 +00:00
|
|
|
int const borderless = (r_borderless == 1 || (r_borderless == 2 && matchedResolution)) ? SDL_WINDOW_BORDERLESS : 0;
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-06-13 19:15:16 +00:00
|
|
|
if (c > 8 || !nogl)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2018-10-07 05:23:44 +00:00
|
|
|
int32_t i;
|
2015-02-11 05:22:48 +00:00
|
|
|
int32_t multisamplecheck = (glmultisample > 0);
|
2014-11-22 12:33:47 +00:00
|
|
|
if (nogl)
|
|
|
|
return -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-11-22 18:37:16 +00:00
|
|
|
struct glattribs
|
|
|
|
{
|
|
|
|
SDL_GLattr attr;
|
|
|
|
int32_t value;
|
2015-02-11 05:22:29 +00:00
|
|
|
} sdlayer_gl_attributes[] =
|
2014-11-22 18:37:16 +00:00
|
|
|
{
|
2015-02-11 05:22:29 +00:00
|
|
|
{ SDL_GL_DOUBLEBUFFER, 1 },
|
|
|
|
{ SDL_GL_MULTISAMPLEBUFFERS, glmultisample > 0 },
|
|
|
|
{ SDL_GL_MULTISAMPLESAMPLES, glmultisample },
|
2019-08-16 15:57:16 +00:00
|
|
|
{ SDL_GL_STENCIL_SIZE, 1 },
|
2015-02-11 05:22:29 +00:00
|
|
|
{ SDL_GL_ACCELERATED_VISUAL, 1 },
|
|
|
|
};
|
2012-11-25 04:26:37 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
do
|
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
SDL_GL_ATTRIBUTES(i, sdlayer_gl_attributes);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-07-22 21:56:28 +00:00
|
|
|
/* HACK: changing SDL GL attribs only works before surface creation,
|
|
|
|
so we have to create a new surface in a different format first
|
|
|
|
to force the surface we WANT to be recreated instead of reused. */
|
2019-08-29 19:00:52 +00:00
|
|
|
|
|
|
|
|
2019-08-29 20:06:31 +00:00
|
|
|
sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
|
|
|
|
windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
|
2019-08-29 19:00:52 +00:00
|
|
|
SDL_WINDOW_OPENGL | borderless);
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
if (sdl_window)
|
|
|
|
sdl_context = SDL_GL_CreateContext(sdl_window);
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
if (!sdl_window || !sdl_context)
|
2013-10-08 09:59:59 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
initprintf("Unable to set video mode: %s failed: %s\n", sdl_window ? "SDL_GL_CreateContext" : "SDL_GL_CreateWindow", SDL_GetError());
|
2019-08-29 19:00:52 +00:00
|
|
|
nogl = 1;
|
2013-10-08 09:59:59 +00:00
|
|
|
destroy_window_resources();
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
return -1;
|
2013-10-08 09:59:59 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
gladLoadGLLoader(SDL_GL_GetProcAddress);
|
2018-06-13 19:15:22 +00:00
|
|
|
if (GLVersion.major < 2)
|
|
|
|
{
|
|
|
|
initprintf("Your computer does not support OpenGL version 2 or greater. GL modes are unavailable.\n");
|
|
|
|
nogl = 1;
|
|
|
|
destroy_window_resources();
|
|
|
|
return -1;
|
|
|
|
}
|
2018-02-26 14:46:36 +00:00
|
|
|
|
2019-08-29 19:00:52 +00:00
|
|
|
SDL_SetWindowFullscreen(sdl_window, ((fs & 1) ? (matchedResolution ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN) : 0));
|
2016-12-26 06:01:36 +00:00
|
|
|
SDL_GL_SetSwapInterval(vsync_renderlayer);
|
2013-10-08 09:59:59 +00:00
|
|
|
|
2016-02-13 21:06:12 +00:00
|
|
|
setrefreshrate();
|
2014-11-22 12:33:47 +00:00
|
|
|
} while (multisamplecheck--);
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-10 15:44:53 +00:00
|
|
|
#endif // defined USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
// init
|
2019-08-29 20:06:31 +00:00
|
|
|
sdl_window = SDL_CreateWindow("", windowpos ? windowx : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display),
|
|
|
|
windowpos ? windowy : (int)SDL_WINDOWPOS_CENTERED_DISPLAY(display), x, y,
|
2019-08-29 19:00:52 +00:00
|
|
|
borderless);
|
2013-10-08 09:59:59 +00:00
|
|
|
if (!sdl_window)
|
2014-04-12 08:45:26 +00:00
|
|
|
SDL2_VIDEO_ERR("SDL_CreateWindow");
|
Add prototypical SDL 2.X support.
Doesn't work: indexed-color modes, gamma (at least for X11), mouse wheel,
special keys like ENTER or BACKSPACE in the OSD, probably more...
In build/Makefile.shared, we now have logic to autodetect an SDL2 installed
in /usr/local, however OS X and Wii builds follow other Makefile code paths,
it seems. Note that the matching SDL2_mixer must be used then, too.
In source/jaudiolib/src/driver_sdl.c, change the #includes from <SDL/SDL_xxx.h>
to "SDL_xxx.h". SDL wiki says this is the most portable way, hopefully this
doesn't break builds for anyone.
git-svn-id: https://svn.eduke32.com/eduke32@2777 1a8010ca-5511-0410-912e-c29ae57300e0
2012-06-22 21:39:53 +00:00
|
|
|
|
2016-02-13 21:06:12 +00:00
|
|
|
setrefreshrate();
|
|
|
|
|
2014-01-12 14:05:56 +00:00
|
|
|
if (!sdl_surface)
|
|
|
|
{
|
|
|
|
sdl_surface = SDL_GetWindowSurface(sdl_window);
|
2014-11-22 12:33:47 +00:00
|
|
|
if (!sdl_surface)
|
|
|
|
SDL2_VIDEO_ERR("SDL_GetWindowSurface");
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2019-08-29 19:00:52 +00:00
|
|
|
SDL_SetWindowFullscreen(sdl_window, ((fs & 1) ? (matchedResolution ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_FULLSCREEN) : 0));
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 02:56:17 +00:00
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");
|
2014-11-22 12:33:47 +00:00
|
|
|
setvideomode_sdlcommonpost(x, y, c, fs, regrab);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// resetvideomode() -- resets the video system
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoResetMode(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
videomodereset = 1;
|
|
|
|
modeschecked = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// begindrawing() -- locks the framebuffer for drawing
|
|
|
|
//
|
2015-07-25 17:23:21 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoBeginDrawing(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-17 05:05:16 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (offscreenrendering) return;
|
|
|
|
frameplace = 0;
|
|
|
|
bytesperline = 0;
|
|
|
|
modechange = 0;
|
|
|
|
return;
|
|
|
|
}
|
2018-06-13 19:15:16 +00:00
|
|
|
|
2018-06-28 02:00:42 +00:00
|
|
|
// lock the frame
|
|
|
|
if (lockcount++ > 0)
|
|
|
|
return;
|
|
|
|
|
2019-08-01 00:08:02 +00:00
|
|
|
static intptr_t backupFrameplace = 0;
|
2018-06-28 02:00:42 +00:00
|
|
|
|
2019-06-25 18:35:05 +00:00
|
|
|
if (inpreparemirror)
|
|
|
|
{
|
2019-08-01 00:08:02 +00:00
|
|
|
//POGO: if we are offscreenrendering and we need to render a mirror
|
|
|
|
// or we are rendering a mirror and we start offscreenrendering,
|
|
|
|
// backup our offscreen target so we can restore it later
|
|
|
|
// (but only allow one level deep,
|
|
|
|
// i.e. no viewscreen showing a camera showing a mirror that reflects the same viewscreen and recursing)
|
|
|
|
if (offscreenrendering)
|
|
|
|
{
|
|
|
|
if (!backupFrameplace)
|
|
|
|
backupFrameplace = frameplace;
|
|
|
|
else if (frameplace != (intptr_t)mirrorBuffer &&
|
|
|
|
frameplace != backupFrameplace)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-25 18:35:05 +00:00
|
|
|
frameplace = (intptr_t)mirrorBuffer;
|
2019-08-01 00:08:02 +00:00
|
|
|
|
|
|
|
if (offscreenrendering)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (offscreenrendering)
|
|
|
|
{
|
|
|
|
if (backupFrameplace)
|
|
|
|
{
|
|
|
|
frameplace = backupFrameplace;
|
|
|
|
backupFrameplace = 0;
|
|
|
|
}
|
|
|
|
return;
|
2019-06-25 18:35:05 +00:00
|
|
|
}
|
|
|
|
else
|
2018-07-14 21:36:44 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-06-28 02:00:42 +00:00
|
|
|
if (!nogl)
|
|
|
|
{
|
2018-06-13 19:15:16 +00:00
|
|
|
frameplace = (intptr_t)glsurface_getBuffer();
|
|
|
|
}
|
2019-06-25 18:35:05 +00:00
|
|
|
else
|
2018-07-14 21:36:44 +00:00
|
|
|
#endif
|
2019-06-25 18:35:05 +00:00
|
|
|
{
|
|
|
|
frameplace = (intptr_t)softsurface_getBuffer();
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-07-14 21:36:44 +00:00
|
|
|
if (modechange)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2018-07-14 21:36:44 +00:00
|
|
|
bytesperline = xdim;
|
2012-12-14 19:28:17 +00:00
|
|
|
calc_ylookup(bytesperline, ydim);
|
2006-04-24 19:04:22 +00:00
|
|
|
modechange=0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// enddrawing() -- unlocks the framebuffer
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoEndDrawing(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-06-28 02:00:42 +00:00
|
|
|
if (bpp > 8)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!offscreenrendering) frameplace = 0;
|
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!frameplace) return;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (lockcount > 1) { lockcount--; return; }
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!offscreenrendering) frameplace = 0;
|
|
|
|
if (lockcount == 0) return;
|
|
|
|
lockcount = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// showframe() -- update the display
|
|
|
|
//
|
2014-11-22 12:33:47 +00:00
|
|
|
#if SDL_MAJOR_VERSION != 1
|
2015-02-11 05:22:29 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
void videoShowFrame(int32_t w)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(w);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-02-11 05:22:29 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-06-13 19:15:16 +00:00
|
|
|
if (!nogl)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2019-11-10 14:15:14 +00:00
|
|
|
if (bpp == 8)
|
2018-06-13 19:15:16 +00:00
|
|
|
{
|
2018-06-25 14:53:46 +00:00
|
|
|
glsurface_blitBuffer();
|
2018-06-13 19:15:16 +00:00
|
|
|
}
|
2018-02-26 14:46:36 +00:00
|
|
|
|
2019-09-13 19:43:05 +00:00
|
|
|
static uint32_t lastSwapTime = 0;
|
|
|
|
glFinish();
|
2013-10-07 10:04:02 +00:00
|
|
|
SDL_GL_SwapWindow(sdl_window);
|
2019-08-13 14:44:09 +00:00
|
|
|
|
2019-09-13 19:43:05 +00:00
|
|
|
lastSwapTime = SDL_GetTicks();
|
2006-04-24 19:04:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (offscreenrendering) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (lockcount)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
printf("Frame still locked %d times when showframe() called.\n", lockcount);
|
2018-04-12 21:02:51 +00:00
|
|
|
while (lockcount) videoEndDrawing();
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2018-07-14 21:36:44 +00:00
|
|
|
if (SDL_MUSTLOCK(sdl_surface)) SDL_LockSurface(sdl_surface);
|
|
|
|
softsurface_blitBuffer((uint32_t*) sdl_surface->pixels, sdl_surface->format->BitsPerPixel);
|
|
|
|
if (SDL_MUSTLOCK(sdl_surface)) SDL_UnlockSurface(sdl_surface);
|
2011-12-28 20:34:41 +00:00
|
|
|
|
2018-07-14 21:36:44 +00:00
|
|
|
if (SDL_UpdateWindowSurface(sdl_window))
|
2013-10-08 09:59:59 +00:00
|
|
|
{
|
|
|
|
// If a fullscreen X11 window is minimized then this may be required.
|
|
|
|
// FIXME: What to do if this fails...
|
|
|
|
sdl_surface = SDL_GetWindowSurface(sdl_window);
|
|
|
|
SDL_UpdateWindowSurface(sdl_window);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
// setpalette() -- set palette values
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoUpdatePalette(int32_t start, int32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-07-14 21:36:44 +00:00
|
|
|
UNREFERENCED_PARAMETER(start);
|
|
|
|
UNREFERENCED_PARAMETER(num);
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
return 0; // no palette in opengl
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-07-14 21:36:44 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
if (!nogl)
|
|
|
|
glsurface_setPalette(curpalettefaded);
|
|
|
|
else
|
2013-10-06 07:49:53 +00:00
|
|
|
#endif
|
2018-07-14 21:36:44 +00:00
|
|
|
{
|
|
|
|
if (sdl_surface)
|
|
|
|
softsurface_setPalette(curpalettefaded,
|
|
|
|
sdl_surface->format->Rmask,
|
|
|
|
sdl_surface->format->Gmask,
|
|
|
|
sdl_surface->format->Bmask);
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2011-12-28 20:34:41 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// setgamma
|
|
|
|
//
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t videoSetGamma(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-04-12 21:02:51 +00:00
|
|
|
if (novideo)
|
|
|
|
return 0;
|
2014-04-15 19:02:48 +00:00
|
|
|
|
2019-10-05 19:59:03 +00:00
|
|
|
return 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:36:14 +00:00
|
|
|
#if !defined __APPLE__ && !defined EDUKE32_TOUCH_DEVICES
|
2019-09-22 21:15:46 +00:00
|
|
|
extern struct sdlappicon sdlappicon;
|
2014-11-22 12:34:29 +00:00
|
|
|
static inline SDL_Surface *loadappicon(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-11-22 12:34:29 +00:00
|
|
|
SDL_Surface *surf = SDL_CreateRGBSurfaceFrom((void *)sdlappicon.pixels, sdlappicon.width, sdlappicon.height, 32,
|
|
|
|
sdlappicon.width * 4, 0xffl, 0xff00l, 0xff0000l, 0xff000000l);
|
2006-04-24 19:04:22 +00:00
|
|
|
return surf;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// Miscellany
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-09-15 15:28:30 +00:00
|
|
|
int32_t handleevents_peekkeys(void)
|
|
|
|
{
|
|
|
|
SDL_PumpEvents();
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2013-10-06 07:49:53 +00:00
|
|
|
return SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYDOWN);
|
2012-09-15 15:28:30 +00:00
|
|
|
}
|
|
|
|
|
2019-11-10 14:15:14 +00:00
|
|
|
static void PostMouseMove(int x, int y)
|
|
|
|
{
|
|
|
|
static int lastx = 0, lasty = 0;
|
|
|
|
event_t ev = { 0,0,0,0,0,0,0 };
|
|
|
|
|
|
|
|
ev.x = x;
|
|
|
|
ev.y = y;
|
|
|
|
lastx = x;
|
|
|
|
lasty = y;
|
|
|
|
if (ev.x | ev.y)
|
|
|
|
{
|
|
|
|
ev.type = EV_Mouse;
|
|
|
|
D_PostEvent(&ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CVAR(Bool, m_noprescale, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|
|
|
|
|
|
|
static void MouseRead()
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (NativeMouse)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
SDL_GetRelativeMouseState(&x, &y);
|
|
|
|
if (!m_noprescale)
|
|
|
|
{
|
|
|
|
x *= 3;
|
|
|
|
y *= 2;
|
|
|
|
}
|
|
|
|
if (x | y)
|
|
|
|
{
|
|
|
|
PostMouseMove(x, -y);
|
|
|
|
}
|
|
|
|
}
|
2014-12-27 18:36:43 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// handleevents() -- process the SDL message queue
|
|
|
|
// returns !0 if there was an important event worth checking (like quitting)
|
|
|
|
//
|
2010-01-23 22:12:02 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
int32_t handleevents_sdlcommon(SDL_Event *ev)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
switch (ev->type)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
case SDL_MOUSEMOTION:
|
2019-11-10 14:15:14 +00:00
|
|
|
{
|
|
|
|
// The menus need this, even in non GUI-capture mode
|
|
|
|
event_t event;
|
|
|
|
event.data1 = ev->motion.x;
|
|
|
|
event.data2 = ev->motion.y;
|
|
|
|
|
|
|
|
//screen->ScaleCoordsFromWindow(event.data1, event.data2);
|
|
|
|
|
|
|
|
event.type = EV_GUI_Event;
|
|
|
|
event.subtype = EV_GUI_MouseMove;
|
|
|
|
|
|
|
|
SDL_Keymod kmod = SDL_GetModState();
|
|
|
|
event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
|
|
|
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
|
|
|
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
|
|
|
|
|
|
|
D_PostEvent(&event);
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
2019-11-10 14:15:14 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2015-04-28 21:30:42 +00:00
|
|
|
{
|
|
|
|
int32_t j;
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
// some of these get reordered to match winlayer
|
|
|
|
switch (ev->button.button)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
default: j = -1; break;
|
2019-11-04 00:01:54 +00:00
|
|
|
case SDL_BUTTON_LEFT: j = KEY_MOUSE1; break;
|
|
|
|
case SDL_BUTTON_RIGHT: j = KEY_MOUSE2; break;
|
|
|
|
case SDL_BUTTON_MIDDLE: j = KEY_MOUSE3; break;
|
2013-12-01 18:28:03 +00:00
|
|
|
|
2014-11-22 18:37:16 +00:00
|
|
|
/* Thumb buttons. */
|
2019-08-21 03:18:23 +00:00
|
|
|
// On SDL2/Windows and SDL >= 2.0.?/Linux, everything is as it should be.
|
|
|
|
// If anyone cares about old versions of SDL2 on Linux, patches welcome.
|
2019-11-04 00:01:54 +00:00
|
|
|
case SDL_BUTTON_X1: j = KEY_MOUSE4; break;
|
|
|
|
case SDL_BUTTON_X2: j = KEY_MOUSE5; break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
if (j < 0)
|
|
|
|
break;
|
|
|
|
|
2019-12-05 22:49:32 +00:00
|
|
|
if (!(GUICapture & 1))
|
|
|
|
{
|
|
|
|
event_t evt = { uint8_t((ev->button.state == SDL_PRESSED) ? EV_KeyDown : EV_KeyUp), 0, (int16_t)j };
|
|
|
|
D_PostEvent(&evt);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event_t evt;
|
|
|
|
evt.type = EV_GUI_Event;
|
|
|
|
evt.subtype = uint8_t((ev->button.state == SDL_PRESSED) ? EV_GUI_LButtonDown : EV_GUI_LButtonUp);
|
|
|
|
|
|
|
|
SDL_Keymod kmod = SDL_GetModState();
|
|
|
|
evt.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
|
|
|
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
|
|
|
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
|
|
|
|
|
|
|
D_PostEvent(&evt);
|
|
|
|
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
2015-04-28 21:30:42 +00:00
|
|
|
}
|
2019-08-14 15:28:59 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
case SDL_JOYAXISMOTION:
|
2019-08-12 15:23:15 +00:00
|
|
|
#if SDL_MAJOR_VERSION >= 2
|
|
|
|
if (joystick.isGameController)
|
|
|
|
break;
|
|
|
|
fallthrough__;
|
|
|
|
case SDL_CONTROLLERAXISMOTION:
|
|
|
|
#endif
|
2018-04-12 21:02:31 +00:00
|
|
|
if (appactive && ev->jaxis.axis < joystick.numAxes)
|
2010-10-21 02:20:40 +00:00
|
|
|
{
|
2019-08-12 15:23:07 +00:00
|
|
|
joystick.pAxis[ev->jaxis.axis] = ev->jaxis.value;
|
|
|
|
int32_t const scaledValue = ev->jaxis.value * 10000 / 32767;
|
|
|
|
if ((scaledValue < joydead[ev->jaxis.axis]) &&
|
|
|
|
(scaledValue > -joydead[ev->jaxis.axis]))
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.pAxis[ev->jaxis.axis] = 0;
|
2019-08-12 15:23:07 +00:00
|
|
|
else if (scaledValue >= joysatur[ev->jaxis.axis])
|
|
|
|
joystick.pAxis[ev->jaxis.axis] = 32767;
|
|
|
|
else if (scaledValue <= -joysatur[ev->jaxis.axis])
|
|
|
|
joystick.pAxis[ev->jaxis.axis] = -32767;
|
2010-10-21 02:20:40 +00:00
|
|
|
else
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.pAxis[ev->jaxis.axis] = joystick.pAxis[ev->jaxis.axis] * 10000 / joysatur[ev->jaxis.axis];
|
2010-10-21 02:20:40 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
case SDL_JOYHATMOTION:
|
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
int32_t hatvals[16] = {
|
|
|
|
-1, // centre
|
|
|
|
0, // up 1
|
|
|
|
9000, // right 2
|
|
|
|
4500, // up+right 3
|
|
|
|
18000, // down 4
|
|
|
|
-1, // down+up!! 5
|
|
|
|
13500, // down+right 6
|
|
|
|
-1, // down+right+up!! 7
|
|
|
|
27000, // left 8
|
|
|
|
27500, // left+up 9
|
|
|
|
-1, // left+right!! 10
|
|
|
|
-1, // left+right+up!! 11
|
|
|
|
22500, // left+down 12
|
|
|
|
-1, // left+down+up!! 13
|
|
|
|
-1, // left+down+right!! 14
|
|
|
|
-1, // left+down+right+up!! 15
|
2007-12-12 17:42:14 +00:00
|
|
|
};
|
2018-04-12 21:02:31 +00:00
|
|
|
if (appactive && ev->jhat.hat < joystick.numHats)
|
|
|
|
joystick.pHat[ev->jhat.hat] = hatvals[ev->jhat.value & 15];
|
2006-11-13 23:12:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
|
case SDL_JOYBUTTONUP:
|
2019-08-12 15:23:15 +00:00
|
|
|
#if SDL_MAJOR_VERSION >= 2
|
|
|
|
if (joystick.isGameController)
|
|
|
|
break;
|
|
|
|
fallthrough__;
|
|
|
|
case SDL_CONTROLLERBUTTONDOWN:
|
|
|
|
case SDL_CONTROLLERBUTTONUP:
|
|
|
|
#endif
|
2018-04-12 21:02:31 +00:00
|
|
|
if (appactive && ev->jbutton.button < joystick.numButtons)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
if (ev->jbutton.state == SDL_PRESSED)
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.bits |= 1 << ev->jbutton.button;
|
2006-04-24 19:04:22 +00:00
|
|
|
else
|
2018-04-12 21:02:31 +00:00
|
|
|
joystick.bits &= ~(1 << ev->jbutton.button);
|
2014-12-27 18:36:43 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
2019-11-25 22:21:51 +00:00
|
|
|
throw ExitEvent(0); // completely bypass the hackery in the games to block Alt-F4.
|
2014-11-22 12:33:47 +00:00
|
|
|
return -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-18 05:14:17 +00:00
|
|
|
|
2019-11-03 23:55:49 +00:00
|
|
|
// So this is how the engine handles text input?
|
|
|
|
// Argh. This is just gross.
|
|
|
|
int scancodetoasciihack(SDL_Event &ev)
|
|
|
|
{
|
2019-11-04 16:58:18 +00:00
|
|
|
int sc = ev.key.keysym.scancode;
|
2019-11-03 23:55:49 +00:00
|
|
|
SDL_Keycode keyvalue = ev.key.keysym.sym;
|
2019-11-04 16:58:18 +00:00
|
|
|
int code = keytranslation[sc];
|
2019-11-03 23:55:49 +00:00
|
|
|
// Modifiers that have to be held down to be effective
|
|
|
|
// (excludes KMOD_NUM, for example).
|
|
|
|
static const int MODIFIERS =
|
|
|
|
KMOD_LSHIFT|KMOD_RSHIFT|KMOD_LCTRL|KMOD_RCTRL|
|
|
|
|
KMOD_LALT|KMOD_RALT|KMOD_LGUI|KMOD_RGUI;
|
|
|
|
|
|
|
|
// XXX: see osd.c, OSD_HandleChar(), there are more...
|
|
|
|
if (
|
|
|
|
(sc == SDL_SCANCODE_RETURN || sc == SDL_SCANCODE_KP_ENTER ||
|
|
|
|
sc == SDL_SCANCODE_ESCAPE ||
|
|
|
|
sc == SDL_SCANCODE_BACKSPACE ||
|
|
|
|
sc == SDL_SCANCODE_TAB ||
|
|
|
|
(((ev.key.keysym.mod) & MODIFIERS) == KMOD_LCTRL &&
|
|
|
|
(sc >= SDL_SCANCODE_A && sc <= SDL_SCANCODE_Z))))
|
|
|
|
{
|
|
|
|
char keyvalue;
|
|
|
|
switch (sc)
|
|
|
|
{
|
|
|
|
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_KP_ENTER: keyvalue = '\r'; break;
|
|
|
|
case SDL_SCANCODE_ESCAPE: keyvalue = 27; break;
|
|
|
|
case SDL_SCANCODE_BACKSPACE: keyvalue = '\b'; break;
|
|
|
|
case SDL_SCANCODE_TAB: keyvalue = '\t'; break;
|
|
|
|
default: keyvalue = sc - SDL_SCANCODE_A + 1; break; // Ctrl+A --> 1, etc.
|
|
|
|
}
|
|
|
|
}
|
2019-11-05 19:25:57 +00:00
|
|
|
else
|
2019-11-03 23:55:49 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Necessary for Duke 3D's method of entering cheats to work without showing IMEs.
|
|
|
|
SDL_TEXTINPUT is preferable overall, but with bitmap fonts it has no advantage.
|
|
|
|
*/
|
|
|
|
// Note that this is not how text input is supposed to be handled!
|
|
|
|
|
|
|
|
if ('a' <= keyvalue && keyvalue <= 'z')
|
|
|
|
{
|
|
|
|
if (!!(ev.key.keysym.mod & KMOD_SHIFT) ^ !!(ev.key.keysym.mod & KMOD_CAPS))
|
|
|
|
keyvalue -= 'a'-'A';
|
|
|
|
}
|
|
|
|
else if (ev.key.keysym.mod & KMOD_SHIFT)
|
|
|
|
{
|
|
|
|
keyvalue = g_keyAsciiTableShift[code];
|
|
|
|
}
|
|
|
|
else if (ev.key.keysym.mod & KMOD_NUM) // && !(ev.key.keysym.mod & KMOD_SHIFT)
|
|
|
|
{
|
|
|
|
switch (keyvalue)
|
|
|
|
{
|
|
|
|
case SDLK_KP_1: keyvalue = '1'; break;
|
|
|
|
case SDLK_KP_2: keyvalue = '2'; break;
|
|
|
|
case SDLK_KP_3: keyvalue = '3'; break;
|
|
|
|
case SDLK_KP_4: keyvalue = '4'; break;
|
|
|
|
case SDLK_KP_5: keyvalue = '5'; break;
|
|
|
|
case SDLK_KP_6: keyvalue = '6'; break;
|
|
|
|
case SDLK_KP_7: keyvalue = '7'; break;
|
|
|
|
case SDLK_KP_8: keyvalue = '8'; break;
|
|
|
|
case SDLK_KP_9: keyvalue = '9'; break;
|
|
|
|
case SDLK_KP_0: keyvalue = '0'; break;
|
|
|
|
case SDLK_KP_PERIOD: keyvalue = '.'; break;
|
|
|
|
case SDLK_KP_COMMA: keyvalue = ','; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (keyvalue)
|
|
|
|
{
|
|
|
|
case SDLK_KP_DIVIDE: keyvalue = '/'; break;
|
|
|
|
case SDLK_KP_MULTIPLY: keyvalue = '*'; break;
|
|
|
|
case SDLK_KP_MINUS: keyvalue = '-'; break;
|
|
|
|
case SDLK_KP_PLUS: keyvalue = '+'; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (keyvalue >= 0x80) keyvalue = 0; // Sadly ASCII only...
|
|
|
|
return keyvalue;
|
|
|
|
}
|
|
|
|
|
2014-11-28 08:12:40 +00:00
|
|
|
int32_t handleevents_pollsdl(void);
|
2014-11-22 12:33:47 +00:00
|
|
|
#if SDL_MAJOR_VERSION != 1
|
|
|
|
// SDL 2.0 specific event handling
|
|
|
|
int32_t handleevents_pollsdl(void)
|
|
|
|
{
|
|
|
|
int32_t code, rv=0, j;
|
|
|
|
SDL_Event ev;
|
2006-08-07 06:18:57 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
while (SDL_PollEvent(&ev))
|
|
|
|
{
|
2019-11-09 21:22:51 +00:00
|
|
|
if ((GUICapture & 10) == 2)
|
2019-11-07 19:31:16 +00:00
|
|
|
{
|
|
|
|
if (ImGui_ImplSDL2_ProcessEvent(&ev)) return 0;
|
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
switch (ev.type)
|
|
|
|
{
|
|
|
|
case SDL_TEXTINPUT:
|
2019-11-07 19:31:16 +00:00
|
|
|
{
|
|
|
|
j = 0;
|
|
|
|
const uint8_t* text = (uint8_t*)ev.text.text;
|
|
|
|
while ((j = GetCharFromString(text)))
|
|
|
|
{
|
|
|
|
code = ev.text.text[j];
|
2019-11-05 19:25:57 +00:00
|
|
|
// Fixme: Send an EV_GUI_Event instead and properly deal with Unicode.
|
2019-12-05 20:39:02 +00:00
|
|
|
if ((GUICapture & 1) && menuactive != MENU_WaitKey)
|
2019-11-07 19:31:16 +00:00
|
|
|
{
|
|
|
|
event_t ev = { EV_GUI_Event, EV_GUI_Char, int16_t(j), !!(SDL_GetModState() & KMOD_ALT) };
|
|
|
|
D_PostEvent(&ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
2015-08-09 09:58:45 +00:00
|
|
|
{
|
2019-12-05 20:39:02 +00:00
|
|
|
if ((GUICapture & 1) && menuactive != MENU_WaitKey)
|
2019-11-07 19:31:16 +00:00
|
|
|
{
|
2019-11-09 22:58:26 +00:00
|
|
|
event_t event = {};
|
2019-11-07 19:31:16 +00:00
|
|
|
event.type = EV_GUI_Event;
|
|
|
|
event.subtype = ev.type == SDL_KEYDOWN ? EV_GUI_KeyDown : EV_GUI_KeyUp;
|
|
|
|
SDL_Keymod kmod = SDL_GetModState();
|
|
|
|
event.data3 = ((kmod & KMOD_SHIFT) ? GKM_SHIFT : 0) |
|
|
|
|
((kmod & KMOD_CTRL) ? GKM_CTRL : 0) |
|
|
|
|
((kmod & KMOD_ALT) ? GKM_ALT : 0);
|
|
|
|
|
|
|
|
if (event.subtype == EV_GUI_KeyDown && ev.key.repeat)
|
|
|
|
{
|
|
|
|
event.subtype = EV_GUI_KeyRepeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev.key.keysym.sym)
|
|
|
|
{
|
|
|
|
case SDLK_KP_ENTER: event.data1 = GK_RETURN; break;
|
|
|
|
case SDLK_PAGEUP: event.data1 = GK_PGUP; break;
|
|
|
|
case SDLK_PAGEDOWN: event.data1 = GK_PGDN; break;
|
|
|
|
case SDLK_END: event.data1 = GK_END; break;
|
|
|
|
case SDLK_HOME: event.data1 = GK_HOME; break;
|
|
|
|
case SDLK_LEFT: event.data1 = GK_LEFT; break;
|
|
|
|
case SDLK_RIGHT: event.data1 = GK_RIGHT; break;
|
|
|
|
case SDLK_UP: event.data1 = GK_UP; break;
|
|
|
|
case SDLK_DOWN: event.data1 = GK_DOWN; break;
|
|
|
|
case SDLK_DELETE: event.data1 = GK_DEL; break;
|
|
|
|
case SDLK_ESCAPE: event.data1 = GK_ESCAPE; break;
|
|
|
|
case SDLK_F1: event.data1 = GK_F1; break;
|
|
|
|
case SDLK_F2: event.data1 = GK_F2; break;
|
|
|
|
case SDLK_F3: event.data1 = GK_F3; break;
|
|
|
|
case SDLK_F4: event.data1 = GK_F4; break;
|
|
|
|
case SDLK_F5: event.data1 = GK_F5; break;
|
|
|
|
case SDLK_F6: event.data1 = GK_F6; break;
|
|
|
|
case SDLK_F7: event.data1 = GK_F7; break;
|
|
|
|
case SDLK_F8: event.data1 = GK_F8; break;
|
|
|
|
case SDLK_F9: event.data1 = GK_F9; break;
|
|
|
|
case SDLK_F10: event.data1 = GK_F10; break;
|
|
|
|
case SDLK_F11: event.data1 = GK_F11; break;
|
|
|
|
case SDLK_F12: event.data1 = GK_F12; break;
|
|
|
|
default:
|
|
|
|
if (ev.key.keysym.sym < 256)
|
|
|
|
{
|
|
|
|
event.data1 = ev.key.keysym.sym;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (event.data1 < 128)
|
|
|
|
{
|
|
|
|
event.data1 = toupper(event.data1);
|
|
|
|
D_PostEvent(&event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto const& sc = ev.key.keysym.scancode;
|
|
|
|
code = keytranslation[sc];
|
2014-11-22 12:33:47 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
// The pause key generates a release event right after
|
|
|
|
// the pressing one. As a result, it gets unseen
|
|
|
|
// by the game most of the time.
|
|
|
|
if (code == 0x59 && ev.type == SDL_KEYUP) // pause
|
|
|
|
break;
|
2019-11-03 23:55:49 +00:00
|
|
|
|
2019-11-07 19:31:16 +00:00
|
|
|
int keyvalue = ev.type == SDL_KEYDOWN ? scancodetoasciihack(ev) : 0;
|
|
|
|
event_t evt = { (uint8_t)(ev.type == SDL_KEYUP ? EV_KeyUp : EV_KeyDown), 0, (int16_t)code, (int16_t)keyvalue };
|
|
|
|
D_PostEvent(&evt);
|
2019-11-03 23:55:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
break;
|
2015-08-09 09:58:45 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
// initprintf("wheel y %d\n",ev.wheel.y);
|
2019-11-04 00:01:54 +00:00
|
|
|
|
|
|
|
// This never sends keyup events. For the current code that should suffice
|
2014-11-22 12:33:47 +00:00
|
|
|
if (ev.wheel.y > 0)
|
|
|
|
{
|
2019-11-04 19:29:07 +00:00
|
|
|
event_t evt = { EV_KeyDown, 0, (int16_t)KEY_MWHEELUP };
|
|
|
|
D_PostEvent(&evt);
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
|
|
|
if (ev.wheel.y < 0)
|
|
|
|
{
|
2019-11-04 19:29:07 +00:00
|
|
|
event_t evt = { EV_KeyDown, 0, (int16_t)KEY_MWHEELDOWN };
|
|
|
|
D_PostEvent(&evt);
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
switch (ev.window.event)
|
|
|
|
{
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
appactive = (ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED);
|
2018-04-12 21:02:31 +00:00
|
|
|
if (g_mouseGrabbed && g_mouseEnabled)
|
2014-11-22 12:33:47 +00:00
|
|
|
grabmouse_low(appactive);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_WINDOWEVENT_MOVED:
|
2019-08-29 20:06:31 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
if (windowpos)
|
|
|
|
{
|
|
|
|
windowx = ev.window.data1;
|
|
|
|
windowy = ev.window.data2;
|
|
|
|
}
|
2019-08-29 20:06:31 +00:00
|
|
|
|
|
|
|
r_displayindex = SDL_GetWindowDisplayIndex(sdl_window);
|
|
|
|
modeschecked = 0;
|
|
|
|
videoGetModes();
|
2014-11-22 12:33:47 +00:00
|
|
|
break;
|
2019-08-29 20:06:31 +00:00
|
|
|
}
|
2014-11-22 12:34:46 +00:00
|
|
|
case SDL_WINDOWEVENT_ENTER:
|
2018-04-12 21:02:31 +00:00
|
|
|
g_mouseInsideWindow = 1;
|
2014-11-22 12:34:46 +00:00
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_LEAVE:
|
2018-04-12 21:02:31 +00:00
|
|
|
g_mouseInsideWindow = 0;
|
2014-11-22 12:34:46 +00:00
|
|
|
break;
|
2014-11-22 12:33:47 +00:00
|
|
|
}
|
2019-08-29 20:06:31 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
default:
|
|
|
|
rv = handleevents_sdlcommon(&ev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 14:15:14 +00:00
|
|
|
MouseRead();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return rv;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-11-22 12:33:47 +00:00
|
|
|
int32_t handleevents(void)
|
2010-05-18 05:14:17 +00:00
|
|
|
{
|
2014-11-22 12:33:47 +00:00
|
|
|
int32_t rv;
|
2019-11-04 00:07:34 +00:00
|
|
|
|
|
|
|
if (inputchecked && g_mouseEnabled)
|
|
|
|
{
|
|
|
|
// This is a horrible crutch
|
|
|
|
if (inputState.mouseReadButtons() & WHEELUP_MOUSE)
|
|
|
|
{
|
|
|
|
event_t ev = { EV_KeyUp, 0, (int16_t)KEY_MWHEELUP };
|
|
|
|
D_PostEvent(&ev);
|
|
|
|
}
|
|
|
|
if (inputState.mouseReadButtons() & WHEELDOWN_MOUSE)
|
|
|
|
{
|
|
|
|
event_t ev = { EV_KeyUp, 0, (int16_t)KEY_MWHEELDOWN };
|
|
|
|
D_PostEvent(&ev);
|
|
|
|
}
|
2010-05-18 05:14:17 +00:00
|
|
|
}
|
2014-11-22 12:33:47 +00:00
|
|
|
|
|
|
|
rv = handleevents_pollsdl();
|
|
|
|
|
|
|
|
inputchecked = 0;
|
2019-10-19 23:43:35 +00:00
|
|
|
timerUpdateClock();
|
2014-11-22 12:33:47 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2019-09-22 21:15:46 +00:00
|
|
|
|
2019-11-08 22:02:52 +00:00
|
|
|
void I_SetMouseCapture()
|
|
|
|
{
|
|
|
|
// Clear out any mouse movement.
|
2019-12-05 22:49:32 +00:00
|
|
|
SDL_CaptureMouse(SDL_TRUE);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void I_ReleaseMouseCapture()
|
|
|
|
{
|
2019-12-05 22:49:32 +00:00
|
|
|
SDL_CaptureMouse(SDL_FALSE);
|
2019-11-08 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2019-09-22 21:15:46 +00:00
|
|
|
auto vsnprintfptr = vsnprintf; // This is an inline in Visual Studio but we need an address for it to satisfy the MinGW compiled libraries.
|
2019-11-20 19:07:33 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// debugprintf() -- sends a debug string to the debugger
|
|
|
|
//
|
|
|
|
void debugprintf(const char* f, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
if (!IsDebuggerPresent()) return;
|
|
|
|
|
|
|
|
va_start(va, f);
|
|
|
|
Bvsnprintf(buf, 1024, f, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
OutputDebugStringA(buf);
|
|
|
|
}
|
2019-11-23 22:05:24 +00:00
|
|
|
|