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); } } }
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); }
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(); } }
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; } }
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); }
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()]}; }
void UKismetMathLibrary::SeedRandomStream(FRandomStream& Stream) { Stream.GenerateNewSeed(); }
void UKismetMathLibrary::ResetRandomStream(const FRandomStream& Stream) { Stream.Reset(); }
FVector UKismetMathLibrary::RandomUnitVectorFromStream(const FRandomStream& Stream) { return Stream.VRand(); }
float UKismetMathLibrary::RandomFloatFromStream(const FRandomStream& Stream) { return Stream.FRand(); }
bool UKismetMathLibrary::RandomBoolFromStream(const FRandomStream& Stream) { return (Stream.RandRange(0,1) == 1) ? true : false; }
int32 UKismetMathLibrary::RandomIntegerInRangeFromStream(int32 Min, int32 Max, const FRandomStream& Stream) { return Stream.RandRange(Min, Max); }
void UKismetMathLibrary::BreakRandomStream(const FRandomStream& InRandomStream, int32& InitialSeed) { InitialSeed = InRandomStream.GetInitialSeed(); }
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; }
void UKismetMathLibrary::SetRandomStreamSeed(FRandomStream& Stream, int32 NewSeed) { Stream.Initialize(NewSeed); }
int32 GenerateBodyIndex(FRandomStream& InRandomStream) const { check(ValidBodies.Num() > 0); return InRandomStream.GetUnsignedInt() % ValidBodies.Num(); }
int32 UKismetMathLibrary::RandomIntegerFromStream(int32 Max, const FRandomStream& Stream) { return Stream.RandHelper(Max); }