From 74c314d01c4fde66b02dd962e62aa2cd5155c0a1 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 22 Sep 2000 02:13:00 -0400 Subject: [PATCH] Version 2.9.7 --- level_1.c | 6 ++--- level_2.c | 11 +++++---- sidebar.c | 2 +- sound.c | 2 +- story.c | 13 ++++++++--- svmwgraph/sdl_svmwgraph.c | 47 +++++++++++++++------------------------ svmwgraph/sdl_svmwgraph.h | 3 +-- svmwgraph/svmwgraph.h | 3 +-- svmwgraph/vmw_paintpro.c | 4 +++- svmwgraph/vmw_palette.c | 13 +++++------ svmwgraph/vmw_setup.c | 5 ++--- tb1.c | 47 ++++++++++++++++++++++++++++----------- tb1_state.h | 1 + 13 files changed, 87 insertions(+), 70 deletions(-) diff --git a/level_1.c b/level_1.c index 09e132b..7701297 100644 --- a/level_1.c +++ b/level_1.c @@ -451,7 +451,7 @@ void levelone(tb1_state *game_state) { if (bullet[itemp].out) if (collision(bullet[itemp].x,bullet[itemp].y,10,10, enemy[i].x,enemy[i].y,9,9)) { - if (game_state->sound_enabled) + if ((game_state->sound_possible)&&(game_state->sound_enabled)) playGameFX(SND_KAPOW); enemy[i].hitsneeded--; if (enemy[i].hitsneeded<1) enemy[i].dead=1; @@ -524,7 +524,7 @@ void levelone(tb1_state *game_state) { } if (enemy[i].y>140) { if (collision(shipx,165,24,15,enemy[i].x,enemy[i].y,9,9)) { - if (game_state->sound_enabled) + if ((game_state->sound_possible)&&(game_state->sound_enabled)) playGameFX(SND_BONK); enemy[i].hitsneeded--; if (enemy[i].hitsneeded==0) enemy[i].dead=1; @@ -571,7 +571,7 @@ void levelone(tb1_state *game_state) { break; case ' ': for(j=0;j<2;j++) if (!bullet[j].out) { - if (game_state->sound_enabled) + if ((game_state->sound_possible)&&(game_state->sound_enabled)) playGameFX(SND_CC); bullet[j].out=1; bullet[j].x=shipx+15; diff --git a/level_2.c b/level_2.c index d8aeb2c..ec8418f 100644 --- a/level_2.c +++ b/level_2.c @@ -231,7 +231,7 @@ void leveltwoengine(tb1_state *game_state) (collision(bullet[j].x,bullet[j].y,3,4,passive[i].x, passive[i].y,10,5))){ if (passive[i].kind!=10) { - if (game_state->sound_enabled) + if ((game_state->sound_possible)&&(game_state->sound_enabled)) playGameFX(SND_KAPOW); passive[i].exploding=1; passive[i].explodeprogress=0; @@ -258,7 +258,8 @@ void leveltwoengine(tb1_state *game_state) if ((passive[i].y>155) && (passive[i].kind!=10)) { if ((collision(passive[i].x,passive[i].y,10,5,shipx+16,165,5,5))|| (collision(passive[i].x,passive[i].y,10,5,shipx+6,175,18,8))) { - if (game_state->sound_enabled) playGameFX(SND_BONK); + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_BONK); passive[i].dead=1; game_state->shields--; if(game_state->shields<0) levelover=1; @@ -274,7 +275,8 @@ void leveltwoengine(tb1_state *game_state) if (enemy[i].out) { if ((collision(enemy[i].x,enemy[i].y,2,5,shipx+16,165,5,5)) || (collision(enemy[i].x,enemy[i].y,2,5,shipx+6,175,18,8))) { - if (game_state->sound_enabled) playGameFX(SND_BONK); + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_BONK); enemy[i].out=0; game_state->shields--; if (game_state->shields<0) levelover=1; @@ -368,7 +370,8 @@ void leveltwoengine(tb1_state *game_state) break; case ' ': for(j=0;j<3;j++) if (!bullet[j].out) { - if (game_state->sound_enabled) playGameFX(SND_CC); + if ((game_state->sound_possible)&&(game_state->sound_enabled)) + playGameFX(SND_CC); bullet[j].out=1; bullet[j].x=shipx+21; bullet[j].y=165; diff --git a/sidebar.c b/sidebar.c index 0a55998..e2de7ef 100644 --- a/sidebar.c +++ b/sidebar.c @@ -41,7 +41,7 @@ int changescore(tb1_state *game_state) vmwTextXY(scorest,317-(strlen(scorest)*9),11, 12,0,1,tb1_font,vaddr); if ( ((game_state->score % 400)==0) && (game_state->shields<16) ) { - if (game_state->sound_enabled) + if ((game_state->sound_possible)&&(game_state->sound_enabled)) playGameFX(/*SND_ZRRP*/7); game_state->shields++; change_shields(game_state); diff --git a/sound.c b/sound.c index 080e688..bb3a2fa 100644 --- a/sound.c +++ b/sound.c @@ -41,7 +41,7 @@ int initSound(char *path_to_data) { /* open the audio device */ if(Mix_OpenAudio(22050, AUDIO_U16, 1, 1024) < 0) { fprintf(stderr, "can't open audio: %s\n", SDL_GetError()); - exit(2); + return -1; } loadFX(path_to_data); return 0; diff --git a/story.c b/story.c index e73915c..267a22e 100644 --- a/story.c +++ b/story.c @@ -134,10 +134,15 @@ void story(tb1_state *game_state) vmwTextXY("Ahhh.... Mr. Bombem.... ",1,1,15,0,0,tb1_font,game_state->virtual_1); vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - if (game_state->sound_enabled) playGameFX(0); + + if ((game_state->sound_possible) && (game_state->sound_enabled)) + playGameFX(0); + pauseawhile(6); - if (game_state->sound_enabled) playGameFX(2); + if ((game_state->sound_possible) && (game_state->sound_enabled)) + playGameFX(2); + /* Show fake error message */ vmwArbitraryCrossBlit(game_state->virtual_2,188,14,91,59, game_state->virtual_1,115,55); @@ -321,7 +326,9 @@ void story(tb1_state *game_state) usleep(80000); vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); - if (game_state->sound_enabled) playGameFX(2); + if ((game_state->sound_possible) && (game_state->sound_enabled)) + playGameFX(2); + for(xtemp=0;xtemp<10;xtemp++) { vmwPutSprite(explosion2,160,118,game_state->virtual_1); doflames(game_state); diff --git a/svmwgraph/sdl_svmwgraph.c b/svmwgraph/sdl_svmwgraph.c index 358fdf5..ab3f651 100644 --- a/svmwgraph/sdl_svmwgraph.c +++ b/svmwgraph/sdl_svmwgraph.c @@ -4,24 +4,15 @@ #include "svmwgraph.h" #include /* For atexit() */ -#define BPP_NUM_TO_TRY 2 -/* Should this be the following instead? -int bpp_to_try[]={32,24,16,15,8 -}; -*/ - -int bpp_to_try[]={16,8 -}; - /* Setup the Graphics */ /* Pass '0' to auto-detect bpp */ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp, int fullscreen,int verbose) { SDL_Surface *sdl_screen=NULL; - int mode,i=0; + int mode; - mode=SDL_SWSURFACE; + mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE; if (fullscreen) mode|=SDL_FULLSCREEN; /* Initialize the SDL library */ @@ -40,19 +31,17 @@ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp, sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode); } else { - i=0; - while ((iformat->BytesPerPixel*8; if (verbose) { printf(" + SDL Graphics Initialization successful...\n"); printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp); @@ -61,23 +50,23 @@ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp, } -void SDL_WritePaletteColor(vmwSVMWGraphState *state, - unsigned char r, - unsigned char g, - unsigned char b, - int color) { +void SDL_FlushPalette(vmwSVMWGraphState *state) { SDL_Surface *target; - SDL_Color temp_col; + SDL_Color temp_col[256]; + int i; - temp_col.r=r; - temp_col.g=g; - temp_col.b=b; + if (state->bpp==8) { + for(i=0;i<256;i++) { + temp_col[i].r=(state->palette[i]>>11)<<3; + temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2; + temp_col[i].b=(state->palette[i]&0x1f)<<3; + } - target=(SDL_Surface *)state->output_screen; - - SDL_SetColors(target,&temp_col,color,1); + target=(SDL_Surface *)state->output_screen; + SDL_SetColors(target,temp_col,0,256); + } } diff --git a/svmwgraph/sdl_svmwgraph.h b/svmwgraph/sdl_svmwgraph.h index ef93222..265adae 100644 --- a/svmwgraph/sdl_svmwgraph.h +++ b/svmwgraph/sdl_svmwgraph.h @@ -4,8 +4,7 @@ void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,int fullscreen, int verbose); -void SDL_WritePaletteColor(vmwSVMWGraphState *state,unsigned char r, - unsigned char g,unsigned char b,int color); +void SDL_FlushPalette(vmwSVMWGraphState *state); void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target, vmwVisual *source); void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source); void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target, vmwVisual *source); diff --git a/svmwgraph/svmwgraph.h b/svmwgraph/svmwgraph.h index 3c50fe2..7e3266a 100644 --- a/svmwgraph/svmwgraph.h +++ b/svmwgraph/svmwgraph.h @@ -112,8 +112,7 @@ void vmwUnFade(vmwVisual *source); extern void *(*vmwSetupGraphics)(int *xsize,int *ysize, int *bpp, int fullscreen,int verbose); extern void (*vmwBlitMemToDisplay)(vmwSVMWGraphState *display, vmwVisual *source); -extern void (*vmwWritePaletteColor)(vmwSVMWGraphState *state, - unsigned char r,unsigned char g,unsigned char b,int color); +extern void (*vmwFlushPalette)(vmwSVMWGraphState *state); extern void (*vmwClearKeyboardBuffer)(void); extern int (*vmwGetInput)(void); vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, diff --git a/svmwgraph/vmw_paintpro.c b/svmwgraph/vmw_paintpro.c index 56e0a63..dbe6b6b 100644 --- a/svmwgraph/vmw_paintpro.c +++ b/svmwgraph/vmw_paintpro.c @@ -98,7 +98,7 @@ int vmwLoadPicPacked(int x1,int y1,vmwVisual *target, /* 565 packed 16bit RGB */ for(i=0;i<256;i++) { - if (LoadPal) + if (LoadPal) vmwLoadPalette(graph_state, buffer[buffpointer], buffer[buffpointer+1], @@ -114,6 +114,8 @@ int vmwLoadPicPacked(int x1,int y1,vmwVisual *target, } } } + + if (LoadPal) vmwFlushPalette(graph_state); x=x1; y=y1; diff --git a/svmwgraph/vmw_palette.c b/svmwgraph/vmw_palette.c index ea8834e..ed298be 100644 --- a/svmwgraph/vmw_palette.c +++ b/svmwgraph/vmw_palette.c @@ -6,19 +6,16 @@ void vmwLoadPalette(vmwSVMWGraphState *state,unsigned char r, unsigned char g, unsigned char b,int color) { - if (state->bpp==8) { - - } - if (state->bpp==16) { + /* 565 color cube */ /* which can be LESS colorful than 8bpp. Imagine that */ - state->palette[color]= ( ((int)(r>>3)) <<11)+ + + state->palette[color]= ( ((int)(r>>3)) <<11)+ ( ((int)(g>>2)) <<5)+ (b>>3); - } - vmwWritePaletteColor(state,r,g,b,color); - + + } diff --git a/svmwgraph/vmw_setup.c b/svmwgraph/vmw_setup.c index 4936e25..94dde5f 100644 --- a/svmwgraph/vmw_setup.c +++ b/svmwgraph/vmw_setup.c @@ -9,8 +9,7 @@ void *(*vmwSetupGraphics)(int *xsize,int *ysize, int *bpp, int fullscreen,int verbose); void (*vmwBlitMemToDisplay)(vmwSVMWGraphState *display, vmwVisual *source); -void (*vmwWritePaletteColor)(vmwSVMWGraphState *state, - unsigned char r,unsigned char g,unsigned char b,int color); +void (*vmwFlushPalette)(vmwSVMWGraphState *state); void (*vmwClearKeyboardBuffer)(void); int (*vmwGetInput)(void); @@ -64,7 +63,7 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, vmwBlitMemToDisplay=SDL_Double16bpp_BlitMem; } } - vmwWritePaletteColor=SDL_WritePaletteColor; + vmwFlushPalette=SDL_FlushPalette; vmwClearKeyboardBuffer=SDL_clearKeyboardBuffer; vmwGetInput=SDL_getInput; break; diff --git a/tb1.c b/tb1.c index 1198cb2..f008240 100644 --- a/tb1.c +++ b/tb1.c @@ -10,7 +10,7 @@ \* This source is released under the GPL */ /****************************************************************/ -#define TB1_VERSION "2.9.5" +#define TB1_VERSION "2.9.7" #include #include /* for calloc */ @@ -82,6 +82,8 @@ int main(int argc,char **argv) game_state->virtual_1=NULL; game_state->virtual_2=NULL; game_state->virtual_3=NULL; + game_state->sound_possible=1; + game_state->music_enabled=1; game_state->sound_enabled=1; /* Parse Command Line Arguments */ @@ -158,19 +160,33 @@ int main(int argc,char **argv) printf(" + Seeding random number generator...\n"); /* Load sounds */ - initSound(game_state->path_to_data); - loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data)); + if (initSound(game_state->path_to_data)<0) game_state->sound_possible=0; + + if (game_state->sound_possible) { + loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data)); + } printf(" + Loaded sounds...\n"); /* Setup Graphics */ - + + if (scale==1) { + if ( (game_state->graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET, 320,200, 0,scale,fullscreen,1))==NULL) { fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); return VMW_ERROR_DISPLAY; } + } + else { + if ( (game_state->graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET, + 640,480, + 0,scale,fullscreen,1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; + } + } /* Load the tom bombem font */ game_state->graph_state->default_font= @@ -200,7 +216,7 @@ int main(int argc,char **argv) tb1_font=game_state->graph_state->default_font; for (x=0;x<256;x++) vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */ - + /* Do the VMW Software Production Logo */ for(x=0;x<=40;x++) { vmwLoadPalette(game_state->graph_state, ((x+20)*4),0,0,100+x); @@ -211,6 +227,8 @@ int main(int argc,char **argv) /* Set the white color */ vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15); + vmwFlushPalette(game_state->graph_state); + /* Actually draw the stylized VMW */ for(x=0;x<=40;x++){ vmwDrawVLine(x+40,45,2*x,100+x,virtual_1); @@ -230,14 +248,16 @@ int main(int argc,char **argv) vmwTextXY("A VMW SOFTWARE PRODUCTION",60,140, 15,15,0,tb1_font,virtual_1); - if (game_state->sound_enabled) playSound(); + if ((game_state->sound_possible) && (game_state->music_enabled)) + playSound(); vmwBlitMemToDisplay(game_state->graph_state,virtual_1); pauseawhile(5); - - stopSound(); - loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data)); - + + if (game_state->sound_possible) { + stopSound(); + loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data)); + } /* Clear the Screen and get ready for the Menu */ vmwClearScreen(virtual_1,0); @@ -271,7 +291,8 @@ int main(int argc,char **argv) } vmwFlipVirtual(virtual_1,virtual_3,320,200); - if (game_state->sound_enabled) playSound(); + if ((game_state->sound_possible) &&(game_state->music_enabled)) + playSound(); vmwBlitMemToDisplay(game_state->graph_state,virtual_1); while (!vmwGetInput()) usleep(300); @@ -309,7 +330,7 @@ int main(int argc,char **argv) usleep(10); gettimeofday(&time_info,&dontcare); if (time_info.tv_sec-time_sec>40) { - stopSound(); + if (game_state->sound_possible) stopSound(); credits(game_state); ch=VMW_ENTER; barpos=9; @@ -337,7 +358,7 @@ int main(int argc,char **argv) if(barpos==7) barpos=0; if(barpos<0) barpos=6; } - stopSound(); + if (game_state->sound_possible) stopSound(); /* Run whatever it was that the person pressed */ switch (barpos) { diff --git a/tb1_state.h b/tb1_state.h index 7486dc5..a01553a 100644 --- a/tb1_state.h +++ b/tb1_state.h @@ -9,6 +9,7 @@ typedef struct { vmwVisual *virtual_2; /* 320x400x8 */ vmwVisual *virtual_3; /* 320x200x8 */ vmwSVMWGraphState *graph_state; /* Graphics state */ + int sound_possible; /* Sound even possible? */ int sound_enabled; /* Sound on or off */ int music_enabled; /* Music on or off */ int sound_volume; /* Sound volume */