GeneratorRule.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "GeneratorRule.h"
  2. #include "JNoise.h"
  3. GeneratorRule::GeneratorRule()
  4. : ReferenceCounter(),
  5. noiseConfig(0),
  6. noise(0),
  7. threshold(0.f),
  8. condition(0)
  9. {}
  10. GeneratorRule::~GeneratorRule()
  11. {
  12. if (noiseConfig) noiseConfig->release();
  13. if (noise) noise->release();
  14. if (condition) condition->release();
  15. }
  16. void GeneratorRule::initialize(JExpressionMemory* zMemory)
  17. {
  18. if (noiseConfig)
  19. {
  20. if (noise) noise->release();
  21. noise = JNoise::parseNoise(noiseConfig, zMemory);
  22. }
  23. }
  24. bool GeneratorRule::checkCondition(
  25. int x, int y, int z, JExpressionMemory* zMemory)
  26. {
  27. return (!noise
  28. || noise->getNoise((double)x, (double)y, (double)z) <= threshold)
  29. && condition->getValue(zMemory);
  30. }
  31. Framework::Either<Block*, int> GeneratorRule::generateBlock(
  32. int x, int y, int z, int dimensionId)
  33. {
  34. return createBlock(x, y, z, dimensionId);
  35. }
  36. void GeneratorRule::setNoiseConfig(Framework::JSON::JSONObject* noiseConfig) {
  37. if (this->noiseConfig) this->noiseConfig->release();
  38. this->noiseConfig = noiseConfig;
  39. }
  40. Framework::JSON::JSONObject* GeneratorRule::zNoiseConfig() const
  41. {
  42. return noiseConfig;
  43. }
  44. void GeneratorRule::setThreshold(float threshold) {
  45. this->threshold = threshold;
  46. }
  47. float GeneratorRule::getThreshold() const
  48. {
  49. return threshold;
  50. }
  51. void GeneratorRule::setCondition(JBoolExpression* condition) {
  52. if (this->condition) this->condition->release();
  53. this->condition = condition;
  54. }
  55. JBoolExpression* GeneratorRule::zCondition() const
  56. {
  57. return condition;
  58. }