Code Monkey home page Code Monkey logo

macroquad's Introduction

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

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)
  • Immediate 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.

Platinum sponsors

Macroquad is supported by:

macroquad's People

Contributors

akholetsky avatar arirawr avatar cedric-h avatar gardrek avatar johndoneth avatar josephcatrambone avatar mlambir avatar mvlabat avatar nokola avatar not-fl3 avatar totallyuniquelily avatar zotho avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.