在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:not-fl3/macroquad开源软件地址:https://github.com/not-fl3/macroquad开源编程语言:Rust 99.7%开源软件介绍:macroquad
Features
Supported platforms
Build instructionsSetting up a macroquad projectMacroquad is a normal rust dependency, therefore an empty macroquad project may be created with: # Create empty cargo project
cargo init --bin Add macroquad as a dependency to Cargo.toml: [dependencies]
macroquad = "0.3" Put some macroquad code in use macroquad::prelude::*;
#[macroquad::main("BasicShapes")]
async fn main() {
loop {
clear_background(RED);
draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
draw_rectangle(screen_width() / 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN);
draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW);
draw_text("IT WORKS!", 20.0, 20.0, 30.0, DARKGRAY);
next_frame().await
}
} And to run it natively: cargo run For more examples take a look on Macroquad examples folder linux# ubuntu system dependencies
apt install pkg-config libx11-dev libxi-dev libgl1-mesa-dev libasound2-dev
# fedora system dependencies
dnf install libX11-devel libXi-devel mesa-libGL-devel alsa-lib-devel
# arch linux system dependencies
pacman -S pkg-config libx11 libxi mesa-libgl alsa-lib windowsOn windows both MSVC and GNU target are supported, no additional dependencies required. Also cross-compilation to windows from linux is supported: rustup target add x86_64-pc-windows-gnu
cargo run --target x86_64-pc-windows-gnu wasmrustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown This will produce .wasm file in And then use the following .html to load it: index.html<html lang="en">
<head>
<meta charset="utf-8">
<title>TITLE</title>
<style>
html,
body,
canvas {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
position: absolute;
background: black;
z-index: 0;
}
</style>
</head>
<body>
<canvas id="glcanvas" tabindex='1'></canvas>
<!-- Minified and statically hosted version of https://github.com/not-fl3/macroquad/blob/master/js/mq_js_bundle.js -->
<script src="https://not-fl3.github.io/miniquad-samples/mq_js_bundle.js"></script>
<script>load("CRATENAME.wasm");</script> <!-- Your compiled wasm file -->
</body>
</html> One of the ways to server static .wasm and .html: cargo install basic-http-server
basic-http-server . tipsAdding 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/awaitWhile macroquad attempts to use as few Rust-specific concepts as possible, detailsThe problem: on WASM and android it's not really easy to organize the main loop like this:
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 async/await in macroquad is used without any external dependencies - no runtime, executor or even futures-rs are involved. It's just a way to preserve Community
Platinum sponsorsMacroquad is supported by: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论