GeneratorRule.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "GeneratorRule.h"
  2. #include "JNoise.h"
  3. GeneratorRule::GeneratorRule(
  4. Framework::JSON::JSONValue* zConfig, JExpressionMemory* zMemory)
  5. : ReferenceCounter(),
  6. noise(0)
  7. {
  8. if (zConfig->asObject()->hasValue("noise"))
  9. {
  10. noise = JNoise::parseNoisse(
  11. zConfig->asObject()->zValue("noise"), zMemory);
  12. }
  13. condition = JExpressionParser::parseBoolExpression(
  14. zConfig->asObject()->zValue("condition"));
  15. if (zConfig->asObject()->hasValue("threshold"))
  16. {
  17. threshold = (float)zConfig->asObject()
  18. ->zValue("threshold")
  19. ->asNumber()
  20. ->getNumber();
  21. }
  22. }
  23. GeneratorRule::~GeneratorRule()
  24. {
  25. if (noise) noise->release();
  26. if (condition) condition->release();
  27. }
  28. bool GeneratorRule::checkCondition(JExpressionMemory* zMemory)
  29. {
  30. return condition->getValue(zMemory);
  31. }
  32. Framework::Either<Block*, int> GeneratorRule::generateBlock(
  33. int x, int y, int z, int dimensionId)
  34. {
  35. if (!noise || noise->getNoise((double)x, (double)y, (double)z) <= threshold)
  36. return createBlock(x, y, z, dimensionId);
  37. return BlockTypeEnum::NO_BLOCK;
  38. }
  39. GeneratorRuleFactory::GeneratorRuleFactory()
  40. : ReferenceCounter()
  41. {}