Skip to content

Commit

Permalink
Moved async runtime into a separate crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
mintlu8 committed Jan 26, 2024
1 parent 8a8923a commit 436212d
Show file tree
Hide file tree
Showing 52 changed files with 1,005 additions and 674 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[workspace]
members = [
"aoui",
# "shapes",
"matui"
"defer",
"shapes",
"matui",
]
resolver="2"

Expand Down
2 changes: 1 addition & 1 deletion aoui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ doctest = false

[dependencies]
bevy = { version = "^0.12", default-features = false, features = ["bevy_sprite", "bevy_text", "trace"] }
bevy_defer = { version = "^0.1", path = "../defer" }
downcast-rs = "^1.2"
itertools = "^0.12"
serde = { version = "^1", optional = true }
Expand All @@ -32,7 +33,6 @@ parse-color = "^0.1.2"
xi-unicode = "^0.3"
thiserror = "^1"
once_cell = "^1.19"
atomic = "^0.6"
futures = "^0.3.30"
parking_lot = "^0.12"

Expand Down
11 changes: 5 additions & 6 deletions aoui/examples/accordion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

use bevy::log::LogPlugin;
use bevy::{prelude::*, diagnostic::FrameTimeDiagnosticsPlugin};
use bevy_aoui::sync::TypedSignal;
use bevy_defer::{TypedSignal, Object, signal_ids};
use bevy_aoui::util::WorldExtension;
use bevy_aoui::{signal_ids, AouiPlugin};
use bevy_aoui::AouiPlugin;
use bevy_aoui::util::AouiCommands;
use bevy_aoui::events::MovementUnits;
use bevy_aoui::util::Object;
use bevy_aoui::widgets::button::RadioButton;
pub fn main() {
App::new()
Expand Down Expand Up @@ -77,7 +76,7 @@ pub fn accordion_page(
signal: receiver::<Invocation>(sig.clone()),
system: |recv: SigRecv<Invocation>, rot: Ac<Interpolate<Rotation>>| {
let index = index;
if recv.recv().await.equals_dyn(&index) {
if recv.recv().await.equal_to(&index) {
rot.interpolate_to(PI).await
} else {
rot.interpolate_to(0.0).await
Expand All @@ -92,7 +91,7 @@ pub fn accordion_page(
signal: receiver::<Invocation>(sig.clone()),
extra: ScrollParent,
system: |recv: SigRecv<Invocation>, rot: Ac<Interpolate<Opacity>>| {
if recv.recv().await.equals_dyn(&index) {
if recv.recv().await.equal_to(&index) {
rot.interpolate_to(1.0).await
} else {
rot.interpolate_to(0.0).await
Expand All @@ -117,7 +116,7 @@ pub fn accordion_page(
let (invoke, dim_y) = futures::join!(
recv.recv(), sd.get(|x| x.0)
);
if invoke.equals_dyn(&index) {
if invoke.equal_to(&index) {
dim.interpolate_to_y(dim_y?).await?;
} else {
dim.interpolate_to_y(0.0).await?;
Expand Down
3 changes: 1 addition & 2 deletions aoui/examples/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#![recursion_limit = "256"]
use bevy::diagnostic::FrameTimeDiagnosticsPlugin;
use bevy::prelude::*;
use bevy_aoui::sync::Signal;
use bevy_defer::{Signal, Object};
use bevy_aoui::AouiPlugin;
use bevy_aoui::util::Object;
use bevy_aoui::util::WorldExtension;
use bevy_aoui::util::AouiCommands;

Expand Down
2 changes: 1 addition & 1 deletion aoui/examples/counter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This is in fact a show case for `Mutation` and not how you typically implement a counter.

use bevy::{prelude::*, diagnostic::FrameTimeDiagnosticsPlugin};
use bevy_aoui::{signal_ids, util::{WorldExtension, AouiCommands}, widgets::button::Payload, AouiPlugin};
use bevy_aoui::{util::{WorldExtension, AouiCommands}, widgets::button::Payload, AouiPlugin};

pub fn main() {
App::new()
Expand Down
23 changes: 16 additions & 7 deletions aoui/src/anim/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::{Add, Mul};
use bevy::{render::color::Color, time::Time};
use bevy::ecs::{component::Component, system::{Query, Res}};
use bevy::math::{Vec2, Vec4};
use crate::sync::AsyncResult;
use bevy_defer::{AsyncComponent, AsyncResult};
use crate::{Opacity, Dimension};
use interpolation::EaseFunction;
use smallvec::SmallVec;
Expand Down Expand Up @@ -386,19 +386,28 @@ impl Interpolation for Padding {
fn into_front_end(data: Self::Data) -> Self::FrontEnd { data }
}

use crate::sync::AsyncComponent;
#[allow(async_fn_in_trait)]
pub trait AsyncInterpolate<T: Interpolation> {
async fn interpolate_to(&self, to: T::FrontEnd) -> AsyncResult<()>;
}

impl<T: Interpolation> AsyncComponent<Interpolate<T>> {
pub async fn interpolate_to(&self, to: T::FrontEnd) -> AsyncResult<()> {
impl<T: Interpolation> AsyncInterpolate<T> for AsyncComponent<Interpolate<T>> {
async fn interpolate_to(&self, to: T::FrontEnd) -> AsyncResult<()> {
self.set(move |x| x.interpolate_to(to)).await
}
}

impl<T: Interpolation<FrontEnd = Vec2>> AsyncComponent<Interpolate<T>> {
pub async fn interpolate_to_x(&self, to: f32) -> AsyncResult<()> {
#[allow(async_fn_in_trait)]
pub trait AsyncInterpolateVec2 {
async fn interpolate_to_x(&self, to: f32) -> AsyncResult<()>;
async fn interpolate_to_y(&self, to: f32) -> AsyncResult<()>;
}

impl<T: Interpolation<FrontEnd = Vec2>> AsyncInterpolateVec2 for AsyncComponent<Interpolate<T>> {
async fn interpolate_to_x(&self, to: f32) -> AsyncResult<()> {
self.set(move |x| x.interpolate_to_x(to)).await
}
pub async fn interpolate_to_y(&self, to: f32) -> AsyncResult<()> {
async fn interpolate_to_y(&self, to: f32) -> AsyncResult<()> {
self.set(move |x| x.interpolate_to_y(to)).await
}
}
6 changes: 5 additions & 1 deletion aoui/src/anim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ use ::interpolation::Ease;
/// Enum for easing functions.
pub use ::interpolation::EaseFunction;
mod interpolation;
pub use interpolation::{Interpolate, Interpolation, Offset, Rotation, Scale, Index, Padding, Margin};
pub use interpolation::{
Interpolate, Interpolation,
Offset, Rotation, Scale, Index, Padding, Margin,
AsyncInterpolate, AsyncInterpolateVec2
};
mod assoc;
pub use assoc::{Attr, InterpolateAssociation};
mod fgsm;
Expand Down
2 changes: 1 addition & 1 deletion aoui/src/dsl/meta_dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ macro_rules! meta_dsl2 {
);
)?
$(
let system = $crate::sync::AsyncSystems::from_systems([$first_sys, $($system),*]);
let system = $crate::defer::AsyncSystems::from_systems([$first_sys, $($system),*]);
$crate::util::ComposeExtension::compose(
&mut $commands.entity(out),
system
Expand Down
12 changes: 8 additions & 4 deletions aoui/src/dsl/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub use interpolation::EaseFunction;

/// Return this inside `AsyncSystem` functions.
#[allow(nonstandard_style)]
pub const AsyncOk: Result<(), crate::sync::AsyncFailure> = Ok(());
pub const AsyncOk: Result<(), bevy_defer::AsyncFailure> = Ok(());

pub use crate::events::{
EventFlags, CustomCursor, TrackCursor,
GreaterBoundingBox, GreaterBoundingBoxPx, GreaterBoundingBoxPercent,
Expand All @@ -39,10 +40,10 @@ pub use crate::widgets::{
drag::Dragging,
inputbox::InputOverflow
};
pub use crate::sync:: {
pub use bevy_defer:: {
SigSend, SigRecv, Signals,
AsyncEntityQuery as Aeq, AsyncEntityCommands, AsyncQuery as Aq,
AsyncComponent as Ac, AsyncResource as Ar, Fps,
AsyncComponent as Ac, AsyncResource as Ar,
TypedSignal, RoleSignal, SignalId, SignalMapper,
};

Expand All @@ -61,13 +62,16 @@ pub use crate::{material_sprite, material_mesh};
pub use crate::{padding, paragraph, hstack, vstack, hbox, vbox, linebreak};
pub use crate::{inputbox, button, check_button, radio_button, camera_frame};
pub use crate::rectangle;
pub use crate::signal_ids;
pub use bevy_defer::signal_ids;

pub use crate::util::Fps;

use bevy::ecs::bundle::Bundle;
use bevy::transform::components::GlobalTransform;

pub use crate::util::signal;
pub use crate::widgets::signals::*;
pub use crate::anim::{AsyncInterpolate, AsyncInterpolateVec2};

/// A signal with the sender role.
pub fn sender<T: SignalId>(sig: TypedSignal<T::Data>) -> RoleSignal<T> {
Expand Down
29 changes: 9 additions & 20 deletions aoui/src/dsl/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use bevy::ecs::component::Component;
use bevy::ecs::world::Mut;
use bevy::math::Vec2;
use bevy::text::Text;
use bevy_defer::{AsyncComponent, AsyncResult};
use crate::layout::{Layout, LayoutObject};
use crate::sync::{AsyncComponent, AsyncResult};
use crate::widgets::TextFragment;
use crate::widgets::inputbox::InputBox;
use crate::{Hitbox, HitboxShape, Anchor, SizeUnit, Size};
Expand Down Expand Up @@ -539,8 +539,13 @@ impl WidgetWrite for Mut<'_, TextFragment> {
}
}

impl<C: Component> AsyncComponent<C> where for<'t> &'t mut C: WidgetWrite {
pub async fn write(self, s: impl Into<String>) -> AsyncResult<()> {
#[allow(async_fn_in_trait)]
pub trait WidgetWriteAsync {
async fn write(self, s: impl Into<String>) -> AsyncResult<()>;
}

impl<C: Component> WidgetWriteAsync for AsyncComponent<C> where for<'t> &'t mut C: WidgetWrite {
async fn write(self, s: impl Into<String>) -> AsyncResult<()> {
let s = s.into();
self.set(move |x| x.write(s)).await
}
Expand All @@ -554,20 +559,4 @@ macro_rules! format_widget {
($widget: expr, $s: literal $(,$rest: expr),* $(,)?) => {
$crate::dsl::WidgetWrite::write($widget, format!($s, $($rest),*))
};
}

/// Quickly construct multiple signal_ids at once.
#[macro_export]
macro_rules! signal_ids {
($($(#[$($attr:tt)*])*$name: ident: $ty: ty),* $(,)?) => {
$(
$(#[$($attr)*])*
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum $name {}

impl $crate::sync::SignalId for $name{
type Data = $ty;
}
)*
};
}
}
4 changes: 2 additions & 2 deletions aoui/src/dsl/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use bevy::hierarchy::BuildChildren;

use bevy::text::Font;
use bevy::window::CursorIcon;
use crate::sync::{TypedSignal, Signals};
use crate::util::{Object, ComposeExtension};
use bevy_defer::{TypedSignal, Signals, Object};
use crate::util::ComposeExtension;
use crate::widgets::TextFragment;
use crate::widgets::button::{Payload, Button, CheckButton, RadioButton, RadioButtonCancel, ButtonClick, ToggleChange};
use crate::widgets::util::{SetCursor, PropagateFocus};
Expand Down
2 changes: 1 addition & 1 deletion aoui/src/events/focus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{ecs::{component::Component, query::Has, system::{Query, Res}}, input::{mouse::MouseButton, Input}};

use crate::sync::{SignalId, SignalSender};
use bevy_defer::{SignalId, SignalSender};

use super::{CursorClickOutside, DescendantHasFocus};

Expand Down
3 changes: 2 additions & 1 deletion aoui/src/events/gbb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy::{ecs::{component::Component, system::Query}, hierarchy::Parent, math::Vec2};

use crate::{sync::{SignalId, SignalSender}, util::{Rem, WindowSize}, Anchor, DimensionData, Transform2D};
use crate::{util::{Rem, WindowSize}, Anchor, DimensionData, Transform2D};
use bevy_defer::{SignalId, SignalSender};

/// An signal that calculates the sized of the sprite's bounding
/// rectangle of **offset** or **dimension**.
Expand Down
3 changes: 2 additions & 1 deletion aoui/src/events/wheel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use bevy::{ecs::{component::Component, system::{Resource, Local, Res}}, input::mouse::{MouseWheel, MouseScrollUnit}, math::{Vec2, IVec2}, reflect::Reflect, render::camera::Camera, transform::components::GlobalTransform, window::{Window, PrimaryWindow}};
use bevy::ecs::{system::{Query, Commands}, event::EventReader, query::{With, Without}, entity::Entity};
use bevy_defer::SignalId;

use crate::{widgets::clipping::CameraClip, sync::SignalId};
use crate::widgets::clipping::CameraClip;

use super::{EventFlags, AouiCamera, CursorDetection, ActiveDetection};

Expand Down
12 changes: 8 additions & 4 deletions aoui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ pub mod widgets;
pub mod events;
pub mod anim;

pub mod sync;

//pub mod signals;
pub use core::*;

#[doc(hidden)]
pub use bevy;

#[doc(hidden)]
pub use bevy_defer as defer;

#[doc(hidden)]
pub use bevy_defer::async_system;

pub mod schedule;

pub use schedule::CorePlugin;
Expand All @@ -29,12 +33,12 @@ pub struct AouiPlugin;
impl bevy::prelude::Plugin for AouiPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app
.init_resource::<util::SignalPool>()
.add_plugins(schedule::CorePlugin)
//.add_plugins(signals::SignalsPlugin)
.add_plugins(events::CursorEventsPlugin)
.add_plugins(anim::AnimationPlugin)
.add_plugins(widgets::WidgetsPlugin)
.add_plugins(sync::AsyncExecutorPlugin)
.add_plugins(bevy_defer::DefaultAsyncPlugin)
;
}
}
60 changes: 0 additions & 60 deletions aoui/src/sync/async_system.rs

This file was deleted.

Loading

0 comments on commit 436212d

Please sign in to comment.