Skip to content

Commit

Permalink
Merge pull request #10 from okkmnone/android102
Browse files Browse the repository at this point in the history
Android mp fix
  • Loading branch information
Dreamtowards committed Feb 25, 2024
2 parents bc4bac0 + 065cfbd commit 7683d7d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .cargo/config_build_fastest.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"

# sudo apt-get install lld
# sudo apt install mold clang
# sudo apt install lld
# sudo apt install clang mold
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
"-Clink-arg=-fuse-ld=/usr/bin/mold", # Use mold linker: mold is up to 5× (five times!) faster than LLD
"-Zshare-generics=y", # (Nightly) Make the current crate share its generic instantiations
"-Zthreads=0", # (Nightly) Use improved multithreading with the recommended amount of threads.
"-Zthreads=8", # (Nightly) Use improved multithreading with the recommended amount of threads.
]

# cargo install -f cargo-binutils
Expand Down
22 changes: 10 additions & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"rust-analyzer.cargo.buildScripts.overrideCommand": {
"command": "cargo",
"args": [
"check",
"--quiet",
"--workspace",
"--message-format=json",
"--all-targets",
"--config=${fileWorkspaceFolder}/.cargo/config_build_faster.toml",
"--features=bevy/dynamic_linking"
]
}
"rust-analyzer.check.overrideCommand": [
"cargo",
"check",
"--quiet",
"--workspace",
"--message-format=json",
"--all-targets",
"--config=${workspaceFolder}/.cargo/config_build_faster.toml",
"--features=bevy/dynamic_linking",
],
}
1 change: 1 addition & 0 deletions build/native_debug_faster_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cargo run --config=../.cargo/config_build_faster.toml --features "bevy/dynamic_linking" --bin dedicated_server
7 changes: 5 additions & 2 deletions crates/mobile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ethertia = { path = "../..", default-features = false }

[package.metadata.android]
package = "com.ethertia.client"
build_targets = [ "aarch64-linux-android" ]
build_targets = ["aarch64-linux-android"]
resources = "../../build/android/res"
assets = "../../assets"
apk_name = "ethertia"
Expand All @@ -27,7 +27,10 @@ keystore_password = "android"
[package.metadata.android.sdk]
min_sdk_version = 24
target_sdk_version = 33
max_sdk_version = 33
#max_sdk_version = 33

[[package.metadata.android.uses_permission]]
name = "android.permission.INTERNET"

[package.metadata.android.application]
icon = "@mipmap/icon"
Expand Down
24 changes: 18 additions & 6 deletions src/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Plugin for ItemPlugin {

app.add_systems(Startup, setup_items);

app.add_systems(PostStartup, bake_items);
app.add_systems(PostStartup, bake_items.pipe(error_handler));
}
}

Expand All @@ -54,6 +54,17 @@ struct Items {

}

fn error_handler(In(result): In<anyhow::Result<()>>) {
let hm = crate::hashmap![
"foo" => 100,
"bar" => 200,
];

if let Err(err) = result {
panic!("{}", err)
}
}

fn setup_items(
mut items: ResMut<Items>,
) {
Expand Down Expand Up @@ -88,13 +99,13 @@ use image::{self, GenericImageView, RgbaImage};
fn bake_items(
mut items: ResMut<Items>,
asset_server: Res<AssetServer>,
) {
) -> anyhow::Result<()> {
// Build NumId Table
items.registry.build_num_id();
info!("Registered {} items: {:?}", items.registry.len(), items.registry.vec);

// Generate Items Atlas Image
let cache_file = std::env::current_dir().unwrap().join("cache/items.png");
let cache_file = std::env::current_dir()?.join("cache/items.png");
let resolution = 64;

if let Err(_) = std::fs::metadata(&cache_file) {
Expand All @@ -114,7 +125,7 @@ fn bake_items(
format!("assets/items/{str_id}/view.png")
};

let img = image::open(imgloc).unwrap();
let img = image::open(imgloc)?;
let img = img.resize_exact(resolution, resolution, image::imageops::FilterType::Triangle);

// copy to
Expand All @@ -125,11 +136,12 @@ fn bake_items(
}
}

std::fs::create_dir_all(&cache_file.parent().unwrap()).unwrap();
atlas.save(&cache_file).unwrap();
std::fs::create_dir_all(&cache_file.parent().ok_or(crate::err_opt_is_none!())?)?;
atlas.save(&cache_file)?;
}

items.atlas = asset_server.load(cache_file);
Ok(())
}


Expand Down
11 changes: 10 additions & 1 deletion src/util/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ macro_rules! hashmap {
}
};
}
pub use hashmap;

#[macro_export]
macro_rules! err_opt_is_none {
() => {
{
let e = anyhow::anyhow!("Option is None");
e
}
};
}
1 change: 0 additions & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[macro_use]
mod macros;
pub use macros::hashmap;

pub mod registry;

Expand Down

0 comments on commit 7683d7d

Please sign in to comment.