Skip to content

Commit

Permalink
listen: Un-rename items after the migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Dec 20, 2024
1 parent c4603c5 commit 30b6c5f
Show file tree
Hide file tree
Showing 25 changed files with 108 additions and 121 deletions.
7 changes: 4 additions & 3 deletions all-is-cubes-desktop/src/bin/all-is-cubes/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use anyhow::Context;
use clap::{CommandFactory as _, Parser as _};

use all_is_cubes::euclid::Size2D;
use all_is_cubes::listen::ListenableCell;
use all_is_cubes::listen;
use all_is_cubes_render::camera::{GraphicsOptions, Viewport};

#[cfg(feature = "record")]
Expand Down Expand Up @@ -95,7 +95,7 @@ fn main() -> Result<(), anyhow::Error> {
// window size. This is a kludge because the `Session`'s `Vui` wants to be able to track
// the viewport aspect ratio. It would be nice to have a better strategy, but at least
// this is mostly confined to initialization.
let viewport_cell = ListenableCell::new(Viewport::with_scale(
let viewport_cell = listen::Cell::new(Viewport::with_scale(
1.0,
display_size.unwrap_or_else(Size2D::zero).cast_unit(),
));
Expand Down Expand Up @@ -180,7 +180,8 @@ fn main() -> Result<(), anyhow::Error> {
if graphics_type == GraphicsType::WindowRt {
// TODO: improve on this kludge by just having a general cmdline graphics config
dsession.session.graphics_options_mut().update_mut(|o| {
Arc::make_mut(o).render_method = all_is_cubes_render::camera::RenderMethod::Reference;
Arc::make_mut(o).render_method =
all_is_cubes_render::camera::RenderMethod::Reference;
});
}
Ok(dsession)
Expand Down
10 changes: 5 additions & 5 deletions all-is-cubes-desktop/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};

use all_is_cubes::arcstr;
use all_is_cubes::listen::{DirtyFlag, ListenableCell};
use all_is_cubes::listen;
#[cfg(doc)]
use all_is_cubes::universe::Universe;
use all_is_cubes::universe::UniverseStepInfo;
Expand Down Expand Up @@ -44,7 +44,7 @@ pub struct DesktopSession<Ren, Win> {
gilrs: Option<gilrs::Gilrs>,

/// The current viewport size linked to the renderer.
pub(crate) viewport_cell: ListenableCell<Viewport>,
pub(crate) viewport_cell: listen::Cell<Viewport>,
pub(crate) clock_source: ClockSource,

/// If present, connection to system audio output.
Expand All @@ -60,7 +60,7 @@ pub struct DesktopSession<Ren, Win> {

/// Flag for `Session` might have changed its `Universe`, or otherwise done something that
/// requires the window title to change.
session_info_altered: DirtyFlag,
session_info_altered: listen::Flag,
}

impl<Ren, Win: crate::glue::Window> DesktopSession<Ren, Win> {
Expand All @@ -70,7 +70,7 @@ impl<Ren, Win: crate::glue::Window> DesktopSession<Ren, Win> {
renderer: Ren,
window: Win,
session: Session,
viewport_cell: ListenableCell<Viewport>,
viewport_cell: listen::Cell<Viewport>,
enable_gamepad_input: bool,
) -> Self {
// TODO: There should be one of this for the whole event loop, not per session
Expand All @@ -87,7 +87,7 @@ impl<Ren, Win: crate::glue::Window> DesktopSession<Ren, Win> {
};

let new_self = Self {
session_info_altered: DirtyFlag::listening(false, session.universe_info()),
session_info_altered: listen::Flag::listening(false, session.universe_info()),

session,
executor,
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-desktop/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ratatui::layout::Rect;

use all_is_cubes::arcstr::literal_substr;
use all_is_cubes::euclid::{Point2D, Size2D};
use all_is_cubes::listen::{self, ListenableCell};
use all_is_cubes::listen;
use all_is_cubes::math::Rgba;
use all_is_cubes_render::camera::{self, Camera, StandardCameras, Viewport};
use all_is_cubes_render::raytracer::{
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn create_terminal_session(
executor: Arc<crate::Executor>,
session: Session,
options: TerminalOptions,
viewport_cell: ListenableCell<Viewport>,
viewport_cell: listen::Cell<Viewport>,
) -> Result<DesktopSession<TerminalRenderer, TerminalWindow>, anyhow::Error> {
viewport_cell.set(options.viewport_from_terminal_size(rect_size(Rect::default())));
let cameras = session.create_cameras(viewport_cell.as_source());
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-desktop/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use winit::event_loop::{ActiveEventLoop, ControlFlow};
use winit::window::{CursorGrabMode, Window};

use all_is_cubes::euclid::{Point2D, Size2D};
use all_is_cubes::listen::ListenableCell;
use all_is_cubes::listen;
use all_is_cubes_gpu::in_wgpu::SurfaceRenderer;
use all_is_cubes_render::camera::{self, StandardCameras, Viewport};

Expand Down Expand Up @@ -169,7 +169,7 @@ pub async fn create_winit_wgpu_desktop_session(
executor: Arc<crate::Executor>,
session: Session,
window: WinAndState,
viewport_cell: ListenableCell<Viewport>,
viewport_cell: listen::Cell<Viewport>,
) -> Result<DesktopSession<SurfaceRenderer<Instant>, WinAndState>, anyhow::Error> {
let start_time = Instant::now();

Expand Down
10 changes: 5 additions & 5 deletions all-is-cubes-gpu/src/common/reloadable.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//! “Hot-reloadable” data sources such as shaders.
//!
//! This module builds on top of the `resource` library to add change notification
//! via a background thread and all-is-cubes's `ListenableCell` mechanism.
//! via a background thread and all-is-cubes's `listen::Cell` mechanism.
use std::sync::{Arc, LazyLock, Mutex, PoisonError};
use std::time::Duration;

use resource::Resource;

use all_is_cubes::listen::{self, ListenableCell};
use all_is_cubes::listen;

#[derive(Clone)]
pub(crate) struct Reloadable(Arc<ReloadableInner>);

pub(crate) struct ReloadableInner {
resource: Mutex<Resource<str>>,
cell: ListenableCell<Arc<str>>,
cell: listen::Cell<Arc<str>>,
}

/// `file_path` is relative to the Cargo package root.
Expand All @@ -29,7 +29,7 @@ pub(crate) use reloadable_str;
impl Reloadable {
pub fn new(resource: Resource<str>) -> Self {
let this = Reloadable(Arc::new(ReloadableInner {
cell: ListenableCell::new(res_arc_str(&resource)),
cell: listen::Cell::new(res_arc_str(&resource)),
resource: Mutex::new(resource),
}));

Expand All @@ -46,7 +46,7 @@ impl Reloadable {
Ok(resource) => {
let changed = resource.reload_if_changed();
if changed {
// unfortunately ListenableCell wants an Arc with Sized contents
// unfortunately listen::Cell wants an Arc with Sized contents
self.0.cell.set(res_arc_str(resource));
}
changed
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-gpu/src/in_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use all_is_cubes::character::Cursor;
use all_is_cubes::content::palette;
use all_is_cubes::drawing::embedded_graphics::{pixelcolor::Gray8, Drawable as _};
use all_is_cubes::euclid::Size2D;
use all_is_cubes::listen::DirtyFlag;
use all_is_cubes::listen;
use all_is_cubes::math::VectorOps as _;
use all_is_cubes_render::camera::{Layers, RenderMethod, StandardCameras};
use all_is_cubes_render::info_text_drawable;
Expand Down Expand Up @@ -112,7 +112,7 @@ pub struct SurfaceRenderer<I: time::Instant> {
everything: EverythingRenderer<I>,

/// True if we need to reconfigure the surface.
viewport_dirty: DirtyFlag,
viewport_dirty: listen::Flag,
}

impl<I: time::Instant> SurfaceRenderer<I> {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<I: time::Instant> SurfaceRenderer<I> {
);

Ok(Self {
viewport_dirty: DirtyFlag::listening(true, &viewport_source),
viewport_dirty: listen::Flag::listening(true, &viewport_source),
everything,
surface,
device,
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-gpu/src/in_wgpu/block_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl texture::Tile for AtlasTile {
//
// * a redundant setting of the AllocatorBacking::dirty flag.
// * this write() blocking until flush() finishes (this could be fixed with
// making the dirty flag a `DirtyFlag` (atomic bool based) instead of being
// making the dirty flag a `Flag` (atomic bool based) instead of being
// inside the lock).
//
// It should always be the case that a write() then flush() will actually
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-gpu/src/in_wgpu/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use futures_channel::oneshot;
use futures_core::future::BoxFuture;

use all_is_cubes::character::Cursor;
use all_is_cubes::listen::{self, DirtyFlag};
use all_is_cubes::listen;
use all_is_cubes::util::Executor;
use all_is_cubes_render::camera::{StandardCameras, Viewport};
use all_is_cubes_render::{Flaws, HeadlessRenderer, RenderError, Rendering};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Builder {
&self.adapter,
);

let viewport_dirty = DirtyFlag::listening(false, &viewport_source);
let viewport_dirty = listen::Flag::listening(false, &viewport_source);
let viewport = viewport_source.get();
let color_texture = create_color_texture(&self.device, viewport);

Expand Down Expand Up @@ -105,7 +105,7 @@ struct RendererImpl {
color_texture: wgpu::Texture,
everything: super::EverythingRenderer<AdaptedInstant>,
viewport_source: listen::DynSource<Viewport>,
viewport_dirty: DirtyFlag,
viewport_dirty: listen::Flag,
flaws: Flaws,
}

Expand Down
5 changes: 2 additions & 3 deletions all-is-cubes-gpu/src/in_wgpu/pipelines.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::mem;
use std::sync::Arc;

use all_is_cubes::listen::DirtyFlag;
use all_is_cubes::listen::{self, Listen as _};
use all_is_cubes_render::camera::{GraphicsOptions, TransparencyOption};

Expand All @@ -24,7 +23,7 @@ use crate::in_wgpu::vertex::WgpuLinesVertex;
#[derive(Debug)]
pub(crate) struct Pipelines {
/// Tracks whether we need to rebuild pipelines for any reasons.
dirty: DirtyFlag,
dirty: listen::Flag,

graphics_options: listen::DynSource<Arc<GraphicsOptions>>,

Expand Down Expand Up @@ -511,7 +510,7 @@ impl Pipelines {
..Default::default()
});

let dirty = DirtyFlag::new(false);
let dirty = listen::Flag::new(false);
shaders.listen(dirty.listener());
graphics_options.listen(dirty.listener());

Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-gpu/src/in_wgpu/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ impl listen::Listen for Shaders {
pub(crate) struct ReloadableShader {
label: String,
source: listen::DynSource<Arc<str>>,
dirty: listen::DirtyFlag,
dirty: listen::Flag,
current_module: Identified<wgpu::ShaderModule>,
next_module: Option<BoxFuture<'static, Result<wgpu::ShaderModule, wgpu::Error>>>,
}

impl ReloadableShader {
fn new(device: &wgpu::Device, label: String, wgsl_source: listen::DynSource<Arc<str>>) -> Self {
let dirty = listen::DirtyFlag::listening(false, &wgsl_source);
let dirty = listen::Flag::listening(false, &wgsl_source);
let current_module =
Identified::new(device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some(&label),
Expand Down
30 changes: 15 additions & 15 deletions all-is-cubes-render/src/camera/stdcam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use alloc::sync::Arc;
use core::fmt;

use all_is_cubes::character::{cursor_raycast, Character, Cursor};
use all_is_cubes::listen::{self, DirtyFlag, ListenableCell};
use all_is_cubes::listen;
use all_is_cubes::math::FreeCoordinate;
use all_is_cubes::space::Space;
use all_is_cubes::universe::{Handle, Universe};
Expand Down Expand Up @@ -79,22 +79,22 @@ impl<T> Layers<T> {
pub struct StandardCameras {
/// Cameras are synced with this
graphics_options: listen::DynSource<Arc<GraphicsOptions>>,
graphics_options_dirty: DirtyFlag,
graphics_options_dirty: listen::Flag,

character_source: listen::DynSource<Option<Handle<Character>>>,
/// Tracks whether the character was replaced (not whether its view changed).
character_dirty: DirtyFlag,
character_dirty: listen::Flag,
character: Option<Handle<Character>>,
/// Cached and listenable version of character's space.
/// TODO: This should be in a `Layers` along with `ui_state`...?
world_space: ListenableCell<Option<Handle<Space>>>,
world_space: listen::Cell<Option<Handle<Space>>>,

ui_source: listen::DynSource<Arc<UiViewState>>,
ui_dirty: DirtyFlag,
ui_dirty: listen::Flag,
ui_space: Option<Handle<Space>>,

viewport_source: listen::DynSource<Viewport>,
viewport_dirty: DirtyFlag,
viewport_dirty: listen::Flag,

cameras: Layers<Camera>,
}
Expand All @@ -112,8 +112,8 @@ impl StandardCameras {
// TODO: Add a unit test that each of these listeners works as intended.
// TODO: This is also an awful lot of repetitive code; we should design a pattern
// to not have it (some kind of "following cell")?
let graphics_options_dirty = DirtyFlag::listening(false, &graphics_options);
let viewport_dirty = DirtyFlag::listening(false, &viewport_source);
let graphics_options_dirty = listen::Flag::listening(false, &graphics_options);
let viewport_dirty = listen::Flag::listening(false, &viewport_source);

let initial_options: &GraphicsOptions = &graphics_options.get();
let initial_viewport: Viewport = viewport_source.get();
Expand All @@ -129,13 +129,13 @@ impl StandardCameras {
graphics_options,
graphics_options_dirty,

character_dirty: DirtyFlag::listening(true, &character_source),
character_dirty: listen::Flag::listening(true, &character_source),
character_source,
character: None, // update() will fix these up
world_space: ListenableCell::new(None),
world_space: listen::Cell::new(None),

ui_space: ui_state.space.clone(),
ui_dirty: DirtyFlag::listening(true, &ui_source),
ui_dirty: listen::Flag::listening(true, &ui_source),
ui_source,

viewport_dirty,
Expand Down Expand Up @@ -229,7 +229,7 @@ impl StandardCameras {
self.cameras.world.set_view_transform(character.view());
}

// TODO: ListenableCell should make this easier and cheaper
// TODO: listen::Cell should make this easier and cheaper
if Option::as_ref(&self.world_space.get()) != Some(&character.space) {
anything_changed = true;

Expand Down Expand Up @@ -409,7 +409,7 @@ mod tests {

#[test]
fn cameras_follow_character_and_world() {
let character_cell = ListenableCell::new(None);
let character_cell = listen::Cell::new(None);
let mut cameras = StandardCameras::new(
listen::constant(Arc::new(GraphicsOptions::default())),
listen::constant(Viewport::ARBITRARY),
Expand All @@ -418,7 +418,7 @@ mod tests {
);

let world_source = cameras.world_space();
let world_flag = DirtyFlag::listening(false, &world_source);
let world_flag = listen::Flag::listening(false, &world_source);
assert_eq!(world_source.get().as_ref(), None);

// No redundant notification when world is absent
Expand Down Expand Up @@ -451,7 +451,7 @@ mod tests {

#[test]
fn cameras_clone() {
let options_cell = ListenableCell::new(Arc::new(GraphicsOptions::default()));
let options_cell = listen::Cell::new(Arc::new(GraphicsOptions::default()));
let mut cameras = StandardCameras::new(
options_cell.as_source(),
listen::constant(Viewport::ARBITRARY),
Expand Down
3 changes: 1 addition & 2 deletions all-is-cubes-render/src/raytracer/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ mod eg {
#[cfg(test)]
mod tests {
use super::*;
use all_is_cubes::listen::ListenableCell;
use all_is_cubes::universe::Universe;
use all_is_cubes::util::assert_conditional_send_sync;
use core::convert::identity;
Expand Down Expand Up @@ -694,7 +693,7 @@ mod tests {
);

// Change the options after the renderer is created.
let custom_options = ListenableCell::new(Arc::new("before"));
let custom_options = listen::Cell::new(Arc::new("before"));
let mut renderer = RtRenderer::new(cameras, Box::new(identity), custom_options.as_source());
custom_options.set(Arc::new("after"));

Expand Down
Loading

0 comments on commit 30b6c5f

Please sign in to comment.