mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-06-30 21:36:33 -04:00
--User changes
-Improve performance in the following variations: cpow2, dc_cube, julia3d, julia3dz, julian2, log_db, nblur, npolar, waffle, wavesn, xtrb. --Code changes -Rand range now uses multiply + shift rather than modulo.
This commit is contained in:
@ -1078,11 +1078,11 @@ public:
|
||||
};
|
||||
|
||||
if (rand.Rand() & 1)
|
||||
sym = symDistrib[rand.Rand() % Vlen(symDistrib)];
|
||||
sym = symDistrib[rand.Rand(Vlen(symDistrib))];
|
||||
else if (rand.Rand() & 31)
|
||||
sym = intmax_t(rand.Rand() % 13) - 6;
|
||||
sym = intmax_t(rand.Rand(13)) - 6;
|
||||
else
|
||||
sym = intmax_t(rand.Rand() % 51) - 25;
|
||||
sym = intmax_t(rand.Rand(51)) - 25;
|
||||
}
|
||||
|
||||
if (sym == 1 || sym == 0)
|
||||
|
@ -148,9 +148,9 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="upper">A value one greater than the maximum value that will be returned</param>
|
||||
/// <returns>A value between 0 and the value passed in minus 1</returns>
|
||||
inline T Rand(T upper)
|
||||
inline T Rand(size_t upper)
|
||||
{
|
||||
return (upper == 0) ? Rand() : Rand() % upper;
|
||||
return (upper == 0) ? Rand() : T(((size_t)Rand() * upper) >> 32);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -158,7 +158,7 @@ public:
|
||||
/// </summary>
|
||||
/// <param name="upper">A value one greater than the maximum value that will be returned</param>
|
||||
/// <returns>A value between 0 and the value passed in minus 1</returns>
|
||||
static inline T LockedRand(T upper)
|
||||
static inline T LockedRand(size_t upper)
|
||||
{
|
||||
rlg l(*s_CS.get());
|
||||
T t = GlobalRand->Rand(upper);
|
||||
@ -420,14 +420,14 @@ protected:
|
||||
{
|
||||
#ifndef __ISAAC64
|
||||
RngStep((a << 13), a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a >> 6) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a << 2) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a >> 6), a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a << 2), a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a >> 16), a, b, mm, m, m2, r, x, y);
|
||||
#else // __ISAAC64
|
||||
RngStep(~(a ^ (a << 21)), a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 5) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a << 12) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 33) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 5), a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a << 12), a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 33), a, b, mm, m, m2, r, x, y);
|
||||
#endif // __ISAAC64
|
||||
}
|
||||
|
||||
@ -437,14 +437,14 @@ protected:
|
||||
{
|
||||
#ifndef __ISAAC64
|
||||
RngStep((a << 13), a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a >> 6) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a << 2) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a >> 6), a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a << 2), a, b, mm, m, m2, r, x, y);
|
||||
RngStep((a >> 16), a, b, mm, m, m2, r, x, y);
|
||||
#else // __ISAAC64
|
||||
RngStep(~(a ^ (a << 21)), a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 5) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a << 12) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 33) , a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 5), a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a << 12), a, b, mm, m, m2, r, x, y);
|
||||
RngStep( a ^ (a >> 33), a, b, mm, m, m2, r, x, y);
|
||||
#endif // __ISAAC64
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ Palette<T>* PaletteList<T>::GetRandomPalette()
|
||||
while (attempts < Size() * 10)
|
||||
{
|
||||
auto p = s_Palettes.begin();
|
||||
auto paletteFileIndex = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand() % Size();
|
||||
auto paletteFileIndex = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(Size());
|
||||
size_t i = 0;
|
||||
|
||||
//Move p forward i elements.
|
||||
@ -281,7 +281,7 @@ Palette<T>* PaletteList<T>::GetRandomPalette()
|
||||
|
||||
if (i < Size())
|
||||
{
|
||||
size_t paletteIndex = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand() % p->second.size();
|
||||
size_t paletteIndex = QTIsaac<ISAAC_SIZE, ISAAC_INT>::LockedRand(p->second.size());
|
||||
|
||||
if (paletteIndex < p->second.size() && !p->second[paletteIndex].IsEmpty())
|
||||
return &p->second[paletteIndex];
|
||||
|
@ -254,7 +254,7 @@ public:
|
||||
//Generate a 2-xform random.
|
||||
Random(mutation, useVars, sym, 2, maxVars);
|
||||
//Which xform to mutate?
|
||||
modXform = m_Rand.Rand() % ember.TotalXformCount();
|
||||
modXform = m_Rand.Rand(ember.TotalXformCount());
|
||||
auto xform1 = ember.GetTotalXform(modXform);
|
||||
auto xform2 = mutation.GetTotalXform(0);
|
||||
os << "mutate xform " << modXform << " coefs";
|
||||
@ -280,7 +280,7 @@ public:
|
||||
else if (mode == eMutateMode::MUTATE_POST_XFORMS)
|
||||
{
|
||||
bool same = (m_Rand.Rand() & 3) > 0;//25% chance of using the same post for all of them.
|
||||
size_t b = 1 + m_Rand.Rand() % 6;
|
||||
size_t b = 1 + m_Rand.Rand(6);
|
||||
os << "mutate post xforms " << b << (same ? " same" : "");
|
||||
|
||||
for (size_t i = 0; i < ember.TotalXformCount(); i++)
|
||||
@ -387,7 +387,7 @@ public:
|
||||
}
|
||||
else if (mode == eMutateMode::MUTATE_DELETE_XFORM)
|
||||
{
|
||||
size_t nx = m_Rand.Rand() % ember.TotalXformCount();
|
||||
size_t nx = m_Rand.Rand(ember.TotalXformCount());
|
||||
os << "mutate delete xform " << nx;
|
||||
|
||||
if (ember.TotalXformCount() > 1)
|
||||
@ -626,7 +626,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
ember.AddXforms(xformDistrib[m_Rand.Rand() % Vlen(xformDistrib)]);
|
||||
ember.AddXforms(xformDistrib[m_Rand.Rand(Vlen(xformDistrib))]);
|
||||
addfinal = m_Rand.Frand01<T>() < T(0.15);//Add a final xform 15% of the time.
|
||||
|
||||
if (addfinal)
|
||||
@ -639,7 +639,7 @@ public:
|
||||
|
||||
//If useVars is empty, randomly choose one to use or decide to use multiple.
|
||||
if (useVars.empty())
|
||||
var = m_Rand.RandBit() ? m_Rand.Rand() % varCount : -1;
|
||||
var = m_Rand.RandBit() ? m_Rand.Rand(varCount) : -1;
|
||||
else
|
||||
var = -2;
|
||||
|
||||
@ -689,7 +689,7 @@ public:
|
||||
else if (multid && var == -1)
|
||||
{
|
||||
if (xform->TotalVariationCount() < maxVars)
|
||||
xform->AddVariation(m_VariationList->GetVariation(m_Rand.Rand() % varCount)->Copy());//Choose a random var for this xform.
|
||||
xform->AddVariation(m_VariationList->GetVariation(m_Rand.Rand(varCount))->Copy());//Choose a random var for this xform.
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -722,7 +722,7 @@ public:
|
||||
if (var != -2)
|
||||
{
|
||||
//Pick a random variation and use a random weight from 0-1.
|
||||
Variation<T>* v = m_VariationList->GetVariationCopy(static_cast<size_t>(m_Rand.Rand() % varCount), m_Rand.Frand<T>(T(0.001), 1));
|
||||
Variation<T>* v = m_VariationList->GetVariationCopy(static_cast<size_t>(m_Rand.Rand(varCount)), m_Rand.Frand<T>(T(0.001), 1));
|
||||
|
||||
if (v && !xform->AddVariation(v))
|
||||
delete v;//It already existed and therefore was not added.
|
||||
@ -730,7 +730,7 @@ public:
|
||||
else
|
||||
{
|
||||
//Pick a random variation from the suppled IDs and use a random weight from 0-1.
|
||||
Variation<T>* v = m_VariationList->GetVariationCopy(useVars[m_Rand.Rand() % useVars.size()], m_Rand.Frand<T>(T(0.001), 1));
|
||||
Variation<T>* v = m_VariationList->GetVariationCopy(useVars[m_Rand.Rand(useVars.size())], m_Rand.Frand<T>(T(0.001), 1));
|
||||
|
||||
if (v && !xform->AddVariation(v))
|
||||
delete v;
|
||||
@ -760,12 +760,12 @@ public:
|
||||
if (var != -2)
|
||||
{
|
||||
//Pick a random variation and use a random weight from 0-1.
|
||||
xform->AddVariation(m_VariationList->GetVariationCopy(static_cast<size_t>(m_Rand.Rand() % varCount), m_Rand.Frand<T>(T(0.001), 1)));
|
||||
xform->AddVariation(m_VariationList->GetVariationCopy(static_cast<size_t>(m_Rand.Rand(varCount)), m_Rand.Frand<T>(T(0.001), 1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
//Pick a random variation from the suppled IDs and use a random weight from 0-1.
|
||||
xform->AddVariation(m_VariationList->GetVariationCopy(useVars[m_Rand.Rand() % useVars.size()], m_Rand.Frand<T>(T(0.001), 1)));
|
||||
xform->AddVariation(m_VariationList->GetVariationCopy(useVars[m_Rand.Rand(useVars.size())], m_Rand.Frand<T>(T(0.001), 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -779,7 +779,7 @@ public:
|
||||
}
|
||||
|
||||
//Randomly add symmetry (but not if we've already added a final xform).
|
||||
if (sym || (!(m_Rand.Rand() % 4) && !addfinal))
|
||||
if (sym || (!(m_Rand.Rand(4)) && !addfinal))
|
||||
ember.AddSymmetry(sym, m_Rand);
|
||||
else
|
||||
ember.m_Symmetry = 0;
|
||||
@ -932,7 +932,7 @@ public:
|
||||
|
||||
while (ntries++ < 100)
|
||||
{
|
||||
size_t i = m_Rand.Rand() % ember.TotalXformCount();
|
||||
size_t i = m_Rand.Rand(ember.TotalXformCount());
|
||||
|
||||
if (i != excluded)
|
||||
{
|
||||
|
@ -1777,7 +1777,7 @@ public:
|
||||
T temp = (helper.m_PrecalcAtanyx + M_2PI * rand.Rand(uint(m_AbsN))) / m_N;
|
||||
helper.Out.x = r * std::cos(temp);
|
||||
helper.Out.y = r * std::sin(temp);
|
||||
helper.Out.z = r * helper.In.z / (helper.m_PrecalcSqrtSumSquares * m_AbsN);
|
||||
helper.Out.z = r * helper.In.z / Zeps(helper.m_PrecalcSqrtSumSquares * m_AbsN);
|
||||
}
|
||||
|
||||
virtual string OpenCLString() const override
|
||||
@ -1796,11 +1796,16 @@ public:
|
||||
<< "\n"
|
||||
<< "\t\tvOut.x = r * cos(temp);\n"
|
||||
<< "\t\tvOut.y = r * sin(temp);\n"
|
||||
<< "\t\tvOut.z = r * vIn.z / (precalcSqrtSumSquares * " << absn << ");\n"
|
||||
<< "\t\tvOut.z = r * vIn.z / Zeps(precalcSqrtSumSquares * " << absn << ");\n"
|
||||
<< "\t}\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
virtual vector<string> OpenCLGlobalFuncNames() const override
|
||||
{
|
||||
return vector<string> { "Zeps" };
|
||||
}
|
||||
|
||||
virtual void Precalc() override
|
||||
{
|
||||
m_AbsN = std::abs(m_N);
|
||||
|
@ -859,7 +859,7 @@ private:
|
||||
if (params.ExactCalc == 1)
|
||||
angXY = rand.Frand01<T>() * M_2PI;
|
||||
else
|
||||
angXY = (std::atan(params.ArcTan1 * (rand.Frand01<T>() - T(0.5))) / params.ArcTan2 + T(0.5) + T(rand.Rand() % glm::uint(params.NumEdges))) * params.MidAngle;
|
||||
angXY = (std::atan(params.ArcTan1 * (rand.Frand01<T>() - T(0.5))) / params.ArcTan2 + T(0.5) + T(rand.Rand(glm::uint(params.NumEdges)))) * params.MidAngle;
|
||||
|
||||
sincos(angXY, ¶ms.X, ¶ms.Y);
|
||||
angMem = angXY;
|
||||
|
Reference in New Issue
Block a user