Commit f61d09fe545a9035a74760489a082b011f484019

Authored by dg
1 parent fa86870b

update to SDL-2.0.0-6302 (hg)


git-svn-id: http://svn.net-core.org/repos/t-engine4@5147 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -57,8 +57,8 @@ project "TEngine"
57 57
58 58
59 59 configuration "linux"
60   - libdirs {"/opt/SDL-1.3/lib/"}
61   - links { "dl", "SDL-1.3", "SDL_ttf", "SDL_image", "openal", "vorbisfile", "GL", "GLU", "m", "pthread" }
  60 + libdirs {"/opt/SDL-2.0/lib/"}
  61 + links { "dl", "SDL2", "SDL2_ttf", "SDL2_image", "png", "openal", "vorbisfile", "GL", "GLU", "m", "pthread" }
62 62 defines { [[TENGINE_HOME_PATH='".t-engine"']], 'SELFEXE_LINUX' }
63 63
64 64 configuration {"Debug"}
... ...
... ... @@ -18,7 +18,7 @@ solution "TEngine"
18 18 "src/physfs",
19 19 "src/physfs/zlib123",
20 20 "src/bzip2",
21   - "/opt/SDL-1.3/include/SDL/",
  21 + "/opt/SDL-2.0/include/SDL2/",
22 22 "/usr/include/GL",
23 23 }
24 24 if _OPTIONS.lua == "default" then includedirs{"src/lua"}
... ...
... ... @@ -41,6 +41,141 @@
41 41
42 42 extern SDL_Window *window;
43 43
  44 +#define SDL_SRCALPHA 0x00010000
  45 +int SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
  46 +{
  47 + if (flag & SDL_SRCALPHA) {
  48 + /* According to the docs, value is ignored for alpha surfaces */
  49 + if (surface->format->Amask) {
  50 + value = 0xFF;
  51 + }
  52 + SDL_SetSurfaceAlphaMod(surface, value);
  53 + SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
  54 + } else {
  55 + SDL_SetSurfaceAlphaMod(surface, 0xFF);
  56 + SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
  57 + }
  58 + SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));
  59 +
  60 + return 0;
  61 +}
  62 +
  63 +typedef struct SDL_VideoInfo
  64 +{
  65 + Uint32 hw_available:1;
  66 + Uint32 wm_available:1;
  67 + Uint32 UnusedBits1:6;
  68 + Uint32 UnusedBits2:1;
  69 + Uint32 blit_hw:1;
  70 + Uint32 blit_hw_CC:1;
  71 + Uint32 blit_hw_A:1;
  72 + Uint32 blit_sw:1;
  73 + Uint32 blit_sw_CC:1;
  74 + Uint32 blit_sw_A:1;
  75 + Uint32 blit_fill:1;
  76 + Uint32 UnusedBits3:16;
  77 + Uint32 video_mem;
  78 +
  79 + SDL_PixelFormat *vfmt;
  80 +
  81 + int current_w;
  82 + int current_h;
  83 +} SDL_VideoInfo;
  84 +
  85 +static int
  86 +GetVideoDisplay()
  87 +{
  88 + const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
  89 + if ( !variable ) {
  90 + variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
  91 + }
  92 + if ( variable ) {
  93 + return SDL_atoi(variable);
  94 + } else {
  95 + return 0;
  96 + }
  97 +}
  98 +
  99 +const SDL_VideoInfo *SDL_GetVideoInfo(void)
  100 +{
  101 + static SDL_VideoInfo info;
  102 + SDL_DisplayMode mode;
  103 +
  104 + /* Memory leak, compatibility code, who cares? */
  105 + if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
  106 + info.vfmt = SDL_AllocFormat(mode.format);
  107 + info.current_w = mode.w;
  108 + info.current_h = mode.h;
  109 + }
  110 + return &info;
  111 +}
  112 +
  113 +SDL_Rect **
  114 +SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
  115 +{
  116 + int i, nmodes;
  117 + SDL_Rect **modes;
  118 +
  119 +/* if (!SDL_GetVideoDevice()) {
  120 + return NULL;
  121 + }
  122 + */
  123 +/* if (!(flags & SDL_FULLSCREEN)) {
  124 + return (SDL_Rect **) (-1);
  125 + }
  126 +*/
  127 + if (!format) {
  128 + format = SDL_GetVideoInfo()->vfmt;
  129 + }
  130 +
  131 + /* Memory leak, but this is a compatibility function, who cares? */
  132 + nmodes = 0;
  133 + modes = NULL;
  134 + for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
  135 + SDL_DisplayMode mode;
  136 + int bpp;
  137 +
  138 + SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
  139 + if (!mode.w || !mode.h) {
  140 + return (SDL_Rect **) (-1);
  141 + }
  142 +
  143 + /* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */
  144 + if (SDL_BYTESPERPIXEL(mode.format) <= 2) {
  145 + bpp = SDL_BITSPERPIXEL(mode.format);
  146 + } else {
  147 + bpp = SDL_BYTESPERPIXEL(mode.format) * 8;
  148 + }
  149 +
  150 + if (bpp != format->BitsPerPixel) {
  151 + continue;
  152 + }
  153 + if (nmodes > 0 && modes[nmodes - 1]->w == mode.w
  154 + && modes[nmodes - 1]->h == mode.h) {
  155 + continue;
  156 + }
  157 +
  158 + modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
  159 + if (!modes) {
  160 + return NULL;
  161 + }
  162 + modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
  163 + if (!modes[nmodes]) {
  164 + return NULL;
  165 + }
  166 + modes[nmodes]->x = 0;
  167 + modes[nmodes]->y = 0;
  168 + modes[nmodes]->w = mode.w;
  169 + modes[nmodes]->h = mode.h;
  170 + ++nmodes;
  171 + }
  172 + if (modes) {
  173 + modes[nmodes] = NULL;
  174 + }
  175 + return modes;
  176 +}
  177 +
  178 +
44 179 /***** Helpers *****/
45 180 static GLenum sdl_gl_texture_format(SDL_Surface *s) {
46 181 // get the number of channels in the SDL surface
... ... @@ -180,12 +315,12 @@ static int lua_set_current_keyhandler(lua_State *L)
180 315 static int lua_get_mod_state(lua_State *L)
181 316 {
182 317 const char *mod = luaL_checkstring(L, 1);
183   - SDLMod smod = SDL_GetModState();
  318 + SDL_Keymod smod = SDL_GetModState();
184 319
185 320 if (!strcmp(mod, "shift")) lua_pushboolean(L, smod & KMOD_SHIFT);
186 321 else if (!strcmp(mod, "ctrl")) lua_pushboolean(L, smod & KMOD_CTRL);
187 322 else if (!strcmp(mod, "alt")) lua_pushboolean(L, smod & KMOD_ALT);
188   - else if (!strcmp(mod, "meta")) lua_pushboolean(L, smod & KMOD_META);
  323 + else if (!strcmp(mod, "meta")) lua_pushboolean(L, smod & KMOD_GUI);
189 324 else if (!strcmp(mod, "caps")) lua_pushboolean(L, smod & KMOD_CAPS);
190 325 else lua_pushnil(L);
191 326
... ... @@ -354,12 +489,6 @@ static const struct luaL_reg gamelib[] =
354 489 ******************************************************************/
355 490 static bool no_text_aa = FALSE;
356 491
357   -static int sdl_fullscreen(lua_State *L)
358   -{
359   - SDL_WM_ToggleFullScreen(screen);
360   - return 0;
361   -}
362   -
363 492 extern bool is_fullscreen;
364 493 static int sdl_screen_size(lua_State *L)
365 494 {
... ... @@ -639,7 +768,7 @@ static int sdl_font_draw(lua_State *L)
639 768 #else
640 769 rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000;
641 770 #endif
642   - SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, max_width, h, 32, rmask, gmask, bmask, amask);
  771 + SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE, max_width, h, 32, rmask, gmask, bmask, amask);
643 772 SDL_FillRect(s, NULL, SDL_MapRGBA(s->format, 0, 0, 0, 0));
644 773
645 774 int id_dduid = 1;
... ... @@ -916,7 +1045,7 @@ static int sdl_new_tile(lua_State *L)
916 1045 #endif
917 1046
918 1047 *s = SDL_CreateRGBSurface(
919   - SDL_SWSURFACE | SDL_SRCALPHA,
  1048 + SDL_SWSURFACE,
920 1049 w,
921 1050 h,
922 1051 32,
... ... @@ -957,7 +1086,7 @@ static int sdl_new_surface(lua_State *L)
957 1086 #endif
958 1087
959 1088 *s = SDL_CreateRGBSurface(
960   - SDL_SWSURFACE | SDL_SRCALPHA,
  1089 + SDL_SWSURFACE,
961 1090 w,
962 1091 h,
963 1092 32,
... ... @@ -1011,7 +1140,7 @@ int init_blank_surface()
1011 1140 amask = 0xff000000;
1012 1141 #endif
1013 1142 SDL_Surface *s = SDL_CreateRGBSurface(
1014   - SDL_SWSURFACE | SDL_SRCALPHA,
  1143 + SDL_SWSURFACE,
1015 1144 4,
1016 1145 4,
1017 1146 32,
... ... @@ -1417,7 +1546,7 @@ static int sdl_surface_alpha(lua_State *L)
1417 1546 if (lua_isnumber(L, 2))
1418 1547 {
1419 1548 int a = luaL_checknumber(L, 2);
1420   - SDL_SetAlpha(*s, SDL_SRCALPHA | SDL_RLEACCEL, (a < 0) ? 0 : (a > 255) ? 255 : a);
  1549 + SDL_SetAlpha(*s, /*SDL_SRCALPHA | */SDL_RLEACCEL, (a < 0) ? 0 : (a > 255) ? 255 : a);
1421 1550 }
1422 1551 else
1423 1552 {
... ... @@ -2219,7 +2348,7 @@ static int get_text_aa(lua_State *L)
2219 2348 static int sdl_get_modes_list(lua_State *L)
2220 2349 {
2221 2350 SDL_PixelFormat format;
2222   - SDL_Rect **modes;
  2351 + SDL_Rect **modes = NULL;
2223 2352 int loops = 0;
2224 2353 int bpp = 0;
2225 2354 int nb = 1;
... ... @@ -2244,7 +2373,7 @@ static int sdl_get_modes_list(lua_State *L)
2244 2373 }
2245 2374
2246 2375 //get available fullscreen/hardware modes
2247   - modes = SDL_ListModes(&format, SDL_FULLSCREEN);
  2376 + modes = SDL_ListModes(&format, 0);
2248 2377 if (modes)
2249 2378 {
2250 2379 int i;
... ... @@ -2388,7 +2517,6 @@ static const struct luaL_reg displaylib[] =
2388 2517 {"setTextBlended", set_text_aa},
2389 2518 {"getTextBlended", get_text_aa},
2390 2519 {"forceRedraw", sdl_redraw_screen},
2391   - {"fullscreen", sdl_fullscreen},
2392 2520 {"size", sdl_screen_size},
2393 2521 {"newFont", sdl_new_font},
2394 2522 {"newSurface", sdl_new_surface},
... ...
... ... @@ -72,8 +72,8 @@ int mouse_drag_tex = 0, mouse_drag_tex_ref = LUA_NOREF;
72 72 int mousex = 0, mousey = 0;
73 73 float gamma_correction = 1;
74 74 int requested_fps = 30;
75   -SDL_TimerID display_timer_id = NULL;
76   -SDL_TimerID realtime_timer_id = NULL;
  75 +SDL_TimerID display_timer_id = 0;
  76 +SDL_TimerID realtime_timer_id = 0;
77 77
78 78 /* OpenGL capabilities */
79 79 GLint max_texture_size = 1024;
... ... @@ -337,12 +337,6 @@ void on_event(SDL_Event *event)
337 337 case SDL_BUTTON_RIGHT:
338 338 lua_pushstring(L, "right");
339 339 break;
340   - case SDL_BUTTON_WHEELUP:
341   - lua_pushstring(L, "wheelup");
342   - break;
343   - case SDL_BUTTON_WHEELDOWN:
344   - lua_pushstring(L, "wheeldown");
345   - break;
346 340 default:
347 341 lua_pushstring(L, "button");
348 342 lua_pushnumber(L, event->button.button);
... ... @@ -650,7 +644,7 @@ void setupRealtime(float freq)
650 644 if (!freq)
651 645 {
652 646 if (realtime_timer_id) SDL_RemoveTimer(realtime_timer_id);
653   - realtime_timer_id = NULL;
  647 + realtime_timer_id = 0;
654 648 printf("[ENGINE] Switching to turn based\n");
655 649 }
656 650 else
... ... @@ -726,7 +720,7 @@ int resizeWindow(int width, int height)
726 720 /* Reset The View */
727 721 glLoadIdentity( );
728 722
729   - SDL_SetGamma(gamma_correction, gamma_correction, gamma_correction);
  723 +//TSDL2 SDL_SetGamma(gamma_correction, gamma_correction, gamma_correction);
730 724
731 725 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
732 726 printf("OpenGL max texture size: %d\n", max_texture_size);
... ... @@ -869,7 +863,7 @@ void boot_lua(int state, bool rebooting, int argc, char *argv[])
869 863 }
870 864 else if (state == 2)
871 865 {
872   - SDL_WM_SetCaption("T-Engine4", NULL);
  866 + SDL_SetWindowTitle(window, "T-Engine4");
873 867
874 868 // Now we can open lua lanes, the physfs paths are set and it can load it's lanes-keeper.lua file
875 869 // luaopen_lanes(L);
... ... @@ -1001,7 +995,6 @@ int main(int argc, char *argv[])
1001 995 }
1002 996 SDL_SetWindowIcon(window, IMG_Load_RW(PHYSFSRWOPS_openRead("/engines/default/data/gfx/te4-icon.png"), TRUE));
1003 997 SDL_SetWindowTitle(window, "T4Engine");
1004   - SDL_EnableKeyRepeat(300, 10);
1005 998 TTF_Init();
1006 999
1007 1000 /* Sets up OpenGL double buffering */
... ...
... ... @@ -275,7 +275,7 @@ static int loadsoundLua(lua_State *L) {
275 275 if (sound->mutex == NULL) luaL_error(L, "out of memory");
276 276 sound->cond = SDL_CreateCond();
277 277 if (sound->cond == NULL) luaL_error(L, "out of memory");
278   - sound->loaderThread = SDL_CreateThread(streamingLoader, sound);
  278 + sound->loaderThread = SDL_CreateThread(streamingLoader, "steamer", sound);
279 279 }
280 280 else {
281 281 sound->static_source = 0;
... ...
... ... @@ -876,6 +876,7 @@ void create_particles_thread()
876 876
877 877 MAX_THREADS = nb_cpus - 1;
878 878 MAX_THREADS = (MAX_THREADS < 1) ? 1 : MAX_THREADS;
  879 + MAX_THREADS = 1;
879 880 threads = calloc(MAX_THREADS, sizeof(particle_thread));
880 881
881 882 cur_thread = 0;
... ... @@ -890,7 +891,7 @@ void create_particles_thread()
890 891 pt->keyframes = SDL_CreateSemaphore(0);
891 892 pt->running = TRUE;
892 893
893   - thread = SDL_CreateThread(thread_particles, pt);
  894 + thread = SDL_CreateThread(thread_particles, "particles", pt);
894 895 if (thread == NULL) {
895 896 printf("Unable to create particle thread: %s\n", SDL_GetError());
896 897 continue;
... ...
... ... @@ -24,11 +24,7 @@
24 24 #define _INCLUDE_PHYSFSRWOPS_H_
25 25
26 26 #include "physfs.h"
27   -#ifdef __APPLE__
28   -#include <SDL/SDL.h>
29   -#else
30   -#include "SDL.h"
31   -#endif
  27 +#include "tSDL.h"
32 28
33 29 #ifdef __cplusplus
34 30 extern "C" {
... ...
... ... @@ -207,7 +207,7 @@ int create_profile_thread(lua_State *L)
207 207 profile->lock_oqueue = SDL_CreateMutex();
208 208 profile->wait_oqueue = SDL_CreateSemaphore(0);
209 209
210   - thread = SDL_CreateThread(thread_profile, profile);
  210 + thread = SDL_CreateThread(thread_profile, "profile", profile);
211 211 if (thread == NULL) {
212 212 printf("Unable to create profile thread: %s\n", SDL_GetError());
213 213 return -1;
... ...