Matt's ASCII Game Engine core crate

Overview

MAGE Engine Core crate

Example screenshot

A 100% safe Rust ASCII game engine for writing text-based tools or tile-based games similar to traditional Rogue-likes.

This crate manages the Mage App trait, the Mage Config struct and the rendering engine. The rendering engine will use the GPU to render tiles (typically ASCII characters) to the screen at blazing fast rates. It can render 30000 characters at around 2000 fps on a nVidia RTX2080 card (so 60 million characters per second).

The App trait provides an interface of two methods: tick and present. The tick method is used for the simulation part of your game. Delta time, input and some other information is passed to the host program. Similarly, the present method is used for rendering. Various u32 slices are passed to the host to read and write to/from.

The Config has information to pass initialisation hints to the engine, including the tile data, window size etc.

After setting this up, the host application calls mage_core::run(...) to kick off the main loop.

How it works

The GPU runs a fragment shader that requires 4 textures:

  • Font/tile texture
  • Character texture
  • Foreground colour texture
  • Background colour texture

The font/tile texture

This is an image (typically a PNG image), that contains 256 tile images arranged in a 16x16 grid. Below is an example of such an image:

Font example image

And is in fact the default image used if one is not given. A single byte can be mapped to each tile (as there are 256 of them).

Character texture

The red channel (or lowest 8 bits) of the character texture represents the tile. This means that the other 24 bits are not used and can, in fact, be used by the application for whatever purpose. Each pixel on the texture represents a single character and the texture dimensions match the number of character cells that can be fit on to the window. As the window changes size, this texture is resized. The current width and height of this texture (in characters) is passed to the application for the present method.

Foreground colour texture

Similar to the character texture, each pixel represents a character cell and its dimensions are the same. Each u32 entry represents the foreground colour the character should take. The u32 has the format ABGR. The alpha channel is ignored and can hold whatever the application wishes.

Background colour texture

This is the same as the foreground colour texture but determines the background colour for the character cell.

Combining it all.

The GPU fragment shader combines the four textures to render the entire screen. The foreground colour, background colour and character textures combine for each character cell to determine the colour and contents of that cell. The contents are lifted from the font/tile texture according to the index given in the character texture. The shader is actually quite simple and can be seen in src/shader.wgsl.

Building

Building it is quite simple:

$ cargo build [--release]

Examples

There are various examples included that I used to test the engine and to help users understand how to use Mage. For now, this is the sole documentation but I will endeavour to write a Mdbook later.

Examples are run the usual way:

$ cargo run --release --example [example name]

For example, for an example that tries to use every feature of Mage:

$ cargo run --release --example basic

Features

  • Simple API
  • Alt+Enter to toggle fullscreen
  • Cross-platform (should work on all major OSes).
  • Rendering is 100% GPU once the textures are set up.

Disclaimer

This is currently work in progress and is not ready for production. It is missing vital features including, but not limited to:

  • Keyboard and mouse input
  • An ECS system
  • Audio support
You might also like...
A blazing fast, type-safe template engine for Rust.

markup.rs A blazing fast, type-safe template engine for Rust. markup.rs is a template engine for Rust powered by procedural macros which parses the te

User-friendly secure computation engine based on secure multi-party computation
User-friendly secure computation engine based on secure multi-party computation

CipherCore If you have any questions, or, more generally, would like to discuss CipherCore, please join the Slack community. See a vastly extended ver

Minimal compile-time Rust template engine

boilerplate boilerplate is a minimal compile-time Rust text template engine. Quick Start Add boilerplate to your project's Cargo.toml: [dependencies]

Kinda functional block engine for testing bundles on jito-solana locally

Half Baked Block Engine About This is a half-baked block engine. It can be used for testing bundles running through jito-solana. Shortcomings The bare

⋰·⋰ Feeless is a Nano cryptocurrency node, wallet, tools, and Rust crate.

⋰·⋰ Feeless What is Feeless? Feeless is a Nano cryptocurrency node, wallet, tools, and Rust crate. This is not the official project for Nano, only an

Example crate using fltk-build

white-frame This is just an example showing the use of fltk-build to create native C/C++ FLTK and cfltk modules for fltk-rs. This repo contains 2 exam

Yi Token by Crate Protocol: the primitive for auto-compounding single token staking pools.
Yi Token by Crate Protocol: the primitive for auto-compounding single token staking pools.

yi Yi Token by Crate Protocol: the primitive for auto-compounding single token staking pools. About Yi is a Solana primitive for building single-sided

This crate reimplements Gelato's Relay SDK in Rust

Gelato Relay SDK This crate reimplements Gelato's Relay SDK in Rust. It simply wraps Gelato Relay requests and responses to/from Gelato endpoints with

Helpers crate to simplify ink! chain extension development

OpenBrush Chain Extension library The library provides tools and primitives to simplify the development of chain extensions for ink! and for the subst

Owner
null
EXPERIMENTAL: Bitcoin Core Prometheus exporter based on User-Space, Statically Defined Tracing and eBPF.

bitcoind-observer An experimental Prometheus metric exporter for Bitcoin Core based on Userspace, Statically Defined Tracing and eBPF. This demo is ba

0xB10C 24 Nov 8, 2022
Core Rust-C FFI for Stackmate Wallet.

STACKMATE-CORE A Rust-C FFI library exposing composite functionality from rust-bitcoin & bdk; to create cross-platform descriptor wallets. Currently u

Vishal Menon 5 May 31, 2022
Opendp - The core library of differential privacy algorithms powering the OpenDP Project.

OpenDP The OpenDP Library is a modular collection of statistical algorithms that adhere to the definition of differential privacy. It can be used to b

OpenDP 176 Dec 27, 2022
A rust implementation of the ABCI protocol for tendermint core

?? DEPRECATED ?? This repo has been deprecated. Development work continues as the "abci" crate of informalsystems/tendermint-rs. Please reference that

Tendermint 117 Dec 12, 2022
Enigma Core library. The domain: Trusted and Untrusted App in Rust.

Enigma Core library Service Master Develop CI Badge Pure Rust Enclave && Untrusted in Rust. Core is part of the Enigma node software stack. The Core c

SCRT Labs 89 Sep 14, 2022
Aptos-core strives towards being the safest and most scalable layer one blockchain solution.

Aptos-core strives towards being the safest and most scalable layer one blockchain solution. Today, this powers the Aptos Devnet, tomorrow Mainnet in order to create universal and fair access to decentralized assets for billions of people.

Aptos Labs 4.7k Jan 6, 2023
Core contracts for Suberra Protocol.

Suberra Core Contracts Core contracts for Suberra. Contract Description product-factory Factory that handles the instantiation and creation of the pro

Suberra Protocol 4 Dec 12, 2022
Dexios-Core is a library used for managing cryptographic functions and headers that adhere to the Dexios format.

What is it? Dexios-Core is a library used for managing cryptographic functions and headers that adhere to the Dexios format. Security Dexios-Core uses

brxken 3 Jul 4, 2022
An extremely high performance matching engine written in Rust.

Galois Introduction Galois is an extremely high performance matching engine written in Rust, typically used for the crypto currency exchange service.

UINB Tech 66 Jan 7, 2023
zkSync: trustless scaling and privacy engine for Ethereum

zkSync: scaling and privacy engine for Ethereum zkSync is a scaling and privacy engine for Ethereum. Its current functionality scope includes low gas

Matter Labs 1.9k Jan 1, 2023