| 46 | static bool emulate_three_button_mouse = false; |
| 47 | |
| 48 | ImU32 evaluate(const Graph<Node>& graph, const int root_node) |
| 49 | { |
| 50 | std::stack<int> postorder; |
| 51 | dfs_traverse( |
| 52 | graph, root_node, [&postorder](const int node_id) -> void { postorder.push(node_id); }); |
| 53 | |
| 54 | std::stack<float> value_stack; |
| 55 | while (!postorder.empty()) |
| 56 | { |
| 57 | const int id = postorder.top(); |
| 58 | postorder.pop(); |
| 59 | const Node node = graph.node(id); |
| 60 | |
| 61 | switch (node.type) |
| 62 | { |
| 63 | case NodeType::add: |
| 64 | { |
| 65 | const float rhs = value_stack.top(); |
| 66 | value_stack.pop(); |
| 67 | const float lhs = value_stack.top(); |
| 68 | value_stack.pop(); |
| 69 | value_stack.push(lhs + rhs); |
| 70 | } |
| 71 | break; |
| 72 | case NodeType::multiply: |
| 73 | { |
| 74 | const float rhs = value_stack.top(); |
| 75 | value_stack.pop(); |
| 76 | const float lhs = value_stack.top(); |
| 77 | value_stack.pop(); |
| 78 | value_stack.push(rhs * lhs); |
| 79 | } |
| 80 | break; |
| 81 | case NodeType::sine: |
| 82 | { |
| 83 | const float x = value_stack.top(); |
| 84 | value_stack.pop(); |
| 85 | const float res = std::abs(std::sin(x)); |
| 86 | value_stack.push(res); |
| 87 | } |
| 88 | break; |
| 89 | case NodeType::time: |
| 90 | { |
| 91 | value_stack.push(current_time_seconds); |
| 92 | } |
| 93 | break; |
| 94 | case NodeType::value: |
| 95 | { |
| 96 | // If the edge does not have an edge connecting to another node, then just use the value |
| 97 | // at this node. It means the node's input pin has not been connected to anything and |
| 98 | // the value comes from the node's UI. |
| 99 | if (graph.num_edges_from_node(id) == 0ull) |
| 100 | { |
| 101 | value_stack.push(node.value); |
| 102 | } |
| 103 | } |
| 104 | break; |
| 105 | default: |
no test coverage detected