Kemena3D
Loading...
Searching...
No Matches
kscriptgraph.h
Go to the documentation of this file.
1
15
16#ifndef KSCRIPTGRAPH_H
17#define KSCRIPTGRAPH_H
18
19#include "kexport.h"
20
21#include <vector>
22#include <string>
23
24#include <nlohmann/json.hpp>
25
26#include "kdatatype.h"
27
28namespace kemena
29{
30 using kJson = nlohmann::json;
31
45
49 enum class kScriptNodeType
50 {
51 // --- Events (entry points; one exec output) -------------------------
58
59 // --- Flow ------------------------------------------------------------
61
62 // --- Actions (exec in + exec out) -----------------------------------
71
72 // --- Getters (pure data) --------------------------------------------
82
83 // --- Literals --------------------------------------------------------
88
89 // --- Math ------------------------------------------------------------
94
95 // --- Vector ----------------------------------------------------------
99
100 // --- Compare / logic -------------------------------------------------
107
109 };
110
117
122 {
123 int id = 0;
126 bool isOutput = false;
127
128 // Inline default used when an input data pin is left unconnected.
129 float defFloat = 0.0f;
130 float defVec[3] = { 0.0f, 0.0f, 0.0f };
131 bool defBool = false;
133
134 // Cached screen position, refreshed by the editor each frame.
135 float uiX = 0.0f, uiY = 0.0f;
136 };
137
142 {
143 int id = 0;
146 float posX = 0.0f, posY = 0.0f;
147
148 std::vector<kScriptGraphPin> inputs;
149 std::vector<kScriptGraphPin> outputs;
150
151 // Payload for literal and variable nodes.
152 float valueFloat[3] = { 0.0f, 0.0f, 0.0f };
153 bool valueBool = false;
155 };
156
161 {
162 int id = 0;
163 int fromNode = 0, fromPin = 0;
164 int toNode = 0, toPin = 0;
165 };
166
174 {
176 float defValue = 0.0f;
177 };
178
183 {
186
187 std::vector<kScriptGraphNode> nodes;
188 std::vector<kScriptGraphLink> links;
189 std::vector<kScriptGraphVar> variables;
190
191 int nextId = 1;
192 bool dirty = false;
193
198 int newId() { return nextId++; }
199
206
212 const kScriptGraphNode *findNode(int id) const;
213
220 const kScriptGraphLink *incomingLink(int nodeId, int pinId) const;
221
228 const kScriptGraphLink *outgoingLink(int nodeId, int pinId) const;
229
236 bool isPinConnected(int nodeId, int pinId) const;
237
242 void removeLinksByNode(int nodeId);
243
249 void removeLinksByPin(int nodeId, int pinId);
250
255 void removeNode(int nodeId);
256
268
273 kJson toJson() const;
274
279 void fromJson(const kJson &j);
280 };
281
291
308}
309
310#endif // KSCRIPTGRAPH_H
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Compiles a node graph into AngelScript source text.
Definition kscriptgraph.h:300
KEMENA3D_API kScriptGraphResult compile(const kScriptGraph &graph)
Compiles a node graph into AngelScript source text.
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
kScriptNodeType
Every node kind the visual scripting graph supports.
Definition kscriptgraph.h:50
@ LiteralString
Constant string value.
Definition kscriptgraph.h:86
@ Divide
a / b.
Definition kscriptgraph.h:93
@ Print
Logs a value to the console.
Definition kscriptgraph.h:63
@ EventAwake
Emits the Awake lifecycle function.
Definition kscriptgraph.h:52
@ SetScale
Sets the object's scale.
Definition kscriptgraph.h:66
@ Less
a < b.
Definition kscriptgraph.h:102
@ Subtract
a - b.
Definition kscriptgraph.h:91
@ LiteralBool
Constant bool value.
Definition kscriptgraph.h:85
@ GetDeltaTime
Frame delta time.
Definition kscriptgraph.h:80
@ SetPosition
Sets the object's world position.
Definition kscriptgraph.h:64
@ GetUp
The object's up axis.
Definition kscriptgraph.h:79
@ GetForward
The object's forward axis.
Definition kscriptgraph.h:77
@ EventOnDestroy
Emits the OnDestroy lifecycle function.
Definition kscriptgraph.h:57
@ BreakVec3
Splits a Vec3 into three floats.
Definition kscriptgraph.h:97
@ GetVariable
Reads a graph variable.
Definition kscriptgraph.h:81
@ Or
Logical OR.
Definition kscriptgraph.h:105
@ GetRotation
Reads the object's rotation.
Definition kscriptgraph.h:75
@ GetPosition
Reads the object's world position.
Definition kscriptgraph.h:74
@ LiteralFloat
Constant float value.
Definition kscriptgraph.h:84
@ SetActive
Enables/disables the object.
Definition kscriptgraph.h:69
@ EventUpdate
Emits the Update lifecycle function.
Definition kscriptgraph.h:54
@ SetVariable
Assigns a graph variable.
Definition kscriptgraph.h:70
@ GetRight
The object's right axis.
Definition kscriptgraph.h:78
@ ScaleVec3
Vec3 * Float.
Definition kscriptgraph.h:98
@ EventFixedUpdate
Emits the FixedUpdate lifecycle function.
Definition kscriptgraph.h:55
@ Greater
a > b.
Definition kscriptgraph.h:101
@ Rotate
Rotates the object by a vector.
Definition kscriptgraph.h:68
@ GetScale
Reads the object's scale.
Definition kscriptgraph.h:76
@ Not
Logical negation.
Definition kscriptgraph.h:106
@ GetSelf
The object the script is attached to.
Definition kscriptgraph.h:73
@ EventLateUpdate
Emits the LateUpdate lifecycle function.
Definition kscriptgraph.h:56
@ And
Logical AND.
Definition kscriptgraph.h:104
@ EventStart
Emits the Start lifecycle function.
Definition kscriptgraph.h:53
@ SetRotation
Sets the object's rotation.
Definition kscriptgraph.h:65
@ Branch
if/else on a Bool condition.
Definition kscriptgraph.h:60
@ Translate
Offsets the object's position by a vector.
Definition kscriptgraph.h:67
@ Multiply
a * b.
Definition kscriptgraph.h:92
@ Count
Sentinel (number of node types).
Definition kscriptgraph.h:108
@ Add
a + b.
Definition kscriptgraph.h:90
@ LiteralVec3
Constant Vec3 value.
Definition kscriptgraph.h:87
@ Equal
a == b.
Definition kscriptgraph.h:103
@ MakeVec3
Combines three floats into a Vec3.
Definition kscriptgraph.h:96
kScriptPinType
Kind/type of a node pin. Exec pins carry control flow; the rest carry typed data values.
Definition kscriptgraph.h:37
@ Vec3
3-component vector value.
Definition kscriptgraph.h:42
@ Float
Floating-point value.
Definition kscriptgraph.h:39
@ String
Text value.
Definition kscriptgraph.h:41
@ Object
kObject handle.
Definition kscriptgraph.h:43
@ Exec
Execution (control-flow) wire.
Definition kscriptgraph.h:38
@ Bool
Boolean value.
Definition kscriptgraph.h:40
std::string kString
Standard string alias.
Definition kdatatype.h:42
nlohmann::json kJson
Definition kscriptgraph.h:30
KEMENA3D_API const char * kScriptNodeTypeName(kScriptNodeType type)
Human-readable label for a node type (used by the editor menu).
The complete editable node graph for one script.
Definition kscriptgraph.h:183
int nextId
Monotonic id source.
Definition kscriptgraph.h:191
std::vector< kScriptGraphLink > links
All wires between pins.
Definition kscriptgraph.h:188
std::vector< kScriptGraphNode > nodes
All nodes in the graph.
Definition kscriptgraph.h:187
int newId()
Returns the next graph-unique id and advances the counter.
Definition kscriptgraph.h:198
kString uuid
Stable script-asset UUID.
Definition kscriptgraph.h:184
std::vector< kScriptGraphVar > variables
Graph-scope variables.
Definition kscriptgraph.h:189
const kScriptGraphLink * incomingLink(int nodeId, int pinId) const
Returns the link feeding an input pin, or nullptr.
kString name
Display name.
Definition kscriptgraph.h:185
void removeLinksByPin(int nodeId, int pinId)
Removes every link attached to a specific pin.
kJson toJson() const
Serialises the whole graph to JSON.
kScriptGraphNode * findNode(int id)
Finds a node by id, or nullptr.
void removeLinksByNode(int nodeId)
Removes every link attached to a node.
bool dirty
Unsaved-changes flag (editor only).
Definition kscriptgraph.h:192
const kScriptGraphLink * outgoingLink(int nodeId, int pinId) const
Returns the first link leaving an output pin, or nullptr.
const kScriptGraphNode * findNode(int id) const
Const overload: finds a node by id, or nullptr.
void removeNode(int nodeId)
Removes a node and all of its links.
bool isPinConnected(int nodeId, int pinId) const
True if any link touches the given pin.
kScriptGraphNode makeNode(kScriptNodeType type, float x, float y)
Builds a fully-pinned node of the given type at (x, y).
void fromJson(const kJson &j)
Restores a graph from JSON produced by toJson().
A single graph node with its input/output pins and payload.
Definition kscriptgraph.h:142
kString valueStr
Literal string OR variable name.
Definition kscriptgraph.h:154
float posX
Definition kscriptgraph.h:146
float valueFloat[3]
Literal numeric value.
Definition kscriptgraph.h:152
float posY
Canvas position (editor only).
Definition kscriptgraph.h:146
std::vector< kScriptGraphPin > inputs
Input pins (exec + data).
Definition kscriptgraph.h:148
kString name
Display label.
Definition kscriptgraph.h:145
bool valueBool
Literal boolean value.
Definition kscriptgraph.h:153
std::vector< kScriptGraphPin > outputs
Output pins (exec + data).
Definition kscriptgraph.h:149
kScriptNodeType type
Node kind.
Definition kscriptgraph.h:144
A connection point on a node.
Definition kscriptgraph.h:122
float uiX
Definition kscriptgraph.h:135
float defVec[3]
Default for unconnected Vec3 inputs.
Definition kscriptgraph.h:130
bool defBool
Default for unconnected Bool inputs.
Definition kscriptgraph.h:131
float uiY
Cached pin screen position (editor only).
Definition kscriptgraph.h:135
kString defStr
Default for unconnected String inputs.
Definition kscriptgraph.h:132
kString name
Display label.
Definition kscriptgraph.h:124
float defFloat
Default for unconnected Float inputs.
Definition kscriptgraph.h:129
bool isOutput
Output vs input.
Definition kscriptgraph.h:126
kScriptPinType type
Wire kind.
Definition kscriptgraph.h:125
Result of compiling a graph to AngelScript text.
Definition kscriptgraph.h:286
bool success
True if code was generated.
Definition kscriptgraph.h:287
kString code
Generated AngelScript source.
Definition kscriptgraph.h:289
kString error
Human-readable failure reason.
Definition kscriptgraph.h:288
A graph-scope variable, emitted as an AngelScript global.
Definition kscriptgraph.h:174
float defValue
Initial value.
Definition kscriptgraph.h:176
kString name
Identifier (must be a valid AngelScript name).
Definition kscriptgraph.h:175