GeneratorRule.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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::parseNoise(
  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(
  29. int x, int y, int z, JExpressionMemory* zMemory)
  30. {
  31. return (!noise
  32. || noise->getNoise((double)x, (double)y, (double)z) <= threshold)
  33. && condition->getValue(zMemory);
  34. }
  35. Framework::Either<Block*, int> GeneratorRule::generateBlock(
  36. int x, int y, int z, int dimensionId)
  37. {
  38. return createBlock(x, y, z, dimensionId);
  39. }
  40. GeneratorRuleFactory::GeneratorRuleFactory()
  41. : ReferenceCounter()
  42. {}