123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "GeneratorRule.h"
- #include "JNoise.h"
- GeneratorRule::GeneratorRule()
- : ReferenceCounter(),
- noiseConfig(0),
- noise(0),
- threshold(0.f),
- condition(0),
- bottomLayer(""),
- topLayer("")
- {}
- GeneratorRule::~GeneratorRule()
- {
- if (noiseConfig) noiseConfig->release();
- if (noise) noise->release();
- if (condition) condition->release();
- }
- void GeneratorRule::initialize(JExpressionMemory* zMemory)
- {
- if (noiseConfig)
- {
- if (noise) noise->release();
- noise = JNoise::parseNoise(noiseConfig, zMemory);
- }
- }
- bool GeneratorRule::checkCondition(
- int x, int y, int z, JExpressionMemory* zMemory)
- {
- if ((topLayer.getLength() && z > zMemory->getFloatVariable(topLayer))
- || (bottomLayer.getLength()
- && z < zMemory->getFloatVariable(bottomLayer)))
- {
- return false;
- }
- return (!condition || condition->getValue(zMemory))
- && (!noise
- || noise->getNoise((double)x, (double)y, (double)z) <= threshold);
- }
- Framework::Either<Block*, int> GeneratorRule::generateBlock(
- int x, int y, int z, int dimensionId)
- {
- return createBlock(x, y, z, dimensionId);
- }
- void GeneratorRule::setNoiseConfig(Framework::JSON::JSONObject* noiseConfig)
- {
- if (this->noiseConfig) this->noiseConfig->release();
- this->noiseConfig = noiseConfig;
- }
- Framework::JSON::JSONObject* GeneratorRule::zNoiseConfig() const
- {
- return noiseConfig;
- }
- void GeneratorRule::setThreshold(float threshold)
- {
- this->threshold = threshold;
- }
- float GeneratorRule::getThreshold() const
- {
- return threshold;
- }
- void GeneratorRule::setCondition(JBoolExpression* condition)
- {
- if (this->condition) this->condition->release();
- this->condition = condition;
- }
- JBoolExpression* GeneratorRule::zCondition() const
- {
- return condition;
- }
- void GeneratorRule::setBottomLayer(Framework::Text bottomLayer)
- {
- this->bottomLayer = bottomLayer;
- }
- Framework::Text GeneratorRule::getBottomLayer() const
- {
- return bottomLayer;
- }
- void GeneratorRule::setTopLayer(Framework::Text topLayer)
- {
- this->topLayer = topLayer;
- }
- Framework::Text GeneratorRule::getTopLayer() const
- {
- return topLayer;
- }
|