Skip to content

Commit

Permalink
Removed <SDL/SDL.h> from main.c
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMaddison committed Oct 27, 2009
1 parent 71e8b0c commit c3142e9
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ INSTALL=/usr/bin/install -c

cabrio: main.o ogl.o sdl.o config.o bg.o menu.o game_sel.o \
game.o font.o hint.o genre.o platform.o submenu.o \
sound.o event.o key.o control.o setup.o
sound.o event.o key.o control.o setup.o sdl_ogl.o
$(CC) -o $@ $(LDFLAGS) $^

.c.o: %.c
Expand Down
30 changes: 14 additions & 16 deletions bg.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bg.h"
#include "sdl_ogl.h"
#include "sdl.h"
#include "ogl.h"

Expand All @@ -13,15 +14,14 @@ void bg_clear( void ) {
bg_texture = bg_clear_texture;
}

int bg_init( void ) {
SDL_Surface *bg = sdl_load_image( BG_DEFAULT );
if( bg == NULL ) {
fprintf( stderr, "Warning: couldn't load default background image '%s'\n", BG_DEFAULT );
bg_clear_texture = 0;
int bg_init( void ) {
int x,y;
bg_clear_texture = sdl_create_texture( BG_DEFAULT, &x, &y );
if( bg_clear_texture == 0 ) {
fprintf( stderr, "Warning: couldn't create default background texture from '%s'\n", BG_DEFAULT );
return -1;
}
ogl_create_texture( bg, &bg_clear_texture );
SDL_FreeSurface( bg );

bg_clear();
return 0;
}
Expand All @@ -43,20 +43,18 @@ int bg_resume( void ) {

int bg_set( const char *filename ) {
if( filename && *filename ) {
SDL_Surface *bg = sdl_load_image( filename );
if( bg == NULL ) {
int x,y;
if( bg_texture != bg_clear_texture ) {
ogl_free_texture( &bg_texture );
}
bg_texture = sdl_create_texture( filename, &x, &y );
if( bg_texture == 0 ) {
fprintf( stderr, "Warning: couldn't load background image '%s'\n", filename );
bg_texture = 0;
return -1;
}
if( bg_texture != bg_clear_texture ) {
glDeleteTextures( 1, &bg_texture );
}
ogl_create_texture( bg, &bg_texture );
SDL_FreeSurface( bg );
}
else {
bg_texture = bg_clear_texture;
bg_clear();
}
return 0;
}
Expand Down
16 changes: 8 additions & 8 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,14 @@ int config_new( void ) {
const int num_params = 4;
const char *params[] = { "-nowindow", "-skip_gameinfo", "-switchres", "-joystick" };
const int keys[] = {
-1, /* Place holder */
SDLK_UP, /* EVENT_UP == 1 */
SDLK_DOWN, /* EVENT_DOWN */
SDLK_LEFT, /* EVENT_LEFT */
SDLK_RIGHT, /* EVENT_RIGHT */
SDLK_RETURN, /* EVENT_SELECT */
SDLK_BACKSPACE, /* EVENT_BACK */
SDLK_ESCAPE /* EVENT_QUIT */
-1, /* Place holder */
key_id("up"), /* EVENT_UP == 1 */
key_id("down"), /* EVENT_DOWN */
key_id("left"), /* EVENT_LEFT */
key_id("right"), /* EVENT_RIGHT */
key_id("return"), /* EVENT_SELECT */
key_id("backspace"), /* EVENT_BACK */
key_id("escape") /* EVENT_QUIT */
};

emulator->id = 0;
Expand Down
21 changes: 0 additions & 21 deletions control.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,3 @@ const char *axis_dir_name( int axis_dir ) {
return "";
}

int hat_dir_value( int direction ) {
switch( direction ) {
case SDL_HAT_UP:
return DIR_UP;
break;
case SDL_HAT_DOWN:
return DIR_DOWN;
break;
case SDL_HAT_LEFT:
return DIR_LEFT;
break;
case SDL_HAT_RIGHT:
return DIR_RIGHT;
break;
default:
fprintf( stderr, "Warning: Bogus hat direction %d\n", direction );
break;
}
return 0;
}

9 changes: 5 additions & 4 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "config.h"
#include "event.h"
#include "sdl.h"
#include <SDL/SDL.h>

#define MAX_JOYSTICKS 8

Expand Down Expand Up @@ -37,14 +38,14 @@ int event_init( void ) {
events[i].control_type = config->iface.controls[i].control_type;
events[i].control_id = config->iface.controls[i].control_id;
events[i].value = config->iface.controls[i].value;
printf("%s: %s%d %s%d = %d\n",
/* printf("%s: %s%d %s%d = %d\n",
event_name(i),
device_name(events[i].device_type),
events[i].device_id,
control_name(events[i].control_type),
events[i].control_id,
events[i].value
);
); */
}

return 0;
Expand Down Expand Up @@ -119,7 +120,7 @@ int event_poll( void ) {
else if ( sdl_event.type == SDL_JOYHATMOTION
&& sdl_event.jhat.which == events[i].device_id
&& events[i].control_type == CTRL_HAT
&& hat_dir_value( sdl_event.jhat.hat ) == events[i].control_id
&& sdl_hat_dir_value( sdl_event.jhat.hat ) == events[i].control_id
&& sdl_event.jhat.value == events[i].value ) {
event = i;
}
Expand Down Expand Up @@ -210,7 +211,7 @@ int event_probe( int timeout, struct event *event ) {
event->device_id = sdl_event.jhat.which;
event->control_type = CTRL_HAT;
event->control_id = sdl_event.jhat.hat;
event->value = hat_dir_value( sdl_event.jhat.value );
event->value = sdl_hat_dir_value( sdl_event.jhat.value );
return 1;
case SDL_JOYBALLMOTION:
event->device_type = DEV_JOYSTICK;
Expand Down
1 change: 1 addition & 0 deletions font.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "font.h"
#include "sdl.h"
#include "ogl.h"
#include "sdl_ogl.h"

static TTF_Font *font = NULL;
static SDL_Color col = { 255, 255, 255 };
Expand Down
37 changes: 18 additions & 19 deletions game.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <stdlib.h>
#include "game.h"
#include "config.h"
#include "genre.h"
#include "platform.h"
#include "ogl.h"
#include "sdl_ogl.h"

struct game *game_start = NULL;
struct game *game_filter_start = NULL;
Expand Down Expand Up @@ -48,31 +50,28 @@ void game_list_free( void ) {
}

int game_load_texture( struct game *game ) {
SDL_Surface *s = sdl_load_image( game->logo_image );
if( s == NULL ) {
int x, y;
game->texture = sdl_create_texture( game->logo_image, &x, &y );
if( game->texture == 0 ) {
return -1;
}
else {
if( ogl_create_texture( s, &(game->texture) ) != -1 ) {
int x = s->w;
int y = s->h;
if( x > y ) {
/* Landscape */
if( x > IMAGE_MAX_WIDTH ) {
y = (int)(float)y/((float)x/IMAGE_MAX_WIDTH);
x = IMAGE_MAX_WIDTH;
}
if( x > y ) {
/* Landscape */
if( x > IMAGE_MAX_WIDTH ) {
y = (int)(float)y/((float)x/IMAGE_MAX_WIDTH);
x = IMAGE_MAX_WIDTH;
}
else {
/* Portrait (or square) */
if( y > IMAGE_MAX_HEIGHT ) {
x = (int)(float)x/((float)y/IMAGE_MAX_HEIGHT);
y = IMAGE_MAX_HEIGHT;
}
}
else {
/* Portrait (or square) */
if( y > IMAGE_MAX_HEIGHT ) {
x = (int)(float)x/((float)y/IMAGE_MAX_HEIGHT);
y = IMAGE_MAX_HEIGHT;
}
game->image_width = x;
game->image_height = y;
}
game->image_width = x;
game->image_height = y;
}
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions game_sel.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <ctype.h>
#include "game_sel.h"
#include "bg.h"
#include "math.h"
Expand Down
8 changes: 5 additions & 3 deletions hint.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "hint.h"
#include "sdl.h"
#include "font.h"
#include "sdl_ogl.h"

#define ORIENT_LEFT 0
#define ORIENT_RIGHT 1
Expand All @@ -19,9 +20,10 @@ struct font_message *text_select_message = 0;
struct font_message *text_back_message = 0;

int hint_init( void ) {
arrow_texture = sdl_create_texture( DATA_DIR "/pixmaps/arrow.png" );
back_texture = sdl_create_texture( DATA_DIR "/pixmaps/button_blue.png" );
select_texture = sdl_create_texture( DATA_DIR "/pixmaps/button_red.png" );
int x,y;
arrow_texture = sdl_create_texture( DATA_DIR "/pixmaps/arrow.png", &x, &y );
back_texture = sdl_create_texture( DATA_DIR "/pixmaps/button_blue.png", &x, &y );
select_texture = sdl_create_texture( DATA_DIR "/pixmaps/button_red.png", &x, &y );
text_select_message = font_message_create( "Select" );
text_back_message = font_message_create( "Back" );
return 0;
Expand Down
1 change: 0 additions & 1 deletion include/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ int direction_id( char *name );

int axis_dir_value( char *name );
const char *axis_dir_name( int axis_dir );
int hat_dir_value( int direction );

#endif

1 change: 0 additions & 1 deletion include/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ int font_resume( void );
void font_free( void );
void font_message_free( struct font_message *m );
struct font_message *font_message_create( const char *text );
SDL_Surface *font_render( const char *text );

#endif

6 changes: 2 additions & 4 deletions include/ogl.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#ifndef _OGL_H_
#define _OGL_H_ 1

#include "sdl.h"
#include <SDL/SDL_opengl.h>
#include <GL/glu.h>
#include "sdl.h"

#define X 0
#define Y 1
#define Z 2

int ogl_init( void );
int ogl_create_texture( SDL_Surface *surface, GLuint *texture );
int ogl_init( void );
void ogl_free_texture( GLuint *t );
void ogl_clear( void );
void ogl_flush( void );
Expand Down
10 changes: 2 additions & 8 deletions include/sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
#define _SDL_H_ 1

#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <SDL/SDL_rotozoom.h>
#include <SDL/SDL_framerate.h>
#include <SDL/SDL_opengl.h>

int sdl_init( void );
void sdl_free( void );
SDL_Surface *sdl_load_image( const char *filename );
GLuint sdl_create_texture( const char *filename );
void sdl_frame_delay( void );
void sdl_clear( void );
void sdl_swap( void );
int sdl_hat_dir_value( int direction );

#endif

11 changes: 11 additions & 0 deletions include/sdl_ogl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef _SDL_OGL_H_
#define _SDL_OGL_H_ 1

#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

int ogl_create_texture( SDL_Surface *surface, GLuint *texture );
GLuint sdl_create_texture( const char *filename, int *x, int *y );

#endif

2 changes: 1 addition & 1 deletion key.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "key.h"
#include "sdl.h"
#include <SDL/SDL.h>

/* Big list o' key names. These are just the SDLK_* macros with their prefix chopped off. */
static const char *key_name_backspace = "backspace";
Expand Down
8 changes: 1 addition & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <sys/wait.h>

#include "sdl.h"
#include "ogl.h"
#include "font.h"
#include "config.h"
#include "genre.h"
Expand Down Expand Up @@ -107,9 +106,6 @@ int main( int argc, char *arvg[] ) {
if( sdl_init() != 0 )
return -1;

if( ogl_init() != 0 )
return -1;

if( event_init() != 0 )
return -1;

Expand Down Expand Up @@ -147,7 +143,7 @@ int main( int argc, char *arvg[] ) {
bg_init();

while( !quit ) {
ogl_clear();
sdl_clear();
bg_draw();
hint_draw( menu_level );
menu_draw();
Expand Down Expand Up @@ -262,8 +258,6 @@ int main( int argc, char *arvg[] ) {
run( to_run );
if( sdl_init() != 0 )
return -1;
if( ogl_init() != 0 )
return -1;
resume_all();
to_run = NULL;
}
Expand Down
5 changes: 4 additions & 1 deletion menu.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <stdlib.h>
#include "sdl.h"
#include "sdl_ogl.h"
#include "menu.h"
#include "font.h"

Expand Down Expand Up @@ -29,7 +31,8 @@ int menu_selected( void ) {
}

int menu_load_texture( void ) {
menu_texture = sdl_create_texture( DATA_DIR "/pixmaps/menu_item.png" );
int x,y;
menu_texture = sdl_create_texture( DATA_DIR "/pixmaps/menu_item.png", &x ,&y );
if( menu_texture == 0 ) {
fprintf( stderr, "Warning: Couldn't create texture for menu items\n" );
return -1;
Expand Down
Loading

0 comments on commit c3142e9

Please sign in to comment.