[][src]Crate riddle

About Riddle

Riddle is a Rust media library in the vein of SDL, building as far as possible on the most active/standard rust libraries (winit, wgpu, image, etc). Riddle is NOT an engine, or a framework. It is a library devoted to exposing media related features in a unified way while avoiding prescribing program structure [note 1].

The rough feature set is listed here, along with the crates the features are primarily built upen. Riddle is only possible due to the massive efforts of the greater rust community.

This crate depends on an array of crates, each of which implements a specific feature. All sub-crates can be used independently of the top level riddle crate, but are best used by adding a dependency on riddle with appropriate feature flags configured.

Each crate fully wraps the underlying libraries to allow for a consistent API to be preserved between releases. Crates also contain extension traits, to provide direct access to the underlying types. The few exceptions to this, where types from other crates are exposed through Riddle's public API are where those crates have become defacto standards for cross crate integration, such as mint, and raw-window-handle.

Cargo Features

Getting started

Add a git dependency in your cargo.toml [note 2].

[dependencies.riddle]
version = 0.1
git = "https://github.com/vickles/riddle/"
tag = "0.1.0"

Place the following in main.rs:

use riddle::{*, platform::*, renderer::*, common::Color};

fn main() -> Result<(), RiddleError> {
    // Initialize the library
    let rdl = RiddleLib::new()?;

    // Create a window and renderer
    let window = WindowBuilder::new().build(rdl.context())?;
    let renderer = Renderer::new_from_window(&window)?;

    // Start the main event loop
    rdl.run(move |rdl| {
        match rdl.event() {
            Event::Platform(PlatformEvent::WindowClose(_)) => rdl.quit(),
            Event::ProcessFrame => {
                // Clear the window with black every frame
                let mut render_ctx = renderer.begin_render().unwrap();
                render_ctx.clear(Color::BLACK);
                render_ctx.present();
            }
            _ => (),
         }
    })
}

Notes

  1. A necesary exception is the top level RiddleLib::run function which must be used if riddle::platform is to be used.
  2. Currently Riddle depends on some patches to underlying libraries, which are being maintained in forked git repositories until the changes are integrated upstream. This means Riddle can't be uploaded to crates.io at the moment.

Re-exports

pub use riddle_common as common;
pub use riddle_image as image;
pub use riddle_input as input;
pub use riddle_math as math;
pub use riddle_platform_winit as platform;
pub use riddle_time as time;
pub use riddle_audio as audio;
pub use riddle_renderer_wgpu as renderer;
pub use riddle_font as font;

Structs

RiddleContext

Riddle main thread context. It can be accessed before the main event loop is started via RiddleLib::context and is provided to the event loop update closure.

RiddleLib

Riddle library initializer

RiddleState

Riddle subsystem state handles

Enums

Event
RiddleError