Skip to content

Commit 29b1686

Browse files
committed
feat: add MergeEventQueues node
Concatenates two event queues into one, enabling multiple event sources to feed into a single event queue input (e.g. FSM driver).
1 parent 0edc95a commit 29b1686

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use bevy::prelude::*;
2+
use bevy_animation_graph_core::{
3+
animation_node::{NodeLike, ReflectNodeLike},
4+
context::{new_context::NodeContext, spec_context::SpecContext},
5+
edge_data::DataSpec,
6+
errors::GraphError,
7+
};
8+
9+
/// Merges two event queues into one.
10+
#[derive(Reflect, Clone, Debug, Default)]
11+
#[reflect(Default, NodeLike)]
12+
#[type_path = "bevy_animation_graph::builtin_nodes"]
13+
pub struct MergeEventQueues;
14+
15+
impl MergeEventQueues {
16+
pub const IN_A: &'static str = "in_a";
17+
pub const IN_B: &'static str = "in_b";
18+
pub const OUTPUT: &'static str = "out";
19+
20+
pub fn new() -> Self {
21+
Self
22+
}
23+
}
24+
25+
impl NodeLike for MergeEventQueues {
26+
fn display_name(&self) -> String {
27+
"Merge Events".into()
28+
}
29+
30+
fn update(&self, mut ctx: NodeContext) -> Result<(), GraphError> {
31+
let a = ctx.data_back(Self::IN_A)?.into_event_queue()?;
32+
let b = ctx.data_back(Self::IN_B)?.into_event_queue()?;
33+
ctx.set_data_fwd(Self::OUTPUT, a.concat(b));
34+
Ok(())
35+
}
36+
37+
fn spec(&self, mut ctx: SpecContext) -> Result<(), GraphError> {
38+
ctx.add_input_data(Self::IN_A, DataSpec::EventQueue)
39+
.add_input_data(Self::IN_B, DataSpec::EventQueue)
40+
.add_output_data(Self::OUTPUT, DataSpec::EventQueue);
41+
Ok(())
42+
}
43+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod fire_event;
22
pub mod map_events;
3+
pub mod merge_event_queues;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Merge Event Queues Node
3+
authors: ["@baszalmstra"]
4+
pull_requests: []
5+
---
6+
7+
A new `MergeEventQueues` node has been added that concatenates two event queues into one. This is useful when multiple event sources (e.g. a `FireEventNode` and a `ClipNode`'s event output) need to feed into a single event queue input like the FSM's driver.

0 commit comments

Comments
 (0)