JsonExpression.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #pragma once
  2. #include <Array.h>
  3. #include <functional>
  4. #include <JSON.h>
  5. #include <Text.h>
  6. #include <Trie.h>
  7. #include "Chunk.h"
  8. #include "Noise.h"
  9. class JExpressionMemory;
  10. class JExpressionMemory : public virtual Framework::ReferenceCounter
  11. {
  12. private:
  13. Framework::RCTrie<Noise> noises;
  14. Framework::Trie<float> floatVariables;
  15. Framework::Trie<bool> boolVariables;
  16. Chunk* currentChunk;
  17. Framework::Critical cs;
  18. public:
  19. JExpressionMemory();
  20. ~JExpressionMemory();
  21. void lock();
  22. void unlock();
  23. float getNoise(Framework::Text name, float x, float y, float z) const;
  24. void setNoise(Framework::Text name, Noise* noise);
  25. void setCurrentChunk(Chunk* chunk);
  26. float getFloatVariable(Framework::Text name) const;
  27. void setFloatVariable(Framework::Text name, float value);
  28. bool getBoolVariable(Framework::Text name) const;
  29. void setBoolVariable(Framework::Text name, bool value);
  30. Chunk* zCurrentChunk();
  31. };
  32. class JFloatExpression : public virtual Framework::ReferenceCounter
  33. {
  34. private:
  35. public:
  36. JFloatExpression();
  37. virtual float getValue(JExpressionMemory* zMemory) = 0;
  38. };
  39. class JBoolExpression : public virtual Framework::ReferenceCounter
  40. {
  41. private:
  42. public:
  43. JBoolExpression();
  44. virtual bool getValue(JExpressionMemory* zMemory) = 0;
  45. };
  46. class JVariableFloatExpression : public JFloatExpression
  47. {
  48. private:
  49. Framework::Text name;
  50. public:
  51. JVariableFloatExpression(Framework::Text name);
  52. float getValue(JExpressionMemory* zMemory) override;
  53. };
  54. class JVariableBoolExpression : public JBoolExpression
  55. {
  56. private:
  57. Framework::Text name;
  58. public:
  59. JVariableBoolExpression(Framework::Text name);
  60. bool getValue(JExpressionMemory* zMemory) override;
  61. };
  62. class JConstantFloatExpression : public JFloatExpression
  63. {
  64. private:
  65. float value;
  66. public:
  67. JConstantFloatExpression(float value);
  68. float getValue(JExpressionMemory* zMemory) override;
  69. };
  70. class JConstantBoolExpression : public JBoolExpression
  71. {
  72. private:
  73. bool value;
  74. public:
  75. JConstantBoolExpression(bool value);
  76. bool getValue(JExpressionMemory* zMemory) override;
  77. };
  78. class JNoiseFloatExpression : public JFloatExpression
  79. {
  80. private:
  81. Framework::Text name;
  82. JFloatExpression* x;
  83. JFloatExpression* y;
  84. JFloatExpression* z;
  85. public:
  86. JNoiseFloatExpression(Framework::Text name,
  87. JFloatExpression* x,
  88. JFloatExpression* y,
  89. JFloatExpression* z);
  90. ~JNoiseFloatExpression();
  91. float getValue(JExpressionMemory* zMemory) override;
  92. };
  93. class JOperatorFloatExpression : public JFloatExpression
  94. {
  95. private:
  96. std::function<float(float a, float b)> accumulator;
  97. Framework::RCArray<JFloatExpression>* values;
  98. public:
  99. JOperatorFloatExpression(std::function<float(float a, float b)> accumulator,
  100. Framework::RCArray<JFloatExpression>* values);
  101. ~JOperatorFloatExpression();
  102. float getValue(JExpressionMemory* zMemory) override;
  103. };
  104. class JBoolOperatorBoolExpression : public JBoolExpression
  105. {
  106. private:
  107. std::function<bool(bool a, bool b)> accumulator;
  108. Framework::RCArray<JBoolExpression>* values;
  109. public:
  110. JBoolOperatorBoolExpression(std::function<bool(bool a, bool b)> accumulator,
  111. Framework::RCArray<JBoolExpression>* values);
  112. ~JBoolOperatorBoolExpression();
  113. bool getValue(JExpressionMemory* zMemory) override;
  114. };
  115. class JFloatOperatorBoolExpression : public JBoolExpression
  116. {
  117. private:
  118. std::function<bool(float a, float b)> accumulator;
  119. Framework::RCArray<JFloatExpression>* values;
  120. public:
  121. JFloatOperatorBoolExpression(
  122. std::function<bool(float a, float b)> accumulator,
  123. Framework::RCArray<JFloatExpression>* values);
  124. ~JFloatOperatorBoolExpression();
  125. bool getValue(JExpressionMemory* zMemory) override;
  126. };
  127. class JBlockTypeBoolExpression : public JBoolExpression
  128. {
  129. private:
  130. int typeId;
  131. JFloatExpression* x;
  132. JFloatExpression* y;
  133. JFloatExpression* z;
  134. public:
  135. JBlockTypeBoolExpression(int typeId,
  136. JFloatExpression* x,
  137. JFloatExpression* y,
  138. JFloatExpression* z);
  139. ~JBlockTypeBoolExpression();
  140. bool getValue(JExpressionMemory* zMemory) override;
  141. };
  142. namespace JExpressionParser
  143. {
  144. JFloatExpression* parseFloatExpression(Framework::JSON::JSONValue* zValue);
  145. Framework::JSON::Validator::JSONValidator* getFloatValidator();
  146. JBoolExpression* parseBoolExpression(Framework::JSON::JSONValue* zValue);
  147. Framework::JSON::Validator::JSONValidator* getBoolValidator();
  148. }; // namespace JExpressionParser