本文整理汇总了C++中FRandomStream类的典型用法代码示例。如果您正苦于以下问题:C++ FRandomStream类的具体用法?C++ FRandomStream怎么用?C++ FRandomStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FRandomStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetClass
void AActor::ResetPropertiesForConstruction()
{
// Get class CDO
AActor* Default = GetClass()->GetDefaultObject<AActor>();
// RandomStream struct name to compare against
const FName RandomStreamName(TEXT("RandomStream"));
// We don't want to reset references to world object
const bool bIsLevelScriptActor = IsA(ALevelScriptActor::StaticClass());
// Iterate over properties
for( TFieldIterator<UProperty> It(GetClass()) ; It ; ++It )
{
UProperty* Prop = *It;
UStructProperty* StructProp = Cast<UStructProperty>(Prop);
UClass* PropClass = CastChecked<UClass>(Prop->GetOuter()); // get the class that added this property
// First see if it is a random stream, if so reset before running construction script
if( (StructProp != NULL) && (StructProp->Struct != NULL) && (StructProp->Struct->GetFName() == RandomStreamName) )
{
FRandomStream* StreamPtr = StructProp->ContainerPtrToValuePtr<FRandomStream>(this);
StreamPtr->Reset();
}
// If it is a blueprint added variable that is not editable per-instance, reset to default before running construction script
else if( !bIsLevelScriptActor
&& Prop->HasAnyPropertyFlags(CPF_DisableEditOnInstance)
&& PropClass->HasAnyClassFlags(CLASS_CompiledFromBlueprint)
&& !Prop->IsA(UDelegateProperty::StaticClass())
&& !Prop->IsA(UMulticastDelegateProperty::StaticClass()) )
{
Prop->CopyCompleteValue_InContainer(this, Default);
}
}
}
示例2: SpawnShootFX
void AProjectile::SpawnShootFX(const FVector& location, const FRotator& rotator, USceneComponent* component, FName name)
{
FRandomStream Stream; //random stream
FRotator rotTemp = rotator;
rotTemp = FRotator(rotTemp.Pitch, rotTemp.Yaw, Stream.FRandRange(-180, 180)); //randomly rotate the effect
//spawn shooting sound FX
UGameplayStatics::SpawnSoundAttached(ShootFX.ShootSound, component, name);
//Spawn shooting particle effect
UGameplayStatics::SpawnEmitterAttached(ShootFX.ShootFlash, component, name);
}
示例3: BaseName
UExample::UExample()
{
FString BaseName(TEXT("Example"));
FRandomStream Rand;
for (int i = 0; i < 10; i++)
{
FString StructName = BaseName + FString::FromInt(i);
ExampleMap.Add(*StructName);
ExampleMap[*StructName].Var1 = Rand.FRand();
ExampleMap[*StructName].Var2 = Rand.FRand();
ExampleMap[*StructName].Var3 = Rand.FRand();
ExampleMap[*StructName].Var4 = Rand.FRand();
}
}
示例4: FRandomStream
void ASpellDeck::Shuffle()
{
int64 DateInSeconds = FDateTime::Now().ToUnixTimestamp();
FRandomStream SRand = FRandomStream();
SRand.Initialize(DateInSeconds);
int32 j;
for (int32 i = spellDeck.Num() - 1; i > 0; i--)
{
j = FMath::FloorToInt(SRand.FRand()*(i + 1));
UActionCard* temp = spellDeck[i];
spellDeck[i] = spellDeck[j];
spellDeck[j] = temp;
}
}
示例5: SpawnImpactFX
void AProjectile::SpawnImpactFX(const FHitResult& Hit)
{
FRandomStream Stream; //random stream
FRotator rotTemp = Hit.ImpactNormal.Rotation();
rotTemp = FRotator(rotTemp.Pitch, rotTemp.Yaw, Stream.FRandRange(-180, 180)); //randomly rotate the effect
//impact effects sound spawn
UGameplayStatics::SpawnEmitterAtLocation(this, ImpactFX.Effect, Hit.ImpactPoint, rotTemp, true);
//spawn decal effect on impact position
UGameplayStatics::SpawnDecalAttached(ImpactFX.DecalMaterial,
FVector(ImpactFX.DecalSize, ImpactFX.DecalSize, 1.0F),
Hit.GetComponent(),
Hit.BoneName,
Hit.ImpactPoint,
rotTemp,
EAttachLocation::KeepWorldPosition, ImpactFX.DecalHealth);
}
示例6: getRandomOpposingEdges
static std::pair<Graph::HalfEdge *, Graph::HalfEdge *> getRandomOpposingEdges(
Graph::Face &face,
FRandomStream &random) {
// Get all the edges in the face.
std::vector<Graph::HalfEdge *> edges;
edges.reserve(4u);
auto &firstEdge = Graph::GetHalfEdge(face);
auto *edge = &firstEdge;
do {
edges.emplace_back(edge);
edge = &Graph::GetNextInFace(*edge);
} while (edge != &firstEdge);
check(edges.size() == 4u);
auto randomIndex = random.RandRange(0, edges.size() - 1);
return {edges[randomIndex], edges[(randomIndex + 2u) % edges.size()]};
}
示例7: SeedRandomStream
void UKismetMathLibrary::SeedRandomStream(FRandomStream& Stream)
{
Stream.GenerateNewSeed();
}
示例8: ResetRandomStream
void UKismetMathLibrary::ResetRandomStream(const FRandomStream& Stream)
{
Stream.Reset();
}
示例9: RandomUnitVectorFromStream
FVector UKismetMathLibrary::RandomUnitVectorFromStream(const FRandomStream& Stream)
{
return Stream.VRand();
}
示例10: RandomFloatFromStream
float UKismetMathLibrary::RandomFloatFromStream(const FRandomStream& Stream)
{
return Stream.FRand();
}
示例11: RandomBoolFromStream
bool UKismetMathLibrary::RandomBoolFromStream(const FRandomStream& Stream)
{
return (Stream.RandRange(0,1) == 1) ? true : false;
}
示例12: RandomIntegerInRangeFromStream
int32 UKismetMathLibrary::RandomIntegerInRangeFromStream(int32 Min, int32 Max, const FRandomStream& Stream)
{
return Stream.RandRange(Min, Max);
}
示例13: BreakRandomStream
void UKismetMathLibrary::BreakRandomStream(const FRandomStream& InRandomStream, int32& InitialSeed)
{
InitialSeed = InRandomStream.GetInitialSeed();
}
示例14: Buffer
bool FTripleBufferTest::RunTest(const FString& Parameters)
{
// uninitialized buffer
{
TTripleBuffer<int32> Buffer(NoInit);
TestFalse(TEXT("Uninitialized triple buffer must not be dirty"), Buffer.IsDirty());
}
// initialized buffer
{
TTripleBuffer<int32> Buffer(1);
TestFalse(TEXT("Initialized triple buffer must not be dirty"), Buffer.IsDirty());
TestEqual(TEXT("Initialized triple buffer must have correct read buffer value"), Buffer.Read(), 1);
Buffer.SwapReadBuffers();
TestEqual(TEXT("Initialized triple buffer must have correct temp buffer value"), Buffer.Read(), 1);
Buffer.SwapWriteBuffers();
TestTrue(TEXT("Write buffer swap must set dirty flag"), Buffer.IsDirty());
Buffer.SwapReadBuffers();
TestFalse(TEXT("Read buffer swap must clear dirty flag"), Buffer.IsDirty());
TestEqual(TEXT("Initialized triple buffer must have correct temp buffer value"), Buffer.Read(), 1);
}
// pre-set buffer
{
int32 Array[3] = { 1, 2, 3 };
TTripleBuffer<int32> Buffer(Array);
int32 Read = Buffer.Read();
TestEqual(TEXT("Pre-set triple buffer must have correct Read buffer value"), Read, 3);
Buffer.SwapReadBuffers();
int32 Temp = Buffer.Read();
TestEqual(TEXT("Pre-set triple buffer must have correct Temp buffer value"), Temp, 1);
Buffer.SwapWriteBuffers();
Buffer.SwapReadBuffers();
int32 Write = Buffer.Read();
TestEqual(TEXT("Pre-set triple buffer must have correct Write buffer value"), Write, 2);
}
// operations
{
TTripleBuffer<int32> Buffer;
for (int32 Index = 0; Index < 6; ++Index)
{
int32& Write = Buffer.GetWriteBuffer(); Write = Index; Buffer.SwapWriteBuffers();
Buffer.SwapReadBuffers();
TestEqual(*FString::Printf(TEXT("Triple buffer must read correct value (%i)"), Index), Buffer.Read(), Index);
}
FRandomStream Rand;
int32 LastRead = -1;
for (int32 Index = 0; Index < 100; ++Index)
{
int32 Writes = Rand.GetUnsignedInt() % 4;
while (Writes > 0)
{
int32& Write = Buffer.GetWriteBuffer(); Write = Index; Buffer.SwapWriteBuffers();
--Writes;
}
int32 Reads = Rand.GetUnsignedInt() % 4;
while (Reads > 0)
{
if (!Buffer.IsDirty())
{
break;
}
Buffer.SwapReadBuffers();
int32 Read = Buffer.Read();
TestTrue(TEXT("Triple buffer must read in increasing order"), Read > LastRead);
LastRead = Read;
--Reads;
}
}
}
return true;
}
示例15: SetRandomStreamSeed
void UKismetMathLibrary::SetRandomStreamSeed(FRandomStream& Stream, int32 NewSeed)
{
Stream.Initialize(NewSeed);
}