#include "GeneratorRule.h" #include "JNoise.h" GeneratorRule::GeneratorRule() : ReferenceCounter(), noiseConfig(0), noise(0), threshold(0.f), condition(0), bottomLayer(""), topLayer(""), topLayerF(0), botomLayerF(0) {} 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); } if (topLayer.getLength()) { topLayerF = zMemory->getFloatVariableP(topLayer); } if (bottomLayer.getLength()) { botomLayerF = zMemory->getFloatVariableP(bottomLayer); } if (condition) { condition->compile(zMemory); } } bool GeneratorRule::checkCondition(int x, int y, int z) { if ((topLayerF && z > *topLayerF) || (botomLayerF && z < *botomLayerF)) { return false; } return (!condition || condition->getValue()) && (!noise || noise->getNoise((double)x, (double)y, (double)z) <= threshold); } Framework::Either 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; }