Overdrivr / ZNoise

C++ noise algorithms library
Other
36 stars 3 forks source link

API change to allow easy parallelisation #11

Closed Overdrivr closed 8 years ago

Overdrivr commented 8 years ago

The Set() method should disappear. Instead, noises should receive their coordinates like it was originally implemented. Also, the SetScale method should disappear and be re-integrated in the call to Get.

The problem is to keep genericity of the mixers (FBM, HMF). They should be able to pass any number of arguments to noises.

In the end, the goal is to make Get() const. This will allow to parrallelize calls without having to create one noise per thread.

Overdrivr commented 8 years ago

tuples looked like a first option http://www.cplusplus.com/reference/tuple/tie/

But tuples need to have their containing types in their template definition. That means one mixer definition per noise dimension

Overdrivr commented 8 years ago

std::initializer_list is interesting http://en.cppreference.com/w/cpp/utility/initializer_list

It would allow such construct

FBM.Get({1.0, 3.2, 1.4});

Then FBM could pass the std::initializer_list to noise, and then the API could gain enormously in genericity:

Perlin(std::initializer_list coordinates)
{
    switch(coordinates.size()):
        case 2:
            return _Perlin2D(...)
        default:
             // Dimensions non supported
             return 0;
}
Overdrivr commented 8 years ago

Last option is to use << overloading but it forces user to use this syntax simply for expressing coordinates, it's not good enough.

Overdrivr commented 8 years ago

Also, don't forget to use thread_local for improving heap usage http://en.cppreference.com/w/cpp/language/storage_duration