Exemple #1
0
//----------------------------------------------------------------------------//
int OggBuffer::vorbisSeek(void *datasource, ogg_int64_t offset, int whence)
{
	size_t				spaceToEOF;
	ogg_int64_t			actualOffset;
	Ogre::DataStreamPtr	vorbisData;

	vorbisData = *(Ogre::DataStreamPtr*)datasource;

	switch (whence)
	{
	case SEEK_SET:
		if (vorbisData->size() >= offset)
			actualOffset = offset;
		else
			actualOffset = vorbisData->size();
		vorbisData->seek((int)actualOffset);
		break;
	case SEEK_CUR:
		spaceToEOF = vorbisData->size() - vorbisData->tell();
		if (offset < spaceToEOF)
			actualOffset = (offset);
		else
			actualOffset = spaceToEOF;	
		vorbisData->seek( static_cast<size_t>(vorbisData->tell() + actualOffset));
		break;
	case SEEK_END:
		vorbisData->seek(vorbisData->size());
		break;
	default:
		SoundSystem::getSingleton().logMessage("*** ERROR *** Unknown seek command in VorbisSeek");
		break;
	};

	return 0;
}
Exemple #2
0
//----------------------------------------------------------------------------//
size_t OggBuffer::vorbisRead(void *ptr, size_t byteSize, size_t sizeToRead, void *datasource )
{
	size_t				spaceToEOF;			// How much more we can read till we hit the EOF marker
	size_t				actualSizeToRead;	// How much data we are actually going to read from memory
	Ogre::DataStreamPtr	vorbisData;			// Our vorbis data, for the typecast

	// Get the data in the right format
	vorbisData = *(Ogre::DataStreamPtr*)datasource;

	// Calculate how much we need to read.  This can be sizeToRead*byteSize or less depending on how near the EOF marker we are
	spaceToEOF = vorbisData->size() - vorbisData->tell();
	if ((sizeToRead * byteSize) < spaceToEOF)
		actualSizeToRead = (sizeToRead * byteSize);
	else
		actualSizeToRead = spaceToEOF;	
	
	// A simple copy of the data from memory to the datastruct that the vorbis libs will use
	if (actualSizeToRead)
	{
		// Copy the data from the start of the file PLUS how much we have already read in
		vorbisData->read(ptr, actualSizeToRead);
	}

	// Return how much we read (in the same way fread would)
	return actualSizeToRead;
}
size_t RocketInterface::Tell(Rocket::Core::FileHandle file)
{
    if (!file)
        return 0;

    Ogre::DataStreamPtr stream = *reinterpret_cast<Ogre::DataStreamPtr*>(file);
    return stream->tell();
}
Exemple #4
0
int64_t FFmpeg_Decoder::seek(void *user_data, int64_t offset, int whence)
{
    Ogre::DataStreamPtr stream = static_cast<FFmpeg_Decoder*>(user_data)->mDataStream;

    whence &= ~AVSEEK_FORCE;
    if(whence == AVSEEK_SIZE)
        return stream->size();
    if(whence == SEEK_SET)
        stream->seek(offset);
    else if(whence == SEEK_CUR)
        stream->seek(stream->tell()+offset);
    else if(whence == SEEK_END)
        stream->seek(stream->size()+offset);
    else
        return -1;

    return stream->tell();
}
int64_t OgreResource_Seek(void *user_data, int64_t offset, int whence)
{
    Ogre::DataStreamPtr stream = static_cast<VideoState*>(user_data)->stream;

    whence &= ~AVSEEK_FORCE;
    if(whence == AVSEEK_SIZE)
        return stream->size();
    if(whence == SEEK_SET)
        stream->seek((size_t)offset);
    else if(whence == SEEK_CUR)
		stream->seek((size_t)(stream->tell() + offset));
    else if(whence == SEEK_END)
		stream->seek((size_t)(stream->size() + offset));
    else
        return -1;

    return stream->tell();
}
    //--------------------------------------------------------------------------
    void
    FLevelFileSerializer::importFLevelFile( Ogre::DataStreamPtr &stream, FLevelFile* pDest )
    {
        size_t start_position( stream->tell() );
        readFileHeader( stream );

        uint32 section_offsets[ m_header.section_count ];
        readInts( stream, section_offsets, m_header.section_count );

        Ogre::DataStreamPtr section;
        for( size_t i(0); i < m_header.section_count; ++i )
        {
            size_t current_offset( stream->tell() - start_position );
            size_t section_gap( section_offsets[i] - current_offset );
            if( current_offset > section_offsets[i] )
            {
                OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
                    ,"FLevel sections overlap"
                    ,"FLevelFileSerializer::importFLevelFile" );
            }
            else if( section_gap )
            {
                stream->skip( section_gap );
                Ogre::LogManager::getSingleton().stream()
                    << "Warning: skiping gap in front of section " << i
                    << " gap size " << section_gap
                    << " FLevelFileSerializer::importFLevelFile";
            }

            readSectionData( stream, section );
            readSection( section, pDest, i );
            section->close();
            section.setNull();
        }
        readEnd( stream );
    }
bool RocketInterface::Seek(Rocket::Core::FileHandle file, long offset, int origin)
{
    if (!file)
        return false;

    Ogre::DataStreamPtr stream = *reinterpret_cast<Ogre::DataStreamPtr*>(file);
    long pos = 0;
    size_t size = stream->size();

    if (origin == SEEK_CUR)
        pos = stream->tell() + offset;
    else if (origin == SEEK_END)
        pos = size + offset;
    else
        pos = offset;

    if (pos < 0 || pos > (long)size)
        return false;

    stream->seek((size_t)pos);
    return true;
}
Exemple #8
0
//----------------------------------------------------------------------------//
long OggBuffer::vorbisTell(void *datasource)
{
	Ogre::DataStreamPtr vorbisData = *(Ogre::DataStreamPtr*)datasource;
	return static_cast<long>(vorbisData->tell());
}
qint64 OgreNetworkReply::bytesAvailable() const
{
    if (mDataStream.isNull())
        return 0;
    return QNetworkReply::bytesAvailable() + mDataStream->size() - mDataStream->tell();
}
bool OgreNetworkReply::seek(qint64 pos)
{
    QNetworkReply::seek(pos);
    mDataStream->seek(pos);
    return (mDataStream->tell() == pos);
}
Exemple #11
0
 size_t tell() const {
     return inp->tell();
 }
    // ----------------------------------------------------------------------
    void FontSerializer::importFont(Ogre::DataStreamPtr &stream, Font *pDest)
    {
        uint32 fccomp;
        stream->read(&fccomp, sizeof(uint32));
        if(fccomp != Font::mFourCC)
            SONETTO_THROW("Invalid Font File");
        stream->read(&pDest->mVersion, sizeof(uint32));
        stream->read(&pDest->mEncode, sizeof(uint32));
        stream->read(&pDest->mVerticalOffsetTop, sizeof(float));
        stream->read(&pDest->mVerticalOffsetBottom, sizeof(float));
        stream->read(&pDest->mHorizontalScale, sizeof(float));

        pDest->mIName = loadString(stream);

        // setup material
        pDest->mMaterial = Ogre::MaterialManager::getSingleton().create(pDest->mIName+"_mat",pDest->getGroup());

        if(pDest->mMaterial.isNull())
            SONETTO_THROW("Unable to create material for font.");

        Ogre::Pass * pass = pDest->mMaterial->getTechnique(0)->getPass(0);

        bool has_separate_blend;
        uint32 mat_scene_blend_source;
        uint32 mat_scene_blend_dest;
        uint32 mat_scene_blend_source_a;
        uint32 mat_scene_blend_dest_a;
        stream->read(&has_separate_blend, sizeof(bool));
        stream->read(&mat_scene_blend_source, sizeof(uint32));
        stream->read(&mat_scene_blend_dest, sizeof(uint32));
        stream->read(&mat_scene_blend_source_a, sizeof(uint32));
        stream->read(&mat_scene_blend_dest_a, sizeof(uint32));

        if(has_separate_blend)
        {
            pass->setSeparateSceneBlending( (Ogre::SceneBlendFactor)mat_scene_blend_source,
                                            (Ogre::SceneBlendFactor)mat_scene_blend_dest,
                                            (Ogre::SceneBlendFactor)mat_scene_blend_source_a,
                                            (Ogre::SceneBlendFactor)mat_scene_blend_dest_a);
        } else {
            pass->setSceneBlending((Ogre::SceneBlendFactor)mat_scene_blend_source,(Ogre::SceneBlendFactor)mat_scene_blend_dest);
        }
        uint32 mat_alpha_reject_func;
        uint8 mat_alpha_reject_val;
        bool map_alpha_reject_atc;
        stream->read(&mat_alpha_reject_func, sizeof(uint32));
        stream->read(&mat_alpha_reject_val, sizeof(uint8));
        stream->read(&map_alpha_reject_atc, sizeof(bool));

        pass->setAlphaRejectSettings((Ogre::CompareFunction) mat_alpha_reject_func, mat_alpha_reject_val, map_alpha_reject_atc);

        pass->setDepthCheckEnabled(false);
        pass->setDepthWriteEnabled(false);
        pass->setLightingEnabled(false);

        Ogre::TextureUnitState * tex_unit = pass->createTextureUnitState();

        uint32 tex_address_mode_u;
        uint32 tex_address_mode_v;
        uint32 tex_address_mode_w;
        uint32 tex_filtering_min;
        uint32 tex_filtering_mag;
        Ogre::ColourValue tex_border_color;
        stream->read(&tex_address_mode_u, sizeof(uint32));
        stream->read(&tex_address_mode_v, sizeof(uint32));
        stream->read(&tex_address_mode_w, sizeof(uint32));
        stream->read(&tex_filtering_min, sizeof(uint32));
        stream->read(&tex_filtering_mag, sizeof(uint32));
        stream->read(tex_border_color.ptr(), sizeof(float) * 4);

        tex_unit->setTextureAddressingMode( (Ogre::TextureUnitState::TextureAddressingMode) tex_address_mode_u,
                                            (Ogre::TextureUnitState::TextureAddressingMode) tex_address_mode_v,
                                            (Ogre::TextureUnitState::TextureAddressingMode) tex_address_mode_w);
        tex_unit->setTextureFiltering((Ogre::FilterOptions)tex_filtering_min, (Ogre::FilterOptions)tex_filtering_mag, Ogre::FO_NONE);
        tex_unit->setTextureBorderColour(tex_border_color);

        uint32 numcol = 0;
        stream->read(&numcol, sizeof(uint32));
        for(uint32 l = 0; l != numcol; ++l)
        {
            std::cout << "reading color #"<<l<<"...\n";
            Ogre::ColourValue color;
            stream->read(color.ptr(), sizeof(float) * 4);
            pDest->mColorList.push_back(color);
            std::cout << "color #"<<l<<" read complete...\n";
        }
        std::cout << "all color values have been read correctly...\n";
        std::cout << "reading font glyph list...\n";
        for(uint16 i = 0; i != 256; ++i)
        {
            std::cout << "reading glyph #"<<(int)i<<"...\n";
            FontGlyph glyph;
            stream->read(&glyph, sizeof(FontGlyph));
            pDest->mGlyph.push_back(glyph);
            std::cout << "glyph #"<<(int)i<<" read complete...\n";
        }
        std::cout << "all font glyph have been read correctly...\n";
        // size_t width, size_t height, size_t depth, size_t pixel format
        size_t txt_width, txt_height, txt_depth, txt_pixelformat, txt_faces, txt_mipmaps = 0;
        stream->read(&txt_width, sizeof(size_t));
        stream->read(&txt_height, sizeof(size_t));
        stream->read(&txt_depth, sizeof(size_t));
        stream->read(&txt_pixelformat, sizeof(size_t));
        stream->read(&txt_faces, sizeof(size_t));
        stream->read(&txt_mipmaps, sizeof(size_t));

        std::cout <<
        "Loading Font Texture Data...\n"
        "Texture Width: "<<txt_width<<"\n"
        "Texture Height: "<<txt_height<<"\n"
        "Texture Depth: "<<txt_depth<<"\n"
        "Texture Pixel Format: "<<txt_pixelformat<<"\n"
        "Texture Faces: "<<txt_faces<<"\n"
        "Texture Mipmaps: "<<txt_mipmaps<<"\n";

        pDest->mFontImage = new Ogre::Image();

        size_t totalimagesize = Ogre::Image::calculateSize(txt_mipmaps, txt_faces, txt_width, txt_height, txt_depth, (Ogre::PixelFormat)txt_pixelformat);

        std::cout << "Current position at file: "<<stream->tell()<<"\n"
        "Target Image Size: "<<totalimagesize<<"\n"
        "Remaining File Size: "<<stream->size()<<"\n";

        unsigned char * imgbuffer = new unsigned char [totalimagesize];

        stream->read(imgbuffer, totalimagesize);

        pDest->mFontImage->loadDynamicImage(imgbuffer, txt_width, txt_height, txt_depth, (Ogre::PixelFormat)txt_pixelformat, true, txt_faces, txt_mipmaps);

        Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().loadImage(pDest->mIName+"_tex",pDest->getGroup(), *pDest->mFontImage, Ogre::TEX_TYPE_2D, 0);

        tex_unit->setTextureName(texture->getName(), Ogre::TEX_TYPE_2D);
    }
Exemple #13
0
	long	OOSStreamTell(void *datasource)
	{
		Ogre::DataStreamPtr dataStream = *reinterpret_cast<Ogre::DataStreamPtr*>(datasource);
		return static_cast<long>(dataStream->tell());
	}