-97
src-tauri/src/runtime.rs.old
-97
src-tauri/src/runtime.rs.old
···
1
-
use std::collections::HashMap;
2
-
3
-
use anyhow::bail;
4
-
5
-
use crate::{ osc::OSCMessage, structs::{ nodes::{ Node, Tab }, parameter_types::ParameterType } };
6
-
7
-
pub fn start_runtime(
8
-
tab: &Tab,
9
-
msg: &OSCMessage,
10
-
node_execution_table:
11
-
&HashMap<String, Box<dyn Fn(&Node, &OSCMessage, Vec<ParameterType>) -> Vec<ParameterType>>>
12
-
) -> anyhow::Result<()>{
13
-
for i in 0..tab.nodes.len(){
14
-
let node = &tab.nodes[i];
15
-
16
-
if node.type_id == "osctrigger"{
17
-
runtime(&tab.nodes, i, msg, node_execution_table)?;
18
-
}
19
-
}
20
-
21
-
Ok(())
22
-
}
23
-
24
-
fn runtime(
25
-
nodes: &Vec<Node>,
26
-
index: usize,
27
-
msg: &OSCMessage,
28
-
node_execution_table:
29
-
&HashMap<String, Box<dyn Fn(&Node, &OSCMessage, Vec<ParameterType>) -> Vec<ParameterType>>>
30
-
) -> anyhow::Result<()>{
31
-
let node = &nodes[index];
32
-
33
-
let execute_node = node_execution_table.get(&node.type_id);
34
-
if execute_node.is_none(){ bail!("Cannot find node in execution table."); }
35
-
36
-
let res = execute_node.unwrap()(node, msg, vec![]);
37
-
if res.len() == 0{ return Ok(()); }
38
-
39
-
let nodes_length = (&nodes).len();
40
-
41
-
for i in 0..res.len(){
42
-
let output = &node.outputs[i];
43
-
if output.value_type == 5 { // 5 - Flow Type
44
-
45
-
if let ParameterType::Flow(run) = res[i]{
46
-
47
-
if run{
48
-
let connections = &output.connections;
49
-
for connection in connections{
50
-
let mut found_node = None;
51
-
52
-
for i in 0..nodes_length{
53
-
let node = &nodes[i];
54
-
55
-
if node.id == connection.node{
56
-
found_node = Some(i);
57
-
break;
58
-
}
59
-
}
60
-
61
-
if found_node.is_some(){
62
-
runtime(nodes, found_node.unwrap(), msg, node_execution_table)?;
63
-
}
64
-
}
65
-
}
66
-
}
67
-
}
68
-
}
69
-
70
-
Ok(())
71
-
}
72
-
73
-
pub fn load_excecution_table(
74
-
node_execution_table:
75
-
&mut HashMap<String, Box<dyn Fn(&Node, &OSCMessage, Vec<ParameterType>) -> Vec<ParameterType>>>
76
-
){
77
-
node_execution_table.insert("osctrigger".into(), Box::new(| node, msg, _ |{
78
-
if node.statics[0].value.is_null(){ return vec![ ParameterType::Flow(false) ] }
79
-
80
-
let node_addr = node.statics[0].value.as_str().unwrap().to_owned();
81
-
if node_addr == msg.address{
82
-
let mut dat = vec![
83
-
ParameterType::Flow(true)
84
-
];
85
-
86
-
dat.extend(msg.values.clone());
87
-
dat
88
-
} else{
89
-
vec![ ParameterType::Flow(false) ]
90
-
}
91
-
}));
92
-
93
-
node_execution_table.insert("debug".into(), Box::new(| _, _, args |{
94
-
dbg!(&args[1]);
95
-
vec![]
96
-
}));
97
-
}