JsonExpression.h 4.4 KB

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