123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- #pragma once
- #include <Array.h>
- #include <Critical.h>
- #include <functional>
- #include <JSON.h>
- #include <Text.h>
- #include <Trie.h>
- #include "Noise.h"
- #include "TypeRegistry.h"
- class Chunk;
- class JExpressionMemory;
- class JExpressionMemory : public virtual Framework::ReferenceCounter
- {
- private:
- Framework::RCTrie<Noise> noises;
- Framework::Trie<float> floatVariables;
- Framework::Trie<bool> boolVariables;
- Chunk* currentChunk;
- Framework::Critical cs;
- public:
- JExpressionMemory();
- ~JExpressionMemory();
- void lock();
- void unlock();
- float getNoise(Framework::Text name, float x, float y, float z) const;
- void setNoise(Framework::Text name, Noise* noise);
- void setCurrentChunk(Chunk* chunk);
- float getFloatVariable(Framework::Text name) const;
- void setFloatVariable(Framework::Text name, float value);
- bool getBoolVariable(Framework::Text name) const;
- void setBoolVariable(Framework::Text name, bool value);
- Chunk* zCurrentChunk();
- };
- class JFloatExpression : public virtual Framework::ReferenceCounter
- {
- private:
- public:
- JFloatExpression();
- virtual float getValue(JExpressionMemory* zMemory) = 0;
- };
- class JBoolExpression : public virtual Framework::ReferenceCounter
- {
- private:
- public:
- JBoolExpression();
- virtual bool getValue(JExpressionMemory* zMemory) = 0;
- };
- class JVariableFloatExpression : public JFloatExpression
- {
- private:
- Framework::Text name;
- public:
- JVariableFloatExpression();
- float getValue(JExpressionMemory* zMemory) override;
- void setName(Framework::Text name);
- Framework::Text getName() const;
- };
- class JVariableFloatExpressionFactory
- : public SubTypeFactory<JFloatExpression, JVariableFloatExpression>
- {
- public:
- JVariableFloatExpressionFactory();
- JVariableFloatExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JVariableFloatExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JVariableFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JVariableBoolExpression : public JBoolExpression
- {
- private:
- Framework::Text name;
- public:
- JVariableBoolExpression();
- bool getValue(JExpressionMemory* zMemory) override;
- void setName(Framework::Text name);
- Framework::Text getName() const;
- };
- class JVariableBoolExpressionFactory
- : public SubTypeFactory<JBoolExpression, JVariableBoolExpression>
- {
- public:
- JVariableBoolExpressionFactory();
- JVariableBoolExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JVariableBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JVariableBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JConstantFloatExpression : public JFloatExpression
- {
- private:
- float value;
- public:
- JConstantFloatExpression();
- float getValue(JExpressionMemory* zMemory) override;
- void setValue(float value);
- float getValue() const;
- };
- class JConstantFloatExpressionFactory
- : public SubTypeFactory<JFloatExpression, JConstantFloatExpression>
- {
- public:
- JConstantFloatExpressionFactory();
- JConstantFloatExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JConstantFloatExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JConstantFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JConstantBoolExpression : public JBoolExpression
- {
- private:
- bool value;
- public:
- JConstantBoolExpression();
- bool getValue(JExpressionMemory* zMemory) override;
- void setValue(bool value);
- bool getValue() const;
- };
- class JConstantBoolExpressionFactory
- : public SubTypeFactory<JBoolExpression, JConstantBoolExpression>
- {
- public:
- JConstantBoolExpressionFactory();
- JConstantBoolExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JConstantBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JConstantBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JNoiseFloatExpression : public JFloatExpression
- {
- private:
- Framework::Text name;
- JFloatExpression* x;
- JFloatExpression* y;
- JFloatExpression* z;
- public:
- JNoiseFloatExpression();
- ~JNoiseFloatExpression();
- float getValue(JExpressionMemory* zMemory) override;
- void setName(Framework::Text name);
- Framework::Text getName() const;
- void setX(JFloatExpression* x);
- JFloatExpression* zX() const;
- void setY(JFloatExpression* y);
- JFloatExpression* zY() const;
- void setZ(JFloatExpression* z);
- JFloatExpression* zZ() const;
- };
- class JNoiseFloatExpressionFactory
- : public SubTypeFactory<JFloatExpression, JNoiseFloatExpression>
- {
- public:
- JNoiseFloatExpressionFactory();
- JNoiseFloatExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JNoiseFloatExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JNoiseFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JOperatorFloatExpression : public JFloatExpression
- {
- private:
- Framework::Text op;
- std::function<float(float a, float b)> accumulator;
- Framework::RCArray<JFloatExpression> values;
- public:
- JOperatorFloatExpression();
- float getValue(JExpressionMemory* zMemory) override;
- void setOperator(
- Framework::Text op, std::function<float(float a, float b)> accumulator);
- Framework::Text getOperator();
- void addValue(JFloatExpression* value);
- const Framework::RCArray<JFloatExpression>& getValues() const;
- };
- class JOperatorFloatExpressionFactory
- : public SubTypeFactory<JFloatExpression, JOperatorFloatExpression>
- {
- public:
- JOperatorFloatExpressionFactory();
- JOperatorFloatExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JOperatorFloatExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JOperatorFloatExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JBoolOperatorBoolExpression : public JBoolExpression
- {
- private:
- Framework::Text op;
- std::function<bool(bool a, bool b)> accumulator;
- Framework::RCArray<JBoolExpression> values;
- public:
- JBoolOperatorBoolExpression();
- bool getValue(JExpressionMemory* zMemory) override;
- void setOperator(
- Framework::Text op, std::function<float(float a, float b)> accumulator);
- Framework::Text getOperator();
- void addValue(JBoolExpression* value);
- const Framework::RCArray<JBoolExpression>& getValues() const;
- };
- class JBoolOperatorBoolExpressionFactory
- : public SubTypeFactory<JBoolExpression, JBoolOperatorBoolExpression>
- {
- public:
- JBoolOperatorBoolExpressionFactory();
- JBoolOperatorBoolExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JBoolOperatorBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JBoolOperatorBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JFloatOperatorBoolExpression : public JBoolExpression
- {
- private:
- Framework::Text op;
- std::function<bool(float a, float b)> accumulator;
- Framework::RCArray<JFloatExpression> values;
- public:
- JFloatOperatorBoolExpression();
- bool getValue(JExpressionMemory* zMemory) override;
- void setOperator(
- Framework::Text op, std::function<bool(float a, float b)> accumulator);
- Framework::Text getOperator();
- void addValue(JFloatExpression* value);
- const Framework::RCArray<JFloatExpression>& getValues() const;
- };
- class JFloatOperatorBoolExpressionFactory
- : public SubTypeFactory<JBoolExpression, JFloatOperatorBoolExpression>
- {
- public:
- JFloatOperatorBoolExpressionFactory();
- JFloatOperatorBoolExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JFloatOperatorBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JFloatOperatorBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
- class JBlockTypeBoolExpression : public JBoolExpression
- {
- private:
- int typeId;
- JFloatExpression* x;
- JFloatExpression* y;
- JFloatExpression* z;
- public:
- JBlockTypeBoolExpression();
- ~JBlockTypeBoolExpression();
- bool getValue(JExpressionMemory* zMemory) override;
- void setTypeId(int typeId);
- int getTypeId() const;
- void setX(JFloatExpression* x);
- JFloatExpression* zX() const;
- void setY(JFloatExpression* y);
- JFloatExpression* zY() const;
- void setZ(JFloatExpression* z);
- JFloatExpression* zZ() const;
- };
- class JBlockTypeBoolExpressionFactory
- : public SubTypeFactory<JBoolExpression, JBlockTypeBoolExpression>
- {
- public:
- JBlockTypeBoolExpressionFactory();
- JBlockTypeBoolExpression* createValue(
- Framework::JSON::JSONObject* zJson) const override;
- void fromJson(JBlockTypeBoolExpression* zResult,
- Framework::JSON::JSONObject* zJson) const override;
- void toJson(JBlockTypeBoolExpression* zObject,
- Framework::JSON::JSONObject* zResult) const override;
- JSONObjectValidationBuilder* addToValidator(
- JSONObjectValidationBuilder* builder) const override;
- Framework::Text getTypeToken() const override;
- };
|