123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "GeneratorRule.h"
- #include "JNoise.h"
- GeneratorRule::GeneratorRule(
- Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
- : ReferenceCounter(),
- noise(0)
- {
- if (zConfig->asObject()->hasValue("noise"))
- {
- noise = JNoise::parseNoise(
- zConfig->asObject()->zValue("noise"), zMemory);
- }
- condition = JExpressionParser::parseBoolExpression(
- zConfig->asObject()->zValue("condition"));
- if (zConfig->asObject()->hasValue("threshold"))
- {
- threshold = (float)zConfig->asObject()
- ->zValue("threshold")
- ->asNumber()
- ->getNumber();
- }
- }
- GeneratorRule::~GeneratorRule()
- {
- if (noise) noise->release();
- if (condition) condition->release();
- }
- 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);
- }
- GeneratorRuleFactory::GeneratorRuleFactory()
- : ReferenceCounter()
- {}
|