//---------------------------------------------------------------------
    void
    BackgroundFileSerializer::readLayer( Ogre::DataStreamPtr &stream
                                        ,Layer *pDest, size_t layer_index )
    {
        if( !pDest->enabled ) return;

        uint16 tmp[4], sprite_count;
        readShorts( stream, tmp, 4 );
        pDest->width        = tmp[0];
        pDest->height       = tmp[1];
        sprite_count        = tmp[2];
        pDest->unknown_06   = tmp[3];

        switch( layer_index )
        {
          case 1:
            readShorts( stream, pDest->unknown_08, 3 );
          case 2:
          case 3:
            readShorts( stream, pDest->unknown_0E, 4 );
        }
        stream->skip( 2 * 2 ); // 2 * uint16 unused;
        m_layer_index = layer_index;
        readVector( stream, pDest->sprites, sprite_count );

        removeBuggySprites( pDest->sprites );
    }
Ejemplo n.º 2
0
void SkeletonSerializerEx::readAnimation(Ogre::DataStreamPtr& stream, Ogre::Skeleton* pSkel)
{
	// char* name                       : Name of the animation
	Ogre::String name;
	name = readString(stream);
	// float length                      : Length of the animation in seconds
	float len;
	readFloats(stream, &len, 1);

	Ogre::Animation *pAnim = pSkel->createAnimation(name, len);

	// Read all tracks
	if (!stream->eof())
	{
		unsigned short streamID = readChunk(stream);
		while(streamID == Ogre::SKELETON_ANIMATION_TRACK && !stream->eof())
		{
			readAnimationTrack(stream, pAnim, pSkel);

			if (!stream->eof())
			{
				// Get next stream
				streamID = readChunk(stream);
			}
		}
		if (!stream->eof())
		{
			// Backpedal back to start of this stream if we've found a non-track
			stream->skip(-STREAM_OVERHEAD_SIZE);
		}
	}
}
Ejemplo n.º 3
0
	int		OOSStreamSeek(void *datasource, ogg_int64_t offset, int whence)
	{
		Ogre::DataStreamPtr dataStream = *reinterpret_cast<Ogre::DataStreamPtr*>(datasource);
		switch(whence)
		{
		case SEEK_SET:
			dataStream->seek(offset);
			break;
		case SEEK_END:
			dataStream->seek(dataStream->size());
			// Falling through purposefully here
		case SEEK_CUR:
			dataStream->skip(offset);
			break;
		}

		return 0;
	}
    //--------------------------------------------------------------------------
    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 );
    }
    //---------------------------------------------------------------------
    void
    BackgroundFileSerializer::readObject( Ogre::DataStreamPtr &stream, SpriteData &pDest )
    {
        readObject( stream, pDest.dst );
        readShorts( stream, pDest.unknown_04, 2 );
        readObject( stream, pDest.src );
        readObject( stream, pDest.src2 );
        readShort( stream, pDest.width );
        readShort( stream, pDest.height );

        uint16 size;
        // width and height are sometimes incorrect in the file
        if ( m_layer_index < 2 )
        {
            size = 16;
        }
        else if ( m_layer_index < BackgroundFile::LAYER_COUNT)
        {
            size = 32;
        }
        else
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
                ,"m_layer_index not set correctly"
                ,"BackgroundFileSerializer::readObject" );
        }
        pDest.width = pDest.height = size;

        readShort( stream, pDest.palette_page );
        readShort( stream, pDest.depth );

        // Force depth values
        switch ( m_layer_index )
        {
          case 0:
            pDest.depth = 4095;
            break;
          case 2:
            pDest.depth = 4096;
            break;
          case 3:
            pDest.depth = 0;
            break;
        }

        uint8 animation[2];
        stream->read( animation, sizeof( animation ) );
        pDest.animation_id = animation[0];
        pDest.animation_frame = animation[1];
        uint8 has_blending[2];
        stream->read( has_blending, sizeof( has_blending ) );
        pDest.has_blending[0] = has_blending[0] > 0;
        pDest.has_blending[1] = has_blending[1] > 0;

        readShort( stream, pDest.blending );
        readShort( stream, pDest.data_page );
        readShort( stream, pDest.data_page2 );
        // when data_page2 != 0, it must be used instead of data_page (not for the first layer)
        if ( m_layer_index > 0 && pDest.data_page2 )
        {
            pDest.src = pDest.src2;
            pDest.data_page = pDest.data_page2;
        }
        readShort( stream, pDest.colour_depth );
        readObject( stream, pDest.src_big );
        pDest.src_big /= src_big_SCALE;
        stream->skip( 2 * 2 ); // 2 * uint16 unused
    }
Ejemplo n.º 6
0
 void skip(size_t size) { inp->skip(size); }
Ejemplo n.º 7
0
void SkeletonSerializerEx::readAnimationTrack(
	Ogre::DataStreamPtr& stream, Ogre::Animation* anim, Ogre::Skeleton* pSkel)
{
	// unsigned short boneIndex     : Index of bone to apply to
	unsigned short boneHandle;
	readShorts(stream, &boneHandle, 1);

	// Find bone
	Ogre::Bone *targetBone = pSkel->getBone(boneHandle);

	// Create track
	Ogre::NodeAnimationTrack* pTrack = anim->createNodeTrack(boneHandle, targetBone);

	// Keep looking for nested keyframes
	if (!stream->eof())
	{
		unsigned short streamID = readChunk(stream);
		while((streamID == Ogre::SKELETON_ANIMATION_TRACK_KEYFRAME || streamID == 0x4120 )
				&& !stream->eof())
		{
			if (streamID == 0x4120)
			{			
				unsigned short len;
				unsigned short flags;
				readShorts(stream, &len, 1);
				readShorts(stream, &flags, 1);

				float time;
				for (int i = 0; i < len; i += 1)
				{
					readFloats(stream, &time, 1);
					Ogre::TransformKeyFrame *kf = pTrack->createNodeKeyFrame(time);

					Ogre::Quaternion rot = Ogre::Quaternion::IDENTITY;
					if (flags & 1)
					{
						readObject(stream, rot);
					}
					kf->setRotation(rot);

					Ogre::Vector3 trans = Ogre::Vector3::ZERO;
					if (flags & 2)
					{
						readObject(stream, trans);
					}
					kf->setTranslate(trans);

					// 为正确解析天龙八部模型的骨骼动画              
					Ogre::Vector3 scale = Ogre::Vector3::UNIT_SCALE;
					if (flags & 4)
					{
						readObject(stream, scale);
					}
					kf->setScale(scale);
				}
			}
			else
				readKeyFrame(stream, pTrack, pSkel);

			if (!stream->eof())
			{
				// Get next stream
				streamID = readChunk(stream);
			}
		}
		if (!stream->eof())
		{
			// Backpedal back to start of this stream if we've found a non-keyframe
			stream->skip(-STREAM_OVERHEAD_SIZE);
		}
	}
}