diff --git a/ChangeLog b/ChangeLog index 7fcaf14..dcb9513 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ -$Id: ChangeLog,v 1.26 2003/07/13 00:36:09 stpohle Exp $ +$Id: ChangeLog,v 1.27 2003/07/22 18:29:07 stpohle Exp $ + +Version 0.9.10 +============== + +- maps have more options to set and it will be displayed in the + multiplayer menu, this options can be saved for every map seperated + Version 0.9.9 ============= diff --git a/TODO b/TODO index 06518d1..18fea66 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,10 @@ -$Id: TODO,v 1.11 2003/07/16 14:41:59 stpohle Exp $ +$Id: TODO,v 1.12 2003/07/22 18:29:07 stpohle Exp $ next version (0.9.10): ====================== - more specials (Kicking Bomb, Pushing Bomb Ver.2) -- maps will have more options to set and it will be displayed in the - multiplayer menu, this options can be saved for every map seperated - - Switch to enable/disable broadcasting chat messages to the bomberclone mserv diff --git a/bomberclone.prj b/bomberclone.prj index dc39c47..10f36c8 100644 --- a/bomberclone.prj +++ b/bomberclone.prj @@ -117,7 +117,9 @@ module.source.files=\ font.h\ map.c\ tileset.c\ - map.h + map.h\ + gfxpixelimage.c\ + gfxengine.c module.pixmap.name=pixmaps module.pixmap.type= diff --git a/src/Makefile.am b/src/Makefile.am index f893d5e..a2dc79c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,6 +12,8 @@ bomberclone_SOURCES = \ font.c\ font.h\ gfx.c\ + gfxengine.c\ + gfxpixelimage.c\ player.c\ packets.h\ game.c\ diff --git a/src/basic.h b/src/basic.h index 4d647d5..20c362b 100644 --- a/src/basic.h +++ b/src/basic.h @@ -1,4 +1,4 @@ -/* $Id: basic.h,v 1.38 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: basic.h,v 1.39 2003/07/22 18:29:08 stpohle Exp $ */ /* basic types which we need everywhere */ #ifndef _BC_BASIC_H_ @@ -37,14 +37,15 @@ #define MAX_BOMBS 12 #define MAX_RANGE 10 #define MAX_SPEED 40 -#define MAX_UPDATERECTS 2048 +#define MAX_BLITRECTS 2048 +#define MAX_STONESTODRAW 2048 #define MAX_SERVERENTRYS 8 /* number of entrys in the server tab */ #define MAX_GAMESRVENTRYS 255 /* number of entry which can be get */ #define MAX_FIELDSIZE_X 51 #define MAX_FIELDSIZE_Y 31 #define MIN_FIELDSIZE_X 15 #define MIN_FIELDSIZE_Y 9 -#define MAX_FILEDANIMATION 2048 /* number of points on the field to be animated exploding +#define MAX_FIELDANIMATION 2048 /* number of points on the field to be animated exploding stoned or powerups*/ #define EXPLOSIONTIMEOUT 20 @@ -74,6 +75,8 @@ #define UDP_TIMEOUT 15000 #define BUF_SIZE 1024 +#define MENU_BG_SHADE_DARK -64 +#define MENU_BG_SHADE_BRIGHT 64 enum _networkflags { NETF_firewall = 1 diff --git a/src/bomb.c b/src/bomb.c index a100114..c075177 100644 --- a/src/bomb.c +++ b/src/bomb.c @@ -1,4 +1,4 @@ -/* $Id: bomb.c,v 1.34 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: bomb.c,v 1.35 2003/07/22 18:29:08 stpohle Exp $ */ /* everything what have to do with the bombs */ #include "bomberclone.h" @@ -35,19 +35,14 @@ draw_bomb (_bomb * bomb) dest.y = gfx.offset.y + (y >> 8) * gfx.block.y + gfx.postab[bomb->pos.y & 0x0FF]; src.x = 0; src.y = src.h * bomb->frame; - draw_stone (x>>8, y>>8); + stonelist_add (x>>8, y>>8); if (bomb->moves) { - draw_stone ((x>>8)+1, y>>8); - draw_stone (x>>8, (y>>8)+1); - draw_stone ((x>>8)+1, (y>>8)+1); - gfx_AddUpdateRect (gfx.offset.x + (x >> 8) * gfx.block.x, - gfx.offset.y + (y >> 8) * gfx.block.y, - dest.w*2, dest.h*2); - } else { - gfx_AddUpdateRect (dest.x, dest.y, dest.w, dest.h); + stonelist_add ((x>>8)+1, y>>8); + stonelist_add (x>>8, (y>>8)+1); + stonelist_add ((x>>8)+1, (y>>8)+1); } - SDL_BlitSurface (gfx.bomb.image, &src, gfx.screen, &dest); - + + gfx_blit (gfx.bomb.image, &src, gfx.screen, &dest, y + 16); }; @@ -238,7 +233,7 @@ draw_fire (int x, int y, int d, int frame) if (frame == -1) // no giving frame frame = map.field[x][y].ex[d].frame; - src.w = src.w = gfx.block.x; + dest.w = src.w = gfx.block.x; dest.h = src.h = gfx.block.y; dest.x = gfx.offset.x + x * gfx.block.x; @@ -247,19 +242,16 @@ draw_fire (int x, int y, int d, int frame) src.y = frame * src.w; src.x = d * src.w; - SDL_BlitSurface (gfx.fire.image, &src, gfx.screen, &dest); - gfx_AddUpdateRect (dest.x, dest.y, dest.w, dest.h); + gfx_blit (gfx.fire.image, &src, gfx.screen, &dest, (y << 8)); }; void restore_explosion (_bomb * bomb) { - int i, - d; - int dx = 0, - dy = 0; - int _x, + int i, j, + d, dx = 0, + dy = 0, _x, _y; _point bpos; @@ -292,15 +284,17 @@ restore_explosion (_bomb * bomb) for (i = 0; i < bomb->firer[d]; i++) { if (--map.field[_x][_y].ex[d].count == 0) // there was only one explosion so map.field[_x][_y].ex[d].frame = 0; // reset the framenumber - - if (i == 0 && d == 3) - draw_stone (_x, _y); - - if (i > 0) - draw_stone (_x, _y); + + for (j = 0; j >= 0 && j < 4; j++) + if (map.field[_x][_y].ex[j].count > 0 && j != d) + j = -4; + if (j > 0) + stonelist_add (_x, _y); + _x = _x + dx; _y = _y + dy; } + // delete the stone completly if there was any in the way if (bomb->firer[d] <= bomb->r && map.field[_x][_y].type != FT_block && bomb->ex_nr != map.field[_x][_y].ex_nr) { @@ -316,7 +310,7 @@ restore_explosion (_bomb * bomb) else map.field[_x][_y].type = FT_nothing; - draw_stone (_x, _y); + stonelist_add (_x, _y); if (GT_MP_PTPM) /* send only if we are the master */ net_game_send_field (_x, _y); @@ -324,17 +318,12 @@ restore_explosion (_bomb * bomb) } _x = bpos.x; _y = bpos.y; - gfx_AddUpdateRect (gfx.offset.x + (_x - bomb->firer[left]) * gfx.block.x, - gfx.offset.y + (_y - bomb->firer[up]) * gfx.block.y, - gfx.block.x * (bomb->firer[left] + bomb->firer[right] + 1), - gfx.block.x * (bomb->firer[up] + bomb->firer[down] + 1)); /* delete field from the bfield map */ map.bfield[bpos.x][bpos.y] = 0; }; - /* check the field on which the explosion is */ @@ -379,8 +368,7 @@ explosion_check_field (int x, int y, int p, int b) map.field[x][y].frameto = ANI_STONETIMEOUT; map.field[x][y].frame = 1; - draw_stone (x, y); - field_update (x, y); + stonelist_add (x, y); } return map.field[x][y].type; @@ -440,7 +428,7 @@ draw_explosion (_bomb * bomb) } } -/* check the fields and all this */ +/* do the bombexplosion itself */ void do_explosion (int p, int b) { @@ -484,13 +472,14 @@ do_explosion (int p, int b) map.field[bpos.x + dx][bpos.y + dy].ex[d].frame = bomb->firer[d]; /* if we have a slow pc we can enable this and disable the drawing animation */ // draw_fire (bomb->pos.x + dx, bomb->pos.y + dy, d, gfx.fire.frames>>1); - } + } else { bomb->firerst[d] = bomb->firer[d]; - draw_stone (bpos.x + dx, bpos.y + dy); + stonelist_add (bpos.x + dx, bpos.y + dy); } } } + /* with a slow pc disable this --- maybe option over a config menu */ if (bomb->state == BS_exploding) draw_explosion (bomb); diff --git a/src/bomberclone.h b/src/bomberclone.h index 834b852..88e6012 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.44 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.45 2003/07/22 18:29:08 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -45,7 +45,7 @@ #include "sound.h" #include "network.h" #include "sysfunc.h" - +#include "keybinput.h" struct __playerilness { int to; // if (to > 0) the ilness is still working @@ -180,10 +180,12 @@ extern void game_start(); // everything is declared in field.c extern void draw_field (); extern void field_clear(int x, int y); -extern void field_update(int x,int y); extern void field_animation_add (int x, int y); extern void field_animation (); extern void draw_stone (int x, int y); +extern void stonelist_add (int x, int y); +extern void stonelist_del (); +extern void stonelist_draw (); // everything what is declared in players.c extern int dead_playerani (); @@ -224,6 +226,7 @@ extern void menu_displaymessage (char *title, char *text); extern void menu_displaytext (char *title, char *text, Uint8 r, Uint8 g, Uint8 b); extern char *menu_dir_select (char *title, char *path, signed char dirflags); void menu_clearkeybuff(); +void draw_menubox (int x, int y); // configuration extern void configuration (); diff --git a/src/chat.c b/src/chat.c index 890f1e5..dc94019 100644 --- a/src/chat.c +++ b/src/chat.c @@ -94,7 +94,7 @@ chat_drawbox () src.w = src.x + chat.window.w - 4; src.h = src.y + font[0].size.y; draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1); - gfx_AddUpdateRect (chat.window.x, chat.window.y, chat.window.w, chat.window.h); + gfx_blitupdaterectadd (&chat.window); }; @@ -113,7 +113,7 @@ chat_deletebox () dest.y = chat.window.y; SDL_BlitSurface (chat.oldscreen, &src, gfx.screen, &dest); - gfx_AddUpdateRect (chat.window.x, chat.window.y, chat.window.w, chat.window.h); + gfx_blitupdaterectadd (&chat.window); chat.visible = 0; SDL_FreeSurface (chat.oldscreen); @@ -182,7 +182,7 @@ chat_clearscreen (signed char all) src.h = src.y + font[0].size.y; draw_shadefield (gfx.screen, &src, CHAT_BG_SHADE_DARK >> 1); - gfx_AddUpdateRect (chat.window.x, chat.window.y, chat.window.w, chat.window.h); + gfx_blitupdaterectadd (&chat.window); }; diff --git a/src/configuration.c b/src/configuration.c index c835c30..e32f306 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -26,6 +26,7 @@ game_init (int argc, char **argv) bman.players[i].gfx_nr = -1; /* and even now in the singleplayer menu */ } + stonelist_del (); chat.visible = 0; chat.startline = 0; keybinput_new (&chat.input); @@ -58,8 +59,15 @@ game_init (int argc, char **argv) bman.firewall = 0; bman.ai_players = 1; snd.inited = 0; -// init_map_tileset(); why was this in here... - + map.bombs = GAME_SPECIAL_ITEMBOMB; + map.fire = GAME_SPECIAL_ITEMFIRE; + map.shoes = GAME_SPECIAL_ITEMSHOE; + map.mixed = GAME_SPECIAL_ITEMMIXED; + map.death = GAME_SPECIAL_ITEMDEATH; + map.sp_trigger = GAME_SPECIAL_ITEMSTRIGGER; + map.sp_row = GAME_SPECIAL_ITEMSROW; + map.sp_push = GAME_SPECIAL_ITEMSPUSH; + d_printf ("\n\n ***** Bomberclone Version %s \n\n",VERSION); if (ReadConfig()) { gfx_init (); diff --git a/src/field.c b/src/field.c index 76450b6..0010a09 100644 --- a/src/field.c +++ b/src/field.c @@ -1,13 +1,49 @@ -/* $Id: field.c,v 1.35 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: field.c,v 1.36 2003/07/22 18:29:08 stpohle Exp $ */ /* field.c - procedures which are needed to control the field */ -#include -#include - #include "bomberclone.h" -#include "gfx.h" -static _point fieldani[MAX_FILEDANIMATION]; +static _point fieldani[MAX_FIELDANIMATION]; +static _point stonelist[MAX_STONESTODRAW]; // keep all stones to draw + + +/* delete the stone entry list */ +void stonelist_del () { + register int i; + + for (i = 0; i < MAX_STONESTODRAW; i++) + stonelist[i].x = stonelist[i].y = -1; +} + + +/* stonelist will be draw and cleaned */ +void stonelist_draw () { + int i; + + for (i = 0; i < MAX_STONESTODRAW && stonelist[i].x != -1 && stonelist[i].y != -1; i++) { + draw_stone (stonelist[i].x, stonelist[i].y); + stonelist[i].x = stonelist[i].y = -1; + } +}; + + +/* add stone to draw */ +void stonelist_add (int x, int y) { + int i; + _point *slentry = NULL; + + for (i = 0, slentry = NULL; i < MAX_STONESTODRAW && slentry == NULL; i++) + if (stonelist[i].x == -1 || stonelist[i].y == -1 || (stonelist[i].x == x && stonelist[i].y == y)) + slentry = &stonelist[i]; + + if (slentry == NULL) // no space left + d_fatal ("field.c adddraw_stone(): out of space in stonelist[]\n"); + else { + slentry->x = x; + slentry->y = y; + } +}; + void draw_stone (int x, int y) @@ -41,7 +77,7 @@ draw_stone (int x, int y) srcbg.x = (x % gfx.field[FT_nothing].frames) * gfx.block.x; srcbg.y = (y % gfx.field[FT_nothing].frames) * gfx.block.y; - SDL_BlitSurface (gfx.field[FT_nothing].image, &srcbg, gfx.screen, &dest); + gfx_blit (gfx.field[FT_nothing].image, &srcbg, gfx.screen, &dest, 0); } if (stone->type == FT_mixed) { @@ -88,12 +124,12 @@ draw_stone (int x, int y) } if (srcimg != NULL) - SDL_BlitSurface (srcimg, &src, gfx.screen, &dest); + gfx_blit (srcimg, &src, gfx.screen, &dest, (y << 8) + 1); if (i >= FT_death) { /* draw now the powerup itself */ srcimg = gfx.field[i].image; src.y = 0; - SDL_BlitSurface (srcimg, &src, gfx.screen, &dest); + gfx_blit (srcimg, &src, gfx.screen, &dest, (y << 8) + 2); } // draw explosions if there is any @@ -128,14 +164,6 @@ field_clear (int x, int y) net_game_send_field (x, y); } -void -field_update (int x, int y) -{ - gfx_AddUpdateRect (x * gfx.block.x + gfx.offset.x, y * gfx.block.y + gfx.offset.y, - gfx.block.x, gfx.block.y); - -} - /* run this to every game cycle for the animations on the field */ void @@ -144,7 +172,7 @@ field_animation () int i,j; _field *stone; - for (i = 0; i < MAX_FILEDANIMATION; i++) + for (i = 0; i < MAX_FIELDANIMATION; i++) if (fieldani[i].x >= 0 && fieldani[i].x < map.size.x && fieldani[i].y >= 0 && fieldani[i].y < map.size.y) { /* check if there is a need to animate this */ @@ -185,8 +213,7 @@ field_animation () if (stone->frame >= gfx.powerup[j].frames) stone->frame = 0; } - draw_stone (fieldani[i].x, fieldani[i].y); - field_update (fieldani[i].x, fieldani[i].y); + stonelist_add (fieldani[i].x, fieldani[i].y); } else /* delete this entry */ fieldani[i].y = fieldani[i].x = -1; @@ -204,7 +231,7 @@ field_animation_add (int x, int y) j = -1, d = -1; - for (i = 0; i < MAX_FILEDANIMATION; i++) { + for (i = 0; i < MAX_FIELDANIMATION; i++) { if (fieldani[i].x == x && fieldani[i].y == y) d = i; if (fieldani[i].x == -1 || fieldani[i].y == -1) diff --git a/src/font.c b/src/font.c index 63902f6..bbb7f4d 100644 --- a/src/font.c +++ b/src/font.c @@ -1,4 +1,4 @@ -/* $Id: font.c,v 1.5 2003/06/06 23:22:03 stpohle Exp $ */ +/* $Id: font.c,v 1.6 2003/07/22 18:29:08 stpohle Exp $ */ // Using Fonts in SDL #include @@ -32,8 +32,6 @@ font_draw (int x, int y, char *text, int size) } font_lastsize = font[size].size; - -// gfx_AddUpdateRect (x, y, dest.x - x, dest.h); }; diff --git a/src/game.c b/src/game.c index 6c64b10..7d7b815 100644 --- a/src/game.c +++ b/src/game.c @@ -9,7 +9,7 @@ #include "packets.h" #include "chat.h" -extern int UpdateRects_nr; +extern int blitdb_nr, blitrects_nr; static Uint32 timediff, timediff1; @@ -28,7 +28,10 @@ game_draw_info () redraw_logo (0, 0, gfx.res.x, 3 * 16); if (bman.updatestatusbar) { bman.updatestatusbar = 0; - gfx_AddUpdateRect (0, 0, gfx.res.x, 3 * 16); + dest.x = dest.y = 0; + dest.h = 3*16; + dest.w = gfx.res.x; + gfx_blitupdaterectadd (&dest); bman.players_nr = 0; @@ -99,28 +102,9 @@ game_draw_info () else if (bman.state == GS_ready) font_draw (100, 32, "Waiting for the Server to Start", 0); } - if (debug) { /* do some debug informations on the screen */ - redraw_logo (0, gfx.res.y - font[0].size.y, gfx.res.x, gfx.res.y); - for (x = 0; x < map.size.x; x++) - draw_stone (x, map.size.y - 1); - if (GT_MP_PTP) { - sprintf (text, "NET_STAT: ["); - for (i = 0; i < MAX_PLAYERS; i++) - sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set); - text[strlen (text) + 1] = 0; - text[strlen (text)] = ']'; - font_draw (0, gfx.res.y - (font[0].size.y << 1), text, 0); - } - sprintf (text, "TILESET: %s Tframe: %d Tloop: %d", map.tileset, timediff, timediff1); - sprintf (text, "%s GFX_RECTS:%d", text, UpdateRects_nr); - font_draw (0, gfx.res.y - font[0].size.y, text, 0); - gfx_AddUpdateRect (0, gfx.res.y - (font[0].size.y << 1), gfx.res.x, font[0].size.y << 1); - } - - if (chat.visible == 0 && GT_MP_PTP) { + if (chat.visible == 0 && GT_MP_PTP) chat_show (4, 3 * 16, gfx.res.x - 4, gfx.offset.y); - } }; @@ -221,7 +205,6 @@ game_loop () field_animation (); draw_players (); game_draw_info (); - gfx_UpdateRects (); /* check if there is only one player left and the game is in multiplayer mode and if there the last dieing animation is done */ @@ -233,6 +216,10 @@ game_loop () done = 1; } + + stonelist_draw (); + gfx_blitdraw (); + // calculate time sync. timeloop1 = SDL_GetTicks (); timediff = timeloop1 - timestamp; // only for debugging needed diff --git a/src/gfx.c b/src/gfx.c index 1a45cf1..99f5add 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1,363 +1,9 @@ -/* $Id: gfx.c,v 1.23 2003/07/15 11:43:09 stpohle Exp $ */ +/* $Id: gfx.c,v 1.24 2003/07/22 18:29:08 stpohle Exp $ */ /* gfx.c */ -#include #include "bomberclone.h" -int UpdateRects_nr = 0; -SDL_Rect UpdateRects[MAX_UPDATERECTS]; - _gfx gfx; -void -getRGBpixel (SDL_Surface * surface, int x, int y, int *R, int *G, int *B) -{ - Uint32 pixel = 0; - Uint8 r, - g, - b; - - /* Lock the screen for direct access to the pixels */ - if (SDL_MUSTLOCK (surface)) - if (SDL_LockSurface (surface) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - return; - } - pixel = getpixel (surface, x, y); - if (SDL_MUSTLOCK (surface)) { - SDL_UnlockSurface (surface); - } - SDL_GetRGB (pixel, surface->format, &r, &g, &b); - *R = r; - *G = g; - *B = b; -}; - - -Uint32 -getpixel (SDL_Surface * surface, int x, int y) -{ - int bpp = surface->format->BytesPerPixel; - - /* Here p is the address to the pixel we want to retrieve */ - Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; - switch (bpp) { - case 1: - return *p; - case 2: - return *(Uint16 *) p; - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - return p[0] << 16 | p[1] << 8 | p[2]; - - else - return p[0] | p[1] << 8 | p[2] << 16; - case 4: - return *(Uint32 *) p; - default: - return 0; /* shouldn't happen, but avoids warnings */ - } -}; - - -void -putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel) -{ - /* Here p is the address to the pixel we want to set */ - int bpp = surface->format->BytesPerPixel; - Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; - - switch (bpp) { - case 1: - *p = pixel; - break; - case 2: - *(Uint16 *) p = pixel; - break; - case 3: - if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } - else { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - } - break; - case 4: - *(Uint32 *) p = pixel; - break; - } -}; - - -void -scale (short int *dpattern, short int x, short int y) -{ - int a, - dx, - dy; - if (x >= SCALE_MAXRES || y >= SCALE_MAXRES) { - for (x = 0; x < SCALE_MAXRES; x++) - dpattern[x] = 0; - return; - } - if (x > y) { - dy = 2 * y; - dx = a = 2 * x - dy; - - do { - if (a <= 0) { - dpattern[(y--) - 1] = x; - a = a + dx; - } - - else - a = a - dy; - } while (x--); - } - - else { - dy = 2 * x; - dx = a = 2 * y - dy; - - do { - dpattern[y] = x; - if (a <= 0) { - x--; - a = a + dx; - } - - else - a = a - dy; - } while (y--); - } -}; - - -SDL_Surface * -scale_image (SDL_Surface * orginal, int newx, int newy) -{ - Uint32 rmask, - gmask, - bmask, - amask; - SDL_Surface *surface; - int y, - x; - short int xpattern[SCALE_MAXRES]; - short int ypattern[SCALE_MAXRES]; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; - -#else /* */ - rmask = 0x00ff0000; - gmask = 0x0000ff00; - bmask = 0x000000ff; - amask = 0xff000000; - -#endif /* */ - - surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask); - if (surface == NULL) { - fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); - return NULL; - } - - /* Lock the screen for direct access to the pixels */ - if (SDL_MUSTLOCK (surface)) - if (SDL_LockSurface (surface) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - return NULL; - } - if (SDL_MUSTLOCK (orginal)) - if (SDL_LockSurface (orginal) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - if (SDL_MUSTLOCK (surface)) { - SDL_UnlockSurface (surface); - } - return NULL; - } - - /* do the scaling work */ - scale (xpattern, orginal->w - 1, newx); - scale (ypattern, orginal->h - 1, newy); - for (x = newx - 1; x >= 0; x--) - for (y = newy - 1; y >= 0; y--) - putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y])); - if (SDL_MUSTLOCK (orginal)) { - SDL_UnlockSurface (orginal); - } - if (SDL_MUSTLOCK (surface)) { - SDL_UnlockSurface (surface); - } - return surface; -}; - -SDL_Surface * -makegray_image (SDL_Surface * org) -{ - Uint32 rmask, - gmask, - bmask, - amask; - Uint32 pixel, - transpixel = 0; - SDL_Surface *dest; - int y, - x; - Uint8 r, - g, - b, - gray; - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x00ff0000; - gmask = 0x0000ff00; - bmask = 0x000000ff; - amask = 0xff000000; -#endif - dest = SDL_CreateRGBSurface (SDL_SWSURFACE, org->w, org->h, 32, rmask, gmask, bmask, amask); - if (dest == NULL) { - fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); - return NULL; - } - - /* Lock the screen for direct access to the pixels */ - if (SDL_MUSTLOCK (dest)) - if (SDL_LockSurface (dest) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - return NULL; - } - if (SDL_MUSTLOCK (org)) - if (SDL_LockSurface (org) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - return NULL; - } - for (x = 0; x < org->w; x++) - for (y = 0; y < org->h; y++) { - pixel = getpixel (org, x, y); - if (x == 0 && y == 0) - transpixel = pixel; - if (pixel != transpixel) { - SDL_GetRGB (pixel, org->format, &r, &g, &b); - gray = (r / 3 + g / 3 + b / 3); - pixel = SDL_MapRGB (dest->format, gray, gray, gray); - } - putpixel (dest, x, y, pixel); - } - if (SDL_MUSTLOCK (org)) { - SDL_UnlockSurface (org); - } - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - SDL_SetColorKey (dest, SDL_SRCCOLORKEY, transpixel); - return dest; -}; - -SDL_Surface * -gfx_quater_image (SDL_Surface * org1, SDL_Surface * org2, SDL_Surface * org3, SDL_Surface * org4) -{ - Uint32 pixel; - SDL_Surface *dest; - int y, - x; - - dest = SDL_CreateRGBSurface (SDL_HWSURFACE, org1->w, org1->h, org1->format->BitsPerPixel, - org1->format->Rmask, org1->format->Gmask, - org1->format->Bmask, org1->format->Amask); - if (dest == NULL) { - fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); - return NULL; - } - - /* Lock the screen for direct access to the pixels */ - if (SDL_MUSTLOCK (dest)) - if (SDL_LockSurface (dest) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - return NULL; - } - if (SDL_MUSTLOCK (org1)) - if (SDL_LockSurface (org1) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - return NULL; - } - if (SDL_MUSTLOCK (org2)) - if (SDL_LockSurface (org2) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - return NULL; - } - if (SDL_MUSTLOCK (org3)) - if (SDL_LockSurface (org3) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - return NULL; - } - if (SDL_MUSTLOCK (org4)) - if (SDL_LockSurface (org4) < 0) { - fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - return NULL; - } - for (x = 0; x < org1->w / 2; x++) - for (y = 0; y < org1->h / 2; y++) { - pixel = getpixel (org1, x, y); - putpixel (dest, x, y, pixel); - } - for (x = org1->w / 2; x < org1->w; x++) - for (y = 0; y < org1->h / 2; y++) { - pixel = getpixel (org2, x, y); - putpixel (dest, x, y, pixel); - } - for (x = 0; x < org1->w / 2; x++) - for (y = org1->h / 2; y < org1->h; y++) { - pixel = getpixel (org3, x, y); - putpixel (dest, x, y, pixel); - } - for (x = org1->w / 2; x < org1->w; x++) - for (y = org1->h / 2; y < org1->h; y++) { - pixel = getpixel (org4, x, y); - putpixel (dest, x, y, pixel); - } - - if (SDL_MUSTLOCK (org1)) - SDL_UnlockSurface (org1); - if (SDL_MUSTLOCK (org2)) - SDL_UnlockSurface (org2); - if (SDL_MUSTLOCK (org3)) - SDL_UnlockSurface (org3); - if (SDL_MUSTLOCK (org4)) - SDL_UnlockSurface (org4); - if (SDL_MUSTLOCK (dest)) { - SDL_UnlockSurface (dest); - } - return dest; -}; - #define __smalsizeX 12 void @@ -506,7 +152,6 @@ gfx_init () }; - void gfx_loaddata () { @@ -573,55 +218,16 @@ gfx_shutdown () }; -void -gfx_AddUpdateRect (int x, int y, int w, int h) -{ - /* clipping of the box */ - if (x >= gfx.res.x || y >= gfx.res.y || y+h <= 0 || x+w <= 0) - return; - - if (UpdateRects_nr >= MAX_UPDATERECTS) - return; - - if (x < 0) - UpdateRects[UpdateRects_nr].x = 0; - else - UpdateRects[UpdateRects_nr].x = x; - - if (y < 0) - UpdateRects[UpdateRects_nr].y = 0; - else - UpdateRects[UpdateRects_nr].y = y; - - if (w+x >= gfx.res.x) - UpdateRects[UpdateRects_nr].w = gfx.res.x - x; - else - UpdateRects[UpdateRects_nr].w = w; - - if (h+y >= gfx.res.y) - UpdateRects[UpdateRects_nr].h = gfx.res.y - y; - else - UpdateRects[UpdateRects_nr].h = h; - - UpdateRects_nr++; -}; - - -void -gfx_UpdateRects () -{ - if (UpdateRects_nr > 0) - SDL_UpdateRects (gfx.screen, UpdateRects_nr, UpdateRects); - UpdateRects_nr = 0; -}; - - void draw_logo () { + SDL_Rect dest; + dest.x = dest.y = 0; + dest.w = gfx.res.x; + dest.h = gfx.res.y; + SDL_BlitSurface (gfx.logo, NULL, gfx.screen, NULL); - UpdateRects_nr = 0; - gfx_AddUpdateRect (0, 0, gfx.screen->w, gfx.screen->h); + gfx_blitupdaterectadd (&dest); }; @@ -760,21 +366,3 @@ draw_shadefield (SDL_Surface * s, SDL_Rect * rec, int c) for (x = x1; x <= x2; x++) shade_pixel (s, x, y, c); }; - - -SDL_Surface * -gfx_copyscreen (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); - dest.x = 0; - dest.y = 0; - dest.w = wnd->w; - dest.h = wnd->h; - SDL_BlitSurface (gfx.screen, wnd, res, &dest); - return res; -}; diff --git a/src/gfx.h b/src/gfx.h index ef2f024..0c37445 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -1,4 +1,4 @@ -/* $Id: gfx.h,v 1.13 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: gfx.h,v 1.14 2003/07/22 18:29:08 stpohle Exp $ */ #ifndef _GFX_H_ #define _GFX_H_ @@ -9,6 +9,16 @@ #include "basic.h" + +struct __gfxblit { + SDL_Rect srcr; + SDL_Surface *srci; + SDL_Rect destr; + SDL_Surface *desti; + int y; +} typedef _gfxblit; + + struct __gfxani { SDL_Surface *image; int frames; // how many single frames (image -> heigh / (1.5 * gamestyle.height)) @@ -54,28 +64,38 @@ struct __gfx { extern _gfx gfx; -// everything what is in gfx.c +// gfx.c extern void gfx_loaddata (); -extern void gfx_UpdateRects (); -extern void gfx_AddUpdateRect (int x, int y, int w, int h); extern void redraw_logo (int x, int y, int w, int h); extern void draw_logo (); extern void gfx_init (); // Load Base Image Data extern void gfx_shutdown (); -extern void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B); -extern Uint32 getpixel(SDL_Surface *surface, int x, int y); -extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); -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 void draw_shadefield (SDL_Surface *s, SDL_Rect *rec, int c); extern int gfx_locksurface (SDL_Surface *surface); extern void gfx_unlocksurface (SDL_Surface *surface); extern void redraw_logo_shaded (int x, int y, int w, int h, int c); extern void gfx_load_players (int sx, int sy); extern void gfx_free_players (); + +// gfxpixelimage.c +extern void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B); +extern Uint32 getpixel(SDL_Surface *surface, int x, int y); +extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); +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); + +// gfxengine.c +extern void gfx_blitdraw (); +extern void gfx_blit (SDL_Surface *srci, SDL_Rect *srcr, SDL_Surface *desti, SDL_Rect *destr, int y); +extern void gfx_blitsort (); +extern inline void gfx_blitsortclear (); +extern inline void gfx_blitupdaterectclear (); +extern void gfx_blitupdaterectdraw (); +extern void gfx_blitupdaterectadd (SDL_Rect *rect); + #endif diff --git a/src/gfxengine.c b/src/gfxengine.c new file mode 100644 index 0000000..2ca19a3 --- /dev/null +++ b/src/gfxengine.c @@ -0,0 +1,192 @@ +/* $Id: gfxengine.c,v 1.1 2003/07/22 18:29:08 stpohle Exp $ */ +/* GFX Game Engine */ + +#include "bomberclone.h" + +int blitdb_nr = 0, blitrects_nr = 0; +static _gfxblit blitdb[MAX_BLITRECTS]; /* unsorted list of blitdb's */ +static _gfxblit *sortblitdb[MAX_BLITRECTS]; /* sorted list of blitdb's */ +static SDL_Rect blitrects[MAX_BLITRECTS]; /* SDLUpdate Rects */ + +/* sort the list of blitting objects highest will be drawn at last */ +void gfx_blitsort () { + register int i,y; + + gfx_blitsortclear (); + for (i = 0; i < MAX_BLITRECTS && i < blitdb_nr; i++) { + for (y = i; (y > 0 && blitdb[i].y < sortblitdb[y-1]->y); y--) + sortblitdb[y] = sortblitdb[y-1]; + sortblitdb[y] = &blitdb[i]; + } +} + + +/* delete sorted order of gfx updates */ +inline void gfx_blitsortclear () { + register int i; + for (i = 0; i < MAX_BLITRECTS; i++) + sortblitdb[i] = NULL; +}; + + +/* delete all updaterect entrys */ +inline void gfx_blitupdaterectclear () { + register int i; + for (i = 0; i < MAX_BLITRECTS; i++) + blitrects[i].x = blitrects[i].y = blitrects[i].h = blitrects[i].w = -1; + blitrects_nr = 0; +}; + + +/* SDL Update of the rects */ +void gfx_blitupdaterectdraw () { + if (blitrects_nr > 0) + SDL_UpdateRects (gfx.screen, blitrects_nr, blitrects); + + blitrects_nr = 0; + gfx_blitupdaterectclear (); +}; + + +/* add updaterect entrys and skipp unneeded or double rects */ +void gfx_blitupdaterectadd (SDL_Rect *rect) { + _point p1a, p1e, p2a, p2e; + int i, done = 0; + + /* search for a match or an close update rect */ + p2a.x = rect->x; + p2a.y = rect->y; + p2e.x = rect->x + rect->w; + p2e.y = rect->y + rect->h; + + for (i = 0; i < blitrects_nr && !done; i++) { + p1a.x = blitrects[i].x; + p1a.y = blitrects[i].y; + p1e.x = blitrects[i].x + blitrects[i].w; + p1e.y = blitrects[i].y + blitrects[i].h; + + if (p2a.x >= p1a.x && p2e.x <= p1e.x && + p2a.y >= p1a.y && p2e.y <= p1e.y) { + /* p2 is in p1 >> drop rects */ + done = 1; + } + + /* p1 is in p2 >> change rect */ + else if (p1a.x >= p2a.x && p1e.x <= p2e.x && + p1a.y >= p2a.y && p1e.y <= p2e.y) { + blitrects[i].x = rect->x; + blitrects[i].y = rect->y; + blitrects[i].w = rect->w; + blitrects[i].h = rect->h; + done = 1; + } + } + + /* no match found, add new */ + if (i == blitrects_nr && !done) { + blitrects_nr++; + blitrects[i] = *rect; + } +}; + + +void +gfx_blitdraw () +{ + int i; + + if (blitdb_nr <= 0) { + blitdb_nr = 0; + return; + } + + gfx_blitsort (); + + for (i = 0; i < MAX_BLITRECTS && sortblitdb[i] != NULL; i++) { + SDL_BlitSurface (sortblitdb[i]->srci, &sortblitdb[i]->srcr, sortblitdb[i]->desti, &sortblitdb[i]->destr); + gfx_blitupdaterectadd (&sortblitdb[i]->destr); + } + + gfx_blitupdaterectdraw (); + blitdb_nr = 0; +}; + + +/* Add a new image to draw/blit on the screen and in thw right order. + srcr srci: source image and rect + destr desti: destination image and rect + y: deep of the image */ +void +gfx_blit (SDL_Surface *srci, SDL_Rect *srcr, SDL_Surface *desti, SDL_Rect *destr, int y) +{ + int i; + + /* check if the rects are out of the images and drop this blitting */ + if (srcr->x > srci->w || srcr->y > srci->h || + destr->x > desti->w || destr->y > desti->h) + return; + + /* clipping src */ + if (srcr->x < 0) { // x < 0 + srcr->w += srcr->x; + destr->w += srcr->x; + destr->x -= srcr->x; + srcr->x = 0; + } + if (srcr->x+srcr->w > srci->w) { // x+w > img.w + i = srcr->x+srcr->w - srci->w; + srcr->w -= i; + destr->w -= i; + } + if (srcr->y < 0) { // y < 0 + srcr->h += srcr->y; + destr->h += srcr->h; + destr->y -= srcr->y; + srcr->y = 0; + } + if (srcr->y+srcr->h > srci->h) { // y+h > img.h + i = srcr->y+srcr->h - srci->h; + srcr->h -= i; + destr->h -= i; + } + + /* clipping dest */ + if (destr->x < 0) { // x < 0 + destr->w += destr->x; + srcr->w += destr->x; + srcr->x -= destr->x; + destr->x = 0; + } + if (destr->x+destr->w > desti->w) { // x+w > img.w + i = destr->x+destr->w - desti->w; + srcr->w -= i; + destr->w -= i; + } + if (destr->y < 0) { // y < 0 + destr->h += destr->y; + srcr->h += destr->h; + srcr->y -= destr->y; + destr->y = 0; + } + if (destr->y+destr->h > desti->h) { // y+h > img.h + i = destr->y+destr->h - desti->h; + srcr->h -= i; + destr->h -= i; + } + + /* add to list */ + if (blitdb_nr < 0) + blitdb_nr = 0; + else if (blitdb_nr >= MAX_BLITRECTS) { + d_fatal ("blitdb_nr > MAX_BLITRECTS\n"); + return; + } + + blitdb[blitdb_nr].srcr = *srcr; + blitdb[blitdb_nr].srci = srci; + blitdb[blitdb_nr].destr = *destr; + blitdb[blitdb_nr].desti = desti; + blitdb[blitdb_nr].y = y; + + blitdb_nr++; +}; diff --git a/src/gfxpixelimage.c b/src/gfxpixelimage.c new file mode 100644 index 0000000..77a3271 --- /dev/null +++ b/src/gfxpixelimage.c @@ -0,0 +1,372 @@ +/* $Id: gfxpixelimage.c,v 1.1 2003/07/22 18:29:08 stpohle Exp $ */ +/* gfx pixel manipulation and image manipulation */ + +#include "bomberclone.h" + +void +getRGBpixel (SDL_Surface * surface, int x, int y, int *R, int *G, int *B) +{ + Uint32 pixel = 0; + Uint8 r, + g, + b; + + /* Lock the screen for direct access to the pixels */ + if (SDL_MUSTLOCK (surface)) + if (SDL_LockSurface (surface) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + return; + } + pixel = getpixel (surface, x, y); + if (SDL_MUSTLOCK (surface)) { + SDL_UnlockSurface (surface); + } + SDL_GetRGB (pixel, surface->format, &r, &g, &b); + *R = r; + *G = g; + *B = b; +}; + + +Uint32 +getpixel (SDL_Surface * surface, int x, int y) +{ + int bpp = surface->format->BytesPerPixel; + + /* Here p is the address to the pixel we want to retrieve */ + Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; + switch (bpp) { + case 1: + return *p; + case 2: + return *(Uint16 *) p; + case 3: + if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + + else + return p[0] | p[1] << 8 | p[2] << 16; + case 4: + return *(Uint32 *) p; + default: + return 0; /* shouldn't happen, but avoids warnings */ + } +}; + + +void +putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel) +{ + /* Here p is the address to the pixel we want to set */ + int bpp = surface->format->BytesPerPixel; + Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; + + switch (bpp) { + case 1: + *p = pixel; + break; + case 2: + *(Uint16 *) p = pixel; + break; + case 3: + if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } + else { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + case 4: + *(Uint32 *) p = pixel; + break; + } +}; + + +void +scale (short int *dpattern, short int x, short int y) +{ + int a, + dx, + dy; + if (x >= SCALE_MAXRES || y >= SCALE_MAXRES) { + for (x = 0; x < SCALE_MAXRES; x++) + dpattern[x] = 0; + return; + } + if (x > y) { + dy = 2 * y; + dx = a = 2 * x - dy; + + do { + if (a <= 0) { + dpattern[(y--) - 1] = x; + a = a + dx; + } + + else + a = a - dy; + } while (x--); + } + + else { + dy = 2 * x; + dx = a = 2 * y - dy; + + do { + dpattern[y] = x; + if (a <= 0) { + x--; + a = a + dx; + } + + else + a = a - dy; + } while (y--); + } +}; + + +SDL_Surface * +scale_image (SDL_Surface * orginal, int newx, int newy) +{ + Uint32 rmask, + gmask, + bmask, + amask; + SDL_Surface *surface; + int y, + x; + short int xpattern[SCALE_MAXRES]; + short int ypattern[SCALE_MAXRES]; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; + +#else /* */ + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0xff000000; + +#endif /* */ + + surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask); + if (surface == NULL) { + fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); + return NULL; + } + + /* Lock the screen for direct access to the pixels */ + if (SDL_MUSTLOCK (surface)) + if (SDL_LockSurface (surface) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + return NULL; + } + if (SDL_MUSTLOCK (orginal)) + if (SDL_LockSurface (orginal) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + if (SDL_MUSTLOCK (surface)) { + SDL_UnlockSurface (surface); + } + return NULL; + } + + /* do the scaling work */ + scale (xpattern, orginal->w - 1, newx); + scale (ypattern, orginal->h - 1, newy); + for (x = newx - 1; x >= 0; x--) + for (y = newy - 1; y >= 0; y--) + putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y])); + if (SDL_MUSTLOCK (orginal)) { + SDL_UnlockSurface (orginal); + } + if (SDL_MUSTLOCK (surface)) { + SDL_UnlockSurface (surface); + } + return surface; +}; + +SDL_Surface * +makegray_image (SDL_Surface * org) +{ + Uint32 rmask, + gmask, + bmask, + amask; + Uint32 pixel, + transpixel = 0; + SDL_Surface *dest; + int y, + x; + Uint8 r, + g, + b, + gray; + +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0xff000000; +#endif + dest = SDL_CreateRGBSurface (SDL_SWSURFACE, org->w, org->h, 32, rmask, gmask, bmask, amask); + if (dest == NULL) { + fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); + return NULL; + } + + /* Lock the screen for direct access to the pixels */ + if (SDL_MUSTLOCK (dest)) + if (SDL_LockSurface (dest) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + return NULL; + } + if (SDL_MUSTLOCK (org)) + if (SDL_LockSurface (org) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + return NULL; + } + for (x = 0; x < org->w; x++) + for (y = 0; y < org->h; y++) { + pixel = getpixel (org, x, y); + if (x == 0 && y == 0) + transpixel = pixel; + if (pixel != transpixel) { + SDL_GetRGB (pixel, org->format, &r, &g, &b); + gray = (r / 3 + g / 3 + b / 3); + pixel = SDL_MapRGB (dest->format, gray, gray, gray); + } + putpixel (dest, x, y, pixel); + } + if (SDL_MUSTLOCK (org)) { + SDL_UnlockSurface (org); + } + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + SDL_SetColorKey (dest, SDL_SRCCOLORKEY, transpixel); + return dest; +}; + +SDL_Surface * +gfx_quater_image (SDL_Surface * org1, SDL_Surface * org2, SDL_Surface * org3, SDL_Surface * org4) +{ + Uint32 pixel; + SDL_Surface *dest; + int y, + x; + + dest = SDL_CreateRGBSurface (SDL_HWSURFACE, org1->w, org1->h, org1->format->BitsPerPixel, + org1->format->Rmask, org1->format->Gmask, + org1->format->Bmask, org1->format->Amask); + if (dest == NULL) { + fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); + return NULL; + } + + /* Lock the screen for direct access to the pixels */ + if (SDL_MUSTLOCK (dest)) + if (SDL_LockSurface (dest) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + return NULL; + } + if (SDL_MUSTLOCK (org1)) + if (SDL_LockSurface (org1) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + return NULL; + } + if (SDL_MUSTLOCK (org2)) + if (SDL_LockSurface (org2) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + return NULL; + } + if (SDL_MUSTLOCK (org3)) + if (SDL_LockSurface (org3) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + return NULL; + } + if (SDL_MUSTLOCK (org4)) + if (SDL_LockSurface (org4) < 0) { + fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + return NULL; + } + for (x = 0; x < org1->w / 2; x++) + for (y = 0; y < org1->h / 2; y++) { + pixel = getpixel (org1, x, y); + putpixel (dest, x, y, pixel); + } + for (x = org1->w / 2; x < org1->w; x++) + for (y = 0; y < org1->h / 2; y++) { + pixel = getpixel (org2, x, y); + putpixel (dest, x, y, pixel); + } + for (x = 0; x < org1->w / 2; x++) + for (y = org1->h / 2; y < org1->h; y++) { + pixel = getpixel (org3, x, y); + putpixel (dest, x, y, pixel); + } + for (x = org1->w / 2; x < org1->w; x++) + for (y = org1->h / 2; y < org1->h; y++) { + pixel = getpixel (org4, x, y); + putpixel (dest, x, y, pixel); + } + + if (SDL_MUSTLOCK (org1)) + SDL_UnlockSurface (org1); + if (SDL_MUSTLOCK (org2)) + SDL_UnlockSurface (org2); + if (SDL_MUSTLOCK (org3)) + SDL_UnlockSurface (org3); + if (SDL_MUSTLOCK (org4)) + SDL_UnlockSurface (org4); + if (SDL_MUSTLOCK (dest)) { + SDL_UnlockSurface (dest); + } + return dest; +}; + + +SDL_Surface * +gfx_copyscreen (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); + dest.x = 0; + dest.y = 0; + dest.w = wnd->w; + dest.h = wnd->h; + SDL_BlitSurface (gfx.screen, wnd, res, &dest); + return res; +}; diff --git a/src/map.c b/src/map.c index 70c4d06..edb925f 100644 --- a/src/map.c +++ b/src/map.c @@ -1,4 +1,4 @@ -/* $Id: map.c,v 1.2 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: map.c,v 1.3 2003/07/22 18:29:08 stpohle Exp $ */ /* map handling, like generate and load maps. */ #include "bomberclone.h" @@ -64,23 +64,23 @@ map_new (char *filename) map_set_playerposition (fmap != NULL); /* put the fire powerups in the field */ - map_fillitems (FT_fire, GAME_SPECIAL_ITEMFIRE); + map_fillitems (FT_fire, map.fire); /* put the bomb powerups in the field */ - map_fillitems (FT_bomb, GAME_SPECIAL_ITEMBOMB); + map_fillitems (FT_bomb, map.bombs); /* put the shoe powerup in the field */ - map_fillitems (FT_shoe, GAME_SPECIAL_ITEMSHOE); + map_fillitems (FT_shoe, map.shoes); /* put the death ?powerups? in the field */ - map_fillitems (FT_death, GAME_SPECIAL_ITEMDEATH); + map_fillitems (FT_death, map.death); /* put the mixed powerrup in the field */ - map_fillitems (FT_mixed, GAME_SPECIAL_ITEMMIXED); + map_fillitems (FT_mixed, map.mixed); /* put the trigger special in the field */ - map_fillitems (FT_sp_trigger, GAME_SPECIAL_ITEMSTRIGGER); + map_fillitems (FT_sp_trigger, map.sp_trigger); /* put the row special in the field */ - map_fillitems (FT_sp_row, GAME_SPECIAL_ITEMSROW); + map_fillitems (FT_sp_row, map.sp_row); /* put the push special in the field */ - map_fillitems (FT_sp_push, GAME_SPECIAL_ITEMSPUSH); + map_fillitems (FT_sp_push, map.sp_push); /* put the kick special in the field */ - map_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK); +// map_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK); } void map_genrandom () { @@ -306,7 +306,7 @@ void init_map_tileset() an espace is nothing ' ' % are commentary at the beginning of the map */ void -map_load (FILE * mapname) +map_load (FILE * fmap) { size_t length; char *currentline; @@ -316,12 +316,28 @@ map_load (FILE * mapname) int i; int d; - while ((currentline = fgets (tmp, MAX_FIELDSIZE_X, mapname))) { + while ((currentline = fgets (tmp, MAX_FIELDSIZE_X, fmap))) { length = strlen (currentline); if (currentline[0] == '%') continue; /* now each line correspond to the field */ - else { + else if (strstr (currentline, "bombs") == currentline) // bombs + map.bombs = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "fire") == currentline) // fire + map.fire = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "shoes") == currentline) // shoes + map.shoes = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "mixed") == currentline) // mixed + map.mixed = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "death") == currentline) // death + map.death = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "sp_trigger") == currentline) // trigger special + map.sp_trigger = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "sp_push") == currentline) // push special + map.sp_push = atoi (strchr (currentline, '=') + 1); + else if (strstr (currentline, "sp_row") == currentline) // row special + map.sp_row = atoi (strchr (currentline, '=') + 1); + else if (currentline[0] == '#') { /* the map itself */ for (i = 0; i < length; i++) { switch (currentline[i]) { case '#': @@ -356,4 +372,6 @@ map_load (FILE * mapname) map.field[i][0].type = map.field[i][map.size.y - 1].type = FT_block; for (i = 0; i < map.size.y; i++) map.field[0][i].type = map.field[map.size.x - 1][i].type = FT_block; + + fclose (fmap); } diff --git a/src/map.h b/src/map.h index 407e8a0..399958a 100644 --- a/src/map.h +++ b/src/map.h @@ -1,4 +1,4 @@ -/* $Id: map.h,v 1.1 2003/07/16 15:27:48 stpohle Exp $ */ +/* $Id: map.h,v 1.2 2003/07/22 18:29:08 stpohle Exp $ */ /* map.h */ #ifndef _MAP_H_ @@ -35,6 +35,8 @@ struct __map { unsigned char bombs; unsigned char fire; unsigned char shoes; + unsigned char mixed; + unsigned char death; unsigned char sp_trigger; unsigned char sp_push; unsigned char sp_row; @@ -45,7 +47,7 @@ extern _map map; // mapmenu.c extern void mapmenu (); -extern void display_mapinfo (); +extern void mapinfo (); // map.c extern void map_random (); @@ -53,6 +55,6 @@ extern void map_genrandom (); extern void init_map_tileset(); extern void map_new (char *filename); extern void map_set_playerposition (int usermap); -extern void map_load (FILE * map); +extern void map_load (FILE * fmap); #endif diff --git a/src/mapmenu.c b/src/mapmenu.c index 747ab21..e82e79d 100644 --- a/src/mapmenu.c +++ b/src/mapmenu.c @@ -1,4 +1,4 @@ -/* $Id: */ +/* $Id: mapmenu.c,v 1.6 2003/07/22 18:29:08 stpohle Exp $ */ /* map/tileset selection menu */ #include "bomberclone.h" @@ -24,18 +24,20 @@ mapmenu () {7, "Bombs:"}, {8, "Fire :"}, {9, "Shoes:"}, - {10, "Special Trigger:"}, - {11, "Special Push :"}, - {12, "Special Row :"}, + {10, "Mixed:"}, + {11, "Death:"}, + {12, "Special Trigger:"}, + {13, "Special Push :"}, + {14, "Special Row :"}, {0, ""}, - {14, "Return To Previous Menu"}, + {15, "Return To Previous Menu"}, {-1, ""} }; while (menuselect != -1) { switch (map.map_selection) { - case (0): + case (0): // Selected Map if (map.map[0] == 0) sprintf (menu[1].text, "Selected Map: < undefined >"); else @@ -47,7 +49,7 @@ mapmenu () menu[3].text[0] = 0; menu[3].index = 0; break; - case (1): + case (1): // Random Map menu[1].text[0] = 0; menu[1].index = 0; sprintf (menu[0].text, "Random Map: random file"); @@ -56,7 +58,7 @@ mapmenu () menu[3].text[0] = 0; menu[3].index = 0; break; - case (2): + case (2): // Random Generated Map menu[1].text[0] = 0; menu[1].index = 0; sprintf (menu[0].text, "Random Map: auto-generated"); @@ -89,9 +91,11 @@ mapmenu () sprintf (menu[7].text, "Bombs:%d", map.bombs); sprintf (menu[8].text, "Fire :%d", map.fire); sprintf (menu[9].text, "Shoes:%d", map.shoes); - sprintf (menu[10].text, "Special Trigger:%d", map.sp_trigger); - sprintf (menu[11].text, "Special Push :%d", map.sp_push); - sprintf (menu[12].text, "Special Row :%d", map.sp_row); + sprintf (menu[10].text, "Mixed:%d", map.mixed); + sprintf (menu[11].text, "Death:%d", map.death); + sprintf (menu[12].text, "Special Trigger:%d", map.sp_trigger); + sprintf (menu[13].text, "Special Push :%d", map.sp_push); + sprintf (menu[14].text, "Special Row :%d", map.sp_row); menuselect = menu_loop ("Map Options", menu, menuselect); @@ -107,8 +111,13 @@ mapmenu () map.map[0] = 0; map.map_selection = 2; } - else + else { + FILE *fmap; + sprintf (map.map, "%s/maps/%s", bman.datapath, mapname); + if ((fmap = fopen (map.map, "r"))) + map_load (fmap); + } break; case (2): // Size X @@ -159,8 +168,47 @@ mapmenu () if (bman.maxplayer < 2) bman.maxplayer = 2; break; - - case (14): // Return to previous menu + case (7): + sprintf (text, "%d", map.bombs); + menu_get_text ("Bomb Powerups", text, 2); + map.bombs = atoi (text); + break; + case (8): + sprintf (text, "%d", map.fire); + menu_get_text ("Fire/Range Powerup", text, 2); + map.fire = atoi (text); + break; + case (9): + sprintf (text, "%d", map.shoes); + menu_get_text ("Shoes Powerup", text, 2); + map.shoes = atoi (text); + break; + case (10): + sprintf (text, "%d", map.mixed); + menu_get_text ("Mixed Powerup", text, 2); + map.mixed = atoi (text); + break; + case (11): + sprintf (text, "%d", map.death); + menu_get_text ("Death Powerup", text, 2); + map.death = atoi (text); + break; + case (12): + sprintf (text, "%d", map.sp_trigger); + menu_get_text ("Trigger Specials", text, 2); + map.sp_trigger = atoi (text); + break; + case (13): + sprintf (text, "%d", map.sp_push); + menu_get_text ("Push Specials", text, 2); + map.sp_push = atoi (text); + break; + case (14): + sprintf (text, "%d", map.sp_row); + menu_get_text ("Row Specials", text, 2); + map.sp_row = atoi (text); + break; + case (16): // Return to previous menu menuselect = -1; break; } @@ -168,8 +216,159 @@ mapmenu () } +/* + Draw an info Screen about the mapsetting which are currently used +*/ +#define WIN_X 500 +#define WIN_Y 350 void -display_mapinfo () +mapinfo () { - /* bla */ + _keybinput ki; + SDL_Event event; + int x, y, eventstate, done = 0; + char text[255]; + + draw_menubox (WIN_X, WIN_Y); + + x = gfx.res.x / 2; + y = gfx.res.y / 2 - WIN_Y / 2; + + sprintf (text, "Map Settings"); + font_setcolor (128,128,0,1); + font_draw (x - (font[1].size.x * strlen (text) / 2), y, text, 1); + font_setcolor (255,255,0,1); + font_draw (1 + x - (font[1].size.x * strlen (text) / 2),1 + y, text, 1); + y = y + 2 + (font[1].size.y << 1); + + /* MapSize */ + sprintf (text, "Fieldsize: %d,%d", map.size.x, map.size.y); + font_setcolor (128,128,128,0); + font_draw (x - (font[0].size.x * strlen (text) / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x - (font[0].size.x * strlen (text) / 2),1 + y, text, 0); + y = y + 2 + font[0].size.y; + + /* Tileset */ + if (map.random_tileset) + sprintf (text, "Random Tileset"); + else + sprintf (text, "Tileset: %s", map.tileset); + font_setcolor (128,128,128,0); + font_draw (2 + x - (WIN_X / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0); + + /* Mapselection */ + if (map.map_selection == 0) + sprintf (text, "Selected Map: %s", map.map); + else if (map.map_selection == 1) + sprintf (text, "Random Map"); + else + sprintf (text, "Random Generated Map"); + font_setcolor (128,128,128,0); + font_draw (x , y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x, 1 + y, text, 0); + y = y + 2 + (font[0].size.y << 1); + + /* Bomb Powerups */ + sprintf (text, "Bomb Powerup: %d", map.bombs); + font_setcolor (128,128,128,0); + font_draw (2 + x - (WIN_X / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0); + + /* Trigger */ + sprintf (text, "Trigger Specials: %d", map.sp_trigger); + font_setcolor (128,128,128,0); + font_draw (x , y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x, 1 + y, text, 0); + y = y + 2 + font[0].size.y; + + /* Fire Powerups */ + sprintf (text, "Fire Powerup: %d", map.fire); + font_setcolor (128,128,128,0); + font_draw (2 + x - (WIN_X / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0); + + /* Push */ + sprintf (text, "Push Specials: %d", map.sp_push); + font_setcolor (128,128,128,0); + font_draw (x , y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x, 1 + y, text, 0); + y = y + 2 + font[0].size.y; + + /* Shoe Powerups */ + sprintf (text, "Shoe Powerup: %d", map.shoes); + font_setcolor (128,128,128,0); + font_draw (2 + x - (WIN_X / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0); + + /* Row */ + sprintf (text, "Row Specials: %d", map.sp_row); + font_setcolor (128,128,128,0); + font_draw (x , y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x, 1 + y, text, 0); + y = y + 2 + font[0].size.y; + + + /* Mixed Powerups */ + sprintf (text, "Mixed Powerup: %d", map.mixed); + font_setcolor (128,128,128,0); + font_draw (2 + x - (WIN_X / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0); + + /* Special FREE + sprintf (text, "Push Specials: %d", map.sp_push); + font_setcolor (128,128,128,0); + font_draw (x , y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x, 1 + y, text, 0); */ + y = y + 2 + font[0].size.y; + + /* Death Powerups */ + sprintf (text, "Death Powerup: %d", map.death); + font_setcolor (128,128,128,0); + font_draw (2 + x - (WIN_X / 2), y, text, 0); + font_setcolor (255,255,255,0); + font_draw (3 + x - (WIN_X / 2) ,1 + y, text, 0); + + /* Special FREE + sprintf (text, "Row Specials: %d", map.sp_row); + font_setcolor (128,128,128,0); + font_draw (x , y, text, 0); + font_setcolor (255,255,255,0); + font_draw (1 + x, 1 + y, text, 0); */ + y = y + 2 + font[0].size.y; + + SDL_Flip (gfx.screen); + keybinput_new (&ki); + + while (!done) { + if (bman.gametype == GT_multi && bman.sock != -1) { + network_loop (); + eventstate = SDL_PollEvent (&event); + } + else + eventstate = SDL_WaitEvent (&event); + + if (eventstate != 0) + switch (event.type) { + case (SDL_QUIT): + bman.state = GS_quit; + done = 1; + break; + } + + done = keybinput_loop (&ki, &event); + } } +#undef WIN_X +#undef WIN_Y diff --git a/src/menu.c b/src/menu.c index c1890e4..f68cb88 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,13 +1,10 @@ -/* $Id: menu.c,v 1.27 2003/06/22 01:12:20 stpohle Exp $ */ +/* $Id: menu.c,v 1.28 2003/07/22 18:29:08 stpohle Exp $ */ /* menu's for the game */ #include #include "bomberclone.h" #include "gfx.h" -#define MENU_BG_SHADE_DARK -64 -#define MENU_BG_SHADE_BRIGHT 64 - /* draws a box size (x,y) */ void draw_menubox (int x, int y) diff --git a/src/multiwait.c b/src/multiwait.c index dc8e831..ce0d561 100644 --- a/src/multiwait.c +++ b/src/multiwait.c @@ -127,7 +127,13 @@ mw_draw_status () y += 32; } - mw_player = y; + /* add to update rect list */ + dest.x = dest.y = 0; + dest.h = y; + dest.w = gfx.res.y; + gfx_blitupdaterectdraw (&dest); + + mw_player = y; }; @@ -212,6 +218,12 @@ mw_draw_gfxselect (int selgfx) } } + dest.x = 0; + dest.y = mw_player; + dest.w = gfx.res.x; + dest.h = 8 + gfx.players[0].size.y; + gfx_blitupdaterectdraw (&dest); + mw_chat = mw_player + 8 + gfx.players[0].size.y; } @@ -226,6 +238,9 @@ mw_draw_chat () chat_addstatusline ("F4 - to start the game"); chat_addstatusline ("F5 - to change map settings"); } + else { + chat_addstatusline ("F5 - to see the map settings"); + } } }; @@ -273,15 +288,13 @@ wait_for_players () else { /* we have a connect so draw status */ if (bman.updatestatusbar) { mw_draw_status (); - gfx_AddUpdateRect (0, 0, gfx.res.x, mw_player); bman.updatestatusbar = 0; } mw_draw_gfxselect (selgfx); - gfx_AddUpdateRect (0, mw_player, gfx.res.x, mw_chat); mw_draw_chat (); } - gfx_UpdateRects (); + gfx_blitupdaterectdraw (); /* do the keyboard handling */ if (SDL_PollEvent (&event) != 0) @@ -336,14 +349,12 @@ wait_for_players () } if ((keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) && (!keypressed)) { - if (bman.players[bman.p_nr].gfx_nr == -1) { + if (bman.players[bman.p_nr].gfx_nr == -1) /* select player */ bman.players[bman.p_nr].gfx_nr = selgfx; - } - else { + else /* deselect player */ bman.players[bman.p_nr].gfx_nr = -1; - } net_change_playerid (bman.p_nr, 1); bman.updatestatusbar = 1; } @@ -353,19 +364,21 @@ wait_for_players () bman.updatestatusbar = 1; } - if ((GT_MP_PTPM) && keys[SDLK_F5] && (!keypressed)) { - /* Map modification */ - mapmenu (); + if (keys[SDLK_F5] && (!keypressed)) { + /* Map modification or setting display */ + if (GT_MP_PTPM) { + mapmenu (); + net_send_mapinfo (); + } + else + mapinfo (); draw_logo (); mw_draw_status (); mw_draw_gfxselect (selgfx); - UpdateRects_nr = 0; - gfx_AddUpdateRect (0, 0, gfx.res.x, gfx.res.y); chat.changed = 1; chat.lineschanged = 1; chat_drawbox (); mw_draw_chat (); - gfx_UpdateRects (); } chat_loop (&event); } diff --git a/src/network.c b/src/network.c index 7f619bc..8de9ffc 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,4 @@ -/* $Id: network.c,v 1.35 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: network.c,v 1.36 2003/07/22 18:29:08 stpohle Exp $ */ /* network routines. */ @@ -330,7 +330,7 @@ draw_netupdatestate () dest.y = y; SDL_BlitSurface (bman.players[i].gfx->smal_image, &src, gfx.screen, &dest); - gfx_AddUpdateRect (dest.x, dest.y, gfx.res.x - dest.x, dest.h); + gfx_blitupdaterectadd (&dest); } if (bman.players[i].net.net_istep == 0) @@ -811,3 +811,20 @@ net_game_send_special (int pl_nr, int ex_nr) if (PS_IS_netplayer (bman.players[pl].state) && pl != pl_nr && NET_CANSEND(pl)) send_special (&bman.players[pl].net.addr, pl_nr, bman.players[pl_nr].special.type, ex_nr); }; + + +/* Send mapinformations to all clients */ +void +net_send_mapinfo () +{ + int i; + + if (GT_MP_PTPS) + return; + + d_printf ("Send Mapinfo\n"); + + for (i = 0; i < MAX_PLAYERS; i++) + if (PS_IS_netplayer (bman.players[i].state) && i != bman.p_nr && NET_CANSEND(i)) + send_mapinfo (&bman.players[i].net.addr); +}; diff --git a/src/network.h b/src/network.h index 564e991..979361e 100644 --- a/src/network.h +++ b/src/network.h @@ -88,6 +88,7 @@ extern void net_send_players (); extern int net_check_timeout (int pl_nr); extern void net_dyn_pkgoption (); extern void net_send_chat (char *text, signed char notigamesrv); +extern void net_send_mapinfo (); // multiwait.c extern void wait_for_players (); diff --git a/src/packets.c b/src/packets.c index 1e5c87f..0e3ff08 100644 --- a/src/packets.c +++ b/src/packets.c @@ -161,6 +161,7 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr) /* send to the new client the servermode and the complete playerlist */ send_servermode (addr, i); + send_mapinfo (addr); for (j = 0; j < MAX_PLAYERS; j++) if (bman.players[j].net.addr.host[0] != 0 || bman.players[j].name[0] != 0) send_playerid (addr, bman.players[j].name, bman.players[j].net.addr.host, @@ -338,7 +339,7 @@ do_field (struct pkg_field *f_dat, _net_addr * addr) memcpy (&map.field[f_dat->x][f_dat->y], &f_dat->field, sizeof (_field)); } if (bman.state == GS_running) - draw_stone (f_dat->x, f_dat->y); + stonelist_add (f_dat->x, f_dat->y); if (f_dat->field.ex_nr > bman.last_ex_nr) bman.last_ex_nr = f_dat->field.ex_nr; @@ -608,8 +609,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr) map.bfield[(bomb->pos.x >> 8)][(bomb->pos.y >> 8)] = 0; //remove bomb at old location else map.bfield[(bomb->pos.x >> 8)][(bomb->pos.y >> 8)] = 1; //set bomb at position - draw_stone (bomb->pos.x >> 8, bomb->pos.y >> 8); - field_update (bomb->pos.x >> 8, bomb->pos.y >> 8); + stonelist_add (bomb->pos.x >> 8, bomb->pos.y >> 8); } if (bomb->state == BS_off && (b_dat->state == BS_ticking || b_dat->state == BS_trigger)) @@ -986,6 +986,67 @@ do_bcmservchat (struct pkg_bcmservchat *packet, _net_addr * addr) }; +void +send_mapinfo (_net_addr * addr) +{ + struct pkg_mapinfo map_pkg; + + map_pkg.h.typ = PKG_mapinfo; + map_pkg.h.len = sizeof (struct pkg_special); + map_pkg.h.flags = PKGF_ackreq; + map_pkg.size_x = map.size.x; + map_pkg.size_y = map.size.y; + map_pkg.bombs = map.bombs; + map_pkg.fire = map.fire; + map_pkg.shoes = map.shoes; + map_pkg.mixed = map.mixed; + map_pkg.death = map.death; + map_pkg.sp_trigger = map.sp_trigger; + map_pkg.sp_row = map.sp_row; + map_pkg.sp_push = map.sp_push; + if (map.random_tileset) + map_pkg.tileset[0] = 0; + else + strcpy (map_pkg.tileset, map.tileset); + map_pkg.map_selection = map.map_selection; + strcpy (map_pkg.mapname, map.map); + + send_pkg ((struct pkg *) &map_pkg, addr); +}; + + +void +do_mapinfo (struct pkg_mapinfo *map_pkg, _net_addr * addr) +{ + d_printf ("do_mapinfo (addr %d, pl_nr %d)\n", addr->pl_nr, addr->pl_nr); + + /* check if the server send this information */ + if (addr->pl_nr == 0) + return; + + if (map_pkg->tileset[0] == 0) { + map.random_tileset = 1; + map.tileset[0] = 0; + } + else { + map.random_tileset = 0; + strcpy(map.tileset, map_pkg->tileset); + } + strcpy (map.map, map_pkg->mapname); + map.map_selection = map_pkg->map_selection; + map.size.x = map_pkg->size_x; + map.size.y = map_pkg->size_y; + map.bombs = map_pkg->bombs; + map.fire = map_pkg->fire; + map.shoes = map_pkg->shoes; + map.mixed = map_pkg->mixed; + map.death = map_pkg->death; + map.sp_trigger = map_pkg->sp_trigger; + map.sp_push = map_pkg->sp_push; + map.sp_row = map_pkg->sp_row; +}; + + int inpkg_check (unsigned char typ, short int id, _net_addr * addr) { @@ -1144,6 +1205,9 @@ do_pkg (struct pkg *packet, _net_addr * addr) case (PKG_special): do_special ((struct pkg_special *) packet, addr); break; + case (PKG_mapinfo): + do_mapinfo ((struct pkg_mapinfo *) packet, addr); + break; default: send_error (addr, "BomberClone: unknown data packet"); break; diff --git a/src/packets.h b/src/packets.h index 8290f9d..d39661b 100644 --- a/src/packets.h +++ b/src/packets.h @@ -214,9 +214,11 @@ struct pkg_mapinfo { struct pkgheader h; char tileset[LEN_TILESETNAME]; char mapname[LEN_FILENAME]; + unsigned char map_selection; unsigned char bombs; unsigned char shoes; unsigned char fire; + unsigned char mixed; unsigned char death; unsigned char sp_trigger; unsigned char sp_push; @@ -269,6 +271,7 @@ extern int do_pkg (struct pkg *packet, _net_addr *addr); extern void do_bcmservchat (struct pkg_bcmservchat *packet, _net_addr *addr); extern void do_ill (struct pkg_ill *ill_pkg, _net_addr *addr); extern void do_special (struct pkg_special *sp_pkg, _net_addr *addr); +extern void do_mapinfo (struct pkg_mapinfo *map_pkg, _net_addr *addr); extern void send_pkg (struct pkg *packet, _net_addr *addr); extern void send_playerid (_net_addr *addr, char *name, char *pladdr, char *plport, int p_nr, int gfx_nr, signed char netflags); @@ -288,6 +291,7 @@ extern void send_pkgack (_net_addr *addr, unsigned char typ, short int id); extern void send_chat (_net_addr *addr, char *text); extern void send_ill (_net_addr *addr, int p_nr, _player *pl); extern void send_special (_net_addr *addr, int p_nr, int typ, int ex_nr); +extern void send_mapinfo (_net_addr *addr); extern void fwd_pkg (struct pkg *packet, _net_addr *addr); diff --git a/src/player.c b/src/player.c index aac6656..5d257b5 100644 --- a/src/player.c +++ b/src/player.c @@ -31,7 +31,8 @@ draw_player (_player * player) gfx.postab[player->pos.y & 255]; src.x = player->d * player->gfx->size.x; src.y = player->frame * player->gfx->size.y; - SDL_BlitSurface (player->gfx->ani.image, &src, gfx.screen, &dest); + + gfx_blit (player->gfx->ani.image, &src, gfx.screen, &dest, player->pos.y + 128); /* if the player is ill, draw this image above him */ if (PS_IS_alife (player->state)) { @@ -47,7 +48,7 @@ draw_player (_player * player) dest.y = gfx.offset.y + ((player->pos.y >> 8) - 1) * gfx.block.y + gfx.postab[player->pos.y & 255]; - SDL_BlitSurface (gfx.ill.image, &src, gfx.screen, &dest); + gfx_blit (gfx.ill.image, &src, gfx.screen, &dest, player->pos.y + 129); } } } @@ -67,9 +68,8 @@ draw_player (_player * player) src.x = 0; src.y = (2 * gfx.block.y) * player->frame; - SDL_BlitSurface (gfx.dead.image, &src, gfx.screen, &dest); + gfx_blit (gfx.dead.image, &src, gfx.screen, &dest, 0xFFFF); } - gfx_AddUpdateRect (dest.x, dest.y, dest.w, dest.h); player->old = player->pos; // save this position }; @@ -115,9 +115,7 @@ restore_players_screen () xs = x; for (; x <= xe; x++) for (y = ys; y <= ye; y++) - draw_stone (x, y); - gfx_AddUpdateRect (xs * gfx.block.x + gfx.offset.x, ys * gfx.block.y + gfx.offset.y, - gfx.block.x * 3, gfx.block.y * 3); + stonelist_add (x, y); } } }; diff --git a/src/special.c b/src/special.c index 93ec263..b809146 100644 --- a/src/special.c +++ b/src/special.c @@ -1,4 +1,4 @@ -/* $Id: special.c,v 1.23 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: special.c,v 1.24 2003/07/22 18:29:08 stpohle Exp $ */ /* special.c - procedues to control the specials */ #include "bomberclone.h" @@ -143,8 +143,7 @@ special_push (int p_nr) b->moves = p->speed; map.bfield[x][y] = 0; map.bfield[x1][y1] = 1; - draw_stone (x, y); - field_update (x, y); + stonelist_add (x, y); if (bman.gametype != GT_single) { net_game_send_bomb (bombs[i].x, bombs[i].y); } diff --git a/src/tileset.c b/src/tileset.c index 41e5870..c4e1430 100644 --- a/src/tileset.c +++ b/src/tileset.c @@ -1,4 +1,4 @@ -/* $Id: tileset.c,v 1.2 2003/07/16 14:42:00 stpohle Exp $ */ +/* $Id: tileset.c,v 1.3 2003/07/22 18:29:08 stpohle Exp $ */ /* load and select tilesets */ #include "bomberclone.h" @@ -216,7 +216,6 @@ tileset_load (char *tilesetname) SDL_FreeSurface (tmpimage); } } - UpdateRects_nr = 0; }; diff --git a/tools/convert-player.sh b/tools/convert-player.sh index c46c242..24e947f 100755 --- a/tools/convert-player.sh +++ b/tools/convert-player.sh @@ -1,17 +1,19 @@ # CROP Files +RES=310x330 +POS=+155+65 -RES=214x305 -POS=+211+89 - -SRES=90x128 +# SCALE +SRES=120x128 SPOS=+0+0 -ARES=90x2560 +ARES=120x2560 APOS=+0+0 -FRES=360x2560 +FRES=480x2560 FPOS=+0+0 +BACKGROUND="#FF00FF" + rm -rf crop* rm -rf out* rm -rf player.bmp