24 releases

new 0.3.0-alpha.7 Oct 22, 2020
0.3.0-alpha.6 Oct 21, 2020
0.2.9 Jul 28, 2020
0.2.7 Jun 27, 2020
0.1.3 Mar 7, 2020

#116 in Game dev

Download history 117/week @ 2020-07-02 32/week @ 2020-07-09 57/week @ 2020-07-16 83/week @ 2020-07-23 32/week @ 2020-07-30 34/week @ 2020-08-06 78/week @ 2020-08-13 68/week @ 2020-08-20 60/week @ 2020-08-27 59/week @ 2020-09-03 46/week @ 2020-09-10 17/week @ 2020-09-17 28/week @ 2020-09-24 40/week @ 2020-10-01 48/week @ 2020-10-08 106/week @ 2020-10-15

238 downloads per month
Used in 2 crates

MIT/Apache

1MB
2K SLoC

macroquad

Github Actions Crates.io version Discord chat

macroquad is a simple and easy to use game library for Rust programming language, heavily inspired by raylib.

macroquad attempts to avoid any rust-specific programming concepts like lifetimes/borrowing, making it very friendly for rust beginners.

Supported platforms

  • PC: Windows/Linux/MacOs
  • HTML5
  • Android
  • IOS

Features

  • Same code for all supported platforms, no platform dependent defines required
  • Efficient 2D rendering with automatic geometry batching
  • Minimal amount of dependencies: build after cargo clean takes only 16s on x230(~6years old laptop)
  • Immidiate mode UI library included
  • Single command deploy for both WASM and Android build instructions
tips Adding the following snippet to your Cargo.toml ensures that all dependencies compile in release even in debug mode. In macroquad, this has the effect of making images load several times faster and your applications much more performant, while keeping compile times miraculously low.
[profile.dev.package.'*']
opt-level = 3

async/await

While macroquad attempts to use as mini rust-specific concepts as possible, .await in every examples looks a bit scary. Rust's async/await is used to solve just one problem - cross platform main loop ogranisation.

details

The problem: on WASM and android its not really easy to organize main loop like this:

fn main() {
    // do some initilization
    
    // start main loop
    loop {
        // handle input 

        // update logic

        // draw frame
    }
}

It is fixable on Android with threads, but on web there is not way to "pause" and "resume" wasm execution, so no wasm code should block ever. While that loop is blocking for the entire game execution! The C++ solution for that problem: https://kripken.github.io/blog/wasm/2019/07/16/asyncify.html

But in Rust we have async/await. Rust's futures is basicly a continuations - future's stack may be store into a variable to later pause/resume execution of future's code.

async/await in macroquad is used without any external dependencies - no runtime, executor or even futures-rs are involved. Its just a way to preserve main's stack on WASM and keep the code cross platform without any wasm-specific main loop.

Dependencies

~3MB
~69K SLoC