forked from Reputeless/PerlinNoise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support user-defined random number generator
- Loading branch information
1 parent
158ad52
commit 508246b
Showing
1 changed file
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
// siv::PerlinNoise | ||
// Perlin noise library for modern C++ | ||
// | ||
// Copyright (C) 2013-2016 Ryo Suzuki <[email protected]> | ||
// Copyright (C) 2013-2018 Ryo Suzuki <[email protected]> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files(the "Software"), to deal | ||
|
@@ -64,6 +64,12 @@ namespace siv | |
reseed(seed); | ||
} | ||
|
||
template <class URNG> | ||
explicit PerlinNoise(URNG& urng) | ||
{ | ||
reseed(urng); | ||
} | ||
|
||
void reseed(std::uint32_t seed) | ||
{ | ||
for (size_t i = 0; i < 256; ++i) | ||
|
@@ -79,6 +85,22 @@ namespace siv | |
} | ||
} | ||
|
||
template <class URNG> | ||
void reseed(URNG& urng) | ||
{ | ||
for (size_t i = 0; i < 256; ++i) | ||
{ | ||
p[i] = i; | ||
} | ||
|
||
std::shuffle(std::begin(p), std::begin(p) + 256, urng); | ||
|
||
for (size_t i = 0; i < 256; ++i) | ||
{ | ||
p[256 + i] = p[i]; | ||
} | ||
} | ||
|
||
double noise(double x) const | ||
{ | ||
return noise(x, 0.0, 0.0); | ||
|