12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "GeneratorRule.h"
- #include "JNoise.h"
- GeneratorRule::GeneratorRule()
- : ReferenceCounter(),
- noiseConfig(0),
- noise(0),
- threshold(0.f),
- condition(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);
- }
- }
- bool GeneratorRule::checkCondition(
- int x, int y, int z, JExpressionMemory* zMemory)
- {
- return (!noise
- || noise->getNoise((double)x, (double)y, (double)z) <= threshold)
- && condition->getValue(zMemory);
- }
- 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;
- }
|