当前位置: 首页>>代码示例>>C++>>正文


C++ TArray::Reserve方法代码示例

本文整理汇总了C++中TArray::Reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::Reserve方法的具体用法?C++ TArray::Reserve怎么用?C++ TArray::Reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TArray的用法示例。


在下文中一共展示了TArray::Reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateAllInstanceBodies

void UPaperGroupedSpriteComponent::CreateAllInstanceBodies()
{
	QUICK_SCOPE_CYCLE_COUNTER(STAT_UPaperGroupedSpriteComponent_CreateAllInstanceBodies);

	FPhysScene* PhysScene = GetWorld()->GetPhysicsScene();

	const int32 NumBodies = PerInstanceSpriteData.Num();
	check(InstanceBodies.Num() == 0);
	InstanceBodies.SetNumUninitialized(NumBodies);

	TArray<FTransform> Transforms;
	Transforms.Reserve(NumBodies);

	TArray<TWeakObjectPtr<UBodySetup>> BodySetups;
	BodySetups.Reserve(NumBodies);

	for (int32 InstanceIndex = 0; InstanceIndex < NumBodies; ++InstanceIndex)
	{
		const FSpriteInstanceData& InstanceData = PerInstanceSpriteData[InstanceIndex];
		FBodyInstance* InstanceBody = InitInstanceBody(InstanceIndex, InstanceData, PhysScene);
		InstanceBodies[InstanceIndex] = InstanceBody;
		BodySetups.Add((InstanceBody != nullptr) ? InstanceBody->BodySetup : TWeakObjectPtr<UBodySetup>());
	}

	if (SceneProxy != nullptr)
	{
		ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
			FSendPaperGroupBodySetups,
			FGroupedSpriteSceneProxy*, InSceneProxy, (FGroupedSpriteSceneProxy*)SceneProxy,
			TArray<TWeakObjectPtr<UBodySetup>>, InBodySetups, BodySetups,
			{
			InSceneProxy->SetAllBodySetups_RenderThread(InBodySetups);
		});
开发者ID:PopCap,项目名称:GameIdea,代码行数:33,代码来源:PaperGroupedSpriteComponent.cpp

示例2: SlateMeshToSlateRenderData

/** Populate OutSlateVerts and OutIndexes with data from this static mesh such that Slate can render it. */
static void SlateMeshToSlateRenderData(const USlateVectorArtData& DataSource, TArray<FSlateVertex>& OutSlateVerts, TArray<SlateIndex>& OutIndexes)
{
	// Populate Index data
	{
		// Note that we do a slow copy because on some platforms the SlateIndex is
		// a 16-bit value, so we cannot do a memcopy.
		const TArray<uint32>& IndexDataSource = DataSource.GetIndexData();
		const int32 NumIndexes = IndexDataSource.Num();
		OutIndexes.Empty();
		OutIndexes.Reserve(NumIndexes);
		for (int32 i = 0; i < NumIndexes; ++i)
		{
			OutIndexes.Add(IndexDataSource[i]);
		}
	}

	// Populate Vertex Data
	{
		const TArray<FSlateMeshVertex> VertexDataSource = DataSource.GetVertexData();
		const uint32 NumVerts = VertexDataSource.Num();
		OutSlateVerts.Empty();
		OutSlateVerts.Reserve(NumVerts);

		for (uint32 i = 0; i < NumVerts; ++i)
		{
			const FSlateMeshVertex& SourceVertex = VertexDataSource[i];
			FSlateVertex& NewVert = OutSlateVerts[OutSlateVerts.AddUninitialized()];

			// Copy Position
			{
				NewVert.Position[0] = SourceVertex.Position.X;
				NewVert.Position[1] = SourceVertex.Position.Y;
			}

			// Copy Color
			{
				NewVert.Color = SourceVertex.Color;
			}


			// Copy all the UVs that we have, and as many as we can fit.
			{
				NewVert.TexCoords[0] = SourceVertex.UV0.X;
				NewVert.TexCoords[1] = SourceVertex.UV0.Y;

				NewVert.TexCoords[2] = SourceVertex.UV1.X;
				NewVert.TexCoords[3] = SourceVertex.UV1.Y;

				NewVert.MaterialTexCoords[0] = SourceVertex.UV2.X;
				NewVert.MaterialTexCoords[1] = SourceVertex.UV2.Y;

				NewVert.ClipRect.TopLeft = SourceVertex.UV3;

				NewVert.ClipRect.ExtentX = SourceVertex.UV4;

				NewVert.ClipRect.ExtentY = SourceVertex.UV5;
			}
		}
	}
}
开发者ID:WasPedro,项目名称:UnrealEngine4.11-HairWorks,代码行数:61,代码来源:SMeshWidget.cpp

示例3: R_ExtendSpriteFrames

static void R_ExtendSpriteFrames(spritedef_t &spr, int frame)
{
	unsigned int i, newstart;

	if (spr.numframes >= ++frame)
	{ // The sprite already has enough frames, so do nothing.
		return;
	}

	if (spr.numframes == 0 || (spr.spriteframes + spr.numframes == SpriteFrames.Size()))
	{ // Sprite's frames are at the end of the array, or it has no frames
	  // at all, so we can tack the new frames directly on to the end
	  // of the SpriteFrames array.
		newstart = SpriteFrames.Reserve(frame - spr.numframes);
		if (spr.numframes == 0)
		{
			spr.spriteframes = WORD(newstart);
		}
	}
	else
	{ // We need to allocate space for all the sprite's frames and copy
	  // the existing ones over to the new space. The old space will be
	  // lost.
		newstart = SpriteFrames.Reserve(frame);
		for (i = 0; i < spr.numframes; ++i)
		{
			SpriteFrames[newstart + i] = SpriteFrames[spr.spriteframes + i];
		}
		spr.spriteframes = WORD(newstart);
		newstart += i;
	}
	// Initialize all new frames to 0.
	memset(&SpriteFrames[newstart], 0, sizeof(spriteframe_t)*(frame - spr.numframes));
	spr.numframes = frame;
}
开发者ID:floverdevel,项目名称:zdoom,代码行数:35,代码来源:sprites.cpp

示例4: GetDynamicMeshElements

	//!< FPrimitiveSceneProxy
	virtual void GetDynamicMeshElements(const TArray<const FSceneView*>& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, class FMeshElementCollector& Collector) const override
	{
		FDynamicMeshBuilder MeshBuilder;

		const auto Num = 20;
		const auto DeltaUV = 1.0f / (Num - 1);
		TArray<FDynamicMeshVertex> Vertices;
		Vertices.Reserve(Num * Num);
		for (auto i = 0; i < Num; ++i)
		{
			for (auto j = 0; j < Num; ++j)
			{
				const auto UV = FVector2D(DeltaUV * j, DeltaUV * i);

				FDynamicMeshVertex Vertex;
				Vertex.Position = GetPosition(UV);
				Vertex.TextureCoordinate = GetUV(UV);
				const auto Edge01 = GetPosition(UV + FVector2D(0.01f, 0.0f)) - Vertex.Position;
				const auto Edge02 = GetPosition(UV - FVector2D(0.0f, 0.01f)) - Vertex.Position;
				Vertex.TangentX = Edge01.GetSafeNormal();
				Vertex.TangentZ = (Edge02 ^ Edge01).GetSafeNormal();
				Vertex.Color = FColor::Green;

				Vertices.Add(Vertex);
			}
		}
		MeshBuilder.AddVertices(Vertices);

		TArray<int32> Indices;
		Indices.Reserve((Num - 1) * (Num - 1) * 6);
		for (auto i = 0; i < Num - 1; ++i)
		{
			for (auto j = 0; j < Num - 1; ++j)
			{
				const auto Index = j + i * Num;
				Indices.Add(Index);
				Indices.Add(Index + Num);
				Indices.Add(Index + 1);

				Indices.Add(Index + 1);
				Indices.Add(Index + Num);
				Indices.Add(Index + Num + 1);
			}
		}
		MeshBuilder.AddTriangles(Indices);

		auto MaterialRenderProxy = UMaterial::GetDefaultMaterial(MD_Surface)->GetRenderProxy(IsSelected());
		if (nullptr != MaterialInterface)
		{
			MaterialRenderProxy = MaterialInterface->GetRenderProxy(false);
		}
		if (Views[0]->Family->EngineShowFlags.Wireframe)
		{
			MaterialRenderProxy = GEngine->WireframeMaterial->GetRenderProxy(IsSelected());
		}
		MeshBuilder.GetMesh(GetLocalToWorld(), MaterialRenderProxy, 0, false, false, 0, Collector);
	}
开发者ID:horinoh,项目名称:UE4ParametricSurface,代码行数:58,代码来源:ParametricSurfaceComponent.cpp

示例5: ScanDirectory

void ScanDirectory(TArray<FFileList> &list, const char *dirpath)
{
	struct _finddata_t fileinfo;
	intptr_t handle;
	FString dirmatch;

	dirmatch << dirpath << "*";

	if ((handle = _findfirst(dirmatch, &fileinfo)) == -1)
	{
		I_Error("Could not scan '%s': %s\n", dirpath, strerror(errno));
	}
	else
	{
		do
		{
			if (fileinfo.attrib & _A_HIDDEN)
			{
				// Skip hidden files and directories. (Prevents SVN bookkeeping
				// info from being included.)
				continue;
			}

			if (fileinfo.attrib & _A_SUBDIR)
			{
				if (fileinfo.name[0] == '.' &&
					(fileinfo.name[1] == '\0' ||
					 (fileinfo.name[1] == '.' && fileinfo.name[2] == '\0')))
				{
					// Do not record . and .. directories.
					continue;
				}

				FFileList *fl = &list[list.Reserve(1)];
				fl->Filename << dirpath << fileinfo.name;
				fl->isDirectory = true;
				FString newdir = fl->Filename;
				newdir << "/";
				ScanDirectory(list, newdir);
			}
			else
			{
				FFileList *fl = &list[list.Reserve(1)];
				fl->Filename << dirpath << fileinfo.name;
				fl->isDirectory = false;
			}
		}
		while (_findnext(handle, &fileinfo) == 0);
		_findclose(handle);
	}
}
开发者ID:Marqt,项目名称:ViZDoom,代码行数:51,代码来源:cmdlib.cpp

示例6: AddSeg

	bool AddSeg(seg_t *seg)
	{
		FGLSectionLine &line = SectionLines[SectionLines.Reserve(1)];


		bool firstline = loop->numlines == 0;

		if (ISDONE(seg-segs, processed_segs))
		{
			// should never happen!
			DPrintf("Tried to add seg %d to Sections twice. Cannot create Sections.\n", seg-segs);
			return false;
		}

		SETDONE(seg-segs, processed_segs);
		section_for_segs[seg-segs] = Sections.Size()-1;

		line.start = seg->v1;
		line.end = seg->v2;
		line.sidedef = seg->sidedef;
		line.linedef = seg->linedef;
		line.refseg = seg;
		line.polysub = NULL;
		line.otherside = -1;

		if (loop->numlines == 0)
		{
			v1_l1 = seg->v1;
			v2_l1 = seg->v2;
		}
		loop->numlines++;
		return true;
	}
开发者ID:RomanHargrave,项目名称:the-tower-of-babel,代码行数:33,代码来源:gl_sections.cpp

示例7: NewLoop

	void NewLoop()
	{
		section->numloops++;
		loop = &SectionLoops[SectionLoops.Reserve(1)];
		loop->startline = SectionLines.Size();
		loop->numlines = 0 ;
	}
开发者ID:RomanHargrave,项目名称:the-tower-of-babel,代码行数:7,代码来源:gl_sections.cpp

示例8: GenerateItems

void UEnvQueryGenerator_SimpleGrid::GenerateItems(FEnvQueryInstance& QueryInstance) const
{
	UObject* BindOwner = QueryInstance.Owner.Get();
	GridSize.BindData(BindOwner, QueryInstance.QueryID);
	SpaceBetween.BindData(BindOwner, QueryInstance.QueryID);

	float RadiusValue = GridSize.GetValue();
	float DensityValue = SpaceBetween.GetValue();

	const int32 ItemCount = FPlatformMath::TruncToInt((RadiusValue * 2.0f / DensityValue) + 1);
	const int32 ItemCountHalf = ItemCount / 2;

	TArray<FVector> ContextLocations;
	QueryInstance.PrepareContext(GenerateAround, ContextLocations);

	TArray<FNavLocation> GridPoints;
	GridPoints.Reserve(ItemCount * ItemCount * ContextLocations.Num());

	for (int32 ContextIndex = 0; ContextIndex < ContextLocations.Num(); ContextIndex++)
	{
		for (int32 IndexX = 0; IndexX <= ItemCount; ++IndexX)
		{
			for (int32 IndexY = 0; IndexY <= ItemCount; ++IndexY)
			{
				const FNavLocation TestPoint = FNavLocation(ContextLocations[ContextIndex] - FVector(DensityValue * (IndexX - ItemCountHalf), DensityValue * (IndexY - ItemCountHalf), 0));
				GridPoints.Add(TestPoint);
			}
		}
	}

	ProjectAndFilterNavPoints(GridPoints, QueryInstance);
	StoreNavPoints(GridPoints, QueryInstance);
}
开发者ID:amyvmiwei,项目名称:UnrealEngine4,代码行数:33,代码来源:EnvQueryGenerator_SimpleGrid.cpp

示例9: GetActors

TArray<FActiveGameplayEffectHandle> FGameplayAbilityTargetData::ApplyGameplayEffectSpec(FGameplayEffectSpec& InSpec, FPredictionKey PredictionKey)
{
	TArray<FActiveGameplayEffectHandle>	AppliedHandles;

	if (!ensure(InSpec.GetContext().IsValid() && InSpec.GetContext().GetInstigatorAbilitySystemComponent()))
	{
		return AppliedHandles;
	}

	TArray<TWeakObjectPtr<AActor> > Actors = GetActors();
	
	AppliedHandles.Reserve(Actors.Num());

	for (TWeakObjectPtr<AActor> TargetActor : Actors)
	{
		UAbilitySystemComponent* TargetComponent = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(TargetActor.Get());

		if (TargetComponent)
		{
			// We have to make a new effect spec and context here, because otherwise the targeting info gets accumulated and things take damage multiple times
			FGameplayEffectSpec	SpecToApply(InSpec);
			FGameplayEffectContextHandle EffectContext = SpecToApply.GetContext().Duplicate();
			SpecToApply.SetContext(EffectContext);

			AddTargetDataToContext(EffectContext, false);

			AppliedHandles.Add(EffectContext.GetInstigatorAbilitySystemComponent()->ApplyGameplayEffectSpecToTarget(SpecToApply, TargetComponent, PredictionKey));
		}
	}

	return AppliedHandles;
}
开发者ID:WasPedro,项目名称:UnrealEngine4.11-HairWorks,代码行数:32,代码来源:GameplayAbilityTargetTypes.cpp

示例10: GetNearbyAgentLocations

int32 UCrowdManager::GetNearbyAgentLocations(const ICrowdAgentInterface* Agent, TArray<FVector>& OutLocations) const
{
	const int32 InitialSize = OutLocations.Num();
#if WITH_RECAST
	const FCrowdAgentData* AgentData = ActiveAgents.Find(Agent);

	if (AgentData && AgentData->bIsSimulated && AgentData->IsValid() && DetourCrowd)
	{
		const dtCrowdAgent* CrowdAgent = DetourCrowd->getAgent(AgentData->AgentIndex);

		if (CrowdAgent)
		{
			OutLocations.Reserve(InitialSize + CrowdAgent->nneis);

			for (int32 NeighbourIndex = 0; NeighbourIndex < CrowdAgent->nneis; NeighbourIndex++)
			{
				const dtCrowdAgent* NeighbourAgent = DetourCrowd->getAgent(CrowdAgent->neis[NeighbourIndex].idx);
				if (NeighbourAgent)
				{
					OutLocations.Add(Recast2UnrealPoint(NeighbourAgent->npos));
				}
			}
		}
	}
#endif

	return OutLocations.Num() - InitialSize;
}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:28,代码来源:CrowdManager.cpp

示例11: RL_AddPoly

// add a poly index to the render list
//  note that the render list is a dynamic array of dynamic arrays
//  the first array is keyed with the OpenGL texture object
//  the sub-array is keyed with the polygon index
//  these are only ever resized up and only the count is reset each frame (they are completely reset on a map change, though)
void RL_AddPoly(GLuint tex, int polyIndex)
{
   RList *rl;
   int amt;
   unsigned int lastSize, i;

   //return;

   if ((tex + 1) >= renderList.Size())
   {
      lastSize = renderList.Size();
      amt = (tex + 1) - renderList.Size();
      renderList.Reserve(amt);
      for (i = lastSize; i < lastSize + amt; i++)
      {
         rl = &renderList[i];
         rl->numPolys = 0;
         rl->polys.Init();
      }
   }

   rl = &renderList[tex];
   if (rl->numPolys == rl->polys.Size())
   {
      rl->polys.Reserve(1);
   }
   rl->polys[rl->numPolys] = polyIndex;
   rl->numPolys++;
}
开发者ID:ddraigcymraeg,项目名称:scoredoomst,代码行数:34,代码来源:gl_geom.cpp

示例12: InitializeRecursive

void FGroupedKeyCollection::InitializeRecursive(const TArray<FSequencerDisplayNode*>& InNodes, float DuplicateThreshold)
{
	KeyAreas.Reset();
	Groups.Reset();

	TArray<TSharedRef<FSequencerSectionKeyAreaNode>> AllKeyAreaNodes;
	AllKeyAreaNodes.Reserve(36);
	for (FSequencerDisplayNode* Node : InNodes)
	{
		if (Node->GetType() == ESequencerNode::KeyArea)
		{
			AllKeyAreaNodes.Add(StaticCastSharedRef<FSequencerSectionKeyAreaNode>(Node->AsShared()));
		}

		Node->GetChildKeyAreaNodesRecursively(AllKeyAreaNodes);
	}

	for (const auto& Node : AllKeyAreaNodes)
	{
		const TArray<TSharedRef<IKeyArea>>& AllKeyAreas = Node->GetAllKeyAreas();
		KeyAreas.Reserve(KeyAreas.Num() + AllKeyAreas.Num());

		for (const TSharedRef<IKeyArea>& KeyArea : AllKeyAreas)
		{
			AddKeyArea(KeyArea);
		}
	}

	RemoveDuplicateKeys(DuplicateThreshold);
}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:30,代码来源:GroupedKeyArea.cpp

示例13: BuildTagTranslationTable_Forward

void FGameplayCueTranslationManager::BuildTagTranslationTable_Forward()
{
#if WITH_EDITOR
	SCOPE_LOG_TIME_IN_SECONDS(*FString::Printf(TEXT("FGameplayCueTranslatorManager::BuildTagTranslationTable_Forward")), nullptr)
#endif

	// Build the normal TranslationLUT first. This is only done to make sure that UsedTranslators are filled in, giving "real" tags higher priority.
	// Example:
	//	1) GC.Rampage.Enraged
	//	2) GC.Rampage.Elemental.Enraged
	//	
	//	2 is am override for 1, but comes first alphabetically. In the _Forward method, 2 would be handled first and expanded again to GC.Rampage.Elemental.Elemental.Enraged.
	//	rule recursion wouldn't have been hit yet because 2 actually exists and would be encountered before 1.
	//
	//	Since BuildTagTranslationTable_Forward is only called by the editor and BuildTagTranslationTable is already fast, this is the simplest way to avoid the above example.
	//	_Forward() could be made more complicated to test for this itself, but doesn't seem like a good trade off for how it would complicate the function.
	BuildTagTranslationTable();

	TArray<FName> SplitNames;
	SplitNames.Reserve(10);
	
	FGameplayTagContainer AllGameplayCueTags = TagManager->RequestGameplayTagChildren(UGameplayCueSet::BaseGameplayCueTag());

	// Each GameplayCueTag
	for (const FGameplayTag& Tag : AllGameplayCueTags)
	{
		SplitNames.Reset();
		TagManager->SplitGameplayTagFName(Tag, SplitNames);

		BuildTagTranslationTable_Forward_r(Tag.GetTagName(), SplitNames);
	}
}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:32,代码来源:GameplayCueTranslator.cpp

示例14: GetOverlaps

bool FProceduralFoliageBroadphase::GetOverlaps(FProceduralFoliageInstance* Instance, TArray<FProceduralFoliageOverlap>& Overlaps) const
{
	const float AShadeRadius     = Instance->GetShadeRadius();
	const float ACollisionRadius = Instance->GetCollisionRadius();

	TArray<FProceduralFoliageInstance*> PossibleOverlaps;
	const FBox2D AABB = GetMaxAABB(Instance);
	QuadTree.GetElements(AABB, PossibleOverlaps);
	Overlaps.Reserve(Overlaps.Num() + PossibleOverlaps.Num());
	
	for (FProceduralFoliageInstance* Overlap : PossibleOverlaps)
	{
		if (Overlap != Instance)
		{
			//We must determine if this is an overlap of shade or an overlap of collision. If both the collision overlap wins
			bool bCollisionOverlap = CircleOverlap(Instance->Location, ACollisionRadius, Overlap->Location, Overlap->GetCollisionRadius());
			bool bShadeOverlap     = CircleOverlap(Instance->Location, AShadeRadius, Overlap->Location, Overlap->GetShadeRadius());

			if (bCollisionOverlap || bShadeOverlap)
			{
				new (Overlaps)FProceduralFoliageOverlap(Instance, Overlap, bCollisionOverlap ? ESimulationOverlap::CollisionOverlap : ESimulationOverlap::ShadeOverlap);
			}
			
		}
	}

	return Overlaps.Num() > 0;
}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:28,代码来源:ProceduralFoliageBroadphase.cpp

示例15: ApplyAlgorithm

void SAnimationCompressionPanel::ApplyAlgorithm(class UAnimCompress* Algorithm)
{
	if ( Algorithm )
	{
		const bool bProceed = EAppReturnType::Yes == FMessageDialog::Open( EAppMsgType::YesNo,
			FText::Format( NSLOCTEXT("UnrealEd", "AboutToCompressAnimations_F", "About to compress {0} animations.  Proceed?"), FText::AsNumber(AnimSequences.Num()) ) );
		if ( bProceed )
		{
			TArray<UAnimSequence*> AnimSequencePtrs;
			AnimSequencePtrs.Reserve(AnimSequences.Num());

			for(int32 Index = 0; Index < AnimSequences.Num(); ++Index)
			{
				AnimSequencePtrs.Add(AnimSequences[Index].Get());
			}

			GWarn->BeginSlowTask( LOCTEXT("AnimCompressing", "Compressing"), true);
			
			Algorithm->Reduce(AnimSequencePtrs, true);

			GWarn->EndSlowTask( );

		}
	}
}
开发者ID:Tigrouzen,项目名称:UnrealEngine-4,代码行数:25,代码来源:AnimationCompressionPanel.cpp


注:本文中的TArray::Reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。