[Xbubble-commits] xbubble/src init.c,1.1,1.2
Martin Quinson
xbubble-devel@lists.alioth.debian.org
Wed, 27 Apr 2005 15:48:05 +0000
Update of /cvsroot/xbubble/xbubble/src
In directory haydn:/tmp/cvs-serv15048
Modified Files:
init.c
Log Message:
cleanup the theme desaloc mess; various cleanups to make gcc happy even with picky warning flags on
Index: init.c
===================================================================
RCS file: /cvsroot/xbubble/xbubble/src/init.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- init.c 5 Dec 2004 20:40:59 -0000 1.1
+++ init.c 27 Apr 2005 15:48:03 -0000 1.2
@@ -35,6 +35,7 @@
#include "bubble.h"
#include "board.h"
#include "gettext.h"
+#include "init.h"
extern Display *display;
extern Visual *visual;
@@ -52,7 +53,7 @@
extern int win_height;
extern int nb_levels;
-extern int level[MAX_NB_LEVELS][NB_CELLS];
+extern int levels[MAX_NB_LEVELS][NB_CELLS];
XFontStruct *title_font;
XFontStruct *dialog_font;
@@ -73,14 +74,15 @@
Set canon_animation;
Set countdown_animation;
Set bubble_animation[NB_COLORS][NB_BUBBLE_STATES];
-char *game_fonts[] = FONTS;
+const char *game_fonts[] = FONTS;
int titlefont_color[3] = TITLEFONT_COLOR;
int menufont_color[3] = MENUFONT_COLOR;
int menufont_selected_color[3] = MENUFONT_SELECTED_COLOR;
+
int notitle = 0;
-char * data_file( char * file, int themed ) {
+static char * data_file( const char * file, int themed) {
int path_max;
int theme_len;
char * abs_data_dir;
@@ -117,7 +119,7 @@
}
-void load_levels( char * file ) {
+static void load_levels( const char * file ) {
FILE *fd;
char line[128];
unsigned char r[8];
@@ -159,7 +161,7 @@
case '6': color = 7; break;
case '7': color = 8; break;
}
- level[nb_levels][cell++] = color;
+ levels[nb_levels][cell++] = color;
}
long_row = 1 - long_row;
}
@@ -205,7 +207,7 @@
}
}
-void add_font_path( char * path ) {
+static void add_font_path( char * path ) {
int i;
int npaths;
char ** fontpath;
@@ -228,7 +230,7 @@
}
}
-XFontStruct * load_font( int pixel_size ) {
+static XFontStruct * load_font( int pixel_size ) {
XFontStruct * xfont;
char name[128];
int i;
@@ -267,7 +269,7 @@
return XCreateGC( display, root, gcm, &gcv );
}
-Frame load_frame( char *file, double zoom ) {
+static Frame load_frame( char *file, double zoom ) {
Pixmap pixmap;
Pixmap mask;
Pixmap *pmask;
@@ -302,14 +304,14 @@
return frame;
}
-void delete_frame( Frame frame ) {
+static void delete_frame( Frame frame ) {
XFreePixmap( display, frame->pixmap);
if ( frame->has_mask )
XFreeGC( display, frame->gc );
free(frame);
}
-Set load_animation( char *filename, double zoom ) {
+static Set load_animation( const char *filename, double zoom ) {
Frame frame;
Set animation = NULL;
int cx;
@@ -357,7 +359,7 @@
return animation;
}
-void load_scaled_image( char *file, Pixmap *pix, Pixmap *mask, double zoom ) {
+static void load_scaled_image( const char *file, Pixmap *pix, Pixmap *mask, double zoom ) {
RgbaImage ri1;
RgbaImage ri2;
ri1 = create_rgba_image_from_png_file(data_file(file,1));
@@ -368,7 +370,7 @@
delete_rgba_image(ri2);
}
-void delete_animation( Set animation ) {
+static void delete_animation( Set animation ) {
int i;
if (animation) {
for ( i = 0; i < animation->size; i++ )
@@ -377,7 +379,12 @@
}
}
-void make_canon_animation( double zoom ) {
+static void unref_animation( Set animation ) {
+ if (animation && !--animation->ref)
+ delete_animation( animation );
+}
+
+static void make_canon_animation( double zoom ) {
RgbaImage ri;
RgbaImage ri2;
Pixmap mask;
@@ -418,7 +425,7 @@
The following Naming convention is used :
Bubble_<COLOR>_<STATE>_<num>.png
*/
-int parse_bubble_name(const char *name,int *color_val, int *state_val)
+static int parse_bubble_name(const char *name,int *color_val, int *state_val)
{
char *copy = NULL, *copy_orig = NULL;
char *token = NULL;
@@ -460,7 +467,7 @@
return return_val;
}
-int diren_select_bubbles (const struct dirent *d) {
+static int diren_select_bubbles (const struct dirent *d) {
int color;
int state;
@@ -471,13 +478,13 @@
return(parse_bubble_name(d->d_name,&color,&state));
}
-void load_animations( double zoom ) {
+static void load_animations( double zoom ) {
int color=-1;
int state=-1;
- int bubble_animation_size[NB_COLORS][NB_BUBBLE_STATES];
+
+ int bubble_animation_size[NB_COLORS][NB_BUBBLE_STATES + 1];
Set default_animation[NB_COLORS];
- int default_animation_size[NB_COLORS];
-
+
struct dirent **namelist = NULL;
int n = 0;
int i;
@@ -486,18 +493,12 @@
alert_animation = load_animation( "frame_light.txt", zoom );
countdown_animation = load_animation( "countdown.txt", zoom );
- for ( color = 0; color < NB_COLORS; color++ ) {
- for ( state = 0; state < NB_BUBBLE_STATES; state++ ) {
- bubble_animation[color][state] = NULL;
- bubble_animation_size[color][state] = 0;
- }
- }
-
- for ( color = 0; color < NB_COLORS; color++ ) {
- default_animation[color] = NULL;
- default_animation_size[color] = 0;
- }
-
+ for ( color = 0; color < NB_COLORS; color++ )
+ default_animation[color] = NULL;
+
+ memset(bubble_animation,0, sizeof(bubble_animation));
+ memset(bubble_animation_size,0, sizeof(bubble_animation_size));
+
color=state=-1;
/* bubble animation */
@@ -505,37 +506,47 @@
n = scandir(dir, &namelist, diren_select_bubbles , alphasort);
if (n < 0) fail(_("Error while scanning %s"),dir);
+
+ /* Count how much frame in each animation */
for(i=0; i<n; i++) {
parse_bubble_name(namelist[i]->d_name,&color,&state);
- if(state!=DEFAULT_STATE) {
- bubble_animation_size[color][state]++;
+ if (state == DEFAULT_STATE) {
+ bubble_animation_size[color][NB_BUBBLE_STATES]++;
} else {
- default_animation_size[color]++;
+ bubble_animation_size[color][state]++;
}
}
+ /* Make room */
for ( color = 0; color < NB_COLORS; color++ ) {
- if(default_animation_size[color]) {
- default_animation[color]= set_new(default_animation_size[color]);
- }
+
for ( state = 0; state < NB_BUBBLE_STATES; state++ ) {
if(bubble_animation_size[color][state]==0) {
- bubble_animation[color][state] = default_animation[color];
+ /* create the default animation set if needed and ref it if not */
+ if (default_animation[color] == NULL) {
+ default_animation[color] = set_new(bubble_animation_size[color][NB_BUBBLE_STATES]);
+ } else {
+ set_ref(default_animation[color]);
+ }
+ /* use the default animation */
+ bubble_animation[color][state] = default_animation[color];
} else {
bubble_animation[color][state] = set_new(bubble_animation_size[color][state]);
}
}
}
- for(i=0; i<n; i++) {
+ /* read the files and fill the animations */
+ for (i=0; i<n; i++) {
color = -1;
state = -1;
parse_bubble_name(namelist[i]->d_name,&color,&state);
- if(state!=DEFAULT_STATE) {
- set_add( bubble_animation[color][state],
- load_frame(namelist[i]->d_name, zoom));
- } else {
+ if (state == DEFAULT_STATE) {
+ Frame frame = load_frame(namelist[i]->d_name, zoom);
set_add( default_animation[color],
+ load_frame(namelist[i]->d_name, zoom) );
+ } else {
+ set_add( bubble_animation[color][state],
load_frame(namelist[i]->d_name, zoom));
}
}
@@ -553,11 +564,11 @@
free(namelist);
}
-void put_pixmap( Pixmap dest_pixmap,
- Pixmap dest_mask,
- Pixmap src_pixmap,
- Pixmap src_mask,
- int x, int y, int w, int h, int dx, int dy ) {
+static void put_pixmap( Pixmap dest_pixmap,
+ Pixmap dest_mask,
+ Pixmap src_pixmap,
+ Pixmap src_mask,
+ int x, int y, int w, int h, int dx, int dy ) {
GC gc;
GC gc_mask;
XGCValues gcv;
@@ -581,7 +592,7 @@
XFreeGC( display, gc_mask );
}
-void load_images( double zoom ) {
+static void load_images( double zoom ) {
GC gc;
GC gc_mask;
int x;
@@ -685,7 +696,7 @@
XFreePixmap( display, tee_mask );
}
-void init_gcs() {
+static void init_gcs() {
/* load dialog font */
dialog_font = load_font( 3*scale/2 );
/* yellow for hilighting menu selection */
@@ -702,19 +713,15 @@
}
void cleanup_graphics() {
-// int color;
+ int color,state;
delete_animation( alert_animation );
delete_animation( canon_animation );
delete_animation( countdown_animation );
- /* FIXME: cleanup animations properly !
- delete_frame( bubble_animation[0][DEAD]->element[1] );
- for ( color = 0; color < NB_COLORS; color++ ) {
- delete_animation( bubble_animation[color][STUCK] );
- delete_animation( bubble_animation[color][EXPLODING] );
- delete_animation( bubble_animation[color][DEAD] );
- }
-*/
+ for ( color = 0; color < NB_COLORS; color++ )
+ for ( state=0; state<NB_BUBBLE_STATES; state++ )
+ unref_animation( bubble_animation[color][state] );
+
XFreeGC( display, dialog_gc );
XFreeGC( display, dialog_text_gc );
XFreeGC( display, menu_gc );
@@ -736,10 +743,10 @@
Window splash2;
int height1;
int height2;
- char * title = "XBubble";
+ const char * title = "XBubble";
char * subtitle = _("Loading graphics ...");
- char *config_file = "config.txt";
+ const char *config_file = "config.txt";
FILE *fd = NULL ;
char line[128];
char *copy = NULL;