Skip to content

Commit

Permalink
C++11 random
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Jan 22, 2017
1 parent 763392c commit 90a5d59
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
24 changes: 10 additions & 14 deletions Source/Util/Random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

namespace Random
{
std::minstd_rand gen;

/*
int integer(int low, int high)
{
return rand() % (high - low + 1) + low;
Expand All @@ -25,28 +27,22 @@ namespace Random
return newNum / multiplier;
}

*/
void setSeed(int seed)
{
srand(seed);
gen.seed(seed);
}

Generator::Generator()
{
m_rng.seed(std::random_device()());
}

void Generator::setSeed(int value)
int integer(int low, int high)
{
m_rng.seed(value);
std::uniform_int_distribution<int> dist(low, high);
return dist(gen);
}

int Generator::get(int low, int high)
double decimal(double low, double high)
{
std::uniform_int_distribution<std::mt19937::result_type> distribution(low, high);
return distribution(m_rng);
std::uniform_real_distribution<double> dist(low, high);
return dist(gen);
}



}
11 changes: 0 additions & 11 deletions Source/Util/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ namespace Random
double decimalD ( double low, double high, int precision = 1 );

void setSeed (int seed);

class Generator
{
public:
Generator();
void setSeed (int value);
int get(int low, int high);

private:
std::mt19937 m_rng;
};
}

#endif
4 changes: 4 additions & 0 deletions Source/World/Chunk/Chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Chunk : public Entity
bool hasMesh () const;
bool hasBuffered () const;

bool needsRegen () const;

void generateMesh ();
void bufferMesh ();

Expand Down Expand Up @@ -86,6 +88,8 @@ class Chunk : public Entity

void resetLight();

Chunk* getAdjacentChunk (int dx, int dz) const;

private:
Chunk_Blocks& getBlocks_nc ();

Expand Down
2 changes: 2 additions & 0 deletions Source/World/Chunk/Chunk_Blocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ void Chunk_Blocks::resetLight()
void Chunk_Blocks::floodNaturalLight(int x, int y, int z, uint8_t value)
{
if (x < 0)
{
return;
}

if (x > World_Constants::CHUNK_SIZE - 1)
return;
Expand Down

0 comments on commit 90a5d59

Please sign in to comment.