Example #1
0
bool FeTextureContainer::load_with_ffmpeg(
	const std::string &path,
	const std::string &filename,
	bool is_image )
{
	std::string loaded_name;
	bool res=false;

	if ( is_supported_archive( path ) )
	{
		loaded_name = path + "|" + filename;
		if ( loaded_name.compare( m_file_name ) == 0 )
			return true;

		clear();
		m_movie = new FeMedia( FeMedia::AudioVideo );
		res = m_movie->openFromArchive( path, filename, &m_texture );
	}
	else
	{
		loaded_name = path + filename;
		if ( loaded_name.compare( m_file_name ) == 0 )
			return true;

		clear();
		m_movie = new FeMedia( FeMedia::AudioVideo );
		res = m_movie->openFromFile( loaded_name, &m_texture );
	}

	if ( !res )
	{
		std::cout << "ERROR loading video: "
			<< loaded_name << std::endl;

		delete m_movie;
		m_movie = NULL;
		return false;
	}

	if ( is_image && (!m_movie->is_multiframe()) )
	{
		m_movie_status = -1; // don't play if there is only one frame

		// if there is only one frame, then we can update the texture immediately
		// (the frame will have been preloaded) and delete our movie object now
		delete m_movie;
		m_movie = NULL;
	}
	else if (m_video_flags & VF_NoAutoStart)
		m_movie_status = 0; // 0=loaded but not on track to play
	else
		m_movie_status = 1; // 1=on track to be played

	m_file_name = loaded_name;
	return true;
}
Example #2
0
FeSound *FePresent::add_sound( const char *n, bool reuse )
{
    //
    // Behaviour:
    //
    // - if n is empty, return a new (empty) sound object
    // - if n is supplied:
    //      - if n matches an existing sound and reuse is true,
    //        return that matching sound object
    //      - otherwise return a new sound object loaded with n
    //

    std::string path;
    std::string name=n;
    if ( !name.empty() )
    {
        if ( is_relative_path( name ) )
        {
            int script_id = get_script_id();
            if ( script_id < 0 )
                m_feSettings->get_path( FeSettings::Current, path );
            else
                m_feSettings->get_plugin_full_path( script_id, path );
        }

        if ( reuse )
        {
            std::string test;
            if ( is_supported_archive( path ) )
                test = name;
            else
                test = path + name;

            for ( std::vector<FeSound *>::iterator itr=m_sounds.begin();
                    itr!=m_sounds.end(); ++itr )
            {
                if ( test.compare( (*itr)->get_file_name() ) == 0 )
                    return (*itr);
            }
        }
    }

    // Sound not found, try loading now
    //
    FeSound *new_sound = new FeSound();

    if ( !name.empty() )
        new_sound->load( path, name );

    new_sound->set_volume(
        m_feSettings->get_play_volume( FeSoundInfo::Sound ) );

    m_sounds.push_back( new_sound );
    return new_sound;
}
Example #3
0
void FeFontContainer::set_font( const std::string &p, const std::string &n )
{
    m_name = n;

    if ( is_supported_archive( p ) )
    {
        if ( m_zs )
            delete m_zs;

        m_zs = new FeZipStream( p );
        m_zs->open( n );

        m_font.loadFromStream( *m_zs );
    }
    else
        m_font.loadFromFile( p + n );
}
Example #4
0
void FeTextureContainer::internal_update_selection( FeSettings *feSettings )
{
	int filter_index = feSettings->get_filter_index_from_offset( m_filter_offset );
	int rom_index = feSettings->get_rom_index( filter_index, m_index_offset );

	//
	// Optimization opportunity: We could already be showing the artwork for rom_index if the
	// layout uses the image swap() function... if we are, then there is no need to do anything...
	//
	if (( m_current_rom_index == rom_index )
				&& ( m_current_filter_index == filter_index ))
	{
#ifdef FE_DEBUG
		std::cout << "Optimization: " << m_file_name << " not loaded." << std::endl;
#endif
		return;
	}

	m_current_rom_index = rom_index;
	m_current_filter_index = filter_index;

	std::vector<std::string> vid_list;
	std::vector<std::string> image_list;
	std::string archive_name; // empty if no archive

	if ( m_type == IsArtwork )
	{
		FeRomInfo *rom	= feSettings->get_rom_absolute( filter_index, rom_index );
		if ( !rom )
			return;

		if ( !feSettings->get_best_artwork_file( *rom,
			m_art_name,
			vid_list,
			image_list,
			(m_video_flags & VF_DisableVideo) ) )
		{
			// check for layout fallback images/videos
			std::string layout_path;
			feSettings->get_path( FeSettings::Current,
				layout_path );

			if ( !layout_path.empty() )
			{
				const std::string &emu_name = rom->get_info(
					FeRomInfo::Emulator );

				if ( is_supported_archive( layout_path ) )
				{
					archive_name = layout_path;

					// check for "[emulator-[artlabel]" artworks first
					if ( !gather_artwork_filenames_from_archive(
							layout_path, emu_name + "-" + m_art_name,
							vid_list, image_list ) )
					{
						// then "[artlabel]"
						gather_artwork_filenames_from_archive( layout_path,
							m_art_name, vid_list, image_list );
					}
				}
				else
				{
					std::vector<std::string> layout_paths;
					layout_paths.push_back( layout_path );

					// check for "[emulator-[artlabel]" artworks first
					if ( !gather_artwork_filenames( layout_paths,
							emu_name + "-" + m_art_name,
							vid_list, image_list ) )
					{
						// then "[artlabel]"
						gather_artwork_filenames( layout_paths,
							m_art_name, vid_list, image_list );
					}
				}
			}
		}
	}
	else if ( m_type == IsDynamic )
	{
		std::string work = m_art_name;
		FePresent::script_process_magic_strings( work,
				m_filter_offset,
				m_index_offset );

		feSettings->get_best_dynamic_image_file( filter_index,
			rom_index,
			work,
			vid_list,
			image_list );
	}

	// Load any found videos/images now
	//
	bool loaded=false;
	std::vector<std::string>::iterator itr;

#ifndef NO_MOVIE
	if ( m_video_flags & VF_DisableVideo )
		vid_list.clear();

	for ( itr=vid_list.begin(); itr != vid_list.end(); ++itr )
	{
		std::string path = archive_name;
		std::string filename = *itr;

		if ( path.empty() )
		{
			// test for artwork in an archive
			// format of filename is "<archivename>|<filename>"
			size_t pos = (*itr).find( "|" );
			if ( pos != std::string::npos )
			{
				path = (*itr).substr( 0, pos );
				filename = (*itr).substr( pos+1 );
			}
		}

		if ( try_to_load( path, filename ) )
		{
			loaded = true;
			break;
		}
	}
#endif

	if ( !loaded )
	{
		if ( image_list.empty() )
			clear();
		else
		{
			for ( itr=image_list.begin();
				itr != image_list.end(); ++itr )
			{
				std::string path = archive_name;
				std::string filename = *itr;

				if ( path.empty() )
				{
					// test for artwork in an archive
					// format of filename is "<archivename>|<filename>"
					size_t pos = (*itr).find( "|" );
					if ( pos != std::string::npos )
					{
						path = (*itr).substr( 0, pos );
						filename = (*itr).substr( pos+1 );
					}
				}

				if ( try_to_load( path, filename, true ) )
				{
					loaded = true;
					break;
				}
			}
		}
	}

	//
	// Texture was replaced, so notify the attached images
	//
	notify_texture_change();
}
Example #5
0
bool FeTextureContainer::try_to_load(
	const std::string &path,
	const std::string &filename,
	bool is_image )
{
	std::string loaded_name;

#ifndef NO_SWF
	if ( !is_image && tail_compare( filename, FE_SWF_EXT ) )
	{

		if ( is_supported_archive( path ) )
		{
			loaded_name = path + "|" + filename;
			if ( loaded_name.compare( m_file_name ) == 0 )
				return true;

			m_swf = new FeSwf();

			if (!m_swf->open_from_archive( path, filename ))
			{
				std::cout << " ! ERROR loading SWF from archive: "
					<< path << " (" << filename << ")" << std::endl;

				delete m_swf;
				m_swf = NULL;
				return false;
			}
		}
		else
		{
			loaded_name = path + filename;
			if ( loaded_name.compare( m_file_name ) == 0 )
				return true;

			m_swf = new FeSwf();
			if (!m_swf->open_from_file( loaded_name ))
			{
				std::cout << " ! ERROR loading SWF: "
					<< loaded_name << std::endl;

				delete m_swf;
				m_swf = NULL;
				return false;
			}
		}

		m_file_name = loaded_name;
		return true;
	}
#endif

#ifndef NO_MOVIE
	if ( !is_image && FeMedia::is_supported_media_file( filename ) )
		return load_with_ffmpeg( path, filename, false );
#endif

	if ( is_supported_archive( path ) )
	{
		loaded_name = path + "|" + filename;
		if ( loaded_name.compare( m_file_name ) == 0 )
			return true;

		clear();
		FeZipStream zs( path );
		if ( !zs.open( filename ) )
		{
			// Error opening specified filename.  Try to correct
			// in case filename is in a subdir of the archive
			std::string temp;
			if ( get_archive_filename_with_base(
					temp, path, filename ) )
			{
				zs.open( temp );
				loaded_name = path + "|" + temp;
			}
		}

		if ( m_texture.loadFromStream( zs ) )
		{
			m_file_name = loaded_name;
			return true;
		}
	}
	else
	{
		loaded_name = path + filename;
		if ( loaded_name.compare( m_file_name ) == 0 )
			return true;

		clear();
		if ( m_texture.loadFromFile( loaded_name ) )
		{
			m_file_name = loaded_name;
			return true;
		}
	}

#ifndef NO_MOVIE
	//
	// we should only get here if we failed to load an image with SFML
	// try loading it with ffmpeg instead, which can handle more image
	// formats...
	//
	return load_with_ffmpeg( path, filename, is_image );
#else
	return false;
#endif
}
Example #6
0
FeShader *FePresent::add_shader( FeShader::Type type, const char *shader1, const char *shader2 )
{
    std::string path;
    m_feSettings->get_path( FeSettings::Current, path );

    std::string s1 = clean_path( shader1 );

    m_scriptShaders.push_back( new FeShader() );
    FeShader *sh = m_scriptShaders.back();

    if ( !is_relative_path( s1 ) )
        path.clear();

    switch ( type )
    {
    case FeShader::VertexAndFragment:
        if ( is_supported_archive( path ) )
        {
            //
            // Known Issue: We don't properly handle the
            // situation where one shader is specified as a
            // relative path and is in a zip, while the other
            // is specified as an absolute path.  If the first
            // is in a zip, the second is assumed to be in the
            // same zip as well.
            //
            FeZipStream zs1( path );
            zs1.open( shader1 );

            FeZipStream zs2( path );
            zs2.open( shader2 );

            sh->load( zs1, zs2 );
        }
        else
        {
            std::string path2 = path;
            std::string s2 = clean_path( shader2 );
            if ( !is_relative_path( s2 ) )
                path2.clear();

            sh->load( path + s1, path2 + s2 );
        }
        break;

    case FeShader::Vertex:
    case FeShader::Fragment:
        if ( is_supported_archive( path ) )
        {
            FeZipStream zs( path );
            zs.open( shader1 );

            sh->load( zs, type );
        }
        else
        {
            sh->load( path + s1, type );
        }
        break;

    case FeShader::Empty:
    default:
        break;
    }

    return sh;
}