50 51 protected: 52 // APawn interface 53 virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override; 54 // End of APawn interface 55 56 public: 57 /** Returns CameraBoom subobject **/ 58 FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } 59 /** Returns FollowCamera subobject **/ 60 FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; } 61 62 protected: 63 64 /*Calculates prime numbers in the game thread*/ 65 UFUNCTION(BlueprintCallable, Category = MultiThreading) 66 void CalculatePrimeNumbers(); 67 68 /*Calculates prime numbers in a background thread*/ 69 UFUNCTION(BlueprintCallable, Category = MultiThreading) 70 void CalculatePrimeNumbersAsync(); 71 72 /*The max prime number*/ 73 UPROPERTY(EditAnywhere, Category = MultiThreading) 74 int32 MaxPrime; 75 }; 76 77 namespace ThreadingTest 78 { 79 static void CalculatePrimeNumbers(int32 UpperLimit) 80 { 81 //Calculating the prime numbers... 82 for (int32 i = 1; i <= UpperLimit; i++) 83 { 84 bool isPrime = true; 85 86 for (int32 j = 2; j <= i / 2; j++) 87 { 88 if (FMath::Fmod(i, j) == 0) 89 { 90 isPrime = false; 91 break; 92 } 93 }
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 protected: // APawn interface virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override; // End of APawn interface public: /** Returns CameraBoom subobject **/ FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; } /** Returns FollowCamera subobject **/ FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; } protected: /*Calculates prime numbers in the game thread*/ UFUNCTION(BlueprintCallable, Category = MultiThreading) void CalculatePrimeNumbers(); /*Calculates prime numbers in a background thread*/ UFUNCTION(BlueprintCallable, Category = MultiThreading) void CalculatePrimeNumbersAsync(); /*The max prime number*/ UPROPERTY(EditAnywhere, Category = MultiThreading) int32 MaxPrime; }; 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; } }
phphy6BeD.docx