Skip to content

Commit

Permalink
Add basic Android support
Browse files Browse the repository at this point in the history
  • Loading branch information
Shatur committed Dec 5, 2024
1 parent 5223f2e commit bd51fee
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 75 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

A work-in-progress life simulation game made with [Bevy](https://bevyengine.org).

## Building

### Desktop

```bash
cargo build --release
```

### Mobile

Tested only on Android. It compiles and runs, but missing proper touch controls and gamepad support (`girls` doesn't support Android).

1. Install [xbuild](https://github.com/rust-mobile/xbuild)
2. Enable USB debugging on the device, connect it and allow access.
3. Get its ID:

```bash
x devices
```

3. Build:

```bash
x build --release --device <device ID> -p project_harmonia
```

## License

The code licensed under [GNU Affero General Public License v3.0](./COPYING).
Expand Down
5 changes: 5 additions & 0 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ license.workspace = true
authors.workspace = true
repository.workspace = true

[lib]
name = "project_harmonia"
# We need `cdylib` for Android and `lib` for everything else.
crate-type = ["lib", "cdylib"]

[dependencies]
project_harmonia_base.workspace = true
project_harmonia_widgets.workspace = true
Expand Down
3 changes: 3 additions & 0 deletions app/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
android:
assets:
- assets/base
79 changes: 79 additions & 0 deletions app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
mod cli;
mod cursor_controller;

use avian3d::{prelude::*, sync::SyncConfig};
use bevy::{
app::PluginGroupBuilder, core_pipeline::experimental::taa::TemporalAntiAliasPlugin,
pbr::wireframe::WireframePlugin, prelude::*, render::RenderPlugin,
};
use bevy_atmosphere::prelude::*;
use bevy_enhanced_input::prelude::*;
#[cfg(feature = "inspector")]
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_mod_outline::OutlinePlugin;
use bevy_replicon::prelude::*;
use bevy_replicon_renet::RepliconRenetPlugins;
use bevy_simple_text_input::TextInputPlugin;
use project_harmonia_base::{game_world::navigation::Obstacle, CorePlugins};
use project_harmonia_ui::UiPlugins;
use project_harmonia_widgets::WidgetsPlugin;
use vleue_navigator::prelude::*;

use cli::{Cli, CliPlugin};
use cursor_controller::CursorControllerPlugin;

struct AppPlugins;

impl PluginGroup for AppPlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(CliPlugin)
.add(CursorControllerPlugin)
}
}

// Separate entry point for Android, which doesn't use `main.rs`.
#[bevy_main]
pub fn main() {
let mut app = App::new();
app.init_resource::<Cli>()
.insert_resource(SyncConfig {
position_to_transform: false,
..Default::default()
})
.add_plugins((
DefaultPlugins
.set(RenderPlugin {
synchronous_pipeline_compilation: true,
..Default::default()
})
.set(WindowPlugin {
primary_window: Some(Window {
title: "Project Harmonia".to_string(),
..Default::default()
}),
..Default::default()
}),
TemporalAntiAliasPlugin,
RepliconPlugins,
RepliconRenetPlugins,
WireframePlugin,
AtmospherePlugin,
EnhancedInputPlugin,
VleueNavigatorPlugin,
NavmeshUpdaterPlugin::<Collider, Obstacle>::default(),
PhysicsPlugins::default()
.build()
.disable::<CcdPlugin>()
.disable::<SleepingPlugin>(),
PhysicsDebugPlugin::default(),
TextInputPlugin,
OutlinePlugin,
))
.add_plugins((CorePlugins, WidgetsPlugin, UiPlugins, AppPlugins));

#[cfg(feature = "inspector")]
app.add_plugins(WorldInspectorPlugin::default());

app.run();
}
76 changes: 1 addition & 75 deletions app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,77 +1,3 @@
mod cli;
mod cursor_controller;

use avian3d::{prelude::*, sync::SyncConfig};
use bevy::{
app::PluginGroupBuilder, core_pipeline::experimental::taa::TemporalAntiAliasPlugin,
pbr::wireframe::WireframePlugin, prelude::*, render::RenderPlugin,
};
use bevy_atmosphere::prelude::*;
use bevy_enhanced_input::prelude::*;
#[cfg(feature = "inspector")]
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_mod_outline::OutlinePlugin;
use bevy_replicon::prelude::*;
use bevy_replicon_renet::RepliconRenetPlugins;
use bevy_simple_text_input::TextInputPlugin;
use project_harmonia_base::{game_world::navigation::Obstacle, CorePlugins};
use project_harmonia_ui::UiPlugins;
use project_harmonia_widgets::WidgetsPlugin;
use vleue_navigator::prelude::*;

use cli::{Cli, CliPlugin};
use cursor_controller::CursorControllerPlugin;

struct AppPlugins;

impl PluginGroup for AppPlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(CliPlugin)
.add(CursorControllerPlugin)
}
}

fn main() {
let mut app = App::new();
app.init_resource::<Cli>()
.insert_resource(SyncConfig {
position_to_transform: false,
..Default::default()
})
.add_plugins((
DefaultPlugins
.set(RenderPlugin {
synchronous_pipeline_compilation: true,
..Default::default()
})
.set(WindowPlugin {
primary_window: Some(Window {
title: "Project Harmonia".to_string(),
..Default::default()
}),
..Default::default()
}),
TemporalAntiAliasPlugin,
RepliconPlugins,
RepliconRenetPlugins,
WireframePlugin,
AtmospherePlugin,
EnhancedInputPlugin,
VleueNavigatorPlugin,
NavmeshUpdaterPlugin::<Collider, Obstacle>::default(),
PhysicsPlugins::default()
.build()
.disable::<CcdPlugin>()
.disable::<SleepingPlugin>(),
PhysicsDebugPlugin::default(),
TextInputPlugin,
OutlinePlugin,
))
.add_plugins((CorePlugins, WidgetsPlugin, UiPlugins, AppPlugins));

#[cfg(feature = "inspector")]
app.add_plugins(WorldInspectorPlugin::default());

app.run();
project_harmonia::main();
}

0 comments on commit bd51fee

Please sign in to comment.