/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/CodeUtils/Expression/ExpressionDeclarations.h
174 строки
6 KB
C-Core
Fixed crash when recreating decal atlas after profile change (#1886)
30 мар 2026, 22:36
Не верифицирован
30 мар 2026, 22:36
f9e84e0
Код
Авторство
О чём код?
#pragma once #include <Foundation/Containers/HashTable.h> #include <Foundation/Containers/SmallArray.h> #include <Foundation/DataProcessing/Stream/ProcessingStream.h> #include <Foundation/Math/Color8UNorm.h> #include <Foundation/Math/ColorScheme.h> #include <Foundation/Reflection/Reflection.h> #include <Foundation/SimdMath/SimdVec4f.h> #include <Foundation/SimdMath/SimdVec4i.h> #include <Foundation/Types/Variant.h> class ezStreamWriter; class ezStreamReader; namespace ezExpression { struct Register { EZ_DECLARE_POD_TYPE(); Register(){}; // NOLINT: using = default doesn't work here. union { ezSimdVec4b b; ezSimdVec4i i; ezSimdVec4f f; }; }; struct RegisterType { using StorageType = ezUInt8; enum Enum { Unknown, Bool, Int, Float, Count, Default = Float, MaxNumBits = 4, }; static const char* GetName(Enum registerType); }; using Output = ezArrayPtr<Register>; using Inputs = ezArrayPtr<ezArrayPtr<const Register>>; // Inputs are in SOA form, means inner array contains all values for one input parameter, one for each instance. using GlobalData = ezHashTable<ezHashedString, ezVariant>; /// \brief Describes an input or output stream for a expression VM struct StreamDesc { ezHashedString m_sName; ezProcessingStream::DataType m_DataType; StreamDesc() = default; StreamDesc(const ezHashedString sName, ezProcessingStream::DataType dataType) : m_sName(sName) , m_DataType(dataType) { } bool operator==(const StreamDesc& other) const { return m_sName == other.m_sName && m_DataType == other.m_DataType; } ezResult Serialize(ezStreamWriter& inout_stream) const; ezResult Deserialize(ezStreamReader& inout_stream); }; /// \brief Describes an expression function and its signature, e.g. how many input parameter it has and their type struct FunctionDesc { using TypeList = ezSmallArray<ezEnum<ezExpression::RegisterType>, 8, ezStaticsAllocatorWrapper>; ezHashedString m_sName; TypeList m_InputTypes; ezUInt8 m_uiNumRequiredInputs = 0; ezEnum<ezExpression::RegisterType> m_OutputType; bool operator==(const FunctionDesc& other) const { return m_sName == other.m_sName && m_InputTypes == other.m_InputTypes && m_uiNumRequiredInputs == other.m_uiNumRequiredInputs && m_OutputType == other.m_OutputType; } bool operator<(const FunctionDesc& other) const; ezResult Serialize(ezStreamWriter& inout_stream) const; ezResult Deserialize(ezStreamReader& inout_stream); ezHashedString GetMangledName() const; }; using Function = void (*)(ezExpression::Inputs, ezExpression::Output, const ezExpression::GlobalData&); using ValidateGlobalDataFunction = ezResult (*)(const ezExpression::GlobalData&); } // namespace ezExpression /// \brief Describes an external function that can be called in expressions. /// These functions need to be state-less and thread-safe. struct ezExpressionFunction { ezExpression::FunctionDesc m_Desc; ezExpression::Function m_Func; // Optional validation function used to validate required global data for an expression function ezExpression::ValidateGlobalDataFunction m_ValidateGlobalDataFunc; }; /// \brief Contains the default expression functions that are always available in the expression system. struct EZ_FOUNDATION_DLL ezDefaultExpressionFunctions { static ezExpressionFunction s_RandomFunc; static ezExpressionFunction s_PerlinNoiseFunc; }; /// \brief Contains extended expression functions that need to be registered explicitly with the expression VM. struct EZ_FOUNDATION_DLL ezExtendedExpressionFunctions { static ezExpressionFunction s_SampleCurveFunc; }; /// \brief Add this attribute a string property that should be interpreted as expression source. /// /// The Inputs/Outputs property reference another array property on the same object that contains objects /// with a name and a type property that can be used for real time error checking of the expression source. /// /// Optionally, a semicolon-separated list of custom keywords can be provided. These are highlighted in the /// expression editor with a dedicated color, distinct from built-in types and functions. class EZ_FOUNDATION_DLL ezExpressionWidgetAttribute : public ezTypeWidgetAttribute { EZ_ADD_DYNAMIC_REFLECTION(ezExpressionWidgetAttribute, ezTypeWidgetAttribute); public: ezExpressionWidgetAttribute() = default; ezExpressionWidgetAttribute(const char* szInputsProperty, const char* szOutputsProperty) : m_sInputsProperty(szInputsProperty) , m_sOutputsProperty(szOutputsProperty) { } /// \param szCustomKeywords Semicolon-separated list of identifiers to highlight as a custom keyword group. /// \param customKeywordColor The color used to highlight the custom keywords. ezExpressionWidgetAttribute(const char* szCustomKeywords, ezColorGammaUB customKeywordColor) : m_sCustomKeywords(szCustomKeywords) , m_CustomKeywordColor(customKeywordColor) { } const char* GetInputsProperty() const { return m_sInputsProperty; } const char* GetOutputsProperty() const { return m_sOutputsProperty; } const char* GetCustomKeywords() const { return m_sCustomKeywords; } ezColorGammaUB GetCustomKeywordColor() const { return m_CustomKeywordColor; } private: ezUntrackedString m_sInputsProperty; ezUntrackedString m_sOutputsProperty; ezUntrackedString m_sCustomKeywords; ezColorGammaUB m_CustomKeywordColor = ezColorGammaUB(ezColorScheme::DarkUI(ezColorScheme::Yellow)); };