Пример #1
0
bool CAgpCoder::DeCode_Agp( const CDataChunk& inData , OBJ_HANDLE handle )
{
	CAnimationGroup* pAniGroup = (CAnimationGroup*)handle;
	CBufFile tData( inData.GetBuffer(), inData.GetSize() );

	int dataSize;
	tData.SafeRead((TCHAR*)&dataSize,sizeof(int));
	pAniGroup->m_SkeName.resize(dataSize);
	tData.SafeRead((TCHAR*)pAniGroup->m_SkeName.data(), dataSize );

	CSkeletalsMgr::GetInst()->GetSkeInPool( pAniGroup->m_SkeName.c_str(), &pAniGroup->m_pSke );

	int Size;

	tData.SafeRead( &Size, sizeof(Size) );
	pAniGroup->m_AnimationList.resize( Size, NULL );

	pAniGroup->m_NameList.clear();
	TCHAR szAniName[256];
	TCHAR* szChild = szAniName + pAniGroup->m_szName.size() - 3;
	strncpy( szAniName, pAniGroup->m_szName.c_str(), pAniGroup->m_szName.size() - 4 );
	szChild[-1] = '_';

	CAnimate* pAnimate = NULL;
	GString strAniname;
	int i;
	for ( i = 0; i < (int)pAniGroup->m_AnimationList.size(); i++ )
	{
		tData.SafeRead( szChild, sizeof(IDNAME) );
		strAniname = szChild;
		IDNAME Name = *(IDNAME*)szChild;

		pAniGroup->m_NameList[szChild] = i;
		strcat( szChild, ".ani" );

		pAnimate = CDataSources::GetInst()->NewAnimate(pAniGroup, szAniName, Name);//new CAnimate(this, szAniName, Name );
		pAniGroup->m_AnimationList[i] = pAnimate;

		if(strAniname.find("stand")!=GString::npos)//这个地方以后要改,以后会在插件到处调整骨骼动画的加载顺序和批量处理老资源,现在临时在这里过滤下把stand在最先加载
			pAniGroup->InsertAni(pAniGroup->m_AnimationList[i]);
	}
	pAniGroup->LoadNextAni();
	pAniGroup->Release();
	return true;
}
shared_ptr<osb::SpriteList> ReadOSBEvents(std::istream& event_str)
{
	auto list = make_shared<osb::SpriteList>();
	int previous_lead = 100;
	shared_ptr<osb::BGASprite> sprite = nullptr;
	shared_ptr<osb::Loop> loop = nullptr;
	bool readingLoop = false;

	GString line;
	while (std::getline(event_str, line))
	{
		int lead_spaces;
		line = line.substr(line.find("//")); // strip comments
		lead_spaces = line.find_first_not_of("\t _");
		line = line.substr(lead_spaces, line.length() - lead_spaces + 1);

		vector<GString> split_result;
		boost::split(split_result, line, boost::is_any_of(","));
		for (auto &&s : split_result) boost::algorithm::to_lower(s);

		if (!line.length() || !split_result.size()) continue;

		if (lead_spaces < previous_lead && !readingLoop)
		{
			if (split_result[0] == "sprite")
			{
				Vec2 new_position(latof(split_result[3]), latof(split_result[4]));
				sprite = make_shared<osb::BGASprite>(split_result[1], OriginFromString(split_result[2]), new_position);
				list->push_back(sprite);
			}
		} else {
			if (!sprite)
				throw std::runtime_error("OSB command unpaired with sprite.");

			// If it's a loop, check if we're out of it.
			// If we're out of it, read a regular event, otherwise, read an event to the loop
			if (readingLoop)
			{
				if (lead_spaces < previous_lead) {
					readingLoop = false;

					// We're done reading the loop - unroll it.
					auto loop_events = loop->Unroll();
					for (auto i = 0; i < osb::EVT_COUNT; i++)
						for (auto evt : (*loop_events)[i])
							sprite->AddEvent(evt);
				}
				else
					loop->AddEvent(ParseEvent(split_result));
			}
			
			// It's not a command on the loop, or we weren't reading a loop in the first place.
			// Read a regular command.

			// Not "else" because we do want to execute this if we're no longer reading the loop.
			if (!readingLoop) {
				auto ev = ParseEvent(split_result);

				// A loop began - set that we are reading a loop and set this loop as where to add the following commands.
				if (ev->GetEventType() == osb::EVT_LOOP)
				{
					loop = static_pointer_cast<osb::Loop>(ev);
					readingLoop = true;
				}else // add this event, if not a loop to this sprite. It'll be unrolled once outside.
					sprite->AddEvent(ev);
			}
		}

		previous_lead = lead_spaces;
	}

	return list;
}