FastNoise2Bindings
FastNoise2Bindings copied to clipboard
NativeArray<float> , burst and Jobs
Worth checking as it's the first time I delve into native plugins :
in NativeFastNoise2.cs :
-
my use of void* instead of float* for noiseOut , xPosArray... , mimax necessary because unity's NativeArrayUnsafeUtility.GetUnsafePtr(NativeArray<T>) returns void*
-
my use of address of a float2 &minMax inspired from the indexer in https://github.com/Unity-Technologies/Unity.Mathematics/blob/master/src/Unity.Mathematics/float2.gen.cs
in NativeFastNoise2Test.cs / FastNoiseJobParallelForBatch
-the threadsafety thing, but I think it's fine :
//need to pass the actual subarray to fastnoise, not the whole array!
//which actually guarantees thread safety, fastnoise has no access to the global array.
var subArray = NoiseOut.GetSubArray(startIndex, idxCount);
MinMaxesOut[batchIndex] = GenUniformGrid2D(NodePtr, subArray, xStart, yStart, xCount, yCount, Frequency, Seed);
And btw, congrats and thanks for fastnoise2 and it's node tool, it's awesome !
I've had a quick look through, I think you could set it up in a way that avoids having to duplicate FastNoise2.cs
You could add a GetNodeHandlePtr()
member function to the normal FastNoise2.cs and use that to pass into the job?
It might be easier to chat through this on the FastNoise discord: https://discord.gg/SHVaVfV