2013-12-31 14:50:28 +00:00
|
|
|
#include "NoiseState.h"
|
|
|
|
|
|
|
|
#include "PackStream.h"
|
|
|
|
#include "RandomGenerator.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
NoiseState::NoiseState() {
|
|
|
|
for (int i = 0; i < 30; i++) {
|
2013-12-31 14:50:28 +00:00
|
|
|
level_offsets.push_back(NoiseOffset());
|
|
|
|
}
|
|
|
|
randomizeOffsets();
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void NoiseState::save(PackStream *stream) const {
|
2013-12-31 14:50:28 +00:00
|
|
|
int levels = level_offsets.size();
|
|
|
|
stream->write(&levels);
|
2015-11-09 21:30:46 +00:00
|
|
|
for (const auto &level_offset : level_offsets) {
|
2013-12-31 14:50:28 +00:00
|
|
|
stream->write(&level_offset.x);
|
|
|
|
stream->write(&level_offset.y);
|
|
|
|
stream->write(&level_offset.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void NoiseState::load(PackStream *stream) {
|
2013-12-31 14:50:28 +00:00
|
|
|
int levels;
|
|
|
|
stream->read(&levels);
|
|
|
|
level_offsets.clear();
|
2015-08-13 17:49:16 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
if (levels > 1000) {
|
2015-08-13 17:49:16 +00:00
|
|
|
levels = 1000;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
for (int i = 0; i < levels; i++) {
|
2013-12-31 14:50:28 +00:00
|
|
|
NoiseOffset level_offset;
|
|
|
|
stream->read(&level_offset.x);
|
|
|
|
stream->read(&level_offset.y);
|
|
|
|
stream->read(&level_offset.z);
|
|
|
|
level_offsets.push_back(level_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void NoiseState::copy(NoiseState *destination) const {
|
2013-12-31 14:50:28 +00:00
|
|
|
destination->level_offsets = level_offsets;
|
|
|
|
}
|
|
|
|
|
2015-12-10 18:40:39 +00:00
|
|
|
void NoiseState::randomizeOffsets(RandomGenerator &random) {
|
2015-11-09 21:30:46 +00:00
|
|
|
for (auto &level_offset : level_offsets) {
|
2015-12-10 18:40:39 +00:00
|
|
|
level_offset.x = random.genDouble();
|
|
|
|
level_offset.y = random.genDouble();
|
|
|
|
level_offset.z = random.genDouble();
|
2013-12-31 14:50:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-31 14:56:30 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void NoiseState::resetOffsets(double x, double y, double z) {
|
|
|
|
for (auto &level_offset : level_offsets) {
|
2013-12-31 14:56:30 +00:00
|
|
|
level_offset.x = x;
|
|
|
|
level_offset.y = y;
|
|
|
|
level_offset.z = z;
|
|
|
|
}
|
|
|
|
}
|
2014-01-01 17:21:34 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void NoiseState::setLevel(int level, double x, double y, double z) {
|
2014-01-01 17:21:34 +00:00
|
|
|
NoiseOffset offset = {x, y, z};
|
|
|
|
level_offsets.at(level) = offset;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void NoiseState::setLevelCount(int level_count) {
|
2014-01-01 17:21:34 +00:00
|
|
|
level_offsets.resize(level_count);
|
|
|
|
}
|