Plasma Engine  2.0
Loading...
Searching...
No Matches
ExpressionDeclarations.h
1#pragma once
2
3#include <Foundation/Containers/HashTable.h>
4#include <Foundation/Containers/SmallArray.h>
5#include <Foundation/DataProcessing/Stream/ProcessingStream.h>
6#include <Foundation/Reflection/Reflection.h>
7#include <Foundation/SimdMath/SimdVec4f.h>
8#include <Foundation/SimdMath/SimdVec4i.h>
9#include <Foundation/Types/Variant.h>
10
11class plStreamWriter;
12class plStreamReader;
13
14namespace plExpression
15{
16 struct Register
17 {
18 PL_DECLARE_POD_TYPE();
19
20 Register(){}; // NOLINT: using = default doesn't work here.
21
22 union
23 {
27 };
28 };
29
31 {
32 using StorageType = plUInt8;
33
34 enum Enum
35 {
36 Unknown,
37
38 Bool,
39 Int,
40 Float,
41
42 Count,
43
44 Default = Float,
45 MaxNumBits = 4,
46 };
47
48 static const char* GetName(Enum registerType);
49 };
50
52 using Inputs = plArrayPtr<plArrayPtr<const Register>>; // Inputs are in SOA form, means inner array contains all values for one input parameter, one for each instance.
54
57 {
58 plHashedString m_sName;
60
61 bool operator==(const StreamDesc& other) const
62 {
63 return m_sName == other.m_sName && m_DataType == other.m_DataType;
64 }
65
66 plResult Serialize(plStreamWriter& inout_stream) const;
67 plResult Deserialize(plStreamReader& inout_stream);
68 };
69
72 {
73 plHashedString m_sName;
75 plUInt8 m_uiNumRequiredInputs = 0;
77
78 bool operator==(const FunctionDesc& other) const
79 {
80 return m_sName == other.m_sName &&
81 m_InputTypes == other.m_InputTypes &&
82 m_uiNumRequiredInputs == other.m_uiNumRequiredInputs &&
83 m_OutputType == other.m_OutputType;
84 }
85
86 bool operator<(const FunctionDesc& other) const;
87
88 plResult Serialize(plStreamWriter& inout_stream) const;
89 plResult Deserialize(plStreamReader& inout_stream);
90
91 plHashedString GetMangledName() const;
92 };
93
94 using Function = void (*)(plExpression::Inputs, plExpression::Output, const plExpression::GlobalData&);
95 using ValidateGlobalDataFunction = plResult (*)(const plExpression::GlobalData&);
96
97} // namespace plExpression
98
102{
104
105 plExpression::Function m_Func;
106
107 // Optional validation function used to validate required global data for an expression function
108 plExpression::ValidateGlobalDataFunction m_ValidateGlobalDataFunc;
109};
110
111struct PL_FOUNDATION_DLL plDefaultExpressionFunctions
112{
113 static plExpressionFunction s_RandomFunc;
114 static plExpressionFunction s_PerlinNoiseFunc;
115};
116
122{
123 PL_ADD_DYNAMIC_REFLECTION(plExpressionWidgetAttribute, plTypeWidgetAttribute);
124
125public:
126 plExpressionWidgetAttribute() = default;
127 plExpressionWidgetAttribute(const char* szInputsProperty, const char* szOutputProperty)
128 : m_sInputsProperty(szInputsProperty)
129 , m_sOutputsProperty(szOutputProperty)
130 {
131 }
132
133 const char* GetInputsProperty() const { return m_sInputsProperty; }
134 const char* GetOutputsProperty() const { return m_sOutputsProperty; }
135
136private:
137 plUntrackedString m_sInputsProperty;
138 plUntrackedString m_sOutputsProperty;
139};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Add this attribute a string property that should be interpreted as expression source.
Definition ExpressionDeclarations.h:122
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition HashedString.h:25
DataType
The data types which can be stored in the stream. When adding new data types the GetDataTypeSize() of...
Definition ProcessingStream.h:13
Definition SimdVec4b.h:7
A 4-component SIMD vector class.
Definition SimdVec4f.h:8
A SIMD 4-component vector class of signed 32b integers.
Definition SimdVec4i.h:9
Definition SmallArray.h:219
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Derive from this class if you want to define an attribute that replaces the property type widget.
Definition PropertyAttributes.h:263
Definition ExpressionDeclarations.h:112
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Describes an expression function and its signature, e.g. how many input parameter it has and their ty...
Definition ExpressionDeclarations.h:72
Definition ExpressionDeclarations.h:17
Definition ExpressionDeclarations.h:31
Describes an input or output stream for a expression VM.
Definition ExpressionDeclarations.h:57
Describes an external function that can be called in expressions. These functions need to be state-le...
Definition ExpressionDeclarations.h:102
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54