add gfx and winit
This commit is contained in:
parent
073952598d
commit
da7b86ab31
7 changed files with 74 additions and 19 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -935,7 +935,9 @@ dependencies = [
|
||||||
name = "framework"
|
name = "framework"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ndk-glue",
|
"anyhow",
|
||||||
|
"bass-sys",
|
||||||
|
"gfx-hal",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -943,7 +945,9 @@ dependencies = [
|
||||||
name = "framework-example-2048"
|
name = "framework-example-2048"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"framework",
|
"framework",
|
||||||
|
"ndk-glue",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -995,6 +999,16 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gfx-hal"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "18d0754f5b7a43915fd7466883b2d1bb0800d7cc4609178d0b27bf143b9e5123"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"raw-window-handle",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gfx_core"
|
name = "gfx_core"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
|
|
|
@ -8,4 +8,11 @@ edition = "2018"
|
||||||
crate-type = ["lib", "cdylib"]
|
crate-type = ["lib", "cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.38"
|
||||||
framework = { path = "../framework" }
|
framework = { path = "../framework" }
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "android")'.dependencies]
|
||||||
|
ndk-glue = "0.2.1"
|
||||||
|
|
||||||
|
[package.metadata.android]
|
||||||
|
apk_label = "2048"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use framework::Game;
|
||||||
|
|
||||||
|
pub fn real_main() -> Result<()> {
|
||||||
|
let game = Game::init()?;
|
||||||
|
game.run();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
|
||||||
|
pub fn android_main() {
|
||||||
|
real_main();
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
use framework_example_2048::real_main;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
real_main();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ authors = ["Michael Zhang <mail@mzhang.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.38"
|
||||||
|
gfx-hal = "0.6.0"
|
||||||
winit = { version = "0.24.0", features = ["web-sys"] }
|
winit = { version = "0.24.0", features = ["web-sys"] }
|
||||||
|
bass-sys = { path = "../bass-sys" }
|
||||||
[target.'cfg(target_os = "android")'.dependencies]
|
|
||||||
ndk-glue = "0.2.1"
|
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
use anyhow::Result;
|
||||||
|
use winit::{
|
||||||
|
event::{Event, WindowEvent},
|
||||||
|
event_loop::{ControlFlow, EventLoop},
|
||||||
|
window::{Window, WindowBuilder},
|
||||||
|
};
|
||||||
|
|
||||||
pub struct ObjectWrapper {
|
pub struct ObjectWrapper {
|
||||||
id: usize,
|
id: usize,
|
||||||
inner: Box<dyn Object>,
|
inner: Box<dyn Object>,
|
||||||
|
@ -9,21 +16,38 @@ pub trait Object {
|
||||||
fn draw(&self);
|
fn draw(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {}
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Game {
|
pub struct Game {
|
||||||
|
event_loop: EventLoop<()>,
|
||||||
|
window: Window,
|
||||||
objects: Vec<ObjectWrapper>,
|
objects: Vec<ObjectWrapper>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
pub fn run<F>(mut self, func: F)
|
pub fn init() -> Result<Self> {
|
||||||
where
|
let event_loop = EventLoop::new();
|
||||||
F: Fn(),
|
let window = WindowBuilder::new().build(&event_loop)?;
|
||||||
{
|
|
||||||
loop {
|
Ok(Game {
|
||||||
for object in self.objects.iter_mut() {
|
objects: vec![],
|
||||||
|
event_loop,
|
||||||
|
window,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(mut self) {
|
||||||
|
let window_id = self.window.id();
|
||||||
|
self.event_loop.run(move |event, _, control_flow| {
|
||||||
|
*control_flow = ControlFlow::Wait;
|
||||||
|
|
||||||
|
match event {
|
||||||
|
Event::WindowEvent {
|
||||||
|
event: WindowEvent::CloseRequested,
|
||||||
|
window_id,
|
||||||
|
} if window_id == window_id => *control_flow = ControlFlow::Exit,
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,3 @@ mod game;
|
||||||
mod renderer;
|
mod renderer;
|
||||||
|
|
||||||
pub use crate::game::Game;
|
pub use crate::game::Game;
|
||||||
|
|
||||||
#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))]
|
|
||||||
pub fn android_main() {
|
|
||||||
println!("hello, world!");
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue