Skip to content

Support for dynamic dictionaries of buffers #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
36d604b
Introducing the concept of a buffer map
mxgrey Jan 23, 2025
d9b9be1
Refactoring Buffered trait
mxgrey Jan 24, 2025
763244b
Figuring out how to dynamically access buffers
mxgrey Jan 24, 2025
96953c5
Prototype of AnyBufferMut
mxgrey Jan 27, 2025
f3ddbf5
Any buffer access is working
mxgrey Jan 29, 2025
9935817
Add AnyBuffer drain and restructure any_buffer module
mxgrey Jan 29, 2025
442c676
Clean up any_buffer implementation
mxgrey Jan 29, 2025
d44e383
Introducing JsonBuffer type
mxgrey Jan 29, 2025
70cec2c
Refactoring the use of AnyBufferStorageAccessInterface
mxgrey Jan 30, 2025
8f79d53
Fix global retention of AnyBufferAccessInterface
mxgrey Jan 30, 2025
b21c218
Fleshing out implementation of JsonBuffer
mxgrey Jan 30, 2025
792e0b6
Almost done with JsonBuffer
mxgrey Jan 31, 2025
ae65f24
Implemented Joined and Accessed for AnyBuffer and JsonBuffer
mxgrey Feb 2, 2025
7c9d490
Add tests for JsonBuffer
mxgrey Feb 2, 2025
0d1224f
Implement JsonBufferView
mxgrey Feb 2, 2025
5dcae45
Implement AnyBufferView
mxgrey Feb 2, 2025
ca7a226
Draft an example implementation of JoinedValue
mxgrey Feb 2, 2025
096ccf4
Fix formatting
mxgrey Feb 2, 2025
800a112
Remove use of 1.75 unstable function
mxgrey Feb 2, 2025
de6596d
Implement more general buffer downcasting
mxgrey Feb 3, 2025
bd32a47
fix doc comments
mxgrey Feb 3, 2025
c419ab3
Refactor buffer keys
mxgrey Feb 3, 2025
a6bf08d
Implement more general buffer key downcasting
mxgrey Feb 3, 2025
a40b8d3
Invert the implementation of JoinedValue
mxgrey Feb 6, 2025
617e22f
Refactor Bufferable so we no longer need join_into
mxgrey Feb 6, 2025
4c087ea
Fix style
mxgrey Feb 6, 2025
858c7e6
Update docs
mxgrey Feb 6, 2025
aa22f87
Fix style
mxgrey Feb 6, 2025
5dd9a30
Merge branch 'main' into buffer_map
mxgrey Feb 14, 2025
f64871e
add derive `JoinedValue` to implement trait automatically (#53)
koonpeng Feb 17, 2025
e94c170
Generalize buffer map keys
mxgrey Feb 17, 2025
6e19af7
Support for joining Vec and json values
mxgrey Feb 17, 2025
4e35ec8
Working towards BufferKeyMap implementation
mxgrey Feb 18, 2025
87387e3
BufferKeyMap macro (#56)
mxgrey Feb 20, 2025
47bd4d0
Merge branch 'main' into buffer_map
mxgrey Feb 20, 2025
c096209
Rename traits to improve semantics (#57)
mxgrey Feb 20, 2025
911a5e1
Tighten up leaks
mxgrey Feb 21, 2025
8a7603c
Fix style
mxgrey Feb 21, 2025
530c92f
Iterate on require buffer functions
mxgrey Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ use bevy_ecs::{

use std::{ops::RangeBounds, sync::Arc};

use thiserror::Error as ThisError;

use crate::{
Builder, Chain, Gate, GateState, InputSlot, NotifyBufferUpdate, OnNewBufferValue, UnusedTarget,
};

mod any_buffer;
pub use any_buffer::*;

mod buffer_access_lifecycle;
pub(crate) use buffer_access_lifecycle::*;

mod buffer_key_builder;
pub(crate) use buffer_key_builder::*;

mod buffer_map;
pub use buffer_map::*;

mod buffer_storage;
pub(crate) use buffer_storage::*;

Expand All @@ -46,6 +54,11 @@ pub use bufferable::*;
mod manage_buffer;
pub use manage_buffer::*;

#[cfg(feature = "diagram")]
mod json_buffer;
#[cfg(feature = "diagram")]
pub use json_buffer::*;

/// A buffer is a special type of node within a workflow that is able to store
/// and release data. When a session is finished, the buffered data from the
/// session will be automatically cleared.
Expand Down Expand Up @@ -89,6 +102,15 @@ impl<T> Buffer<T> {
}
}

impl<T> Clone for Buffer<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> Copy for Buffer<T> {}

#[derive(Clone, Copy)]
pub struct CloneFromBuffer<T: Clone> {
pub(crate) scope: Entity,
pub(crate) source: Entity,
Expand Down Expand Up @@ -157,22 +179,6 @@ impl Default for RetentionPolicy {
}
}

impl<T> Clone for Buffer<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T> Copy for Buffer<T> {}

impl<T: Clone> Clone for CloneFromBuffer<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T: Clone> Copy for CloneFromBuffer<T> {}

/// This key can unlock access to the contents of a buffer by passing it into
/// [`BufferAccess`] or [`BufferAccessMut`].
///
Expand Down Expand Up @@ -424,7 +430,7 @@ where
self.len() == 0
}

/// Check whether the gate of this buffer is open or closed
/// Check whether the gate of this buffer is open or closed.
pub fn gate(&self) -> Gate {
self.gate
.map
Expand Down Expand Up @@ -467,7 +473,7 @@ where
self.storage.drain(self.session, range)
}

/// Pull the oldest item from the buffer
/// Pull the oldest item from the buffer.
pub fn pull(&mut self) -> Option<T> {
self.modified = true;
self.storage.pull(self.session)
Expand Down Expand Up @@ -500,7 +506,7 @@ where
// continuous systems with BufferAccessMut from running at the same time no
// matter what the buffer type is.

/// Tell the buffer [`Gate`] to open
/// Tell the buffer [`Gate`] to open.
pub fn open_gate(&mut self) {
if let Some(gate) = self.gate.map.get_mut(&self.session) {
if *gate != Gate::Open {
Expand All @@ -510,7 +516,7 @@ where
}
}

/// Tell the buffer [`Gate`] to close
/// Tell the buffer [`Gate`] to close.
pub fn close_gate(&mut self) {
if let Some(gate) = self.gate.map.get_mut(&self.session) {
*gate = Gate::Closed;
Expand All @@ -519,7 +525,7 @@ where
}
}

/// Perform an action on the gate of the buffer
/// Perform an action on the gate of the buffer.
pub fn gate_action(&mut self, action: Gate) {
match action {
Gate::Open => self.open_gate(),
Expand Down Expand Up @@ -569,6 +575,12 @@ where
}
}

#[derive(ThisError, Debug, Clone)]
pub enum BufferError {
#[error("The key was unable to identify a buffer")]
BufferMissing,
}

#[cfg(test)]
mod tests {
use crate::{prelude::*, testing::*, Gate};
Expand Down
Loading
Loading