Skip to content

Commit 0700320

Browse files
committed
check
1 parent 5b9b257 commit 0700320

File tree

4 files changed

+41
-39
lines changed

4 files changed

+41
-39
lines changed

src/builder.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ mod tests {
865865
app.update();
866866

867867
// Verify the component was mutated correctly.
868-
app.world_mut().entity(entity1);
869868
let component1 = app.world().get::<TestComponent>(entity1).unwrap();
870869
assert_eq!(component1.0, 15, "Component should be 10 + 5 = 15.");
871870

@@ -1428,7 +1427,6 @@ mod tests {
14281427
drop(output_guard);
14291428

14301429
// Reactivity test
1431-
app.world_mut().entity(parent);
14321430
app.world_mut().get_mut::<TestComponent>(parent).unwrap().0 = "Parent B".to_string();
14331431
app.update();
14341432
let mut output_guard = app.world().resource::<TestOutput>().0.lock().unwrap();
@@ -2120,9 +2118,7 @@ mod tests {
21202118

21212119
// Mutate the parent's component again. If the signal was not cleaned up,
21222120
// this could panic when trying to access the despawned child.
2123-
app.world_mut().get_mut::<SourceComponent>(parent).unwrap().0 = "Post-Despawn
2124-
Update"
2125-
.to_string();
2121+
app.world_mut().get_mut::<SourceComponent>(parent).unwrap().0 = "Post-Despawn Update".to_string();
21262122
app.update();
21272123

21282124
// The test passes if the previous update didn't panic.

src/signal.rs

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,12 +1521,15 @@ pub trait SignalExt: Signal {
15211521
Throttle {
15221522
signal: self.map(
15231523
move |In(item): In<Self::Item>, time: Res<Time>, mut timer_option: Local<Option<Timer>>| {
1524+
bevy_log::info!("delta y: {:?}", time.delta());
15241525
match timer_option.as_mut() {
15251526
None => {
15261527
*timer_option = Some(Timer::new(duration, TimerMode::Once));
1528+
bevy_log::info!("delta f: {:?}", time.delta());
15271529
Some(item)
15281530
}
15291531
Some(timer) => {
1532+
bevy_log::info!("delta: {:?}", time.delta());
15301533
if timer.tick(time.delta()).finished() {
15311534
timer.reset();
15321535
Some(item)
@@ -1976,10 +1979,11 @@ mod tests {
19761979
// Import Bevy prelude for MinimalPlugins and other common items
19771980
use bevy::prelude::*;
19781981
use bevy_platform::sync::*;
1979-
use bevy_time::TimeUpdateStrategy;
1982+
use bevy_time::TimePlugin;
19801983

19811984
// Add Duration
19821985
use core::time::Duration;
1986+
use test_log::test;
19831987

19841988
// Helper component and resource for testing Add Default
19851989
#[derive(Component, Clone, Debug, PartialEq, Reflect, Default, Resource)]
@@ -2641,12 +2645,15 @@ mod tests {
26412645

26422646
#[test]
26432647
fn test_throttle() {
2644-
let mut app = create_test_app();
2648+
let mut app = App::new();
2649+
app.add_plugins((MinimalPlugins.build().disable::<TimePlugin>(), JonmoPlugin));
2650+
app.init_resource::<Time>(); // manually managing time for the test
26452651
app.init_resource::<SignalOutput<i32>>();
26462652

26472653
// A simple counter to generate a new value (1, 2, 3...) for each update.
26482654
let source_signal = SignalBuilder::from_system(|_: In<()>, mut counter: Local<i32>| {
26492655
*counter += 1;
2656+
bevy_log::info!("fuck");
26502657
*counter
26512658
});
26522659

@@ -2655,68 +2662,71 @@ mod tests {
26552662
.map(capture_output)
26562663
.register(app.world_mut());
26572664

2658-
// 1. Initial emission: The first value should always pass through.
2665+
// 1. Initial emission: The first update runs with near-zero delta. The first value should always
2666+
// pass.
26592667
app.update();
26602668
assert_eq!(
2661-
get_output(&app.world()),
2669+
get_output(app.world()),
26622670
Some(1),
26632671
"First value (1) should pass immediately."
26642672
);
26652673
// Clear the output to prepare for the next check.
26662674
app.world_mut().resource_mut::<SignalOutput<i32>>().0 = None;
26672675

2668-
// 2. Blocked emission: Advance time by less than the duration. The next value (2) should be
2669-
// blocked.
2676+
// 2. Blocked emission: Manually advance time by 50ms.
26702677
app.world_mut()
2671-
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(50)));
2672-
app.update();
2678+
.resource_mut::<Time>()
2679+
.advance_by(Duration::from_millis(50));
2680+
app.update(); // `time.delta()` is now 50ms. The timer ticks but isn't finished.
26732681
assert_eq!(
2674-
get_output::<i32>(&app.world()),
2682+
get_output::<i32>(app.world()),
26752683
None,
26762684
"Value (2) emitted after 50ms should be blocked."
26772685
);
26782686

2679-
// 3. Another blocked emission: Update again with no time elapsed. The next value (3) should also be
2680-
// blocked.
2687+
// 3. Another blocked emission: Advance time by another 40ms (total 90ms).
26812688
app.world_mut()
2682-
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(0)));
2683-
app.update();
2689+
.resource_mut::<Time>()
2690+
.advance_by(Duration::from_millis(40));
2691+
app.update(); // `time.delta()` is 40ms. Timer ticks to 90ms. Still not finished.
26842692
assert_eq!(
2685-
get_output::<i32>(&app.world()),
2693+
get_output::<i32>(app.world()),
26862694
None,
2687-
"Value (3) emitted immediately after should also be blocked."
2695+
"Value (3) emitted after 90ms total should be blocked."
26882696
);
2689-
2690-
// 4. Allowed emission: Advance time past the threshold (50ms from step 2 + 60ms now = 110ms total).
2697+
app.world_mut().entity(**handle);
2698+
// 4. Allowed emission: Advance time by another 20ms (total 110ms).
26912699
app.world_mut()
2692-
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(60)));
2693-
app.update();
2700+
.resource_mut::<Time>()
2701+
.advance_by(Duration::from_millis(20));
2702+
app.update(); // `time.delta()` is 20ms. Timer ticks to 110ms, which is >= 100ms.
26942703
// The source signal has been called 4 times now. The value should be 4.
26952704
assert_eq!(
2696-
get_output(&app.world()),
2705+
get_output(app.world()),
26972706
Some(4),
26982707
"Value (4) should pass after total duration > 100ms."
26992708
);
27002709
app.world_mut().resource_mut::<SignalOutput<i32>>().0 = None;
27012710

2702-
// 5. Blocked again: Immediately after an emission, the timer resets, so the next value (5) is
2703-
// blocked.
2711+
// 5. Blocked again: The timer was reset on the last pass. A small advance is not enough.
27042712
app.world_mut()
2705-
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(10)));
2713+
.resource_mut::<Time>()
2714+
.advance_by(Duration::from_millis(10));
27062715
app.update();
27072716
assert_eq!(
2708-
get_output::<i32>(&app.world()),
2717+
get_output::<i32>(app.world()),
27092718
None,
27102719
"Value (5) immediately after a pass should be blocked again."
27112720
);
27122721

27132722
// 6. Pass again: Advance time to pass the threshold again.
27142723
app.world_mut()
2715-
.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(100)));
2724+
.resource_mut::<Time>()
2725+
.advance_by(Duration::from_millis(100));
27162726
app.update();
27172727
// The source signal has now been called 6 times. The value should be 6.
27182728
assert_eq!(
2719-
get_output(&app.world()),
2729+
get_output(app.world()),
27202730
Some(6),
27212731
"Value (6) should pass again after another full duration."
27222732
);

src/signal_map.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,10 +977,9 @@ impl<K, V> MutableBTreeMap<K, V> {
977977
V: Clone + SSs,
978978
{
979979
let replay_lazy_signal = LazySignal::new(clone!((self => self_) move |world: &mut World| {
980-
let self_entity = LazyEntity::new();
981980
let broadcaster_system = world.get::<MutableBTreeMapData<K, V>>(self_.entity).unwrap().broadcaster.clone().register(world);
982981

983-
let replay_system_logic = clone!((self_entity, self_) move |In(upstream_diffs): In<Vec<MapDiff<K, V>>>, world: &mut World, mut has_run: Local<bool>| {
982+
let replay_system_logic = clone!((self_) move |In(upstream_diffs): In<Vec<MapDiff<K, V>>>, world: &mut World, mut has_run: Local<bool>| {
984983
if !*has_run {
985984
*has_run = true;
986985
let initial_map = self_.read(&*world);
@@ -993,7 +992,6 @@ impl<K, V> MutableBTreeMap<K, V> {
993992
});
994993

995994
let replay_signal = register_signal::<_, Vec<MapDiff<K, V>>, _, _, _>(world, replay_system_logic);
996-
self_entity.set(*replay_signal);
997995

998996
let trigger = Box::new(move |world: &mut World| {
999997
process_signals(world, [replay_signal], Box::new(Vec::<MapDiff<K, V>>::new()));

src/signal_vec.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3758,10 +3758,9 @@ impl<T> MutableVec<T> {
37583758
T: Clone + SSs,
37593759
{
37603760
let replay_lazy_signal = LazySignal::new(clone!((self => self_) move |world: &mut World| {
3761-
let self_entity = LazyEntity::new();
37623761
let broadcaster_system = world.get::<MutableVecData<T>>(self_.entity).unwrap().broadcaster.clone().register(world);
37633762

3764-
let replay_system_logic = clone!((self_entity, self_) move |In(upstream_diffs): In<Vec<VecDiff<T>>>, world: &mut World, mut has_run: Local<bool>| {
3763+
let replay_system_logic = clone!((self_) move |In(upstream_diffs): In<Vec<VecDiff<T>>>, world: &mut World, mut has_run: Local<bool>| {
37653764
if !*has_run {
37663765
*has_run = true;
37673766
let initial_vec = self_.read(&*world).to_vec();
@@ -3774,7 +3773,6 @@ impl<T> MutableVec<T> {
37743773
});
37753774

37763775
let replay_signal = register_signal::<_, Vec<VecDiff<T>>, _, _, _>(world, replay_system_logic);
3777-
self_entity.set(*replay_signal);
37783776

37793777
let trigger = Box::new(move |world: &mut World| {
37803778
process_signals(world, [replay_signal], Box::new(Vec::<VecDiff<T>>::new()));
@@ -4006,7 +4004,7 @@ pub(crate) mod tests {
40064004
use crate::JonmoPlugin;
40074005
use bevy::prelude::*;
40084006
use bevy_platform::sync::RwLock;
4009-
use test_log;
4007+
use test_log::test;
40104008

40114009
#[derive(Resource, Default, Debug)]
40124010
struct SignalVecOutput<T: Clone + fmt::Debug>(Vec<VecDiff<T>>);
@@ -5085,7 +5083,7 @@ pub(crate) mod tests {
50855083
cleanup(true)
50865084
}
50875085

5088-
#[test_log::test]
5086+
#[test]
50895087
fn test_filter_map() {
50905088
{
50915089
// A comprehensive test for `SignalVecExt::filter_map`, covering all `VecDiff`

0 commit comments

Comments
 (0)