-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use proc_macro::TokenStream; | ||
use quote::quote; | ||
use syn::{parse_macro_input, ItemFn}; | ||
|
||
pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream { | ||
let input = parse_macro_input!(item as ItemFn); | ||
if input.sig.ident != "main" { | ||
panic!("bevy_main can only be used on a function called 'main'") | ||
} | ||
|
||
TokenStream::from(quote! { | ||
#[no_mangle] | ||
#[cfg(target_os = "android")] | ||
unsafe extern "C" fn ANativeActivity_onCreate( | ||
activity: *mut std::os::raw::c_void, | ||
saved_state: *mut std::os::raw::c_void, | ||
saved_state_size: usize, | ||
) { | ||
bevy::ndk_glue::init( | ||
activity as _, | ||
saved_state as _, | ||
saved_state_size as _, | ||
main, | ||
); | ||
} | ||
|
||
#[no_mangle] | ||
#[cfg(target_os = "ios")] | ||
extern "C" fn main_rs() { | ||
main(); | ||
} | ||
|
||
#[allow(unused)] | ||
#input | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
// Edit to run any single file example from Bevy. | ||
include!("../3d/3d_scene.rs"); | ||
use bevy::prelude::*; | ||
|
||
#[cfg_attr( | ||
target_os = "android", | ||
ndk_glue::main(logger(level = "debug", tag = "android"), backtrace = "full") | ||
)] | ||
pub fn android_main() { | ||
main(); | ||
// the `bevy_main` proc_macro generates the required android boilerplate | ||
#[bevy_main] | ||
fn main() { | ||
App::build() | ||
.add_resource(Msaa { samples: 2 }) | ||
.add_plugins(DefaultPlugins) | ||
.add_startup_system(setup.system()) | ||
.run(); | ||
} | ||
|
||
/// set up a simple 3D scene | ||
fn setup( | ||
commands: &mut Commands, | ||
mut meshes: ResMut<Assets<Mesh>>, | ||
mut materials: ResMut<Assets<StandardMaterial>>, | ||
) { | ||
// add entities to the world | ||
commands | ||
// plane | ||
.spawn(PbrComponents { | ||
mesh: meshes.add(Mesh::from(shape::Plane { size: 10.0 })), | ||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), | ||
..Default::default() | ||
}) | ||
// cube | ||
.spawn(PbrComponents { | ||
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), | ||
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), | ||
transform: Transform::from_translation(Vec3::new(0.0, 1.0, 0.0)), | ||
..Default::default() | ||
}) | ||
// light | ||
.spawn(LightComponents { | ||
transform: Transform::from_translation(Vec3::new(4.0, 8.0, 4.0)), | ||
..Default::default() | ||
}) | ||
// camera | ||
.spawn(Camera3dComponents { | ||
transform: Transform::from_translation(Vec3::new(-3.0, 5.0, 8.0)) | ||
.looking_at(Vec3::default(), Vec3::unit_y()), | ||
..Default::default() | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters