mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-30 12:00:30 +01:00
perf(physics): the steps of the vehicle physics on many threads, in groups of vehicles which act on one another (performance.cpucores, 0: all cores)
This commit is contained in:
@@ -125,18 +125,33 @@ bool ClearFlag(int &Flag, int const Value)
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
thread_local std::mt19937 *t_random_engine{nullptr};
|
||||
|
||||
std::mt19937 &random_engine()
|
||||
{
|
||||
return t_random_engine != nullptr ? *t_random_engine : Global.random_engine;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void set_thread_random_engine(std::mt19937 *Engine)
|
||||
{
|
||||
t_random_engine = Engine;
|
||||
}
|
||||
|
||||
double Random(double min, double max)
|
||||
{
|
||||
if (max < min) { std::swap(min, max); } // std::uniform_real_distribution requires min <= max (inverted bounds are UB)
|
||||
std::uniform_real_distribution dist(min, max);
|
||||
return dist(Global.random_engine);
|
||||
return dist(random_engine());
|
||||
}
|
||||
|
||||
int Random(int min, int max)
|
||||
{
|
||||
if (max < min) { std::swap(min, max); } // std::uniform_int_distribution requires min <= max (inverted bounds are UB)
|
||||
std::uniform_int_distribution dist(min, max);
|
||||
return dist(Global.random_engine);
|
||||
return dist(random_engine());
|
||||
}
|
||||
|
||||
std::uint64_t true_random_seed()
|
||||
|
||||
Reference in New Issue
Block a user