[Add] Support SDL 1.3 as well as 1.2 right?! Who's going to tell me I should be using 2.0 already?
This commit is contained in:
parent
81ae76236c
commit
fb3c093f02
61
src/input.c
61
src/input.c
@ -112,14 +112,17 @@ unsigned int input_afterburnSensibility = 200; /**< ms between taps to afterbur
|
||||
/* From player.c */
|
||||
extern double player_turn;
|
||||
|
||||
static const char* keyconv[SDLK_LAST]; /**< Key conversion table. */
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
# define INPUT_NUMKEYS SDL_NUM_SCANCODES /**< Number of keys available. */
|
||||
#else /* SDL_VERSION_ATLEASE(1,3,0) */
|
||||
# define INPUT_NUMKEYS SDLK_LAST /**< Number of keys available. */
|
||||
#endif /* SDL_VERSION_ATLEAST(1,3,0) */
|
||||
static const char* keyconv[INPUT_NUMKEYS]; /**< Key conversion table. */
|
||||
|
||||
static void input_keyConvGen(void);
|
||||
static void input_keyConvDestroy(void);
|
||||
|
||||
/**
|
||||
* @fn void input_setDefault(void)
|
||||
*
|
||||
* @brief Set the default input keys.
|
||||
*/
|
||||
void input_setDefault(void) {
|
||||
@ -167,17 +170,47 @@ void input_setDefault(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void input_init(void)
|
||||
*
|
||||
* @brief Initialize the input subsystem (does not set keys).
|
||||
*/
|
||||
void input_init(void) {
|
||||
Keybind* tmp;
|
||||
int i;
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++); /* Get number of bindings. */
|
||||
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
/* Window. */
|
||||
SDL_EventState(SDL_WINDOW_EVENT, SDL_DISABLE);
|
||||
sDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
|
||||
|
||||
/* Keyboard. */
|
||||
SDL_EventState(SDL_KEYDOWN, SDL_ENABLE);
|
||||
SDL_EventState(SDL_KEYUP, SDL_ENABLE);
|
||||
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
|
||||
|
||||
/* Mice. */
|
||||
SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
|
||||
SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_ENABLE);
|
||||
SDL_EventState(SDL_MOUSEBUTTONUP, SDL_ENABLE);
|
||||
SDL_EventState(SDL_MOUSEWHEEL, SDL_ENABLE);
|
||||
|
||||
/* Joystick, enabled in joystick.c if needed. */
|
||||
SDL_EventState(SDL_JOYAXISMOTION, SDL_DISABLE);
|
||||
SDL_EventState(SDL_JOYHATMOTION, SDL_DISABLE);
|
||||
SDL_EventState(SDL_JOYBUTTONDOWN, SDL_DISABLE);
|
||||
SDL_EventState(SDL_JOYBUTTONUP, SDL_DISABLE);
|
||||
|
||||
/* Quit. */
|
||||
SDL_EventState(SDL_QUIT, SDL_ENABLE);
|
||||
|
||||
/* Proximity. */
|
||||
SDL_EventState(SDL_PROXIMITYIN, SDL_DISABLE);
|
||||
SDL_EventState(SDL_PROXIMITYOUT, SDL_DISABLE);
|
||||
#endif
|
||||
|
||||
/* Get the number of keybindings. */
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++);
|
||||
input_keybinds = malloc(i*sizeof(Keybind*));
|
||||
|
||||
/* Create a null keybinding for each. */
|
||||
/* Create sane null keybinding for each. */
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
|
||||
tmp = malloc(sizeof(Keybind));
|
||||
tmp->name = (char*)keybindNames[i];
|
||||
@ -188,12 +221,11 @@ void input_init(void) {
|
||||
input_keybinds[i] = tmp;
|
||||
}
|
||||
|
||||
/* Generate key translation table. */
|
||||
input_keyConvGen();
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void input_exit(void)
|
||||
*
|
||||
* @brief Exit the input subsystem.
|
||||
*/
|
||||
void input_exit(void) {
|
||||
@ -211,15 +243,18 @@ void input_exit(void) {
|
||||
static void input_keyConvGen(void) {
|
||||
SDLKey k;
|
||||
|
||||
for(k = SDLK_FIRST; k < SDLK_LAST; k++)
|
||||
keyconv[k] = SDL_GetKeyName(k);
|
||||
for(k = 0; k < INPUT_NUMKEYS; k++)
|
||||
keyconv[k] = strdup(SDL_GetKeyName(k));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy the key conversion table.
|
||||
*/
|
||||
static void input_keyConvDestroy(void) {
|
||||
int i;
|
||||
|
||||
for(i = 0; i < INPUT_NUMKEYS; i++)
|
||||
free(keyconv[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,7 +271,7 @@ SDLKey input_keyConv(char* name) {
|
||||
buf[0] = tolower(name[0]);
|
||||
buf[1] = '\0';
|
||||
|
||||
for(k = SDLK_FIRST; k < SDLK_LAST; k++)
|
||||
for(k = 0; k < INPUT_NUMKEYS; k++)
|
||||
if(strcmp((l==1) ? buf : name, keyconv[k])==0)
|
||||
return k;
|
||||
|
||||
@ -245,8 +280,6 @@ SDLKey input_keyConv(char* name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @fn void input_setKeybind(char* keybind, KeybindType type, int key, int reverse)
|
||||
*
|
||||
* @brief Bind a key of type to action keybind.
|
||||
* @param keybind The name of the keybind defined above.
|
||||
* @param type The type of the keybind.
|
||||
|
@ -232,7 +232,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
/* Main loop. */
|
||||
SDL_Event event;
|
||||
/* flushes the event loop, since I notices that when the joystick is loaded, it */
|
||||
/* Flushes the event loop, since I notices that when the joystick is loaded, it */
|
||||
/* creates button events that results in the player starting out accelerating. */
|
||||
while(SDL_PollEvent(&event));
|
||||
while(!quit) {
|
||||
|
64
src/opengl.c
64
src/opengl.c
@ -137,12 +137,15 @@ static int SDL_VFlipSurface(SDL_Surface* surface) {
|
||||
* @return 0 if the pixel isn't transparent, 0 if it is.
|
||||
*/
|
||||
static int SDL_IsTrans(SDL_Surface* s, int x, int y) {
|
||||
int bpp = s->format->BytesPerPixel;
|
||||
int bpp;
|
||||
Uint8* p;
|
||||
Uint32 pixelcolour;
|
||||
|
||||
bpp = s->format->BytesPerPixel;
|
||||
/* p is the address to the pixel we want to retrieve. */
|
||||
Uint8* p = (Uint8*)s->pixels + y * s->pitch + x*bpp;
|
||||
|
||||
Uint32 pixelcolour = 0;
|
||||
p = (Uint8*)s->pixels + y * s->pitch + x*bpp;
|
||||
|
||||
pixelcolour = 0;
|
||||
switch(bpp) {
|
||||
case 1:
|
||||
pixelcolour = *p;
|
||||
@ -160,9 +163,15 @@ static int SDL_IsTrans(SDL_Surface* s, int x, int y) {
|
||||
pixelcolour = *(Uint32*)p;
|
||||
break;
|
||||
}
|
||||
/* Test whetehr the pixels color is equal to color of */
|
||||
/*transparent pixels for that surface. */
|
||||
/*
|
||||
* Test whether the pixels color is equal to color of
|
||||
* transparent pixels for that surface.
|
||||
*/
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
return ((pixelcolour & s->format->Amask) == 0);
|
||||
#else
|
||||
return (pixelcolour == s->format->colorkey);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,17 +183,22 @@ static int SDL_IsTrans(SDL_Surface* s, int x, int y) {
|
||||
* @return 0 on success.
|
||||
*/
|
||||
static uint8_t* SDL_MapTrans(SDL_Surface* s) {
|
||||
int i, j;
|
||||
int size;
|
||||
uint8* t;
|
||||
|
||||
/* Allocate memory for just enough bits to hold all the data we need. */
|
||||
int size = s->w*s->h/8 + ((s->w*s->h%8)?1:0);
|
||||
uint8_t* t = malloc(size);
|
||||
size = s->w*s->h/8 + ((s->w*s->h%8)?1:0);
|
||||
t = malloc(size);
|
||||
memset(t, 0, size); /* *must* be set to zero. */
|
||||
|
||||
if(t == NULL) {
|
||||
WARN("Out of memeory");
|
||||
return NULL;
|
||||
}
|
||||
memset(t, 0, size); /* Important, must be set to zero. */
|
||||
|
||||
int i, j;
|
||||
/* Check each pixel individually. */
|
||||
for(i = 0; i < s->h; i++)
|
||||
for(j = 0; j < s->w; j++) /* Set each bit to be 1 if not transparent or 0 if it is. */
|
||||
t[(i*s->w+j)/8] |= (SDL_IsTrans(s,j,i)) ? 0 : (1<<((i*s->w+j)%8));
|
||||
@ -226,8 +240,10 @@ int SDL_savePNG(SDL_Surface* surface, const char* file) {
|
||||
|
||||
int alpha;
|
||||
int pixel_bits;
|
||||
#if ! SDL_VERSION_ATLEAST(1,3,0)
|
||||
unsigned int surf_flags;
|
||||
unsigned int surf_alpha;
|
||||
#endif
|
||||
|
||||
ss_rows = NULL;
|
||||
ss_size = 0;
|
||||
@ -251,18 +267,22 @@ int SDL_savePNG(SDL_Surface* surface, const char* file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
|
||||
#else
|
||||
surf_flags = surface->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY);
|
||||
surf_alpha = surface->format->alpha;
|
||||
if(surf_flags & SDL_SRCALPHA)
|
||||
SDL_SetAlpha(surface, 0, SDL_ALPHA_OPAQUE);
|
||||
if(surf_flags & SDL_SRCCOLORKEY)
|
||||
SDL_SetColorKey(surface, 0, surface->format->colorkey);
|
||||
#endif
|
||||
|
||||
ss_rect.x = 0;
|
||||
ss_rect.y = 0;
|
||||
ss_rect.w = ss_w;
|
||||
ss_rect.h = ss_h;
|
||||
SDL_BlitSurface(surface, &ss_rect, ss_surface, 0);
|
||||
SDL_BlitSurface(surface, &ss_rect, ss_surface, NULL);
|
||||
|
||||
if(ss_size == 0) {
|
||||
ss_size = ss_h;
|
||||
@ -271,10 +291,13 @@ int SDL_savePNG(SDL_Surface* surface, const char* file) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
#else
|
||||
if(surf_flags & SDL_SRCALPHA)
|
||||
SDL_SetAlpha(surface, SDL_SRCALPHA, (Uint8)surf_alpha);
|
||||
if(surf_flags & SDL_SRCCOLORKEY)
|
||||
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, surface->format->colorkey);
|
||||
#endif
|
||||
|
||||
for(i = 0; i < ss_h; i++)
|
||||
ss_rows[i] = ((unsigned char*)ss_surface->pixels) + i * ss_surface->pitch;
|
||||
@ -303,10 +326,12 @@ int SDL_savePNG(SDL_Surface* surface, const char* file) {
|
||||
*/
|
||||
SDL_Surface* gl_prepareSurface(SDL_Surface* surface) {
|
||||
SDL_Surface* tmp;
|
||||
Uint32 saved_flags;
|
||||
Uint8 saved_alpha;
|
||||
int potw, poth;
|
||||
SDL_Rect rtemp;
|
||||
#if ! SDL_VERSION_ATLEAST(1,3,0)
|
||||
Uint32 saved_flags;
|
||||
Uint8 saved_alpha;
|
||||
#endif
|
||||
|
||||
/* Make size power of two. */
|
||||
potw = gl_pot(surface->w);
|
||||
@ -317,6 +342,13 @@ SDL_Surface* gl_prepareSurface(SDL_Surface* surface) {
|
||||
rtemp.h = surface->h;
|
||||
|
||||
/* Save alpha. */
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
|
||||
|
||||
/* Create the tmp POT surface. */
|
||||
tmp = SDL_CreateRGBSurface(0, potw, poth,
|
||||
surface->format->BytesPerPixel*8, RGBAMASK);
|
||||
#else
|
||||
saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
|
||||
saved_alpha = surface->format->alpha;
|
||||
if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
|
||||
@ -327,6 +359,8 @@ SDL_Surface* gl_prepareSurface(SDL_Surface* surface) {
|
||||
/* Create the temp POT surface. */
|
||||
tmp = SDL_CreateRGBSurface(SDL_SRCCOLORKEY,
|
||||
potw, poth, surface->format->BytesPerPixel*8, RGBAMASK);
|
||||
#endif
|
||||
|
||||
if(tmp == NULL) {
|
||||
WARN("Unable to create POT surface: %s", SDL_GetError());
|
||||
return 0;
|
||||
@ -342,9 +376,11 @@ SDL_Surface* gl_prepareSurface(SDL_Surface* surface) {
|
||||
SDL_FreeSurface(surface);
|
||||
surface = tmp;
|
||||
|
||||
#if ! SDL_VERSION_ATLEAST(1,3,0)
|
||||
/* Set saved alpha. */
|
||||
if((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA)
|
||||
SDL_SetAlpha(surface, 0, 0);
|
||||
#endif
|
||||
|
||||
return surface;
|
||||
}
|
||||
@ -1063,7 +1099,11 @@ int gl_init(void) {
|
||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, gl_screen.fsaa);
|
||||
}
|
||||
if(gl_has(OPENGL_VSYNC))
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
#else
|
||||
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
|
||||
#endif
|
||||
|
||||
if(gl_has(OPENGL_FULLSCREEN)) {
|
||||
/* Try to use desktop resolution if nothing is specifically set. */
|
||||
|
Loading…
Reference in New Issue
Block a user