Skip to content
Draft

Android #1081

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ crevice = "0.11"
typed-arena = "2.0"
ordered-float = "3.0"

[target.'cfg(target_os = "android")'.dependencies]
ndk = "0.5.0"
ndk-glue = "0.5.0"

[dev-dependencies]
chrono = "0.4"
fern = "0.6"
Expand Down
16 changes: 7 additions & 9 deletions examples/05_astroblasto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,11 @@ pub fn main() -> GameResult {
path::PathBuf::from("./resources")
};

let cb = ContextBuilder::new("astroblasto", "ggez")
.window_setup(conf::WindowSetup::default().title("Astroblasto!"))
.window_mode(conf::WindowMode::default().dimensions(640.0, 480.0))
.add_resource_path(resource_dir);

let (mut ctx, events_loop) = cb.build()?;

let game = MainState::new(&mut ctx)?;
event::run(ctx, events_loop, game)
event::run(
ContextBuilder::new("astroblasto", "ggez")
.window_setup(conf::WindowSetup::default().title("Astroblasto!"))
.window_mode(conf::WindowMode::default().dimensions(640.0, 480.0))
.add_resource_path(resource_dir),
|ctx| MainState::new(ctx).unwrap(),
)
}
9 changes: 4 additions & 5 deletions examples/bunnymark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ fn main() -> GameResult {
path::PathBuf::from("./resources")
};

let cb = ggez::ContextBuilder::new("bunnymark", "ggez").add_resource_path(resource_dir);
let (mut ctx, event_loop) = cb.build()?;

let state = GameState::new(&mut ctx)?;
event::run(ctx, event_loop, state)
event::run(
ggez::ContextBuilder::new("bunnymark", "ggez").add_resource_path(resource_dir),
|ctx| GameState::new(ctx).unwrap(),
)
}
17 changes: 10 additions & 7 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ impl Context {
fn from_conf(
conf: conf::Conf,
fs: Filesystem,
) -> GameResult<(Context, winit::event_loop::EventLoop<()>)> {
window: winit::window::Window,
) -> GameResult<Context> {
#[cfg(feature = "audio")]
let audio_context = audio::AudioContext::new(&fs)?;
let events_loop = winit::event_loop::EventLoop::new();
let timer_context = timer::TimeContext::new();
let graphics_context = graphics::context::GraphicsContext::new(&events_loop, &conf, &fs)?;
let graphics_context = graphics::context::GraphicsContext::new(window, &conf, &fs)?;

let ctx = Context {
conf,
Expand All @@ -192,7 +192,7 @@ impl Context {
gamepad: input::gamepad::GamepadContext::new()?,
};

Ok((ctx, events_loop))
Ok(ctx)
}
}

Expand Down Expand Up @@ -318,7 +318,7 @@ impl ContextBuilder {
}

/// Build the `Context`.
pub fn build(self) -> GameResult<(Context, winit::event_loop::EventLoop<()>)> {
pub(crate) fn build(self, window: winit::window::Window) -> GameResult<Context> {
let fs = Filesystem::new(
self.game_id.as_ref(),
self.author.as_ref(),
Expand All @@ -340,7 +340,7 @@ impl ContextBuilder {
self.conf
};

Context::from_conf(config, fs)
Context::from_conf(config, fs, window)
}
}

Expand All @@ -362,10 +362,13 @@ mod tests {
graphics::GraphicsContext,
ContextBuilder,
};
use winit::window::WindowBuilder;

#[test]
fn has_traits() {
let (mut ctx, _event_loop) = ContextBuilder::new("test", "ggez").build().unwrap();
let event_loop = winit::event_loop::EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap(/* TODO */);
let mut ctx = ContextBuilder::new("test", "ggez").build(window).unwrap();

fn takes_gfx(_gfx: &impl Has<GraphicsContext>) {}
takes_gfx(&ctx);
Expand Down
Loading