Skip to content

Commit 4854f11

Browse files
committed
refactor node specs
1 parent 41dcd87 commit 4854f11

49 files changed

Lines changed: 591 additions & 613 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/bevy_animation_graph_builtin_nodes/src/blend_node.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::prelude::*;
22
use bevy_animation_graph_core::{
3-
animation_graph::{PinMap, TimeUpdate},
3+
animation_graph::TimeUpdate,
44
animation_node::{NodeLike, ReflectNodeLike},
55
context::{new_context::NodeContext, spec_context::SpecContext},
66
edge_data::DataSpec,
@@ -128,31 +128,27 @@ impl NodeLike for BlendNode {
128128
Ok(())
129129
}
130130

131-
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
132-
let mut input_data = vec![
133-
(Self::FACTOR.into(), DataSpec::F32),
134-
(Self::IN_POSE_A.into(), DataSpec::Pose),
135-
(Self::IN_POSE_B.into(), DataSpec::Pose),
136-
];
131+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
132+
// Input
133+
ctx.add_input_data(Self::FACTOR, DataSpec::F32);
137134

138-
if matches!(self.sync_mode, BlendSyncMode::EventTrack(_)) {
139-
input_data.push((Self::IN_EVENT_A.into(), DataSpec::EventQueue));
140-
input_data.push((Self::IN_EVENT_B.into(), DataSpec::EventQueue));
135+
ctx.add_input_data(Self::IN_POSE_A, DataSpec::Pose);
136+
if matches!(&self.sync_mode, BlendSyncMode::EventTrack(_)) {
137+
ctx.add_input_data(Self::IN_EVENT_A, DataSpec::EventQueue);
141138
}
139+
ctx.add_input_time(Self::IN_TIME_A);
142140

143-
input_data.into_iter().collect()
144-
}
145-
146-
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
147-
[(Self::OUT_POSE.into(), DataSpec::Pose)].into()
148-
}
141+
ctx.add_input_data(Self::IN_POSE_B, DataSpec::Pose);
142+
if matches!(&self.sync_mode, BlendSyncMode::EventTrack(_)) {
143+
ctx.add_input_data(Self::IN_EVENT_B, DataSpec::EventQueue);
144+
}
145+
ctx.add_input_time(Self::IN_TIME_B);
149146

150-
fn time_input_spec(&self, _: SpecContext) -> PinMap<()> {
151-
[(Self::IN_TIME_A.into(), ()), (Self::IN_TIME_B.into(), ())].into()
152-
}
147+
// Output
148+
ctx.add_output_data(Self::OUT_POSE, DataSpec::Pose)
149+
.add_output_time();
153150

154-
fn time_output_spec(&self, _: SpecContext) -> Option<()> {
155-
Some(())
151+
Ok(())
156152
}
157153

158154
fn display_name(&self) -> String {

crates/bevy_animation_graph_builtin_nodes/src/blend_space_node.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::prelude::*;
22
use bevy_animation_graph_core::{
3-
animation_graph::{PinMap, TimeUpdate},
3+
animation_graph::TimeUpdate,
44
animation_node::{EditProxy, NodeLike, ReflectEditProxy, ReflectNodeLike},
55
context::{new_context::NodeContext, spec_context::SpecContext},
66
edge_data::DataSpec,
@@ -194,36 +194,21 @@ impl NodeLike for BlendSpaceNode {
194194
Ok(())
195195
}
196196

197-
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
198-
let mut input_spec = PinMap::from([(Self::POSITION.into(), DataSpec::Vec2)]);
197+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
198+
ctx.add_input_data(Self::POSITION, DataSpec::Vec2);
199199

200-
input_spec.extend(self.points.iter().flat_map(|p| {
201-
let mut out = vec![(Self::pose_pin_id(&p.id), DataSpec::Pose)];
202-
203-
if matches!(self.sync_mode, BlendSyncMode::EventTrack(_)) {
204-
out.push((Self::events_pin_id(&p.id), DataSpec::EventQueue));
200+
for p in &self.points {
201+
ctx.add_input_data(Self::pose_pin_id(&p.id), DataSpec::Pose);
202+
if matches!(&self.sync_mode, BlendSyncMode::EventTrack(_)) {
203+
ctx.add_input_data(Self::events_pin_id(&p.id), DataSpec::EventQueue);
205204
}
205+
ctx.add_input_time(Self::time_pin_id(&p.id));
206+
}
206207

207-
out
208-
}));
209-
210-
input_spec
211-
}
212-
213-
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
214-
[(Self::OUT_POSE.into(), DataSpec::Pose)].into()
215-
}
216-
217-
fn time_input_spec(&self, _: SpecContext) -> PinMap<()> {
218-
let mut input_spec = PinMap::new();
219-
220-
input_spec.extend(self.points.iter().map(|p| (Self::time_pin_id(&p.id), ())));
208+
ctx.add_output_data(Self::OUT_POSE, DataSpec::Pose)
209+
.add_output_time();
221210

222-
input_spec
223-
}
224-
225-
fn time_output_spec(&self, _: SpecContext) -> Option<()> {
226-
Some(())
211+
Ok(())
227212
}
228213

229214
fn display_name(&self) -> String {

crates/bevy_animation_graph_builtin_nodes/src/bool/const_bool.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bevy::prelude::*;
22
use bevy_animation_graph_core::{
3-
animation_graph::PinMap,
43
animation_node::{NodeLike, ReflectNodeLike},
54
context::{new_context::NodeContext, spec_context::SpecContext},
65
edge_data::DataSpec,
@@ -32,7 +31,9 @@ impl NodeLike for ConstBool {
3231
Ok(())
3332
}
3433

35-
fn data_output_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
36-
[(Self::OUTPUT.into(), DataSpec::Bool)].into()
34+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
35+
ctx.add_output_data(Self::OUTPUT, DataSpec::Bool);
36+
37+
Ok(())
3738
}
3839
}

crates/bevy_animation_graph_builtin_nodes/src/chain_node.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::prelude::*;
22
use bevy_animation_graph_core::{
3-
animation_graph::{PinMap, TimeUpdate},
3+
animation_graph::TimeUpdate,
44
animation_node::{NodeLike, ReflectNodeLike},
55
context::{new_context::NodeContext, spec_context::SpecContext},
66
edge_data::DataSpec,
@@ -89,24 +89,16 @@ impl NodeLike for ChainNode {
8989
Ok(())
9090
}
9191

92-
fn data_input_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
93-
[
94-
(Self::IN_POSE_A.into(), DataSpec::Pose),
95-
(Self::IN_POSE_B.into(), DataSpec::Pose),
96-
]
97-
.into()
98-
}
99-
100-
fn data_output_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
101-
[(Self::OUT_POSE.into(), DataSpec::Pose)].into()
102-
}
103-
104-
fn time_input_spec(&self, _ctx: SpecContext) -> PinMap<()> {
105-
[(Self::IN_TIME_A.into(), ()), (Self::IN_TIME_B.into(), ())].into()
106-
}
107-
108-
fn time_output_spec(&self, _: SpecContext) -> Option<()> {
109-
Some(())
92+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
93+
ctx //
94+
.add_input_data(Self::IN_POSE_A, DataSpec::Pose)
95+
.add_input_time(Self::IN_TIME_A)
96+
.add_input_data(Self::IN_POSE_B, DataSpec::Pose)
97+
.add_input_time(Self::IN_TIME_B);
98+
ctx //
99+
.add_output_data(Self::OUT_POSE, DataSpec::Pose)
100+
.add_output_time();
101+
Ok(())
110102
}
111103

112104
fn display_name(&self) -> String {

crates/bevy_animation_graph_builtin_nodes/src/clip_node.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bevy::{
1111
};
1212
use bevy_animation_graph_core::{
1313
animation_clip::{GraphClip, Interpolation},
14-
animation_graph::{PinMap, TimeUpdate},
14+
animation_graph::TimeUpdate,
1515
animation_node::{NodeLike, ReflectNodeLike},
1616
context::{new_context::NodeContext, spec_context::SpecContext},
1717
edge_data::{DataSpec, DataValue, events::EventQueue},
@@ -134,16 +134,13 @@ impl NodeLike for ClipNode {
134134
Ok(())
135135
}
136136

137-
fn data_output_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
138-
[
139-
(Self::OUT_POSE.into(), DataSpec::Pose),
140-
(Self::OUT_EVENT_QUEUE.into(), DataSpec::EventQueue),
141-
]
142-
.into()
143-
}
137+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
138+
ctx //
139+
.add_output_data(Self::OUT_POSE, DataSpec::Pose)
140+
.add_output_data(Self::OUT_EVENT_QUEUE, DataSpec::EventQueue)
141+
.add_output_time();
144142

145-
fn time_output_spec(&self, _: SpecContext) -> Option<()> {
146-
Some(())
143+
Ok(())
147144
}
148145

149146
fn display_name(&self) -> String {

crates/bevy_animation_graph_builtin_nodes/src/const_entity_path.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use bevy::reflect::{Reflect, prelude::ReflectDefault};
22
use bevy_animation_graph_core::{
33
animation_clip::EntityPath,
4-
animation_graph::PinMap,
54
animation_node::NodeLike,
65
context::{new_context::NodeContext, spec_context::SpecContext},
76
edge_data::{DataSpec, DataValue},
@@ -33,7 +32,9 @@ impl NodeLike for ConstEntityPath {
3332
Ok(())
3433
}
3534

36-
fn data_output_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
37-
[(Self::OUTPUT.into(), DataSpec::EntityPath)].into()
35+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
36+
ctx.add_output_data(Self::OUTPUT, DataSpec::EntityPath);
37+
38+
Ok(())
3839
}
3940
}

crates/bevy_animation_graph_builtin_nodes/src/dummy_node.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use bevy::prelude::*;
2-
use bevy_animation_graph_core::animation_node::{NodeLike, ReflectNodeLike};
2+
use bevy_animation_graph_core::{
3+
animation_node::{NodeLike, ReflectNodeLike},
4+
context::{new_context::NodeContext, spec_context::SpecContext},
5+
errors::GraphError,
6+
};
37

48
#[derive(Reflect, Clone, Debug, Default)]
59
#[reflect(Default, NodeLike)]
@@ -16,4 +20,12 @@ impl NodeLike for DummyNode {
1620
fn display_name(&self) -> String {
1721
"Dummy".into()
1822
}
23+
24+
fn update(&self, _: NodeContext) -> Result<(), GraphError> {
25+
Ok(())
26+
}
27+
28+
fn spec(&self, _: SpecContext) -> Result<(), GraphError> {
29+
Ok(())
30+
}
1931
}

crates/bevy_animation_graph_builtin_nodes/src/event_markup_node.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy::{platform::collections::HashMap, prelude::*};
22
use bevy_animation_graph_core::{
3-
animation_graph::{PinMap, TimeUpdate},
3+
animation_graph::TimeUpdate,
44
animation_node::{NodeLike, ReflectNodeLike},
55
context::{new_context::NodeContext, spec_context::SpecContext},
66
edge_data::{DataSpec, events::EventQueue},
@@ -93,20 +93,16 @@ impl NodeLike for EventMarkupNode {
9393
Ok(())
9494
}
9595

96-
fn data_input_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
97-
[(Self::IN_POSE.into(), DataSpec::Pose)].into()
98-
}
99-
100-
fn data_output_spec(&self, _: SpecContext) -> PinMap<DataSpec> {
101-
[(Self::OUT_POSE.into(), DataSpec::Pose)].into()
102-
}
96+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
97+
ctx //
98+
.add_input_data(Self::IN_POSE, DataSpec::Pose)
99+
.add_input_time(Self::IN_TIME);
100+
ctx //
101+
.add_output_data(Self::OUT_POSE, DataSpec::Pose)
102+
.add_output_data(Self::OUT_EVENT_QUEUE, DataSpec::EventQueue)
103+
.add_output_time();
103104

104-
fn time_input_spec(&self, _: SpecContext) -> PinMap<()> {
105-
[(Self::IN_TIME.into(), ())].into()
106-
}
107-
108-
fn time_output_spec(&self, _: SpecContext) -> Option<()> {
109-
Some(())
105+
Ok(())
110106
}
111107

112108
fn display_name(&self) -> String {

crates/bevy_animation_graph_builtin_nodes/src/event_queue/fire_event.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bevy::prelude::*;
22
use bevy_animation_graph_core::{
3-
animation_graph::PinMap,
43
animation_node::{NodeLike, ReflectNodeLike},
54
context::{new_context::NodeContext, spec_context::SpecContext},
65
edge_data::{
@@ -46,11 +45,10 @@ impl NodeLike for FireEventNode {
4645
Ok(())
4746
}
4847

49-
fn data_input_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
50-
[(Self::CONDITION_IN.into(), DataSpec::Bool)].into()
51-
}
48+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
49+
ctx.add_input_data(Self::CONDITION_IN, DataSpec::Bool);
50+
ctx.add_output_data(Self::EVENT_OUT, DataSpec::EventQueue);
5251

53-
fn data_output_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
54-
[(Self::EVENT_OUT.into(), DataSpec::EventQueue)].into()
52+
Ok(())
5553
}
5654
}

crates/bevy_animation_graph_builtin_nodes/src/f32/abs_f32.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bevy::prelude::*;
22
use bevy_animation_graph_core::{
3-
animation_graph::PinMap,
43
animation_node::{NodeLike, ReflectNodeLike},
54
context::{new_context::NodeContext, spec_context::SpecContext},
65
edge_data::DataSpec,
@@ -32,11 +31,9 @@ impl NodeLike for AbsF32 {
3231
Ok(())
3332
}
3433

35-
fn data_input_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
36-
[(Self::INPUT.into(), DataSpec::F32)].into()
37-
}
38-
39-
fn data_output_spec(&self, _ctx: SpecContext) -> PinMap<DataSpec> {
40-
[(Self::OUTPUT.into(), DataSpec::F32)].into()
34+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
35+
ctx.add_input_data(Self::INPUT, DataSpec::F32)
36+
.add_output_data(Self::OUTPUT, DataSpec::F32);
37+
Ok(())
4138
}
4239
}

0 commit comments

Comments
 (0)