This is a template project for using Rust in Protologic.
- Clone this repository
- Install the
wasmtoolchain for Rust:- Open terminal (e.g. PowerShell/bash):
- Run:
rustup target add wasm32-wasi
- Download the latest
binaryenrelease, place it intools/binaryen - Run
build.ps1to compile the demo fleet. - todo: sim instructions/link
- todo: player instructions/link
If you do not require the entire example project protologic_core is also available on crates.io.
The project is split into two Rust "crates".
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 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.
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!
}