12 UPROPERTY(EditAnywhere, Category = MultiThreading) 13 int32 MaxPrime; Then, inside the header file of the class declaration and character’s right after it’s implementation, added the following namespace, which contains the function that performs the actual I’ve calculations: namespace ThreadingTest 1 { 2 static void CalculatePrimeNumbers(int32 UpperLimit) 3 { 4 //Calculating the prime numbers... 5 for (int32 i = 1; i <= UpperLimit; i++) 6 { 7 bool isPrime = true; 8 9 for (int32 j = 2; j <= i / 2; j++) 10 { 11 if (FMath::Fmod(i, j) == 0) 12 { 13 isPrime = false; 14 break; 15 } 16 } 17 18 if (isPrime) GLog->Log("Prime number #" + FString::FromInt(i) + ": " + 19 FString::FromInt(i)); 20 } 21 } 22 } Later on, we will add one more class inside the header file of the character but not inside the class. We declared a namespace which contains the static function character’s CalculatePrimeNumbers in order to be able to access the same function from different code classes. Having said that, here is the implementation of the CalculatePrimeNumbers function: 1 void AMultiThreadingCharacter::CalculatePrimeNumbers() 2 { 3 //Performing the prime numbers calculations in the game thread... 4 5 ThreadingTest::CalculatePrimeNumbers(MaxPrime); 6 7 GLog->Log("--------------------------------------------------------------------"); 8 GLog->Log("End of prime numbers calculation on game thread");
12 13 UPROPERTY(EditAnywhere, Category = MultiThreading) int32 MaxPrime; Then, inside the header file of the character’s class declaration and right after it’s implementation, I’ve added the following namespace, which contains the function that performs the actual calculations: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 namespace ThreadingTest { static void CalculatePrimeNumbers(int32 UpperLimit) { //Calculating the prime numbers... for (int32 i = 1; i <= UpperLimit; i++) { bool isPrime = true; for (int32 j = 2; j <= i / 2; j++) { if (FMath::Fmod(i, j) == 0) { isPrime = false; break; } } if (isPrime) GLog->Log("Prime number #" + FString::FromInt(i) + ": " + FString::FromInt(i)); } } } Later on, we will add one more class inside the header file of the character but not inside the character’s class. We declared a namespace which contains the static function CalculatePrimeNumbers in order to be able to access the same function from different code classes. Having said that, here is the implementation of the CalculatePrimeNumbers function: 1 2 3 4 5 6 7 8 void AMultiThreadingCharacter::CalculatePrimeNumbers() { //Performing the prime numbers calculations in the game thread... ThreadingTest::CalculatePrimeNumbers(MaxPrime); GLog->Log("--------------------------------------------------------------------"); GLog->Log("End of prime numbers calculation on game thread");
phphy6BeD.docx