本文整理汇总了C++中TArray::AddDefaulted方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::AddDefaulted方法的具体用法?C++ TArray::AddDefaulted怎么用?C++ TArray::AddDefaulted使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TArray
的用法示例。
在下文中一共展示了TArray::AddDefaulted方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadWeatherDescriptionsFromFile
void ADynamicWeather::LoadWeatherDescriptionsFromFile(
const FString &MapName,
TArray<FWeatherDescription> &Descriptions)
{
// Try to load config file.
FString DefaultFilePath;
if (GetWeatherIniFilePath(GetIniFileName(), DefaultFilePath)) {
UE_LOG(LogCarla, Log, TEXT("Loading weather description from %s"), *DefaultFilePath);
FIniFile ConfigFile(DefaultFilePath);
{ // Override map specific presets.
FString MapOverridesFilePath;
if (GetWeatherIniFilePath(GetIniFileName(MapName), MapOverridesFilePath)) {
UE_LOG(LogCarla, Log, TEXT("Loading weather description from %s"), *MapOverridesFilePath);
ConfigFile.Combine(MapOverridesFilePath);
}
}
// For every section in the config file add a weather description.
for (auto &Item : ConfigFile.GetFConfigFile()) {
Descriptions.AddDefaulted(1u);
Descriptions.Last().ReadFromConfigFile(ConfigFile, Item.Key);
}
}
// If no description was found, append a defaulted one.
if (Descriptions.Num() == 0) {
UE_LOG(LogCarla, Warning, TEXT("No weather description found"));
Descriptions.AddDefaulted(1u);
Descriptions.Last().Name = TEXT("Default");
}
}
示例2: AddSweepResults
EConvertQueryResult AddSweepResults(bool& OutHasValidBlockingHit, const UWorld* World, int32 NumHits, PxSweepHit* Hits, float CheckLength, const PxFilterData& QueryFilter, TArray<FHitResult>& OutHits, const FVector& StartLoc, const FVector& EndLoc, const PxGeometry& Geom, const PxTransform& QueryTM, float MaxDistance, bool bReturnFaceIndex, bool bReturnPhysMat)
{
OutHits.Reserve(OutHits.Num() + NumHits);
EConvertQueryResult ConvertResult = EConvertQueryResult::Valid;
bool bHadBlockingHit = false;
const PxVec3 PDir = U2PVector((EndLoc - StartLoc).GetSafeNormal());
for(int32 i=0; i<NumHits; i++)
{
PxSweepHit& PHit = Hits[i];
checkSlow(PHit.flags & PxHitFlag::eDISTANCE);
if(PHit.distance <= MaxDistance)
{
PHit.faceIndex = FindFaceIndex(PHit, PDir);
FHitResult& NewResult = OutHits[OutHits.AddDefaulted()];
if (ConvertQueryImpactHit(World, PHit, NewResult, CheckLength, QueryFilter, StartLoc, EndLoc, &Geom, QueryTM, bReturnFaceIndex, bReturnPhysMat) == EConvertQueryResult::Valid)
{
bHadBlockingHit |= NewResult.bBlockingHit;
}
else
{
// Reject invalid result (this should be rare). Remove from the results.
OutHits.Pop(/*bAllowShrinking=*/ false);
ConvertResult = EConvertQueryResult::Invalid;
}
}
}
// Sort results from first to last hit
OutHits.Sort( FCompareFHitResultTime() );
OutHasValidBlockingHit = bHadBlockingHit;
return ConvertResult;
}
示例3: GetTranslatedTags
bool FGameplayCueTranslationManager::GetTranslatedTags(const FName& ParentTag, TArray<FGameplayCueTranslationEditorInfo>& Children)
{
if (const FGameplayCueTranslatorNode* Node = GetTranslationNodeForName(ParentTag))
{
for (const FGameplayCueTranslationLink& Link : Node->Links)
{
for (int32 LinkIdx=0; LinkIdx < Link.NodeLookup.Num(); ++LinkIdx)
{
const FGameplayCueTranslatorNodeIndex& Index = Link.NodeLookup[LinkIdx];
if (Index != INDEX_NONE)
{
FGameplayCueTranslatorNode& ChildNode = TranslationLUT[Index];
// Find the description of the rule this came from
for (FNameSwapData& SwapData : AllNameSwaps)
{
if (SwapData.ClassCDO == Link.RulesCDO)
{
check(SwapData.NameSwaps.IsValidIndex(LinkIdx));
FGameplayCueTranslationEditorInfo& Info = Children[Children.AddDefaulted()];
Info.GameplayTagName = ChildNode.CachedGameplayTagName;
Info.GameplayTag = ChildNode.CachedGameplayTag;
Info.EditorData = SwapData.NameSwaps[LinkIdx].EditorData;
break;
}
}
}
}
}
}
return Children.Num() > 0;
}
示例4: ConvertRaycastResults
void ConvertRaycastResults(const UWorld* World, int32 NumHits, PxRaycastHit* Hits, float CheckLength, const PxFilterData& QueryFilter, TArray<FHitResult>& OutHits, const FVector& StartLoc, const FVector& EndLoc, bool bReturnFaceIndex, bool bReturnPhysMat)
{
OutHits.Reserve(OutHits.Num() + NumHits);
PxTransform PStartTM(U2PVector(StartLoc));
for(int32 i=0; i<NumHits; i++)
{
FHitResult& NewResult = OutHits[OutHits.AddDefaulted()];
const PxRaycastHit& PHit = Hits[i];
ConvertQueryImpactHit(World, PHit, NewResult, CheckLength, QueryFilter, StartLoc, EndLoc, NULL, PStartTM, bReturnFaceIndex, bReturnPhysMat);
}
// Sort results from first to last hit
OutHits.Sort( FCompareFHitResultTime() );
}
示例5: SendText
bool FWebSocket::SendText(uint8* Data, uint32 Size)
{
TArray<uint8> Buffer;
#if !PLATFORM_HTML5
Buffer.AddDefaulted(LWS_PRE); // Reserve space for WS header data
#endif
// Buffer.Append((uint8*)&Size, sizeof (uint32)); // insert size.
Buffer.Append((uint8*)Data, Size);
CriticalSection.Lock();
OutgoingBuffer.Add(Buffer);
OutgoingBufferType.Add( LWS_WRITE_TEXT );
CriticalSection.Unlock();
return true;
}
示例6: AddSweepResults
bool AddSweepResults(const UWorld* World, int32 NumHits, const PxSweepHit* Hits, float CheckLength, const PxFilterData& QueryFilter, TArray<FHitResult>& OutHits, const FVector& StartLoc, const FVector& EndLoc, const PxGeometry& Geom, const PxTransform& QueryTM, float MaxDistance, bool bReturnPhysMat)
{
OutHits.Reserve(OutHits.Num() + NumHits);
bool bHadBlockingHit = false;
for(int32 i=0; i<NumHits; i++)
{
const PxSweepHit& PHit = Hits[i];
checkSlow(PHit.flags & PxHitFlag::eDISTANCE);
if(PHit.distance <= MaxDistance)
{
FHitResult& NewResult = OutHits[OutHits.AddDefaulted()];
ConvertQueryImpactHit(World, PHit, NewResult, CheckLength, QueryFilter, StartLoc, EndLoc, &Geom, QueryTM, false, bReturnPhysMat);
bHadBlockingHit |= NewResult.bBlockingHit;
}
}
// Sort results from first to last hit
OutHits.Sort( FCompareFHitResultTime() );
return bHadBlockingHit;
}
示例7: GetOverlays
void UMediaPlayer::GetOverlays(EMediaOverlayType Type, TArray<FMediaPlayerOverlay>& OutOverlays) const
{
FTimespan CurrentTime = GetTime();
if (CurrentTime == FTimespan::Zero())
{
return;
}
for (const FOverlay& Overlay : Overlays)
{
if ((Overlay.Type == Type) && (Overlay.Time <= CurrentTime) && (CurrentTime - Overlay.Time < Overlay.Duration))
{
const int32 OverlayIndex = OutOverlays.AddDefaulted();
FMediaPlayerOverlay& OutOverlay = OutOverlays[OverlayIndex];
{
OutOverlay.HasPosition = Overlay.Position.IsSet();
OutOverlay.Position = OutOverlay.HasPosition ? Overlay.Position.GetValue() : FIntPoint::ZeroValue;
OutOverlay.Text = Overlay.Text;
}
}
}
}
示例8: RunTest
bool FLocTextHelperTest::RunTest(const FString& Parameters)
{
const int32 NumTestEntries = 100;
const FString TestingPath = FPaths::GameAgnosticSavedDir() / TEXT("LocTextHelperTest_") + FGuid::NewGuid().ToString();
TArray<FString> ForeignCultures;
ForeignCultures.Add(TEXT("fr"));
ForeignCultures.Add(TEXT("de"));
FLocTextHelper LocTestHelper(TestingPath, TEXT("Test.manifest"), TEXT("Test.archive"), TEXT("en"), ForeignCultures, nullptr);
LocTestHelper.LoadAll(ELocTextHelperLoadFlags::Create);
TArray<FLocTextHelperTestSourceEntry> TestSources;
TestSources.Reserve(NumTestEntries);
TArray<FLocTextHelperTestTranslationEntry> EnglishTranslations;
EnglishTranslations.Reserve(NumTestEntries);
TArray<FLocTextHelperTestTranslationEntry> FrenchTranslations;
FrenchTranslations.Reserve(NumTestEntries);
TArray<FLocTextHelperTestTranslationEntry> GermanTranslations;
GermanTranslations.Reserve(NumTestEntries);
// Create test data
for (int32 Index = 0; Index < NumTestEntries; ++Index)
{
FLocTextHelperTestSourceEntry& TestSourceEntry = TestSources[TestSources.AddDefaulted()];
TestSourceEntry.Namespace = TEXT("Test");
TestSourceEntry.Key = FString::Printf(TEXT("Test_%d"), Index + 1);
TestSourceEntry.SourceText = FString::Printf(TEXT("Source Text %d"), Index + 1);
FLocTextHelperTestTranslationEntry& TestEnglishEntry = EnglishTranslations[EnglishTranslations.AddDefaulted()];
TestEnglishEntry.Namespace = TestSourceEntry.Namespace;
TestEnglishEntry.Key = TestSourceEntry.Key;
TestEnglishEntry.SourceText = TestSourceEntry.SourceText;
TestEnglishEntry.TranslationText = FString::Printf(TEXT("English Text %d"), Index + 1);
FLocTextHelperTestTranslationEntry& TestFrenchEntry = FrenchTranslations[FrenchTranslations.AddDefaulted()];
TestFrenchEntry.Namespace = TestSourceEntry.Namespace;
TestFrenchEntry.Key = TestSourceEntry.Key;
TestFrenchEntry.SourceText = TestEnglishEntry.TranslationText;
TestFrenchEntry.TranslationText = FString::Printf(TEXT("French Text %d"), Index + 1);
FLocTextHelperTestTranslationEntry& TestGermanEntry = GermanTranslations[GermanTranslations.AddDefaulted()];
TestGermanEntry.Namespace = TestSourceEntry.Namespace;
TestGermanEntry.Key = TestSourceEntry.Key;
TestGermanEntry.SourceText = TestEnglishEntry.TranslationText;
TestGermanEntry.TranslationText = FString::Printf(TEXT("German Text %d"), Index + 1);
}
// Populate database with test data
for (int32 Index = 0; Index < NumTestEntries; ++Index)
{
{
const FLocTextHelperTestSourceEntry& TestSource = TestSources[Index];
FManifestContext Ctx;
Ctx.Key = TestSource.Key;
LocTestHelper.AddSourceText(TestSource.Namespace, FLocItem(TestSource.SourceText), Ctx);
}
{
FLocTextHelperTestTranslationEntry& TestEnglishEntry = EnglishTranslations[Index];
LocTestHelper.AddTranslation(TEXT("en"), TestEnglishEntry.Namespace, TestEnglishEntry.Key, nullptr, FLocItem(TestEnglishEntry.SourceText), FLocItem(TestEnglishEntry.TranslationText), false);
}
{
FLocTextHelperTestTranslationEntry& TestFrenchEntry = FrenchTranslations[Index];
LocTestHelper.AddTranslation(TEXT("fr"), TestFrenchEntry.Namespace, TestFrenchEntry.Key, nullptr, FLocItem(TestFrenchEntry.SourceText), FLocItem(TestFrenchEntry.TranslationText), false);
}
{
FLocTextHelperTestTranslationEntry& TestGermanEntry = GermanTranslations[Index];
LocTestHelper.AddTranslation(TEXT("de"), TestGermanEntry.Namespace, TestGermanEntry.Key, nullptr, FLocItem(TestGermanEntry.SourceText), FLocItem(TestGermanEntry.TranslationText), false);
}
}
// Check that all the test data can be found
for (int32 Index = 0; Index < NumTestEntries; ++Index)
{
const FLocTextHelperTestSourceEntry& TestSourceEntry = TestSources[Index];
const FLocTextHelperTestTranslationEntry& TestEnglishEntry = EnglishTranslations[Index];
const FLocTextHelperTestTranslationEntry& TestFrenchEntry = FrenchTranslations[Index];
const FLocTextHelperTestTranslationEntry& TestGermanEntry = GermanTranslations[Index];
{
TSharedPtr<FManifestEntry> ManifestEntry = LocTestHelper.FindSourceText(TestSourceEntry.Namespace, TestSourceEntry.Key, &TestSourceEntry.SourceText);
if (!ManifestEntry.IsValid())
{
AddError(FString::Printf(TEXT("Failed to find expected source text: '%s', '%s', '%s'."), *TestSourceEntry.Namespace, *TestSourceEntry.Key, *TestSourceEntry.SourceText));
}
}
auto TestTranslationLookup = [this, &LocTestHelper](const FString& InCultureName, const FLocTextHelperTestSourceEntry& InSourceEntry, const FLocTextHelperTestTranslationEntry& InTranslationEntry)
{
TSharedPtr<FArchiveEntry> FoundArchiveEntry = LocTestHelper.FindTranslation(InCultureName, InTranslationEntry.Namespace, InTranslationEntry.Key, nullptr);
if (!FoundArchiveEntry.IsValid() || !FoundArchiveEntry->Translation.Text.Equals(InTranslationEntry.TranslationText, ESearchCase::CaseSensitive))
{
//.........这里部分代码省略.........