Skip to content

Instantly share code, notes, and snippets.

View michaelfairley's full-sized avatar

Michael Fairley michaelfairley

View GitHub Profile
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "arrayvec"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
struct Playing {
state: GameState,
event_queue: VecDeque<Vec<Event>>,
event_time: f32,
}
impl Playing {
fn handle_input(&mut self, input: InputEvent) {
match input_event {
KeyboardInput(Key::Right) => self.event_queue.extend(self.state.handle(Dir::Right)),
type Bid = Int where self >= 1 && self <= 7;
fn doubled(bid: Bid) -> Int {
bid * 2
}
// The return type of ^^^ could be `Int where self >= 2 && self <= 14`, but since
// Int is a supertype of that, just returning `Int` is fine
fn main() {
n = get_console_input.to_int().or_go_boom()
#![cfg_attr(any(target_os = "ios", target_os = "android"), no_main]
fn main() {
main2();
}
#[cfg(any(target_os = "ios", target_os = "android"))]
#[no_mangle]
#[allow(non_snake_case)]
pub extern "C" fn SDL_main() -> i32 {

Where you able to produce a binary directly from the Rust build tools that you could submit to the app/play store?


Not quite, but I tried to get as close to that as was reasonably possible. Alas, things ended up a little convoluted.

For iOS, I have a nearly empty Xcode project with a build script that copies my cargo produced executable into the .app that Xcode generates (before Xcode signs it). The build script also uses lipo to merge the executables for each architecture I’m targeting (e.g. armv7 and aarch64 for non-simulator devices) into a single, universal binary.

On top of that, there are various iOS-y things that need to happen before my application’s main method is called. SDL2 provides the Objective-C code that does all of that. In a C or C++ game, SDL2 renames main to SDL_main, and then [inserts its own mai

Where you able to produce a binary directly from the Rust build tools that you could submit to the app/play store?


Not quite, but I tried to get as close to that as was reasonably possible. Alas, things ended up a little convoluted.

For iOS, I have an empty Xcode project with a build script that copies my cargo produced executable into the .app that Xcode generates (before Xcode signs it). The build script also uses lipo to merge the executables for each architecture I’m targeting (e.g. armv7 and aarch64 for non-simulator devices) into a single, universal binary.

On top of that, there are various iOS-y things that need to happen before my application’s main method is called. SDL2 provides the Objective-C code that does all of that. In a C or C++ game, SDL2 renames main to SDL_main, and then inserts its own main which does all of the AppDelegate and LaunchImage and whatever other iOS shenanigans, and then eventually calls SDL_main (all of which happens behind the scenes if you’re just using C or C++).

@michaelfairley
michaelfairley / OUT_DIR gl_bindings.rs
Last active February 7, 2017 23:49
gl-bindings.rs
mod __gl_imports {
pub use std::mem;
pub use std::os::raw;
}
#[inline(never)]
fn metaloadfn(mut loadfn: &mut FnMut(&str) -> *const __gl_imports::raw::c_void,
symbol: &str,
use sdl2_mixer;
use sdl2;
extern "C" {
pub fn Mix_LoadMUS_RW(src: *mut sdl2::libc::c_void, freesrc: i32) -> *mut sdl2::libc::c_void;
}
pub fn music_from_bytes(data: &'static [u8]) -> sdl2_mixer::Music {
let music_rwops = sdl2::rwops::RWops::from_bytes(data).unwrap();
module StartingPoint
def self.list_with_longest_word(list1, list2)
list1_longest = list1.map(&:length).max
list2_longest = list2.map(&:length).max
list1_longest > list2_longest ? list1 : list2
end
end
# That `.map(&:length).max` "isn't DRY enough". Let's clean it up.
let cube = [
// Front
Vertex { position: [ 0.5, 0.5, 0.5], normal: [ 0.0, 0.0, 1.0] },
Vertex { position: [ 0.5, -0.5, 0.5], normal: [ 0.0, 0.0, 1.0] },
Vertex { position: [-0.5, 0.5, 0.5], normal: [ 0.0, 0.0, 1.0] },
Vertex { position: [-0.5, 0.5, 0.5], normal: [ 0.0, 0.0, 1.0] },
Vertex { position: [ 0.5, -0.5, 0.5], normal: [ 0.0, 0.0, 1.0] },
Vertex { position: [-0.5, -0.5, 0.5], normal: [ 0.0, 0.0, 1.0] },
// Back