23 stable releases (10 major)
Uses old Rust 2015
11.0.0 | Feb 8, 2024 |
---|---|
10.0.0 | Jan 31, 2024 |
9.0.0 | Jan 26, 2024 |
8.1.1 | Jan 23, 2024 |
1.0.0 | Nov 23, 2023 |
#33 in #target
25 downloads per month
36KB
809 lines
Protologic.rs
This is a template project for using Rust in Protologic.
Getting Started
- Clone this repository
- Install the
wasm
toolchain for Rust:- Open terminal (e.g. PowerShell/bash):
- Run:
rustup target add wasm32-wasi
- Download the latest
binaryen
release, place it intools/binaryen
- Run
build.ps1
to compile the demo fleet. - todo: sim instructions/link
- todo: player instructions/link
Alternative
If you do not require the entire example project protologic_core
is also available on crates.io.
Project Structure
The project is split into two Rust "crates".
protologic_core
protologic_core
contains the bindings to the game API. lowlevel
are the direct bindings to the unsafe WASM API. highlevel
are slightly nicer to use wrappers around the low level bindings. You should never need to edit this project.
demo_fleet
demo_fleet
contains a simple demo fleet. lib.rs
is the root of this project and contains a tick
function that the game will call every tick:
#[no_mangle]
pub extern fn tick()
{
// Every frame
}
state.rs
is the main implementation of the demo fleet. You can delete all of this, or you can use it as an example framework to get started.
Special Methods
If your code calls the special method sched_yield()
then execution of your program will be immediately suspended, execution will resume from that point next frame instead of calling tick()
. This allows you to write simpler programs, for example:
radar_trigger(); // Trigger radar, results will be available next frame
sched_yield(); // Wait for the next frame.
for i in 0..radar_get_target_count() {
// Radar contact!
}
Dependencies
~0.4–0.9MB
~20K SLoC