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

Add new version of modor_graphics #295

Merged
merged 36 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c5702f7
Add part of new version of `modor_graphics`
Nicolas-Ferre May 7, 2024
9a87d65
Make minor changes
Nicolas-Ferre May 12, 2024
de26f96
Merge branch '280-simplify-api' into 280-reimplement-modor-graphics
Nicolas-Ferre May 12, 2024
7f69868
Remove `NoVisit` and `#[modor(skip)]` references
Nicolas-Ferre May 12, 2024
8edaf19
Start simplification of `Gpu` access
Nicolas-Ferre May 18, 2024
99f3d9c
Finish simplification of `Gpu` access
Nicolas-Ferre May 19, 2024
be457ad
Make material glob generic
Nicolas-Ferre May 19, 2024
f7f6a89
Add default value for position and size in `Model2D` and `Body2D`
Nicolas-Ferre May 19, 2024
e545662
Rename `App::root` to `App::get_mut` + rename `Context::root` to `Con…
Nicolas-Ferre May 19, 2024
bdbbb26
Replace `Res::err` by `Res::state`
Nicolas-Ferre May 19, 2024
3eff063
Add better support for transparent models
Nicolas-Ferre May 19, 2024
3a64c6a
Add custom shader example
Nicolas-Ferre May 19, 2024
5b5956d
Simplify `Material` trait
Nicolas-Ferre May 19, 2024
a430153
Add texture target and texture buffer access
Nicolas-Ferre May 20, 2024
03e341b
Refactor examples + add texture_2d example
Nicolas-Ferre May 25, 2024
db78496
Add documentation
Nicolas-Ferre May 25, 2024
f892c22
Add tests
Nicolas-Ferre Jun 1, 2024
8f23ff0
Reformat
Nicolas-Ferre Jun 1, 2024
cc94339
Fix doc examples
Nicolas-Ferre Jun 1, 2024
2b1e66f
Fix tests on Windows
Nicolas-Ferre Jun 2, 2024
591e728
Change Vulkan install script for CI
Nicolas-Ferre Jun 2, 2024
43f31fc
Fix CI for linux
Nicolas-Ferre Jun 2, 2024
a735cab
Fix doc + speed up doc check in CI
Nicolas-Ferre Jun 2, 2024
61dc017
Merge remote-tracking branch 'origin/280-reimplement-modor-graphics' …
Nicolas-Ferre Jun 2, 2024
ac17a9c
Add graphics dependency install for Windows CI + fix WASM lints
Nicolas-Ferre Jun 2, 2024
a3222ee
Change graphics dependency install for Windows CI
Nicolas-Ferre Jun 2, 2024
5221d90
Change graphics dependency install for Windows CI
Nicolas-Ferre Jun 2, 2024
9cf1103
Change graphics dependency install for Windows CI
Nicolas-Ferre Jun 2, 2024
141e8bf
Fix CI
Nicolas-Ferre Jun 2, 2024
9ace3fd
Fix CI
Nicolas-Ferre Jun 2, 2024
4714a07
Fix CI
Nicolas-Ferre Jun 2, 2024
b2e140f
Disable graphics tests in CI for Windows
Nicolas-Ferre Jun 2, 2024
17c562d
Increase test coverage
Nicolas-Ferre Jun 2, 2024
d3f7817
Fix WASM canvas + apply remaining TODOs
Nicolas-Ferre Jun 2, 2024
c775337
Fix lints
Nicolas-Ferre Jun 2, 2024
a90a4bf
Increase test coverage
Nicolas-Ferre Jun 2, 2024
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
9 changes: 2 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install libudev-dev
if: matrix.target == 'x86_64-unknown-linux-gnu'
- name: Run clippy
run: cargo clippy --all-targets --target ${{ matrix.target }} -- -D warnings
run: cargo clippy --all-targets --no-deps --target ${{ matrix.target }} -- -D warnings

test:
strategy:
Expand All @@ -75,12 +75,10 @@ jobs:
- name: Windows
os: windows-2022
target: x86_64-pc-windows-msvc
wgpu_backend: dx12
- name: Linux
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
command_prefix: xvfb-run --server-args="-screen 0 1920x1080x24"
wgpu_backend: vulkan
- name: macOS
os: macos-13
target: x86_64-apple-darwin
Expand Down Expand Up @@ -119,8 +117,6 @@ jobs:
- name: Test other
run: ${{ matrix.command_prefix }} cargo test --no-fail-fast
if: matrix.target != 'wasm32-unknown-unknown'
env:
WGPU_BACKEND: ${{ matrix.wgpu_backend }}

coverage:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -152,7 +148,6 @@ jobs:
env:
RUSTFLAGS: -Cinstrument-coverage -Clink-dead-code
LLVM_PROFILE_FILE: "%m.profraw"
WGPU_BACKEND: vulkan
- name: Generate HTML coverage report
if: ${{ env.CODECOV_UPLOAD != 'true' }}
run: bash -x .github/workflows/scripts/generate_coverage.sh html ./coverage/
Expand Down Expand Up @@ -201,7 +196,7 @@ jobs:
- name: Install Linux general dependencies
run: sudo apt-get update && sudo apt-get install libudev-dev
- name: Generate documentation
run: cargo doc
run: cargo doc --no-deps
env:
RUSTDOCFLAGS: -Dwarnings

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash
set -xeu

VULKAN_SDK_VERSION="1.3.268"

sudo apt-get update -y -qq
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-$VULKAN_SDK_VERSION-jammy.list https://packages.lunarg.com/vulkan/$VULKAN_SDK_VERSION/lunarg-vulkan-$VULKAN_SDK_VERSION-jammy.list
sudo apt-get update -y
sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers vulkan-sdk
sudo apt install -y vulkan-sdk
12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ approx = "0.5"
android-activity = { version = "0.5", features = ["native-activity"] }
android_logger = "0.13"
async-std = "1.12"
bytemuck = { version = "1.15", features = ["derive"] }
cargo-run-wasm = "0.3"
console_error_panic_hook = "0.1"
console_log = "1.0"
Expand All @@ -23,27 +24,36 @@ derivative = "2.2"
fs_extra = "1.2"
futures = "0.3"
fxhash = "0.2"
getrandom = { version = "*", features = ["js"] } # To fix this issue: https://github.com/rust-random/getrandom/issues/208
gilrs = "0.10"
image = "0.25"
instant = "0.1"
log = "0.4"
pico-args = "0.5"
pretty_env_logger = "0.5"
proc-macro-crate = "3.0"
proc-macro2 = "1.0"
rand = "0.8"
rapier2d = "0.18"
regex = "1.10"
reqwest = "0.12"
quote = "1.0"
spin_sleep = "1.2"
syn = { version = "2.0", features = ["full"] }
wasm-bindgen-futures = "0.4"
wasm-bindgen-test = "0.3"
web-sys = { version = "0.3", features = ["Location"] }

wgpu = "0.19"
winit = "0.29"
modor = { version = "0.1.0", path = "crates/modor" }
modor_derive = { version = "0.1.0", path = "crates/modor_derive" }
modor_graphics = { version = "0.1.0", path = "crates/modor_graphics" }
modor_input = { version = "0.1.0", path = "crates/modor_input" }
modor_internal = { version = "0.1.0", path = "crates/modor_internal" }
modor_jobs = { version = "0.1.0", path = "crates/modor_jobs" }
modor_math = { version = "0.1.0", path = "crates/modor_math" }
modor_physics = { version = "0.1.0", path = "crates/modor_physics" }
modor_resources = { version = "0.1.0", path = "crates/modor_resources" }

[workspace.lints.rust]
anonymous_parameters = "warn"
Expand Down
1 change: 1 addition & 0 deletions PUBLISHED-CRATES
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ modor_physics
modor_input
modor_jobs
modor_resources
modor_graphics
38 changes: 26 additions & 12 deletions crates/modor/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl App {
T: RootNode,
{
platform::init_logging(log_level);
debug!("initialize app...");
debug!("Initialize app...");
let mut app = Self {
root_indexes: FxHashMap::default(),
roots: vec![],
};
app.root::<T>();
debug!("app initialized");
app.get_mut::<T>();
debug!("App initialized");
app
}

Expand All @@ -53,7 +53,7 @@ impl App {
///
/// Root nodes are updated in the order in which they are created.
pub fn update(&mut self) {
debug!("run update app...");
debug!("Run update app...");
for root_index in 0..self.roots.len() {
let root = &mut self.roots[root_index];
let mut value = root
Expand All @@ -64,7 +64,7 @@ impl App {
update_fn(&mut *value, &mut self.ctx());
self.roots[root_index].value = Some(value);
}
debug!("app updated");
debug!("App updated");
}

/// Returns an update context.
Expand All @@ -77,7 +77,7 @@ impl App {
/// Returns a mutable reference to a root node.
///
/// The root node is created using [`RootNode::on_create`] if it doesn't exist.
pub fn root<T>(&mut self) -> &mut T
pub fn get_mut<T>(&mut self) -> &mut T
where
T: RootNode,
{
Expand All @@ -101,9 +101,9 @@ impl App {
where
T: RootNode,
{
debug!("create root node `{}`...", any::type_name::<T>());
debug!("Create root node `{}`...", any::type_name::<T>());
let root = RootNodeData::new(T::on_create(&mut self.ctx()));
debug!("root node `{}` created", any::type_name::<T>());
debug!("Root node `{}` created", any::type_name::<T>());
let index = self.roots.len();
self.root_indexes.insert(type_id, index);
self.roots.push(root);
Expand All @@ -117,7 +117,7 @@ impl App {
self.roots[root_index]
.value
.as_mut()
.expect("internal error: root node already borrowed")
.unwrap_or_else(|| panic!("root node `{}` already borrowed", any::type_name::<T>()))
.downcast_mut::<T>()
.expect("internal error: misconfigured root node")
}
Expand All @@ -132,14 +132,14 @@ pub struct Context<'a> {
}

impl Context<'_> {
/// Returns a mutable reference to a root node.
/// Returns a handle to a root node.
///
/// The root node is created using [`RootNode::on_create`] if it doesn't exist.
///
/// # Panics
///
/// This will panic if root node `T` is currently updated.
pub fn root<T>(&mut self) -> RootNodeHandle<T>
pub fn handle<T>(&mut self) -> RootNodeHandle<T>
where
T: RootNode,
{
Expand All @@ -148,6 +148,20 @@ impl Context<'_> {
phantom: PhantomData,
}
}

/// Returns a mutable reference to a root node.
///
/// The root node is created using [`RootNode::on_create`] if it doesn't exist.
///
/// # Panics
///
/// This will panic if root node `T` is currently updated.
pub fn get_mut<T>(&mut self) -> &mut T
where
T: RootNode,
{
self.handle::<T>().get_mut(self)
}
}

/// A handle to access a [`RootNode`].
Expand Down Expand Up @@ -176,7 +190,7 @@ where
ctx.app.roots[self.index]
.value
.as_ref()
.expect("internal error: root node already borrowed")
.unwrap_or_else(|| panic!("root node `{}` already borrowed", any::type_name::<T>()))
.downcast_ref::<T>()
.expect("internal error: misconfigured root node")
}
Expand Down
6 changes: 3 additions & 3 deletions crates/modor/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
{
/// Creates a new shared `value`.
pub fn new(ctx: &mut Context<'_>, value: T) -> Self {
let globals = ctx.root::<Globals<T>>();
let globals = ctx.handle::<Globals<T>>();
Self {
ref_: GlobRef {
index: globals.get_mut(ctx).register(value).into(),
Expand Down Expand Up @@ -142,7 +142,7 @@ where
/// # use modor::*;
/// #
/// fn access_glob(ctx: &mut Context<'_>, index: usize) -> &'static str {
/// ctx.root::<Globals<&'static str>>().get(ctx)[index]
/// ctx.get_mut::<Globals<&'static str>>()[index]
/// }
/// ```
#[derive(Debug)]
Expand Down Expand Up @@ -282,7 +282,7 @@ impl Drop for Index {
fn drop(&mut self) {
match self.pool.deleted_indexes.lock() {
Ok(mut indexes) => indexes.push(self.index),
Err(err) => error!("error: {err}"), // no-coverage (difficult to test poisoning)
Err(err) => error!("Error: {err}"), // no-coverage (difficult to test poisoning)
}
}
}
3 changes: 3 additions & 0 deletions crates/modor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ pub use modor_derive::Node;
///
/// Both structs and enums are supported.
///
/// Note that generic fields are not dynamically visited. In case a generic field should be visited,
/// an explicit [`Node`] trait bound is necessary.
///
/// # Examples
///
/// See [`modor`](crate).
Expand Down
2 changes: 1 addition & 1 deletion crates/modor/tests/integration/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use modor_derive::{Node, RootNode, Visit};
fn create_node_handle() {
let mut app = App::new::<Root>(Level::Info);
let mut ctx = app.ctx();
let handle = ctx.root::<Root>();
let handle = ctx.handle::<Root>();
assert_eq!(handle.get(&ctx).value, 0);
assert_eq!(handle.get_mut(&mut ctx).value, 0);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/modor/tests/integration/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn access_all_globals() {
let mut ctx = app.ctx();
let _glob1 = Glob::new(&mut ctx, "a");
let _glob2 = Glob::new(&mut ctx, "b");
let globals = app.root::<Globals<&str>>();
let globals = app.get_mut::<Globals<&str>>();
assert!(globals.deleted_items().is_empty());
assert_eq!(globals.get(0), Some(&"a"));
assert_eq!(globals.get(1), Some(&"b"));
Expand All @@ -116,7 +116,7 @@ fn access_all_globals_after_value_dropped() {
let _glob2 = Glob::new(&mut ctx, "b");
drop(glob1);
app.update();
let globals = app.root::<Globals<&str>>();
let globals = app.get_mut::<Globals<&str>>();
assert_eq!(globals.deleted_items(), [(0, "a")]);
assert_eq!(globals.get(0), None);
assert_eq!(globals.get(1), Some(&"b"));
Expand Down
12 changes: 3 additions & 9 deletions crates/modor/tests/integration/node/box_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use modor::{App, Context, Node, RootNode, Visit};
fn update_node() {
let mut app = App::new::<Root>(Level::Info);
app.update();
let container = app.root::<Container>();
let container = app.get_mut::<Container>();
assert_eq!(container.0, ["InnerNode::on_enter", "InnerNode::on_exit"]);
}

Expand All @@ -26,16 +26,10 @@ struct InnerNode;

impl Node for InnerNode {
fn on_enter(&mut self, ctx: &mut Context<'_>) {
ctx.root::<Container>()
.get_mut(ctx)
.0
.push("InnerNode::on_enter");
ctx.get_mut::<Container>().0.push("InnerNode::on_enter");
}

fn on_exit(&mut self, ctx: &mut Context<'_>) {
ctx.root::<Container>()
.get_mut(ctx)
.0
.push("InnerNode::on_exit");
ctx.get_mut::<Container>().0.push("InnerNode::on_exit");
}
}
12 changes: 3 additions & 9 deletions crates/modor/tests/integration/node/const_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn update_node() {
app.update();
app.update();
app.update();
let container = app.root::<Container>();
let container = app.get_mut::<Container>();
assert_eq!(container.0, ["InnerNode::on_enter", "InnerNode::on_exit"]);
}

Expand All @@ -30,16 +30,10 @@ struct InnerNode(u32);

impl Node for InnerNode {
fn on_enter(&mut self, ctx: &mut Context<'_>) {
ctx.root::<Container>()
.get_mut(ctx)
.0
.push("InnerNode::on_enter");
ctx.get_mut::<Container>().0.push("InnerNode::on_enter");
}

fn on_exit(&mut self, ctx: &mut Context<'_>) {
ctx.root::<Container>()
.get_mut(ctx)
.0
.push("InnerNode::on_exit");
ctx.get_mut::<Container>().0.push("InnerNode::on_exit");
}
}
12 changes: 3 additions & 9 deletions crates/modor/tests/integration/node/dyn_box_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use modor::{App, Context, Node, RootNode, Visit};
fn update_node() {
let mut app = App::new::<Root>(Level::Info);
app.update();
let container = app.root::<Container>();
let container = app.get_mut::<Container>();
assert_eq!(container.0, ["InnerNode::on_enter", "InnerNode::on_exit"]);
}

Expand All @@ -26,16 +26,10 @@ struct InnerNode;

impl Node for InnerNode {
fn on_enter(&mut self, ctx: &mut Context<'_>) {
ctx.root::<Container>()
.get_mut(ctx)
.0
.push("InnerNode::on_enter");
ctx.get_mut::<Container>().0.push("InnerNode::on_enter");
}

fn on_exit(&mut self, ctx: &mut Context<'_>) {
ctx.root::<Container>()
.get_mut(ctx)
.0
.push("InnerNode::on_exit");
ctx.get_mut::<Container>().0.push("InnerNode::on_exit");
}
}
Loading
Loading