コード例 #1
0
ファイル: tsMovieClip.cpp プロジェクト: Creativegame/tinyswf
bool MovieClip::createFrames( Reader& reader, SWF& swf, MovieFrames &data )
{
	RECT empty = {FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX};
	data._rectangle = empty;
	sbCalculateRectangle = true;

	// get all tags and build frame lists
    TagHeader header;
	ITag* tag = NULL;
	TagList* frame_tags = new TagList;
	TagList actionTags;
	do {
		header.read( reader );
        const uint32_t code = header.code();
		SWF::TagFactoryFunc factory = SWF::getTagFactory( code );
		if (! factory ) {
			// no registered factory so skip this tag
			SWF_TRACE("*** SKIP *** ");
			header.print();
			reader.skip( header.length() );
			continue;
		}
		tag = factory( header );
		SWF_ASSERT(tag);

		int32_t end_pos = reader.getCurrentPos() + tag->length();
		bool keepTag = tag->read( reader, swf, data );
		tag->print();
		reader.align();

		int32_t dif = end_pos - reader.getCurrentPos();
		if( dif != 0 ) {
			SWF_TRACE("WARNING: tag not read correctly. trying to skip.\n");
			reader.skip( dif );
		}

        if (keepTag) {
			// collect action tags
			if (tag->code() == TAG_DO_ACTION) {
				actionTags.push_back(tag);
			} else {
				frame_tags->push_back( tag );
			}
        } else {
            delete tag;
        }

        // create a new frame
        if ( TAG_SHOW_FRAME == code ) {
			SWF_TRACE("[%d] has %d tags\n", data._frames.size(), frame_tags->size());

			// put action tags at the end of list in order to avoid callback error
			TagList::iterator it = actionTags.begin();
			while (it != actionTags.end()) {
				frame_tags->push_back( *it );
				++it;
			}
			actionTags.clear();

			data._frames.push_back( frame_tags );
			frame_tags = new TagList;
			sbCalculateRectangle = false;
        }
	} while( header.code() != TAG_END );
	delete frame_tags;
    return true;
}