Skip to content

Commit

Permalink
fix #264, fix #8 - use owned wit-bindgen types
Browse files Browse the repository at this point in the history
  • Loading branch information
philpax committed Mar 30, 2023
1 parent 492102f commit 62e0e09
Show file tree
Hide file tree
Showing 40 changed files with 968 additions and 1,481 deletions.
68 changes: 50 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ wasmtime = { version = "7.0.0", features = ["component-model"] }
# Use published versions of these crates when available, or pull them in ourselves
wasi-common = { git = "https://github.com/bytecodealliance/preview2-prototyping.git", rev = "5836a6b0028f6fbdd094fbdd87df1ff4ca535168" }
wasi-cap-std-sync = { git = "https://github.com/bytecodealliance/preview2-prototyping.git", rev = "5836a6b0028f6fbdd094fbdd87df1ff4ca535168" }
wit-bindgen-core = "0.4.0"
wit-bindgen-rust = "0.4.0"
wit-bindgen-core = { git = "https://github.com/bytecodealliance/wit-bindgen.git", rev = "7ec986ba6bab38b4ccf5a771200c689c77f1e404" }
wit-bindgen-rust = { git = "https://github.com/bytecodealliance/wit-bindgen.git", rev = "7ec986ba6bab38b4ccf5a771200c689c77f1e404" }
wit-component = "0.7.3"

[patch.crates-io]
Expand Down
2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ambient_editor_derive = { path = "../shared_crates/editor_derive" }
ambient_element = { path = "../shared_crates/element" }
ambient_project = { path = "../shared_crates/project" }
ambient_window_types = { path = "../shared_crates/window_types" }
ambient_event_types = { path = "../shared_crates/event_types" }
ambient_shared_types = { path = "../shared_crates/shared_types" }

tracing-tree = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true }
Expand Down
5 changes: 3 additions & 2 deletions app/src/shared/components/dev.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use ambient_ecs::{
primitive_component_definitions, ComponentDesc, ComponentEntry, ComponentRegistry, ComponentValue, DefaultValue, EntityId,
ExternalComponentAttributes, PrimitiveComponentType,
ComponentDesc, ComponentEntry, ComponentRegistry, ComponentValue, DefaultValue, EntityId, ExternalComponentAttributes,
PrimitiveComponentType,
};
use ambient_shared_types::primitive_component_definitions;
use glam::{Mat4, Quat, UVec2, UVec3, UVec4, Vec2, Vec3, Vec4};

pub fn build_components_toml() -> toml_edit::Document {
Expand Down
2 changes: 1 addition & 1 deletion app/src/shared/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use ambient_core::{
};
use ambient_ecs::{query, query_mut, Entity, SystemGroup, WorldDiff};
use ambient_element::{element_component, Element, Hooks};
use ambient_event_types::{WINDOW_FOCUSED, WINDOW_KEYBOARD_INPUT, WINDOW_MOUSE_INPUT, WINDOW_MOUSE_MOTION, WINDOW_MOUSE_WHEEL};
use ambient_input::{
event_focus_change, event_keyboard_input, event_mouse_input, event_mouse_motion, event_mouse_wheel, event_mouse_wheel_pixels, keycode,
mouse_button, player_prev_raw_input, player_raw_input, PlayerRawInput,
};
use ambient_network::{client::game_client, log_network_result, rpc::rpc_world_diff, PLAYER_INPUT_DATAGRAM_ID};
use ambient_shared_types::events::{WINDOW_FOCUSED, WINDOW_KEYBOARD_INPUT, WINDOW_MOUSE_INPUT, WINDOW_MOUSE_MOTION, WINDOW_MOUSE_WHEEL};
use ambient_std::unwrap_log_err;
use ambient_window_types::VirtualKeyCode;

Expand Down
2 changes: 2 additions & 0 deletions crates/ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2021"

[dependencies]
ambient_std = { path = "../std" }
ambient_shared_types = { path = "../../shared_crates/shared_types" }

itertools = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
Expand Down
27 changes: 1 addition & 26 deletions crates/ecs/src/primitive_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,7 @@ use crate::{
ExternalComponentAttributes, Name,
};

/// A mapping from enum names to Rust types. Instantiate this with a macro that takes `$(($value:ident, $type:ty)),*`.
#[macro_export]
macro_rules! primitive_component_definitions {
($macro_to_instantiate:ident) => {
$macro_to_instantiate!(
(Empty, ()),
(Bool, bool),
(EntityId, EntityId),
(F32, f32),
(F64, f64),
(Mat4, Mat4),
(I32, i32),
(Quat, Quat),
(String, String),
(U8, u8),
(U32, u32),
(U64, u64),
(Vec2, Vec2),
(Vec3, Vec3),
(Vec4, Vec4),
(Uvec2, UVec2),
(Uvec3, UVec3),
(Uvec4, UVec4)
);
};
}
use ambient_shared_types::primitive_component_definitions;

// implementation
macro_rules! build_attribute_registration {
Expand Down
2 changes: 1 addition & 1 deletion crates/editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ physxx = { path = "../../libs/physxx" }

ambient_element = { path = "../../shared_crates/element" }
ambient_window_types = { path = "../../shared_crates/window_types" }
ambient_event_types = { path = "../../shared_crates/event_types" }
ambient_shared_types = { path = "../../shared_crates/shared_types" }

glam = { workspace = true }
itertools = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/input/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ambient_std = { path = "../std" }
ambient_ecs = { path = "../ecs" }
ambient_core = { path = "../core" }
ambient_window_types = { path = "../../shared_crates/window_types" }
ambient_event_types = { path = "../../shared_crates/event_types" }
ambient_shared_types = { path = "../../shared_crates/shared_types" }
winit = { workspace = true }
glam = { workspace = true }
serde = { workspace = true }
Expand Down
20 changes: 10 additions & 10 deletions crates/input/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashSet;

use ambient_ecs::{components, world_events, Debuggable, Description, Entity, Name, Networked, Store, System, SystemGroup};
use ambient_shared_types::events;
use glam::{vec2, Vec2};
use serde::{Deserialize, Serialize};
use winit::event::ModifiersState;
Expand Down Expand Up @@ -77,21 +78,20 @@ impl System<Event<'static, ()>> for InputSystem {
self.is_focused = focused;
world
.resource_mut(world_events())
.add_event((ambient_event_types::WINDOW_FOCUSED.to_string(), Entity::new().with(event_focus_change(), focused)));
.add_event((events::WINDOW_FOCUSED.to_string(), Entity::new().with(event_focus_change(), focused)));
}
WindowEvent::ReceivedCharacter(c) => {
world.resource_mut(world_events()).add_event((
ambient_event_types::WINDOW_RECEIVED_CHARACTER.to_string(),
events::WINDOW_RECEIVED_CHARACTER.to_string(),
Entity::new().with(event_received_character(), c.to_string()),
));
}

WindowEvent::ModifiersChanged(mods) => {
self.modifiers = *mods;
world.resource_mut(world_events()).add_event((
ambient_event_types::WINDOW_MODIFIERS_CHANGED.to_string(),
Entity::new().with(event_modifiers_change(), *mods),
));
world
.resource_mut(world_events())
.add_event((events::WINDOW_MODIFIERS_CHANGED.to_string(), Entity::new().with(event_modifiers_change(), *mods)));
}

WindowEvent::KeyboardInput { input, .. } => {
Expand All @@ -107,12 +107,12 @@ impl System<Event<'static, ()>> for InputSystem {
if let Some(key) = input.virtual_keycode {
data.set(keycode(), ambient_window_types::VirtualKeyCode::from(key).to_string());
}
world.resource_mut(world_events()).add_event((ambient_event_types::WINDOW_KEYBOARD_INPUT.to_string(), data));
world.resource_mut(world_events()).add_event((events::WINDOW_KEYBOARD_INPUT.to_string(), data));
}

WindowEvent::MouseInput { state, button, .. } => {
world.resource_mut(world_events()).add_event((
ambient_event_types::WINDOW_MOUSE_INPUT.to_string(),
events::WINDOW_MOUSE_INPUT.to_string(),
Entity::new()
.with(
event_mouse_input(),
Expand All @@ -127,7 +127,7 @@ impl System<Event<'static, ()>> for InputSystem {

WindowEvent::MouseWheel { delta, .. } => {
world.resource_mut(world_events()).add_event((
ambient_event_types::WINDOW_MOUSE_WHEEL.to_string(),
events::WINDOW_MOUSE_WHEEL.to_string(),
Entity::new()
.with(
event_mouse_wheel(),
Expand All @@ -145,7 +145,7 @@ impl System<Event<'static, ()>> for InputSystem {

Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. } => {
world.resource_mut(world_events()).add_event((
ambient_event_types::WINDOW_MOUSE_MOTION.to_string(),
events::WINDOW_MOUSE_MOTION.to_string(),
Entity::new().with(event_mouse_motion(), vec2(delta.0 as f32, delta.1 as f32)),
));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ambient_element = { path = "../../shared_crates/element" }
ambient_ui_components = { path = "../../shared_crates/ui_components", default-features = false, features = ["native"] }
ambient_editor_derive = { path = "../../shared_crates/editor_derive" }
ambient_window_types = { path = "../../shared_crates/window_types", features = ["native"] }
ambient_event_types = { path = "../../shared_crates/event_types" }
ambient_shared_types = { path = "../../shared_crates/shared_types" }
glam = { workspace = true }
winit = { workspace = true }
itertools = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub use tabs::*;
pub use throbber::*;

pub use self::image::*;
use ambient_event_types::{WINDOW_FOCUSED, WINDOW_MOUSE_MOTION};
use ambient_shared_types::events::{WINDOW_FOCUSED, WINDOW_MOUSE_MOTION};
use ambient_window_types::MouseButton;

pub fn init_all_components() {
Expand Down
Loading

0 comments on commit 62e0e09

Please sign in to comment.