Skip to content

Commit

Permalink
Update code for YieldProgress deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Sep 6, 2023
1 parent 80e7033 commit b541ff7
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 63 deletions.
2 changes: 1 addition & 1 deletion all-is-cubes-content/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ criterion = { workspace = true, features = ["async_futures"] }
pretty_assertions = { workspace = true }
# Using tokio for async test-running.
tokio = { workspace = true, features = ["macros", "rt"] }

yield-progress = { workspace = true }
4 changes: 2 additions & 2 deletions all-is-cubes-content/benches/gen_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;

use strum::IntoEnumIterator as _;

use all_is_cubes::util::YieldProgress;
use all_is_cubes::util::yield_progress_for_testing;
use all_is_cubes_content::{TemplateParameters, UniverseTemplate};

pub fn template_bench(c: &mut Criterion) {
Expand All @@ -26,7 +26,7 @@ pub fn template_bench(c: &mut Criterion) {
group.bench_function(&format!("{template}"), |b| {
b.to_async(FuturesExecutor).iter_with_large_drop(|| {
template.clone().build::<std::time::Instant>(
YieldProgress::noop(),
yield_progress_for_testing(),
TemplateParameters {
seed: Some(0),
size: None,
Expand Down
5 changes: 3 additions & 2 deletions all-is-cubes-content/src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,13 @@ fn square_radius(resolution: Resolution, cube: Cube) -> [GridCoordinate; 2] {
#[cfg(test)]
mod tests {
use super::*;
use all_is_cubes::content::make_some_blocks;
use crate::make_some_blocks;
use all_is_cubes::util::yield_progress_for_testing;

#[tokio::test]
pub async fn install_demo_blocks_test() {
let mut universe = Universe::new();
install_demo_blocks(&mut universe, YieldProgress::noop())
install_demo_blocks(&mut universe, yield_progress_for_testing())
.await
.unwrap();
// TODO: assert what entries were created, once Universe has iteration
Expand Down
11 changes: 6 additions & 5 deletions all-is-cubes-content/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,15 @@ async fn arbitrary_space(
mod tests {
use super::*;
use all_is_cubes::time;
use all_is_cubes::util::yield_progress_for_testing;
use futures_core::future::BoxFuture;

#[allow(clippy::let_underscore_future)]
fn _test_build_future_is_send() {
let _: BoxFuture<'_, _> = Box::pin(
UniverseTemplate::Atrium
.build::<std::time::Instant>(YieldProgress::noop(), TemplateParameters::default()),
);
let _: BoxFuture<'_, _> = Box::pin(UniverseTemplate::Atrium.build::<std::time::Instant>(
yield_progress_for_testing(),
TemplateParameters::default(),
));
}

pub(super) async fn check_universe_template(template: UniverseTemplate) {
Expand All @@ -488,7 +489,7 @@ mod tests {

let result = template
.clone()
.build::<std::time::Instant>(YieldProgress::noop(), params)
.build::<std::time::Instant>(yield_progress_for_testing(), params)
.await;

if matches!(template, UniverseTemplate::Fail) {
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tui = { version = "0.19.0", default-features = false, features = ["crossterm"] }
unicode-width = { version = "0.1.9", default-features = false }
# Note on feature selection: winit requires either "x11" or "wayland" to build at all on Linux, which is harmless elsewhere. I picked x11 because it should be the most compatible.
winit = { version = "0.28.1", default-features = false, features = ["x11"] }
# Enable the log-hiccups feature
# Enable the log_hiccups feature
yield-progress = { workspace = true, features = ["log_hiccups"] }

[dev-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions all-is-cubes-desktop/src/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ pub(crate) trait Window {
impl Window for () {
fn set_title(&self, _title: String) {}
}

pub(crate) fn tokio_yield_progress() -> yield_progress::Builder {
yield_progress::Builder::new().yield_using(|_| tokio::task::yield_now())
}
14 changes: 6 additions & 8 deletions all-is-cubes-desktop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ use all_is_cubes::cgmath::{Vector2, Zero as _};
use all_is_cubes::listen::ListenableCell;
use all_is_cubes::space::{LightUpdatesInfo, Space};
use all_is_cubes::universe::Universe;
use all_is_cubes::util::YieldProgress;
use all_is_cubes_content::TemplateParameters;

mod aic_winit;
Expand Down Expand Up @@ -366,13 +365,12 @@ async fn create_universe(
universe_progress_bar.set_position(0);
let yield_progress = {
let universe_progress_bar = universe_progress_bar.clone();
YieldProgress::new(
|| std::future::ready(()),
move |fraction, label| {
universe_progress_bar.set_position((fraction * 100.0) as u64);
universe_progress_bar.set_message(String::from(label));
},
)
glue::tokio_yield_progress()
.progress_using(move |info| {
universe_progress_bar.set_position((info.fraction() * 100.0) as u64);
universe_progress_bar.set_message(String::from(info.label_str()));
})
.build()
};
let universe = match input_source.clone() {
UniverseSource::Template(template, TemplateParameters { seed, size }) => {
Expand Down
3 changes: 1 addition & 2 deletions all-is-cubes-desktop/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use all_is_cubes::camera::{Flaws, StandardCameras};
use all_is_cubes::listen::{self, ListenableSource};
use all_is_cubes::raytracer::RtRenderer;
use all_is_cubes::universe::Universe;
use all_is_cubes::util::YieldProgress;
use all_is_cubes_port::gltf::{GltfDataDestination, GltfWriter};
use all_is_cubes_port::{ExportFormat, ExportSet};

Expand Down Expand Up @@ -212,7 +211,7 @@ impl Recorder {
runtime_handle
.block_on(all_is_cubes_port::export_to_path(
// TODO: hook up a progress bar
YieldProgress::noop(),
crate::glue::tokio_yield_progress().build(),
export_format,
export_set,
options.output_path.clone(),
Expand Down
3 changes: 1 addition & 2 deletions all-is-cubes-desktop/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::time::{Duration, Instant};
use all_is_cubes::camera::Viewport;
use all_is_cubes::listen::{DirtyFlag, ListenableCell, Listener};
use all_is_cubes::universe::UniverseStepInfo;
use all_is_cubes::util::YieldProgress;

use crate::record;
use crate::Session;
Expand Down Expand Up @@ -133,7 +132,7 @@ impl<Ren, Win: crate::glue::Window> DesktopSession<Ren, Win> {
// Also a progress bar and other UI.
self.session.set_universe_async(async move {
let universe = all_is_cubes_port::load_universe_from_file(
YieldProgress::noop(),
crate::glue::tokio_yield_progress().build(),
Arc::new(path.clone()),
)
.await
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-port/src/gltf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use all_is_cubes::camera::GraphicsOptions;
use all_is_cubes::content::{make_some_blocks, make_some_voxel_blocks};
use all_is_cubes::space::Space;
use all_is_cubes::universe::{Name, URef, Universe};
use all_is_cubes::util::YieldProgress;
use all_is_cubes::util::yield_progress_for_testing;
use all_is_cubes_mesh::{block_meshes_for_space, MeshOptions, SpaceMesh};

use crate::{ExportError, ExportFormat, ExportSet};
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn export_block_defs() {
let destination: PathBuf = destination_dir.path().join("export_block_defs.gltf");

crate::export_to_path(
YieldProgress::noop(),
yield_progress_for_testing(),
ExportFormat::Gltf,
ExportSet::from_block_defs(block_defs),
PathBuf::from(&destination),
Expand All @@ -116,7 +116,7 @@ async fn export_space_not_supported() {
let destination: PathBuf = destination_dir.path().join("foo.gltf");

let error = crate::export_to_path(
YieldProgress::noop(),
yield_progress_for_testing(),
ExportFormat::Gltf,
ExportSet::all_of_universe(&universe),
destination,
Expand Down
29 changes: 18 additions & 11 deletions all-is-cubes-port/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ mod tests {
use all_is_cubes::block::BlockDef;
use all_is_cubes::raytracer::print_space;
use all_is_cubes::universe::URef;
use all_is_cubes::util::yield_progress_for_testing;
use either::Either;

#[test]
Expand Down Expand Up @@ -364,7 +365,9 @@ mod tests {

#[tokio::test]
async fn invalid_file_error() {
let error = load_dot_vox(YieldProgress::noop(), &[]).await.unwrap_err();
let error = load_dot_vox(yield_progress_for_testing(), &[])
.await
.unwrap_err();
assert!(
matches!(
error,
Expand All @@ -379,12 +382,12 @@ mod tests {
) -> Result<Universe, Either<ExportError, DotVoxConversionError>> {
// TODO: also roundtrip through bytes, for maximum rigor
let data = export_to_dot_vox_data(
YieldProgress::noop(),
yield_progress_for_testing(),
ExportSet::all_of_universe(export_universe),
)
.await
.map_err(Either::Left)?;
dot_vox_data_to_universe(YieldProgress::noop(), &data)
dot_vox_data_to_universe(yield_progress_for_testing(), &data)
.await
.map_err(Either::Right)
}
Expand Down Expand Up @@ -451,10 +454,12 @@ mod tests {
Space::builder(GridAab::from_lower_size([0, 0, 0], [257, 1, 1])).build(),
);

let error =
export_to_dot_vox_data(YieldProgress::noop(), ExportSet::from_spaces(vec![space]))
.await
.unwrap_err();
let error = export_to_dot_vox_data(
yield_progress_for_testing(),
ExportSet::from_spaces(vec![space]),
)
.await
.unwrap_err();
assert!(matches!(error, ExportError::NotRepresentable { .. }));
}

Expand All @@ -465,10 +470,12 @@ mod tests {
.insert("x".into(), BlockDef::new(block::AIR))
.unwrap();

let error =
export_to_dot_vox_data(YieldProgress::noop(), ExportSet::all_of_universe(&universe))
.await
.unwrap_err();
let error = export_to_dot_vox_data(
yield_progress_for_testing(),
ExportSet::all_of_universe(&universe),
)
.await
.unwrap_err();
assert!(matches!(
error,
ExportError::NotRepresentable {
Expand Down
11 changes: 6 additions & 5 deletions all-is-cubes-port/src/native/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;

use all_is_cubes::block;
use all_is_cubes::universe::{Name, URef};
use all_is_cubes::util::YieldProgress;
use all_is_cubes::util::yield_progress_for_testing;

use crate::{export_to_path, load_universe_from_file, ExportSet};

Expand All @@ -14,9 +14,10 @@ async fn import_export_native_format() {
env!("CARGO_MANIFEST_DIR"),
"/src/native/tests/native-test.alliscubesjson"
));
let universe = load_universe_from_file(YieldProgress::noop(), Arc::new(import_path.clone()))
.await
.unwrap();
let universe =
load_universe_from_file(yield_progress_for_testing(), Arc::new(import_path.clone()))
.await
.unwrap();

assert_eq!(
universe.whence.document_name(),
Expand All @@ -32,7 +33,7 @@ async fn import_export_native_format() {
let destination_dir = tempfile::tempdir().unwrap();
let destination: PathBuf = destination_dir.path().join("foo.alliscubesjson");
export_to_path(
YieldProgress::noop(),
yield_progress_for_testing(),
crate::ExportFormat::AicJson,
ExportSet::all_of_universe(&universe),
destination.to_path_buf(),
Expand Down
3 changes: 2 additions & 1 deletion all-is-cubes-port/src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ mod tests {
use all_is_cubes::content::make_some_voxel_blocks;
use all_is_cubes::content::testing::lighting_bench_space;
use all_is_cubes::universe::{Name, URef, Universe};
use all_is_cubes::util::yield_progress_for_testing;
use std::collections::BTreeSet;
use std::path::PathBuf;

Expand Down Expand Up @@ -150,7 +151,7 @@ mod tests {
let destination: PathBuf = destination_dir.path().join("foo.stl");

crate::export_to_path(
YieldProgress::noop(),
yield_progress_for_testing(),
ExportFormat::Stl,
ExportSet::from_block_defs(block_defs),
destination,
Expand Down
7 changes: 3 additions & 4 deletions all-is-cubes-port/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::error::Error as _;
use std::sync::Arc;

use all_is_cubes::block;
use all_is_cubes::util::assert_send_sync;
use all_is_cubes::util::{assert_send_sync, yield_progress_for_testing};

use crate::file::NonDiskFile;
use crate::{
load_universe_from_file, BlockDef, ExportError, ExportSet, ImportError, Path, PathBuf,
Universe, YieldProgress,
load_universe_from_file, BlockDef, ExportError, ExportSet, ImportError, Path, PathBuf, Universe,
};

#[test]
Expand All @@ -19,7 +18,7 @@ fn errors_are_send_sync() {
#[tokio::test]
async fn import_unknown_format() {
let error = load_universe_from_file(
YieldProgress::noop(),
yield_progress_for_testing(),
Arc::new(NonDiskFile::from_name_and_data_source("foo".into(), || {
Ok(b"nonsense".to_vec())
})),
Expand Down
9 changes: 7 additions & 2 deletions all-is-cubes-ui/src/ui_content/vui_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use all_is_cubes::space::Space;
use all_is_cubes::time;
use all_is_cubes::transaction::{self, Transaction};
use all_is_cubes::universe::{URef, Universe, UniverseStepInfo};
use all_is_cubes::util::YieldProgress;

use crate::apps::{ControlMessage, FullscreenSetter, FullscreenState, InputProcessor};
use crate::ui_content::hud::{HudBlocks, HudInputs};
Expand Down Expand Up @@ -83,7 +82,13 @@ impl Vui {
) -> Self {
let mut universe = Universe::new();
// TODO: take YieldProgress as a parameter
let hud_blocks = Arc::new(HudBlocks::new(&mut universe, YieldProgress::noop()).await);
let hud_blocks = Arc::new(
HudBlocks::new(
&mut universe,
all_is_cubes::util::YieldProgressBuilder::new().build(),
)
.await,
);

let (control_send, control_recv) = mpsc::sync_channel(100);
let state = ListenableCell::new(VuiPageState::Hud);
Expand Down
3 changes: 2 additions & 1 deletion all-is-cubes-ui/src/vui/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,10 @@ impl fmt::Display for ToolbarButtonState {
#[cfg(test)]
mod tests {
use super::*;
use all_is_cubes::util::yield_progress_for_testing;

#[tokio::test]
async fn blocks_smoke_test() {
UiBlocks::new(&mut Universe::new(), YieldProgress::noop()).await;
UiBlocks::new(&mut Universe::new(), yield_progress_for_testing()).await;
}
}
4 changes: 2 additions & 2 deletions all-is-cubes-ui/src/vui/widgets/tooltip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ impl WidgetController for TooltipController {
#[cfg(test)]
mod tests {
use super::*;
use all_is_cubes::util::YieldProgress;
use all_is_cubes::util::yield_progress_for_testing;

#[tokio::test]
async fn tooltip_timeout_and_dirty_text() {
// TODO: reduce boilerplate
let mut universe = Universe::new();
let hud_blocks = &HudBlocks::new(&mut universe, YieldProgress::noop()).await;
let hud_blocks = &HudBlocks::new(&mut universe, yield_progress_for_testing()).await;

// Initial state: no update.
let mut t = TooltipState::default();
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ send_wrapper = "0.6.0"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = { workspace = true }
wgpu = { workspace = true, features = ["webgl"] }
# Enable the log-hiccups feature
# Enable the log_hiccups feature
yield-progress = { workspace = true, features = ["log_hiccups"] }

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-wasm/src/gameapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl WebSession {
SendWrapper::new(buffer.dyn_into().unwrap());
// TODO: error reporting
let universe = all_is_cubes_port::load_universe_from_file(
YieldProgress::noop(),
yield ::noop(),
Arc::new(NonDiskFile::from_name_and_data_source(
found_file.name(),
move || Ok(Uint8Array::new(&buffer).to_vec()),
Expand Down
Loading

0 comments on commit b541ff7

Please sign in to comment.