Exemplo n.º 1
0
int credits_handler(window *wind, d_event *event, credits *cr)
{
	int j, l, y;
	char * tempp;
	
	switch (event->type)
	{
		case EVENT_KEY_COMMAND:
			if (!call_default_handler(event))	// if not print screen, debug etc
				window_close(wind);
			return 1;

		case EVENT_MOUSE_BUTTON_DOWN:
		case EVENT_MOUSE_BUTTON_UP:
			if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT)
			{
				window_close(wind);
				return 1;
			}
			break;

		case EVENT_IDLE:
			if (cr->done>NUM_LINES)
			{
				window_close(wind);
				return 0;
			}
			break;
			
		case EVENT_WINDOW_DRAW:
			timer_delay(F1_0/28);
			
			if (cr->row == 0)
			{
				do {
					cr->buffer_line = (cr->buffer_line+1) % NUM_LINES;
				get_line:;
					if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], 80, cr->file ))	{
						char *p;
						if (cr->have_bin_file) // is this a binary tbl file
							decode_text_line (cr->buffer[cr->buffer_line]);
						p = cr->buffer[cr->buffer_line];
						if (p[0] == ';')
							goto get_line;
						
						if (p[0] == '%')
						{
							if (p[1] == ALLOWED_CHAR)
							{
								int i = 0, len = strlen(p);
								for (i = 0; i < len; i++)
									p[i] = p[i+2];
							}
							else
								goto get_line;
						}
						
					} else	{
						//fseek( file, 0, SEEK_SET);
						cr->buffer[cr->buffer_line][0] = 0;
						cr->done++;
					}
				} while (cr->extra_inc--);
				cr->extra_inc = 0;
			}

			// cheap but effective: towards end of credits sequence, fade out the music volume
			if (cr->done >= NUM_LINES-16)
			{
				static int curvol = -10; 
				if (curvol == -10) 
					curvol = GameCfg.MusicVolume;
				if (curvol > (NUM_LINES-cr->done)/2)
				{
					curvol = (NUM_LINES-cr->done)/2;
					songs_set_volume(curvol);
				}
			}
			
			y = cr->first_line_offset - cr->row;
			show_fullscr(&cr->backdrop);
			for (j=0; j<NUM_LINES; j++ )	{
				char *s;
				
				l = (cr->buffer_line + j + 1 ) %  NUM_LINES;
				s = cr->buffer[l];
				
				if ( s[0] == '!' ) {
					s++;
				} else if ( s[0] == '$' )	{
					gr_set_curfont( HUGE_FONT );
					s++;
				} else if ( s[0] == '*' )	{
					gr_set_curfont( MEDIUM3_FONT );
					s++;
				} else
					gr_set_curfont( MEDIUM2_FONT );
				
				tempp = strchr( s, '\t' );
				if ( !tempp )	{
					// Wacky Fast Credits thing
					int w, h, aw;
					
					gr_get_string_size( s, &w, &h, &aw);
					gr_string( 0x8000, y, s );
				}
				y += ROW_SPACING;
			}
			
			cr->row += SHEIGHT/200;
			if (cr->row >= ROW_SPACING)
				cr->row = 0;
			break;

		case EVENT_WINDOW_CLOSE:
			gr_free_bitmap_data (&cr->backdrop);
			PHYSFS_close(cr->file);
			songs_set_volume(GameCfg.MusicVolume);
			songs_play_song( SONG_TITLE, 1 );
			d_free(cr);
			break;
			
		default:
			break;
	}
	
	return 0;
}
Exemplo n.º 2
0
// Set up everything for our music
// NOTE: you might think this is done once per runtime but it's not! It's done for EACH song so that each mission can have it's own descent.sng structure. We COULD optimize that by only doing this once per mission.
void songs_init()
{
    int i = 0;
    char inputline[80+1];
    PHYSFS_file * fp = NULL;
    char sng_file[PATH_MAX];

    Songs_initialized = 0;

    if (BIMSongs != NULL)
        d_free(BIMSongs);

    memset(sng_file, '\0', sizeof(sng_file));
    if (Current_mission != NULL) // try MISSION_NAME.sngdxx - might be rarely used but handy if you want a songfile for a specific mission outside of the mission hog file. use special extension to not crash with other ports of the game
    {
        snprintf(sng_file, strlen(Current_mission_filename)+8, "%s.sngdxx", Current_mission_filename);
        fp = PHYSFSX_openReadBuffered(sng_file);
    }

    if (fp == NULL) // try descent.sngdxx - a songfile specifically for dxx which level authors CAN use (dxx does not care if descent.sng contains MP3/OGG/etc. as well) besides the normal descent.sng containing files other versions of the game cannot play. this way a mission can contain a DOS-Descent compatible OST (hmp files) as well as a OST using MP3, OGG, etc.
        fp = PHYSFSX_openReadBuffered( "descent.sngdxx" );

    if (fp == NULL) // try to open regular descent.sng
        fp = PHYSFSX_openReadBuffered( "descent.sng" );

    if ( fp == NULL ) // No descent.sng available. Define a default song-set
    {
        int predef=30; // define 30 songs - period

        MALLOC(BIMSongs, bim_song_info, predef);
        if (!BIMSongs)
            return;

        strncpy(BIMSongs[SONG_TITLE].filename, "descent.hmp",sizeof(BIMSongs[SONG_TITLE].filename));
        strncpy(BIMSongs[SONG_BRIEFING].filename, "briefing.hmp",sizeof(BIMSongs[SONG_BRIEFING].filename));
        strncpy(BIMSongs[SONG_CREDITS].filename, "credits.hmp",sizeof(BIMSongs[SONG_CREDITS].filename));
        strncpy(BIMSongs[SONG_ENDLEVEL].filename, "endlevel.hmp",sizeof(BIMSongs[SONG_ENDLEVEL].filename));	// can't find it? give a warning
        strncpy(BIMSongs[SONG_ENDGAME].filename, "endgame.hmp",sizeof(BIMSongs[SONG_ENDGAME].filename));	// ditto

        for (i = SONG_FIRST_LEVEL_SONG; i < predef; i++) {
            snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%02d.hmp", i - SONG_FIRST_LEVEL_SONG + 1);
            if (!PHYSFSX_exists(BIMSongs[i].filename,1))
                snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%d.hmp", i - SONG_FIRST_LEVEL_SONG);
            if (!PHYSFSX_exists(BIMSongs[i].filename,1))
            {
                memset(BIMSongs[i].filename, '\0', sizeof(BIMSongs[i].filename)); // music not available
                break;
            }
        }
    }
    else
    {
        while (!PHYSFS_eof(fp))
        {
            PHYSFSX_fgets(inputline, 80, fp );
            if ( strlen( inputline ) )
            {
                BIMSongs = d_realloc(BIMSongs, sizeof(bim_song_info)*(i+1));
                memset(BIMSongs[i].filename, '\0', sizeof(BIMSongs[i].filename));
                sscanf( inputline, "%15s", BIMSongs[i].filename );

                if (strrchr(BIMSongs[i].filename, '.'))
                    if (!stricmp(strrchr(BIMSongs[i].filename, '.'), ".hmp") ||
                            !stricmp(strrchr(BIMSongs[i].filename, '.'), ".mp3") ||
                            !stricmp(strrchr(BIMSongs[i].filename, '.'), ".ogg") ||
                            !stricmp(strrchr(BIMSongs[i].filename, '.'), ".aif") ||
                            !stricmp(strrchr(BIMSongs[i].filename, '.'), ".mid") ||
                            !stricmp(strrchr(BIMSongs[i].filename, '.'), ".flac")
                       )
                        i++;
            }
        }

        // HACK: If Descent.hog is patched from 1.0 to 1.5, descent.sng is turncated. So let's patch it up here
        if (i==12 && PHYSFSX_fsize("descent.sng")==422)
        {
            BIMSongs = d_realloc(BIMSongs, sizeof(bim_song_info)*(i+15));
            for (i = 12; i <= 26; i++)
                snprintf(BIMSongs[i].filename, sizeof(BIMSongs[i].filename), "game%02d.hmp", i-4);
        }
    }

    Num_bim_songs = i;
    Songs_initialized = 1;
    if (fp != NULL)
        PHYSFS_close(fp);

    if (GameArg.SndNoMusic)
        GameCfg.MusicType = MUSIC_TYPE_NONE;

    // If SDL_Mixer is not supported (or deactivated), switch to no-music type if SDL_mixer-related music type was selected
#ifdef USE_SDLMIXER
    if (GameArg.SndDisableSdlMixer)
#else
    if (1)
#endif
    {
#ifndef _WIN32
        if (GameCfg.MusicType == MUSIC_TYPE_BUILTIN)
            GameCfg.MusicType = MUSIC_TYPE_NONE;
#endif
        if (GameCfg.MusicType == MUSIC_TYPE_CUSTOM)
            GameCfg.MusicType = MUSIC_TYPE_NONE;
    }

    if (GameCfg.MusicType == MUSIC_TYPE_REDBOOK)
        RBAInit();
#ifdef USE_SDLMIXER
    else if (GameCfg.MusicType == MUSIC_TYPE_CUSTOM)
        jukebox_load();
#endif

    songs_set_volume(GameCfg.MusicVolume);
}
Exemplo n.º 3
0
static window_event_result credits_handler(window *, const d_event &event, credits *cr)
{
	int l, y;
	window_event_result result;

	switch (event.type)
	{
		case EVENT_KEY_COMMAND:
			if ((result = call_default_handler(event)) == window_event_result::ignored)	// if not print screen, debug etc
			{
				return window_event_result::close;
			}
			return result;

		case EVENT_MOUSE_BUTTON_DOWN:
		case EVENT_MOUSE_BUTTON_UP:
			if (event_mouse_get_button(event) == MBTN_LEFT || event_mouse_get_button(event) == MBTN_RIGHT)
			{
				return window_event_result::close;
			}
			break;

		case EVENT_IDLE:
			if (cr->done>NUM_LINES)
			{
				return window_event_result::close;
			}
			break;
			
		case EVENT_WINDOW_DRAW:
#if defined(DXX_BUILD_DESCENT_I)
			timer_delay(F1_0/17);
#elif defined(DXX_BUILD_DESCENT_II)
			timer_delay(F1_0/28);
#endif
			
			if (cr->row == 0)
			{
				do {
					cr->buffer_line = (cr->buffer_line+1) % NUM_LINES;
#if defined(DXX_BUILD_DESCENT_II)
				get_line:;
#endif
					if (PHYSFSX_fgets( cr->buffer[cr->buffer_line], cr->file ))	{
						char *p;
						if (cr->have_bin_file) // is this a binary tbl file
							decode_text_line (cr->buffer[cr->buffer_line]);
#if defined(DXX_BUILD_DESCENT_I)
						p = strchr(&cr->buffer[cr->buffer_line][0],'\n');
						if (p) *p = '\0';
#elif defined(DXX_BUILD_DESCENT_II)
						p = cr->buffer[cr->buffer_line];
						if (p[0] == ';')
							goto get_line;
						
						if (p[0] == '%')
						{
							if (p[1] == ALLOWED_CHAR)
							{
								for (int i = 0; p[i]; i++)
									p[i] = p[i+2];
							}
							else
								goto get_line;
						}
#endif	
					} else	{
						//fseek( file, 0, SEEK_SET);
						cr->buffer[cr->buffer_line][0] = 0;
						cr->done++;
					}
				} while (cr->extra_inc--);
				cr->extra_inc = 0;
			}

			// cheap but effective: towards end of credits sequence, fade out the music volume
			if (cr->done >= NUM_LINES-16)
			{
				static int curvol = -10; 
				if (curvol == -10) 
					curvol = GameCfg.MusicVolume;
				if (curvol > (NUM_LINES-cr->done)/2)
				{
					curvol = (NUM_LINES-cr->done)/2;
					songs_set_volume(curvol);
				}
			}
			
			y = cr->first_line_offset - cr->row;
			show_fullscr(cr->backdrop);
			for (uint_fast32_t j=0; j != NUM_LINES; ++j, y += ROW_SPACING)
			{
				l = (cr->buffer_line + j + 1 ) %  NUM_LINES;
				const char *s = cr->buffer[l];
				if (!s)
					continue;
				
				if ( s[0] == '!' ) {
					s++;
				} else if ( s[0] == '$' )	{
					gr_set_curfont( HUGE_FONT );
					s++;
				} else if ( s[0] == '*' )	{
					gr_set_curfont( MEDIUM3_FONT );
					s++;
				} else
					gr_set_curfont( MEDIUM2_FONT );
				
				const auto tempp = strchr( s, '\t' );
				if ( !tempp )	{
					// Wacky Fast Credits thing
					gr_string( 0x8000, y, s );
				}
			}
			
			cr->row += SHEIGHT/200;
			if (cr->row >= ROW_SPACING)
				cr->row = 0;
			break;

		case EVENT_WINDOW_CLOSE:
			songs_set_volume(GameCfg.MusicVolume);
			songs_play_song( SONG_TITLE, 1 );
			std::default_delete<credits>()(cr);
			break;
		default:
			break;
	}
	return window_event_result::ignored;
}