From 612284cfeae0e4b5f6d494c00d84fd2f42047ca1 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 6 Oct 2013 07:49:53 +0000 Subject: [PATCH] Improve SDL2 support as much as I can, for now. The game compiles, links, and starts, but all three renderers either don't display correctly or crash. To build with SDL2: make RENDERTYPE=SDL SDL_TARGET=2 git-svn-id: https://svn.eduke32.com/eduke32@4074 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile | 6 +- polymer/eduke32/build/Makefile.shared | 57 ++++++----- polymer/eduke32/build/include/sdl_inc.h | 20 +++- polymer/eduke32/build/src/sdlayer.c | 99 ++++++++++++------- polymer/eduke32/source/jaudiolib/Makefile | 3 +- .../eduke32/source/jaudiolib/src/driver_sdl.c | 17 +--- polymer/eduke32/source/sdlmusic.c | 6 +- 7 files changed, 123 insertions(+), 85 deletions(-) diff --git a/polymer/eduke32/Makefile b/polymer/eduke32/Makefile index b281d078e..3145f47cc 100644 --- a/polymer/eduke32/Makefile +++ b/polymer/eduke32/Makefile @@ -277,7 +277,11 @@ endif ifeq ($(RENDERTYPE),SDL) ifeq ($(PLATFORM),WINDOWS) OURCOMMONFLAGS += -I$(SDLROOT)/include -I$(SDLROOT)/include/SDL - LIBS+= platform/Windows/lib$(WINLIB)/SDL_mixer.lib + ifeq ($(SDL_TARGET),1) + LIBS+= platform/Windows/lib$(WINLIB)/SDL_mixer.lib + else + LIBS+= -l$(SDLNAME)_mixer + endif LIBDIRS+= -L$(SDLROOT)/lib else ifneq ($(PLATFORM),DARWIN) diff --git a/polymer/eduke32/build/Makefile.shared b/polymer/eduke32/build/Makefile.shared index b533476f6..361433479 100644 --- a/polymer/eduke32/build/Makefile.shared +++ b/polymer/eduke32/build/Makefile.shared @@ -9,36 +9,10 @@ EDITORLIB=libbuild.a # SDK locations - adjust to match your setup # Overrides must use absolute paths since this Makefile is included at different directory levels # -SDLCONFIG ?= sdl-config -SDLNAME ?= SDL -SDL_FRAMEWORK ?= 1 - DXROOT=$(abspath $(dir $(MAKEFILE_COMMON))../sdk/dx) #DXROOT=/c/sdks/directx/dx8 SDLROOT=$(abspath $(dir $(MAKEFILE_COMMON))../sdk/SDL) -ifneq ($(PLATFORM),WINDOWS) - SDLVERSION:=$(strip $(shell $(SDLCONFIG) --version)) - ifneq ($(SDLVERSION),) - SDLROOT:=$(strip $(shell $(SDLCONFIG) --prefix)) - endif - - # Uncomment the following line to enable SDL 2.X detection - #TRYSDL2=1 - ifeq ($(TRYSDL2),1) - SDL2CONFIG ?= sdl2-config - SDL2NAME ?= SDL2 - - SDL2VERSION:=$(strip $(shell $(SDL2CONFIG) --version)) - ifneq ($(SDL2VERSION),) - SDLVERSION:=$(SDL2VERSION) - SDLCONFIG:=$(SDL2CONFIG) - SDLNAME:=$(SDL2NAME) - SDLROOT:=$(strip $(shell $(SDLCONFIG) --prefix)) - endif - endif -endif - DXROOT_OVERRIDE ?= SDLROOT_OVERRIDE ?= ifneq ($(DXROOT_OVERRIDE),) @@ -48,6 +22,26 @@ ifneq ($(SDLROOT_OVERRIDE),) SDLROOT=$(SDLROOT_OVERRIDE) endif +SDL_TARGET ?= 1 + +ifeq ($(SDL_TARGET),2) + SDLCONFIG ?= sdl2-config + SDLNAME ?= SDL2 +endif +ifeq ($(SDL_TARGET),1) + SDLCONFIG ?= sdl-config + SDLNAME ?= SDL +endif + +ifneq ($(PLATFORM),WINDOWS) + SDLVERSION:=$(strip $(shell $(SDLCONFIG) --version)) + ifneq ($(SDLVERSION),) + SDLROOT:=$(strip $(shell $(SDLCONFIG) --prefix)) + endif +endif + +SDL_FRAMEWORK ?= 1 + ifeq (1,$(strip $(shell expr $(GCC_MAJOR) \>= 4))) L_SSP := -lssp @@ -185,7 +179,11 @@ ifneq (0,$(CLANG)) endif endif +SDL_STATIC?=1 + ifeq ($(RENDERTYPE),SDL) + BUILDCOMMONFLAGS += -DSDL_TARGET=$(SDL_TARGET) + ifeq ($(SDL_FRAMEWORK),1) BUILDCOMMONFLAGS += -DSDL_FRAMEWORK endif @@ -207,7 +205,12 @@ ifeq ($(RENDERTYPE),SDL) endif else BUILDCOMMONFLAGS += -D_GNU_SOURCE=1 - BUILDLIBS+= -lmingw32 -lSDLmain -lSDL + ifneq ($(SDL_STATIC),0) + ifneq ($(SDL_TARGET),1) # Since SDL2 is under the zlib license, link statically if possible. + BUILDLIBS+= -static + endif + endif + BUILDLIBS+= -l$(SDLNAME)main -l$(SDLNAME) -lmingw32 -limm32 -lole32 -loleaut32 -lwinmm -lversion endif ifeq (1,$(WITHOUT_GTK)) diff --git a/polymer/eduke32/build/include/sdl_inc.h b/polymer/eduke32/build/include/sdl_inc.h index dd61b9bcc..59f693733 100644 --- a/polymer/eduke32/build/include/sdl_inc.h +++ b/polymer/eduke32/build/include/sdl_inc.h @@ -2,9 +2,15 @@ #define __SDL_INC_H #if defined(SDL_FRAMEWORK) +# if (SDL_TARGET == 2) +# include +# include +# else # include +# include +# endif #else -# include "SDL.h" +# include "SDL.h" #endif /* ================================================================= @@ -29,9 +35,17 @@ Minimum required SDL versions: #if defined(_NEED_SDLMIXER) # if defined(SDL_FRAMEWORK) # if defined(_WIN32) || defined(GEKKO) -# include +# if (SDL_TARGET == 2) +# include +# else +# include +# endif # else -# include +# if (SDL_TARGET == 2) +# include +# else +# include +# endif # endif # else # include "SDL_mixer.h" diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 3b88a9936..47dda50e4 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -2,7 +2,7 @@ // for the Build Engine // by Jonathon Fowler (jf@jonof.id.au) // -// Use SDL 1.2 or 1.3 from http://www.libsdl.org +// Use SDL 1.2 or 2.0 from http://www.libsdl.org #define __STDC_FORMAT_MACROS #define __STDC_LIMIT_MACROS @@ -81,6 +81,7 @@ static SDL_Surface *sdl_surface2; static SDL_Palette *sdl_palptr; static SDL_Window *sdl_window; static SDL_Renderer *sdl_renderer; +static SDL_GLContext sdl_context; #endif int32_t xres=-1, yres=-1, bpp=0, fullscreen=0, bytesperline; intptr_t frameplace=0; @@ -560,7 +561,14 @@ int32_t initinput(void) { i = SDL_NumJoysticks(); initprintf("%d joystick(s) found\n",i); - for (j=0; j> 3; - modes = SDL_ListModes(&pf, SURFACE_FLAGS -// #if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION < 3) - | SDL_FULLSCREEN // not implemented/working in SDL 1.3 SDL_compat.c -//#endif - ); + modes = SDL_ListModes(&pf, SURFACE_FLAGS | SDL_FULLSCREEN); if (modes == (SDL_Rect **)0) { @@ -1179,10 +1188,10 @@ static void destroy_window_and_renderer() sdl_window = NULL; } -static int32_t create_window_and_renderer(int32_t x, int32_t y, int32_t fs, uint32_t flags) +static int32_t create_window_and_renderer(int32_t x, int32_t y, int32_t c, int32_t fs, uint32_t flags) { sdl_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, - x,y, ((fs&1)?SDL_WINDOW_FULLSCREEN:0)); + x,y, ((fs&1)?SDL_WINDOW_FULLSCREEN:0) | (c > 8 ? SDL_WINDOW_OPENGL : 0)); if (!sdl_window) { initprintf("Unable to set video mode: SDL_CreateWindow failed: %s\n", @@ -1199,6 +1208,9 @@ static int32_t create_window_and_renderer(int32_t x, int32_t y, int32_t fs, uint return -1; } + if (c > 8) + sdl_context = SDL_GL_CreateContext(sdl_window); + return 0; } #endif @@ -1338,7 +1350,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) # else destroy_window_and_renderer(); - if (create_window_and_renderer(x,y,fs, SDL_RENDERER_ACCELERATED) == -1) + if (create_window_and_renderer(x,y,c,fs, SDL_RENDERER_ACCELERATED) == -1) return -1; #endif } @@ -1361,7 +1373,7 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) destroy_window_and_renderer(); // init - if (create_window_and_renderer(x,y,fs, SDL_RENDERER_SOFTWARE | + if (create_window_and_renderer(x,y,c,fs, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE) == -1) return -1; @@ -1764,7 +1776,13 @@ int32_t setpalette(int32_t start, int32_t num) Bmemcpy(sdlayer_pal, curpalettefaded, 256*4); for (i=start, n=num; n>0; i++, n--) - curpalettefaded[i].f = sdlayer_pal[i].unused = 0; + curpalettefaded[i].f = +#if SDL_MAJOR_VERSION==1 + sdlayer_pal[i].unused +#else + sdlayer_pal[i].a +#endif + = 0; needpalupdate = 1; @@ -1877,12 +1895,11 @@ static SDL_Surface *loadappicon(void) int32_t handleevents_peekkeys(void) { -#if (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2) SDL_PumpEvents(); +#if SDL_MAJOR_VERSION==1 return SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_EVENTMASK(SDL_KEYDOWN)); #else - // SDL 1.3 up has not been tested to compile. - return 0; + return SDL_PeepEvents(NULL, 1, SDL_PEEKEVENT, SDL_KEYDOWN, SDL_KEYDOWN); #endif } @@ -1901,7 +1918,7 @@ int32_t handleevents(void) { switch (ev.type) { -#if (SDL_MAJOR_VERSION > 1 || SDL_MINOR_VERSION > 2) +#if (SDL_MAJOR_VERSION > 1 || (SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION > 2)) case SDL_TEXTINPUT: j = 0; do @@ -1930,9 +1947,17 @@ int32_t handleevents(void) ev.key.keysym.scancode == SDL_SCANCODE_TAB) && ((keyasciififoend+1)&(KEYFIFOSIZ-1)) != keyasciififoplc) { - if (OSD_HandleChar(ev.key.keysym.unicode & 0x7f)) + char keyvalue; + switch (ev.key.keysym.scancode) { - keyasciififo[keyasciififoend] = ev.key.keysym.unicode & 0x7f; + 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; keyasciififoend = ((keyasciififoend+1)&(KEYFIFOSIZ-1)); } } @@ -1966,6 +1991,23 @@ int32_t handleevents(void) keypresscallback(code, 0); } break; + 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; case SDL_WINDOWEVENT: switch (ev.window.event) { @@ -1999,25 +2041,6 @@ int32_t handleevents(void) break; } break; - /* - 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; - */ // #warning Using SDL 1.3 or 2.X #else // SDL 1.3+ ^^^ | vvv SDL 1.2 // #warning Using SDL 1.2 @@ -2444,7 +2467,7 @@ static int32_t buildkeytranslationtable(void) return 0; } -#else // if SDL 1.3 +#else // if SDL 1.3+ static int32_t buildkeytranslationtable(void) { memset(keytranslation,0,sizeof(keytranslation)); diff --git a/polymer/eduke32/source/jaudiolib/Makefile b/polymer/eduke32/source/jaudiolib/Makefile index 11f78c596..c4fcba2bd 100644 --- a/polymer/eduke32/source/jaudiolib/Makefile +++ b/polymer/eduke32/source/jaudiolib/Makefile @@ -5,9 +5,10 @@ OBJ=obj OBJNAME=libjfaudiolib.a SRC=src INC=include +EINC=../../$(EROOT)/include # for BUILD_ECHOFLAGS: -OURCOMMONFLAGS=$(BASECOMMONFLAGS) $(BUILDCOMMONFLAGS) -I$(INC) -I$(SRC) -DHAVE_VORBIS +OURCOMMONFLAGS=$(BASECOMMONFLAGS) $(BUILDCOMMONFLAGS) -I$(INC) -I$(EINC) -I$(SRC) -DHAVE_VORBIS ifneq ($(PLATFORM),WII) OURCOMMONFLAGS+= -DHAVE_FLAC endif diff --git a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c index dae171102..8106c3bb8 100644 --- a/polymer/eduke32/source/jaudiolib/src/driver_sdl.c +++ b/polymer/eduke32/source/jaudiolib/src/driver_sdl.c @@ -22,20 +22,9 @@ * libSDL output driver for MultiVoc */ - -#if defined(SDL_FRAMEWORK) -# include -# if defined(_WIN32) || defined(GEKKO) -# include -# else -# include -# endif -# include -#else -# include "SDL.h" -# include "SDL_mixer.h" -# include "SDL_thread.h" -#endif +#include +#define _NEED_SDLMIXER +#include "sdl_inc.h" #include "driver_sdl.h" #include "multivoc.h" diff --git a/polymer/eduke32/source/sdlmusic.c b/polymer/eduke32/source/sdlmusic.c index 0a7e88d90..b5e660095 100644 --- a/polymer/eduke32/source/sdlmusic.c +++ b/polymer/eduke32/source/sdlmusic.c @@ -484,7 +484,11 @@ int32_t MUSIC_PlaySong(char *song, int32_t loopflag) else initprintf("%s: fopen: %s\n", __func__, strerror(errno)); } else - music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem((char *) song, g_musicSize)); + music_musicchunk = Mix_LoadMUS_RW(SDL_RWFromMem((char *) song, g_musicSize) +#if (SDL_MAJOR_VERSION > 1) + , SDL_FALSE +#endif + ); if (music_musicchunk != NULL) if (Mix_PlayMusic(music_musicchunk, (loopflag == MUSIC_LoopSong)?-1:0) == -1)