示例#1
0
void CStatCounterArray::GenerateGameStats (CGameStats &Stats)

//	GenerateGameStats
//
//	Adds the list of stats to the target

	{
	//	Loop over all sections

	CMapIterator i;
	m_Array.Reset(i);
	while (m_Array.HasMore(i))
		{
		TMap<CString, SEntry> *pSection;
		CString sSection = m_Array.GetNext(i, &pSection);

		//	Loop over all stats

		CMapIterator j;
		pSection->Reset(j);
		while (pSection->HasMore(j))
			{
			SEntry *pEntry;
			CString sStat = pSection->GetNext(j, &pEntry);

			//	Add it

			Stats.Insert(sStat, 
					::strFormatInteger(pEntry->iCount, -1, FORMAT_THOUSAND_SEPARATOR | FORMAT_UNSIGNED), 
					sSection, 
					pEntry->sSort);
			}
		}
	}
int CMarkovWordGenerator::GenerateUnique (int iCount, TArray<CString> *retArray)

//	GenerateUnique
//
//	Generates an array of unique words

	{
	int i;
	TMap<CString, DWORD> Generated;

	for (i = 0; i < iCount; i++)
		{
		int iTriesLeft = 500;

		while (iTriesLeft > 0)
			{
			//	Generate a random word

			CString sWord = Generate();

			//	Lookup the word in our map. If we found it,
			//	try again.

			if (Generated.Find(sWord))
				{
				iTriesLeft--;
				continue;
				}

			//	If it is unique, add it

			Generated.Insert(sWord, 1);
			break;
			}

		//	If we couldn't find a unique word, then quit

		if (iTriesLeft == 0)
			break;
		}

	//	Add the entries that we generated to the output array

	CMapIterator j;
	Generated.Reset(j);
	int iGeneratedCount = 0;
	while (Generated.HasMore(j))
		{
		DWORD *pDummy;
		CString sWord = Generated.GetNext(j, &pDummy);
		retArray->Insert(sWord);
		iGeneratedCount++;
		}

	return iGeneratedCount;
	}
void UFoliageStatistics::FoliageOverlappingMeshCounts_Debug(UObject* WorldContextObject, FVector CenterPosition, float Radius, TMap<UStaticMesh*, int32>& OutMeshCounts)
{
	UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject);
	const FSphere Sphere(CenterPosition, Radius);

	OutMeshCounts.Reset();
	for (TActorIterator<AInstancedFoliageActor> It(World); It; ++It)
	{
		AInstancedFoliageActor* IFA = *It;
		if (!IFA->IsPendingKill())
		{
			IFA->GetOverlappingMeshCounts(Sphere, OutMeshCounts);
		}
	}
}
void FPaperFlipbookHelpers::ExtractFlipbooksFromSprites(TMap<FString, TArray<UPaperSprite*> >& OutSpriteFlipbookMap, const TArray<UPaperSprite*>& Sprites, const TArray<FString>& InSpriteNames)
{
	OutSpriteFlipbookMap.Reset();

	// Local copy
	check((InSpriteNames.Num() == 0) || (InSpriteNames.Num() == Sprites.Num()));
	TArray<FString> SpriteNames = InSpriteNames;
	if (InSpriteNames.Num() == 0)
	{
		SpriteNames.Reset();
		for (int32 SpriteIndex = 0; SpriteIndex < Sprites.Num(); ++SpriteIndex)
		{
			check(Sprites[SpriteIndex] != nullptr);
			SpriteNames.Add(Sprites[SpriteIndex]->GetName());
		}
	}

	// Group them
	TMap<FString, UPaperSprite*> SpriteNameMap;
	TArray<UPaperSprite*> RemainingSprites;

	for (int32 SpriteIndex = 0; SpriteIndex < Sprites.Num(); ++SpriteIndex)
	{
		UPaperSprite* Sprite = Sprites[SpriteIndex];
		const FString SpriteName = SpriteNames[SpriteIndex];

		SpriteNameMap.Add(SpriteName, Sprite);

		int32 SpriteNumber = 0;
		FString SpriteBareString;
		if (ExtractSpriteNumber(SpriteName, /*out*/ SpriteBareString, /*out*/ SpriteNumber))
		{
			SpriteBareString = ObjectTools::SanitizeObjectName(SpriteBareString);
			OutSpriteFlipbookMap.FindOrAdd(SpriteBareString).Add(Sprite);
		}
		else
		{
			RemainingSprites.Add(Sprite);
		}
	}

	// Natural sort using the same method as above
	struct FSpriteSortPredicate
	{
		FSpriteSortPredicate() {}

		// Sort predicate operator
		bool operator()(UPaperSprite& LHS, UPaperSprite& RHS) const
		{
			FString LeftString;
			int32 LeftNumber;
			ExtractSpriteNumber(LHS.GetName(), /*out*/ LeftString, /*out*/ LeftNumber);

			FString RightString;
			int32 RightNumber;
			ExtractSpriteNumber(RHS.GetName(), /*out*/ RightString, /*out*/ RightNumber);

			return (LeftString == RightString) ? (LeftNumber < RightNumber) : (LeftString < RightString);
		}
	};

	// Sort sprites
	TArray<FString> Keys;
	OutSpriteFlipbookMap.GetKeys(Keys);
	for (auto SpriteName : Keys)
	{
		OutSpriteFlipbookMap[SpriteName].Sort(FSpriteSortPredicate());
	}

	// Create a flipbook from all remaining sprites
	// Not sure if this is desirable behavior, might want one flipbook per sprite
	if (RemainingSprites.Num() > 0)
	{
		RemainingSprites.Sort(FSpriteSortPredicate());

		const FString DesiredName = GetCleanerSpriteName(RemainingSprites[0]->GetName()) + TEXT("_Flipbook");
		const FString SanitizedName = ObjectTools::SanitizeObjectName(DesiredName);

		OutSpriteFlipbookMap.Add(SanitizedName, RemainingSprites);
	}
}