From 2eb9ef076c32c770f0e2e3ac3675144f2d669ad5 Mon Sep 17 00:00:00 2001 From: stpohle Date: Sat, 25 Sep 2004 10:57:50 +0000 Subject: [PATCH] first changes for a faster game loading. All menu graphic will be loaded from the begin with. --- include/basic.h | 4 +- include/gfx.h | 17 +-- include/menu.h | 5 +- src/configuration.c | 47 +++++-- src/game.c | 18 ++- src/gfx.c | 296 +++++++++++++++++++++++++++++++++++++------- src/gfxengine.c | 3 +- src/gfxpixelimage.c | 18 +-- src/main.c | 4 +- src/multiwait.c | 13 +- src/network.c | 10 +- src/playermenu.c | 288 +++++++++++++++++++----------------------- src/single.c | 4 +- src/tileset.c | 84 ++++--------- 14 files changed, 492 insertions(+), 319 deletions(-) diff --git a/include/basic.h b/include/basic.h index 7e858af..91165d9 100644 --- a/include/basic.h +++ b/include/basic.h @@ -1,4 +1,4 @@ -/* $Id: basic.h,v 1.25 2004/09/12 20:54:24 stpohle Exp $ */ +/* $Id: basic.h,v 1.26 2004/09/25 10:57:50 stpohle Exp $ */ /* basic types which we need everywhere */ #ifndef _BC_BASIC_H_ @@ -141,6 +141,8 @@ enum _fieldtype { }; +extern const char *ft_filenames[]; // declared in tileset.c + enum _poweruptypes { PWUP_good = 0, PWUP_bad, diff --git a/include/gfx.h b/include/gfx.h index 17b8a79..f5115d3 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -1,4 +1,4 @@ -/* $Id: gfx.h,v 1.6 2004/01/27 20:44:02 stpohle Exp $ */ +/* $Id: gfx.h,v 1.7 2004/09/25 10:57:50 stpohle Exp $ */ #ifndef _GFX_H_ #define _GFX_H_ @@ -8,6 +8,8 @@ #define GFX_IMGSIZE 64 #define GFX_IMGBIGSIZE 96 #define GFX_PLAYERIMGSIZE_Y 128 +#define GFX_SMALLPLAYERIMGSIZE_X 12 +#define GFX_MENUPLAYERIMGSIZE_X 32 #include "basic.h" @@ -32,8 +34,8 @@ struct __gfxani { struct __gfxplayer { _gfxani ani; _point offset; - _point smal_size; - SDL_Surface *smal_image; // smal size of the animation + SDL_Surface *small_image; // small size of the player (single frame) + SDL_Surface *menu_image; // menu image of the player (single frame) } typedef _gfxplayer; @@ -47,12 +49,12 @@ struct __gfx { _point offset; // where the game field starts - _gfxplayer players[MAX_PLAYERS]; + _gfxplayer *players; + int player_gfx_count; short int postab[256]; // table of points where we need to go to. _gfxani field[FT_max]; // the field animations - SDL_Surface *smal_special[FT_max - FT_sp_trigger]; - + SDL_Surface *menu_field[FT_max]; _gfxani powerup[3]; // powerup field animation _gfxani fire; // fire (explostion) _gfxani bomb; // bomb animation @@ -89,7 +91,8 @@ extern void scale (short int *dpattern, short int x, short int y); extern SDL_Surface *scale_image (SDL_Surface * orginal, int newx, int newy); extern void shade_pixel(SDL_Surface *s, int x, int y, int c); extern SDL_Surface *makegray_image (SDL_Surface *org); -extern SDL_Surface *gfx_copyscreen (SDL_Rect *wnd); +extern SDL_Surface *gfx_copyfrom(SDL_Surface *img, SDL_Rect *wnd); +#define gfx_copyscreen(__wnd) gfx_copyfrom(gfx.screen, __wnd) extern void gfx_restorescreen (SDL_Surface *img, SDL_Rect *wnd); diff --git a/include/menu.h b/include/menu.h index e9afc8d..75573ab 100644 --- a/include/menu.h +++ b/include/menu.h @@ -1,4 +1,4 @@ -/* $Id: menu.h,v 1.12 2004/06/15 15:04:37 stpohle Exp $ +/* $Id: menu.h,v 1.13 2004/09/25 10:57:50 stpohle Exp $ * GUI for menuhandling */ @@ -67,6 +67,9 @@ extern SDL_Surface *menulistimages[2][9]; // holds the gfx for the lists extern SDL_Surface *menubuttonimages[3][3]; // holds the images for the buttons extern SDL_Surface *menuentryimages[2][3]; // [PRESSED][Left|Center|Right] +extern SDL_Surface *menu_players[MAX_PLAYERS]; // holds playergfx of a single frame +extern SDL_Surface *menu_stones[FT_max]; // hold a frame of every stone type + extern _menu *menu_new (char *title, int x, int y); extern void menu_delete (_menu *menu); extern int menu_getlastitem (_menuitem *first); diff --git a/src/configuration.c b/src/configuration.c index 5dfda89..f665f18 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -1,4 +1,4 @@ -/* $Id: configuration.c,v 1.63 2004/09/12 20:54:24 stpohle Exp $ +/* $Id: configuration.c,v 1.64 2004/09/25 10:57:51 stpohle Exp $ * configuration */ #include @@ -14,6 +14,42 @@ #include "keyb.h" #include "player.h" + +/* + * try to find the datapath and set the variable bman.datapath + * test: 1) PACKAGE_DATA_DIR + * 2) ./data + * 3) ../data + */ +void config_get_datapath () { + FILE *f; + char filename[255]; + + sprintf (bman.datapath, PACKAGE_DATA_DIR); + sprintf (filename, "%s/gfx/logo.png", bman.datapath); + f = fopen (filename, "r"); + + if (!f) { + sprintf (bman.datapath, "data"); + sprintf (filename, "%s/gfx/logo.png", bman.datapath); + f = fopen (filename, "r"); + if (!f) { + sprintf (bman.datapath, "../data"); + sprintf (filename, "%s/gfx/logo.png", bman.datapath); + f = fopen (filename, "r"); + if (!f) { + printf ("Can't find Datafiles.\n"); + exit (1); + } + } + } + fclose (f); +} + + +/* + * reset all variables and load all configs. + */ void config_init (int argc, char **argv) { @@ -21,13 +57,10 @@ config_init (int argc, char **argv) char text[255], icon[255]; int i, j; + config_get_datapath (); + srand (((int) time (NULL))); // initialize randomgenerator - for (i = 0; i < MAX_PLAYERS; i++) { - players[i].gfx = NULL; /* we will select them in the wait_for_players loop */ - players[i].gfx_nr = -1; /* and even now in the singleplayer menu */ - players[i].team_nr = -1; /* delete team assignment */ - } for (i = 0; i < MAX_TEAMS; i++) { sprintf (teams[i].name, "Team %d", i+1); for (j = 0; j < MAX_PLAYERS; j++) @@ -63,13 +96,13 @@ config_init (int argc, char **argv) gfx.res.x = 640; gfx.res.y = 480; gfx.bpp = 16; + gfx.players = NULL; bman.password[0] = 0; bman.passwordenabled = 0; map.tileset[0] = 0; map.random_tileset = 1; map.size.x = 25; map.size.y = 17; - sprintf (bman.datapath, PACKAGE_DATA_DIR); map.map[0] = 0; map.map_selection = 2; map.type = -1; diff --git a/src/game.c b/src/game.c index f4ea58c..5093b58 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.90 2004/09/13 22:15:57 stpohle Exp $ +/* $Id: game.c,v 1.91 2004/09/25 10:57:51 stpohle Exp $ game.c - procedures for the game. */ #include @@ -55,15 +55,15 @@ game_draw_info () if ((players[i].state & PSFM_used) != 0) { if (players[i].gfx_nr != -1 && PS_IS_used (players[i].state)) { - src.x = 3 * players[i].gfx->smal_size.x; + src.x = 3 * players[i].gfx->small_image->w; src.y = 0; - src.w = dest.w = players[i].gfx->smal_size.x; - src.h = dest.h = players[i].gfx->smal_size.y; + src.w = dest.w = players[i].gfx->small_image->w; + src.h = dest.h = players[i].gfx->small_image->h; dest.x = x; dest.y = j - 4; - SDL_BlitSurface (players[i].gfx->smal_image, &src, gfx.screen, &dest); + SDL_BlitSurface (players[i].gfx->small_image, &src, gfx.screen, &dest); } sprintf (scrtext, "%10s:%2d", players[i].name, players[i].points); @@ -97,10 +97,10 @@ game_draw_info () if (players[bman.p_nr].special.type != 0) { dest.x = x - 32; dest.y = 16; - dest.w = gfx.smal_special[players[bman.p_nr].special.type - 1]->w; - dest.h = gfx.smal_special[players[bman.p_nr].special.type - 1]->h; + dest.w = gfx.menu_field[players[bman.p_nr].special.type - 1]->w; + dest.h = gfx.menu_field[players[bman.p_nr].special.type - 1]->h; - SDL_BlitSurface (gfx.smal_special[players[bman.p_nr].special.type - 1], NULL, + SDL_BlitSurface (gfx.menu_field[players[bman.p_nr].special.type - 1], NULL, gfx.screen, &dest); } @@ -429,7 +429,6 @@ void game_showresult () { dest.x = dest.y = 0; dest.w = gfx.res.x; dest.h = gfx.res.y; - gfx_load_players (40, 40); draw_logo (); strcpy (text, "Game Result"); @@ -499,7 +498,6 @@ void game_showresult () { gfx_blitdraw (); SDL_Flip (gfx.screen); - gfx_free_players (); while (!done && bman.state != GS_quit) { /* do the keyboard handling */ diff --git a/src/gfx.c b/src/gfx.c index 7ea25e6..0850da0 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,4 +1,4 @@ -/* $Id: gfx.c,v 1.36 2004/09/12 20:54:24 stpohle Exp $ */ +/* $Id: gfx.c,v 1.37 2004/09/25 10:57:51 stpohle Exp $ */ /* gfx.c */ #include "bomberclone.h" @@ -6,7 +6,34 @@ _gfx gfx; -#define __smalsizeX 12 +static int gfx_get_nr_of_playergfx (); +static void gfx_load_menusmall_players (); +static void gfx_load_fieldtype_menu (); + +/* + * count all playergfx + */ +static int gfx_get_nr_of_playergfx () { + int i = 0; + FILE *f = NULL; + char filename[255]; + + do { + if (f) { + fclose (f); + i++; + } + sprintf (filename, "%s/player/player%d.png", bman.datapath, i); + f = fopen (filename, "r"); + } while (f); + + return i; +} + + +/* + * Load all players graphics we have + */ void gfx_load_players (int sx, int sy) { @@ -14,31 +41,26 @@ gfx_load_players (int sx, int sy) ssfkt; char filename[255]; int i, - j, r, g, b; SDL_Surface *tmpimage, *tmpimage1; sfkt = ((float) sx) / ((float) GFX_IMGSIZE); - ssfkt = ((float) __smalsizeX) / ((float) GFX_IMGSIZE); + ssfkt = ((float) GFX_SMALLPLAYERIMGSIZE_X) / ((float) GFX_IMGSIZE); + d_printf ("gfx_load_players (%d, %d)\n", sx, sy); + /* loading the player images */ - for (j = i = 0; i < MAX_PLAYERS; i++) { - sprintf (filename, "%s/player/player%d.png", bman.datapath, j); - j++; + for (i = 0; i < gfx.player_gfx_count; i++) { + sprintf (filename, "%s/player/player%d.png", bman.datapath, i); tmpimage = IMG_Load (filename); if (tmpimage == NULL) { - if (j == 0) { // try again with the first image, if this don't work give up. - printf ("Can't load image: %s\n", SDL_GetError ()); - exit (1); - } - i--; // load the this image again - j = 0; - } - + printf ("Can't load image: %s\n", SDL_GetError ()); + exit (1); + } + else { - /* load the game player image */ gfx.players[i].ani.h = sy * 2; gfx.players[i].ani.w = (tmpimage->w / 4) * sfkt; @@ -55,18 +77,7 @@ gfx_load_players (int sx, int sy) gfx.players[i].offset.x = (sx - gfx.players[i].ani.w) / 2; gfx.players[i].offset.y = -sy; - /* load the smal image */ - gfx.players[i].smal_size.y = __smalsizeX * 2; - gfx.players[i].smal_size.x = (tmpimage->w / 4) * ssfkt; - tmpimage1 = - scale_image (tmpimage, gfx.players[i].smal_size.x * 4, - gfx.players[i].ani.frames * gfx.players[i].smal_size.y); - getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); - gfx.players[i].smal_image = SDL_DisplayFormat (tmpimage1); - SDL_FreeSurface (tmpimage1); SDL_FreeSurface (tmpimage); - } } @@ -129,13 +140,12 @@ gfx_free_players () { int i; - for (i = 0; i < MAX_PLAYERS; i++) { + d_printf ("gfx_free_players\n"); + + for (i = 0; i < gfx.player_gfx_count; i++) { if (gfx.players[i].ani.image != NULL) SDL_FreeSurface (gfx.players[i].ani.image); gfx.players[i].ani.image = NULL; - if (gfx.players[i].smal_image != NULL) - SDL_FreeSurface (gfx.players[i].smal_image); - gfx.players[i].smal_image = NULL; } if (gfx.dead.image != NULL) @@ -151,6 +161,8 @@ gfx_free_players () void gfx_init () { + int i; + if (gfx.fullscreen) gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp, @@ -165,11 +177,24 @@ gfx_init () return; } SDL_ShowCursor (SDL_DISABLE); + + /* delete small gfx und the menu player gfx */ + gfx.player_gfx_count = gfx_get_nr_of_playergfx(); + gfx.players = malloc (gfx.player_gfx_count * sizeof (_gfxplayer)); + for (i = 0; i < gfx.player_gfx_count; i++) { + gfx.players[i].ani.image = NULL; + gfx.players[i].small_image = NULL; + gfx.players[i].menu_image = NULL; + } + + for (i = 0; i < FT_max; i++) gfx.menu_field[i] = NULL; + gfx_blitupdaterectclear (); gfx_loaddata (); }; + void gfx_loaddata () { @@ -182,18 +207,8 @@ gfx_loaddata () sprintf (filename, "%s/gfx/logo.png", bman.datapath); tmpimage = IMG_Load (filename); if (tmpimage == NULL) { - sprintf (bman.datapath, "data"); - sprintf (filename, "%s/gfx/logo.png", bman.datapath); - tmpimage = IMG_Load (filename); - if (tmpimage == NULL) { - sprintf (bman.datapath, "../data"); - sprintf (filename, "%s/gfx/logo.png", bman.datapath); - tmpimage = IMG_Load (filename); - if (tmpimage == NULL) { - printf ("Can't load image: %s\n", SDL_GetError ()); - exit (1); - } - } + printf ("Can't load image: %s\n", SDL_GetError ()); + exit (1); } tmpimage1 = scale_image (tmpimage, gfx.res.x, gfx.res.y); SDL_FreeSurface (tmpimage); @@ -263,9 +278,185 @@ gfx_loaddata () exit (1); } gfx.menuselect.frames = tmpimage->h / (2 * GFX_IMGSIZE); + + gfx_load_fieldtype_menu (); + gfx_load_menusmall_players (); }; +/*** + * load a single frame of the player + */ +static void gfx_load_menusmall_players () { + SDL_Surface *orgimg, *tmpimg; + int i, r, g, b; + float sfkt; + char filename[255]; + + for (i = 0; i < gfx.player_gfx_count; i++) { + if (gfx.players[i].small_image == NULL || gfx.players[i].menu_image == NULL) { + SDL_Surface *img; + SDL_Rect rect; + + sprintf (filename, "%s/player/player%d.png", bman.datapath, i); + orgimg = IMG_Load (filename); + if (orgimg == NULL) { + printf ("Can't load image: %s\n", SDL_GetError ()); + exit (1); + } + rect.x = 3 * (orgimg->w/4); + rect.y = 0; + rect.w = orgimg->w/4; + rect.h = GFX_PLAYERIMGSIZE_Y; + img = gfx_copyfrom (orgimg, &rect); + + SDL_FreeSurface (orgimg); + + /* small image */ + sfkt = (float)(((float)(GFX_SMALLPLAYERIMGSIZE_X * 2)) / ((float)img->h)); + if (gfx.players[i].small_image == NULL) { + tmpimg = scale_image (img, (int)(((float)img->w)*sfkt), GFX_SMALLPLAYERIMGSIZE_X * 2); + getRGBpixel (tmpimg, 0, 0, &r, &g, &b); + SDL_SetColorKey (tmpimg, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimg->format, r, g, b)); + gfx.players[i].small_image = SDL_DisplayFormat (tmpimg); + SDL_FreeSurface (tmpimg); + } + /* menu image */ + sfkt = (float)(((float)(GFX_MENUPLAYERIMGSIZE_X * 2)) / ((float)img->h)); + if (gfx.players[i].menu_image == NULL) { + tmpimg = scale_image (img, (int)(((float)img->w)*sfkt), GFX_MENUPLAYERIMGSIZE_X * 2); + getRGBpixel (tmpimg, 0, 0, &r, &g, &b); + SDL_SetColorKey (tmpimg, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimg->format, r, g, b)); + gfx.players[i].menu_image = SDL_DisplayFormat (tmpimg); + SDL_FreeSurface (tmpimg); + } + SDL_FreeSurface (img); + } + } +} + + + +/*** + * load a single frame from the powerups + */ +static void gfx_load_fieldtype_menu () { + int i, ft, r, g, b; + SDL_Surface *background = NULL, *orgimg = NULL, *tmpimg = NULL; + char filename[255]; + SDL_Rect rect; + + for (i = 0; i < FT_max; i++) { + if (gfx.menu_field[i]!=NULL) SDL_FreeSurface (gfx.menu_field[i]); + gfx.menu_field[i] = NULL; + } + + rect.x = 0; + rect.y = 0; + rect.w = GFX_IMGSIZE; + rect.h = GFX_IMGSIZE; + + for (ft = 0; ft < FT_max; ft++) if (ft != FT_mixed) { + /* + * load background image + */ + if (ft == 0) { + if (background != NULL) SDL_FreeSurface (background); + sprintf (filename, "%s/tileset/default/background.png", bman.datapath); + orgimg = IMG_Load (filename); + if (!orgimg) { + printf ("Can't load image. :%s\n", SDL_GetError ()); + exit (1); + } + + tmpimg = gfx_copyfrom (orgimg, &rect); + SDL_FreeSurface (orgimg); + orgimg = scale_image (tmpimg, GFX_IMGSIZE/2, GFX_IMGSIZE/2); + SDL_FreeSurface (tmpimg); + background = SDL_DisplayFormat (orgimg); + SDL_FreeSurface (orgimg); + } + + if (ft == FT_death) { + if (background != NULL) SDL_FreeSurface (background); + sprintf (filename, "%s/tileset/default/powerbad.png", bman.datapath); + orgimg = IMG_Load (filename); + if (!orgimg) { + printf ("Can't load image. :%s\n", SDL_GetError ()); + exit (1); + } + + tmpimg = gfx_copyfrom (orgimg, &rect); + SDL_FreeSurface (orgimg); + orgimg = scale_image (tmpimg, GFX_IMGSIZE/2, GFX_IMGSIZE/2); + SDL_FreeSurface (tmpimg); + background = SDL_DisplayFormat (orgimg); + SDL_FreeSurface (orgimg); + } + + if (ft == FT_fire) { + if (background != NULL) SDL_FreeSurface (background); + sprintf (filename, "%s/tileset/default/powerup.png", bman.datapath); + orgimg = IMG_Load (filename); + if (!orgimg) { + printf ("Can't load image. :%s\n", SDL_GetError ()); + exit (1); + } + + tmpimg = gfx_copyfrom (orgimg, &rect); + SDL_FreeSurface (orgimg); + orgimg = scale_image (tmpimg, GFX_IMGSIZE/2, GFX_IMGSIZE/2); + SDL_FreeSurface (tmpimg); + background = SDL_DisplayFormat (orgimg); + SDL_FreeSurface (orgimg); + } + + if (ft == FT_sp_trigger) { + if (background != NULL) SDL_FreeSurface (background); + sprintf (filename, "%s/tileset/default/powersp.png", bman.datapath); + orgimg = IMG_Load (filename); + if (!orgimg) { + printf ("Can't load image. :%s\n", SDL_GetError ()); + exit (1); + } + + tmpimg = gfx_copyfrom (orgimg, &rect); + SDL_FreeSurface (orgimg); + orgimg = scale_image (tmpimg, GFX_IMGSIZE/2, GFX_IMGSIZE/2); + SDL_FreeSurface (tmpimg); + background = SDL_DisplayFormat (orgimg); + SDL_FreeSurface (orgimg); + } + + /* + * load fieldgfx for the menu + */ + gfx.menu_field[ft] = gfx_copyfrom (background, &rect); + sprintf (filename, "%s/tileset/default/%s.png", bman.datapath, ft_filenames[ft]); + + orgimg = IMG_Load (filename); + if (!orgimg) { + printf ("Can't load image. :%s\n", SDL_GetError ()); + exit (1); + } + + tmpimg = gfx_copyfrom (orgimg, &rect); + SDL_FreeSurface (orgimg); + orgimg = scale_image (tmpimg, GFX_IMGSIZE/2, GFX_IMGSIZE/2); + SDL_FreeSurface (tmpimg); + getRGBpixel (orgimg, 0, 0, &r, &g, &b); + SDL_SetColorKey (orgimg, SDL_SRCCOLORKEY, SDL_MapRGB (orgimg->format, r, g, b)); + tmpimg = SDL_DisplayFormat (orgimg); + SDL_FreeSurface (orgimg); + SDL_BlitSurface (tmpimg, NULL, gfx.menu_field[ft], NULL); + SDL_FreeSurface (tmpimg); + } + + if (background) + SDL_FreeSurface (background); +} + + void gfx_shutdown () { @@ -280,14 +471,29 @@ gfx_shutdown () } for (j = 0; j < 2; j++) SDL_FreeSurface (menulistimages[j][i]); - } + for (i = 0; i < gfx.player_gfx_count; i++) { + if (gfx.players[i].small_image != NULL) { + SDL_FreeSurface (gfx.players[i].small_image); + gfx.players[i].small_image = NULL; + } + if (gfx.players[i].menu_image != NULL) { + SDL_FreeSurface (gfx.players[i].menu_image); + gfx.players[i].menu_image = NULL; + } + } + + for (i = 0; i < FT_max; i++) if (gfx.menu_field[i] != NULL) { + SDL_FreeSurface (gfx.menu_field[i]); + gfx.menu_field[i] = NULL; + } + SDL_FreeSurface (gfx.logo); SDL_FreeSurface (gfx.menuselect.image); gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, 16, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_FreeSurface (gfx.screen); - + font_free(); }; diff --git a/src/gfxengine.c b/src/gfxengine.c index ca7345b..75894ab 100644 --- a/src/gfxengine.c +++ b/src/gfxengine.c @@ -1,4 +1,4 @@ -/* $Id: gfxengine.c,v 1.4 2004/01/06 19:52:02 stpohle Exp $ */ +/* $Id: gfxengine.c,v 1.5 2004/09/25 10:57:51 stpohle Exp $ */ /* GFX Game Engine */ #include "bomberclone.h" @@ -8,7 +8,6 @@ static _gfxblit *blitdb; /* unsorted list of blitdb's */ static _gfxblit **sortblitdb; /* sorted list of blitdb's */ static SDL_Rect *blitrects; /* SDLUpdate Rects */ - /* alloc all needed space */ void gfxengine_init () { blitdb = malloc (sizeof (_gfxblit)* MAX_BLITRECTS); diff --git a/src/gfxpixelimage.c b/src/gfxpixelimage.c index 3fcd990..982fd72 100644 --- a/src/gfxpixelimage.c +++ b/src/gfxpixelimage.c @@ -1,4 +1,4 @@ -/* $Id: gfxpixelimage.c,v 1.10 2004/02/01 03:39:02 stpohle Exp $ */ +/* $Id: gfxpixelimage.c,v 1.11 2004/09/25 10:57:51 stpohle Exp $ */ /* gfx pixel manipulation and image manipulation */ #include "bomberclone.h" @@ -484,21 +484,21 @@ gfx_quater_image (SDL_Surface * org1, SDL_Surface * org2, SDL_Surface * org3, SD }; -/* save a part of a screen so we can restore it later */ -SDL_Surface * -gfx_copyscreen (SDL_Rect * wnd) -{ +/* + * part of a surface from one to another with the same format + */ +SDL_Surface *gfx_copyfrom (SDL_Surface *img, SDL_Rect *wnd) { SDL_Surface *res; SDL_Rect dest; res = - SDL_CreateRGBSurface (SDL_HWSURFACE, wnd->w, wnd->h, gfx.screen->format->BitsPerPixel, - gfx.screen->format->Rmask, gfx.screen->format->Gmask, - gfx.screen->format->Bmask, gfx.screen->format->Amask); + SDL_CreateRGBSurface (SDL_HWSURFACE, wnd->w, wnd->h, img->format->BitsPerPixel, + img->format->Rmask, img->format->Gmask, + img->format->Bmask, img->format->Amask); dest.x = 0; dest.y = 0; dest.w = wnd->w; dest.h = wnd->h; - SDL_BlitSurface (gfx.screen, wnd, res, &dest); + SDL_BlitSurface (img, wnd, res, &dest); return res; }; diff --git a/src/main.c b/src/main.c index 4edc3c0..df34a6f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.27 2004/09/12 20:54:24 stpohle Exp $ */ +/* $Id: main.c,v 1.28 2004/09/25 10:57:51 stpohle Exp $ */ #include "basic.h" #include "bomberclone.h" @@ -27,7 +27,7 @@ main (int argc, char **argv) players = malloc (sizeof (_player) * MAX_PLAYERS); teams = malloc (sizeof (_team) * MAX_TEAMS); gfxengine_init (); - + if (SDL_Init (SDL_INIT_VIDEO| SDL_INIT_NOPARACHUTE) != 0) { d_printf ("Unable to init SDL: %s\n", SDL_GetError ()); return (1); diff --git a/src/multiwait.c b/src/multiwait.c index 0b3fba6..3145395 100644 --- a/src/multiwait.c +++ b/src/multiwait.c @@ -1,4 +1,4 @@ -/* $Id: multiwait.c,v 1.44 2004/09/12 22:12:02 stpohle Exp $ +/* $Id: multiwait.c,v 1.45 2004/09/25 10:57:51 stpohle Exp $ multiwait.c - this manages only the network screen where everyone have to select it's players and where even the basic chat is inside */ @@ -31,7 +31,6 @@ mw_init () menu_displaytext ("Please Wait", "Loading GFX Data"); - gfx_load_players (32, 32); network_loop (); mw_num_readyplayers = 0; bman.updatestatusbar = 1; @@ -58,8 +57,6 @@ void mw_shutdown () { gfx_blitdraw (); draw_logo (); - gfx_free_players (); - SDL_Flip (gfx.screen); }; @@ -103,11 +100,11 @@ void mw_draw_player (_player *player, int pos) { /* player is used and selected a gfx */ dest.x = p.x; dest.y = p.y + (MW_PLAYERSCR_Y - GFX_IMGSIZE) / 2; - src.w = dest.w = gfx.players[player->gfx_nr].ani.w; - src.h = dest.h = gfx.players[player->gfx_nr].ani.h; - src.x = down * gfx.players[player->gfx_nr].ani.w; + src.w = dest.w = gfx.players[player->gfx_nr].menu_image->w; + src.h = dest.h = gfx.players[player->gfx_nr].menu_image->h; + src.x = 0; src.y = 0; - gfx_blit (gfx.players[player->gfx_nr].ani.image, &src, gfx.screen, &dest, 10001); + gfx_blit (gfx.players[player->gfx_nr].menu_image, &src, gfx.screen, &dest, 10001); } font_gfxdraw (p.x + GFX_IMGSIZE, p.y, player->name, 2, COLOR_yellow, 10002); diff --git a/src/network.c b/src/network.c index 894ac71..5124e4a 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,4 @@ -/* $Id: network.c,v 1.65 2004/09/23 13:12:15 stpohle Exp $ */ +/* $Id: network.c,v 1.66 2004/09/25 10:57:51 stpohle Exp $ */ /* network routines. */ @@ -307,15 +307,15 @@ draw_netupdatestate (char st) redraw_logo (0, y, gfx.res.x, y + 50); if (players[i].gfx_nr != -1) { - dest.w = src.w = players[i].gfx->smal_size.x; - dest.h = src.h = players[i].gfx->smal_size.y; - src.x = players[i].gfx->smal_size.x * down; + dest.w = src.w = players[i].gfx->small_image->w; + dest.h = src.h = players[i].gfx->small_image->h; + src.x = players[i].gfx->small_image->w * down; src.y = 0; dest.x = 50; dest.y = y; - SDL_BlitSurface (players[i].gfx->smal_image, &src, gfx.screen, &dest); + SDL_BlitSurface (players[i].gfx->small_image, &src, gfx.screen, &dest); gfx_blitupdaterectadd (&dest); } diff --git a/src/playermenu.c b/src/playermenu.c index e80912a..40433cc 100644 --- a/src/playermenu.c +++ b/src/playermenu.c @@ -1,4 +1,4 @@ -/* $Id: playermenu.c,v 1.6 2004/09/23 14:06:48 stpohle Exp $ +/* $Id: playermenu.c,v 1.7 2004/09/25 10:57:51 stpohle Exp $ * */ @@ -15,14 +15,14 @@ /* * prototype definitions */ -static int playermenu_gfxaviable (int gfx); +// static int playermenu_gfxaviable (int gfx); static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu); #define PLAYERMENU_GFXSEL_Y 130 /* * check if the gfx is still aviable - */ + * static int playermenu_gfxaviable (int gfx) { int i; @@ -32,17 +32,15 @@ static int playermenu_gfxaviable (int gfx) { return 0; }; - + * + * **** DO WE NEED THIS? + */ /* - * draw a list of all stil aviable players and the - * selection border of where we are at the moment - * ! menu == NULL, in this case just delete the gfx_aviable - * buffer to force an repaint of all gfx. + * show the basis menu */ static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu) { - static int gfx_aviable[2][MAX_PLAYERS]; // old and new state, 1 if gfx is aviable static int old_gfxsel = -1; static int changed = 0; SDL_Rect rect, srcrect; @@ -52,36 +50,13 @@ static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu) { * delete old state, to force an update of all playergfx */ if (menu == NULL) { - for (i = 0; i < MAX_PLAYERS; i++) - gfx_aviable[1][i] = -1; changed = 1; return; } - - /* - * check changes in the playerselections - * 1. copy current state into the old state and set all - * gfx as aviable. - */ - for (i = 0; i < MAX_PLAYERS; i++) { - gfx_aviable[0][i] = gfx_aviable[1][i] & 1; - gfx_aviable[1][i] = 1; - } - /* - * 2. delete the aviable flag from all selected player gfx - * set another bit to mark our selection, set the changedc flag if - * there was any change - */ - for (i = 0; i < MAX_PLAYERS; i++) { - if (PS_IS_used (players[i].state) && players[i].gfx_nr >= 0 && players[i].gfx_nr < MAX_PLAYERS) - gfx_aviable[1][players[i].gfx_nr] = 0; - } - for (i = 0; i < MAX_PLAYERS && changed == 0; i++) if (players[i].gfx_nr >= 0) changed = 1; - if (selgfx >= 0 && selgfx < MAX_PLAYERS) // do the selection - gfx_aviable[1][selgfx] += 2; if (selgfx != old_gfxsel) changed = 1; old_gfxsel = selgfx; + /* * 3. draw changes from the last loop */ @@ -92,36 +67,141 @@ static void playermenu_selgfx_drawplayer (int selgfx, _menu *menu) { rect.h = 4 * GFX_IMGSIZE; menu_draw_background (menu, &rect); - for (i = 0; i < MAX_PLAYERS; i++) { - srcrect.h = rect.h = gfx.players[i].ani.h; - srcrect.w = rect.w = gfx.players[i].ani.w; - rect.x = GFX_IMGSIZE * (i % 4) + ((menu->oldscreenpos.w - 2 * menuimages[0]->w) -(4 * GFX_IMGSIZE)) / 2 ; - rect.y = GFX_IMGSIZE * (i / 4) + PLAYERMENU_GFXSEL_Y; - if (gfx_aviable[1][i] & 1) { - /* gfx is aviable */ - srcrect.x = gfx.players[i].ani.w * down; - srcrect.y = 0; - rect.x += menu->oldscreenpos.x + menuimages[0]->w; - rect.y += menu->oldscreenpos.y + menuimages[0]->h; - gfx_blit (gfx.players[i].ani.image, &srcrect, gfx.screen, &rect, 10002); - } - if (gfx_aviable[1][i] & 2) { - /* draw the select border */ + for (i = 0; i < gfx.player_gfx_count; i++) { + srcrect.h = rect.h = gfx.players[i].menu_image->h; + srcrect.w = rect.w = gfx.players[i].menu_image->w; + rect.x = (2 * GFX_MENUPLAYERIMGSIZE_X) * (i % 4) + ((menu->oldscreenpos.w - 2 * menuimages[0]->w) - (8 * GFX_MENUPLAYERIMGSIZE_X)) / 2; + rect.y = (GFX_MENUPLAYERIMGSIZE_X * 2) * (i / 4) + PLAYERMENU_GFXSEL_Y; + srcrect.x = 0; + srcrect.y = 0; + rect.x += menu->oldscreenpos.x + menuimages[0]->w; + rect.y += menu->oldscreenpos.y + menuimages[0]->h; + gfx_blit (gfx.players[i].menu_image, &srcrect, gfx.screen, &rect, 10002); + + /* draw the select border */ + if (i == selgfx) { srcrect.x = 0; srcrect.y = 0; srcrect.h = rect.h = GFX_IMGSIZE; srcrect.w = rect.w = GFX_IMGSIZE; rect.x = GFX_IMGSIZE * (i % 4) + ((menu->oldscreenpos.w - 2 * menuimages[0]->w) -(4 * GFX_IMGSIZE)) / 2; rect.y = GFX_IMGSIZE * (i / 4) + PLAYERMENU_GFXSEL_Y; - rect.x += (gfx.players[i].ani.w - gfx.menuselect.image->w) / 2; // center the playergfx + rect.x += (gfx.players[i].menu_image->w - gfx.menuselect.image->w) / 2; // center the playergfx rect.x += menu->oldscreenpos.x + menuimages[0]->w; rect.y += menu->oldscreenpos.y + menuimages[0]->h; - gfx_blit (gfx.menuselect.image, &srcrect, gfx.screen, &rect, 10001); + gfx_blit (gfx.menuselect.image, &srcrect, gfx.screen, &rect, 10001); } } } } +/* + * draw a small menu where the player has to select his gfx + */ +int playermenu_selgfx (int pl_nr) { + _menu *menu; + int selgfx, eventstate; + SDL_Event event; + Uint8 *keys; + int done = 0; + + if (pl_nr < 0 || pl_nr >= MAX_PLAYERS) + return -1; + + selgfx = players[pl_nr].gfx_nr; + if (selgfx < 0) + selgfx = 1; + + playermenu_selgfx_drawplayer (-1, NULL); + player_set_gfx (&players[pl_nr], -1); + + menu = menu_new ("Player Selection", 400, 270); + menu_create_text (menu, "playergfxsel", -1, 50, 40, 5, COLOR_yellow, "%s, please select your Player and press ENTER/RETURN or press ESCAPE for no player (that means you will only watch the next game).", players[pl_nr].name); + + menu->looprunning = 1; + menu_draw (menu); + + + while (!done && bman.state != GS_quit) { + /* do the network loop if we have to */ + if (bman.sock > 0) { + network_loop (); + if (bman.notifygamemaster) + ogc_loop (); + } + + eventstate = SDL_PollEvent (&event); + + if (eventstate) { + switch (event.type) { + case (SDL_QUIT): + bman.state = GS_quit; + done = 1; + menu_delete (menu); + return -1; + break; + case (SDL_KEYDOWN): + /* + * go to the next gfx or the preview one + */ + if (event.key.keysym.sym == SDLK_TAB) { + keys = SDL_GetKeyState (NULL); + if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) { + if ((--selgfx) < 0) + selgfx = gfx.player_gfx_count-1; + } + else { + if ((++selgfx) >= gfx.player_gfx_count) + selgfx = 0; + } + break; + } + /* + * cursor keys for gfx selection + */ + if (event.key.keysym.sym == SDLK_UP && selgfx >= 4) + selgfx -= 4; + if (event.key.keysym.sym == SDLK_DOWN && selgfx < MAX_PLAYERS-4) + selgfx += 4; + if (event.key.keysym.sym == SDLK_RIGHT && selgfx < MAX_PLAYERS-1) + selgfx++; + if (event.key.keysym.sym == SDLK_LEFT && selgfx > 0) + selgfx--; + /* + * do not select any gfx + */ + else if (event.key.keysym.sym == SDLK_ESCAPE) { + selgfx = -1; + done = 2; + break; + } + /* + * select the current gfx if aviable + */ + else if (event.key.keysym.sym == SDLK_RETURN + || event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL + || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_drop] || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_special] + || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_max + BCPK_drop] || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_max + BCPK_special]) { + done = 1; + break; + } + } + } + + playermenu_selgfx_drawplayer (selgfx, menu); + gfx_blitdraw (); + + s_calctimesync (); + }; + menu_delete (menu); + player_set_gfx (&players[pl_nr], selgfx); + if (done == 2) + return -1; + + return 0; +}; + + /* @@ -288,114 +368,6 @@ void playermenu_getflags (char *text, _player *player) { }; -/* - * draw a small menu where the player has to select his gfx - */ -int playermenu_selgfx (int pl_nr) { - _menu *menu; - int selgfx, eventstate; - SDL_Event event; - Uint8 *keys; - int done = 0; - - if (pl_nr < 0 || pl_nr >= MAX_PLAYERS) - return -1; - - selgfx = players[pl_nr].gfx_nr; - if (selgfx < 0) - selgfx = 1; - - playermenu_selgfx_drawplayer (-1, NULL); - player_set_gfx (&players[pl_nr], -1); - - menu = menu_new ("Player Selection", 400, 270); - menu_create_text (menu, "playergfxsel", -1, 50, 40, 5, COLOR_yellow, "%s, please select your Player and press ENTER/RETURN or press ESCAPE for no player (that means you will only watch the next game).", players[pl_nr].name); - - menu->looprunning = 1; - menu_draw (menu); - - - while (!done && bman.state != GS_quit) { - /* do the network loop if we have to */ - if (bman.sock > 0) { - network_loop (); - if (bman.notifygamemaster) - ogc_loop (); - } - - eventstate = SDL_PollEvent (&event); - - if (eventstate) { - switch (event.type) { - case (SDL_QUIT): - bman.state = GS_quit; - done = 1; - menu_delete (menu); - return -1; - break; - case (SDL_KEYDOWN): - /* - * go to the next gfx or the preview one - */ - if (event.key.keysym.sym == SDLK_TAB) { - keys = SDL_GetKeyState (NULL); - if (keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) { - if ((--selgfx) < 0) - selgfx = MAX_PLAYERS-1; - } - else { - if ((++selgfx) >= MAX_PLAYERS) - selgfx = 0; - } - break; - } - /* - * cursor keys for gfx selection - */ - if (event.key.keysym.sym == SDLK_UP && selgfx >= 4) - selgfx -= 4; - if (event.key.keysym.sym == SDLK_DOWN && selgfx < MAX_PLAYERS-4) - selgfx += 4; - if (event.key.keysym.sym == SDLK_RIGHT && selgfx < MAX_PLAYERS-1) - selgfx++; - if (event.key.keysym.sym == SDLK_LEFT && selgfx > 0) - selgfx--; - /* - * do not select any gfx - */ - else if (event.key.keysym.sym == SDLK_ESCAPE) { - selgfx = -1; - done = 2; - break; - } - /* - * select the current gfx if aviable - */ - else if (event.key.keysym.sym == SDLK_RETURN - || event.key.keysym.sym == SDLK_LCTRL || event.key.keysym.sym == SDLK_RCTRL - || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_drop] || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_special] - || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_max + BCPK_drop] || event.key.keysym.sym == keyb_gamekeys.keycode[BCPK_max + BCPK_special]) { - if (playermenu_gfxaviable (selgfx)) - done = 1; - break; - } - } - } - - playermenu_selgfx_drawplayer (selgfx, menu); - gfx_blitdraw (); - - s_calctimesync (); - }; - menu_delete (menu); - player_set_gfx (&players[pl_nr], selgfx); - if (done == 2) - return -1; - - return 0; -}; - - /* * teammenu: Teamplay menuselection * Show and edit all teams and the players. diff --git a/src/single.c b/src/single.c index c9d8fcd..f8ababa 100644 --- a/src/single.c +++ b/src/single.c @@ -1,4 +1,4 @@ -/* $Id: single.c,v 1.70 2004/09/23 13:21:44 stpohle Exp $ */ +/* $Id: single.c,v 1.71 2004/09/25 10:57:51 stpohle Exp $ */ /* single player */ #include "basic.h" @@ -623,7 +623,6 @@ single_playergame (int second_player, int ai_players) } strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME); - gfx_load_players (32, 32); do { done = playermenu_selgfx (bman.p_nr); } while (players[bman.p_nr].gfx_nr == -1 && done != -1); @@ -637,7 +636,6 @@ single_playergame (int second_player, int ai_players) done = playermenu_selgfx (bman.p2_nr); } while (players[bman.p2_nr].gfx_nr == -1 && done != -1); } - gfx_free_players (); if (done == -1) return; diff --git a/src/tileset.c b/src/tileset.c index e381daa..eb2006d 100644 --- a/src/tileset.c +++ b/src/tileset.c @@ -1,10 +1,29 @@ -/* $Id: tileset.c,v 1.14 2004/02/07 13:35:28 stpohle Exp $ */ +/* $Id: tileset.c,v 1.15 2004/09/25 10:57:51 stpohle Exp $ */ /* load and select tilesets */ #include "bomberclone.h" extern int UpdateRects_nr; +const char *ft_filenames[] = { + "background", + "stone", + "block", + "tunnel" , + "pwdeath", + "pwbomb", + "pwfire", + "pwshoe", + NULL, + "sptrigger", + "sprow", + "sppush", + "spmoved", + "spliquid", + "spkick" +}; + + /* load a random tileset */ void tileset_random () @@ -168,61 +187,17 @@ tileset_load (char *tilesetname, int dx, int dy) } /* loading the field images */ for (i = 0; i < FT_max; i++) { - switch (i) { - case (FT_nothing): - sprintf (filename, "background"); - break; - case (FT_stone): - sprintf (filename, "stone"); - break; - case (FT_block): - sprintf (filename, "block"); - break; - case (FT_tunnel): - sprintf (filename, "tunnel"); - break; - case (FT_death): - sprintf (filename, "pwdeath"); - break; - case (FT_bomb): - sprintf (filename, "pwbomb"); - break; - case (FT_fire): - sprintf (filename, "pwfire"); - break; - case (FT_shoe): - sprintf (filename, "pwshoe"); - break; - case (FT_sp_trigger): - sprintf (filename, "sptrigger"); - break; - case (FT_sp_row): - sprintf (filename, "sprow"); - break; - case (FT_sp_push): - sprintf (filename, "sppush"); - break; - case (FT_sp_moved): - sprintf (filename, "spmoved"); - break; - case (FT_sp_liquid): - sprintf (filename, "spliquid"); - break; - case (FT_sp_kick): - sprintf (filename, "spkick"); - break; - } if (i != FT_mixed) { - sprintf (fullname, "%s/tileset/%s/%s.png", bman.datapath, tileset, filename); + sprintf (fullname, "%s/tileset/%s/%s.png", bman.datapath, tileset, ft_filenames[i]); gfx.field[i].w = GFX_IMGSIZE; gfx.field[i].h = GFX_IMGSIZE; tmpimage = IMG_Load (fullname); if (tmpimage == NULL) { - sprintf (fullname, "%s/tileset/%s/%s96.png", bman.datapath, tileset, filename); + sprintf (fullname, "%s/tileset/%s/%s96.png", bman.datapath, tileset, ft_filenames[i]); gfx.field[i].h = GFX_IMGBIGSIZE; tmpimage = IMG_Load (fullname); if (tmpimage == NULL) { - sprintf (fullname, "%s/tileset/default/%s.png", bman.datapath, filename); + sprintf (fullname, "%s/tileset/default/%s.png", bman.datapath, ft_filenames[i]); gfx.field[i].h = GFX_IMGSIZE; tmpimage = IMG_Load (fullname); if (tmpimage == NULL) { @@ -246,14 +221,6 @@ tileset_load (char *tilesetname, int dx, int dy) SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); gfx.field[i].image = SDL_DisplayFormat (tmpimage1); SDL_FreeSurface (tmpimage1); - if (i >= FT_sp_trigger && i < FT_max) { - // create the smal special thing - tmpimage1 = scale_image (tmpimage, 32, 32); - getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); - SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, - SDL_MapRGB (tmpimage1->format, r, g, b)); - gfx.smal_special[i - FT_sp_trigger] = SDL_DisplayFormat (tmpimage1); - } SDL_FreeSurface (tmpimage); } } @@ -269,11 +236,6 @@ tileset_free () if (gfx.field[i].image != NULL) SDL_FreeSurface (gfx.field[i].image); gfx.field[i].image = NULL; - if (i >= FT_sp_trigger && i < FT_max) { - if (gfx.smal_special[i - FT_sp_trigger] != NULL) - SDL_FreeSurface (gfx.smal_special[i - FT_sp_trigger]); - gfx.smal_special[i - FT_sp_trigger] = NULL; - } } if (gfx.bomb.image != NULL) SDL_FreeSurface (gfx.bomb.image);