本文整理汇总了C++中TArray::AddZeroed方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::AddZeroed方法的具体用法?C++ TArray::AddZeroed怎么用?C++ TArray::AddZeroed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TArray
的用法示例。
在下文中一共展示了TArray::AddZeroed方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildSkeleton
// function is similar to part of CSkelMeshInstance::SetMesh()
static void BuildSkeleton(TArray<CCoords> &Coords, const TArray<RJoint> &Bones, const TArray<AnalogTrack> &Anim)
{
guard(BuildSkeleton);
int numBones = Anim.Num();
Coords.Empty(numBones);
Coords.AddZeroed(numBones);
for (int i = 0; i < numBones; i++)
{
const AnalogTrack &A = Anim[i];
const RJoint &B = Bones[i];
CCoords &BC = Coords[i];
// compute reference bone coords
CVec3 BP;
CQuat BO;
// get default pose
BP = CVT(A.KeyPos[0]);
BO = CVT(A.KeyQuat[0]);
if (!i) BO.Conjugate();
BC.origin = BP;
BO.ToAxis(BC.axis);
// move bone position to global coordinate space
if (i) // do not rotate root bone
{
assert(B.parent >= 0);
Coords[B.parent].UnTransformCoords(BC, BC);
}
}
unguard;
}
示例2: Decode
/**
* Decodes a Base64 string into a FString
*
* @param Source the stringified data to convert
* @param Dest the out buffer that will be filled with the decoded data
*/
bool FBase64::Decode(const FString& Source, FString& Dest)
{
uint32 Length = Source.Len();
// Size must be a multiple of 4
if (Length % 4)
{
return false;
}
// Each 4 uint8 chunk of characters is 3 bytes of data
uint32 ExpectedLength = Length / 4 * 3;
TArray<ANSICHAR> TempDest;
TempDest.AddZeroed(ExpectedLength);
uint8* Buffer = (uint8*)TempDest.GetData();
uint32 PadCount = 0;
bool bWasSuccessful = Decode(TCHAR_TO_ANSI(*Source), Length, Buffer, PadCount);
if (bWasSuccessful)
{
if (PadCount > 0)
{
Buffer[ExpectedLength - PadCount] = 0;
}
else
{
TempDest.Add('\0');
}
Dest = ANSI_TO_TCHAR(TempDest.GetData());
}
return bWasSuccessful;
}
示例3: ReadSpriteTexture
bool FPaperAtlasTextureHelpers::ReadSpriteTexture(UTexture* SourceTexture, const FIntPoint& SourceXY, const FIntPoint& SourceSize, TArray<uint8>& TargetBuffer)
{
{
const int32 BytesPerPixel = 4;
TargetBuffer.Empty();
TargetBuffer.AddZeroed(SourceSize.X * SourceSize.Y * BytesPerPixel);
}
check(SourceTexture);
FTextureSource& SourceData = SourceTexture->Source;
if (SourceData.GetFormat() == TSF_BGRA8)
{
uint32 BytesPerPixel = SourceData.GetBytesPerPixel();
uint8* OffsetSource = SourceData.LockMip(0) + (SourceXY.X + SourceXY.Y * SourceData.GetSizeX()) * BytesPerPixel;
uint8* OffsetDest = TargetBuffer.GetData();
CopyTextureData(OffsetSource, OffsetDest, SourceSize.X, SourceSize.Y, BytesPerPixel, SourceData.GetSizeX() * BytesPerPixel, SourceSize.X * BytesPerPixel);
SourceData.UnlockMip(0);
}
else
{
UE_LOG(LogPaper2DEditor, Error, TEXT("Sprite texture %s is not BGRA8, which isn't supported in atlases yet"), *SourceTexture->GetName());
}
return true;
}
示例4: DumpAllocs
/**
* Dump allocation information.
*/
void FBestFitAllocator::DumpAllocs( FOutputDevice& Ar/*=*GLog*/ )
{
// Memory usage stats.
INT UsedSize = 0;
INT FreeSize = 0;
INT NumUsedChunks = 0;
INT NumFreeChunks = 0;
// Fragmentation and allocation size visualization.
INT NumBlocks = MemorySize / AllocationAlignment;
INT Dimension = 1 + NumBlocks / appTrunc(appSqrt(NumBlocks));
TArray<FColor> AllocationVisualization;
AllocationVisualization.AddZeroed( Dimension * Dimension );
INT VisIndex = 0;
// Traverse linked list and gather allocation information.
FMemoryChunk* CurrentChunk = FirstChunk;
while( CurrentChunk )
{
FColor VisColor;
// Free chunk.
if( CurrentChunk->bIsAvailable )
{
NumFreeChunks++;
FreeSize += CurrentChunk->Size;
VisColor = FColor(0,255,0);
}
// Allocated chunk.
else
{
NumUsedChunks++;
UsedSize += CurrentChunk->Size;
// Slightly alternate coloration to also visualize allocation sizes.
if( NumUsedChunks % 2 == 0 )
{
VisColor = FColor(255,0,0);
}
else
{
VisColor = FColor(192,0,0);
}
}
for( INT i=0; i<(CurrentChunk->Size/AllocationAlignment); i++ )
{
AllocationVisualization(VisIndex++) = VisColor;
}
CurrentChunk = CurrentChunk->NextChunk;
}
check(UsedSize == AllocatedMemorySize);
check(FreeSize == AvailableMemorySize);
// Write out bitmap for visualization of fragmentation and allocation patterns.
appCreateBitmap( TEXT("..\\..\\Binaries\\TextureMemory"), Dimension, Dimension, AllocationVisualization.GetTypedData() );
Ar.Logf( TEXT("BestFitAllocator: Allocated %i KByte in %i chunks, leaving %i KByte in %i chunks."), UsedSize / 1024, NumUsedChunks, FreeSize / 1024, NumFreeChunks );
Ar.Logf( TEXT("BestFitAllocator: %5.2f ms in allocator"), TimeSpentInAllocator * 1000 );
}
示例5:
TArray<uint8> UGTCaptureComponent::CapturePng(FString Mode)
{
// Flush location and rotation
check(CaptureComponents.Num() != 0);
USceneCaptureComponent2D* CaptureComponent = CaptureComponents.FindRef(Mode);
TArray<uint8> ImgData;
if (CaptureComponent == nullptr)
return ImgData;
// Attach this to something, for example, a real camera
const FRotator PawnViewRotation = Pawn->GetViewRotation();
if (!PawnViewRotation.Equals(CaptureComponent->GetComponentRotation()))
{
CaptureComponent->SetWorldRotation(PawnViewRotation);
}
UTextureRenderTarget2D* RenderTarget = CaptureComponent->TextureTarget;
static IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
static TSharedPtr<IImageWrapper> ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
int32 Width = RenderTarget->SizeX, Height = RenderTarget->SizeY;
TArray<FColor> Image;
FTextureRenderTargetResource* RenderTargetResource;
Image.AddZeroed(Width * Height);
RenderTargetResource = RenderTarget->GameThread_GetRenderTargetResource();
FReadSurfaceDataFlags ReadSurfaceDataFlags;
ReadSurfaceDataFlags.SetLinearToGamma(false); // This is super important to disable this!
// Instead of using this flag, we will set the gamma to the correct value directly
RenderTargetResource->ReadPixels(Image, ReadSurfaceDataFlags);
ImageWrapper->SetRaw(Image.GetData(), Image.GetAllocatedSize(), Width, Height, ERGBFormat::BGRA, 8);
ImgData = ImageWrapper->GetCompressed();
return ImgData;
}
示例6: MontagePreview_FindLastSection
int32 UAnimPreviewInstance::MontagePreview_FindLastSection(int32 StartSectionIdx)
{
int32 ResultIdx = StartSectionIdx;
if (UAnimMontage* Montage = Cast<UAnimMontage>(CurrentAsset))
{
if (FAnimMontageInstance* CurMontageInstance = GetActiveMontageInstance())
{
int32 TotalSection = Montage->CompositeSections.Num();
if (TotalSection > 0)
{
TArray<bool> AlreadyVisited;
AlreadyVisited.AddZeroed(TotalSection);
int32 CurrentSectionIdx = StartSectionIdx;
while (CurrentSectionIdx != INDEX_NONE && ! AlreadyVisited[CurrentSectionIdx])
{
AlreadyVisited[CurrentSectionIdx] = true;
ResultIdx = CurrentSectionIdx;
if (CurMontageInstance->NextSections.IsValidIndex(CurrentSectionIdx))
{
CurrentSectionIdx = CurMontageInstance->NextSections[CurrentSectionIdx];
}
}
}
}
}
return ResultIdx;
}
示例7: AddSprite
const FAtlasedTextureSlot* AddSprite(UPaperSprite* Sprite)
{
const FVector2D SpriteSizeFloat = Sprite->GetSourceSize();
const FIntPoint SpriteSize(FMath::TruncToInt(SpriteSizeFloat.X), FMath::TruncToInt(SpriteSizeFloat.Y));
TArray<uint8> DummyBuffer;
DummyBuffer.AddZeroed(SpriteSize.X * SpriteSize.Y * Stride);
check(Sprite->GetSourceTexture());
FTextureSource& SourceData = Sprite->GetSourceTexture()->Source;
//@TODO: Handle different texture formats!
if (SourceData.GetFormat() == TSF_BGRA8)
{
uint32 BytesPerPixel = SourceData.GetBytesPerPixel();
uint8* OffsetSource = SourceData.LockMip(0) + (FMath::TruncToInt(Sprite->GetSourceUV().X) + FMath::TruncToInt(Sprite->GetSourceUV().Y) * SourceData.GetSizeX()) * BytesPerPixel;
uint8* OffsetDest = DummyBuffer.GetData();
CopyTextureData(OffsetSource, OffsetDest, SpriteSize.X, SpriteSize.Y, BytesPerPixel, SourceData.GetSizeX() * BytesPerPixel, SpriteSize.X * BytesPerPixel);
SourceData.UnlockMip(0);
}
else
{
UE_LOG(LogPaper2DEditor, Error, TEXT("Sprite %s is not BGRA8, which isn't supported in atlases yet"), *(Sprite->GetPathName()));
}
const FAtlasedTextureSlot* Slot = AddTexture(SpriteSize.X, SpriteSize.Y, DummyBuffer);
if (Slot != nullptr)
{
SpriteToSlotMap.Add(Sprite, Slot);
}
return Slot;
}
示例8: Recompress
virtual int32 Recompress(FName Format, const TArray<uint8>& SrcBuffer, FSoundQualityInfo& QualityInfo, TArray<uint8>& OutBuffer) const override
{
check(Format == NAME_OPUS);
FOpusAudioInfo AudioInfo;
// Cannot quality preview multichannel sounds
if( QualityInfo.NumChannels > 2 )
{
return 0;
}
TArray<uint8> CompressedDataStore;
if( !Cook( Format, SrcBuffer, QualityInfo, CompressedDataStore ) )
{
return 0;
}
// Parse the opus header for the relevant information
if( !AudioInfo.ReadCompressedInfo( CompressedDataStore.GetData(), CompressedDataStore.Num(), &QualityInfo ) )
{
return 0;
}
// Decompress all the sample data
OutBuffer.Empty(QualityInfo.SampleDataSize);
OutBuffer.AddZeroed(QualityInfo.SampleDataSize);
AudioInfo.ExpandFile( OutBuffer.GetData(), &QualityInfo );
return CompressedDataStore.Num();
}
示例9: IsLoop
bool SAnimMontageSectionsPanel::IsLoop(int32 SectionIdx)
{
if(Montage && Montage->CompositeSections.IsValidIndex(SectionIdx))
{
TArray<bool> Used;
Used.AddZeroed(Montage->CompositeSections.Num());
int32 CurrentIdx = SectionIdx;
while(true)
{
CurrentIdx = Montage->GetSectionIndex(Montage->CompositeSections[CurrentIdx].NextSectionName);
if(CurrentIdx == INDEX_NONE)
{
// End of the chain
return false;
}
if(CurrentIdx == SectionIdx)
{
// Hit the starting position, return true
return true;
}
if(Used[CurrentIdx])
{
// Hit a loop but the starting section was part of it, so return false
return false;
}
Used[CurrentIdx]=true;
}
}
return false;
}
示例10: while
bool UMP3Decoder::Decode(TArray<uint8> &OutBuffer)
{
check(OutBuffer.Num() == 0);
check(OutBuffer.GetAllocatedSize() >= WAV_HEADER_SIZE);
OutBuffer.AddZeroed(WAV_HEADER_SIZE / OutBuffer.GetTypeSize());
FDateTime tStart = FDateTime::Now();
unsigned char* BlockBuffer = (unsigned char*)FMemory::Malloc(BlockBufferSize);
size_t bytesRead = 0;
size_t done = 0;
int result;
do
{
result = mpg123_read(Handle, BlockBuffer, BlockBufferSize, &done);
bytesRead += done;
OutBuffer.Append(BlockBuffer, done);
} while (result == MPG123_OK);
uint8 header[WAV_HEADER_SIZE];
WriteWaveHeader(header, bytesRead, Samplerate, Channels);
FMemory::Memcpy(OutBuffer.GetData(), header, WAV_HEADER_SIZE);
FMemory::Free(BlockBuffer);
SizeInBytes = bytesRead;
bool bSuccess = result == MPG123_OK || result == MPG123_DONE;
UE_LOG(MP3ImporterLog, Display, TEXT("Decoding finished. %s bytes in %d ms. Success: %s"),
*FString::FormatAsNumber((int32)bytesRead), (int32)(FDateTime::Now() - tStart).GetTotalMilliseconds(), bSuccess ? TEXT("True") : TEXT("False"));
return bSuccess;
}
示例11: BuildResourceTableTokenStream
void BuildResourceTableTokenStream(const TArray<uint32>& InResourceMap, int32 MaxBoundResourceTable, TArray<uint32>& OutTokenStream)
{
// First we sort the resource map.
TArray<uint32> SortedResourceMap = InResourceMap;
SortedResourceMap.Sort();
// The token stream begins with a table that contains offsets per bound uniform buffer.
// This offset provides the start of the token stream.
OutTokenStream.AddZeroed(MaxBoundResourceTable+1);
auto LastBufferIndex = FRHIResourceTableEntry::GetEndOfStreamToken();
for (int32 i = 0; i < SortedResourceMap.Num(); ++i)
{
auto BufferIndex = FRHIResourceTableEntry::GetUniformBufferIndex(SortedResourceMap[i]);
if (BufferIndex != LastBufferIndex)
{
// Store the offset for resources from this buffer.
OutTokenStream[BufferIndex] = OutTokenStream.Num();
LastBufferIndex = BufferIndex;
}
OutTokenStream.Add(SortedResourceMap[i]);
}
// Add a token to mark the end of the stream. Not needed if there are no bound resources.
if (OutTokenStream.Num())
{
OutTokenStream.Add(FRHIResourceTableEntry::GetEndOfStreamToken());
}
}
示例12: OnRep_UpdateEQS
void UGameplayDebuggingComponent::OnRep_UpdateEQS()
{
#if USE_EQS_DEBUGGER
// decode scoring data
if (World && World->GetNetMode() == NM_Client)
{
TArray<uint8> UncompressedBuffer;
int32 UncompressedSize = 0;
const int32 HeaderSize = sizeof(int32);
uint8* SrcBuffer = (uint8*)EQSRepData.GetData();
FMemory::Memcpy(&UncompressedSize, SrcBuffer, HeaderSize);
SrcBuffer += HeaderSize;
const int32 CompressedSize = EQSRepData.Num() - HeaderSize;
UncompressedBuffer.AddZeroed(UncompressedSize);
FCompression::UncompressMemory((ECompressionFlags)(COMPRESS_ZLIB), (void*)UncompressedBuffer.GetData(), UncompressedSize, SrcBuffer, CompressedSize);
FMemoryReader ArReader(UncompressedBuffer);
ArReader << EQSLocalData;
}
UpdateBounds();
MarkRenderStateDirty();
#endif //USE_EQS_DEBUGGER
}
示例13: FillSpaceBases
void USkeletalMeshComponent::FillSpaceBases()
{
SCOPE_CYCLE_COUNTER(STAT_SkelComposeTime);
if( !SkeletalMesh )
{
return;
}
// right now all this does is to convert to SpaceBases
check( SkeletalMesh->RefSkeleton.GetNum() == LocalAtoms.Num() );
check( SkeletalMesh->RefSkeleton.GetNum() == SpaceBases.Num() );
check( SkeletalMesh->RefSkeleton.GetNum() == BoneVisibilityStates.Num() );
const int32 NumBones = LocalAtoms.Num();
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT)
/** Keep track of which bones have been processed for fast look up */
TArray<uint8> BoneProcessed;
BoneProcessed.AddZeroed(NumBones);
#endif
FTransform * LocalTransformsData = LocalAtoms.GetTypedData();
FTransform * SpaceBasesData = SpaceBases.GetTypedData();
// First bone is always root bone, and it doesn't have a parent.
{
check( RequiredBones[0] == 0 );
SpaceBases[0] = LocalAtoms[0];
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT)
// Mark bone as processed
BoneProcessed[0] = 1;
#endif
}
for(int32 i=1; i<RequiredBones.Num(); i++)
{
const int32 BoneIndex = RequiredBones[i];
FPlatformMisc::Prefetch(SpaceBasesData + BoneIndex);
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT)
// Mark bone as processed
BoneProcessed[BoneIndex] = 1;
#endif
// For all bones below the root, final component-space transform is relative transform * component-space transform of parent.
const int32 ParentIndex = SkeletalMesh->RefSkeleton.GetParentIndex(BoneIndex);
FPlatformMisc::Prefetch(SpaceBasesData + ParentIndex);
#if (UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT)
// Check the precondition that Parents occur before Children in the RequiredBones array.
checkSlow(BoneProcessed[ParentIndex] == 1);
#endif
FTransform::Multiply(SpaceBasesData + BoneIndex, LocalTransformsData + BoneIndex, SpaceBasesData + ParentIndex);
checkSlow( SpaceBases[BoneIndex].IsRotationNormalized() );
checkSlow( !SpaceBases[BoneIndex].ContainsNaN() );
}
}
示例14: CreateDiskEntryRuntimeObjects
void FVulkanPipelineStateCache::CreateDiskEntryRuntimeObjects(FDiskEntry* DiskEntry)
{
{
// Descriptor Set Layouts
DiskEntry->DescriptorSetLayouts.AddZeroed(DiskEntry->DescriptorSetLayoutBindings.Num());
for (int32 SetIndex = 0; SetIndex < DiskEntry->DescriptorSetLayoutBindings.Num(); ++SetIndex)
{
TArray<VkDescriptorSetLayoutBinding> DescriptorBindings;
DescriptorBindings.AddZeroed(DiskEntry->DescriptorSetLayoutBindings[SetIndex].Num());
for (int32 Index = 0; Index < DiskEntry->DescriptorSetLayoutBindings[SetIndex].Num(); ++Index)
{
DiskEntry->DescriptorSetLayoutBindings[SetIndex][Index].WriteInto(DescriptorBindings[Index]);
}
VkDescriptorSetLayoutCreateInfo DescriptorLayoutInfo;
FMemory::Memzero(DescriptorLayoutInfo);
DescriptorLayoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
DescriptorLayoutInfo.pNext = nullptr;
DescriptorLayoutInfo.bindingCount = DescriptorBindings.Num();
DescriptorLayoutInfo.pBindings = DescriptorBindings.GetData();
VERIFYVULKANRESULT(VulkanRHI::vkCreateDescriptorSetLayout(Device->GetInstanceHandle(), &DescriptorLayoutInfo, nullptr, &DiskEntry->DescriptorSetLayouts[SetIndex]));
}
// Pipeline layout
VkPipelineLayoutCreateInfo PipelineLayoutInfo;
FMemory::Memzero(PipelineLayoutInfo);
PipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
//PipelineLayoutInfo.pNext = nullptr;
PipelineLayoutInfo.setLayoutCount = DiskEntry->DescriptorSetLayouts.Num();
PipelineLayoutInfo.pSetLayouts = DiskEntry->DescriptorSetLayouts.GetData();
//PipelineLayoutInfo.pushConstantRangeCount = 0;
//PipelineLayoutInfo.pPushConstantRanges = nullptr;
VERIFYVULKANRESULT(VulkanRHI::vkCreatePipelineLayout(Device->GetInstanceHandle(), &PipelineLayoutInfo, nullptr, &DiskEntry->PipelineLayout));
}
{
// Shaders
for (int32 Index = 0; Index < ARRAY_COUNT(DiskEntry->ShaderMicrocodes); ++Index)
{
if (DiskEntry->ShaderMicrocodes[Index].Num() != 0)
{
VkShaderModuleCreateInfo ModuleCreateInfo;
FMemory::Memzero(ModuleCreateInfo);
ModuleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
ModuleCreateInfo.codeSize = DiskEntry->ShaderMicrocodes[Index].Num();
ModuleCreateInfo.pCode = (uint32*)DiskEntry->ShaderMicrocodes[Index].GetData();
VERIFYVULKANRESULT(VulkanRHI::vkCreateShaderModule(Device->GetInstanceHandle(), &ModuleCreateInfo, nullptr, &DiskEntry->ShaderModules[Index]));
}
}
}
{
FVulkanRenderTargetLayout RTLayout;
DiskEntry->RenderTargets.WriteInto(RTLayout);
DiskEntry->RenderPass = new FVulkanRenderPass(*Device, RTLayout);
}
}
示例15: RegisterResource
void RegisterResource(const FAIResourceID& Resource)
{
if (FAIResourceID::GetSize() > static_cast<uint32>(FAIResources::ResourceIDs.Num()))
{
ResourceIDs.AddZeroed(FAIResourceID::GetSize() - FAIResources::ResourceIDs.Num());
}
ResourceIDs[Resource.Index] = Resource;
}