2006-04-13 20:47:06 +00:00
|
|
|
// SDL interface layer
|
|
|
|
// for the Build Engine
|
2012-03-12 04:47:04 +00:00
|
|
|
// by Jonathon Fowler (jf@jonof.id.au)
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
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
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_LIMIT_MACROS
|
2006-04-13 20:47:06 +00:00
|
|
|
#include <stdlib.h>
|
2012-09-02 14:05:23 +00:00
|
|
|
#include <math.h> // pow
|
2009-08-03 22:15:53 +00:00
|
|
|
#include <signal.h>
|
2008-04-25 01:46:19 +00:00
|
|
|
#include "sdl_inc.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "sdlayer.h"
|
|
|
|
#include "cache1d.h"
|
2011-12-28 20:34:57 +00:00
|
|
|
//#include "pragmas.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
#include "a.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "osd.h"
|
|
|
|
|
2010-05-18 05:14:17 +00:00
|
|
|
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2
|
|
|
|
// for SDL_WaitEventTimeout defined below
|
|
|
|
#include <SDL/SDL_events.h>
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
# include "glbuild.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#if defined _WIN32
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
# include <windows.h>
|
|
|
|
# include "winbits.h"
|
|
|
|
#elif defined __APPLE__
|
2006-04-13 20:47:06 +00:00
|
|
|
# include "osxbits.h"
|
2012-08-02 10:52:41 +00:00
|
|
|
# include <mach/mach.h>
|
|
|
|
# include <mach/mach_time.h>
|
2006-04-13 20:47:06 +00:00
|
|
|
#elif defined HAVE_GTK2
|
|
|
|
# include "gtkbits.h"
|
2013-02-18 08:50:42 +00:00
|
|
|
#elif defined GEKKO
|
|
|
|
# define HW_RVL
|
|
|
|
# include <ogc/lwp.h>
|
|
|
|
# include <ogc/lwp_watchdog.h>
|
2011-07-20 23:04:20 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-04 17:28:13 +00:00
|
|
|
#if !defined _WIN32 && !defined HAVE_GTK2 && !defined __APPLE__
|
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; }
|
2006-04-13 20:47:06 +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==2
|
|
|
|
# define SDL_GRAB_OFF SDL_FALSE
|
|
|
|
# define SDL_GRAB_ON SDL_TRUE
|
|
|
|
# define SDL_WM_GrabInput(yn) SDL_SetWindowGrab(sdl_window, yn)
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
#define MWHEELTICKS 10
|
2009-01-09 09:29:17 +00:00
|
|
|
static uint32_t mwheelup, mwheeldown;
|
2006-08-07 06:18:57 +00:00
|
|
|
|
2013-03-21 10:19:25 +00:00
|
|
|
extern int32_t app_main(int32_t argc, const char **argv);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
char quitevent=0, appactive=1, novideo=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// video
|
|
|
|
static SDL_Surface *sdl_surface;
|
2013-10-07 10:03:37 +00:00
|
|
|
static SDL_Surface *sdl_buffersurface=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
|
|
|
#if SDL_MAJOR_VERSION==2
|
2013-10-07 10:04:02 +00:00
|
|
|
static SDL_Texture *sdl_texture;
|
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
|
|
|
static SDL_Palette *sdl_palptr;
|
|
|
|
static SDL_Window *sdl_window;
|
|
|
|
static SDL_Renderer *sdl_renderer;
|
2013-10-06 07:49:53 +00:00
|
|
|
static SDL_GLContext sdl_context;
|
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
|
2011-09-15 17:03:50 +00:00
|
|
|
int32_t xres=-1, yres=-1, bpp=0, fullscreen=0, bytesperline;
|
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;
|
|
|
|
char nofog=0;
|
2009-01-09 09:29:17 +00:00
|
|
|
static uint16_t sysgamma[3][256];
|
|
|
|
extern int32_t curbrightness, gammabrightness;
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
// OpenGL stuff
|
2008-08-26 19:50:34 +00:00
|
|
|
char nogl=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t vsync=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-12-28 20:34:57 +00:00
|
|
|
// last gamma, contrast, brightness
|
|
|
|
static float lastvidgcb[3];
|
|
|
|
|
2011-11-25 09:50:07 +00:00
|
|
|
//#define KEY_PRINT_DEBUG
|
|
|
|
|
2013-10-06 07:50:16 +00:00
|
|
|
#include "sdlkeytrans.c"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//static SDL_Surface * loadtarga(const char *fn); // for loading the icon
|
2011-01-16 02:50:27 +00:00
|
|
|
static SDL_Surface *appicon = NULL;
|
|
|
|
static SDL_Surface *loadappicon(void);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
static mutex_t m_initprintf;
|
|
|
|
|
2010-10-21 02:20:40 +00:00
|
|
|
// Joystick dead and saturation zones
|
|
|
|
uint16_t *joydead, *joysatur;
|
|
|
|
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t wm_msgbox(char *name, 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);
|
|
|
|
vsprintf(buf,fmt,va);
|
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
2006-04-24 19:04:22 +00:00
|
|
|
return osx_msgbox(name, buf);
|
2006-04-13 20:47:06 +00:00
|
|
|
#elif defined HAVE_GTK2
|
2006-04-24 19:04:22 +00:00
|
|
|
if (gtkbuild_msgbox(name, buf) >= 0) return 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
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;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t wm_ynbox(char *name, 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
|
|
|
char c;
|
|
|
|
va_list va;
|
2008-03-26 03:53:54 +00:00
|
|
|
#if (!defined(__APPLE__) && defined(HAVE_GTK2))
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t r;
|
2008-03-26 03:53:54 +00:00
|
|
|
#endif
|
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);
|
|
|
|
vsprintf(buf,fmt,va);
|
|
|
|
va_end(va);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#if defined __APPLE__
|
2006-04-24 19:04:22 +00:00
|
|
|
return osx_ynbox(name, buf);
|
2006-04-13 20:47:06 +00:00
|
|
|
#elif defined HAVE_GTK2
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((r = gtkbuild_ynbox(name, buf)) >= 0) return r;
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
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');
|
|
|
|
if (c == 'Y' || c == 'y') return 1;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void wm_setapptitle(char *name)
|
|
|
|
{
|
2006-11-17 05:05:16 +00:00
|
|
|
if (name)
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(apptitle, name, sizeof(apptitle));
|
2006-04-13 20:47:06 +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 == 1
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_WM_SetCaption(apptitle, 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
|
|
|
#else
|
|
|
|
SDL_SetWindowTitle(sdl_window, apptitle);
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_settitle(apptitle);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// System
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t main(int32_t argc, char *argv[])
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t r;
|
2013-01-08 06:17:10 +00:00
|
|
|
#ifdef USE_OPENGL
|
2008-02-18 08:10:54 +00:00
|
|
|
char *argp;
|
2013-01-08 06:17:10 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
buildkeytranslationtable();
|
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (!CheckWinVersion())
|
|
|
|
{
|
|
|
|
MessageBox(0, "This application requires Windows XP or better to run.",
|
|
|
|
apptitle, MB_OK|MB_ICONSTOP);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
win_open();
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef HAVE_GTK2
|
2006-04-24 19:04:22 +00:00
|
|
|
gtkbuild_init(&argc, &argv);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_open();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-01-06 18:56:29 +00:00
|
|
|
maybe_redirect_outputs();
|
2008-02-18 08:10:54 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2008-02-18 08:10:54 +00:00
|
|
|
if ((argp = Bgetenv("BUILD_NOFOG")) != NULL)
|
|
|
|
nofog = Batol(argp);
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
baselayer_init();
|
2013-03-21 10:19:25 +00:00
|
|
|
r = app_main(argc, (const char **)argv);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_close();
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef HAVE_GTK2
|
2006-04-24 19:04:22 +00:00
|
|
|
gtkbuild_exit(r);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2012-11-25 04:26:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
win_close();
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return r;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2009-01-09 09:29:17 +00:00
|
|
|
void setvsync(int32_t sync)
|
2008-07-22 21:03:09 +00:00
|
|
|
{
|
2008-07-23 03:56:50 +00:00
|
|
|
if (vsync == sync) return;
|
2008-07-22 21:03:09 +00:00
|
|
|
vsync = sync;
|
|
|
|
resetvideomode();
|
|
|
|
if (setgamemode(fullscreen,xdim,ydim,bpp))
|
|
|
|
OSD_Printf("restartvid: Reset failed...\n");
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
static void attach_debugger_here(void) {}
|
2009-08-03 22:15:53 +00:00
|
|
|
|
2013-07-20 03:36:54 +00:00
|
|
|
|
2011-05-11 21:58:19 +00:00
|
|
|
/* XXX: libexecinfo could be used on systems without gnu libc. */
|
2013-07-20 03:36:54 +00:00
|
|
|
#if !defined _WIN32 && defined __GNUC__ && !defined __OpenBSD__ && !(defined __APPLE__ && defined __BIG_ENDIAN__) && !defined(GEKKO) && !defined(__ANDROID__) && !defined __OPENDINGUX__
|
2010-10-17 14:49:39 +00:00
|
|
|
# define PRINTSTACKONSEGV 1
|
|
|
|
# include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-03 22:15:53 +00:00
|
|
|
static void sighandler(int signum)
|
|
|
|
{
|
2010-05-18 05:14:17 +00:00
|
|
|
UNREFERENCED_PARAMETER(signum);
|
2009-10-01 19:43:15 +00:00
|
|
|
// if (signum==SIGSEGV)
|
2009-08-03 22:15:53 +00:00
|
|
|
{
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
2010-10-17 14:49:39 +00:00
|
|
|
#if PRINTSTACKONSEGV
|
|
|
|
{
|
|
|
|
void *addr[32];
|
|
|
|
int32_t errfd = fileno(stderr);
|
|
|
|
int32_t n=backtrace(addr, sizeof(addr)/sizeof(addr[0]));
|
|
|
|
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);
|
|
|
|
#endif
|
2009-08-03 22:15:53 +00:00
|
|
|
attach_debugger_here();
|
2012-11-25 04:26:37 +00:00
|
|
|
app_crashhandler();
|
2009-08-03 22:15:53 +00:00
|
|
|
uninitsystem();
|
2010-10-17 14:49:39 +00:00
|
|
|
exit(8);
|
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
|
|
|
{
|
2008-07-10 02:45:24 +00:00
|
|
|
/*
|
2008-07-20 00:39:06 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2006-04-24 19:04:22 +00:00
|
|
|
const SDL_VideoInfo *vid;
|
2008-07-20 00:39:06 +00:00
|
|
|
#endif
|
2008-07-10 02:45:24 +00:00
|
|
|
*/
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_version compiled;
|
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
|
|
|
|
const SDL_version *linked = SDL_Linked_Version();
|
|
|
|
#else
|
|
|
|
SDL_version linked_;
|
|
|
|
const SDL_version *linked = &linked_;
|
|
|
|
SDL_GetVersion(&linked_);
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_VERSION(&compiled);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_init(&m_initprintf);
|
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
win_init();
|
|
|
|
#endif
|
|
|
|
|
2008-02-24 00:46:57 +00:00
|
|
|
initprintf("Initializing SDL system interface "
|
2008-04-25 01:46:19 +00:00
|
|
|
"(compiled against SDL version %d.%d.%d, found version %d.%d.%d)\n",
|
|
|
|
compiled.major, compiled.minor, compiled.patch,
|
|
|
|
linked->major, linked->minor, linked->patch);
|
|
|
|
|
|
|
|
if (SDL_VERSIONNUM(linked->major,linked->minor,linked->patch) < SDL_REQUIREDVERSION)
|
2008-05-10 01:29:37 +00:00
|
|
|
{
|
|
|
|
/*reject running under SDL versions older than what is stated in sdl_inc.h */
|
2008-04-25 01:46:19 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (SDL_Init(SDL_INIT_VIDEO //| SDL_INIT_TIMER
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef NOSDLPARACHUTE
|
2006-04-24 19:04:22 +00:00
|
|
|
| SDL_INIT_NOPARACHUTE
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
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());
|
|
|
|
/* if (SDL_Init(0))
|
|
|
|
{
|
|
|
|
initprintf("Initialization failed! (%s)\n", SDL_GetError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*/
|
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
|
|
|
|
2009-08-03 22:15:53 +00:00
|
|
|
signal(SIGSEGV, sighandler);
|
2011-12-09 19:11:31 +00:00
|
|
|
signal(SIGILL, sighandler); /* clang -fcatch-undefined-behavior uses an ill. insn */
|
2009-10-01 19:43:15 +00:00
|
|
|
signal(SIGABRT, sighandler);
|
|
|
|
signal(SIGFPE, sighandler);
|
2009-08-03 22:15:53 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2011-01-16 02:50:27 +00:00
|
|
|
if (!novideo && loadgldriver(getenv("BUILD_GLDRV")))
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("Failed loading OpenGL driver. GL modes will be unavailable.\n");
|
|
|
|
nogl = 1;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-15 00:17:30 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(__ANDROID__)
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2009-11-18 01:17:56 +00:00
|
|
|
//icon = loadtarga("icon.tga");
|
2011-01-16 02:50:27 +00:00
|
|
|
|
|
|
|
if (!novideo)
|
|
|
|
{
|
|
|
|
appicon = loadappicon();
|
|
|
|
if (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
|
|
|
{
|
|
|
|
#if SDL_MAJOR_VERSION==1
|
2011-01-16 02:50:27 +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
|
|
|
|
SDL_SetWindowIcon(sdl_window, appicon);
|
|
|
|
#endif
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
if (!novideo)
|
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
|
|
|
|
char drvname[32];
|
2011-01-16 02:50:27 +00:00
|
|
|
if (SDL_VideoDriverName(drvname, 32))
|
|
|
|
initprintf("Using \"%s\" video driver\n", drvname);
|
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
|
|
|
|
const char *drvname = SDL_GetVideoDriver(0);
|
|
|
|
if (drvname)
|
|
|
|
initprintf("Using \"%s\" video driver\n", drvname);
|
|
|
|
#endif
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-07-10 02:45:24 +00:00
|
|
|
/*
|
2006-04-24 19:04:22 +00:00
|
|
|
// dump a quick summary of the graphics hardware
|
2008-07-20 00:39:06 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2006-04-24 19:04:22 +00:00
|
|
|
vid = SDL_GetVideoInfo();
|
|
|
|
initprintf("Video device information:\n");
|
|
|
|
initprintf(" Can create hardware surfaces? %s\n", (vid->hw_available)?"Yes":"No");
|
|
|
|
initprintf(" Window manager available? %s\n", (vid->wm_available)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated hardware blits? %s\n", (vid->blit_hw)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated hardware colourkey blits? %s\n", (vid->blit_hw_CC)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated hardware alpha blits? %s\n", (vid->blit_hw_A)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated software blits? %s\n", (vid->blit_sw)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated software colourkey blits? %s\n", (vid->blit_sw_CC)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated software alpha blits? %s\n", (vid->blit_sw_A)?"Yes":"No");
|
|
|
|
initprintf(" Accelerated colour fills? %s\n", (vid->blit_fill)?"Yes":"No");
|
|
|
|
initprintf(" Total video memory: %dKB\n", vid->video_mem);
|
2008-07-20 00:39:06 +00:00
|
|
|
#endif
|
|
|
|
*/
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitsystem() -- uninit SDL systems
|
|
|
|
//
|
|
|
|
void uninitsystem(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
uninitinput();
|
|
|
|
uninittimer();
|
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
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
win_uninit();
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
unloadgldriver();
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// initprintf() -- prints a string to the intitialization window
|
|
|
|
//
|
|
|
|
void initprintf(const char *f, ...)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2010-06-27 10:08:58 +00:00
|
|
|
char buf[2048];
|
|
|
|
static char dabuf[2048];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
va_start(va, f);
|
2010-06-27 10:08:58 +00:00
|
|
|
Bvsnprintf(buf, sizeof(buf), f, va);
|
2006-04-24 19:04:22 +00:00
|
|
|
va_end(va);
|
2009-01-06 06:59:18 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
OSD_Printf("%s", buf);
|
|
|
|
// Bprintf("%s", buf);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_lock(&m_initprintf);
|
2009-01-06 06:59:18 +00:00
|
|
|
if (Bstrlen(dabuf) + Bstrlen(buf) > 1022)
|
|
|
|
{
|
|
|
|
startwin_puts(dabuf);
|
|
|
|
Bmemset(dabuf, 0, sizeof(dabuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
Bstrcat(dabuf,buf);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-06-13 21:06:45 +00:00
|
|
|
if (flushlogwindow || Bstrlen(dabuf) > 768)
|
2009-01-06 06:59:18 +00:00
|
|
|
{
|
|
|
|
startwin_puts(dabuf);
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifndef _WIN32
|
2009-01-06 06:59:18 +00:00
|
|
|
startwin_idle(NULL);
|
2012-11-24 09:13:29 +00:00
|
|
|
#endif
|
2009-01-06 06:59:18 +00:00
|
|
|
Bmemset(dabuf, 0, sizeof(dabuf));
|
|
|
|
}
|
2010-06-22 21:50:01 +00:00
|
|
|
mutex_unlock(&m_initprintf);
|
2009-01-06 06:59:18 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// debugprintf() -- prints a debug string to stderr
|
|
|
|
//
|
|
|
|
void debugprintf(const char *f, ...)
|
|
|
|
{
|
2011-07-20 23:04:20 +00:00
|
|
|
#if defined DEBUGGINGAIDS && !(defined __APPLE__ && defined __BIG_ENDIAN__)
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
va_start(va,f);
|
|
|
|
Bvfprintf(stderr, f, va);
|
|
|
|
va_end(va);
|
2008-03-26 04:11:26 +00:00
|
|
|
#else
|
|
|
|
UNREFERENCED_PARAMETER(f);
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
//
|
|
|
|
// initinput() -- init input system
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t initinput(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef __APPLE__
|
2006-04-24 19:04:22 +00:00
|
|
|
// force OS X to operate in >1 button mouse mode so that LMB isn't adulterated
|
|
|
|
if (!getenv("SDL_HAS3BUTTONMOUSE")) putenv("SDL_HAS3BUTTONMOUSE=1");
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2008-10-24 09:20:38 +00:00
|
|
|
if (!remapinit)
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<256; i++)
|
2008-10-24 09:20:38 +00:00
|
|
|
remap[i]=i;
|
|
|
|
remapinit=1;
|
2006-04-13 20:47:06 +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==1
|
2008-10-24 09:20:38 +00:00
|
|
|
if (SDL_EnableKeyRepeat(250, 30)) // doesn't do anything in 1.3
|
|
|
|
initprintf("Error enabling keyboard repeat.\n");
|
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
|
|
|
SDL_EnableUNICODE(1); // let's hope this doesn't hit us too hard
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
inputdevices = 1|2; // keyboard (1) and mouse (2)
|
2011-04-07 01:16:29 +00:00
|
|
|
mousegrab = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
memset(key_names,0,sizeof(key_names));
|
2008-10-20 12:33:29 +00:00
|
|
|
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3)
|
2006-11-17 05:05:16 +00:00
|
|
|
for (i=0; i<SDLK_LAST; i++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!keytranslation[i]) continue;
|
2012-11-15 14:27:57 +00:00
|
|
|
Bstrncpyz(key_names[ keytranslation[i] ], SDL_GetKeyName((SDLKey)i), sizeof(key_names[i]));
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2008-10-20 12:33:29 +00:00
|
|
|
#else
|
|
|
|
for (i=0; i<SDL_NUM_SCANCODES; i++)
|
|
|
|
{
|
|
|
|
if (!keytranslation[i]) continue;
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(key_names[ keytranslation[i] ], SDL_GetKeyName(SDL_SCANCODE_TO_KEYCODE(i)), sizeof(key_names[i]));
|
2008-10-20 12:33:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (!SDL_InitSubSystem(SDL_INIT_JOYSTICK))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
i = SDL_NumJoysticks();
|
|
|
|
initprintf("%d joystick(s) found\n",i);
|
2013-10-06 07:49:53 +00:00
|
|
|
for (j=0; j<i; j++)
|
|
|
|
initprintf(" %d. %s\n", j+1,
|
|
|
|
#if SDL_MAJOR_VERSION==1
|
|
|
|
SDL_JoystickName(j)
|
|
|
|
#else
|
|
|
|
SDL_JoystickNameForIndex(j)
|
|
|
|
#endif
|
|
|
|
);
|
2006-04-24 19:04:22 +00:00
|
|
|
joydev = SDL_JoystickOpen(0);
|
2006-11-17 05:05:16 +00:00
|
|
|
if (joydev)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_JoystickEventState(SDL_ENABLE);
|
2006-09-02 02:34:29 +00:00
|
|
|
inputdevices |= 4;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
joynumaxes = SDL_JoystickNumAxes(joydev);
|
|
|
|
joynumbuttons = min(32,SDL_JoystickNumButtons(joydev));
|
|
|
|
joynumhats = SDL_JoystickNumHats(joydev);
|
|
|
|
initprintf("Joystick 1 has %d axes, %d buttons, and %d hat(s).\n",
|
|
|
|
joynumaxes,joynumbuttons,joynumhats);
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
joyaxis = (int32_t *)Bcalloc(joynumaxes, sizeof(int32_t));
|
2012-02-11 11:51:34 +00:00
|
|
|
if (joynumhats)
|
|
|
|
joyhat = (int32_t *)Bcalloc(joynumhats, sizeof(int32_t));
|
2010-10-21 02:20:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < joynumhats; i++)
|
2011-01-16 02:50:27 +00:00
|
|
|
joyhat[i] = -1; // centre
|
2010-10-21 02:20:40 +00:00
|
|
|
|
|
|
|
joydead = (uint16_t *)Bcalloc(joynumaxes, sizeof(uint16_t));
|
|
|
|
joysatur = (uint16_t *)Bcalloc(joynumaxes, sizeof(uint16_t));
|
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)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
uninitmouse();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-05-01 12:38:43 +00:00
|
|
|
#ifndef GEKKO
|
2009-01-09 09:29:17 +00:00
|
|
|
const char *getjoyname(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)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
case 0: // axis
|
|
|
|
if ((unsigned)num > (unsigned)joynumaxes) return NULL;
|
2009-02-02 01:49:14 +00:00
|
|
|
Bsprintf(tmp,"Axis %d",num);
|
2009-01-09 09:29:17 +00:00
|
|
|
return (char *)tmp;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
case 1: // button
|
|
|
|
if ((unsigned)num > (unsigned)joynumbuttons) return NULL;
|
2009-02-02 01:49:14 +00:00
|
|
|
Bsprintf(tmp,"Button %d",num);
|
2009-01-09 09:29:17 +00:00
|
|
|
return (char *)tmp;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
case 2: // hat
|
|
|
|
if ((unsigned)num > (unsigned)joynumhats) return NULL;
|
2009-02-02 01:49:14 +00:00
|
|
|
Bsprintf(tmp,"Hat %d",num);
|
2009-01-09 09:29:17 +00:00
|
|
|
return (char *)tmp;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2012-05-01 12:38:43 +00:00
|
|
|
#else
|
|
|
|
static const char *joynames[3][15] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"Left Stick X",
|
|
|
|
"Left Stick Y",
|
|
|
|
"Right Stick X",
|
|
|
|
"Right Stick Y",
|
2012-06-03 16:11:22 +00:00
|
|
|
"Axis 5",
|
|
|
|
"Axis 6",
|
|
|
|
"Axis 7",
|
|
|
|
"Axis 8",
|
|
|
|
"Axis 9",
|
|
|
|
"Axis 10",
|
|
|
|
"Axis 11",
|
|
|
|
"Axis 12",
|
|
|
|
"Axis 13",
|
|
|
|
"Axis 14",
|
|
|
|
"Axis 15",
|
2012-05-01 12:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"Button A",
|
|
|
|
"Button B",
|
|
|
|
"Button 1",
|
|
|
|
"Button 2",
|
|
|
|
"Button -",
|
|
|
|
"Button +",
|
2012-06-03 16:11:22 +00:00
|
|
|
"Button HOME",
|
2012-05-01 12:38:43 +00:00
|
|
|
"Button Z",
|
|
|
|
"Button C",
|
|
|
|
"Button X",
|
|
|
|
"Button Y",
|
|
|
|
"Trigger L",
|
|
|
|
"Trigger R",
|
2012-06-03 16:11:22 +00:00
|
|
|
"Trigger ZL",
|
|
|
|
"Trigger ZR",
|
2012-05-01 12:38:43 +00:00
|
|
|
},
|
|
|
|
{
|
2012-06-03 16:11:22 +00:00
|
|
|
"D-Pad Up",
|
|
|
|
"D-Pad Right",
|
|
|
|
"D-Pad Down",
|
|
|
|
"D-Pad Left",
|
|
|
|
"Hat 5",
|
|
|
|
"Hat 6",
|
|
|
|
"Hat 7",
|
|
|
|
"Hat 8",
|
|
|
|
"Hat 9",
|
|
|
|
"Hat 10",
|
|
|
|
"Hat 11",
|
|
|
|
"Hat 12",
|
|
|
|
"Hat 13",
|
|
|
|
"Hat 14",
|
|
|
|
"Hat 15",
|
2012-05-01 12:38:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
const char *getjoyname(int32_t what, int32_t num)
|
|
|
|
{
|
|
|
|
switch (what)
|
|
|
|
{
|
|
|
|
case 0: // axis
|
|
|
|
if ((unsigned)num > (unsigned)joynumaxes) return NULL;
|
|
|
|
return joynames[0][num];
|
|
|
|
|
|
|
|
case 1: // button
|
|
|
|
if ((unsigned)num > (unsigned)joynumbuttons) return NULL;
|
|
|
|
return joynames[1][num];
|
|
|
|
|
|
|
|
case 2: // hat
|
|
|
|
if ((unsigned)num > (unsigned)joynumhats) return NULL;
|
|
|
|
return joynames[2][num];
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// initmouse() -- init mouse input
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t initmouse(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
moustat=1;
|
2008-02-16 22:27:08 +00:00
|
|
|
grabmouse(1); // FIXME - SA
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninitmouse() -- uninit mouse input
|
|
|
|
//
|
|
|
|
void uninitmouse(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
grabmouse(0);
|
|
|
|
moustat=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// grabmouse() -- show/hide mouse cursor
|
|
|
|
//
|
|
|
|
void grabmouse(char a)
|
|
|
|
{
|
2006-11-17 05:05:16 +00:00
|
|
|
if (appactive && moustat)
|
|
|
|
{
|
2011-04-07 01:16:29 +00:00
|
|
|
if (a != mousegrab)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2012-11-25 04:26:37 +00:00
|
|
|
#if !defined __ANDROID__ && (!defined DEBUGGINGAIDS || defined _WIN32 || defined __APPLE__)
|
2013-10-06 07:49:53 +00:00
|
|
|
#if SDL_MAJOR_VERSION==1
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_GrabMode g;
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
g = SDL_WM_GrabInput(a ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
2011-04-07 01:16:29 +00:00
|
|
|
mousegrab = (g == SDL_GRAB_ON);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-04-07 01:16:29 +00:00
|
|
|
SDL_ShowCursor(mousegrab ? SDL_DISABLE : SDL_ENABLE);
|
2013-10-06 07:49:53 +00:00
|
|
|
#else
|
|
|
|
if (!SDL_SetRelativeMouseMode(a ? SDL_TRUE : SDL_FALSE))
|
|
|
|
mousegrab = a;
|
|
|
|
#endif
|
2006-11-19 01:28:51 +00:00
|
|
|
#else
|
2011-04-07 01:16:29 +00:00
|
|
|
mousegrab = a;
|
2006-11-19 01:28:51 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-07 01:16:29 +00:00
|
|
|
mousegrab = a;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
mousex = mousey = 0;
|
2012-05-01 12:38:14 +00:00
|
|
|
mouseabsx = mouseabsy = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// setjoydeadzone() -- sets the dead and saturation zones for the joystick
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
void setjoydeadzone(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
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
void getjoydeadzone(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// releaseallbuttons()
|
|
|
|
//
|
|
|
|
void releaseallbuttons(void)
|
2006-11-17 05:05:16 +00:00
|
|
|
{}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
// All things Timer
|
|
|
|
// Ken did this
|
|
|
|
//
|
|
|
|
// ---------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
static Uint32 timerfreq=0;
|
|
|
|
static Uint32 timerlastsample=0;
|
2012-01-27 15:02:25 +00:00
|
|
|
int32_t timerticspersec=0;
|
2013-07-07 20:59:00 +00:00
|
|
|
static double msperu64tick = 0;
|
2006-11-17 05:05:16 +00:00
|
|
|
static void(*usertimercallback)(void) = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-06-22 21:39:57 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
2008-02-24 00:46:57 +00:00
|
|
|
// inittimer() -- initialize timer
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t inittimer(int32_t tickspersecond)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (timerfreq) return 0; // already installed
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-02-24 00:46:57 +00:00
|
|
|
// initprintf("Initializing timer\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
{
|
|
|
|
int32_t t = win_inittimer();
|
|
|
|
if (t < 0)
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
timerfreq = 1000;
|
|
|
|
timerticspersec = tickspersecond;
|
|
|
|
timerlastsample = SDL_GetTicks() * timerticspersec / timerfreq;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
usertimercallback = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-07-07 20:59:00 +00:00
|
|
|
msperu64tick = 1000.0 / (double)getu64tickspersec();
|
2012-06-22 21:39:57 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// uninittimer() -- shut down timer
|
|
|
|
//
|
|
|
|
void uninittimer(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!timerfreq) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
timerfreq=0;
|
2012-06-22 21:39:57 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
win_timerfreq=0;
|
|
|
|
#endif
|
|
|
|
|
2013-07-07 20:59:00 +00:00
|
|
|
msperu64tick = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// sampletimer() -- update totalclock
|
|
|
|
//
|
|
|
|
void sampletimer(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
Uint32 i;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t n;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!timerfreq) return;
|
|
|
|
i = SDL_GetTicks();
|
2009-01-09 09:29:17 +00:00
|
|
|
n = (int32_t)(i * timerticspersec / timerfreq) - timerlastsample;
|
2006-11-17 05:05:16 +00:00
|
|
|
if (n>0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
totalclock += n;
|
|
|
|
timerlastsample += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usertimercallback) for (; n>0; n--) usertimercallback();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// getticks() -- returns the sdl ticks count
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
uint32_t getticks(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
return (uint32_t)SDL_GetTicks();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 17:05:00 +00:00
|
|
|
// high-resolution timers for profiling
|
2013-07-07 20:59:00 +00:00
|
|
|
uint64_t getu64ticks(void)
|
2011-09-15 17:05:00 +00:00
|
|
|
{
|
2012-06-22 21:39:57 +00:00
|
|
|
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2
|
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
|
|
|
# if defined _WIN32
|
2013-07-07 20:59:00 +00:00
|
|
|
return win_getu64ticks();
|
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
|
|
|
# elif defined __APPLE__
|
|
|
|
return mach_absolute_time();
|
|
|
|
# elif _POSIX_TIMERS>0 && defined _POSIX_MONOTONIC_CLOCK
|
2012-06-22 21:39:57 +00:00
|
|
|
// This is SDL HG's SDL_GetPerformanceCounter() when clock_gettime() is
|
|
|
|
// available.
|
|
|
|
uint64_t ticks;
|
|
|
|
struct timespec now;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
|
ticks = now.tv_sec;
|
|
|
|
ticks *= 1000000000;
|
|
|
|
ticks += now.tv_nsec;
|
2013-02-18 08:50:42 +00:00
|
|
|
return ticks;
|
|
|
|
# elif defined GEKKO
|
|
|
|
return ticks_to_nanosecs(gettime());
|
2012-06-22 21:39:57 +00:00
|
|
|
# else
|
2012-08-02 10:52:41 +00:00
|
|
|
// Blar. This pragma is unsupported on earlier GCC versions.
|
|
|
|
// At least we'll get a warning and a reference to this line...
|
2013-07-07 20:59:00 +00:00
|
|
|
# pragma message "Using low-resolution (1ms) timer for getu64ticks. Profiling will work badly."
|
2011-09-15 17:05:00 +00:00
|
|
|
return SDL_GetTicks();
|
2012-06-22 21:39:57 +00:00
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
return SDL_GetPerformanceCounter();
|
|
|
|
#endif
|
2011-09-15 17:05:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-07 20:59:00 +00:00
|
|
|
uint64_t getu64tickspersec(void)
|
2011-09-15 17:05:00 +00:00
|
|
|
{
|
2012-06-22 21:39:57 +00:00
|
|
|
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2
|
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
|
|
|
# if defined _WIN32
|
2012-11-25 04:26:37 +00:00
|
|
|
return win_timerfreq;
|
2012-08-02 10:52:41 +00:00
|
|
|
# elif defined __APPLE__
|
|
|
|
static mach_timebase_info_data_t ti;
|
|
|
|
if (ti.denom == 0)
|
|
|
|
(void)mach_timebase_info(&ti); // ti.numer/ti.denom: nsec/(m_a_t() tick)
|
|
|
|
return (1000000000LL*ti.denom)/ti.numer;
|
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
|
|
|
# elif _POSIX_TIMERS>0 && defined _POSIX_MONOTONIC_CLOCK
|
|
|
|
return 1000000000;
|
2013-02-18 08:50:42 +00:00
|
|
|
# elif defined GEKKO
|
|
|
|
return TB_NSPERSEC;
|
2012-08-02 10:52:41 +00:00
|
|
|
# else
|
2011-09-15 17:05:00 +00:00
|
|
|
return 1000;
|
2012-08-02 10:52:41 +00:00
|
|
|
# endif
|
2011-09-15 17:05:00 +00:00
|
|
|
#else // SDL 1.3
|
2012-06-22 21:39:57 +00:00
|
|
|
return SDL_GetPerformanceFrequency();
|
|
|
|
#endif
|
2011-09-15 17:05:00 +00:00
|
|
|
}
|
|
|
|
|
2012-06-22 21:39:57 +00:00
|
|
|
// Returns the time since an unspecified starting time in milliseconds.
|
|
|
|
// (May be not monotonic for certain configurations.)
|
|
|
|
ATTRIBUTE((flatten))
|
2013-07-07 20:59:05 +00:00
|
|
|
double gethiticks(void)
|
2011-09-15 17:05:00 +00:00
|
|
|
{
|
2013-07-07 20:59:00 +00:00
|
|
|
return (double)getu64ticks() * msperu64tick;
|
2011-09-15 17:05:00 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// gettimerfreq() -- returns the number of ticks per second the timer is configured to generate
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t gettimerfreq(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return timerticspersec;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// installusertimercallback() -- set up a callback function to be called when the timer is fired
|
|
|
|
//
|
2006-11-17 05:05:16 +00:00
|
|
|
void(*installusertimercallback(void(*callback)(void)))(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-17 05:05:16 +00:00
|
|
|
void(*oldtimercallback)(void);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
oldtimercallback = usertimercallback;
|
|
|
|
usertimercallback = callback;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return oldtimercallback;
|
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
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t x;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-09-21 13:38:44 +00:00
|
|
|
const struct validmode_t *a = (const struct validmode_t *)a_;
|
|
|
|
const struct validmode_t *b = (const struct validmode_t *)b_;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
static char modeschecked=0;
|
|
|
|
void getvalidmodes(void)
|
|
|
|
{
|
2012-10-15 00:17:30 +00:00
|
|
|
int32_t i, j, maxx=0, maxy=0;
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t cdepths[] =
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
8,
|
2006-04-13 20:47:06 +00:00
|
|
|
#ifdef USE_OPENGL
|
2007-12-12 17:42:14 +00:00
|
|
|
16,24,32,
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2007-12-12 17:42:14 +00:00
|
|
|
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 SDL_MAJOR_VERSION==1
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_Rect **modes;
|
2011-03-05 07:17:00 +00:00
|
|
|
SDL_PixelFormat pf;
|
|
|
|
|
|
|
|
pf.palette = NULL;
|
|
|
|
pf.BitsPerPixel = 8;
|
|
|
|
pf.BytesPerPixel = 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
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
if (modeschecked || novideo) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
validmodecnt=0;
|
2008-07-10 02:45:24 +00:00
|
|
|
// initprintf("Detecting video modes:\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-08 23:02:38 +00:00
|
|
|
#define ADDMODE(x,y,c,f) do { \
|
|
|
|
if (validmodecnt<MAXVALIDMODES) { \
|
|
|
|
int32_t mn; \
|
|
|
|
for(mn=0;mn<validmodecnt;mn++) \
|
|
|
|
if (validmode[mn].xdim==x && validmode[mn].ydim==y && \
|
|
|
|
validmode[mn].bpp==c && validmode[mn].fs==f) break; \
|
|
|
|
if (mn==validmodecnt) { \
|
|
|
|
validmode[validmodecnt].xdim=x; \
|
|
|
|
validmode[validmodecnt].ydim=y; \
|
|
|
|
validmode[validmodecnt].bpp=c; \
|
|
|
|
validmode[validmodecnt].fs=f; \
|
|
|
|
validmodecnt++; \
|
|
|
|
/*initprintf(" - %dx%d %d-bit %s\n", x, y, c, (f&1)?"fullscreen":"windowed");*/ \
|
|
|
|
} \
|
2010-05-02 23:27:30 +00:00
|
|
|
} \
|
2011-03-08 23:02:38 +00:00
|
|
|
} while (0)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#define CHECK(w,h) if ((w < maxx) && (h < maxy))
|
|
|
|
|
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
|
|
|
// do fullscreen modes first
|
2006-11-17 05:05:16 +00:00
|
|
|
for (j=0; cdepths[j]; j++)
|
|
|
|
{
|
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
|
|
|
# ifdef USE_OPENGL
|
2006-07-01 01:40:18 +00:00
|
|
|
if (nogl && cdepths[j] > 8) continue;
|
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-24 19:04:22 +00:00
|
|
|
pf.BitsPerPixel = cdepths[j];
|
|
|
|
pf.BytesPerPixel = cdepths[j] >> 3;
|
|
|
|
|
2013-10-07 10:03:37 +00:00
|
|
|
// We convert paletted contents to non-paletted
|
|
|
|
modes = SDL_ListModes((cdepths[j] == 8) ? NULL : &pf, SURFACE_FLAGS | SDL_FULLSCREEN);
|
2008-10-24 09:20:38 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (modes == (SDL_Rect **)0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (cdepths[j] > 8) cdepths[j] = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (modes == (SDL_Rect **)-1)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
for (i=0; defaultres[i][0]; i++)
|
2011-03-08 23:02:38 +00:00
|
|
|
ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],1);
|
|
|
|
}
|
2006-11-17 05:05:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i=0; modes[i]; i++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((modes[i]->w > MAXXDIM) || (modes[i]->h > MAXYDIM)) continue;
|
|
|
|
|
2011-03-08 23:02:38 +00:00
|
|
|
ADDMODE(modes[i]->w, modes[i]->h, cdepths[j], 1);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if ((modes[i]->w > maxx) && (modes[i]->h > maxy))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
maxx = modes[i]->w;
|
|
|
|
maxy = modes[i]->h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 // SDL_MAJOR_VERSION==1
|
2006-11-17 05:05:16 +00:00
|
|
|
if (maxx == 0 && maxy == 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("No fullscreen modes available!\n");
|
|
|
|
maxx = MAXXDIM; maxy = MAXYDIM;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add windowed modes next
|
2006-11-17 05:05:16 +00:00
|
|
|
for (j=0; cdepths[j]; j++)
|
|
|
|
{
|
2006-07-01 01:40:18 +00:00
|
|
|
#ifdef USE_OPENGL
|
|
|
|
if (nogl && cdepths[j] > 8) continue;
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
if (cdepths[j] < 0) continue;
|
|
|
|
for (i=0; defaultres[i][0]; i++)
|
|
|
|
CHECK(defaultres[i][0],defaultres[i][1])
|
2011-03-08 23:02:38 +00:00
|
|
|
ADDMODE(defaultres[i][0],defaultres[i][1],cdepths[j],0);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#undef CHECK
|
|
|
|
#undef ADDMODE
|
|
|
|
|
2013-09-21 13:38:44 +00:00
|
|
|
qsort((void *)validmode, validmodecnt, sizeof(struct validmode_t), &sortmodes);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
modeschecked=1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// checkvideomode() -- makes sure the video mode passed is legal
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t checkvideomode(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
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
getvalidmodes();
|
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
|
|
|
|
if (*x < 320) *x = 320;
|
|
|
|
if (*y < 200) *y = 200;
|
|
|
|
if (*x > MAXXDIM) *x = MAXXDIM;
|
|
|
|
if (*y > MAXYDIM) *y = MAXYDIM;
|
2008-10-24 09:20:38 +00:00
|
|
|
// *x &= 0xfffffff8l;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
for (i=0; i<validmodecnt; i++)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (validmode[i].bpp != c) continue;
|
|
|
|
if (validmode[i].fs != fs) continue;
|
|
|
|
dx = klabs(validmode[i].xdim - *x);
|
|
|
|
dy = klabs(validmode[i].ydim - *y);
|
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;
|
|
|
|
}
|
2006-11-17 05:05:16 +00:00
|
|
|
if ((dx <= odx) && (dy <= ody))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
nearest = i;
|
|
|
|
odx = dx; ody = dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// no mode that will match (eg. if no fullscreen modes)
|
|
|
|
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
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return nearest; // JBF 20031206: Returns the mode number
|
2006-04-13 20:47:06 +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
|
|
|
static int32_t needpalupdate;
|
|
|
|
static SDL_Color sdlayer_pal[256];
|
|
|
|
|
|
|
|
#if SDL_MAJOR_VERSION==2
|
|
|
|
static void destroy_window_and_renderer()
|
|
|
|
{
|
2013-10-07 10:04:02 +00:00
|
|
|
if (sdl_buffersurface)
|
|
|
|
SDL_FreeSurface(sdl_buffersurface);
|
|
|
|
sdl_buffersurface = NULL;
|
|
|
|
if (sdl_surface)
|
|
|
|
SDL_FreeSurface(sdl_surface);
|
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
|
|
|
sdl_surface = NULL;
|
2013-10-07 10:04:02 +00:00
|
|
|
if (sdl_texture)
|
|
|
|
SDL_DestroyTexture(sdl_texture);
|
|
|
|
sdl_texture = NULL;
|
|
|
|
if (sdl_context)
|
|
|
|
SDL_GL_DeleteContext(sdl_context);
|
|
|
|
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
|
|
|
if (sdl_renderer)
|
|
|
|
SDL_DestroyRenderer(sdl_renderer);
|
|
|
|
sdl_renderer = NULL;
|
|
|
|
if (sdl_window)
|
|
|
|
SDL_DestroyWindow(sdl_window);
|
|
|
|
sdl_window = NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-06 07:49:53 +00:00
|
|
|
static int32_t create_window_and_renderer(int32_t x, int32_t y, int32_t c, int32_t fs, uint32_t flags)
|
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
|
|
|
{
|
|
|
|
sdl_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,
|
2013-10-06 07:49:53 +00:00
|
|
|
x,y, ((fs&1)?SDL_WINDOW_FULLSCREEN:0) | (c > 8 ? SDL_WINDOW_OPENGL : 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 (!sdl_window)
|
|
|
|
{
|
|
|
|
initprintf("Unable to set video mode: SDL_CreateWindow failed: %s\n",
|
|
|
|
SDL_GetError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdl_renderer = SDL_CreateRenderer(sdl_window, -1, flags);
|
|
|
|
if (!sdl_renderer)
|
|
|
|
{
|
|
|
|
initprintf("Unable to set video mode: SDL_CreateRenderer failed: %s\n",
|
|
|
|
SDL_GetError());
|
2013-10-07 10:04:02 +00:00
|
|
|
destroy_window_and_renderer();
|
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-06 07:49:53 +00:00
|
|
|
if (c > 8)
|
2013-10-07 10:04:02 +00:00
|
|
|
{
|
2013-10-06 07:49:53 +00:00
|
|
|
sdl_context = SDL_GL_CreateContext(sdl_window);
|
2013-10-07 10:04:02 +00:00
|
|
|
if (!sdl_context)
|
|
|
|
{
|
|
|
|
initprintf("Unable to set video mode: SDL_GL_CreateContext failed: %s\n",
|
|
|
|
SDL_GetError());
|
|
|
|
destroy_window_and_renderer();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, x, y);
|
|
|
|
if (!sdl_texture)
|
|
|
|
{
|
|
|
|
initprintf("Unable to set video mode: SDL_CreateTexture failed: %s\n",
|
|
|
|
SDL_GetError());
|
|
|
|
destroy_window_and_renderer();
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-06 07:49:53 +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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// setvideomode() -- set SDL video mode
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t regrab = 0;
|
2011-05-18 22:44:09 +00:00
|
|
|
#ifdef USE_OPENGL
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t warnonce = 0;
|
2012-01-12 20:49:15 +00:00
|
|
|
# if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3)
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t ovsync = 1;
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2011-05-18 22:44:09 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((fs == fullscreen) && (x == xres) && (y == yres) && (c == bpp) &&
|
2006-11-17 05:05:16 +00:00
|
|
|
!videomodereset)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
OSD_ResizeDisplay(xres,yres);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
if (checkvideomode(&x,&y,c,fs,0) < 0) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_close();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-04-07 01:16:29 +00:00
|
|
|
if (mousegrab)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
regrab = 1;
|
|
|
|
grabmouse(0);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (lockcount) while (lockcount) enddrawing();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
if (bpp > 8 && sdl_surface) polymost_glreset();
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2011-12-28 20:34:57 +00:00
|
|
|
// clear last gamma/contrast/brightness so that it will be set anew
|
|
|
|
lastvidgcb[0] = lastvidgcb[1] = lastvidgcb[2] = 0.0f;
|
|
|
|
|
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
|
|
|
// restore gamma before we change video modes if it was changed
|
2006-11-17 05:05:16 +00:00
|
|
|
if (sdl_surface && gammabrightness)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_SetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]);
|
|
|
|
gammabrightness = 0; // redetect on next mode switch
|
|
|
|
}
|
2013-10-07 10:03:37 +00:00
|
|
|
|
|
|
|
if (sdl_buffersurface)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(sdl_buffersurface);
|
|
|
|
sdl_buffersurface = 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
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2006-11-17 05:05:16 +00:00
|
|
|
if (c > 8)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, multisamplecheck = (glmultisample > 0);
|
2006-11-17 05:05:16 +00:00
|
|
|
struct
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_GLattr attr;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t value;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
attributes[] =
|
|
|
|
{
|
2011-09-10 15:44:53 +00:00
|
|
|
# if 0
|
2007-12-12 17:42:14 +00:00
|
|
|
{ SDL_GL_RED_SIZE, 8 },
|
|
|
|
{ SDL_GL_GREEN_SIZE, 8 },
|
|
|
|
{ SDL_GL_BLUE_SIZE, 8 },
|
|
|
|
{ SDL_GL_ALPHA_SIZE, 8 },
|
|
|
|
{ SDL_GL_BUFFER_SIZE, c },
|
|
|
|
{ SDL_GL_STENCIL_SIZE, 0 },
|
|
|
|
{ SDL_GL_ACCUM_RED_SIZE, 0 },
|
|
|
|
{ SDL_GL_ACCUM_GREEN_SIZE, 0 },
|
|
|
|
{ SDL_GL_ACCUM_BLUE_SIZE, 0 },
|
|
|
|
{ SDL_GL_ACCUM_ALPHA_SIZE, 0 },
|
|
|
|
{ SDL_GL_DEPTH_SIZE, 24 },
|
2011-09-10 15:44:53 +00:00
|
|
|
# endif
|
2007-12-12 17:42:14 +00:00
|
|
|
{ SDL_GL_DOUBLEBUFFER, 1 },
|
|
|
|
{ SDL_GL_MULTISAMPLEBUFFERS, glmultisample > 0 },
|
|
|
|
{ SDL_GL_MULTISAMPLESAMPLES, glmultisample },
|
2008-04-06 23:35:48 +00:00
|
|
|
{ SDL_GL_STENCIL_SIZE, 1 },
|
2011-09-10 15:44:53 +00:00
|
|
|
# if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3)
|
2008-07-22 21:56:28 +00:00
|
|
|
{ SDL_GL_SWAP_CONTROL, vsync },
|
2011-09-10 15:44:53 +00:00
|
|
|
# endif
|
2007-12-12 17:42:14 +00:00
|
|
|
};
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (nogl) return -1;
|
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
# ifdef _WIN32
|
|
|
|
win_setvideomode(c);
|
|
|
|
# endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("Setting video mode %dx%d (%d-bpp %s)\n",
|
|
|
|
x,y,c, ((fs&1) ? "fullscreen" : "windowed"));
|
2006-11-17 05:05:16 +00:00
|
|
|
do
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
for (i=0; i < (int32_t)(sizeof(attributes)/sizeof(attributes[0])); i++)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
j = attributes[i].value;
|
|
|
|
if (!multisamplecheck &&
|
|
|
|
(attributes[i].attr == SDL_GL_MULTISAMPLEBUFFERS ||
|
|
|
|
attributes[i].attr == SDL_GL_MULTISAMPLESAMPLES)
|
2006-11-17 05:05:16 +00:00
|
|
|
)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
SDL_GL_SetAttribute(attributes[i].attr, j);
|
|
|
|
}
|
|
|
|
|
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. */
|
2011-09-10 15:44:53 +00:00
|
|
|
# if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3)
|
2008-07-22 21:56:28 +00:00
|
|
|
if (vsync != ovsync)
|
|
|
|
{
|
|
|
|
if (sdl_surface)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(sdl_surface);
|
2008-07-23 03:56:50 +00:00
|
|
|
sdl_surface = SDL_SetVideoMode(1, 1, 8, SDL_NOFRAME | SURFACE_FLAGS | ((fs&1)?SDL_FULLSCREEN:0));
|
2008-07-22 21:56:28 +00:00
|
|
|
SDL_FreeSurface(sdl_surface);
|
|
|
|
}
|
|
|
|
ovsync = vsync;
|
|
|
|
}
|
2011-09-10 15:44:53 +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_surface = SDL_SetVideoMode(x, y, c, SDL_OPENGL | ((fs&1)?SDL_FULLSCREEN:0));
|
2006-11-17 05:05:16 +00:00
|
|
|
if (!sdl_surface)
|
|
|
|
{
|
|
|
|
if (multisamplecheck)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("Multisample mode not possible. Retrying without multisampling.\n");
|
|
|
|
glmultisample = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
initprintf("Unable to set video mode!\n");
|
|
|
|
return -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
|
|
|
# else
|
|
|
|
destroy_window_and_renderer();
|
|
|
|
|
2013-10-06 07:49:53 +00:00
|
|
|
if (create_window_and_renderer(x,y,c,fs, SDL_RENDERER_ACCELERATED) == -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
|
|
|
return -1;
|
|
|
|
#endif
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
while (multisamplecheck--);
|
|
|
|
}
|
|
|
|
else
|
2011-09-10 15:44:53 +00:00
|
|
|
#endif // defined USE_OPENGL
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
initprintf("Setting video mode %dx%d (%d-bpp %s)\n",
|
|
|
|
x,y,c, ((fs&1) ? "fullscreen" : "windowed"));
|
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
|
2013-10-07 10:03:37 +00:00
|
|
|
// We convert paletted contents to non-paletted
|
|
|
|
sdl_surface = SDL_SetVideoMode(x, y, 0, SURFACE_FLAGS | ((fs&1)?SDL_FULLSCREEN:0));
|
2006-11-17 05:05:16 +00:00
|
|
|
if (!sdl_surface)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("Unable to set video mode!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-07 10:03:37 +00:00
|
|
|
sdl_buffersurface = SDL_CreateRGBSurface(SURFACE_FLAGS, x, y, c, 0, 0, 0, 0);
|
|
|
|
if (!sdl_buffersurface)
|
|
|
|
{
|
|
|
|
initprintf("Unable to set video mode: SDL_CreateRGBSurface failed: %s\n",
|
|
|
|
SDL_GetError());
|
|
|
|
return -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
|
|
|
#else
|
|
|
|
// deinit
|
|
|
|
destroy_window_and_renderer();
|
|
|
|
|
|
|
|
// init
|
2013-10-06 07:49:53 +00:00
|
|
|
if (create_window_and_renderer(x,y,c,fs, SDL_RENDERER_SOFTWARE |
|
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
|
|
|
SDL_RENDERER_TARGETTEXTURE) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
2013-10-07 10:04:02 +00:00
|
|
|
sdl_surface = SDL_CreateRGBSurface(0, x, y, 32, 0, 0, 0, 0);
|
|
|
|
if (!sdl_surface)
|
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
|
|
|
{
|
2013-10-07 10:04:02 +00:00
|
|
|
initprintf("Unable to set video mode: SDL_CreateRGBSurface failed: %s\n",
|
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
|
|
|
SDL_GetError());
|
2013-10-07 10:04:02 +00:00
|
|
|
destroy_window_and_renderer();
|
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-07 10:04:02 +00:00
|
|
|
sdl_buffersurface = SDL_CreateRGBSurface(0, x, y, c, 0, 0, 0, 0);
|
|
|
|
if (!sdl_buffersurface)
|
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
|
|
|
{
|
2013-10-07 10:04:02 +00:00
|
|
|
initprintf("Unable to set video mode: SDL_CreateRGBSurface failed: %s\n",
|
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
|
|
|
SDL_GetError());
|
2013-10-07 10:04:02 +00:00
|
|
|
destroy_window_and_renderer();
|
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-07 10:04:02 +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_palptr)
|
|
|
|
sdl_palptr = SDL_AllocPalette(256);
|
|
|
|
|
2013-10-07 10:03:37 +00:00
|
|
|
if (SDL_SetSurfacePalette(sdl_buffersurface, sdl_palptr) < 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
|
|
|
initprintf("SDL_SetSurfacePalette failed: %s\n", SDL_GetError());
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#if 0
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
char flags[512] = "";
|
2012-01-12 20:49:15 +00:00
|
|
|
# define FLAG(x,y) if ((sdl_surface->flags & x) == x) { strcat(flags, y); strcat(flags, " "); }
|
2006-04-24 19:04:22 +00:00
|
|
|
FLAG(SDL_HWSURFACE, "HWSURFACE") else
|
|
|
|
FLAG(SDL_SWSURFACE, "SWSURFACE")
|
|
|
|
FLAG(SDL_ASYNCBLIT, "ASYNCBLIT")
|
|
|
|
FLAG(SDL_ANYFORMAT, "ANYFORMAT")
|
|
|
|
FLAG(SDL_HWPALETTE, "HWPALETTE")
|
|
|
|
FLAG(SDL_DOUBLEBUF, "DOUBLEBUF")
|
|
|
|
FLAG(SDL_FULLSCREEN, "FULLSCREEN")
|
|
|
|
FLAG(SDL_OPENGL, "OPENGL")
|
|
|
|
FLAG(SDL_OPENGLBLIT, "OPENGLBLIT")
|
|
|
|
FLAG(SDL_RESIZABLE, "RESIZABLE")
|
|
|
|
FLAG(SDL_HWACCEL, "HWACCEL")
|
|
|
|
FLAG(SDL_SRCCOLORKEY, "SRCCOLORKEY")
|
|
|
|
FLAG(SDL_RLEACCEL, "RLEACCEL")
|
|
|
|
FLAG(SDL_SRCALPHA, "SRCALPHA")
|
|
|
|
FLAG(SDL_PREALLOC, "PREALLOC")
|
2012-01-12 20:49:15 +00:00
|
|
|
# undef FLAG
|
2006-04-24 19:04:22 +00:00
|
|
|
initprintf("SDL Surface flags: %s\n", flags);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
//static char t[384];
|
|
|
|
//sprintf(t, "%s (%dx%d %s)", apptitle, x, y, ((fs) ? "fullscreen" : "windowed"));
|
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, 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
|
|
|
|
SDL_SetWindowTitle(sdl_window, apptitle);
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2006-11-17 05:05:16 +00:00
|
|
|
if (c > 8)
|
|
|
|
{
|
2006-07-24 02:47:47 +00:00
|
|
|
char *p,*p2,*p3;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
polymost_glreset();
|
|
|
|
|
|
|
|
bglEnable(GL_TEXTURE_2D);
|
|
|
|
bglShadeModel(GL_SMOOTH); //GL_FLAT
|
|
|
|
bglClearColor(0,0,0,0.5); //Black Background
|
|
|
|
bglHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); //Use FASTEST for ortho!
|
|
|
|
bglHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
|
|
|
|
bglDisable(GL_DITHER);
|
|
|
|
|
2006-07-24 02:47:47 +00:00
|
|
|
glinfo.vendor = (const char *)bglGetString(GL_VENDOR);
|
|
|
|
glinfo.renderer = (const char *)bglGetString(GL_RENDERER);
|
|
|
|
glinfo.version = (const char *)bglGetString(GL_VERSION);
|
|
|
|
glinfo.extensions = (const char *)bglGetString(GL_EXTENSIONS);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2012-01-12 20:49:15 +00:00
|
|
|
# ifdef POLYMER
|
2011-01-16 02:50:27 +00:00
|
|
|
if (!Bstrcmp(glinfo.vendor,"ATI Technologies Inc."))
|
|
|
|
{
|
2009-06-28 21:03:50 +00:00
|
|
|
pr_ati_fboworkaround = 1;
|
|
|
|
initprintf("Enabling ATI FBO color attachment workaround.\n");
|
2009-06-28 21:16:11 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
if (Bstrstr(glinfo.renderer,"Radeon X1"))
|
|
|
|
{
|
2009-06-28 21:16:11 +00:00
|
|
|
pr_ati_nodepthoffset = 1;
|
|
|
|
initprintf("Enabling ATI R520 polygon offset workaround.\n");
|
2011-01-16 02:50:27 +00:00
|
|
|
}
|
|
|
|
else
|
2009-06-28 21:16:11 +00:00
|
|
|
pr_ati_nodepthoffset = 0;
|
2012-01-12 20:49:15 +00:00
|
|
|
# ifdef __APPLE__
|
2010-05-02 23:27:30 +00:00
|
|
|
//See bug description at http://lists.apple.com/archives/mac-opengl/2005/Oct/msg00169.html
|
2011-01-16 02:50:27 +00:00
|
|
|
if (!Bstrncmp(glinfo.renderer,"ATI Radeon 9600", 15))
|
|
|
|
{
|
2010-01-23 22:12:02 +00:00
|
|
|
pr_ati_textureformat_one = 1;
|
|
|
|
initprintf("Enabling ATI Radeon 9600 texture format workaround.\n");
|
2011-01-16 02:50:27 +00:00
|
|
|
}
|
|
|
|
else
|
2010-01-23 22:12:02 +00:00
|
|
|
pr_ati_textureformat_one = 0;
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2011-01-16 02:50:27 +00:00
|
|
|
}
|
|
|
|
else
|
2009-06-28 21:16:11 +00:00
|
|
|
pr_ati_fboworkaround = 0;
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif // defined POLYMER
|
2009-06-28 21:03:50 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
glinfo.maxanisotropy = 1.0;
|
|
|
|
glinfo.bgra = 0;
|
|
|
|
glinfo.texcompr = 0;
|
|
|
|
|
|
|
|
// process the extensions string and flag stuff we recognize
|
|
|
|
p = Bstrdup(glinfo.extensions);
|
|
|
|
p3 = p;
|
2011-01-16 02:50:27 +00:00
|
|
|
while ((p2 = Bstrtoken(p3==p?p:NULL, " ", (char **)&p3, 1)) != NULL)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
|
|
|
if (!Bstrcmp(p2, "GL_EXT_texture_filter_anisotropic"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// supports anisotropy. get the maximum anisotropy level
|
|
|
|
bglGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glinfo.maxanisotropy);
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp(p2, "GL_EXT_texture_edge_clamp") ||
|
|
|
|
!Bstrcmp(p2, "GL_SGIS_texture_edge_clamp"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// supports GL_CLAMP_TO_EDGE or GL_CLAMP_TO_EDGE_SGIS
|
|
|
|
glinfo.clamptoedge = 1;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp(p2, "GL_EXT_bgra"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// support bgra textures
|
|
|
|
glinfo.bgra = 1;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
2011-04-07 01:16:29 +00:00
|
|
|
else if (!Bstrcmp(p2, "GL_ARB_texture_compression") && Bstrcmp(glinfo.vendor,"ATI Technologies Inc."))
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// support texture compression
|
|
|
|
glinfo.texcompr = 1;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp(p2, "GL_ARB_texture_non_power_of_two"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// support non-power-of-two texture sizes
|
|
|
|
glinfo.texnpot = 1;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp(p2, "WGL_3DFX_gamma_control"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// 3dfx cards have issues with fog
|
|
|
|
nofog = 1;
|
|
|
|
if (!(warnonce&1)) initprintf("3dfx card detected: OpenGL fog disabled\n");
|
|
|
|
warnonce |= 1;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp(p2, "GL_ARB_multisample"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// supports multisampling
|
|
|
|
glinfo.multisample = 1;
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else if (!Bstrcmp(p2, "GL_NV_multisample_filter_hint"))
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// supports nvidia's multisample hint extension
|
|
|
|
glinfo.nvmultisamplehint = 1;
|
|
|
|
}
|
2007-01-06 01:29:45 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_fragment_program"))
|
|
|
|
{
|
|
|
|
glinfo.arbfp = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_depth_texture"))
|
|
|
|
{
|
|
|
|
glinfo.depthtex = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_shadow"))
|
|
|
|
{
|
|
|
|
glinfo.shadow = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_EXT_framebuffer_object"))
|
|
|
|
{
|
|
|
|
glinfo.fbos = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_NV_texture_rectangle") ||
|
|
|
|
!Bstrcmp((char *)p2, "GL_EXT_texture_rectangle"))
|
|
|
|
{
|
|
|
|
glinfo.rect = 1;
|
|
|
|
}
|
2007-01-15 09:08:57 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_multitexture"))
|
|
|
|
{
|
|
|
|
glinfo.multitex = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_texture_env_combine"))
|
|
|
|
{
|
|
|
|
glinfo.envcombine = 1;
|
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_vertex_buffer_object"))
|
|
|
|
{
|
|
|
|
glinfo.vbos = 1;
|
|
|
|
}
|
2009-02-05 08:56:59 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_EXT_gpu_shader4"))
|
|
|
|
{
|
|
|
|
glinfo.sm4 = 1;
|
|
|
|
}
|
2009-09-30 01:26:13 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_occlusion_query"))
|
|
|
|
{
|
|
|
|
glinfo.occlusionqueries = 1;
|
|
|
|
}
|
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_shader_objects"))
|
|
|
|
{
|
|
|
|
glinfo.glsl = 1;
|
|
|
|
}
|
2011-10-02 05:56:35 +00:00
|
|
|
else if (!Bstrcmp((char *)p2, "GL_ARB_debug_output"))
|
|
|
|
{
|
|
|
|
glinfo.debugoutput = 1;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
Bfree(p);
|
2008-02-24 00:46:57 +00:00
|
|
|
|
|
|
|
if (!glinfo.dumped)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t oldbpp = bpp;
|
2008-05-31 03:53:53 +00:00
|
|
|
bpp = 32;
|
2008-02-24 00:46:57 +00:00
|
|
|
osdcmd_glinfo(NULL);
|
2008-05-31 07:27:43 +00:00
|
|
|
glinfo.dumped = 1;
|
2008-05-31 03:53:53 +00:00
|
|
|
bpp = oldbpp;
|
2008-02-24 00:46:57 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2012-01-12 20:49:15 +00:00
|
|
|
#endif // defined USE_OPENGL
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
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;
|
|
|
|
OSD_ResizeDisplay(xres,yres);
|
|
|
|
|
|
|
|
// save the current system gamma to determine if gamma is available
|
2006-11-17 05:05:16 +00:00
|
|
|
if (!gammabrightness)
|
|
|
|
{
|
2008-07-19 13:12:20 +00:00
|
|
|
// float f = 1.0 + ((float)curbrightness / 10.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 SDL_MAJOR_VERSION==1
|
2006-04-24 19:04:22 +00:00
|
|
|
if (SDL_GetGammaRamp(sysgamma[0], sysgamma[1], sysgamma[2]) >= 0)
|
|
|
|
gammabrightness = 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
|
|
|
#else
|
|
|
|
if (SDL_GetWindowGammaRamp(sdl_window, sysgamma[0], sysgamma[1], sysgamma[2]) == 0)
|
|
|
|
gammabrightness = 1;
|
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
// see if gamma really is working by trying to set the brightness
|
2008-07-19 13:12:20 +00:00
|
|
|
if (gammabrightness && setgamma() < 0)
|
2006-04-24 19:04:22 +00:00
|
|
|
gammabrightness = 0; // nope
|
|
|
|
}
|
|
|
|
|
|
|
|
// setpalettefade will set the palette according to whether gamma worked
|
|
|
|
setpalettefade(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta);
|
|
|
|
|
|
|
|
//if (c==8) setpalette(0,256,0);
|
|
|
|
|
|
|
|
if (regrab) grabmouse(1);
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// resetvideomode() -- resets the video system
|
|
|
|
//
|
|
|
|
void resetvideomode(void)
|
|
|
|
{
|
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
|
|
|
|
//
|
|
|
|
void begindrawing(void)
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lock the frame
|
|
|
|
if (lockcount++ > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (offscreenrendering) return;
|
|
|
|
|
2013-10-07 10:03:37 +00:00
|
|
|
if (SDL_MUSTLOCK(sdl_buffersurface)) SDL_LockSurface(sdl_buffersurface);
|
|
|
|
frameplace = (intptr_t)sdl_buffersurface->pixels;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2013-10-07 10:03:37 +00:00
|
|
|
if (sdl_buffersurface->pitch != bytesperline || modechange)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2013-10-07 10:03:37 +00:00
|
|
|
bytesperline = sdl_buffersurface->pitch;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
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
|
|
|
|
//
|
|
|
|
void enddrawing(void)
|
|
|
|
{
|
2006-11-17 05:05:16 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
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
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (offscreenrendering) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-10-07 10:03:37 +00:00
|
|
|
if (SDL_MUSTLOCK(sdl_buffersurface)) SDL_UnlockSurface(sdl_buffersurface);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// showframe() -- update the display
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
void showframe(int32_t w)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
// int32_t i,j;
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(w);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2006-11-17 05:05:16 +00:00
|
|
|
if (bpp > 8)
|
|
|
|
{
|
|
|
|
if (palfadedelta)
|
2012-12-10 18:17:44 +00:00
|
|
|
fullscreen_tint_gl(palfadergb.r, palfadergb.g, palfadergb.b, palfadedelta);
|
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
|
|
|
# if SDL_MAJOR_VERSION==1
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_GL_SwapBuffers();
|
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
|
2013-10-07 10:04:02 +00:00
|
|
|
SDL_GL_SwapWindow(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
|
|
|
SDL_RenderPresent(sdl_renderer);
|
|
|
|
# endif
|
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);
|
2006-04-24 19:04:22 +00:00
|
|
|
while (lockcount) enddrawing();
|
|
|
|
}
|
|
|
|
|
2011-12-28 20:34:41 +00:00
|
|
|
// deferred palette updating
|
|
|
|
if (needpalupdate)
|
|
|
|
{
|
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
|
2013-10-07 10:03:37 +00:00
|
|
|
SDL_SetColors(sdl_buffersurface, sdlayer_pal, 0, 256);
|
2011-12-28 20:34:41 +00:00
|
|
|
// same as:
|
2013-10-07 10:03:37 +00:00
|
|
|
//SDL_SetPalette(sdl_buffersurface, SDL_LOGPAL|SDL_PHYSPAL, pal, 0, 256);
|
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
|
|
|
|
if (SDL_SetPaletteColors(sdl_palptr, sdlayer_pal, 0, 256) < 0)
|
|
|
|
initprintf("SDL_SetPaletteColors failed: %s\n", SDL_GetError());
|
|
|
|
#endif
|
2011-12-28 20:34:41 +00:00
|
|
|
needpalupdate = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-07 10:03:37 +00:00
|
|
|
SDL_BlitSurface(sdl_buffersurface, NULL, sdl_surface, NULL);
|
2013-10-07 10:04:02 +00:00
|
|
|
|
|
|
|
#if SDL_MAJOR_VERSION==1
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_Flip(sdl_surface);
|
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
|
2013-10-07 10:04:02 +00:00
|
|
|
SDL_UpdateTexture(sdl_texture, NULL, sdl_surface->pixels, sdl_surface->pitch);
|
|
|
|
|
|
|
|
SDL_RenderClear(sdl_renderer);
|
|
|
|
SDL_RenderCopy(sdl_renderer, sdl_texture, NULL, 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
|
|
|
SDL_RenderPresent(sdl_renderer);
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// setpalette() -- set palette values
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t setpalette(int32_t start, int32_t num)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,n;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (bpp > 8) return 0; // no palette in opengl
|
|
|
|
|
2011-12-28 20:34:41 +00:00
|
|
|
Bmemcpy(sdlayer_pal, curpalettefaded, 256*4);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
for (i=start, n=num; n>0; i++, n--)
|
2013-10-06 07:49:53 +00:00
|
|
|
curpalettefaded[i].f =
|
|
|
|
#if SDL_MAJOR_VERSION==1
|
|
|
|
sdlayer_pal[i].unused
|
|
|
|
#else
|
|
|
|
sdlayer_pal[i].a
|
|
|
|
#endif
|
|
|
|
= 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-12-28 20:34:41 +00:00
|
|
|
needpalupdate = 1;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// getpalette() -- get palette values
|
|
|
|
//
|
2011-12-28 20:34:41 +00:00
|
|
|
#if 0
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t getpalette(int32_t start, int32_t num, char *dapal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
int32_t i;
|
|
|
|
SDL_Palette *pal;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
// we shouldn't need to lock the surface to get the palette
|
|
|
|
pal = sdl_surface->format->palette;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
for (i=num; i>0; i--, start++) {
|
|
|
|
dapal[0] = pal->colors[start].b >> 2;
|
|
|
|
dapal[1] = pal->colors[start].g >> 2;
|
|
|
|
dapal[2] = pal->colors[start].r >> 2;
|
|
|
|
dapal += 4;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
return 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2011-12-28 20:34:41 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// setgamma
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t setgamma(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
|
|
|
uint16_t gammaTable[768];
|
2008-07-20 00:39:06 +00:00
|
|
|
float gamma = max(0.1f,min(4.f,vid_gamma));
|
|
|
|
float contrast = max(0.1f,min(3.f,vid_contrast));
|
|
|
|
float bright = max(-0.8f,min(0.8f,vid_brightness));
|
|
|
|
|
|
|
|
double invgamma = 1 / gamma;
|
|
|
|
double norm = pow(255., invgamma - 1);
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
if (novideo) return 0;
|
|
|
|
|
2011-12-28 20:34:57 +00:00
|
|
|
if (lastvidgcb[0]==gamma && lastvidgcb[1]==contrast && lastvidgcb[2]==bright)
|
|
|
|
return 0;
|
|
|
|
|
2008-07-20 00:39:06 +00:00
|
|
|
// This formula is taken from Doomsday
|
|
|
|
|
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
double val = i * contrast - (contrast - 1) * 127;
|
|
|
|
if (gamma != 1) val = pow(val, invgamma) / norm;
|
|
|
|
val += bright * 128;
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
gammaTable[i] = gammaTable[i + 256] = gammaTable[i + 512] = (uint16_t)max(0.f,(double)min(0xffff,val*256));
|
2008-07-20 00:39:06 +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==1
|
2011-12-28 20:34:57 +00:00
|
|
|
i = SDL_SetGammaRamp(&gammaTable[0],&gammaTable[256],&gammaTable[512]);
|
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
|
|
|
|
i = INT32_MIN;
|
|
|
|
if (sdl_window)
|
|
|
|
i = SDL_SetWindowGammaRamp(
|
|
|
|
sdl_window,&gammaTable[0],&gammaTable[256],&gammaTable[512]);
|
|
|
|
#endif
|
2011-12-28 20:34:57 +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==1
|
2011-12-28 20:34:57 +00:00
|
|
|
if (i != -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
|
|
|
#else
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
if (i != INT32_MIN)
|
|
|
|
initprintf("Unable to set gamma: SDL_SetWindowGammaRamp failed: %s\n", SDL_GetError());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2011-12-28 20:34:57 +00:00
|
|
|
{
|
|
|
|
lastvidgcb[0] = gamma;
|
|
|
|
lastvidgcb[1] = contrast;
|
|
|
|
lastvidgcb[2] = bright;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 00:17:30 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(__ANDROID__)
|
2006-04-13 20:47:06 +00:00
|
|
|
extern struct sdlappicon sdlappicon;
|
2011-01-16 02:50:27 +00:00
|
|
|
static SDL_Surface *loadappicon(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_Surface *surf;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
surf = SDL_CreateRGBSurfaceFrom((void *)sdlappicon.pixels,
|
2006-04-24 19:04:22 +00:00
|
|
|
sdlappicon.width, sdlappicon.height, 32, sdlappicon.width*4,
|
|
|
|
0xffl,0xff00l,0xff0000l,0xff000000l);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
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();
|
2013-10-06 07:49:53 +00:00
|
|
|
#if SDL_MAJOR_VERSION==1
|
2012-09-15 15:28:30 +00:00
|
|
|
return SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_KEYDOWN));
|
|
|
|
#else
|
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
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t handleevents(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t code, rv=0, j;
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_Event ev;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
while (SDL_PollEvent(&ev))
|
|
|
|
{
|
|
|
|
switch (ev.type)
|
|
|
|
{
|
2013-10-06 07:49:53 +00:00
|
|
|
#if (SDL_MAJOR_VERSION > 1 || (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION > 2))
|
2008-10-20 12:33:29 +00:00
|
|
|
case SDL_TEXTINPUT:
|
|
|
|
j = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
code = ev.text.text[j];
|
|
|
|
|
|
|
|
if (code != scantoasc[OSD_OSDKey()] && ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc)
|
|
|
|
{
|
|
|
|
if (OSD_HandleChar(code))
|
|
|
|
{
|
|
|
|
keyasciififo[keyasciififoend] = code;
|
|
|
|
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (j < SDL_TEXTINPUTEVENT_TEXT_SIZE && ev.text.text[++j]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
|
|
|
code = keytranslation[ev.key.keysym.scancode];
|
2011-03-14 03:10:25 +00:00
|
|
|
|
2011-04-07 01:16:29 +00:00
|
|
|
if (ev.key.type == SDL_KEYDOWN &&
|
|
|
|
(ev.key.keysym.scancode == SDL_SCANCODE_RETURN ||
|
|
|
|
ev.key.keysym.scancode == SDL_SCANCODE_BACKSPACE ||
|
|
|
|
ev.key.keysym.scancode == SDL_SCANCODE_TAB) &&
|
2011-03-14 03:10:25 +00:00
|
|
|
((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc)
|
|
|
|
{
|
2013-10-06 07:49:53 +00:00
|
|
|
char keyvalue;
|
|
|
|
switch (ev.key.keysym.scancode)
|
2011-03-14 03:10:25 +00:00
|
|
|
{
|
2013-10-06 07:49:53 +00:00
|
|
|
case SDL_SCANCODE_RETURN: keyvalue = '\n'; break;
|
|
|
|
case SDL_SCANCODE_BACKSPACE: keyvalue = '\b'; break;
|
|
|
|
case SDL_SCANCODE_TAB: keyvalue = '\t'; break;
|
|
|
|
default: keyvalue = 0; break;
|
|
|
|
}
|
|
|
|
if (OSD_HandleChar(keyvalue))
|
|
|
|
{
|
|
|
|
keyasciififo[keyasciififoend] = keyvalue;
|
2011-03-14 03:10:25 +00:00
|
|
|
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:14:17 +00:00
|
|
|
// printf("got key %d, %d\n",ev.key.keysym.scancode,code);
|
2008-10-20 12:33:29 +00:00
|
|
|
|
|
|
|
// hook in the osd
|
|
|
|
if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ev.key.type == SDL_KEYDOWN)
|
|
|
|
{
|
|
|
|
if (!keystatus[code])
|
|
|
|
{
|
|
|
|
SetKey(code, 1);
|
|
|
|
if (keypresscallback)
|
2008-10-24 09:20:38 +00:00
|
|
|
keypresscallback(code, 1);
|
2008-10-20 12:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-12 20:49:15 +00:00
|
|
|
# ifdef __linux
|
2011-05-07 18:23:34 +00:00
|
|
|
// The pause key generates a release event right after
|
|
|
|
// the pressing one on linux. As a result, it gets unseen
|
|
|
|
// by the game most of the time.
|
|
|
|
if (code == 0x59) // pause
|
|
|
|
break;
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2008-10-20 12:33:29 +00:00
|
|
|
SetKey(code, 0);
|
|
|
|
if (keypresscallback)
|
2008-10-24 09:20:38 +00:00
|
|
|
keypresscallback(code, 0);
|
2008-10-20 12:33:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-10-06 07:49:53 +00:00
|
|
|
case SDL_MOUSEWHEEL:
|
|
|
|
// initprintf("wheel y %d\n",ev.wheel.y);
|
|
|
|
if (ev.wheel.y > 0)
|
|
|
|
{
|
|
|
|
mwheelup = totalclock;
|
|
|
|
mouseb |= 16;
|
|
|
|
if (mousepresscallback)
|
|
|
|
mousepresscallback(5, 1);
|
|
|
|
}
|
|
|
|
if (ev.wheel.y < 0)
|
|
|
|
{
|
|
|
|
mwheeldown = totalclock;
|
|
|
|
mouseb |= 32;
|
|
|
|
if (mousepresscallback)
|
|
|
|
mousepresscallback(6, 1);
|
|
|
|
}
|
|
|
|
break;
|
2008-10-20 12:33:29 +00:00
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
switch (ev.window.event)
|
|
|
|
{
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
|
|
|
appactive = 1;
|
2012-11-25 04:26:37 +00:00
|
|
|
# if !defined DEBUGGINGAIDS || defined _WIN32
|
2011-04-07 01:16:29 +00:00
|
|
|
if (mousegrab && moustat)
|
2008-10-20 12:33:29 +00:00
|
|
|
{
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
|
|
}
|
2012-11-25 04:26:37 +00:00
|
|
|
# endif
|
|
|
|
# ifdef _WIN32
|
|
|
|
if (backgroundidle)
|
|
|
|
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2008-10-20 12:33:29 +00:00
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT_FOCUS_LOST:
|
|
|
|
appactive = 0;
|
2012-11-25 04:26:37 +00:00
|
|
|
# if !defined DEBUGGINGAIDS || defined _WIN32
|
2011-04-07 01:16:29 +00:00
|
|
|
if (mousegrab && moustat)
|
2008-10-20 12:33:29 +00:00
|
|
|
{
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
}
|
2012-11-25 04:26:37 +00:00
|
|
|
# endif
|
|
|
|
# ifdef _WIN32
|
|
|
|
if (backgroundidle)
|
|
|
|
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2008-10-20 12:33:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
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
|
|
|
// #warning Using SDL 1.3 or 2.X
|
|
|
|
#else // SDL 1.3+ ^^^ | vvv SDL 1.2
|
|
|
|
// #warning Using SDL 1.2
|
2006-04-24 19:04:22 +00:00
|
|
|
case SDL_KEYDOWN:
|
|
|
|
case SDL_KEYUP:
|
|
|
|
code = keytranslation[ev.key.keysym.sym];
|
2012-01-12 20:49:15 +00:00
|
|
|
# ifdef KEY_PRINT_DEBUG
|
2011-11-25 09:50:07 +00:00
|
|
|
printf("keytranslation[%d] = %s (%d) %s\n", ev.key.keysym.sym,
|
|
|
|
key_names[code], code, ev.key.type==SDL_KEYDOWN?"DOWN":"UP");
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2008-07-07 12:35:21 +00:00
|
|
|
if (code != OSD_OSDKey() && ev.key.keysym.unicode != 0 && ev.key.type == SDL_KEYDOWN &&
|
2006-04-24 19:04:22 +00:00
|
|
|
(ev.key.keysym.unicode & 0xff80) == 0 &&
|
2006-11-17 05:05:16 +00:00
|
|
|
((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc)
|
|
|
|
{
|
2008-07-05 09:12:36 +00:00
|
|
|
if (OSD_HandleChar(ev.key.keysym.unicode & 0x7f))
|
2008-07-04 02:13:48 +00:00
|
|
|
{
|
|
|
|
keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f;
|
|
|
|
keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1));
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// hook in the osd
|
2011-06-17 11:53:41 +00:00
|
|
|
// if (ev.type==SDL_KEYDOWN)
|
|
|
|
// printf("got key SDLK %d (%s), trans 0x%x\n", ev.key.keysym.sym, SDL_GetKeyName(ev.key.keysym.sym), code);
|
2008-07-02 01:32:53 +00:00
|
|
|
if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0)
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (ev.key.type == SDL_KEYDOWN)
|
|
|
|
{
|
|
|
|
if (!keystatus[code])
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SetKey(code, 1);
|
|
|
|
if (keypresscallback)
|
2008-10-24 09:20:38 +00:00
|
|
|
keypresscallback(code, 1);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-12 20:49:15 +00:00
|
|
|
# ifdef __linux
|
2011-05-07 18:23:34 +00:00
|
|
|
if (code == 0x59) // pause
|
|
|
|
break;
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2006-04-24 19:04:22 +00:00
|
|
|
SetKey(code, 0);
|
|
|
|
if (keypresscallback)
|
2008-10-24 09:20:38 +00:00
|
|
|
keypresscallback(code, 0);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_ACTIVEEVENT:
|
2006-11-17 05:05:16 +00:00
|
|
|
if (ev.active.state & SDL_APPINPUTFOCUS)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
appactive = ev.active.gain;
|
2012-11-25 04:26:37 +00:00
|
|
|
# if !defined DEBUGGINGAIDS || defined _WIN32
|
2011-04-07 01:16:29 +00:00
|
|
|
if (mousegrab && moustat)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
|
|
|
if (appactive)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
|
|
SDL_ShowCursor(SDL_DISABLE);
|
2006-11-17 05:05:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
SDL_ShowCursor(SDL_ENABLE);
|
|
|
|
}
|
|
|
|
}
|
2012-11-25 04:26:37 +00:00
|
|
|
# endif
|
|
|
|
# ifdef _WIN32
|
|
|
|
if (backgroundidle)
|
|
|
|
SetPriorityClass(GetCurrentProcess(),
|
|
|
|
appactive ? NORMAL_PRIORITY_CLASS : IDLE_PRIORITY_CLASS);
|
2012-01-12 20:49:15 +00:00
|
|
|
# endif
|
2006-04-24 19:04:22 +00:00
|
|
|
rv=-1;
|
|
|
|
}
|
|
|
|
break;
|
2011-09-06 17:46:50 +00:00
|
|
|
#endif // SDL version
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2012-01-12 20:48:57 +00:00
|
|
|
//if (ev.button.button>=0)
|
|
|
|
// initprintf("BTN %d\n", ev.button.button);
|
2006-11-17 05:05:16 +00:00
|
|
|
switch (ev.button.button)
|
|
|
|
{
|
2008-10-20 04:00:00 +00:00
|
|
|
// some of these get reordered to match winlayer
|
2008-10-20 03:09:19 +00:00
|
|
|
default:
|
2008-10-20 12:33:29 +00:00
|
|
|
j = -1; break;
|
2006-11-13 23:12:47 +00:00
|
|
|
case SDL_BUTTON_LEFT:
|
|
|
|
j = 0; break;
|
|
|
|
case SDL_BUTTON_RIGHT:
|
|
|
|
j = 1; break;
|
|
|
|
case SDL_BUTTON_MIDDLE:
|
|
|
|
j = 2; break;
|
2012-01-12 20:48:57 +00:00
|
|
|
case 8 /*SDL_BUTTON_X1*/: // 8 --> 3
|
|
|
|
j = 3; break;
|
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
|
2012-01-12 20:48:57 +00:00
|
|
|
case SDL_BUTTON_WHEELUP: // 4
|
|
|
|
case SDL_BUTTON_WHEELDOWN: // 5
|
2006-11-13 23:12:47 +00:00
|
|
|
j = ev.button.button; break;
|
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
|
2012-01-12 20:48:57 +00:00
|
|
|
case 9 /*SDL_BUTTON_X2*/: // 9 --> 6
|
|
|
|
j = 6; break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
if (j<0) break;
|
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (ev.button.state == SDL_PRESSED)
|
|
|
|
{
|
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-11-17 05:05:16 +00:00
|
|
|
if (ev.button.button == SDL_BUTTON_WHEELUP)
|
|
|
|
{
|
2006-08-07 06:18:57 +00:00
|
|
|
mwheelup = totalclock;
|
|
|
|
}
|
2006-11-17 05:05:16 +00:00
|
|
|
if (ev.button.button == SDL_BUTTON_WHEELDOWN)
|
|
|
|
{
|
2006-08-07 06:18:57 +00:00
|
|
|
mwheeldown = totalclock;
|
|
|
|
}
|
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-24 19:04:22 +00:00
|
|
|
mouseb |= (1<<j);
|
2006-08-07 06:18:57 +00:00
|
|
|
}
|
2006-11-17 05:05:16 +00:00
|
|
|
else
|
|
|
|
{
|
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
|
2008-10-18 12:37:26 +00:00
|
|
|
if (j != SDL_BUTTON_WHEELUP && j != SDL_BUTTON_WHEELDOWN)
|
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
|
2008-10-18 12:37:26 +00:00
|
|
|
mouseb &= ~(1<<j);
|
2006-08-07 06:18:57 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (mousepresscallback)
|
|
|
|
mousepresscallback(j+1, ev.button.state == SDL_PRESSED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_MOUSEMOTION:
|
2012-05-01 12:38:14 +00:00
|
|
|
// SDL <VER> doesn't handle relative mouse movement correctly yet as the cursor still clips to the screen edges
|
2011-03-14 03:10:25 +00:00
|
|
|
// so, we call SDL_WarpMouse() to center the cursor and ignore the resulting motion event that occurs
|
2012-05-01 12:38:14 +00:00
|
|
|
// <VER> is 1.3 for PK, 1.2 for tueidj
|
|
|
|
if (appactive && mousegrab)
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2012-05-01 12:38:14 +00:00
|
|
|
#ifdef GEKKO
|
|
|
|
// check if it's a wiimote pointer pretending to be a mouse
|
|
|
|
if (ev.motion.state & SDL_BUTTON_X2MASK)
|
|
|
|
{
|
|
|
|
// the absolute values are used to draw the crosshair
|
|
|
|
mouseabsx = ev.motion.x;
|
|
|
|
mouseabsy = ev.motion.y;
|
|
|
|
// hack: reduce the scale of the "relative" motions
|
|
|
|
// to make it act more like a real mouse
|
|
|
|
ev.motion.xrel /= 16;
|
|
|
|
ev.motion.yrel /= 12;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (ev.motion.x != xdim>>1 || ev.motion.y != ydim>>1)
|
|
|
|
{
|
|
|
|
mousex += ev.motion.xrel;
|
|
|
|
mousey += ev.motion.yrel;
|
2012-06-01 20:09:27 +00:00
|
|
|
#if !defined DEBUGGINGAIDS || MY_DEVELOPER_ID==805120924
|
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
|
2012-05-01 12:38:14 +00:00
|
|
|
SDL_WarpMouse(xdim>>1, ydim>>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
|
|
|
# else
|
|
|
|
SDL_WarpMouseInWindow(sdl_window, xdim>>1, ydim>>1);
|
|
|
|
# endif
|
2012-04-01 03:57:36 +00:00
|
|
|
#endif
|
2012-05-01 12:38:14 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_JOYAXISMOTION:
|
|
|
|
if (appactive && ev.jaxis.axis < joynumaxes)
|
2010-10-21 02:20:40 +00:00
|
|
|
{
|
|
|
|
joyaxis[ev.jaxis.axis] = ev.jaxis.value * 10000 / 32767;
|
|
|
|
if ((joyaxis[ev.jaxis.axis] < joydead[ev.jaxis.axis])
|
2011-01-16 02:50:27 +00:00
|
|
|
&& (joyaxis[ev.jaxis.axis] > -joydead[ev.jaxis.axis]))
|
2010-10-21 02:20:40 +00:00
|
|
|
joyaxis[ev.jaxis.axis] = 0;
|
|
|
|
else if (joyaxis[ev.jaxis.axis] >= joysatur[ev.jaxis.axis])
|
|
|
|
joyaxis[ev.jaxis.axis] = 10000;
|
|
|
|
else if (joyaxis[ev.jaxis.axis] <= -joysatur[ev.jaxis.axis])
|
|
|
|
joyaxis[ev.jaxis.axis] = -10000;
|
|
|
|
else
|
2011-01-16 02:50:27 +00:00
|
|
|
joyaxis[ev.jaxis.axis] = joyaxis[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:
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t hatvals[16] =
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
-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
|
|
|
|
};
|
2006-11-13 23:12:47 +00:00
|
|
|
if (appactive && ev.jhat.hat < joynumhats)
|
|
|
|
joyhat[ ev.jhat.hat ] = hatvals[ ev.jhat.value & 15 ];
|
|
|
|
break;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
case SDL_JOYBUTTONDOWN:
|
|
|
|
case SDL_JOYBUTTONUP:
|
2006-11-17 05:05:16 +00:00
|
|
|
if (appactive && ev.jbutton.button < joynumbuttons)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (ev.jbutton.state == SDL_PRESSED)
|
|
|
|
joyb |= 1 << ev.jbutton.button;
|
|
|
|
else
|
|
|
|
joyb &= ~(1 << ev.jbutton.button);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SDL_QUIT:
|
|
|
|
quitevent = 1;
|
|
|
|
rv=-1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-05-21 05:53:21 +00:00
|
|
|
//OSD_Printf("Got event (%d)\n", ev.type);
|
2006-04-24 19:04:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:14:17 +00:00
|
|
|
// if (mousex|mousey) printf("%d,%d\n",mousex,mousey); ///
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
sampletimer();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-17 05:05:16 +00:00
|
|
|
if (moustat)
|
|
|
|
{
|
2006-11-19 01:28:51 +00:00
|
|
|
if ((mwheelup) && (mwheelup <= (unsigned)(totalclock - MWHEELTICKS)))
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-08-07 06:18:57 +00:00
|
|
|
mouseb &= ~16;
|
|
|
|
mwheelup = 0;
|
|
|
|
}
|
2006-11-19 01:28:51 +00:00
|
|
|
if ((mwheeldown) && (mwheeldown <= (unsigned)(totalclock - MWHEELTICKS)))
|
2006-11-17 05:05:16 +00:00
|
|
|
{
|
2006-08-07 06:18:57 +00:00
|
|
|
mouseb &= ~32;
|
|
|
|
mwheeldown = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifndef _WIN32
|
2006-07-01 01:40:18 +00:00
|
|
|
startwin_idle(NULL);
|
2012-11-24 09:13:29 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#undef SetKey
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return rv;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2010-05-18 05:14:17 +00:00
|
|
|
#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) // SDL 1.2
|
|
|
|
// from SDL HG, modified
|
2012-11-05 20:04:02 +00:00
|
|
|
int32_t SDL_WaitEventTimeout(SDL_Event *event, int32_t timeout)
|
2010-05-18 05:14:17 +00:00
|
|
|
{
|
|
|
|
uint32_t expiration = 0;
|
|
|
|
|
|
|
|
if (timeout > 0)
|
|
|
|
expiration = SDL_GetTicks() + timeout;
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
2010-05-18 05:14:17 +00:00
|
|
|
SDL_PumpEvents();
|
2011-01-16 02:50:27 +00:00
|
|
|
switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, ~0)) //SDL_FIRSTEVENT, SDL_LASTEVENT)) {
|
|
|
|
{
|
2010-05-18 05:14:17 +00:00
|
|
|
case -1:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
return 1;
|
|
|
|
case 0:
|
2011-01-16 02:50:27 +00:00
|
|
|
if (timeout == 0)
|
|
|
|
{
|
2010-05-18 05:14:17 +00:00
|
|
|
/* Polling and no events, just return */
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
if (timeout > 0 && ((int32_t)(SDL_GetTicks() - expiration) >= 0))
|
|
|
|
{
|
2010-05-18 05:14:17 +00:00
|
|
|
/* Timeout expired and no events */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SDL_Delay(10);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-24 07:12:50 +00:00
|
|
|
|