1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "GeneratorRule.h"
- #include "JNoise.h"
- GeneratorRule::GeneratorRule(
- Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
- : ReferenceCounter(),
- noise(0)
- {
- if (zConfig->asObject()->hasValue("noise"))
- {
- noise = JNoise::parseNoisse(
- 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(JExpressionMemory* zMemory)
- {
- return condition->getValue(zMemory);
- }
- Framework::Either<Block*, int> GeneratorRule::generateBlock(
- int x, int y, int z, int dimensionId)
- {
- if (!noise || noise->getNoise((double)x, (double)y, (double)z) <= threshold)
- return createBlock(x, y, z, dimensionId);
- return BlockTypeEnum::NO_BLOCK;
- }
- GeneratorRuleFactory::GeneratorRuleFactory()
- : ReferenceCounter()
- {}
|