Skip to content
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

Egui image api #72

Merged
merged 24 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bfac30c
chore: use universal set of lints across crates
melody-rs Nov 29, 2023
7f145d4
chore: :rotating_light: auto-fix most warnings
melody-rs Nov 29, 2023
fcbac2a
chore: disable panic and unwrap lints for now
melody-rs Nov 29, 2023
95c958d
chore: :rotating_light: fix wasily fixable warnings
melody-rs Nov 29, 2023
a8212b4
refactor(image cache): :recycle: add basic egui texture loader
melody-rs Nov 29, 2023
ffe4dcd
fix(image cache): :bug: handle image load errors semi-gracefully
melody-rs Nov 29, 2023
96cfa41
fix(image cache): :bug: clear up the difference between uris and paths
melody-rs Nov 30, 2023
e003788
refactor(image cache): :recycle: drop the use of multiple bind groups…
melody-rs Nov 30, 2023
479e14c
refactor(graphics): :recycle: remove pervasive passing of push consta…
melody-rs Nov 30, 2023
65f501d
fix(tilemap): :bug: fix various shader and bind group issues
melody-rs Nov 30, 2023
e76f3b3
refactor(tilemap): :recycle: don't pass viewports around constantly
melody-rs Nov 30, 2023
e2e551f
fix(tilemap): :bug: fix the collision shader crashing
melody-rs Nov 30, 2023
e1deae2
refactor: :recycle: remove all uses of retainedimage
melody-rs Nov 30, 2023
8036f50
fix(image cache): :bug: fix loading errors & textures not being srgb
melody-rs Nov 30, 2023
ab0607a
fix(image cache): :bug: fix srgb weirdness
melody-rs Nov 30, 2023
3501004
fix(image cache): :bug: properly unload textures
melody-rs Nov 30, 2023
0358b0a
refactor(image cache): :fire: remove TextureLoader and add BytesLoade…
melody-rs Dec 2, 2023
15cb4a6
refactor: :recycle: Rename atlas cache to atlas loader
melody-rs Dec 2, 2023
ed769c7
fix: :rotating_light: fix compile error on wasm
melody-rs Dec 3, 2023
d84b44b
Add CJK font (#71)
white-axe Dec 2, 2023
4bd59bd
Merge branch 'dev' into egui-image-api
melody-rs Dec 3, 2023
498157b
rustfmt
melody-rs Dec 3, 2023
5988e7c
Merge branch 'dev' into egui-image-api
melody-rs Dec 3, 2023
a562e49
fix(tilemap): :bug: fix collision shader on native
melody-rs Dec 3, 2023
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
24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ categories.workspace = true
members = ["crates/*"]
resolver = "2"

[workspace.lints.rust]
rust_2018_idioms = "warn"
# unsafe code is sometimes fine but in general we don't want to use it.
unsafe_code = "warn"
# clearly denote where you are using unsafe code in unsafe fns. in a future rust edition this will become a hard error.
unsafe_op_in_unsafe_fn = "forbid"
# will become a hard error in a future rust edition
elided_lifetimes_in_paths = "forbid"

[workspace.lints.clippy]
all = "warn"
# we should turn these on in the future to avoid possible crashes
# panic = "warn"
# panic_in_result_fn = "warn"
# panicking_unwrap = "warn"
unnecessary_wraps = "warn"

missing_errors_doc = "allow"
doc_markdown = "allow"
missing_panics_doc = "allow"
too_many_lines = "allow"
# you must provide a safety doc.
missing_safety_doc = "forbid"

[workspace.package]
version = "0.4.0"
authors = [
Expand Down
4 changes: 3 additions & 1 deletion crates/audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ categories.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[lints]
workspace = true

[dependencies]
rustysynth = "1.3.1"

strum.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions crates/components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ categories.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
luminol-audio.workspace = true
luminol-core.workspace = true
Expand Down
16 changes: 4 additions & 12 deletions crates/components/src/command_view/command_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,13 @@
impl super::CommandView {
pub fn command_ui<'i, I>(
&mut self,
ui: &mut egui::Ui,
db: &luminol_config::command_db::CommandDB,
(index, command): (usize, &'i mut luminol_data::rpg::EventCommand),
iter: &mut std::iter::Peekable<I>,
_ui: &mut egui::Ui,
_db: &luminol_config::command_db::CommandDB,
(_index, _command): (usize, &'i mut luminol_data::rpg::EventCommand),
_iter: &mut std::iter::Peekable<I>,
) where
I: Iterator<Item = (usize, &'i mut luminol_data::rpg::EventCommand)>,
{
todo!()
}
}

fn parameter_label(
string: &mut String,
parameter: &luminol_data::commands::Parameter,
command: &mut luminol_data::rpg::EventCommand,
) -> std::fmt::Result {
todo!()
}
20 changes: 9 additions & 11 deletions crates/components/src/command_view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,31 @@ mod ui;
use std::collections::HashMap;

pub struct CommandView {
selected_index: usize,
window_state: WindowState,
id: egui::Id,
modals: HashMap<u64, bool>, // todo find a better way to handle modals
_selected_index: usize,
_window_state: WindowState,
_id: egui::Id,
_modals: HashMap<u64, bool>, // todo find a better way to handle modals
}

enum WindowState {
Insert { index: usize, tab: usize },
Edit { index: usize },
None,
}

impl Default for CommandView {
fn default() -> Self {
Self {
selected_index: 0,
window_state: WindowState::None,
id: egui::Id::new("command_view"),
modals: HashMap::new(),
_selected_index: 0,
_window_state: WindowState::None,
_id: egui::Id::new("command_view"),
_modals: HashMap::new(),
}
}
}

impl CommandView {
pub fn new(id: impl std::hash::Hash) -> Self {
Self {
id: egui::Id::new(id),
_id: egui::Id::new(id),
..Default::default()
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/components/src/command_view/parameter_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl CommandView {
#[allow(clippy::only_used_in_recursion)]
pub fn parameter_ui(
&mut self,
ui: &mut egui::Ui,
parameter: &luminol_data::commands::Parameter,
command: &mut luminol_data::rpg::EventCommand,
_ui: &mut egui::Ui,
_parameter: &luminol_data::commands::Parameter,
_command: &mut luminol_data::rpg::EventCommand,
) {
todo!()
}
Expand Down
6 changes: 3 additions & 3 deletions crates/components/src/command_view/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ impl super::CommandView {
#[allow(clippy::ptr_arg)]
pub fn ui(
&mut self,
ui: &mut egui::Ui,
db: &luminol_config::command_db::CommandDB,
commands: &mut Vec<luminol_data::rpg::EventCommand>,
_ui: &mut egui::Ui,
_db: &luminol_config::command_db::CommandDB,
_commands: &mut Vec<luminol_data::rpg::EventCommand>,
) {
todo!()
}
Expand Down
22 changes: 7 additions & 15 deletions crates/components/src/map_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

use itertools::Itertools;

#[derive(Debug)]
pub struct MapView {
/// Toggle to display the visible region in-game.
pub visible_display: bool,
Expand Down Expand Up @@ -84,35 +83,28 @@ impl MapView {
|x, y, passage| passages[(x, y)] = passage,
);

let atlas = update_state.graphics.atlas_cache.load_atlas(
let atlas = update_state.graphics.atlas_loader.load_atlas(
&update_state.graphics,
update_state.filesystem,
tileset,
)?;
let events = map
.events
.iter()
.map(|(id, e)| {
.map(|(id, e)| -> anyhow::Result<_> {
let sprite = luminol_graphics::Event::new(
&update_state.graphics,
update_state.filesystem,
e,
&atlas,
update_state.graphics.push_constants_supported(),
);
)?;
let preview_sprite = luminol_graphics::Event::new(
&update_state.graphics,
update_state.filesystem,
e,
&atlas,
update_state.graphics.push_constants_supported(),
);
let Ok(sprite) = sprite else {
return Err(sprite.unwrap_err());
};
let Ok(preview_sprite) = preview_sprite else {
return Err(preview_sprite.unwrap_err());
};
)?;

Ok(if let Some(sprite) = sprite {
preview_sprite.map(|preview_sprite| (id, (sprite, preview_sprite)))
} else {
Expand All @@ -127,7 +119,6 @@ impl MapView {
&map,
tileset,
&passages,
update_state.graphics.push_constants_supported(),
)?;

Ok(Self {
Expand Down Expand Up @@ -159,7 +150,8 @@ impl MapView {
})
}

// FIXME
// FIXME lots of arguments
#[allow(clippy::too_many_arguments)]
pub fn ui(
&mut self,
ui: &mut egui::Ui,
Expand Down
2 changes: 1 addition & 1 deletion crates/components/src/sound_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl SoundTab {
.show_inside(ui, |ui| {
ui.vertical(|ui| {
ui.horizontal(|ui| {
if ui.button("Play").clicked() && !self.selected_track.as_str().is_empty() {
if ui.button("Play").clicked() && !self.selected_track.is_empty() {
let path = format!("Audio/{}/{}", self.source, &self.selected_track);
let pitch = self.pitch;
let volume = self.volume;
Expand Down
63 changes: 22 additions & 41 deletions crates/components/src/tilepicker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
// along with Luminol. If not, see <http://www.gnu.org/licenses/>.

use itertools::Itertools;
use slab::Slab;
use std::sync::Arc;
use std::time::Duration;

#[derive(Debug)]
pub struct Tilepicker {
pub selected_tiles_left: i16,
pub selected_tiles_top: i16,
Expand All @@ -30,14 +28,13 @@ pub struct Tilepicker {
drag_origin: Option<egui::Pos2>,

resources: Arc<Resources>,
viewport: Arc<luminol_graphics::viewport::Viewport>,
ani_time: Option<f64>,
}

#[derive(Debug)]
struct Resources {
tiles: luminol_graphics::tiles::Tiles,
collision: luminol_graphics::collision::Collision,
viewport: luminol_graphics::viewport::Viewport,
}

struct Callback {
Expand All @@ -47,8 +44,12 @@ struct Callback {
coll_enabled: bool,
}

// FIXME
//? SAFETY:
//? wgpu resources are not Send + Sync on wasm, but egui_wgpu::CallbackTrait requires Send + Sync (because egui::Context is Send + Sync)
//? as long as this callback does not leave the thread it was created on on wasm (which it shouldn't be) these are ok.
#[allow(unsafe_code)]
unsafe impl Send for Callback {}
#[allow(unsafe_code)]
unsafe impl Sync for Callback {}

impl luminol_egui_wgpu::CallbackTrait for Callback {
Expand All @@ -58,22 +59,14 @@ impl luminol_egui_wgpu::CallbackTrait for Callback {
render_pass: &mut wgpu::RenderPass<'a>,
_callback_resources: &'a luminol_egui_wgpu::CallbackResources,
) {
self.resources.viewport.bind(1, render_pass);
self.resources.tiles.draw(
&self.graphics_state,
&self.resources.viewport,
&[true],
None,
render_pass,
);
self.resources
.tiles
.draw(&self.graphics_state, &[true], None, render_pass);

if self.coll_enabled {
self.resources.viewport.bind(0, render_pass);
self.resources.collision.draw(
&self.graphics_state,
&self.resources.viewport,
render_pass,
);
self.resources
.collision
.draw(&self.graphics_state, render_pass);
}
}
}
Expand Down Expand Up @@ -107,8 +100,6 @@ impl Default for SelectedTile {
}
}

type ResourcesSlab = Slab<Arc<Resources>>;

impl Tilepicker {
pub fn new(
update_state: &luminol_core::UpdateState<'_>,
Expand All @@ -120,7 +111,7 @@ impl Tilepicker {
let tilesets = update_state.data.tilesets();
let tileset = &tilesets[map.tileset_id];

let atlas = update_state.graphics.atlas_cache.load_atlas(
let atlas = update_state.graphics.atlas_loader.load_atlas(
&update_state.graphics,
update_state.filesystem,
tileset,
Expand All @@ -137,24 +128,17 @@ impl Tilepicker {
tilepicker_data,
);

let viewport = luminol_graphics::viewport::Viewport::new(
let viewport = Arc::new(luminol_graphics::viewport::Viewport::new(
&update_state.graphics,
glam::Mat4::orthographic_rh(
0.0,
256.,
atlas.tileset_height as f32 + 32.,
0.0,
-1.0,
1.0,
),
update_state.graphics.push_constants_supported(),
);
256.,
atlas.tileset_height as f32 + 32.,
));

let tiles = luminol_graphics::tiles::Tiles::new(
&update_state.graphics,
viewport.clone(),
atlas,
&tilepicker_data,
update_state.graphics.push_constants_supported(),
);

let mut passages =
Expand All @@ -175,16 +159,13 @@ impl Tilepicker {
.copy_from_slice(&tileset.passages.as_slice()[384..384 + length]);
let collision = luminol_graphics::collision::Collision::new(
&update_state.graphics,
viewport.clone(),
&passages,
update_state.graphics.push_constants_supported(),
);

Ok(Self {
resources: Arc::new(Resources {
tiles,
collision,
viewport,
}),
resources: Arc::new(Resources { tiles, collision }),
viewport,
ani_time: None,
selected_tiles_left: 0,
selected_tiles_top: 0,
Expand Down Expand Up @@ -241,7 +222,7 @@ impl Tilepicker {
.intersect(scroll_rect.translate(canvas_rect.min.to_vec2()));
let scroll_rect = absolute_scroll_rect.translate(-canvas_rect.min.to_vec2());

self.resources.viewport.set_proj(
self.viewport.set_proj(
&graphics_state.render_state,
glam::Mat4::orthographic_rh(
scroll_rect.left(),
Expand Down
3 changes: 3 additions & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ categories.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
rust-ini.workspace = true

Expand Down
3 changes: 3 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ categories.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lints]
workspace = true

[dependencies]
egui.workspace = true

Expand Down
Loading
Loading