GitXplorerGitXplorer
D

voxel_engine

public
4 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
0b7d8b8665f69f4319623d0c839bb0e6bc2051b8

Improve example code

DDouglasDwyer committed 5 months ago
Unverified
0e963955dfa0b6d680047d6e71f50f5b5088cde4

Update Cargo.toml

DDouglasDwyer committed 5 months ago
Unverified
17c69333bfad0e8afb2679db0e8e3e05d4a2515e

Remove version from example_mod

DDouglasDwyer committed 5 months ago
Unverified
eae9bce6c3088de7d52f9e15c6385098ddda12d2

Run cargo fmt

DDouglasDwyer committed 5 months ago
Unverified
8229e3a85e8a8b8be5688902a9aaa54890412084

Clean up crates and add docs

DDouglasDwyer committed 5 months ago
Unverified
b1e1d180fb98df46a042a996fae76d528515d41a

Remove focused method

DDouglasDwyer committed 5 months ago

README

The README file for this repository.

voxel_engine

Crates.io Docs.rs

This repository contains the public modding API for the Octo voxel game engine. The modding API can be used to develop new games for the engine, in the form of WASM plugins. The following functionality is available:

  • Adjusting the camera position
  • Drawing in-game GUIs using egui
  • Reading user input, including mouse movements, key presses, and controller inputs

This crate is early in development, and breaking changes may occur at any time. This crate is not guaranteed to follow semantic versioning.

Getting started

The following is an abridged tutorial demonstrating how to compile/load a WASM plugin into the voxel engine. A complete example plugin can be found in the example_mod directory.

First, initialize a Rust project:

cargo new my_mod --lib

Next, add the following lines to the Cargo.toml:

[lib]
crate-type = [ "cdylib" ]  # Indicate that cargo should generate a .wasm file

[dependencies]
voxel_engine = { version = "0.1" }  # Provides access to engine APIs
wings = { version = "0.1" }  # Allows for creating WASM plugins

Then, create an example WingsSystem and export it. This will cause the engine to load the system:

use voxel_engine::*;
use voxel_engine::timing::*;
use wings::*;

// The game client will load all systems listed in brackets.
instantiate_systems!(Client, [HelloClient]);

/// A system that will print out the frame
/// time each frame.
#[export_system]
struct HelloClient {
    /// The context handle.
    ctx: WingsContextHandle<Self>
}

impl HelloClient {
    /// Event that executes once per frame
    fn print_frame_time(&mut self, _: &voxel_engine::timing::on::Frame) {
        println!("Frame time: {}", self.ctx.get::<dyn FrameTiming>().frame_duration().as_secs_f32());
    }
}

impl WingsSystem for HelloClient {
    const DEPENDENCIES: Dependencies = dependencies()
        .with::<dyn FrameTiming>();

    const EVENT_HANDLERS: EventHandlers<Self> = event_handlers()
        .with(Self::print_frame_time);

    fn new(ctx: WingsContextHandle<Self>) -> Self {
        println!("Hello client!");
        Self { ctx }
    }
}

Next, build the WASM mod with Cargo:

cargo build --target wasm32-wasip1

The resultant WASM binary will be located under target/wasm32-wasip1/release. This file can be selected and loaded into the voxel engine.