Skip to content

Commit

Permalink
begin dwn upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Dec 8, 2024
1 parent 2ce9469 commit de0cf29
Show file tree
Hide file tree
Showing 55 changed files with 9,670 additions and 11,158 deletions.
7,225 changes: 1,765 additions & 5,460 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ bevy_vrm = "0.0.12"
capnp = "0.19.4"
capnp-rpc = "0.19.1"
clap = { version = "4.5.4", features = ["derive"] }
didkit = { version = "0.6.0", default-features = false, features = ["ed25519"] }
directories = "5.0.1"
dwn = { version = "0.0.10", git = "https://github.com/unavi-xyz/dwn" }
dwn = { git = "https://github.com/unavi-xyz/dwn" }
glam = "0.28.0"
reqwest = "0.12.5"
semver = "1.0.22"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
surrealdb = { version = "2.0.2", default-features = false }
thiserror = "1.0.61"
tokio = { version = "1.40.0", features = ["macros", "rt", "time"] }
tracing = "0.1.40"
Expand All @@ -46,8 +44,9 @@ wasm-bindgen-futures = "0.4.41"
web-sys = "0.3.70"
wit-bindgen-rt = { version = "0.23.0", features = ["bitflags"] }
wtransport = "0.3.0"
xwt-core = { version = "0.5.0", git = "https://github.com/kayhhh/xwt" }
xwt-wtransport = { version = "0.9.0", git = "https://github.com/kayhhh/xwt" }
xdid = "0.2.0"
xwt-core = { git = "https://github.com/kayhhh/xwt" }
xwt-wtransport = { git = "https://github.com/kayhhh/xwt" }

[workspace.metadata.release]
publish = false
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ unavi-settings = { path = "../unavi-settings" }
unavi-world = { path = "../unavi-world" }

[target.'cfg(target_family = "wasm")'.dependencies]
surrealdb = { workspace = true, features = ["kv-indxdb"] }
tokio.workspace = true
wasm-bindgen-futures.workspace = true
wasm-bindgen.workspace = true
Expand All @@ -43,7 +42,6 @@ bevy_oxr = "0.3.0"
image = { version = "0.25.2", default-features = false, features = ["png"] }
reqwest.workspace = true
self_update = "0.41.0"
surrealdb = { workspace = true, features = ["kv-mem", "kv-surrealkv"] }
tempfile = "3.12.0"
tokio.workspace = true
winit = { version = "0.30.5", default-features = false }
Expand Down
34 changes: 14 additions & 20 deletions crates/unavi-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ use bevy::{
};

use avian3d::prelude::*;
use dwn::{actor::Actor, store::SurrealStore, DWN};
use surrealdb::{engine::local::Db, Surreal};
use unavi_world::UserActor;
use dwn::{
core::store::{DataStore, RecordStore},
stores::NativeDbStore,
Dwn,
};

#[cfg(not(target_family = "wasm"))]
pub mod native;
Expand All @@ -61,14 +63,7 @@ impl Default for StartOptions {
}
}

pub async fn start(db: Surreal<Db>, opts: StartOptions) {
let store = SurrealStore::new(db)
.await
.expect("Failed to create DWN store.");

let dwn = DWN::from(store);
let actor = Actor::new_did_key(dwn).expect("Failed to create DWN actor.");

pub async fn start(dwn: Dwn, opts: StartOptions) {
let mut meta_paths = HashSet::new();
meta_paths.insert("images/dev-white.png".into());

Expand Down Expand Up @@ -107,15 +102,14 @@ pub async fn start(db: Surreal<Db>, opts: StartOptions) {
})
.finish(&mut app);

app.insert_resource(UserActor(Arc::new(actor)))
.add_plugins((
PhysicsPlugins::default(),
unavi_networking::NetworkingPlugin,
unavi_player::PlayerPlugin,
unavi_scripting::ScriptingPlugin,
unavi_settings::SettingsPlugin,
unavi_world::WorldPlugin,
));
app.add_plugins((
PhysicsPlugins::default(),
unavi_networking::NetworkingPlugin,
unavi_player::PlayerPlugin,
unavi_scripting::ScriptingPlugin,
unavi_settings::SettingsPlugin,
unavi_world::WorldPlugin,
));

app.add_systems(Startup, unavi_system::spawn_unavi_system);
#[cfg(not(target_family = "wasm"))]
Expand Down
102 changes: 31 additions & 71 deletions crates/unavi-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,80 +1,10 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use clap::{Parser, ValueEnum};
use surrealdb::Surreal;
use dwn::{stores::NativeDbStore, Dwn};
use tracing::Level;
use unavi_app::StartOptions;

#[cfg(not(target_family = "wasm"))]
fn main() {
use surrealdb::engine::local::Mem;
use unavi_app::native::{db::get_filesystem_db, update::check_for_updates};

let args = Args::parse();

if !args.no_update {
if let Err(e) = check_for_updates() {
panic!("Failed to update: {}", e);
};
}

let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed to build tokio runtime");

rt.block_on(async {
let db = match args.storage {
Storage::Filesystem => get_filesystem_db().await,
Storage::Memory => Surreal::new::<Mem>(()).await,
}
.expect("Failed to create SurrealDB");

unavi_app::start(db, args.to_options()).await;
});
}

#[cfg(target_family = "wasm")]
#[wasm_bindgen::prelude::wasm_bindgen(start)]
pub async fn start() {
let window = web_sys::window().unwrap();
let document = window.document().unwrap();
let location = document.location().unwrap();
let search = location.search().unwrap();
let params = web_sys::UrlSearchParams::new_with_str(&search).unwrap();

let mut args = Args {
debug_physics: false,
log_level: LogLevel::default(),
storage: Storage::Memory,
xr: false,
};

if let Some(value) = params.get("debug-physics") {
if let Ok(value) = value.parse() {
args.debug_physics = value;
}
}

if let Some(value) = params.get("log-level") {
match value.as_str() {
"info" => args.log_level = LogLevel::Info,
"debug" => args.log_level = LogLevel::Debug,
"trace" => args.log_level = LogLevel::Trace,
_ => tracing::warn!("Unknown log-level: {}", value),
}
}

let db = Surreal::new::<surrealdb::engine::local::IndxDb>("unavi")
.await
.expect("Failed to create SurrealDB.");

unavi_app::start(db, args.to_options()).await;
}

#[cfg(target_family = "wasm")]
fn main() {}

#[derive(Parser, Debug)]
#[command(version, about)]
struct Args {
Expand Down Expand Up @@ -114,6 +44,36 @@ impl Args {
}
}

#[cfg(not(target_family = "wasm"))]
fn main() {
use unavi_app::native::update::check_for_updates;

let args = Args::parse();

if !args.no_update {
if let Err(e) = check_for_updates() {
panic!("Failed to update: {}", e);
};
}

let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed to build tokio runtime");

rt.block_on(async {
let db = match args.storage {
Storage::Filesystem => NativeDbStore::new_in_memory(),
Storage::Memory => NativeDbStore::new_in_memory(),
}
.expect("Failed to create db");

let dwn = Dwn::from(db);

unavi_app::start(dwn, args.to_options()).await;
});
}

#[derive(ValueEnum, Clone, Debug, Default)]
enum LogLevel {
#[default]
Expand Down
31 changes: 0 additions & 31 deletions crates/unavi-app/src/native/db.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/unavi-app/src/native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod db;
mod dirs;
pub mod icon;
pub mod update;
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/unavi-layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::{prelude::PhysicsDebugPlugin, PhysicsPlugins};
use bevy::prelude::*;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/unavi-shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/unavi-ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use unavi_player::PlayerPlugin;
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/unavi-vscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use unavi_player::PlayerPlugin;
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/wired-input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use unavi_player::PlayerPlugin;
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/wired-physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/wired-player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use unavi_player::PlayerPlugin;
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
2 changes: 0 additions & 2 deletions crates/unavi-scripting/examples/wired-scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use unavi_scripting::{ScriptBundle, ScriptingPlugin};
use unavi_world::util::init_user_actor;

#[tokio::main]
async fn main() {
let mut app = App::new();
init_user_actor(app.world_mut()).await;

app.add_plugins((
DefaultPlugins.set(AssetPlugin {
Expand Down
16 changes: 7 additions & 9 deletions crates/unavi-scripting/src/api/wired/dwn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use dwn::{actor::Actor, DWN};
use dwn::Dwn;
use wasm_bridge::component::{Linker, Resource};

use crate::data::ScriptData;
Expand Down Expand Up @@ -35,25 +35,23 @@ pub fn add_to_linker(linker: &mut Linker<ScriptData>) -> Result<()> {
}

pub struct WiredDwn {
dwn: DWN,
dwn: Dwn,
}

impl WiredDwn {
pub fn new(dwn: DWN) -> Self {
pub fn new(dwn: Dwn) -> Self {
Self { dwn }
}
}

impl Host for ScriptData {
fn user_dwn(&mut self) -> wasm_bridge::Result<Resource<DwnRes>> {
let actor = Actor::new_did_key(self.api.wired_dwn.as_ref().unwrap().dwn.clone())?;
let res = self.table.push(DwnRes { actor })?;
Ok(res)
todo!();
// let res = self.table.push(DwnRes { dwn })?;
// Ok(res)
}

fn world_host_dwn(&mut self) -> wasm_bridge::Result<Resource<DwnRes>> {
let actor = Actor::new_did_key(self.api.wired_dwn.as_ref().unwrap().dwn.clone())?;
let res = self.table.push(DwnRes { actor })?;
Ok(res)
todo!();
}
}
Loading

0 comments on commit de0cf29

Please sign in to comment.