The whole manual in one page. Print it, or choose Save as PDF as the printer. The API reference stays on the site: https://omardev29.github.io/rmp-docs/reference/.
https://omardev29.github.io/rmp-docs/ — documents raylib_multiplatform at 982bf2a1.
https://omardev29.github.io/rmp-docs/getting-started/index.html
rmp is the one command: it makes a game, builds it, runs it, tests
it and ships it. You install it once, and every game you make has its own copy.
cmake package can be older than 3.30, and an
older CMake stops the first build before anything is compiled: cmake --version says
which one you have.Everything a build needs — the compiler, CMake, Ninja, Python, git and the X11 headers — for
each family of distributions. Any C++20 compiler does: [dev] compiler = "clang" uses
clang where it is installed and the system's compiler where it is not.
Debian and Ubuntu
sudo apt install build-essential cmake ninja-build python3 git \
libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev libgl1-mesa-devUbuntu 24.04's cmake is 3.28; take a newer one from Kitware's
own apt repository, or pipx install cmake.
Fedora
sudo dnf install gcc-c++ cmake ninja-build python3 git \
libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa-libGL-develArch
sudo pacman -S --needed base-devel cmake ninja python git \
libx11 libxrandr libxi libxcursor libxinerama mesaAlpine,
3.21 or newer for a CMake of 3.30. Its Ninja is samurai, its compiler and
make come in build-base, and GLFW reads the kernel's input headers.
Alpine ships doas rather than sudo:
doas apk add build-base cmake samurai python3 git linux-headers \
libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev mesa-devOr install nothing on the machine at all, and work inside the image CI builds in: In the build image, with Podman.
On a Linux console with no desktop, rmp builds for DRM/KMS instead, and needs the
DRM headers in their place; Linux from a
console says which, and how the game reaches the screen.
One line, in a terminal. On Linux and macOS:
curl -fsSL https://omardev29.github.io/rmp-docs/install.sh | shOn Windows, in PowerShell:
irm https://omardev29.github.io/rmp-docs/install.ps1 | iexIt needs git and Python 3.11 or newer, and says how to get either if it is missing. It puts the
framework in your home folder and rmp on your PATH, as you and without
sudo, and at the end it lists anything a build still needs on this machine.
Install rmp has the line for the BSDs and for Linux
without curl, where everything goes, and how to update and remove it. Open a new
terminal, and check:
rmp helprmp new my_game
cd my_game
rmp runrmp new makes a folder with the framework, the build and CI for every target, and
a small game in src/ to start from. rmp run builds it and opens the
window: a menu with a rabbit on it. The first build compiles raylib and the framework, so it takes
a while; after that only what changed is compiled again.
The folder is also a git repository, with every file already added. Commit it, so that what
the next pages change is yours to see in git diff:
git commit -m "New game"Most of the folder is the framework and the build, and you do not edit it. Your game is seven places:
| Path | What it is |
|---|---|
src/main.cpp | Where the game starts. It names the first scene, and that is all it does. |
src/scenes/ | The scenes, one per file: main_menu.h and main_menu.cpp are the menu you just saw. |
include/ | Your headers, when you want them apart from the code. This tutorial keeps each header beside its .cpp instead. |
resources/ | Pictures and sounds, loaded by name. rabbit.png is the one on the menu. |
tests/game/ | Tests of your game, run with no window by rmp test unit. It starts with one, of the menu. |
branding/icon.png | The app's icon: the Android and iOS icons, and the one inside the Windows .exe, are all made from this one picture. It is not in resources/ because the game never loads it. |
raylib_multiplatform.toml | The game's name, its window, its app ids and which platforms to build. |
src/rmp/ and include/rmp/ are the framework itself, inside your game.
Every other .cpp under src/, in any folder, is compiled without being
listed anywhere: adding a file to the game touches no build file.
The new game's raylib_multiplatform.toml has your game's name in it, and app ids
that start with com.example.. Set real ones before your first release:
rmp deploy refuses to tag a release while they are placeholders, because a Google Play
app id can never change once it is published.
The pages that follow turn the game rmp new made into a real one, a step at a time:
Coin Rabbit, in which a rabbit gathers coins while bats close in on it. Each page shows
every source file it adds or changes, whole, and the keys it sets in
raylib_multiplatform.toml, and ends with a game that builds and runs.
https://omardev29.github.io/rmp-docs/getting-started/install.html
One line in a terminal gets the framework and puts rmp on your PATH.
It installs into your home folder, as you, and asks for no administrator: nothing in it runs
sudo, and nothing in it installs a package.
On Linux and macOS:
curl -fsSL https://omardev29.github.io/rmp-docs/install.sh | shThe same script, fetched with what each system has. None of the three BSDs has
curl in its base system:
wget -qO- https://omardev29.github.io/rmp-docs/install.sh | sh # Linux without curl
fetch -o - https://omardev29.github.io/rmp-docs/install.sh | sh # FreeBSD
ftp -o - https://omardev29.github.io/rmp-docs/install.sh | sh # OpenBSD, NetBSDOn Windows, in PowerShell — Windows PowerShell 5.1 or PowerShell 7:
irm https://omardev29.github.io/rmp-docs/install.ps1 | iexThen open a new terminal and check:
rmp helpA line that pipes a download into a shell runs whatever is at that address, so read it first if
you like: it is install.sh and install.ps1.
They are the framework's tools/install.sh and tools/install.ps1, served
by this site byte for byte as they are at the commit it documents — this site's own checks fail
the day they are not.
Two
things, and the installer stops and says how to get whichever is missing, having installed
nothing: git, which fetches the framework and every update after it, and
Python 3.11 or newer, which rmp is written in. It asks every Python it
finds for its version rather than trusting the name: macOS's own python3 is older than
3.11, and on Windows python3 can be the Microsoft Store's placeholder. On a Mac, git
comes with Apple's command line tools, and without them the installer stops and says
xcode-select --install.
Building a game
needs more — CMake, Ninja, a C++ compiler, and on Linux and FreeBSD the X11 development headers —
and the installer looks for those at the end. What is missing is listed with the command that
installs it on this system: apt, dnf, pacman,
zypper, apk, Homebrew, pkg, pkg_add or pkgin, and on
Windows winget. The command is printed for you to run, as root where the system wants
it; the installer never runs it.
On
a Linux console with no desktop, rmp builds games for DRM/KMS, straight to the screen,
and the installer decides the same way: there it looks for the libdrm, GBM, EGL and OpenGL ES
headers instead of X11's, and says it is on a console.
Linux from a console has the packages for each
system, and what comes after.
| Linux, macOS, the BSDs | Windows | |
|---|---|---|
| The framework, a git clone of it | ~/.local/share/rmp | %LOCALAPPDATA%\rmp |
The rmp you type | ~/.local/bin/rmp, a link to the clone's | %LOCALAPPDATA%\Programs\rmp\rmp.cmd, a two-line script that calls the clone's |
| Your PATH | a marked block in your shell's startup file, only if ~/.local/bin is not on PATH already | that folder added to your user PATH |
The
clone is of the framework's main, without the file contents of old commits, so it is
the size of one checkout rather than of the whole history.
The
startup file is the one your login shell reads, from $SHELL: ~/.zshrc for
zsh, in $ZDOTDIR when that is set; ~/.bashrc for bash on Linux and, on
macOS, the first of ~/.bash_profile, ~/.bash_login and
~/.profile that exists; ~/.config/fish/conf.d/rmp.fish for fish, under
$XDG_CONFIG_HOME when that is set;
~/.cshrc for csh, and ~/.tcshrc for tcsh when there is one; for ksh, the
file $ENV names, when it names one; and ~/.profile for any other. The
block it adds starts with # added by rmp install: ~/.local/bin on PATH and ends with
# end of rmp install, and it is added once however many times you install.
On
Windows the folder on PATH holds only that small script, and not the clone itself: in the clone,
PowerShell would find rmp.ps1 first, and its default execution policy refuses to run a
script from your own disk. So nothing needs Set-ExecutionPolicy, and
rmp is the same command in PowerShell and in cmd. Your user PATH is changed in place,
keeping every entry it had, and Windows is told, so a terminal opened from now on sees it without
logging out; the PowerShell window you installed from has it already.
The
same line run again updates instead of installing: when the clone is already there, it runs
rmp update in it, and then rmp install, which finds everything in place and
changes nothing. Or run the update yourself, from anywhere:
rmp updateIt fetches the framework's main and moves the clone forward to it, and says which
commit it went from and to. It never merges: a clone with changes of its own, on another branch,
or with commits the framework does not have is refused, and told what to do about it.
Your games are not touched. Each game carries its own copy of the framework and of
rmp, and keeps the one it was made with; rmp new makes the next game from
the updated framework. The
rmp command explains why.
The installer is a clone and two commands, and the commands are rmp's own. A
framework you cloned yourself — to work on it, or into a folder you chose — goes on your PATH the
same way, by running its rmp once by its path:
git clone https://github.com/omardev29/raylib_multiplatform ~/raylib_multiplatform
~/raylib_multiplatform/rmp installOn Windows, rmp.cmd install in that folder. rmp install makes the link,
or the script on Windows, and says so when it is already there; when another rmp is in
the way — a link to some other clone — it refuses and names it, and rmp install force
replaces it. rmp update then updates that clone.
Both
act on the framework the rmp you typed belongs to, wherever you type them. A game's own
copy refuses them: it is not the framework on your PATH, and it is never updated.
Completion, hover and go-to-declaration
come from clangd, which VS Code, LazyVim, Zed and most editors run. The framework, and every game
rmp new makes, carries its settings in .clangd: it reads what the debug build
was compiled with, so build once (rmp build) and restart clangd. It is the desktop build on
every machine, Windows included: no Android NDK and no Xcode, and the code for other platforms is
greyed out behind its #if.
Your game's code is checked as the compiler
checks it, warnings as warnings. The framework's code and what it vendors — include/rmp/,
src/rmp/, thirdparty/ — complete and navigate like any other, and clangd
reports nothing in them: the framework's own CI builds and checks them. A Visual Studio newer than
your clangd, or a MinGW flag clang does not know, is not an error in the editor either.
The
packages above go on your machine, one distribution at a time. The other way is to install none
of them: CI builds every target inside one image, ghcr.io/omardev29/raylib-build, and
you can work inside the same one. It is Ubuntu with every compiler and tool rmp uses —
clang, gcc, CMake, Ninja, zig, Emscripten for the web, MinGW-w64, clang-cl and Wine for Windows,
tcc, the Android SDK and NDK, the X11, Wayland and DRM headers — at the versions CI's own builds
are proved with. It weighs several gigabytes, and carries more than a 2D desktop game will ever
ask for; in exchange, nothing in it has to be installed later, and none of it touches your
system. Every game carries the digest it was made with, in
thirdparty/FROZEN_VERSIONS.md.
Podman runs it with no daemon and no root: rootless.
Inside the container you are root, and that root is your own user outside, so whatever it writes in
your game's folder is yours. Install Podman from your system's packages
(apt, dnf, pacman and apk all call it
podman), then, from your game's folder:
IMAGE=ghcr.io/omardev29/raylib-build@$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
podman pull "$IMAGE"
podman create --name my-game-dev -it --init \
-v "$PWD":/work:Z -w /work "$IMAGE" bash
podman start -ai my-game-devThat is a container of your own, kept between sessions: podman start -ai
my-game-dev opens it again, with anything you added to it still there, and your game's
folder is /work inside it. Build and test there with the game's own
rmp:
./rmp build
./rmp test
./rmp build windowsA few things worth knowing. --init is not optional: without an init process a game
started as the container's first process does not stop when asked. :Z labels the folder
for SELinux, where the system has it (Fedora does), and changes nothing where it does not. The build
folders remember the path they were configured from, /work inside the container, so
CMake refuses one made outside it, and the other way round: build in one place, or
./rmp clean when you move.
The game's window needs a display. On a Linux desktop, X11 or Wayland with XWayland, give the
container yours when you create it — -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix
--device /dev/dri --security-opt label=disable — and ./rmp run opens on your
screen. With no display to give, the next section's container brings a desktop of its own, in the
browser.
The
framework, and every game rmp new makes, carries a development container:
.devcontainer/devcontainer.json. It is the build image CI runs in, pinned by the same
digest — every compiler, tool and library rmp uses, tcc, MinGW-w64, clang-cl and Wine
included — with a light desktop on top for the game's window. In VS Code, Dev Containers: Reopen
in Container; in a GitHub Codespace it is what starts. rmp run,
rmp test and rmp build windows work at once, with nothing installed on
your machine but the editor and Docker.
The desktop is a page in the browser: open the forwarded port 6080 and type the password
vscode, and the game's window is there. It draws with the CPU, not your graphics card,
which is plenty for a 2D game and slow for a heavy 3D one.
Nothing is installed anywhere else, so removing it is deleting what the table above lists. On Linux, macOS and the BSDs:
rm ~/.local/bin/rmp
rm -rf ~/.local/share/rmpand, if the installer added one, the block from # added by rmp install to
# end of rmp install in your shell's startup file — for fish, the whole of
rmp.fish. Other programs install into ~/.local/bin
too, so you may want to keep that folder on your PATH anyway.
On Windows, delete %LOCALAPPDATA%\rmp and %LOCALAPPDATA%\Programs\rmp,
and take %LOCALAPPDATA%\Programs\rmp out of your user PATH in Windows' "Edit
environment variables for your account".
Your games keep working without it: each has its own rmp at its root,
./rmp, rmp.ps1 and rmp.cmd, and its own copy of the
framework.
Next: make a game.
https://omardev29.github.io/rmp-docs/getting-started/your-first-scene.html
A scene is one screen of the game: the main menu is a scene, the level is a scene,
a pause menu is a scene. The game rmp new made has one, a menu. This page replaces it
with your own and adds a second one for Play to go to.
Open src/main.cpp. You will not change it in this tutorial, and it is worth
reading once:
// Your game starts here, and this is all of it.
//
// RMP_GAME opens the window from [window] in raylib_multiplatform.toml, enters
// the scene you name, runs it every frame, and shuts everything down on the way
// out — on every target, including the two where main() is not a main() at
// all. Your work is in src/scenes/ and src/objects/.
#include <rmp/app.h>
#include "scenes/main_menu.h"
RMP_GAME(MainMenuScene);
RMP_GAME is the whole program. It opens the window
described in raylib_multiplatform.toml, enters the scene you name, runs it every
frame, and closes everything on the way out. There is no InitWindow() and no frame
loop in your code because the platforms do not agree on who owns the loop: on the desktop it is a
while in main(), in the browser it is the browser, and on iOS it is
UIKit. The macro writes the right one for each, so your code is the same everywhere.
The scene is named here, in C++, and not in the .toml. A name in a text file
would have to be turned into a type at run time, and the usual way to do that in C++, a global
that registers itself, is exactly what a linker throws away from a library when nothing refers to
it, and the result is a game that runs on your desktop and finds no scenes on a phone. Naming the
type means a typo is a compile error instead.
rmp new named the window after the folder. Give the game its real name in
raylib_multiplatform.toml, under [window]:
[window]
title = "Coin Rabbit"The title goes in the window's title bar on the desktop, and under the app's icon on Android
and iOS. The values your code can use reach it as macros, written again on every build from the
.toml: this one is RMP_WINDOW_TITLE, and the menu below shows it. You
never include anything to get them; every header of the framework brings them along.
A scene is a class that derives from rmp::Scene and
overrides the hooks it needs. Replace the whole of the template's menu, header first:
#pragma once
// The title screen: the game's name, Play and Quit.
#include <rmp/scene.h>
class MainMenuScene : public rmp::Scene {
public:
void _draw() override;
};The menu needs one hook, _draw(), which runs
every frame, in screen space. The underscore is a rule that holds across the whole framework: a
method whose name starts with _ is one the framework calls on your type. You
override it; you never call it yourself.
Then the code, which replaces src/scenes/main_menu.cpp:
#include "main_menu.h"
#include "game.h"
#include <rmp/app.h>
#include <rmp/ui.h>
void MainMenuScene::_draw() {
rmp::ui::begin();
rmp::ui::text(RMP_WINDOW_TITLE, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play", { .style = rmp::ui::Variant::PRIMARY })) {
rmp::Scene::change<GameScene>();
}
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
rmp::ui::end();
}Everything between rmp::ui::begin() and
rmp::ui::end() is laid out as a column in the middle
of the screen, which is what a menu is. Nothing in it says where, or how big: the layout is
worked out at the size you set in [window] and scaled to the real window, so the
same menu fits a phone and a 4K monitor. A mouse, a finger, the keyboard and a gamepad all work
it, with nothing written for any of them.
rmp::ui::button() draws a button and returns
true on the frame it is pressed, so the button and what it does are one line. The
braces after a label are an options struct written with designated initialisers:
{ .style = rmp::ui::Variant::PRIMARY } marks Play as the button to press. C++20
wants the fields in the order the struct declares them, and every options struct in the framework
is ordered the way they are usually written.
rmp::Scene::change<GameScene>() ends
this scene and starts a GameScene. It does not happen on that line: it happens when
the frame ends. The call is made from inside the menu's own _draw(), and destroying
the menu right there would pull it out from under the code that is still running in it.
rmp::app::quit() asks the game to close. It
lets the frame finish and then shuts everything down in order, which is why it is not
exit(). On iOS it closes nothing, because Apple rejects an app that closes itself:
it writes a warning to the log, once, and returns (with [dev] strict on, a debug
build stops at that warning, as at any other). The #if hides the button there rather
than leave one that does nothing.
The
game rmp new made also came with a test of its menu, in
tests/game/main_menu_test.cpp. It makes the menu with no window, runs its
_ready(), and checks that every file the menu asked for was found. A menu that asks
for none passes, with a warning that the test checked nothing — and yours loads nothing yet: the
rabbit comes back later. Keep the check, and leave the warning out:
// The main menu finds every file it loads: a file renamed in resources/ and
// not in the code leaves a hole in the picture rather than a crash, and this
// says which.
#include <doctest.h>
#include <rmp/assets.h>
#include "scenes/main_menu.h"
TEST_CASE("the main menu finds every file it loads") {
const int failed = rmp::assets::failed_loads();
MainMenuScene menu;
menu._ready();
CHECK(rmp::assets::failed_loads() == failed);
}A test is the one place that calls a hook itself: it stands in for the framework. Every file
in tests/game/ is built with your game — everything in src/ but
main.cpp — and run with no window by rmp test unit, and by CI.
Testing has the rest.
Play goes to GameScene, which does not exist yet. Make two new files in
src/scenes/, a header and its code:
#pragma once
// The game. For now, a screen that says so and a way back.
#include <rmp/scene.h>
class GameScene : public rmp::Scene {
public:
void _draw() override;
};#include "game.h"
#include "main_menu.h"
#include <rmp/ui.h>
void GameScene::_draw() {
rmp::ui::begin();
rmp::ui::text("The game goes here.");
if (rmp::ui::button("Back")) rmp::Scene::change<MainMenuScene>();
rmp::ui::end();
}The game has nothing in it yet: a line of text, and a way back. Each scene's header includes
only <rmp/scene.h>; it is the .cpp files that include each other's
headers, which is what lets two scenes name each other without a circle of includes.
Nothing else needs to know the new files exist. Every .cpp under src/
is compiled, on every platform, so adding a scene is adding its files.
These are all the hooks a scene can override. Each has an empty default, so a scene writes only the ones it uses.
| Hook | Runs |
|---|---|
_ready() | Once, when the scene starts. The window exists by then, so this is where a scene loads what it needs. |
_update(float delta) | Every frame, before anything is drawn. delta is the seconds since the last frame. |
_draw() | Every frame, after the scene's objects have been drawn, in screen space. |
_suspend() and _resume() | When another scene is put on top of this one, and when it comes off again. |
_end() | Once, when the scene ends for good. |
The Scenes chapter of the manual has the rest: the
stack of scenes, and passing data from one to the next. The
Interface chapter has the rest of rmp::ui.
rmp runThe menu has the game's name, Play takes you to the game screen and Back brings you to the
menu again. Try it without the mouse: the first button of each screen already has the focus, so
Enter presses it, and the up and down arrows move between buttons. The template's
rabbit.png is still in resources/, unused for now: it comes back as the
player.

https://omardev29.github.io/rmp-docs/getting-started/a-player.html
A scene holds objects: the player, a coin, an enemy, a bullet are all the same kind of thing, and what makes them different is what you put in them. This page puts the first one in the game, a box for now, that moves with the keyboard, a gamepad, the mouse or a finger.
The player gets a class of its own, because it has a few things to say about itself. Objects go in a folder of their own, beside the scenes, as the names of the two new files say:
#pragma once
// The rabbit: what it looks like, what it collides as, and how it moves.
#include <rmp/object.h>
class Player : public rmp::Object {
public:
void _ready() override;
void _update(float delta) override;
};#include "player.h"
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/math.h>
namespace {
constexpr float SPEED = 260; // design units per second
} // namespace
void Player::_ready() {
// A white box until it has a picture.
shape = rmp::rect({ 40, 40 });
shape.color = RAYWHITE;
// Eight directions, from the keyboard, a d-pad or a stick.
add<rmp::behavior::TopDown>({ .speed = SPEED });
}
void Player::_update(float /*delta*/) {
// The mouse held down, or a finger on the screen: run towards it. Not when
// the pointer is on a button, which is the interface's and not the game's.
if (rmp::input::pointer_down() && !rmp::input::consumed_pointer()) {
const Vector2 to = rmp::input::pointer() - position;
if (Vector2Length(to) > 8) velocity = Vector2Normalize(to) * SPEED;
}
}An rmp::Object is mostly public fields that you
read and write directly: position,
velocity,
shape, and so on. There is no getter in front
of them because there is nothing for one to do. position is the object's
centre, unlike raylib, which draws from the top-left corner: the centre is what a
rotation turns about and what a distance is measured from, so nothing has to be corrected by half
a size.
An object draws its shape when it has no picture: here a white box, 40 units a
side. The picture comes later, and nothing else about the player will change when it does.
It has the same kind of hooks as a scene. _ready()
runs once, as soon as the object is in its scene; _update()
runs every frame.
Moving in eight directions from the keyboard, the d-pad and the stick is not something to
write by hand, so the player adds a behavior from the catalogue that does it:
rmp::behavior::TopDown. A behavior is a
plain struct, and its fields are its settings, written with designated initialisers:
{ .speed = SPEED }. It reads the input, sets the object's velocity, and the
framework moves the object by its velocity every frame. Going diagonally is not faster than
going straight, which is the bug in most hand-written movement.
The fields stay live after add():
get<rmp::behavior::TopDown>()->speed = 400 would be a power-up.
_update() adds the one thing TopDown does not do: while the mouse
button is held, or a finger is on the screen, the player runs towards it. The framework treats the
mouse and a touch as one pointer, which is what lets the same code run on a desktop and on a
phone without an #if.
rmp::input::pointer_down() is the
mouse button, or a finger, held down.rmp::input::consumed_pointer()
is true while the pointer belongs to someone else: a button or a panel of the interface under it,
or a scene on top of this one. Without it, pressing a button on screen would also send the player
running towards it.rmp::input::pointer() is where it is, in
the same units as position, whatever the camera is doing.The arithmetic on Vector2 comes from raylib's own raymath.h, which
<rmp/math.h> includes: the operators - and *, and
Vector2Length() and Vector2Normalize(). The object's own
_update() runs after its behaviors' and before it is moved, so the velocity it sets
is the one used.
TopDown does not read keys. It reads actions: a name with any number of
keys and buttons bound to it. These come defined:
| Action | Keyboard | Gamepad |
|---|---|---|
move_left | A, Left | d-pad left, left stick |
move_right | D, Right | d-pad right, left stick |
move_up | W, Up | d-pad up, left stick |
move_down | S, Down | d-pad down, left stick |
ui_accept | Enter, Space | bottom face button |
ui_cancel | Escape | right face button |
The game defines one more, in the game scene below:
rmp::input::action("pause", KEY_P, KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);The
type of each binding says which device it belongs to, so keys, mouse buttons, gamepad buttons and
half of a stick, made with rmp::input::stick(),
can share one list, and a value of any other type, a plain number for one, does not compile.
Defining a name again replaces it,
which is why rmp::input::action() can sit in a
scene's _ready() and run every time the scene starts.
The game then asks for the action by name, with
rmp::input::just_pressed("pause"), true on
the frame it goes down. Asked by name, an action is quiet whenever something else has the input:
a text field being typed in, or a scene on top of this one. That is what stops the key that closes
a menu from also doing something in the game underneath.
Escape is the game's to bind, with
nothing more to write. raylib makes it the key that closes the window, and in a game it is the
key for "back" and "pause", so the framework takes it back from raylib as the game starts. The
window's close button still closes the game; a game that wants a key to quit calls
rmp::app::quit() when that key is pressed.
The game scene now has a player in it instead of the text. Replace both of its files:
#pragma once
// The game: the player, in an arena the size of the design resolution.
#include <rmp/scene.h>
class GameScene : public rmp::Scene {
public:
void _ready() override;
void _update(float delta) override;
};#include "game.h"
#include "../objects/player.h"
#include "main_menu.h"
#include <rmp/input.h>
namespace {
// The arena is the design resolution: [window] width and height in the .toml.
constexpr Rectangle ARENA{ 0, 0, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT };
} // namespace
void GameScene::_ready() {
background = Color{ 52, 92, 60, 255 }; // grass
// P, Escape, or the gamepad's Start button.
rmp::input::action("pause", KEY_P, KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
spawn<Player>({
.position = { ARENA.width / 2, ARENA.height / 2 },
.edges = rmp::Edge::CLAMP,
.bounds = ARENA,
});
}
void GameScene::_update(float /*delta*/) {
// There is no pause menu yet, so for now "pause" goes back to the menu.
if (rmp::input::just_pressed("pause")) rmp::Scene::change<MainMenuScene>();
}spawn<Player>() makes a
Player, puts it in the scene, and calls its _ready(). The scene owns it
from then on: it is updated and drawn with the scene, and it goes when the scene goes. The braces
are its starting values, which spawn() applies before _ready() runs.
The arena is the size the .toml gives the window, [window]
width and height, which reach the code as
RMP_WINDOW_WIDTH and RMP_WINDOW_HEIGHT. The player is centred in it,
and .edges = rmp::Edge::CLAMP with .bounds = ARENA stops it at the
arena's edges.
The window is resizable,
though, and a phone's screen is whatever size it is. The scene's
camera decides what part of the world is on
screen, and it starts centred on the arena. On a window of another size it does what
[window] stretch in the .toml says, and rmp new wrote
"letterbox" there: the arena is scaled to fit the window and centred in it, with bars
of the clear colour around it, so the whole arena is in view at any size and either way round, and
nothing in the game says so. The menu needed none of this either: the interface scales on its
own.
background is the colour the frame is
cleared with. There is no pause menu yet, so for now pause goes back to the menu.
rmp runPlay, and the box moves with WASD, the arrows, a gamepad, or the mouse held down, and stops at the edges. Make the window bigger and the arena grows with it. P or Escape goes back to the menu.

The manual has a chapter for each thing this page touched: Objects, Behaviors, Input and the Camera.
https://omardev29.github.io/rmp-docs/getting-started/coins-and-bats.html
A game needs a goal and a danger. Here the goal is coins, one at a time and each in a new place, and the danger is bats that keep coming and chase the player. Three bites, and the game is over.
Every object collides with every other unless it is told otherwise, which is right until there
are two kinds of thing that should not notice each other. A bat flying over a coin must not pick
it up, and the game has to be able to say "bats hurt the player" without an if in
every collision. That is what collision layers are for. Give each kind of thing one bit, in a new
header beside the player's:
#pragma once
// Who collides with whom: one bit for each kind of thing in the game.
namespace layer {
constexpr unsigned PLAYER = 1u << 0;
constexpr unsigned COIN = 1u << 1;
constexpr unsigned BAT = 1u << 2;
} // namespace layerEach object has two of these numbers:
collision_layer is what it is, and
collision_mask is what it collides
with. Two objects touch when either one's mask has the other's layer in it. The player is on the
player's layer and collides with coins and bats; the rest of its file is as it was:
#include "player.h"
#include "layers.h"
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/math.h>
namespace {
constexpr float SPEED = 260; // design units per second
} // namespace
void Player::_ready() {
// A white box until it has a picture.
shape = rmp::rect({ 40, 40 });
shape.color = RAYWHITE;
collision_layer = layer::PLAYER;
collision_mask = layer::COIN | layer::BAT;
// Eight directions, from the keyboard, a d-pad or a stick.
add<rmp::behavior::TopDown>({ .speed = SPEED });
}
void Player::_update(float /*delta*/) {
// The mouse held down, or a finger on the screen: run towards it. Not when
// the pointer is on a button, which is the interface's and not the game's.
if (rmp::input::pointer_down() && !rmp::input::consumed_pointer()) {
const Vector2 to = rmp::input::pointer() - position;
if (Vector2Length(to) > 8) velocity = Vector2Normalize(to) * SPEED;
}
}The coins and the bats each have the player's bit in their mask and nothing else, so a bat and a coin never touch, and neither do two bats. The Collision chapter of the manual has the rest: solid objects that push each other apart, and the edges of the world.
The game scene gets three things to do, each in a function of its own: make a coin, make a bat, and end the game. Replace both files:
#pragma once
// The game: the rabbit, the coins and the bats, in an arena the size of the
// design resolution.
#include <rmp/scene.h>
class GameScene : public rmp::Scene {
public:
void _ready() override;
void _update(float delta) override;
void _draw() override;
private:
void spawn_coin();
void spawn_bat();
void caught();
rmp::Handle<rmp::Object> _player; // kept across frames, so a handle
int _coins = 0;
float _next_bat = 1; // seconds until the next bat comes
};#include "game.h"
#include "../objects/layers.h"
#include "../objects/player.h"
#include "game_over.h"
#include "main_menu.h"
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/random.h>
#include <rmp/ui.h>
#include <string>
namespace {
// The arena is the design resolution: [window] width and height in the .toml.
constexpr Rectangle ARENA{ 0, 0, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT };
constexpr float SECONDS_PER_BAT = 4;
} // namespace
void GameScene::_ready() {
background = Color{ 52, 92, 60, 255 }; // grass
// P, Escape, or the gamepad's Start button.
rmp::input::action("pause", KEY_P, KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
auto &player = spawn<Player>({
.position = { ARENA.width / 2, ARENA.height / 2 },
.edges = rmp::Edge::CLAMP,
.bounds = ARENA,
});
player.add<rmp::behavior::Health>({
.hp = 3,
.destroy_on_death = false, // it stays on screen, under the game over
.on_death = [this](rmp::Object &) { caught(); },
.hurt_by = layer::BAT,
});
_player = player.handle();
spawn_coin();
}
void GameScene::_update(float delta) {
// There is no pause menu yet, so for now "pause" goes back to the menu.
if (rmp::input::just_pressed("pause")) rmp::Scene::change<MainMenuScene>();
_next_bat -= delta;
if (_next_bat <= 0) {
spawn_bat();
_next_bat = SECONDS_PER_BAT;
}
}
void GameScene::_draw() {
const int lives = _player->get<rmp::behavior::Health>()->hp;
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text("Coins " + std::to_string(_coins));
rmp::ui::text("Lives " + std::to_string(lives));
});
rmp::ui::end();
}
void GameScene::spawn_coin() {
// Anywhere in the arena, clear of its edges and of the score at the top.
const Vector2 at{ rmp::random::range(40.0f, ARENA.width - 40),
rmp::random::range(80.0f, ARENA.height - 40) };
auto &coin = spawn({ .position = at, .shape = rmp::circle(10) });
coin.shape.color = GOLD;
coin.collision_layer = layer::COIN;
coin.collision_mask = layer::PLAYER;
coin.on_collision([this](rmp::Object &self, rmp::Object &) {
self.destroy();
++_coins;
spawn_coin();
});
}
void GameScene::spawn_bat() {
// From just outside the arena, above it or below it.
const Vector2 at{ rmp::random::range(0.0f, ARENA.width),
rmp::random::chance(0.5f) ? -40.0f : ARENA.height + 40 };
auto &bat = spawn({ .position = at, .shape = rmp::circle(16) });
bat.shape.color = Color{ 90, 60, 120, 255 };
bat.collision_layer = layer::BAT;
bat.collision_mask = layer::PLAYER;
// Each one a little faster or slower, so that they do not fly as one.
bat.add<rmp::behavior::Follow>({
.target = _player,
.speed = rmp::random::range(70.0f, 120.0f),
});
}
void GameScene::caught() { rmp::Scene::push<GameOverScene>(_coins); }A coin needs no class of its own: it is a plain rmp::Object,
which is what spawn() makes when it is not given
a type. Its shape is a gold circle, made with rmp::circle(),
and it goes somewhere random in the arena:
rmp::random::range() is a number between two
others, from a generator the framework seeds from the clock when the game starts.
spawn() returns a reference to the new object, good for the rest of the frame,
which is all spawn_coin() needs it for. What the coin does when it is touched is a
function handed to it with on_collision(),
which runs when the coin touches something its layers allow, and that can only be the player:
self.destroy() takes the coin out. It
stops being drawn and touched at once, and its memory goes when the frame ends, so nothing still
running in this frame is left holding a dangling reference._coins++ counts it. The lambda captures this, the scene, which owns
the coin and therefore outlives it.spawn_coin() puts the next one somewhere else.The two kinds of name are the framework's rule for who calls whom: _collision(),
with an underscore, would be a hook you override in a class of your own; on_collision()
takes a function, for when a class would be more than the job needs.
A bat starts just outside the arena, above it or below it, which
rmp::random::chance(0.5f) decides. It chases
the player with another behavior from the catalogue,
rmp::behavior::Follow, at a speed of its
own so that the bats spread out instead of flying as one. The first comes after a second and
then one every four: _update() counts _next_bat down by
delta, the seconds since the last frame, and makes a bat when it reaches zero.
Follow is given the player as a handle, an
rmp::Handle made by
player.handle(), and not as a reference, and
the scene keeps one in _player the same way. A reference is good for the frame
it was got in: a destroyed object's memory goes when that frame ends, and a reference kept past
it points at nothing. A handle knows when its object is gone, and reads as empty from then on.
The player gets a second behavior, rmp::behavior::Health,
and it is the whole of being hurt. The scene adds it, and not the player's own file, because what
a death means is the game's business: here, it ends the game.
.hp = 3 is three lives..hurt_by = layer::BAT says what
costs one: touching anything on the bats' layer.Health's default, and blinks while
that lasts. Each bite that lands starts the wait again, so a bat sitting on the rabbit costs a
life every 0.6 seconds and not sixty a second: three lives last a little over a second..on_death runs once, when the
last life goes, and calls caught(). .destroy_on_death = false leaves
the rabbit on screen for the game over to be drawn over.The fields are written in the order Health declares them, which C++20 requires of
designated initialisers.
_draw() puts the coins and the lives in the top-left corner, with
rmp::ui again: begin() with .placement set to
rmp::ui::Align::TOP_LEFT, and a
row to put the two side by side. A container takes
its contents as a lambda, so there is no closing call to forget. The strings are temporaries, and
that is safe: text() copies what it is given.
The lives are read from the player's Health through the handle, with
get<rmp::behavior::Health>(). The scene
draws its interface after its objects, so the score is always on top of the game.
When the last life goes, the game does not end: a new scene is put on top of it. Two new files
in src/scenes/:
#pragma once
// Pushed on top of the game when the rabbit is caught. The game stays on
// screen, frozen, underneath.
#include <rmp/scene.h>
class GameOverScene : public rmp::Scene {
public:
explicit GameOverScene(int coins) : _coins(coins) {}
void _draw() override;
private:
int _coins;
};#include "game_over.h"
#include "game.h"
#include "main_menu.h"
#include <rmp/ui.h>
#include <string>
void GameOverScene::_draw() {
// A veil over the game, which has already drawn this frame.
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Color{ 0, 0, 0, 150 });
rmp::ui::begin();
rmp::ui::text("Caught!", { .size = rmp::ui::Size::LARGE });
rmp::ui::text(std::to_string(_coins) + " coins");
if (rmp::ui::button("Play again", { .style = rmp::ui::Variant::PRIMARY })) {
rmp::Scene::change<GameScene>();
}
if (rmp::ui::button("Menu")) rmp::Scene::change<MainMenuScene>();
rmp::ui::end();
}rmp::Scene::push<GameOverScene>(_coins)
puts it on top of the game, and the arguments go to its constructor, which is how the score gets
there. A scene pushed on top of another freezes it: the game below is still drawn, but nothing in
it moves and it hears no input. Nothing in the game scene says "stop": it is simply not updated
while something is on top of it.
The veil is plain raylib, DrawRectangle(), called in _draw(): the game
underneath has already drawn this frame, so the rectangle darkens it, and the menu is drawn over
both.
Play again is rmp::Scene::change<GameScene>(), which ends both scenes and
starts a new game from nothing: a new GameScene, with no coins, no bats and three
lives. Starting over needs no reset code, because everything that was the old game belonged to
the old scene.
rmp runGather the gold coins and keep away from the purple bats. The third bite brings the game over up, frozen on the moment you were caught.

https://omardev29.github.io/rmp-docs/getting-started/a-pause-menu.html
Pausing is the game over again, without the ending: a scene pushed on top of the
game, which freezes it, and taken off again to carry on. The game scene does not get a
paused flag, and nothing in it checks one.
Two new files in src/scenes/:
#pragma once
// Pushed on top of the game. The game underneath freezes, stays on screen and
// stops hearing the input: that is what any scene pushed on top does, so
// nothing here says it.
#include <rmp/scene.h>
class PauseScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};#include "pause.h"
#include "main_menu.h"
#include <rmp/input.h>
#include <rmp/ui.h>
void PauseScene::_update(float /*delta*/) {
// The same key that paused resumes.
if (rmp::input::just_pressed("pause")) rmp::Scene::pop();
}
void PauseScene::_draw() {
// A veil over the game, which has already drawn this frame.
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Color{ 0, 0, 0, 150 });
rmp::ui::begin();
rmp::ui::text("Paused", { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Resume")) rmp::Scene::pop();
if (rmp::ui::button("Menu")) rmp::Scene::change<MainMenuScene>();
rmp::ui::end();
}rmp::Scene::pop() takes the pause scene off
the top, and the game underneath carries on from the frame it stopped at, with every bat where it
was. Menu is change<MainMenuScene>(), which ends both: the pause scene and the
game under it.
The same key that paused also resumes, which is why the pause scene reads the
pause action in its own _update(). The press that pushed it does not pop
it again straight away: the push happens at the end of the frame, and by the next one the key is
held, not pressed.
Nothing in PauseScene says "freeze the game", and that is the point. Three fields
of every scene decide what reaches the scene underneath it, and their defaults are a pause
menu:
| Field | Default | When it is true |
|---|---|---|
updates_below | false | The scene below keeps running. |
draws_below | true | The scene below stays on screen. |
input_below | false | The scene below still hears the input. |
So with the pause scene on top, the game is drawn and nothing in it runs: no bat moves, no
_update() counts down to the next one, and the game's own pause check
is not even reached. Its interface is drawn too, and nothing in it can be pressed. The game over
scene of the last page works the same way, with the same defaults.
The game scene now pushes the pause scene where it used to go back to the menu. Only its code changes; its header is as it was:
#include "game.h"
#include "../objects/layers.h"
#include "../objects/player.h"
#include "game_over.h"
#include "pause.h"
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/random.h>
#include <rmp/ui.h>
#include <string>
namespace {
// The arena is the design resolution: [window] width and height in the .toml.
constexpr Rectangle ARENA{ 0, 0, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT };
constexpr float SECONDS_PER_BAT = 4;
} // namespace
void GameScene::_ready() {
background = Color{ 52, 92, 60, 255 }; // grass
// P, Escape, or the gamepad's Start button.
rmp::input::action("pause", KEY_P, KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
auto &player = spawn<Player>({
.position = { ARENA.width / 2, ARENA.height / 2 },
.edges = rmp::Edge::CLAMP,
.bounds = ARENA,
});
player.add<rmp::behavior::Health>({
.hp = 3,
.destroy_on_death = false, // it stays on screen, under the game over
.on_death = [this](rmp::Object &) { caught(); },
.hurt_by = layer::BAT,
});
_player = player.handle();
spawn_coin();
}
void GameScene::_update(float delta) {
if (rmp::input::just_pressed("pause")) rmp::Scene::push<PauseScene>();
_next_bat -= delta;
if (_next_bat <= 0) {
spawn_bat();
_next_bat = SECONDS_PER_BAT;
}
}
void GameScene::_draw() {
const int lives = _player->get<rmp::behavior::Health>()->hp;
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text("Coins " + std::to_string(_coins));
rmp::ui::text("Lives " + std::to_string(lives));
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_IOS)
// A phone has no key to pause with.
if (rmp::ui::button("Pause", { .style = rmp::ui::Variant::GHOST })) {
rmp::Scene::push<PauseScene>();
}
#endif
});
rmp::ui::end();
}
void GameScene::spawn_coin() {
// Anywhere in the arena, clear of its edges and of the score at the top.
const Vector2 at{ rmp::random::range(40.0f, ARENA.width - 40),
rmp::random::range(80.0f, ARENA.height - 40) };
auto &coin = spawn({ .position = at, .shape = rmp::circle(10) });
coin.shape.color = GOLD;
coin.collision_layer = layer::COIN;
coin.collision_mask = layer::PLAYER;
coin.on_collision([this](rmp::Object &self, rmp::Object &) {
self.destroy();
++_coins;
spawn_coin();
});
}
void GameScene::spawn_bat() {
// From just outside the arena, above it or below it.
const Vector2 at{ rmp::random::range(0.0f, ARENA.width),
rmp::random::chance(0.5f) ? -40.0f : ARENA.height + 40 };
auto &bat = spawn({ .position = at, .shape = rmp::circle(16) });
bat.shape.color = Color{ 90, 60, 120, 255 };
bat.collision_layer = layer::BAT;
bat.collision_mask = layer::PLAYER;
// Each one a little faster or slower, so that they do not fly as one.
bat.add<rmp::behavior::Follow>({
.target = _player,
.speed = rmp::random::range(70.0f, 120.0f),
});
}
void GameScene::caught() { rmp::Scene::push<GameOverScene>(_coins); }The keyboard and the gamepad have their key, but a phone has neither, so on Android and iOS the
score gets a Pause button; the #if keeps it off a desktop, which has P and Escape.
Where it is, it does not get in the game's way. The rabbit reads the arrows through
rmp::input, so the interface knows this scene is being played and its button is a
HUD's: it takes no focus by itself, so Enter and Space never press it in the middle of the game, and
a finger or the mouse does. The interface
chapter has the rest.
The button is also where the pointer check of the player pays off. A finger on Pause is a finger
on the screen, and consumed_pointer() is what keeps the rabbit from running to the
corner as the game pauses: the pointer is the interface's while it is on a button.
rmp runP, Escape or the gamepad's Start button pauses, and the same key resumes. Resume does too, and Menu leaves the game.
https://omardev29.github.io/rmp-docs/getting-started/art-and-sound.html
Boxes and circles were enough to make the game work. Now it gets pictures and
sounds: the rabbit that has been in resources/ since the start, and a coin, a bat and
three sounds copied from one of the framework's own example games.
Run these from the game's folder. They copy from the framework you cloned into your home
folder when you installed rmp:
cp ~/raylib_multiplatform/examples/games/07_platformer/resources/coin.aseprite resources/cp ~/raylib_multiplatform/examples/games/07_platformer/resources/bat.aseprite resources/cp ~/raylib_multiplatform/examples/games/07_platformer/resources/coin.ogg resources/cp ~/raylib_multiplatform/examples/games/07_platformer/resources/hurt.ogg resources/cp ~/raylib_multiplatform/examples/games/07_platformer/resources/music.ogg resources/They are Kenney's work (kenney.nl), from his Pixel Platformer, Impact Sounds, Interface Sounds
and Music Loops packs, and so is the rabbit, from his Animal Pack. All of it is CC0: public domain,
free for any use, with nothing asked in return, not even a credit. The framework's copy keeps the
details in examples/games/07_platformer/resources/License-kenney.txt, and the
rabbit's licence is the License.txt already in your resources/.
The two .aseprite files are sprite sheets as Aseprite saves them, several frames
of a little animation in each. The framework reads them as they are: there is no export step
between drawing a frame and seeing it in the game.
The player gets its picture in place of the white box, in its _ready(). Replace
the player's code:
#include "player.h"
#include "layers.h"
#include <rmp/assets.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/math.h>
namespace {
constexpr float SPEED = 260; // design units per second
} // namespace
void Player::_ready() {
sprite.texture = rmp::assets::load_texture("rabbit.png");
sprite.size = { 44, 64 };
// The body, and not the ears: a bat that only brushes an ear misses.
collider = rmp::rect({ 34, 40 });
collider.offset = { 0, 10 };
collision_layer = layer::PLAYER;
collision_mask = layer::COIN | layer::BAT;
// Eight directions, from the keyboard, a d-pad or a stick.
add<rmp::behavior::TopDown>({ .speed = SPEED });
}
void Player::_update(float /*delta*/) {
// The mouse held down, or a finger on the screen: run towards it. Not when
// the pointer is on a button, which is the interface's and not the game's.
if (rmp::input::pointer_down() && !rmp::input::consumed_pointer()) {
const Vector2 to = rmp::input::pointer() - position;
if (Vector2Length(to) > 8) velocity = Vector2Normalize(to) * SPEED;
}
}rmp::assets::load_texture("rabbit.png")
takes a name, not a path: the file is looked for in resources/, or in the pack that
a release can carry instead, as the end of this page shows. What it returns is an
rmp::Texture, which frees itself when the last copy of
it goes, so there is no unload to remember; asking twice for the same name gives the same texture
back, not a second copy.
An object with a sprite draws that instead
of its shape. The picture is 284 by 414 pixels, far too big for the arena, and
sprite.size draws it at 44 by 64 units instead.
Without a shape, an object collides as its picture, and a rabbit's picture is mostly ears. The
collider says what it collides as instead: a
box over the body, moved down by its offset, so a bat that only brushes an ear
misses.
The coins and the bats lose their circles and get their sheets, and two sounds go in. Replace the game scene's code; its header does not change:
#include "game.h"
#include "../objects/layers.h"
#include "../objects/player.h"
#include "game_over.h"
#include "pause.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/random.h>
#include <rmp/ui.h>
#include <string>
namespace {
// The arena is the design resolution: [window] width and height in the .toml.
constexpr Rectangle ARENA{ 0, 0, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT };
constexpr float SECONDS_PER_BAT = 4;
} // namespace
void GameScene::_ready() {
background = Color{ 52, 92, 60, 255 }; // grass
// P, Escape, or the gamepad's Start button.
rmp::input::action("pause", KEY_P, KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
auto &player = spawn<Player>({
.position = { ARENA.width / 2, ARENA.height / 2 },
.edges = rmp::Edge::CLAMP,
.bounds = ARENA,
});
player.add<rmp::behavior::Health>({
.hp = 3,
.destroy_on_death = false, // it stays on screen, under the game over
.on_death = [this](rmp::Object &) { caught(); },
.on_damage = [](rmp::Object &, int) { rmp::audio::play("hurt"); },
.hurt_by = layer::BAT,
});
_player = player.handle();
spawn_coin();
}
void GameScene::_update(float delta) {
if (rmp::input::just_pressed("pause")) rmp::Scene::push<PauseScene>();
_next_bat -= delta;
if (_next_bat <= 0) {
spawn_bat();
_next_bat = SECONDS_PER_BAT;
}
}
void GameScene::_draw() {
const int lives = _player->get<rmp::behavior::Health>()->hp;
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text("Coins " + std::to_string(_coins));
rmp::ui::text("Lives " + std::to_string(lives));
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_IOS)
// A phone has no key to pause with.
if (rmp::ui::button("Pause", { .style = rmp::ui::Variant::GHOST })) {
rmp::Scene::push<PauseScene>();
}
#endif
});
rmp::ui::end();
}
void GameScene::spawn_coin() {
// Anywhere in the arena, clear of its edges and of the score at the top.
const Vector2 at{ rmp::random::range(40.0f, ARENA.width - 40),
rmp::random::range(80.0f, ARENA.height - 40) };
auto &coin = spawn({ .position = at, .scale = { 2, 2 } });
coin.sprite.sheet = rmp::assets::load_sheet("coin.aseprite");
coin.sprite.play("spin");
coin.collision_layer = layer::COIN;
coin.collision_mask = layer::PLAYER;
coin.on_collision([this](rmp::Object &self, rmp::Object &) {
self.destroy();
++_coins;
rmp::audio::play("coin");
spawn_coin();
});
}
void GameScene::spawn_bat() {
// From just outside the arena, above it or below it.
const Vector2 at{ rmp::random::range(0.0f, ARENA.width),
rmp::random::chance(0.5f) ? -40.0f : ARENA.height + 40 };
auto &bat = spawn({ .position = at, .scale = { 2, 2 } });
bat.sprite.sheet = rmp::assets::load_sheet("bat.aseprite");
bat.sprite.play("fly");
bat.collision_layer = layer::BAT;
bat.collision_mask = layer::PLAYER;
// Each one a little faster or slower, so that they do not fly as one.
bat.add<rmp::behavior::Follow>({
.target = _player,
.speed = rmp::random::range(70.0f, 120.0f),
});
}
void GameScene::caught() { rmp::Scene::push<GameOverScene>(_coins); }rmp::assets::load_sheet() reads an
.aseprite file, with its frames, how long each one shows, and its tags: the named
animations in it. sprite.play("spin") names one
of those tags, and the framework moves through its frames from then on. The names are the ones in
the file, and nothing else: spin and fly are what these two sheets call
their animations. A tag the sheet does not have plays nothing and says so once, in the log.
The art is small, 18 pixels for a coin and 24 for a bat, and .scale = { 2, 2 }
draws it twice the size. scale applies to what
the object collides as as well, so the bigger bat bites from where it is drawn.
rmp::audio::play("coin") plays a sound by name,
without its extension: coin finds coin.wav, coin.ogg,
coin.mp3 or coin.qoa, the first of them that exists. The sound is loaded
the first time it is played and kept. Playing it again while it still sounds starts another
voice instead of cutting the first one off, up to four at once; a fifth, while all four still
sound, cuts off the one that has played longest. The bite's sound goes in Health's
.on_damage, which runs every time a life is lost, the last one too.
The sound device opens with the first sound, so a game that plays none never opens it. A machine with no sound device at all is not an error: every call simply does nothing.
The music starts with the menu, so the menu gets a _ready(). Replace both of its
files:
#pragma once
// The title screen: the game's name, Play and Quit.
#include <rmp/scene.h>
class MainMenuScene : public rmp::Scene {
public:
void _ready() override;
void _draw() override;
};#include "main_menu.h"
#include "game.h"
#include <rmp/app.h>
#include <rmp/audio.h>
#include <rmp/ui.h>
void MainMenuScene::_ready() {
// Already playing when the menu comes back after a game: then it carries on.
rmp::audio::music("music");
}
void MainMenuScene::_draw() {
rmp::ui::begin();
rmp::ui::text(RMP_WINDOW_TITLE, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play", { .style = rmp::ui::Variant::PRIMARY })) {
rmp::Scene::change<GameScene>();
}
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
rmp::ui::end();
}rmp::audio::music("music") streams
music.ogg, looping, and the framework keeps it fed every frame, under a pause menu
too. Asking for the track that is already playing does not start it again, so the song carries on
when a game ends and the menu comes back, instead of jumping to its beginning.
In a browser, nothing is heard until the player has clicked, touched or pressed a key: browsers keep a page silent until then, and no game can get round it.
While you work, the game reads the files in resources/ as they are. A release can
carry them as one file instead, resources.rres, encrypted, and the game reads that
with the same calls and the same names: nothing in the code knows which it is. You can try it
here:
rmp pack
rmp run
rmp unpackrmp pack writes the pack into resources/, and the game reads it for
as long as it is there; rmp unpack deletes it, and the loose files are read again.
Most of the desktop builds CI makes for a release ship the pack in place of the loose files.
The pack takes every file below resources/, its folders too, each under its path
there, so a game names "sprites/hero.png" the same in development and in a release.
A release for
the desktop reads the resources/ that sits next to its executable, so it starts the
same from a file manager, a shortcut or a terminal open in some other folder: when there is one
there, the game makes the executable's folder its working directory before it loads anything.
When there is none, it stays in the folder it was started from and reads the
resources/ there. On NetBSD and OpenBSD raylib cannot tell where the
executable is, so a release there reads the resources/ of the folder it was started
from, and its log says so: ASSETS: this system does not say where the executable is…
The encryption keeps casual hands off your files and nothing more. Its password is
[resources] rres_password in the .toml, which rmp new made
up for this game, and it ends up inside the game's binary.
rmp runMusic on the menu, a rabbit in the arena, and spinning coins and flapping bats, each with its sound. The Sprites, Assets and Audio chapters of the manual go further into each.

https://omardev29.github.io/rmp-docs/getting-started/saving-a-record.html
A score is more fun with something to beat. This page keeps the most coins anyone has gathered in one game, on disk, so that it is still there the next time the game starts, and shows it on the menu.
Both the menu and the game need the best score, so it gets two small functions of its own, in
two new files at the top of src/, next to main.cpp:
#pragma once
// The best score, kept on disk from one session to the next.
// The most coins collected in one game, or 0 before the first game ends.
int best_score();
// Keeps `coins` as the best score if it beats it, and says whether it did.
bool keep_if_best(int coins);#include "record.h"
#include <rmp/save.h>
#include <string_view>
namespace {
// The slot: the save file's name, without a folder and without an extension.
constexpr std::string_view SLOT = "record";
} // namespace
int best_score() {
rmp::Value saved;
rmp::save::read(SLOT, saved);
// No save yet, or one without this key: the 0 is what reads then.
return saved["coins"].as_int(0);
}
bool keep_if_best(int coins) {
if (coins <= best_score()) return false;
rmp::Value record;
record["coins"] = coins;
rmp::save::write(SLOT, record);
return true;
}A
save is an rmp::Value: a tree of the shapes JSON has,
which are nothing (JSON's null), true or false, numbers, strings, lists and keyed
objects. So a save can grow into something with structure without changing how it is written. Assigning to a key creates it:
record["coins"] = coins.
rmp::save::write() writes it to a
slot, a file name without a folder or an extension. The file is written beside the old one
first and replaces it only once it is complete, so a game that crashes, or a battery that dies, in
the middle of a save leaves the previous save as it was.
rmp::save::read() fills the
rmp::Value it is given, or leaves it exactly as it was when it cannot: the first time
the game runs there is no save at all. Every read of a value says what to give back when the key
is not there, so saved["coins"].as_int(0) is 0 on the first run and the
record from then on, with no special case. Reading creates nothing, and a key a later version of
the game adds simply reads as its default in an older save.
read() also says why it did not fill the value, when that matters, and here it
does not: no save and a damaged save both mean "no record yet". The
Saving chapter of the manual shows how to tell them
apart.
The game keeps the record when the rabbit is caught, and tells the game over screen whether it was beaten. Replace the game scene's code; its header does not change:
#include "game.h"
#include "../objects/layers.h"
#include "../objects/player.h"
#include "../record.h"
#include "game_over.h"
#include "pause.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/random.h>
#include <rmp/ui.h>
#include <string>
namespace {
// The arena is the design resolution: [window] width and height in the .toml.
constexpr Rectangle ARENA{ 0, 0, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT };
constexpr float SECONDS_PER_BAT = 4;
} // namespace
void GameScene::_ready() {
background = Color{ 52, 92, 60, 255 }; // grass
// P, Escape, or the gamepad's Start button.
rmp::input::action("pause", KEY_P, KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
auto &player = spawn<Player>({
.position = { ARENA.width / 2, ARENA.height / 2 },
.edges = rmp::Edge::CLAMP,
.bounds = ARENA,
});
player.add<rmp::behavior::Health>({
.hp = 3,
.destroy_on_death = false, // it stays on screen, under the game over
.on_death = [this](rmp::Object &) { caught(); },
.on_damage = [](rmp::Object &, int) { rmp::audio::play("hurt"); },
.hurt_by = layer::BAT,
});
_player = player.handle();
spawn_coin();
}
void GameScene::_update(float delta) {
if (rmp::input::just_pressed("pause")) rmp::Scene::push<PauseScene>();
_next_bat -= delta;
if (_next_bat <= 0) {
spawn_bat();
_next_bat = SECONDS_PER_BAT;
}
}
void GameScene::_draw() {
const int lives = _player->get<rmp::behavior::Health>()->hp;
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text("Coins " + std::to_string(_coins));
rmp::ui::text("Lives " + std::to_string(lives));
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_IOS)
// A phone has no key to pause with.
if (rmp::ui::button("Pause", { .style = rmp::ui::Variant::GHOST })) {
rmp::Scene::push<PauseScene>();
}
#endif
});
rmp::ui::end();
}
void GameScene::spawn_coin() {
// Anywhere in the arena, clear of its edges and of the score at the top.
const Vector2 at{ rmp::random::range(40.0f, ARENA.width - 40),
rmp::random::range(80.0f, ARENA.height - 40) };
auto &coin = spawn({ .position = at, .scale = { 2, 2 } });
coin.sprite.sheet = rmp::assets::load_sheet("coin.aseprite");
coin.sprite.play("spin");
coin.collision_layer = layer::COIN;
coin.collision_mask = layer::PLAYER;
coin.on_collision([this](rmp::Object &self, rmp::Object &) {
self.destroy();
++_coins;
rmp::audio::play("coin");
spawn_coin();
});
}
void GameScene::spawn_bat() {
// From just outside the arena, above it or below it.
const Vector2 at{ rmp::random::range(0.0f, ARENA.width),
rmp::random::chance(0.5f) ? -40.0f : ARENA.height + 40 };
auto &bat = spawn({ .position = at, .scale = { 2, 2 } });
bat.sprite.sheet = rmp::assets::load_sheet("bat.aseprite");
bat.sprite.play("fly");
bat.collision_layer = layer::BAT;
bat.collision_mask = layer::PLAYER;
// Each one a little faster or slower, so that they do not fly as one.
bat.add<rmp::behavior::Follow>({
.target = _player,
.speed = rmp::random::range(70.0f, 120.0f),
});
}
void GameScene::caught() {
const bool record = keep_if_best(_coins);
rmp::Scene::push<GameOverScene>(_coins, record);
}The game over scene takes a second argument, and says so when there is a new best:
#pragma once
// Pushed on top of the game when the rabbit is caught. The game stays on
// screen, frozen, underneath.
#include <rmp/scene.h>
class GameOverScene : public rmp::Scene {
public:
GameOverScene(int coins, bool record) : _coins(coins), _record(record) {}
void _draw() override;
private:
int _coins;
bool _record;
};#include "game_over.h"
#include "game.h"
#include "main_menu.h"
#include <rmp/ui.h>
#include <string>
void GameOverScene::_draw() {
// A veil over the game, which has already drawn this frame.
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Color{ 0, 0, 0, 150 });
rmp::ui::begin();
rmp::ui::text("Caught!", { .size = rmp::ui::Size::LARGE });
rmp::ui::text(std::to_string(_coins) + " coins");
if (_record) {
rmp::ui::text("A new best!", { .color = rmp::ui::ColorRole::PRIMARY });
}
if (rmp::ui::button("Play again", { .style = rmp::ui::Variant::PRIMARY })) {
rmp::Scene::change<GameScene>();
}
if (rmp::ui::button("Menu")) rmp::Scene::change<MainMenuScene>();
rmp::ui::end();
}The menu shows the record under the title, once there is one:
#pragma once
// The title screen: the game's name, the best score, Play and Quit.
#include <rmp/scene.h>
class MainMenuScene : public rmp::Scene {
public:
void _ready() override;
void _draw() override;
private:
int _best = 0; // read once, when the menu opens
};#include "main_menu.h"
#include "../record.h"
#include "game.h"
#include <rmp/app.h>
#include <rmp/audio.h>
#include <rmp/ui.h>
#include <string>
void MainMenuScene::_ready() {
_best = best_score();
// Already playing when the menu comes back after a game: then it carries on.
rmp::audio::music("music");
}
void MainMenuScene::_draw() {
rmp::ui::begin();
rmp::ui::text(RMP_WINDOW_TITLE, { .size = rmp::ui::Size::LARGE });
if (_best > 0) {
rmp::ui::text("Best: " + std::to_string(_best) + " coins",
{ .color = rmp::ui::ColorRole::MUTED });
}
if (rmp::ui::button("Play", { .style = rmp::ui::Variant::PRIMARY })) {
rmp::Scene::change<GameScene>();
}
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
rmp::ui::end();
}The menu reads the record once, in _ready(), and keeps it in
_best, rather than reading a file sixty times a second in _draw(). The
menu is a new scene every time a game ends and the player goes back to it, so it always shows the
record as it is now.
The slot record is a file called record.save, in a folder named
after [project] name, where each platform keeps an application's data:
| Platform | Folder |
|---|---|
| Linux and the BSDs | ~/.local/share/my_game, or my_game in $XDG_DATA_HOME when that is set |
| Windows | %APPDATA%\my_game |
| macOS | ~/Library/Application Support/my_game |
| Android | the app's internal storage |
| iOS | the app's Application Support folder |
| Web | the browser's own storage, IndexedDB, which survives a reload |
rmp::save::directory() says which folder it
is on the machine the game is running on. [save] portable = true in the
.toml puts saves in a saves folder next to the game's executable instead,
on Windows, Linux and FreeBSD, which is what a game handed out as a zip file wants. NetBSD and
OpenBSD cannot say where the executable is, so there the saves stay in the folder above.
The file is a line of header and then the JSON, so anyone can read it in a text editor, and
the framework notices if they change it: every save carries a checksum. [save] encrypt = true also seals it, which stops a
player from simply typing in a better score, but the key is inside the game, so it stops the
curious and not the determined.
rmp runGather a coin or two and get caught: the game over screen says "A new best!", and back on the menu the record is under the title. Close the game and start it again, and the record is still there.
https://omardev29.github.io/rmp-docs/getting-started/ship-it.html
The game is finished. What is left is to give it the identity stores will know it by, check it the way CI will, and tag a version: CI does the rest, and builds it for every platform the game has turned on.
rmp new gave the game ids that start with com.example., which a
release refuses. Choose real ones, made of a domain you own written backwards and the game's name,
and set them in raylib_multiplatform.toml:
[android]
application_id = "com.yourname.coinrabbit"
[ios]
bundle_id = "com.yourname.coinrabbit"Choose with care: once an app is published on Google Play under an id, that id is its id for good, and changing it means a new listing that starts with no players. The App Store's bundle id is the same kind of promise.
The two kinds of id do not accept quite the same characters. Android takes letters, digits and underscores in each part, and Apple takes letters, digits and hyphens, so the safest id has neither. A hyphen in the Android id is refused, with the line it is on and an id that would work, the moment anything reads the file:
[android]
application_id = "com.yourname.coin-rabbit" raylib_multiplatform.toml:2: application_id = "com.yourname.coin-rabbit"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android] application_id = 'com.yourname.coin-rabbit' is not a valid Android application id.
It contains '-': an Android id takes letters, digits, '_' and '.', and nothing else.
A '-' is fine in an iOS bundle id and refused here: write 'com.yourname.coin_rabbit'.
It needs at least one dot and each segment must start with a letter, e.g. com.yourname.yourgame.That is the rule for the whole .toml: a value that cannot work stops the build
before anything is compiled, and says where.
rmp testIn a game, rmp test runs four stages, and CI checks the same four things on
every push:
config: the .toml, the versions the framework pins, and the licence
of every library in the game;unit:
your tests in tests/game/ — the menu's, from Your
first scene — built with the game and run with no window;render:
the game built for raylib's software renderer and booted with no window and no graphics card,
checked to have loaded every asset it asked for, drawn a frame with something on it, run every
frame it was given and exited cleanly;smoke: the game built
as you run it, booted for a few frames, and checked to have drawn something with no asset failing
to load, and to have exited cleanly. A file that is missing fails, and so does one that is there and
does not decode: a PNG cut short counts the same as no file at all.A boot only reaches the first scene, so rmp test says the game starts, loads its
art and draws its menu. Whether the game is fun is still yours to check, with
rmp run.
CI is GitHub Actions, and the workflows came with the game. Commit your work, make an empty repository on GitHub, tell git where it is, and push to it:
git add -A
git commit -m "Coin Rabbit"
git remote add origin https://github.com/yourname/my_game.git
rmp pushA
branch that has never been pushed has nowhere to go yet, so its first rmp push is
git push -u origin main: the -u tells git that main goes to
the repository's main from then on, and every push after it is a plain
git push. Without the git remote add line there is nothing to push to, and
rmp push stops with FAIL: there is no remote to push to. and the line to
type.
rmp push
checks one thing before any of that: it will not push while a CI run of the repository is still
going, because a new push cancels it. It needs the gh command to ask; without it, it
says so and pushes.
Every push to main runs the fast lane: the checks above, and builds for Linux, the
web, Windows and Android. Watch it on the repository's Actions tab. A private repository pays for
those runs in Actions minutes, and one line of the .toml,
[ci] on_push = false, stops them: a push
then starts nothing, a release tag still builds everything, and rmp push has no run
to look for.
rmp deploy 1.0.0rmp deploy checks everything a release needs before it makes a tag that cannot be
quietly taken back: that every change to a tracked file is committed, that v1.0.0 is
not already a tag, here or on GitHub, that the commit is the one your branch on GitHub points at
as of your last fetch or push (it does not fetch), and that the .toml is valid with
real ids in it. Then it tags the commit v1.0.0 and pushes the tag.
The tag is the version: there is no version number in the project to keep in step with it.
For a tag, CI builds every target that [targets] has turned on, all
17 of them unless you turned some off, boots the ones it can, and, when every build
has passed, publishes a GitHub release with them attached. It also pushes them to itch.io, if [deploy.itch] names your page
there and the repository has the secret butler needs.
The Android build is signed with a throwaway key, which Google Play does not accept, until the repository holds your upload key as a secret. The Publishing section has that, and everything else about where each build goes: releases and versions, itch.io, Google Play and the App Store.
The game you built uses most of what the framework has: scenes, objects, behaviors, input, the interface, assets, audio and saving. The Manual takes each of them further, and the Examples are whole games to read, from Pong to a platformer whose levels are made in an editor.
https://omardev29.github.io/rmp-docs/manual/index.html
The manual explains the framework by concept: what each part is for, how to use it, and why it works the way it does. The reference lists every name; this is where they are put together.
It starts with the core every game uses — the app, scenes, objects — and goes on to the modules a game takes when it needs them.
https://omardev29.github.io/rmp-docs/manual/basics/index.html
Before a game draws anything it is a folder, a config file, a command and a handful of headers. This group is about those four things: what each one is, which parts of it are yours, and why it is laid out the way it is.
rmp new puts in a game's folder, which parts you edit and which belong to the framework, and what the build generates.raylib_multiplatform.toml: the one file that drives CMake, Gradle and Xcode, and what happens when a value in it is wrong.RMP_ values every header carries from the config.When the folder builds and runs, the core is next: the app, the scenes it moves between and the objects in them.
https://omardev29.github.io/rmp-docs/manual/basics/project-layout.html
A game is a folder that rmp new makes. It holds your code, your art and
one config file, next to its own copy of the framework and everything needed to build it for
17 targets. Most of the folder is never yours to open, and the framework's own code
sits in two folders called rmp/, so the two are told apart at a glance.
rmp new my_game # makes my_game/, here
cd my_game
rmp run # build it and play itThe name of the folder is the name of the game. rmp new writes it into
[project] name and [window] title, and from there it becomes the executable,
the CMake target, the Xcode scheme, the save folder on desktops and the web, and the name of every
artifact CI uploads.
Because it becomes a file name on every operating system the game ships to, it has to be letters,
digits, _ and -, starting with a letter. A name that is not, or that is
already taken by a target of the build (rmp, raylib,
unit_test and the like), or that Windows reserves for a device (con,
nul, com1…) is refused before anything is written. When the trouble is a
character, such as a space, the refusal suggests the name with it turned into _.
The folder can be anywhere — rmp new ~/games/space_rocks makes
space_rocks — except inside the framework itself. If it exists it has to be empty.
Besides copying files, rmp new does six things to the new game:
[android] application_id becomes com.example.my_game and [ios] bundle_id
becomes com.example.my-game. The two differ because Android ids take _ and not
-, and Apple bundle ids the other way round. A release build refuses any id under
com.example., because a Google Play application id can never be changed once it is
published.[resources] rres_password a random value of its own, so that games made from
the framework do not share the key their asset packs are encrypted with.[android.admob] enabled = false,
so the Android build carries no ads SDK and asks for no advertising permission until the game has an
ad to show, and [android] gl_version = "ES20", which every Android device has. The
framework's own .toml sets both the other way, so that its CI builds the ads path and the
ES 3.0 one.README.md for the game, which says which parts of the folder are the
game's.main, with every file added and
nothing committed yet. The raylib-iOS submodule is recorded at the commit the framework pins, with
its folder left empty: git submodule update --init is only needed to build for iOS.tools/configure.py --check and
tools/license_db.py --check. If either fails, the folder is removed again: there is no
half-made game to clean up.A game has no licence of its own; choosing one is yours. The framework's MIT licence travels with
it as thirdparty/raylib_multiplatform/LICENSE, next to every other component's, and
reaches the LICENSES.txt each build ships. It is not a LICENSE at the root
of the game, which would make GitHub call every game made with the framework MIT.
The copy is an explicit list, not "everything except". rmp new --list prints it, one
path per line, without making anything:
rmp new --listA list of what to take fails loudly when it is wrong: a file a game needs and does not get is a game that does not build. A list of what to leave out would fail silently and for good, because the next file added to the framework — a gate, a test fixture, a maintenance script — would ride along into every game and nothing would say so. The framework's own tests make every file it tracks be classified as one or the other, so a new file forces the question.
Some
of what a game gets is not what the framework itself uses. Its [dev] sanitize is
empty, and its [dev] c_compiler is "auto": on x86-64 Linux, with tcc
installed, the C of its debug builds — raylib and the libraries it bundles — is compiled by tcc, many
times faster (c_compiler). And it gets the
development container, so it can be
opened in one with nothing installed.
This is the top of a new game. The comments say whose each entry is.
my_game/
├── raylib_multiplatform.toml yours: the name, the ids, the platforms, everything else
├── src/
│ ├── main.cpp yours: RMP_GAME(MainMenuScene); and nothing else
│ ├── scenes/ yours: main_menu.h and main_menu.cpp to start from
│ └── rmp/ the framework's implementation
├── include/
│ └── rmp/ the framework's headers
├── resources/ yours: art, sounds, fonts, levels (rabbit.png to start)
├── branding/icon.png yours: the one picture the app icons are made from
├── README.md yours: written by rmp new
├── rmp rmp.ps1 rmp.cmd the command, for sh, PowerShell and cmd
├── tools/ configure.py, rmp.py, the licence check, the packer, CI's scripts
├── CMakeLists.txt the build, driven by the .toml
├── CMakePresets.json the presets: debug, release, web, memory, lint
├── cmake/ the build's helpers; cmake/generated/ appears here
├── raymob/ the Android app shell (Gradle)
├── ios/ the iOS scaffold; ios/project.yml appears here
├── tests/
│ ├── game/ yours: tests of your game, with no window (main_menu_test.cpp)
│ └── smoke_test.h the boot and render check CI runs on every target
├── thirdparty/ raylib and the other vendored libraries, pinned
├── THIRD_PARTY_LICENSES.md every vendored component and its licence
├── .github/workflows/ CI for every enabled target, and the release
└── package.json what CI's web boot test runs on (Playwright)| Path | What goes there |
|---|---|
raylib_multiplatform.toml | The game's name and identities, its window, the platforms it is built for, and every setting the framework reads. See Configuration. |
src/main.cpp | The entry point: one line, RMP_GAME(MainMenuScene);, naming the first scene. See The app. |
src/scenes/ | Your scenes, one per file. More folders beside it — a folder for your objects, one for your behaviors — are yours to add. |
include/ | Headers you want on the include path from anywhere in src/. Headers that sit next to their .cpp in src/ work too, included by their relative path. |
resources/ | Everything the game loads at run time, loaded by name. |
branding/icon.png | The app icon, one square PNG. |
tests/game/ | Your tests: doctest cases built with everything in src/ but main.cpp, run with no window by rmp test unit and by CI. See Testing. |
Two paths are the framework's and carry the same name so that you can tell at a glance:
include/rmp/, the headers you include, and src/rmp/, their implementation.
Everything else under src/ and include/ is yours.
The rest of the folder is the machinery that builds and ships the game: CMake for the desktops
and the web, Gradle under raymob/ for Android, an XcodeGen spec under ios/
for iOS, the workflows under .github/workflows/ for CI, and the vendored libraries under
thirdparty/, each pinned and each licence on record. None of it is edited to rename the
game, to add a source file or to pick platforms; all three are the .toml's or
src/'s job.
The game's copy of tools/rmp.py is the one that runs inside it, even when the
rmp on your PATH is a newer framework's. That is what keeps a game building the way it
did when it was made; The rmp
command has the detail.
A game does not get the framework's examples/, its own tests or its maintenance tools.
The examples are on this site, under Examples, each one a small
game of its own that can be read and copied from.
There is no list of source files anywhere. Every .cpp and .c under
src/, in any subfolder, is part of the game, in all four build systems: CMake globs the
folder recursively, Android's CMake under raymob/ does the same, and the iOS spec takes
src/ as a whole. Adding a game.cpp to src/scenes/ touches no
CMake, no Gradle and no Xcode project; the next build finds it.
On the desktops and the web, src/rmp/ is left out of the game's own sources and
compiled once into a library called rmp, which the game links. That is why changing a
scene recompiles the scene and not the framework.
A
game whose own sources hold no C++ — main.cpp, the scenes and tests/game/
deleted, and a main.c in their place — is built as plain C: its own main(), linked to
raylib alone.
src/rmp/
goes too, because nothing in a C game uses it and yet it would be built: the framework library is
built from it whenever it has sources, so kept, it is the whole C++ framework compiled for nothing on
the desktops, and compiled into the game on Android and iOS, whose builds take everything under
src/. With it gone there is no rmp library, and none is built; a C++ file
left in src/ without it stops the configure with a message that says so.
What
the C game still includes is written in C, and on its include path on every target:
rmp/config.h for the .toml's values, which is why include/rmp/
stays, tests/smoke_test.h for the boot checks CI runs, and <admob.h>,
the ads as C functions, which do nothing off Android.
Plain C explains it, and examples/plain_c is
that shape.
A plain C
game keeps the builds, the generated identities and icons and the release pipeline. It gives up the asset pack,
which raylib alone cannot read: its releases ship the loose files of resources/, with a
PACK_SKIPPED.txt beside them saying why. And it gives up the web and iOS, whose frame
loops belong to the browser and to UIKit and are written by the framework's entry point.
The game loads its files from resources/ by name —
rmp::assets::load_texture("rabbit.png") — without knowing whether they are loose files
or packed into one encrypted resources.rres. While you work they are loose, so a new
picture is in the game the next time it runs. rmp pack bundles the folder into a
resources.rres inside it, the way a release does, and rmp unpack deletes the
pack so the loose files are read again.
Assets has the whole of loading, and the loading example reads the same files both ways.
Keep the folder in folders by kind — sprites/, maps/,
audio/, fonts/, dialogue/, locale/. A resource's name
is its path below resources/ ("sprites/hero.png"), and every target finds
it by that name: the pack a desktop release ships keeps each file under it, and the web, Android
and iOS ship the folder whole.
Where the game looks for the folder depends on the build. On a desktop, a debug build reads the
project's resources/ by its absolute path, so the game finds its files whatever folder it
is started from. A release build reads ./resources/, and a release ships the folder, or
the pack in it, next to the executable; at start it moves into the executable's folder when a
resources/ is there, so a player can start it from anywhere —
The app has the detail, and the
two BSDs where it cannot. The web build preloads the files with the page, Android puts them in the
APK's assets and iOS copies the folder into the app bundle.
branding/icon.png is one square PNG, 1024×1024 recommended, and the Android, iOS
and Windows icons are made from it: each Android density with its round and adaptive variants, the
Play Store image, the iOS app icon and the .ico embedded in the Windows executable. The
other targets have no icon of their own to make: macOS, Linux and the BSDs ship a bare executable,
and the web a page.
It is not in resources/ on purpose. Everything there is packed and shipped with the
game, and a launcher icon is an input of the build, not an asset the game loads.
The folder is yours, name included: [icon] source is the only thing that has to agree
with it. When the file is missing the build warns and keeps whatever icons already exist instead of
failing. Resizing it into the Android icons needs Pillow, the Python imaging library; a machine
without it keeps the icons it has, because only the Android and iOS builds use them. The Windows
.ico needs Pillow too: without it a build of your own makes an .exe with no
icon, and CI's Windows jobs install it and fail an .exe that came out without one.
Every configure turns raylib_multiplatform.toml into the files each build system
reads. None of them is committed — .gitignore lists them — so none can drift out of step
with the .toml, and git status stays clean after a build.
| Generated | For |
|---|---|
cmake/generated/ | CMake: the project name, raylib's module switches, the compiler, linker and sanitizers of debug builds, the Windows icon, the LICENSES.txt of each family of targets. |
include/rmp/generated/ | C and C++: the config.h that holds the RMP_ values. See Headers. |
raymob/generated.properties, raymob/app/generated/ | Gradle: the Android properties and the manifest. |
ios/project.yml | XcodeGen: the iOS project. |
build/ | Everything compiled, one folder per build: build/debug/, build/release/, build/debug-drm/ and build/release-drm/ on a Linux console, build/web/ for the browser, build/memory/ for the software-rendered check. |
The app icons are generated too, into the Android resource folders and an asset catalogue under
ios/, and ignored the same way.
One generated part is committed, because GitHub reads it before anything runs: the triggers of
.github/workflows/ci.yml, which the configure writes from
[ci] on_push.
Continuous integration explains it.
rmp clean deletes build/ and every generated file except the Android and iOS
icons, which stay because making the Android ones again needs Pillow. The Windows icon lives in
cmake/generated/ and is deleted with it, so after a clean a machine without Pillow builds
an .exe with no icon. The next build makes the rest again. Gradle and XcodeGen
never run CMake, so the Android and iOS builds run tools/configure.py themselves first;
rmp android does.
https://omardev29.github.io/rmp-docs/manual/basics/configuration.html
Everything about a game that is not code lives in one file at the root of the
project, raylib_multiplatform.toml: its name, its store identities, its window, the
platforms it is built for, and every setting the framework reads. CMake, Gradle, Xcode and CI all
take their answers from it, so they cannot disagree with each other.
This page explains how the file works. Every key, with its default and the values it takes, is listed in the configuration reference.
A game is built by four different systems — CMake for the desktops and the web, Gradle for Android, Xcode for iOS, GitHub Actions for all of them — and all four need to agree on the same facts: what the game is called, what its bundle id is, which platforms to build. Left to themselves they disagree, and the failure is always silent: a release that ships under the wrong identity, or an Android build that encrypts its assets with a different password from the desktop one and cannot read them.
So there is one hand-written source and one generator. tools/configure.py reads the
.toml and writes what each system needs:
| It writes | Which is read by |
|---|---|
cmake/generated/ | CMake: the project name, which raylib modules to build, the compiler, linker and sanitizers of debug builds, the web build's memory, the Windows icon. |
rmp/config.h, generated | Your C and C++: the RMP_ values, such as RMP_WINDOW_WIDTH. |
raymob/generated.properties and the manifest | Gradle: the application id, the SDK levels, the permissions, the orientation, the OpenGL ES version the game is compiled for, whether AdMob is in the build. |
ios/project.yml | XcodeGen, which makes the Xcode project: the bundle id, the deployment target, your [ios.settings]. |
the icons and the LICENSES.txt files | The packages the game ships in: the icons go into the Android, iOS and Windows ones, a LICENSES.txt into each. |
the triggers of .github/workflows/ci.yml | GitHub Actions: whether a push and a pull request start a run, from [ci] on_push. |
The build files stay dumb: they read what the generator wrote and never parse the
.toml themselves, because three parsers would be three ways to drift. CI asks the same
generator its questions — which targets are enabled, which jobs to start, where to publish — through
its --print- options. None of the generated files is committed but the triggers in
ci.yml, which GitHub reads from the repository; see
what the build generates.
You never run it by hand to build. Every cmake --preset runs it first, before
anything else is configured, because the project's own name comes out of it — so
rmp run, rmp build release and rmp web all regenerate. CMake also
watches the .toml, so editing it and building again picks the change up. The generator
takes milliseconds and rewrites a file only when its content changed, so a configure that changed
nothing rebuilds nothing.
Gradle and XcodeGen never run CMake, so those two builds run
python3 tools/configure.py as a step of their own; rmp android does it for
you, and so do the CI jobs.
The generator needs Python 3.11 or newer. A machine without one can still build from files that
were generated earlier, with a warning that edits to the .toml will not be seen; with
nothing generated yet, the build stops and says how to get Python.
The file is TOML. A key lives under a section, and the framework names it the same way
everywhere — in its messages, in its comments and on this site — as [section] key:
[window]
title = "Space Rocks" # this is [window] title
width = 1280 # and this is [window] width
height = 720The file is laid over the defaults. A key you leave out takes its default, a section you leave
out is entirely default, and a game whose .toml is deleted still builds through
cmake --preset debug, with a warning saying it is running on defaults — though not through
rmp, which finds the project by that file and, without it, says it is not inside one. So
a .toml holds only what the game changes:
[project]
name = "space_rocks"
[window]
title = "Space Rocks"
width = 1280
height = 720
[targets]
enabled = ["all"]
disabled = ["ios"]
[android]
application_id = "com.yourname.spacerocks"
[ios]
bundle_id = "com.yourname.spacerocks"The .toml that rmp new gives a game is the framework's own, with every key
written out and a comment over each one saying what it does and why its default is what it is. It
is worth reading once. rmp new writes the game's own values into it — its name, its
placeholder store ids, a password of its own — and turns AdMob off and Android's OpenGL ES version
down to 2.0, the two keys the framework sets the other way so that its CI builds those paths; see
Project layout.
The values a game needs at run time reach C and C++ as macros, generated into
rmp/config.h, which every framework header includes for you:
const float centre_x = RMP_WINDOW_WIDTH / 2.0f; // [window] width
TraceLog(LOG_INFO, "%s starting", RMP_PROJECT_NAME); // [project] nameThey are macros rather than constants so that a game in plain C can use them too. Not every key has one: only the ones the game itself reads, such as the window, the UI's starting font and scale, the volumes and the save settings. Headers explains the file, and the macros reference lists every one with the key it comes from.
An invalid .toml fails in configure.py, in about a second, before
anything is compiled — not at the compiler, and not on a CI runner twenty minutes in. The message
names the exact line, says what is wrong with it, and says what to write instead. Every combination
of keys that cannot work is a refusal with a reason, and each refusal has a test in the
framework.
A key the framework does not know is refused, because a misspelt key would otherwise be silently ignored and its default used instead:
[window]
titel = "Space Rocks" raylib_multiplatform.toml:2: titel = "Space Rocks"
^^^^^^^^^^^^^^^^^^^^^
configure: error: unknown key [window.titel] in raylib_multiplatform.tomlEvery value is checked for its type before anything reads it. A list written without its brackets is the commonest slip, and TOML would hand the string over a character at a time:
[targets]
enabled = "all" raylib_multiplatform.toml:2: enabled = "all"
^^^^^^^^^^^^^^^
configure: error: [targets] enabled = 'all' is a string, and this has to be a list.
Write [targets] enabled = ['all'] -- with the brackets. Without them TOML hands over the characters one at a time.
Groups count as names here: ["all"], ["desktop"].A stray pair of brackets the other way round is refused just as plainly:
[window]
orientation = ["landscape"] raylib_multiplatform.toml:2: orientation = ["landscape"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [window] orientation = ['landscape'] has to be a string, one of landscape, portrait, unspecified.
A TOML array or table here is almost always a stray pair of brackets.An empty value is refused too, wherever empty would mean nothing. A game with no title would have a blank title bar and no name under its icon:
[window]
title = "" raylib_multiplatform.toml:2: title = ""
^^^^^^^^^^
configure: error: [window] title is empty. It is the title bar on desktop and the name under the app's icon on Android and iOS -- give the game a name.Where empty does mean something, the key says what: [linux] glibc = "" builds against
the glibc of the machine doing the build.
And two keys that are each valid can still contradict each other. A frame cap of 15 frames a
second makes every frame a fifteenth of a second long, but [app] max_delta hands the game
at most a twentieth, so the game would run slow forever without anything saying why:
[window]
fps = 15 raylib_multiplatform.toml:2: fps = 15
^^^^^^^^
configure: error: [window] fps = 15 makes every frame 0.06667 s long, but [app]
max_delta = 0.05 hands the game at most that much per frame, so the
game would run at 75% speed forever. Raise fps to 20 or
more, raise max_delta to 0.06667 or more, or set max_delta = 0.The same check runs wherever the .toml is read: cmake --preset debug,
rmp run, the config stage of rmp test, and the first job of every
CI run. python3 tools/configure.py --check runs it on its own and writes nothing.
One check is stricter on a release. A tag build refuses an [android] application_id
or an [ios] bundle_id that is still a placeholder under com.example., for a
target that is enabled, because a Google Play application id can never be changed after the first
upload. A debug build accepts them, so that a game builds the moment it is made.
No version. A release takes its version from the git tag: v1.2.3
becomes the version name on every platform, and Android's version code is worked out from it as
major × 1000000 + minor × 1000 + patch, so it only ever goes up. A build that is not a
tag is 0.0.0-dev. There is nothing in the file to remember to bump.
No secrets. The .toml is committed, so nothing in it may be secret:
no keystore, no token, no password. Signing keys and publishing credentials are GitHub secrets.
[resources] rres_password is not an exception — it is compiled into the game, which can
therefore read its own pack, and it makes unpacking the assets inconvenient rather than
impossible. [save] encrypt is the same: the key is derived from
[project] name and lives in the binary.
Every section, and what it is for. Most games touch the first four and leave the rest at their defaults.
| Section | What it decides |
|---|---|
[project] | The game's name: the executable, the CMake target, the Xcode scheme, the save folder on desktops and the web, and every artifact's name. |
[window] | The title, the size the window opens at — which is also the design resolution — how the world fits a window of another size, the phone orientation, vsync and a frame cap. |
[targets] | Which platforms the game is built for, by group or by exact id. |
[android], [ios] | The store identities, the oldest OS versions supported, the OpenGL ES version Android is compiled for and requires, the Play Store category. [ios.settings] passes raw Xcode build settings through, such as a signing team. |
[android.display], [android.permissions], [android.features] | Screen behaviour on Android (keep the screen on, hide the system bars, draw behind the notch), the permissions the app asks for, and the hardware the Play Store requires. |
[android.admob] | Whether AdMob is in the Android build at all — not unless the game turns it on — and the app and ad unit ids. See rmp::ads. |
[icon] | The picture the Android, iOS and Windows icons are made from, and the colour behind Android's adaptive icon. |
[app] | The longest step the game logic is ever handed, so a stalled frame is a moment of slow motion and not a teleport through a wall. |
[ui] | The theme, font, font size and scale rmp::ui starts with, and the ceiling on its layout tree. |
[input] | The analogue stick's dead zone. See rmp::input. |
[audio] | The volumes the three buses of rmp::audio start at. |
[save] | Where rmp::save puts the saves, whether they are sealed by default, and the version of your save format. |
[resources] | The password the asset pack is encrypted with. |
[raylib] | raylib modules a game does not use, left out to shrink the binary. |
[web] | The browser build's memory, whether it may grow, and which layer raylib talks to. |
[linux], [windows] | The windowing backend on each, native Wayland, and the oldest glibc the linux-x64-glibc and linux-arm64-glibc binaries may need. linux-riscv64-glibc is cross-compiled against Ubuntu 24.04's glibc and needs 2.38, which its CI job holds it to. |
[upx] | Which shipped binaries are compressed with UPX. A target that cannot be compressed is refused by name, with the reason. |
[dev] | Debug builds only: their compiler and linker, whether a framework warning aborts them, and the sanitizers they run under. The debug builds CI runs its checks with read it too; the release and web builds that ship never do. |
[ci] | Whether CI runs on every push and every pull request, or only on a release tag and when you start it by hand. See Continuous integration. |
[deploy], [deploy.itch], [deploy.firebase] | Whether a LICENSES.txt ships with the game, where a release is published on itch.io, and the Firebase project whose Test Lab runs the Android build and taps through it. |
[project] name is the one value that names files. It has to be letters, digits,
_ and -, starting with a letter, because it becomes the executable on every
operating system. Changing it after release changes where the saves are kept on desktops and the web
— Android and iOS keep them in a folder without it, and so does a [save] portable build
that saves next to its executable — and, on every platform, makes sealed saves from the old name
unreadable, since their key is derived from it.
[window] width and height are two things at once. On a desktop they are
the size the window opens at. Everywhere, they are the design resolution: the size
rmp::ui lays a menu out at before scaling it to the real
window, and the area the camera starts centred on. The window
can be resized, and a phone's screen is whatever it is; the design resolution is the fixed size the
game is written against, and [window] stretch says what the world does in a window of
another size: letterboxed, expanded to show more of it, or left at 1:1. See
a window of another size.
[window] title is the title bar on a desktop and the name under the icon on Android
and iOS. orientation — "landscape", "portrait" or
"unspecified" — is applied to Android and iOS at once; on a desktop the window's shape
is its width and height.
vsync, on by default, waits for the screen's refresh before showing each frame: no
tearing, and no frames drawn that nobody sees. fps caps the frame rate, and 0, the
default, is no cap. The web and iOS ignore fps, because the browser and the display
pace the frame there.
enabled lists groups and exact target ids; they are expanded and duplicates
dropped. disabled is then subtracted from the result. There is no precedence to reason
about, because the two never conflict: enabled = ["all"] with
disabled = ["ios"] is every target except iOS, whatever order they are written in.
[targets]
enabled = ["desktop", "web"]
disabled = []A target turned off is out of the build, out of CI and out of the release. Every target, with the groups it belongs to:
| Target | What it is | Family | Groups it is in |
|---|---|---|---|
linux-x64-glibc | Linux x86-64 | linux | all, desktop, linux |
linux-arm64-glibc | Linux ARM64 | linux | all, desktop, linux |
linux-riscv64-glibc | Linux RISC-V | linux | all, desktop, linux |
linux-x64-musl | Linux x86-64 (musl / Alpine) | linux | all, linux |
windows-x64 | Windows x86-64 | windows | all, desktop, windows |
windows-arm64 | Windows ARM64 | windows | all, desktop, windows |
macos | macOS (universal) | apple | all, apple, desktop |
ios | iOS (simulator) | apple | all, apple, mobile |
web | Web (WebAssembly) | web | all, web |
android | Android | android | all, android, mobile |
freebsd-x64 | FreeBSD x86-64 | bsd | all, bsd |
freebsd-arm64 | FreeBSD ARM64 | bsd | all, bsd |
openbsd-x64 | OpenBSD x86-64 | bsd | all, bsd |
openbsd-arm64 | OpenBSD ARM64 | bsd | all, bsd |
netbsd-x64 | NetBSD x86-64 | bsd | all, bsd |
linux-x64-glibc-drm | Linux DRM/KMS (no X11) | linux | all, drm, linux |
linux-arm64-glibc-drm | Linux ARM64 DRM/KMS (no X11) | linux | all, drm, linux |
[android] application_id and [ios] bundle_id are the game's identity on
the stores. A Google Play application id is permanent: once an app is published under one, it can
never be renamed or moved, and getting it wrong means a new listing that starts again from zero
installs and reviews. That is why a release refuses the com.example. placeholders that
rmp new writes. Set both before the first release.
[android] gl_version
decides what raylib and the game are compiled for on Android, and the manifest requires the same
version. "ES20", the default, compiles for OpenGL ES 2.0, which every Android device
has. "ES30" compiles raylib's ES 3.0 path, links libGLESv3 and asks EGL for
a version 3 context, and the Play Store does not offer the game to a device without ES 3.0.
"ES31" and "ES32" are refused, because raylib has no 3.1 or 3.2 path: they
would compile the ES 3.0 one all the same and only hide the game from more devices.
[android]
gl_version = "ES31" raylib_multiplatform.toml:2: gl_version = "ES31"
^^^^^^^^^^^^^^^^^^^
configure: error: [android] gl_version = 'ES31' would compile raylib for ES 3.0 all the same -- it has no 3.1 or 3.2 path -- and only hide the game from devices without 3.1.
Use "ES30" for ES 3.0, or "ES20" to reach every device.Ads are opt-in. With [android.admob] enabled = false, the default and what
rmp new writes, the Android build carries no Google Mobile Ads SDK, asks for no
advertising-id permission and owes Play no advertising-id declaration; the
rmp::ads calls still compile and do nothing, as they do on
every other platform. AdMob also stays out of a build whose targets do not include Android.
Turned on, the three ids go into the release build's manifest and SDK as they are written, and
the SDK stops the app at startup over an app id it cannot read. So each one has to be a string, always, and while
AdMob is on it has to have AdMob's shape: ca-app-pub-, sixteen digits, ~ and
ten digits for app_id, and the same with a / for interstitial_id
and rewarded_id. The defaults are Google's test ids, which have that shape. An empty
id, a malformed one, or an app id where a unit id goes, is refused at its line:
[android.admob]
enabled = true
app_id = "" raylib_multiplatform.toml:3: app_id = ""
^^^^^^^^^^^^
configure: error: [android.admob] app_id is empty, and AdMob is on.
Put the app id from the AdMob console here -- or Google's test one while developing -- or set [android.admob] enabled = false.A
debug APK — the one rmp android builds, and the one CI hands to Firebase Test Lab, whose
crawler taps whatever is on the screen — shows Google's test ads whatever ids the
.toml holds, because a tap on a real ad from your
own build is invalid traffic, and invalid traffic is how an AdMob account gets suspended.
[dev] applies to debug builds and to nothing else. The release and web presets never
read it, so nothing in it can change what ships. compiler picks the compiler of a debug
build, when the machine has it, linker a faster linker when one works, and
strict = true turns the first warning the framework prints about a mistake in the game —
an action nobody defined, a pop() with nothing underneath — into an abort, in the
debugger, at the line that caused it. Release builds compile that check out.
Debug builds are not only the ones on your machine. CI checks a game with debug builds too —
the software render check in a game's own CI is one, booting the game for a few frames — and those
read [dev] exactly as yours do. So with strict = true, a warning the game
triggers while CI boots it aborts the game and fails the check.
Most
of what a debug build compiles is not your game. It is raylib and what it bundles — GLFW, miniaudio,
the image and font decoders — and all of it is C. The Tiny C Compiler compiles C many times faster
than GCC or Clang: on x86-64 Linux, a clean debug build of raylib takes a fraction of a second with
it instead of seconds. c_compiler picks the compiler of a debug build's C, while its C++
— your game and the framework — keeps compiler's:
| Value | Means |
|---|---|
"same" | The C compiler that goes with compiler. The framework's own .toml says this. |
"auto" | tcc when it is installed, on x86-64 Linux; the same as "same" anywhere else, saying which it took. What rmp new writes into a game. |
"tcc" | tcc, and configuring fails when it is not installed. |
[dev]
c_compiler = "auto""tcc" is refused anywhere but Linux, and with compiler = "mingw" or
"msvc", by configure.py, with the line. A tcc build links with GNU ld,
whatever linker says, and its C is never sanitized — tcc has no sanitizers; the C++ is,
when sanitize asks. That is why the framework keeps "same": every line of
its debug builds runs under the sanitizers. A tcc that writes no debugging information or unwinding
tables is not enough: the build image carries tcc 0.9.28rc, built from one commit of its
repository; your distribution's tcc may be older.
Every
configure of CMake — rmp run, rmp build, rmp test, and every
CI job that runs CMake itself (Gradle keeps the Android build's to itself) — prints the C compiler, the C++ compiler and the linker it was given, each with its path and
version, at the top of its log: === C compiler:, === C++ compiler: and
=== Linker:. Which one compiled what is never a guess.
A test sees what
it asserts, and a read one past the end of an array that happens to find a zero passes every test
there is. [dev] sanitize lists what a debug build is instrumented with to catch that
kind of mistake where it happens instead of where it crashes, and each report stops the game at
the line that did it, with the stack that got there:
"address", AddressSanitizer: a read or a write past a buffer, a use after free or
after return, and on Linux, through LeakSanitizer, memory nobody freed, reported when the game
exits. About three times as slow — the framework's unit tests take 5.5 seconds, and 18.6 under
it — and two to three times the memory."undefined", UndefinedBehaviorSanitizer: a signed overflow, a shift past the
width, a float cast to an int it does not fit, a misaligned or null access. Cheap.[dev]
sanitize = ["address", "undefined"]A
game starts with sanitize = [], none: turning them on is its author's choice. The
framework lists both, so every debug build of its own — the library, the examples and every test —
runs under them. Release, web, Android and iOS builds never read the key.
Whether
the compiler can give a sanitizer is decided when the build is configured, by building a small
program with it and running it, because a compiler can accept the flag and then have no runtime to
link. A sanitizer that does not run is the machine's problem and not the .toml's: the
debug build goes on without it and says so in a warning, naming what brings it — on Linux, clang
needs compiler-rt, libclang-rt-<N>-dev on Debian and Ubuntu, and gcc's runtimes
come with most distributions. With RMP_REQUIRE_SANITIZERS=1 in the environment the
same configure fails instead, and the software-render check of CI's lint job sets it,
so a sanitizer the .toml lists is never quietly missing there. cmake --preset debug -DRMP_SANITIZE=OFF turns them
off for one build folder, to measure what they cost.
A
runtime can also have part of a sanitizer. The probe calls a virtual function, which is what
UndefinedBehaviorSanitizer's check of dynamic types needs, and NetBSD's GCC has no runtime for that
one check: there a debug build keeps every other check of "undefined", and of
"address", leaves out that one, and says so in a warning.
What can never work is
refused in configure.py, with its reason. Every other sanitizer a compiler knows —
thread, memory, leak, hwaddress,
integer, implicit-conversion and fuzzer — is refused by
name, saying why it does not fit a game:
[dev]
sanitize = ["thread"] raylib_multiplatform.toml:2: sanitize = ["thread"]
^^^^^^^^^^^^^^^^^^^^^
configure: error: [dev] sanitize: 'thread' is refused -- ThreadSanitizer has to see every library the game runs, the system's audio and GL drivers included, or it reports races that are not there -- and it cannot be combined with address.
Use "address" and "undefined", or [] for none.So is a pair that cannot work together: "undefined" with
[dev] compiler = "msvc", whose /fsanitize has address only; any
sanitizer with "mingw", whose GCC ships no runtime; and "address" on
OpenBSD, whose clang has no AddressSanitizer.
A
report fails the checks that boot the game in debug. rmp test smoke, rmp test
render and the software-render check in CI read the game's output for one and its exit
status as well, because a leak is reported after the game has printed everything else; they stop
with a sanitizer reported the run above (exit …) and the first forty lines of the
report. Code that has to know — a timing test that allows for the slowdown — can ask
#if defined(RMP_SANITIZE), and RMP_SANITIZE_ADDRESS or
RMP_SANITIZE_UNDEFINED for one of them; the build defines each for what it
applied.
https://omardev29.github.io/rmp-docs/manual/basics/the-rmp-command.html
rmp is the one command a game needs. It builds the game, runs it, checks
it, packs its assets, tags a release and makes new games. It is a single Python file,
tools/rmp.py, standard library only, behind three small launchers so that the same word
works in every shell.
Every command, with its examples, is in the commands
reference, which is read from rmp help itself.
The installer gets the framework and puts rmp on your PATH, in one line:
curl -fsSL https://omardev29.github.io/rmp-docs/install.sh | shirm https://omardev29.github.io/rmp-docs/install.ps1 | iexInstall rmp has the line for every system, where it
puts things, and how to remove them. Underneath, it is a clone of the framework and two of
rmp's own commands, and a clone you made yourself goes on your PATH with the second:
~/raylib_multiplatform/rmp installBuilding a game also needs Python 3.11 or newer, CMake, Ninja and a C++ compiler on the PATH, and on a Linux desktop the X11 development libraries; the installer lists whichever this machine lacks. On a Linux console with no desktop it lists the DRM/KMS ones instead, which Linux from a console names. The one command for each of Debian and Ubuntu, Fedora, Arch and Alpine is in Getting started, and the build image needs none of them on your machine.
The framework's root, and every game's, holds three files that do one thing each: find a Python
3.11 or newer and hand it tools/rmp.py with every argument you typed.
| File | For |
|---|---|
rmp | POSIX sh, so it runs as /bin/sh on Linux, macOS and the BSDs and under bash, zsh and ksh. It follows a symbolic link to itself, so ln -s ~/raylib_multiplatform/rmp ~/bin/rmp works too. |
rmp.ps1 | PowerShell, Windows PowerShell 5.1 included. |
rmp.cmd | cmd.exe. |
Each one asks every Python it finds whether it is 3.11 or newer instead of trusting the name:
macOS's own python3 is older than that, and on Windows python3 can be the
Microsoft Store's placeholder, which exits without running anything. The sh launcher tries
python3, then python3.14 down to python3.11, then
python, then the py launcher that python.org installs on Windows; the
PowerShell and cmd launchers try py -3, python3 and python.
When none will do, the command says so and stops:
rmp: needs Python 3.11 or newer on PATH (python3, python or py).
rmp works on the project it is standing in: the nearest folder, from the current one
upwards, that holds a raylib_multiplatform.toml. So it works from any subfolder of a
game. Outside a project, only rmp new, rmp install, rmp update
and rmp help mean anything, and the others say so.
The project is either a game or the framework itself — the framework is the one that also holds
its own test suite. rmp lint and rmp example are the framework's maintenance
commands and are refused in a game.
Inside a project, the rmp on your PATH does not run its own code: it runs that
project's copy of tools/rmp.py. A game therefore keeps the rmp it was made
with — its build, its checks, its release steps — when the framework on your PATH moves on. Games
made months apart each behave the way they did when they were made.
rmp new,
rmp install and rmp update are the exceptions, by design: they act on the
framework that ships the rmp being run, wherever they are typed. A new game is made from
the framework you have installed, not from the game you happen to be standing in; and what goes on
your PATH, and what updates, is that framework too. A game's own copy of rmp refuses
the last two, because it is never what is on your PATH and never updated.
One variable in the environment turns the hand-over off, so that the rmp on the PATH
runs its own code on the project:
RMP_NO_DELEGATE=1 rmp testrmp run # build (debug) and play
rmp test # the .toml, the pins, the licences, a frame drawn, a boot
rmp build release # the release build
rmp web # or: rmp android
rmp package # the zip a release ships, made here
rmp help # every command; rmp help <command> explains one, with examplesrmp run builds the game in debug and starts it. Only what changed is compiled again,
and only the game's own target is built, not anything else the build folder has configured. When the
game exits, rmp exits with the game's code, so a crash is not reported as a
success.
rmp build compiles without running and prints where the executable is:
build/debug/, the folder rmp run builds in too.
rmp build release is the build players get: optimised, with link-time optimisation
except on NetBSD, whose linker cannot read GCC's link-time objects in a static library, and reading
its assets from the resources/ shipped beside it rather than from the project.
It puts the executable in build/release/ and copies nothing next to it, so started from the
project's root it falls back on the project's own resources/. Laid out the way a release
ships it — the executable with resources/ beside it — it finds its files from whatever
folder it is started in, everywhere but NetBSD and OpenBSD; The app
explains how.
Debug and release each have a folder of their own, so switching between them rebuilds
nothing, and the release never meets the compiler [dev] compiler chose for debug,
which stays in the debug folder's cache. build/ itself only holds those folders and is
never a build. A CMakeCache.txt at its top is a build from a checkout older than that,
and the first rmp command that configures removes what it left there, says so, and
keeps the folders of the builds beside it.
On
a Linux console with no desktop, rmp builds the game for DRM/KMS — raylib's backend
that draws straight to the screen, with no X11 and no Wayland — and says so once. Debug and
release then go to build/debug-drm and build/release-drm, and
rmp run checks that the game can open the screen and read the keyboard before it
starts it, saying what to do when it cannot. rmp run sudo builds as you and starts
only the game as root, and rmp itself under sudo refuses every command but
rmp help and rmp clean. RMP_DRM=1 or 0 in the
environment overrides what rmp decides.
Linux from a console has the whole of it.
rmp web builds the game for the browser with Emscripten, into
build/web/. The emsdk has to be activated in the shell first, so that
EMSDK is set; rmp refuses with that instruction when it is not. The page has
to be served, not opened as a file:
rmp web
python3 -m http.server 8000 --directory build/weband then localhost:8000/my_game.html in the browser, with the game's name in place of
my_game. Web has the rest of the browser
target.
rmp android regenerates the Android configuration from the .toml, builds a
debug APK with Gradle — which needs the Android SDK and NDK — and prints every APK it finds, marking
the one it has just written. adb install -r with that path puts it on a connected
phone. Android has the rest.
On
Linux, rmp build windows builds the release .exe for 64-bit Windows,
without a Windows machine: with MinGW-w64, into build/windows/. rmp build windows
clang-cl builds it with clang-cl and lld-link instead, into
build/windows-clang-cl/, against Microsoft's own C runtime and Windows SDK — the same
ones Visual Studio links — which is closer to what a Windows machine builds.
rmp build windows # build/windows/my_game.exe, by MinGW-w64
rmp build windows clang-cl # the same with clang-cl, against Microsoft's runtime
rmp run windows # built, then started under WineMicrosoft's runtime and SDK cannot be handed out by anyone but Microsoft, so neither the
framework nor its build image carries them. The first rmp build windows clang-cl asks
you to accept Microsoft's licence for them, and once you type yes, xwin downloads them
from Microsoft into ~/.xwin (about 800 MB; XWIN_DIR puts them elsewhere),
once. Not on a terminal, it refuses instead of asking, unless
RMP_ACCEPT_MICROSOFT_LICENSE=1 says you accept it. The runtime it fetches is the newest
your clang-cl can compile.
rmp run windows builds the .exe and starts it under Wine, which is a
quick look and not a proof: Wine is not Windows. The build image has MinGW-w64, clang-cl, lld-link,
xwin and Wine (on x86-64; there is no Wine for x86 programs on ARM). On a Linux machine of your own,
MinGW-w64 is the mingw-w64 package, clang-cl and lld-link come with LLVM, and xwin is
cargo install --locked xwin. On Windows, rmp build release already builds
the .exe, and rmp build windows says so.
rmp package makes, on your machine, the archive a release job would upload, into
build/package/: the release build, packed with UPX where [upx] asks, the
resource pack, and LICENSES.txt, zipped. For when you ship by hand — an upload to itch,
a zip for a friend, a build for a store — without a tag and a CI run.
rmp package # build/package/my_game-linux-x64-glibc.zip: this machine's target
rmp package windows # build/package/my_game-windows-x64.zip, made on Linux
rmp package windows clang-cl # the same with clang-cl: my_game-windows-x64-clang-cl.zip
rmp package web # build/package/my_game-web.zip: the page, ready to upload
rmp package android # build/package/my_game-android.aab and .apk, signedrmp package android builds the release bundle — what Google Play takes — and a release
APK, what a phone installs from a file, both signed with your upload key. It reads the key from the
same four variables CI does, and refuses, naming each one missing, when they are not set:
export ANDROID_KEYSTORE_FILE=~/keys/upload.jks
export ANDROID_KEYSTORE_PASSWORD=...
export ANDROID_KEY_ALIAS=upload
export ANDROID_KEY_PASSWORD=...
rmp package androidThe keystore never goes in the .toml or the repository. CI checks the command is
what it ships: the web job makes the zip with rmp package web as well and compares the
two file by file, and the Android job signs with rmp package android and verifies both
files' signatures. Google Play says how to make an upload
key.
rmp test checks the game, stage by stage, and stops at the first that fails.
rmp test smoke runs a single stage. In a game there are four, in this order:
| Stage | What it does |
|---|---|
config | Validates raylib_multiplatform.toml the way every build does, checks that the pinned versions agree with each other, and checks every licence of everything vendored. |
unit | Builds your tests in tests/game/ with the game and runs them with no window. With no .cpp there, it says so and passes. See Testing. |
render | Builds the game a second time against raylib's software renderer, which draws into memory with no GPU and no window, runs it for ten frames, and requires that it exited with status 0 and no sanitizer report, booted with no asset failing to load, drew something, honoured [window] vsync and reached the end of its frames. |
smoke | Builds the game in debug, runs it for ten frames for real, and requires that it exited with status 0 and no sanitizer report, booted with no asset failing to load and put pixels on the screen. |
These are the same checks CI runs on the targets it can start, which is why a game that passes
rmp test rarely surprises anyone in CI. A failed smoke stage prints the game's own output
and one of four reasons, in this order: a sanitizer reported the run above (exit …),
the game exited with status …, the game did not boot, or an asset failed to
load, or the game booted and drew nothing. The exit status is read because the
markers are printed before the game ends: a crash on the way out, or a leak that
[dev] sanitize reports at
exit, comes after them.
The config stage runs shell scripts, so on Windows it needs a bash; the one Git for
Windows installs is the one rmp looks for.
rmp fmt
formats your C and C++ — everything under src/, include/ and
tests/ except the framework's own folders, tests/smoke_test.h and
generated files — with whichever
clang-format is on your PATH. rmp fmt check only reports what would change.
Neither compares that clang-format's version with the one pinned in
thirdparty/FROZEN_VERSIONS.md, and a different version would reformat files that were
already correct, so it is worth installing the pinned one.
rmp pack bundles resources/ into one encrypted resources.rres
inside it, the way a release ships, so you can see the game run from the pack. From then on the game
reads the pack. rmp unpack deletes it, and the game reads the loose files again — which
is what you want while you are adding art.
rmp clean deletes build/ and every file generated from the
.toml. The next build makes all of it again. It is the answer when a build goes strange.
The Android and iOS icons stay, because they are not in those folders and remaking the Android ones
needs Pillow. The Windows icon is in cmake/generated/ and goes with the rest, so after a
clean a machine without Pillow builds an .exe with no icon.
rmp push is git push, refused while a CI run is still in flight: CI
cancels the run in progress when a branch receives a new push, so pushing would throw away a run
that was half done. It names the run instead, with the command to watch it. rmp push force
pushes anyway. Without the gh command installed it cannot ask, says so, and pushes.
With [ci] on_push = false a push starts no
run to cancel, so it asks nothing and pushes — unless ci.yml has changes not committed
yet, when the commit being pushed may still start one.
A
branch with no upstream yet has nowhere to go, so its first push, to the remote called
origin, is git push -u origin and the branch's name — git push -u origin main for the main of a game
rmp new made, once git remote add origin has named its repository. Git
then knows where the branch goes, and every push after it is a plain one. With no remote at all,
rmp push refuses and says how to add one.
rmp deploy 1.2.0 releases a version. It adds the v, and refuses — before
tagging anything — when there are uncommitted changes, when the tag already exists here or on the
remote, when the branch has not been pushed (rmp push is what it tells you to run), or
when the commit you are on is not the one on the remote, since CI builds the tag from the remote. It then checks the .toml the way the
release will, which refuses placeholder store ids and a version that is not
MAJOR.MINOR.PATCH, and only then makes an annotated tag and pushes it. CI builds every
enabled target and attaches them to the release. rmp deploy 1.2.0-rc1 is a
pre-release.
rmp install puts the framework it belongs to on your PATH, and rmp update
moves that framework forward to the latest main; the installer runs both for you.
Install rmp explains them.
rmp new my_game makes a game; rmp new --list prints what a game gets
without making one. Project layout
explains both.
rmp help lists the commands on one screen. rmp help test explains one,
with examples — and for test, its stages. -h or --help after
any command prints the same page. rmp help --json prints every command and stage for a
tool to read; this site checks every rmp line it shows against it.
| Exit code | Means |
|---|---|
| 0 | Done, or help printed. |
| 1 | A check failed, or a precondition did not hold and the command refused. |
| 2 | The command line was wrong: an unknown command, a wrong argument, a framework command in a game, no project here, or an RMP_DRM that is neither 1 nor 0. |
| 127 | No Python 3.11 or newer was found to run it: the launcher printed the message above and stopped. |
| 130 | Interrupted. |
A misspelt command gets the nearest real one suggested back. A command that ran something external, such as CMake, and saw it fail, names what failed and its exit code.
Nothing in a game requires rmp: underneath, it is plain CMake with presets, and the
.toml is applied by the configure step itself.
cmake --preset debug # configures AND generates everything from the .toml
cmake --build --preset debug
./build/debug/my_gameThe presets a game builds with are debug, release, web and
memory, the software-rendered build the render stage uses, and each builds
into the folder of its name under build/: build/debug,
build/release, build/web, build/memory. On a Linux console,
debug-drm and release-drm take the place of the first two, in
build/debug-drm and build/release-drm. Configuring
build/ itself is refused before anything else runs, and so is a release configured by
hand into a folder where [dev] compiler was applied, because that compiler stays in the
folder's cache. A fifth, cmake --preset lint, only configures, into
build/lint: it writes the compile database that clang-tidy and an editor read.
https://omardev29.github.io/rmp-docs/manual/basics/headers.html
The framework is 16 headers under include/rmp/, one per
module, and there is no header that includes them all. A file includes the modules it uses, and
what it does not include it does not pay for.
A file that draws the HUD includes rmp/ui.h and nothing else of the framework's:
#include <rmp/ui.h>
#include <string>
void draw_hud(int score) {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::text("Score " + std::to_string(score));
rmp::ui::end();
}That file gets the interface layer and only it: no entry point, no asset layer, no scene, and
none of the C library's maths behind them. When the HUD changes it recompiles, and when the asset
pipeline changes it does not. examples/platform/03_minimal_includes is this file as a
check the framework's CI compiles on its own, so the claim cannot quietly stop being true.
The split is also what makes the framework something you take a piece at a time. A game can use
rmp::ui and draw everything else with raylib, or use scenes
and objects and never touch the UI. Each header is a module you can name and decide about — which
is the rule for adding one: a new header has to be a part of the framework with a name, because
every header is one more thing a reader has to know exists.
A missing include is a compile error that says exactly what is missing. Using
rmp::input::just_pressed in a file that never included rmp/input.h is an error
that rmp::input was never declared — the compiler telling you which header to add.
| Header | What it gives | Manual |
|---|---|---|
rmp/app.h | The entry point — RMP_GAME and RMP_ENTRY_POINT — closing the app with rmp::app::quit(), and rmp::global<T>(). Reference: rmp::app. | The app |
rmp/scene.h | rmp::Scene, the stack of scenes, spawning and raycasting, and rmp::Camera. | Scenes, Camera |
rmp/object.h | rmp::Object, rmp::Handle, rmp::Callback, rmp::Sprite, the shapes, the edges and the ray queries. | Objects, Collision |
rmp/behavior.h | The catalogue of rmp::behavior: movement, tweens, timers, spawners, health. | Behaviors |
rmp/input.h | rmp::input: named actions with up to eight bindings each, axes and directions, and the pointer. | Input |
rmp/ui.h | rmp::ui: menus, buttons, text, layout, the controls of a settings screen, and themes. | Interface |
rmp/assets.h | rmp::assets: loading from resources/ by name, and the counted handles that release what they own — rmp::Texture, rmp::Font, rmp::Sound and the rest — with rmp::SheetData behind an Aseprite sheet. | Assets, Sprites |
rmp/tilemap.h | rmp::Tilemap and rmp::MapObject: levels from LDtk, and from Tiled. | Tilemaps |
rmp/audio.h | rmp::audio: sound effects and music by name, and three volume buses. | Audio |
rmp/save.h | rmp::save and rmp::Value: saving the game, in the right folder on every platform. | Saving |
rmp/random.h | rmp::random: one seeded generator, so a run can be reproduced. | Random |
rmp/ads.h | rmp::ads: interstitial and rewarded ads, real on Android once [android.admob] enabled turns them on, and silently nothing otherwise. | Ads |
rmp/math.h | raymath's operators on raylib's own Vector2, Vector3, Vector4 and Matrix, and raylib-cpp's methods on those and on Rectangle and Color. | raylib in your game |
rmp/config.h | The RMP_ values from raylib_multiplatform.toml. Every header above includes it, so you never write it. | Below |
Everything the framework adds is under rmp::, and everything else is raylib's, so in
a file that mixes the two you can always tell which is which. All of raylib is there:
DrawTexture, IsKeyPressed, LoadModel. The framework's types
take and convert to raylib's own, so a Vector2 is the same Vector2 on both
sides.
This header exists for one line:
position = position + velocity * delta;The operators come from raylib's own raymath.h, which defines them for C++, so they
work on the plain Vector2 every raylib function takes; there is no second vector type to
convert to and from. raylib-cpp's maths classes — raylib::Vector2 and its siblings —
derive from raylib's structs and add methods such as Normalize, for whoever prefers
them. The rest of raylib-cpp is not vendored: its loaders throw on a failure, and nothing in this
framework throws to the game.
It is a header of its own because the C library's <math.h> behind it is the
expensive part, and a file that only draws menus should not pay for it. rmp/ui.h
deliberately does not include it.
The framework's headers do not include each other. Where one needs a type from another it
declares the name and nothing more — rmp/app.h names rmp::Scene without
including rmp/scene.h — so that a header can grow without dragging the rest of the
framework into every file that touches it.
The exceptions are where a type is held by value, which a declaration cannot provide, and each one says so at the top of the header:
| This header | Includes | Because |
|---|---|---|
rmp/scene.h | rmp/object.h, rmp/tilemap.h | Every scene holds its map and its camera, and the camera holds a handle to the object it follows. |
rmp/object.h | rmp/assets.h | An object's sprite holds an rmp::Texture or an rmp::SpriteSheet. |
rmp/tilemap.h | rmp/object.h | A map stores the factories registered with on_object() as rmp::Callbacks. |
rmp/behavior.h | rmp/object.h, rmp/scene.h | The behaviors hold handles and callbacks, and a spawner's callback is handed the scene. |
So rmp/scene.h alone is enough to write a scene with objects in it. Including the
headers you use by name anyway costs nothing and keeps the file honest about what it depends on.
The rule is about the framework's own headers only. The standard library and raylib are used
wherever the job needs them: rmp/app.h includes <memory>, because
the first scene is handed over as a std::unique_ptr. What each header costs to include
is measured, and the framework's checks fail when one grows or shrinks by more than a fifth of what
it was measured at.
The values a game reads from raylib_multiplatform.toml arrive as macros:
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);rmp/config.h is the one framework header that every other one includes, and the
only exception to the rule above. It earns that by costing nothing: its one include is the
generated file of #defines, which includes nothing itself, and the two parse as fast as
an empty file, within the noise of measuring it. In return the
values are simply there, in every scene and every object, with nothing to remember. The framework's
checks compile every public header on its own and fail the one that forgets it, so a new header
cannot hand you an undefined macro.
It includes rmp/generated/config.h, which tools/configure.py rewrites on
every configure and which is never committed. The file you can see in your editor exists so that the
word "generated" never appears in anyone's code, and so that an editor that has not configured yet
still resolves the include.
They are macros, not constexpr constants, so that a game in plain C can use the same
values: a C file has no namespace to reach into. Plain C is
also the one place you include it yourself, because a C file includes none of the framework's C++
headers.
| Macro | From |
|---|---|
RMP_PROJECT_NAME | [project] name |
RMP_WINDOW_TITLE, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT | [window] title, width, height — the design resolution |
RMP_WINDOW_VSYNC, RMP_WINDOW_FPS | [window] vsync and fps, as 0 or 1 and a number |
RMP_MAX_DELTA | [app] max_delta |
RMP_UI_THEME, RMP_UI_FONT, RMP_UI_FONT_SIZE, RMP_UI_SCALE, RMP_UI_MAX_ELEMENTS | [ui]: what the interface starts with |
RMP_INPUT_DEADZONE | [input] deadzone |
RMP_AUDIO_MASTER, RMP_AUDIO_MUSIC, RMP_AUDIO_SFX | [audio]: the volumes the buses start at |
RMP_SAVE_PORTABLE, RMP_SAVE_ENCRYPT, RMP_SAVE_VERSION | [save] |
RMP_RRES_PASSWORD | [resources] rres_password |
RMP_DEV_STRICT | [dev] strict |
The macros reference has the same list with the framework's own values.
RMP_RRES_PASSWORD is in the header, and not only in the CMake build, because Android
and iOS take nothing from CMake: a value defined there alone would differ on those two, and they
could not open the pack they shipped with.
Two more values come from the build system rather than from the .toml, and every
build system defines both — CMake from its preset, Gradle from the build variant, Xcode per
configuration:
#if RMP_PRODUCTION_BUILD
// compiled into a release build only
#endif
TraceLog(LOG_INFO, "assets are read from %s", RMP_RESOURCES_PATH);The first is 1 in a release build and 0 in a debug one. It is defined everywhere on purpose: an
undefined macro in #if is not an error but 0, which would quietly compile a game's
debug-only code into its release on whichever platform forgot it. A build that forgets it fails to
compile instead. The second is
where the loose files of resources/ are read from. On a desktop that is the project's
folder by its absolute path in a debug build, and ./resources/ in a release. A desktop
release moves into the executable's folder when it starts, when there is a resources/
there, so that the path means the folder shipped beside it —
The app has the detail. The web,
Android and iOS read the copy packaged with the game.
https://omardev29.github.io/rmp-docs/manual/core/index.html
What every game made with the framework is built from: the app that runs the frame, the scenes the game moves between, and the objects that live in them.
https://omardev29.github.io/rmp-docs/manual/core/app.html
The app is what runs a game: it opens the window, runs one frame after another, and
closes everything in the right order on the way out — on a desktop, in a browser, on a phone. A game
written with scenes meets it once, in the last line of src/main.cpp, and after that
only when it wants to quit or keep something across scenes.
This is the whole of src/main.cpp in a new game:
// Your game starts here, and this is all of it.
//
// RMP_GAME opens the window from [window] in raylib_multiplatform.toml, enters
// the scene you name, runs it every frame, and shuts everything down on the way
// out — on every target, including the two where main() is not a main() at
// all. Your work is in src/scenes/ and src/objects/.
#include <rmp/app.h>
#include "scenes/main_menu.h"
RMP_GAME(MainMenuScene);
RMP_GAME takes the type of the first scene. It opens the
window from [window] in raylib_multiplatform.toml, then makes that scene and
puts it on the stack, runs the stack every frame, and shuts everything down when the game ends.
The window is open before the scene is made, so a texture, a font or a sheet among the scene's
members loads exactly as one in _ready() does. There is no InitWindow(), no
frame loop and no unloading in the game, because those were the same lines in every game and none
of them was ever yours to get right.
A texture, a font or a sheet asked for before the window opens has nothing to draw: raylib's GPU calls have nowhere to go yet. That is a load at namespace scope, or in the constructor of a global. The framework names the first one, once, when the window opens: ASSETS: 'hero.png' was loaded before the window opened, so it has nothing to draw; in a debug build that is on the screen too, and a CI boot fails on it. Load it in a scene.
It also writes the entry point the platform expects, and the platforms do not agree on what that is. The difference between them is who owns the frame loop:
| Platform | What RMP_GAME writes |
|---|---|
| Windows, Linux, macOS, the BSDs, Android | A main() with the frame loop in it: the game owns the loop. On Android, raylib's own entry point calls that main(). |
| The web | A main() that hands each frame to the browser: the browser owns the loop. |
| iOS | The three callbacks UIKit calls instead of a main(): UIKit owns the loop, and there is nothing to return to. |
The web is a loop the browser runs and not a while loop for a reason that costs real
bytes. A loop that never returns would freeze the page, and the only way to run one there is
Emscripten's ASYNCIFY, which instruments every function that might be on the stack —
most of them — and makes the whole program larger and slower whether or not it ever waits. Handing
each frame to the browser is what lets the web build go without it.
Naming the first scene in the .toml would mean looking it up by a string, and a
string-to-type lookup in C++ is built from objects that register themselves when the program starts.
In a static library, and in the prebuilt framework iOS links, the linker throws away any object file
nothing refers to — and a self-registering object is exactly that. It would not fail to compile; it
would work on your desktop and find no scenes on the phone. So the scene is named where a C++
program starts, in main.cpp, where the linker can see it.
A
program with no entry point, or with two, is a link error that names the symbol
rmp_entry_point_is_declared_exactly_once: missing, or defined twice. The linker's own
complaint about main comes with it, and on its own it says neither what to write nor
which file to look at. The framework asks for the symbol from a static initializer, the one kind of
code every linker keeps, so the name is there even when the linker discards everything else
unused.
Before your first scene exists, the app:
resources/ is;rmp::random from the clock, so a shipped game plays a
different sequence every launch;[dev] strict when the build is a debug build and the .toml
asks for it;resources/ folder in it (see
where a release finds its files);[window] vsync is on, capped at
[window] fps when that is not 0 (except on the web and iOS, which pace the frame
themselves), at [window] width by height, titled [window] title;_ready().So a scene's _ready() always runs with the window open and the assets available, which
is why it is where a scene loads what it draws. Once that first _ready() has returned,
the app turns raylib's exit key off, so that Escape belongs to the game; see
the Escape key.
A
release build reads its files from ./resources/, and . is whatever folder
the game was started from: a file manager, a shortcut or a terminal somewhere else would leave it
loading nothing. So on Windows, Linux, macOS and FreeBSD a release moves into the folder the
executable is in before anything is loaded, when that folder holds a resources/. The
game starts the same from anywhere, and plain raylib calls with relative paths, such as
LoadTexture(RMP_RESOURCES_PATH "x.png"), find their files too.
When the executable's folder has no resources/ — a release built in the project and
started from the project's root, with the executable in build/release/ — the game keeps the
folder it was started from and says so in its log. On NetBSD and OpenBSD raylib's
GetApplicationDirectory(), which the framework asks, has no code and answers nothing, so
a release there always reads resources/ from the folder it was started from, and logs
that it does. The web, Android and iOS read the copy packaged with the game
and never need it.
Every frame runs the same steps in the same order, and the order is the contract — it is what every property of the scene stack is built on:
on_click,
on_drag), then the scene's
_update() runs, then its
objects update and move, then the
collision pass resolves where they ended up, and last the
camera follows._draw() runs after, in screen space. The
notices go last, over everything.After each frame the music that is playing is fed, whatever else is going on — under a pause menu too, since a streamed track that is not fed stutters.
Every _update(float delta) receives the seconds the last frame took. Real time has no
ceiling: drag the window, stop at a breakpoint, let a disk stall, and a frame comes back half a
second long. A bullet moving 900 units a second then moves 450 units in one step, straight through a
wall it never overlapped.
So delta is clamped to [app] max_delta, a twentieth of a second by
default. A frame that really took longer arrives as that, and the game runs a moment of slow motion
instead of teleporting through the level: nobody minds a hitch, and everybody minds falling out of
the world. Setting max_delta = 0 switches the clamp off. A negative reading, which a
clock can produce across a suspend, arrives as 0.
The first frame's delta is 0, because raylib has no previous frame to measure from.
With [window] vsync on, the default, each frame waits for the screen's refresh, which
paces the game at the display's rate. [window] fps caps it, for a desktop without
vsync. The browser and iOS pace the frame themselves and ignore fps; never call
SetTargetFPS() in a game that builds for the web, where a wait inside the browser's frame
would only stall it.
[window] width and height are the design size: what the game is
drawn for. The window, though, can be resized, a phone's screen is whatever it is, and a monitor may
be 21:9. [window] stretch says what the world does in a window that is not the design
size. Below, s is how much bigger the window is than the design —
min(window width / design width, window height / design height), the most the whole
design fits:
stretch | The world |
|---|---|
"none" | At 1:1 around the camera: a bigger window shows more of it and a smaller one less, and nothing is scaled. |
"letterbox" | The design, scaled by s and centred; the rest of the window is bars of the clear colour. Every player sees the same part of the world, the interface stays inside it, and nothing is cut off: a court, a board, a single screen. |
"expand" | Scaled by s like letterbox, with no bars: more of the world shows the way the window is longer than the design — above and below on a 4:3 monitor for a 16:9 design, at the sides on a 21:9 one. For a level that scrolls anyway, where seeing further is fine. |
The
framework's .toml says letterbox, and so does every game
rmp new makes from it. A .toml without the line gets none.
[window]
stretch = "expand"rmp::app::stretch()
is the mode in use, starting from the .toml's, and
rmp::app::set_stretch() changes it from anywhere,
at once: the next thing that asks sees the new one. The .toml is the place for a game's
own mode. The framework's examples share one .toml, so the ones that need another set it
in their first scene's _ready():
rmp::app::set_stretch(rmp::app::Stretch::EXPAND);Everything that places the world follows the mode, and nothing in a scene has to ask which one is
on: the camera, with
view(), to_world() and the raylib() camera a game draws with;
rmp::input::pointer() and a click on an object, which go through it; and
the interface, which keeps inside the
game's area. The stretch example is a court in all
three modes, with a key and a button to go round them and a window to resize.
if (rmp::ui::button("Quit")) rmp::app::quit();rmp::app::quit() can be called from anywhere — a
menu, a callback, ten calls deep in your own code — and it returns. It raises a flag that
the app checks before the next frame, so the frame you are in finishes normally, and then the game
shuts down exactly as it does when the window's close button is pressed. A second call does
nothing.
That is the reason not to call std::exit() instead: it ends the process on the spot,
so nothing is shut down, the window is not closed properly, and on Android the app's activity is left
behind while its process disappears. It is not an exception either. Exceptions are switched off in
plenty of game builds, unwinding through raylib's C code is undefined, and throwing in the middle of
a frame would leave a frame and a UI pass half open. A flag costs one check a frame and cannot leave
anything half done.
rmp::app::quit_requested() says whether it
has been called, for code that wants to skip work on the way out.
| Platform | What quit() does |
|---|---|
| Desktops and the web | The frame loop ends after this frame, and the game shuts down. |
| Android | The same, and the app's activity is finished, so that it goes away instead of leaving an empty task in the recent apps. |
| iOS | Nothing. It logs a warning, once, and returns — except in a debug build with [dev] strict = true, where that warning aborts the app instead. |
iOS is not an oversight. Apple's guidance is that an app which ends itself "will appear to the user to have crashed", App Review rejects apps that crash or appear to, and a quit control fails Apple's interface guidelines by itself. So the same code ships everywhere, and on an iPhone the call is inert and says so: APP: quit() does nothing on iOS … Apple rejects apps that terminate themselves (QA1561). Ignoring. If a dead button bothers you, leave it out of the iOS build — which is what the menu of a new game does:
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endifiOS has the rest of what is different there.
Escape does
not close the game. raylib's InitWindow() makes Escape its exit key, which ends the
frame loop when it is pressed, and in a game Escape means "back" or "pause":
rmp::ui goes back on it, and the standard
ui_cancel action is bound to it. So the app turns the exit key off, on every platform,
right after the ready hook — the first scene's _ready() with RMP_GAME, your
on_ready() with RMP_ENTRY_POINT — because that is where the window has
just opened. The window's close button still closes it: that is the window asking, not a key.
Because it happens after the ready hook, a SetExitKey() of your own there is
overwritten. A game that wants a key to quit says so where it reads its keys, and
rmp::app::quit() shuts down the same way the close button does:
if (IsKeyPressed(KEY_ESCAPE)) rmp::app::quit();Every
backend goes through the exit key: raylib 6.2's Win32 backend closes on it and not on Escape by
name, and the framework's copy of raylib is patched where the DRM backend did not — its terminal
keyboard hands a lone Escape to the game instead of to the exit check, a patch listed in
thirdparty/raylib/PATCHES.md.
However the game ends — rmp::app::quit() or the window's close button — the shutdown
is the same, and its order matters, because a texture released after the window is closed is a write
into a graphics context that no longer exists:
_end(),
and its objects are destroyed after it, each getting theirs.Everything that owns something on the graphics card goes while the window is still open, so a
scene or a global that holds an rmp::Texture as a member
releases it safely without anyone writing an unload.
A scene owns its state and loses it when it leaves the stack. That is exactly right for the
enemies of a level and exactly wrong for the player's best score. The second kind has one home,
rmp::global<T>():
#pragma once
// State that has to survive a scene change lives in exactly one place. A scene
// owns its state and loses it on the way out, which is right for the enemies
// and wrong for the score. Every scene reaches this through
// rmp::global<Progress>(), and there is exactly one for the life of the app.
struct Progress {
int best_score = 0;
int runs = 0;
};
++rmp::global<Progress>().runs;
Progress &progress = rmp::global<Progress>();
if (score > progress.best_score) progress.best_score = score;The scene-stack example keeps its best score this way, across a menu, a game and a pause overlay.
There is one instance per type, built the first time it is asked for and destroyed by the
framework on the way out, before the window closes. The type is the key: there is no registration,
no name and no lookup, and the type knows nothing about it — no instance() method, no
private constructor, no macro. Any type with a default constructor works, including a plain struct
written a minute ago.
It is called global because that is what it is, and a softer name would get used for
things that should have been passed as arguments — to a scene's constructor, for instance, which is
how a level number crosses a
transition. Reaching for it should be a decision, not a habit.
A global lives in memory for as long as the app runs; it is not saved anywhere. Keeping the best
score between launches is the job of rmp::save; see
Saving.
A global first asked for while the globals are being destroyed — by a destructor that reaches for one late in the shutdown — is still a working object, but it is never destroyed by the framework, and the log says so once: GLOBAL: a global was created while the globals were being destroyed; it will not be destroyed by the framework.
RMP_GAME is built on a lower-level entry point, RMP_ENTRY_POINT,
which takes three functions of yours instead of a scene and runs them on the same platform runners:
static void on_ready() {
SetConfigFlags(FLAG_WINDOW_RESIZABLE); // before InitWindow, or it is ignored
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
}
static void on_frame(float delta) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(TextFormat("%.1f ms", delta * 1000), 20, 20, 20, DARKGRAY);
EndDrawing();
}
static void on_exit() { CloseWindow(); }
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);There is no scene stack and no objects, and the window and the drawing are yours: the hooks are
on_ and not _ because they are functions you hand over. What the platform
runners do around them is the same as for RMP_GAME — the asset pack opened before
on_ready and closed after on_exit, a release moved next to its
resources/, the exit key turned off after on_ready, the input devices read
once before each on_frame, so that rmp::input's
actions and pointer_screen() work in it as
they do in a scene, the same clamped delta, the same quit(),
the music fed every frame. What RMP_GAME adds is the part that reads
[window]: with RMP_ENTRY_POINT, vsync and the frame cap are yours to set,
like the window.
In a scene,
pointer() is the pointer in world units, converted
through the current scene's camera. With no scene on the stack there is no camera to go through, so
here it is the position on the screen, the same as pointer_screen(), and it says
nothing about it: either one works in a game without scenes.
The UI examples are written this way, because a menu needs no scene. Plain C is one step further
down: Plain C is a game with its own main(),
raylib, and no framework library: what it keeps of the framework is the build, the
.toml's values from rmp/config.h and the C hooks CI boots it with.
https://omardev29.github.io/rmp-docs/manual/core/scenes.html
A scene is one context of the game, with its own state, its own update and its own drawing: a main menu is a scene, a level is a scene, a pause overlay is a scene. The game is a stack of them, and moving between screens is putting one on that stack or taking one off.
Derive from rmp::Scene and override what the scene
needs. Every hook has an empty default, so a scene that only draws overrides only
_draw():
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <rmp/app.h>
class MainMenuScene : public rmp::Scene {
void _draw() override {
rmp::ui::begin();
if (rmp::ui::button("Play")) rmp::Scene::change<GameScene>();
if (rmp::ui::button("Quit")) rmp::app::quit();
rmp::ui::end();
}
};The game starts with one scene, named once in src/main.cpp:
RMP_GAME(MainMenuScene);The underscore is a rule that holds across the whole framework: a method whose name starts
with _ is one the framework calls on your type. You override it; you never call it.
Its other half is on_: a function you hand to the framework, which it calls when
something happens.
These are the methods a scene overrides, and when each one runs.
| Hook | Runs |
|---|---|
_ready() | Once, when the scene enters the stack. The window exists by then, so this is where assets load. |
_update(float delta) | Every frame, unless a scene on top of it freezes it (see below). delta is the seconds since the last frame. |
_draw() | Every frame, in screen space, after the scene's objects and its map have been drawn. |
_suspend() | When another scene is pushed on top of this one. It is still alive and still owns everything it owned. |
_resume() | When the scene on top of it comes off again. |
_end() | Once, when the scene leaves the stack for good. Not on a suspend. |
It is _end and not _exit because exit() is a function of
the C library, and a member with that name in a class you write would hide it.
The four calls that change the stack are static, because navigation is a service and not a
property of one scene: rmp::Scene::change<GameScene>() reads the same from
inside a scene, from a callback, or from anywhere else.
| Call | What it does |
|---|---|
change<T>(args...) | Clears the stack and starts T. Every scene that was on it gets _end(), top down. |
push<T>(args...) | Puts T on top. The scene underneath is suspended, not ended. |
replace<T>(args...) | Swaps the top scene only. Whatever is under it is untouched and stays suspended. |
pop() | Takes the top scene off and resumes the one under it. |
replace is the one that is easy to overlook: it is level 3 becoming level 4
without disturbing the pause menu that put you there.
These calls record what to do and return; the change happens when the frame ends. That is
not an optimisation. Most of these calls come from inside the very scene that is about to go away
— if (rmp::ui::button("Play")) change<GameScene>() sits in the
_draw() of the menu that disappears — and destroying the menu there would pull the
floor out from under the code that is still running in it.
The same scene asked for twice in one frame is pushed once: two end conditions that fire in the same frame do not stack two game-over screens.
Popping the last scene is refused with a warning, because the app would be left with nothing to
draw — a black window on a desktop, and on iOS no way back at all. To leave, call
rmp::app::quit().
The arguments of change, push and replace go to the new
scene's constructor, so data crosses a transition the way it crosses into any object:
class GameScene : public rmp::Scene {
public:
GameScene(int level, Difficulty difficulty) : _level(level), _difficulty(difficulty) {}
private:
int _level;
Difficulty _difficulty;
};and, wherever the game starts a level:
rmp::Scene::change<GameScene>(3, Difficulty::HARD);No dictionary to look things up in, and no globals. To use designated initialisers, give the
struct a name — change<GameScene>(GameScene::Start{ .level = 3 }) — because a
braced list cannot deduce its type through a variadic template. That is C++, not a choice of the
framework's.
When a scene is pushed on top of another, three fields decide what still reaches the one underneath:

| Field | Default | Means |
|---|---|---|
updates_below | false | The scene below keeps running. |
draws_below | true | The scene below stays on screen. |
input_below | false | The scene below still sees input. |
The defaults are a pause menu. Push a scene that touches none of them, and the world underneath freezes, stays visible, and stops hearing the keyboard — which is why a pause scene in this framework sets no policy at all:
class PauseScene : public rmp::Scene {
void _draw() override {
rmp::ui::begin();
if (rmp::ui::button("Resume")) rmp::Scene::pop();
if (rmp::ui::button("Menu")) rmp::Scene::change<MainMenuScene>();
rmp::ui::end();
}
};With its begin()/end() pair turned into an
rmp::ui::overlay(), the same scene dims
or blurs the frozen game behind its menu, and takes every click and the focus while it is up.
camera[window] stretch says, with
that centre in the middle, and world { 0, 0 } is no longer the top-left corner. See
rmp::Camera.mapgravity{ 0, 980 } by default. Each
object says how much of it applies to it, and none does until it asks.backgroundBLANK, the default, means the theme's.
Only the lowest scene that is drawn chooses it: the ones above are drawn over it.A scene owns its objects. spawn<T>()
makes one, puts it in the scene and calls its _ready(); the object is updated and
drawn with the scene, and ends with it. The reference it returns is good for the rest of the
frame:
auto &bullet = spawn({ .position = muzzle });
bullet.velocity = aim * 900;Kept across frames, the reference can dangle, because a destroyed object's memory goes at the end of the frame it was destroyed in. What to keep instead is a handle, which knows when its object is gone.
https://omardev29.github.io/rmp-docs/manual/core/objects.html
An object is anything that lives in a scene: the player, an enemy, a bullet, a coin, a platform. They are all the same kind of thing. There is no tree, no hierarchy and no parent: what makes one object a paddle and another a ball is the data you put in it.
auto &ball = spawn({ .position = { 400, 225 }, .shape = rmp::circle(6) });
ball.velocity = { 320, 120 };
ball.edges = rmp::Edge::BOUNCE;That is a ball that bounces around the screen. Nothing else is needed: the scene moves it by its velocity every frame, bounces it off the edges, draws it, and frees it when the scene ends.
spawn() is a method of the
scene, which owns its objects. It makes the object, applies the
options you pass, puts it in the scene, calls its _ready(), and returns a reference to
it:
auto &bullet = spawn({ .position = muzzle, .size = { 4, 10 } });
bullet.velocity = aim * 900;The options are an rmp::ObjectOptions, and each
of its fields sets the object's field of the same name — except size, which is a shorter
way to write a rectangular shape. When both are given, shape wins:
{ .size = { 12, 12 }, .shape = rmp::circle(6) } is a circle.
| Option | Default | Sets |
|---|---|---|
position | { 0, 0 } | Where its centre is, in world units. |
size | { 0, 0 } | A rectangle of this size, when shape is not given. |
shape | none | What it draws and collides as. |
velocity | { 0, 0 } | World units per second. |
scale | { 1, 1 } | Multiplies the shape, the collider and the sprite. |
rotation | 0 | Degrees, as raylib counts them. |
layer | 0 | Draw order: higher draws on top. |
visible | true | false is not drawn and cannot be clicked, but is still updated and collided. |
edges | Edge::NONE | What happens at the edge of bounds. |
bounds | empty | The area edges applies to; empty means the map's, or the camera's view. |
They are written as designated initialisers, and C++20 requires those in the order the fields are declared, which is the order of this table. GCC and MSVC refuse any other order, and the framework turns Clang's warning about it into an error in the CMake build, in Android's native build and in the generated Xcode project, so an order that compiles on your machine compiles on every target. The order is the one they are naturally written in — where, how big, what it looks like, how it moves. Designated initialisers has the reasons.
The reference spawn() returns stays valid for the whole frame it was returned in,
whatever else happens in that frame, because objects are only ever freed at the end of a frame.
Kept across frames, it can dangle. What to keep instead is a handle.
The options are applied before _ready() runs, and _ready() runs before
spawn() returns. So inside _ready() the object already has its position and
everything else the options set, and anything you write on the returned reference — like the
bullet's velocity above — comes after _ready().
Its first _update() depends on where in the frame it was spawned, because the
scene's objects are updated in one pass, after the pointer and the scene's own
_update() and before collision:
| Spawned from | First _update() |
|---|---|
the scene's _update(), an on_click or an on_drag | this frame: the pass has not started |
an object's _update(), a behavior's | the next frame: the pass is under way |
a _collision() or an on_collision | the next frame: the pass is over |
Wherever it comes from, its _ready() runs at once, inside the spawn()
call.
Inside an object, scene() is the scene it lives
in, and spawning into it is scene().spawn(...). A
Spawner's on_spawn and a
map's object factory are handed the scene; the other
behavior callbacks, such as a Timer's on_timeout, are handed the object, and
reach the scene through its scene().
auto &spark = scene().spawn({ .position = position, .size = { 3, 3 } });
spark.velocity = { 0, -60 };It
is a reference, because a spawned object always has a scene. An object no scene spawned — a member,
a local — has none of its own: asking it is a mistake in the game, said once in the log, and the
answer is Scene::current(), the scene on top of
the stack.
When an object needs code of its own, derive from rmp::Object
and spawn your type with spawn<T>():
class Coin : public rmp::Object {
public:
int value = 1;
void _ready() override {
shape = rmp::circle(8);
shape.color = GOLD;
}
void _collision(rmp::Object &other) override {
if (other.solid) destroy();
}
};
class Level : public rmp::Scene {
void _ready() override {
auto &coin = spawn<Coin>({ .position = { 300, 200 } });
coin.value = 5;
}
};The type only needs a default constructor. There is no constructor to forward and no
using Object::Object; to write, which is the usual toll of this pattern; what your type
needs goes in its fields, set on the reference spawn() returns, or in its
_ready(). A type that is not an object, or that cannot be default-constructed, is refused
with a sentence instead of a page of template errors:
spawn<Goblin>();The compiler refuses it, saying among other things: give it a default constructor
An object cannot be copied: a copy would be a second object that believes it is in the scene.
The fields are public, and reading and writing them directly is the point:
player.flip_x = player.velocity.x < 0; is the API. A getter and a setter in front of
every field would be ceremony between you and the object you touch most often in a day.
| Field | Default | Is |
|---|---|---|
position | { 0, 0 } | The centre of the object, in world units. |
velocity | { 0, 0 } | World units per second. The scene moves the object by it every frame. |
scale | { 1, 1 } | Multiplies the shape, the collider and the sprite. |
rotation | 0 | Degrees, as raylib counts them. It turns a sprite and a filled rectangle as they are drawn; an outlined rectangle is drawn unturned, and collision ignores it. |
mass | 1 | Read only by apply_force and apply_impulse. |
position is the centre, and that is the one place the framework
deliberately disagrees with raylib, which draws from the top-left corner. Rotating about the centre
is what nearly every 2D sprite wants, a shape stays symmetric around its position, and
Vector2Distance(a.position, b.position) means what it looks like. The corner would turn
every rotation and every distance check into a correction by half the size, by hand.
| Field | Default | Is |
|---|---|---|
sprite | empty | A picture. When it has one, the sprite is what is drawn. |
shape | none | A rectangle or a circle, drawn when there is no sprite. |
flip_x, flip_y | false | Mirror the sprite left to right, or top to bottom. |
visible | true | false is not drawn and cannot be clicked, and is still updated and collided. |
layer | 0 | Draw order. A higher layer draws on top, and objects on the same layer draw in the order they were spawned. |
layer is only about drawing. Which objects collide is collision_layer and
collision_mask, a different pair of fields explained in
Collision.
| Field | Default | Is |
|---|---|---|
gravity_scale | 0 | How much of the scene's gravity applies to it. Nothing falls until it asks to. |
edges | Edge::NONE | What it does at the edge of its bounds: clamp, bounce, wrap, be destroyed, or leave. |
bounds | empty | The area edges applies to; empty is the map's bounds, or the camera's view without a map. |
collider | none | What it collides as, when that is not its shape or its picture. |
solid, immovable | false | Whether a contact pushes it apart from what it touches, and whether it is the one that gets pushed. |
collision_layer, collision_mask | 1 | Which layers it is on, and which it collides with. |
Gravity belongs to the scene, gravity,
{ 0, 980 } by default, because its direction and strength are a property of the world.
Each object then says how much of it applies to it, and the default of 0 is not negotiable: a
top-down game cannot have things falling over. A gravity nobody uses until they ask is what lets one
kind of object serve a platformer and a game seen from above.
The last four rows are the subject of Collision, and
edges and bounds are explained there too.
A rmp::Shape is a rectangle or a circle around the
object's centre, and there are two kinds and not five. Rectangle against rectangle, circle against
circle and circle against rectangle are the three cases collision can resolve honestly; a capsule
that was drawn as a capsule and collided as a box would be a lie in the API. To draw anything else,
override _draw() and use raylib.
shape = rmp::rect({ 14, 90 }); // a paddle
shape.color = RED;
shape = rmp::circle(7); // a ball
shape.filled = false; // the outline only
shape.offset = { 0, -4 }; // moved from the object's centre| Field | Default | Is |
|---|---|---|
kind | ShapeKind::NONE | RECTANGLE, CIRCLE, or nothing. rmp::rect() and rmp::circle() set it. |
size | { 0, 0 } | A rectangle's width and height. |
radius | 0 | A circle's radius. |
offset | { 0, 0 } | Where it sits relative to the object's centre. |
color | WHITE | The fill, or the outline when not filled. |
filled | true | false draws the outline only. |
thickness | 1 | A rectangle's outline width when not filled; a circle ignores it. |
A circle stays a circle when its object is scaled unevenly: the larger of the two scales applies to its radius, in the drawing, in the box it occupies and in collision alike, because this layer has no ellipses and the three must agree.
An object with a sprite draws the picture in place of
its shape. A sprite is either a loose texture or an Aseprite sheet, which brings its frames, its tags
and the time of each frame:
sprite.texture = rmp::assets::load_texture("ship.png");
sprite.sheet = rmp::assets::load_sheet("player.aseprite"); // a sheet wins over a texture
sprite.play("walk"); // "walk" is a tag in your file| Field | Default | Is |
|---|---|---|
texture | none | A picture with no animation. |
sheet | none | An .aseprite file; used instead of texture when both are set. |
source | empty | The part of the texture to draw; empty is all of it, or the sheet's current frame. |
origin | { 0.5, 0.5 } | Which point of the picture sits on the position, as a fraction of its size: the centre by default, { 0.5, 1 } for the feet. |
size | { 0, 0 } | The size to draw it at; zero is the picture's own size. |
tint | WHITE | Multiplies the picture's colours; white leaves them as they are. |
speed | 1 | Animation speed: 2 is twice as fast, 0 is frozen, -1 runs backwards. |
play(tag) starts a tag of the sheet, looping
unless you pass false. Calling it again with the tag already playing does not restart it,
so playing "walk" every frame while the player walks is correct. A tag that is not in the
sheet is reported once and changes nothing, rather than showing a blank frame or filling the log
sixty times a second. stop(), finished() and playing() do what
they say, and set_frame() with frame_index() is the way to drive the frames
yourself.
The animation advances while the object is updated, after it moves, and not while it is drawn — so an object in a scene that runs under a pause menu without being drawn still keeps time. Sprites has the whole of it.
An object of your own type overrides the hooks it needs; each has an empty default. As with
scenes, a method whose name starts with _ is one the framework calls on your type: you
override it and never call it.
| Hook | Runs |
|---|---|
_ready() | Once, when spawn() has put the object in its scene and applied the options. The place to load what it draws and to add its behaviors. |
_update(float delta) | Every frame it is alive, after its behaviors' _update and before it is moved by its velocity. |
_draw() | Every frame it is visible, after its sprite or shape and its behaviors have drawn, in world units: it is already inside the scene's camera. |
_collision(Object &other) | Once per frame for each object it touches, on both of them, whether or not either is solid. |
_end() | When it is destroyed: drop the loot, tell somebody. |
Every frame, in the scene's update, each living object goes through the same steps, in the order they were spawned:
_update, in the order they were added;_update(), so your code has the last word on what the frame leaves behind;edges rule is applied;_late_update, for those that correct where it ended up.When every object of the scene has moved, the collision pass resolves and reports the contacts,
and then the camera follows. In the draw that comes later, objects are drawn in
layer order: each one's sprite or shape, then its behaviors' _draw, then its
own _draw().
Writing position in _update() is a teleport, not a move: the collision
pass sweeps the path an object travelled by its velocity, and does not treat a jump you made by hand
as a path across everything in between.
A frame with no time in it moves nothing by velocity. The first frame of a game has a delta of 0,
and a push applied in _ready() is kept for the first frame that can use it rather than
spent on that one.
destroy();destroy() takes effect at once and frees the
memory later. From the moment it is called the object is no longer updated, drawn, collided or
clicked; alive() is false, every handle to it is
empty, and its _end() runs, followed by its behaviors'. Its memory is released at the end
of the frame. Calling it twice is harmless.
The memory waits because most objects are destroyed from inside their own code: a coin in its
_collision(), a bullet when it leaves the screen, an enemy when its health runs out.
Freeing the object there would pull the floor out from under the code that is still running in it,
and under the other object of a collision, which is about to be told about the same contact. So the
other side of a contact always receives a valid object, whose alive() says whether it is
still in the game.
scene.destroy(object) is the same call, from
the scene's side. When a scene leaves the stack, its objects are destroyed after the scene's own
_end(), so a scene that tidies up can still walk what it spawned.
object_count() counts the live ones, and an
object destroyed earlier in the frame is already not counted.
Within a frame, a reference. Between frames, a handle. An
rmp::Handle remembers an object and knows when it is gone:
rmp::Handle<rmp::Object> _player;
void _ready() override {
auto &player = spawn({ .position = { 100, 300 }, .size = { 20, 40 } });
_player = player.handle();
}
void _update(float) override {
if (_player) _player->velocity.x = 200; // only while the player exists
}handle() makes one. It converts to
true while the object is alive, -> and * reach it, and
get() returns it as an
rmp::Ref, empty once it is gone. It becomes empty the moment
destroy() is called, not when the memory goes. -> on an empty one is a
mistake in the game, said once in the log, and reaches a stand-in made for the purpose instead of
crashing: ask first, as the if above does. A default-constructed
handle is empty, and two handles compare equal when they point at the same object.
A handle is a slot number and a generation, so checking one costs an integer comparison — and it cannot come back to life. When the slot is reused for a new object the generation no longer matches, and the old handle stays empty instead of pointing at a stranger, which is the classic bug with stored indices.
handle<Goblin>() makes a typed one, whose -> reaches the
goblin's own fields without a cast. That conversion is not checked: get() is a
static_cast, not a dynamic_cast, because nothing in the framework uses
run-time type information and a handle resolved every frame should not pay for the lookup. Take a
typed handle only from an object that is that type; a type that is not an object at all is refused
when it compiles.
When a subclass is more than you want, an object takes functions instead:
auto &coin = spawn({ .position = { 300, 200 }, .shape = rmp::circle(8) });
coin.on_collision([](rmp::Object &self, rmp::Object &other) {
if (other.solid) {
score += 10;
self.destroy();
}
});
coin.on_click([](rmp::Object &self) { self.scale = { 1.5f, 1.5f }; });| Callback | Is called | With |
|---|---|---|
on_collision | Every frame it touches another object, after the hooks. | Itself and the other object. |
on_click | When the pointer is pressed on it and released on it. | Itself. |
on_drag | Every frame the pointer moves while held, after being pressed on it. | Itself and how far the pointer moved since the last frame, in world units. |
This is the other half of the underscore rule: _name is yours and the framework calls
it, on_name is the framework's and you hand it a function. The two never collide, so an
object can override _collision() and carry an on_collision as well, and both
run. Setting a callback again replaces it; there is no list of them.
A click is a press and a release on the same object, which is what a click means on every
platform, and lets a player change their mind by dragging off before letting go. The mouse and a
finger are the same pointer. Only visible objects that have an on_click or an
on_drag are tested, against what they collide as, in world units through the scene's
camera — so a click lands on what is under it even while the camera shakes. When objects overlap, the
one drawn on top is the one pressed.
The rmp::ui gets first refusal: a press on a button drawn
over the world goes to the button, never to the object under it.
A drag is two lines, because on_drag hands over the movement in world units, the
units of position:
auto &card = spawn({ .position = { 200, 200 }, .size = { 60, 90 } });
card.on_drag([](rmp::Object &self, Vector2 moved) {
self.position.x += moved.x;
self.position.y += moved.y;
});The movement is where the pointer is in the world minus where it was, both taken through the scene's camera — not the pixels divided by the zoom — so the card stays under the finger at any zoom and under a rotated camera too.
What a callback is stored in is an rmp::Callback, and
it is not std::function on purpose. It moves and never copies, so it accepts a lambda
that captures something only movable — a std::unique_ptr, for instance — which
std::function refuses. A function with the wrong arguments is a compile error that says
which signature was expected:
auto &button = spawn({ .size = { 80, 30 } });
button.on_click([](int times) { (void)times; });The compiler refuses it, saying among other things: the callback does not take the arguments this one is called with
The behaviors' on_ fields — a timer's on_timeout, a spawner's
on_spawn — are the same type, which is why a lambda can be written straight into the
braces that configure one.
Most movement is written straight into velocity, which is what the behaviors do. When
a push is the right way to think about it, there are two kinds, and the difference between them is
the whole physics API: call it every frame and it is a force; call it once and it is an
impulse.
if (rmp::input::pressed("thrust")) apply_force({ 0, -600 }); // every frame it is held
apply_impulse({ 0, -450 }); // once: the jump starts| Call | Does | For |
|---|---|---|
apply_force(f) | Adds up with the other forces of the frame and is spent when the object moves: velocity += f / mass × delta. | Thrust, wind, a magnet — anything sustained. |
apply_impulse(i) | Changes the velocity at once: velocity += i / mass. | A jump, a hit, an explosion, a serve. |
Pong serves its ball with an impulse, because only the direction of the push matters to a ball that keeps its own speed.
Both exist because using the wrong one gives exactly the bug you would expect. A force applied
once barely moves anything, since it is multiplied by one frame's delta; an impulse
applied every frame goes twice as fast at 120 frames a second as at 60. A mass of 0 or
less counts as 1.
Gravity goes through the same path as a force — scene.gravity × gravity_scale is added
to the object's acceleration, without dividing by mass, the way gravity works — so an object with
gravity_scale = 1 that you push upwards does what it would do in the world.
https://omardev29.github.io/rmp-docs/manual/core/collision.html
Every frame, after a scene's objects have moved, the scene finds the ones that touch, pushes apart the ones that are solid, and tells both sides of every contact. There is no physics world to set up: an object collides as soon as it has a shape, and everything else is a field.
It is arcade collision on purpose. Rectangles and circles, solid or not, layers and masks, a test
that catches fast objects, and raycasts — and deliberately not rotation, polygons, friction, bounce
coefficients or joints, which are the beginning of a physics engine. A physics engine such as Box2D
is a model of the world: adopting it would make an object's position a mirror of a body
somewhere else, and would make the simple case harder — a Pong ball would go from one line to a body,
a shape, a density, a restitution, a friction and a gravity switched off. A game that genuinely needs
rigid bodies can still link one, step it in _update() and write position
from it; the fields are public, and nothing stands in the way.
An object collides as the first of these it has:
An object with none of the three is a point, and a point collides with nothing — otherwise every invisible logic object would be a trigger. The collider is there for the most common step up of all: a character's picture includes hair, a cape and air, and nobody wants to collide with the air.
sprite.sheet = rmp::assets::load_sheet("player.aseprite"); // drawn as the picture
collider = rmp::rect({ 20, 44 }); // collided as a box
collider.offset = { 0, 4 }; // a little lower than the centreA collider is a rmp::Shape, a rectangle or a circle,
placed around the object's centre and scaled with it. Rotation does not turn it: collision is
axis-aligned, and a rotated rectangle collides as the same rectangle unrotated. A circle collides as
a circle, against circles and against rectangles, which is what sends a ball off the corner of a
paddle at the right angle.
world_collider() is the box the collider
occupies right now, in world units — for drawing it while you debug, or for a query of your own.
world_bounds() is the box of what is drawn,
the sprite or the shape. Inside an object's _draw(), which is already in world units:
DrawRectangleLinesEx(world_collider(), 1, LIME);When two objects touch, both are told, through the hook and the callback:
class Spikes : public rmp::Object {
void _collision(rmp::Object &other) override {
other.velocity.y = -500; // whatever touched them jumps
}
};A touching pair is reported once per frame, on both objects, for as long as they touch. For each
pair, in this order: the first object's _collision()
and its behaviors', then the second's, then the first's
on_collision callback, then the second's. It
happens whether or not either one is solid: solid decides whether they are pushed apart,
not whether you hear about it.
The reports come after the pushing, so the positions your code reads are the resolved ones and not an overlap that is about to be undone.
Because a contact is reported every frame and not only when it starts, something that should
happen once — a coin collected, a hit taken — destroys the object, or remembers that it happened. The
Health behavior's invulnerable window is that
memory for damage.
Each side is told as long as it was alive when its pair came up, even if the other side has
already been destroyed — so a bullet that destroys itself on contact does not stop the enemy's
_collision() and on_collision hearing that it was hit. The other object is
always valid to read in a report; its alive() says whether it is still in the game. An
object destroyed by an earlier pair of the same frame is told nothing more.
Behaviors are the exception. An object's behaviors are walked in the order they were added, and
the walk stops after any behavior once either of the two is no longer alive. So if the bullet was
destroyed before the enemy's turn — by its own _collision(), or by a
Projectile, which destroys it on a hit by
default — only the enemy's first behavior is reached. A
Health that has to count that hit goes on before
any other behavior.
Three fields, three different questions, and keeping them apart is what makes the common case free:
| Field | Asks | Default |
|---|---|---|
collider | What shape? | The shape, or the picture. |
solid | Pushed apart, or only told? | false: only told. |
immovable | Who gets pushed? | false: this one can be. |
Most objects in a 2D game are not walls — bullets, coins, particles, pickups, triggers — so
solid is off by default, and the two that are solid — the ground, and whatever stands on
it — are the two you configure:
auto &ground = spawn({ .position = { 400, 430 }, .size = { 800, 40 } });
ground.solid = true;
ground.immovable = true;
auto &player = spawn({ .position = { 400, 100 }, .size = { 24, 40 } });
player.solid = true;
player.gravity_scale = 1;When two solid objects overlap, they are pushed apart by the shortest move that separates them. Between two rectangles that is along the axis they overlap least on, which is what makes a character land on top of a platform instead of being shoved off its side. If neither is immovable each moves half the way; if one is, the other moves all of it; two immovable objects overlapping are a mistake in the level, and neither is moved.
Whoever is pushed also loses the part of its velocity going into the contact, and nothing else: a box resting on another under gravity is pushed back up every frame, and without this its downward speed would grow every frame too, so that when the one underneath moved away it would drop at whatever all that resting added up to. With it, the box starts falling from rest; a jump off it keeps its jump, because moving away from the contact is not moving into it; and sliding along a wall keeps the slide. The map's solid cells, below, zero the velocity along the axis they stop.
That happens after the reports, so a _collision() or an on_collision
reads the velocity the object hit with — to measure an impact, or to bounce. A bounce that turns the
velocity round points it away from the contact, and loses nothing:
class Puck : public rmp::Object {
void _collision(rmp::Object &other) override {
if (other.solid) velocity.x = -velocity.x; // still the speed it hit with
}
};By default everything collides with everything, so the simple case never mentions a layer. Then,
in about the fourth game anybody writes, come the three things that cannot be said without them: the
player's bullet must not hit the player, the enemies pass through each other but not through the
walls, and a trigger sees the player and nothing else. The alternative is an if at the
top of every _collision().
| Field | Default | Is |
|---|---|---|
collision_layer | 1 | The layers this object is on, one bit each. |
collision_mask | 1 | The layers it collides with. |
Two objects interact when either one's mask includes the other's layer. Name the bits once, in a header of their own:
#pragma once
// ---------------------------------------------------------------------------
// Who is what, in one place.
//
// One bit per kind of thing. Three fields speak these numbers:
// rmp::Object::collision_layer (what I am), rmp::Object::collision_mask (what
// I collide with) and rmp::behavior::Health::hurt_by (what may hurt me). A
// header of its own, because a second scene file would need exactly these.
// ---------------------------------------------------------------------------
namespace layer {
inline constexpr unsigned PLAYER = 1u << 0;
inline constexpr unsigned ENEMY = 1u << 1;
inline constexpr unsigned BULLET = 1u << 2;
inline constexpr unsigned WORLD = 1u << 3;
inline constexpr unsigned TRIGGER = 1u << 4; // the door: it sees the player, nothing else
} // namespace layer
That file is from the top-down game, where each of the three cases above is a pair of fields. Then say what each kind of object is and what it meets:
auto &bullet = spawn({ .size = { 4, 4 } });
bullet.collision_layer = layer::BULLET;
bullet.collision_mask = layer::ENEMY | layer::WORLD; // not the player who fired it
auto &enemy = spawn({ .size = { 24, 24 } });
enemy.collision_layer = layer::ENEMY;
enemy.collision_mask = layer::WORLD; // not the other enemies
auto &floor = spawn({ .size = { 720, 370 }, .layer = -10 });
floor.collision_layer = 0; // scenery: in nothing's way
floor.collision_mask = 0;The bullet still hits the enemy although the enemy's mask leaves bullets out, because the bullet's mask includes enemies: one side is enough, and then both are told. An object on no layer with an empty mask is out of collision entirely.
These collision layers have nothing to do with the plain layer field, which is draw
order.
Health::hurt_by speaks the same bits,
naming the layers whose touch costs a hit point.
What an object does when it reaches the edge of its world is one field,
edges, because it is five answers to one question:
rmp::Edge | At the edge | For |
|---|---|---|
NONE | Nothing: objects may leave, and do. The default. | Almost everything. |
CLAMP | Stops at it. | A paddle, a player, a cursor. |
BOUNCE | Is put back inside and its velocity turned around. | A Pong or Breakout ball. |
WRAP | Comes back on the other side. | Asteroids. |
DESTROY | Is destroyed once it has left. | Bullets and particles. |
The edge is that of the object's bounds. Left
empty, it is the scene's map when the scene has one, and otherwise the camera's view — the view and
not the window, because once the camera has moved away from the start, the window's rectangle is
somewhere nothing on screen is. That is the difference between a paddle in a one-screen game, which
wants the screen, and a player in a level, which wants the level, and neither has to say so. Any
rectangle can be given instead; Pong gives its ball bounds
wider than the court, so that the ball
bounces off the top and bottom and leaves by the sides to score.
The rules work on the box of what is drawn, world_bounds(), and they run each frame
after the object has moved:
CLAMP and BOUNCE act as soon as the box crosses an edge.
BOUNCE turns the velocity around only when it points out of the world, so an object that
starts overlapping an edge leaves instead of shaking against it.WRAP waits until the box is entirely outside, so an asteroid slides off instead of
popping, and it comes back just outside the far edge, so it slides back in the way it went out.DESTROY waits until the box is entirely outside — so a bullet fired from a muzzle on
the edge of the screen is not destroyed at birth — and only destroys an object that has been inside
at some point, so obstacles spawned ahead of the camera, outside the view, are not destroyed on their
first frame.A scene with a map collides against it;
Tilemaps is about loading and drawing one. Which cells are
solid is decided in the level editor: in LDtk, the cells of an IntGrid painted with the value whose
identifier is solid, or tiles tagged solid through the tileset's enum; in
Tiled, every tile of a layer whose class is solid, or a tile its tileset marks
solid.
An object that is solid and not immovable is stopped by those cells as it
moves — not pushed out of them afterwards. The difference is the classic one: pushing a box out of
each overlapping tile the shortest way makes a player running along a floor catch on the seam
between two tiles, where the shortest way out of the next one is sideways. So the move is made one
axis at a time, across and then down, and running only ever meets walls and falling only ever meets
floors.
Objects that are not solid, and immovable ones, pass through the map; they are moved by your code,
not by the world. The cells are not objects, so they never appear in _collision(): ask
the map instead, with map.solid_at(point) or
map.solid_in(rectangle). A rectangle only touching
a solid cell is not in it: a box standing on the floor is not in the floor.
A bullet moving 900 units a second moves 15 units in a frame at 60 frames a second. Against a wall 10 units thick there is no frame on which the two overlap, and a test of where things are would let it through. So an object that moved more than half its own smaller side in one step is tested against the path it travelled, not only where it ended.
When both objects of such a contact are solid, the fast one is put back at the point of contact before they are pushed apart. When either is not, nothing is moved, and both are still told: a trigger learns that something went through it, and it goes through.
Only travel counts as a path. A position written by your code is a teleport, and is
not swept across everything between where the object was and where you put it. Two objects that
already overlapped when the step began are left to the ordinary test, which separates them on the
frame they really overlap. The other half of the answer to tunnelling is
[app] max_delta, which stops a stalled frame
from turning into one enormous step.
A ray asks what is along a line: what a shot hits, whether there is ground under the feet, whether an enemy can see the player.
if (rmp::RayHit hit = raycast(muzzle, muzzle + aim * 400)) {
auto &spark = spawn({ .position = hit.point, .size = { 3, 3 } });
spark.velocity = hit.normal * 120;
}raycast() tests the segment from one point to the
other against the scene's objects and returns the nearest hit, an
rmp::RayHit, which is true when something was
hit:
| Field | Is |
|---|---|
object | What was hit, as a handle, so it is safe to keep. |
point | Where, in world units. |
normal | The surface's direction there, pointing back at the ray: what orients a spark, a bullet hole or a bounce. |
distance | From the start of the ray. |
A ray that starts inside a rectangle hits it at distance 0, with the normal pointing back along the ray, wherever the ray ends. One that starts inside a circle hits it where it leaves, with the normal pointing outwards there — and misses it altogether when it ends inside the circle too. Two hits at the same distance come back in the order the objects were spawned, so the answer does not change from one run to the next.
The longer form takes an rmp::RayQuery, and the field
that matters most is ignore, because without it the first thing every shot hits is the
thing that fired it. It is a handle, so an object shooting names itself with
handle():
rmp::RayHit hit = scene().raycast({ .from = position, .to = target,
.mask = layer::ENEMY, .ignore = handle() });| Field | Default | Is |
|---|---|---|
from, to | { 0, 0 } | The segment, in world units; nothing beyond to is hit. |
mask | every layer | Only objects on one of these layers are hit. |
ignore | an empty handle | One object to pass through: normally whoever is shooting. An empty handle, or the handle of an object that is gone, passes through nothing. |
solid_only | false | Only solid objects are hit. |
solid_only exists for the ground check. A character asking what is under its feet
wants the floor and not the coin lying on it, and a mask cannot say that: layers are about who
collides with whom, and solid is about whether the contact holds. Filtering the nearest hit afterwards
would not do either, because the coin would hide the floor behind it; with solid_only the
coin is skipped and the floor is found.
The ray's mask is tested against the objects' layers only — a ray has no layer of its
own for an object's mask to match.
raycast_all() writes every hit along the
ray into an array of yours, nearest first, as many as it holds, and returns how many it wrote — for
a shot that pierces, or a line of sight that has to know everything in the way:
std::array<rmp::RayHit, 8> hits;
const int count = raycast_all({ .from = muzzle, .to = target }, hits);
for (int i = 0; i < count; ++i) {
if (auto object = hits[i].object.get()) object->destroy();
}It takes a std::span, so a std::array, a std::vector or a
plain array goes in as it is, and the span carries its length: there is no count to pass beside it
and get wrong.
Rays hit objects and not the map's cells; for those, ask the map with
solid_at(). From inside an object, the scene is scene():
scene().raycast(from, to).
Rays are nearly free, because they reuse the grid the collision pass already builds: only the
objects in the cells the line crosses are tested, so a ray across a thousand objects touches a
handful. The price of sharing is when that grid is rebuilt — whenever the framework moves the world:
a spawn, a destroy, the start of each scene's update and of its collision pass. A ray cast right
after your code wrote another object's position by hand sees that object where it was at
the start of the pass, the way a physics engine with a stepped world does. The ray's own start is
whatever you pass, so a character asking about the ground under itself is never the stale half.
Objects collide with the other objects of their own scene, and with its map. A pause menu pushed on top has objects of its own, which never meet the frozen world underneath.
https://omardev29.github.io/rmp-docs/manual/core/behaviors.html
A behavior is a piece of how an object acts — moving like a platformer character, bouncing like a Pong ball, disappearing after two seconds — that you add to an object instead of writing it again. Add one and the object moves like that game; change its fields and it moves differently, while the game runs.
auto &player = spawn({ .position = { 200, 225 }, .size = { 26, 26 } });
player.add<rmp::behavior::TopDown>({ .speed = 240 });A behavior is any struct with a function void _update(rmp::Object &self, float delta).
It inherits from nothing, has no virtual functions and is registered nowhere:
struct Spin {
float degrees_per_second = 90;
void _update(rmp::Object &self, float delta) {
self.rotation += degrees_per_second * delta;
}
};and it is added to an object with its fields written in braces:
auto &coin = spawn({ .position = { 300, 200 }, .shape = rmp::circle(8) });
coin.add<Spin>({ .degrees_per_second = 180 });That is the whole model, and leaving out a base class is not a matter of taste. A struct with
virtual functions is not an aggregate in C++20, and then { .speed = 320 } no longer
compiles against it. The usual way round — a nested options struct and a constructor that takes it —
turns every later read into get<TopDown>()->options.speed. Without one, the
fields are the configuration.
And the behaviors in rmp::behavior are structs exactly
like that one. There is no extension API to learn, because there is nothing to extend: one of yours
and one of the framework's are the same kind of thing, added, read and removed the same way.
| Call | Does |
|---|---|
add<B>({ ... }) | Attaches a B made from the braces, runs its _ready if it has one, and returns a reference to it. |
get<B>() | The object's B, as an rmp::Ref: empty when it has none. |
has<B>() | Whether it has one. |
remove<B>() | Takes it off, running its _end if it has one. |
enable<B>(on) | Pauses it with false and resumes it with true, keeping its fields and its ours. |
enabled<B>() | Whether it has one and it is not paused. |
The fields stay live after the behavior is added. A power-up is one line:
auto &player = spawn({ .size = { 26, 26 } });
player.add<rmp::behavior::TopDown>({ .speed = 240 });
if (auto walk = player.get<rmp::behavior::TopDown>()) walk->speed = 400;get() answers with an optional reference, and the if is how you ask it:
true when the object has a TopDown, and then -> reaches it. Reaching
into an empty one without asking is a mistake in the game: it is said once in the log, and the
line writes to a stand-in instead of crashing. The reference add() returns and the one
get() returns stay valid for as long as the behavior is attached: a behavior lives in
memory of its own and never moves.
An object carries at most one behavior of each type. Adding a type it already has replaces the old
one — its _end runs, then the new one's _ready — because two of the same is
never what anybody means, and get() could only ever return one of them.
Behaviors run in the order they were added. One added from inside an _update gets its
_ready at once and its first _update on the next frame. One removed from
inside an _update — its own included, which is what a one-shot effect does — is taken off
without costing any other behavior its turn in that frame.
A paused behavior gets no hooks — no _update, _late_update,
_draw or _collision — until it is enabled again; it still gets its
_end when it is removed or the object dies. It is how one behavior takes over from
another for a while without either losing where it was: a Chase pauses the
Patrol it interrupts, and a StateMachine's states say which behaviors run
while each is on. Pausing a behavior the object has not got does nothing, and adding one again
replaces it with an enabled one.
auto &guard = spawn({ .size = { 16, 16 } });
guard.add<rmp::behavior::Patrol>();
guard.enable<rmp::behavior::Patrol>(false); // stands still, and remembers where it was going
if (!guard.enabled<rmp::behavior::Patrol>()) guard.enable<rmp::behavior::Patrol>();When the object is destroyed, its own _end() runs first and then each behavior's
_end, while everything the object owns is still there.
The framework finds a behavior's hooks when it is compiled, from their names and arguments, so a hook a behavior does not declare costs nothing at all.
| Hook | Runs |
|---|---|
_update(Object &self, float delta) | Every frame, before the object's own _update() and before it moves, so it can set the velocity the move will use. |
_late_update(Object &self, float delta) | Every frame, after the object has moved, been held to its edges and had its animation advanced. |
_ready(Object &self) | Once, when it is added. |
_draw(Object &self) | Every frame the object is drawn, after its sprite or shape and before its own _draw(), in world units. |
_collision(Object &self, Object &other) | Once per frame for each object the object touches, right after the object's own _collision(). The walk stops after any behavior once either of the two is no longer alive: the behaviors after one that destroyed either object hear nothing, and if one was destroyed before the walk began, only the first behavior hears it. See Collision. |
_end(Object &self) | When it is removed, replaced, or the object is destroyed. |
A behavior needs _update or _late_update; every other hook is optional.
_late_update exists because behaviors run before the move, which is what lets them write
the velocity — so a behavior whose job is to correct where the object ended up needs a place
after it. GridSnap is that: rounding the
position the object had before it moved would round the wrong number.
A struct with neither, or one with virtual functions, is refused with a sentence that says why:
auto &coin = spawn({ .size = { 8, 8 } });
coin.add<Score>({ .points = 10 });The compiler refuses it, saying among other things: a behavior needs
A behavior that has to remember something between frames — the time since a jump was pressed,
whether it is standing on the ground — keeps it in one public member called ours:
struct Blink {
float every = 0.5f; // seconds between switches
void _update(rmp::Object &self, float delta) {
ours.elapsed += delta;
if (ours.elapsed >= every) {
ours.elapsed -= every;
self.visible = !self.visible;
}
}
void _end(rmp::Object &self) { self.visible = true; }
struct {
float elapsed = 0;
} ours;
};It is public and not private because a struct with a private member is not an aggregate, and then
{ .every = 0.2f } stops compiling — which is the whole design. The name is the fence: you
can read what is in ours, and it is not yours to write. The catalogue follows the same
rule, and where a value in it is worth reading it has a function that says so —
Platformer::grounded() reads
ours for you. rmp::Sprite
keeps its animation state the same way.
A behavior contributes how something moves, not what the game intends. Which way the Pong ball is
served is a rule of the game, so a Ball starts still; a Projectile travels
the way you pushed it; a Follow chases the handle you give it; and the character
behaviors read the input actions you name, or the standard ones when you name none —
the actions example shows how one is defined.
The catalogue is the pieces a game would otherwise write again: moving like a character
(TopDown, Platformer, Runner), moving on its own
(Ball, Projectile, Follow, Tween,
Patrol, Orbit, Pathfind, Chase), the places and
things a level is made of (Area, Hitbox, Collectible,
Shooter, Spawner, Timer, Lifespan,
Health), and the rest (GridSnap, Parallax,
Animator, Draggable, StateMachine). A Tetris piece, a
formation of invaders and a paddle are not in it: each of those is a game with another name on
it.
Each one has a page in the reference with every field and its default. All of them come with
rmp/behavior.h.
auto &hero = spawn({ .size = { 16, 16 } });
hero.add<rmp::behavior::TopDown>({ .speed = 180, .eight_way = false });TopDown walks in eight directions, seen from
above, at speed units per second, reading the standard move_left,
move_right, move_up and move_down actions unless you name others.
Going diagonally is not faster, because the input it reads is
normalised. With
eight_way = false it walks in four, and the direction pushed harder wins.
acceleration, 0 by default, is instant; a value is how fast it reaches its speed, in units
per second squared. direction() is the last way it moved, for aiming a weapon where the
character looks.
It also picks the animation. With a sheet on the object's sprite, moving plays
walk_<direction> when the sheet has such a tag and walk mirrored with
flip_x when it does not, and standing still plays idle. So a sheet drawn in
two, four or eight directions works with nothing configured. The names are yours — they are the tags
in your file — and idle, walk and the direction suffixes are fields you can
change. Without a sheet it only sets flip_x.
The mirroring assumes one thing about your art: what has no direction of its own faces
right. flip_x is set while the object faces left, so a plain walk,
idle and a sprite with no sheet must be drawn facing east to come out facing west. A tag
with a direction suffix is drawn for that direction, so it plays unflipped: walk_w is
your west-facing art, shown as you drew it.
auto &hero = spawn({ .size = { 14, 22 } });
hero.add<rmp::behavior::Platformer>({ .speed = 200, .jump = 650, .air_jumps = 1 });Platformer runs left and right, falls, and
jumps, reading move_left, move_right and ui_accept unless you name
others. jump is the upward speed a jump starts with, gravity its own pull while
in the air, and air_jumps = 1 is a double jump. It makes the object solid when it is added,
and applies its own gravity instead of the scene's, so a jump reaches the same height whatever the
scene's gravity is.
That is why adding it sets the object's
gravity_scale to 0. A heavier character is
its own field, get<rmp::behavior::Platformer>()->gravity = 3000; setting
gravity_scale again afterwards does not replace the behavior's gravity but adds the
scene's on top of it, and the character falls with both.
Two fields separate a platformer that feels right from one that does not, and players never name
either — they only notice when they are missing. coyote_time keeps a jump available for a
moment after walking off a ledge, and jump_buffer remembers a jump pressed just before
landing and fires it on landing. grounded() says whether it was standing on something at
its last update: a solid object, or a solid cell of the map, just under its feet, while not moving
up.
auto &runner = spawn({ .size = { 20, 36 } });
runner.add<rmp::behavior::Runner>({ .speed = 300, .accelerate = 8, .duck_action = "duck" });Runner runs forward on its own, faster and
faster: speed grows by accelerate every second up to max_speed,
and it jumps on ui_accept unless you name another action. distance() is how far
it has run — in an endless runner that is both the score and the clock the difficulty hangs off.
ducking() says whether duck_action is held, and that is all ducking does here:
a smaller collider or another animation is the game's to set.
The endless runner is one, with a
Spawner measuring by its distance.
auto &ball = spawn({ .position = { 400, 225 }, .shape = rmp::circle(7) });
ball.add<rmp::behavior::Ball>({ .speed = 340 });
ball.apply_impulse({ 1, 0.35f }); // the serve, and it is the game'sBall bounces off the edges of its bounds and off
whatever it collides with, and keeps its pace: every frame its velocity is set back to
speed in whatever direction it is going. That one rule is what makes the serve a single
push — only its direction survives — and what makes velocity = {} a stable stop between
points. Where it hits a paddle tilts the bounce, up to max_bounce_deg at the very end,
which is half of why Pong feels like Pong. speed_up multiplies the speed on every bounce
off something solid, and it compounds:
Breakout's
is 1.01, which makes the ball about twice its serve by the last of its fifty bricks; 1.03 makes it
four times its serve by the thirtieth, faster than the paddle can follow. It sets the
object to bounce at its edges and to be not solid itself, so it
never pushes a paddle out of the way. Pong and
Breakout are both a Ball.
auto &shot = spawn({ .position = muzzle, .size = { 4, 4 } });
shot.velocity = aim;
shot.add<rmp::behavior::Projectile>({ .speed = 600 });Projectile travels the way it was pushed,
at speed — or at whatever velocity it was given, when speed is 0 — and is
destroyed when it leaves its bounds and, with destroy_on_hit, when it touches anything it
collides with. Which things those are is its layers' business. With destroy_on_wall it
is destroyed too when its centre is in a solid cell of the map, which an object that is not
solid otherwise passes through.
auto &bat = spawn({ .size = { 12, 8 } });
bat.add<rmp::behavior::Follow>({ .target = player_handle, .speed = 90, .stop_distance = 20 });Follow chases a target at
speed, and stops within stop_distance of it. The target is a handle and not a
pointer because the thing being chased is exactly the thing most likely to die while being chased:
when it is gone, the follower keeps its velocity, the way a homing missile whose target explodes keeps
flying.
auto &lift = spawn({ .position = { 200, 300 }, .size = { 64, 12 } });
lift.add<rmp::behavior::Tween>({
.property = rmp::behavior::Property::POSITION_X,
.from = 200,
.to = 500,
.seconds = 3,
.ping_pong = true,
});Tween moves one property of its object from
from to to over seconds, along an
Ease: LINEAR, or IN,
OUT and IN_OUT, the default, which start slow, end slow, or both. The
Property is the x or y of the position, the x or
y of the scale, the rotation in degrees, or the alpha of the shape's colour and the sprite's tint, from
0 to 255. loop starts again from from, ping_pong turns back at each
end forever, and with neither it stops exactly on to — not a hair short of it, which on a
platform is a gap — and finished() turns true. restart() runs it again.
A Tween writes its property every frame it runs, and an object carries one behavior of each type, so one object animates one property with it.
auto &piece = spawn({ .size = { 24, 24 } });
piece.add<rmp::behavior::GridSnap>({ .cell = { 24, 24 } });GridSnap rounds the object's position to the
nearest point of a grid of cell spacing, starting at offset, after everything
else has moved it — so a puzzle piece never rests on half a pixel. A cell of 0 on one axis leaves that
axis alone.
auto &sky = spawn({ .layer = -10 });
sky.add<rmp::behavior::Parallax>({ .texture = "sky.png", .factor = 0.2f });Parallax draws a background strip that
repeats sideways with no seam and scrolls at its own rate as the camera moves. It loads the
texture by name from resources/. factor 0 is pinned to the
screen, like a far sky; 1 stands still in the world, like the ground; in between, the smaller the
farther away it looks. speed adds a drift of its own, for clouds; y is where
the top of the strip sits; tint colours it. The object it is on needs no shape of its
own, and its layer puts the strip behind or in front of the rest.
auto &source = spawn({ .position = { 900, 380 } });
source.add<rmp::behavior::Spawner>({
.every_seconds = 1.5f,
.jitter = 0.4f,
.max_alive = 5,
.on_spawn = [](rmp::Scene &scene, Vector2 at) {
auto &rock = scene.spawn({ .position = at, .size = { 30, 30 }, .velocity = { -200, 0 } });
rock.add<rmp::behavior::Lifespan>({ .seconds = 6 });
},
});Spawner calls on_spawn every
every_seconds, or every every_distance units travelled, handing it the scene
and the position the distance is measured at. Distance is not the same as time, and the difference is why this is not a
timer: in an endless runner the speed climbs, so "every two seconds" spaces the obstacles further and
further apart and the game gets easier the faster it goes. The distance is measured on the object
track names, or on the spawner itself.
jitter moves each interval after the first by a random amount up to that much either
way, drawn from rmp::random. Intervals are counted from when
the last one was due, not from the frame it fired on, so they do not drift.
max_alive caps how many of the objects it made are alive at once — everything
on_spawn spawns counts — and alive() says how many that is now. It is a cap
and not a quota: when one dies, another can be made. One spawner keeps track of at most
rmp::behavior::MAX_SPAWNED objects, and a
larger max_alive is reported once and held to that.
auto &cannon = spawn({ .position = { 100, 100 }, .size = { 20, 20 } });
cannon.add<rmp::behavior::Timer>({
.seconds = 0.8f,
.on_timeout = [](rmp::Object &self) { self.rotation += 45; },
});Timer calls on_timeout every
seconds, with the object it is on; with repeat = false it calls once and is
spent. A frame longer than the interval calls it once for each interval the frame covered, so a
countdown keeps time on a slow machine — up to a thousand calls in one frame, past which it drops
the rest and says so once.
auto &spark = spawn({ .size = { 3, 3 } });
spark.add<rmp::behavior::Lifespan>({ .seconds = 0.5f });Lifespan destroys its object after
seconds: particles, bullets, a message that fades.
auto &hero = spawn({ .size = { 26, 26 } });
hero.add<rmp::behavior::Health>({
.hp = 5,
.invulnerable_for = 0.8f,
.destroy_on_death = false,
.on_death = [](rmp::Object &) { TraceLog(LOG_INFO, "game over"); },
.hurt_by = layer::ENEMY,
});Health is hit points, a window of
invulnerability after each hit, and death. damage() takes points off and returns whether
it landed — during the window it does not, which is what stops one spike costing three hearts in three
frames — and the object blinks blink_hz times a second while the window is open.
on_damage is told how much landed; on_death is called once when the points run
out, even if two lethal hits land in the same frame, and then the object is destroyed unless
destroy_on_death is off. heal() adds points up to max_hp, which is
the starting hp unless set, and does nothing after death.
Nothing hurts by default: hurt_by names the
collision layers whose touch costs
damage_on_hit points, so contact damage is one field instead of an if at the
top of every _collision(). A Health with nothing in hurt_by is a
counter that only damage() reduces. An object that carries a Hitbox
is never counted by hurt_by: the Hitbox decides, so one touch never costs twice. The top-down
game gives its player a TopDown and a Health hurt by the enemies.
auto &door = spawn({ .position = { 400, 200 }, .size = { 32, 48 } });
door.collision_layer = 0;
door.collision_mask = layer::PLAYER;
door.add<rmp::behavior::Area>({
.on_enter = [](rmp::Object &, rmp::Object &who) { TraceLog(LOG_INFO, "welcome"); (void)who; },
.on_exit = [](rmp::Object &, rmp::Object &) { TraceLog(LOG_INFO, "goodbye"); },
});Area is a region that says who comes and
goes: a trigger, a door's sensor, a pit, a shop counter. It sees exactly what its object collides
with — its collider and its layers — and
whether the object is solid is the object's business (a trigger is not, the default).
Each moment is told with the area and the other object:
| Callback | When |
|---|---|
on_enter | The first frame the other touches it. |
on_stay | Every frame after that it still does. |
on_exit | The frame after the first one it no longer does. |
on_inside | Its collider is wholly inside the area's, from a frame it was not. |
on_outside | It is no longer wholly inside: part of it is out, or it left. A jump from wholly inside to gone is on_outside and then on_exit. |
overlapping() is who touched it in the last collision pass, as
handles, and contains(other) asks about one object. An
object destroyed while it touches the area leaves overlapping() and is told nothing:
it is gone, and there is no object to hand over.
auto &spikes = spawn({ .position = { 300, 300 }, .size = { 32, 8 } });
spikes.collision_layer = layer::TRAP;
spikes.add<rmp::behavior::Hitbox>({ .damage = 1, .hits = layer::PLAYER, .knockback = 250 });Hitbox is what hurts: a sword's swing, a
spike, a bullet, an explosion. On touching an object with a Health on one of the layers
it hits, it calls that Health's damage() — the invulnerable window,
on_damage and the one death all apply — and pushes it away by knockback
(an impulse, away from the hitbox). destroy_on_hit discards it after its first hit,
landed or not, which is a bullet; once_per_target hits each object once at most, which
is one swing of a sword; on_hit is told the hitbox and who it hurt, when the damage
landed.
A Hitbox decides for itself, so a Health's hurt_by does not count an object that has
one: one touch never costs twice. hurt_by is the quick way for plain contact damage; a
Hitbox is the way when the damage, the push or the rule belongs to what hurts.
auto &coin = spawn({ .position = { 200, 200 }, .shape = rmp::circle(5) });
coin.add<rmp::behavior::Collectible>({
.collected_by = layer::PLAYER,
.sound = "coin",
.magnet = 40,
.on_collect = [](rmp::Object &, rmp::Object &) { ++coins; },
});Collectible is a coin, a key, a heart.
Touched by an object on a layer of collected_by, it calls on_collect once,
plays sound through rmp::audio,
stops colliding, and vanishes — it rises, grows and fades for vanish_seconds — before it
is destroyed. Within magnet units of a collector it flies to it at
magnet_speed first. What a pickup is worth is the game's: on_collect is
where it counts, and there is no counter of the framework's to keep in step with yours.
collected() says whether it has been picked up.
auto &turret = spawn({ .position = { 400, 120 }, .size = { 16, 16 } });
turret.add<rmp::behavior::Shooter>({
.automatic = true,
.every = 1.2f,
.target = player_handle,
.range = 220,
.speed = 180,
.count = 3,
.spread = 30,
});Shooter fires: while its
action is held, on its own every every seconds with
automatic, or at a target — and with a target, only within
range. Without one it aims along direction, or the way the object faces
when that is {0, 0}. A volley is count bullets spread over spread degrees
(360 is all around, evenly), and rotate_per_shot turns the whole pattern after each
volley, which is how a spiral is made. fire() fires now if every has passed,
and shots() counts the volleys.
The bullet is a circle of bullet_radius in bullet_color with a
Hitbox of damage, a Projectile that ends at a wall or a hit,
and a Lifespan of bullet_life; it hits the layers of hits, or
the shooter's own mask less its own layer. Or it is whatever on_shoot makes, handed the
scene, where it leaves from and its velocity:
auto &archer = spawn({ .size = { 16, 16 } });
archer.add<rmp::behavior::Shooter>({
.action = "fire",
.on_shoot = [](rmp::Scene &s, Vector2 at, Vector2 velocity) {
auto &arrow = s.spawn({ .position = at, .size = { 10, 2 }, .velocity = velocity });
arrow.add<rmp::behavior::Lifespan>({ .seconds = 1.5f });
},
});for (int i = 0; i < 3; ++i) {
auto &blade = spawn({ .size = { 6, 6 } });
blade.add<rmp::behavior::Orbit>({ .centre = player_handle, .radius = 40,
.degrees_per_second = 180,
.face = rmp::behavior::Face::OUTWARD,
.index = i, .of = 3 });
}Orbit circles a centre handle,
or a point without one, at radius, turning
degrees_per_second (negative the other way) from angle, where it is now.
Several on one centre spread evenly with index and of, and
face turns each to look at the centre or away from it. It runs after everything has
moved, so the centre's movement this frame is already in.
auto &hero = spawn({ .size = { 16, 16 } });
hero.sprite.sheet = rmp::assets::load_sheet("hero.aseprite");
hero.add<rmp::behavior::Animator>({ .run = "walk" });
hero.get<rmp::behavior::Animator>()->rules.push_back(
{ .tag = "dash", .when = [](rmp::Object &) { return dashing; } });Animator plays the tag that fits what the
object is doing: die once its Health is dead (once, not looped),
hurt while it is invulnerable after a hit, jump and fall in the
air (with gravity), run while it moves faster than moving_at and
idle while it does not — and with flip it sets flip_x while it
moves left, so the art faces right. The names are fields: the tags of your .aseprite. A tag the sheet
lacks is skipped for the next that fits, and without a sheet only flip_x is set. Its
rules are asked first, in order: an
AnimationRule is a tag and a
when. playing() is the tag it chose last.
auto &slot = spawn({ .position = { 500, 300 }, .size = { 40, 40 } });
slot.add<rmp::behavior::Area>();
auto &gem = spawn({ .position = { 200, 300 }, .shape = rmp::circle(8) });
gem.add<rmp::behavior::Draggable>({
.on_drop = [](rmp::Object &, rmp::Object &) { TraceLog(LOG_INFO, "socketed"); },
});Draggable is picked up with the pointer
and put down somewhere: an inventory, a puzzle piece, a card. It takes the object's
on_drag. Let go over an object with an Area — on a layer of
drop_on, and accepts saying yes — it is dropped there:
on_drop, and put on its centre with centre_on_drop. Anywhere else,
on_reject, and back where it was picked up with return_if_rejected — or
it stays, snapped to snap, and with throwable keeps the pointer's speed
and slides to a stop at friction. bounds keeps it inside a rectangle,
on_pick is told the first time it moves, held() says whether the pointer has
it, and drop() lets go of it as the pointer would.
accepts is an rmp::Condition: a callback
that answers, and an empty one answers no.
auto &guard = spawn({ .position = { 100, 100 }, .size = { 16, 16 } });
guard.add<rmp::behavior::Patrol>({
.waypoints = { { 100, 100 }, { 300, 100 }, { 300, 220 } },
.speed = 60,
.wait = 0.5f,
.ping_pong = true,
});Patrol goes from waypoint to waypoint — round
in a loop, or back and forth with ping_pong — waiting wait seconds at each;
heading_for() is the one it is going to. Waypoints are for what flies or walks
top-down: it moves straight to each, on both axes. With no waypoints it walks the floor instead,
left and right at speed, turning at a wall, at anything that stops it, and, with
turn_at_ledges, before a drop — a platformer's goomba, with gravity the object's own.
The way it goes sets flip_x, and its sheet plays walk and
idle when it has them, unless the object has an Animator, which then
chooses.
auto &rat = spawn({ .size = { 10, 10 } });
rat.add<rmp::behavior::Pathfind>({ .target = player_handle, .speed = 90, .clearance = 5 });Pathfind walks to a target,
or to a goal point without one, around the map's walls: it asks
rmp::find_path() again every repath_every seconds while it walks and
follows the way at speed, on both axes. With neither it leaves the velocity to whoever
else moves the object. path() is the cells still ahead, the last one the goal;
arrived() says it is there, or that there is no way. A Chase on the same
object steers it.
rmp::find_path(map, from, to) is the search itself,
for a game that wants the way without walking it: A* over the map's cells, around its solid ones,
eight directions — or four, with .diagonal = false — and a diagonal step never cuts a
solid cell's corner. .clearance keeps that far from every wall: half the walker's
width. The answer is the centres of the cells to walk through, ending on to itself and
without from; it is empty when there is no way, when either end is outside the map or
in a wall, and for a map with no cells.
const auto way = rmp::find_path(map, { 40, 40 }, { 400, 300 }, { .diagonal = false });
if (way.empty()) TraceLog(LOG_INFO, "walled in");auto &hound = spawn({ .position = { 300, 200 }, .size = { 14, 14 } });
hound.add<rmp::behavior::Patrol>({ .waypoints = { { 300, 200 }, { 420, 200 } } });
hound.add<rmp::behavior::Pathfind>();
hound.add<rmp::behavior::Chase>({
.target = player_handle,
.speed = 110,
.sight = 160,
.fov = 120,
.on_spot = [](rmp::Object &, rmp::Object &) { TraceLog(LOG_INFO, "there you are"); },
});Chase sees a target and goes after it. It
sees it within sight units (0 is any distance), inside a cone of fov
degrees around the way it faces, and — with line_of_sight — when no solid map cell
stands between them. While it chases, a Patrol on the same object is paused (with
enable<Patrol>(false)) and a Pathfind, when
there is one, finds the way; without one it runs straight at the target, stopping within
stop_distance. After lose_after seconds without seeing it, it gives up:
on_lose, back to where it started with return_home, and the patrol resumes.
chasing() and sees() say where it is.
auto &boss = spawn({ .size = { 32, 32 } });
boss.add<rmp::behavior::Pathfind>({ .target = player_handle });
boss.add<rmp::behavior::Shooter>({ .automatic = true, .count = 8, .spread = 360 });
rmp::behavior::StateMachine mind;
mind.states.push_back({ .name = "hunt", .enables = rmp::behavior::kinds<rmp::behavior::Pathfind>() });
mind.states.push_back({ .name = "volley",
.on_enter = [](rmp::Object &self) { self.velocity = {}; },
.enables = rmp::behavior::kinds<rmp::behavior::Shooter>() });
mind.transitions.push_back({ .from = "hunt", .to = "volley", .when = [](rmp::Object &self) {
return self.get<rmp::behavior::StateMachine>()->seconds_in_state() > 3;
} });
mind.transitions.push_back({ .from = "volley", .to = "hunt", .when = [](rmp::Object &self) {
return self.get<rmp::behavior::StateMachine>()->seconds_in_state() > 2;
} });
boss.add(std::move(mind));StateMachine is named states and the
moves between them: an enemy that idles, patrols, chases and flees; a boss's phases. A
State has a name,
on_enter, on_update (handed the delta) and on_exit, and
enables: the behaviors that run while it is on, written
rmp::behavior::kinds<Patrol, Animator>(). Every behavior some state names is paused
in the states that do not name it. It starts in initial (the first state when that is
empty) at its first update, and every frame asks its
transitions in order: the first whose
from matches (empty is any state) and whose when says yes is taken.
go("name") moves by name at its next update, state() is the state it is in
and seconds_in_state() how long it has been. A name it does not have is said once and
changes nothing.
The behaviors a level designer places — Patrol, Chase,
Orbit, Shooter, Hitbox, Collectible — read
their fields from an entity of the map with B::from(const MapObject &), which takes
each field the entity has by the name below and leaves the rest at their defaults. Put the fields on
the entity in LDtk (or as custom properties in Tiled), and the factory is one line:
map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &bat = s.spawn({ .position = o.position, .size = { 12, 8 } });
bat.add(rmp::behavior::Patrol::from(o));
});| Behavior | Fields it reads |
|---|---|
Patrol | path (Array<Point>; the entity's own position is the first waypoint), speed, wait, ping_pong |
Chase | speed, sight, fov |
Orbit | radius, speed (degrees_per_second), angle |
Shooter | every, speed, count, spread, rotate (rotate_per_shot), range |
Hitbox | damage, knockback |
Collectible | magnet |
What is not a number — a target, a callback, a sound — the factory sets, as anything it would set on a behavior of its own. The dungeon is built this way: every monster, trap and pickup is an entity with these fields, and its code is which behaviors each one carries.
A behavior of your own is the same struct as the ones above. Write its configuration as fields
with defaults, in the order they will be written in the braces; give it _update, or
_late_update when it corrects where the object ended up; add only the hooks it needs; and
keep what it remembers in ours. A callback field is an
rmp::Callback, so a lambda can go straight into the
braces:
#include <cmath>
// Bobs in place until something on one of the `by` layers touches it, then
// tells on_pick who took it and goes away.
struct Pickup {
unsigned by = 1; // the collision layers that collect it
rmp::Callback<rmp::Object &, rmp::Object &> on_pick; // the pickup, and who took it
void _ready(rmp::Object &self) { ours.rest_y = self.position.y; }
void _update(rmp::Object &self, float delta) {
ours.clock += delta;
self.position.y = ours.rest_y + std::sin(ours.clock * 3) * 2;
}
void _collision(rmp::Object &self, rmp::Object &other) {
if ((other.collision_layer & by) == 0) return;
on_pick(self, other);
self.destroy();
}
struct {
float clock = 0;
float rest_y = 0;
} ours;
};
namespace layer { constexpr unsigned PLAYER = 1u << 0; }
class Level : public rmp::Scene {
int _coins = 0;
void _ready() override {
auto &coin = spawn({ .position = { 300, 200 }, .shape = rmp::circle(6) });
coin.add<Pickup>({
.by = layer::PLAYER,
.on_pick = [this](rmp::Object &, rmp::Object &) { ++_coins; },
});
}
};A behavior is the right shape when the same few lines would otherwise be written into several
kinds of object. When something belongs to one kind of object only, its own _update() is
simpler.
https://omardev29.github.io/rmp-docs/manual/core/camera.html
Every scene has a camera, an
rmp::Camera, which decides what part of the scene's world
is on screen. Untouched, it is the identity while the window is the design size, and on a window of
any other size it fits the world the way [window] stretch says; a level bigger than the
screen is three lines.
auto &player = spawn({ .position = { 400, 300 }, .size = { 16, 24 } });
camera.follow = player.handle();
camera.smoothing = 10;
camera.limits = map.bounds(); // never show the void outside the levelThe camera starts centred on the design resolution — half of [window] width and
height — with no zoom and no rotation. At the design size that is the identity: a world
unit is a pixel, and an object at { 100, 50 } is drawn 100 pixels from the left and 50
from the top, as raylib would draw it.
| Field | Default | Is |
|---|---|---|
position | the centre of the design resolution | The world point at the centre of the view. |
zoom | 1 | 2 shows everything twice as big. Zero or less counts as 1. |
rotation | 0 | Degrees, clockwise, as raylib's Camera2D counts them. |
follow | empty | A handle to the object to keep centred. |
smoothing | 0 | How fast it catches up with that object, per second; 0 snaps. |
limits | empty | A rectangle of the world the view never leaves. |
Each frame, the scene draws its map and its objects through its camera, and then runs its own
_draw() outside it, in screen pixels. So everything in the world moves with the view, and
a HUD or a pause menu drawn in a scene's _draw() stays where it is while the player moves —
which is why the interface in a scene's _draw() never
drifts with the camera. An object's own _draw(), and its behaviors', run inside the camera, in
world units like the object.
The window can be resized, and a phone's screen is whatever it is. How the world fits a window
that is not the design size is [window]
stretch's to say, and the camera is where it happens. What the camera shows,
view(), is the game's area of the window divided by
the zoom and the stretch's scale, centred on position:
stretch | view() is |
|---|---|
"none" | The window, at 1:1: a bigger window shows more of the world, not a bigger picture of the same part. |
"letterbox" | The design, whatever the window: the same slice of the world for every player, scaled to fit, with bars around it. |
"expand" | The design and more, the way the window is longer than the design: taller on a 4:3 monitor, wider on a 21:9 one. |
The
camera puts position in the middle of the game's area — the window's middle, unless
letterbox left bars — and to_screen(), to_world() and the
pointer carry the stretch with them, so nothing in a scene asks which mode is on.
zoom goes on top of the stretch: under letterbox and expand
the design is scaled into the window first, and a zoom of 2 is twice as big as the stretch drew it.
So a game that wants a slice of the world of its own size — 225 world units of height, say, for pixel
art drawn two screen pixels to a pixel of the art — sets a constant zoom once and leaves the window to
the stretch. Under expand it never shows fewer than those 225 units of height, and shows
more where the window is longer:
rmp::app::set_stretch(rmp::app::Stretch::EXPAND);
camera.zoom = RMP_WINDOW_HEIGHT / VIEW_HEIGHT; // 225 world units of height at the design sizeThat
is the platformer's camera. Working the zoom out from
the window every frame, from GetScreenHeight(), is the stretch's job already: under
letterbox or expand it would be done twice, and the world drawn too big.
Under
letterbox the map and the objects are cut to the game's area, so the bars keep the clear
colour whatever stands past the edge of the design, and a pointer on a bar is outside the world. The
scene's own _draw() is not cut: the interface lays itself out inside the area on its
own, and something a scene draws over the whole window, a veil, covers the bars as well.
The stretch example is a court drawn in world units, in all three modes, with a key and a button to go round them; resize the window and the camera, the pointer and the interface follow, with nothing in the scene asking which mode is on. On Android and on a Linux console every mode is a letterbox: see a window of another size.
With follow set to an object's handle, the camera
centres on that object every frame — after the objects have moved and the collision pass has had its
say, so it frames where things ended up and not where they were heading. It is a handle, so a target
that is destroyed simply stops being followed, and the camera stays where it was. An empty handle
leaves the camera wherever you put it.
Changing follow to a different object snaps to it instead of gliding across the level:
a scene that opens with the camera drifting in from the middle of the screen is the other half of the
classic smoothing bug.
smoothing is how fast the camera catches up, as a rate per second: 0, the default, is a
snap, which is what a one-screen game wants; 5 is a gentle drift; 20 is nearly a snap.
It is a rate and not the fraction-per-frame that tutorials write —
position += (target - position) * 0.1f every frame — because that version depends on the
frame rate: at 120 frames a second it takes twice as many steps a second, and follows twice as fast as
at 60. Here the fraction of the distance covered in a frame is
1 - exp(-smoothing × delta), with the frame's time in the exponent, so two frames of half
the time land exactly where one frame of the whole time does, and the camera feels the same at 30
frames a second and at 144.
limits is a rectangle of the world the view never
leaves. Near the edge of the level the camera stops and the player keeps going, instead of the screen
showing a black strip past the end of the map. Limits win over following, and over smoothing too: they
are applied after both, so a smoothed camera still never shows the void.
camera.limits = map.bounds(); // the level, whatever its size
camera.limits = { 0, 0, 0, RMP_WINDOW_HEIGHT }; // a runner: free across, pinned top to bottomEach axis is limited on its own, and a zero width or a zero height means that axis is not limited
at all — which is exactly what an endless
runner wants. A level narrower than the view, on an axis,
centres the view on it rather than showing the void on one side. The limits apply to a
position you write by hand as well, so a camera you move yourself — a title screen
panning across the level — needs no arithmetic about the window to stay inside it.
zoom scales the view about its centre: 2 shows half as much of the world, twice as big.
Limits are worked out on the zoomed view, so a camera zoomed in can travel closer to the edge.
rotation turns the picture, in degrees clockwise. view() and
limits ignore it: they describe the unrotated rectangle, and a rotated view can show a
little past the limits at its corners.
camera.shake(8, 0.35f); // up to 8 world units, fading out over 0.35 secondsThat is Breakout's, when a ball is lost.
shake(strength, seconds) shakes the view by up to
strength world units, fading to nothing over seconds, 0.3 if you leave it out:
a hit, an explosion, a landing. The fade goes with the square of the time left, so it reads as a jolt
that settles rather than a buzz that stops, and the motion is a fixed pattern of waves rather than
random numbers, which would change direction every frame and look like a broken monitor.
The shake never touches position or view(). It is an offset applied only
to what is drawn, and to the two conversions below — so an object clamped to the view does not jitter,
there is nothing to restore when it ends, and a click during a shake still lands on what is under the
pointer, because the pointer is converted through the same shaken camera that drew the frame. The drawn
view is kept inside limits too, so a shake near the edge of the level shakes inwards.
Shaking again while a shake is running keeps the stronger of the two, measured against what the
running one is doing now rather than what it started at, instead of adding them up: a burst of hits in
one frame cannot build a shake that throws the screen across the room. A short strong hit on top of a
long shake lasts at least as long as the long one had left. A strength or a duration that is not a
positive number is ignored. shake_offset() is
how far the shake is moving the view right now.
The camera is moved, smoothed and shaken in its scene's update, so the camera of a scene frozen under a pause menu stands still, shake included, until the scene runs again.
| Call | Gives |
|---|---|
to_world(screen) | The world point under a point of the screen, in pixels from its top-left corner. |
to_screen(world) | Where a world point is on the screen. |
view() | The rectangle of the world that is visible, ignoring rotation. |
raylib() | The raylib Camera2D this camera is, shake and stretch included, for BeginMode2D(). |
The pointer is the commonest thing to convert, and it is already done:
rmp::input::pointer() is the pointer in world units, through
the current scene's camera, ready to compare with an object's position. An object's
on_click is tested the same way. The other direction places something drawn in screen
space over something in the world — a marker over the player's head, in the scene's
_draw():
rmp::Handle<rmp::Object> _player;
void _draw() override {
if (!_player) return;
const Vector2 above = camera.to_screen({ _player->position.x, _player->position.y - 30 });
DrawText("!", static_cast<int>(above.x), static_cast<int>(above.y), 20, YELLOW);
}A box of the interface over a point of the world — a health bar, a name, a button over a door —
is rmp::ui::at(), which goes
through the camera by itself.
A scene's _draw() is in screen pixels. To draw part of it in the world instead — a net
across a court, a line from the player to its target — open the camera for the lines that need it:
void _draw() override {
BeginMode2D(camera.raylib());
DrawLineV({ 400, 0 }, { 400, 450 }, GRAY); // in the world, moving with the view
EndMode2D();
DrawText("SCORE", 10, 10, 20, WHITE); // on the screen, staying put
}Drawing world things without it is right only while the window is the design size and the camera has not moved, which is exactly when the difference does not show — and on the first other window, the net ends up somewhere the court is not. Pong draws its net this way for that reason.
Besides drawing, five things in the framework take the camera into account, so they follow it without anything written:
edges, when its bounds are empty and the scene has no map, use
the camera's view as the edge of the world;on_click and on_drag find the object under the pointer through it, and
on_drag hands over the movement through it, in world units, so a dragged object stays
under the finger at any zoom;rmp::input::pointer() answers in world units through it;Parallax behavior scrolls each layer by
how far the view has moved;rmp::ui::at() puts its boxes where the camera shows the points they follow.Each scene has a camera of its own. A pause menu pushed over a level draws through its own camera, which nobody has moved, while the level underneath keeps its framing.
https://omardev29.github.io/rmp-docs/manual/modules/index.html
The core is what every game is made of. The modules are what a game takes when it
needs them: each one is a header of its own under include/rmp/, there is no header that
includes them all, and a game includes only the ones it uses. Which header holds what is in
headers.
resources/, loaded by
name, the same from loose files or from a pack.rmp::Value
and rmp::save: a tree of data written to the right folder on
every platform.rmp text keeps the tables in step with the code.https://omardev29.github.io/rmp-docs/manual/modules/input.html
rmp::input gives what the player
presses a name, and decides who gets to hear it. raylib answers "is the space bar down?"; a game
wants to know "did the player jump?", and whether that press was meant for the game at all or for
the button under the player's finger.
rmp::input::action("jump", KEY_SPACE, KEY_W, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
if (rmp::input::just_pressed("jump")) jump();It
is one header, #include <rmp/input.h>. The entry point reads the devices once at
the top of every frame, before the frame hook runs, so every question asked during that frame gets
the same answer. In a game started with RMP_GAME that is before any scene updates, and
two scenes in the same frame cannot disagree about what is held down. A game that runs its own frame
with RMP_ENTRY_POINT gets the same reading before its on_frame, and reads
its actions there exactly as a scene does.
An action is a name and the bindings that press it, as many as you like.
rmp::input::action takes the name first and the
bindings after it:
rmp::input::action("jump", KEY_SPACE, KEY_W, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
rmp::input::action("fire", MOUSE_BUTTON_LEFT, KEY_J, GAMEPAD_BUTTON_RIGHT_TRIGGER_1);Each binding is a plain raylib constant, and its type says which device it belongs to.
KeyboardKey, MouseButton and GamepadButton are three different
enums in C++, so the framework knows at compile time that KEY_SPACE is a key and
MOUSE_BUTTON_LEFT a mouse button. Anything else is a compile error at the call, which is
also why there is no string of key names to spell wrong:
rmp::input::action("jump", 32); // an int is not a keyThe compiler refuses it, saying among other things: no matching function
An action with no binding at all does not compile either: there is no version of
action() that takes the name alone.
Calling action() with a name that already exists replaces its bindings; it does not
add to them. That is what makes the natural place for these calls safe — a scene's
_ready(), which runs every time the player enters the scene:
void _ready() override {
rmp::input::action("jump", KEY_SPACE, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
rmp::input::action("fire", MOUSE_BUTTON_LEFT, GAMEPAD_BUTTON_RIGHT_TRIGGER_1);
}It is also how a game rebinds a key at runtime: call action() again with the new
list. An action holds up to eight bindings; more than that keeps the first eight and says so in the
log: INPUT: "…" was given … bindings and the limit is …; the extra ones are ignored.
Three questions, each asked by name:
| Call | True |
|---|---|
pressed("jump") | Every frame any of its bindings is held down. |
just_pressed("jump") | The frame one of them goes down. |
just_released("jump") | The frame one of them comes up. |
The edges compare this frame with the one before, and the first frame of the game is compared with itself: a key already held when the game starts does not read as just pressed and fire whatever it is bound to.
An action nobody has defined reads as false, and the log says so once per name — not sixty times a second: INPUT: no action called followed by the name. A misspelt name is the usual reason.
An analogue stick reads from -1 to +1 and an action is on or off, so a stick binding names one
half of an axis. rmp::input::stick is the one place
you write something that is not a plain raylib constant:
rmp::input::action("aim_left", KEY_Q, rmp::input::stick(GAMEPAD_AXIS_RIGHT_X, -1));
rmp::input::action("aim_right", KEY_E, rmp::input::stick(GAMEPAD_AXIS_RIGHT_X, 1));The sign says which half counts: -1 is left or up, +1 right or down. Any negative number is taken as -1 and any other, 0 included, as +1, because a stick has two halves and there is no third thing to mean. The half counts as pressed once the stick is past the dead zone, described below.
Every gamepad binding reads the first gamepad raylib knows, index 0. A game for several players on
one machine reads the others from raylib itself, with IsGamepadButtonDown() and the
gamepad's index.
Six actions exist before the game defines any, so that movement works with no setup at all. They are ordinary actions: defining one of these names again replaces it like any other.
| Action | Keyboard | Gamepad |
|---|---|---|
move_left | KEY_A, KEY_LEFT | d-pad left, left stick to the left |
move_right | KEY_D, KEY_RIGHT | d-pad right, left stick to the right |
move_up | KEY_W, KEY_UP | d-pad up, left stick up |
move_down | KEY_S, KEY_DOWN | d-pad down, left stick down |
ui_accept | KEY_ENTER, KEY_SPACE | the bottom face button |
ui_cancel | KEY_ESCAPE | the right face button |
ui_accept and ui_cancel are there for the game to read. The interface
does not read them: rmp::ui watches its own keys for moving
the focus, pressing a button, and backing out of a text field or an open list (see
focus, keyboard and gamepad), so
redefining ui_accept does not change what presses a focused button.
The four movement actions each take a letter and an arrow. Two players at one keyboard, the second on the arrows, means taking the arrows away from the first: define the first player's actions again without them, or the up arrow moves both. Pong does exactly that (main.cpp):
void _ready() override {
rmp::input::action("p2_up", KEY_UP);
rmp::input::action("p2_down", KEY_DOWN);
// Player one keeps W, S, the d-pad and the stick.
rmp::input::action("move_up", KEY_W, GAMEPAD_BUTTON_LEFT_FACE_UP,
rmp::input::stick(GAMEPAD_AXIS_LEFT_Y, -1));
rmp::input::action("move_down", KEY_S, GAMEPAD_BUTTON_LEFT_FACE_DOWN,
rmp::input::stick(GAMEPAD_AXIS_LEFT_Y, 1));
}rmp::input::vector() is a direction from four
actions, and with no arguments it uses the four move_ actions above — the keyboard, the
d-pad and the left stick at once:
velocity = rmp::input::vector() * 200;Three things are decided for you in that line:
position, so "up" gives a negative Y and nothing has to be flipped.rmp::input::axis() is the same thing on one axis:
-1, 0 or +1 from move_left and move_right, or the analogue value in between
when a stick is what is moving it. A platformer walks with it:
velocity.x = rmp::input::axis() * 180;Both take your own actions too, in the order negative then positive:
float aim = rmp::input::axis("aim_left", "aim_right");
rmp::input::action("port", KEY_A);
rmp::input::action("starboard", KEY_D);
rmp::input::action("ahead", KEY_W);
rmp::input::action("astern", KEY_S);
Vector2 boat = rmp::input::vector("port", "starboard", "ahead", "astern");Each action contributes how far it is pushed, from 0 to 1. A key or a button is all or nothing; a stick is analogue. When an action has several bindings the strongest one wins, so a key held down gives a full 1 even if the stick on the same action is only half pushed.
For a stick's raw reading — a camera that turns with the right stick, say —
rmp::input::axis_value() gives one axis from
-1 to +1, dead zone applied, and is never routed:
float turn = rmp::input::axis_value(GAMEPAD_AXIS_RIGHT_X);A stick at rest does not read exactly 0, and a worn one drifts further. The dead zone is the part
of the travel that reads as zero, as a fraction of it, and it starts at [input] deadzone
in raylib_multiplatform.toml:
[input]
deadzone = 0.25Past the zone the reading is rescaled so that it starts again from 0: just outside a dead zone of 0.2 the stick reads a little above zero, not a sudden 0.2, and a character does not lurch into motion at a fifth of its speed. Keys and the d-pad have no travel and are unaffected.
The value has to be between 0 and 0.95. Anything else is refused when the configuration is read, before a build starts, with the reason:
[input]
deadzone = 1.0 raylib_multiplatform.toml:2: deadzone = 1.0
^^^^^^^^^^^^^^
configure: error: [input] deadzone = 1.0 has to be between 0 and 0.95.
It is the fraction of a stick's travel that reads as zero. 0 turns it off, which on a worn controller means the character walks on its own; past 0.95 there is almost no travel left to read.At runtime, rmp::input::deadzone() reads it and
rmp::input::set_deadzone() changes it — what a
settings slider calls. A value outside 0..0.95 is clamped rather than refused, so a slider cannot
switch the sticks off:
static float deadzone = rmp::input::deadzone();
if (rmp::ui::slider("Stick dead zone", deadzone, 0.0f, 0.5f)) rmp::input::set_deadzone(deadzone);The mouse and a finger are one pointer. raylib already reports the first touch as the mouse, so
the same code works on a desktop and on a phone, with no #if:
| Call | Gives |
|---|---|
pointer_screen() | Where it is, in pixels, from the top-left of the window. |
pointer() | Where it is in the world, through the camera of the scene on top of the stack: what you compare an object's position with. With no scene on the stack, as in a game on RMP_ENTRY_POINT without scenes, there is no camera, and it is pointer_screen(). The same as pointer_screen() while that camera has not moved and the window is the size [window] width and height ask for. The camera puts its position, which starts at the middle of that size, in the middle of the game's area, scaled as [window] stretch says, so in a window of any other size — resized, or a phone's screen — the two differ even when the camera has not moved. On a letterboxed window, a pointer on a bar is outside the world. |
pointer_delta() | How far it moved since the last frame, in pixels. Zero on the first frame. |
pointer_down() | The left button, or a finger, is held. |
pointer_pressed() | The frame it goes down. |
pointer_released() | The frame it comes up. |
The last three are the left mouse button, read raw: they are not routed, so a press on an
interface button reads as pointer_pressed() too. To act only on presses the interface
did not take, ask consumed_pointer() first —
or bind the button to an action, which asks for you:
if (rmp::input::pointer_pressed() && !rmp::input::consumed_pointer()) {
spawn({ .position = rmp::input::pointer() });
}An object that wants to be clicked does not need any of this: its
on_click already gives the interface first
refusal.
A finger that presses a button on the HUD must not also fire the gun under it, and typing a name
into a text field must not walk the player across the level. Both have to be true without anyone
writing an if, so a query by name is routed, and a query by
device is not:
if (rmp::input::just_pressed("fire")) shoot(); // routed: quiet while something above has the input
if (rmp::input::pressed(KEY_W)) walk(); // raw: exactly IsKeyDown(KEY_W), alwaysThe argument's type says which of the two you asked for, and you can see it at the call. The raw
versions — pressed, just_pressed and just_released given a
key, a mouse button or a gamepad button constant instead of a name — are there for
when you want to know regardless of who else is listening: a held Shift that makes the player run,
a debug key.
An action reads as false while something above the code asking for it has taken its device. It is decided binding by binding, so an action on both a key and a mouse button still answers to the key while the mouse is over a button.
rmp::ui::wants_pointer() is true. That is
while the pointer is over anything the interface paints — a control, a panel or any box with a
background or a border, an image, a scroll area, empty part included — while a slider is being
dragged, and while a dropdown's list is open. Plain text with nothing behind it does not take the
pointer, so a score drawn over the game can be clicked through.rmp::ui::wants_keyboard() is true, which is
while a text field is typing — not merely while it has the focus (see
typing is having the
keyboard). Gamepad buttons and sticks go with the keyboard.input_below, which is
false by default. A covered scene is usually not updated at all; when the one on top
sets updates_below — a world that keeps
moving under a menu — its _update() runs and every action it reads is false, and neither
scene says so. See what a scene lets
through._update()
runs before anything draws, so the interface answers it from what the last frame drew:
wants_pointer() for where the pointer is now, and wants_keyboard() for the
field that was typing, which still is. A finger that lands on
a button without hovering over it first is the button's in the frame it lands, so the tap does not
reach the game as well. A slider being dragged keeps wants_pointer() true wherever the
pointer goes, until it comes up.
In
a game of scenes, a frame in which no scene draws any interface ends with both false, so a pause
menu that pops while the pointer is over one of its buttons does not leave the game's mouse
dead.
For code that wants the reason and not the answer — a different cursor over the HUD, a raw read
that should still respect the interface —
consumed_pointer() and
consumed_keyboard() answer whether
anything above the caller is holding that device: a scene on top, or the interface.
The interface's own navigation is not an action. Up, Down and Tab — and the d-pad and the left stick, up and down — move the focus between controls, and Left and Right move a focused slider. Enter, Space and the bottom face button press the focused one, and Escape and the right face button back out of a text field or an open list.
A
scene that reads one of those keys through an action — move_up, on the up arrow — is
taken by the interface for a game being played, and its controls for a HUD over it. They take no
focus by themselves, and the arrows stay the game's until Tab walks into the HUD; from then the keys
are the interface's, wants_keyboard() is true and the game's keyboard and gamepad
actions read nothing, until Escape, the right face button or a click elsewhere gives them back. So the
up arrow moves the player or the focus, never both. A menu is still best as a scene of its own,
pushed on top, with the game underneath frozen or, by the third rule, deaf;
a button in the HUD has the rest, and what
to say when the guess is wrong.
examples/input/01_actions defines its own actions, moves with
vector(), shoots with an action on the left mouse button and pushes a pause scene with a
button in the middle of the screen. Pressing that button does not shoot, and nothing in the code
says so:
// ---------------------------------------------------------------------------
// examples/input/01_actions/src/main.cpp
//
// Named actions, eight-direction movement in one line, and the part nobody
// thinks about until it bites: who gets to hear a press.
//
// Run it: `rmp example 01_actions`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/input.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
class PauseScene : public rmp::Scene {
public:
void _draw() override {
rmp::ui::begin();
rmp::ui::text("Paused");
if (rmp::ui::button("Resume")) rmp::Scene::pop();
rmp::ui::end();
}
};
class GameScene : public rmp::Scene {
public:
void _ready() override {
// The name first, then as many bindings as you like. The TYPE of each
// argument says which device it is — KeyboardKey, MouseButton and
// GamepadButton are three different enums — so passing anything else is
// a compile error, and there is no string to spell wrong.
rmp::input::action("jump", KEY_SPACE, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
rmp::input::action("fire", MOUSE_BUTTON_LEFT, GAMEPAD_BUTTON_RIGHT_TRIGGER_1);
rmp::input::action("pause", KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
// An analogue stick needs to know which half counts, and stick() is the
// only place you write something that is not a plain raylib constant.
rmp::input::action("aim_left", KEY_Q,
rmp::input::stick(GAMEPAD_AXIS_RIGHT_X, -1));
// Defining these here is safe even though the player enters this scene
// over and over: registering a name again REPLACES it, never adds to it.
}
void _update(float delta) override {
// Eight directions, keyboard and d-pad and stick at once, normalised so
// the diagonal is not 41 % faster — with no configuration at all. The
// six factory actions (move_*, ui_accept, ui_cancel) are already there,
// and they are ordinary actions you can redefine.
_position.x += rmp::input::vector().x * _speed * delta;
_position.y += rmp::input::vector().y * _speed * delta;
if (rmp::input::just_pressed("jump")) jump();
// AND THIS IS THE PART THAT MATTERS. "fire" is bound to the left mouse
// button, and there is a pause menu one push away with a Resume button
// in the middle of the screen. A finger that presses Resume must not
// also shoot.
//
// It does not, and nothing here says so. A query BY NAME is routed: an
// action on a mouse button goes quiet while the UI wants the pointer,
// one on a key goes quiet while a text field has the keyboard, and all
// of them go quiet in a scene with something above it that kept the
// input. Compare with what it takes by hand:
//
// if (!rmp::ui::wants_pointer() && IsMouseButtonPressed(0)) shoot();
//
if (rmp::input::just_pressed("fire")) shoot();
if (rmp::input::just_pressed("pause")) rmp::Scene::push<PauseScene>();
// The escape hatch, for when you want to know regardless of who else is
// listening. The argument type says which of the two you asked for, and
// you can see it at the call site.
if (rmp::input::pressed(KEY_LEFT_SHIFT))
_speed = 400.0f;
else
_speed = 200.0f;
}
void _draw() override {
DrawCircleV(_position, 16, SKYBLUE);
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
// The pointer is one pointer: mouse on a desktop, finger on a phone,
// and the same code on every target with no #ifdef.
rmp::ui::text(rmp::input::pointer_down() ? "pointer down" : "pointer up");
rmp::ui::text(TextFormat("%d jumps, %d shots", _jumps, _shots));
rmp::ui::end();
}
private:
void jump() { ++_jumps; }
void shoot() { ++_shots; }
Vector2 _position{ 400, 225 };
float _speed = 200.0f;
int _jumps = 0;
int _shots = 0;
};
RMP_GAME(GameScene);
rmp example 01_actionsNothing here hides raylib. IsKeyPressed(), GetMousePosition(),
GetTouchPointCount(), GetGestureDetected() and the rest work as they always
do, next to rmp::input, and they are what to reach for when the game needs something
this module does not model: several touches at once, a second gamepad, text typed as characters with
GetCharPressed(). They are raw — the routing above does not apply to them — so a raw
read that should leave the interface alone asks
consumed_pointer() or
consumed_keyboard() first.
https://omardev29.github.io/rmp-docs/manual/modules/ui.html
rmp::ui is the interface layer: menus, HUDs,
dialogs and settings screens. A main menu is three calls between a begin() and an
end(), and it comes out centred, sized for the screen it is on, and playable with a
mouse, a finger, a keyboard or a gamepad without a line about any of them.


rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) quit();
rmp::ui::end();No coordinates, no sizes, no fonts and no hit boxes. Everything else on these pages is what you reach for when the default is not what you want, and you only meet it when you do:
The same interface can be written two ways, and a game uses either, or both on one screen. The simple way is a call each frame that draws the control and answers what happened to it — nothing to keep, nothing to set up. The full way keeps each widget as a member of your scene, the way a Godot scene keeps its nodes: set up once, with its text, its look, its sounds and what to run when it is clicked, hovered or focused, and shown each frame where it goes. Both are drawn by the same code, so they lay out, navigate and look the same:
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) quit();
rmp::ui::end();rmp::ui::Button start{ .text = "Play", .on_click = [] { play(); } };
rmp::ui::Button leave{ .text = "Quit", .on_click = [] { quit(); } };
void _draw() override {
rmp::ui::begin();
start.show();
leave.show();
rmp::ui::end();
}Start with the simple way; it is what most screens need. Reach for the full way when a screen is
designed rather than written — a shop whose every button has its own picture, a dialog that shakes
when the password is wrong, an item that plays a sound when the pointer reaches it. Every control has
both: button() and Button,
text() and Label, image() and
Image, panel() and
Panel, checkbox() and
Checkbox, slider() and
Slider, dropdown() and
Dropdown, text_input() and
TextInput, progress() and
ProgressBar. The pages that follow show each
control both ways, side by side; widgets
you keep has every field and callback of the full one.
In the simple way there are no widget objects. A call to button()
both draws the button for this frame and answers whether it was pressed, and the next frame asks
again. What persists from one frame to the next is your data; what is rebuilt every frame is the
picture. So a menu that depends on the game's state is an if, and a label that changes
is a string you build where you call it:
rmp::ui::begin();
rmp::ui::text("Score: " + std::to_string(score));
if (has_save && rmp::ui::button("Continue")) load();
rmp::ui::end();A temporary string is safe there. Every string handed to the interface is copied the moment it is
passed, into memory that lasts until the frame is drawn, so std::to_string(score) dying
at the end of the line changes nothing. That memory is a few kilobytes per frame; a frame that
somehow needs more has its labels cut short and the log says so once:
UI: text arena full (… bytes); labels are being truncated.
In a game made of scenes, a scene's interface goes in its
_draw(). That hook runs in screen space after the
scene's map and objects have been drawn, so the interface sits on top of the world and stays put
while the camera moves:
class PauseScene : public rmp::Scene {
void _draw() override {
rmp::ui::begin();
rmp::ui::text("Paused");
if (rmp::ui::button("Resume")) rmp::Scene::pop();
rmp::ui::end();
}
};The frame is cleared for you with the theme's background colour, unless the scene
sets background itself. A scene underneath
another one keeps drawing its interface when the scene on top lets it (see
what a scene lets through), and the
framework treats every scene's begin()/end() pair as part of one frame.
A game that runs its own loop with RMP_ENTRY_POINT calls the pair between
BeginDrawing() and EndDrawing(), after whatever the interface should sit on
top of, and clears the screen itself:
BeginDrawing();
ClearBackground(rmp::ui::current_theme().background);
draw_world();
rmp::ui::begin();
if (rmp::ui::button("Quit")) rmp::app::quit();
rmp::ui::end();
EndDrawing();There is nothing to
start and nothing to stop. The interface starts itself on the first
begin() — by which time there is a window — so a game
that never draws an interface never allocates one, and the entry point shuts it down for you while
the window is still open. A begin() after
rmp::ui::shutdown() starts it again, the same way
the first one did.
That is all of them.
end() draws. Everything between
begin() and end() is laid out and drawn when end() runs, so the
pair goes where the drawing is: in _draw(), or between BeginDrawing() and
EndDrawing()._draw(), in screen space — not in
_update(), which draws nothing, and not in an object's _draw(), which runs
under the camera: a box that follows something in the world is
at(). A call in the wrong place does nothing, and the
log says so once: UI: rmp::ui::begin() in _update(): nothing is drawn while the world moves, so
it did nothing. Pairs do not nest either. A begin() before the end()
of the one open says UI: rmp::ui::begin() while a frame is open: end() was not called, or
begin() is inside a container -- column() is what goes there., and what follows it goes into
the frame already open. A widget with no pair open draws nothing, returns false and
says UI: rmp::ui::button("Play") with no frame open, so it did nothing.button("Play")
has to answer, this frame's layout does not exist yet — it is computed in end() — so the
button is hit-tested against where it was last frame. A control cannot be clicked on the very first
frame it appears, which is 16 ms at 60 frames a second, and while the interface is moving the place
you can click trails what you see by one frame.The third rule is the cost of immediate mode, and the alternative is worse. Laying the interface
out twice per frame would mean running your code twice, and a score++ inside a button's
if would count double.
Each
begin()/end() pair is a pass, and a frame can hold several: a HUD
and the pause menu over it, a screen and the overlay() in front of
it. In a game of scenes each scene's _draw() has its own; a frame hook of your own, with
RMP_ENTRY_POINT, can draw several too, and they are one frame of the interface.
rmp::ui::button returns true on the
frame it is pressed: the pointer released over it, having been pressed on it — press, drag off and
let go, and nothing happens — or, while it has the focus, Enter, Space or the gamepad's bottom face
button. It reads the way it looks:
if (rmp::ui::button("Start", { .style = rmp::ui::Variant::PRIMARY }))
start_game();
if (rmp::ui::button("Delete save",
{ .style = rmp::ui::Variant::DANGER, .enabled = has_save }))
delete_save();rmp::ui::Button start{ .text = "Start",
.variant = rmp::ui::Variant::PRIMARY,
.on_click = [] { start_game(); } };
rmp::ui::Button erase{ .text = "Delete save",
.variant = rmp::ui::Variant::DANGER,
.on_click = [] { delete_save(); } };
void _draw() override {
erase.enabled = has_save;
rmp::ui::begin();
start.show();
erase.show();
rmp::ui::end();
}ButtonOptions has four fields, written in
this order:
| Field | Default | Means |
|---|---|---|
style | Variant::NORMAL | What the button means — normal, primary, danger, outline, ghost. The theme decides what that looks like; see variants. |
size | the theme's | Size::SMALL, MEDIUM or LARGE, or a number of design units. See sizes. |
enabled | true | false draws it in the theme's disabled colours; it cannot be pressed and the focus skips it. |
id | none | A name that stays the same whatever the label says. See labels are ids. |
The order
matters, because C++20 requires designated initialisers in declaration order:
{ .style = …, .enabled = false } is right, and { .enabled = false, .style = … }
does not compile. GCC and MSVC refuse it on their own; Clang only warns, so wherever Clang compiles a
game the framework adds -Werror=reorder-init-list — in the CMake builds, on Android and
in the generated iOS project — and the mistake fails on the machine that made it, not later on
another compiler. Every options struct in rmp::ui is ordered
the way its fields are most likely to be written, so the order you would write them in is usually
the one that compiles; when a compiler complains about designator order, that is what it means.
A button fills the width it is offered. In begin()'s column that is the width of the
widest thing in it, which is why the buttons of a menu come out the same width without anyone
measuring anything; in a row, the buttons share the row; in a frame opened to
fill the window, it is the window's
width less the padding. Its height is at least the theme's
min_touch_size — 44 design units, a
target a thumb can hit — scaled with its type size.
A button that is a picture — an icon, a slot, a "Play" the artist drew — is
rmp::ui::image_button,
pressed the same way. A screen where every button has its own look, icon, sounds and callbacks is
easier with widgets you keep, and a
look for every button of the game is a style in the
theme; neither changes a line of a menu written the simple way.
rmp::ui::text draws a string, in one of the theme's
colours, at one of its sizes:
rmp::ui::text("Game over", { .size = rmp::ui::Size::LARGE });
rmp::ui::text("Progress since the last save is lost.",
{ .color = rmp::ui::ColorRole::MUTED });
rmp::ui::text("v1.0.2", { .color = rmp::ui::ColorRole::MUTED,
.size = 14, .wrap = false });rmp::ui::Label title{ .text = "Game over", .size = rmp::ui::Size::LARGE };
rmp::ui::Label lost{ .text = "Progress since the last save is lost.",
.color = rmp::ui::ColorRole::MUTED };
rmp::ui::Label version{ .text = "v1.0.2", .color = rmp::ui::ColorRole::MUTED,
.size = 14, .wrap = false };
void _draw() override {
rmp::ui::begin();
title.show();
lost.show();
version.show();
rmp::ui::end();
}TextOptions is
color — a
ColorRole, not a colour —
size and
wrap. With wrap on, the
default, a line too long for the space it is given breaks between words; off, it is never broken.
The interface keeps a little state of its own about each control: whether the pointer is over it,
whether a press started on it, whether it has the focus, the colour it is fading towards, whether a
dropdown is open. It finds that state again every frame by the control's label. Two controls with the
same label in one begin()/end() are told apart by their order — the second
"Back" is a different control from the first — so the common case needs nothing.
Order is what breaks when the interface is conditional. A control that appears or disappears
before others with the same label renumbers them, and the hover, the focus or the fade moves to a
different control with nothing in your code having changed. The
id field is the escape: a name that is the same control whatever else is on screen.
for (int i = 0; i < 3; ++i) {
if (!slots[i].used) continue;
rmp::ui::text(slots[i].name);
const std::string id = "erase" + std::to_string(i);
if (rmp::ui::button("Erase", { .id = id })) erase(i);
}A label that changes is a new control each time it does. A button that reads "Music: on"
and then "Music: off" loses the focus when it is pressed from the keyboard, because the control that
had it is gone, and the focus goes back to the first control on the screen. An id keeps it
the same control:
if (rmp::ui::button(music ? "Music: on" : "Music: off", { .id = "music" })) music = !music;Containers have no id unless you give them one; see naming a container.
Every control is focusable, in the order it is declared, and nothing in your code asks for it. The widgets you already wrote can be played with a keyboard or a gamepad:
| Does | Keyboard | Gamepad |
|---|---|---|
| Next control | Tab, Down | d-pad down, left stick down |
| Previous control | Shift+Tab, Up | d-pad up, left stick up |
| Press, tick, open | Enter, keypad Enter, Space | bottom face button |
| Back out of a text field or an open list | Escape | right face button |
| Move a slider | Left, Right | d-pad left and right, left stick |
Past the last control the focus wraps to the first, and holding a direction walks the list after a short pause. These keys are read by the interface itself, from raylib; they are not rmp::input actions, and redefining an action does not change them. The focus moves between controls of the previous frame, for the same reason hit testing does.
Two controls use the keys a little differently, and their sections say how. A text field types only once it has the keyboard, which is not the same as having the focus, and Tab, Up and Down leave it like any other control. An open dropdown takes Up and Down for its own items. Escape backs out and nothing more: raylib's habit of closing the window on it is switched off by the entry point (see the Escape key).
A screen that declares something focusable and has nothing focused gives the focus to its first control. A game-over scene with one "Play again" button on it answers Enter and the gamepad's bottom button the moment it appears. The one exception is a HUD over a game being played, whose keys are the game's: see a button in the HUD.
Having the focus and showing it are two things. The focus ring — the theme's
focus colour,
focus_ring design units wide — appears once
the player touches the keyboard or the gamepad, and goes away again on a click. Someone playing with
a mouse does not find an outline on the first button of every menu; someone with a controller sees
where they are as soon as they reach for it.
A screen does not need to put the focus anywhere: its first control already has it.
rmp::ui::focus() is for starting somewhere else. It
gives the focus to a control by its label or by the id it was given, and shows the ring
straight away, because you asked for it; a text field given the focus this way also takes the
keyboard. An empty string clears it, and by the rule above the screen's first control then takes it.
rmp::ui::focused() names what has it, or gives
"".
The place to call it is the scene's
_ready(), once. Between frames there is no interface being described to look the name up
in, so the name waits: the next frame that draws controls gives the focus to the first one carrying
it, in whichever scene draws it. focused() answers with the name at once. If that frame
draws controls and none of them has the name, the request is dropped and the screen keeps its own
first control, rather than lying in wait for a control with that label to turn up later.
void _ready() override {
rmp::ui::focus("Continue"); // not the first button: the one the player most likely wants
}
void _draw() override {
rmp::ui::begin();
rmp::ui::button("New game");
rmp::ui::button("Continue");
rmp::ui::end();
}Called
inside a begin()/end() pair, it looks the label up among the controls of
that pair, so it goes before the control it names.
rmp::ui::set_navigation_enabled(false)
turns keyboard and gamepad handling off, for a game that drives the focus itself;
navigation_enabled() says whether it is on.
It starts on. With it off, clicks and taps still work but no control has the focus, so Enter, Space
and the gamepad press nothing. A text field still types when it is clicked, and stops on Enter,
Escape or a click elsewhere, because those are read whether navigation is on or not. Turning it off
also hands back the keys of a HUD the player walked into with Tab.
When two scenes draw, the one on top holds the focus. A scene underneath that input cannot reach
— the scene above left input_below at
false — is drawn exactly as usual, and nothing in it can be hovered, focused or clicked:
a HUD under an open pause menu is visible and inert, and neither scene says so.
When the scene on
top sets input_below, both scenes' controls are one list: the one underneath can hold the
focus, and the arrows walk up out of it into the scene above and back down. A scene whose interface
is drawn first does not claim a focus that was on screen last frame, because a scene drawn after it
may be about to declare that control; only when no scene does is the focus handed on.
The
scene the player plays in reads its own keys, and Space there is a jump, not a press of the HUD's
first button. So a scene that reads any of the keys the interface navigates with — Enter, Space,
the arrows, Tab, the d-pad, the gamepad's bottom face button, the left stick — through
rmp::input, in its own _update() or in its
objects' and their behaviors', is taken for a game being played, and its interface for a HUD over
it. The HUD's controls take no focus by themselves, and those keys stay the game's. The pointer
presses them as always, which is what a Pause button is for on a phone that has no Escape:
class PauseScene : public rmp::Scene {
void _draw() override {
rmp::ui::overlay([] {
if (rmp::ui::button("Resume")) rmp::Scene::pop();
});
}
};
class GameScene : public rmp::Scene {
void _ready() override {
rmp::input::action("jump", KEY_SPACE, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
}
void _update(float /*delta*/) override {
if (rmp::input::just_pressed("jump")) jump(); // Space is the game's: Pause has no focus
}
void _draw() override {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT });
if (rmp::ui::button("Pause")) rmp::Scene::push<PauseScene>();
rmp::ui::end();
}
};Tab
walks into the HUD, and from there the arrows walk on as they do in any menu. While the player is in
it the keys are the interface's: wants_keyboard()
is true, and the game's keyboard and gamepad actions read nothing, so the arrow that moves the focus
does not move the player too. Escape, the gamepad's right face button or a click anywhere else hands
them back to the game. rmp::ui::focus() on a control of the HUD is the game choosing it,
as Tab would.
That
is a guess, made every frame from what the scene read in it — in a game without scenes, from what
the frame read — and two kinds of scene defeat it: one
that reads raylib's keys itself — IsKeyPressed(KEY_SPACE) — is never noticed, and one
that reads the arrows and still wants its interface to be a menu.
FrameOptions::focus_first says it
for them: false is a HUD whatever the scene reads, true a menu whose first
control takes the focus.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT, .focus_first = false });
if (rmp::ui::button("Map")) open_map();
rmp::ui::end();A pause scene pushed over the game usually reads none of those keys — Escape and the right face
button are not among them, so a pause on Escape stays a menu — and its first button takes the focus
like any menu's. An overlay() gives its first control the focus
whatever the scene under it reads.
A pause menu, a "Really quit?", a game-over card: something in front of everything else, with what
is behind it dimmed — or blurred — so that the eye goes where the player has to act.
rmp::ui::overlay() is that. It is a frame of its own:
it takes the place of a begin()/end() pair, and what it shows goes in the
function it is handed, as a container's contents do.
class PauseScene : public rmp::Scene {
void _draw() override {
rmp::ui::overlay({ .blur = 6, .dim = 0.4f }, [] {
rmp::ui::text("Paused", { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Resume")) rmp::Scene::pop();
if (rmp::ui::button("Quit")) rmp::app::quit();
});
}
};Everything
drawn earlier in the frame is behind it, dimmed towards its veil colour and blurred when
asked; its own content is drawn on top of that, sharp. And it is modal without a word about it:
wants_pointer() is true wherever the pointer is — at a dim of
0 too, where there is no veil to see.OverlayOptions, in this order:
| Field | Default | Means |
|---|---|---|
placement | Align::CENTER | Where its content sits, as a frame's placement. |
blur | 0 | How far to blur what is underneath: the Gaussian's standard deviation in design units, as CSS's blur() means it. 0 is no blur, and costs one rectangle. |
dim | 0.45 | From 0 to 1: how far what is underneath goes towards veil. |
veil | black | The colour it is dimmed towards. |
The pause menu above is a scene of its own, pushed over the game, and its whole
_draw() is one overlay. A pushed scene freezes the scene under it and leaves it on
screen — the defaults of what a scene
lets through — so the game stops where it was and shows through the veil, and
pop() carries on from there. Nothing about pausing is written anywhere.
There is no menu() and no dialog() to learn. A menu is the three calls at
the top of this page, and a dialog is an overlay with a
panel() in it. Drawn by the game scene itself, after its
own end(), it pushes nothing, so nothing stops: the game goes on behind the question,
and the overlay takes the clicks, the focus and Enter for as long as the scene draws it.
bool _asking = false; // "Really quit?" is on screen
void _draw() override {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT });
if (rmp::ui::button("Quit")) _asking = true;
rmp::ui::end();
if (_asking) {
rmp::ui::overlay({ .dim = 0.6f }, [&] {
rmp::ui::panel([&] {
rmp::ui::text("Really quit?");
rmp::ui::row([&] {
if (rmp::ui::button("Stay")) _asking = false;
if (rmp::ui::button("Quit", { .style = rmp::ui::Variant::DANGER }))
rmp::app::quit();
});
});
});
}
}What the dialog answers is the scene's to decide, here with a flag it keeps. Stay comes first, so Enter is the answer that loses nothing. The overlay example has both patterns: the pause, pushed and blurred, and this dialog, with the game moving behind it.
An overlay is a frame, so it goes after end(), never between begin() and
end(). Called there it says so once, UI: overlay() inside begin()/end() -- an
overlay is a frame of its own: call it after end(), or from the _draw() of a scene of its
own., and shows its content as a layer of the open frame, over the veil and without the
blur.
The
blur is a real one on every GPU raylib drives, OpenGL ES 2.0 and WebGL included: the frame is drawn
into a texture, blurred at a fraction of its size and stretched back over the screen. Only a frame
after the one that asks is drawn into that texture, so an overlay's first frame has the veil alone,
and the blur eases in over the theme's
transition. Where no shader can run —
raylib's software renderer, OpenGL 1.1 and 2.1, a driver that refuses one — the veil comes alone, and
the log says why, once: UI: overlay() cannot blur here (raylib's software renderer has no
shaders); the veil comes alone. That is a fact about the machine and not a mistake in the
game, so [dev] strict does not stop for it.
Drawing
the frame into a texture from its first line is something only RMP_GAME's frame does. In
a frame hook of your own, with RMP_ENTRY_POINT, an overlay that asks for a blur shows the
veil alone and says so once. So does a scene that draws through a BeginTextureMode() of
its own under a blurred overlay: ending it sends the rest of the frame to the screen, so the blur goes
off and the veil stays. Draw that texture before the frame, or ask the overlay for no blur.
rmp::ui::at() puts a box of the interface over a point of
the world — a health bar over an enemy, a name over a character, a button over a door — wherever the
scene's camera shows that point, zoomed, scrolled, shaken and stretched with it. It goes between
begin() and end() in the scene's _draw(), like everything
else here:
std::vector<rmp::Handle<Enemy>> _enemies;
void _draw() override {
rmp::ui::begin();
for (const rmp::Handle<Enemy> &e : _enemies) {
if (e) rmp::ui::at(e->position, [&] { rmp::ui::progress(e->hp / 10.0f); });
}
rmp::ui::end();
}The
point goes through the camera that drew the scene's world, so the box stays on the enemy however the
view moves, and the box takes no room in the column it is described in.
AtOptions says where it sits:
| Field | Default | Means |
|---|---|---|
anchor | Align::BOTTOM_CENTER | The point of the box that sits on the world position. The bottom centre puts the box above it, which is where a health bar or a name goes. |
offset | { 0, 0 } | Design units, after projecting: { 0, -8 } lifts the box clear of the sprite. |
id | none | A stable name for the box, as a container's id. |
What
a box paints does not take the pointer: a click on the enemy under its health bar is still the
enemy's, and wants_pointer() stays false over the bar. A control inside one is a control
like any other, hovered, pressed and focused where it is drawn. The boxes are drawn under the rest of
their pass, as the world they belong to is, so a health bar that walks under the HUD's panel goes
behind it; and a box is never narrower than the theme's min_touch_size, which gives a
progress bar in it a width to fill. Without scenes there is no camera, and the world is the
screen. The top-down game puts a bar over every enemy
this way.
A box goes with its point. While the point is off the screen the box is not drawn at all, not even the part that would still show, and nothing in it takes the pointer, the focus or the keys: a button over a character who has walked away is not a button anyone can press. Back on the screen it is a control again, and the e2e driver holds it to the window like any other.
rmp::ui::tooltip() is a line about the control
declared just before it:
if (rmp::ui::button("Sell")) sell();
rmp::ui::tooltip("Gives you half of what it cost");It shows while the pointer rests on that control, and at once while the keyboard's or the gamepad's focus is on it: a player walking a menu with a pad does not hover, and gets the same line. It floats in front of the rest of the frame, so it moves nothing; it stays on the screen, taking the other side when the one asked for would run off the edge; and a scroll area the control is in does not cut it. The text is copied, like every label.
| Field | Default | Means |
|---|---|---|
side | Align::TOP_CENTER | Which side of the control it appears on. |
delay | 0.5 | Seconds the pointer rests on the control before it shows. Infinity is never by the pointer: by the focus alone. |
One tooltip goes with one control. A tooltip with no control before it shows nothing, and says
UI: rmp::ui::tooltip("…") with no control declared just before it, so it is about nothing and
shows nothing. An empty text shows nothing and is no mistake, so
tooltip(item.description) needs no if for an item without one.
The inventory describes every item this way.
rmp::ui::notify() puts a short message at the bottom
of the screen that goes away by itself — "Saved", "Achievement unlocked" — with nothing to close and
nothing in the layout moving to make room for it:
rmp::ui::notify("Saved");
rmp::ui::notify("Not saved: the disk refused it", { .color = rmp::ui::ColorRole::DANGER });
rmp::ui::notify("Achievement unlocked", { .seconds = 5 });It
only queues a copy of the text, so it can be called from anywhere — _update(), a
callback, a frame that draws no interface. The framework draws what is queued after the last scene,
over everything, and a notice never takes the pointer or the focus.
NotifyOptions is
seconds on screen, 3 by default, at the
end of which it fades out, and the color
of the theme its text is painted in. The newest few are shown, one above the other.
In a frame hook of your own, with RMP_ENTRY_POINT, they are drawn over the frame's
first begin()/end() pair, there being no telling which end() is
the last; a frame of it that describes no interface draws none, and they wait, no older, for the next
one that does.
In
a debug build the framework's own warnings arrive here too. A mistake in the game that it says once
in the log — an action nobody defined, a widget outside begin()/end(), a
tooltip about nothing — is also a notice, in the theme's danger colour, where it cannot scroll past
unread. A release build only logs them, and [dev] strict stops a debug build at the first
one instead. rmp test smoke holds a game to none at all: the framework reported a
mistake in the game (the WARNING lines above, said once each).
The interface reads the pointer and the keyboard itself, and the game reads them too. Two functions say when the game should leave them alone:
rmp::ui::wants_pointer() — the pointer is
over something the interface paints, a slider is being dragged, or a dropdown's list is open.rmp::ui::wants_keyboard() — a text field
has the keyboard and is typing. Having the focus is not enough: a field the player pressed Enter on
keeps the focus and gives the keyboard back."Something the interface paints" is every control, every box with a background colour or a border — a panel, a progress bar, an open dropdown list — every image, and every scroll area, its empty part included but not where it has clipped its rows away. A click on a panel's background is the interface's, and does not fall through to the game behind it. Plain text with nothing behind it is the exception, on purpose: a score drawn over the game does not stop the game being clicked through it. An overlay's veil covers the whole screen, so while one is up the pointer is the interface's wherever it is; what a box over the world paints is the other way round, and lets the game have the pointer.
Both
can be asked before anything draws — in _update(), or above begin() — and
on the line after end(). Until the frame's first begin(),
wants_pointer() answers for where the pointer is now, against what the last frame
drew, so a finger that lands on a button without hovering over it first is the button's from the
frame it lands in, and the tap does not reach the game too; wants_keyboard() answers
for the field that was typing, which still is. From the frame's first begin() on,
both answer for what this frame draws.
In
a game of scenes, a frame in which no scene calls begin() ends with both false — a
pause menu that pops while the pointer is over one of its buttons does not leave the game's mouse
dead — except that a slider being dragged keeps wants_pointer() true until the
pointer comes up. A game that reads its
actions by name through rmp::input rarely calls them, because such a read already asks
them — the subject of who hears a press.
Wherever the game reads raylib's input directly, they are the check:
if (!rmp::ui::wants_pointer() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) shoot();
if (!rmp::ui::wants_keyboard() && IsKeyDown(KEY_W)) walk();raylib reports the first touch as the mouse, so a menu works on Android and iOS with no extra code. Three things change underneath on those two:
min_touch_size, even a small one: a
small button on a phone is still pressed with a thumb.begin() keeps 24 design units free at
every edge of the screen, on top of its own padding, for the status bar and the notch —
[android.display] into_cutout draws the game behind the notch, which is right for a
background and wrong for a menu.Every size in rmp::ui — a theme's padding, a panel's width, a text's size — is in
design units: pixels at the resolution [window] width and
height declare in raylib_multiplatform.toml. That block is the resolution
you design for, and the interface is drawn as if the window were that size. One number turns design
units into pixels:
scale = clamp(min(window width / [window] width, window height / [window] height), 0.5, 4)Designed at 800×450 and played at 1920×1080, everything is 2.4 times bigger; in a window of
1280×720, 1.6 times. It is min() and not max() because what does not fit is
worse than what is left over: the tighter side wins and the interface stays on screen. The clamp stops
the two absurd ends, a window too small to read and a monitor that turns a button into a
billboard.
That
scale is the interface's whatever [window]
stretch says. Under letterbox the interface also stays inside the game's
area: a frame, and an overlay's content, keep clear of the bars as they keep clear of a phone's notch,
and the breakpoint is the shape of
that area, the design's, whatever the window does.
What the scale cannot do is fit a screen that does not fit at the size you design for. It keeps the proportions, so a control laid out below the bottom edge at 800×450 is below it at 1920×1080 as well, where nobody can see it or click it. A screen with more on it than that is laid out in two columns, as the settings example is, or put in a scroll area, which the keyboard and the gamepad scroll by moving the focus.
Text follows the same scale: it is drawn at the pixel size the layout asks for, its size in design units times the scale. raylib's built-in font is a small bitmap stretched to that size; a font of your own is rasterised at that exact size, so it stays sharp. See fonts.
rmp::ui::scale() reads the factor in use.
rmp::ui::set_scale() pins it — an "interface
size" option in a settings screen — and 0 goes back to automatic. A pinned scale is used
as it is, without the clamp, up to 16; past that it is 16, and a NaN or one below 0 is automatic,
each said once. [ui] scale pins it from the start; it is 0,
automatic, unless you set it:
[ui]
scale = 1.5Scale makes everything bigger or smaller together. Changing the shape of a layout on a narrow screen is a different tool, the breakpoint, in interface style.
The [ui] section of raylib_multiplatform.toml holds five keys, and with
all of them at their defaults a menu is still three calls:
| Key | Default | Means |
|---|---|---|
theme | "dark" | Which theme the game starts with, "dark" or "light". See themes. |
font | "" | A font file in resources/; empty is raylib's built-in font. See fonts. |
font_size | 20 | The theme's type size, in design units: a whole number from 6 to 200. |
scale | 0 | 0 is automatic; a number from 0 to 8 pins it. |
max_elements | 512 | The most elements the interface lays out in one frame, from 16 to 65536. |
max_elements is what sizes the interface's memory, and it is a ceiling, not a guess.
Every control is more than one element — a button is its box and its label — so a long list counts
quickly. Past the ceiling the interface stops laying anything out until the game is restarted, and
says so once, naming the key:
UI: more than max_elements (…) elements in one frame. The interface will not lay out again until
the game is restarted. Raise it, or draw less at once:
[ui]
max_elements = 1024The layout engine is Clay, and none of its types
appear in rmp/ui.h, so code written against rmp::ui does not depend on it.
It is still there to use. Include <clay.h> and write Clay's own elements between
begin() and end(): they join the same tree, are laid out in the same pass
and drawn by the same renderer. Two things to know before doing it: begin() has already
opened two elements — a root that fills the screen and the column inside it — so yours become
children of that column; and Clay does not copy strings, so a string built at runtime has to outlive
end(). Dropping to Clay has the rest of the rules,
and the Clay example does it next to
rmp::ui calls in the same frame.
Every example is a small project the framework builds and boots in CI, and each of these is one idea:
rmp::ui.set_font().The main menu of the first one is the whole idea in one file:
// The whole point: a main menu.
#include "screens.h"
#include <rmp/ui.h>
void MainMenuScene::_draw() {
// A centred column, sized and spaced by the theme, scaled to the window.
// Three ifs and you have a menu.
rmp::ui::begin();
rmp::ui::text("MY GAME");
if (rmp::ui::button("Play")) change<PlayingScene>();
if (rmp::ui::button("Options")) change<OptionsScene>();
if (rmp::ui::button("Quit")) change<ConfirmScene>();
rmp::ui::end();
}
https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html
Everything inside begin() and end() arranges itself in a
centred column, which is the right answer for a menu and the wrong one for anything with structure.
Containers are how you get structure: they nest, they take their contents as a lambda, and every
size they take is in design units, so a layout drawn for the [window] resolution keeps
its proportions on any screen.


rmp::ui::begin();
rmp::ui::panel([&] {
rmp::ui::text("Really quit?");
rmp::ui::row({ .grow_x = true }, [&] {
if (rmp::ui::button("Yes")) quit();
rmp::ui::spacer();
rmp::ui::button("No");
});
});
rmp::ui::end();The contents are a lambda, and that is the reason there is no closing call to forget: the
container closes when the lambda returns. Capture with [&] when the body needs your
variables, which is most of the time.
| Container | What it does |
|---|---|
row | Its children left to right. |
column | Its children top to bottom. |
panel | A column with a background, padding and rounded corners: a dialog, a card. |
center | Fills the space it is given and puts its contents in the middle of it. |
stack and layer | Layers in the same box, the later ones on top. |
grid and cell | Equal columns, as many rows as it takes. |
scroll | Clips its contents and scrolls them. |
spacer | Not a container: it eats the space left over, or leaves a gap of a given size. |
begin() opens two boxes before anything of yours: a
root that fills the screen, and one column inside it that everything you declare goes into. The
column is as big as its contents, and the root places it — in the middle, unless you say otherwise.
FrameOptions says otherwise:
| Field | Default | Means |
|---|---|---|
placement | Align::CENTER | Where the column sits on the screen. |
gap | the theme's gap | Between the things in the column. |
padding | the theme's panel_padding | Kept clear around the edge of the screen. |
grow | false | true: the column fills the window, less the padding, instead of fitting what is in it. See filling the window. |
focus_first | unset | Whether the first control takes the focus by itself. Unset, the framework decides: yes, unless the scene drawing it is a game being played. See a button in the HUD. |
The screen, here, is the game's area. Under [window] stretch
"letterbox" that is the design inside its bars, and what the frame lays out keeps clear
of them as it keeps clear of a phone's notch; see
scale and design units.
Align has the nine values you would guess, a
three-by-three grid of the vertical (TOP, CENTER, BOTTOM)
crossed with the horizontal (LEFT, CENTER, RIGHT):
TOP_LEFT, TOP_CENTER, TOP_RIGHT, CENTER_LEFT,
CENTER, CENTER_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER
and BOTTOM_RIGHT. A HUD in the corner is a placement and a smaller gap:
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .gap = 4 });
rmp::ui::text("Score " + std::to_string(score));
rmp::ui::text("Lives " + std::to_string(lives), { .color = rmp::ui::ColorRole::MUTED });
rmp::ui::end();On Android and iOS the root also keeps 24 design units clear at every edge, for the status bar and the notch.
Inside a scene, _draw() can hold more than one pair — the score in one corner, a
button in another — and they are drawn as parts of the same frame. In a game that runs its own loop,
keep to one pair per frame.
Each axis of a box is sized one of three ways, and there is no fourth:
| Sizing | Written | Means |
|---|---|---|
| Fit | nothing: the default | As big as its contents need. |
| Grow | grow_x, grow_y | Fill the space its parent offers on that axis — along a row or a column, shared with the siblings that grow too. |
| Fixed | width, height above 0 | That many design units, whatever else is set. |
A box that fits its contents, holding children that grow into it, is the pairing that makes the buttons of a menu the same width: the column is as wide as its widest button, and every other button grows to match.
The fields are interleaved by axis — grow_x, width, grow_y,
height — and not grouped by kind, because designated initialisers have to be written in
declaration order. This way round the most ordinary thing anyone writes, a sidebar of a fixed width
that fills the height, is legal:
rmp::ui::panel({ .box = { .width = 240, .grow_y = true } }, [&] {
rmp::ui::text("Sections");
});Grow
fills the parent, and the column that begin() opens fits its contents. So
grow_x on something directly inside it fills the width of that column — the width of
the widest thing next to it — and not the width of the screen. A menu wants exactly that, which is
why it is the default.
A screen laid out edge to edge — a sidebar beside a content area, a list as tall as the window —
asks for the other kind of frame. begin({ .grow = true })
makes the column fill the
window, less the padding, on both axes, so whatever grows inside it reaches the edges:
rmp::ui::begin({ .grow = true });
rmp::ui::row({ .grow_x = true, .grow_y = true }, [&] {
rmp::ui::panel({ .box = { .width = 200, .grow_y = true } }, [&] {
rmp::ui::text("Sections");
});
rmp::ui::panel({ .box = { .grow_x = true, .grow_y = true } }, [&] {
rmp::ui::text("World");
});
});
rmp::ui::end();What does not grow is still placed by placement: in a frame opened with
{ .placement = rmp::ui::Align::TOP_CENTER, .grow = true }, a line of text sits at the top
in the middle, and a row that grows beneath it takes the rest. Without grow, the frame
is the one the three-function menu is drawn in. The inventory
and responsive examples are both laid out this way.
Inside a frame that fits, a bar that has to be a given size gets that size: a fixed
width or height, in design units, which the scale turns into pixels with
everything else. Everything that grows inside it then has something to grow into:
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::row({ .width = 760 }, [&] {
rmp::ui::text("Inventory");
rmp::ui::spacer();
rmp::ui::text("24 / 40", { .color = rmp::ui::ColorRole::MUTED });
});
rmp::ui::end();A fixed width is a fixed number of design units: on a window wider than the [window]
resolution's shape, there is room left at the sides, because the scale follows the tighter axis.
Rows, columns and panels take BoxOptions — a
panel inside its .box — and three of its fields decide the space around things:
| Field | Default | Means |
|---|---|---|
gap | the theme's gap, 12 | Between children, in design units. |
padding | none; a panel's is the theme's panel_padding, 20 | Inside the container, the same on all four sides. |
items | Align::CENTER | Where the children sit in the space left over. |
items is the one that makes a card look like a card: a column of text is centred
unless it is told to hug the left.
rmp::ui::column({ .gap = 6, .items = rmp::ui::Align::CENTER_LEFT }, [&] {
rmp::ui::text("Rabbit", { .color = rmp::ui::ColorRole::PRIMARY });
rmp::ui::text("Level 7", { .color = rmp::ui::ColorRole::MUTED, .size = 14 });
});spacer() grows on both axes and eats the space left
over, which is how two things are pushed to opposite ends of a row. The row has to have space left
over for it to eat, so it is given a width or set to grow:
rmp::ui::panel({ .box = { .width = 300 } }, [&] {
rmp::ui::row({ .grow_x = true }, [&] {
rmp::ui::text("Health");
rmp::ui::spacer(); // shoves what follows to the right
rmp::ui::text("999");
});
});spacer(n) is the other one: a fixed box of n by n design
units, for breathing room in one place without changing the container's gap.
A panel is a column with a background, which is what
makes it visible, padding of the theme's panel_padding, and the theme's
corner_radius. PanelOptions holds the
layout in .box and the look after it:
| Field | Default | Means |
|---|---|---|
box | {} | The layout, as a column takes it, except that its padding defaults to the theme's panel_padding. |
background | the theme's panel | The fill. { 0, 0, 0, 0 } means the theme's. |
radius | the theme's corner_radius | Of the corners, in design units; 0 is square. |
border | none | An outline colour. Left unset, the theme's border is drawn only when the theme's border_width is above 0 — in the light theme, not in the dark one. |
border_width | 1 | The width of an outline you set, in design units. |
rmp::ui::panel({ .box = { .width = 260, .height = 70 },
.border = rmp::ui::current_theme().border },
[&] {
rmp::ui::center([&] {
rmp::ui::text("nothing here",
{ .color = rmp::ui::ColorRole::MUTED });
});
});rmp::ui::Panel empty{
.box = { .width = 260, .height = 70 },
.style = { .border = GRAY, .border_width = 1 },
};
void _draw() override {
rmp::ui::begin();
empty.show([&] {
rmp::ui::center([&] {
rmp::ui::text("nothing here",
{ .color = rmp::ui::ColorRole::MUTED });
});
});
rmp::ui::end();
}In the framework's themes a panel sits on a soft shadow, and fades and rises into place the first
frame it is drawn — see styles for that look and
how to take it away. A kept Panel can also be clicked,
and styles everything inside it: Panel.
center() grows on both axes and puts its contents
in the middle of what it grew into — so it centres within its parent, and its parent decides how much
room that is: a panel of a fixed size, a grid cell.
stack() puts things on top of each other. Every child
of a stack has to be a layer(); each layer fills the
stack, centres what is in it, and is drawn over the layers written before it:
rmp::ui::panel({ .box = { .width = 260, .height = 90 } }, [&] {
rmp::ui::stack([&] {
rmp::ui::layer([&] {
rmp::ui::image(portrait, { .grow = true, .tint = CLITERAL(Color){ 255, 255, 255, 60 } });
});
rmp::ui::layer([&] {
rmp::ui::text("PAUSED", { .color = rmp::ui::ColorRole::DANGER });
});
});
});The explicit layer() is not ceremony: it is what tells the layout which things are
meant to overlap and which are ordinary children. And because layers overlap, they take no room of
their own — a stack is as big as the space its parent gives it, so it goes inside something with a
size, like the panel above. In a box that only fits its contents, a stack has no size at all and
its layers spill over whatever comes next.
A grid lays its items out in equal columns and starts
a new row when one fills. Each item goes in a cell(),
which is what lets the grid count them; the layout engine underneath wraps text, not boxes, so the
rows are built as real rows:
rmp::ui::grid(4, [&] {
for (auto &item : inventory)
rmp::ui::cell([&] { rmp::ui::image(item.icon); });
});Every cell in a row is the same width, its share of the row, and what is in it is centred. A
cell() outside a grid is a plain box, so the mistake shows on screen instead of breaking
the frame.
With columns at 0 the grid works out
how many cells of min_cell design units,
each with its gap, fit in the width it had last frame, and works it out again as the window changes.
An inventory then reflows on a phone held upright instead of staying at the number someone typed on a
desktop. This is also the row that wraps: there is no wrap flag on row(), because
grid({ .columns = 0 }) is one.
rmp::ui::panel({ .box = { .width = 480 } }, [&] {
rmp::ui::grid({ .columns = 0, .min_cell = 88, .id = "inventory" }, [&] {
for (const std::string_view name : names)
rmp::ui::cell([&] { rmp::ui::text(name, { .size = 13 }); });
});
});It is never fewer
than one column and never more than fit. A grid too narrow for even one cell of
min_cell is one column, so the narrower it gets, the fewer columns it has, down to one.
Its first frame, with no width measured yet, is one column too, and it has its real count from the
second.
| Field | Default | Means |
|---|---|---|
columns | 0 | How many; 0 is as many as fit, and at least one. |
min_cell | 96 | The width a column needs, when columns is 0. |
gap | the theme's gap | Between cells and between rows. |
padding | none | Inside the grid. |
grow_x | true | Take the width it is offered. |
grow_y | false | Fill the parent's height instead of fitting the rows. |
id | none | Which grid it is, from frame to frame. See below. |
To work out its columns, a grid finds its own width from last frame, with or without a name. A
grid with an id finds itself by that name; one without is found by its order among the
unnamed grids of the same begin()/end(), and a grid that comes and goes
before it can make it borrow another's width. Name the ones that share a screen with
others that come and go.
scroll() clips its contents to its own box and
scrolls them: with the mouse wheel, or by dragging inside it — with a finger on a phone, with the
mouse on a desktop. It stops at the end of the contents. Neither gesture needs a line of code:
// The list. scroll() clips its contents; the wheel and a dragging finger both
// move it, and neither needs a line of code here. Each item says what it is
// with tooltip().
#include "inventory.h"
#include <rmp/ui.h>
#include <string>
void item_list() {
rmp::ui::panel({ .box = { .width = 240, .grow_y = true } }, [&] {
rmp::ui::text("All items");
rmp::ui::scroll({ .gap = 4, .id = "list" }, [&] {
for (int i = 0; i < ITEM_COUNT; ++i) {
// Two buttons could share a label across a long list, so the
// ids are made explicit. Identical labels in one frame are told
// apart automatically; this is for when you want the identity
// to survive the list being reordered.
const std::string id = "item" + std::to_string(i);
if (rmp::ui::button(items[i].name, { .id = id })) {
selected = i;
}
// About the button just above, and only that: shown when the
// pointer rests on it for half a second, or at once when the
// keyboard or a gamepad walks onto it. To the left, over the
// grid, where it hides no other item of the list.
rmp::ui::tooltip(items[i].description,
{ .side = rmp::ui::Align::CENTER_LEFT });
}
});
rmp::ui::text("scroll me", { .color = rmp::ui::ColorRole::MUTED, .size = 12 });
});
}
How big the area is follows the sizing rules. By default it grows on both axes: it takes the room
its parent gives it and clips there. The list above is in a panel that grows to the height of the
example's frame, which fills the window, and the area takes what
the panel has left once its two lines of text are in. Its rows never push a parent past
the window: where everything around it only fits its contents, the area is squeezed to the room the
window has left, and clips there.
height makes it a window of a fixed
size onto a longer list:
rmp::ui::scroll({ .height = 200, .id = "levels" }, [&] {
for (int i = 1; i <= level_count; ++i) {
if (rmp::ui::button("Level " + std::to_string(i))) play_level(i);
}
});| Field | Default | Means |
|---|---|---|
horizontal | false | Clip and scroll left to right. |
vertical | true | Clip and scroll top to bottom. |
gap | the theme's gap | Between children. |
padding | none | Inside the area. |
grow_x, width | true, 0 | Fill the parent's width, or a fixed one. |
grow_y, height | true, 0 | Fill the parent's height, or a fixed one. |
id | none | Which area it is, from frame to frame. |
Inside the area, children are laid out top to bottom whichever way it scrolls; a strip that
scrolls sideways is a row() inside a horizontal area. How far an area has scrolled is
remembered by the area, and an area without an id is told apart by its order among the
unnamed ones, as a grid is — so one that shares a screen with areas that come and go gets a name.
What is scrolled out of view cannot be clicked: only the part of a control inside the area takes the pointer, and the area itself — its empty part included — is the interface's, so a drag inside it scrolls the list instead of reaching the game.
The keyboard and the gamepad scroll it too, by moving the focus. When the focus lands on a control the area has clipped away, and its ring is showing, the area moves just far enough to show the control — and a list inside a scrolling page shows its row first, then the page shows the list. It happens once for each move of the focus, so the wheel or a finger can take the list somewhere else afterwards without being pulled back to it.
rmp::ui::image draws a texture. With no options it is
drawn at its own size, its pixels taken as design units, so an icon grows with the rest of the
interface instead of shrinking into nothing on a big screen.
ImageOptions changes that:
| Field | Default | Means |
|---|---|---|
grow | false | Fill the space available on both axes; the picture is stretched to it. |
width, height | 0 | A size in design units; 0 is the texture's own. |
tint | WHITE | Multiplies the picture's colours; WHITE leaves them as they are. |
rmp::ui::image(portrait, { .width = 96, .height = 96 });rmp::ui::Image face{ .picture = portrait,
.width = 96, .height = 96,
.on_click = [] { TraceLog(LOG_INFO, "hi"); } };
void _draw() override {
rmp::ui::begin();
face.show();
rmp::ui::end();
}What it draws is any rmp::ui::Picture: an
rmp::Texture, a part of one, the frame an
rmp::Sprite shows, a slice of an Aseprite file, a
nine-slice. Pictures says how each is made. A
picture holds counted handles, so the texture stays loaded until end() has drawn the
frame, and a temporary is safe:
rmp::ui::image(rmp::assets::load_texture("icon.png"), { .width = 40, .height = 40 });A raylib Texture2D is taken too, for a texture the game made itself — a render
texture, an image it generated. It is copied on the way in, but what is copied is a handle to
something on the GPU, so that texture has to stay loaded until end() has drawn the
frame:
rmp::ui::image(minimap.texture, { .width = 160, .height = 160 });rmp::ui::progress is a bar, filled to a fraction
from 0 to 1 — clamped, so a health of -5 draws empty rather than going wrong:
rmp::ui::progress(health, { .width = 180 });
rmp::ui::progress(mana, { .width = 180, .height = 8,
.fill = SKYBLUE });rmp::ui::ProgressBar health_bar{ .width = 180 };
rmp::ui::ProgressBar mana_bar{ .width = 180, .height = 8,
.fill = SKYBLUE };
void _draw() override {
health_bar.value = health;
mana_bar.value = mana;
rmp::ui::begin();
health_bar.show();
mana_bar.show();
rmp::ui::end();
}ProgressOptions:
width (0 fills the space available),
height (by default 0.6 of the theme's
type size), radius (by default half
the height, for round ends), fill and
track (the theme's
primary and surface unless set), and
id.
A bar drawn by the artist — a filled part that is a picture, its ends kept round by a
nine-slice — is a kept rmp::ui::ProgressBar with
a fill_picture; see
widgets you keep.
Containers are anonymous unless you give them an id —
BoxOptions::id, and the same field on a
panel's .box, a grid, a scroll area and a progress bar. A named one is the same element
from frame to frame, whatever else is on screen. Nothing needs it for a row, a column or a panel;
it is what a test uses to find one, and for grids and scroll areas it is their identity, as above.
rmp::ui::panel({ .box = { .id = "inventory" } }, [&] {
rmp::ui::text("Inventory");
});examples/ui/02_layout puts most of this page on one screen — a toolbar with a spacer,
a card of a row and a column, a stack, a centred placeholder — with bars that move so it is clear
the layout is rebuilt every frame:
// ---------------------------------------------------------------------------
// examples/ui/02_layout/src/main.cpp
//
// Containers: row, column, panel, center, stack, spacer — plus image and
// progress, the two widgets that only make sense once you have somewhere to
// put them.
//
// The rule that shapes all of it: a container takes its contents as a lambda.
// There is no closing call to forget, because the compiler closes it for you.
// Capture with [&] when the body needs your variables, which is most of the
// time.
//
// Every measurement below is in DESIGN UNITS, at the [window] resolution from
// raylib_multiplatform.toml. rmp::ui multiplies them by the current scale, so
// `width = 200` is 200 at your design Size, 400 at twice it, and never a
// hard-coded pixel count that looks right on exactly one monitor.
//
// Run it: `rmp example 02_layout`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <string>
class LayoutScene : public rmp::Scene {
public:
void _ready() override {
// Resize the window and watch everything follow.
_portrait = rmp::assets::load_texture("rabbit.png");
}
void _update(float delta) override {
// Bars that move, so the layout is doing something rather than sitting
// still -- and so it is obvious the numbers are read fresh every frame.
_health -= delta * 0.05f;
if (_health < 0) _health = 1.0f;
_mana += delta * 0.08f;
if (_mana > 1) _mana = 0.0f;
}
void _draw() override {
// begin() is a centred column. placement moves the whole thing: this one
// hugs the top-left corner, like a HUD would.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .gap = 14 });
toolbar();
character_card();
banner();
empty_slot();
if (rmp::ui::button("Done")) rmp::app::quit();
rmp::ui::end();
}
private:
// An rmp::Texture, not a Texture2D. The handle OWNS the texture; a raw
// Texture2D copied out of the temporary would have been unloaded on the
// same line, before the next statement ran.
rmp::Texture _portrait;
float _health = 0.72f;
float _mana = 0.35f;
// -------------------------------------------------------------------
// row and column: the two directions
// -------------------------------------------------------------------
void character_card() {
// panel = a column with a background and padding. It is what you put
// a dialog, a card or a tooltip inside.
rmp::ui::panel([&] {
// row lays out left to right.
rmp::ui::row({ .gap = 16 }, [&] {
rmp::ui::image(_portrait, { .width = 72, .height = 72 });
// column lays out top to bottom. items decides where children
// sit across the other axis -- here, hard against the left
// instead of centred, which is what makes a card look like a
// card.
rmp::ui::column({ .gap = 6, .items = rmp::ui::Align::CENTER_LEFT }, [&] {
rmp::ui::text("Rabbit", { .color = rmp::ui::ColorRole::PRIMARY });
rmp::ui::progress(_health, { .width = 180 });
rmp::ui::progress(_mana,
{ .width = 180, .height = 8, .fill = SKYBLUE });
rmp::ui::text("Level 7",
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
});
});
});
}
// -------------------------------------------------------------------
// spacer: how you push things apart
// -------------------------------------------------------------------
static void toolbar() {
// grow_x makes the row take the full width it is offered; without it
// the row would shrink to fit its contents and the spacer would have
// nothing to eat.
rmp::ui::row({ .grow_x = true }, [&] {
rmp::ui::text("Inventory");
rmp::ui::spacer(); // <- takes everything left over
rmp::ui::text("24 / 40", { .color = rmp::ui::ColorRole::MUTED });
});
// spacer(n) is the other one: a fixed gap, when you want breathing
// room in one specific place rather than changing the container's gap.
rmp::ui::spacer(8);
}
// -------------------------------------------------------------------
// stack and layer: things on top of each other
// -------------------------------------------------------------------
void banner() {
rmp::ui::panel({ .box = { .width = 260, .height = 90 } }, [&] {
// Every child of a stack has to be a layer(). That is not
// ceremony: it is what says "these are meant to overlap" instead
// of "these are ordinary children in a column". Later layers draw
// on top.
rmp::ui::stack([&] {
rmp::ui::layer([&] {
rmp::ui::image(
_portrait,
{ .grow = true, .tint = CLITERAL(Color){ 255, 255, 255, 60 } });
});
rmp::ui::layer([&] {
rmp::ui::text("PAUSED", { .color = rmp::ui::ColorRole::DANGER });
});
});
});
}
// -------------------------------------------------------------------
// center: fill what you were given, put the contents in the middle
// -------------------------------------------------------------------
static void empty_slot() {
rmp::ui::panel({ .box = { .width = 260, .height = 70 },
.border = rmp::ui::current_theme().border },
[&] {
rmp::ui::center([&] {
rmp::ui::text("nothing here",
{ .color = rmp::ui::ColorRole::MUTED });
});
});
}
};
RMP_GAME(LayoutScene);
// ---------------------------------------------------------------------------
// The Sizing model, in three lines
// ---------------------------------------------------------------------------
//
// default fit — as big as the contents need
// grow_x/grow_y fill the space the parent is offering
// width/height a fixed number of design units, overriding both
//
// A container fits its contents; a child with grow expands to fill whatever
// the container ended up being. That pairing is what makes the buttons in a
// menu come out the same width without anyone measuring anything.
//
// NAMING A CONTAINER. Every container takes an optional `.id`: a stable name,
// the same element from frame to frame whatever else is on screen.
//
// rmp::ui::panel({ .box = { .id = "inventory" } }, [&]{ ... });
//
// Unnamed containers are anonymous, which is right for almost all of them.
https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html
Four controls own a value: a checkbox, a slider, a dropdown and a text field. Each one takes your variable, by reference, and writes to it, and that is the whole of their state model — there is no widget object holding a copy, and nothing to keep in sync. For a screen designed widget by widget there are also widgets you keep, each with its own style and callbacks, and every control sends events.

rmp::ui::begin();
rmp::ui::checkbox("Fullscreen", settings.fullscreen);
rmp::ui::slider("Music", settings.music, 0.0f, 1.0f);
rmp::ui::dropdown("Quality", settings.quality, { "Low", "Medium", "High" });
rmp::ui::text_input("Name", settings.name);
rmp::ui::end();Every control reads your variable and writes it back in the same call, so what is on screen is what is in your struct because it was read this frame. Delete the screen and the settings still exist: they were never the interface's. The struct stays plain data, which is also what makes it easy to save:
#pragma once
// Plain data. This is the whole model, and it is the point of the example: the
// controls take a field of this, by reference, and write to it. Delete the UI
// and your settings still exist; they were never ours.
#include <array>
#include <string>
#include <string_view>
struct Settings {
bool fullscreen = false;
bool vsync = true;
bool subtitles = false;
float master = 0.8f;
float music = 0.5f;
float sensitivity = 0.35f;
int quality = 1;
int language = 0;
std::string player; // "Player" until the player says otherwise: see _ready()
};
// What the two dropdowns offer: a std::array the dropdown takes as a span, so
// nobody has to tell it how long the list is.
inline constexpr std::array<std::string_view, 4> QUALITY{ "Low", "Medium", "High",
"Ultra" };
inline constexpr std::array<std::string_view, 3> LANGUAGE{ "English", "Espanol",
"Francais" };
Each control returns true on the frame its value changed, so "do something when it
changes" reads the way it sounds:
if (rmp::ui::checkbox("Fullscreen", cfg.fullscreen)) apply(cfg);The variable stays yours: the control reads it and writes it during the call, and keeps nothing of it afterwards.
What the interface does keep is the state that means nothing to your game — whether a dropdown is
open, whether a slider is being dragged — and it keeps it by the control's id, which is its label
unless you give it an id. The rules are the ones for buttons, in
labels are ids.
Each control is a row: a slider, a dropdown and a text field put their label on the left and the
control after it; a checkbox puts its box first and the label after it. The row fills the width
it is offered and is focusable as one thing, so the focus ring goes around the whole row and the
keyboard and gamepad reach it like a button (see
focus, keyboard and gamepad). The label
is drawn at the theme's font_size.
A checkbox, a dropdown and a text field count a click the way a button does: the press has to start on the control and the release end on it. A release alone is not a click, so a drag that starts in the game and ends on a settings panel ticks no box, opens no list and starts no typing. The items of an open dropdown are clicked the same way.
All four options structs have the two fields buttons have:
enabled — false draws the control in the theme's
disabled colours: its label in disabled_text, and a checkbox's box, a slider's filled
part and a text field's field in disabled. A dropdown greys only its label and value;
its field keeps the theme's surface. A disabled control cannot be changed, and the
focus skips it. A control that is unavailable right
now reads better disabled than missing: a menu whose items appear and disappear is a menu nobody can
learn.id — a name that is the same control whatever its label says, for
two controls that share a label on a screen that changes.rmp::ui::checkbox flips a bool when
its row is clicked, or when it is pressed — Enter, Space, the bottom face button — while it has the
focus. It returns true on the frame it flipped:
if (rmp::ui::checkbox("Light theme", light))
rmp::ui::set_theme(light ? rmp::ui::theme_light()
: rmp::ui::theme_dark());rmp::ui::Checkbox light{
.text = "Light theme",
.on_change = [](bool on) {
rmp::ui::set_theme(on ? rmp::ui::theme_light()
: rmp::ui::theme_dark());
},
};
void _draw() override {
rmp::ui::begin();
light.show();
rmp::ui::end();
}The box is filled with the theme's primary and carries a dot when the value is
true, and is the theme's surface inside a border when it is
false — a difference that reads at a glance without a tick, which the built-in font
does not have. Its size is the theme's
control_size.
CheckboxOptions is
enabled and
id.
rmp::ui::slider sets a float between a
minimum and a maximum:
if (rmp::ui::slider("Music", music, 0.0f, 1.0f))
rmp::audio::set_volume(rmp::audio::Bus::MUSIC, music);
rmp::ui::slider("Sensitivity", sensitivity, 0.0f, 1.0f,
{ .step = 0.05f });rmp::ui::Slider music{
.text = "Music",
.value = 0.8f,
.on_change = [](float v) {
rmp::audio::set_volume(rmp::audio::Bus::MUSIC, v);
},
};
rmp::ui::Slider sensitivity{ .text = "Sensitivity",
.value = 0.35f, .step = 0.05f };
void _draw() override {
rmp::ui::begin();
music.show();
sensitivity.show();
rmp::ui::end();
}wants_pointer()
stays true — even when the pointer leaves the rail.step, or 5 % of the range when there is none, so a controller can move a slider of
any range.The value is clamped to the range, and snapped to step when there is one, on every
call — not only when it is touched. A variable that starts outside the range is corrected on the
first frame, and the slider returns true for that frame like for any other change.
Nothing is drawn when max is not above min.
| Field | Default | Means |
|---|---|---|
width | 0 | Of the rail, in design units; 0 fills the space available. |
step | 0 | 0 is continuous; otherwise the value snaps to min plus a multiple of it. |
enabled | true | As above. |
show_value | true | Draw the position after the rail, as a percentage of the range. |
id | none | As above. |
The number show_value draws is where the handle is, not the value: a slider from 0 to
60 standing at 30 shows 50%. A screen that wants the value itself turns it off and draws it with
text().
rmp::ui::dropdown picks one string of a list.
The value it writes is an index into that list:
if (rmp::ui::dropdown("Quality", quality,
{ "Low", "Medium", "High", "Ultra" }))
apply_quality(quality);rmp::ui::Dropdown quality{
.text = "Quality",
.items = { "Low", "Medium", "High", "Ultra" },
.selected = 1,
.on_change = [](int index) { apply_quality(index); },
};
void _draw() override {
rmp::ui::begin();
quality.show();
rmp::ui::end();
}The list can be written in place, as there, or kept somewhere — a std::array, a
std::vector or a plain array of std::string_view — and handed over as
it is, because the dropdown takes a std::span of them and the span knows its length.
settings.h above keeps its two lists that way.
A click on it opens the list, which floats over whatever is below instead of pushing it down the
screen. A click on an item picks it and closes the list; a click anywhere else closes it. The return
value is true when a different item was picked. While the list is open it is in front
of everything else in the scene: wants_pointer() is true wherever the pointer is, and a
click on the list does not reach what is behind it.
A controller has to be
able to pick from a list it can open, so the keyboard and the gamepad work the whole of it. While the
dropdown has the focus, Enter, Space or the bottom face button opens the list. Open and focused, the
list takes the keys that would move the focus — Up and Down, the d-pad, the stick — for itself: they
walk a highlight that starts on the current value and stops at the first and the last item, and once
the player has used a key it lights up the way an item under the pointer does. Enter, Space or the
bottom face button picks the highlighted item and closes the list, returning true if it
is a different one; Escape or the right face button closes it and changes nothing.
The index is clamped into the list on every call, so a value read from an old save cannot point
past the end of a shorter list. Nothing is drawn for an empty list. The strings are copied as they
are drawn, so they only have to live through the call — which is what lets a list written in place
be a temporary.
DropdownOptions is
width — of the field, in design
units, 0 filling the space available — enabled
and id. Two dropdowns that both have a
"Low" in them are still two lists: an item belongs to its dropdown, not to its text.
rmp::ui::text_input edits a
std::string of yours, in UTF-8:
static std::string name;
rmp::ui::text_input("Name", name,
{ .placeholder = "your name",
.max_length = 16 });rmp::ui::TextInput name{ .text = "Name",
.placeholder = "your name",
.max_length = 16 };
void _draw() override {
rmp::ui::begin();
name.show(); // what is typed is name.value
rmp::ui::end();
}While
the field is typing — which is not the same as having the focus; see
below — what the player types is added at the end, any
character but a control character, and Backspace removes the last character, never half of one,
repeating while it is held. A blinking _ marks the end of the text. There is no caret
to move, no selection and no clipboard. Typing arrives through raylib's
GetCharPressed(); the field does not open an on-screen keyboard on Android or iOS.
The return value is true on the frames the text changed.
TextInputOptions:
| Field | Default | Means |
|---|---|---|
width | 0 | Of the field, in design units; 0 fills the space available. |
enabled | true | As above. |
placeholder | none | Shown in the theme's text_muted while the field is empty and not typing. It is copied, so a temporary is fine. |
id | none | As above. |
max_length | 0 | The most characters it holds; 0 is no limit. |
A
max_length counts characters, which is what a player counts: an é is one,
not the two bytes it takes. Typing stops at it. A string longer than that — one you hand in, or one
left by a max_length that came down — is cut to it when the field is drawn, at the end
of a character, and the field returns true for that frame like for any other change.
An empty label draws the field alone.
A field types only while it has the keyboard, and the keyboard is not the focus. The focus says which control Enter would press; the keyboard says which field the keys are typed into. The focus can rest on a field that is not typing, and a player who reaches a field with a controller can always leave it again.
rmp::ui::focus() — and when Enter, Space or the bottom face button is pressed while it
has the focus. The focus a screen gives its first control by itself is not one of those: a screen
whose first control is a name field opens with the field focused and not typing.While a field is typing, rmp::ui::wants_keyboard()
is true, and every rmp::input action reads its keys, gamepad
buttons and sticks as not pressed; only its mouse buttons still count. Typing "Wolf" into a name
field does not walk the player across the level. A field that has the focus and not the keyboard
leaves them alone, so once the player presses Enter the game hears its keys again.
The settings example puts all four on one screen over
the Settings struct above: toggles, two volume sliders that drive the audio buses, a
stepped slider, two dropdowns and a name field, with Revert and Apply buttons that are disabled until
something changes, and the struct saved with rmp::save when
it is applied.
rmp example 04_settingsEverything above is immediate: a call each frame, and nothing to keep. That is the simple way, and the three-function menu stays exactly that. A screen that is designed rather than written — each button with its own look, an icon, its sounds, and something to run when it is clicked, hovered or focused — is easier to read as objects you keep, the way a Godot scene keeps its nodes: members of your scene, set up once with designated initialisers, and shown each frame where they go.
rmp::ui::Button play{
.text = "Play",
.variant = rmp::ui::Variant::PRIMARY,
.style = { .shadow = rmp::ui::Shadow{} },
.on_click = [this] { change<GameScene>(); },
};
rmp::ui::Button quit{ .text = "Quit", .on_click = [] { rmp::app::quit(); } };
void _draw() override {
rmp::ui::begin();
play.show();
quit.show();
rmp::ui::end();
}show() puts the widget in the layout like the immediate call of the same name —
between begin() and end(), in a row, a column, a panel — and is drawn by the
same code, so it lays out, navigates and is hit-tested exactly as that call is. The callbacks run
inside show(), on the frame the thing happened, in the order it happened. A widget that
is kept and not shown is not on screen and hears nothing.
play.text = "Continue"; and
the next show() draws it.rmp::Callbacks, which hold lambdas that capture what they
like, a std::unique_ptr too, and cannot be copied; keep the widget where it lives.ours, a
KeptState —
hovered,
pressed,
focused and the
shakes not yet started. It is public only so
the widget stays a struct you can write with designated initialisers; read it with the methods
hovered(), pressed() and focused().shake() shakes it side to side by its style's
Motion, plays its shake
sound and sends EventKind::SHAKE: "that did
not work". It starts at the next show().style is its own style,
over everything around it, and id is the
same id the immediate calls take.The callbacks, each one optional — an empty one is not called:
| Callback | Runs when | On |
|---|---|---|
on_click | it was clicked: released on it after a press on it, or Enter or the gamepad's A with the focus | Button, Label, Image, Panel |
on_hover | the pointer arrived on it | all nine |
on_unhover | …and left | all nine |
on_press | the pointer went down on it | Button, Image, Panel |
on_release | …and came up, on it or not | Button, Image, Panel |
on_focus | the keyboard or gamepad focus arrived | Button and the four value controls |
on_blur | …and left | Button and the four value controls |
on_change | its value changed, with the new value | Checkbox (bool), Slider (float), Dropdown (int, the index), TextInput (std::string_view, the text) |
A pointer that arrives on a button gives it the focus too, so moving onto one and clicking it runs
on_hover, on_focus, on_press, on_release and
on_click, over as many frames as the player took. show() also returns what
the immediate call would — true on the frame it was clicked, or changed — so
if (play.show()) works as well as on_click.
rmp::ui::Button: text, an icon, or both.
rmp::ui::Button settings{ .text = "Settings",
.icon = gear_icon,
.icon_size = 24,
.on_click = [] { open_settings(); } };
rmp::ui::Button tool{ .icon = gear_icon, .icon_above = true, .id = "tool" };| Field | Default | Is |
|---|---|---|
text | "" | The label; empty for a button that is only its icon. |
icon | none | A picture before the label, or alone. |
icon_size | 0 | The icon's height in design units; 0 is the label's type size, or the picture's own height when there is no label. |
icon_above | false | true puts the icon over the label, as a toolbar tile. |
variant | NORMAL | What it means, as ButtonOptions::style. |
size | the theme's | A step or design units, as ButtonOptions::size. |
width, height | 0 | Above 0, a fixed size in design units; 0, sized as button() is. |
enabled | true | false: disabled colours, no press, no focus. |
id | "" | Only for two buttons with one label. |
style | empty | Its look. |
on_click, on_hover, on_unhover, on_press, on_release, on_focus, on_blur | empty | See the table above. |
show() is true on the frame it
was clicked; hovered(),
pressed() and
focused() say what it is doing now. An
icon-only button has no padding and is the size of its picture, as
image_button() is.
rmp::ui::Label is text as text() draws
it, with a style of its own — a title in another font, with an outline — and clickable when it has an
on_click:
rmp::ui::Label credits{ .text = "Credits",
.color = rmp::ui::ColorRole::MUTED,
.on_click = [] { rmp::ui::notify("Made with raylib"); } };Its fields: text;
color, a ColorRole used when the style
sets no text colour; size and
wrap, as TextOptions has them;
id; style;
and on_click, on_hover, on_unhover.
show() is true on the frame it was
clicked, and hovered() says whether the
pointer is on it.
rmp::ui::Image is a picture with a style — a frame
behind it, a shadow, a tint — that can be clicked. With a
sprite that has a sheet, it plays the sprite's
animation, one step of the game's clock every show():
rmp::ui::Image coin{ .sprite = rmp::Sprite{ .sheet = rmp::assets::load_sheet("coin.aseprite") },
.width = 32,
.height = 32 };
coin.sprite.play("spin");| Field | Default | Is |
|---|---|---|
picture | none | What it shows, unless sprite has a texture or a sheet. |
sprite | none | An animated picture, advanced every show(). |
grow | false | Fill the space available, as ImageOptions::grow. |
width, height | 0 | Above 0, a fixed size in design units; 0, the picture's own. |
enabled | true | false: never clicked. |
id | "" | Its id; images have no label to go by. |
style | empty | Tint, a skin behind it, a shadow, a border. |
on_click, on_hover, on_unhover, on_press, on_release | empty | See above. |
show() is true on the frame it was
clicked; hovered() and
pressed() say what it is doing.
rmp::ui::Panel is a container with a look of its own,
style, and a look for everything inside it,
children — see
a look for everything
inside a container. Its show() takes what goes inside it, as panel()
does, and it is clickable as a whole when it has an on_click: an inventory slot, a
card.
rmp::ui::Panel slot{ .box = { .width = 64, .height = 64 },
.id = "slot-1",
.style = { .background = DARKGRAY },
.on_click = [] { equip(1); } };
slot.show([] { rmp::ui::text("Sword"); });| Field | Default | Is |
|---|---|---|
row | false | Its children left to right; false, top to bottom. |
box | fit | Its layout — sizing, padding, gap, alignment — as panel() takes it. |
background | true | false: a bare row or column, with no fill unless its style gives one, that still styles its children. |
id | "" | Its id: one per clickable panel, so each is told apart. |
style, children | empty | Its look, and the look of everything inside it. |
on_click, on_hover, on_unhover, on_press, on_release | empty | See above. |
show(body) lays it out with body
inside it and is true on the frame it was clicked;
hovered() and
pressed() say what it is doing.
The four value controls, each holding its own value instead of writing to yours. Their fields are the immediate control's options, plus the value and the callbacks:
rmp::ui::Checkbox fullscreen{ .text = "Fullscreen", .on_change = [](bool on) { (void)on; } };
rmp::ui::Slider music{ .text = "Music",
.value = 0.5f,
.step = 0.1f,
.on_change = [](float v) {
rmp::audio::set_volume(rmp::audio::Bus::MUSIC, v);
} };
rmp::ui::Dropdown quality{ .text = "Quality",
.items = { "Low", "Medium", "High" },
.selected = 1 };
rmp::ui::TextInput name{ .text = "Name", .placeholder = "Your name", .max_length = 16 };| Widget | Its value | Its other fields |
|---|---|---|
Checkbox | checked (false) | text, enabled, id, style |
Slider | value (0), kept from min (0) to max (1) | text, step, width, show_value, enabled, id, style |
Dropdown | selected (0), an index into items | text, width, enabled, id, style |
TextInput | value (""), what is typed | text (its label), placeholder, max_length, width, enabled, id, style |
Each has on_change with the new value, on_hover,
on_unhover, on_focus and on_blur. Each one's show()
is true on a frame its value changed, and hovered() and
focused() say what it is doing. What every field means is what the immediate control's
option of the same name means, above.
rmp::ui::ProgressBar is a bar with a look of its
own: the style is the track's — its background, its skin — and
fill and
fill_picture are the bar's. A
nine-slice as the fill stretches with the bar and keeps its ends:
rmp::ui::ProgressBar hp{ .value = health, .width = 200, .fill_picture = bar_art };
hp.show();| Field | Default | Is |
|---|---|---|
value | 0 | From 0 to 1, clamped. |
width | 0 | In design units; 0 fills the space available. |
height | -1 | -1 is from the type size. |
radius | -1 | -1 is round ends. |
fill | none | The bar's colour; none is the theme's primary. |
fill_picture | none | The filled part as a picture, tinted by the style's tint. |
id, style | As every other. | |
on_hover, on_unhover | empty | A bar is never pressed. |
show() returns nothing, and
hovered() says whether the pointer is on
it: what a bar's tooltip needs.
Everything a control does, as it happens, is an Event:
the pointer arriving and leaving, a press, a click, the focus coming and going, a value changing.
The sounds of the theme and of a style play on
these; on_event() is one hook for everything else —
a vibration on a phone, a particle, a counter for achievements. Every control sends them, the ones
written as rmp::ui::button("Play") too:
rmp::ui::on_event([](const rmp::ui::Event &e) {
if (e.kind == rmp::ui::EventKind::CLICK) ++clicks;
});An event has three fields: kind, what happened;
widget, a
WidgetKind — BUTTON,
LABEL, IMAGE, PANEL, CHECKBOX, SLIDER,
DROPDOWN, TEXT_INPUT or PROGRESS; and
name, the control's label, or its id when it has
one, valid during the call only.
EventKind | When |
|---|---|
HOVER | the pointer arrived on it |
UNHOVER | …and left |
PRESS | the pointer went down on it |
RELEASE | the pointer came up after a PRESS, on it or not |
CLICK | it was pressed: released on it, or Enter or the A button with the focus |
FOCUS | the keyboard or gamepad focus arrived |
BLUR | …and left |
CHANGE | a checkbox, slider, dropdown or text field changed its value |
OPEN | a dropdown opened its list |
CLOSE | …and closed it |
SHAKE | a kept widget's shake() started |
An event's sound plays first, then the hook. There is one hook: setting it again replaces it, and
rmp::ui::on_event({}) turns it off. A kept widget's own callbacks run in its
show(), after the hook has heard the same thing.
https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html
A control in rmp::ui says what it means — primary, danger, a
muted line of text — and how important it is — small, medium, large — and the theme decides what
that looks like. Restyling a game is then one theme, and no call site is revisited. When one widget,
or one screen, has to look like nothing else — a shop drawn by an artist, a title with an outline,
a button that grows under the pointer — a style says so for that widget and
everything inside it, over the theme, and the simple calls stay as they are.


rmp::ui::button("Start game", { .style = rmp::ui::Variant::PRIMARY, .size = rmp::ui::Size::LARGE });
rmp::ui::text("v1.0.2", { .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });A rmp::ui::Theme is plain data: every colour the
widgets are drawn with, as raylib's Color, and every metric, in design units. There is no
inheritance, no cascade and no stylesheet. Customising one is assignment — copy it, change what you
want, set it back:
rmp::ui::Theme theme = rmp::ui::current_theme();
theme.primary = GOLD;
theme.primary_hover = YELLOW;
theme.primary_press = ORANGE;
theme.corner_radius = 0; // square corners
rmp::ui::set_theme(theme);current_theme() returns the one theme in
use, and set_theme() copies a new one over it.
Anything drawn after the call uses the new one, in the same frame. Both work at any time, before the
window exists too.
Two themes come with the framework, theme_dark()
and theme_light(). Each returns a copy, so the same
copy-modify-set works on top of either. Which one the game starts with is [ui] theme:
[ui]
theme = "light"Only those two names exist, and a typo is refused when the configuration is read instead of falling back to dark at runtime:
[ui]
theme = "blue" raylib_multiplatform.toml:2: theme = "blue"
^^^^^^^^^^^^^^
configure: error: [ui] theme has to be one of dark, light, got 'blue'.
It only picks which one the app starts with — rmp::ui::set_theme() changes it at runtime.After that it is a runtime call, so an appearance setting in the game is one line:
if (rmp::ui::checkbox("Light theme", light))
rmp::ui::set_theme(light ? rmp::ui::theme_light() : rmp::ui::theme_dark());The dark theme is a default-constructed Theme; its values are the member initialisers
in include/rmp/ui.h. The light one is not the dark one with the numbers flipped. A dark
interface separates its surfaces with their own shadows and a light one has none, so the light theme
sets border_width to 1, and normal buttons
and panels get an outline that keeps a pale button on a pale page a button. Its accents are darker,
because the blue that reads as bright on near-black looks washed out on near-white, and white text on
it stops being legible.
Each colour of the theme has a job, and these are all of them:
| Field | Paints |
|---|---|
background | Behind the interface. No widget paints it: a game of scenes is cleared with it every frame unless the scene sets its own background; a loop of your own passes it to ClearBackground(). |
panel | A panel, and a dropdown's open list. |
surface | A normal button at rest, the field of a dropdown and of a text field, a slider's rail, an unticked checkbox, the track of a progress bar. |
surface_hover, surface_press | A normal, outline or ghost button under the pointer, and while the pointer is held down on it; also a checkbox's row, a dropdown's field and the items of its open list. |
border | An outline button, an unticked checkbox, a dropdown's open list; and normal buttons and panels when border_width is above 0. |
text | Text, the labels of normal, outline and ghost buttons and of every control. |
text_muted | Muted text, a slider's percentage, a text field's placeholder. |
text_on_accent | The label of a primary or danger button, and the dot of a ticked checkbox. |
primary, primary_hover, primary_press | A primary button in its three states; also primary text, a ticked checkbox, the filled part of a slider and of a progress bar. |
danger, danger_hover, danger_press | A danger button in its three states; also danger text. |
disabled, disabled_text | The fill and the label of a button or control whose enabled is false: the fill is a button's, a checkbox's box, a slider's filled part and a text field's field. A disabled dropdown keeps surface for its field and greys only its label and value. |
focus | The ring around whatever the keyboard or gamepad is on. A controller build cannot be used without it, which is why it is the theme's and not each widget's. |
Text picks one of four of these through a ColorRole,
never a colour of its own: TEXT is text, MUTED is
text_muted, PRIMARY is primary and DANGER is
danger.
A button's style is a Variant: what
the button is for, not what colour it is.
| Variant | For | Looks |
|---|---|---|
NORMAL | Most buttons; the default. | A filled surface. |
PRIMARY | The one thing you want pressed on this screen. | primary, with text_on_accent. |
DANGER | Something destructive, which should look it. | danger, with text_on_accent. |
OUTLINE | A secondary action. | An outline and a label; it fills in under the pointer. |
GHOST | Toolbars, "back" links. | The label alone, in either theme, until the pointer is on it. |
rmp::ui::row({ .grow_x = true }, [&] {
rmp::ui::button("Start game", { .style = rmp::ui::Variant::PRIMARY });
rmp::ui::button("Load");
rmp::ui::button("Settings", { .style = rmp::ui::Variant::OUTLINE });
rmp::ui::button("Back", { .style = rmp::ui::Variant::GHOST });
rmp::ui::button("Delete", { .style = rmp::ui::Variant::DANGER });
});Being disabled is not a sixth variant, because it can happen to any of them: it is the
enabled flag, and a disabled button of any variant is drawn in disabled and
disabled_text.
Anywhere a size is asked for — a button's, a text's — the same field takes one of three steps of the theme's type scale, or a plain number of design units:
rmp::ui::button("Play", { .size = rmp::ui::Size::LARGE });
rmp::ui::text("Chapter One", { .size = 34 });| Step | Theme field | Default |
|---|---|---|
Size::SMALL | font_size_small | 0.8 × [ui] font_size |
Size::MEDIUM | font_size | [ui] font_size, 20 unless set |
Size::LARGE | font_size_large | 1.4 × [ui] font_size |
The steps are what to reach for almost always: they come from the theme, so they stay in proportion when someone changes the type scale. A number is the escape hatch — for a title, not for a button. It is one field that takes two spellings rather than two fields that could disagree.
On a button the step moves the type, the padding and the minimum height together, so a large
button is large all over and not a normal one with bigger letters. The one exception is a touch
screen: on Android and iOS no button is shorter than min_touch_size, small ones
included. The labels of checkboxes, sliders, dropdowns and text fields are always at
font_size.
The three type sizes are three fields of the theme. Changing font_size moves the
medium step only, so making all the text bigger is all three:
rmp::ui::Theme theme = rmp::ui::current_theme();
theme.font_size *= 1.15f;
theme.font_size_small *= 1.15f;
theme.font_size_large *= 1.15f;
rmp::ui::set_theme(theme);The rest of the theme is measurements, every one in design units:
| Field | Default | Is |
|---|---|---|
padding_x | 20 | Inside a button, left and right of the label. |
padding_y | 12 | Inside a button, above and below it. |
gap | 12 | Between siblings. |
panel_padding | 20 | Inside a panel, and around what begin() lays out. |
corner_radius | 8 | Of buttons, panels and the controls' fields; 0 is square. |
border_width | 0 dark, 1 light | The outline of normal buttons and of panels; 0 draws none. |
control_size | 22 | A checkbox's box, and the height of a slider's drag area. |
track_thickness | 6 | A slider's rail. |
focus_ring | 2 | The outline on the focused control. |
min_touch_size | 44 | The shortest a button can be: Apple's touch-target guidance, close to Material's 48 dp. It follows a button's type size, except on Android and iOS. |
transition | 0.12 | Seconds, not design units: how long a colour takes to change. See below. |
Controls fade between their colours — at rest, under the pointer, pressed — instead of snapping,
and a checkbox's box fills in instead of switching. There is nothing to opt into and one knob,
transition, the time a change takes. A control seen for the first time starts at the
colour it should have, so nothing fades in from nowhere.
A transition moves only colour. Nothing about the layout is animated, so a
control is always exactly where it was drawn and an animation can never make the player miss what
they aimed at. A style's motion — growing under the pointer, a panel sliding
in — moves the drawing and never the layout either, and is off unless a game asks for it.
transition = 0 turns it off — every control takes its new colour on the frame it
changes — which is what a "reduce motion" setting does:
rmp::ui::Theme theme = rmp::ui::current_theme();
theme.transition = reduce_motion ? 0.0f : 0.12f;
rmp::ui::set_theme(theme);Two mechanisms make an interface fit a screen, and knowing which to reach for is most of the skill. The scale makes everything bigger or smaller together; it is automatic, and you rarely touch it. A breakpoint changes the shape of a layout, which no amount of growing, fitting or fixing can do: on a phone held upright, a sidebar beside the content has to go above it.
if (rmp::ui::compact()) {
rmp::ui::column([&] { sidebar(); content(); });
} else {
rmp::ui::row([&] { sidebar(); content(); });
}current_breakpoint() classifies the
screen by its aspect ratio, width over height, and
compact() is the case that comes up:
| Breakpoint | Width ÷ height | In practice |
|---|---|---|
COMPACT | below 1 | A phone held upright, a narrow window. |
MEDIUM | 1 up to 1.6 | A tablet, a small desktop window, 4:3. |
EXPANDED | 1.6 and wider | An ordinary desktop, a TV, a phone on its side. |
Aspect ratio and not pixels, deliberately: a pixel threshold would call a phone 1080 pixels wide
a desktop, and the scale has already dealt with how big everything is. What is left — the only thing
that decides whether a row still fits — is how wide the screen is next to how tall. It reads the
window's size when it is called, so it needs no begin() first; a window with no height
yet is MEDIUM.
More
exactly, it is the shape of the game's area. Under
[window] stretch
"letterbox" — the default of a game rmp new makes — that is the design
inside its bars, the same shape whatever the window does, and the breakpoint never changes. An
interface that should change shape with the window wants "none" or
"expand", which give it the whole window; the responsive example sets
NONE for that reason.
Reach for a breakpoint when the layout has to become a different layout. Using one to pick a size undoes the work the scale already did, and is how a layout ends up right on exactly one machine. The responsive example turns a sidebar and its content from a row into a column as the window is resized.
A rmp::ui::Style is how one thing looks: a
button, a panel, a line of text. Every field is optional, and a field left unset is taken from around
it. A widget you keep has one in
its style field:
const rmp::ui::Style gold{
.background = GOLD,
.radius = 0,
.shadow = rmp::ui::Shadow{},
.text = BLACK,
.text_outline = rmp::ui::TextOutline{ .color = WHITE },
};
rmp::ui::Button buy{ .text = "Buy", .style = gold };The fields are written in the order they are declared — C++20 requires it of designated initialisers — and they are declared in the order you would think of them: the box, its spacing, its text, and how it feels.
| Field | Type | Is |
|---|---|---|
background | Color | The fill of the box. On a button, a checkbox, a dropdown or a field, the hover and press colours are worked out from it — a little lighter, a little darker — unless the next two give them. |
background_hover | Color | The fill under the pointer. Given without a background, it is used alone over the theme's fill. |
background_press | Color | The fill while held down; alone too, like the one above. |
background_disabled | Color | The fill when enabled is false. |
skin | Skin | Pictures instead of the fill, one per state. See skins. |
tint | Color | Multiplies the colours of a skin or an image; WHITE leaves them as drawn. |
border | Color | The outline's colour, drawn when border_width is above 0. |
border_width | float | The outline's width in design units; 0 draws none. |
radius | float | The corners, in design units; 0 is square. |
shadow | Shadow | A soft shadow under the box. See shadows and outlines. |
padding_x | float | Inside, left and right, in design units. On a panel it is its padding all round. |
padding_y | float | Inside, above and below. |
gap | float | Between the children of a container. |
text | Color | The colour of its text, over the role a call gives it. |
text_disabled | Color | The same, when enabled is false. |
font | rmp::Font | A font you loaded. The interface draws with that font's file; see fonts. An empty one is inherited. |
font_size | float | What Size::MEDIUM is here, in design units. SMALL and LARGE follow it, in proportion. |
text_outline | TextOutline | An outline around every letter. |
text_shadow | TextShadow | A copy of the text under it, offset. |
motion | Motion | How it moves under the pointer, as it appears and when it shakes. See motion. |
sounds | Sounds | A sound per event. See sounds. |
Every field but font and sounds is a std::optional, and
"unset" is what it says: not 0, not black. font is unset when it is an empty handle, and
each sound of sounds is an optional of its own.
A field a widget's own style leaves unset is looked for, in this order, and the first that sets it wins:
style;children style of the Panels it is
inside, the nearest first;Theme::styles;Inside a widget, current_theme() answers
with the theme as that style changes it, so every widget reads its style the way it already read
the theme, and a style can do nothing the theme could not do on its own but for one widget.
Theme::styles holds one
Style for each kind of widget. What is set there is how every widget of that kind looks
before its own style — the ones written the simple way, rmp::ui::button("Play"),
included. A skinned game is then one theme, and its menus stay three lines:
rmp::ui::Theme theme = rmp::ui::current_theme();
theme.styles.button.skin = rmp::ui::Skin{ .normal = frame };
theme.styles.button.text = WHITE;
theme.styles.panel.shadow = rmp::ui::Shadow{};
rmp::ui::set_theme(theme);Field of styles | Under |
|---|---|
button | button(), image_button(), Button |
label | text(), Label |
image | image(), Image |
panel | panel(), Panel |
checkbox | checkbox(), Checkbox |
slider | slider(), Slider |
dropdown | dropdown(), Dropdown |
text_input | text_input(), TextInput |
progress | progress(), ProgressBar |
Two of them are not empty in theme_dark() and theme_light(), and they
are the framework's own look. styles.button grows a button 3 % under the pointer, gives
it 3 % while it is held, and sits it on a soft shadow; styles.panel puts a panel on a
deeper shadow and fades it in, rising 10 design units, over 0.18 seconds the first frame it is drawn
— an overlay's panel included, so a pause menu arrives instead of appearing. The light theme's
shadows are the same, fainter. There is never a text shadow by default. The other seven are empty,
and so are the theme's sounds and
motion: silent.
rmp::ui::Theme theme = rmp::ui::theme_dark();
theme.styles.button.shadow.reset(); // buttons with no shadow, still growing
theme.styles.panel = {}; // panels as flat and still as text
rmp::ui::set_theme(theme);A Style{} is empty, so theme.styles.panel = {} takes the whole look of
panels away. theme.styles = {} is not that: it is a new Styles, which has
the framework's look in it again.
A kept Panel has two styles, the way a Godot
container has its own theme override and one for its children:
style is how the panel itself looks, and
children is a style every widget inside it
inherits, however deep. Panels nest, and the nearest one's wins:
rmp::ui::Panel shop{
.style = { .background = DARKBROWN, .shadow = rmp::ui::Shadow{} },
.children = { .text = GOLD, .font = title },
};
shop.show([] {
rmp::ui::text("Shop");
rmp::ui::button("Buy");
});With background = false a panel is a bare
row or column — no fill of its own unless its style gives one, no padding unless asked — that still
styles its children: a way to give one part of a screen a font or a colour without drawing a box.
A length, a time or a scale that is not a finite number in its range — a NaN from a division by zero, a radius of minus four — is drawn the way no style would draw it, and said once: UI: a Style's … of … is not from … to …; … is used. A negative length is 0 without a word: a border of -4 is no border.
Everything in the interface that shows an image — image(), an icon on a button, a
skin behind a button or a panel, the fill of a bar — takes an
rmp::ui::Picture, and a picture is made from whatever
you have, without naming it:
| From | Is |
|---|---|
an rmp::Texture | The whole texture. |
{ texture, Rectangle{ … } } | A part of it: an atlas, a sheet laid out by hand. |
an rmp::Sprite | What the sprite shows now: its texture, or its sheet's current frame. A snapshot: make one each frame to see it move, or keep an Image, which plays it. |
a NineSlice | A picture that stretches by its middle. See below. |
slice(sheet, name) | A slice of an Aseprite file, by its name. |
rmp::ui::image(logo);
rmp::ui::image({ atlas, Rectangle{ 32, 0, 16, 16 } });
rmp::ui::image(hero);A picture holds counted handles to what it shows, so the texture stays loaded for as long as a
picture that shows it exists — through the end of the frame that draws it — and a temporary is
safe. empty() is true when there is nothing to
draw: no texture, or one that did not load; an empty picture draws nothing and takes no room.
size() is its size in pixels of the source, and
sliced() is true when it has nine-slice
margins. Its fields are public — texture,
sheet,
source, the margins
left,
top,
right,
bottom and
slice_scale — but one of the
constructors normally sets them.
A NineSlice is the classic "9-patch": four
margins cut the picture into a three-by-three grid, and it is drawn stretched to any box with its
corners at their own size, its edges stretched along one axis and its middle along both. One small
frame becomes a button of any length:
const rmp::ui::NineSlice frame{ .texture = ui_art,
.source = { 0, 0, 24, 24 },
.left = 8,
.top = 8,
.right = 8,
.bottom = 8,
.scale = 3 };
rmp::ui::Button play{ .text = "Play", .style = { .skin = rmp::ui::Skin{ .normal = frame } } };| Field | Default | Is |
|---|---|---|
texture | empty | The picture. |
sheet | empty | Or an Aseprite sheet's texture, when texture is empty. |
source | all of it | The part of the texture to cut, in pixels. |
left, top, right, bottom | 0 | The margins, in pixels of the source. |
scale | 0, which is 1 | How big one source pixel is drawn, in design units, so the corners grow with the interface's scale like everything else. Pixel art wants a whole number. |
A box smaller than its corners shrinks the corners together rather than letting them overlap. All four margins 0 is a picture that simply stretches.
An artist marks the parts of an .aseprite with the slice tool and names them: an
icon of an atlas, the frame of a button. slice(sheet, name)
is the part of the first frame the slice covers, as a picture, and one with "9-Slices" ticked in
Aseprite comes with its margins, so it is already a nine-slice.
nine_slice(sheet, name) is the same slice as a
NineSlice, to change its scale or keep it:
static const rmp::SpriteSheet icons = rmp::assets::load_sheet("skin.aseprite");
rmp::ui::image(rmp::ui::slice(icons, "coin"));
rmp::ui::NineSlice frame = rmp::ui::nine_slice(icons, "button");
frame.scale = 3;A name the sheet does not have is an empty picture, and said once:
UI: rmp::ui::…(sheet, "…"): the sheet has no slice by that name. A slice without
9-slices asked for as one stretches whole, and says
UI: rmp::ui::nine_slice(sheet, "…"): the slice has no 9-slices; it stretches whole. The
slices themselves are in the sheet's SheetData::slices;
sprites says what is read from the file.
rmp::ui::image_button is a button that is a
picture: an icon, an inventory slot, a "Play" drawn by the artist. It is pressed and focused like
button(), and wears theme.styles.button — its skin behind the picture, its
sounds:
if (rmp::ui::image_button(gear)) open_settings();
if (rmp::ui::image_button(gear, { .width = 64, .height = 64, .id = "settings" })) open_settings();ImageButtonOptions:
width and
height in design units, 0 for
the picture's own size;
enabled; and
id, since a picture has no label to be
told apart by — without one, unnamed image buttons are told apart by their order. It has no padding
around it and no minimum height, except on Android and iOS, where it is still as tall as a thumb needs.
A Skin is pictures instead of a flat fill, one per
state. Only normal is needed: a state without
its own picture shows normal, changed the way the colours of that state would be —
lit under the pointer, darker while held, grey and faded when disabled. Give the others when the
artist drew them:
const rmp::ui::Style wooden{ .skin = rmp::ui::Skin{ .normal = up, .press = down } };| Field | Shown | When it is missing |
|---|---|---|
normal | at rest | no skin at all: the theme's fill |
hover | under the pointer | normal, drawn a second time on top, faintly, to light it |
press | held down | normal, darker |
disabled | enabled = false | normal, grey and a little transparent |
focus | with the keyboard or gamepad focus | normal; the focus ring is drawn either way |
The picture is the box: a skinned button has no flat fill over it or under it, and its
style's tint multiplies it. On an image, the skin is a frame behind the picture, as far
in as the style's padding.
A Shadow under a box is drawn as a few rounded
rectangles, each fainter than the last, outwards. That reads as blurred on every target — the
software renderer and OpenGL ES 2.0 included — and costs a handful of rectangles:
const rmp::ui::Style card{ .shadow = rmp::ui::Shadow{ .offset = { 0, 6 }, .blur = 12 } };| Field | Default | Is |
|---|---|---|
offset | { 0, 4 } | Where it falls, in design units: down a little, as light from above. |
blur | 8 | How far it fades out past the box; 0 is one hard shadow. |
spread | 0 | How much bigger than the box it is before it fades. |
color | black at 90 of 255 | Its colour at the box. |
Text has two of its own. A TextOutline draws
copies of the text around it, so a title reads over any background —
width in design units (1 by default; keep
it from 1 to 3, every copy is drawn), color
black. A TextShadow is one copy under it —
offset { 1, 2 } design units,
color black at 160 of 255. A box's own
outline is border and border_width.
rmp::ui::Label title{ .text = "Game over",
.size = rmp::ui::Size::LARGE,
.style = { .text = GOLD,
.text_outline = rmp::ui::TextOutline{ .width = 2 },
.text_shadow = rmp::ui::TextShadow{} } };A Motion is movement. The framework's themes have
a little of it, in their styles: buttons grow under the pointer and give when
pressed, and panels fade and rise in. Anything more is a choice of style, and a game that wants it
says so. Nothing here moves the layout. A control is drawn bigger, lifted or
sliding, with everything inside it, but it is laid out — and clicked — where it always was.
rmp::ui::Theme theme = rmp::ui::current_theme();
theme.styles.button.motion = rmp::ui::Motion{ .hover_scale = 1.05f, .press_scale = 0.95f };
theme.styles.panel.motion = rmp::ui::Motion{ .appear = 0.25f, .appear_offset = 24 };
rmp::ui::set_theme(theme);| Field | Default | Is |
|---|---|---|
hover_scale | 1 | How big under the pointer: 1.05 is 5 % bigger. |
press_scale | 1 | How big while held: 0.95 is 5 % smaller. |
hover_lift | 0 | How far it rises under the pointer, in design units, its shadow falling further below it: a card lifting off the table. |
speed | 0.12 | Seconds hover and press take to get there. |
appear | 0 | Seconds a box takes to fade in the first frame it is drawn; 0, it is simply there. Panels and overlays are what it is for. |
appear_offset | 0 | How far below it starts as it appears, in design units, sliding up. |
appear_scale | 1 | How big it starts as it appears, growing to 1. |
shake | 0.4 | Seconds a shake() lasts. |
shake_strength | 8 | How far side to side it shakes, in design units, dying away. |
A shake is a kept widget's shake() — "that did not work": a wrong password, a coin
you do not have. It needs no Motion to be set: the defaults above shake. Hover and press
follow the same clock as the scenes, so a script that plays the game sees the same frames every
run.
A Sounds names a sound for each thing a control
does, by the name rmp::audio::play() takes —
"click" is click.wav, click.ogg… in resources/. In
the theme, every control makes them; in a style, one widget does, or everything inside a
panel:
rmp::ui::Theme theme = rmp::ui::current_theme();
theme.sounds.hover = "hover";
theme.sounds.click = "click";
theme.sounds.volume = 0.6f;
rmp::ui::set_theme(theme);
rmp::ui::Button quiet{ .text = "Back", .style = { .sounds = { .hover = "" } } };| Field | Plays when |
|---|---|
hover | the pointer arrives on a control |
press | the pointer goes down on it |
release | …and comes up |
click | it is pressed: the pointer, Enter, the gamepad's A button |
focus | the keyboard or gamepad focus arrives |
change | a checkbox, slider, dropdown or text field changes its value |
open | a dropdown opens its list |
close | …and closes it |
shake | a widget's shake() starts |
volume | not a sound: 0 to 1, for all of them; 1 when nothing sets it |
Each one is inherited on its own, like every field of a style, so an empty name is
silence: .hover = "" turns off a hover sound the theme or a panel set. Unset is
"whatever is around it"; empty is "nothing".
A name is a SoundName, written as a string — a
literal, a std::string or a std::string_view, copied — with
view() to read it,
empty() for silence and == to
compare it with a string. It is a type of its own for one reason: writing one is what brings
rmp::audio's player and its decoders into the game. A game whose interface names no sound
links none of them.
Every sound goes through rmp::audio, so it follows the
mixer's sound-effect volume and master volume, and a sound
that is missing says so once, as any play() does. Anything else that should happen on an
event — a vibration, a particle — is
on_event().
The interface draws its text in one global font unless a style gives another. The global font
starts as [ui] font, at sizes measured from [ui] font_size; that is only
where the game starts, and it can change at any time.
Text is drawn at the pixel size the layout asks for: its size in design units — a step or a number — times the scale.
Left empty, the default, the font is raylib's built-in one: no file, no licence, and it works on every platform. It is a bitmap 10 pixels tall, stretched to whatever size the text asks for.
A font of your own is a file in resources/, named relative to it:
[ui]
font = "ui.ttf"
font_size = 24font_size is the medium step in design units, a whole number from 6 to 200; the small
and large steps start at 0.8 and 1.4 times it.
set_font() changes the global font: by its name in
resources/, or from a font the game loaded — the interface takes that font's file and
bakes it itself. "", an empty font or one that failed to load is raylib's built-in one.
font_name() says which it is now. A language with
other letters, an accessibility setting for a plainer face:
rmp::ui::set_font(dyslexia_friendly ? "plain.ttf" : "ui.ttf");Style::font gives one widget, or everything in a
panel, a font of its own: one the game loaded with
rmp::assets::load_font. The size it was loaded
at does not matter. The interface draws with that font's file, baked by itself at every
size it draws, so a title at 48 and a caption at 14 in the same font are both sharp:
static const rmp::Font title = rmp::assets::load_font("title.ttf", 32);
rmp::ui::Label heading{ .text = "Chapter one",
.size = rmp::ui::Size::LARGE,
.style = { .font = title } };A font file is a set of
outlines, and drawing it means baking the letters it needs into a texture first. The interface bakes
a letter the first time a text uses it — Spanish, Polish, Russian, Japanese, whatever the file has —
and then bakes the face again with it, before the frame is drawn. Latin-1 and Latin Extended-A are
there from the start. A game that draws more than 8192 different letters with one font draws the ones
past that as ?, and says so once:
UI: more than … different letters drawn with a [ui] font; the ones past that are drawn as '?'.
It is loaded through
rmp::assets, so it works the same loose in resources/ and packed in a release.
A font file is only sharp at the size it was rasterised at, so the interface rasterises it once for
every pixel size it draws — SMALL, MEDIUM, LARGE and every
number, each times the scale, for every font in use — and keeps each of those faces until the
interface shuts down. Text is then drawn from a face made at exactly its size, so it stays sharp at
any scale. Sixteen faces are kept at once; one more makes room by letting go of the face used
longest ago, never of one drawn in the same frame, whose glyphs may still be waiting to be drawn. A
frame that draws more than sixteen sizes draws the extra ones from the nearest face of the same font,
stretched.
A font file that is missing or cannot be read does not switch the interface off: it falls back to the built-in font and says so once, UI: font '…' could not be loaded; using the built-in font.
https://omardev29.github.io/rmp-docs/manual/modules/assets.html
A game's pictures, sounds, fonts and levels live in one folder,
resources/, and are loaded by their file name. What comes back is a handle that knows
how many copies of it exist and frees what it loaded when the last one goes. The same call reads
the loose files while you work and a single packed, encrypted file in a release, and the game
never has to know which.
Everything in rmp::assets takes the name of a file in
resources/, not a path. A scene loads what it needs in _ready(), keeps the
handle as a member, and hands it to raylib wherever raylib wants the picture:
class TitleScene : public rmp::Scene {
rmp::Texture _logo;
void _ready() override { _logo = rmp::assets::load_texture("logo.png"); }
void _draw() override { DrawTexture(_logo, 40, 40, WHITE); }
};There is nothing to unload. When the scene ends, _logo goes with it, and with it
the texture — unless something else still holds the same one.
One loader per kind of thing, each returning its own handle:
| Call | Returns | For |
|---|---|---|
load_texture(name) | rmp::Texture | A picture on the GPU, to draw. |
load_image(name) | rmp::Image | A picture in memory, to read pixels from or make a texture out of. |
load_font(name, size) | rmp::Font | A .ttf or .otf, baked at one size, from 1 to 1024. |
load_sound(name) | rmp::Sound | A short sound, decoded into memory. Most games play sounds by name with rmp::audio instead. |
load_sheet(name) | rmp::SpriteSheet | An Aseprite file, with its frames and tags. See Sprites. |
load_map(name) | rmp::Tilemap | A level made in LDtk or Tiled. See Tilemaps. |
load_data(name) | std::vector<unsigned char> | The bytes of any other file. |
rmp::Texture player = rmp::assets::load_texture("player.png");
rmp::Image mask = rmp::assets::load_image("mask.png");
rmp::Font title = rmp::assets::load_font("title.ttf", 48);
rmp::Sound jump = rmp::assets::load_sound("jump.wav");
rmp::SpriteSheet hero = rmp::assets::load_sheet("hero.aseprite");
std::vector<unsigned char> dialogue = rmp::assets::load_data("dialogue.json");The name is the file's path inside resources/, with / between folders —
"jump.wav" for a file at the top, "sfx/jump.wav" for one in a
folder sfx inside it — never "resources/jump.wav" and never an absolute path. The
folder where those names are looked up is set by the build, so the same name works however the
game was started.
Keep
resources/ in folders by kind — sprites/, maps/,
audio/, fonts/, dialogue/, locale/ — the way a game
of any size wants it. Every target finds the same name: a debug build reads the loose file, the
pack a desktop release ships keeps each file under its path below resources/ (the
packer runs inside that folder), and the web, Android and iOS ship the folder whole.
rmp::Texture hero = rmp::assets::load_texture("sprites/hero.png");
rmp::Sound jump = rmp::assets::load_sound("audio/jump.wav");
rmp::Tilemap town = rmp::assets::load_map("maps/town.ldtk");A
map names its tilesets and its separate level files by a path relative to itself, as LDtk and Tiled
write them: maps/town.ldtk with a tileset at ../tiles/town.png loads
tiles/town.png. When that file is not there, the map's tileset is looked for by its
file name at the top of resources/, where maps kept their files before there were
folders.
A font is turned into a texture of glyphs at the size you ask for, and the size is part of what
identifies it: load_font("ui.ttf", 16) and load_font("ui.ttf", 32) are two
fonts, two textures. Ask for the size you draw at.
A font is baked with
the letters most languages written in the Latin alphabet need: printable ASCII, Latin-1 (ñ, á, ü, ç,
¿, ¡, £, °), Latin Extended-A (the Polish, Czech, Hungarian, Turkish, Baltic and Croatian letters),
and the dashes, curly quotes, bullet, ellipsis, euro and trademark sign a translated line uses. A
letter outside that set is drawn as ? by raylib's text functions. The interface does
not have that limit: it bakes every letter its text uses, on demand — see
every letter, on demand.
rmp::Texture, rmp::Image, rmp::Font and
rmp::Sound are the same thing for different raylib types: a
counted reference to one loaded resource. Each converts to
the raylib struct it wraps, so every raylib function that takes a Texture2D takes an
rmp::Texture. rmp::SpriteSheet is the same handle around a struct of the
framework's own, rmp::SheetData — the texture, the
frames and the tags of an .aseprite — and converts to that.
Loading a name that is already loaded does not load it again. The name is the key, and the second load hands back the resource the first one made, with one more reference to it. A copy of a handle is one more reference too:
rmp::Texture a = rmp::assets::load_texture("enemy.png");
rmp::Texture b = rmp::assets::load_texture("enemy.png"); // the same texture, loaded once
rmp::Texture c = a; // and one more reference to itThat is what lets a hundred enemies each hold their picture without anyone deciding who owns it: each holds a handle, the texture is on the GPU once, and it goes when the last enemy does. A move takes the reference over and leaves the moved-from handle empty.
A resource is unloaded when the last handle to it goes out of scope — a scene ending, an object
being destroyed, a member being assigned something else. Whatever is still held when the game
ends is released by the framework before the window closes, because a texture freed after the
GPU context is gone is a crash. A handle that outlives that, such as a static one,
holds nothing from then on: it hands raylib a zeroed struct, which draws nothing, and its own end
does nothing. Unlike the empty handles below, it still answers
valid() with true.
Since a handle is the owner, there is one mistake the types refuse: keeping the raylib struct and letting the handle go.
Texture2D player = rmp::assets::load_texture("player.png");The compiler refuses it, saying among other things: deleted function
If that compiled, the handle would be a temporary that died at the end of the line, taking the
texture with it, and player would be a texture that had already been unloaded. Only a
handle that is still alive converts; keep the rmp::Texture and pass it to raylib where
raylib wants the picture.
Loading in _ready() and keeping the handle is the shape to use. Loading in
_draw() every frame is a search of the loaded resources every frame, and if no other
handle holds the resource it is loaded and freed again each time.
A handle can hold nothing: one that was never assigned, one that was moved from, and one whose
load failed. valid() says which, and
so does the handle in an if:
rmp::Texture logo = rmp::assets::load_texture("logo.png");
if (!logo) TraceLog(LOG_WARNING, "no logo: the title is drawn as text");An empty handle converts to a zeroed raylib struct, and raylib draws nothing for one of those. A missing picture is a hole in the frame, not a crash.
The handles come from the loaders. A texture you make yourself with raylib —
LoadTextureFromImage(), LoadRenderTexture(), a model from
LoadModel() — is a plain raylib struct, under raylib's own rule: what you load, you
unload. The types rmp::Music, rmp::Shader and
rmp::RenderTexture exist, but nothing in rmp::assets returns one; music is
played by name through rmp::audio.
An rmp::Image is read through its handle and not changed: the image belongs to
every handle that loaded the same name. Making a texture from it is the usual use.
A level in your own format, a shader's source, a JSON table of items: load_data()
returns the bytes, as a vector that frees itself. It is not cached, so each call reads the file
again, and it is empty when the file is not there.
const std::vector<unsigned char> bytes = rmp::assets::load_data("intro.txt");
const std::string intro(bytes.begin(), bytes.end());It reads from the pack in a release exactly as the other loaders do. The Aseprite and map loaders are built on it.
Tuning numbers, a table of items, the lines of a dialogue: a JSON file in
resources/ is read into an rmp::Value, the
same value a save is, with
load_value(). It reads from the pack in a
release like every loader, and a file that is not there, or is not JSON, is an empty Value and a
failed load, said once.
const rmp::Value tuning = rmp::assets::load_value("tuning.json");
const float speed = tuning["player"]["speed"].as_float(200);
const int lives = tuning["lives"].as_int(3);A Value read with load_value() remembers its file, and so does a texture read with
load_texture(). While a Debug build runs on the desktop,
changed() says when that file is different from
what was read — a number tuned, a sprite redrawn and saved in any editor — and
reload() reads it again. Nothing is read behind
the game's back: the game asks, and decides when.
rmp::Value tuning = rmp::assets::load_value("tuning.json");
rmp::Texture hero = rmp::assets::load_texture("hero.png");
float speed = 200;
void _update(float) override {
if (tuning.changed()) tuning.reload();
if (hero.changed()) hero.reload();
speed = tuning["speed"].as_float(200);
}changed() is for every frame. It compares two numbers. The files
themselves are looked at by the framework at most four times a second, the first time something
asks after a quarter of a second has gone by: their size and modification time, and their bytes
only when one of those moved — so an editor that saves the same contents again is no change.reload() of a texture is in place. The texture is loaded again
into the slot every handle to it shares, so the copies a sprite or a picture made draw the new one
too, and changed() is false again for all of them. A Value reloads only itself: two
Values read from one file are two copies, and each reloads on its own.reload()
returns false and changed() stays true, so the next frame tries again.
A file that is gone for a moment — an editor writes a new one and renames it over the old — is no
change until it is back.rmp pack), changed() is always
false and costs nothing.tuning["enemy"] copied into a Value of its own — answers
false, and its reload() does nothing. A copy of the whole Value is the
same file.Only JSON and textures reload. Code does not: a change to the C++ is a new build.
The rmp::assets functions are the short way, not the only one. When a pack is in
use, raylib's own file loading is routed through it, so a raylib loader given a path inside
resources/ finds the packed copy:
Model ship = LoadModel(RMP_RESOURCES_PATH "ship.obj"); // in a release, read from the pack
// ... and raylib's rule for what raylib loads:
UnloadModel(ship);That covers models and the files they pull in behind your back — an .obj's
.mtl and the textures it names — as well as shaders, fonts and textures loaded through
raylib directly. The path has to start with the macro the build defines for the folder,
RMP_RESOURCES_PATH: only files inside it are answered from the pack, by their path below it, so a
save file elsewhere on disk that happens to share a name with a packed one is never mistaken for
it.
The build tells the game where its folder is. A debug build reads the absolute path of the
project's resources/, so the game finds its files whichever folder it is started from.
A release build (rmp build release) reads ./resources/, which is where the
released archive puts the folder, beside the executable.
On Windows, macOS, Linux and the
BSDs, the entry point makes that relative path start at the executable's folder: before anything is
loaded, a release moves into the folder its executable is in, when there is a resources/
there. A player can start it from a file manager, a shortcut or any terminal folder, and it finds
its files — and so does a plain raylib load of an RMP_RESOURCES_PATH path, because the
path stays relative and only the folder it is relative to changes. The log says where it read
from: ASSETS: reading … next to the executable, in …. CI starts a release from another
folder to prove it.
Two cases keep the folder the game was started from. A release built in the source tree and
started from its root — the executable in build/release/, with no resources/ beside
it — reads the root's. And NetBSD and OpenBSD do not tell a program where its executable is, so there a release reads
resources/ from the folder it was started in, and says so:
ASSETS: this system does not say where the executable is, so … is read from the working directory, …
The web reads its files from the page, Android from the APK, and iOS moves into the app's bundle
the same way.
An example with a resources/ of its own reads that one and not the game's; one
without reads the game's.
A release does not have to ship a folder of loose files. rmp pack bundles every
file below resources/, its folders too, into one file, resources.rres, inside that same
folder, encrypted. The container format is rres, by
raylib's author, and the packer is part of the framework, so nothing has to be installed or
bought.
rmp pack # resources/ into resources/resources.rres
rmp run # the game now reads the pack
rmp unpack # delete the pack: the game reads the loose files againAt startup the framework looks for resources.rres in the game's resources folder.
If it is there, every load asks the pack first; if not, the loose files are read. The log says
which:
rmp::assets::using_pack() answers the
same question in code. There is no call to make for any of it: the entry point calls
rmp::assets::init() before the first scene, which
finds the pack, and rmp::assets::shutdown()
after the last.
A name the pack does not have — a picture you added after packing — is read from the loose
files instead, with a warning such as ASSETS: '…' not found in pack, falling back to loose
file. In development that means you can keep working after rmp pack without
packing again. In a release that ships only the pack there is no loose file to fall back to, and
the load fails, which is what the warning is there to tell you before a player does.
The release jobs build the pack where the packer can run on the machine that builds the game:
| Release | What its resources/ holds |
|---|---|
| Linux on glibc (x64, arm64, and both DRM builds), Windows x64, macOS, FreeBSD, OpenBSD, NetBSD | resources.rres alone. |
linux-x64-musl, linux-riscv64-glibc, windows-arm64 | The loose files, and a PACK_SKIPPED.txt saying why: these are cross-compiled, and the packer they build cannot run on the machine that builds them. |
| Web, iOS | The loose files: the folder is preloaded into the page, or copied into the app. |
| Android | The loose files, copied into the APK's assets. A resources.rres is left out of the APK, because the pack cannot be opened from inside one. |
A game in plain C, made the way
examples/plain_c says — no src/rmp/ — has no framework to read a pack with,
so the releases that would ship the pack ship the loose files instead, with a
PACK_SKIPPED.txt saying why.
The game does not care: a folder with a pack is read through the pack, and one without is read file by file.
The pack is encrypted with AES, under a key derived from one password, which is set in the
.toml and reaches both the packer and the game from there:
[resources]
rres_password = "a phrase of your own"An empty password is refused, because it would ship a pack encrypted with a key of nothing rather than one with no encryption:
[resources]
rres_password = "" raylib_multiplatform.toml:2: rres_password = ""
^^^^^^^^^^^^^^^^^^
configure: error: [resources] rres_password is empty, which ships the pack with an AES key of nothing rather than with no encryption.
Put a passphrase here. There is no setting for an unencrypted pack: every release job that builds resources.rres encrypts it with this value. A game reads loose files only where no pack was built -- a development build, or an archive whose resources/ holds PACK_SKIPPED.txt.Each file read from the pack derives its key again (Argon2i, 16 MiB, three passes). That is a cost paid when something loads, never while the game runs.
rmp new writes a random password into the new game's .toml, so each game
has one of its own. Leave the key out and the framework's default applies, which is the same for
everyone.
A load that finds nothing returns an empty handle, and the game keeps running. A missing texture is a gap on the screen; a missing font, sound or sheet is empty in the same way. Nothing throws: no call into the framework throws to the game's code.
The failure is still counted.
requested_loads() is how many loads the
game asked for, and failed_loads() how many
of them failed, which means:
.aseprite file that cannot be read as one;A file that does not decode — a broken PNG, a download cut short — is an empty handle, and the log names it once: ASSETS: '…' is in … but could not be decoded. A font is no exception. raylib answers a font file it cannot read with its own built-in font, and the framework does not hand that back as yours, or keep it under your file's name: the handle is empty, and nothing is cached. No failed load is cached, so a file fixed while the game runs is found by the next load.
A picture that decoded and could not reach the GPU, because there is no window, is not counted: that is every headless test, not a broken file.
When the game boots under the smoke test, the framework prints one line once the ready hook has returned — in a game of scenes, once the first scene is ready:
RAY_TEST_BOOT_OK assets_failed=0 …
rmp test smoke
on your machine requires assets_failed=0, and so does every CI job that boots the game
and reads its log — the desktops, the BSDs, the web, the release started from another folder — and
the boot of every example. A game that asks for a file it does not ship, or ships one that does not
decode, fails the build instead of reaching a player as a blank sprite.
iOS
and Android are not counted. iOS is not booted: the hosted simulator does not come up, so that step
runs only when the repository variable IOS_SIMULATOR_TEST is true.
Android's test runs in Firebase Test Lab and has no log to read, so it shows that the game starts, not
this count.
The count covers what is loaded by then: the first scene's _ready(), or a game's
own on_ready. A file loaded later, by a level the boot never reaches, is outside it.
https://omardev29.github.io/rmp-docs/manual/modules/sprites.html
An object's sprite is its
picture. It is either a plain texture or a sheet read straight out of an Aseprite file, with the
frames, the time each one shows for and the named animations you drew. You save in Aseprite, and
the game has the new animation.
Give the sprite a texture and the object draws it, centred on its position and turned, scaled and flipped with it:
sprite.texture = rmp::assets::load_texture("ship.png");An object with a sprite draws the sprite; one without draws its
shape. The rest of
rmp::Sprite says how the picture is put on the
screen:
| Field | Default | Means |
|---|---|---|
texture | empty | A loose picture, for an object that does not animate. |
sheet | empty | An Aseprite sheet. When there is one, it is drawn and texture is not. |
source | {0,0,0,0} | The part of texture to draw; all of it when empty. A sheet chooses its own frame and ignores this. |
origin | {0.5, 0.5} | Which point of the picture sits on the object's position, as a fraction of its size: the centre by default, {0.5, 1} for the middle of the bottom edge. Rotation turns about it too. |
size | {0,0} | The size to draw at, before the object's scale; the picture's own size when empty. |
tint | WHITE | Multiplies the picture's colours. White leaves them alone; its alpha fades the picture. |
speed | 1 | How fast a sheet animates: 2 is twice as fast, 0 is frozen, -1 runs backwards. |
A handful of the object's own fields act on the picture as well:
scale multiplies its size,
rotation turns it,
flip_x and
flip_y mirror it,
visible hides it without taking the object out
of the game, and layer decides what is drawn on
top of what.
Drawing a character twice, once facing each way, is unnecessary: flip it. Flipping mirrors the
picture in place and costs nothing. Only the picture: a collider moved sideways with an
offset stays on the side it was put.
if (velocity.x < 0) flip_x = true;
if (velocity.x > 0) flip_x = false;The tint is a colour every pixel of the picture is multiplied by. A flash of red when hit, a ghost at half opacity:
sprite.tint = RED; // the hit flash
sprite.tint = Fade(WHITE, 0.5f); // half transparent, colours unchanged
sprite.tint = WHITE; // back to the picture as drawnA texture that holds many pictures — a sheet of tiles, a set of icons — is drawn one part at a
time through source, in the texture's pixels:
sprite.texture = rmp::assets::load_texture("items.png");
sprite.source = Rectangle{ 32, 0, 16, 16 }; // the third 16-pixel icon of the first rowFor anything that animates, use a sheet instead: it knows its own frames and how long each one lasts.
rmp::assets::load_sheet() reads an
.aseprite or .ase file, and play()
starts one of its animations by name:
sprite.sheet = rmp::assets::load_sheet("player.aseprite");
sprite.play("idle");The names are yours. They are the tags in your Aseprite file: the framework does not
know or expect an idle or a walk, and play("idle") works
because the file has a tag called that. A tag is a run of frames with a name, and each frame shows
for the time you gave it in Aseprite, so the animation plays at the speed you drew it at. The name
is a std::string_view, so a literal, a std::string or a view of one goes in
as it is.
play() starts a tag only when it is not already playing it. That makes the natural
way to write it — say, every frame, which animation the object should be showing — the right one:
the walk is not restarted sixty times a second while the player walks.
class Player : public rmp::Object {
void _ready() override {
sprite.sheet = rmp::assets::load_sheet("player.aseprite");
sprite.play("idle");
}
void _update(float delta) override {
if (velocity.y != 0) {
sprite.play("jump");
} else if (velocity.x != 0) {
sprite.play("walk");
} else {
sprite.play("idle");
}
}
};The platformer in examples/games/07_platformer
does exactly this for its player, with a hurt tag on top and the art turned to face
the way it moves: player.cpp.
An animation plays in a loop unless you say otherwise. With loop false it stops
on its last frame — not after it, so a death animation does not vanish into a blank frame
— and finished() turns true:
class Enemy : public rmp::Object {
public:
void die() {
sprite.play("die", false);
_dying = true;
}
private:
void _update(float delta) override {
if (_dying && sprite.finished()) destroy();
}
bool _dying = false;
};A tag that has finished is no longer "already playing", so asking for it again starts it again. A one-shot animation is asked for once, when the thing it shows happens, and not every frame.
playing()play(), or "" before any has
been. It keeps naming that tag after stop() and after a tag that does not loop has
finished; finished() is what says the clock has stopped.
It is a
std::string_view of the sheet's own copy of the name, good for as long as the sheet is
loaded.stop()frame_index() and set_frame(i)play() on shows its first frame and stays there, so a sheet used as a
set of still pictures — a door closed and open, an icon per item — is driven with
set_frame() alone.speedThe clock moves in the update pass, after the object has moved, and not when it is drawn. A scene that is still updated under a pause menu keeps animating; one frozen under it holds its frames, and picks up where it was when it resumes. A long frame — the game hitched for a moment — advances as many animation frames as the time covered, so an animation keeps time on a slow machine instead of slowing down with it.
Aseprite files are read directly; there is no export step and no JSON beside the picture. The whole of the workflow is:
play(). The tag's direction is honoured, all four of Aseprite's: Forward, Reverse,
Ping-pong, which plays to the end and back, and Ping-pong Reverse, which starts at the end..aseprite into resources/.Every visible layer is blended into the frame, the way Aseprite shows it with the Normal blend
mode; a hidden layer is left out, so a sketch or a reference layer can stay in the file. Other
blend modes are not reproduced — merge such a layer down in Aseprite if it matters. RGBA,
grayscale and indexed sprites all load. A tag's name is kept whole, however long it is: the
name of each
rmp::SheetTag is a std::string.
All the frames are packed side by side into one texture, so a hundred enemies drawn from the
same sheet are one texture and one name in the resource table: loading
"bat.aseprite" for each of them loads it once. Each object's sprite still has its own
clock, so they do not flap in step unless they started together. The packed texture is as wide as
all the frames together; a GPU has a largest texture it accepts, which a long animation of large
frames can reach.
An artist
marks parts of the canvas with Aseprite's slice tool and names them: the icons of an atlas, the frame
of a button. They are read with the pictures, into the sheet's
slices, in the file's order, up to 256 of them.
Each rmp::SheetSlice has its
name; its
bounds, in pixels of the packed texture,
already moved to where its frame is; and, when "9-Slices" is ticked for it in Aseprite,
nine set and its middle in
center, relative to the bounds.
slice(name) finds one —
the first, when two share a name — or an empty one, and
slice_count() says how many there are.
const rmp::SpriteSheet skin = rmp::assets::load_sheet("skin.aseprite");
const rmp::SheetSlice &coin = skin.raw().slice("coin");
const Rectangle where = coin.bounds;
(void)where;A slice is read where its first key is: a slice that moves from frame to frame is where it starts. One that does not lie inside the canvas, or does not read whole, is left out, and the pictures load all the same: a slice is never a reason to refuse a file. The interface takes slices by name as pictures and nine-slices: slices of an Aseprite file.
The rmp::behavior::TopDown behavior
chooses the tag for you from the direction the object faces: it plays walk_e,
walk_n and the rest when the sheet has them, and walk with
flip_x when it does not, so a sheet with two, four or eight directions works without
configuration. Its tag names are fields you can change.
Draw the frames that have no direction in their name — walk, idle —
facing right: the behavior mirrors them while the object faces left. A tag with a direction is
drawn for that direction and played unflipped, so walk_w shows exactly as you drew
it. TopDown has the rest.
An object with no shape and no collider
collides as its sprite: the rectangle the current frame covers. That is right until the picture
includes air, hair or a cape, which is most characters, and then a smaller collider is one line:
sprite.sheet = rmp::assets::load_sheet("player.aseprite");
collider = rmp::rect({ 12, 20 }); // the body, not the whole 24-pixel frame
collider.offset = { 0, 2 }; // standing on the bottom edge of the frameA tag that is not in the sheet warns once and changes nothing — the frame already showing stays, rather than the sprite going blank, and the console does not fill at sixty lines a second:
SPRITE: no animation tag "jmup" in this sheet. It has 4: the names are the tags in your .aseprite.
play() on a sprite with no sheet says so the same way. Both are mistakes in the
game, and with [dev] strict on, the first of them aborts a debug build, so it is met
in the debugger instead of scrolling past in a log. Release builds never carry it:
[dev]
strict = trueA file that is not an Aseprite file — the wrong file, a cut-short download, a PNG renamed — is refused before it is parsed, comes back as an empty sheet, and counts as a failed load:
SHEET: [player.aseprite] is not an .aseprite file this can read
On a machine with no GPU — a test, a server — the sheet's texture is empty and everything else is there: the frames, their durations and the tags, which is what lets the animation clock be tested without a window.
https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html
A level is designed in an editor and loaded by name. Every scene has a
map: the scene draws it under everything, stops
solid objects at its solid cells, and the enemies, coins and doors you placed in the editor turn
up in the game as objects. The editor stops being a file format and becomes the place where the
level is made.


The map is a field of the scene. Assign it in _ready():
map = rmp::assets::load_map("world.ldtk");That is all it takes for the level to be on screen and solid. There is no draw() to
call: the scene draws the map first, inside the camera, so the objects stand on it and the HUD
your _draw() paints stays on top. A scene that never assigns its map — a menu — has an
empty one, which costs nothing.
load_map() picks the reader by the file's
extension:
| File | Editor | Status |
|---|---|---|
.ldtk | LDtk | The one the framework tests and keeps up to date. |
.json | Tiled | Read as it is, with the tests it has. It gets nothing new. |
LDtk is the primary one because it is the more modern editor — auto-layers, IntGrid, entities
with typed fields, worlds of many levels, and a JSON format it documents and has kept stable since
1.5 — and holding two readers to the same level of testing is more than it is worth. Whichever
made it, a map is the same rmp::Tilemap afterwards:
nothing past the parser knows which editor drew it.
A map is not shared the way a texture is. It belongs to one scene, moves rather than copies, and is read from the file each time it is loaded; the tileset images it draws with are ordinary textures and are shared.
camera — and only what the camera shows. The
scene hands the map the rectangle of the world in view, rotation, zoom and shake included, and the
map looks only at the tiles that reach into it: an LDtk layer's through the 16 by 16 cell blocks it
sorts them into when it is read, a Tiled layer's through the range of cells under the view. On a
400 by 400 cell map that is about 500 tiles of 320 000 a frame, 0.25 ms instead of 87, and the
picture is the same pixel for pixel. Nothing is drawn ahead into a texture, so a map costs no
memory beyond its own and changes nothing about how it is made.solid and not
immovable cannot move into a solid cell: the
floor holds the player up, a wall stops it, a ceiling ends a jump, and the
Platformer behavior counts the floor as
ground. A coin, a trigger, a bullet or a platform the game moves by hand is not stopped.edges say what to do at the
edge of the world — clamp, bounce, wrap — and whose
bounds are left empty takes the map's bounds
as that edge rather than the view's, so a player clamped to the world is clamped to the
level.Movement against the map is worked out one axis at a time — across, then down — so a player
running along a floor made of separate tiles does not catch on the seams between them. A fast
object moves in steps of at most half a cell, so a fall faster than a tile per frame still lands
on the floor instead of passing through it. The camera is the one thing to set yourself, and it
is one line: camera.limits = map.bounds(); keeps the view inside the level.
An LDtk project can hold many levels. Without a name, load_map() loads the first;
with one, it loads the level of that identifier:
map = rmp::assets::load_map("world.ldtk", "Desert");Starting from "" — the first level, whatever it is called — means renaming or
reordering levels in LDtk does not stop the game starting at the beginning. A name the project
does not have loads nothing and the log lists the names it does have.
resources/ beside the
.ldtk, or in a folder of their own: LDtk stores paths relative to the project, and
they are read from the project's folder (maps/town.ldtk and ../tiles/town.png
are tiles/town.png), or by the file's name at the top of resources/ when
nothing is there. A tileset image that does not become a texture is a
warning naming the file, and the level still loads with that tileset drawing nothing. The warning
says which of two things happened: the image is not there,
MAP: the tileset image … is not in resources/, or it is there and did not load,
MAP: the tileset image … is in resources/ but did not load: it does not decode, or there is no window to upload it to yet
— the file you can see, refused. A missing or broken image is also a failed load. A tileset must
be a picture load_texture() reads, such as a PNG; LDtk's built-in icon atlas has no
file and draws nothing either.solid makes
every cell painted with it solid. So does any tile tagged solid through its tileset's
enum for tile marking, even under another tile. Either is compared without case, because LDtk's
default identifier style saves solid as Solid..ldtkl beside the project; copy them into resources/ too. Loading a
.ldtkl on its own is refused, because its tilesets and layer definitions live in the
.ldtk.Not read: level backgrounds, parallax, IntGrid values other than solid, and the
fields of a level itself.
In LDtk's GridVania and Free layouts every level has a place in one world, and the map keeps
it: bounds() is where the level sits in the
world, and every position the map hands out — objects, points, solid cells — is in those same world
units. A level loaded at x = 720 starts at 720, not at 0. The linear layouts have no
world, and each of their levels starts at 0,0.
That is what makes walking from one level into the next a single if.
neighbour_at(point) names the other
level of the world at a point, or "" while the point is still in this level or in no
level at all. Change to that level and put the player at the same position, which still means the
same place, because the coordinates are the world's:
class Level : public rmp::Scene {
public:
Level(std::string name, Vector2 arrival) : _name(std::move(name)), _arrival(arrival) {}
private:
void _ready() override {
map = rmp::assets::load_map("world.ldtk", _name);
_player = spawn<Player>({ .position = _arrival }).handle();
camera.follow = _player;
camera.limits = map.bounds();
}
void _update(float) override {
if (!_player) return;
const std::string_view next = map.neighbour_at(_player->position);
if (!next.empty()) rmp::Scene::change<Level>(std::string(next), _player->position);
}
std::string _name;
Vector2 _arrival;
rmp::Handle<rmp::Object> _player;
};Both
answers are std::string_views of the map's own text, good while the map is loaded,
which is why the next scene is handed a std::string of the name: by the time it
loads, this map is gone. level() is the
identifier of the level loaded. The platformer in examples/games/07_platformer
is a world of three levels side by side in a GridVania layout, walked through exactly like this:
level.cpp.
An LDtk entity, or an object on a Tiled object layer, is a
rmp::MapObject: a type, a position, a size and a set
of properties. A factory says what to make of each type, and
spawn_objects() runs them all:
class LevelScene : public rmp::Scene {
void _ready() override {
map = rmp::assets::load_map("world.ldtk");
map.on_object("Goblin", [](rmp::Scene &scene, const rmp::MapObject &o) {
auto &goblin = scene.spawn<Goblin>({ .position = o.position });
goblin.hp = o.property_int("hp", 20);
});
map.spawn_objects(*this);
camera.limits = map.bounds();
}
};Three things in it matter:
on_object() is called after
load_map(). Factories belong to the map that is loaded when they are registered:
on an empty map they register nothing, and the next load_map() starts with none.rmp::Object. The editors give a corner or a pivot; the
conversion is done once, when the map is read, so no factory has to.LDtk's entity fields and Tiled's custom properties are read by name. Every accessor takes a fallback, which is what comes back when the object has no property by that name, when the field was left empty in the editor, or when it holds another kind of value:
| In LDtk | In Tiled | Read with |
|---|---|---|
| Int | int | property_int(key, fallback); a float is cut towards zero |
| Float | float | property_float(key, fallback); an int is read too |
| Bool | bool | property_bool(key, fallback) |
| String, Multilines | string, file | property_string(key, fallback) |
| Enum | property_string: the value's name | |
| Color | property_string: "#rrggbb" | |
| EntityRef | property_string: the iid of the entity it points at | |
| Point | property_point(key): the world position of the centre of that cell | |
| Array<Point> | property_point(key, i) for each i below property_count(key) |
A point comes back in the same world units as position, so a patrol route drawn in
LDtk is used as it comes:
map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &bat = s.spawn<Bat>({ .position = o.position });
bat.speed = o.property_float("speed", 50);
for (int i = 0; i < o.property_count("patrol"); ++i) {
bat.route.push_back(o.property_point("patrol", i));
}
if (bat.route.empty()) bat.route.push_back(o.position);
});Not read: arrays of anything but points, and the FilePath and Tile field types.
Every LDtk entity has an iid, a unique
identifier, and an EntityRef field holds the iid of the entity it points at. Making
the link is up to the game: keep the iid on the object, and compare.
map.on_object("Key", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &key = s.spawn<Key>({ .position = o.position });
key.opens = o.property_string("opens"); // the iid of a Door
});
map.on_object("Door", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &door = s.spawn<Door>({ .position = o.position });
door.iid = o.iid;
});The
key and the door keep std::strings, and not what the map hands them: a
MapObject's names and the text of its properties are std::string_views of
the parsed map, good while the map is loaded, which is all of spawn_objects().
An iid also outlives the scene, which makes it the way to remember that a coin was
collected or a door opened when the player walks back into a level: the platformer keeps the
iids of what is gone in an rmp::global and
skips them in its factories.
A type nobody registered still comes out, as a plain invisible
rmp::Object with the position and the size, immovable. Whether it is solid depends on
what it was:
A Tiled map is the .json Tiled saves. What the reader expects of it:
.tsx
file is XML, which is not read: embed it in the map, or save the tileset as .tsj.
Until then that tileset draws nothing, none of its tiles are solid, and the load counts as
failed. The tileset image is looked up by its file name in resources/.solid is solid;
so is a tile the tileset gives a bool property solid set to true.type, its name is
name, and rotation and gid are Tiled's. Rectangles, ellipses,
points and polygons are placed by their top-left corner and tile objects by their bottom-left, and
both arrive at their centre. Objects come out in the order the layer has them.Tiled maps have no world: level() and neighbour_at() answer
"", and the map starts at 0,0.
The scene uses the map for drawing and collision; the same questions are open to the game, in world units:
| Call | Answers |
|---|---|
solid_at(point) | Whether a solid cell is under a point, on any layer. |
solid_in(rect) | Whether a solid cell covers any part of a rectangle. Every cell under it is checked, not only the corners. Touching is not covering: a box standing on the floor is not in the floor. |
tile_at(layer, column, row) | The tile in one cell of one layer, as its global tile id; 0 for an empty cell. Layers count from 0 at the bottom, and the cell is in that layer's own grid. For LDtk it is the topmost tile of the cell. |
bounds() | The level's rectangle in the world. |
tile_size() | One cell of the map's grid. |
layer_count(), object_count() | How many tile layers and how many objects it holds. |
An enemy that turns round at the edge of its platform, rather than walking off it, asks whether there is floor just ahead of its feet:
// Walking right: is there anything to stand on one pixel ahead and one below?
const Rectangle body = world_collider();
const Vector2 ahead{ body.x + body.width + 1, body.y + body.height + 1 };
if (!scene().map.solid_at(ahead)) velocity.x = -velocity.x;draw() is public for a game that wants the
map drawn somewhere else in its own order; draw(area) draws only the tiles that reach
into area, a rectangle of the world, which is how the scene draws it. The scene already
draws it, so calling it as well draws it twice.
// A minimap of the room the player is in, in a game that draws its own.
map.draw(Rectangle{ 0, 0, 320, 180 });Which cells are solid is worked out once, when the map is read — an LDtk IntGrid value called
Solid, a tile tagged Solid, a Tiled layer or tile marked solid all go into
one table — so solid_at() and solid_in() are a lookup each, as cheap on the
hundredth question of a frame as on the first. The walk to a cell of that table is what
rmp::find_path() searches.
examples/games/07_platformer is built on one
LDtk project, examples/games/07_platformer/resources/world.ldtk: three levels —
Meadow, Desert and Snowfield — side by side in a GridVania world, an IntGrid layer called
Collisions whose one value is Solid, a tileset whose enum tags mark the solid tiles,
and entities with fields: coins with a value, walkers and bats with a
patrol route of points, a moving platform with a to point, a key whose
opens is an EntityRef to its door, signs with text and an arrow enum. This is the
scene that plays any one of those levels, whole — loading it, a factory per entity, the camera,
and the walk into the next level:
// ---------------------------------------------------------------------------
// One level of the world: load it, build what LDtk placed in it, and watch the
// player leave it -- into the next level, or off the bottom.
// ---------------------------------------------------------------------------
#include "game.h"
#include "objects.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/input.h>
#include <rmp/tilemap.h>
#include <rmp/ui.h>
#include <algorithm>
#include <utility>
namespace game {
namespace {
// A sign's picture: plain, or with the arrow LDtk's `arrow` Enum asks for.
int sign_tile(std::string_view arrow) {
if (arrow == "Left") return tiles::SIGN_LEFT;
if (arrow == "Right") return tiles::SIGN_RIGHT;
return tiles::SIGN;
}
} // namespace
LevelScene::LevelScene(std::string level, Entry entry)
: _level(std::move(level)), _entry(entry) {}
void LevelScene::_ready() {
// "" is the first level of the world, whatever LDtk calls it: rename or
// reorder the levels there and the game still starts at the beginning.
map = rmp::assets::load_map("world.ldtk", _level);
rmp::audio::music("music"); // already playing after a level change: not restarted
// Not Space, not Enter: those are the jump's and the menus'. Defining it
// again in the next level replaces it, never adds to it.
rmp::input::action("pause", KEY_ESCAPE, KEY_P, GAMEPAD_BUTTON_MIDDLE_RIGHT);
// The player first, so that what is built below can know who it is.
auto &player =
spawn<Player>({ .position = _entry.position, .velocity = _entry.velocity });
_player = player.handle();
// ---- what LDtk placed, one factory per entity -------------------------
//
// Anything already collected, stomped or opened in this run is in
// run().gone by its iid, and is simply not built again.
map.on_object("Player", [this](rmp::Scene &, const rmp::MapObject &o) {
if (!_entry.carried) _player->position = o.position;
});
map.on_object("Coin", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &coin = s.spawn<Coin>({ .position = o.position, .layer = 1 });
coin.iid = o.iid;
coin.value = o.property_int("value", 1);
});
map.on_object("Walker", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &walker = s.spawn<Walker>({ .position = o.position, .layer = 2 });
walker.iid = o.iid;
walker.speed = o.property_float("speed", 40);
walker.stompable = o.property_bool("stompable", true);
// The route is drawn in LDtk as Points; a walker keeps to its floor
// and only needs to know where to turn.
walker.left = walker.right = o.position.x;
for (int i = 0; i < o.property_count("patrol"); ++i) {
const float x = o.property_point("patrol", i).x;
walker.left = std::min(walker.left, x);
walker.right = std::max(walker.right, x);
}
});
map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &bat = s.spawn<Bat>({ .position = o.position, .layer = 2 });
bat.iid = o.iid;
bat.speed = o.property_float("speed", 50);
for (int i = 0; i < o.property_count("patrol"); ++i) {
bat.route.push_back(o.property_point("patrol", i));
}
if (bat.route.empty()) bat.route.push_back(o.position);
});
map.on_object("MovingPlatform", [this](rmp::Scene &s, const rmp::MapObject &o) {
auto &platform = s.spawn<Platform>({ .position = o.position });
platform.collider = rmp::rect(o.size);
platform.from = o.position;
platform.to = o.property_point("to", o.position);
platform.speed = o.property_float("speed", 40);
platform.rider = _player;
});
map.on_object("Key", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &key = s.spawn<Key>({ .position = o.position, .layer = 1 });
key.iid = o.iid;
key.opens = o.property_string("opens");
});
map.on_object("Door", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &door = s.spawn<Door>({ .position = o.position });
door.collider = rmp::rect(o.size);
door.iid = o.iid;
});
map.on_object("Spikes", [](rmp::Scene &s, const rmp::MapObject &o) {
// Only the points hurt: the bottom eight pixels, a little in from the ends.
auto &spikes = s.spawn<Spikes>({ .position = o.position });
spikes.collider = rmp::rect({ o.size.x - 4, 8 });
spikes.collider.offset = { 0, (o.size.y / 2) - 4 };
});
map.on_object("Sign", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &sign = s.spawn<Sign>({ .position = o.position, .layer = -1 });
sign.text = o.property_string("text");
sign.tile = sign_tile(o.property_string("arrow", "None"));
});
map.on_object("Goal", [](rmp::Scene &s, const rmp::MapObject &o) {
s.spawn<Goal>({ .position = o.position });
});
map.spawn_objects(*this);
_start = _player->position;
// ---- the camera ----------------------------------------------------------
camera.follow = _player;
camera.limits = map.bounds(); // the level's own rectangle, in the world
camera.smoothing = 10;
camera.zoom = ZOOM;
}
void LevelScene::_update(float delta) {
if (_over) return;
if (rmp::input::just_pressed("pause")) {
rmp::Scene::push<PauseScene>(); // this scene freezes under it, clock and all
return;
}
run().seconds += delta;
const auto player = _player.get();
if (!player) return;
// THE NEXT LEVEL. Out of this one and into another of the world: change
// to it, and arrive at the same world position going the same way.
const std::string_view next = map.neighbour_at(player->position);
if (!next.empty()) {
_over = true;
rmp::Scene::change<LevelScene>(std::string(next),
Entry{ true, player->position, player->velocity });
return;
}
// No level there. The sides of the world are walls; below is a fall.
const Rectangle b = map.bounds();
if (player->position.x < b.x || player->position.x > b.x + b.width) {
player->position.x = std::clamp(player->position.x, b.x, b.x + b.width);
player->velocity.x = 0;
}
if (player->position.y > b.y + b.height + 48) {
lose_life();
if (!_over) respawn();
}
}
void LevelScene::lose_life() {
if (_over) return;
Run &r = run();
--r.lives;
camera.shake(5, 0.35f);
rmp::audio::play("hurt");
if (r.lives > 0) return;
_over = true;
rmp::audio::music("lose", false);
rmp::Scene::push<EndScene>(false, false);
}
void LevelScene::respawn() {
if (const auto player = _player.get()) {
player->position = _start;
player->velocity = Vector2{};
}
}
void LevelScene::win() {
if (_over) return;
_over = true;
const bool record = keep_if_best(run().coins, run().seconds);
rmp::audio::music("win", false);
rmp::Scene::push<EndScene>(true, record);
}
// The HUD, in screen space: hearts, coins and the clock down the left, drawn
// from the same tiles as the world and at its scale -- however the window
// stretches it -- and the Pause button at the right.
void LevelScene::_draw() {
const float scale = camera.raylib().zoom; // screen pixels to a pixel of the art
for (int i = 0; i < 3; ++i) {
const int heart = i < run().lives ? tiles::HEART : tiles::HEART_EMPTY;
draw_icon(heart, { (6 + (static_cast<float>(i) * 17)) * scale, 4 * scale },
scale);
}
draw_icon(tiles::COIN, { 6 * scale, 22 * scale }, scale);
draw_icon(tiles::TIMES, { 20 * scale, 22 * scale }, scale);
draw_number(run().coins, { 32 * scale, 22 * scale }, scale);
draw_seconds(run().seconds, { 6 * scale, 40 * scale }, scale);
// A phone has no Escape: the one way to pause there is a finger. The
// interface knows this scene is being played -- the player reads Space,
// the arrows and the A button through rmp::input -- so the button takes
// no focus, and Space jumps rather than pressing it (FrameOptions'
// focus_first, in rmp/ui.h).
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT });
if (rmp::ui::button("Pause")) rmp::Scene::push<PauseScene>();
rmp::ui::end();
}
} // namespace game
A map that is missing or does not parse is an empty map:
valid() is false, every query answers zero,
empty or false, and on_object() registers nothing. The game runs, on a level with
nothing in it. Each reason is said in the log in words that name the file and the fix — the
compressed layers, the .tsx tileset, the level LDtk keeps in a file that is not in
resources/, the level name that is not in the project. A map file that is missing,
or does not parse, counts as a failed
load, and so does a tileset image that is not there or does not decode, so the boot check in CI
sees them.
https://omardev29.github.io/rmp-docs/manual/modules/audio.html
rmp::audio plays a sound by its name and
a song by its name, and that is most of it. There is no device to open, nothing to load first,
no stream to feed and nothing to unload: the framework does each of those at the moment it has to
be done, and on a machine with no sound at all, every call quietly does nothing.
rmp::audio::play("coin");The name is logical: "coin" finds coin.wav,
coin.ogg, coin.mp3 or coin.qoa in resources/,
trying them in that order and taking the first that exists. Re-export a sound in another format
and the code does not change. A name that already ends in an audio extension —
"coin.ogg" — is taken exactly as written.
The first play() of a name loads the file; every
later one costs nothing, because the sound stays loaded until the game ends. A sound comes out of
the pack in a release and out of the folder while
you work, like every other asset.
A second argument changes one play, and only that play. Its fields, in the order a designated initialiser has to write them:
| Field | Default | Means |
|---|---|---|
volume | 1 | 0 to 1, for this play; multiplied by the SFX bus and by MASTER. |
pitch | 1 | 2 is an octave up, 0.5 an octave down, from 1/16 to 16: past either end it stops there. Zero, a negative number or a NaN plays at 1. |
pan | 0 | -1 is the left speaker, 0 the centre, 1 the right; clamped to that range. |
rmp::audio::play("hit", { .volume = 0.7f, .pitch = 1.2f });
rmp::audio::play("door", { .pan = -0.8f }); // mostly from the left
rmp::audio::play("step", { .pitch = rmp::random::range(0.9f, 1.1f) });The last line is the cheapest trick in game audio: the same footstep at a slightly different pitch each time stops sounding like a recording. With a fixed seed, it is also the same sequence of footsteps every run.
Playing a sound that is still playing starts it again on another voice instead of cutting the first one off, so a machine gun sounds like one and not like a stuck record. Each sound has up to four voices; when all four are busy, the one that has been playing longest is cut. The voices share the loaded samples, so a voice costs a few bytes, not a second copy of the sound.
class LevelScene : public rmp::Scene {
void _ready() override { rmp::audio::music("level1"); }
};music() starts a track, looping, and replaces
whatever was playing. There is one track at a time. The name is logical, the same as for
play().
Asking for the track that is already playing is not a restart. A scene that asks for
its song in _ready() can be changed to itself every time the player dies, and the song
carries on instead of jumping back to the beginning. The platformer asks for its music in every
level's _ready() and the music plays straight through from one level to the next.
A track that is not looped plays once and stops, which is what a jingle wants. Asking for it again once it has finished starts it again:
rmp::audio::music("victory", false); // once, then silencestop_music(), or
music(""), stops the music and lets the track go.
music_playing() says whether anything is
playing right now.
The new track is loaded before the old one stops, so asking for a song that does not exist leaves the current one playing, and says so once. A name that came to nothing is remembered and not searched for again.
Music is streamed: it is decoded a little at a time while it plays, so the minutes of sound it
would decode to never exist in memory at once. The encoded file itself is held in memory while it
plays, which is what lets a song come out of the pack — a few megabytes for a few minutes of
.ogg. The stream is fed once per frame by the framework, so music keeps playing under
a pause menu that freezes the scene below it.
| Format | As a sound | As music |
|---|---|---|
.wav | yes, found by its logical name, first | yes |
.ogg | yes, second | yes |
.mp3 | yes, third | yes |
.qoa | yes, fourth | yes |
.xm, .mod | no | yes, by the full name: music("theme.xm") |
.flac | no | no: raylib is built without its decoder |
A short effect is best as .wav, which needs no decoding; music is best as
.ogg, which is small.
A settings screen offers three volumes, and those are the three buses of
rmp::audio::Bus:
MASTERMUSICMASTER.SFXMASTER, multiplied by each play's own volume.Each is a fraction from 0 to 1, and they multiply: music at 0.8 under a master of 0.5 plays at
40 percent. They start at the values in [audio]:
[audio]
master = 1.0
music = 0.8
sfx = 1.0A volume is a fraction of full, not a gain, so a value past 1 is refused when the
.toml is read rather than turned into clipping:
[audio]
music = 1.5 raylib_multiplatform.toml:2: music = 1.5
^^^^^^^^^^^
configure: error: [audio] music = 1.5 has to be between 0 and 1.
It is a fraction of full volume, not a gain: past 1 is clipping, and a negative volume means nothing. Use 1 for full.At run time, set_volume() moves a bus and
volume() reads it. A new volume takes effect at
once on what is already playing — effects still ringing out keep their own volume and are scaled
by the new SFX. The value is clamped to 0..1, and a NaN is ignored rather than
stored, so one bad slider value cannot silence the game.
class SoundSettings : public rmp::Scene {
float _music = rmp::audio::volume(rmp::audio::Bus::MUSIC);
float _effects = rmp::audio::volume(rmp::audio::Bus::SFX);
void _draw() override {
rmp::ui::begin();
if (rmp::ui::slider("Music", _music, 0, 1))
rmp::audio::set_volume(rmp::audio::Bus::MUSIC, _music);
if (rmp::ui::slider("Effects", _effects, 0, 1))
rmp::audio::set_volume(rmp::audio::Bus::SFX, _effects);
if (rmp::ui::button("Back")) rmp::Scene::pop();
rmp::ui::end();
}
};Neither call opens the sound device, so a settings screen can show and move its sliders in a game that has not made a sound yet. The buses are not saved for you; a game that wants the player's volumes next time keeps them with rmp::save, as examples/ui/04_settings does.
A game does not call InitAudioDevice() or CloseAudioDevice(). The device
opens the first time something needs it — a play(), a music(), or a
rmp::assets::load_sound() — so a game with no
sound never opens it. On the way out, the voices and the music are released before the device
closes, in the order that does not crash. A game that opens the device itself — older code, a
raylib example pasted in — keeps it: the framework closes only a device it opened.
available() says whether the device is open
and working. It is false until the first sound, and asking does not open anything.
A CI runner, a server, a laptop with no output: the device fails to open, and that is not an error. The framework says so once —
AUDIO: no sound device on this machine; sound is off and every rmp::audio call is a silent no-op from here on
— and the game runs, silent. The open is tried once: a footstep sixty times a second does not
pay for a failing device sixty times a second. Because this is a fact about the machine and not a
mistake in the game, [dev] strict does not abort on it, and a strict debug build
still runs on a machine with no speakers.
A game that does not want sound at all can take the audio module out of raylib, which makes the binary smaller. The game still compiles unchanged, and behaves exactly as it does on a machine with no device:
[raylib]
disabled_modules = ["raudio"]Except on iOS, where
the setting does nothing: the iOS build links a prebuilt raylib, built without it, and
configure.py warns so when iOS is among the targets.
Browsers keep a page silent until the player has clicked, touched it or pressed a key. That is the browser's rule, and no game gets round it: music started on the title screen is heard from the player's first click or key press on. A gamepad button does not count, because browsers do not treat it as a gesture, so a player on a gamepad alone hears nothing until then.
For raylib's own sound functions there is a handle:
rmp::assets::load_sound() returns an rmp::Sound
that converts to raylib's Sound, opening the device first if it has to.
rmp::Sound beep = rmp::assets::load_sound("beep.wav");
PlaySound(beep);It and play() do not get in each other's way. play() never plays the
sound it loaded, only voices that share its samples, so a volume, pitch or pan it sets never lands
on the rmp::Sound you hold.
A name that finds no file, or finds one that does not decode, plays nothing, and says which of the two it was, once:
These are mistakes in the game, so under [dev] strict the first of them aborts a
debug build. Looking a logical name up is not counted as a
failed load: trying four extensions to
find one file is not three failures, so a game whose sounds are .ogg boots with
nothing failed. It also means a sound that is missing altogether is caught by the warning, not by
the boot count. A file that is found and does not decode is different: the sound or the song is
there and broken, and that counts as a failed load, the way a broken picture does.
https://omardev29.github.io/rmp-docs/manual/modules/saving.html
A save is a rmp::Value — a tree of
numbers, strings, lists and objects — written to a slot with
rmp::save::write() and read back with
rmp::save::read(). Every read has a default, a write
never leaves half a file behind, and the file goes where each platform expects a game's data to
be.
rmp::Value v;
v["level"] = 7;
v["name"] = "Ada";
v["unlocked"].push("forest");
rmp::save::write("slot1", v);and, the next time the game starts:
rmp::Value v;
rmp::save::read("slot1", v);
const int level = v["level"].as_int(1); // 1 on the first run: there was nothing to readThere is no if around the read, and the first run needs no code of its own. When
there is no save, v stays empty, and an empty Value answers every question with the
default it is given.
A Value is one of six things — exactly what JSON can hold, so a real structure fits and not only flat pairs:
Type | Holds | Read with |
|---|---|---|
NONE | nothing: a missing key, an index out of range, a Value never assigned | every reader returns its fallback |
BOOL | true or false | as_bool(fallback) |
NUMBER | a double: every integer up to 253 is exact | as_int(fallback), as_float(fallback) |
STRING | text | as_string(fallback) |
LIST | Values in order | v[i], size() |
OBJECT | keys naming Values, in the order they were added | v["key"], contains(), key(i) |
Assigning makes the Value what was assigned, and assigning through a key or an index makes whatever path leads there:
rmp::Value v;
v["player"]["x"] = 120.5f; // creates "player", an object, on the way
v["player"]["hp"] = 3;
v["inventory"] = rmp::Value::list(); // an empty list, for "nothing yet"
v["inventory"].push("sword");
v["inventory"].push("rope");
v["options"]["subtitles"] = true;rmp::Value::list() and
rmp::Value::object() make an empty one of each;
push() appends to a list, and turns a Value that
holds nothing into one first. erase(key) removes a
key, and assigning rmp::Value{} to a key amounts to the same: a key that holds nothing
and a key that is not there read the same everywhere, in size(), in
contains(), in == and in the file.
A Value can also come from a JSON file of your game's: rmp::assets::load_value(), which
remembers the file, so a Debug build can reload
it while the game runs.
Reading through [] walks the tree and returns what is there, or nothing. It does
not add the keys it asks about, even on a Value that is not const:
rmp::Value v;
const int coins = v["stats"]["coins"].as_int(0); // 0, and v is still emptyThat is the difference from std::map, where asking is adding. Reading a save never
grows it, and reading a Value never warns about anything, so going through what a load returned
can never be what trips [dev] strict.
A read gives the fallback whenever the Value is not of the type asked for. Types are not
converted: a number is not a bool, and "7" is not 7. as_int() cuts a
number towards zero and clamps it to the range of an int, so an edited save holding a
number too big for one cannot overflow anything. as_float() clamps to the range of a
float the same way, so a finite number never reads as an infinity.
as_string() returns a view that is valid while the Value is alive and unchanged; copy it
into a std::string to keep it.
Writing through a path creates what is missing, but it does not change what is there into
something else. Writing a key into a number — a number read from an old save, say — goes nowhere,
and says so once; so does an index past the end of a list. Turning that number into an object
behind your back would lose it. To change what a key is, assign the whole thing first:
v["stats"] = rmp::Value::object();. A list is written at 0 up to
size(), and writing at size() appends.
Reading a save never needs type(): a read of the
wrong type gives its fallback. A tree of unknown shape — one a modding tool wrote, say — is walked
with type(), size() and key(i):
rmp::Value v;
rmp::save::read("slot1", v);
const rmp::Value &items = v["inventory"];
std::vector<std::string> names;
for (int i = 0; i < items.size(); ++i) names.emplace_back(items[i].as_string("?"));
const rmp::Value &stats = v["stats"];
for (int i = 0; i < stats.size(); ++i) {
const std::string_view key = stats.key(i);
const int value = stats[key].as_int(0);
}Two Values are == when they hold the same things, whatever order an object's keys
were added in.
write(slot, value) returns whether it worked. A
write that fails leaves the previous save exactly as it was: the new file is written beside the
old one, flushed to the disk, and only then put in its place, so at every instant there is one
whole save on disk — the old or the new. The power going out in the middle of a save does not lose
the game.
A slot is the name of the file, without its extension: letters, digits,
_, - and ., not starting with a dot, at most 64 of them. Each
slot is a file of its own, so a game with three save slots, settings and a best score uses five
names. Anything else — a path above all — is refused and said once.
A Value that could not be read back is refused too, rather than written and lost: more than
64 lists and objects inside each other, a NUL character in a string or a key, or a number that is not
finite — a NaN or an infinity, which JSON cannot hold. A file holding a number too large for a
double, such as 1e400, is not a save at all: read() says UNREADABLE.
A write flushes the file to the disk, so it is a thing to do at a checkpoint, on a menu, when a level ends — not every frame.
read(slot, value) fills the Value you hand it, by
reference, and returns a
Result that is true in an if only when
the save was read and checked. When it is false,
status says why, because each reason is a
different thing to tell a player:
Status | Means |
|---|---|
OK | Read, checked, and the Value filled. |
MISSING | Nothing has been saved in that slot: the first run. |
TRUNCATED | The file is cut short, as a write the power went out on would be. |
MODIFIED | The checksum or the seal does not match: the file was edited, or the disk damaged it. |
UNREADABLE | Not a save at all, a save from a newer version of the framework, a slot name that is refused, or a file too large to be one. |
On anything but OK, the Value passed in is left exactly as it was. That gives the
pattern for loading settings: fill a struct with its defaults, read, and let each field take the
saved value when there is one.
struct Settings {
float music = 0.8f;
bool subtitles = false;
};
// Each field keeps its default unless the save has it. True when the file
// was there and could not be trusted.
bool load_settings(Settings &s) {
rmp::Value v;
const rmp::save::Result read = rmp::save::read("settings", v);
s.music = v["music"].as_float(s.music);
s.subtitles = v["subtitles"].as_bool(s.subtitles);
return read.status == rmp::save::Status::MODIFIED ||
read.status == rmp::save::Status::TRUNCATED;
}A missing file is simply the first run and needs no message; a damaged one is worth telling the player about before the next write replaces it. That is what examples/ui/04_settings does.
exists(slot)remove(slot)directory()Each platform has a place for an application's own data, and the saves go there, in a folder
named after [project] name:
| Platform | Folder |
|---|---|
| Windows | %APPDATA%\<name>\ |
| macOS | ~/Library/Application Support/<name>/ |
| Linux and the BSDs | $XDG_DATA_HOME/<name>/ when that is set to an absolute path, otherwise ~/.local/share/<name>/ |
| Android | the app's private internal storage, in a saves folder: no permission needed, invisible to other apps, removed with the app |
| iOS | Library/Application Support/ in the app's own container — not Documents, which Apple keeps for files the user made |
| Web | the browser's IndexedDB, one database per game |
On the web, every write and every remove is copied into IndexedDB, and the game does not start until the saves already there have been read in, so the first scene finds them. Where the browser refuses IndexedDB — a private window, storage turned off — the game still runs, and its saves last as long as the tab.
A
game handed out as a zip — on itch.io, say — is expected to keep everything in its own
folder, so that deleting the folder deletes the game. [save] portable = true puts the
saves in a saves folder next to the executable instead. Only Windows, Linux and
FreeBSD have such a place; on macOS, Android, iOS and the web the setting is ignored. NetBSD and
OpenBSD cannot say where an executable is — raylib's GetApplicationDirectory() has no
answer there — so the saves go to the user's folder, and the log says so once:
SAVE: [save] portable: this system does not say where the executable is; saving in the user's folder instead
If that folder cannot be written — a portable build copied into Program Files — the saves go to the user's folder instead, and the log says so once:
SAVE: cannot write in … (a portable build in a read-only folder, like Program Files?); saving in … instead
Reads look in both folders and take the newer save, so a session that had to fall back and a
later one that did not — the game was moved out of Program Files — do not disagree about where the
player's progress is. directory() returns where the saves really went.
[save]
portable = false
encrypt = false
version = 1portableencryptwrite() seals the file by default. See below.versionNothing in [save] is a secret, and there is no password to put there; a key the
section does not have is refused:
[save]
password = "hunter2" raylib_multiplatform.toml:2: password = "hunter2"
^^^^^^^^^^^^^^^^^^^^
configure: error: unknown key [save.password] in raylib_multiplatform.tomlMost updates need no migration at all. A save written by yesterday's version is not broken, it is only missing the keys added since, and a missing key reads as its default. Adding a key never needs a version bump.
Bump [save] version when a key changes meaning — when gold
becomes coins, or a time is stored in milliseconds instead of seconds. The version
the file was written with comes back in version(),
and the game moves the old meaning to the new one as it reads:
rmp::Value v;
if (rmp::save::read("slot1", v) && v.version() < 2) {
v["coins"] = v["gold"].as_int(0);
v.erase("gold");
}write() always stores the version this build has, so once the migrated Value is
written back, the save is migrated for good.
[save]
version = 2The version is a counter that only goes up, from 1:
[save]
version = 0 raylib_multiplatform.toml:2: version = 0
^^^^^^^^^^^
configure: error: [save] version = 0 has to be between 1 and 2000000000.
It is a counter that only goes up, starting at 1; it is stored as an int.A plain save is readable: it is one line of header followed by the JSON, and anyone who opens
it in a text editor can see the coins and change them. A sealed save is encrypted and
authenticated, so it cannot be read, and any change to it — a single byte, even with the checksum
worked out again — reads as MODIFIED.
[save] encrypt = true seals every write; a single write can ask either way:
rmp::save::write("slot1", v, { .encrypted = true });
rmp::save::write("debug", v, { .encrypted = false });With sealing on, a plain file in a slot reads as MODIFIED too — otherwise
anyone could replace a sealed save with a plain one of their own. A game that turns sealing on in
an update still has players with plain saves; it reads them for as long as they may exist
with:
rmp::save::read("slot1", v, { .sealed_only = false });The seal is XChaCha20-Poly1305, from the copy of Monocypher the framework already carries for its resource pack, with a fresh random nonce for every write.
Every save is one line of ASCII, then the payload:
rmp-save 1 <version> <plain|sealed> <payload bytes> <crc32>
{"level":7,"name":"Ada","unlocked":["forest"]}The 1 is the layout of the file itself; a framework that meets a bigger one says
UNREADABLE rather than guessing. The checksum, a CRC-32, spans the first line and
the payload, so an edited version or length is caught like an edited byte, and the length is what tells a file cut
short (TRUNCATED) from one with something added (MODIFIED). A file of
more than 64 MB is not a save and is not read.
Numbers are written with as many digits as it takes to read back exactly the same number, and
read and written with a . as the decimal point whatever language the player's system
is set to, so a save made under a German locale reads anywhere.
https://omardev29.github.io/rmp-docs/manual/modules/localization.html
Every text the framework draws is an rmp::Text.
A literal you write in the call translates itself: its own words are the key it is looked up by in
the game's tables, and what the tables do not have is shown as written. So the three-function menu
is already translatable, without a line of its own:

![The same panel in Japanese, drawn with the font [lang] fonts names for it; below it, two notices shown before the switch, still in the language they were shown in](shots/e2e/ui/11_localization/ja.png)
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) rmp::app::quit();
rmp::ui::end();Add a table with a Spanish column, and a player whose system speaks Spanish sees
Jugar and Salir. Nothing else changes. The header is
rmp/text.h, and rmp/ui.h already includes it.
The difference is the type, not the words. A string literal written in the call
("Play") is a fixed key: translated. A string made while the game runs — a
std::string, a std::string_view, what TextFormat() returns —
is shown exactly as it is and never looked up, because it has no key that stays the same from one
frame to the next:
rmp::ui::text("High scores"); // translated
rmp::ui::text(player_name); // the player's name, as it is
rmp::ui::text(TextFormat("%d", score)); // a number, as it isA literal kept in a std::string_view variable first is a runtime string by then.
Pass the literal straight to the function, or make the rmp::Text where it is
written.
A text with a value in it keeps its key fixed by naming the value instead of printing it:
rmp::ui::text(rmp::Text("Score: {score}", { { "score", score } }));
rmp::ui::text(rmp::Text("{name} wins in {time} s", { { "name", "Ada" }, { "time", seconds } }));The key is Score: {score}, whatever the score is, and the Spanish column says
Puntos: {score}. Each rmp::TextArg is a
name and a number or a text. A whole number is written as one (3, and
100000000 for a double that holds it); any other number is written with the fewest
digits that read back as the same number (2.5, 0.1). A text argument goes
in as it is, never translated. {{ and }} are a brace, and a placeholder
with no argument of its name stays as written, braces and all, so a missing value is visible.
A widget's identity is its text's key and context, never the translation, and never the
values: Score: {score} is the same button at every score and in every language, so
the focus, the hover and a click in progress all survive a score that changes and a language that
changes.
When the arguments hold a number, a text can have plural forms, written in one cell with
| between them, in the order of the language's
CLDR plural categories. The
first number among the arguments chooses:
rmp::ui::text(rmp::Text("{count} gem|{count} gems", { { "count", gems } }));| Languages | Forms | Chosen by |
|---|---|---|
| English, Spanish, German, Italian, Dutch, the Nordic languages, Greek, Hungarian, Turkish and others | one|other | one for exactly 1 |
| French, Portuguese, Hindi, Bengali, Persian | one|other | one for 0 and 1 |
| Russian, Ukrainian, Belarusian | one|few|many|other | 1, 21, 31…; 2–4, 22–24…; the rest of the whole numbers; fractions |
| Polish | one|few|many|other | 1; 2–4, 22–24…; the rest; fractions |
| Czech, Slovak | one|few|many|other | 1; 2–4; fractions; the rest |
| Japanese, Chinese, Korean, Thai, Vietnamese, Indonesian, Malay and others | other | the one form there is |
A language not on the list takes the last form written. A | in a text with no
number among its arguments is a character like any other. rmp text check fails on a
cell with the wrong number of forms for its language.
"Open" a door and "Open" a file are one key in English and two words in many languages. A
context tells them apart: it is a column of the
table, and two rows with the same key and different contexts are two texts.
if (rmp::ui::button(rmp::Text("Open", { .context = "door" }))) { /* ... */ }
if (rmp::ui::button(rmp::Text("Open", { .context = "file" }))) { /* ... */ }They are two buttons as well: the context is part of the identity.
Translations live in resources/, in tab-separated files, and the game can use
either shape or both; they are merged when the game starts.
lang.tsv in resources/
([lang] file). The first row is
the header, key, context, then one column per language code, and an
unused column that rmp text scan keeps:
key context en es unused
Play Play Jugar
Open door Open Abrir
{count} gem|{count} gems {count} gem|{count} gems {count} gema|{count} gemas
language.name English Españoles.tsv in a lang folder of resources/
([lang] folder): three
columns, key, context and the text, the file's name being the language.
A translator can have one file without seeing the others.A row starting with # is a comment, a cell may hold \t,
\n and \\ for a tab, a new line and a backslash, and a file written on
Windows, with CRLF and a byte-order mark, reads the same. The row language.name is the
language's own name, what a language menu shows. In a debug build on the desktop the tables are
watched: edit a translation, and the next frame shows it.
With [lang] languages
empty, the files of the folder are looked for under the common codes (en,
es, fr, de, pt-BR, ja,
zh-TW and the others of the list in src/rmp/text/text.cpp); a game that ships
another one names it in the list.
The game starts in the language the player chose last time, if rmp::lang::set() was ever called; otherwise in the
system's language — the environment on Linux and the BSDs, the preferred languages on macOS and
iOS, the user's locale on Windows, the device's configuration on Android, the browser's language on
the web — and otherwise in [lang]
default. A text is looked up down a chain: es-MX, then es,
then the default language, then the words the code wrote.
With [lang] languages set, the system's language is taken only when it is one of
them (or a chain of it reaches one), so a player is never put in a language the game does not
ship. rmp::lang is the rest:
for (const std::string &code : rmp::lang::available()) {
if (rmp::ui::button(rmp::lang::name(code))) rmp::lang::set(code); // "English", "Español"...
}
rmp::ui::text(rmp::Text("Language: {name}",
{ { "name", rmp::lang::name(rmp::lang::current()) } }));set() changes every screen at once — the next
frame draws in it, nothing is reloaded — and saves the choice with
rmp::save, so the next run starts in it.
available() is [lang] languages in
its order, or every column and file the tables have.
translate() is the text of a key in the current
language, for a place that is not the UI's — a window of your own, a texture drawn with raylib.
The interface bakes the letters a text needs when it first draws them, so any alphabet works
with a font that has its glyphs — Cyrillic, Greek, Chinese, Japanese, Korean. A language whose
alphabet the [ui] font lacks gets
a font of its own:
[lang]
languages = ["en", "es", "ja"]
fonts = { ja = "NotoSansJP.ttf" }The interface changes to it when the language changes, and back to the [ui] font
for a language with none. Right-to-left and complex shaping — Arabic, Hebrew, the Indic scripts —
are not supported: their letters are drawn left to right, one by one.
A language menu shows every language's name at once, whatever the language is: 日本語 has to be
drawn in a font with kanji while the interface is in English, and Español in one with ñ while it is
in Japanese. A button's Style names its font:
rmp::Font japanese = rmp::assets::load_font("jp.ttf", 16);
rmp::Font latin = rmp::assets::load_font("font.ttf", 16);
void _draw() override {
rmp::ui::begin();
rmp::ui::row([this] {
for (const std::string &code : rmp::lang::available()) {
rmp::ui::Button pick{ .text = rmp::Text(rmp::lang::name(code)),
.id = "language_" + code };
pick.style.font = code == "ja" ? japanese : latin;
if (pick.show()) rmp::lang::set(code);
}
});
rmp::ui::end();
}A font in a scene's members loads as one in _ready() does: RMP_GAME
opens the window before it makes the first scene. One loaded at namespace scope has no window yet,
and the framework says so, once (the app).
examples/ui/11_localization — play it in
its page — is a lantern stall in English, Spanish and Japanese from lang.tsv and German
from lang/de.tsv, with its plurals, its placeholders, a context, and Japanese in Jigmo
(CC0), cut down to the letters the table uses.
rmp text scan # add every text the game shows to resources/lang.tsv
rmp text check # fail on a text a shipped language lacks, or gets wrongrmp text scan reads the game's src/ and include/ for every
literal the framework translates — the first argument of the interface's text functions and of
rmp::Text, the .text, .placeholder and .items
of a kept widget, with the context an rmp::Text gives — the #line: ids
of the game's Yarn scripts, and what a
debug build drew that the tables lacked. It adds a row for each text that is not there, with the
words in the default language's column, and keeps every translation. A row nothing uses any more
is never deleted: it gets an x in its unused column, and the game and
rmp text check ignore it — in the per-language files too. The
language.name row is never marked: rmp::lang::name() reads it, and no
literal in the code does.
The texts a debug build drew and did not find are written, when the game ends, to
lang_seen.tsv next to the executable
([lang] collect), and
scan reads it from build/debug/: a text built in a way the scanner cannot
see still reaches the table, the first time somebody sees it on screen.
rmp text check holds the tables to [lang] languages, or to every
language they have: a text with no translation, a placeholder a translation lost or invented, a
plural with the wrong number of forms. Each mistake is a line with the file, the key and the
language. It is a stage of rmp test and a step of a game's CI, so a release cannot
ship a language with a hole in it.
[window]
title, which is the game's name.DrawText()); pass it through
rmp::lang::translate() first.https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html
A conversation is written in a .yarn file in resources/, in
Yarn Spinner's language, version 3, and run by an
rmp::Dialogue. The framework compiles it with a
compiler of its own — a port to C++ of Yarn Spinner's official one — and steps it with a small
machine: the game shows the lines, offers the choices and answers the commands. Drawing it is a
separate piece, so the same conversation can be a box at the bottom of the screen, a bubble over
a head, a visual novel's stage, or something the game draws itself. The header is
rmp/dialogue.h.



title: Start
---
<<declare $gold = 10>>
<<declare $met = false>>
Mika: Welcome, traveller. #line:welcome #mood:happy
<<if $met>>
Mika: Back again? #line:again
<<else>>
Mika: I have not seen you before. #line:first
<<set $met = true>>
<<endif>>
Mika: What will it be? You have {$gold} gold. #line:ask
-> Buy a [wave]potion[/wave] <<if $gold >= 5>> #line:buy
<<set $gold -= 5>>
<<give_item potion>>
Mika: A fine choice. #line:fine
-> Ask about the tower #line:tower
<<jump Tower>>
-> Leave #line:leave
Mika: Safe travels. #line:safe
===
title: Tower
---
Mika: [shake]Nobody[/shake] comes back from the tower. #line:nobody
<<if visited("Tower") == false and has_key()>>
Mika: But you have the key... #line:key
<<endif>>
===Each node has a title: and its body between --- and ===.
Mika: names the speaker. {$gold} is the value of a variable, written
into the line. [wave]…[/wave] is markup the presenters draw. #line: is the
line's id, the key of its translation, and any other #tag travels with the line for
the game to read. -> lines are the choices, each with its body indented under it;
<<if …>> after a choice makes it available only when the condition holds.
give_item is a command of the game's, and has_key() a function of the
game's. Yarn's own documentation is the reference for the language; what the framework runs of it
is below.
rmp::Dialogue talk = rmp::assets::load_dialogue("wizard.yarn");
talk.start("Start");
// every frame:
if (talk.has_line()) {
say(talk.line().speaker, talk.line().text); // "Mika", "Welcome, traveller."
if (rmp::input::just_pressed("accept")) talk.advance();
} else if (talk.has_options()) {
for (const rmp::DialogueOption &o : talk.options()) offer(o.text, o.available);
if (rmp::input::just_pressed("accept")) talk.choose(picked);
}rmp::assets::load_dialogue() reads and
compiles the file. A script with a mistake gives a Dialogue that is not
loaded(), and
errors() says what is wrong, a line each, as
file:line:column: what; they are in the log too and, in a debug build, on screen.
Several files compiled together can jump from one to another:
const std::string_view files[] = { "town.yarn", "school.yarn", "endings.yarn" };
rmp::Dialogue story = rmp::assets::load_dialogue(files);At any moment the dialogue is waiting for one of three things, or for nothing once it has finished:
has_line().
line() is an
rmp::DialogueLine: its id, the
speaker, the text in the current language with the speaker and the markup
taken out, where the markup was, and its tags without the
#. advance() goes on.has_options().
options() are
rmp::DialogueOptions, and one whose condition
failed is there with available false: show it greyed out, or not at all.
choose(i) takes the one at that place.has_command()
and its text in command(); the game does
what it says and calls advance(). A command with a handler (below) never waits.running() is true from
start() to the end of the conversation or a
stop(), and
node() is the node it is in. A Dialogue is moved,
never copied: keep it in the scene that shows it, or in a Talker.
A script asks the game to do something with a command, <<walk Mika door>>,
and asks it a question with a function in an expression, has_item("key"). The game
answers both by name, with a lambda whose parameters say what it takes:
// has_item("key") in an expression: a string in, a bool out.
talk.on_function("has_item", [](std::string item) -> bool { return carries(item); });
// <<walk Mika door>>: two words, as two strings.
talk.on_command("walk", [](std::string who, std::string where) { walk_to(who, where); });
// <<quake 2.5>>: a number.
talk.on_command("quake", [](float strength) { shake_camera(strength); });A parameter is a number (float, int, double or any other
arithmetic type), a bool, a string (std::string or
std::string_view), or an rmp::DialogueValue,
which takes anything. A function returns one of the same. Each is checked before the call: a
script that gives has_item() two arguments, or a number where its string goes, or a
<<quake>> a word that is not a number, is a mistake said once — in the
log, on screen in a debug build, and in errors()
— and the call is not made. Write the result's type (-> bool): it is what
rmp yarn ysls tells the editor.
The untyped forms take every argument as it comes, for a function or a command that takes any number of them:
talk.on_command("give", [](std::span<const std::string> words) {
for (const std::string &item : words) give(item); // <<give potion map key>>
});
talk.on_function("sum", [](rmp::DialogueValue &result,
std::span<const rmp::DialogueValue> args) {
float total = 0;
for (const rmp::DialogueValue &a : args) total += a.as_number();
result = total; // sum(1, 2, 3)
});A command's words are what follows its name, with its {expressions} filled. A
command nobody handles does not run anything: the dialogue waits on it in
has_command(), for a game that reads
command() itself; the presenters pass it.
Yarn's own functions are built in: visited(), visited_count(),
random(), random_range(), dice(), round(),
round_places(), floor(), ceil(), inc(),
dec(), decimal(), int(), format_invariant() and
the conversions string(), number() and bool(). Their random
numbers come from rmp::random, so a
scripted run of the game is reproducible. There is no overloading: one name, one function.
start() looks at every function the script
calls, in every node, and says each one that is neither built in nor registered — when the
conversation starts, not at the line that calls it an hour into the game. Register the game's
functions before the first start(). What goes wrong while it runs — a node a
<<jump>> names that is not there, a call of the wrong kind — is said the
same way, once, and kept in errors(). rmp yarn check
finds all of it before the game is even built.
A command that takes time — someone walking to the door, a door opening, a camera panning — holds the conversation until it is over. Its handler starts it and says when it is done:
talk.on_command("walk", [&](std::string where) {
mika.walk_to(where);
talk.wait_until([&] { return mika.arrived(); }); // asked once a frame
});
talk.on_command("pause", [&](float seconds) { talk.wait(seconds); });From inside a command's handler, wait(seconds)
holds the dialogue for that long, and wait_until(done)
until done() is true; called anywhere else, either is a mistake said once. Yarn's own
<<wait 2>> does the first by itself, when the game has no command of
that name. While a command waits there is no line and no choice: the presenters draw nothing and
show() stays true, and the world is seen doing what the command started.
waiting() says whether a command holds it,
and asking is what moves it on — the presenters ask every frame, and so does a game's own loop:
if (talk.waiting()) {
// nothing to show: the world goes on
} else if (talk.has_line()) {
// ...
}Time is counted once a frame however often it is asked, from the step the scenes get, so a
script waits the same in every run. advance() past a wait goes on at once: a skip
button. A conversation shown over a world that is paused under it (a DialogueBox in a
pushed scene) can wait on time, but never on something in that world: nothing there moves.
examples/games/09_after_school shows its conversations in the town's own scene, so
Mika can walk to the pond while the dialogue waits.
talk.set_variable("$gold", 25); // before the script reads it
const float gold = talk.variable("$gold").as_number();
const int times = talk.visits("Tower"); // what visited_count("Tower") says
rmp::Value state;
talk.save(state); // variables, visits, what was seen once
rmp::Value saved;
saved["talk"] = state;
rmp::save::write("slot1", saved);
// and when the game starts again:
rmp::save::read("slot1", saved);
talk.load(saved["talk"]);save() puts everything the conversation
remembers — its variables, how many times each node was visited, which <<once>>
blocks and line groups have been seen — into an rmp::Value,
and load() takes it back, so a conversation
picks up where the player left it with rmp::save. A
variable a script declares has the type of its declaration; one the game sets has the type of
the value.
A variable the game keeps — the gold in the player's purse, the hour of the town's clock — is bound instead of copied: the script reads it and writes it, and there is one of it.
talk.bind("$gold", player.gold); // int &
talk.bind("$name", player.name); // std::string &
talk.bind("$met_mika", player.met_mika); // bool &
talk.bind("$speed", player.speed); // float &
talk.bind("$hour", // or two functions, for a value worked out
[&](rmp::DialogueValue &out) { out = hour; },
[&](const rmp::DialogueValue &in) { hour = in.as_number(); });<<declare $gold = 0>>
You have {$gold} coins.
<<set $gold = $gold - 5>>The script declares a bound variable, with the type it has
(<<declare $gold = 0>>): a binding to one it does not declare, or of
another type — a bool for a number — is a mistake said once, and the script keeps its
own. bind() takes a reference, so the variable
has to outlive the dialogue. save() leaves bound variables out: they are the game's
to save. Several conversations bound to the same variables share them, which is how every person
in 09_after_school knows what the others were told. Bind before the first
start(); a Talker has on_load for it.
The interface has three widgets that show a Dialogue, each kept in the scene and shown every
frame between begin() and
end(). They type the line out, offer the choices as
buttons and take the player's answer from the keyboard, a gamepad, the mouse or a finger:
rmp::Dialogue talk = rmp::assets::load_dialogue("wizard.yarn");
rmp::ui::DialogueBox box{
.portraits = { { .speaker = "Mika", .picture = mika_face } },
.flow = { .letters_per_second = 40, .blip = "blip" },
};
void _ready() override { talk.start(); }
void _draw() override {
rmp::ui::begin();
if (!box.show(talk)) { /* the conversation is over */ }
rmp::ui::end();
}| Presenter | Looks like | The world under it |
|---|---|---|
DialogueBox | A box along the bottom of the screen, the speaker's portrait and name beside the line, the choices under it: the classic RPG. | waits (pauses_world) |
DialogueBubble | A bubble over
the speaker's head, drawn in the world with rmp::ui::at()
over the object each BubbleSpeaker names, the choices in it. | goes on |
DialogueStage | A visual novel: big portraits of who is on stage, the one speaking in front and the others dimmed, the line in a box under them. | waits |
The same conversation, three ways: examples/ui/10_dialogue
switches between them while it runs, in Kenney's art (CC0) — play it in its page.
pauses_world is a hint for whoever starts the conversation: a box or a stage is
shown in a scene pushed over the game, which then stops under it; a bubble is drawn in the game's
own scene, which goes on. show() returns true while the dialogue has something to
show.
Every presenter has a flow:
letters_per_second types the line out, 0 shows it whole. A press while it types
shows the rest at once; the next press goes on. In the line, [speed=2]…[/speed]
types those letters twice as fast and [pause=0.4/] waits 0.4 s there.blip is a sound played as the letters appear, every blip_every
letters: the voice of a character who has no recorded voice.voices plays a recorded line: the sound named voices plus the line's
id, "vo/" and #line:welcome playing vo/welcome.auto_advance goes on by itself so many seconds after a line is whole, and
skip_seen lets a line already read go by at once.choice_seconds gives a choice a timer, drawn as a bar, and when it runs out
default_choice is taken — or the first available one, when that one is not.portraits are chosen by speaker and by the
line's #mood: tag, falling back to the speaker's picture for no mood; a picture is any
Picture — a texture, an atlas region, an Aseprite
sprite or slice, a nine-slice. style, name_style and
choice_style dress the box, the name plate and each choice with the same
Styles as every other widget, so a game's theme and
skins apply. The lines read so far are in ours.history, and a
DialogueBox's toggle_history() shows them in place of the box.
A Speaker is how one person's lines are shown:
their blip and its pitch, and a Style over the presenter's for their box and their
name plate. A field left unset is the presenter's.
rmp::ui::DialogueBox box{
.speakers = { { .name = "Mika", .blip = "blip_high", .pitch = 1.25f,
.name_style = { .tint = Color{ 226, 92, 92, 255 } } },
{ .name = "Sora", .pitch = 0.85f,
.style = { .background = Color{ 30, 40, 80, 230 } } } },
.flow = { .blip = "blip", .blip_jitter = 0.06f },
};A speaker with no blip of their own uses the flow's, at their pitch;
blip_jitter moves each blip's pitch by up to that much (0.06 is 6 %), so a voice
made of one sound does not drone. A BubbleSpeaker has the same blip,
pitch and style.
rmp::ui::DialogueBox box{
.width = 640, // 0: as wide as it is given
.portrait_size = 96, // design units, square
.portrait_side = rmp::ui::DialogueSide::RIGHT, // or LEFT
.name_offset = { 18, -16 }, // the plate on the frame's edge
.choices = rmp::ui::DialogueChoices::ABOVE, // IN_BOX, ABOVE or CENTER
};name_offset moves the name plate out of the column and over the frame's top-left
corner, so the line has the box to itself; { 0, 0 } puts it above the line.
choices shows the choices in the box in place of the line, in a panel of their own
above the box at its right, or in a panel in the middle of the screen. height fixes
the box's height, 0 being what the line needs.
A bubble drawn over its speaker has a tail pointing down at them, tail design
units tall and twice as wide, in the bubble's background colour — or tail_color, or a
picture of the game's art in its place, tail_picture. tail = 0 has none.
A bubble with nobody to point at, drawn where the game put it, has no tail either.
rmp::ui::DialogueStage stage{
.enter_seconds = 0.3f, .enter_offset = 80, // slides in from its side, and fades in
.focus_seconds = 0.15f, .focus_lift = 10, // the speaker comes forward...
.focus_scale = 1.04f, // ...a little bigger
};
talk.on_command("quake", [&] { stage.shake(12, 0.4f); });
talk.on_command("flash", [&] { stage.flash(WHITE, 0.3f); });Whoever speaks for the first time comes on stage: the first half of the cast slides in from
the left, the rest from the right, fading in. The speaker comes forward — full colour, raised,
bigger — and whoever stops speaking goes back to dimmed, over
focus_seconds. shake()
shakes the whole stage, dying away, and
flash() turns the screen a colour and
back: what a game's commands call. A slanted box, a torn edge, a frame like a comic's are art: a
Skin of nine-slices or Aseprite slices on style.
When none of the three is the layout a game wants, it writes its own around the two pieces they are made of:
const rmp::ui::DialogueFlow flow{ .letters_per_second = 40, .blip = "blip" };
rmp::ui::begin({ .placement = rmp::ui::Align::BOTTOM_CENTER, .grow = true });
rmp::ui::row({ .gap = 16, .grow_x = true }, [&] {
rmp::ui::image(face, { .width = 120, .height = 120 });
rmp::ui::column({ .grow_x = true }, [&] {
rmp::ui::dialogue_line(talk, memory, flow); // the line, typed out
rmp::ui::dialogue_choices(talk, memory, flow); // or the choices
});
});
rmp::ui::end();dialogue_line() draws the line where the
call is — its markup, the typewriter with its [speed] and [pause], the
blips and the recorded voice, auto-advance, skip-seen, and the > button that goes
on — and is true while there is a line;
dialogue_choices() draws the choices and
a timed choice's bar, true while there are choices. Both pass a command nobody handles and draw
nothing while a command waits. The DialogueMemory
is what they remember between frames: keep one, as a presenter does.
The markup of a line is drawn a letter at a time by
rmp::ui::rich_text(), which a game can use for
any text of its own:
rmp::ui::rich_text("A [wave]strange[/wave] [color=#ffcc00]light[/color], [b]now[/b]!");
rmp::ui::rich_text("[rainbow]You win![/rainbow]", { .width = 300, .visible = 4 });[b] is bold, [color=#rrggbb] or [color=red] a colour,
[size=30] a size in design units, and [wave], [shake] and
[rainbow] move or colour their letters by the interface's clock.
visible shows that many letters and holds the rest back: a typewriter counts it up
to rich_text_length().
rmp::behavior::Talker is the behavior of a
character who talks. When the player is within range and presses action
— or as soon as it arrives, with an empty action — it loads its dialogue, starts it
at node and hands it to on_talk, where the game shows it:
auto &mika = spawn({ .position = { 200, 120 }, .size = { 16, 16 } });
mika.add<rmp::behavior::Talker>({
.dialogue = "wizard.yarn",
.node = "Start",
.range = 32,
.player = player_handle,
.on_talk = [](rmp::Dialogue &talk) { rmp::Scene::push<Talking>(talk); },
});The scene it pushes keeps a reference to the conversation, shows it with a box or a stage, and
pops itself when show() returns false. The Dialogue belongs to the Talker, so its
variables and visits stay with the character between conversations, and once makes
it talk a single time. in_range() is for the prompt over its head — "Talk", with
rmp::ui::at() — and talking() says a conversation is running. A level
designer places one in LDtk with the fields dialogue, node,
range and once, read by Talker::from(), as every
behavior from the editor.
A Talker loads its file the first time it is asked to talk. on_load is called
then, before the first line, with the dialogue: where the game binds its variables and registers
its functions and commands, so that the first line already sees them.
npc.add<rmp::behavior::Talker>({
.dialogue = "school.yarn",
.player = hero,
.on_load = [&](rmp::Dialogue &talk) { talk.bind("$gold", gold); },
.on_talk = [](rmp::Dialogue &) { /* show it */ },
});examples/games/09_after_school is
a whole story told this way, playable in its page: a Talker per person of an LDtk town, a Stage
over the town, every $variable bound to the game's story, a <<walk>>
the dialogue waits on, a timed choice and three endings, in English and Spanish.
A line's #line: id is the key of its translation in the game's
tables, as line:welcome, and
the .yarn holds the text in [lang]
default. rmp text scan adds every line that has an id to
lang.tsv in resources/ with its text in the default language's column, so a translator
fills one table for the menus and the dialogue alike, and rmp text check holds both to
[lang] languages. The text is written the way Yarn Spinner's own string table writes
it: the speaker and the markup stay, the tags and an option's condition go, and each
{expression} becomes a number in order, {0}, {1}, which the
machine fills with its value. Mika: What will it be? You have {0} gold. in the English
column is Mika: ¿Qué será? Tienes {0} de oro. in the Spanish one, and
check fails on a translation that lost a {0}.
Give every line an id. A line without one gets an id made from its file, its node and its place
in the node, which changes when a line is added above it; it is shown, but it cannot be translated
reliably and rmp text scan leaves it out.
rmp yarn check # every resources/**/*.yarn
rmp yarn check resources/intro.yarn # onermp yarn check compiles every script with the framework's own compiler — the same
one the game runs, built for the machine as rmp_yarnc — and says each mistake as
file:line:column: what is wrong. It reads the game's src/ and
include/ for what they register: the typed functions are told to the compiler, so a
script that calls has_item(3) where a string goes fails here, and a function a script
calls that nothing registers is an error — the game would only find it at the line that calls it.
A command nothing handles is a warning, since a game may read it itself. It is a stage of
rmp test and a step of a game's CI, and exits 1 on an error. In the framework, each
example is checked against its own code.
The Yarn
Spinner extension for VS Code highlights the language, draws a script's nodes as a graph and
checks it as it is typed. What it cannot know is the game's own commands and functions, which are
C++. rmp yarn ysls tells it:
rmp yarn ysls # writes rmp.ysls.json next to resources/The file is the extension's own format (a .ysls.json, which it looks for anywhere
in the workspace): each command and function the C++ registers, with its parameters' names and
types, its result, the file it is in, and the // comment just above the registration
as its documentation. The extension then completes them, shows that comment on hover and checks
their arguments. Run it again when a registration changes.
// Whether the player carries `item`: "key", "map", "flyer".
talk.on_function("has_item", [](std::string item) -> bool { return carries(item); });Any editor that runs a linter gets the same checks from rmp yarn check, whose lines
are file:line:column: message. In Neovim (LazyVim included), with
nvim-lint:
require("lint").linters.rmp_yarn = {
cmd = "rmp", args = { "yarn", "check" }, stdin = false, append_fname = true,
stream = "stdout", ignore_exitcode = true,
parser = require("lint.parser").from_errorformat("%f:%l:%c: %m,%f:%l: %m"),
}
require("lint").linters_by_ft.yarn = { "rmp_yarn" }[dialogue] build says
where a script is compiled:
build = | The scripts are compiled |
|---|---|
"runtime" | when the game loads them, from resources/: edit a
line and load it again. |
"embedded" | when the game is built: the host tool rmp_yarnc
compiles every .yarn of resources/ into the executable, so the game reads
no script and compiles nothing when it starts, and a script with a mistake fails the build with
its file, line and column. On the desktop; a cross build — Android, iOS, the web — compiles at
runtime. |
"auto" (the default) | at runtime in a debug build, embedded in a release. |
The machine is the same in both, so a script behaves the same, and
load_dialogue() is the same call: it looks in the embedded scripts first.
python3 tools/ink_to_yarn.py story.ink resources/story.yarnA story written in Ink is converted into a
.yarn file, from its source: knots and stitches become nodes, VAR
declarations, ~ assignments, choices with their conditions and their once-only
*, diverts, -> END and simple conditional text. What Ink has and Yarn
has not — nested choices, tunnels, threads, lists, functions, sequences, glue — is reported with
its line number and kept in the output as a comment, so nothing is lost without a word. The
conversion is done once, by the developer; the game only ever reads Yarn.
The whole of Yarn Spinner 3: nodes and their headers; lines with ids, tags and shadow lines;
speakers; {expressions} with Yarn's operators; markup, with select,
plural and ordinal by the current language; options and their
conditions; line groups (=>) and node groups (when:), chosen by
saliency (set_saliency());
<<if>>, <<once>>, <<set>> and
<<declare>> with types, enums and smart variables;
<<jump>>, <<detour>> and
<<return>>; visit tracking; and the game's commands and functions. It is
held to Yarn Spinner's own test cases, which the framework runs as they are: every test plan plays
step for step, and every script that must not compile does not. What a later Yarn adds and the
framework does not run yet is listed, with its test, in
tests/dialogue/yarn_unsupported.txt, which is empty today.
Maintaining the dialogue is how that is
kept so.
https://omardev29.github.io/rmp-docs/manual/modules/random.html
rmp::random is one generator of random
numbers for the whole game, and the sequence it gives depends on one number, its seed. Every launch
gets a different seed, so the game varies; the same seed gives the same numbers in the same order,
so a run can be repeated — for a roguelike's shareable seed, a bug report, a replay, or a test that
gives the same answer every time.
const float angle = rmp::random::range(0.0f, 360.0f);
const int damage = rmp::random::range(3, 6); // 3, 4, 5 or 6
const bool critical = rmp::random::chance(0.25f); // one time in four
const Vector2 spark = rmp::random::in_circle(80); // a point within 80 units of the centre
const Vector2 heading = rmp::random::direction(); // a unit vector, any angle| Call | Gives |
|---|---|
value() | A float from 0 up to, never reaching, 1. |
range(min, max) with floats | A float from min up to, never reaching, max. |
range(min, max) with ints | An int from min to max, both included, as raylib's GetRandomValue() counts. When max is not above min, min — where GetRandomValue() swaps the two, so range(6, 3) is always 6 and GetRandomValue(6, 3) is 3 to 6. |
chance(p) | true with probability p: 0 is never, 1 is always. |
in_circle(radius) | A point spread evenly over the whole disc, not bunched at the middle and not only on the rim. |
direction() | A vector of length 1, pointing anywhere. |
index(count) | An index from 0 to count - 1; 0 for a count of 0 or less, so it needs no check before it is used. |
The two range()s are told apart by their arguments, so both have to be the same
type. A float and an int together is a question with two answers, and the compiler says so
rather than picking one:
const float x = rmp::random::range(0, 1.5f);The compiler refuses it, saying among other things: is ambiguous
Write range(0.0f, 1.5f).
index() picks one of a list:
const std::vector<std::string> greetings = { "Hello!", "Nice day.", "Watch out." };
const std::string &line = greetings[rmp::random::index(static_cast<int>(greetings.size()))];and shuffles one, from the last element down, each swapped with one at or before it:
std::vector<int> bag = { 0, 1, 2, 3, 4, 5, 6 };
for (int i = static_cast<int>(bag.size()) - 1; i > 0; --i) {
std::swap(bag[i], bag[rmp::random::index(i + 1)]);
}That is the falling-block game's bag in
examples/games/06_tetris: every seven pieces are the
seven pieces in a shuffled order, which is fairer than one at random each time, and with the same
seed it is the same game (main.cpp).
examples/games/03_space_invaders gives every
alien a shooting period of its own with range(4.0f, 9.0f), so that a whole formation
started on the same frame does not fire as one gun.
The framework seeds the generator once, when the game starts, from the clock, so a game that
never mentions seeds plays differently each time it is launched.
current_seed() is the seed the sequence
running now started from — the number to print in a bug report or show on a roguelike's pause
screen:
TraceLog(LOG_INFO, "seed %llu",
static_cast<unsigned long long>(rmp::random::current_seed()));seed(n) starts the sequence again from
n. Called with the number a player typed, or the one from the bug report, it gives
the same numbers in the same order:
class RunScene : public rmp::Scene {
public:
explicit RunScene(uint64_t seed) : _seed(seed) {}
private:
void _ready() override {
rmp::random::seed(_seed); // the same seed, the same dungeon
}
uint64_t _seed;
};current_seed() is always the truth, even before anything has called
seed(): a run nobody seeded starts from a fixed default seed, and reports that one.
The seed fixes the sequence of numbers; it does not fix who asks for them. There is one
generator for the whole game — the behaviors use it too: a
Spawner with jitter draws each interval's
jitter from it — so a run repeats when the same things ask for numbers in the same order. Anything that
differs from one run to the next — what the player pressed, and when — changes which number goes
where. Seeding at the start of a level and generating the level at once, before any of that
happens, is what makes a seeded level the same level every time.
The seed from the clock is set by the entry point, and a unit test does not go through the entry point. So a test of anything that varies — a spawner's jitter, a wander, a shake — starts from the same default seed every time it runs and gives the same answer, without seeding anything. A test that fails one time in twenty teaches everyone to ignore a red test.
A
test that plays a whole game does go through the entry point, and names the seed it starts from
instead of the clock: that is how the framework's own tests
play an example from a script, and why the falling-block
game deals the same pieces every time they do. The seed is named through a seam inside the
framework, not through rmp::random.
The C library's rand() keeps its state in one global that every library in the
process shares, so any of them calling srand() changes your sequence, and the low bits
of what it returns are poor. raylib's GetRandomValue() keeps its state inside raylib
and seeds it from the clock. rmp::random is a generator of the framework's own, so the
game and its tests decide where a sequence starts. It is xoshiro128++: sixteen bytes of state, no
allocation, and good enough for a game by a wide margin.
https://omardev29.github.io/rmp-docs/manual/modules/ads.html
rmp::ads shows Google AdMob ads of two
kinds: interstitials, the full-screen ads between levels, and rewarded ads, which
the player chooses to watch in exchange for something. They are real on Android once the game
turns them on, and do nothing on every other platform, so the same
game code builds on all 17 targets without a single #ifdef.
An ad has to be downloaded before it can be shown, and that takes seconds. So each kind is three calls — ask for one early, check whether it has arrived, show it — and a shown ad is used up:
| Interstitial | Rewarded | |
|---|---|---|
| Start loading one | request_interstitial() | request_rewarded() |
| Has it loaded? | is_interstitial_loaded() | is_rewarded_loaded() |
| Show it | show_interstitial() | show_rewarded() |
| The reward | take_reward_earned() and reward_amount() |
Request as soon as you know you might want one — when the game starts, when a level starts —
and again after each one is shown, because showing it consumes it. Showing when nothing has
loaded does nothing. A request that fails — no connection, no ad to fill it — leaves
is_*_loaded() false and is not retried for you; asking again is the game's
decision.
An interstitial belongs at a natural break, where the player has stopped anyway: between two levels, after a game over. Request it while the level is being played, and show it on the way out if it made it in time:
class GameScene : public rmp::Scene {
void _ready() override { rmp::ads::request_interstitial(); } // loads while the level is played
};
class GameOverScene : public rmp::Scene {
void _draw() override {
rmp::ui::begin();
if (rmp::ui::button("Play again")) {
if (rmp::ads::is_interstitial_loaded()) rmp::ads::show_interstitial();
rmp::Scene::change<GameScene>();
}
rmp::ui::end();
}
};An ad that has not arrived is simply skipped: the player is never kept waiting for one.
A rewarded ad is a deal with the player — watch this, get that — and the deal is only kept when
the player watched enough of it. So the reward does not come from show_rewarded(). It
arrives later, through take_reward_earned(), which is true once for each reward
earned and clears itself; reward_amount() is then the amount set on the ad unit in
AdMob. A player who closes the ad early gets nothing, and no code has to say so.
class ShopScene : public rmp::Scene {
void _ready() override { rmp::ads::request_rewarded(); }
void _update(float delta) override {
if (rmp::ads::take_reward_earned()) {
_coins += rmp::ads::reward_amount();
rmp::ads::request_rewarded(); // the next one, for next time
}
}
void _draw() override {
rmp::ui::begin();
rmp::ui::text("Coins: " + std::to_string(_coins));
if (rmp::ads::is_rewarded_loaded()) {
if (rmp::ui::button("Watch an ad for coins")) rmp::ads::show_rewarded();
} else {
rmp::ui::button("Ad not ready", { .enabled = false });
}
rmp::ui::end();
}
int _coins = 0;
};Two things in it are worth copying:
Do not put progress behind an ad that may never load. On a bad connection
is_rewarded_loaded() can stay false for a long time, and a player who cannot continue
without an ad is a player who uninstalls.
examples/ads/02_rewarded is this flow, end to end; examples/ads/01_interstitial shows both kinds side by side.
Off Android — the desktops, the web, iOS — every call compiles and does nothing:
is_*_loaded() is always false, take_reward_earned() never fires and
reward_amount() is 0. The code above runs unchanged on a laptop: the buttons say "not
ready" and the rest of the game is there to work on. Ads on iOS are not implemented.
rmp::ads forwards each call to a C function in <admob.h>, one for
each of the calls above, with the same meaning and the same no-op off Android. A C source file in
the game, which has no namespace to call into, calls them directly — and so does a game written
entirely in plain C, which has
<admob.h> on its include path on every target:
#include <admob.h>
void level_finished(void) {
if (IsInterstitialAdLoaded()) ShowInterstitialAd();
RequestInterstitialAd();
}
void every_frame(int *coins) {
if (TakeRewardEarned()) *coins += GetRewardAmount();
}Ads are off until the game turns
them on: [android.admob] enabled is false by default, and rmp new
writes false into a new game's .toml. (The framework's own
.toml has it on, so that its CI builds the ads path.) Turning them on is the switch and
three ids, in [android.admob]:
[android.admob]
enabled = true
app_id = "ca-app-pub-3940256099942544~3347511713"
interstitial_id = "ca-app-pub-3940256099942544/1033173712"
rewarded_id = "ca-app-pub-3940256099942544/5224354917"app_idinterstitial_id, rewarded_idYour
ids reach the release build only. The Android debug build — the one rmp android makes,
the one you tap through yourself, and the one Firebase Test Lab's Robo crawler taps at random —
carries Google's test ids whatever the .toml says, the app id in its manifest
included, so it shows test ads even after your own ids are in. A release build carries your ids
and serves real ads wherever it is installed, your own phone included, so do not tap the ads in
it.
Each id is a string, in
quotes, whether ads are on or not. While they are on, each one is also checked when the
configuration is read: it cannot be empty, and it has to have AdMob's shape — ca-app-pub-
and sixteen digits, then ~ and ten digits for the app id, or / and ten
digits for an ad unit. The Google Mobile Ads library stops the app at startup over an app id it
cannot read, so a wrong one is refused before a build starts, at its line, with the reason. An app
id pasted where an ad unit goes is named for what it is:
[android.admob]
enabled = true
interstitial_id = "ca-app-pub-3940256099942544~3347511713" raylib_multiplatform.toml:3: interstitial_id = "ca-app-pub-3940256099942544~3347511713"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android.admob] interstitial_id = 'ca-app-pub-3940256099942544~3347511713' is not an AdMob ad unit id.
An AdMob ad unit id looks like ca-app-pub-<16 digits>/<10 digits> -- this one has a '~', which makes it the app id.
Copy it from the AdMob console, or set [android.admob] enabled = false.[android.admob]
enabled = falseWith enabled = false, the default, AdMob is not in the Android build at all: no Google Mobile
Ads library, no advertising-id permission, nothing started when the app opens, and nothing to
declare about advertising ids in Google Play's Data safety form. The game's code does not change:
the calls keep compiling and do nothing, exactly as they do on desktop. The same happens on its
own when android is not among the targets the game builds, however it was left out —
there is no Android build to put ads in.
With ads on, the app asks for the internet permission whatever
[android.permissions] internet says, because an ad has to be downloaded.
enabled is a switch, and only true or false is
accepted:
[android.admob]
enabled = "no" raylib_multiplatform.toml:2: enabled = "no"
^^^^^^^^^^^^^^
configure: error: [android.admob] enabled = 'no' must be true or false.https://omardev29.github.io/rmp-docs/manual/raylib/index.html
Everything the framework adds lives under rmp::, and everything else in
a game is raylib's, unchanged in its API and fully available. These pages are about that border:
what the framework does in your place, what stays yours, and how to go below it — to raylib
directly, to the layout engine underneath rmp::ui, to rlgl and OpenGL, or out of the
framework altogether.
_update() and
_draw(), and the handful of raylib calls that would fight it.rmp::ui, and the rules that make it work: ids, strings, images.main() in C, the build and the pipeline kept, the runtime layer given up.The rule underneath all four is the same one: the framework never stops you from calling
raylib, and it never asks you to. rmp::assets does not stop you calling
LoadTexture(), and rmp::ui does not stop you calling Clay.
https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html
A game made with the framework is a raylib game. The framework makes a small number of raylib calls for you — the ones every raylib program writes the same way: opening the window, beginning and ending the frame, closing it all at the end. Everything else in raylib is yours, from any scene, with nothing to unlock and nothing to convert.
The split is easy to remember: the framework owns when things happen, and you own what happens. The frame loop, the window and the shutdown order are the framework's; drawing, input, loading, sound and the rest of raylib are yours, inside the hooks it calls.
RMP_GAME in src/main.cpp writes the entry
point for the platform you are building, and these are the raylib calls it makes so that you do
not:
| raylib call | When the framework makes it |
|---|---|
SetConfigFlags() | Once, before the window opens: FLAG_WINDOW_RESIZABLE, plus FLAG_VSYNC_HINT when [window] vsync = true. |
SetTargetFPS() | Once, before the window opens, when [window] fps is above 0 — and never on the web or iOS, where the browser and the display link pace the frame. |
InitWindow() | Once, at [window] width × height, titled [window] title. Your first scene's _ready() runs after it, so a texture loads there. |
SetExitKey() | Once, with KEY_NULL, right after your first scene's _ready() returns. raylib's InitWindow() makes Escape the key that closes the window, and in a game Escape means "back" or "pause". See below. |
WindowShouldClose() | Every frame, to see whether the player closed the window — except on the web and iOS, which have no such window and where it is never called. |
GetFrameTime() | Every frame, clamped to [app] max_delta, and handed to _update(float delta) as delta. |
BeginDrawing() and ClearBackground() | Every frame, cleared with the background of the lowest scene being drawn, or the theme's when that is BLANK. |
BeginMode2D() and EndMode2D() | Every frame, around each scene's map and objects, with that scene's camera. |
EndDrawing() | Every frame, after the last scene's _draw(). |
CloseWindow() | Once, at the very end, after every scene, every rmp::global and every resource that lives on the GPU has been released. |
The sound device is not on that list on purpose: rmp::audio
calls InitAudioDevice() the first time a sound is loaded or played, so a game that
never makes a sound never opens one.
Before
your first scene's _ready() the framework has also opened the asset pack, if there is
one, and routed raylib's own file loading through it; seeded
rmp::random; on iOS moved into the app bundle, where the
resources are; and in a desktop release moved into the executable's folder, when there is a
resources/ in it, so that ./resources/ means the one shipped next to the
game wherever it was started from — see Desktop.
Every frame of a game made with RMP_GAME is the same sequence, and every hook you
write has a fixed place in it:
RMP_ENTRY_POINT.on_click or on_drag handler, so a handler can spawn or destroy before
anything else looks — then its _update(delta), then its objects, then the collision
pass, then its camera, which follows where everything ended up.BeginDrawing(), and the clear — into a texture instead of the screen while an
overlay() blurs what is under it.BeginMode2D() with its camera,
its map, its objects, EndMode2D(), and then its own _draw() — outside the
camera, in screen space.rmp::ui::notify(), over
everything.EndDrawing().change, push,
replace, pop — are applied.That
fourth step is why a HUD drawn in a scene's _draw() stays put while the camera moves:
the camera is closed before _draw() is called, and it is the reason the
scene hooks say which space they draw in.
The shutdown runs in an order that was chosen so nothing touches a dead GL context. First,
everything that owns something on the GPU, while the window still exists: the scenes are ended from
the top of the stack down — each gets its _end() —
then the globals are destroyed, then the UI's font, then every texture, font and sound still
loaded through rmp::assets. Then CloseWindow(). Then what owns nothing on
the GPU: the asset pack, raylib's loader hook, and the sound device.
It is the same sequence whether the player closed the window, the game called
rmp::app::quit(), or a CI run reached its frame
budget.
All of raylib: shapes, textures, text, models, shaders, sound, input, files, the window's state.
Most headers under include/rmp/ already include <raylib.h>, so a
scene can call raylib with nothing more than the header it already has.
_update(), use the delta you are given#delta is the seconds since the last frame, the same number
GetFrameTime() returns — with one difference that matters. A frame that really took
longer than [app] max_delta arrives clamped, so dragging the window or stopping at a
breakpoint gives the game a moment of slow motion instead of moving a bullet through a wall. Call
GetFrameTime() yourself and you get the real number, unclamped.
Vector2 ship{ 400, 225 };
void _update(float delta) override {
if (IsKeyDown(KEY_RIGHT)) ship.x += 300 * delta;
if (IsKeyDown(KEY_LEFT)) ship.x -= 300 * delta;
}
void _draw() override {
DrawTriangle({ ship.x, ship.y - 20 }, { ship.x - 15, ship.y + 15 },
{ ship.x + 15, ship.y + 15 }, SKYBLUE);
}raylib's input functions work everywhere, and read the same frame of input the framework does.
What they do not know about is who should hear it. A query by name through
rmp::input is routed: an action bound to the mouse goes
quiet while the interface wants the pointer, and every action goes quiet in a scene whose input is
taken by a scene above it. IsMouseButtonPressed() called directly fires on the click
that pressed a button in your menu as well.
// raw: also fires when the click lands on a UI button
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) shoot();
// routed: silent while rmp::ui wants the pointer
rmp::input::action("fire", MOUSE_BUTTON_LEFT, KEY_SPACE);
if (rmp::input::just_pressed("fire")) shoot();The raw form has a spelling of its own in rmp::input too:
rmp::input::pressed(KEY_W) is exactly
IsKeyDown(KEY_W), never routed. The type of the argument says which of the two you
asked for. The rmp::ui controls read the keyboard and the
gamepad through a seam of their own, so a menu navigates with the arrow keys whether or not the
game defines a single action.
raylib's
InitWindow() makes Escape its exit key: pressed, it closes the window. In a game it
is the key for "back" and "pause" — rmp::ui goes back on it, and the
ui_cancel action is bound to it — so the framework calls
SetExitKey(KEY_NULL) once the window is open, right after the ready hook returns, on
every target: after your first scene's _ready() with RMP_GAME, after your
own on_ready() with RMP_ENTRY_POINT.
Upstream raylib's Win32 and DRM backends close on Escape whatever the exit key is; the copy the
framework ships is patched so that they obey it (thirdparty/raylib/PATCHES.md). The
window's close button still closes the game: that is a request from the window, not a key.
A SetExitKey() of your own in that first ready hook is overwritten. To quit on a
key, say so where the game reads its keys, with
rmp::app::quit(), which ends the game the way the close
button does:
if (IsKeyPressed(KEY_ESCAPE)) rmp::app::quit();_draw(), screen space — and the world when you open the camera#A scene's _draw() runs after its map and its
objects have been drawn, with the camera already closed. A coordinate there is a pixel of the
window. To draw in the same world units as the objects, open the camera yourself, for exactly the
lines that need it, with camera.raylib():
Vector2 target{ 640, 300 };
void _draw() override {
// the world, through the same camera the objects were drawn with
BeginMode2D(camera.raylib());
DrawCircleLinesV(target, 24, RED);
EndMode2D();
// the screen: stays put while the camera moves
DrawText("Find the target", 10, 10, 20, RAYWHITE);
}On a window of exactly the design size, with a camera nobody touched, the two spaces are the
same and the difference is invisible. On any other window they are not, which is why Pong in
examples/games/01_pong opens the camera to draw its net: drawn in screen pixels, the
net and the court would come apart as soon as the window is resized.
An object's own _draw() is different: it
runs inside the camera already, because objects live in the world. Override it to draw an object
with raylib calls of your own, in world units, without opening anything.
rmp::ui draws when rmp::ui::end() is called, so the order inside
_draw() is the order on screen: what you draw before rmp::ui::begin() is
under the interface, and what you draw after rmp::ui::end() is over it.
Nothing in the framework is 2D-only on raylib's side. A scene that wants a 3D view keeps a
Camera3D of its own and opens it in _draw():
Camera3D view{ .position = { 6, 6, 6 },
.target = { 0, 0, 0 },
.up = { 0, 1, 0 },
.fovy = 45,
.projection = CAMERA_PERSPECTIVE };
void _draw() override {
BeginMode3D(view);
DrawCube({ 0, 0, 0 }, 2, 2, 2, MAROON);
DrawGrid(10, 1);
EndMode3D();
DrawText("3D, from a scene", 10, 10, 20, RAYWHITE);
}The scene's own map and objects are 2D and are
drawn before _draw(), so a 3D scene simply has neither. DrawCube() and
DrawGrid() live in raylib's rmodels module; a game that lists
"rmodels" in [raylib] disabled_modules does not have them — except on iOS,
where that setting has no effect, because iOS links a prebuilt raylib (see
iOS).
raylib's loaders work, and they read through the asset pack when there is one: opening the pack
also routes raylib's own file loading through it, so LoadTexture(),
LoadModel() and LoadShader() find a packed file by the same path they
would find a loose one. Build every path from RMP_RESOURCES_PATH, the macro every build system
defines with the folder its resources/ are read from:
Texture2D picture{};
void _ready() override { picture = LoadTexture(RMP_RESOURCES_PATH "rabbit.png"); }
void _end() override { UnloadTexture(picture); }
void _draw() override { DrawTexture(picture, 0, 0, WHITE); }What you load yourself you unload yourself, and _end() is a safe place for it: at
shutdown every scene is ended while the window — and the GL context with it — still exists. The
same goes for a RenderTexture2D from LoadRenderTexture(). The
alternative is rmp::assets::load_texture(),
whose rmp::Texture releases itself and converts to a
Texture2D wherever raylib wants one.
One of raylib's loaders stays outside the pack, by raylib's design: LoadMusicStream()
opens its file itself, so music loaded with it has to ship as a loose file — and a desktop archive
that CI packs ships the pack alone (tools/ship_resources.sh).
rmp::audio::music() streams from the pack instead.
The pack holds every file below resources/, folders too, under its path there.
If your code calls InitAudioDevice() itself, the framework notices and leaves
closing it to you; when rmp::audio opened it, the framework closes it after the
window.
A short list, and each one is on it because the framework already does the same job at a moment it has chosen for a reason.
InitWindow() and CloseWindow()_ready() to after your last
_end(). A CloseWindow() of your own takes the GL context away while the
framework still has textures, a font and your scenes' resources to release through it. To end the
game, call rmp::app::quit(): the frame you are in finishes, and the shutdown above
runs.BeginDrawing() and EndDrawing() inside a hook_draw() runs. EndDrawing() is what ends
it — it submits the batch, swaps the buffers and polls the input — so a pair of your own inside a
hook puts a half-drawn frame on the screen and then ends the frame a second time.SetTargetFPS() on the web and on iOS[window] fps, which the framework applies before the window opens on every
target where it means something. If you change it at run time — a battery-saving option — keep the
call off those two:
#if !defined(__EMSCRIPTEN__) && !defined(PLATFORM_IOS)
SetTargetFPS(30);
#endif__EMSCRIPTEN__ rather than PLATFORM_WEB, because the second is only
defined by one of the two [web] backend choices.WindowShouldClose()false and calls emscripten_sleep(), which a build without
ASYNCIFY — and this one has none — cannot do. To know whether the game is on its way out, ask
rmp::app::quit_requested().exit(), std::exit(), abort()_end(), the window is
never closed, and on Android the Activity is left behind with its process gone. On iOS an app that
ends itself "will appear to the user to have crashed", in Apple's own words (QA1561), and App
Review rejects it. rmp::app::quit() is the way out everywhere it exists — and on iOS it
deliberately does nothing but say, once,
APP: quit() does nothing on iOS — Apple rejects apps that terminate themselves (QA1561). Ignoring.while loop that drawsBeginDrawing() until the work is done works on a
desktop and freezes the tab on the web, where the browser owns the loop. Do the work a slice per
frame in _update() instead, or in a scene of its own.There is no umbrella header. Each header under include/rmp/ is one part of the
framework you can name — rmp/app.h, rmp/scene.h, rmp/ui.h,
rmp/assets.h and the rest — and a file includes the ones whose names it uses. A file
that draws the HUD with rmp::ui includes rmp/ui.h and recompiles when the
interface changes, not when the asset pipeline does;
examples/platform/03_minimal_includes is one translation unit that includes
rmp/ui.h and nothing else of ours, compiled on every run to prove that it is
enough.
For raylib the same rule reads naturally: include <raylib.h> in a file that
calls raylib, rather than relying on which rmp/ header happens to bring it. The other
headers you may want are on the include path of every target and are never included for
you:
| Header | For |
|---|---|
<raymath.h>, or rmp/math.h | Vector and matrix maths, with C++ operators on raylib's own Vector2. rmp/math.h adds raylib-cpp's maths classes on top. |
<rlgl.h> | raylib's GL layer. See rlgl and OpenGL. |
<clay.h> | The layout engine under rmp::ui. See Dropping to Clay. |
<raymob.h> | Android's extras — vibration, the soft keyboard, the sensors — declared on Android only. See Android. |
The values from raylib_multiplatform.toml — RMP_WINDOW_WIDTH,
RMP_WINDOW_TITLE and the rest, listed on the
macros page — come with every
rmp/ header, so you never include rmp/config.h yourself unless the file
includes none of them.
Most games need no platform branch at all. When one does, the build defines a
PLATFORM_* macro that names which of raylib's backends it was compiled for:
| Macro | Defined when |
|---|---|
PLATFORM_DESKTOP | Windows, Linux, macOS and the BSDs on the default GLFW backend. |
PLATFORM_DESKTOP_WIN32 | [windows] backend = "win32". |
PLATFORM_DESKTOP_RGFW | [windows] backend or [linux] backend set to "rgfw". |
PLATFORM_DRM | The Linux DRM/KMS targets, which draw with no X11 and no Wayland. |
PLATFORM_WEB | The web, with [web] backend = "glfw". |
PLATFORM_WEB_EMSCRIPTEN | The web, with [web] backend = "emscripten". |
PLATFORM_ANDROID | Android. |
PLATFORM_IOS | iOS. |
PLATFORM_MEMORY | raylib's software renderer, with no window and no GPU: what rmp test render and CI's render checks build. |
For the operating system itself, use what the compiler defines: _WIN32,
__APPLE__ (macOS and iOS both), __linux__ (Android too — test
__ANDROID__ first), __ANDROID__, __EMSCRIPTEN__ (both web
backends), and __FreeBSD__, __OpenBSD__ and __NetBSD__, since
the BSDs share PLATFORM_DESKTOP with the other desktops. And RMP_PRODUCTION_BUILD,
which every build system defines, is 0 or 1 on every target, for code that
belongs in a debug build only:
#if !RMP_PRODUCTION_BUILD
DrawFPS(10, 10);
#endifhttps://omardev29.github.io/rmp-docs/manual/raylib/clay.html
rmp::ui is a small surface over Clay,
the layout engine underneath it. When a screen needs something that surface does not have — an
element floating at an exact spot, an aspect ratio, a clip container shaped your way — you do not
have to give up rmp::ui to get it. Include <clay.h> and write Clay
between rmp::ui::begin() and rmp::ui::end(): your elements join the same
tree, are laid out in the same pass and are drawn by the same renderer.
It is the same bargain as the rest of the framework. rmp::assets does not stop you
calling LoadTexture(), and rmp::ui does not stop you calling Clay.
Clay is on the include path of every target and is never included for you: no Clay type, macro
or enum appears in rmp/ui.h, so a game that does not ask for it never sees it. A file
that wants it says so:
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <clay.h> // the layout engine itself: not included for you
class InventoryScene : public rmp::Scene {
void _draw() override {
rmp::ui::begin();
rmp::ui::text("Inventory");
// a row of four slots, which rmp::ui has no primitive for
CLAY(CLAY_ID("hotbar"), { .layout = { .padding = CLAY_PADDING_ALL(8),
.childGap = 8,
.layoutDirection = CLAY_LEFT_TO_RIGHT },
.backgroundColor = { 30, 30, 38, 255 } }) {
for (int i = 0; i < 4; ++i) {
CLAY(CLAY_IDI("hotbar-slot", i),
{ .layout = { .sizing = { .width = CLAY_SIZING_FIXED(48),
.height = CLAY_SIZING_FIXED(48) } },
.backgroundColor = { 44, 44, 56, 255 } }) {}
}
}
if (rmp::ui::button("Close")) rmp::Scene::pop();
rmp::ui::end();
}
};The text, the row and the button are one layout, in the order they were declared.
rmp::ui::begin() and
rmp::ui::end() are Clay's own begin and end, with the
framework's input, scale and drawing around them, so never call Clay_BeginLayout() or
Clay_EndLayout() yourself. Clay itself is started by the first
rmp::ui::begin() of the game, sized by [ui] max_elements, and your elements
count towards that ceiling with the framework's.
examples/ui/03_clay_direct is the whole technique in one file: Clay's macros in the
same frame as rmp::ui, a strip shaped like a tab — its top corners rounded, its bottom
ones square, a border along one side — an image, ids in a loop and a hover query. It is written with
RMP_ENTRY_POINT rather than scenes, so it opens its
own window and its own frame; in a game with scenes, the part between begin() and
end() goes in a scene's _draw() exactly as it is. The framework's CI
builds and boots it on every run, and compiles it with MSVC as well, because Clay's macros are
designated initialisers inside a for block — the shape MSVC is fussiest about.
// ---------------------------------------------------------------------------
// examples/ui/03_clay_direct/src/main.cpp
//
// THE ESCAPE HATCH: using Clay's own API directly, alongside rmp::ui.
//
// rmp::ui is a small, opinionated surface over Clay — enough for menus, HUDs
// and dialogs without ever mentioning a coordinate. When you want something it
// does not expose yet (floating elements placed where you choose, aspect
// ratios, per-corner radii, a border on one side, an explicit z-index), you do
// not have to wait for us and you do not have to give up rmp::ui to get it.
// (Clipping and scrolling it does expose: rmp::ui::scroll().)
//
// It is the same bargain as the rest of the framework: rmp::assets does not stop
// you calling LoadTexture, and rmp::ui does not stop you calling Clay. Or
// rlgl. Or raw OpenGL, for that matter.
//
// #include <clay.h>
//
// and write Clay between rmp::ui::begin() and rmp::ui::end(). Your elements go
// into the same tree, get laid out in the same pass and drawn by the same
// renderer.
//
// Two things to know and then you are on your own:
//
// * begin() has already opened two elements — a root that fills the screen
// and a column that centres its contents. Yours become children of that
// column. If you want to escape it, use Clay's floating elements.
// * Clay does NOT copy strings. CLAY_STRING() on a literal is fine forever;
// anything built at runtime must stay alive until end() has returned. This
// is the one footgun rmp::ui::text() removes for you by copying.
//
// Run it: `rmp example 03_clay_direct`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <clay.h> // the escape hatch: not included for you on purpose
class ClayScene : public rmp::Scene {
public:
void _ready() override { _logo = rmp::assets::load_texture("rabbit.png"); }
void _draw() override {
// A copy of the raylib struct, alive for this frame. The handle below
// is the owner; this is what Clay is allowed to point at.
Texture2D logo_tex = _logo;
rmp::ui::begin();
// --- the normal API ---------------------------------------------------
rmp::ui::text("Inventory");
// --- and Clay, in the same frame --------------------------------------
//
// A horizontal strip of slots, which rmp::ui has no primitive for yet.
// CLAY_AUTO_ID is the version without an explicit id; CLAY(CLAY_ID("x"),
// ...) is the one to use when you want to ask Clay about the element later
// with Clay_PointerOver or Clay_GetElementData.
//
// It is shaped like a tab, which rmp::ui cannot do either: each corner has
// its own radius, and the border is on one side only.
CLAY_AUTO_ID(
{ .layout = { .sizing = { .width = CLAY_SIZING_FIT(0),
.height = CLAY_SIZING_FIT(0) },
.padding = CLAY_PADDING_ALL(10),
.childGap = 10,
.layoutDirection = CLAY_LEFT_TO_RIGHT },
.backgroundColor = { 30, 30, 38, 255 },
.cornerRadius = { .topLeft = 18,
.topRight = 18,
.bottomLeft = 0,
.bottomRight = 0 },
.border = { .color = { 88, 120, 245, 255 }, .width = { .bottom = 3 } } }) {
for (int i = 0; i < 4; ++i) {
// CLAY_IDI gives each slot in a loop its own identity without
// building a string per element.
CLAY(CLAY_IDI("slot", i),
{ .layout = { .sizing = { .width = CLAY_SIZING_FIXED(64),
.height = CLAY_SIZING_FIXED(64) } },
.backgroundColor = { 44, 44, 56, 255 },
.cornerRadius = CLAY_CORNER_RADIUS(6) }) {
// Images: point imageData at a Texture2D you own and keep
// alive for the frame. Our renderer draws it stretched to the
// element's box, untinted. A tint is a Color* in userData; a
// backgroundColor is NOT a tint -- Clay draws it as a rectangle
// after the image, which paints a flat square over it.
if (i == 0) {
CLAY_AUTO_ID(
{ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0),
.height = CLAY_SIZING_GROW(0) } },
.image = { .imageData = &logo_tex } }) {}
}
}
}
}
// Hover, straight from Clay. Note it reads the PREVIOUS frame's geometry,
// exactly like rmp::ui::button() does — the layout for this frame does not
// exist until end().
if (Clay_PointerOver(CLAY_IDI("slot", 0))) {
rmp::ui::text("slot 1", { .color = rmp::ui::ColorRole::PRIMARY });
}
// Back to the normal API, still the same frame.
if (rmp::ui::button("Close")) rmp::app::quit();
rmp::ui::end();
}
private:
// The owning handle. Clay wants a Texture2D* that stays valid for the
// frame, so _draw() copies the raylib struct out for exactly that long.
rmp::Texture _logo;
};
RMP_GAME(ClayScene);
// ---------------------------------------------------------------------------
// What our renderer understands
// ---------------------------------------------------------------------------
//
// RECTANGLE background colour + each corner's own radius
// BORDER colour + each side's own width + each corner's own radius
// TEXT drawn with the UI font; fontId is ignored, there is one font
// IMAGE imageData as a Texture2D*; userData as a Color* tint, or
// null for none (a backgroundColor covers the image: see above)
// SCISSOR_START clipping, so Clay's clip/scroll containers work
// SCISSOR_END
//
// CUSTOM commands are not handled. If you need them, src/rmp/ui/render.cpp is
// one short file, and adding a case is the intended way to extend it.
//
// AND THE LIMITS. Doing this ties your code to a specific version of Clay
// (0.14, pinned in thirdparty/FROZEN_VERSIONS.md). rmp::ui exists partly so
// that most code does not carry that dependency — Clay is pre-1.0 and its API
// has moved between minor versions. That is a fair trade for a feature you need
// today; it is a bad trade for a button.
rmp::ui::begin() has already opened two elements by the time your first
CLAY() runs: a root that fills the window, and inside it a column that fits its
contents and centres them. Your elements are children of that column, beside the framework's
widgets. The placement you give begin() — rmp::ui::begin({ .placement =
rmp::ui::Align::TOP_LEFT }) — moves that column, and your elements with it. With
rmp::ui::begin({ .grow = true }) the column fills the window instead, less the padding,
so an element of yours sized with CLAY_SIZING_GROW reaches its edges; see
filling the window.
To get out of the column, float. An element with .floating.attachTo =
CLAY_ATTACH_TO_ROOT is placed by its .offset from the corner of the window,
whatever the column is doing:
rmp::ui::begin();
rmp::ui::text("Paused");
CLAY(CLAY_ID("build-badge"), { .layout = { .padding = CLAY_PADDING_ALL(6) },
.backgroundColor = { 200, 60, 60, 255 },
.floating = { .offset = { 16, 16 },
.attachTo = CLAY_ATTACH_TO_ROOT } }) {
CLAY_TEXT(CLAY_STRING("BETA"),
CLAY_TEXT_CONFIG({ .textColor = { 255, 255, 255, 255 }, .fontSize = 16 }));
}
rmp::ui::end();Clay's own designated initialisers follow the rule every C++20 one does: the fields in the order
the struct declares them. .layout before .backgroundColor before
.floating, and inside .layout, .sizing, .padding,
.childGap, .childAlignment, .layoutDirection. Out of order is
a compile error, not a warning.
Every element gets the id you give it, and the id is how you ask Clay about it later:
| Spelling | For |
|---|---|
CLAY(CLAY_ID("wallet"), ...) | One element with a name of its own. |
CLAY(CLAY_IDI("slot", i), ...) | One of many, in a loop, without building a string per element. |
CLAY_AUTO_ID(...) | An element you will never ask about. |
Three rules follow from how they are made.
CLAY_ID("x") and
CLAY_IDI("x", 0) are two different ids: Clay hashes them differently even at index 0,
so an element made with one is never found with the other. The example asks
Clay_PointerOver(CLAY_IDI("slot", 0)) about the element it made with
CLAY_IDI("slot", i).rmp::ui names
its elements by their label through Clay_GetElementIdWithIndex() — the function behind
CLAY_IDI — counting each label's occurrences and giving each scene that draws UI a
block of indices of its own. In the first such scene of a frame that block starts at 0, so
CLAY_IDI("Close", 0) there is the id rmp::ui::button("Close") already
has.[dev] strict = true the first one stops a debug
build where it happened.Clay does not copy strings. It keeps the pointer it is given and reads it while the layout is
computed and drawn, which is inside rmp::ui::end(). rmp::ui::text() takes
that problem away by copying what it is given into a frame arena first — which is why
rmp::ui::text(std::to_string(score)) is safe — but a string you hand to Clay yourself
is your responsibility:
CLAY_STRING("BETA") on a literal is fine forever: a literal lives as long as the
program.rmp::ui::end() returns. A
std::string declared in _draw() before rmp::ui::begin() does;
a temporary made inside the CLAY_TEXT() call does not.int coins = 120;
void _draw() override {
// alive until _draw() returns, which is after end()
const std::string label = "Coins: " + std::to_string(coins);
const Clay_String text{ .isStaticallyAllocated = false,
.length = static_cast<int32_t>(label.size()),
.chars = label.c_str() };
rmp::ui::begin();
CLAY(CLAY_ID("wallet"), { .layout = { .padding = CLAY_PADDING_ALL(8) },
.backgroundColor = { 30, 30, 38, 255 } }) {
CLAY_TEXT(text, CLAY_TEXT_CONFIG({ .textColor = { 255, 220, 120, 255 },
.fontSize = 24 }));
}
rmp::ui::end();
}Text is measured and drawn with the interface's font — the one [ui] font names, or
raylib's built-in font when it is empty — whatever .fontId says. The
.fontSize is in pixels, and the spacing between letters is a tenth of it, the same as
rmp::ui's own text, and a font of your own is rasterised at exactly that size for your
text as it is for theirs.
An image element points .image.imageData at a Texture2D — raylib's
struct, not an rmp::Texture — that stays alive until
rmp::ui::end() returns. The renderer draws it stretched to the element's box. The
example does it the safe way: it keeps the rmp::Texture that owns the picture, and
copies the raylib struct out of it into a local for the frame.
The tint is the part that is easy to write wrong. It travels in .userData, as a
pointer to a Color; a null userData draws the picture untinted. It is not
.backgroundColor: Clay emits a rectangle for any element with a background colour,
after the element's image, so a colour put there is painted straight over the
picture.
rmp::Texture face; // owns the picture
Color hurt{ 255, 120, 120, 255 }; // a member: alive for as long as the scene
void _ready() override { face = rmp::assets::load_texture("rabbit.png"); }
void _draw() override {
Texture2D frame_face = face; // the raylib struct, for this frame
rmp::ui::begin();
CLAY(CLAY_ID("portrait"),
{ .layout = { .sizing = { .width = CLAY_SIZING_FIXED(96 * rmp::ui::scale()),
.height = CLAY_SIZING_FIXED(96 * rmp::ui::scale()) } },
.image = { .imageData = &frame_face },
.userData = &hurt }) {}
rmp::ui::end();
}rmp::ui::image() does all of this for you, copying
the struct into the frame arena and carrying its
tint the same way; drop to Clay for an
image only when it has to sit somewhere rmp::ui cannot put it.
Every number you give Clay is a pixel of the window. Every number you give rmp::ui
is a design unit — a pixel at the [window] resolution — which it multiplies by
rmp::ui::scale() on the way to Clay, so a menu is the
same size on a laptop and on a 4K screen. Clay elements of your own do not get that for free.
Multiply by rmp::ui::scale(), as the portrait above does, and they grow and shrink with
the rest of the interface; leave it out, and they stay the same number of pixels on every
screen.
Clay_PointerOver() answers from the previous frame's layout, exactly as
rmp::ui::button() does: this frame's layout does not exist until end().
The framework hands Clay the pointer at the end of each scene's layout, and for a scene whose input
a scene above it has taken, it hands Clay a position no element can contain — so
Clay_PointerOver() is false under a pause menu, the same as every rmp::ui
widget there.
Clay keeps one pointer state, and the last rmp::ui::end() of a frame is what sets
it. With two scenes describing UI in the same frame, ask Clay about the pointer only in the upper
one.
Your
elements count for rmp::ui::wants_pointer()
the same as the framework's own. It is answered from what each end() drew: the pointer
over an element of yours with a background colour, a border or an image, or over a clip container, is
over the interface, and the game's mouse actions go quiet there. Text alone is not, and neither is
whatever a clip container has clipped away.
Clay does not draw: it produces a list of commands, and src/rmp/ui/render.cpp turns
them into raylib calls, in Clay's z order. It understands these, and the elements you write get
exactly what the framework's own get:
| Command | Drawn as |
|---|---|
RECTANGLE | The background colour, each corner rounded by its own radius. |
BORDER | The border colour, each side at its own width, each corner rounded by its own radius. |
TEXT | The interface's font, at the element's size and colour. |
IMAGE | imageData as a Texture2D, stretched to the box, tinted by a Color in userData. |
SCISSOR_START, SCISSOR_END | Clipping, so Clay's clip and scroll containers work. |
Each
radius is taken on its own and held to half the box's shorter side, so a radius too big for the box
cannot turn it inside out. A box with four
equal corners and four equal sides — everything rmp::ui draws — goes through raylib's own
rounded-rectangle calls; any other shape is drawn by the renderer itself, such as a tab rounded only
along the top with a border along the bottom:
rmp::ui::begin();
CLAY(CLAY_ID("tab"), { .layout = { .padding = CLAY_PADDING_ALL(10) },
.backgroundColor = { 30, 30, 38, 255 },
.cornerRadius = { .topLeft = 18, .topRight = 18 },
.border = { .color = { 88, 120, 245, 255 }, .width = { .bottom = 3 } } }) {
CLAY_TEXT(CLAY_STRING("Items"),
CLAY_TEXT_CONFIG({ .textColor = { 255, 255, 255, 255 }, .fontSize = 20 }));
}
rmp::ui::end();Anything else Clay can emit — CUSTOM elements, overlay colours — is not drawn. The
renderer is one short file, and adding a case to it is the intended way to extend it.
The Clay in thirdparty/clay/clay.h is pinned at 0.14 in
thirdparty/FROZEN_VERSIONS.md, carries one marked patch so that it builds with
NetBSD's compiler, and does not move unless someone decides it should. Clay is not at 1.0, and its
API has changed between minor versions. Code written against rmp::ui does not depend on
any of that — it never names a Clay type — while code that drops to Clay is tied to the version it
was written for.
That is a fair trade for a feature a screen needs today, and a poor one for a button. Reach for
Clay for the element rmp::ui cannot make, and keep everything around it in
rmp::ui.
https://omardev29.github.io/rmp-docs/manual/raylib/rlgl.html
Under every raylib drawing call is rlgl, raylib's thin layer over OpenGL: a matrix
stack, a render batch, blend and depth state, shaders. It is on the include path of every target,
it is what raylib's own drawing is made of, and it is the portable way to reach below
DrawTexture() — the one that works on every target the framework builds, including the
software renderer its tests run on.
Raw OpenGL is possible too, and costs more than it looks: the version is not the same on every target, and the framework hands your code no GL header and no loader.
<rlgl.h> is never included for you; a file that uses it says so. What it is
safe to do, and where, follows from the frame the framework runs:
| Where | What is safe there |
|---|---|
A scene's _draw() | Drawing, in screen space. It is the hook that runs between BeginDrawing() and EndDrawing(). |
An object's _draw() | Drawing, in world space: it runs inside the scene's camera. |
A scene's _ready() | Creating GPU resources — textures, render textures, shaders. The window, and the GL context with it, exists by then. |
A scene's _end() | Releasing them. At shutdown every scene is ended before the window closes. |
| A scene's constructor, or a member initialiser | Nothing that touches the GPU. The first scene is constructed before the window opens. |
_update() | Nothing that draws. The frame has not begun. |
The constructor is the one that surprises. RMP_GAME builds your first scene as the
argument to the call that opens the window, so anything its constructor or its member initialisers
load is loaded with no GL context — and comes back empty, with raylib asking in the log whether you
are trying to load before InitWindow(). Every scene after the first is
constructed while the game runs, which is why the mistake hides until the scene it is in becomes
the first one.
raylib does not send each drawing call to the GPU as it comes. It queues vertices into a render
batch and submits the batch when it is full, when a change of state forces it, and at the end of
the frame in EndDrawing(). Everything drawn through raylib and rlgl goes through that
one queue, in order, so mixing DrawRectangle() with rlBegin() and
rlVertex2f() needs no ceremony.
Two things do need it, and both are about code that reads or writes the GPU around the queue
rather than through it: raw OpenGL calls, and reading the framebuffer back. Flush the queue first
with rlDrawRenderBatchActive(), or raylib's drawing lands after yours, and the read
sees only what was submitted before. The framework's own CI capture, in
tests/smoke_test.h, flushes for exactly that reason before it reads a frame back.
The batch is not the same size everywhere: rlgl sizes it at 8192 quads on OpenGL 3.3 and at 2048 on OpenGL ES, 3.0 as well as 2.0, so the same scene submits more often on the web and on Android than on a desktop.
Your _draw() is not the last thing in the frame. The interface draws in
rmp::ui::end(), the scenes above yours draw after it, and next frame the world draws
again with whatever state the GPU was left in. raylib's paired calls put back what they change; a
bare rlgl switch stays switched until something switches it back:
float angle = 0;
void _update(float delta) override { angle += 90 * delta; }
void _draw() override {
// a pair: blending goes back to alpha at EndBlendMode()
BeginBlendMode(BLEND_ADDITIVE);
DrawCircleV({ 200, 200 }, 60, Fade(ORANGE, 0.6f));
DrawCircleV({ 240, 200 }, 60, Fade(SKYBLUE, 0.6f));
EndBlendMode();
// the matrix stack: whatever is pushed is popped
rlPushMatrix();
rlTranslatef(500, 225, 0);
rlRotatef(angle, 0, 0, 1);
DrawRectangle(-40, -40, 80, 80, LIME);
rlPopMatrix();
}The same goes for BeginScissorMode(), BeginShaderMode() and
BeginTextureMode(), each with its End. Switches such as
rlEnableDepthTest() or rlDisableBackfaceCulling() have no pair: turn
back on what you turned off before _draw() returns.
raylib is compiled once per target for one version of OpenGL, and it is not the same version everywhere. This is what the framework's build asks for at its current source:
| Targets | OpenGL | rlGetVersion() |
|---|---|---|
| Windows, Linux (glibc and musl, every architecture), the BSDs | OpenGL 3.3, whichever windowing backend is chosen | RL_OPENGL_33 |
| macOS | OpenGL 3.3 — raylib's build fixes it there, and notes that Apple has marked OpenGL deprecated | RL_OPENGL_33 |
| Linux DRM/KMS | OpenGL ES 2.0, through EGL and GBM | RL_OPENGL_ES_20 |
| Web | OpenGL ES 2.0, which the browser provides as WebGL — with either [web] backend | RL_OPENGL_ES_20 |
| Android | OpenGL ES 2.0, or 3.0 with [android] gl_version = "ES30" (see below) | RL_OPENGL_ES_20, or RL_OPENGL_ES_30 |
| iOS | OpenGL ES 3.0, through ANGLE, which runs it on Metal. The game is compiled for ES 3.0; raylib itself comes prebuilt from the raylib-iOS fork. | RL_OPENGL_ES_30 |
The software renderer of rmp test render and CI's render checks | None: raylib rasterises on the CPU, into memory | RL_OPENGL_SOFTWARE |
[android] gl_version is the one version a game chooses. "ES20", the
default, compiles raylib and the game for OpenGL ES 2.0; "ES30" compiles both for
OpenGL ES 3.0, links ES 3.0's library and asks EGL for an ES 3.0 context. The manifest requires the
same version, so "ES30" also hides the game from the devices without ES 3.0 on the Play
Store: it is for a game that needs what raylib's ES 3.0 path adds. See
Android.
Ask at run time rather than with a macro: rlGetVersion() is compiled into raylib
itself, so it answers for the library the game really linked against.
The version decides which shading language a shader is written in: GLSL 330 for OpenGL 3.3, GLSL 100 for OpenGL ES 2.0, and GLSL 300 es for OpenGL ES 3.0. A game with shaders ships one file for each language its targets report, and picks by version:
Shader glow{};
void _ready() override {
const char *glsl = "100"; // ES 2.0: DRM, web, Android
if (rlGetVersion() == RL_OPENGL_33) glsl = "330"; // the desktops
if (rlGetVersion() == RL_OPENGL_ES_30) glsl = "300es"; // iOS, and Android on "ES30"
glow = LoadShader(nullptr, TextFormat(RMP_RESOURCES_PATH "glow%s.fs", glsl));
}
void _end() override { UnloadShader(glow); }
void _draw() override {
BeginShaderMode(glow);
DrawRectangle(100, 100, 200, 200, WHITE);
EndShaderMode();
}LoadShader() reads its files through the asset pack like every raylib loader the
framework hooks, so the shaders ship inside resources.rres with everything else, in a
shaders/ folder or at the top of resources/.
The framework gives your code no OpenGL header and no function loader. raylib loads the GL functions it needs inside rlgl's implementation, for itself. What that means in practice:
rmp test render and the
render checks in CI build the game against raylib's software renderer, which links no GL library —
a direct glClear() in a game's code links on a Linux desktop and fails to link there,
with the linker reporting an undefined glClear. Code that calls OpenGL directly has to
be left out of that build, for instance with
#if !defined(GRAPHICS_API_OPENGL_SOFTWARE) around it.rlDrawRenderBatchActive() before your
own GL calls, so raylib's queued drawing reaches the GPU before them.raylib
does lend out its loader. rlGetProcAddress() returns the address of a GL function
through the same loader raylib used for itself, in a raylib compiled for OpenGL 3.3 or OpenGL ES —
2.0, or 3.0 on Android. Under the software renderer it returns null. On iOS it is the fork's prebuilt
raylib that answers, and nothing in the framework calls it there or tests what it returns. So the
call has to be checked:
using GetIntegerv = void (*)(unsigned int, int *);
auto get_integerv = reinterpret_cast<GetIntegerv>(rlGetProcAddress("glGetIntegerv"));
if (get_integerv != nullptr) {
rlDrawRenderBatchActive();
int largest = 0;
get_integerv(0x0D33, &largest); // GL_MAX_TEXTURE_SIZE
TraceLog(LOG_INFO, "largest texture: %d", largest);
}Everything past that — a GL loader of your own, linking the platform's GL library yourself, the GLES headers of each mobile SDK — is outside what the framework builds and tests on its targets. If rlgl can say it, say it with rlgl.
https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html
The framework has two halves, and the second can go without the first. One is the
runtime layer — rmp::, scenes, the interface, the asset pack. The other is everything
around your code: the build for each target, the icons and identifiers generated from
raylib_multiplatform.toml, the pinned toolchains, CI and the release. A game in plain
C, with its own main() and raylib, keeps the second half and gives up the first.
examples/plain_c is that game: one C file, raylib, the framework's headers that are
plain C — <rmp/config.h> and <smoke_test.h> — and a
while loop of its own. Its header is the recipe and the list of what changes:
// ===========================================================================
// examples/plain_c -- the framework with none of the framework.
//
// Plain C, your own main(), raylib and nothing of ours but the CI hooks. No
// rmp::assets, no scenes, no entry-point macro. What you keep is everything
// the framework does *around* your code, which is the part that is hard to
// reproduce: the build targets, the pinned toolchains, the icons and
// identifiers generated from raylib_multiplatform.toml, the release pipeline.
//
// To use it, in a game made with `rmp new`, from the game's folder:
//
// rm src/main.cpp && rm -r src/rmp/ src/scenes/ tests/game/
// cp <the framework>/examples/plain_c/src/main.c src/
// rmp run
//
// src/ is globbed by all four build systems (CMake, the Android CMakeLists,
// XcodeGen, Emscripten), so nothing else needs editing. src/rmp/ is the
// framework itself, and it goes because nothing here uses it: CMakeLists.txt
// builds the framework library from it whenever it has sources, while a src/
// with no C++ in it gets an executable linked to raylib alone -- so kept, it
// is the whole C++ framework compiled for nothing on the desktop, and
// compiled into the game on Android and iOS, whose builds take everything
// under src/. With it gone there is no framework library at all. tests/game/
// goes with src/scenes/: it tests the main menu, through the framework. Keep
// include/rmp/: this file reads [window] from <rmp/config.h>, the one header
// of ours that is plain #defines. The rmp new CI job follows the first two
// lines in a fresh game and boots what they make.
//
// What you give up, and what replaces it:
//
// assets::Load* -> LoadTexture(RMP_RESOURCES_PATH "x.png"), as below
// the resource pack -> gone. Loose files only: a release ships
// resources/ as it is, with a PACK_SKIPPED.txt
// saying why (tools/ship_resources.sh), because
// raw raylib cannot read resources.rres -- reading
// it is what src/rmp/assets/loader_hook.cpp was doing.
// RMP_WINDOW_TITLE, ... -> #include <rmp/config.h>, as below: [window] and
// the rest of the .toml as plain #defines, in C.
// the smoke-test hooks -> <smoke_test.h>, as below. It is C, it is on the
// include path, and every CI boot greps the lines it
// prints: a boot, a frame read back, a clean exit.
//
// TWO PLATFORMS DO NOT RUN THIS FILE AS IT STANDS, and both for the same
// reason: the `while` loop below assumes your code owns the frame loop, and on
// those two it does not.
//
// iOS does not call main() at all. The run loop belongs to UIKit, and
// raylib's iOS backend calls ios_ready/ios_update/ios_destroy.
// Web has no loop either: the browser calls you back, through
// emscripten_set_main_loop(). A `while` loop there freezes the tab
// unless the whole binary is built with -s ASYNCIFY, which is a real
// cost in size and speed and which this project does not pay.
//
// Papering over exactly that is what RMP_ENTRY_POINT is for -- it writes the
// right loop for each target and calls the same three hooks. So if you want
// iOS or Web, either keep the framework's entry point (which is one include and
// one line, and costs you nothing else) or write those two runners yourself.
// Linux, Windows, macOS, the BSDs and Android run this as it is.
// ===========================================================================
#include <raylib.h>
#include <rmp/config.h> // [window] from raylib_multiplatform.toml, as #defines
#include <smoke_test.h> // the CI hooks: no-ops unless RAY_TEST_MAX_FRAMES is set
// RMP_RESOURCES_PATH is defined by CMake, not by us: an absolute path to
// resources/ in a development build, "./resources/" in a release, "" on
// Android (where assets sit at the root of the APK). Build every asset path
// out of it and the same source works on all of them.
int main(void) {
SmokeTest_Begin();
#if RMP_PRODUCTION_BUILD && !defined(PLATFORM_ANDROID) && !defined(__EMSCRIPTEN__)
// A release reads "./resources/", and "." has to be the executable's folder,
// not wherever it was started from -- a file manager, a shortcut, another
// terminal. Only when resources/ is THERE, though: `rmp build release`
// leaves the executable in build/ and resources/ beside build/, and run
// from the project folder it reads that one. The framework's entry point
// does the same for a C++ game (enter_executable_folder() in
// src/rmp/app/app.cpp); here it is yours. GetApplicationDirectory() is "" on
// NetBSD and OpenBSD, which cannot say where an executable is: there a
// release reads the working directory's resources/.
const char *folder = GetApplicationDirectory();
if (folder[0] != '\0' &&
DirectoryExists(TextFormat("%s%s", folder, RMP_RESOURCES_PATH))) {
ChangeDirectory(folder);
}
#endif
// [window] in the .toml, the way RMP_GAME opens it: resizable, vsync if it
// says so, and its size and title. CI checks the window was asked for the
// vsync the .toml names.
SetConfigFlags(RMP_WINDOW_VSYNC ? FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT
: FLAG_WINDOW_RESIZABLE);
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
Texture2D rabbit = LoadTexture(RMP_RESOURCES_PATH "rabbit.png");
// One asset asked for, and failed if it came back empty: what the boot
// line reports and every CI boot requires to be assets_failed=0.
SmokeTest_ReportBoot(rabbit.id == 0 ? 1 : 0, 1);
// The window's X ends it, and under CI so does the frame budget.
while (!WindowShouldClose() && !SmokeTest_Done()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(rabbit, GetScreenWidth() / 2 - rabbit.width / 2,
GetScreenHeight() / 2 - rabbit.height / 2, WHITE);
DrawText("Raylib is Multiplatform!", 190, 200, 20, LIGHTGRAY);
SmokeTest_CaptureFrame(); // between the last draw and EndDrawing()
EndDrawing();
SmokeTest_Tick();
}
UnloadTexture(rabbit);
CloseWindow();
return 0;
}
The recipe, from the folder of a game made with rmp new:
rm src/main.cpp && rm -r src/rmp/ src/scenes/ tests/game/
cp <the framework>/examples/plain_c/src/main.c src/
rmp runtests/game/
goes with src/scenes/: the test a new game starts with is a test of the main menu,
written in C++ against the framework, and its program is built with the framework library — which
a plain C game no longer has.
The
framework's CI follows it on every commit, in a copy of a game freshly made with
rmp new: it reads the first line out of the example and runs it, copies the file in as
the second line says, and then, in place of rmp run, runs that game's render check —
rmp test render — which has to build it, boot it with its one asset loaded, see a frame
drawn and see it exit cleanly. Then it starts that game's release with
tools/shipped_check.sh, from the project folder and from a folder with no
resources/ in it, and both have to load the asset. The examples job boots the example
itself like every other one.
Nothing in the
configuration says "this is a C game". The build looks: when the game's src/ has no
.cpp file outside src/rmp/, the game is compiled as C99 and linked against
raylib and nothing else — no entry point of ours, no library of ours. With src/rmp/
gone, CMake builds no framework library at all, and its configure says
=== NO src/rmp/: no framework library, a plain C game ===.
The
recipe deletes src/rmp/, the framework's own source, because a plain C game uses none
of it and the builds would compile it anyway. CMake builds the framework library from
src/rmp/ whenever the folder holds sources, even while the game itself is linked to
raylib alone: kept, it is the whole C++ framework compiled for nothing. Android's and iOS's builds
take everything under src/, so there it would be compiled into the game itself. And a
release decides by the folder what to ship in resources/: the pack while it is there,
the loose files once it is gone (below).
Put a .cpp file back without src/rmp/ and the configure stops, naming
the problem: … has C++ sources and there is no src/rmp/, so no framework to link …. A
C++ game keeps src/rmp/, and with it the framework's entry point and library.
Both values the build defines for every game are still there: RMP_RESOURCES_PATH, the folder the
files are read from — an absolute path to resources/ in a debug build,
./resources/ in a release, and empty on Android, where the files sit at the root of the
APK's assets — and RMP_PRODUCTION_BUILD, 0 or 1.
So is everything raylib_multiplatform.toml sets, through rmp/config.h, the
one header of ours that is plain #defines: its one include is
rmp/generated/config.h, the file configure.py writes from the
.toml, which includes nothing. A plain C game's include path is
raylib's, the game's include/, where rmp/config.h is,
tests/, where smoke_test.h is, and thirdparty/raymob, where
<admob.h> is (below):
int main(void) {
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(RMP_PROJECT_NAME, 20, 20, 20, DARKGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}Renaming the game, or resizing its window, is still one line in one file.
raylib_multiplatform.toml as it is for every game: rmp run,
rmp build release and cmake --preset debug work the same..ico generated from
[icon] source.| Given up | What it means |
|---|---|
Everything under rmp:: | Scenes, objects and behaviors, the interface, named input, audio by name, saves, random, and rmp::ads — though not the ads themselves (below). Your code is raylib's API and your own. |
| The entry point | Your main() owns the loop, which is exactly what the web and iOS do not allow (below). No [app] max_delta clamp on GetFrameTime(), and no rmp::app::quit(): the loop ends when your condition says so. Escape stays raylib's exit key and closes the window, unless your code calls SetExitKey(KEY_NULL). |
| Starting a release from anywhere | The framework's entry point moves a desktop release into the executable's folder when a resources/ sits next to it, so that ./resources/ is that one wherever the game was started from. In plain C that is yours, and the example does the same in a release: ChangeDirectory() into GetApplicationDirectory() only when DirectoryExists() finds resources/ there. Otherwise it stays put and reads the working directory's — which is what rmp build release needs, since it leaves the executable in build/release/ and resources/ in the project folder. On NetBSD and OpenBSD, which cannot say where an executable is, the folder is empty and the release always reads the working directory's. |
| The asset pack | Reading resources.rres is the framework's runtime, and raylib alone cannot. A plain C game reads loose files only, and its release ships them — see the release packages. |
| The boot and render reports | The entry point prints what CI looks for; a plain C game calls the same hooks itself. See the smoke test. |
The ads
survive without rmp::. rmp::ads is a wrapper
over the C functions in <admob.h>, and a plain C game has that header on its
include path on every target: the real calls on Android, static inline functions that
do nothing everywhere else, so the same calls compile wherever the game builds. The calls and what they mean
are on the Ads page, and
[android.admob] turns them on as it does for any game.
void game_over(void) {
if (IsInterstitialAdLoaded()) ShowInterstitialAd();
RequestInterstitialAd();
}The file's own header says it, and the reason is the while loop: it assumes your
code owns the frame loop, and on the web and iOS it does not.
| Target | The file as it stands |
|---|---|
| Windows, Linux, macOS, the BSDs | Runs. |
| Android | Runs, by the file's own account: raylib's Android glue calls main(). |
| Web | Does not. The browser owns the loop and calls the game back once per frame; a while loop there needs -s ASYNCIFY, which this build deliberately does not have. |
| iOS | Does not. UIKit never calls main(): raylib's iOS backend calls three functions instead, and they are what the framework's entry point exists to provide. |
A plain C game should say so in its configuration, so CI does not build the web and iOS, which it cannot run:
[targets]
enabled = ["all"]
disabled = ["web", "ios"]To have the web or iOS back, keep the framework's entry point:
RMP_ENTRY_POINT with three functions of yours, which
writes the right loop for every target. It is C++, and that brings the rest of the framework back
with it: a .cpp file in src/ needs src/rmp/, the framework's
library is built and linked again, and a release ships the pack instead of the loose files — which
raylib's own loaders then read through the framework. Or write those two runners yourself.
CI does not take a build's word for it. It starts the game with RAY_TEST_MAX_FRAMES
set, and requires three log lines: RAY_TEST_BOOT_OK with
assets_failed=0, RAY_TEST_RENDER_OK for a frame read back with something
on it, and RAY_TEST_DONE_FRAMES for a clean exit when the budget is spent.
rmp test render asks for the same three. rmp test smoke asks for the
first two only: it does not look for RAY_TEST_DONE_FRAMES.
The
framework's entry point calls the hooks that print them. A plain C game calls them itself, from
<smoke_test.h>, which is written to compile as C. Every hook but one does nothing
unless RAY_TEST_MAX_FRAMES is set; SmokeTest_ReportBoot prints its line on
every run. The example shows where each one goes:
SmokeTest_Begin once, first: it reads the frame budget.SmokeTest_ReportBoot, with how many assets failed and how many
were asked for, once the window is open and the assets are loaded. The framework counts the loads
made through rmp::assets; with raylib's loaders the game counts its own, and the failed
count must be 0. The line also says whether the window asked for vsync, and the render check
compares that with [window] vsync — which is why the example passes
FLAG_VSYNC_HINT only when RMP_WINDOW_VSYNC says so.SmokeTest_CaptureFrame after the last draw call and before
EndDrawing(): the frame it reads back is the one about to be shown.SmokeTest_Tick after EndDrawing(), and
SmokeTest_Done in the loop's condition, so that the budget ends the
loop the way the window's close button does.What goes in a release
archive's resources/ is decided by one script, tools/ship_resources.sh,
which the packaging steps of the targets that pack call — the Linux glibc and DRM ones, macOS and
the BSDs — and which the windows-x64 job repeats in PowerShell. While
src/rmp/ is there it ships resources.rres alone, which the framework reads.
Without it, it ships the loose files of resources/, the pack left out, and a
PACK_SKIPPED.txt saying that this game is plain C and raw raylib cannot read the pack.
Android copies the folder into the APK whatever the game is, and the targets whose packer cannot run on
the machine that builds them — Linux RISC-V, Linux musl and Windows ARM64 — ship loose files with a
note of their own.
https://omardev29.github.io/rmp-docs/manual/platforms/index.html
One codebase builds for 17 targets: Linux x86-64, Linux ARM64, Linux RISC-V, Linux x86-64 (musl / Alpine), Windows x86-64, Windows ARM64, macOS (universal), iOS (simulator), Web (WebAssembly), Android, FreeBSD x86-64, FreeBSD ARM64, OpenBSD x86-64, OpenBSD ARM64, NetBSD x86-64, Linux DRM/KMS (no X11), Linux ARM64 DRM/KMS (no X11). A game chooses
which of them it ships in one place, [targets] in
raylib_multiplatform.toml, and everything downstream — the build files, CI, the
release — follows that choice.
The code of a game does not change from one target to another. What changes is how the game is built, packaged and run, and the pages in this section are about those differences:
rmp builds for DRM/KMS by itself: the screen and the keyboard from
/dev, sudo or the groups, and the terminal it gives back..toml, permissions, signing.| Target | What it is | Family | Groups it is in |
|---|---|---|---|
linux-x64-glibc | Linux x86-64 | linux | all, desktop, linux |
linux-arm64-glibc | Linux ARM64 | linux | all, desktop, linux |
linux-riscv64-glibc | Linux RISC-V | linux | all, desktop, linux |
linux-x64-musl | Linux x86-64 (musl / Alpine) | linux | all, linux |
windows-x64 | Windows x86-64 | windows | all, desktop, windows |
windows-arm64 | Windows ARM64 | windows | all, desktop, windows |
macos | macOS (universal) | apple | all, apple, desktop |
ios | iOS (simulator) | apple | all, apple, mobile |
web | Web (WebAssembly) | web | all, web |
android | Android | android | all, android, mobile |
freebsd-x64 | FreeBSD x86-64 | bsd | all, bsd |
freebsd-arm64 | FreeBSD ARM64 | bsd | all, bsd |
openbsd-x64 | OpenBSD x86-64 | bsd | all, bsd |
openbsd-arm64 | OpenBSD ARM64 | bsd | all, bsd |
netbsd-x64 | NetBSD x86-64 | bsd | all, bsd |
linux-x64-glibc-drm | Linux DRM/KMS (no X11) | linux | all, drm, linux |
linux-arm64-glibc-drm | Linux ARM64 DRM/KMS (no X11) | linux | all, drm, linux |
A target's name is <os>-<arch>-<libc>-<env>, and each part
is only there when it can differ. linux-x64-glibc and linux-x64-musl name
their C library because a glibc binary does not start on Alpine and a musl binary does not start on
Debian; windows-x64 stops after the architecture because Windows has one C library;
macos stops at the operating system because its binary carries both architectures. The
last part, the environment, is the windowing system, and it is only written when the binary is
limited to one: linux-x64-glibc-drm draws through DRM/KMS, with no X11 and no
Wayland.
Each target belongs to one of 6 families, and the family is which part of CI
builds it: linux, windows, apple, web,
android and bsd. CI skips a whole family when none of its targets are
enabled, so a game that ships only to desktops never starts an Android build.
[targets] has two lists. enabled names targets and groups;
disabled is subtracted from whatever enabled came to. Groups expand and
duplicates fold together, so there is no order to think about and nothing to conflict:
[targets]
enabled = ["all"]
disabled = ["ios"]That is everything but iOS. The same lists take exact target names, and mix them with groups:
[targets]
enabled = ["desktop", "web", "linux-x64-musl"]
disabled = ["windows-arm64"]The groups:
| Group | Holds |
|---|---|
all | Every target. |
desktop | Linux glibc on x86-64, ARM64 and RISC-V; Windows on x86-64 and ARM64; macOS. Not musl, not the DRM targets and not the BSDs. |
linux | Every Linux target: the glibc ones, musl and the DRM ones. |
windows | Windows on x86-64 and ARM64. |
apple | macOS and iOS. |
mobile | Android and iOS. |
bsd | FreeBSD, OpenBSD and NetBSD, on every architecture built for them. |
drm | The Linux DRM/KMS targets. |
web, android | The one target each. |
The table above says which groups each target is in. A name that is neither a target nor a group is refused, and so is a pair of lists that leaves nothing to build. So is the most natural typo of all — a group name without the brackets of a list:
[targets]
enabled = "all" raylib_multiplatform.toml:2: enabled = "all"
^^^^^^^^^^^^^^^
configure: error: [targets] enabled = 'all' is a string, and this has to be a list.
Write [targets] enabled = ['all'] -- with the brackets. Without them TOML hands over the characters one at a time.
Groups count as names here: ["all"], ["desktop"].Turning a target off removes it from the build, from CI and from the release. Other settings
follow it: [android.admob] switches itself off when Android is not a target, and a
non-empty [raylib] disabled_modules warns when iOS is one, because iOS links a prebuilt
raylib that it cannot reach.
CI runs in two lanes. A push or a pull request gets the fast lane: the targets that catch most mistakes, in about ten minutes. A tag — a release — gets the full lane: every target the game has enabled, and then the release itself. The full lane can also be started by hand, for every target or for the groups and targets you list, separated by commas:
gh workflow run ci.yml -f full=true # every enabled target
gh workflow run ci.yml -f targets=drm # one group or target; implies the full lane
gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macosBuilding is not the bar. Wherever CI can start a desktop build, the game is started with a
frame budget: it must report that it booted with every asset loaded — assets_failed=0, where a file asked for through
rmp::assets that is missing or does not decode counts — a frame is read back and must
have something drawn on it, and it must print that it reached the end of the budget. The web build
has no frame budget: it is opened in headless Chromium, must report the same boot line, and its
canvas is measured for pixels. A desktop release is started from a folder with no
resources/ in it, the way a player starts it from a file manager, and has to find the
one next to it — on every system but OpenBSD and NetBSD, which cannot say where an executable
is.
| Target | Lane | What CI checks |
|---|---|---|
linux-x64-glibc | every push | Built; checked against the [linux] glibc floor and for how it was linked; resources packed; booted under a virtual X server, with a frame read back; the archive unzipped and started from another folder, compressed by UPX by default. |
web | every push | Built; booted in headless Chromium, the canvas measured for pixels, and a save written to IndexedDB and read back. |
windows-x64 | every push | Built with the runner's MinGW GCC; its imports checked to be all part of Windows 10; booted on the Windows runner from another folder, with the compiler off PATH and a software OpenGL placed next to the executable, a frame read back, and a save made in a user folder whose name is not ASCII. |
android | every push | A debug APK built and checked; a release AAB built, signed and its signature verified. Not run, except by the optional Firebase Test Lab job, which runs in the full lane and skips with a warning unless a Firebase project and its key are set up: its Robo test taps through the debug APK, which shows only Google's test ads. |
linux-arm64-glibc | full | Built on an ARM64 runner, checked against the glibc floor, booted under a virtual X server; the archive unzipped and started from another folder, compressed by UPX by default. |
linux-x64-musl | full | Built; checked to be a musl binary with no glibc symbol, asking the system for musl's loader and C library and nothing else; on Alpine, a software-rendered build of it booted, and the archive's binary, compressed by UPX by default, started under a virtual X server. |
linux-riscv64-glibc | full | Cross-compiled and checked to be a RISC-V executable; checked against its own glibc floor, 2.38, which [linux] glibc does not set. The archive is unzipped and started from another folder on a RISC-V board when [ci] riscv64 names one, and under QEMU's emulation of RISC-V when it does not or the board fails, under a virtual X server. Not compressed unless named in [upx]. |
linux-x64-glibc-drm | full | Built; checked to link libdrm and no X11 or Wayland; the archive's binary, compressed by UPX by default, booted on a virtual display the kernel provides. On the same display, rmp run run the way a Linux console runs it, which has to decide DRM/KMS by itself, build, check /dev and boot the game. |
linux-arm64-glibc-drm | full | Built and checked the same way. Not run: what it is for is a Raspberry Pi's own display pipeline, which a virtual display does not resemble. |
windows-arm64 | full | Cross-compiled with MSVC and checked to be an ARM64 executable whose imports are all part of Windows 10. Never run. |
macos | full | Built as one binary with both architectures, and checked for both and for the oldest macOS each asks for; a software-rendered build booted, and a software-rendered release started from the project folder it was built in and from another folder. |
ios | full | raylib built for iOS, the Xcode project generated, a simulator app built and its bundle checked. Booted in the simulator only when the repository variable IOS_SIMULATOR_TEST is true. |
| the BSDs | full | Built in a virtual machine of each system; checked to be an executable; resources packed; a software-rendered build booted inside the machine, and a software-rendered release started from the project folder it was built in and then from another folder — from its own on OpenBSD and NetBSD, which cannot say where an executable is. |
Every release binary is also held to its size, once a game has written its sizes down — see
the size budget. Every push also runs the checks that
need no target: the .toml, the pinned versions, the licences, and one frame of the game
drawn by raylib's software renderer — most of what rmp test runs on your machine.
A push to a branch cancels a CI run already going on that branch, so a second push can kill a
long full-lane run halfway. rmp push refuses while a run is in flight and names it;
rmp push force pushes anyway.
What becomes of the builds — the release, its archives, the stores — is the subject of Publishing.
https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html
On a desktop the framework's job is the smallest: raylib already runs there, and the game owns its frame loop the ordinary way. What differs between Windows, macOS, Linux and the BSDs is the build — the compiler, the C library, the windowing system, what goes in the archive — and that is what this page is about.
A debug build reads its files from your project's resources/ by its absolute path,
so it finds them from wherever it is started. A release reads ./resources/, the folder
the archives CI makes put next to the executable — and . is the working directory,
which is wherever a file manager, a shortcut or a terminal happened to be. So before it opens
anything, a desktop release moves into the executable's folder, when that folder has a
resources/ in it, and says so: ASSETS: reading … next to the executable, in
…. It starts from anywhere.
CI holds it to that. Every
desktop job that starts a release starts it from a folder with no resources/ in it —
macOS and the BSDs through tools/shipped_check.sh, which runs on a laptop too — and the
run has to boot with every asset loaded. The two exceptions to that folder are OpenBSD and NetBSD,
started from their own folder for the reason below. The release is laid out as the archive ships
it, except in the musl job's first run, a software-rendered build of the game, which gets the
project's own resources/ folder next to it; its second run starts the archive's
binary.
Where
the executable's folder has no resources/, the release stays where it was
started and reads the working directory's, saying
ASSETS: no … next to the executable; reading the working directory's, … — which is
what lets a release you build yourself, inside the project's build/release/, run from the
project's folder: rmp build release leaves the executable in build/release/ and
resources/ where it is. tools/shipped_check.sh checks that case too,
before the other: it starts the release where it was built, from the project folder, and the run
has to boot with every asset loaded. OpenBSD and NetBSD are the exception: raylib cannot say where the executable is
on those two, so a release there reads resources/ from the working directory and logs
ASSETS: this system does not say where the executable is, so … is read from the working
directory, …. Started from its own folder, it finds them; CI starts it from there on those
two, and checks that the line is in the log.
Every release archive also carries LICENSES.txt, the notices of everything the
game is built from, unless [deploy] licenses = false says where the game shows its
credits instead.
Windows is windows-x64 and windows-arm64. The archive is the
.exe, resources/ and the licence notices, and the player installs nothing:
a player double-clicking the game has no compiler installed, so raylib and the compiler's own C and
C++ runtimes are linked into the .exe. A release build is a windowed program — no
console opens behind the game — and a debug build keeps its console for the log.
How depends on the compiler, and the
build does it for both. MinGW links with -static, so libstdc++, libgcc and winpthread
are inside the .exe instead of in libstdc++-6.dll and
libgcc_s_seh-1.dll next to a compiler the player does not have. MSVC, and Clang
when it builds for Microsoft's ABI ([dev] compiler = "clang" on Windows, or
rmp build windows clang-cl), build with the static C runtime, /MT
(/MTd in a debug build), so no Visual C++ Redistributable is needed. The Universal C Runtime is part of Windows 10 and stays a DLL. No
/arch: option is set either: the x64 build stays on the SSE2 every x64 processor has,
where AVX2 would stop the game with an illegal instruction on a processor without it.
What
the .exe still asks the loader for is Windows itself, and CI holds it to that:
tools/binary_check.py windows reads the import table and the delay-load table of the
.exe each Windows job ships, and fails on any DLL that is not part of every Windows 10
— KERNEL32, USER32, GDI32, SHELL32,
WINMM and the Universal C Runtime are what a game imports, and OPENGL32
too with the win32 and rgfw backends. It needs only Python's standard
library, so it runs on your own build too:
python tools/binary_check.py windows build/release/my_game.exeThe icon is inside the .exe, because that is where Windows looks for it:
configure.py turns [icon] source into a multi-resolution
.ico and the build embeds it. Making the .ico needs Pillow; without it a
build of your own goes on without an icon rather than failing. CI's Windows jobs install a pinned
Pillow, and fail when [icon] source exists and the .exe they built does not
carry it.
[windows] backend chooses what raylib talks to. "glfw", the default,
is what raylib uses everywhere else and what the whole matrix is tested against.
"win32" is raylib's native Windows backend and "rgfw" a single-header
library; both drop GLFW and make a smaller .exe, and both are younger — gamepads,
several monitors, the clipboard and some keyboard cases are thinner there. Right for a simple game,
measured before it is kept:
[windows]
backend = "win32"rmp comes as rmp.ps1 for PowerShell and rmp.cmd for cmd.
The rmp the installer puts on your PATH is
a .cmd, which PowerShell runs as it is; running a rmp.ps1 yourself, such
as .\rmp.ps1 in a game's folder, needs PowerShell to be allowed to run a local
script, once (Set-ExecutionPolicy -Scope CurrentUser RemoteSigned). The launchers look for a Python
3.11 or newer by running each candidate once to ask its version, so the Microsoft Store's
python3 placeholder, which fails that question, is passed over instead of being handed
the command.
[dev] compiler picks the compiler for debug builds — yours, and the
software-rendered check CI runs — and never for a release CI ships. On Windows that can be "msvc" or "mingw" as well as
"clang" and "gcc"; "mingw" looks for
x86_64-w64-mingw32-gcc before a plain gcc, which is what makes it work
from MSYS2. [dev] linker = "mold" is refused on Windows, because mold writes Linux and
BSD executables only.
Saves go to %APPDATA%\<name>\, which follows a player between machines on a
domain. With [save] portable = true they go to a saves\ folder next to the
.exe instead — what a zip on itch.io wants — and fall back to the user's folder, saying
so once, when that folder cannot be written.
[upx] can compress the .exe and leaves Windows out by default: an
unsigned executable packed by UPX is a shape Windows Defender associates with malware, and some
machines quarantine it. If your builds are signed, add the Windows targets to
[upx] enabled.
CI builds windows-x64 with the compiler CMake finds first on the Windows runner, its
MinGW GCC, and prints which one in the log, because the runner image decides it.
windows-arm64 is cross-compiled with MSVC on an x86-64 machine. That machine cannot
run the ARM64 resource packer, so the archive ships resources/ as loose files with a
PACK_SKIPPED.txt that says why; the game reads loose files when there is no pack.
One target, macos, and one binary with both architectures in it: Apple silicon and
Intel. The archive is that binary, resources/ with the asset pack, and the licence
notices. It draws with OpenGL 3.3, which raylib's build fixes on macOS.
It opens on
macOS 10.15 on an Intel Mac and macOS 11 on Apple silicon, the
first macOS that ran there. The build sets that floor, CMAKE_OSX_DEPLOYMENT_TARGET in
CMakeLists.txt, because left unset the toolchain writes its SDK's own version into the
binary, and every Mac older than the one that built it refuses to open the game without saying why.
10.15 is where Apple's C++ library starts to have std::filesystem, which
rmp::save uses. CI reads the minimum macOS out of each slice
of the binary it ships and fails on one above the floor.
Saves go to ~/Library/Application Support/<name>/. [save]
portable means nothing on macOS and is ignored. [upx] refuses
macos by name, at its line, in either list — the binary is code-signed, and compressing
it would break the signature:
[upx]
enabled = ["linux", "macos"] raylib_multiplatform.toml:2: enabled = ["linux", "macos"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [upx] enabled: 'macos' cannot be compressed — the binary is code-signed; compressing it breaks the signature.
Remove it; there is no setting that makes it work.Building on a Mac needs a Python 3.11 or newer: the python3 macOS ships is older,
and the launcher passes it by. The scripts under tools/ are written for the bash 3.2
macOS keeps, and rmp runs under zsh. [dev] linker = "mold" is refused, for
the same reason as on Windows. "auto" skips mold there and tries lld, which it keeps
only when the toolchain can link with it; otherwise the game links with Apple's own linker.
Linux has the most targets, because "Linux" is several things to a binary: a C library, a windowing system, a processor.
| Target | For |
|---|---|
linux-x64-glibc, linux-arm64-glibc | Almost every desktop distribution, on x86-64 and on ARM64. |
linux-riscv64-glibc | RISC-V machines running a distribution with glibc 2.38 or newer. |
linux-x64-musl | Alpine, and the other distributions built on musl. |
linux-x64-glibc-drm, linux-arm64-glibc-drm | A machine with no desktop at all: a Raspberry Pi, a kiosk, an arcade cabinet, a bare console. |
A Linux executable records, for every function it takes from glibc, the glibc version that
function came from, and the loader refuses to start one that asks for more than the machine has. A
binary built on a new distribution and copied to an older one does not start, with an error that
names a version like GLIBC_2.39 — and nothing about the build warned.
[linux] glibc is the oldest glibc linux-x64-glibc and
linux-arm64-glibc may need, and the default is "2.28":
[linux] glibc | Starts on |
|---|---|
"2.17" | RHEL and CentOS 7, and everything newer. The oldest it can reach. |
"2.28" | RHEL 8, Debian 10, Ubuntu 18.10, and everything newer. |
"2.31" | Ubuntu 20.04, Debian 11, and Steam's "sniper" runtime. |
"" | The machine that built it, and whatever has its glibc or newer. |
The floor costs the game nothing: everything it asks of a newer glibc is maths or threading
functions that older ones also have. CI builds both through
tools/linux_build.sh, which compiles with zig cc against that version of
glibc, and then tools/glibc_check.sh reads the finished binary and fails the build if
any symbol asks for more. It reaches no other target, because the others are not built that way:
RISC-V, below, has a floor of its own that CI holds it to, and DRM is built against the glibc of
the machine that builds it, whose floor CI prints instead of gating it. rmp build release on your own machine uses your compiler and your glibc; run
bash tools/linux_build.sh build/release to build the way CI does.
Nothing has to be installed on the player's side either. GLFW opens the X11 and OpenGL libraries at run time, so the binary's only fixed dependencies are the C library, the maths library and the threading and dynamic-loading libraries every Linux has.
To build on a Linux desktop you need the X11 development libraries, which each family of distributions names its own way:
| Distribution | The X11 development libraries |
|---|---|
| Debian, Ubuntu | sudo apt install libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev libgl1-mesa-dev |
| Fedora | sudo dnf install libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa-libGL-devel |
| Arch | sudo pacman -S --needed libx11 libxrandr libxi libxcursor libxinerama mesa |
| Alpine | doas apk add libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev mesa-dev linux-headers |
With the compiler, CMake and Ninja, in one command each: Getting started.
On a console with no desktop, rmp builds for DRM/KMS instead, and needs none of
them: Linux from a console.
By default the binary talks to X11, and on a Wayland desktop it runs through XWayland — which
works, with one more hop, and is where fractional scaling and per-monitor DPI misbehave.
[linux] wayland = true builds GLFW with both of its backends and lets it choose when the
game starts: a Wayland session gets Wayland, an X11 session gets X11, and neither is a fallback for
the other. It needs libwayland-dev, wayland-protocols and
libxkbcommon-dev on the machine that builds.
[linux]
wayland = trueOne difference you will see on Wayland is Wayland's own design: a window has no position there.
GetWindowPosition() and SetWindowPosition() do not work, and GLFW says so
the first time something asks.
[linux] backend = "rgfw" swaps GLFW for RGFW, which is smaller and talks to X11
only — so asking for it together with Wayland is refused, rather than quietly building an X11
binary:
[linux]
backend = "rgfw"
wayland = true raylib_multiplatform.toml:2: backend = "rgfw"
^^^^^^^^^^^^^^^^
configure: error: [linux] backend = "rgfw" and wayland = true cannot both hold.
RGFW's Linux backend is X11-only — it reports itself as "DESKTOP (RGFW - X11)" — and the wayland switch only reaches GLFW.
Leaving it would build an X11 binary while the config said Wayland.
Pick one: backend = "glfw" to get native Wayland, or wayland = false.musl and glibc are two C libraries, not two versions of one: a glibc binary does not start on
Alpine, and a musl binary does not start on Debian. linux-x64-musl is therefore a
second binary, cross-compiled with zig, for Alpine, Void's musl edition and the other
musl distributions.
What
it needs is read out of the binary, because that is where it is written: CI checks that it names no
glibc symbol, and tools/binary_check.py elf --musl wants musl's loader as its
interpreter and musl's libc.so as the one library it names — or a static binary that
names neither and asks the system for nothing. Then it is started on Alpine, in an image of the
framework's own pinned by its digest, with the network off: a software-rendered build of the game
boots and draws there, and so does the binary the archive ships, under a virtual X server with
Mesa's software OpenGL, the libraries an Alpine desktop has.
The packer it would need to make resources.rres comes out musl-linked too, and
cannot run on the machine that builds it, so the archive ships resources/ as loose
files, with a PACK_SKIPPED.txt saying so.
linux-riscv64-glibc
is cross-compiled for RISC-V on an x86-64 machine, with the build image's RISC-V GNU toolchain,
against Ubuntu 24.04's RISC-V glibc, rather than with zig. [linux] glibc
does not reach it. It needs glibc 2.38 or newer — Ubuntu 24.04, Debian 13 and
Fedora 39 have it; Debian 12 and Ubuntu 22.04 do not — and the .toml's note on
[linux] glibc says so. CI holds it to that number: its job, in the full lane, runs
tools/glibc_check.sh with 2.38 and fails if the binary asks for more. It
ships loose resources for the same reason musl does.
Where
a RISC-V board is there — RISE's or Cloud-V's, as [ci] riscv64 says
(RISC-V on RISC-V) — the game is built and started on it.
Where none is, or it fails, CI starts it under emulation: QEMU runs the RISC-V binary on the x86-64
build image, with the image's RISC-V libraries — glibc, the X libraries GLFW opens, Mesa — under a
virtual X server, drawing with Mesa's software OpenGL. Either way the archive is unzipped and the
game started from another folder, and held to the same markers and exit status as every other
Linux start. The emulator proves the code, the C library and the libraries it opens work on RISC-V;
the board proves it on a RISC-V machine's own caches, timing and kernel.
The DRM targets draw straight to the screen through the kernel's display interface, with no X11, no Wayland and no window: the game is the whole screen, started from a bare console. raylib's DRM backend draws with OpenGL ES 2.0 through EGL and GBM.
The binary links libdrm, GBM and EGL directly, rather than opening them at run time the way GLFW
opens X11. Two things follow. It is built with the native compiler, against the distribution's own
copies of those libraries, so [linux] glibc does not apply to it: its floor is the
build machine's glibc, and CI prints that floor on every run. And a musl edition of it would be a
separate binary, which is why the name spells out glibc.
Building one needs the libdrm, GBM, EGL and OpenGL ES development files on the machine that
builds, and running it needs a /dev/dri device to draw on and the
/dev/input devices to read. On a Linux console with no desktop, rmp
builds this way by itself, into build/debug-drm and build/release-drm,
and checks the devices before it starts the game:
Linux from a console has all of it. Anywhere
else, the release-drm preset builds the release by hand:
cmake --preset release-drm
cmake --build --preset release-drmCI builds
the shipped one from the release preset with -DRMP_TARGET_DRM=ON, which
is the same build in build/release.
On DRM, [window] fps also chooses the display mode — 144 asks for a 144 Hz mode —
which is why the framework applies it before the window opens. Both DRM targets are in the
all group; to leave them out, disabled = ["drm"].
Saves go to $XDG_DATA_HOME/<name>/ when that variable is set to an absolute
path, and to ~/.local/share/<name>/ otherwise. [save] portable =
true puts them in saves/ next to the executable.
[upx] compresses linux-x64-glibc, linux-arm64-glibc,
linux-x64-musl and linux-x64-glibc-drm
by default — the ones whose packed archive CI starts, so a packed binary that would not launch is
caught: on every push for linux-x64-glibc, and in the full lane for the other three,
on a runner of its own architecture, on Alpine and on a virtual DRM display.
linux-riscv64-glibc is compressed only when you name it: UPX 5.2.0's RISC-V stub dies on
every kernel before 6.3, which most RISC-V boards run (Compressing with UPX says
why).
linux-arm64-glibc-drm can be added to [upx] enabled; it is left out by
default because nothing in CI runs it at all.
FreeBSD on x86-64 and ARM64, OpenBSD on x86-64 and ARM64, and NetBSD on x86-64. raylib treats
them as desktops like any other — the same GLFW backend, X11, OpenGL 3.3 and
PLATFORM_DESKTOP — so a game that needs to tell one apart tests the compiler's
__FreeBSD__, __OpenBSD__ or __NetBSD__.
CI builds each one inside a virtual machine running that system, as a release, checks the result is an executable, packs the resources and boots a software-rendered build of the game inside the machine. The build tools are installed from each system's own package mirrors, which publish no dated snapshots, so their versions are not pinned and move with the mirror. A BSD job that fails for no reason you can find in your own change is the first thing to suspect there.
Saves go to ~/.local/share/<name>/, as on Linux. On OpenBSD and NetBSD
raylib cannot say where the executable is, so [save] portable = true has no folder to
use there and says SAVE: [save] portable: this system does not say where the executable is;
saving in the user's folder instead, and a release reads resources/ from the
folder it was started in (above). NetBSD builds without link-time optimisation, which its
linker cannot read from a static library, and with a compiler that reports C++20 by an older
number — Clay carries a one-line patch for it. [upx] leaves the BSDs out by default:
UPX publishes no build for them.
The VM images ship no Python, so CI generates the configuration on Linux first and the VM builds from the generated files; CMake warns when it has no Python to regenerate them. Building on a BSD machine yourself, install Python 3.11 or newer and the build behaves as on any other desktop.
https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html
A Linux machine with no desktop — a Raspberry Pi, a server, a laptop started to a
text login — has no X11 and no Wayland for a window to open on, and often none of their headers to
build against. On such a console rmp builds the game for DRM/KMS instead: raylib's
backend that draws straight to the screen through the kernel. There is nothing to configure.
rmp run, rmp build, rmp test and rmp pack decide
by themselves, and say so.
Once
per command, before anything is configured, rmp asks these in order, and the first
that answers decides:
RMP_DRM=1
builds for DRM/KMS and RMP_DRM=0 for the desktop, whatever else is true. Empty is the
same as unset. Any other value is refused rather than read as one of the two, and so is
RMP_DRM=1 anywhere but Linux.DISPLAY or WAYLAND_DISPLAY is set: the desktop. There is one to open
a window on.SSH_CONNECTION, SSH_CLIENT or SSH_TTY is
set — with no display: the desktop, and a note saying so.XDG_SESSION_TYPE=tty, which logind sets for a text login: DRM/KMS.rmp runs in is a virtual console, /dev/tty1,
/dev/tty2 and so on: DRM/KMS, for a console that logind did not set up. The terminal
is stdin's or, when stdin is not one, the controlling terminal's, so rmp run <
/dev/null typed on a console still counts. A terminal window, SSH and tmux are
/dev/pts/… and a serial line is /dev/ttyS0: none of them is a virtual
console.The
order is there because a console's own word for itself is wrong twice. startx keeps
the console's XDG_SESSION_TYPE=tty inside the desktop it starts, so a display is asked
about first. And logind calls a login over SSH a tty session too, while the screen of
a machine you are logged into from elsewhere is not yours to take — so SSH comes before it. From
SSH, RMP_DRM=1 asks for the machine's own screen anyway:
RMP_DRM=1 rmp runWhen
it builds for DRM/KMS, rmp says why on a line of its own:
XDG_SESSION_TYPE=tty: building for DRM/KMS, in build/debug-drm and build/release-drm
(RMP_DRM=0 for the desktop).
The
framework's tests walk every combination of them.
On
a console the debug build goes to build/debug-drm and the release to
build/release-drm, never to build/debug and build/release.
They are presets of their own, debug-drm and release-drm: the debug and
release presets with RMP_TARGET_DRM on, which picks raylib's DRM platform. A console
and a desktop on the same machine never share a cache, so going from one to the other rebuilds
nothing.
rmp run # builds build/debug-drm/my_game, checks /dev, starts it
rmp build release # builds build/release-drm/my_gameWithout rmp, the same presets by hand:
cmake --preset debug-drm
cmake --build --preset debug-drmCMake
never looks for X11 in either. A test configures both presets with X11 made impossible to find,
and the desktop's preset beside them, which has to fail that way for the test to count. A
debug build on a console is sanitized the way any debug build is, as
[dev] sanitize says.
A console build needs the development files of libdrm, GBM, EGL and OpenGL ES — what raylib's
DRM backend draws with — and none of X11's. The
installer decides the way rmp does, and on a console it looks for those instead
of the X11 headers and lists what is missing with the command for this system:
| System | Packages |
|---|---|
apt | libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev |
dnf | libdrm-devel mesa-libgbm-devel mesa-libEGL-devel mesa-libGLES-devel |
pacman | libdrm mesa libglvnd |
zypper | libdrm-devel libgbm-devel Mesa-libEGL-devel Mesa-libGLESv2-devel |
apk (Alpine) | libdrm-dev mesa-dev linux-headers |
sudo apt install libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-devIt says what it decided, too: This is a Linux console with no desktop: rmp builds games for DRM/KMS here, and how to build for a desktop instead. As everywhere, it prints the command and never runs it.
A
DRM/KMS game opens the screen through /dev/dri/card*, which it has to be able to read
and write and be the DRM master of: the kernel makes the first program that opens a card
nobody else draws on its master. It reads the keyboard, the mouse and the gamepads from
/dev/input/event*. Those belong to root and to a group, video and
input, and logind lets the person at the console open the card but not read the
keyboard. A game that cannot reach them finds out after the screen has gone black, so
rmp run asks first, between the build and the start:
/dev/dri/by-path/platform-gpu-card, then card1, card0 and
card2 — card1 before card0 because on a Raspberry Pi
card0 is the 3D engine and card1 the display. It takes the first of them
it can open that has a display — that answers drmModeGetResources(), as raylib asks —
and says which one the game draws on. With none of them, rmp run refuses: no display driver with modesetting has loaded, as
in a virtual machine without a display device or a container started without
--device /dev/dri; and with cards that answer no display — a GPU with no display
engine, or a driver loaded with nomodeset — it says so, and sudo does not
help.rmp run refuses:
FAIL: something else draws on the screen: it is the DRM master of …, and a game can only take
a screen nobody holds. Log out of that desktop or stop it. sudo is not offered, because
root cannot take a screen from its master either.rmp run refuses with
the game could not reach the screen and the keyboard from here (DRM/KMS):, lists each
one with its owner and mode the way ls -l shows them, and gives the two ways out
below.The
smoke stage of rmp test boots the game on the console's screen, and asks the same
before it does.
Start
the game as root this once, or put yourself in the video and input
groups for good. A group you are added to counts from your next login, so log out and in again,
and from then on rmp run starts the game as you, without root:
rmp run sudo # this once: the game as root, the build as you
sudo usermod -aG video,input "$USER" # for good, then log out and in againrmp
run sudo builds as you, says the exact command, and starts only the game with
sudo --: nothing rmp writes is ever root's. It asks the same questions
first, but the last: a card that is not there, or one that something else holds, is refused
before sudo asks for a password, because sudo fixes neither — what only root may open is what sudo
is for.
On
a desktop it is refused before anything is built: a window needs no root. When rmp is
root already it starts the game as it is, and on a machine with no sudo it refuses
and prints the game's path, to start as root some other way. rmp never runs sudo
unless you typed it.
rmp
never builds as root. Under sudo — root, with SUDO_USER naming somebody else — every
command but rmp help and rmp clean is refused before anything runs —
FAIL: rmp is running as root through sudo, and would build as root: … — because
build/, the files generated from the .toml, the sources and
.git would be root's, and the next command you ran as yourself could not write them.
sudo rmp clean is how what an earlier root left goes away. Root with nobody behind it
— a container, CI — has no other user to be, and builds.
A
game started with sudo is root, and saves as root. With sudo's defaults its home is root's, so
rmp::save writes to
/root/.local/share/<name>/ and not to your folder; a sudoers that keeps your
HOME gives your own folder, written as root, and
[save] portable = true writes root's files next to the game. rmp run
sudo says so before it starts the game.
The
game says it as well, once, as it starts — WARNING: CONSOLE: started with sudo by … —
with your name, the folder it really saves in, read from the environment sudo left it, and the
groups. In the video and input groups the game runs as you and saves where
it always does.
raylib's
DRM backend reads the keyboard from the terminal the game starts on, and changes it: no echo, no
line editing, no Ctrl+C, the terminal made non-blocking — a setting your shell shares — and a
virtual console's keyboard put in another mode. It puts them back only from an atexit
handler, which
a crash, abort(), a sanitizer's report and a kill never run, and the shell after
them would type blind, with no Ctrl+C.
So the framework puts it back however the game ends. Before the window opens it remembers the terminal, and puts it back on every fatal signal — then hands the signal on to whoever had it, so a crash is still a crash: a core dump, AddressSanitizer's report, the status your shell sees — on the sanitizers' way out, and at exit. Its handler runs on a stack set apart for signals — AddressSanitizer's, or one of its own where nothing set one up — because a stack overflow leaves none to run on.
SIGKILL
is the one ending nothing inside a process can catch, so rmp run also saves the
terminal before the game and restores it after, and says when it had to: the game left the
terminal changed -- … -- and rmp put it back. The screen needs none of this: the kernel
gives the console its screen back when the game's last handle on the card closes, however the
process ended.
The
framework's tests make a small program die each of those ways on a pseudo-terminal — an exit, a
segmentation fault, abort(), SIGTERM, a trap, a division by zero, a stack overflow,
an AddressSanitizer report — with the guard, and the terminal has to come back each time, with
the program still ending the way it would have. Without the guard, a crash, abort(),
SIGTERM, a stack overflow and the sanitizer's report have to leave it changed, or the test would
prove nothing. SIGKILL leaves it changed with the guard too, which is why rmp run
mends it from outside.
Ctrl+C does nothing while the game runs: the terminal's signals are off. The game quits from its own menu, and Escape is the game's key, not a way out — see the Escape key.
Ctrl+Alt+F1, F2 and the others still switch to another virtual console, but the screen may go on showing the game: the kernel does not take a screen from its DRM master. To end a game that is stuck, log in on another console — without seeing what you type, if it comes to that — or over SSH, and end it from there.
| What you see | What it means |
|---|---|
rmp run says something else draws on the screen | A desktop, or another program on the card, holds it. Log out of the desktop or stop the program; sudo does not help. |
rmp run says no card raylib tries has a display | A GPU with no display engine, or a driver loaded with nomodeset. sudo does not help: give the machine a display driver with modesetting. |
rmp run says there is no card | No display driver with modesetting has loaded. In a container, pass the card in with --device /dev/dri. |
rmp run lists nodes under /dev/dri or /dev/input | You cannot open them. rmp run sudo this once, or the video and input groups and a new login. |
| Added to the groups, and still refused | Groups are read at login: log out and in again. |
| The game reads the keyboard, and no mouse or gamepad | There is no /dev/input/event*; the game reads the terminal's keys. |
| Over SSH, it built a game that opens a window | SSH counts as the desktop. RMP_DRM=1 rmp run builds for the machine's own screen. |
sudo rmp … is refused | Run rmp as yourself; rmp run sudo gives root to the game alone. |
| The screen stays black, and raylib's log says it failed to initialize the EGL device | Mesa could not draw on that card. CI's virtual display has no GPU behind it, and Mesa draws there only in software, with LIBGL_ALWAYS_SOFTWARE=1 in the environment; a display with no GPU Mesa can drive needs the same. |
The
job that boots linux-x64-glibc-drm on a virtual display — vkms, a DRM device the kernel
provides with no hardware behind it — also runs rmp the way a console does: in the
build image, with the card passed in, no display, XDG_SESSION_TYPE=tty and
./rmp run. It
has to decide DRM/KMS by itself, build build/debug-drm without touching
build/debug, link libdrm and no X11 or Wayland, check /dev before it
starts the game, and boot it, draw and exit cleanly with no sanitizer report. It runs in a
game's CI too, when the game ships linux-x64-glibc-drm; only the framework's build is
held to having been sanitized there, because a game's [dev] sanitize is its own.
What
it cannot prove follows from where it runs: the container is root, so the groups and sudo are not
tried, and it is given no /dev/input, so no real keyboard either.
https://omardev29.github.io/rmp-docs/manual/platforms/web.html
The web target is the same game compiled to WebAssembly with
Emscripten, and it plays in a browser tab. Almost everything about it is the same as anywhere else.
The one thing that is not shapes the rest: in a browser, the browser owns the frame loop.
rmp web
python3 -m http.server 8000 --directory build/weband open http://localhost:8000/my_game.html. rmp web needs the
Emscripten SDK activated in the shell first — emsdk_env.sh, or
emsdk_env.ps1 on Windows — and says so when it is not:
the web build needs the emsdk: activate it first (source emsdk_env.sh, or emsdk_env.ps1 on
Windows), so that EMSDK is set. Underneath it is cmake --preset web, a release
build optimised for size; CI builds with the Emscripten pinned in its build image.
The build is four files that belong together: my_game.html, the page;
my_game.js, the loader; my_game.wasm, the game; and
my_game.data, the contents of resources/. The page fetches the other three,
so it has to be served — rmp web ends by saying serve it, do not open the file
directly — and any static web server will do.
A desktop game is a while loop: draw a frame, ask whether the window was closed, go
round again. A browser tab cannot run that. JavaScript is single-threaded and cooperative, and a
function that never returns never gives the page back — nothing is drawn, nothing is heard, and the
tab freezes. So on the web the framework's entry point hands the loop to the browser with
emscripten_set_main_loop(), and the browser calls the game once per frame, in step with
the display. main() never returns, which is the same contract the desktop loop has.
The only way to keep a while loop in a browser is to build with
-s ASYNCIFY, which rewrites the whole program so its stack can be put aside and picked
up again. Its cost is not charged to the loop: it is charged to every function that could be on the
stack, in size and in speed, whether or not anything ever waits. The framework measured it at 26 %
more .wasm and 18 % more download, and builds without it.
Four rules come out of that, and the framework already follows each of them for you:
while loop that draws. A loading screen that loops until the
work is done freezes the tab. Do the work a slice per frame in _update().WindowShouldClose(). On the web raylib's version waits with
emscripten_sleep(), which needs ASYNCIFY; the framework never calls it there.SetTargetFPS(). The browser paces the frame, and a cap would be a
wait inside its callback. [window] fps and [window] vsync change nothing on
the web.rmp::app::quit() works: the frame that asked
finishes, the browser stops calling the game, and the same shutdown as on a desktop runs. The page
itself stays open: a browser tab is the player's to close.
Emscripten compiles the game whatever [web] backend says; the choice is what raylib
talks to in the browser.
[web] backend | raylib talks to |
|---|---|
"glfw" | GLFW, which Emscripten emulates in JavaScript. The default, and the path raylib has shipped on the web for years. Defines PLATFORM_WEB. |
"emscripten" | The browser, through Emscripten's own API, with no GLFW layer to download. Defines PLATFORM_WEB_EMSCRIPTEN. raylib's code for it still marks its key-code mapping and file dropping as unfinished, which is why it is not the default. |
A third, RGFW, is refused, because its web backend waits with emscripten_sleep(): it
would build, and then die in the tab.
[web]
backend = "rgfw" raylib_multiplatform.toml:2: backend = "rgfw"
^^^^^^^^^^^^^^^^
configure: error: [web] backend = 'rgfw' cannot work here.
RGFW's web backend calls emscripten_sleep, which needs -sASYNCIFY. This framework deliberately has no ASYNCIFY: it hands the frame loop to emscripten_set_main_loop instead, and the measurement behind that decision is +26 % .wasm and +18 % download. Turning it on for one backend would put that cost on the build.
It BUILDS without it and then dies in the browser with "Please compile your program with async support" — which is how this was found: the boot test in .github/workflows/web-backends.yml opened it in Chromium.
Use one of emscripten, glfw.Since the two backends define different PLATFORM_* macros, code that has to know it
is on the web tests __EMSCRIPTEN__, which both define.
raylib draws with OpenGL ES 2.0 on the web, which the browser provides as WebGL, with either backend. That is a smaller OpenGL than a desktop's 3.3: shaders are written in GLSL 100, and rlgl and OpenGL has what else differs.
A WebAssembly module gets its memory up front. [web] memory is how much, in
megabytes, between 16 and 4096; the default, 64, is enough for menus and a handful of textures. A
game that loads a tile atlas and a few tracks wants more, and when it runs out the tab dies with
Emscripten's "Cannot enlarge memory arrays" rather than an error of raylib's.
[web]
memory = 256[web] grow = true lets the memory grow past that instead of stopping the game, and
costs a little speed on every access to it, since each one goes through a bounds check that cannot
be lifted out of a loop. A game that knows its ceiling is better served by raising
memory.
The web build CI makes has no asset pack. The whole of resources/ is preloaded into
Emscripten's in-memory file system — that is the .data file — and the game reads it
there with the same paths and the same rmp::assets calls as anywhere else. It also means
the assets of a web build are ordinary files to anyone who opens the .data: the pack's
encryption applies only to the targets that ship the pack.
Emscripten's files live in memory, so a save written there would be gone at the next reload. The
framework mounts a folder backed by the browser's IndexedDB, /rmp_save/<name>/,
and rmp::save uses it: every write is pushed to IndexedDB,
and before the game starts the folder is filled from it — the game's main() is held back
until that has finished, so the first scene's _ready() finds the save the player left.
The folder is named after [project] name, so games served from the same site do not share
their saves.
A browser that refuses storage — a private window, site data switched off — does not stop the game. The failure is logged on the browser's console and the saves last as long as the page does.
Browsers keep a page's sound suspended until the player does something. raylib's audio backend resumes it on a click or a touch, and the framework adds a key press to those, so a game played from the keyboard is heard from its first key. A gamepad cannot do it: browsers do not count its buttons as the kind of gesture that may start sound, and a game that only ever sees a gamepad stays silent until the first click, touch or key.
Any
static web server that serves the four files from one folder will run the game; the page is
<name>.html. CI's web archive is those four files and a LICENSES.txt
of the web's own, which credits what a web build contains and none of the desktop windowing
libraries a .wasm does not carry.
itch.io wants the page called index.html, and the framework's itch.io job uploads the
build that way, so it plays in the page rather than as a download. More on hosting, size and the
archive in The web build.
The web target is in the fast lane, on every push. CI builds it, checks the four files are there
and not empty, and then plays it: the page is served from a local web server and opened in
headless Chromium; the game must report that it booted with every asset loaded
(assets_failed=0), after writing a save to IndexedDB, reading it back and removing it;
and after the game has had time to draw, the canvas is photographed and
measured for drawn pixels. When the render check fails, the picture of the canvas is kept with the
run.
https://omardev29.github.io/rmp-docs/manual/platforms/android.html
On Android the game is a native library inside an app. The app around it is
raymob, a small implementation of raylib for Android — a Java activity and a C library of Android
extras, vendored with the framework and patched where marked — and the Gradle build that makes it is
driven by
raylib_multiplatform.toml like every other build. The game's code does not change:
raylib's Android glue starts it through the same main() a desktop uses.
rmp android
adb install -r <the APK rmp android printed>rmp android regenerates the configuration and runs Gradle's debug build, and prints
the APK it wrote. It needs the Android SDK and NDK; the versions CI builds with are pinned in
thirdparty/FROZEN_VERSIONS.md — compile and target SDK 36, NDK r28, the CMake package of
the SDK — and Gradle needs JDK 17 to run.
Gradle never runs CMake early enough to generate anything, so the build reads two files
configure.py writes from the .toml: raymob/generated.properties,
with the game's name, ids, version and switches, and
raymob/app/generated/AndroidManifest.xml, the manifest with exactly the permissions and
features the .toml asks for. Neither is committed, so neither can drift from the
.toml. Building from Android Studio or with ./gradlew yourself, run
python3 tools/configure.py first; Gradle says so when the first file is missing.
The game is compiled into one shared library named after [project] name, with its
own copy of raylib built for Android — [raylib] disabled_modules applies to it as it does
on a desktop. A release build is optimised and has RMP_PRODUCTION_BUILD at 1; a debug build has it at
0.
[android]
application_id = "com.yourname.yourgame"This is the app's identity on the device and on Google Play, and on Google Play it is permanent:
once an app is published under an id, the id can never change, and a new one is a new listing
without its installs and reviews. rmp new fills it with a com.example.
placeholder; a release is refused while it still says so, by rmp deploy before it tags
and by CI when a tag arrives.
The id needs at least one dot, every part starts with a letter, and it takes letters, digits,
_ and . and nothing else. A hyphen, which an iOS bundle id may contain, is
refused with the id written the way Android takes it:
[android]
application_id = "com.my-game.app" raylib_multiplatform.toml:2: application_id = "com.my-game.app"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android] application_id = 'com.my-game.app' is not a valid Android application id.
It contains '-': an Android id takes letters, digits, '_' and '.', and nothing else.
A '-' is fine in an iOS bundle id and refused here: write 'com.my_game.app'.
It needs at least one dot and each segment must start with a letter, e.g. com.yourname.yourgame.It also must not contain the string the build rewrites in raymob's sources on the way through, which is refused with the reason:
[android]
application_id = "com.raylib.raymob.mygame" raylib_multiplatform.toml:2: application_id = "com.raylib.raymob.mygame"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android] application_id = 'com.raylib.raymob.mygame' must not contain 'com.raylib.raymob'.
Gradle rewrites and then reverts that exact string in the raymob sources; an id containing it corrupts them.The version name and the version code come from the git tag, not from the .toml:
v1.2.3 is version name 1.2.3 and version code 1002003. See
Releases.
| Key | Becomes |
|---|---|
[window] title | The app's name under its icon. |
[window] orientation | The activity's screen orientation: "landscape", "portrait" or "unspecified". The same key sets iOS. |
[android] min_sdk | The oldest Android the app installs on, as an API level from 21 to 36; 24, the default, is Android 7.0. The target SDK is fixed at 36, which Google Play requires. |
[android] category | android:appCategory, how the Play Store files the app: "game" by default. It is not what puts the icon in the launcher; that part is fixed. |
[android] gl_version | The OpenGL ES version raylib and the game are compiled for, and the one a device must have to be offered the app. See below. |
[android.display] keep_on | The screen never sleeps while the game runs. |
[android.display] immersive | The system bars are hidden. |
[android.display] into_cutout | The game draws behind the notch. raylib reports no safe area, so rmp::ui does not know where the notch is: on Android and iOS it pads every interface by a fixed 24 design units, whether this is on or off. |
[android.permissions] internet, vibration | The permissions the app asks for. Each one is shown on the Play listing, so ask for nothing you do not use. vibration is what raymob's Vibrate needs. |
[android.features] gyroscope, accelerometer | true hides the app from devices without the sensor; false declares it optional. |
[icon] source, adaptive_background | Every launcher icon density, the round icon and the adaptive icon's foreground, made from one picture. That needs Pillow on the machine that configures. |
All of the switches are true or false and nothing else; the string
"false" is refused rather than read as yes. A permission is an element of the manifest,
present or absent, which is why the manifest is generated rather than filled in.
[android]
min_sdk = 26
[android.display]
into_cutout = false
[android.permissions]
vibration = truegl_version: what the game draws with#
[android] gl_version is "ES20", the default, or "ES30", and it
decides three things together, so that what the game draws with and what the Play Store asks of a
device cannot disagree. raylib and the game are compiled for that version —
GRAPHICS_API_OPENGL_ES2 or GRAPHICS_API_OPENGL_ES3. With
"ES30" the game links OpenGL ES 3.0's library, and raylib asks EGL for a version-3
context: the framework's copy of raylib is patched to ask for the version it was compiled for. And
the manifest's <uses-feature android:glEsVersion> requires the same version, so a
device without it is not offered the app.
"ES20" reaches every device. "ES30" is for a game that needs what
raylib's OpenGL ES 3.0 path adds — its shaders are GLSL 300 es, as
rlgl and OpenGL explains. There is no
"ES31" or "ES32": raylib has no 3.1 or 3.2 path, and asking for one would
only hide the game from more devices:
[android]
gl_version = "ES31" raylib_multiplatform.toml:2: gl_version = "ES31"
^^^^^^^^^^^^^^^^^^^
configure: error: [android] gl_version = 'ES31' would compile raylib for ES 3.0 all the same -- it has no 3.1 or 3.2 path -- and only hide the game from devices without 3.1.
Use "ES30" for ES 3.0, or "ES20" to reach every device.Gradle copies resources/ into the APK's assets before it builds, and raylib's file
functions read them there. The asset pack is left out: the pack is opened as a plain file, and inside
an APK there is no such file, so Android always reads the loose copies — the files are in the APK
unencrypted, and [resources] rres_password protects nothing on this target.
Saves go to the app's private internal storage, in a saves/ folder: no permission is
needed, no other app can see them, and they are removed with the app.
<raymob.h> adds what raylib does not have on a phone: vibration, the on-screen
keyboard, the accelerometer and the gyroscope, the screen's orientation, keeping the screen on, the
app's storage folder. It declares those functions on Android only, so calls to it are guarded:
#include <raylib.h>
#ifdef __ANDROID__
#include <raymob.h>
#endif
void on_hit() {
#ifdef __ANDROID__
VibrateMS(40); // needs [android.permissions] vibration = true
#endif
}examples/platform/02_mobile_raymob uses vibration, the on-screen keyboard, the
accelerometer, the screen's orientation and keeping the screen on; see
its page.
[android.admob] enabled decides whether AdMob is in the build at all, and it is off
until a game turns it on: false is the default, and what rmp new writes into a new game's
.toml. Off, there is no Google Mobile Ads library, no advertising-ID permission and
nothing to declare about advertising in Play's Data safety form, and the
rmp::ads calls still compile and do nothing. On, the app
carries the SDK and starts it at launch, asks for the advertising-ID permission, and has the
internet permission forced on with it. It switches itself off when Android is not a target,
whatever it says.
[android.admob]
enabled = trueThe
three ids, app_id, interstitial_id and rewarded_id, start
as Google's test ids; replace them with your own from the AdMob console before publishing. Your own ids
reach the release build only. The debug build — what rmp android makes and what Firebase
Test Lab's Robo crawler taps through — overrides all three with Google's test ids whatever the
.toml says, because a tap on a real ad from your own build is invalid traffic, and
invalid traffic is how AdMob accounts get suspended.
The ids are
strings, always, and while AdMob is on each must have the shape AdMob gives it — the app id
ca-app-pub-, 16 digits, ~, 10 digits; an ad unit id the same with a
/ — because the Google Mobile Ads SDK stops an app at startup over an app id it cannot
read. An empty or malformed id is refused at its line, and one pasted where the other kind goes is
named for what it is:
[android.admob]
enabled = true
app_id = "ca-app-pub-3940256099942544/1033173712" raylib_multiplatform.toml:3: app_id = "ca-app-pub-3940256099942544/1033173712"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android.admob] app_id = 'ca-app-pub-3940256099942544/1033173712' is not an AdMob app id.
An AdMob app id looks like ca-app-pub-<16 digits>~<10 digits> -- this one has a '/', which makes it an ad unit id.
Copy it from the AdMob console, or set [android.admob] enabled = false.The framework does not ship a consent form. Serving ads to players in the EEA or the UK requires one certified by Google, and adding it is yours before publishing with ads on.
rmp::app::quit() ends the frame loop and, on
Android, also tells the system the activity is finished, with ANativeActivity_finish. A
process that simply stopped would leave its task in the recent-apps list, pointing at nothing.
Google Play takes an Android App Bundle (an AAB) signed with your upload key. The key, and every
password for it, are secrets, and none of them ever goes in raylib_multiplatform.toml —
the .toml is committed, and there is no key in it for them. Create the upload keystore
once and keep it somewhere you will not lose it:
keytool -genkey -v -keystore upload.jks -keyalg RSA -keysize 2048 -validity 10000 -alias uploadCI reads it from four repository secrets on GitHub:
| Secret | Value |
|---|---|
ANDROID_KEYSTORE_BASE64 | The keystore file, base64-encoded: base64 -w0 upload.jks. |
ANDROID_KEYSTORE_PASSWORD | The keystore's password. |
ANDROID_KEY_ALIAS | The key's alias: upload above. |
ANDROID_KEY_PASSWORD | The key's password. |
With them, the release bundle is signed with your key, its signature is verified, and it is
attached to the release. Set the repository variable ANDROID_SIGNER_CN to the
name your key was made with, and CI also checks the bundle is signed by that key and not merely by
some key. Without the secrets, CI still builds and signs the bundle on every run — with a throwaway
key made for that run — and names it …-NOT-FOR-PLAY.aab; that file is never attached to
a release.
On your own machine the release bundle is Gradle's bundleRelease, run in
raymob/ after python3 tools/configure.py:
python3 tools/configure.py
cd raymob
./gradlew bundleReleaseGradle signs it when four environment variables say where the key is:
ANDROID_KEYSTORE_FILE, the path to the keystore, and the same three passwords and alias
as above. Without them the bundle comes out unsigned, which is fine for looking at and not accepted
by Google Play.
raymob's sources carry its own package name, and the build rewrites them to your application id
on the way in and puts them back when it finishes. A build that is killed half way — a cancelled
job, a closed terminal, a machine out of memory — leaves them rewritten, and the next build then
"restores" the wrong thing. CI fails loudly when that happens; on your machine, look for changes in
thirdparty/raymob/ and raymob/app/ after an interrupted build, and put the
files back with git before building again.
Android is in the fast lane. On every push CI builds the debug APK and checks it holds a manifest and the native library; builds the release AAB, signs it and verifies the signature; holds each ABI's native library to its line of the size budget, once the game has one; checks from the compiler's own records that the release was compiled as a release; and checks that Gradle put back every source it rewrote. It does not run the game: an Android emulator on a CI runner is slow and fails for reasons that have nothing to do with the game. A release can also send the debug APK to Firebase Test Lab, to be started on one of its devices — by default MediumPhone.arm, an Arm virtual device — and crawled by its Robo test, which taps whatever is on the screen — the debug APK and never the release, because the debug build shows only Google's test ads. See Publishing.
CI's
Android job downloads nothing. Gradle, the Android build plugin and every library the app builds
with — the AdMob SDK too, for a game that turns ads on — come from a Gradle home warmed for them in
the build image, and
Gradle runs with --offline, so a library the image lacks fails the build at once, by
name. Before that, a step checks that the Gradle the wrapper asks for is in the image, because
--offline does not reach the wrapper. A game that adds a Gradle dependency of its own
turns it off:
[android]
gradle_offline = falseThen Gradle downloads what the image lacks, and the job says so in a warning. rmp
android is never offline: on your machine Gradle downloads what it needs, as it always
does.
https://omardev29.github.io/rmp-docs/manual/platforms/ios.html
iOS is the target that differs most from the others, in three ways. It is built by
Xcode rather than CMake, from a project generated out of raylib_multiplatform.toml.
Upstream raylib has no iOS backend, so raylib comes prebuilt from a fork. And the app does not own
its frame loop or its own ending: UIKit does, and Apple rejects an app that quits.
Building for iOS needs a Mac with Xcode, and XcodeGen to turn the generated description into an Xcode project. The steps, from the game's folder:
git submodule update --init thirdparty/raylib-ios # the raylib-iOS fork; a clone leaves it empty
python3 tools/configure.py # writes ios/project.yml from the .toml
(cd thirdparty/raylib-ios/projects/scripts && bash build-ios-xcframework.sh) # device + simulator
cd ios
xcodegen generate # ios/my_game.xcodeproj
open my_game.xcodeprojraylib.xcframework is built once, and again only when the submodule moves. Run
configure.py with the submodule in place: it is what writes the iOS licence notice,
which credits the fork.
A simulator build needs no signing at all, and is what CI builds:
xcodebuild -project my_game.xcodeproj -scheme my_game \
-destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO buildthirdparty/raylib-ios is a git submodule, which rmp new leaves empty
until you ask for it — it is only needed to build for iOS. It points at
omardev29/raylib-iOS, a fork of the community project ghera/raylib-iOS,
pinned at one commit. The fork exists for availability only: a submodule that points at somebody
else's repository fails for ever the day that repository goes away.
The fork is what gives raylib an iOS backend: UIKit for the app, and OpenGL ES 3.0 through ANGLE,
which runs it on Metal. Its script builds raylib into raylib.xcframework, with a device
slice and the simulator's, and the app embeds ANGLE's two frameworks next to it. Because
raylib comes prebuilt, [raylib] disabled_modules cannot reach it, and
configure.py says so when both are set:
[raylib] disabled_modules has no effect on iOS: it links the prebuilt raylib.xcframework from
the pinned fork, which is built without these flags.
configure.py writes ios/project.yml, XcodeGen's description of the
project, and nothing in it is meant to be edited by hand: it is regenerated on every configure, and
not committed. What goes into it:
| From | Becomes |
|---|---|
[ios] bundle_id | The bundle identifier: the app's identity on the App Store. |
[ios] deployment_target | The oldest iOS the app runs on. 13.0 at the least; 15.6 by default. |
[project] name | The product, the scheme and the Xcode project's name. |
[window] title | The name under the app's icon. |
[window] orientation | The supported orientations: both landscapes, portrait, or all three for "unspecified". The same key sets Android. |
[icon] source | The app icon. |
[ios.settings] | Raw Xcode build settings, copied in as they are — except an OTHER_CPLUSPLUSFLAGS of yours, which is added after the framework's own flags in that setting rather than replacing them. |
| the git tag | The marketing version. |
The
rest is fixed: the game's src/ and include/ as sources; the whole of
resources/ copied into the app as a folder; the licence notices; a launch screen Xcode
generates, without which iOS would run the game letterboxed at a legacy resolution; full screen with
the status bar hidden; RMP_PRODUCTION_BUILD at 0 in the Debug configuration and 1 in Release; and
C++20, with -Werror=reorder-init-list, the flag the CMake and Android builds give
Clang: a designated initialiser out of declaration order is a compile error in Xcode too, as it is
with GCC and MSVC, and not a warning that passes on one machine and fails on another.
The deployment target has a floor because of rmp::save:
it uses std::filesystem, which Apple's C++ library only has from iOS 13. Below that the
configuration is refused, rather than failing in the compiler later:
[ios]
deployment_target = "12.4" raylib_multiplatform.toml:2: deployment_target = "12.4"
^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [ios] deployment_target = '12.4' is below 13.0.
rmp::save uses std::filesystem, which Apple's C++ library only has from iOS 13. Use 13.0 or later; the default, 15.6, covers every iPhone Apple still updates.A bundle id may contain hyphens, which an Android application id may not, and like the Android
id, a com.example. placeholder is refused for a release.
On every other target the game has a main(). On iOS it does not: UIKit owns the run
loop, and raylib's iOS backend calls three functions instead — one when the app is ready, one per
frame, one when it is destroyed. RMP_GAME writes those three
on iOS — it expands to RMP_IOS_FUNCS there — and
nothing in the game changes.
The process does not start inside the app's bundle, where resources/ is, so before
anything loads the framework moves into it. The bundle is read-only; saves go to the app's
Library/Application Support/ instead — not to Documents/, which the Files
app shows and Apple's storage guidelines keep for what the user made.
The frame is paced by the display: [window] fps is ignored, and the framework never
calls SetTargetFPS() there.
Apple is explicit about it, in its Q&A 1561: an app that ends itself "will appear to the user to have crashed", and App Review rejects apps that crash or look as if they did. A control whose job is to quit fails the Human Interface Guidelines on its own.
So rmp::app::quit() does nothing on iOS. It says
once, APP: quit() does nothing on iOS — Apple rejects apps that terminate themselves
(QA1561). Ignoring., and returns. The same source keeps its Quit button and ships everywhere;
on an iPhone the button is simply inert. To leave it off the screen there instead:
rmp::ui::begin();
if (rmp::ui::button("Play")) rmp::Scene::pop();
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
rmp::ui::end();That message is a framework warning like the others, so with [dev] strict = true it
stops a debug build where the button was pressed — a reminder to hide the button. For the same
reason the framework refuses to pop the last scene off the stack: on iOS there would be no way
back.
Nothing built in CI can be installed on an iPhone. Apple requires a signed app, and signing needs a paid Apple Developer account, a certificate and a provisioning profile — none of which belongs in a public repository or in CI. What CI builds is a simulator app, with signing switched off.
For a device, open the generated project on a Mac. Put your team in the .toml
rather than clicking it into Xcode, so it survives the next regeneration — a team id is an
identifier, not a secret:
[ios.settings]
DEVELOPMENT_TEAM = "ABCDE12345"
CODE_SIGN_STYLE = "Automatic"Then choose the device in Xcode and run. TestFlight and the App Store go through an archive made in Xcode; that path is not automated, because it needs credentials that should not live in CI.
The simulator app CI builds is attached to a release as ios-app-simulator.zip, next
to ios-raylib-xcframework.zip, the raylib it was built with, and runs on a Mac's
simulator:
unzip ios-app-simulator.zip
xcrun simctl boot "iPhone 16"
open -a Simulator
xcrun simctl install booted my_game.app
xcrun simctl launch --console booted com.yourname.yourgameiOS is in the full lane: on a release, or when the full lane is asked for. On a pinned macOS
runner and a pinned Xcode, CI builds the xcframework from the fork, generates the project, builds the
simulator app, unsigned, and checks the bundle: that its executable is a Mach-O, that it has an
Info.plist with a bundle identifier, and that resources/ is inside it. Starting the app in the simulator is a
step of its own, run only when the repository variable IOS_SIMULATOR_TEST is
true: the simulator on the hosted runners does not boot reliably, and a gate that fails
for the runner's reasons would teach everyone to ignore it.
[upx] refuses ios by name, at its line, when the configuration is
checked: the app is signed, and compressing it would break the signature.
https://omardev29.github.io/rmp-docs/manual/help/index.html
The framework tries to fail early and say why: a configuration it cannot build is refused before anything compiles, with the line and the reason, and a mistake it can see in a running game is said once, in the log, in words that name the fix. These pages collect what those messages mean and the questions that come up around them.
Two commands answer most questions on your own machine. rmp test checks the
.toml, the pinned versions and the licences, draws a frame with the software renderer,
and boots the game to see it draw. rmp help lists every command, and
rmp help test explains one with examples.
https://omardev29.github.io/rmp-docs/manual/help/troubleshooting.html
Each entry here is a problem that really happens, with what the framework prints
when it does. A message set like rmp: not inside a project is the framework's own
words, checked against its source; a line of the log
that starts with INFO: or WARNING: is raylib's log, which the framework
writes into too.
Most of the framework's warnings about a game are said once, however many frames they happen in.
With [dev] strict = true the first one stops a debug build instead, in the debugger, at
the line that caused it, saying [dev] strict = true: the diagnostic above is fatal in a debug
build. Fix it, or set strict = false in raylib_multiplatform.toml. A release build never
stops for one.
rmp and the configuration need Python 3.11 or newer, because they read the
.toml with the library that version added. The launchers ask every Python they find for
its version, rather than taking the first one, because the obvious one is often wrong: the
python3 macOS ships is older than 3.11, and on Windows python3 can be the
Microsoft Store's placeholder. A Python older than 3.11 is passed over like a missing one, and when
none will do, the launcher says rmp: needs Python 3.11 or newer on PATH …. Only
tools/rmp.py started directly with an older Python gets as far as saying
rmp needs Python 3.11 or newer; this is …, with its version and its path.
CMake
needs it too: cmake --preset debug runs tools/configure.py before anything
else, and stops when it can find no Python 3.11 and nothing has been generated yet. When the files
were generated before, it warns and builds with them — but then edits to the .toml are
not picked up until a Python is there again.
rmp says which one: FAIL: cmake is not installed, or not on PATH. A
game needs CMake, Ninja and a C++ compiler; on a Linux desktop, the X11 development libraries as
well, and on a Linux console with no desktop the DRM/KMS ones in their place —
Linux from a console names them.
rmp does nothing outside a game#rmp: not inside a project means there is no raylib_multiplatform.toml
in the folder or above it. rmp works from anywhere inside a game; rmp new
my_game makes one.
tools/configure.py reads the .toml before anything is compiled, and
refuses a value it cannot build — or a pair of values it cannot honour together — with the file, the
line, and what to write instead. This one asks for a frame rate the clamp on the frame time would
turn into slow motion:
[window]
fps = 15 raylib_multiplatform.toml:2: fps = 15
^^^^^^^^
configure: error: [window] fps = 15 makes every frame 0.06667 s long, but [app]
max_delta = 0.05 hands the game at most that much per frame, so the
game would run at 75% speed forever. Raise fps to 20 or
more, raise max_delta to 0.06667 or more, or set max_delta = 0.The message is the fix. rmp test config, or python3 tools/configure.py
--check, checks the file without building anything. A key the framework does not know is
refused as well, so a misspelt key cannot be silently ignored, and so is a value of the wrong type —
a list where a string goes, the commonest being a stray pair of brackets — or an empty one where the
key needs something, each at its line:
[window]
orientation = ["landscape"] raylib_multiplatform.toml:2: orientation = ["landscape"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [window] orientation = ['landscape'] has to be a string, one of landscape, portrait, unspecified.
A TOML array or table here is almost always a stray pair of brackets.A tag builds a release, and a release under a placeholder identity is refused:
refusing to build a release with placeholder identifiers, naming the Android
application id or the iOS bundle id that still says com.example.. A Google Play id can
never change once published, so it is checked before the first release rather than after it. Set
real ids in the .toml. A tag that is not a version — v1.2.3 in ASCII
digits, no number with a leading zero, optionally with a pre-release part — is refused as well, and
so is v0.0.0; see Releases.
A debug build goes to build/debug/ and a release to build/release/,
each with a CMake cache of its own, so the compiler [dev] compiler chose for debug
never reaches the release CI ships. build/ only holds those folders. A
CMakeCache.txt at its top is a build from a checkout older than that, and the first
rmp command that configures removes what it left there and says so:
build/ is a build from before debug and release had folders of their own, keeping the
folders of the builds beside it.
With
CMake used directly, configuring build/ itself stops before anything else runs:
build/ holds one folder per build and is not a build itself:, followed by the presets
and the folder each one builds in. rmp clean deletes it with the rest of
build/.
A release configured by hand
into a folder where [dev] compiler was applied — cmake --preset debug, then
the same build/debug again with -DPRODUCTION_BUILD=ON — stops too, saying
that a release build must not inherit that compiler. A release has a folder of its own:
cmake --preset release, or rmp build release.
With
[dev] sanitize listing one
and a compiler that cannot run it, a debug configure warns [dev] sanitize asks for …,
gives the reason the probe found, and builds without it. On Linux, clang's sanitizer runtimes are
compiler-rt — libclang-rt-<N>-dev on Debian and Ubuntu, compiler-rt
on Arch and Fedora; [dev] compiler = "gcc" is the other way, since most distributions
ship gcc's; and sanitize = [] stops the warning. With
RMP_REQUIRE_SANITIZERS=1 in the environment, as in CI's lint job, the
same configure fails instead.
In
a debug build with sanitizers, a read past a buffer, a use after free, a signed overflow and the
rest stop the game where they happen, and the report is the sanitizer's own, starting with
ERROR: AddressSanitizer:, ERROR: LeakSanitizer: or runtime
error:, followed by the stack that got there; the first frame in your own code is the line to
read. A leak is reported when the game exits, after everything else it printed. rmp test
smoke and rmp test render fail on any report, with its first forty lines:
a sanitizer reported the run above (exit …).
The
build gives each runtime its defaults — every report fatal, the stack printed — and the environment
still wins: ASAN_OPTIONS, UBSAN_OPTIONS and LSAN_OPTIONS
change any of them for one run.
A
program has exactly one entry point: RMP_GAME or RMP_ENTRY_POINT, once,
in one file. The symbol rmp_entry_point_is_declared_exactly_once exists so that the
link error points at the cause either way. Two entry points define it twice, and the linker names it
as a duplicate. A program with neither has no main(), and the linker names it as
undefined, next to main: the framework's own code asks for it, so the error says what
was forgotten instead of only that there is no main.
This does not compile, on purpose:
Texture2D picture = rmp::assets::load_texture("rabbit.png");The compiler refuses it, saying among other things: deleted
The rmp::Texture the loader returns is a temporary that would release the texture
at the end of the line, leaving picture pointing at a texture that had already been
unloaded. Keep the handle — rmp::Texture picture = … — and hand it to raylib where
raylib wants a Texture2D; it converts there.
RMP_PRODUCTION_BUILD is not defined: the build system has to pass it (0 or 1) comes
from src/rmp/app/app.cpp when it is compiled by a build that does not define that macro.
CMake, Gradle and the generated Xcode project all do; a build of your own has to as well.
rmp test render and CI's render checks build the game against raylib's software
renderer, which links no OpenGL library, so a direct glClear() in a game links on a
Linux desktop and fails there as an undefined symbol. See
rlgl and OpenGL.
A debug build reads resources/ by its absolute path. A desktop release reads
./resources/, and moves into the executable's folder first when that folder has a
resources/, so it finds the one shipped next to it wherever it is started from. Finding
no pack where it looks, it logs ASSETS: No resource pack found, using loose files from …,
and with no loose files there either, every texture comes back empty. The line before that one says
why it looked there:
resources/ beside the executable. Put it there, the way the archive does, or start
the game from a folder that has one: the release rmp build release leaves in
build/release/ reads the project folder's when it is started from the project folder.Every run logs a line beginning RAY_TEST_BOOT_OK with assets_failed=
and assets_requested=, and a checked run — rmp test smoke, and every boot
test in CI — does not pass with a failed asset:
FAIL: the game did not boot, or an asset failed to load. An asset failed when an
rmp::assets load found its name neither in the pack nor in resources/, or
found a file there that does not decode. Look for:
resources/:
"sprites/player.png", not "resources/sprites/player.png", and with
/ between folders on every system.rmp::audio::music() cannot
stream counts too, and says AUDIO: "…" is in resources/ but could not be streamed.[resources] rres_password, or
one cut short since; a pack whose directory itself is broken says
ASSETS: … is cut short or corrupt, using loose files once, at startup. rmp pack makes it again, or
rmp unpack goes back to loose files. A name the pack does not hold says the second line
too for a sound or a font, and ASSETS: '…' not found in pack, falling back to loose
file for a picture.Only
loads through rmp::assets are counted. rmp::audio loads through it once
it has found a file, so a sound or a song whose file is there and does not decode or stream counts
too. A name that matches no file at all does not: rmp::audio says so once, below, and
counts nothing — a missing sound does not fail the boot check. And on a machine with no sound
device rmp::audio loads nothing, so none of its files are counted there. A LoadTexture() of
your own that fails is not in the number, and leaves an empty texture all the same.
rmp::audio finds a sound by its name. A name that ends in an audio extension —
"coin.ogg" — is looked for as it is; a bare one — "coin" — as
coin.wav, coin.ogg, coin.mp3 and coin.qoa, in
that order. When there is nothing it says once AUDIO: no sound called "…" in resources/
(looked for …), naming the files it tried, and a file that is there and does not decode says
AUDIO: "…" is in resources/ but could not be decoded (raylib here reads .wav, .ogg, .mp3 and
.qoa). On a machine with no sound device it says
AUDIO: no sound device on this machine; sound is off and every rmp::audio call is a silent
no-op from here on, and the game runs on, silent. In a browser, sound waits for the player's
first click, touch or key — see Web.
rmp test smoke says FAIL: the game booted and drew nothing when the
frame it reads back is blank. Things that come to that:
[ui] max_elements, or draw less at once._draw() is in screen
pixels, and objects are drawn through the camera. On a window that is not the design size, world
coordinates drawn in _draw() without opening the camera land somewhere else — see
raylib in your game.[web] memory.An action read by a name nobody defined reads as false, and says so once: INPUT: no action called followed by the name and how to define it. An action that is defined can still be silent on purpose: a mouse action while the interface wants the pointer, a key action while the interface wants the keyboard, and every action in a scene whose input a scene above it has taken.
On purpose. raylib makes Escape the key that closes the window, and the framework takes it back
with SetExitKey(KEY_NULL) once the window is open, because in a game Escape is "back"
and "pause": rmp::ui goes back on it. The window's close button still quits. To quit on
Escape, call rmp::app::quit() when the game reads it —
see Escape is the game's key.
The binary was built against a newer glibc than the machine has. CI's builds honour
[linux] glibc, the oldest glibc the binary may need; rmp build release on
your own machine uses your machine's. See Desktop for
the floor, and for the targets it does not apply to.
On a console with no
desktop, rmp run builds for DRM/KMS and asks whether the game can open the screen and
read the keyboard before it starts it; when it cannot, it refuses and says why: no card, a card a
desktop holds, or devices you may not open — which rmp run sudo fixes this once, and
the video and input groups and a new login fix for good. sudo
rmp is refused on purpose: rmp never builds as root.
Linux from a console has
each case and what to do about it, a black screen and a keyboard with no mouse among them, and
how the terminal comes back after a
crash.
With [linux] wayland = true, GetWindowPosition() and
SetWindowPosition() do nothing, and GLFW warns the first time. That is Wayland's
design: a window does not know where it is.
An unsigned .exe compressed with UPX looks like malware to Windows Defender on some
machines. Windows is left out of [upx] by default for that reason; if you added it and
do not sign your builds, take it out again.
Opened as a file, the page cannot fetch the rest of the game — rmp web says
serve it, do not open the file directly. Serve the folder over HTTP. Without the
Emscripten SDK activated, rmp web stops at once with
the web build needs the emsdk: activate it first (source emsdk_env.sh, or emsdk_env.ps1 on
Windows), so that EMSDK is set.
The Android build rewrites raymob's package name in a few of its sources and puts it back at the
end. A build that was killed half way leaves them rewritten, and the next build restores the wrong
thing. After an interrupted Gradle build, check thirdparty/raymob/ and
raymob/app/ for changes and put them back with git. Gradle also stops at once when
raymob/generated.properties is missing; python3 tools/configure.py writes
it.
On purpose: APP: quit() does nothing on iOS — Apple rejects apps that terminate themselves (QA1561). Ignoring. See iOS for why, and for hiding the button there.
SAVE: [save] portable: this system does not say where the executable is; saving in the user's folder instead — raylib cannot tell where the executable is on those two, so there is no "next to the executable" to save in.
FAIL:
there is no remote to push to. Make the repository on GitHub, then: … — a game made with
rmp new is a git repository with no remote. Make an empty repository on GitHub, add it
with git remote add origin and its URL, and run rmp push again. The first
push of a branch sets its upstream on origin, so plain rmp push is all it
takes from then on. rmp deploy on a branch that was never pushed says the same thing
the other way round: push it first, with rmp push.
A push cancels the run already going on the same branch. rmp push refuses while one
is in flight and names it; rmp push force is for when cancelling it is what you
meant.
The BSD jobs install their build tools from each system's package mirrors, which publish no dated snapshots, so what they install is not pinned and changes without a commit of yours. Suspect the mirror first, and run the job again.
CI signed it with a throwaway key because the signing secrets are not set. See Android for the four secrets that make it a bundle Google Play accepts.
Starting it in the simulator runs only when the repository variable
IOS_SIMULATOR_TEST is true, because the simulator on the hosted runners does
not boot reliably.
https://omardev29.github.io/rmp-docs/manual/help/faq.html
Short answers, each with a link to where the long one is.
The framework's own README says that it is experimental and not meant for production. The pipeline is real — every target is built, and every target with a machine to run on is booted and checked for pixels — but the features themselves are young. Test your game on the platforms you ship it to.
All of it, from any scene, with nothing to unlock: the framework adds rmp:: beside
raylib and changes none of raylib's functions. A handful of calls are the framework's to make —
opening and closing the window, beginning and ending the frame — and
raylib in your game lists them and why.
No. RMP_GAME is built on a lower-level entry point,
RMP_ENTRY_POINT, which takes three functions of yours
and nothing else. The window and the frame are then yours to open and close, as in a plain raylib
program, while the framework still writes the right loop for each target, opens the asset pack,
samples the input rmp::input reads once a frame, clamps the frame time, keeps Escape
from closing the window and reports to CI. Many of the framework's examples are written this
way:
#include <rmp/app.h>
static void on_ready() { InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE); }
static void on_frame(float delta) {
static float seconds = 0;
seconds += delta;
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(TextFormat("%.1f s", seconds), 20, 20, 20, DARKGRAY);
EndDrawing();
}
static void on_exit() { CloseWindow(); }
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);main()?#In plain C, yes: a game whose src/ holds no C++, and no src/rmp/, is
linked against raylib alone, and its main() is its own — on the targets where a program
owns its loop, which the web and iOS are not. See Plain C. In C++ with the framework, the
entry-point macro writes main() for you, and a second one is a link error.
No. Nothing of the framework's
throws to your code. A load that finds nothing gives an empty handle that draws nothing;
rmp::app::quit() raises a flag the loop reads; a mistake
it can see is said once in the log. Where a standard-library call inside it can throw, the framework
catches it and turns it into a value — three places in rmp::save.
C++20, with designated initialisers throughout: the options of a call are written by name —
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT }) — in the order the struct
declares them. Out of order is a compile error with every compiler the framework builds with: GCC
and MSVC refuse it themselves, and every build gives Clang -Werror=reorder-init-list —
CMake, Android and the generated Xcode project alike. A plain C game is C99.
17 targets: Linux x86-64, Linux ARM64, Linux RISC-V, Linux x86-64 (musl / Alpine), Windows x86-64, Windows ARM64, macOS (universal), iOS (simulator), Web (WebAssembly), Android, FreeBSD x86-64, FreeBSD ARM64, OpenBSD x86-64, OpenBSD ARM64, NetBSD x86-64, Linux DRM/KMS (no X11), Linux ARM64 DRM/KMS (no X11). A game turns any of them off in
[targets]. See Platforms.
CI builds every target a game enables, on GitHub's runners, so a release has all of them whatever machine you work on. On your own machine you build for that machine, for the web with the Emscripten SDK, and for Android with the Android SDK and NDK. iOS needs a Mac with Xcode, and a real iPhone needs an Apple Developer account as well.
Linux x86-64, the web, Windows x86-64 and Android, in about ten minutes. A release tag builds every enabled target. See what CI does with each target.
Not to build or play the game: rmp run and rmp build release work on
your machine alone. The CI and the release pipeline that come with every game are GitHub Actions
workflows, so building every target, and publishing, happens on GitHub.
There is a target made for one with no desktop installed: linux-arm64-glibc-drm,
which draws straight to the screen. CI builds it and checks it is an ARM64
binary linked against libdrm, and does not run it, because what it is for is the Pi's own display
hardware, which no runner has. Its glibc floor is the one of the machine that built it, which CI
prints whenever it builds it: compare it with the system on your Pi. linux-arm64-glibc, the
ARM64 desktop build, asks for OpenGL 3.3 like every desktop build, and CI starts it on GitHub's ARM64
runners under a virtual X server, never on a Pi. See
Desktop.
On the Pi's own console, with no desktop, rmp run builds for DRM/KMS as on any
Linux console, and starts the game on its screen: see
Linux from a console.
No. raylib is linked into the game, and on Windows the compiler's C and C++ runtimes are too, so
there are no DLLs to ship: CI reads every .exe it ships and fails on an import that is
not part of Windows 10. The macOS build opens on macOS 10.15 on Intel and macOS 11 on Apple silicon.
A Linux build opens X11 and OpenGL at run time from the system, and needs no glibc newer than
[linux] glibc — except the RISC-V build, which [linux] glibc does not
reach and which needs glibc 2.38 or newer. The DRM builds are the other exception: they link
libdrm, GBM and EGL directly, and those have to be on the machine that runs them.
Desktop and BSD archives has each one.
| Target | Folder |
|---|---|
| Windows | %APPDATA%\<name>\, or saves\ next to the .exe with [save] portable = true |
| macOS | ~/Library/Application Support/<name>/ |
| Linux and the BSDs | $XDG_DATA_HOME/<name>/ or ~/.local/share/<name>/, or saves/ next to the executable with [save] portable = true — except on OpenBSD and NetBSD, which cannot say where the executable is, so the saves stay in the user's folder |
| Web | IndexedDB, as the folder /rmp_save/<name>/ |
| Android | The app's private storage, in saves/ |
| iOS | The app's Library/Application Support/ |
<name> is [project] name. rmp::save::directory()
says which folder a running game is using.
Yes. A desktop release reads ./resources/, and before it reads anything it moves into
the executable's folder when there is a resources/ in it — so a double-click, a shortcut
or a terminal somewhere else all find the files the archive put next to it. OpenBSD and NetBSD are
the exception: raylib cannot say where the executable is there, so the game reads
resources/ from the folder it was started in, and says so in its log. See
Desktop, and
Troubleshooting when
it finds nothing.
Because it comes from the git tag: v1.2.3 becomes the Android version name and
version code and the iOS app's version, and CI makes the release from that tag, so there is no
number in the project to forget to change. The desktop and web builds carry no version inside them. See
Releases.
A release build already drops what it does not call, at link time. Beyond that,
[raylib] disabled_modules can leave out raylib's 3D models and its audio when the game
uses neither — the shapes, textures and text cannot go, because the framework is built on them —
and [upx] compresses four Linux binaries by default — linux-x64-glibc,
linux-arm64-glibc, linux-x64-musl and linux-x64-glibc-drm,
the ones whose compressed binary CI starts — and the others you
add to it. To keep it small once it
is, write the sizes down: CI then warns when a binary moves more than 1.5% and fails past 10%. See
the size budget.
[raylib]
disabled_modules = ["rmodels"]The modules do not reach iOS, which links a prebuilt raylib.
Yes, and it is a licence decision before it is a build one. Put it under
thirdparty/ and give it a row in THIRD_PARTY_LICENSES.md:
rmp test config fails on a folder there it does not know, and on a copyleft licence.
That row is also how its notice gets into the LICENSES.txt every build ships. Then add
it to the build — to CMakeLists.txt, and, for Android and iOS, to the projects those
two build through.
None that the framework chooses: a game made with rmp new has no licence of its own,
and picking one is yours. The framework's own code is MIT, and it is built on a copy of raylib,
which is zlib-licensed and modified, each change listed beside it. Every build ships
LICENSES.txt with the notices of everything in it, the framework's included.
https://omardev29.github.io/rmp-docs/examples/index.html
The framework comes with 29 examples. Each one is a small, complete
project in its own folder under examples/, and 9 of them are whole games
you can play from start to finish.
Every example is built by CI on every change to the framework, and every one that is a program — the plain C one included — is started, headless, with a screenshot taken of it, and has to boot with every asset loaded, draw and exit cleanly. An example that is a source file with no program in it is compiled, and has nothing to run. None of them can quietly stop working.
From a clone of the framework, rmp example lists them, and one runs with its name or
its path:
rmp example
rmp example 01_pong
rmp example games/01_pong
Interstitialsource Full-screen ads between levels: request, check, show, request the next one.
Rewardedsource Watch an ad, get a reward — and only if the player actually finished it.
Pongplayable rmp::behavior::Ball and Edge::CLAMP, two players, first to seven.
Breakoutplayable A wall of bricks, and "a brick breaks" as a one-line on_collision — which is exactly why destroy_on_hit is not in the catalogue.
Space invadersplayable Collision layers earning their place, Timer + a callback instead of a shooter behavior, hurt_by deciding what may hurt the ship, and the formation written out — because the formation is Space Invaders.
Top downplayable TopDown with eight normalised directions, Follow for the enemies, an HP bar with rmp::ui::progress (and one over every enemy with rmp::ui::at(), wherever it has walked to), and what you can only say with layers: the player's shot misses the player, enemies pass through each other but not walls, and the doorway out sees the player and nothing else.
Endless runnerplayable Parallax, Runner, a Spawner by distance and a camera that follows, with a little smoothing.
Tetrisplayable The honest one: a Tetris is a 10×20 array and the rules of Tetris, and the framework does not pretend otherwise.
Platformerplayable A level designed in LDtk. Three levels side by side in one world — a meadow, a desert, a snowfield — with Kenney's Pixel Platformer art.
Dungeonplayable A dungeon crawler made of the behavior catalogue. Two LDtk levels -- the Crypt and the Sanctum -- in Kenney's Tiny Dungeon art, lit by braziers, gems and the hero's own light in the dark.
After schoolplayable An afternoon in town, told in Yarn. The lantern festival is at seven, and whom you talk to -- and what you say -- decides how the evening ends: with Mika at the festival, in the front row of Sora's concert, or at home.
Mobile raymobsource The raymob mobile API: vibration, soft keyboard, sensors, orientation, app storage.
Minimal includessource The proof that rmp/ui.h stands alone. One translation unit that includes <rmp/ui.h> and nothing else of ours, and no main() on purpose: it is compiled, never linked, and if it stops compiling the header has grown a dependency.
Stackplayable The whole model, one scene per file under src/scenes/: a menu that changes to a game, and a game that pushes a pause menu onto itself.
Stretchplayable [window] stretch, in a window that is not the design's size: a court that is letterboxed, expanded or shown 1:1, a key and a button to go round the three, and a HUD that stays on the court.
Menuplayable A main menu in three lines, then an options screen, a confirm dialog and a HUD — one scene per screen under src/scenes/, and change<>() between them.
Layoutplayable row, column, panel, center, stack/layer, spacer, plus image and progress.
Clay directplayable The escape hatch. Clay's own macros in the same frame as rmp::ui, for anything the small API does not expose yet.
Settingsplayable Checkbox, slider, dropdown, text input — and the focus/keyboard/gamepad navigation you get without writing any.
Inventoryplayable grid with a column count worked out from the space available, scroll with clipping, tooltip() for what each item is -- under a resting pointer or the keyboard's focus -- and wants_pointer() keeping the game's hands off the UI's clicks.
Styleplayable The two themes, the five variants, the three sizes and the transition.
Responsiveplayable scale() versus current_breakpoint(), and which to reach for.
Overlayplayable overlay(): a pause menu pushed as a scene of its own, blurred, that freezes the game below; and "Really quit?" drawn by the game scene itself -- an overlay with a panel() in it, which is all a dialog is.
Skinnedplayable The other way to write rmp::ui: a game's shop screen designed rather than written.
Dialogueplayable One Yarn conversation, three ways, switched while it runs: a DialogueBox (a portrait, a name plate on the frame, a voice per Speaker), a DialogueBubble over whoever speaks with its tail pointing at them, and a DialogueStage whose cast slides in and comes forward, shaken by a <<quake>>.
Localizationplayable A lantern stall in English, Spanish, Japanese and German, switched while it runs: every literal its own key in resources/lang.tsv, German in a file of its own (lang/de.tsv), {placeholders}, plurals in each language's forms, a context, and a font per language -- Japanese in Jigmo (CC0), cut down to the letters the table uses -- with each language's name in the menu in a font that has its letters (Style::font).
Fontplayable A menu in a font of your own: a title, its options and its credits, one scene each, every word in Hack Bold through one rmp::ui::set_font().
https://omardev29.github.io/rmp-docs/examples/plain_c.html
The opt-out. A C entry point with your own main(): raylib, plus two headers of ours that are C -- <rmp/config.h> for the [window] values and <smoke_test.h> for the CI hooks -- and none of rmp::. You keep every build target but two and lose the runtime layer: iOS and Web are the two you give up, because on those the loop is not yours to write, and the file says so. Its top lines are the recipe, which CI follows in a game made with rmp new. Built as C99 and booted like the rest; a release of a plain C game ships its loose resources/, which raw raylib reads, instead of the pack it cannot.

It writes its own while loop, which a browser cannot run without ASYNCIFY — the web is one of the targets it gives up, and the file says so.
From a clone of the framework:
rmp example plain_cEvery file of examples/plain_c, as it is at the commit this site documents (on GitHub).
src/main.c 117 lines// ===========================================================================
// examples/plain_c -- the framework with none of the framework.
//
// Plain C, your own main(), raylib and nothing of ours but the CI hooks. No
// rmp::assets, no scenes, no entry-point macro. What you keep is everything
// the framework does *around* your code, which is the part that is hard to
// reproduce: the build targets, the pinned toolchains, the icons and
// identifiers generated from raylib_multiplatform.toml, the release pipeline.
//
// To use it, in a game made with `rmp new`, from the game's folder:
//
// rm src/main.cpp && rm -r src/rmp/ src/scenes/ tests/game/
// cp <the framework>/examples/plain_c/src/main.c src/
// rmp run
//
// src/ is globbed by all four build systems (CMake, the Android CMakeLists,
// XcodeGen, Emscripten), so nothing else needs editing. src/rmp/ is the
// framework itself, and it goes because nothing here uses it: CMakeLists.txt
// builds the framework library from it whenever it has sources, while a src/
// with no C++ in it gets an executable linked to raylib alone -- so kept, it
// is the whole C++ framework compiled for nothing on the desktop, and
// compiled into the game on Android and iOS, whose builds take everything
// under src/. With it gone there is no framework library at all. tests/game/
// goes with src/scenes/: it tests the main menu, through the framework. Keep
// include/rmp/: this file reads [window] from <rmp/config.h>, the one header
// of ours that is plain #defines. The rmp new CI job follows the first two
// lines in a fresh game and boots what they make.
//
// What you give up, and what replaces it:
//
// assets::Load* -> LoadTexture(RMP_RESOURCES_PATH "x.png"), as below
// the resource pack -> gone. Loose files only: a release ships
// resources/ as it is, with a PACK_SKIPPED.txt
// saying why (tools/ship_resources.sh), because
// raw raylib cannot read resources.rres -- reading
// it is what src/rmp/assets/loader_hook.cpp was doing.
// RMP_WINDOW_TITLE, ... -> #include <rmp/config.h>, as below: [window] and
// the rest of the .toml as plain #defines, in C.
// the smoke-test hooks -> <smoke_test.h>, as below. It is C, it is on the
// include path, and every CI boot greps the lines it
// prints: a boot, a frame read back, a clean exit.
//
// TWO PLATFORMS DO NOT RUN THIS FILE AS IT STANDS, and both for the same
// reason: the `while` loop below assumes your code owns the frame loop, and on
// those two it does not.
//
// iOS does not call main() at all. The run loop belongs to UIKit, and
// raylib's iOS backend calls ios_ready/ios_update/ios_destroy.
// Web has no loop either: the browser calls you back, through
// emscripten_set_main_loop(). A `while` loop there freezes the tab
// unless the whole binary is built with -s ASYNCIFY, which is a real
// cost in size and speed and which this project does not pay.
//
// Papering over exactly that is what RMP_ENTRY_POINT is for -- it writes the
// right loop for each target and calls the same three hooks. So if you want
// iOS or Web, either keep the framework's entry point (which is one include and
// one line, and costs you nothing else) or write those two runners yourself.
// Linux, Windows, macOS, the BSDs and Android run this as it is.
// ===========================================================================
#include <raylib.h>
#include <rmp/config.h> // [window] from raylib_multiplatform.toml, as #defines
#include <smoke_test.h> // the CI hooks: no-ops unless RAY_TEST_MAX_FRAMES is set
// RMP_RESOURCES_PATH is defined by CMake, not by us: an absolute path to
// resources/ in a development build, "./resources/" in a release, "" on
// Android (where assets sit at the root of the APK). Build every asset path
// out of it and the same source works on all of them.
int main(void) {
SmokeTest_Begin();
#if RMP_PRODUCTION_BUILD && !defined(PLATFORM_ANDROID) && !defined(__EMSCRIPTEN__)
// A release reads "./resources/", and "." has to be the executable's folder,
// not wherever it was started from -- a file manager, a shortcut, another
// terminal. Only when resources/ is THERE, though: `rmp build release`
// leaves the executable in build/ and resources/ beside build/, and run
// from the project folder it reads that one. The framework's entry point
// does the same for a C++ game (enter_executable_folder() in
// src/rmp/app/app.cpp); here it is yours. GetApplicationDirectory() is "" on
// NetBSD and OpenBSD, which cannot say where an executable is: there a
// release reads the working directory's resources/.
const char *folder = GetApplicationDirectory();
if (folder[0] != '\0' &&
DirectoryExists(TextFormat("%s%s", folder, RMP_RESOURCES_PATH))) {
ChangeDirectory(folder);
}
#endif
// [window] in the .toml, the way RMP_GAME opens it: resizable, vsync if it
// says so, and its size and title. CI checks the window was asked for the
// vsync the .toml names.
SetConfigFlags(RMP_WINDOW_VSYNC ? FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT
: FLAG_WINDOW_RESIZABLE);
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
Texture2D rabbit = LoadTexture(RMP_RESOURCES_PATH "rabbit.png");
// One asset asked for, and failed if it came back empty: what the boot
// line reports and every CI boot requires to be assets_failed=0.
SmokeTest_ReportBoot(rabbit.id == 0 ? 1 : 0, 1);
// The window's X ends it, and under CI so does the frame budget.
while (!WindowShouldClose() && !SmokeTest_Done()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(rabbit, GetScreenWidth() / 2 - rabbit.width / 2,
GetScreenHeight() / 2 - rabbit.height / 2, WHITE);
DrawText("Raylib is Multiplatform!", 190, 200, 20, LIGHTGRAY);
SmokeTest_CaptureFrame(); // between the last draw and EndDrawing()
EndDrawing();
SmokeTest_Tick();
}
UnloadTexture(rabbit);
CloseWindow();
return 0;
}https://omardev29.github.io/rmp-docs/examples/ads/index.html
https://omardev29.github.io/rmp-docs/examples/ads/01_interstitial.html
Full-screen ads between levels: request, check, show, request the next one.

Ads are shown on Android only: in a browser every rmp::ads call does nothing, so there would be nothing to see.
From a clone of the framework:
rmp example 01_interstitialRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
| read directly | Space, R |
Every file of examples/ads/01_interstitial, as it is at the commit this site documents (on GitHub).
src/main.cpp 78 lines// ---------------------------------------------------------------------------
// examples/ads/01_interstitial/src/main.cpp
//
// Interstitial ads: the full-screen ones you show between levels.
//
// The rewarded flow, which is the one with a contract attached, is in
// 02_rewarded.cpp.
//
// The API is rmp::ads, from <rmp/ads.h>. It is CROSS-PLATFORM: on
// Android it calls the real Google Mobile Ads SDK via JNI; on every other
// platform the functions are no-op stubs. So you write ONE code path with no
// #ifdefs, and ads simply only appear on Android.
//
// Lifecycle of an ad:
// request_*() -> start preloading (do it early, e.g. in on_ready)
// is_*_loaded() -> has it finished loading?
// show_*() -> display it, then request the next one
// take_reward_earned() -> rewarded only: true once, then reward_amount()
//
// Configure your real ad-unit ids in [android.admob] in
// raylib_multiplatform.toml before shipping (the framework defaults to Google's
// official TEST ids). Banner ads are not supported by design.
//
// [android.admob] enabled = false removes AdMob from the Android build
// entirely, and this file still compiles and still runs: the calls become the
// same no-ops they already are on desktop. Ads are opt-in for a reason — see
// the consent (UMP) warning in README.md before shipping with them on.
//
// Run it: `rmp example 01_interstitial`.
// ---------------------------------------------------------------------------
#include <raylib.h>
#include <rmp/ads.h> // rmp::ads
#include <rmp/app.h> // RMP_ENTRY_POINT
static int last_reward = 0;
static void on_ready() {
InitWindow(800, 450, "admob example");
// Preload both ad types as early as possible so they are ready when you
// want to show them. No-ops outside Android.
rmp::ads::request_interstitial();
rmp::ads::request_rewarded();
}
static void on_frame(float) {
// Show an interstitial when it is loaded (here: on SPACE).
if (IsKeyPressed(KEY_SPACE) && rmp::ads::is_interstitial_loaded()) {
rmp::ads::show_interstitial();
rmp::ads::request_interstitial(); // preload the next one right away
}
// Show a rewarded ad (here: on R) and poll for the reward.
if (IsKeyPressed(KEY_R) && rmp::ads::is_rewarded_loaded()) {
rmp::ads::show_rewarded();
rmp::ads::request_rewarded();
}
if (rmp::ads::take_reward_earned()) { // true exactly once per earned reward
last_reward = rmp::ads::reward_amount(); // grant it to the player here
}
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("SPACE: interstitial R: rewarded", 10, 40, 20, DARKGRAY);
DrawText(rmp::ads::is_interstitial_loaded() ? "interstitial ready"
: "interstitial loading...",
10, 80, 20, GRAY);
DrawText(rmp::ads::is_rewarded_loaded() ? "rewarded ready" : "rewarded loading...",
10, 110, 20, GRAY);
if (last_reward > 0)
DrawText(TextFormat("Last reward: %d", last_reward), 10, 150, 20, DARKGREEN);
EndDrawing();
}
static void on_exit() { CloseWindow(); }
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);https://omardev29.github.io/rmp-docs/examples/ads/02_rewarded.html
Watch an ad, get a reward — and only if the player actually finished it. The flow where a mistake costs money or trust.

Ads are shown on Android only: in a browser every rmp::ads call does nothing, so there would be nothing to see.
From a clone of the framework:
rmp example 02_rewardedEvery file of examples/ads/02_rewarded, as it is at the commit this site documents (on GitHub).
src/main.cpp 108 lines// ---------------------------------------------------------------------------
// examples/ads/02_rewarded/src/main.cpp
//
// A rewarded ad, end to end: the player asks for a bonus, watches an ad, and
// gets the reward — only if they actually finished it.
//
// This is the flow worth getting right, because it is the one where a mistake
// costs you real money or a real player's trust. An interstitial you can fire
// and forget (see 01_interstitial.cpp); a rewarded ad has a contract with the
// player attached to it.
//
// Real on Android, silently nothing everywhere else. On desktop the buttons
// below are live and the reward never arrives, which is exactly what you want
// while building the rest of the game.
//
// Run it: `rmp example 02_rewarded`.
// ---------------------------------------------------------------------------
#include <rmp/ads.h>
#include <rmp/app.h>
#include <rmp/ui.h>
#include <string>
static int coins = 0;
static bool waiting_for_ad = false;
static void on_ready() {
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
// Preload as early as you can. Loading takes seconds, and an ad the player
// has to wait for is an ad they close.
rmp::ads::request_rewarded();
}
static void on_frame(float /*delta*/) {
// THE POLL. take_reward_earned() is true exactly once per reward earned and
// clears itself, so this can live in the frame loop with no bookkeeping. It
// fires only if the player watched enough of the ad — if they closed it
// early, nothing happens here and they get nothing, which is the whole
// point of a rewarded ad.
if (rmp::ads::take_reward_earned()) {
coins += rmp::ads::reward_amount();
waiting_for_ad = false;
// Line the next one up straight away, so the button is live again by
// the time the player wants it.
rmp::ads::request_rewarded();
}
BeginDrawing();
ClearBackground(rmp::ui::current_theme().background);
rmp::ui::begin();
rmp::ui::panel([&] {
rmp::ui::text("Coins: " + std::to_string(coins));
if (rmp::ads::is_rewarded_loaded()) {
if (rmp::ui::button("Watch an ad for 50 coins",
{ .style = rmp::ui::Variant::PRIMARY })) {
waiting_for_ad = true;
rmp::ads::show_rewarded();
}
} else {
// Never show a live button for an ad that is not there: the player
// taps it, nothing happens, and they decide your game is broken.
// A disabled control says "not yet" honestly.
rmp::ui::button("Ad not ready", { .enabled = false });
}
if (waiting_for_ad) {
rmp::ui::text("waiting for the reward…",
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
}
rmp::ui::text("Ads only exist on Android. Everywhere else the calls do "
"nothing and the button above stays disabled.",
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
});
rmp::ui::end();
EndDrawing();
}
static void on_exit() { CloseWindow(); }
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);
// ---------------------------------------------------------------------------
// Before you ship this
// ---------------------------------------------------------------------------
//
// * The ids in [android.admob] are Google's TEST ids. Replace them, or you will
// be showing test ads to real players. Clicking real ads from your own build
// is the fastest way to get an AdMob account suspended, so keep the test ids
// until the day you publish.
//
// * CONSENT IS NOT IMPLEMENTED. Serving ads in the EEA or the UK requires a
// Google-certified consent platform, and this framework does not ship one.
// See the warning in README.md.
//
// * Do not gate progress behind an ad that may never load. is_rewarded_loaded()
// can be false for a long time on a bad connection, and a player who cannot
// continue is a player who uninstalls.
//
// * [android.admob] enabled = false removes AdMob from the build entirely, and
// this file still compiles and still runs — the calls become the no-ops they
// already are on desktop.https://omardev29.github.io/rmp-docs/examples/assets/index.html
resources.rres.https://omardev29.github.io/rmp-docs/examples/assets/01_loading.html
Loading by name — the same code whether it comes from loose files or a packed, AES-encrypted resources.rres. The counted handles (rmp::Texture, rmp::Font, rmp::Sound) and why there is no Unload* in the file, nor an InitAudioDevice(): the sound device opens on the first sound. Brings its own resources/, which is all an example has to do to read its own.

From a clone of the framework:
rmp example 01_loadingRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
| read directly | Space, Enter |
Every file of examples/assets/01_loading, as it is at the commit this site documents (on GitHub).
src/main.cpp 93 lines// ---------------------------------------------------------------------------
// examples/assets/01_loading/src/main.cpp
//
// How resources/ reaches your game, in both shapes it can arrive in:
// - a packed, optionally AES-encrypted "resources.rres", or
// - the loose files, while you are working.
// The same code reads either. Switch between them with:
// cmake --build --preset debug --target pack_resources # -> resources/resources.rres
// cmake --build --preset debug --target unpack_resources # back to loose files
//
// This example carries its own resources/ next to src/, and that is all it
// takes: an example with a resources/ folder reads that one, not the game's.
//
// Note what is missing: there is no rmp::assets::init() call anywhere below. The
// entry point macro opens the pack before on_ready() and closes it after
// on_exit(), so there is nothing to remember and nothing to get wrong.
//
// Run it: `rmp example 01_loading`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <vector>
// The counted handles, not the raylib structs. Each one owns what it loaded
// and releases it when it goes -- there is no Unload* anywhere in this file.
// Writing `Texture2D t = rmp::assets::load_texture(...)` instead would copy
// the struct out and destroy the only owner on the same line.
static rmp::Texture player;
static rmp::Font ui;
static rmp::Sound jump;
// Called once at startup: the pack (if any) is already open by now.
static void on_ready() {
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
// Load by resource name — no path, no extension guessing, and no #ifdef
// for "did this build get a pack or not".
player = rmp::assets::load_texture("rabbit.png");
ui = rmp::assets::load_font("ui.ttf", 20);
// The sound device opens here, on the first sound, with no
// InitAudioDevice() and no CloseAudioDevice() anywhere: a game with no
// sound never opens it, and on a machine without one this comes back
// empty and the game runs silent.
jump = rmp::assets::load_sound("jump.wav");
// Anything else, as bytes: a vector that frees itself, empty when the
// file is not there.
const std::vector<unsigned char> level = rmp::assets::load_data("level1.json");
TraceLog(LOG_INFO, "level1.json: %d bytes", static_cast<int>(level.size()));
// Plain raylib works too, and reads the pack just the same: opening the
// pack also routes raylib's own file loading through it. That is what
// makes ::LoadModel(RMP_RESOURCES_PATH "ship.obj") work from a pack — raylib
// reads the .obj, its .mtl and the textures the .mtl names through the
// same LoadFileData the pack is hooked into.
//
// One exception: raylib's LoadMusicStream opens the file itself and never
// sees the pack. rmp::audio::music("song") does, and so does
// rmp::audio::play("jump") -- the same sound as above, by logical name,
// with overlapping voices and no handle to keep.
}
static void on_frame(float /*delta*/) {
if (IsKeyPressed(KEY_SPACE)) PlaySound(jump);
if (IsKeyPressed(KEY_ENTER)) rmp::audio::play("jump");
BeginDrawing();
ClearBackground(RAYWHITE);
const Texture2D &tex = player; // the raylib struct, borrowed for the call
DrawTexture(tex, GetScreenWidth() / 2 - tex.width / 2,
GetScreenHeight() / 2 - tex.height / 2, WHITE);
DrawTextEx(ui,
rmp::assets::using_pack() ? "serving from resources.rres"
: "serving loose files",
Vector2{ 10, 40 }, 20, 1, GRAY);
EndDrawing();
}
static void on_exit() {
// The framework has already released everything in the resource table
// and closed the sound device by the time this runs; letting the handles
// go is tidiness, not a requirement -- a handle that outlives the table
// is empty, not dangling.
jump = {};
ui = {};
player = {};
CloseWindow();
}
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);https://omardev29.github.io/rmp-docs/examples/games/index.html
rmp::behavior::Ball and Edge::CLAMP, two players, first to seven.on_collision — which is exactly why destroy_on_hit is not in the catalogue.Timer + a callback instead of a shooter behavior, hurt_by deciding what may hurt the ship, and the formation written out — because the formation is Space Invaders.TopDown with eight normalised directions, Follow for the enemies, an HP bar with rmp::ui::progress (and one over every enemy with rmp::ui::at(), wherever it has walked to), and what you can only say with layers: the player's shot misses the player, enemies pass through each other but not walls, and the doorway out sees the player and nothing else.Parallax, Runner, a Spawner by distance and a camera that follows, with a little smoothing.https://omardev29.github.io/rmp-docs/examples/games/01_pong.html
rmp::behavior::Ball and Edge::CLAMP, two players, first to seven. No bounce arithmetic, no bounds check, no frame loop. The serve is the game's, because no behavior chooses a direction for you — and so is the one field that makes a point possible: bounds WIDER than the court, since a ball that bounces off all four sides can never go out. With sound: rmp::audio::play("hit") on the paddle and nothing else -- no device to open, feed or close. Start here.

From a clone of the framework:
rmp example 01_pongRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
p2_up | ↑ |
p2_down | ↓ |
move_up | W, gamepad left face up |
move_down | S, gamepad left face down |
Every file of examples/games/01_pong, as it is at the commit this site documents (on GitHub).
src/main.cpp 186 lines// ---------------------------------------------------------------------------
// examples/games/01_pong -- Pong, whole.
//
// Two players, a point when the ball leaves by a side, first to seven, and a
// way to play again. Every line here is a rule of Pong: there is no frame
// loop, no bounds check, no bounce arithmetic and no collision test, because
// those are the framework's.
//
// The sounds are played by name -- resources/ holds hit.wav, point.wav and
// win.wav -- and nothing here opens or closes a sound device. On a machine
// without one the game is the same, in silence.
//
// Run it: `rmp example 01_pong`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/object.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
namespace {
constexpr float PADDLE_SPEED = 420;
constexpr float SERVE_SPEED = 340;
constexpr int WINNING_SCORE = 7;
constexpr float MID_X = RMP_WINDOW_WIDTH / 2.0f;
constexpr float MID_Y = RMP_WINDOW_HEIGHT / 2.0f;
// A paddle is a rectangle that goes up and down and stops at the edge. `edges`
// is the stopping, and it is one field.
class Paddle : public rmp::Object {
public:
const char *up = "move_up";
const char *down = "move_down";
void _ready() override {
shape = rmp::rect({ 14, 90 });
edges = rmp::Edge::CLAMP;
solid = true;
immovable = true;
}
void _update(float) override {
velocity.y = rmp::input::axis(up, down) * PADDLE_SPEED;
}
};
// The end of a game, PUSHED on top of it: the court below freezes, stays on
// screen and stops hearing the keyboard, which is what the scene stack does on
// its own -- so this is only what it says and the way out.
class OverScene : public rmp::Scene {
public:
explicit OverScene(const char *said) : _said(said) {}
void _draw() override; // below PongScene, which it starts again
private:
const char *_said;
};
class PongScene : public rmp::Scene {
public:
void _ready() override {
background = Color{ 14, 30, 28, 255 };
// Player two's keys. The six actions that come as standard are player
// one's, and a second player is the game's to name -- reading an action
// nobody defined is silent, which is how these two went missing.
rmp::input::action("p2_up", KEY_UP);
rmp::input::action("p2_down", KEY_DOWN);
// And the arrows are player two's ALONE. move_up and move_down come
// bound to W/S and to the arrows, so as they came, Up moved both
// paddles; tests/e2e/games/01_pong.e2e played it and saw them go
// together. Defining a name again replaces it: player one keeps W, S,
// the d-pad and the stick.
rmp::input::action("move_up", KEY_W, GAMEPAD_BUTTON_LEFT_FACE_UP,
rmp::input::stick(GAMEPAD_AXIS_LEFT_Y, -1));
rmp::input::action("move_down", KEY_S, GAMEPAD_BUTTON_LEFT_FACE_DOWN,
rmp::input::stick(GAMEPAD_AXIS_LEFT_Y, 1));
const rmp::ui::Theme &theme = rmp::ui::current_theme();
auto &left = spawn<Paddle>({ .position = { 40, MID_Y } });
left.shape.color = theme.primary;
_left = left.handle<Paddle>();
auto &right = spawn<Paddle>({ .position = { RMP_WINDOW_WIDTH - 40, MID_Y } });
right.up = "p2_up";
right.down = "p2_down";
right.shape.color = theme.danger;
_right = right.handle<Paddle>();
// BOUNDS WIDER THAN THE COURT, and this is the rule the game turns on:
// Ball sets Edge::BOUNCE, which bounces off all four sides of its
// bounds -- so a ball left with the view's bounds can never go out and
// no point can ever be scored. Tall as the court and wide past it, and
// it bounces off the top and the bottom and leaves by the sides.
auto &ball = spawn(
{ .position = { MID_X, MID_Y },
.shape = rmp::circle(7),
.bounds = { -240, 0, RMP_WINDOW_WIDTH + 480.0f, RMP_WINDOW_HEIGHT } });
ball.add<rmp::behavior::Ball>({ .speed = SERVE_SPEED });
// Ball does the bouncing; the sound of it is the game's.
ball.on_collision([](rmp::Object &, rmp::Object &) { rmp::audio::play("hit"); });
_ball = ball.handle();
serve(1);
}
void _update(float) override {
// The only rule Pong has that the framework does not: a point.
if (_ball->position.x < 0) {
point(_right_score, "Red wins", -1);
} else if (_ball->position.x > RMP_WINDOW_WIDTH) {
point(_left_score, "Blue wins", 1);
}
}
void _draw() override {
// The net, over the court and under the score. IN WORLD UNITS, because
// _draw() is handed the screen and the paddles are drawn through the
// camera: on a window that is not the design size the two disagree, and
// the net ends up somewhere the court is not.
BeginMode2D(camera.raylib());
for (int y = 8; y < RMP_WINDOW_HEIGHT; y += 30) {
DrawRectangle(static_cast<int>(MID_X) - 2, y, 4, 16,
Color{ 255, 255, 255, 38 });
}
EndMode2D();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::row({ .gap = 110 }, [&] {
rmp::ui::text(TextFormat("%d", _left_score),
{ .color = rmp::ui::ColorRole::PRIMARY, .size = 56 });
rmp::ui::text(TextFormat("%d", _right_score),
{ .color = rmp::ui::ColorRole::DANGER, .size = 56 });
});
rmp::ui::end();
}
private:
// Which way the ball leaves is a rule of the game, so the game decides it:
// towards whoever just conceded. An impulse, because only its direction
// matters -- Ball keeps its own speed.
void serve(float towards) {
_ball->position = { MID_X, MID_Y };
_ball->velocity = {};
_ball->apply_impulse({ towards, 0.35f });
_left->position.y = MID_Y; // a new rally starts level
_right->position.y = MID_Y;
}
void point(int &counter, const char *winner, float towards) {
++counter;
serve(towards);
if (counter >= WINNING_SCORE) {
rmp::audio::play("win");
rmp::Scene::push<OverScene>(winner);
} else {
rmp::audio::play("point");
}
}
// Between frames, a handle. A reference to an object is good for the
// frame it was got in and no longer -- see rmp/object.h.
rmp::Handle<Paddle> _left;
rmp::Handle<Paddle> _right;
rmp::Handle<rmp::Object> _ball;
int _left_score = 0;
int _right_score = 0;
};
// An overlay, and not begin()/end(): a frame of its own in front of everything
// drawn before it, which it dims -- most of the way to black here, so that the
// words read over the court -- and whose first button has the focus, so Enter
// plays again too. A pause menu is the same call with a Resume button in it.
void OverScene::_draw() {
rmp::ui::overlay({ .dim = 0.75f }, [this] {
rmp::ui::text(_said, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play again")) rmp::Scene::change<PongScene>();
});
}
} // namespace
RMP_GAME(PongScene);https://omardev29.github.io/rmp-docs/examples/games/02_breakout.html
A wall of bricks, and "a brick breaks" as a one-line on_collision — which is exactly why destroy_on_hit is not in the catalogue. Three lives, and an open floor for the same reason Pong has open sides. A lost ball shakes the camera, which gameplay never sees.

From a clone of the framework:
rmp example 02_breakoutRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
move_left | A, ←, gamepad left face left |
move_right | D, →, gamepad left face right |
Every file of examples/games/02_breakout, as it is at the commit this site documents (on GitHub).
src/main.cpp 159 lines// ---------------------------------------------------------------------------
// examples/games/02_breakout -- Breakout.
//
// Pong plus a wall of bricks. A brick breaking on contact is `on_collision`
// and one line, so there is no behavior for it. The rest is the three rules a
// Breakout has: three lives, a floor the ball can fall through, and a wall
// that is gone.
//
// Run it: `rmp example 02_breakout`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/object.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <array>
namespace {
constexpr int COLUMNS = 10;
constexpr int ROWS = 5;
constexpr float BRICK_WIDTH = 72;
constexpr float BRICK_HEIGHT = 24;
constexpr int LIVES = 3;
constexpr float PADDLE_Y = 420;
constexpr float PADDLE_SPEED = 520;
// One per row, top to bottom. A wall of one colour is a wall; five is a game.
constexpr std::array<Color, ROWS> ROW_COLORS{ MAROON, ORANGE, GOLD, LIME, SKYBLUE };
// The end of a game, PUSHED on top of it: the wall below freezes, stays on
// screen and stops hearing the keyboard, which is what the scene stack does on
// its own -- so this is only what it says and the way out.
class OverScene : public rmp::Scene {
public:
explicit OverScene(const char *said) : _said(said) {}
void _draw() override; // below BreakoutScene, which it starts again
private:
const char *_said;
};
class BreakoutScene : public rmp::Scene {
public:
void _ready() override {
background = Color{ 16, 18, 34, 255 };
auto &paddle =
spawn({ .position = { 400, PADDLE_Y }, .shape = rmp::rect({ 110, 16 }) });
paddle.shape.color = rmp::ui::current_theme().primary;
paddle.edges = rmp::Edge::CLAMP;
paddle.solid = true;
paddle.immovable = true;
_paddle = paddle.handle();
// AN OPEN FLOOR, and it is one field: Ball sets Edge::BOUNCE, which
// bounces off all four sides of its bounds, so a ball left with the
// view's bounds would come back up off the bottom of the screen for
// ever and a life could never be lost. Bounds taller than the court
// keep the three walls and take the fourth away.
auto &ball =
spawn({ .position = { 400, 380 },
.shape = rmp::circle(7),
.bounds = { 0, 0, RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT + 300.0f } });
// speed_up is per bounce off anything solid, and every brick is: at 1 %
// the ball is about twice its serve by the last of fifty. At 3 % it was
// four times its serve by the thirtieth brick, far faster than the
// paddle, and even a bot that knew where every ball would come down lost
// its three balls with bricks left (tests/e2e/games/02_breakout.e2e
// clears the wall at 1 %).
ball.add<rmp::behavior::Ball>({ .speed = 320, .speed_up = 1.01f });
_ball = ball.handle();
serve();
for (int row = 0; row < ROWS; ++row) {
for (int column = 0; column < COLUMNS; ++column) {
add_brick(row, column);
}
}
}
void _update(float) override {
_paddle->velocity.x = rmp::input::axis("move_left", "move_right") * PADDLE_SPEED;
// The two rules the framework has no opinion about: the ball is lost,
// and the wall is gone.
if (_ball->position.y > RMP_WINDOW_HEIGHT + 20) {
--_lives;
if (_lives <= 0) {
rmp::Scene::push<OverScene>("Game over");
return;
}
// A life lost, felt: the view jolts and settles in a third of a
// second. It never moves the paddle, the ball or the bricks --
// gameplay does not see it, only what is drawn does.
camera.shake(8, 0.35f);
serve();
}
if (_bricks == 0) rmp::Scene::push<OverScene>("You win");
}
void _draw() override {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text(TextFormat("Bricks %d", _bricks));
rmp::ui::text(TextFormat("Lives %d", _lives),
{ .color = rmp::ui::ColorRole::DANGER });
});
rmp::ui::end();
}
private:
void add_brick(int row, int column) {
auto &brick = spawn({
.position = { 44 + static_cast<float>(column) * (BRICK_WIDTH + 4),
60 + static_cast<float>(row) * (BRICK_HEIGHT + 4) },
.shape = rmp::rect({ BRICK_WIDTH, BRICK_HEIGHT }),
});
brick.solid = true;
brick.immovable = true;
brick.shape.color = ROW_COLORS[row];
++_bricks;
// The whole of "a brick breaks". No behavior, no subclass.
brick.on_collision([this](rmp::Object &self, rmp::Object &other) {
if (other.handle() != _ball) return;
self.destroy();
--_bricks;
});
}
// Where the ball goes is the game's to say: up off the paddle. An impulse,
// because only its direction matters -- Ball keeps its own speed.
void serve() {
_ball->position = { _paddle->position.x, PADDLE_Y - 40 };
_ball->velocity = {};
_ball->apply_impulse({ 0.4f, -1 });
}
// Between frames, a handle. A raw pointer is good for the frame it was got
// in and no longer -- see rmp/object.h.
rmp::Handle<rmp::Object> _paddle;
rmp::Handle<rmp::Object> _ball;
int _bricks = 0;
int _lives = LIVES;
};
void OverScene::_draw() {
rmp::ui::overlay({ .dim = 0.75f }, [this] {
rmp::ui::text(_said, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play again")) rmp::Scene::change<BreakoutScene>();
});
}
} // namespace
RMP_GAME(BreakoutScene);https://omardev29.github.io/rmp-docs/examples/games/03_space_invaders.html
Collision layers earning their place, Timer + a callback instead of a shooter behavior, hurt_by deciding what may hurt the ship, and the formation written out — because the formation is Space Invaders. A handle per alien and one number is the whole of it.

From a clone of the framework:
rmp example 03_space_invadersRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
move_left | A, ←, gamepad left face left |
move_right | D, →, gamepad left face right |
ui_accept | Enter, Space, gamepad right face down |
Every file of examples/games/03_space_invaders, as it is at the commit this site documents (on GitHub).
src/main.cpp 211 lines// ---------------------------------------------------------------------------
// examples/games/03_space_invaders -- Space Invaders.
//
// The formation -- a block of aliens stepping sideways, dropping and speeding
// up as they thin out -- IS the game, so it is written here. The framework
// supplies what is not the game: shooting on a Timer, bullets that discard
// themselves, hit points, and who is allowed to hurt whom.
//
// The formation is a handle per alien and two offsets. Nothing walks a list of
// objects looking for aliens, and nothing holds a pointer to one that a shot
// may have destroyed two frames ago.
//
// Run it: `rmp example 03_space_invaders`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/object.h>
#include <rmp/random.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <algorithm>
#include <array>
namespace {
namespace layer {
constexpr unsigned PLAYER = 1u << 0;
constexpr unsigned ALIEN = 1u << 1;
constexpr unsigned PLAYER_SHOT = 1u << 2;
constexpr unsigned ALIEN_SHOT = 1u << 3;
} // namespace layer
constexpr int COLUMNS = 11;
constexpr int ROWS = 4;
constexpr int ALIENS = COLUMNS * ROWS;
constexpr float MARCH = 40; // how far the block slides each way
constexpr float DROP = 16; // and how far down it steps when it turns
constexpr float PLAYER_Y = 410;
constexpr float GROUND_Y = 434;
constexpr float PLAYER_SPEED = 360;
constexpr float PLAYER_SHOT_SPEED = 560;
constexpr float ALIEN_SHOT_SPEED = 300;
// One per row, and the row a picture would put the strange ones in is the one
// at the top.
constexpr std::array<Color, ROWS> ROW_COLORS{ VIOLET, PINK, ORANGE, GOLD };
// The end of a game, PUSHED on top of it: the board below freezes, stays on
// screen and stops hearing the keyboard, which is what the scene stack does on
// its own -- so this is only what it says and the way out.
class OverScene : public rmp::Scene {
public:
explicit OverScene(const char *said) : _said(said) {}
void _draw() override; // below InvadersScene, which it starts again
private:
const char *_said;
};
class InvadersScene : public rmp::Scene {
public:
void _ready() override {
background = Color{ 8, 10, 20, 255 };
auto &player =
spawn({ .position = { 400, PLAYER_Y }, .shape = rmp::rect({ 44, 18 }) });
player.shape.color = LIME;
player.edges = rmp::Edge::CLAMP;
player.collision_layer = layer::PLAYER;
player.collision_mask = layer::ALIEN_SHOT | layer::ALIEN;
// Who is allowed to hurt it is one field, `hurt_by`: without it a
// Health is a hit-point counter that nothing ever reduces.
player.add<rmp::behavior::Health>({
.hp = 3,
.invulnerable_for = 1.2f,
.destroy_on_death = false, // the ship stays on screen under the overlay
.on_death = [](rmp::Object &) { rmp::Scene::push<OverScene>("Game over"); },
.hurt_by = layer::ALIEN_SHOT | layer::ALIEN,
});
_player = player.handle();
for (int i = 0; i < ALIENS; ++i) add_alien(i);
}
void _update(float delta) override {
_player->velocity.x = rmp::input::axis("move_left", "move_right") * PLAYER_SPEED;
if (rmp::input::just_pressed("ui_accept")) shoot();
// The formation. Every alien moves as one, turns at the wall and drops
// a step, and the block speeds up as it thins: with half of them left
// it moves twice as fast, and with a quarter four times -- and no
// faster. The block turns every MARCH * 2 units, so its pace is also
// how fast it comes down: uncapped, the last alien moved 44 times as
// fast, came down at over 300 units a second and landed before a ship
// could get under it (tests/e2e/games/03_space_invaders.e2e).
const float alive = static_cast<float>(std::max(_alive, ALIENS / 4));
_march += _march_speed * delta * static_cast<float>(ALIENS) / alive;
if (_march > MARCH || _march < -MARCH) {
_march_speed = -_march_speed;
_march = _march > 0 ? MARCH : -MARCH;
_drop += DROP;
}
float lowest = 0;
for (int i = 0; i < ALIENS; ++i) {
auto alien = _aliens[i].get();
if (!alien) continue; // shot down: the handle says so
alien->position = { home(i).x + _march, home(i).y + _drop };
lowest = std::max(lowest, alien->position.y);
}
if (_alive == 0) {
rmp::Scene::push<OverScene>("You win");
} else if (lowest > PLAYER_Y - 30) {
rmp::Scene::push<OverScene>("They landed");
}
}
void _draw() override {
// The ground, IN WORLD UNITS: _draw() is handed the screen and the
// ships are drawn through the camera, so on a window that is not the
// design size a line drawn in screen units lands somewhere else.
BeginMode2D(camera.raylib());
DrawRectangle(0, static_cast<int>(GROUND_Y), RMP_WINDOW_WIDTH, 3, DARKGREEN);
EndMode2D();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text(TextFormat("Aliens %d", _alive));
rmp::ui::text(TextFormat("HP %d", _player->get<rmp::behavior::Health>()->hp),
{ .color = rmp::ui::ColorRole::DANGER });
});
rmp::ui::end();
}
private:
// Where an alien belongs when the block has not moved. The formation is
// this plus one offset, which is why no alien has to remember anything.
static Vector2 home(int index) {
const int column = index % COLUMNS;
const int row = index / COLUMNS;
return { 180 + static_cast<float>(column) * 44,
70 + static_cast<float>(row) * 38 };
}
void add_alien(int index) {
auto &alien = spawn({ .position = home(index), .shape = rmp::rect({ 32, 22 }) });
alien.shape.color = ROW_COLORS[index / COLUMNS];
alien.collision_layer = layer::ALIEN;
alien.collision_mask = layer::PLAYER_SHOT;
alien.on_collision([this](rmp::Object &self, rmp::Object &) {
self.destroy();
--_alive;
});
// Shooting is a Timer and a callback. Each alien gets a period of its
// own from rmp::random: forty-four timers started on the same frame with
// the same number would fire as one gun.
alien.add<rmp::behavior::Timer>({
.seconds = rmp::random::range(4.0f, 9.0f),
.on_timeout = [this, index](rmp::Object &self) { alien_shoot(self, index); },
});
_aliens[index] = alien.handle();
++_alive;
}
void shoot() {
auto &shot =
spawn({ .position = _player->position, .shape = rmp::rect({ 4, 14 }) });
shot.shape.color = LIME;
shot.velocity = { 0, -PLAYER_SHOT_SPEED };
shot.collision_layer = layer::PLAYER_SHOT;
shot.collision_mask = layer::ALIEN;
shot.add<rmp::behavior::Projectile>();
}
// Only the lowest alien of a column fires. The ones above it would shoot
// their own row in the back, and one `if` against a handle says so.
void alien_shoot(rmp::Object &from, int index) {
if (index + COLUMNS < ALIENS && _aliens[index + COLUMNS]) return;
auto &shot = spawn({ .position = from.position, .shape = rmp::rect({ 4, 14 }) });
shot.shape.color = RED;
shot.velocity = { 0, ALIEN_SHOT_SPEED };
shot.collision_layer = layer::ALIEN_SHOT;
shot.collision_mask = layer::PLAYER;
shot.add<rmp::behavior::Projectile>();
}
// Between frames, a handle: a raw pointer is good for the frame it was got
// in and no longer, and an alien is the thing most likely to die between
// two of them.
rmp::Handle<rmp::Object> _player;
std::array<rmp::Handle<rmp::Object>, ALIENS> _aliens;
int _alive = 0;
float _march = 0; // how far the block has slid sideways from home
float _march_speed = 40; // units per second, and its sign is the way it goes
float _drop = 0; // and how far down
};
void OverScene::_draw() {
rmp::ui::overlay({ .dim = 0.75f }, [this] {
rmp::ui::text(_said, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play again")) rmp::Scene::change<InvadersScene>();
});
}
} // namespace
RMP_GAME(InvadersScene);https://omardev29.github.io/rmp-docs/examples/games/04_top_down.html
TopDown with eight normalised directions, Follow for the enemies, an HP bar with rmp::ui::progress (and one over every enemy with rmp::ui::at(), wherever it has walked to), and what you can only say with layers: the player's shot misses the player, enemies pass through each other but not walls, and the doorway out sees the player and nothing else. The bits are named once, in include/layers.h.

From a clone of the framework:
rmp example 04_top_downRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
ui_accept | Enter, Space, gamepad right face down |
Every file of examples/games/04_top_down, as it is at the commit this site documents (on GitHub).
src/main.cpp 197 lines// ---------------------------------------------------------------------------
// examples/games/04_top_down -- a top-down room, with a way out.
//
// The collision layers doing the work they exist for: the player's shot does
// not hit the player, the enemies walk through each other but not through the
// walls, the door sees the player and nothing else, and what may hurt the
// player is one field rather than an `if` in a _collision. Each of those is a
// pair of bit masks, named once in include/layers.h.
//
// And a health bar over every enemy, wherever it has walked to: rmp::ui::at()
// puts a box of the interface over a point of the world.
//
// A whole level: clear the room or don't, walk out of the door, or die trying.
//
// Run it: `rmp example 04_top_down`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/object.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include "layers.h"
#include <vector>
namespace {
constexpr int ENEMIES = 5;
constexpr int ENEMY_HP = 2;
constexpr int PLAYER_HP = 5;
constexpr float DOOR_Y = 225; // the gap in the right-hand wall
constexpr float SHOT_SPEED = 520;
// The end of a level, PUSHED on top of it: the room below freezes, stays on
// screen and stops hearing the keyboard, which is what the scene stack does on
// its own -- so this is only what it says and the way out.
class OverScene : public rmp::Scene {
public:
explicit OverScene(const char *said) : _said(said) {}
void _draw() override; // below TopDownScene, which it starts again
private:
const char *_said;
};
class TopDownScene : public rmp::Scene {
public:
void _ready() override {
background = Color{ 22, 20, 24, 255 };
// The floor: an object drawn below everything else, and out of the
// collision pass entirely -- layer 0 and mask 0 say "I am scenery".
auto &floor =
spawn({ .position = { 400, 225 }, .size = { 720, 370 }, .layer = -10 });
floor.shape.color = Color{ 62, 52, 44, 255 };
floor.collision_layer = 0;
floor.collision_mask = 0;
add_wall({ 400, 20 }, { 800, 40 });
add_wall({ 400, 430 }, { 800, 40 });
add_wall({ 20, 225 }, { 40, 450 });
// The right-hand wall, in two pieces, and the gap between them is the
// way out.
add_wall({ 780, 90 }, { 40, 180 });
add_wall({ 780, 360 }, { 40, 180 });
add_door();
auto &player =
spawn({ .position = { 200, 225 }, .shape = rmp::rect({ 26, 26 }) });
player.shape.color = rmp::ui::current_theme().primary;
player.solid = true;
player.collision_layer = layer::PLAYER;
player.collision_mask = layer::WORLD | layer::ENEMY | layer::TRIGGER;
// Eight directions, normalised, so the diagonal is not 41 % faster.
player.add<rmp::behavior::TopDown>({ .speed = 240 });
// What may hurt it is one field, `hurt_by`: without it a Health is a
// hit-point counter that nothing ever reduces.
player.add<rmp::behavior::Health>({
.hp = PLAYER_HP,
.invulnerable_for = 0.8f,
.destroy_on_death = false, // it stays on screen under the overlay
.on_death = [](rmp::Object &) { rmp::Scene::push<OverScene>("You died"); },
.hurt_by = layer::ENEMY,
});
_player = player.handle();
for (int i = 0; i < ENEMIES; ++i) add_enemy(560 + static_cast<float>(i) * 30);
}
void _update(float) override {
if (rmp::input::just_pressed("ui_accept")) shoot();
}
void _draw() override {
auto health = _player->get<rmp::behavior::Health>();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::row({ .gap = 16 }, [&] {
rmp::ui::progress(static_cast<float>(health->hp) / PLAYER_HP,
{ .width = 150, .fill = rmp::ui::current_theme().danger });
rmp::ui::text(TextFormat("Enemies %d", _enemies));
});
// A bar over each enemy still standing. at() projects the point
// through the scene's camera -- so the bar stays on the enemy however
// the world is scrolled, zoomed or stretched -- and puts the box's
// bottom centre on it, lifted clear of the circle by the offset. What
// it paints does not take the pointer: a click on the enemy is still
// the enemy's.
const rmp::ui::ProgressOptions bar{ .width = 24,
.height = 5,
.fill = rmp::ui::current_theme().danger };
for (const rmp::Handle<rmp::Object> &foe : _foes) {
const auto enemy = foe.get();
if (!enemy) continue; // shot down: its Health destroyed it
const float hp =
static_cast<float>(enemy->get<rmp::behavior::Health>()->hp) / ENEMY_HP;
rmp::ui::at(enemy->position, { .offset = { 0, -18 } },
[&] { rmp::ui::progress(hp, bar); });
}
rmp::ui::end();
}
private:
void add_wall(Vector2 at, Vector2 size) {
auto &wall = spawn({ .position = at, .size = size });
wall.solid = true;
wall.immovable = true;
wall.collision_layer = layer::WORLD;
wall.collision_mask = 0;
wall.shape.color = DARKGRAY;
}
// The way out: not solid, so it is walked INTO rather than bumped against,
// and on a layer of its own that only the player's bit is in -- an enemy
// standing in the doorway does not finish the level.
void add_door() {
auto &door = spawn({ .position = { 780, DOOR_Y }, .size = { 34, 90 } });
door.shape.color = GOLD;
door.collision_layer = layer::TRIGGER;
door.collision_mask = layer::PLAYER;
door.on_collision([](rmp::Object &, rmp::Object &) {
rmp::Scene::push<OverScene>("Level cleared");
});
}
void add_enemy(float x) {
auto &enemy = spawn({ .position = { x, 225 }, .shape = rmp::circle(14) });
enemy.solid = true;
enemy.collision_layer = layer::ENEMY;
// Walls, bullets and the player, not other enemies: they walk through
// each other.
enemy.collision_mask = layer::WORLD | layer::BULLET | layer::PLAYER;
enemy.shape.color = MAROON;
enemy.add<rmp::behavior::Follow>({ .target = _player, .speed = 90 });
// Two hits, and only a bullet lands one: `hurt_by` is the rule, and
// on_death is what the room does about it.
enemy.add<rmp::behavior::Health>({
.hp = ENEMY_HP,
.invulnerable_for = 0.1f,
.on_death = [this](rmp::Object &) { --_enemies; },
.hurt_by = layer::BULLET,
});
++_enemies;
_foes.push_back(enemy.handle());
}
void shoot() {
// The direction the character is facing, which is what TopDown keeps.
const Vector2 aim = _player->get<rmp::behavior::TopDown>()->direction();
auto &shot = spawn({ .position = _player->position, .shape = rmp::circle(4) });
shot.shape.color = GOLD;
shot.velocity = { aim.x * SHOT_SPEED, aim.y * SHOT_SPEED };
shot.collision_layer = layer::BULLET;
shot.collision_mask = layer::ENEMY | layer::WORLD; // never the player
shot.add<rmp::behavior::Projectile>();
shot.add<rmp::behavior::Lifespan>({ .seconds = 1.5f });
}
// Between frames, a handle -- and Follow takes one for the same reason:
// what is being chased is the thing most likely to die while it is chased.
rmp::Handle<rmp::Object> _player;
std::vector<rmp::Handle<rmp::Object>> _foes; // for their health bars
int _enemies = 0;
};
void OverScene::_draw() {
rmp::ui::overlay({ .dim = 0.75f }, [this] {
rmp::ui::text(_said, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play again")) rmp::Scene::change<TopDownScene>();
});
}
} // namespace
RMP_GAME(TopDownScene);include/layers.h 17 lines#pragma once
// ---------------------------------------------------------------------------
// Who is what, in one place.
//
// One bit per kind of thing. Three fields speak these numbers:
// rmp::Object::collision_layer (what I am), rmp::Object::collision_mask (what
// I collide with) and rmp::behavior::Health::hurt_by (what may hurt me). A
// header of its own, because a second scene file would need exactly these.
// ---------------------------------------------------------------------------
namespace layer {
inline constexpr unsigned PLAYER = 1u << 0;
inline constexpr unsigned ENEMY = 1u << 1;
inline constexpr unsigned BULLET = 1u << 2;
inline constexpr unsigned WORLD = 1u << 3;
inline constexpr unsigned TRIGGER = 1u << 4; // the door: it sees the player, nothing else
} // namespace layerhttps://omardev29.github.io/rmp-docs/examples/games/05_endless_runner.html
Parallax, Runner, a Spawner by distance and a camera that follows, with a little smoothing. No background loop, no distance counter, no camera arithmetic. Read it for what is not there. Its art is in its own resources/, drawn by tools/make_example_art.py.

From a clone of the framework:
rmp example 05_endless_runnerEvery file of examples/games/05_endless_runner, as it is at the commit this site documents (on GitHub).
src/main.cpp 162 lines// ---------------------------------------------------------------------------
// examples/games/05_endless_runner -- an endless runner.
//
// Worth reading for what is NOT here: no background loop, no modulo of a
// texture width, no distance counter, no camera arithmetic, no obstacle
// recycling.
//
// What is left is: what art is in the background, how fast the player runs, how
// much it accelerates, how often a rock appears, and what a rock does to you.
// That is the game.
//
// The camera is what makes it a runner rather than a treadmill: it FOLLOWS the
// player, every parallax layer reads it, and the rocks stand still in the world
// while the view goes past them.
//
// Run it: `rmp example 05_endless_runner`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/behavior.h>
#include <rmp/object.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
namespace {
namespace layer {
constexpr unsigned PLAYER = 1u << 0;
constexpr unsigned GROUND = 1u << 1;
constexpr unsigned ROCK = 1u << 2;
} // namespace layer
constexpr float GROUND_TOP = 360; // where ground.png starts, and the floor with it
// The end of a run, PUSHED on top of it: the world below freezes, stays on
// screen -- distance and all -- and stops hearing the keyboard, which is what
// the scene stack does on its own. So this is only what it says and the way
// out.
class OverScene : public rmp::Scene {
public:
explicit OverScene(const char *said) : _said(said) {}
void _draw() override; // below RunnerScene, which it starts again
private:
const char *_said;
};
class RunnerScene : public rmp::Scene {
public:
void _ready() override {
// Three layers, each at its own speed, each repeating itself. They read
// the camera, so nothing here has to tell them it moved.
add_layer("sky.png", 0.1f, 0);
add_layer("hills.png", 0.4f, 120);
add_layer("ground.png", 1.0f, GROUND_TOP);
auto &player = spawn({ .position = { 120, 300 } });
player.sprite.texture = rmp::assets::load_texture("runner.png");
// The picture is 36x54 and includes air; the box that collides is not.
player.collider = rmp::rect({ 26, 48 });
player.collision_layer = layer::PLAYER;
player.collision_mask = layer::GROUND | layer::ROCK;
player.add<rmp::behavior::Runner>({ .speed = 320, .accelerate = 6 });
// One rock and it is over. `hurt_by` is what makes touching a rock
// cost something.
player.add<rmp::behavior::Health>({
.hp = 1,
.invulnerable_for = 0,
.destroy_on_death = false, // it stays on screen under the overlay
.on_death = [](rmp::Object &) { rmp::Scene::push<OverScene>("Ouch"); },
.hurt_by = layer::ROCK,
});
_player = player.handle();
// The camera follows the runner, and `limits` keeps it level: a zero
// width leaves x free, and a height of exactly the view pins y. A camera
// that followed the jump would take the ground and the sky up with it.
camera.follow = _player;
camera.limits = { 0, 0, 0, RMP_WINDOW_HEIGHT };
// And a little give: the camera catches up at a rate, so the runner
// leads the view by a few pixels at speed instead of being nailed to
// its centre. A rate per second, the same at 30 and at 144 Hz.
camera.smoothing = 12;
add_ground();
add_rocks();
}
void _update(float) override {
// The floor travels with the runner, so the strip under the art is
// always there. One line instead of a mile of collider.
_ground->position.x = _player->position.x;
}
void _draw() override {
// Ten world units to the metre.
const float distance = _player->get<rmp::behavior::Runner>()->distance();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::text(TextFormat("%d m", static_cast<int>(distance / 10)),
{ .size = 40 });
rmp::ui::end();
}
private:
void add_layer(const char *art, float factor, float y) {
spawn({ .layer = -10 })
.add<rmp::behavior::Parallax>({
.texture = art,
.factor = factor,
.y = y,
});
}
void add_ground() {
auto &floor =
spawn({ .position = { 400, GROUND_TOP + 60 }, .size = { 2400, 120 } });
floor.visible = false; // ground.png is the picture; this is the floor
floor.solid = true;
floor.immovable = true;
floor.collision_layer = layer::GROUND;
floor.collision_mask = 0;
_ground = floor.handle();
}
// One rock every 520 units travelled, not every N seconds: by time, the
// rocks would spread further apart the faster you go, and the game would
// get easier as it speeds up.
void add_rocks() {
spawn().add<rmp::behavior::Spawner>({
.every_distance = 520,
.jitter = 120,
.max_alive = 8, // a live cap: it goes down again as they are dropped
.track = _player,
.on_spawn =
[](rmp::Scene &scene, Vector2 at) {
auto &rock = scene.spawn({ .position = { at.x + 520, 330 } });
rock.sprite.texture = rmp::assets::load_texture("rock.png");
rock.collider = rmp::rect({ 30, 52 });
rock.collision_layer = layer::ROCK;
rock.collision_mask = layer::PLAYER;
rock.edges = rmp::Edge::DESTROY; // once the view is past it
},
});
}
// Between frames, a handle. A raw pointer is good for the frame it was got
// in and no longer -- see rmp/object.h.
rmp::Handle<rmp::Object> _player;
rmp::Handle<rmp::Object> _ground;
};
void OverScene::_draw() {
rmp::ui::overlay({ .dim = 0.75f }, [this] {
rmp::ui::text(_said, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play again")) rmp::Scene::change<RunnerScene>();
});
}
} // namespace
RMP_GAME(RunnerScene);https://omardev29.github.io/rmp-docs/examples/games/06_tetris.html
The honest one: a Tetris is a 10×20 array and the rules of Tetris, and the framework does not pretend otherwise. What it does contribute is named at the top of the file, and so is what it does not — plus a 7-bag out of rmp::random, which is what makes the same seed the same game, and the best score kept between sessions with rmp::save.

From a clone of the framework:
rmp example 06_tetrisRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
move_left | A, ←, gamepad left face left |
move_right | D, →, gamepad left face right |
ui_accept | Enter, Space, gamepad right face down |
move_down | S, ↓, gamepad left face down |
Every file of examples/games/06_tetris, as it is at the commit this site documents (on GitHub).
src/main.cpp 280 lines// ---------------------------------------------------------------------------
// examples/games/06_tetris -- Tetris.
//
// A Tetris is a 10x20 grid and the rules of Tetris, and that is what this file
// is: the framework does not abstract it, because a Tetromino behavior would be
// this game with another name. What the framework does contribute:
//
// scenes play, and a game over pushed on top of it; the board below
// freezes because that is what the scene stack does.
// rmp::ui the score, and the button that starts again.
// rmp::input named actions for move, rotate and soft drop.
// rmp::random the 7-bag, so the same seed is the same game.
// rmp::save the best score, kept between sessions. There is no `if`
// around the read: the first time there is no save, and an
// empty Value reads as the default.
//
// Run it: `rmp example 06_tetris`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/input.h>
#include <rmp/random.h>
#include <rmp/save.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <array>
#include <utility>
namespace {
constexpr int WIDE = 10;
constexpr int TALL = 20;
constexpr float CELL = 20;
constexpr Vector2 ORIGIN{ 300, 30 };
constexpr Vector2 PREVIEW{ 72, 132 }; // where the next piece is shown
constexpr int SQUARE = 1; // the O, the one piece that must not turn
constexpr int EMPTY = -1; // a cell of the board with nothing in it
// The seven pieces, as offsets from their pivot. Four rotations are worked out
// rather than tabulated, because rotating a coordinate is two lines.
using Cells = std::array<std::array<int, 2>, 4>; // (x, y) of each of the four
struct Piece {
Cells cells;
Color color;
};
constexpr std::array<Piece, 7> PIECES{ {
{ { { { -1, 0 }, { 0, 0 }, { 1, 0 }, { 2, 0 } } }, SKYBLUE }, // I
{ { { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } } }, GOLD }, // O
{ { { { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } } }, VIOLET }, // T
{ { { { -1, 1 }, { 0, 1 }, { 0, 0 }, { 1, 0 } } }, LIME }, // S
{ { { { -1, 0 }, { 0, 0 }, { 0, 1 }, { 1, 1 } } }, RED }, // Z
{ { { { -1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 } } }, BLUE }, // J
{ { { { 1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 } } }, ORANGE }, // L
} };
// The end of a game, PUSHED on top of it: the board below freezes, stays on
// screen and stops hearing the keyboard, which is what the scene stack does on
// its own -- so this is only what it says and the way out. Its one button has
// the focus already, so Enter or the gamepad start again too.
class OverScene : public rmp::Scene {
public:
explicit OverScene(const char *said) : _said(said) {}
void _draw() override; // below TetrisScene, which it starts again
private:
const char *_said;
};
class TetrisScene : public rmp::Scene {
public:
void _ready() override {
background = Color{ 12, 12, 18, 255 };
for (auto &row : _board) {
for (int &cell : row) cell = EMPTY;
}
_next = from_bag();
next_piece();
rmp::Value saved;
rmp::save::read("tetris", saved);
_best = saved["best_lines"].as_int(0);
}
void _update(float delta) override {
if (rmp::input::just_pressed("move_left")) try_move(-1, 0);
if (rmp::input::just_pressed("move_right")) try_move(1, 0);
if (rmp::input::just_pressed("ui_accept")) try_rotate();
// Down a row every _seconds_per_row, twelve times as often while the
// player holds down.
_since_last_row += delta * (rmp::input::pressed("move_down") ? 12.0f : 1.0f);
if (_since_last_row < _seconds_per_row) return;
_since_last_row = 0;
if (!try_move(0, 1)) lock_piece();
}
void _draw() override {
// The well, drawn rather than made of objects: two hundred cells that
// never move on their own do not need an object's life each. Through
// the camera, in world units, so it stays where the design put it on a
// window of any size.
BeginMode2D(camera.raylib());
const Rectangle well{ ORIGIN.x, ORIGIN.y, WIDE * CELL, TALL * CELL };
DrawRectangleRec(well, Color{ 22, 22, 32, 255 });
DrawRectangleLinesEx(
Rectangle{ well.x - 4, well.y - 4, well.width + 8, well.height + 8 }, 4,
rmp::ui::current_theme().border);
for (int y = 0; y < TALL; ++y) {
for (int x = 0; x < WIDE; ++x) {
if (_board[y][x] == EMPTY) continue;
draw_cell(x, y, PIECES[_board[y][x]].color);
}
}
for (const auto &cell : _shape) {
draw_cell(_x + cell[0], _y + cell[1], PIECES[_current].color);
}
for (const auto &cell : PIECES[_next].cells) {
draw_block(PREVIEW.x + static_cast<float>(cell[0]) * CELL,
PREVIEW.y + static_cast<float>(cell[1]) * CELL,
PIECES[_next].color);
}
EndMode2D();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::text(TextFormat("Lines %d", _lines), { .size = rmp::ui::Size::LARGE });
rmp::ui::text(TextFormat("Best %d", _best),
{ .color = rmp::ui::ColorRole::MUTED });
rmp::ui::text("Next", { .color = rmp::ui::ColorRole::MUTED });
rmp::ui::end();
}
private:
static void draw_block(float x, float y, Color color) {
DrawRectangle(static_cast<int>(x), static_cast<int>(y),
static_cast<int>(CELL) - 1, static_cast<int>(CELL) - 1, color);
}
static void draw_cell(int x, int y, Color color) {
draw_block(ORIGIN.x + static_cast<float>(x) * CELL,
ORIGIN.y + static_cast<float>(y) * CELL, color);
}
bool fits(const Cells &cells, int cx, int cy) const {
for (int i = 0; i < 4; ++i) {
const int x = cx + cells[i][0];
const int y = cy + cells[i][1];
if (x < 0 || x >= WIDE || y >= TALL) return false;
if (y >= 0 && _board[y][x] != EMPTY) return false;
}
return true;
}
bool try_move(int dx, int dy) {
if (!fits(_shape, _x + dx, _y + dy)) return false;
_x += dx;
_y += dy;
return true;
}
void try_rotate() {
// The O turns about a corner and not about its middle, so turning it
// would slide it one column. No Tetris turns it.
if (_current == SQUARE) return;
// A quarter turn about the pivot: (x, y) becomes (-y, x).
Cells turned{};
for (int i = 0; i < 4; ++i) {
turned[i][0] = -_shape[i][1];
turned[i][1] = _shape[i][0];
}
if (!fits(turned, _x, _y)) return;
_shape = turned;
}
void lock_piece() {
for (const auto &cell : _shape) {
const int x = _x + cell[0];
const int y = _y + cell[1];
if (y < 0) {
game_over();
return;
}
_board[y][x] = _current;
}
clear_lines();
next_piece();
}
// From the bottom up. A full row is removed and everything above falls
// into it, so the same row is looked at again before moving on.
void clear_lines() {
int y = TALL - 1;
while (y >= 0) {
if (!row_full(y)) {
--y;
continue;
}
remove_row(y);
++_lines;
if (_seconds_per_row > 0.12f) _seconds_per_row -= 0.01f; // faster, to a limit
}
}
bool row_full(int y) const {
for (int x = 0; x < WIDE; ++x) {
if (_board[y][x] == EMPTY) return false;
}
return true;
}
void remove_row(int y) {
for (int row = y; row > 0; --row) {
for (int x = 0; x < WIDE; ++x) _board[row][x] = _board[row - 1][x];
}
for (int x = 0; x < WIDE; ++x) _board[0][x] = EMPTY;
}
// A 7-bag: every seven pieces are the seven pieces, in a shuffled order.
// One of seven at random would deal four S's in a row often enough to be
// unfair. Shuffled with rmp::random, so the same seed is the same game.
int from_bag() {
if (_bag_left == 0) {
for (int i = 0; i < 7; ++i) _bag[i] = i;
for (int i = 6; i > 0; --i)
std::swap(_bag[i], _bag[rmp::random::index(i + 1)]);
_bag_left = 7;
}
--_bag_left;
return _bag[_bag_left];
}
void next_piece() {
_current = _next;
_next = from_bag();
_shape = PIECES[_current].cells;
_x = WIDE / 2;
_y = 0;
// The other way a Tetris ends: there is no room for what comes next.
if (!fits(_shape, _x, _y)) game_over();
}
// The one number that outlives a game, and the whole of saving it.
void game_over() {
const bool record = _lines > _best;
if (record) {
_best = _lines;
rmp::Value v;
v["best_lines"] = _best;
rmp::save::write("tetris", v);
}
rmp::Scene::push<OverScene>(record ? "New best!" : "Game over");
}
std::array<std::array<int, WIDE>, TALL>
_board{}; // EMPTY, or the index of the piece that left it
int _current = 0; // which of PIECES is falling
Cells _shape{}; // its cells, as turned so far
int _x = 0; // and where its pivot is on the board
int _y = 0;
int _next = 0;
std::array<int, 7> _bag{};
int _bag_left = 0;
int _lines = 0;
int _best = 0;
float _since_last_row = 0;
float _seconds_per_row = 0.5f;
};
void OverScene::_draw() {
rmp::ui::overlay({ .dim = 0.75f }, [this] {
rmp::ui::text(_said, { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Play again")) rmp::Scene::change<TetrisScene>();
});
}
} // namespace
RMP_GAME(TetrisScene);https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html
A level designed in LDtk. Three levels side by side in one world — a meadow, a desert, a snowfield — with Kenney's Pixel Platformer art. The player stands on the IntGrid and runs along it without catching on a seam, every coin, enemy, sign, door and platform is placed in the editor and arrives through on_object() with its fields (a patrol is an Array<Point>, a platform's destination a Point, the key names its door with an EntityRef), and walking off the edge of a level is neighbour_at() and a scene change. Music, effects, a shaking camera held to each level's edges, the run in an rmp::global, the best one in rmp::save. A window of another shape shows more of the world (Stretch::EXPAND, so the zoom is one constant), and the pause is a scene of its own — the level blurred behind overlay() — reached by Escape, P, a gamepad's Start or a HUD button for a finger, which Space, the jump, does not press. The art, the sounds and the first version of world.ldtk come out of tools/make_platformer_assets.py; the level is LDtk's from there on. One file per scene under src/scenes/, the things in the level under src/objects/.

From a clone of the framework:
rmp example 07_platformerRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
jump | Space, W, ↑, gamepad right face down |
pause | Esc, P, gamepad middle right |
Every file of examples/games/07_platformer, as it is at the commit this site documents (on GitHub).
src/main.cpp 51 lines// ---------------------------------------------------------------------------
// examples/games/07_platformer -- a platformer whose levels are made in LDtk.
//
// Three levels side by side in one LDtk world -- a meadow, a desert and a
// snowfield -- with Kenney's Pixel Platformer art, walked through from left to
// right to the flag.
//
// What the framework does here, and therefore what is NOT in these files:
//
// rmp::Tilemap resources/world.ldtk, loaded by name. The scene draws it,
// and the player stands on its IntGrid `Solid` cells, and on
// any tile tagged `Solid` in the tileset (the meadow's crate).
// No collision code anywhere in the game.
// entities every coin, enemy, sign and door is placed in LDtk and
// arrives through map.on_object(): a patrol is an
// Array<Point> drawn in the editor, a platform's destination
// is a Point, the key names its door with an EntityRef, a
// sign's text is a String and its arrow an Enum.
// the world walking off the right edge of a level is
// map.neighbour_at() and a scene change; the player arrives
// at the same world position in the next one.
// Platformer the run, the jump, coyote time and the buffered jump.
// rmp::Camera follows with smoothing, stops at the level's edges
// (`limits = map.bounds()`), and shakes when you are hit.
// the stretch Stretch::EXPAND: a window of another shape shows more of
// the world rather than bars, so the zoom is one constant.
// rmp::ui the menus; the pause, the level blurred behind it by
// overlay(); and the HUD's Pause button for a finger, which
// Space -- the jump -- does not press.
// rmp::audio the music and the effects, by name. Asking for the track
// that is already playing does not restart it, so the music
// carries on from one level to the next.
// rmp::save the best run, kept between sessions.
// rmp::global the run itself -- lives, coins, the clock, what has been
// collected -- which has to outlive each level's scene.
//
// What is left is the game: what a coin is worth, what a stomp does, how long
// you are safe after a hit, and when you have won.
//
// Open resources/world.ldtk in LDtk 1.5 to change the levels; the game reads
// whatever it saves. Paint IntGrid `Solid` and the auto-layer rules draw the
// edges and corners; a level's `biome` (Grass, Sand or Snow) picks the terrain.
//
// Run it: `rmp example 07_platformer`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "game.h"
RMP_GAME(game::TitleScene);include/game.h 161 lines#pragma once
// ---------------------------------------------------------------------------
// What every file of the platformer shares: the collision layers, the run
// that outlives a level, the four scenes, and two helpers for the art.
// ---------------------------------------------------------------------------
#include <rmp/scene.h>
#include <raylib.h>
#include <string>
#include <string_view>
#include <vector>
namespace game {
inline constexpr float TILE = 18; // the grid of tiles.png and of every level
// How much of the world is on screen: twelve and a half rows of tiles at the
// [window] size, each pixel of the art two of the screen's. A window of another
// shape is rmp::app::Stretch::EXPAND's (TitleScene::_ready()): the view scaled
// to fit it, and MORE of the world showing the way the window is longer --
// never fewer rows than these. So the zoom is a constant, and nothing here
// reads the window's size.
inline constexpr float VIEW_HEIGHT = 225;
inline constexpr float ZOOM = RMP_WINDOW_HEIGHT / VIEW_HEIGHT;
// The tiles of tiles.png this game draws by hand, by index (20 to a row).
namespace tiles {
inline constexpr int KEY = 27;
inline constexpr int DOOR = 28;
inline constexpr int HEART = 44;
inline constexpr int HEART_EMPTY = 46;
inline constexpr int PLATFORM_LEFT = 48;
inline constexpr int PLATFORM_MIDDLE = 49;
inline constexpr int PLATFORM_RIGHT = 50;
inline constexpr int SPIKES = 68;
inline constexpr int SIGN = 86;
inline constexpr int SIGN_LEFT = 87;
inline constexpr int SIGN_RIGHT = 88;
inline constexpr int FLAG = 111; // and 112, the other half of its wave
inline constexpr int POLE = 131;
inline constexpr int COIN = 151;
inline constexpr int POINT = 157; // the decimal point
inline constexpr int TIMES = 158; // the x in "x 12"
inline constexpr int DIGIT_0 = 160; // to 169
} // namespace tiles
// Who notices whom. The player is on its own layer and everything that can
// touch it looks at that layer; nothing else needs to know about anything else.
namespace layer {
inline constexpr unsigned PLAYER = 1u << 0;
inline constexpr unsigned ENEMY = 1u << 1;
inline constexpr unsigned PICKUP = 1u << 2; // coins and keys
inline constexpr unsigned HAZARD = 1u << 3; // spikes
inline constexpr unsigned SOLID = 1u << 4; // moving platforms and doors
inline constexpr unsigned GOAL = 1u << 5;
inline constexpr unsigned SIGN = 1u << 6;
} // namespace layer
// THE RUN: what survives walking from one level into the next, and dying.
// A level is a scene, and a scene keeps nothing when it changes, so this is an
// rmp::global<Run>() -- and `gone` is what stops a coin collected in the
// Meadow from being there again when the player walks back to it.
struct Run {
int lives = 3;
int coins = 0;
float seconds = 0;
// The iids of the coins, keys, enemies and doors that are no more.
std::vector<std::string> gone;
// The iids of the doors the player holds a key for.
std::vector<std::string> keys;
};
Run &run();
void new_run();
bool contains(const std::vector<std::string> &list, std::string_view iid);
// The best run, as rmp::save keeps it: the most coins, and on a tie the
// faster time. Returns true when this one is a new best (and keeps it).
struct Best {
int coins = -1; // -1: nobody has finished yet
float seconds = 0;
};
Best best();
bool keep_if_best(int coins, float seconds);
// A tile of tiles.png by its index, drawn with its top-left corner at `at`.
void draw_tile(int index, Vector2 at, Color tint = WHITE, bool flip_x = false);
// The same tile `scale` times its size, for the HUD.
void draw_icon(int index, Vector2 at, float scale);
// A number in the sheet's own pixel digits, at `scale`, left to right from `at`.
void draw_number(int value, Vector2 at, float scale);
// "73.4" as tiles: the run clock.
void draw_seconds(float seconds, Vector2 at, float scale);
// ---------------------------------------------------------------------------
// The scenes
// ---------------------------------------------------------------------------
class TitleScene : public rmp::Scene {
public:
void _ready() override;
void _update(float delta) override;
void _draw() override;
private:
Best _best; // read once: a file, not something to ask sixty times a second
float _clock = 0;
};
// Where the player comes into a level from: nowhere (a new game, or a level
// started from its Player entity), or another level, at a world position --
// which is the same place in this one, because the levels share the world.
struct Entry {
bool carried = false;
Vector2 position{};
Vector2 velocity{};
};
class LevelScene : public rmp::Scene {
public:
explicit LevelScene(std::string level, Entry entry = {});
void _ready() override;
void _update(float delta) override;
void _draw() override;
// Called by the player when it is hit, and by this scene when it falls.
void lose_life();
void win();
private:
void respawn();
std::string _level;
Entry _entry;
Vector2 _start{}; // where a lost life puts the player back
rmp::Handle<rmp::Object> _player;
bool _over = false;
};
// Pushed on top of the level by the HUD's Pause button, Escape, P or a
// gamepad's Start: the level stays on screen, frozen and blurred, under it.
class PauseScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};
// Pushed on top of the level when it ends: the level stays on screen, frozen,
// under it -- the scene stack's defaults, and no code here.
class EndScene : public rmp::Scene {
public:
EndScene(bool won, bool record);
void _draw() override;
private:
bool _won;
bool _record;
};
} // namespace gameinclude/objects.h 170 lines#pragma once
// ---------------------------------------------------------------------------
// Everything that moves, hurts or can be picked up. Each one is placed in
// LDtk and built from its rmp::MapObject by a factory in src/scenes/level.cpp;
// what it does when the player touches it is its own _collision().
// ---------------------------------------------------------------------------
#include "game.h"
#include <rmp/object.h>
#include <raylib.h>
#include <string>
#include <vector>
namespace game {
class Player : public rmp::Object {
public:
void _ready() override;
void _update(float delta) override;
// A life, a knock away from `from_x`, and a moment of grace.
void hurt(float from_x);
// Off an enemy's head.
void bounce();
// Coming down onto the top of `other`: a stomp rather than a bump.
[[nodiscard]] bool falling_onto(const rmp::Object &other) const;
[[nodiscard]] bool hurting() const { return _knocked > 0; }
private:
float _grace = 0; // seconds of not being hurt again
float _knocked = 0; // seconds without control after a hit
int _jumps_heard = 0; // the Platformer's jump count when the sound last played
};
// What walks and flies. The same rules for both when the player touches one:
// from above it is stomped, from anywhere else it hurts.
class Enemy : public rmp::Object {
public:
std::string iid;
bool stompable = true;
void _collision(rmp::Object &other) override;
void _update(float delta) override;
protected:
virtual void patrol(float delta) = 0;
virtual const char *squashed_tag() const { return nullptr; }
private:
float _dying = -1; // seconds left of the squashed frame, -1 = alive
};
// Back and forth along its floor, between the x of its first and last patrol
// Points. The floor is where LDtk put it; the Points say where to turn.
class Walker : public Enemy {
public:
float speed = 40;
float left = 0;
float right = 0;
void _ready() override;
protected:
void patrol(float delta) override;
const char *squashed_tag() const override { return "squash"; }
private:
int _direction = -1;
};
// Along the whole route of its Points, there and back again.
class Bat : public Enemy {
public:
float speed = 50;
std::vector<Vector2> route;
void _ready() override;
protected:
void patrol(float delta) override;
private:
std::size_t _next = 1;
int _step = 1;
};
// From where LDtk put it to its `to` Point and back, carrying whoever stands
// on it. Solid and immovable: the player lands on it like on the floor.
class Platform : public rmp::Object {
public:
void _ready() override;
Vector2 from{};
Vector2 to{};
float speed = 40;
rmp::Handle<rmp::Object> rider; // the only one who can stand on it
void _update(float delta) override;
void _draw() override;
private:
void carry_rider(Vector2 before);
float _travelled = 0;
int _direction = 1;
float _waiting = 0; // at either end, long enough to get on or off
};
class Coin : public rmp::Object {
public:
void _ready() override;
std::string iid;
int value = 1;
void _collision(rmp::Object &other) override;
};
// A key opens the door its `opens` field names -- an EntityRef in LDtk, an
// iid here, compared against the door's own.
class Key : public rmp::Object {
public:
void _ready() override;
std::string iid;
std::string opens;
void _update(float delta) override;
void _draw() override;
void _collision(rmp::Object &other) override;
private:
float _clock = 0;
};
class Door : public rmp::Object {
public:
void _ready() override;
std::string iid;
void _draw() override;
void _collision(rmp::Object &other) override;
};
class Spikes : public rmp::Object {
public:
void _ready() override;
void _draw() override;
void _collision(rmp::Object &other) override;
};
// A wooden sign that says something while the player stands near it.
class Sign : public rmp::Object {
public:
void _ready() override;
std::string text;
int tile = tiles::SIGN;
void _update(float delta) override;
void _draw() override;
void _collision(rmp::Object &other) override;
private:
float _player_near = 0;
};
class Goal : public rmp::Object {
public:
void _ready() override;
void _update(float delta) override;
void _draw() override;
void _collision(rmp::Object &other) override;
private:
float _waving = 0; // seconds, the flag's own clock
};
} // namespace gamesrc/art.cpp 94 lines// The run, the best run, and drawing from tiles.png.
#include "game.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/save.h>
#include <algorithm>
#include <cmath>
#include <string>
namespace game {
namespace {
// A global and not a static texture: globals are destroyed while the window is
// still open, and a texture freed after the GPU context is gone is a crash.
struct Art {
rmp::Texture tiles = rmp::assets::load_texture("tiles.png");
};
Rectangle source_of(int index) {
const int columns = 20;
const int column = index % columns;
const int row = index / columns;
return Rectangle{ static_cast<float>(column) * TILE, static_cast<float>(row) * TILE,
TILE, TILE };
}
void draw_scaled_tile(int index, Vector2 at, float scale) {
const Texture2D &tiles = rmp::global<Art>().tiles;
DrawTexturePro(tiles, source_of(index),
Rectangle{ at.x, at.y, TILE * scale, TILE * scale }, Vector2{}, 0,
WHITE);
}
} // namespace
Run &run() { return rmp::global<Run>(); }
void new_run() { rmp::global<Run>() = Run{}; }
bool contains(const std::vector<std::string> &list, std::string_view iid) {
return std::find(list.begin(), list.end(), iid) != list.end();
}
Best best() {
rmp::Value saved;
rmp::save::read("platformer", saved);
return Best{ saved["coins"].as_int(-1), saved["seconds"].as_float(0) };
}
bool keep_if_best(int coins, float seconds) {
const Best before = best();
const bool better =
coins > before.coins || (coins == before.coins && seconds < before.seconds);
if (!better) return false;
rmp::Value v;
v["coins"] = coins;
v["seconds"] = seconds;
rmp::save::write("platformer", v);
return true;
}
void draw_icon(int index, Vector2 at, float scale) { draw_scaled_tile(index, at, scale); }
void draw_tile(int index, Vector2 at, Color tint, bool flip_x) {
const Texture2D &tiles = rmp::global<Art>().tiles;
Rectangle source = source_of(index);
if (flip_x) source.width = -source.width;
DrawTextureRec(tiles, source, at, tint);
}
// Each digit sits in the middle of its cell, so the advance (11 px) is
// narrower than the cell.
void draw_number(int value, Vector2 at, float scale) {
const std::string digits = std::to_string(std::max(0, value));
for (std::size_t i = 0; i < digits.size(); ++i) {
draw_scaled_tile(tiles::DIGIT_0 + (digits[i] - '0'),
{ at.x + (static_cast<float>(i) * 11 * scale), at.y }, scale);
}
}
void draw_seconds(float seconds, Vector2 at, float scale) {
const int tenths = static_cast<int>(std::floor(seconds * 10));
draw_number(tenths / 10, at, scale);
const float after =
static_cast<float>(std::to_string(tenths / 10).size()) * 11 * scale;
draw_scaled_tile(tiles::POINT, { at.x + after - (3 * scale), at.y }, scale);
draw_number(tenths % 10, { at.x + after + (5 * scale), at.y }, scale);
}
} // namespace gamesrc/objects/enemies.cpp 97 lines// The walker and the bat, and the one rule they share: stomped from above,
// hurtful from anywhere else.
#include "game.h"
#include "objects.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <cmath>
namespace game {
void Enemy::_collision(rmp::Object &other) {
if (_dying >= 0 || (other.collision_layer & layer::PLAYER) == 0) return;
auto &player = static_cast<Player &>(other);
if (stompable && player.falling_onto(*this)) {
player.bounce();
rmp::audio::play("stomp");
run().gone.push_back(iid); // stomped for the rest of the run
// Out of every collision from now on, flattened for a moment, gone.
collision_layer = 0;
collision_mask = 0;
if (const char *tag = squashed_tag()) {
sprite.play(tag);
_dying = 0.4f;
} else {
flip_y = true; // what has no squashed frame falls out of the sky
gravity_scale = 1;
_dying = 1.0f;
}
return;
}
player.hurt(position.x);
}
void Enemy::_update(float delta) {
if (_dying >= 0) {
_dying -= delta;
if (_dying < 0) destroy();
return;
}
patrol(delta);
}
void Walker::_ready() {
sprite.sheet = rmp::assets::load_sheet("walker.aseprite");
sprite.play("walk");
collider = rmp::rect({ 14, 12 });
collider.offset = { 0, 6 }; // the beetle is the bottom half of its frame
collision_layer = layer::ENEMY;
collision_mask = layer::PLAYER;
}
void Walker::patrol(float delta) {
position.x += static_cast<float>(_direction) * speed * delta;
if (position.x <= left) {
position.x = left;
_direction = 1;
} else if (position.x >= right) {
position.x = right;
_direction = -1;
}
flip_x = _direction > 0;
}
void Bat::_ready() {
sprite.sheet = rmp::assets::load_sheet("bat.aseprite");
sprite.play("fly");
collider = rmp::rect({ 16, 12 });
collision_layer = layer::ENEMY;
collision_mask = layer::PLAYER;
}
void Bat::patrol(float delta) {
if (route.size() < 2) return;
const Vector2 target = route[_next];
const Vector2 to{ target.x - position.x, target.y - position.y };
const float distance = std::sqrt((to.x * to.x) + (to.y * to.y));
const float step = speed * delta;
if (distance <= step) {
position = target;
// There and back along the route: turn round at either end.
if (_next + 1 >= route.size()) _step = -1;
if (_next == 0) _step = 1;
if (_step > 0)
++_next;
else
--_next;
return;
}
position.x += to.x / distance * step;
position.y += to.y / distance * step;
if (std::fabs(to.x) > 0.5f) flip_x = to.x > 0;
}
} // namespace gamesrc/objects/player.cpp 99 lines// The player. rmp::behavior::Platformer does the running and the jumping; this
// is what belongs to this game: being hit, the stomp, the sound of a jump and
// which animation to show.
#include "game.h"
#include "objects.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <cmath>
namespace game {
namespace {
// After a hit it cannot be hurt again for GRACE_SECONDS, and for KNOCK_SECONDS
// it is thrown back at KNOCK_SPEED, out of control.
constexpr float GRACE_SECONDS = 1.5f;
constexpr float KNOCK_SECONDS = 0.3f;
constexpr float KNOCK_SPEED = 110;
} // namespace
void Player::_ready() {
// Space, W or Up, or the gamepad's bottom button.
rmp::input::action("jump", KEY_SPACE, KEY_W, KEY_UP, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
sprite.sheet = rmp::assets::load_sheet("player.aseprite");
sprite.play("idle");
// The alien fills 20 px of its 24 px frame and stands on the bottom edge.
collider = rmp::rect({ 12, 20 });
collider.offset = { 0, 2 };
collision_layer = layer::PLAYER;
collision_mask = layer::ENEMY | layer::PICKUP | layer::HAZARD | layer::SOLID |
layer::GOAL | layer::SIGN;
layer = 5; // in front of everything else
add<rmp::behavior::Platformer>({
.speed = 130,
.acceleration = 1400,
.gravity = 1100,
.jump = 380, // 3.6 tiles high, 4.5 long at full speed
.jump_action = "jump",
});
}
void Player::_update(float delta) {
_grace -= delta;
_knocked -= delta;
// Thrown back after a hit: the knock wins over the controls for a moment.
if (_knocked > 0) velocity.x = velocity.x < 0 ? -KNOCK_SPEED : KNOCK_SPEED;
// Blinking while it cannot be hurt: shown for 0.12 s of every 0.2 s.
visible = _grace <= 0 || std::fmod(_grace, 0.2f) < 0.12f;
// The jump sound. Platformer counts the jumps it makes, so when the count
// goes up a jump has just happened -- a buffered or a coyote jump too.
const auto platformer = get<rmp::behavior::Platformer>();
if (platformer->ours.jumps_used > _jumps_heard)
rmp::audio::play("jump", { .volume = 0.6f });
_jumps_heard = platformer->ours.jumps_used;
if (hurting()) {
sprite.play("hurt");
} else if (!platformer->grounded()) {
sprite.play("jump");
} else if (std::fabs(velocity.x) > 10) {
sprite.play("walk");
} else {
sprite.play("idle");
}
// The art faces left: turn it round while it moves right.
if (velocity.x < -1) flip_x = false;
if (velocity.x > 1) flip_x = true;
}
void Player::hurt(float from_x) {
if (_grace > 0) return;
_grace = GRACE_SECONDS;
_knocked = KNOCK_SECONDS;
velocity = { position.x < from_x ? -KNOCK_SPEED : KNOCK_SPEED, -240 };
// The player only ever lives in a LevelScene.
static_cast<LevelScene &>(scene()).lose_life();
}
void Player::bounce() { velocity.y = -260; }
bool Player::falling_onto(const rmp::Object &other) const {
if (velocity.y <= 0) return false;
const Rectangle me = world_collider();
const Rectangle it = other.world_collider();
// The feet are in the top half of it. One frame of falling is a few pixels,
// so a stomp always lands there.
return me.y + me.height - it.y < it.height / 2;
}
} // namespace gamesrc/objects/things.cpp 228 lines// What is placed in the level and is not alive: the moving platform, coins,
// the key and its door, spikes, signs and the flag.
#include "game.h"
#include "objects.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <cmath>
namespace game {
namespace {
bool is_player(const rmp::Object &other) {
return (other.collision_layer & layer::PLAYER) != 0;
}
// The top-left corner of an object's box, which is where tiles are drawn from.
Vector2 corner(const rmp::Object &object) {
const Rectangle box = object.world_collider();
return Vector2{ box.x, box.y };
}
} // namespace
// ---- the moving platform ----------------------------------------------------
void Platform::_ready() {
// Solid and immovable: the floor, as far as the player is concerned. The
// box is LDtk's, set by the factory.
solid = true;
immovable = true;
collision_layer = layer::SOLID;
collision_mask = layer::PLAYER;
}
void Platform::_update(float delta) {
const float dx = to.x - from.x;
const float dy = to.y - from.y;
const float length = std::sqrt((dx * dx) + (dy * dy));
if (length <= 0) return;
// There and back, with a pause at either end: a lift that turns round the
// instant it arrives is level with the ledge for one frame, and nobody can
// step off in one frame.
const Vector2 before = position;
if (_waiting > 0) {
_waiting -= delta;
} else {
_travelled += static_cast<float>(_direction) * speed * delta / length;
if (_travelled >= 1 || _travelled <= 0) {
_travelled = _travelled >= 1 ? 1.0f : 0.0f;
_direction = -_direction;
_waiting = 0.6f;
}
}
position = { from.x + (dx * _travelled), from.y + (dy * _travelled) };
carry_rider(before);
}
// Whoever stands on it goes with it. Moving the platform is not enough: the
// player on top would stay where it was, and the platform would slide out from
// under its feet.
void Platform::carry_rider(Vector2 before) {
const auto player = rider.get();
if (!player) return;
const Rectangle me = world_collider();
const Rectangle them = player->world_collider();
const float feet = them.y + them.height;
// Standing on it: feet on its top as it was before this frame's move,
// within a couple of pixels, and over it across.
const Rectangle was{ me.x - (position.x - before.x), me.y - (position.y - before.y),
me.width, me.height };
const bool on_top = std::fabs(feet - was.y) < 3 && them.x + them.width > was.x &&
them.x < was.x + was.width;
// Not riding: jumping off it (on its way up), or stepping off onto a ledge
// while the platform goes down -- taking it down too would put it inside
// the ledge.
const bool jumping = player->velocity.y < 0;
const bool going_down = position.y > before.y;
const bool on_a_ledge =
scene().map.solid_in(Rectangle{ them.x, feet, them.width, 1 });
if (!on_top || jumping || (going_down && on_a_ledge)) return;
// Across by as much as it moved, and up or down to stand exactly on its top.
player->position.x += position.x - before.x;
player->position.y += me.y - feet;
}
void Platform::_draw() {
const Vector2 at = corner(*this);
draw_tile(tiles::PLATFORM_LEFT, at);
draw_tile(tiles::PLATFORM_MIDDLE, { at.x + TILE, at.y });
draw_tile(tiles::PLATFORM_RIGHT, { at.x + (2 * TILE), at.y });
}
// ---- coins, the key, the door -------------------------------------------------
void Coin::_ready() {
sprite.sheet = rmp::assets::load_sheet("coin.aseprite");
sprite.play("spin");
collider = rmp::rect({ 10, 10 });
collision_layer = layer::PICKUP;
collision_mask = layer::PLAYER;
}
void Coin::_collision(rmp::Object &other) {
if (!alive() || !is_player(other)) return;
run().coins += value;
run().gone.push_back(iid);
rmp::audio::play("coin", { .volume = 0.7f });
destroy();
}
void Key::_ready() {
collider = rmp::rect({ 14, 10 });
collision_layer = layer::PICKUP;
collision_mask = layer::PLAYER;
}
void Key::_update(float delta) { _clock += delta; }
void Key::_draw() {
// It bobs up and down, so it reads as a thing to take.
const float bob = std::sin(_clock * 3) * 2;
draw_tile(tiles::KEY, { position.x - (TILE / 2), position.y - (TILE / 2) + bob });
}
void Key::_collision(rmp::Object &other) {
if (!alive() || !is_player(other)) return;
run().keys.push_back(opens);
run().gone.push_back(iid);
rmp::audio::play("key");
destroy();
}
void Door::_ready() {
solid = true;
immovable = true;
collision_layer = layer::SOLID;
collision_mask = layer::PLAYER;
}
void Door::_draw() {
const Vector2 at = corner(*this);
// One tile per row the door is tall.
for (int row = 0; static_cast<float>(row) * TILE + 1 < world_collider().height; ++row)
draw_tile(tiles::DOOR, { at.x, at.y + static_cast<float>(row) * TILE });
}
void Door::_collision(rmp::Object &other) {
if (!alive() || !is_player(other) || !contains(run().keys, iid)) return;
run().gone.push_back(iid);
rmp::audio::play("door");
destroy();
}
// ---- what hurts, what talks, what wins ----------------------------------------
void Spikes::_ready() {
collision_layer = layer::HAZARD;
collision_mask = layer::PLAYER;
}
void Spikes::_draw() {
// The collider is the points only, the bottom of the cells; the art fills
// the cells, so it is drawn from the cells' corner.
const float width = world_collider().width + 4;
const Vector2 at{ position.x - (width / 2), position.y - (TILE / 2) };
for (int column = 0; static_cast<float>(column) * TILE + 1 < width; ++column)
draw_tile(tiles::SPIKES, { at.x + static_cast<float>(column) * TILE, at.y });
}
void Spikes::_collision(rmp::Object &other) {
if (is_player(other)) static_cast<Player &>(other).hurt(position.x);
}
void Sign::_ready() {
// The box is where the player can read it from, not the sign itself.
collider = rmp::rect({ 54, 36 });
collision_layer = layer::SIGN;
collision_mask = layer::PLAYER;
}
void Sign::_update(float delta) { _player_near -= delta; }
void Sign::_draw() {
draw_tile(tile, { position.x - (TILE / 2), position.y - (TILE / 2) });
if (_player_near <= 0 || text.empty()) return;
// World space, in raylib's default font at its own 10 px: the camera's
// zoom makes it as chunky as the art.
const int width = MeasureText(text.c_str(), 10);
const auto x = static_cast<int>(position.x) - (width / 2);
const auto y = static_cast<int>(position.y) - 30;
DrawRectangle(x - 3, y - 2, width + 6, 14, Color{ 20, 24, 40, 200 });
DrawText(text.c_str(), x, y, 10, RAYWHITE);
}
void Sign::_collision(rmp::Object &other) {
if (is_player(other)) _player_near = 0.15f;
}
void Goal::_ready() {
collider = rmp::rect({ 10, 36 });
collision_layer = layer::GOAL;
collision_mask = layer::PLAYER;
}
// The flag's clock is the delta it is handed, not GetTime(): the game's time
// is what the scene stack says it is, which is what lets a paused scene stop
// waving and a scripted run (tests/e2e/) draw the same flag every time.
void Goal::_update(float delta) { _waving += delta; }
void Goal::_draw() {
// The pole in the bottom cell, the flag waving in the top one.
const Rectangle box = world_collider();
const float left = position.x - (TILE / 2);
draw_tile(tiles::POLE, { left, box.y + box.height - TILE });
const int wave = static_cast<int>(_waving * 4) % 2; // four times a second
draw_tile(tiles::FLAG + wave, { left, box.y + box.height - (2 * TILE) });
}
void Goal::_collision(rmp::Object &other) {
if (is_player(other)) static_cast<LevelScene &>(scene()).win();
}
} // namespace gamesrc/scenes/end.cpp 35 lines// The end of a run, pushed on top of the level. The level underneath freezes
// and stays on screen, and stops hearing the keyboard -- the scene stack's
// defaults -- so this is only what it says and the two ways out, in an
// overlay: in front of the level, which it dims towards a night blue.
#include "game.h"
#include <rmp/audio.h>
#include <rmp/ui.h>
namespace game {
EndScene::EndScene(bool won, bool record) : _won(won), _record(record) {}
void EndScene::_draw() {
const Run &r = run();
rmp::ui::overlay({ .dim = 2 / 3.0f, .veil = Color{ 10, 12, 24, 255 } }, [&] {
rmp::ui::text(_won ? "You made it!" : "Game over",
{ .size = rmp::ui::Size::LARGE });
rmp::ui::text(TextFormat("%d coins in %.1f s", r.coins, r.seconds));
if (_won && _record)
rmp::ui::text("A new best!", { .color = rmp::ui::ColorRole::PRIMARY });
if (rmp::ui::button("Play again")) {
rmp::audio::play("select");
new_run();
rmp::Scene::change<LevelScene>("");
}
if (rmp::ui::button("Menu")) {
rmp::audio::play("select");
rmp::Scene::change<TitleScene>();
}
});
}
} // namespace gamesrc/scenes/level.cpp 214 lines// ---------------------------------------------------------------------------
// One level of the world: load it, build what LDtk placed in it, and watch the
// player leave it -- into the next level, or off the bottom.
// ---------------------------------------------------------------------------
#include "game.h"
#include "objects.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/input.h>
#include <rmp/tilemap.h>
#include <rmp/ui.h>
#include <algorithm>
#include <utility>
namespace game {
namespace {
// A sign's picture: plain, or with the arrow LDtk's `arrow` Enum asks for.
int sign_tile(std::string_view arrow) {
if (arrow == "Left") return tiles::SIGN_LEFT;
if (arrow == "Right") return tiles::SIGN_RIGHT;
return tiles::SIGN;
}
} // namespace
LevelScene::LevelScene(std::string level, Entry entry)
: _level(std::move(level)), _entry(entry) {}
void LevelScene::_ready() {
// "" is the first level of the world, whatever LDtk calls it: rename or
// reorder the levels there and the game still starts at the beginning.
map = rmp::assets::load_map("world.ldtk", _level);
rmp::audio::music("music"); // already playing after a level change: not restarted
// Not Space, not Enter: those are the jump's and the menus'. Defining it
// again in the next level replaces it, never adds to it.
rmp::input::action("pause", KEY_ESCAPE, KEY_P, GAMEPAD_BUTTON_MIDDLE_RIGHT);
// The player first, so that what is built below can know who it is.
auto &player =
spawn<Player>({ .position = _entry.position, .velocity = _entry.velocity });
_player = player.handle();
// ---- what LDtk placed, one factory per entity -------------------------
//
// Anything already collected, stomped or opened in this run is in
// run().gone by its iid, and is simply not built again.
map.on_object("Player", [this](rmp::Scene &, const rmp::MapObject &o) {
if (!_entry.carried) _player->position = o.position;
});
map.on_object("Coin", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &coin = s.spawn<Coin>({ .position = o.position, .layer = 1 });
coin.iid = o.iid;
coin.value = o.property_int("value", 1);
});
map.on_object("Walker", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &walker = s.spawn<Walker>({ .position = o.position, .layer = 2 });
walker.iid = o.iid;
walker.speed = o.property_float("speed", 40);
walker.stompable = o.property_bool("stompable", true);
// The route is drawn in LDtk as Points; a walker keeps to its floor
// and only needs to know where to turn.
walker.left = walker.right = o.position.x;
for (int i = 0; i < o.property_count("patrol"); ++i) {
const float x = o.property_point("patrol", i).x;
walker.left = std::min(walker.left, x);
walker.right = std::max(walker.right, x);
}
});
map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &bat = s.spawn<Bat>({ .position = o.position, .layer = 2 });
bat.iid = o.iid;
bat.speed = o.property_float("speed", 50);
for (int i = 0; i < o.property_count("patrol"); ++i) {
bat.route.push_back(o.property_point("patrol", i));
}
if (bat.route.empty()) bat.route.push_back(o.position);
});
map.on_object("MovingPlatform", [this](rmp::Scene &s, const rmp::MapObject &o) {
auto &platform = s.spawn<Platform>({ .position = o.position });
platform.collider = rmp::rect(o.size);
platform.from = o.position;
platform.to = o.property_point("to", o.position);
platform.speed = o.property_float("speed", 40);
platform.rider = _player;
});
map.on_object("Key", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &key = s.spawn<Key>({ .position = o.position, .layer = 1 });
key.iid = o.iid;
key.opens = o.property_string("opens");
});
map.on_object("Door", [](rmp::Scene &s, const rmp::MapObject &o) {
if (contains(run().gone, o.iid)) return;
auto &door = s.spawn<Door>({ .position = o.position });
door.collider = rmp::rect(o.size);
door.iid = o.iid;
});
map.on_object("Spikes", [](rmp::Scene &s, const rmp::MapObject &o) {
// Only the points hurt: the bottom eight pixels, a little in from the ends.
auto &spikes = s.spawn<Spikes>({ .position = o.position });
spikes.collider = rmp::rect({ o.size.x - 4, 8 });
spikes.collider.offset = { 0, (o.size.y / 2) - 4 };
});
map.on_object("Sign", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &sign = s.spawn<Sign>({ .position = o.position, .layer = -1 });
sign.text = o.property_string("text");
sign.tile = sign_tile(o.property_string("arrow", "None"));
});
map.on_object("Goal", [](rmp::Scene &s, const rmp::MapObject &o) {
s.spawn<Goal>({ .position = o.position });
});
map.spawn_objects(*this);
_start = _player->position;
// ---- the camera ----------------------------------------------------------
camera.follow = _player;
camera.limits = map.bounds(); // the level's own rectangle, in the world
camera.smoothing = 10;
camera.zoom = ZOOM;
}
void LevelScene::_update(float delta) {
if (_over) return;
if (rmp::input::just_pressed("pause")) {
rmp::Scene::push<PauseScene>(); // this scene freezes under it, clock and all
return;
}
run().seconds += delta;
const auto player = _player.get();
if (!player) return;
// THE NEXT LEVEL. Out of this one and into another of the world: change
// to it, and arrive at the same world position going the same way.
const std::string_view next = map.neighbour_at(player->position);
if (!next.empty()) {
_over = true;
rmp::Scene::change<LevelScene>(std::string(next),
Entry{ true, player->position, player->velocity });
return;
}
// No level there. The sides of the world are walls; below is a fall.
const Rectangle b = map.bounds();
if (player->position.x < b.x || player->position.x > b.x + b.width) {
player->position.x = std::clamp(player->position.x, b.x, b.x + b.width);
player->velocity.x = 0;
}
if (player->position.y > b.y + b.height + 48) {
lose_life();
if (!_over) respawn();
}
}
void LevelScene::lose_life() {
if (_over) return;
Run &r = run();
--r.lives;
camera.shake(5, 0.35f);
rmp::audio::play("hurt");
if (r.lives > 0) return;
_over = true;
rmp::audio::music("lose", false);
rmp::Scene::push<EndScene>(false, false);
}
void LevelScene::respawn() {
if (const auto player = _player.get()) {
player->position = _start;
player->velocity = Vector2{};
}
}
void LevelScene::win() {
if (_over) return;
_over = true;
const bool record = keep_if_best(run().coins, run().seconds);
rmp::audio::music("win", false);
rmp::Scene::push<EndScene>(true, record);
}
// The HUD, in screen space: hearts, coins and the clock down the left, drawn
// from the same tiles as the world and at its scale -- however the window
// stretches it -- and the Pause button at the right.
void LevelScene::_draw() {
const float scale = camera.raylib().zoom; // screen pixels to a pixel of the art
for (int i = 0; i < 3; ++i) {
const int heart = i < run().lives ? tiles::HEART : tiles::HEART_EMPTY;
draw_icon(heart, { (6 + (static_cast<float>(i) * 17)) * scale, 4 * scale },
scale);
}
draw_icon(tiles::COIN, { 6 * scale, 22 * scale }, scale);
draw_icon(tiles::TIMES, { 20 * scale, 22 * scale }, scale);
draw_number(run().coins, { 32 * scale, 22 * scale }, scale);
draw_seconds(run().seconds, { 6 * scale, 40 * scale }, scale);
// A phone has no Escape: the one way to pause there is a finger. The
// interface knows this scene is being played -- the player reads Space,
// the arrows and the A button through rmp::input -- so the button takes
// no focus, and Space jumps rather than pressing it (FrameOptions'
// focus_first, in rmp/ui.h).
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT });
if (rmp::ui::button("Pause")) rmp::Scene::push<PauseScene>();
rmp::ui::end();
}
} // namespace gamesrc/scenes/pause.cpp 37 lines// The pause, pushed on top of the level by the HUD's Pause button, Escape, P
// or a gamepad's Start. The level underneath freezes -- its clock too -- and
// stays on screen, and stops hearing the keyboard: the scene stack's defaults.
// What is here is the menu, and the look of it: the level blurred behind it,
// so the eye goes to Resume.
#include "game.h"
#include <rmp/audio.h>
#include <rmp/input.h>
#include <rmp/ui.h>
namespace game {
void PauseScene::_update(float /*delta*/) {
// The key that paused takes the pause away again.
if (rmp::input::just_pressed("pause")) rmp::Scene::pop();
}
void PauseScene::_draw() {
// A real blur wherever there is a GPU, a plain veil where there is none
// (raylib's software renderer); either way Resume has the focus, so Enter
// and the A button resume too.
rmp::ui::overlay({ .blur = 6, .dim = 0.4f }, [] {
rmp::ui::text("Paused", { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Resume")) {
rmp::audio::play("select");
rmp::Scene::pop();
}
if (rmp::ui::button("Menu")) {
rmp::audio::play("select");
rmp::Scene::change<TitleScene>();
}
});
}
} // namespace gamesrc/scenes/title.cpp 65 lines// The title: the first level behind a three-line menu, the camera drifting
// across it, and the best run so far.
#include "game.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/ui.h>
#include <cmath>
namespace game {
void TitleScene::_ready() {
// A window of another shape than the [window] size shows more of the
// world rather than bars or a cut: a level that scrolls anyway can show
// further. The first scene says it, for the whole game (rmp/app.h).
rmp::app::set_stretch(rmp::app::Stretch::EXPAND);
// The map with no factories: the level is drawn and nothing in it is
// built. A map costs a scene nothing it does not ask for.
map = rmp::assets::load_map("world.ldtk");
camera.limits = map.bounds();
camera.zoom = ZOOM;
rmp::audio::music("music");
_best = best();
}
void TitleScene::_update(float delta) {
_clock += delta;
const Rectangle b = map.bounds();
// Slowly from one end of the level to the other and back; `limits` keeps
// the view inside it, so the drift needs no arithmetic about the window.
camera.position = { b.x + (b.width / 2) + (std::sin(_clock * 0.15f) * b.width / 2),
b.y + (b.height / 2) };
}
void TitleScene::_draw() {
rmp::ui::begin();
// A dark panel, because the level behind is bright and the theme's text is
// light: the menu itself is the three lines inside it.
rmp::ui::panel({ .background = Color{ 20, 24, 40, 210 } }, [this] {
rmp::ui::text("Pixel Platformer",
{ .size = rmp::ui::Size::LARGE, .wrap = false });
if (_best.coins >= 0) {
rmp::ui::text(
TextFormat("Best: %d coins in %.1f s", _best.coins, _best.seconds),
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
}
if (rmp::ui::button("Play")) {
rmp::audio::play("select");
new_run();
rmp::Scene::change<LevelScene>("");
}
// quit() does nothing on iOS, where Apple rejects an app that ends
// itself -- so the button is not there at all rather than dead.
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
});
rmp::ui::end();
}
} // namespace gamehttps://omardev29.github.io/rmp-docs/examples/games/08_dungeon.html
A dungeon crawler made of the behavior catalogue. Two LDtk levels -- the Crypt and the Sanctum -- in Kenney's Tiny Dungeon art, lit by braziers, gems and the hero's own light in the dark. Every monster is behaviors with the editor's numbers in them (B::from(MapObject)): a Slime is a Chase that finds its way with Pathfind, a Bat a Patrol along a path drawn in LDtk, a Spider a Patrol, a Chase and a StateMachine that flees when hurt, a Wizard a Shooter, the Cyclops a StateMachine of sleep, hunt and a spiral of bolts with Ghosts in Orbit round it. Gems and potions are Collectibles with a magnet, chests, levers, the altar and the stairs Areas, spikes a Hitbox a Timer turns on and off with enable<B>(), the blades an Orbit and a Hitbox, a rune a Draggable laid on the altar with the pointer, and the hero TopDown, Animator and Health with a sword that is a Hitbox. One Theme of nine-slices and a pixel font for the menus and the HUD. Its art, sounds and first world.ldtk come out of tools/make_dungeon_assets.py.

From a clone of the framework:
rmp example 08_dungeonRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
pause | Esc, P, gamepad middle right |
attack | Space, J, gamepad right face down |
Every file of examples/games/08_dungeon, as it is at the commit this site documents (on GitHub).
src/main.cpp 46 lines// ---------------------------------------------------------------------------
// examples/games/08_dungeon -- a dungeon crawler whose levels are made in LDtk,
// and whose monsters are made of the behavior catalogue.
//
// Two levels of one LDtk world, the Crypt and the Sanctum, in Kenney's Tiny
// Dungeon art, under his Ancient frames and his pixel font.
//
// What the framework does here, and therefore what is NOT in these files:
//
// rmp::Tilemap resources/world.ldtk: the walls are its IntGrid `Solid`,
// drawn only where the camera looks; every monster, gem,
// trap, chest, lever, rune and stair is an entity with
// fields, built by a factory in src/objects/.
// the behaviors the whole cast is the catalogue with LDtk's numbers in
// it (B::from(MapObject)): a Slime is a Chase that finds its
// way with Pathfind; a Bat a Patrol along a path drawn in
// the editor; a Spider a Patrol, a Chase and a StateMachine
// that flees when it is hurt; a Wizard a Shooter; the
// Cyclops a StateMachine of sleep, hunt and a spiral of
// bolts, with Ghosts in Orbit round it. Gems and potions are
// Collectibles with a magnet; chests, levers, the altar and
// the stairs are Areas; spikes a Hitbox a Timer turns on and
// off (enable<B>); the blades an Orbit and a Hitbox; a rune a
// Draggable you lay on the altar with the pointer. The hero
// is TopDown, Animator and Health, and its sword a Hitbox.
// rmp::Camera follows, stays inside the level, shakes on a hit.
// rmp::ui the menus, the HUD and its health bar, all in one Theme
// of nine-slices and a pixel font (src/look.cpp).
// rmp::audio every sound, by name.
// rmp::save the most gems ever carried out.
//
// What is left is the game: what a gem is worth, what a potion heals, when
// the gate opens and when you have won.
//
// Move with the arrows or WASD, strike with Space or J (the A button), pause
// with Escape. Drag a rune onto the altar for another heart.
//
// Open resources/world.ldtk in LDtk 1.5 to change the levels.
// Run it: `rmp example 08_dungeon`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "dungeon.h"
RMP_GAME(game::TitleScene);include/cast.h 59 lines#pragma once
// ---------------------------------------------------------------------------
// Everything in a level. Nearly all of it is a plain rmp::Object with the
// catalogue's behaviors on it, built from its LDtk entity by a factory in
// src/objects/: what it IS is which behaviors it carries and with which
// fields. The hero has a class of its own, because the sword is the game's.
// ---------------------------------------------------------------------------
#include "dungeon.h"
#include <rmp/object.h>
#include <rmp/tilemap.h>
#include <raylib.h>
#include <string_view>
namespace game {
class Hero : public rmp::Object {
public:
void _ready() override;
void _update(float delta) override;
private:
void swing();
float _cooldown = 0; // seconds until the sword can swing again
};
// A light in the dark: what the level's darkness lets through, drawn over it
// by add_darkness()'s object. A flame breathes; a gem shines still.
struct Light {
float radius = 30;
Color color = { 255, 140, 40, 120 };
bool flicker = true;
float clock = 0;
void _ready(rmp::Object &self);
void _update(rmp::Object &self, float delta);
};
// The dark over the whole level, and every Light drawn on top of it.
void add_darkness(rmp::Scene &scene);
// One factory per entity type of world.ldtk, registered on the scene's map.
void add_monsters(rmp::Scene &scene, rmp::Handle<rmp::Object> hero);
void add_things(LevelScene &scene, rmp::Handle<rmp::Object> hero);
// Whether this level's Cyclops is still standing.
bool boss_lives();
// A burst of `count` sparks of `color` from `at`: a death, a pickup.
void sparks(rmp::Scene &scene, Vector2 at, Color color, int count);
// A number that rises and fades from `at`: "+1", "-1".
void float_text(rmp::Scene &scene, Vector2 at, std::string_view text, Color color);
// Whether `object` is the hero.
bool is_hero(const rmp::Object &object);
} // namespace gameinclude/dungeon.h 134 lines#pragma once
// ---------------------------------------------------------------------------
// What every file of the dungeon shares: the collision layers, the run that
// outlives a level, the scenes, and the look.
// ---------------------------------------------------------------------------
#include <rmp/scene.h>
#include <raylib.h>
#include <string>
#include <string_view>
namespace game {
inline constexpr float TILE = 16; // the grid of tiles.png and of every level
// How much of the world is on screen: twelve and a half rows of tiles at the
// [window] size, each pixel of the art several of the screen's. A window of
// another shape shows more of the dungeon (Stretch::EXPAND), never less.
inline constexpr float VIEW_HEIGHT = 200;
inline constexpr float ZOOM = RMP_WINDOW_HEIGHT / VIEW_HEIGHT;
// The tiles of tiles.png the game draws by itself, by index (12 to a row).
namespace tiles {
inline constexpr int GEM = 102;
inline constexpr int RUNE = 101;
inline constexpr int POTION = 115;
inline constexpr int CHEST = 89;
inline constexpr int CHEST_OPEN = 91;
inline constexpr int LEVER = 80;
inline constexpr int LEVER_PULLED = 79;
inline constexpr int GATE = 45;
inline constexpr int ALTAR = 64;
inline constexpr int SPIKES = 41;
inline constexpr int BLADE = 103;
inline constexpr int PILLAR = 65;
inline constexpr int BRAZIER = 29;
inline constexpr int STAIRS = 56;
inline constexpr int PORTAL = 60;
inline constexpr int SWORD = 104;
inline constexpr int BOLT = 125;
} // namespace tiles
// Who notices whom.
namespace layer {
inline constexpr unsigned HERO = 1u << 0;
inline constexpr unsigned MONSTER = 1u << 1;
inline constexpr unsigned PICKUP = 1u << 2; // gems, potions, runes
inline constexpr unsigned TRAP = 1u << 3; // spikes, blades, bolts
inline constexpr unsigned PLACE = 1u << 4; // chests, levers, altars, stairs
inline constexpr unsigned WALL = 1u << 5; // the gate
inline constexpr unsigned SWING = 1u << 6; // the hero's sword
} // namespace layer
// THE RUN: what survives going down the stairs into the next level.
struct Run {
int hp = 6;
int max_hp = 6;
int gems = 0;
float seconds = 0;
};
Run &run();
void new_run();
// The best run, as rmp::save keeps it: the most gems.
int best_gems();
bool keep_if_best(int gems);
// The look of every screen: Kenney's Ancient frames, his pixel font, sounds
// on hover and click. Set once, by the title.
void set_look();
// A tile of tiles.png, centred on `at`, in the world.
void draw_tile(int index, Vector2 at, Color tint = WHITE, float scale = 1,
float rotation = 0);
// A glow of `radius` around `at`, added to what is under it.
void draw_glow(Vector2 at, float radius, Color color);
// ---------------------------------------------------------------------------
// The scenes
// ---------------------------------------------------------------------------
class TitleScene : public rmp::Scene {
public:
void _ready() override;
void _update(float delta) override;
void _draw() override;
private:
float _clock = 0;
int _best = -1;
};
class LevelScene : public rmp::Scene {
public:
explicit LevelScene(std::string level);
void _ready() override;
void _update(float delta) override;
void _draw() override;
void hero_died();
void go_down(const std::string &level);
void win();
// A line across the top of the screen for a moment: a room's name, a gate.
void announce(std::string_view text);
private:
void build();
std::string _level;
rmp::Handle<rmp::Object> _hero;
std::string _banner;
float _banner_left = 0;
bool _over = false;
};
class PauseScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};
class EndScene : public rmp::Scene {
public:
EndScene(bool won, bool record);
void _draw() override;
private:
bool _won;
bool _record;
};
} // namespace gamesrc/look.cpp 121 lines// The run, the best run, the look of every screen, and the two ways the game
// draws a tile of its own.
#include "dungeon.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/save.h>
#include <rmp/ui.h>
#include <cmath>
namespace game {
namespace {
constexpr int COLUMNS = 12; // tiles.png, packed
// Kenney's Ancient frames are 48 pixels square; the border is 6 of them, and
// the bottom 8 with its shadow. Drawn three design units to a pixel of the art.
constexpr float FRAME = 6;
constexpr float FRAME_BOTTOM = 8;
constexpr float FRAME_SCALE = 3;
const Color PARCHMENT = { 248, 232, 200, 255 };
const Color INK = { 58, 34, 26, 255 };
const Color EMBER = { 255, 196, 92, 255 };
struct Art {
rmp::Texture tiles = rmp::assets::load_texture("tiles.png");
};
rmp::ui::Picture frame(std::string_view file, float inset = 0) {
return rmp::ui::NineSlice{ .texture = rmp::assets::load_texture(file),
.left = FRAME - inset,
.top = FRAME - inset,
.right = FRAME - inset,
.bottom = FRAME_BOTTOM - inset,
.scale = FRAME_SCALE };
}
} // namespace
Run &run() { return rmp::global<Run>(); }
void new_run() { rmp::global<Run>() = Run{}; }
int best_gems() {
rmp::Value saved;
rmp::save::read("dungeon", saved);
return saved["gems"].as_int(-1);
}
bool keep_if_best(int gems) {
if (gems <= best_gems()) return false;
rmp::Value v;
v["gems"] = gems;
rmp::save::write("dungeon", v);
return true;
}
void set_look() {
rmp::ui::set_font(rmp::assets::load_font("font.ttf", 16));
rmp::ui::Theme look = rmp::ui::theme_dark();
look.text = PARCHMENT;
look.text_muted = Color{ 214, 180, 140, 255 };
look.primary = EMBER;
look.sounds = { .hover = "hover", .click = "click", .volume = 0.6f };
look.styles.panel = {
.skin = rmp::ui::Skin{ .normal = frame("panel.png") },
.shadow =
rmp::ui::Shadow{ .offset = { 0, 8 }, .blur = 14, .color = { 0, 0, 0, 140 } },
.padding_x = 28,
.padding_y = 24,
.gap = 14,
.text_shadow =
rmp::ui::TextShadow{ .offset = { 0, 2 }, .color = { 30, 14, 10, 200 } },
.motion = rmp::ui::Motion{ .appear = 0.22f,
.appear_offset = 14,
.appear_scale = 0.97f },
};
look.styles.button = {
.skin = rmp::ui::Skin{ .normal = frame("button.png"),
.press = frame("button_down.png") },
.shadow =
rmp::ui::Shadow{ .offset = { 0, 4 }, .blur = 6, .color = { 0, 0, 0, 120 } },
.padding_x = 26,
.padding_y = 12,
.text = INK,
.motion = rmp::ui::Motion{ .hover_scale = 1.05f, .press_scale = 0.95f },
};
look.styles.progress = {
.skin = rmp::ui::Skin{ .normal = frame("inlay.png", 2) },
};
rmp::ui::set_theme(look);
}
void draw_tile(int index, Vector2 at, Color tint, float scale, float rotation) {
const Texture2D &tiles = rmp::global<Art>().tiles;
const Rectangle source{ static_cast<float>(index % COLUMNS) * TILE,
std::floor(static_cast<float>(index) / COLUMNS) * TILE, TILE,
TILE };
const float size = TILE * scale;
DrawTexturePro(tiles, source, Rectangle{ at.x, at.y, size, size },
Vector2{ size / 2, size / 2 }, rotation, tint);
}
void draw_glow(Vector2 at, float radius, Color color) {
// Rings from the edge in, each adding a little light: a soft falloff that
// needs nothing but circles.
constexpr int RINGS = 14;
const Color step{ color.r, color.g, color.b,
static_cast<unsigned char>(color.a / RINGS) };
BeginBlendMode(BLEND_ADDITIVE);
for (int i = 0; i < RINGS; ++i) {
DrawCircleV(at, radius * static_cast<float>(RINGS - i) / RINGS, step);
}
EndBlendMode();
}
} // namespace gamesrc/objects/effects.cpp 128 lines// Sparks and rising numbers: small objects that fade and go, made of the
// catalogue's Tween and Lifespan.
#include "cast.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/behavior.h>
#include <rmp/random.h>
#include <cmath>
#include <string>
#include <vector>
namespace game {
namespace {
constexpr float SPARK_SIZE = 2;
constexpr float SPARK_SPEED = 70;
constexpr float SPARK_LIFE = 0.45f;
constexpr float TEXT_RISE = 26;
constexpr float TEXT_LIFE = 0.8f;
constexpr float TEXT_SIZE = 8;
struct Letters {
rmp::Font font = rmp::assets::load_font("font.ttf", 8);
};
// A word in the world, drawn in the game's font, fading with its object.
struct Words {
std::string text;
Color color = WHITE;
float elapsed = 0;
void _update(rmp::Object &self, float delta) {
(void)self;
elapsed += delta;
}
void _draw(rmp::Object &self) {
const Font &font = rmp::global<Letters>().font;
const float fade = 1 - (elapsed / TEXT_LIFE);
const Vector2 size = MeasureTextEx(font, text.c_str(), TEXT_SIZE, 0);
const Vector2 at{ self.position.x - (size.x / 2),
self.position.y - (size.y / 2) };
DrawTextEx(font, text.c_str(), Vector2{ at.x + 1, at.y + 1 }, TEXT_SIZE, 0,
Fade(BLACK, fade * 0.7f));
DrawTextEx(font, text.c_str(), at, TEXT_SIZE, 0, Fade(color, fade));
}
};
// How dark the dungeon is between its lights, of 255.
constexpr unsigned char DARK = 150;
const Color NIGHT = { 14, 6, 18, DARK };
// Every object with a Light, for the darkness to draw.
std::vector<rmp::Handle<rmp::Object>> lit;
struct Dark {
void _update(rmp::Object &self, float delta) {
(void)self;
(void)delta;
}
void _draw(rmp::Object &self) {
const Rectangle view = self.scene().camera.view();
DrawRectangleRec(Rectangle{ view.x - TILE, view.y - TILE, view.width + (2 * TILE),
view.height + (2 * TILE) },
NIGHT);
std::erase_if(lit, [](const rmp::Handle<rmp::Object> &h) { return !h; });
for (const rmp::Handle<rmp::Object> &h : lit) {
const auto object = h.get();
if (!object->visible || !object->enabled<Light>()) continue;
const Light &light = *object->get<Light>();
const float breath = light.flicker
? 1 + (0.08f * std::sin(light.clock * 7.3f)) +
(0.05f * std::sin(light.clock * 13.1f))
: 1;
draw_glow(object->position, light.radius * breath, light.color);
}
}
};
} // namespace
void Light::_ready(rmp::Object &self) { lit.push_back(self.handle()); }
void Light::_update(rmp::Object &self, float delta) {
(void)self;
clock += delta;
}
void add_darkness(rmp::Scene &scene) {
lit.clear();
auto &dark = scene.spawn({ .layer = 50 });
dark.collision_layer = 0;
dark.collision_mask = 0;
dark.add<Dark>();
}
void sparks(rmp::Scene &scene, Vector2 at, Color color, int count) {
for (int i = 0; i < count; ++i) {
const Vector2 velocity{ rmp::random::range(-SPARK_SPEED, SPARK_SPEED),
rmp::random::range(-SPARK_SPEED, SPARK_SPEED) };
auto &spark = scene.spawn({ .position = at,
.size = { SPARK_SIZE, SPARK_SIZE },
.velocity = velocity,
.layer = 8 });
spark.shape.color = color;
spark.collision_layer = 0;
spark.collision_mask = 0;
spark.add<rmp::behavior::Tween>({ .property = rmp::behavior::Property::ALPHA,
.from = 255,
.to = 0,
.seconds = SPARK_LIFE,
.ease = rmp::behavior::Ease::IN });
spark.add<rmp::behavior::Lifespan>({ .seconds = SPARK_LIFE });
}
}
void float_text(rmp::Scene &scene, Vector2 at, std::string_view text, Color color) {
auto &words = scene.spawn(
{ .position = at, .velocity = { 0, -TEXT_RISE / TEXT_LIFE }, .layer = 9 });
words.collision_layer = 0;
words.collision_mask = 0;
words.add<Words>({ .text = std::string(text), .color = color });
words.add<rmp::behavior::Lifespan>({ .seconds = TEXT_LIFE });
}
} // namespace gamesrc/objects/hero.cpp 119 lines// The hero: walks with TopDown, is drawn by an Animator, lives with a Health,
// and swings a sword -- a Hitbox that lives a fifth of a second, in front.
#include "cast.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <cmath>
#include <numbers>
namespace game {
namespace {
constexpr float SPEED = 84;
constexpr float SWING_EVERY = 0.32f;
constexpr float SWING_LASTS = 0.18f;
constexpr float SWING_REACH = 13;
constexpr float SWING_SIZE = 18;
constexpr float SWING_KNOCKBACK = 260;
constexpr float GRACE = 0.9f; // seconds safe after a hit
constexpr float SHAKE = 3;
// The blade, drawn turning through its arc while the swing lives.
struct Slash {
float angle = 0; // degrees, where the arc is centred
float elapsed = 0;
void _update(rmp::Object &self, float delta) {
(void)self;
elapsed += delta;
}
void _draw(rmp::Object &self) {
const float t = elapsed / SWING_LASTS;
const float turn = angle - 70 + (140 * t) + 45; // the tile points up-right
draw_tile(tiles::SWORD, self.position, WHITE, 1.2f, turn);
}
};
} // namespace
bool is_hero(const rmp::Object &object) { return object.collision_layer == layer::HERO; }
void Hero::_ready() {
sprite.sheet = rmp::assets::load_sheet("hero.aseprite");
collider = rmp::rect({ 10, 10 });
solid = true;
collision_layer = layer::HERO;
collision_mask =
layer::MONSTER | layer::PICKUP | layer::TRAP | layer::PLACE | layer::WALL;
layer = 5;
add<rmp::behavior::TopDown>({ .speed = SPEED, .idle = "", .walk = "" });
add<rmp::behavior::Animator>();
add<Light>({ .radius = 78, .color = { 255, 200, 140, 80 } });
add<rmp::behavior::Health>({
.hp = run().hp,
.max_hp = run().max_hp,
.invulnerable_for = GRACE,
.destroy_on_death = false,
.on_death =
[](rmp::Object &self) {
static_cast<LevelScene &>(self.scene()).hero_died();
},
.on_damage =
[](rmp::Object &self, int amount) {
run().hp = self.get<rmp::behavior::Health>()->hp;
self.scene().camera.shake(SHAKE, 0.25f);
rmp::audio::play("hurt");
sparks(self.scene(), self.position, Color{ 228, 59, 68, 255 }, 10);
float_text(self.scene(), self.position, TextFormat("-%d", amount),
Color{ 255, 90, 90, 255 });
},
});
}
void Hero::_update(float delta) {
_cooldown -= delta;
const auto health = get<rmp::behavior::Health>();
if (health && health->dead()) {
velocity = Vector2{};
enable<rmp::behavior::TopDown>(false);
return;
}
if (health) {
// A potion or the altar heals the run; the Health follows it.
health->max_hp = run().max_hp;
if (run().hp > health->hp) health->heal(run().hp - health->hp);
}
if (rmp::input::just_pressed("attack") && _cooldown <= 0) swing();
}
void Hero::swing() {
_cooldown = SWING_EVERY;
const Vector2 facing = get<rmp::behavior::TopDown>()->direction();
const Vector2 at{ position.x + (facing.x * SWING_REACH),
position.y + (facing.y * SWING_REACH) };
auto &slash = scene().spawn({ .position = at, .layer = 6 });
slash.collider = rmp::rect({ SWING_SIZE, SWING_SIZE }); // felt, and drawn by Slash
slash.collision_layer = layer::SWING;
slash.collision_mask = layer::MONSTER;
slash.add<rmp::behavior::Hitbox>({ .damage = 1,
.hits = layer::MONSTER,
.knockback = SWING_KNOCKBACK,
.once_per_target = true,
.on_hit = [](rmp::Object &, rmp::Object &victim) {
rmp::audio::play("hit");
sparks(victim.scene(), victim.position,
Color{ 255, 236, 180, 255 }, 6);
} });
slash.add<rmp::behavior::Lifespan>({ .seconds = SWING_LASTS });
slash.add<Slash>(
{ .angle = std::atan2(facing.y, facing.x) * 180 / std::numbers::pi_v<float> });
rmp::audio::play("swing", { .volume = 0.5f });
}
} // namespace gamesrc/objects/monsters.cpp 206 lines// The monsters. Each is a list of behaviors with the fields LDtk gave it:
//
// Slime Chase + Pathfind: it sees you, and finds its way round the walls
// Bat Patrol along the Array<Point> drawn in the editor
// Spider Patrol + Chase, and a StateMachine that flees when it is hurt
// Wizard Shooter, aimed at you, three bolts in a fan, in range
// Cyclops a StateMachine: asleep, hunting (Pathfind), a spiral of bolts
// Ghost Orbit round the Cyclops
//
// Every one has an Animator, a Health and a Hitbox that hurts on touch.
#include "cast.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/random.h>
#include <raymath.h>
#include <string>
#include <utility>
namespace game {
namespace {
namespace b = rmp::behavior;
constexpr float TOUCH_KNOCKBACK = 240;
constexpr float BOLT_RADIUS = 3;
constexpr float BOLT_LIFE = 2.5f;
constexpr float BOLT_GLOW = 14;
constexpr float BODY = 11; // a monster's collider, square
constexpr float FLEE_SPEED = 70;
constexpr float FLEE_SECONDS = 2;
constexpr float WAKE_DISTANCE = 120;
constexpr float HUNT_SECONDS = 3.5f;
constexpr float VOLLEY_SECONDS = 2.8f;
constexpr float BOSS_SPEED = 38;
const Color BOLT = { 190, 120, 255, 255 };
const Color FIRE = { 255, 150, 60, 255 };
const Color GORE = { 120, 220, 120, 255 };
// The Cyclops the Ghosts circle: built first, because LDtk lists it first.
rmp::Handle<rmp::Object> boss;
float distance(Vector2 a, Vector2 c) { return Vector2Distance(a, c); }
rmp::Object &monster(rmp::Scene &s, const rmp::MapObject &o, std::string_view sheet,
int hp) {
auto &m = s.spawn({ .position = o.position, .layer = 4 });
m.sprite.sheet = rmp::assets::load_sheet(sheet);
m.collider = rmp::rect({ BODY, BODY });
m.solid = true;
m.collision_layer = layer::MONSTER;
m.collision_mask = layer::HERO | layer::SWING | layer::MONSTER | layer::WALL;
m.add<b::Hitbox>({ .damage = 1, .hits = layer::HERO, .knockback = TOUCH_KNOCKBACK });
m.add<b::Health>(
{ .hp = hp, .invulnerable_for = 0.25f, .on_death = [](rmp::Object &self) {
rmp::audio::play("hit", { .pitch = 0.7f });
sparks(self.scene(), self.position, GORE, 14);
} });
m.add<b::Animator>();
return m;
}
// A bolt of the wizard's or the cyclops's: a violet spark that hurts the hero
// and ends at a wall.
void bolt(rmp::Scene &s, Vector2 at, Vector2 velocity) {
auto &shot = s.spawn({ .position = at,
.shape = rmp::circle(BOLT_RADIUS),
.velocity = velocity,
.layer = 7 });
shot.shape.color = BOLT;
shot.collision_layer = layer::TRAP;
shot.collision_mask = layer::HERO;
shot.add<b::Hitbox>(
{ .damage = 1, .hits = layer::HERO, .knockback = 160, .destroy_on_hit = true });
shot.add<b::Projectile>({ .destroy_on_wall = true });
shot.add<b::Lifespan>({ .seconds = BOLT_LIFE });
shot.add<Light>(
{ .radius = BOLT_GLOW, .color = Color{ 150, 80, 255, 170 }, .flicker = false });
}
} // namespace
bool boss_lives() { return static_cast<bool>(boss); }
void add_monsters(rmp::Scene &scene, rmp::Handle<rmp::Object> hero) {
rmp::Tilemap &map = scene.map;
boss = {};
map.on_object("Slime", [hero](rmp::Scene &s, const rmp::MapObject &o) {
auto &slime = monster(s, o, "slime.aseprite", 2);
b::Chase chase = b::Chase::from(o);
chase.target = hero;
slime.add<b::Pathfind>({ .clearance = 4 });
slime.add(std::move(chase));
});
map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &bat = monster(s, o, "bat.aseprite", 1);
bat.solid = false; // it flies
bat.add(b::Patrol::from(o));
});
map.on_object("Spider", [hero](rmp::Scene &s, const rmp::MapObject &o) {
auto &spider = monster(s, o, "spider.aseprite", 3);
b::Chase chase = b::Chase::from(o);
chase.target = hero;
spider.add(b::Patrol::from(o));
spider.add(std::move(chase));
// Hurt down to its last point, it runs from you for a while.
b::StateMachine mind;
mind.states.push_back(
{ .name = "hunt", .enables = b::kinds<b::Patrol, b::Chase>() });
mind.states.push_back(
{ .name = "flee", .on_update = [hero](rmp::Object &self, float) {
if (const auto h = hero.get()) {
const Vector2 away =
Vector2Normalize(Vector2Subtract(self.position, h->position));
self.velocity = Vector2Scale(away, FLEE_SPEED);
}
} });
mind.transitions.push_back(
{ .from = "hunt", .to = "flee", .when = [](rmp::Object &self) {
return self.get<b::Health>()->hp == 1;
} });
mind.transitions.push_back(
{ .from = "flee", .to = "hunt", .when = [](rmp::Object &self) {
return self.get<b::StateMachine>()->seconds_in_state() > FLEE_SECONDS;
} });
spider.add(std::move(mind));
});
map.on_object("Wizard", [hero](rmp::Scene &s, const rmp::MapObject &o) {
auto &wizard = monster(s, o, "wizard.aseprite", 2);
wizard.solid = false;
wizard.immovable = true;
b::Shooter staff = b::Shooter::from(o);
staff.automatic = true;
staff.target = hero;
staff.on_shoot = [](rmp::Scene &scene, Vector2 at, Vector2 velocity) {
bolt(scene, at, velocity);
};
wizard.add(std::move(staff));
wizard.add<Light>({ .radius = 22, .color = Color{ 90, 40, 160, 90 } });
});
map.on_object("Cyclops", [hero](rmp::Scene &s, const rmp::MapObject &o) {
auto &cyclops = monster(s, o, "cyclops.aseprite", o.property_int("hp", 14));
cyclops.scale = { 2, 2 };
cyclops.collider = rmp::rect({ BODY * 1.4f, BODY * 1.4f });
boss = cyclops.handle();
cyclops.get<b::Health>()->on_death = [](rmp::Object &self) {
sparks(self.scene(), self.position, FIRE, 40);
self.scene().camera.shake(6, 0.6f);
static_cast<LevelScene &>(self.scene()).announce("The Sanctum falls silent");
};
cyclops.add<b::Pathfind>({ .target = hero, .speed = BOSS_SPEED, .clearance = 6 });
cyclops.add<b::Shooter>({ .every = 0.3f,
.speed = 90,
.count = 6,
.spread = 360,
.rotate_per_shot = 17,
.on_shoot = [](rmp::Scene &scene, Vector2 at,
Vector2 v) { bolt(scene, at, v); } });
// Asleep until you come near; then it hunts you, and stops to throw
// a spiral of bolts, and hunts again.
b::StateMachine mind;
mind.states.push_back({ .name = "asleep" });
mind.states.push_back({ .name = "hunt", .enables = b::kinds<b::Pathfind>() });
mind.states.push_back({ .name = "volley",
.on_enter = [](rmp::Object &self) { self.velocity = {}; },
.enables = b::kinds<b::Shooter>() });
mind.transitions.push_back(
{ .from = "asleep", .to = "hunt", .when = [hero](rmp::Object &self) {
const auto h = hero.get();
return h && distance(h->position, self.position) < WAKE_DISTANCE;
} });
mind.transitions.push_back(
{ .from = "hunt", .to = "volley", .when = [](rmp::Object &self) {
return self.get<b::StateMachine>()->seconds_in_state() > HUNT_SECONDS;
} });
mind.transitions.push_back(
{ .from = "volley", .to = "hunt", .when = [](rmp::Object &self) {
return self.get<b::StateMachine>()->seconds_in_state() > VOLLEY_SECONDS;
} });
cyclops.add(std::move(mind));
cyclops.get<b::Shooter>()->automatic = true;
cyclops.add<Light>({ .radius = 40, .color = Color{ 160, 40, 30, 90 } });
});
map.on_object("Ghost", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &ghost = monster(s, o, "ghost.aseprite", 1);
ghost.solid = false;
b::Orbit orbit = b::Orbit::from(o);
orbit.centre = boss;
orbit.point = o.position;
ghost.add(orbit);
ghost.sprite.tint = Color{ 255, 255, 255, 200 };
});
}
} // namespace gamesrc/objects/things.cpp 246 lines// What is not alive: gems and potions (Collectible), chests, levers, the
// altar and the stairs (Area), runes (Draggable), spikes (Hitbox and Timer),
// the blades round their pillar (Orbit and Hitbox), the gate a lever opens,
// and the braziers that light it all.
#include "cast.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/random.h>
#include <cmath>
#include <raymath.h>
#include <string>
#include <utility>
#include <vector>
namespace game {
namespace {
namespace b = rmp::behavior;
constexpr float PICKUP = 10;
constexpr float SPILL_SPEED = 60;
constexpr float SPIKES_EVERY = 1.1f;
constexpr int POTION_HEALS = 2;
const Color GEM_LIGHT = { 60, 200, 255, 110 };
const Color SHINE = { 255, 214, 102, 255 };
const Color FLAME = { 255, 140, 40, 120 };
Rectangle tile_rect(int index) {
constexpr int COLUMNS = 12;
return Rectangle{ static_cast<float>(index % COLUMNS) * TILE,
std::floor(static_cast<float>(index) / COLUMNS) * TILE, TILE,
TILE };
}
// An object drawn as one tile of tiles.png.
rmp::Object &thing(rmp::Scene &s, Vector2 at, int tile, int draw_layer = 2) {
auto &t = s.spawn({ .position = at, .layer = draw_layer });
t.sprite.texture = rmp::assets::load_texture("tiles.png");
t.sprite.source = tile_rect(tile);
t.collider = rmp::rect({ PICKUP, PICKUP });
t.collision_layer = layer::PLACE;
t.collision_mask = layer::HERO;
return t;
}
// Slows what was thrown to a stop: a gem out of a chest.
struct Slide {
float keep = 0.9f; // of its speed, every sixtieth of a second
void _update(rmp::Object &self, float delta) {
self.velocity = Vector2Scale(self.velocity, std::pow(keep, delta * 60));
}
};
// The gates, by their LDtk iid, so that a lever can find the one it opens.
std::vector<std::pair<std::string, rmp::Handle<rmp::Object>>> gates;
void gem(rmp::Scene &s, Vector2 at, Vector2 velocity = {}) {
auto &g = thing(s, at, tiles::GEM, 3);
g.velocity = velocity;
g.collision_layer = layer::PICKUP;
g.add<b::Collectible>({ .collected_by = layer::HERO,
.sound = "coin",
.magnet = 26,
.on_collect = [](rmp::Object &self, rmp::Object &) {
++run().gems;
float_text(self.scene(), self.position, "+1", SHINE);
} });
g.add<Light>({ .radius = 14, .color = GEM_LIGHT, .flicker = false });
if (velocity.x != 0 || velocity.y != 0) g.add<Slide>();
}
void spill_gems(rmp::Scene &s, Vector2 at, int count) {
for (int i = 0; i < count; ++i) {
const float angle = rmp::random::range(0.0f, 6.2831f);
gem(s, at,
Vector2{ std::cos(angle) * SPILL_SPEED, std::sin(angle) * SPILL_SPEED });
}
}
} // namespace
void add_things(LevelScene &scene, rmp::Handle<rmp::Object> hero) {
rmp::Tilemap &map = scene.map;
(void)hero;
gates.clear();
map.on_object("Gem",
[](rmp::Scene &s, const rmp::MapObject &o) { gem(s, o.position); });
map.on_object("Potion", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &p = thing(s, o.position, tiles::POTION, 3);
p.collision_layer = layer::PICKUP;
p.add<b::Collectible>({ .collected_by = layer::HERO,
.sound = "potion",
.on_collect = [](rmp::Object &self, rmp::Object &) {
run().hp =
std::min(run().max_hp, run().hp + POTION_HEALS);
float_text(self.scene(), self.position, "+2",
Color{ 255, 110, 110, 255 });
} });
p.add<Light>({ .radius = 12, .color = Color{ 255, 60, 60, 90 } });
});
map.on_object("Brazier", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &fire = thing(s, o.position, tiles::BRAZIER, 1);
fire.collision_mask = 0;
fire.add<Light>({ .radius = 70, .color = FLAME });
});
map.on_object("Chest", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &chest = thing(s, o.position, tiles::CHEST);
const int count = o.property_int("gems", 5);
chest.add<b::Area>({ .on_enter = [count](rmp::Object &self, rmp::Object &who) {
if (!is_hero(who) || self.sprite.source.x == tile_rect(tiles::CHEST_OPEN).x)
return;
self.sprite.source = tile_rect(tiles::CHEST_OPEN);
rmp::audio::play("chest");
spill_gems(self.scene(), self.position, count);
} });
});
map.on_object("Gate", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &gate = thing(s, o.position, tiles::GATE);
gate.collider = rmp::rect({ TILE, TILE });
gate.solid = true;
gate.immovable = true;
gate.collision_layer = layer::WALL;
gate.collision_mask = layer::HERO | layer::MONSTER;
gate.layer = 3;
gates.emplace_back(std::string(o.iid), gate.handle());
});
map.on_object("Lever", [&scene](rmp::Scene &s, const rmp::MapObject &o) {
auto &lever = thing(s, o.position, tiles::LEVER);
const std::string opens(o.property_string("opens"));
lever.add<b::Area>({ .on_enter = [&scene, opens](rmp::Object &self,
rmp::Object &who) {
if (!is_hero(who) || self.sprite.source.x == tile_rect(tiles::LEVER_PULLED).x)
return;
self.sprite.source = tile_rect(tiles::LEVER_PULLED);
rmp::audio::play("door");
scene.camera.shake(2, 0.4f);
scene.announce("A gate grinds open");
for (const auto &[iid, handle] : gates) {
const auto gate = handle.get();
if (iid != opens || !gate) continue;
sparks(scene, gate->position, Color{ 200, 180, 160, 255 }, 16);
gate->destroy();
}
} });
});
map.on_object("Spikes", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &spikes = thing(s, o.position, tiles::SPIKES, 1);
spikes.collider = rmp::rect({ 12, 12 });
spikes.collision_layer = layer::TRAP;
spikes.add(b::Hitbox::from(o));
// Up and down: a Timer flips the Hitbox on and off, and the tile with it.
spikes.add<b::Timer>(
{ .seconds = SPIKES_EVERY, .on_timeout = [](rmp::Object &self) {
const bool up = !self.enabled<b::Hitbox>();
self.enable<b::Hitbox>(up);
self.sprite.tint = up ? WHITE : Color{ 120, 110, 110, 255 };
} });
});
map.on_object("Blades", [](rmp::Scene &s, const rmp::MapObject &o) {
auto &pillar = thing(s, o.position, tiles::PILLAR, 3);
pillar.collider = rmp::rect({ TILE, TILE });
pillar.solid = true;
pillar.immovable = true;
pillar.collision_layer = layer::WALL;
const int count = o.property_int("blades", 3);
for (int i = 0; i < count; ++i) {
auto &blade = thing(s, o.position, tiles::BLADE, 4);
blade.collision_layer = layer::TRAP;
blade.add(b::Hitbox::from(o));
b::Orbit orbit = b::Orbit::from(o);
orbit.point = o.position;
orbit.face = b::Face::OUTWARD;
orbit.index = i;
orbit.of = count;
blade.add(orbit);
blade.add<Light>({ .radius = 9, .color = Color{ 220, 230, 255, 70 } });
}
});
map.on_object("Altar", [&scene](rmp::Scene &s, const rmp::MapObject &o) {
auto &altar = thing(s, o.position, tiles::ALTAR);
altar.collider = rmp::rect({ 22, 22 });
altar.add<b::Area>();
altar.add<Light>({ .radius = 26, .color = Color{ 255, 230, 140, 70 } });
(void)scene;
});
map.on_object("Rune", [&scene](rmp::Scene &s, const rmp::MapObject &o) {
auto &rune = thing(s, o.position, tiles::RUNE, 3);
rune.collider = rmp::rect({ 14, 14 });
rune.add<Light>({ .radius = 14, .color = Color{ 255, 230, 120, 110 } });
// Picked up with the pointer and laid on the altar: a heart more.
rune.add<b::Draggable>({ .drop_on = layer::PLACE,
.on_drop = [&scene](rmp::Object &self, rmp::Object &) {
rmp::audio::play("rune");
++run().max_hp;
run().hp = run().max_hp;
sparks(scene, self.position, SHINE, 20);
scene.announce("The altar blesses you");
self.destroy();
} });
});
map.on_object("Stairs", [&scene](rmp::Scene &s, const rmp::MapObject &o) {
auto &stairs = thing(s, o.position, tiles::STAIRS, 1);
const std::string to(o.property_string("to", "Sanctum"));
stairs.add<b::Area>({ .on_inside = [&scene, to](rmp::Object &, rmp::Object &who) {
if (is_hero(who)) scene.go_down(to);
} });
stairs.add<Light>({ .radius = 22, .color = Color{ 120, 160, 255, 80 } });
});
map.on_object("Exit", [&scene](rmp::Scene &s, const rmp::MapObject &o) {
auto &exit = thing(s, o.position, tiles::STAIRS, 1);
exit.collider = rmp::rect({ 18, 18 });
exit.visible = false;
// Shut until the Cyclops is gone.
exit.add<b::Area>({ .on_enter = [&scene](rmp::Object &self, rmp::Object &who) {
if (is_hero(who) && self.visible) scene.win();
} });
exit.add<Light>({ .radius = 36, .color = Color{ 255, 220, 120, 130 } });
exit.enable<Light>(false);
exit.add<b::Timer>({ .seconds = 0.25f, .on_timeout = [](rmp::Object &self) {
if (self.visible || boss_lives()) return;
self.visible = true;
self.enable<Light>(true);
sparks(self.scene(), self.position, SHINE, 24);
} });
});
}
} // namespace gamesrc/scenes/end.cpp 29 lines// The end of a run, won or lost, over the level it ended in.
#include "dungeon.h"
#include <rmp/ui.h>
namespace game {
EndScene::EndScene(bool won, bool record) : _won(won), _record(record) {}
void EndScene::_draw() {
rmp::ui::overlay({ .blur = 4, .dim = 0.55f }, [this] {
rmp::ui::panel([this] {
rmp::ui::text(_won ? "You walk out into the dawn" : "The crypt keeps you",
{ .size = rmp::ui::Size::LARGE, .wrap = false });
rmp::ui::text(TextFormat("%d %s in %.0f seconds", run().gems,
run().gems == 1 ? "gem" : "gems", run().seconds),
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
if (_record) rmp::ui::text("More than ever before!", { .wrap = false });
if (rmp::ui::button("Again")) {
new_run();
rmp::Scene::change<LevelScene>("Crypt");
}
if (rmp::ui::button("Title")) rmp::Scene::change<TitleScene>();
});
});
}
} // namespace gamesrc/scenes/level.cpp 150 lines// A level: the map, the hero, what LDtk placed, and the HUD over it all.
#include "dungeon.h"
#include "cast.h"
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/behavior.h>
#include <rmp/input.h>
#include <rmp/tilemap.h>
#include <rmp/ui.h>
#include <algorithm>
#include <cmath>
#include <utility>
namespace game {
namespace {
constexpr float BANNER_SECONDS = 2.6f;
constexpr float SHADE = 150; // how dark the edges of the screen go, of 255
constexpr float SHADE_SHARE = 0.22f; // how far in from each edge the shade reaches
constexpr int COLUMNS = 12;
const Color HEALTH = { 214, 64, 64, 255 };
rmp::ui::Picture icon(int tile) {
return { rmp::assets::load_texture("tiles.png"),
Rectangle{ static_cast<float>(tile % COLUMNS) * TILE,
std::floor(static_cast<float>(tile) / COLUMNS) * TILE, TILE,
TILE } };
}
// The torchlight's edge: the screen darkens towards its borders.
void shade_edges() {
const auto w = static_cast<float>(GetScreenWidth());
const auto h = static_cast<float>(GetScreenHeight());
const Color dark{ 10, 4, 6, static_cast<unsigned char>(SHADE) };
const Color clear{ 10, 4, 6, 0 };
const float dx = w * SHADE_SHARE;
const float dy = h * SHADE_SHARE;
DrawRectangleGradientV(0, 0, static_cast<int>(w), static_cast<int>(dy), dark, clear);
DrawRectangleGradientV(0, static_cast<int>(h - dy), static_cast<int>(w),
static_cast<int>(dy), clear, dark);
DrawRectangleGradientH(0, 0, static_cast<int>(dx), static_cast<int>(h), dark, clear);
DrawRectangleGradientH(static_cast<int>(w - dx), 0, static_cast<int>(dx),
static_cast<int>(h), clear, dark);
}
} // namespace
LevelScene::LevelScene(std::string level) : _level(std::move(level)) {}
void LevelScene::_ready() {
background = Color{ 37, 19, 26, 255 };
rmp::input::action("pause", KEY_ESCAPE, KEY_P, GAMEPAD_BUTTON_MIDDLE_RIGHT);
rmp::input::action("attack", KEY_SPACE, KEY_J, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
build();
}
void LevelScene::build() {
map = rmp::assets::load_map("world.ldtk", _level);
add_darkness(*this); // first: every Light from here on is drawn over it
auto &hero = spawn<Hero>();
_hero = hero.handle();
map.on_object("Player", [this](rmp::Scene &, const rmp::MapObject &o) {
if (const auto h = _hero.get()) h->position = o.position;
});
add_monsters(*this, _hero);
add_things(*this, _hero);
map.spawn_objects(*this);
camera.follow = _hero;
camera.limits = map.bounds();
camera.smoothing = 8;
camera.zoom = ZOOM;
announce(_level == "Crypt" ? "The Crypt" : "The Sanctum");
}
void LevelScene::_update(float delta) {
if (_over) return;
if (rmp::input::just_pressed("pause")) {
rmp::Scene::push<PauseScene>();
return;
}
run().seconds += delta;
_banner_left = std::max(0.0f, _banner_left - delta);
}
void LevelScene::announce(std::string_view text) {
_banner = std::string(text);
_banner_left = BANNER_SECONDS;
}
void LevelScene::hero_died() {
if (_over) return;
_over = true;
camera.shake(6, 0.5f);
if (const auto h = _hero.get()) h->sprite.play("die", false);
rmp::Scene::push<EndScene>(false, keep_if_best(run().gems));
}
void LevelScene::go_down(const std::string &level) {
if (_over) return;
_over = true;
rmp::audio::play("door");
rmp::Scene::change<LevelScene>(level);
}
void LevelScene::win() {
if (_over) return;
_over = true;
rmp::Scene::push<EndScene>(true, keep_if_best(run().gems));
}
void LevelScene::_draw() {
shade_edges();
// The HUD: health and gems in a frame at the top left.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .padding = 12 });
rmp::ui::panel([] {
rmp::ui::row([] {
rmp::ui::image(icon(tiles::POTION), { .width = 24, .height = 24 });
rmp::ui::progress(static_cast<float>(run().hp) /
static_cast<float>(run().max_hp),
{ .width = 120, .fill = HEALTH });
rmp::ui::text(TextFormat("%d/%d", run().hp, run().max_hp), { .wrap = false });
});
rmp::ui::row([] {
rmp::ui::image(icon(tiles::GEM), { .width = 24, .height = 24 });
rmp::ui::text(TextFormat("%d", run().gems), { .wrap = false });
});
});
rmp::ui::end();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT, .padding = 12 });
if (rmp::ui::button("Pause")) rmp::Scene::push<PauseScene>();
rmp::ui::end();
if (_banner_left > 0) {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER, .padding = 70 });
rmp::ui::panel([this] {
rmp::ui::text(_banner, { .size = rmp::ui::Size::LARGE, .wrap = false });
});
rmp::ui::end();
}
}
} // namespace gamesrc/scenes/pause.cpp 24 lines// The pause: the level frozen and blurred behind it.
#include "dungeon.h"
#include <rmp/input.h>
#include <rmp/ui.h>
namespace game {
void PauseScene::_update(float /*delta*/) {
if (rmp::input::just_pressed("pause")) rmp::Scene::pop();
}
void PauseScene::_draw() {
rmp::ui::overlay({ .blur = 6, .dim = 0.5f }, [] {
rmp::ui::panel([] {
rmp::ui::text("Paused", { .size = rmp::ui::Size::LARGE, .wrap = false });
if (rmp::ui::button("Resume")) rmp::Scene::pop();
if (rmp::ui::button("Leave the dungeon")) rmp::Scene::change<TitleScene>();
});
});
}
} // namespace gamesrc/scenes/title.cpp 64 lines// The title: the Crypt behind the menu, the camera drifting through it.
#include "dungeon.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/ui.h>
#include <cmath>
namespace game {
namespace {
constexpr float DRIFT = 0.12f; // how fast the camera wanders, in turns of a sine
const Color TITLE = { 255, 210, 120, 255 };
const Color SHADOW = { 20, 8, 6, 255 };
} // namespace
void TitleScene::_ready() {
rmp::app::set_stretch(rmp::app::Stretch::EXPAND);
set_look();
background = Color{ 37, 19, 26, 255 };
map = rmp::assets::load_map("world.ldtk", "Crypt");
camera.limits = map.bounds();
camera.zoom = ZOOM;
_best = best_gems();
}
void TitleScene::_update(float delta) {
_clock += delta;
const Rectangle b = map.bounds();
camera.position = { b.x + (b.width / 2) + (std::sin(_clock * DRIFT) * b.width / 3),
b.y + (b.height / 2) +
(std::cos(_clock * DRIFT * 0.7f) * b.height / 4) };
}
void TitleScene::_draw() {
rmp::ui::begin();
rmp::ui::panel([this] {
rmp::ui::Label title{ .text = "EMBERFALL",
.size = 44,
.wrap = false,
.style = { .text = TITLE,
.text_outline = rmp::ui::TextOutline{
.width = 2, .color = SHADOW } } };
title.show();
rmp::ui::text("A crypt, a cyclops, and you",
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
if (_best >= 0) {
rmp::ui::text(TextFormat("Most gems carried out: %d", _best),
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
}
if (rmp::ui::button("Descend")) {
new_run();
rmp::Scene::change<LevelScene>("Crypt");
}
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
});
rmp::ui::end();
}
} // namespace gamehttps://omardev29.github.io/rmp-docs/examples/games/09_after_school.html
An afternoon in town, told in Yarn. The lantern festival is at seven, and whom you talk to -- and what you say -- decides how the evening ends: with Mika at the festival, in the front row of Sora's concert, or at home. The town and everyone in it come from LDtk; each person is a Talker with a node of resources/dialogue/school.yarn; the conversations are a DialogueStage over the town, Persona style, each person with a face per mood and a voice of their own; the script's $variables are bound to the game's Story, so every conversation knows what the others decided; <<walk Mika pond>> makes the dialogue wait while she walks there with Pathfind, around the walls, and the view goes with her; trees and street lamps are entities too, drawn over whoever walks behind them; the light turns to dusk as the clock runs, and at seven the evening comes wherever you are; Kai's race is a timed choice; the flyer is a Collectible the script asks about with has_item(). English and Spanish, saved progress, lanterns over the town at dusk, and resources/ in folders by kind (maps/, sprites/, portraits/, ui/, audio/, fonts/, dialogue/). Kenney's art (CC0) from tools/make_story_assets.py.

From a clone of the framework:
rmp example 09_after_schoolRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
pause | Esc, P, gamepad middle right |
interact | E, Space, gamepad right face down |
Every file of examples/games/09_after_school, as it is at the commit this site documents (on GitHub).
src/main.cpp 41 lines// ---------------------------------------------------------------------------
// examples/games/09_after_school -- an afternoon in town, told in Yarn.
//
// The last bell has rung, the lantern festival starts at seven, and whoever
// you talk to -- and what you say -- decides how the evening ends: at the
// festival with Mika, in the front row of Sora's concert, or at home.
//
// What the framework does here, and therefore what is NOT in these files:
//
// rmp::Tilemap resources/maps/world.ldtk: the town, its walls, every
// person, tree and street lamp in it and the places they
// walk to, from the editor.
// rmp::Dialogue resources/dialogue/school.yarn: everything anyone says,
// its branches and its endings, compiled by the framework.
// Its $variables ARE the game's (Dialogue::bind), so
// every conversation knows what the others decided.
// rmp::behavior the people are Talkers (talk with E or the A button)
// and walk where the script sends them with Pathfind,
// around the walls; you walk with TopDown; the flyer is a
// Collectible.
// rmp::ui the conversations are a DialogueStage, Persona style:
// big portraits that slide in, the speaker in front, each
// with a voice of their own; Kai's race is a timed choice.
// rmp::lang English and Spanish (resources/lang.tsv): every line's
// #line: id is its key.
// rmp::save the afternoon, so Continue picks it up again.
//
// The files: src/story.cpp is the afternoon so far, src/people.cpp who walks
// and who is drawn in front of whom, src/scenery.cpp the town's map and its
// trees, src/look.cpp the theme and the Stage, src/scenes/ the four screens.
// resources/ is in folders by kind.
//
// Move with the arrows or WASD, talk with E (or A), pause with Escape.
// Run it: `rmp example 09_after_school`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "school.h"
RMP_GAME(game::TitleScene);include/school.h 128 lines#pragma once
// ---------------------------------------------------------------------------
// What every file of the afternoon shares: the story so far, the people, the
// scenes and the look.
// ---------------------------------------------------------------------------
#include <rmp/dialogue.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <string>
namespace game {
inline constexpr float TILE = 16; // the grid of maps/tiles.png and of the town
// Three pixels of the screen for each one of the art's, at the [window] size.
// A whole number: at 2.14 some of a tile's pixels were drawn wider than others.
inline constexpr float ZOOM = 3;
inline constexpr int FIRST_HOUR = 15; // the last bell
inline constexpr int FESTIVAL_HOUR = 19; // seven: the lanterns, and the evening's end
// THE STORY SO FAR: what every conversation reads and writes -- the
// $variables of dialogue/school.yarn are these, bound -- and what Continue
// restores.
struct Story {
int hour = FIRST_HOUR; // of the afternoon
float minutes = 0;
std::string with; // "", "mika" or "sora": who you go with
bool met_mika = false;
bool met_sora = false;
bool met_aki = false;
bool met_kai = false;
bool raced = false;
bool flyer = false; // picked up by the east trees
};
Story &story();
void new_story();
bool has_saved_story();
void load_story();
void save_story();
void forget_story();
// How the evening ends, from who you go with: "festival", "concert" or "home".
std::string evening();
// The look of every screen: Kenney's frames and font, a voice for each
// person, sounds on hover and click. Set once, by the title.
void set_look();
// The conversations: one Stage, Persona style, its portraits and voices.
rmp::ui::DialogueStage make_stage();
// The dusk that comes over the town as the afternoon goes: none at three.
Color dusk(const Story &at);
// The town into a scene's map, with a factory for its trees and street lamps
// and nobody else in it: the town scene registers the people before it calls
// map.spawn_objects(), the title and the ending call it as it is.
void load_town(rmp::Scene &scene);
// Anyone who walks, you included: the sheet's tag for where they go, or last
// went, and drawn in front of whatever stands further up the screen.
struct Character {
Vector2 facing{ 0, 1 }; // south, towards the screen
void _update(rmp::Object &self, float delta);
};
// Turns `who` to look at `at`.
void face(rmp::Object &who, Vector2 at);
// ---------------------------------------------------------------------------
// The scenes
// ---------------------------------------------------------------------------
class TitleScene : public rmp::Scene {
public:
void _ready() override;
void _update(float delta) override;
void _draw() override;
private:
float _clock = 0;
};
class TownScene : public rmp::Scene {
public:
void _ready() override;
void _update(float delta) override;
void _draw() override;
// A conversation began with whoever stands at `speaker`, or ended.
void talking(rmp::Handle<rmp::Object> speaker);
void done_talking();
// An ending the script asked for: shown once its last line has been read.
void ending(std::string kind);
// What the story's conversations need from the game.
void prepare(rmp::Dialogue &talk);
private:
void build();
void pass_time(float delta);
void draw_clock() const;
void draw_prompts() const;
rmp::Handle<rmp::Object> _you;
rmp::Handle<rmp::Object> _speaker; // whose Talker holds the conversation
rmp::Dialogue _seven; // what the clock says at seven, to nobody's Talker
rmp::ui::DialogueStage _stage = make_stage();
std::string _ending;
};
class PauseScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};
class EndScene : public rmp::Scene {
public:
explicit EndScene(std::string kind);
void _ready() override;
void _update(float delta) override;
void _draw() override;
private:
std::string _kind;
float _clock = 0;
};
} // namespace gamesrc/look.cpp 109 lines// The look: Kenney's beige frames and brown plates, his Kenpixel font, and a
// Stage whose people each have a face for every mood and a voice of their own.
#include "school.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/ui.h>
#include <array>
#include <string>
#include <string_view>
namespace game {
namespace {
constexpr float FRAME = 12; // panel.png's border, in its pixels
constexpr float PLATE = 10; // button.png's and plate.png's
constexpr float PORTRAIT_HEIGHT = 250;
const Color INK = { 62, 39, 35, 255 };
const Color CREAM = { 255, 246, 226, 255 };
const Color DUSK = { 255, 178, 92, 255 };
rmp::ui::Picture frame(std::string_view file, float border) {
return rmp::ui::NineSlice{ .texture =
rmp::assets::load_texture("ui/" + std::string(file)),
.left = border,
.top = border,
.right = border,
.bottom = border,
.scale = 2 };
}
// Who is in the script, their voice's pitch, and the colour of their plate.
struct Person {
std::string_view name;
std::string_view look;
float pitch;
Color plate;
};
constexpr std::array<Person, 4> PEOPLE{ {
{ "Mika", "mika", 1.25f, { 226, 92, 92, 255 } },
{ "Sora", "sora", 0.85f, { 92, 132, 226, 255 } },
{ "Aki", "aki", 1.1f, { 120, 180, 96, 255 } },
{ "Kai", "kai", 0.95f, { 230, 160, 60, 255 } },
} };
constexpr std::array<std::string_view, 3> MOODS{ "happy", "sad", "think" };
} // namespace
void set_look() {
rmp::ui::set_font(rmp::assets::load_font("fonts/font.ttf", 16));
rmp::ui::Theme look = rmp::ui::theme_light();
look.text = INK;
look.primary = DUSK;
look.sounds = { .hover = "audio/tap", .click = "audio/click", .volume = 0.5f };
look.styles.panel = {
.skin = rmp::ui::Skin{ .normal = frame("panel.png", FRAME) },
.shadow =
rmp::ui::Shadow{ .offset = { 0, 6 }, .blur = 12, .color = { 0, 0, 0, 110 } },
.padding_x = 30,
.padding_y = 24,
.gap = 12,
.motion = rmp::ui::Motion{ .appear = 0.25f, .appear_offset = 18 },
};
look.styles.button = {
.skin = rmp::ui::Skin{ .normal = frame("button.png", PLATE),
.press = frame("button_down.png", PLATE) },
.padding_x = 26,
.padding_y = 12,
.text = INK,
.motion = rmp::ui::Motion{ .hover_scale = 1.04f, .press_scale = 0.96f },
};
rmp::ui::set_theme(look);
}
rmp::ui::DialogueStage make_stage() {
rmp::ui::DialogueStage stage{
.flow = { .letters_per_second = 50,
.blip = "audio/tap",
.blip_every = 3,
.blip_jitter = 0.06f },
.portrait_height = PORTRAIT_HEIGHT,
.name_style = { .skin = rmp::ui::Skin{ .normal = frame("plate.png", PLATE) },
.padding_x = 22,
.padding_y = 8,
.text = CREAM },
};
for (const Person &p : PEOPLE) {
const std::string face = "portraits/" + std::string(p.look) + "_";
stage.portraits.push_back(
{ .speaker = std::string(p.name),
.picture = rmp::assets::load_texture(face + "neutral.png") });
for (const std::string_view mood : MOODS) {
stage.portraits.push_back({ .speaker = std::string(p.name),
.mood = std::string(mood),
.picture = rmp::assets::load_texture(
face + std::string(mood) + ".png") });
}
stage.speakers.push_back({ .name = std::string(p.name),
.pitch = p.pitch,
.name_style = { .tint = p.plate } });
}
return stage;
}
} // namespace gamesrc/people.cpp 39 lines// Everyone who walks through town: which way they look, and who is drawn in
// front of whom.
#include "school.h"
#include <cmath>
#include <string>
#include <string_view>
namespace game {
namespace {
// The sheet's tags end in the side they face: idle_s, walk_e.
std::string_view side(Vector2 facing) {
if (std::abs(facing.x) > std::abs(facing.y)) return facing.x > 0 ? "e" : "w";
return facing.y > 0 ? "s" : "n";
}
} // namespace
void Character::_update(rmp::Object &self, float /*delta*/) {
const bool walking = self.velocity.x != 0 || self.velocity.y != 0;
if (walking) facing = self.velocity;
self.sprite.play(std::string(walking ? "walk_" : "idle_") +
std::string(side(facing)));
// Every tag is drawn for its own side: nothing is mirrored.
self.flip_x = false;
// Lower on the screen is nearer: over whoever, and whatever, stands behind.
self.layer = static_cast<int>(self.position.y);
}
void face(rmp::Object &who, Vector2 at) {
if (auto character = who.get<Character>()) {
character->facing = { at.x - who.position.x, at.y - who.position.y };
}
}
} // namespace gamesrc/scenery.cpp 53 lines// The town as every scene shows it: the map, and the trees and street lamps
// standing in it, which are entities so that they can be drawn over whoever
// walks behind them.
#include "school.h"
#include <rmp/assets.h>
#include <rmp/tilemap.h>
#include <array>
#include <string_view>
namespace game {
namespace {
// The two tiles of each in maps/tiles.png, top-left first.
constexpr Rectangle GREEN_TREE{ 16 * TILE, 8 * TILE, TILE, 2 * TILE };
constexpr Rectangle ORANGE_TREE{ 16 * TILE, 11 * TILE, TILE, 2 * TILE };
constexpr Rectangle STREET_LAMP{ 7 * TILE, 6 * TILE, TILE, 2 * TILE };
// Who and what else the map holds: the town scene's, and nobody's elsewhere.
constexpr std::array<std::string_view, 5> CAST{ "Player", "Person", "Home", "Place",
"Flyer" };
// Two tiles standing on the lower one, in front of whoever is further up.
void stand(rmp::Scene &scene, const rmp::MapObject &o, Rectangle tiles) {
auto &standing = scene.spawn({ .position = o.position });
standing.sprite.texture = rmp::assets::load_texture("maps/tiles.png");
standing.sprite.source = tiles;
standing.sprite.origin = { 0.5f, 0.75f };
standing.layer = static_cast<int>(o.position.y);
// The map's cell under it is what stops you; the picture touches nothing.
standing.collision_layer = 0;
standing.collision_mask = 0;
}
} // namespace
void load_town(rmp::Scene &scene) {
scene.map = rmp::assets::load_map("maps/world.ldtk", "Town");
scene.map.on_object("Tree", [](rmp::Scene &into, const rmp::MapObject &o) {
stand(into, o, o.property_string("kind") == "green" ? GREEN_TREE : ORANGE_TREE);
});
scene.map.on_object("Lamp", [](rmp::Scene &into, const rmp::MapObject &o) {
stand(into, o, STREET_LAMP);
});
for (const std::string_view name : CAST) {
scene.map.on_object(name, [](rmp::Scene &, const rmp::MapObject &) {});
}
}
} // namespace gamesrc/scenes/end.cpp 91 lines// How the evening ended: the town at dusk, and -- at the festival, at the
// concert -- a sky of lanterns rising over it.
#include "school.h"
#include <rmp/assets.h>
#include <rmp/random.h>
#include <rmp/ui.h>
#include <array>
#include <cmath>
#include <utility>
namespace game {
namespace {
constexpr int LANTERNS = 40;
constexpr float RISE = 16; // world units a second
constexpr float SWAY = 0.7f; // turns of a sine a second
const Color DUSK = { 24, 20, 60, 150 };
const Color FLAME = { 255, 170, 70, 255 };
const Color GLOW = { 255, 120, 40, 60 };
// Where each lantern starts and how it drifts: seeded, so every run (and
// every e2e shot) draws the same sky.
struct Lantern {
Vector2 from;
float phase;
float size;
};
std::array<Lantern, LANTERNS> &lanterns() {
static std::array<Lantern, LANTERNS> all{};
return all;
}
} // namespace
EndScene::EndScene(std::string kind) : _kind(std::move(kind)) {}
void EndScene::_ready() {
load_town(*this);
map.spawn_objects(*this);
const Rectangle b = map.bounds();
camera.zoom = ZOOM;
camera.position = { b.x + b.width / 2, b.y + b.height / 3 };
for (Lantern &l : lanterns()) {
l = { { rmp::random::range(b.x, b.x + b.width),
rmp::random::range(b.y, b.y + b.height * 1.2f) },
rmp::random::range(0.0f, 6.28f),
rmp::random::range(2.0f, 4.0f) };
}
}
void EndScene::_update(float delta) { _clock += delta; }
void EndScene::_draw() {
// Dusk over the town; the lanterns are drawn in the world's coordinates.
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), DUSK);
if (_kind != "home") {
BeginMode2D(camera.raylib());
for (const Lantern &l : lanterns()) {
const Vector2 at{ l.from.x + std::sin(_clock * SWAY + l.phase) * 6,
l.from.y - _clock * RISE };
DrawCircleV(at, l.size * 2.5f, GLOW);
DrawCircleV(at, l.size, FLAME);
}
EndMode2D();
}
rmp::ui::begin();
rmp::ui::panel([this] {
if (_kind == "festival") {
rmp::ui::text("The Lantern Festival",
{ .size = rmp::ui::Size::LARGE, .wrap = false });
rmp::ui::text("You and Mika watch a thousand lanterns rise.",
{ .wrap = false });
} else if (_kind == "concert") {
rmp::ui::text("Front Row", { .size = rmp::ui::Size::LARGE, .wrap = false });
rmp::ui::text("Sora plays the best set of his life.", { .wrap = false });
} else {
rmp::ui::text("A Quiet Evening",
{ .size = rmp::ui::Size::LARGE, .wrap = false });
rmp::ui::text("The lanterns rise far away. Maybe next year.",
{ .wrap = false });
}
if (rmp::ui::button("Back to the title")) rmp::Scene::change<TitleScene>();
});
rmp::ui::end();
}
} // namespace gamesrc/scenes/pause.cpp 27 lines// The pause: the town waits below.
#include "school.h"
#include <rmp/input.h>
#include <rmp/ui.h>
namespace game {
void PauseScene::_update(float /*delta*/) {
if (rmp::input::just_pressed("pause")) rmp::Scene::pop();
}
void PauseScene::_draw() {
rmp::ui::overlay([] {
rmp::ui::panel([] {
rmp::ui::text("Paused", { .size = rmp::ui::Size::LARGE, .wrap = false });
if (rmp::ui::button("Back to town")) rmp::Scene::pop();
if (rmp::ui::button("To the title")) {
save_story();
rmp::Scene::change<TitleScene>();
}
});
});
}
} // namespace gamesrc/scenes/title.cpp 73 lines// The title: the town behind the menu, the camera drifting over it, and the
// language you read it in.
#include "school.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/text.h>
#include <rmp/ui.h>
#include <cmath>
namespace game {
namespace {
constexpr float DRIFT = 0.1f; // how fast the camera wanders
const Color TITLE = { 255, 214, 140, 255 };
const Color OUTLINE = { 62, 39, 35, 255 };
} // namespace
void TitleScene::_ready() {
rmp::app::set_stretch(rmp::app::Stretch::EXPAND);
set_look();
background = Color{ 60, 200, 168, 255 };
load_town(*this);
map.spawn_objects(*this);
camera.limits = map.bounds();
camera.zoom = ZOOM;
}
void TitleScene::_update(float delta) {
_clock += delta;
const Rectangle b = map.bounds();
camera.position = { b.x + (b.width / 2) + (std::sin(_clock * DRIFT) * b.width / 4),
b.y + (b.height / 2) +
(std::cos(_clock * DRIFT) * b.height / 5) };
}
void TitleScene::_draw() {
rmp::ui::begin();
rmp::ui::panel([] {
rmp::ui::Label title{ .text = "After School",
.size = 46,
.wrap = false,
.style = { .text = TITLE,
.text_outline = rmp::ui::TextOutline{
.width = 3, .color = OUTLINE } } };
title.show();
rmp::ui::text("The lantern festival starts at seven.",
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
if (has_saved_story() && rmp::ui::button("Continue")) {
load_story();
rmp::Scene::change<TownScene>();
}
if (rmp::ui::button("New afternoon")) {
new_story();
rmp::Scene::change<TownScene>();
}
// The languages lang.tsv has, each in its own words.
rmp::ui::row([] {
for (const std::string &code : rmp::lang::available()) {
if (rmp::ui::button(rmp::Text(rmp::lang::name(code))))
rmp::lang::set(code);
}
});
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
});
rmp::ui::end();
}
} // namespace gamesrc/scenes/town.cpp 300 lines// The town: the map, you, whoever LDtk put in it, and the conversations.
//
// Everything here is an entity of maps/world.ldtk. A Person is a Talker: their
// `node` of dialogue/school.yarn, their `look` (which sheet walks around, which
// portraits the Stage shows). A Place is where a <<walk who place>> of the
// script goes, and Home is the way out of the afternoon. The trees and the
// street lamps are src/scenery.cpp's, in every scene that shows the town.
#include "school.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/behavior.h>
#include <rmp/dialogue.h>
#include <rmp/input.h>
#include <rmp/tilemap.h>
#include <rmp/ui.h>
#include <cmath>
#include <map>
#include <string>
#include <utility>
namespace game {
namespace {
constexpr float SPEED = 72; // yours, in world units a second
constexpr float STROLL = 44; // theirs, walking where the script sends them
constexpr float ARRIVED = 6; // close enough to a place
constexpr float MINUTES_A_SECOND = 3; // the afternoon's pace
constexpr float MINUTES_AN_HOUR = 60;
constexpr float KAI_SECONDS = 4; // Kai's race: say yes in time
constexpr float CAMERA_DRIFT = 8; // how quickly the view catches up with you
constexpr Vector2 FEET{ 10, 6 }; // what of a person stops at a wall
constexpr Vector2 OVER_HEAD{ 0, -14 }; // where a person's prompt floats
constexpr int ON_THE_GROUND = -1; // drawn under everyone
const Color INK = { 62, 39, 35, 235 };
const Color CREAM = { 255, 246, 226, 255 };
constexpr Rectangle POSTER{ 11 * TILE, 13 * TILE, TILE, TILE }; // in maps/tiles.png
// Where a <<walk>> goes, by the names LDtk gives them, and who is in town.
struct Town {
std::map<std::string, Vector2, std::less<>> places;
std::map<std::string, rmp::Handle<rmp::Object>, std::less<>> people;
};
Town &town() { return rmp::global<Town>(); }
bool close_to(Vector2 a, Vector2 b) {
return std::hypot(a.x - b.x, a.y - b.y) <= ARRIVED;
}
// Someone with a sheet of their own, standing on their feet.
rmp::Object &person(rmp::Scene &scene, Vector2 position, std::string_view look) {
auto &someone = scene.spawn({ .position = position });
someone.sprite.sheet =
rmp::assets::load_sheet("sprites/" + std::string(look) + ".aseprite");
someone.collider = rmp::rect(FEET);
someone.solid = true;
return someone;
}
// Sends `who` to one of the map's places; the dialogue waits until they are there.
void walk(rmp::Dialogue &talk, std::string_view who, std::string_view where) {
const auto walker = town().people.find(who);
const auto place = town().places.find(where);
if (walker == town().people.end() || place == town().places.end()) return;
const rmp::Handle<rmp::Object> them = walker->second;
const Vector2 to = place->second;
if (const auto o = them.get()) {
if (auto path = o->get<rmp::behavior::Pathfind>()) path->goal = to;
}
talk.wait_until([them, to, asked = 0]() mutable {
const auto o = them.get();
if (!o || close_to(o->position, to)) return true;
// With no way there the script goes on, rather than wait for ever.
const auto path = o->get<rmp::behavior::Pathfind>();
return ++asked > 2 && (!path || path->arrived());
});
}
} // namespace
void TownScene::prepare(rmp::Dialogue &talk) {
Story &s = story();
talk.bind("$hour", s.hour);
talk.bind("$with", s.with);
talk.bind("$met_mika", s.met_mika);
talk.bind("$met_sora", s.met_sora);
talk.bind("$met_aki", s.met_aki);
talk.bind("$met_kai", s.met_kai);
talk.bind("$raced", s.raced);
// Whether you carry the item: "flyer" is the only one in town.
talk.on_function("has_item", [](const std::string &item) -> bool {
return item == "flyer" && story().flyer;
});
// The view goes with whoever the script walks somewhere, until the
// conversation is over.
talk.on_command("walk",
[this, &talk](const std::string &who, const std::string &where) {
walk(talk, who, where);
if (const auto walker = town().people.find(who);
walker != town().people.end()) {
camera.follow = walker->second;
}
});
// The evening's end: festival, concert or home.
talk.on_command("ending", [this](std::string kind) { ending(std::move(kind)); });
}
void TownScene::_ready() {
background = Color{ 60, 200, 168, 255 };
rmp::input::action("pause", KEY_ESCAPE, KEY_P, GAMEPAD_BUTTON_MIDDLE_RIGHT);
rmp::input::action("interact", KEY_E, KEY_SPACE, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
build();
}
void TownScene::build() {
town() = Town{};
load_town(*this);
_seven = rmp::assets::load_dialogue("dialogue/school.yarn");
prepare(_seven);
auto &you = person(*this, {}, "you");
you.add<rmp::behavior::TopDown>({ .speed = SPEED, .idle = "", .walk = "" });
you.add<Character>({ .facing = { 0, -1 } });
_you = you.handle();
map.on_object("Player", [this](rmp::Scene &, const rmp::MapObject &o) {
if (const auto y = _you.get()) y->position = o.position;
});
map.on_object("Place", [](rmp::Scene &, const rmp::MapObject &o) {
town().places[std::string(o.property_string("name"))] = o.position;
});
map.on_object("Person", [this](rmp::Scene &scene, const rmp::MapObject &o) {
auto &them = person(scene, o.position, o.property_string("look", "mika"));
// Nobody is pushed out of their conversation.
them.immovable = true;
them.add<rmp::behavior::Pathfind>({ .speed = STROLL, .clearance = FEET.x / 2 });
them.add<Character>();
rmp::behavior::Talker talker = rmp::behavior::Talker::from(o);
talker.player = _you;
talker.on_load = [this](rmp::Dialogue &d) { prepare(d); };
const rmp::Handle<rmp::Object> me = them.handle();
talker.on_talk = [this, me](rmp::Dialogue &) { talking(me); };
talker.on_done = [this] { done_talking(); };
them.add<rmp::behavior::Talker>(std::move(talker));
town().people[std::string(o.property_string("name", "Mika"))] = me;
});
map.on_object("Home", [this](rmp::Scene &scene, const rmp::MapObject &o) {
auto &home = scene.spawn({ .position = o.position });
home.visible = false;
rmp::behavior::Talker talker = rmp::behavior::Talker::from(o);
talker.player = _you;
talker.action = ""; // walking onto it is enough
talker.on_load = [this](rmp::Dialogue &d) { prepare(d); };
const rmp::Handle<rmp::Object> me = home.handle();
talker.on_talk = [this, me](rmp::Dialogue &) { talking(me); };
talker.on_done = [this] { done_talking(); };
home.add<rmp::behavior::Talker>(std::move(talker));
});
map.on_object("Flyer", [](rmp::Scene &scene, const rmp::MapObject &o) {
if (story().flyer) return;
auto &flyer = scene.spawn({ .position = o.position, .shape = rmp::circle(6) });
flyer.sprite.texture = rmp::assets::load_texture("maps/tiles.png");
flyer.sprite.source = POSTER;
flyer.layer = ON_THE_GROUND;
flyer.add<rmp::behavior::Collectible>(
{ .sound = "audio/switch", .on_collect = [](rmp::Object &, rmp::Object &) {
story().flyer = true;
rmp::ui::notify("You found a festival flyer!");
} });
});
map.spawn_objects(*this);
camera.follow = _you;
camera.limits = map.bounds();
camera.smoothing = CAMERA_DRIFT;
camera.zoom = ZOOM;
}
void TownScene::talking(rmp::Handle<rmp::Object> speaker) {
_speaker = speaker;
_stage.ours = {};
const auto them = speaker.get();
const auto talker =
them ? them->get<rmp::behavior::Talker>() : rmp::Ref<rmp::behavior::Talker>{};
// Kai's race: a choice with a clock on it.
_stage.flow.choice_seconds = talker && talker->node == "Kai" ? KAI_SECONDS : 0;
_stage.flow.default_choice = 1;
const auto you = _you.get();
if (!you) return;
// You stop where you are, and the two of you look at each other.
you->enable<rmp::behavior::TopDown>(false);
you->velocity = {};
if (them) {
face(*you, them->position);
face(*them, you->position);
}
}
void TownScene::done_talking() {
_speaker = {};
camera.follow = _you;
if (const auto you = _you.get()) you->enable<rmp::behavior::TopDown>(true);
save_story();
if (_ending.empty()) return;
forget_story();
rmp::Scene::change<EndScene>(std::exchange(_ending, {}));
}
void TownScene::ending(std::string kind) { _ending = std::move(kind); }
// The afternoon goes on while you walk, not while you talk; at seven it is over.
void TownScene::pass_time(float delta) {
Story &s = story();
if (s.hour >= FESTIVAL_HOUR) {
s.hour = FESTIVAL_HOUR;
s.minutes = 0;
if (_seven.start("Seven")) talking({});
return;
}
s.minutes += delta * MINUTES_A_SECOND;
while (s.minutes >= MINUTES_AN_HOUR && s.hour < FESTIVAL_HOUR) {
s.minutes -= MINUTES_AN_HOUR;
++s.hour;
}
}
void TownScene::_update(float delta) {
const bool at_seven = _seven.running();
if (_speaker || at_seven) return;
// Seven's last line was read: the evening it asked for.
if (!_ending.empty()) {
done_talking();
return;
}
if (rmp::input::just_pressed("pause")) {
rmp::Scene::push<PauseScene>();
return;
}
pass_time(delta);
}
void TownScene::draw_clock() const {
const Story &s = story();
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .padding = 10 });
rmp::ui::panel({ .box = { .gap = 2, .padding = 12 } }, [&] {
rmp::ui::text(
rmp::Text("{hour}:{minutes} pm",
{ { "hour", s.hour - 12 },
{ "minutes", TextFormat("%02d", static_cast<int>(s.minutes)) } }),
{ .wrap = false });
rmp::ui::text(s.flyer ? rmp::Text("A festival flyer")
: rmp::Text("The festival is at seven"),
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
});
rmp::ui::end();
}
// "Talk" over whoever is close enough to talk to.
void TownScene::draw_prompts() const {
for (const auto &[name, handle] : town().people) {
const auto them = handle.get();
const auto talker =
them ? them->get<rmp::behavior::Talker>() : rmp::Ref<rmp::behavior::Talker>{};
if (!talker || !talker->in_range()) continue;
rmp::ui::begin();
rmp::ui::at(them->position, { .offset = OVER_HEAD, .id = name }, [] {
rmp::ui::Label prompt{ .text = "Talk",
.wrap = false,
.style = { .background = INK,
.radius = 6,
.padding_x = 8,
.padding_y = 3,
.text = CREAM } };
prompt.show();
});
rmp::ui::end();
}
}
void TownScene::_draw() {
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), dusk(story()));
draw_clock();
const auto them = _speaker.get();
auto talker =
them ? them->get<rmp::behavior::Talker>() : rmp::Ref<rmp::behavior::Talker>{};
if (!talker && !_seven.running()) {
draw_prompts();
return;
}
rmp::ui::begin({ .placement = rmp::ui::Align::BOTTOM_CENTER, .grow = true });
_stage.show(talker ? talker->conversation() : _seven);
rmp::ui::end();
}
} // namespace gamesrc/story.cpp 76 lines// The story so far, kept with rmp::save, and what follows from it: how the
// evening ends, and how late the light says it is.
#include "school.h"
#include <rmp/app.h>
#include <rmp/save.h>
#include <algorithm>
#include <string>
namespace game {
namespace {
constexpr std::string_view SLOT = "after_school";
constexpr float MINUTES_AN_HOUR = 60;
// The light at seven, over everything: the afternoon fades towards it.
constexpr Color NIGHTFALL = { 52, 28, 96, 120 };
} // namespace
Story &story() { return rmp::global<Story>(); }
void new_story() { story() = Story{}; }
bool has_saved_story() { return rmp::save::exists(SLOT); }
void load_story() {
rmp::Value v;
rmp::save::read(SLOT, v);
Story &s = story();
s.hour = std::clamp(v["hour"].as_int(FIRST_HOUR), FIRST_HOUR, FESTIVAL_HOUR);
s.minutes = std::clamp(v["minutes"].as_float(0), 0.0f, MINUTES_AN_HOUR - 1);
s.with = std::string(v["with"].as_string(""));
s.met_mika = v["met_mika"].as_bool();
s.met_sora = v["met_sora"].as_bool();
s.met_aki = v["met_aki"].as_bool();
s.met_kai = v["met_kai"].as_bool();
s.raced = v["raced"].as_bool();
s.flyer = v["flyer"].as_bool();
}
void save_story() {
const Story &s = story();
rmp::Value v;
v["hour"] = s.hour;
v["minutes"] = s.minutes;
v["with"] = s.with;
v["met_mika"] = s.met_mika;
v["met_sora"] = s.met_sora;
v["met_aki"] = s.met_aki;
v["met_kai"] = s.met_kai;
v["raced"] = s.raced;
v["flyer"] = s.flyer;
rmp::save::write(SLOT, v);
}
void forget_story() { rmp::save::remove(SLOT); }
std::string evening() {
const Story &s = story();
if (s.with == "mika") return "festival";
if (s.with == "sora") return "concert";
return "home";
}
Color dusk(const Story &at) {
const float hours =
static_cast<float>(at.hour - FIRST_HOUR) + at.minutes / MINUTES_AN_HOUR;
const float gone = std::clamp(hours / (FESTIVAL_HOUR - FIRST_HOUR), 0.0f, 1.0f);
// Slow at first, then quickly: the last hour is the one that darkens.
return Fade(NIGHTFALL, gone * gone * NIGHTFALL.a / 255.0f);
}
} // namespace gamehttps://omardev29.github.io/rmp-docs/examples/input/index.html
https://omardev29.github.io/rmp-docs/examples/input/01_actions.html
Named actions with as many bindings as you like, eight-direction movement in one call, and the routing that stops a finger on a UI button from also firing the gun — which costs no code at all.

From a clone of the framework:
rmp example 01_actionsRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
jump | Space, gamepad right face down |
fire | left mouse button, gamepad right trigger 1 |
pause | Esc, gamepad middle right |
aim_left | Q |
move_left | A, ←, gamepad left face left |
move_right | D, →, gamepad left face right |
move_up | W, ↑, gamepad left face up |
move_down | S, ↓, gamepad left face down |
Every file of examples/input/01_actions, as it is at the commit this site documents (on GitHub).
src/main.cpp 102 lines// ---------------------------------------------------------------------------
// examples/input/01_actions/src/main.cpp
//
// Named actions, eight-direction movement in one line, and the part nobody
// thinks about until it bites: who gets to hear a press.
//
// Run it: `rmp example 01_actions`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/input.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
class PauseScene : public rmp::Scene {
public:
void _draw() override {
rmp::ui::begin();
rmp::ui::text("Paused");
if (rmp::ui::button("Resume")) rmp::Scene::pop();
rmp::ui::end();
}
};
class GameScene : public rmp::Scene {
public:
void _ready() override {
// The name first, then as many bindings as you like. The TYPE of each
// argument says which device it is — KeyboardKey, MouseButton and
// GamepadButton are three different enums — so passing anything else is
// a compile error, and there is no string to spell wrong.
rmp::input::action("jump", KEY_SPACE, GAMEPAD_BUTTON_RIGHT_FACE_DOWN);
rmp::input::action("fire", MOUSE_BUTTON_LEFT, GAMEPAD_BUTTON_RIGHT_TRIGGER_1);
rmp::input::action("pause", KEY_ESCAPE, GAMEPAD_BUTTON_MIDDLE_RIGHT);
// An analogue stick needs to know which half counts, and stick() is the
// only place you write something that is not a plain raylib constant.
rmp::input::action("aim_left", KEY_Q,
rmp::input::stick(GAMEPAD_AXIS_RIGHT_X, -1));
// Defining these here is safe even though the player enters this scene
// over and over: registering a name again REPLACES it, never adds to it.
}
void _update(float delta) override {
// Eight directions, keyboard and d-pad and stick at once, normalised so
// the diagonal is not 41 % faster — with no configuration at all. The
// six factory actions (move_*, ui_accept, ui_cancel) are already there,
// and they are ordinary actions you can redefine.
_position.x += rmp::input::vector().x * _speed * delta;
_position.y += rmp::input::vector().y * _speed * delta;
if (rmp::input::just_pressed("jump")) jump();
// AND THIS IS THE PART THAT MATTERS. "fire" is bound to the left mouse
// button, and there is a pause menu one push away with a Resume button
// in the middle of the screen. A finger that presses Resume must not
// also shoot.
//
// It does not, and nothing here says so. A query BY NAME is routed: an
// action on a mouse button goes quiet while the UI wants the pointer,
// one on a key goes quiet while a text field has the keyboard, and all
// of them go quiet in a scene with something above it that kept the
// input. Compare with what it takes by hand:
//
// if (!rmp::ui::wants_pointer() && IsMouseButtonPressed(0)) shoot();
//
if (rmp::input::just_pressed("fire")) shoot();
if (rmp::input::just_pressed("pause")) rmp::Scene::push<PauseScene>();
// The escape hatch, for when you want to know regardless of who else is
// listening. The argument type says which of the two you asked for, and
// you can see it at the call site.
if (rmp::input::pressed(KEY_LEFT_SHIFT))
_speed = 400.0f;
else
_speed = 200.0f;
}
void _draw() override {
DrawCircleV(_position, 16, SKYBLUE);
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
// The pointer is one pointer: mouse on a desktop, finger on a phone,
// and the same code on every target with no #ifdef.
rmp::ui::text(rmp::input::pointer_down() ? "pointer down" : "pointer up");
rmp::ui::text(TextFormat("%d jumps, %d shots", _jumps, _shots));
rmp::ui::end();
}
private:
void jump() { ++_jumps; }
void shoot() { ++_shots; }
Vector2 _position{ 400, 225 };
float _speed = 200.0f;
int _jumps = 0;
int _shots = 0;
};
RMP_GAME(GameScene);https://omardev29.github.io/rmp-docs/examples/platform/index.html
rmp/ui.h stands alone. One translation unit that includes <rmp/ui.h> and nothing else of ours, and no main() on purpose: it is compiled, never linked, and if it stops compiling the header has grown a dependency.https://omardev29.github.io/rmp-docs/examples/platform/02_mobile_raymob.html
The raymob mobile API: vibration, soft keyboard, sensors, orientation, app storage. Android only.

It calls raymob's Android API — vibration, the soft keyboard, the sensors — which a browser does not have.
From a clone of the framework:
rmp example 02_mobile_raymobRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
| read directly | Back, K, H |
Every file of examples/platform/02_mobile_raymob, as it is at the commit this site documents (on GitHub).
src/main.cpp 78 lines// ---------------------------------------------------------------------------
// examples/platform/02_mobile_raymob/src/main.cpp
//
// How to use the raymob mobile API (thirdparty/raymob/raymob.h): vibration,
// soft keyboard, sensors, screen orientation, keep-screen-on and app storage.
//
// Unlike <admob.h>, these functions exist ONLY on Android — raymob.h declares
// nothing elsewhere. So guard the calls with #ifdef __ANDROID__ (or keep them
// in Android-only code paths). The rest of your game still runs on desktop;
// these features simply compile out off-device.
//
// Vibrate / VibrateMS / VibrateEx -> haptics
// ShowSoftKeyboard / HideSoftKeyboard -> on-screen keyboard
// GetLastSoftKeyChar / ... -> read what was typed
// InitSensorManager / EnableSensor -> accelerometer / gyroscope
// GetAccelerotmerAxis / GetGyroscopeAxis
// KeepScreenOn(bool) -> stop the screen from sleeping
// GetScreenOrientation() -> portrait / landscape
// GetAppStoragePath / WriteToAppStorage / ReadFromAppStorage
//
// Run it: `rmp example 02_mobile_raymob`.
// ---------------------------------------------------------------------------
#include <raylib.h>
#include <rmp/app.h> // RMP_ENTRY_POINT
#ifdef __ANDROID__
#include <raymob.h>
#endif
static void on_ready() {
InitWindow(800, 450, "raymob mobile example");
#ifdef __ANDROID__
KeepScreenOn(true); // don't let the screen sleep
InitSensorManager(); // needed before enabling any sensor
EnableSensor(SENSOR_ACCELEROMETER); // turn the accelerometer on
#endif
}
static void on_frame(float) {
#ifdef __ANDROID__
// Haptics: vibrate for 50 ms whenever the screen is tapped.
if (IsKeyPressed(KEY_BACK) || IsGestureDetected(GESTURE_TAP)) VibrateMS(50);
// Soft keyboard: toggle it and read the last typed character.
if (IsKeyPressed(KEY_K)) ShowSoftKeyboard();
if (IsKeyPressed(KEY_H)) HideSoftKeyboard();
char lastKey = GetLastSoftKeyChar(); // 0 if nothing new was typed
ClearLastSoftKey();
// Sensors: read the accelerometer axis.
Vector3 accel = GetAccelerotmerAxis();
Orientation orient = GetScreenOrientation();
#endif
BeginDrawing();
ClearBackground(RAYWHITE);
#ifdef __ANDROID__
DrawText(TextFormat("accel: %.2f %.2f %.2f", accel.x, accel.y, accel.z), 10, 40, 20,
DARKGRAY);
DrawText(TextFormat("last key: %c orientation: %d", lastKey ? lastKey : '-',
static_cast<int>(orient)),
10, 80, 20, DARKGRAY);
#else
DrawText("raymob mobile features only run on Android", 10, 40, 20, GRAY);
#endif
EndDrawing();
}
static void on_exit() {
#ifdef __ANDROID__
DisableSensor(SENSOR_ACCELEROMETER);
#endif
CloseWindow();
}
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);https://omardev29.github.io/rmp-docs/examples/platform/03_minimal_includes.html
The proof that rmp/ui.h stands alone. One translation unit that includes <rmp/ui.h> and nothing else of ours, and no main() on purpose: it is compiled, never linked, and if it stops compiling the header has grown a dependency.
It has no main() on purpose: it is compiled and never run, to prove that rmp/ui.h stands alone.
From a clone of the framework:
rmp example 03_minimal_includesEvery file of examples/platform/03_minimal_includes, as it is at the commit this site documents (on GitHub).
src/hud.cpp 65 lines// ---------------------------------------------------------------------------
// What you include is what you use.
//
// There is no umbrella header. `#include <rmp/ui.h>` gives you the interface
// layer and NOTHING else: no entry point, no asset layer, no ads, no <raymath.h>
// and no <math.h> behind it. That is the point of the split, and it only stays
// true if something checks — so this file is that check as well as an example.
//
// In a real game this is what your files look like. The one that draws the HUD
// knows about the interface and nothing else, so it recompiles when you change
// the HUD and not when you change the asset pipeline:
//
// src/hud.h void draw_hud(int score, float health);
// src/hud.cpp #include <rmp/ui.h> <- this file
// src/main.cpp #include <rmp/app.h>
//
// It has no main() on purpose. The examples build compiles it and runs
// nothing, which is the right check here: what is being tested is whether the
// header is enough on its own, not whether a program runs.
//
// The headers, and what each one is for:
//
// rmp/app.h the entry point, rmp::app::quit() and rmp::global
// rmp/scene.h rmp::Scene and rmp::Camera
// rmp/object.h rmp::Object and rmp::Handle
// rmp/behavior.h rmp::behavior: TopDown, Platformer, Health and the rest
// rmp/input.h rmp::input: named actions and the pointer
// rmp/ui.h rmp::ui: menus, buttons, layout, Theme
// rmp/assets.h rmp::assets: loading from resources/
// rmp/tilemap.h rmp::Tilemap: LDtk and Tiled maps
// rmp/audio.h rmp::audio: sounds and music, by name
// rmp/save.h rmp::save and rmp::Value: saving the game
// rmp/random.h rmp::random: one seeded generator
// rmp/ads.h rmp::ads: interstitial and rewarded
// rmp/math.h vectors, rectangles, colours, and the arithmetic
// rmp/config.h RMP_WINDOW_TITLE and the rest of the .toml -- every
// header above brings it, so you never type this one
//
// If you get "'rmp::input' has not been declared", you are missing the header
// that declares it. The compiler is telling you the truth, which is more than
// an umbrella header ever does.
// ---------------------------------------------------------------------------
#include <rmp/ui.h>
#include <string>
void draw_hud(int score, float health) {
// A HUD pinned to the top of the screen, and every measurement in it comes
// from the theme, so it scales with everything else.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::panel([&] {
rmp::ui::row({ .gap = 24, .grow_x = true }, [&] {
rmp::ui::text("SCORE");
// Safe with a temporary: the string is copied into the frame arena
// on the way in, because Clay keeps the pointer rather than the text.
rmp::ui::text(std::to_string(score));
rmp::ui::spacer();
rmp::ui::progress(health, { .width = 160 });
});
});
rmp::ui::end();
}https://omardev29.github.io/rmp-docs/examples/scenes/index.html
src/scenes/: a menu that changes to a game, and a game that pushes a pause menu onto itself.[window] stretch, in a window that is not the design's size: a court that is letterboxed, expanded or shown 1:1, a key and a button to go round the three, and a HUD that stays on the court.https://omardev29.github.io/rmp-docs/examples/scenes/01_stack.html
The whole model, one scene per file under src/scenes/: a menu that changes to a game, and a game that pushes a pause menu onto itself. The pause scene contains no policy — freezing the world is what the defaults already do, and its whole _draw() is one rmp::ui::overlay() — and nothing in the game knows it exists. A HUD over a scene being played: the arrows move the player, not the focus, and Tab walks into the HUD. Plus rmp::global<T>() for the score that survives the transition. Start here.

From a clone of the framework:
rmp example 01_stackRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
move_left | A, ←, gamepad left face left |
move_right | D, →, gamepad left face right |
move_up | W, ↑, gamepad left face up |
move_down | S, ↓, gamepad left face down |
Every file of examples/scenes/01_stack, as it is at the commit this site documents (on GitHub).
src/main.cpp 39 lines// ---------------------------------------------------------------------------
// examples/scenes/01_stack/src/main.cpp
//
// The whole scene model: a menu that goes to a game, and a game that puts a
// pause overlay on top of itself. One scene per file under src/scenes/, the
// way Godot does it and the way a real project is laid out -- src/ is globbed
// recursively by all four build systems, so a new scene file costs no CMake,
// no Gradle and no Xcode edit.
//
// Four things are worth watching for, because they are what the stack buys
// you and none of them is written here:
//
// 1. PauseScene contains NO POLICY. The defaults are a pause menu -- what is
// underneath freezes, stays visible, and stops receiving input -- so
// pushing it stops the world. It works the same with five enemies as with
// ten thousand, because what is suspended is the SCENE. Its whole _draw()
// is one rmp::ui::overlay(): the veil, the clicks it swallows and the
// focus on Resume come with it.
// 2. Nothing in GameScene knows the pause menu exists. There is no
// `if (paused) return;` at the top of _update, and no `player.freeze()`.
// 3. `Scene::change<T>()` from inside a _draw() is safe. The transition is
// deferred to the end of the frame, so the scene that asked for it
// survives the rest of the frame it asked from.
// 4. The arrows move the player and not the focus. GameScene reads them, so
// it is a scene being played, and its HUD's Pause button takes the keys
// only when the player walks into it with Tab.
//
// Run it: `rmp example 01_stack`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "scenes/main_menu.h"
// Four lines in a real project, and one of them is this. RMP_GAME opens the
// window from [window] in raylib_multiplatform.toml, enters this scene, and
// writes the entry point for whichever of the seventeen targets you are
// building.
RMP_GAME(MainMenuScene);include/progress.h 9 lines#pragma once
// State that has to survive a scene change lives in exactly one place. A scene
// owns its state and loses it on the way out, which is right for the enemies
// and wrong for the score. Every scene reaches this through
// rmp::global<Progress>(), and there is exactly one for the life of the app.
struct Progress {
int best_score = 0;
int runs = 0;
};src/scenes/game.cpp 56 lines#include "game.h"
#include "pause.h"
#include "progress.h"
#include <rmp/app.h>
#include <rmp/input.h>
#include <rmp/ui.h>
#include <string>
namespace {
constexpr float PLAYER_SPEED = 220.0f; // units per second
} // namespace
void GameScene::_ready() {
++rmp::global<Progress>().runs;
// The player: a dot, kept inside the window by Edge::CLAMP.
rmp::Shape dot = rmp::circle(14);
dot.color = rmp::ui::current_theme().primary;
_player = spawn({ .position = { 400, 260 }, .shape = dot, .edges = rmp::Edge::CLAMP })
.handle();
}
void GameScene::_update(float delta) {
// No pause check. When PauseScene is on top, this is not called at all.
_elapsed += delta;
_score = static_cast<int>(_elapsed * 10.0f);
// The arrows, WASD, the d-pad and the left stick, in one call. Reading
// them is what makes this a scene being PLAYED -- see the HUD below.
const Vector2 move = rmp::input::vector();
if (_player) _player->velocity = { move.x * PLAYER_SPEED, move.y * PLAYER_SPEED };
}
void GameScene::_draw() {
// A HUD over a game being played. This scene reads the arrows above, so
// the framework does not hand its Pause button the focus: the arrows,
// Enter and Space stay the game's, a click or a tap presses it, and Tab
// walks into it from the keyboard (Escape walks back out). A menu that is
// the whole screen -- the main menu, the pause menu -- reads no keys of
// its own, and its first button has the focus from the start.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::text("Level " + std::to_string(_level));
// Safe: rmp::ui interns every string it is given into a frame arena, so a
// temporary like this one outlives the layout that reads it.
rmp::ui::text("Score " + std::to_string(_score));
if (rmp::ui::button("Pause")) rmp::Scene::push<PauseScene>();
rmp::ui::end();
}
void GameScene::_end() {
Progress &p = rmp::global<Progress>();
if (_score > p.best_score) p.best_score = _score;
}src/scenes/game.h 22 lines#pragma once
#include <rmp/object.h>
#include <rmp/scene.h>
class GameScene : public rmp::Scene {
public:
// Constructor arguments cross a transition the way arguments normally
// cross into an object: Scene::change<GameScene>(3) forwards to here. No
// std::any, no dictionary, no globals.
explicit GameScene(int level) : _level(level) {}
void _ready() override;
void _update(float delta) override;
void _draw() override;
void _end() override;
private:
int _level = 1;
int _score = 0;
float _elapsed = 0.0f;
rmp::Handle<rmp::Object> _player;
};src/scenes/main_menu.cpp 31 lines#include "main_menu.h"
#include "game.h"
#include "progress.h"
#include <rmp/app.h>
#include <rmp/ui.h>
#include <string>
void MainMenuScene::_draw() {
rmp::ui::begin();
rmp::ui::text("Scene stack example");
// change<T>() from inside _draw(), which is the case the deferral exists
// for: this scene is destroyed by that call, and it is the scene the call
// is being made from.
if (rmp::ui::button("Play")) rmp::Scene::change<GameScene>(1);
const Progress &p = rmp::global<Progress>();
if (p.runs > 0) {
rmp::ui::text("Best " + std::to_string(p.best_score),
{ .color = rmp::ui::ColorRole::MUTED });
}
#if !defined(PLATFORM_IOS)
// Inert on iPhone: Apple rejects apps that terminate themselves.
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
rmp::ui::end();
}src/scenes/main_menu.h 7 lines#pragma once
#include <rmp/scene.h>
class MainMenuScene : public rmp::Scene {
public:
void _draw() override;
};src/scenes/pause.cpp 17 lines#include "pause.h"
#include "main_menu.h"
#include <rmp/ui.h>
void PauseScene::_draw() {
// overlay() is a frame of its own, in front of everything drawn before it
// -- the game underneath, its world AND its HUD -- dimmed behind a veil.
// The veil takes every click, so the HUD's Pause under it presses
// nothing, and the first button has the focus, so Enter is Resume.
rmp::ui::overlay([] {
rmp::ui::text("Paused");
if (rmp::ui::button("Resume")) rmp::Scene::pop();
if (rmp::ui::button("Give up")) rmp::Scene::change<MainMenuScene>();
});
}src/scenes/pause.h 10 lines#pragma once
#include <rmp/scene.h>
// Every default untouched. This is the whole example's point:
// push<PauseScene>() freezes the game, keeps it on screen behind the menu, and
// takes the input -- and not one line in this class says so.
class PauseScene : public rmp::Scene {
public:
void _draw() override;
};https://omardev29.github.io/rmp-docs/examples/scenes/02_stretch.html
[window] stretch, in a window that is not the design's size: a court that is letterboxed, expanded or shown 1:1, a key and a button to go round the three, and a HUD that stays on the court. Resize it. The camera, the pointer and the interface follow the mode, and nothing in the scene asks which one is on.

From a clone of the framework:
rmp example 02_stretchRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
next_mode | M, gamepad right face up |
Every file of examples/scenes/02_stretch, as it is at the commit this site documents (on GitHub).
src/main.cpp 143 lines// ---------------------------------------------------------------------------
// examples/scenes/02_stretch/src/main.cpp
//
// [window] stretch: what the world does in a window that is not the size it
// was designed for -- a desktop window dragged wider, a phone held upright, a
// 21:9 monitor. [window] width and height in raylib_multiplatform.toml are the
// DESIGN size, 800x450 here, and this court is exactly that big.
//
// LETTERBOX the design, scaled to fit and centred; the rest of the window is
// bars of the clear colour (`background`, below). Every player
// sees the same court, and the HUD stays on it.
// EXPAND scaled the same, with no bars: more of the world shows where the
// window is longer than the design -- the stands around the court.
// NONE 1:1 around the camera: a bigger window shows more of the world
// at the same size, a smaller one less.
//
// Resize the window, and press M (the gamepad's Y, or the button) to go round
// the three. The camera, the pointer and the interface follow the mode, so
// nothing below knows which one is on: the court is drawn in world units, and
// the ball bounces off the court's lines whatever the window does.
//
// The framework's .toml says letterbox, so that is where this starts. On
// Android and on a Linux console, raylib scales the design to the display
// itself, so every mode is a letterbox there.
//
// Run it: `rmp example 02_stretch`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/input.h>
#include <rmp/object.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <string>
#include <string_view>
namespace {
// The court's grass, its lines, and the stands beyond it: the part of the
// world only EXPAND and NONE ever show.
constexpr Color STANDS{ 52, 64, 92, 255 };
constexpr Color GRASS{ 46, 125, 60, 255 };
constexpr Color LINE = WHITE;
std::string_view mode_name() {
switch (rmp::app::stretch()) {
case rmp::app::Stretch::NONE:
return "NONE";
case rmp::app::Stretch::LETTERBOX:
return "LETTERBOX";
case rmp::app::Stretch::EXPAND:
return "EXPAND";
}
return "?";
}
// LETTERBOX, EXPAND, NONE, and round again.
void next_mode() {
switch (rmp::app::stretch()) {
case rmp::app::Stretch::LETTERBOX:
rmp::app::set_stretch(rmp::app::Stretch::EXPAND);
break;
case rmp::app::Stretch::EXPAND:
rmp::app::set_stretch(rmp::app::Stretch::NONE);
break;
case rmp::app::Stretch::NONE:
rmp::app::set_stretch(rmp::app::Stretch::LETTERBOX);
break;
}
}
// An outline: a rectangle that is not filled.
rmp::Shape outline(Vector2 size) {
rmp::Shape s = rmp::rect(size);
s.color = LINE;
s.filled = false;
s.thickness = 4;
return s;
}
} // namespace
class CourtScene : public rmp::Scene {
public:
void _ready() override {
// The bars' colour, under LETTERBOX. The scene's own, so that the
// bars are not the court and not the stands.
background = Color{ 8, 8, 12, 255 };
rmp::input::action("next_mode", KEY_M, GAMEPAD_BUTTON_RIGHT_FACE_UP);
// The world, in world units, centred on the camera -- which starts
// centred on the design, (400, 225). Higher layers draw on top.
rmp::Shape stands = rmp::rect({ 2400, 1600 });
stands.color = STANDS;
spawn({ .position = { 400, 225 }, .shape = stands, .layer = -2 });
rmp::Shape grass = rmp::rect({ 800, 450 });
grass.color = GRASS;
spawn({ .position = { 400, 225 }, .shape = grass, .layer = -1 });
// The lines on top, ball included, so that nothing ever hides them:
// tools/examples_build.sh finds the court by its white lines.
spawn({ .position = { 400, 225 }, .shape = outline({ 760, 410 }), .layer = 1 });
spawn({ .position = { 400, 225 }, .shape = outline({ 4, 410 }), .layer = 1 });
rmp::Shape circle = rmp::circle(60);
circle.color = LINE;
circle.filled = false;
spawn({ .position = { 400, 225 }, .shape = circle, .layer = 1 });
// A ball that bounces off the lines, which are where they are in
// every mode: `bounds` is in world units, like everything here.
rmp::Shape ball = rmp::circle(10);
ball.color = GOLD;
spawn({ .position = { 300, 160 },
.shape = ball,
.velocity = { 230, 150 },
.edges = rmp::Edge::BOUNCE,
.bounds = { 20, 20, 760, 410 } });
}
void _update(float /*delta*/) override {
if (rmp::input::just_pressed("next_mode")) next_mode();
}
void _draw() override {
// The HUD stays inside the game's area: on the court, scaled with it,
// under LETTERBOX; at the window's corner otherwise.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT });
rmp::ui::panel([] {
rmp::ui::text("Stretch: " + std::string(mode_name()));
rmp::ui::text(std::to_string(GetScreenWidth()) + "x" +
std::to_string(GetScreenHeight()) + ", designed for " +
std::to_string(RMP_WINDOW_WIDTH) + "x" +
std::to_string(RMP_WINDOW_HEIGHT),
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
if (rmp::ui::button("Next mode", { .size = rmp::ui::Size::SMALL }))
next_mode();
});
rmp::ui::end();
}
};
RMP_GAME(CourtScene);https://omardev29.github.io/rmp-docs/examples/ui/index.html
src/scenes/, and change<>() between them.row, column, panel, center, stack/layer, spacer, plus image and progress.rmp::ui, for anything the small API does not expose yet.grid with a column count worked out from the space available, scroll with clipping, tooltip() for what each item is -- under a resting pointer or the keyboard's focus -- and wants_pointer() keeping the game's hands off the UI's clicks.scale() versus current_breakpoint(), and which to reach for.overlay(): a pause menu pushed as a scene of its own, blurred, that freezes the game below; and "Really quit?" drawn by the game scene itself -- an overlay with a panel() in it, which is all a dialog is.rmp::ui: a game's shop screen designed rather than written.DialogueBox (a portrait, a name plate on the frame, a voice per Speaker), a DialogueBubble over whoever speaks with its tail pointing at them, and a DialogueStage whose cast slides in and comes forward, shaken by a <<quake>>.resources/lang.tsv, German in a file of its own (lang/de.tsv), {placeholders}, plurals in each language's forms, a context, and a font per language -- Japanese in Jigmo (CC0), cut down to the letters the table uses -- with each language's name in the menu in a font that has its letters (Style::font).rmp::ui::set_font().https://omardev29.github.io/rmp-docs/examples/ui/01_menu.html
A main menu in three lines, then an options screen, a confirm dialog and a HUD — one scene per screen under src/scenes/, and change<>() between them. Variants, disabled controls, explicit ids, placement, the Theme. Start here.

From a clone of the framework:
rmp example 01_menuRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
ui_cancel | Esc, gamepad right face right |
Every file of examples/ui/01_menu, as it is at the commit this site documents (on GitHub).
src/main.cpp 49 lines// ---------------------------------------------------------------------------
// examples/ui/01_menu/src/main.cpp
//
// rmp::ui, from the three-line version to the parts you reach for later.
//
// The API is deliberately small: begin, end, button, text. Everything that
// would normally make a UI tedious -- coordinates, sizes, fonts, hitboxes,
// hover states, what happens when the window is resized -- is decided for you,
// and each of those decisions can be overridden individually when you need it.
//
// One scene per screen under src/scenes/; this file only says which comes first.
// Run it: `rmp example 01_menu`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "scenes/screens.h"
RMP_GAME(MainMenuScene);
// ---------------------------------------------------------------------------
// Things worth knowing, none of which you need on day one
// ---------------------------------------------------------------------------
//
// THEME. Plain data. Copy, change, set back — usually once, in a _ready():
//
// auto t = rmp::ui::current_theme();
// t.primary = GOLD;
// t.corner_radius = 0; // angular instead of rounded
// rmp::ui::set_theme(t);
//
// SCALE. Every Theme metric is in design units, at the [window] resolution
// from raylib_multiplatform.toml, and multiplied by rmp::ui::scale() before it
// is drawn. That is why this menu looks right on a phone and on a 4K monitor
// without a single conditional. To pin it — an "interface Size" setting, say:
//
// rmp::ui::set_scale(1.5f); // and 0 puts it back to automatic
//
// FONT. [ui] font = "ui.ttf" in the toml and every widget picks it up. Left
// empty you get the font built into raylib: no asset, no licence, works
// everywhere, and its scale is rounded to whole numbers so it stays sharp.
//
// TOUCH. This file already works on Android and iOS. Buttons are never shorter
// than the theme's min_touch_size, and hover is suppressed when nothing is
// touching the screen, so nothing stays lit up after a tap.
//
// ONE FRAME BEHIND. A button cannot be clicked on the very first frame it
// appears — 16 ms at 60 fps. It is inherent to immediate mode and the
// alternative is worse; TECHNICAL.md explains why.src/scenes/confirm.cpp 32 lines// Two buttons with the same label, in different screens.
#include "screens.h"
#include <rmp/app.h>
#include <rmp/ui.h>
void ConfirmScene::_draw() {
rmp::ui::begin();
rmp::ui::text("Really quit?");
rmp::ui::text("Progress since the last save will be lost.",
{ .color = rmp::ui::ColorRole::MUTED });
// rmp::app::quit(), never std::exit(): this lets the frame finish and
// then ends the scenes and closes the window on the way out. On Android it also
// finishes the Activity, so the app does not leave a dead task behind.
//
// On iOS it does nothing at all, on purpose -- Apple rejects apps that
// terminate themselves. Guarding it out is optional; the call is safe
// everywhere. Here it is guarded so the button is not dead on iPhone.
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit", { .style = rmp::ui::Variant::DANGER })) rmp::app::quit();
#endif
// This screen and the main menu both have a "Back"-ish button. Identical
// labels inside ONE frame are told apart automatically; an explicit id is
// for when the UI is conditional -- as it is here -- and you want an
// element's hover state to stay its own across screen changes.
if (rmp::ui::button("Cancel", { .id = "confirm.cancel" })) change<MainMenuScene>();
rmp::ui::end();
}src/scenes/main_menu.cpp 18 lines// The whole point: a main menu.
#include "screens.h"
#include <rmp/ui.h>
void MainMenuScene::_draw() {
// A centred column, sized and spaced by the theme, scaled to the window.
// Three ifs and you have a menu.
rmp::ui::begin();
rmp::ui::text("MY GAME");
if (rmp::ui::button("Play")) change<PlayingScene>();
if (rmp::ui::button("Options")) change<OptionsScene>();
if (rmp::ui::button("Quit")) change<ConfirmScene>();
rmp::ui::end();
}src/scenes/options.cpp 29 lines// One step up: options on the widgets.
#include "screens.h"
#include <rmp/ui.h>
#include <string>
void OptionsScene::_draw() {
rmp::ui::begin();
rmp::ui::text("Options");
// A button whose label is built this frame. std::string_view takes it, and
// the text is copied immediately -- temporaries are safe here.
if (rmp::ui::button(std::string("Music: ") + (game.music ? "on" : "off"))) {
game.music = !game.music;
}
// Semantic variants: you say what the button MEANS, the theme decides what
// that looks like. Restyling the game never means revisiting this line.
rmp::ui::button("Reset progress", { .style = rmp::ui::Variant::DANGER });
// Disabled controls still lay out, and still look deliberate.
rmp::ui::button("Cloud saves", { .enabled = false });
if (rmp::ui::button("Back")) change<MainMenuScene>();
rmp::ui::end();
}src/scenes/playing.cpp 29 lines// A HUD: not everything is a centred menu.
#include "screens.h"
#include <rmp/input.h>
#include <rmp/ui.h>
#include <string>
void PlayingScene::_update(float) {
game.score += 1;
// "ui_cancel" is one of the actions that come defined: Escape, or the
// gamepad's right face button. Through rmp::input rather than
// IsKeyPressed(KEY_ESCAPE), so a controller can go back too.
if (rmp::input::just_pressed("ui_cancel")) change<MainMenuScene>();
}
void PlayingScene::_draw() {
// placement moves the whole thing. The nine Align values are the ones you
// would guess: TOP_LEFT, TOP_CENTER, ..., BOTTOM_RIGHT.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .gap = 4 });
// Built fresh every frame, which is exactly how immediate mode is meant to
// be used: no label object to update, no "setText" to remember.
rmp::ui::text("Score: " + std::to_string(game.score));
rmp::ui::text("Press ESC for the menu",
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
rmp::ui::end();
}src/scenes/screens.h 36 lines#pragma once
// One scene per screen, one file per scene under src/scenes/. Going from one
// to the next is rmp::Scene::change<T>(): the scene on screen ends, the next
// one starts, at the end of the frame the button was pressed in.
#include <rmp/scene.h>
// What outlives a screen: the score of the run, and the music switch the
// options change. Plain data of YOURS -- the UI is immediate mode, so it holds
// no state, and there is nothing to keep in sync.
struct Progress {
int score = 0;
bool music = true;
};
inline Progress game;
class MainMenuScene : public rmp::Scene {
public:
void _draw() override;
};
class OptionsScene : public rmp::Scene {
public:
void _draw() override;
};
class ConfirmScene : public rmp::Scene {
public:
void _draw() override;
};
// Not everything is a centred menu: the game being played, with its HUD.
class PlayingScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};https://omardev29.github.io/rmp-docs/examples/ui/02_layout.html
row, column, panel, center, stack/layer, spacer, plus image and progress. The Sizing model — fit, grow, fixed — and why design units are not pixels.

From a clone of the framework:
rmp example 02_layoutEvery file of examples/ui/02_layout, as it is at the commit this site documents (on GitHub).
src/main.cpp 168 lines// ---------------------------------------------------------------------------
// examples/ui/02_layout/src/main.cpp
//
// Containers: row, column, panel, center, stack, spacer — plus image and
// progress, the two widgets that only make sense once you have somewhere to
// put them.
//
// The rule that shapes all of it: a container takes its contents as a lambda.
// There is no closing call to forget, because the compiler closes it for you.
// Capture with [&] when the body needs your variables, which is most of the
// time.
//
// Every measurement below is in DESIGN UNITS, at the [window] resolution from
// raylib_multiplatform.toml. rmp::ui multiplies them by the current scale, so
// `width = 200` is 200 at your design Size, 400 at twice it, and never a
// hard-coded pixel count that looks right on exactly one monitor.
//
// Run it: `rmp example 02_layout`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <string>
class LayoutScene : public rmp::Scene {
public:
void _ready() override {
// Resize the window and watch everything follow.
_portrait = rmp::assets::load_texture("rabbit.png");
}
void _update(float delta) override {
// Bars that move, so the layout is doing something rather than sitting
// still -- and so it is obvious the numbers are read fresh every frame.
_health -= delta * 0.05f;
if (_health < 0) _health = 1.0f;
_mana += delta * 0.08f;
if (_mana > 1) _mana = 0.0f;
}
void _draw() override {
// begin() is a centred column. placement moves the whole thing: this one
// hugs the top-left corner, like a HUD would.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .gap = 14 });
toolbar();
character_card();
banner();
empty_slot();
if (rmp::ui::button("Done")) rmp::app::quit();
rmp::ui::end();
}
private:
// An rmp::Texture, not a Texture2D. The handle OWNS the texture; a raw
// Texture2D copied out of the temporary would have been unloaded on the
// same line, before the next statement ran.
rmp::Texture _portrait;
float _health = 0.72f;
float _mana = 0.35f;
// -------------------------------------------------------------------
// row and column: the two directions
// -------------------------------------------------------------------
void character_card() {
// panel = a column with a background and padding. It is what you put
// a dialog, a card or a tooltip inside.
rmp::ui::panel([&] {
// row lays out left to right.
rmp::ui::row({ .gap = 16 }, [&] {
rmp::ui::image(_portrait, { .width = 72, .height = 72 });
// column lays out top to bottom. items decides where children
// sit across the other axis -- here, hard against the left
// instead of centred, which is what makes a card look like a
// card.
rmp::ui::column({ .gap = 6, .items = rmp::ui::Align::CENTER_LEFT }, [&] {
rmp::ui::text("Rabbit", { .color = rmp::ui::ColorRole::PRIMARY });
rmp::ui::progress(_health, { .width = 180 });
rmp::ui::progress(_mana,
{ .width = 180, .height = 8, .fill = SKYBLUE });
rmp::ui::text("Level 7",
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
});
});
});
}
// -------------------------------------------------------------------
// spacer: how you push things apart
// -------------------------------------------------------------------
static void toolbar() {
// grow_x makes the row take the full width it is offered; without it
// the row would shrink to fit its contents and the spacer would have
// nothing to eat.
rmp::ui::row({ .grow_x = true }, [&] {
rmp::ui::text("Inventory");
rmp::ui::spacer(); // <- takes everything left over
rmp::ui::text("24 / 40", { .color = rmp::ui::ColorRole::MUTED });
});
// spacer(n) is the other one: a fixed gap, when you want breathing
// room in one specific place rather than changing the container's gap.
rmp::ui::spacer(8);
}
// -------------------------------------------------------------------
// stack and layer: things on top of each other
// -------------------------------------------------------------------
void banner() {
rmp::ui::panel({ .box = { .width = 260, .height = 90 } }, [&] {
// Every child of a stack has to be a layer(). That is not
// ceremony: it is what says "these are meant to overlap" instead
// of "these are ordinary children in a column". Later layers draw
// on top.
rmp::ui::stack([&] {
rmp::ui::layer([&] {
rmp::ui::image(
_portrait,
{ .grow = true, .tint = CLITERAL(Color){ 255, 255, 255, 60 } });
});
rmp::ui::layer([&] {
rmp::ui::text("PAUSED", { .color = rmp::ui::ColorRole::DANGER });
});
});
});
}
// -------------------------------------------------------------------
// center: fill what you were given, put the contents in the middle
// -------------------------------------------------------------------
static void empty_slot() {
rmp::ui::panel({ .box = { .width = 260, .height = 70 },
.border = rmp::ui::current_theme().border },
[&] {
rmp::ui::center([&] {
rmp::ui::text("nothing here",
{ .color = rmp::ui::ColorRole::MUTED });
});
});
}
};
RMP_GAME(LayoutScene);
// ---------------------------------------------------------------------------
// The Sizing model, in three lines
// ---------------------------------------------------------------------------
//
// default fit — as big as the contents need
// grow_x/grow_y fill the space the parent is offering
// width/height a fixed number of design units, overriding both
//
// A container fits its contents; a child with grow expands to fill whatever
// the container ended up being. That pairing is what makes the buttons in a
// menu come out the same width without anyone measuring anything.
//
// NAMING A CONTAINER. Every container takes an optional `.id`: a stable name,
// the same element from frame to frame whatever else is on screen.
//
// rmp::ui::panel({ .box = { .id = "inventory" } }, [&]{ ... });
//
// Unnamed containers are anonymous, which is right for almost all of them.https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html
The escape hatch. Clay's own macros in the same frame as rmp::ui, for anything the small API does not expose yet.

From a clone of the framework:
rmp example 03_clay_directEvery file of examples/ui/03_clay_direct, as it is at the commit this site documents (on GitHub).
src/main.cpp 140 lines// ---------------------------------------------------------------------------
// examples/ui/03_clay_direct/src/main.cpp
//
// THE ESCAPE HATCH: using Clay's own API directly, alongside rmp::ui.
//
// rmp::ui is a small, opinionated surface over Clay — enough for menus, HUDs
// and dialogs without ever mentioning a coordinate. When you want something it
// does not expose yet (floating elements placed where you choose, aspect
// ratios, per-corner radii, a border on one side, an explicit z-index), you do
// not have to wait for us and you do not have to give up rmp::ui to get it.
// (Clipping and scrolling it does expose: rmp::ui::scroll().)
//
// It is the same bargain as the rest of the framework: rmp::assets does not stop
// you calling LoadTexture, and rmp::ui does not stop you calling Clay. Or
// rlgl. Or raw OpenGL, for that matter.
//
// #include <clay.h>
//
// and write Clay between rmp::ui::begin() and rmp::ui::end(). Your elements go
// into the same tree, get laid out in the same pass and drawn by the same
// renderer.
//
// Two things to know and then you are on your own:
//
// * begin() has already opened two elements — a root that fills the screen
// and a column that centres its contents. Yours become children of that
// column. If you want to escape it, use Clay's floating elements.
// * Clay does NOT copy strings. CLAY_STRING() on a literal is fine forever;
// anything built at runtime must stay alive until end() has returned. This
// is the one footgun rmp::ui::text() removes for you by copying.
//
// Run it: `rmp example 03_clay_direct`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <clay.h> // the escape hatch: not included for you on purpose
class ClayScene : public rmp::Scene {
public:
void _ready() override { _logo = rmp::assets::load_texture("rabbit.png"); }
void _draw() override {
// A copy of the raylib struct, alive for this frame. The handle below
// is the owner; this is what Clay is allowed to point at.
Texture2D logo_tex = _logo;
rmp::ui::begin();
// --- the normal API ---------------------------------------------------
rmp::ui::text("Inventory");
// --- and Clay, in the same frame --------------------------------------
//
// A horizontal strip of slots, which rmp::ui has no primitive for yet.
// CLAY_AUTO_ID is the version without an explicit id; CLAY(CLAY_ID("x"),
// ...) is the one to use when you want to ask Clay about the element later
// with Clay_PointerOver or Clay_GetElementData.
//
// It is shaped like a tab, which rmp::ui cannot do either: each corner has
// its own radius, and the border is on one side only.
CLAY_AUTO_ID(
{ .layout = { .sizing = { .width = CLAY_SIZING_FIT(0),
.height = CLAY_SIZING_FIT(0) },
.padding = CLAY_PADDING_ALL(10),
.childGap = 10,
.layoutDirection = CLAY_LEFT_TO_RIGHT },
.backgroundColor = { 30, 30, 38, 255 },
.cornerRadius = { .topLeft = 18,
.topRight = 18,
.bottomLeft = 0,
.bottomRight = 0 },
.border = { .color = { 88, 120, 245, 255 }, .width = { .bottom = 3 } } }) {
for (int i = 0; i < 4; ++i) {
// CLAY_IDI gives each slot in a loop its own identity without
// building a string per element.
CLAY(CLAY_IDI("slot", i),
{ .layout = { .sizing = { .width = CLAY_SIZING_FIXED(64),
.height = CLAY_SIZING_FIXED(64) } },
.backgroundColor = { 44, 44, 56, 255 },
.cornerRadius = CLAY_CORNER_RADIUS(6) }) {
// Images: point imageData at a Texture2D you own and keep
// alive for the frame. Our renderer draws it stretched to the
// element's box, untinted. A tint is a Color* in userData; a
// backgroundColor is NOT a tint -- Clay draws it as a rectangle
// after the image, which paints a flat square over it.
if (i == 0) {
CLAY_AUTO_ID(
{ .layout = { .sizing = { .width = CLAY_SIZING_GROW(0),
.height = CLAY_SIZING_GROW(0) } },
.image = { .imageData = &logo_tex } }) {}
}
}
}
}
// Hover, straight from Clay. Note it reads the PREVIOUS frame's geometry,
// exactly like rmp::ui::button() does — the layout for this frame does not
// exist until end().
if (Clay_PointerOver(CLAY_IDI("slot", 0))) {
rmp::ui::text("slot 1", { .color = rmp::ui::ColorRole::PRIMARY });
}
// Back to the normal API, still the same frame.
if (rmp::ui::button("Close")) rmp::app::quit();
rmp::ui::end();
}
private:
// The owning handle. Clay wants a Texture2D* that stays valid for the
// frame, so _draw() copies the raylib struct out for exactly that long.
rmp::Texture _logo;
};
RMP_GAME(ClayScene);
// ---------------------------------------------------------------------------
// What our renderer understands
// ---------------------------------------------------------------------------
//
// RECTANGLE background colour + each corner's own radius
// BORDER colour + each side's own width + each corner's own radius
// TEXT drawn with the UI font; fontId is ignored, there is one font
// IMAGE imageData as a Texture2D*; userData as a Color* tint, or
// null for none (a backgroundColor covers the image: see above)
// SCISSOR_START clipping, so Clay's clip/scroll containers work
// SCISSOR_END
//
// CUSTOM commands are not handled. If you need them, src/rmp/ui/render.cpp is
// one short file, and adding a case is the intended way to extend it.
//
// AND THE LIMITS. Doing this ties your code to a specific version of Clay
// (0.14, pinned in thirdparty/FROZEN_VERSIONS.md). rmp::ui exists partly so
// that most code does not carry that dependency — Clay is pre-1.0 and its API
// has moved between minor versions. That is a fair trade for a feature you need
// today; it is a bad trade for a button.https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html
Checkbox, slider, dropdown, text input — and the focus/keyboard/gamepad navigation you get without writing any. The state model, which is "your variable, by reference" and nothing else; the variable lives in include/settings.h. The two volume sliders are the rmp::audio buses, and the settings are kept with rmp::save -- read with every field defaulting to the struct, written on Apply with a "Saved" from notify(), and a damaged file said as such.

From a clone of the framework:
rmp example 04_settingsEvery file of examples/ui/04_settings, as it is at the commit this site documents (on GitHub).
src/main.cpp 274 lines// ---------------------------------------------------------------------------
// examples/ui/04_settings/src/main.cpp
//
// A settings screen: checkbox, slider, dropdown, text input — and the thing
// that makes all four playable on a TV with a controller, which is focus.
//
// THE STATE MODEL, because it is the part that surprises people coming from a
// retained-mode toolkit: every control takes YOUR variable, by reference, and
// writes to it. There is no widget object holding a copy, nothing to
// synchronise, no setter to remember. What is on screen is what is in your
// struct, because it was read this frame. Delete this file and your settings
// still exist; they were never ours.
//
// Each one returns true on the frame it changed, so "apply when something
// changes" reads exactly like that:
//
// if (rmp::ui::checkbox("Fullscreen", cfg.fullscreen)) apply(cfg);
//
// And they are kept: load() reads them through rmp::save when the screen
// opens, store() writes them on Apply, and rmp::ui::notify() says so. The
// Settings struct stays plain data; the Value is only the shape it has on
// disk.
//
// Run it: `rmp example 04_settings`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/audio.h>
#include <rmp/save.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include "settings.h"
#include <algorithm>
#include <string>
namespace {
void apply(const Settings &s) {
// Where you would actually act on it. Called only when something changed,
// which is why the controls return a bool at all.
#if !defined(PLATFORM_WEB) && !defined(__EMSCRIPTEN__)
// VSync is a window state, on and off at any time. Not on the web: the
// browser paces the frame there and there is nothing to switch.
if (s.vsync)
SetWindowState(FLAG_VSYNC_HINT);
else
ClearWindowState(FLAG_VSYNC_HINT);
#endif
// The two volume sliders are the audio buses. Neither call opens the
// sound device: a game can show and apply this screen before it has made
// a sound, and what is already playing changes at once.
rmp::audio::set_volume(rmp::audio::Bus::MASTER, s.master);
rmp::audio::set_volume(rmp::audio::Bus::MUSIC, s.music);
const std::string quality(QUALITY[static_cast<std::size_t>(s.quality)]);
TraceLog(LOG_INFO, "SETTINGS: applied (master %.2f, quality %s)",
static_cast<double>(s.master), quality.c_str());
}
// What is on disk, over what the struct says. Every field reads with its
// current value as the default, so the first run -- no save yet -- and a save
// from an older version missing a field both simply keep the defaults. There
// is no `if` around the read for the same reason. True when the file was
// there but edited or cut short.
bool load(Settings &s) {
rmp::Value v;
// When the read fails, `v` stays empty and every field keeps its default
// -- that is the whole of "the first run". Only a damaged file is worth
// telling the player about; a missing one is simply the first time.
const rmp::save::Result read = rmp::save::read("settings", v);
const bool damaged = read.status == rmp::save::Status::MODIFIED ||
read.status == rmp::save::Status::TRUNCATED;
s.fullscreen = v["fullscreen"].as_bool(s.fullscreen);
s.vsync = v["vsync"].as_bool(s.vsync);
s.master = v["master"].as_float(s.master);
s.music = v["music"].as_float(s.music);
s.sensitivity = v["sensitivity"].as_float(s.sensitivity);
// An index from a file is clamped before it indexes anything: a save can
// be edited, or come from a version with a longer list.
s.quality = std::clamp(v["quality"].as_int(s.quality), 0,
static_cast<int>(QUALITY.size()) - 1);
s.language = std::clamp(v["language"].as_int(s.language), 0,
static_cast<int>(LANGUAGE.size()) - 1);
s.player = std::string(v["player"].as_string(s.player));
return damaged;
}
// True when it reached the disk.
bool store(const Settings &s) {
rmp::Value v;
v["fullscreen"] = s.fullscreen;
v["vsync"] = s.vsync;
v["master"] = s.master;
v["music"] = s.music;
v["sensitivity"] = s.sensitivity;
v["quality"] = s.quality;
v["language"] = s.language;
v["player"] = s.player;
return rmp::save::write("settings", v);
}
} // namespace
class SettingsScene : public rmp::Scene {
public:
void _ready() override {
// The controls start where the game does -- [window] vsync and [audio] in
// the .toml -- and then whatever the player saved last time wins.
_cfg.vsync = RMP_WINDOW_VSYNC != 0;
_cfg.player = "Player";
_cfg.master = rmp::audio::volume(rmp::audio::Bus::MASTER);
_cfg.music = rmp::audio::volume(rmp::audio::Bus::MUSIC);
_damaged = load(_cfg);
apply(_cfg);
_saved = _cfg;
// The first control of a screen has the focus without asking, so Enter and
// the A button work the moment it appears. Asking for it by name does one
// thing more: the ring shows from the start, before the player has touched
// a key. Name another control to start somewhere else.
rmp::ui::focus("Fullscreen");
}
void _draw() override {
rmp::ui::begin();
rmp::ui::panel({ .box = { .width = 760 } }, [&] {
rmp::ui::text("Settings");
// Two columns, so that the whole screen fits the window it opens in --
// [window] in the .toml, 800x450. In one column Apply was below the
// bottom edge, where a mouse could not reach it. Focus still goes
// down the first column and then the second: it follows the order the
// controls are written in, not where they land.
rmp::ui::row(
{ .gap = 24, .items = rmp::ui::Align::TOP_CENTER, .grow_x = true }, [&] {
rmp::ui::column({ .grow_x = true }, [&] {
// --- toggles ----------------------------------------------
if (rmp::ui::checkbox("Fullscreen", _cfg.fullscreen))
_dirty = true;
#if !defined(PLATFORM_WEB) && !defined(__EMSCRIPTEN__)
// Not on the web, where there is no such switch at all. That
// is not the same as the Subtitles box below: a control that
// is unavailable RIGHT NOW is disabled, one that cannot exist
// here is not shown.
if (rmp::ui::checkbox("VSync", _cfg.vsync)) _dirty = true;
#endif
// A control that is not available right now is disabled, not
// missing. A menu whose items appear and disappear is a menu
// nobody can learn.
rmp::ui::checkbox("Subtitles", _cfg.subtitles,
{ .enabled = false });
// --- sliders ----------------------------------------------
// Continuous: drag it anywhere, or hold left/right on a
// controller.
if (rmp::ui::slider("Master volume", _cfg.master, 0.0f, 1.0f))
_dirty = true;
if (rmp::ui::slider("Music", _cfg.music, 0.0f, 1.0f))
_dirty = true;
// step snaps to multiples, which is what you want for a value
// the player will want to describe to someone else ("I play on
// 40").
if (rmp::ui::slider("Sensitivity", _cfg.sensitivity, 0.0f, 1.0f,
{ .step = 0.05f }))
_dirty = true;
});
rmp::ui::column({ .grow_x = true }, [&] {
// --- pick one of a list -----------------------------------
// The dropdown owns nothing but the open/closed flag, and that
// is ours, not yours: the int is an index into the list you
// passed.
if (rmp::ui::dropdown("Quality", _cfg.quality, QUALITY))
_dirty = true;
if (rmp::ui::dropdown("Language", _cfg.language, LANGUAGE))
_dirty = true;
// --- typing -----------------------------------------------
// Edits your std::string, up to 20 characters as the player
// counts them.
if (rmp::ui::text_input(
"Name", _cfg.player,
{ .placeholder = "your name", .max_length = 20 })) {
_dirty = true;
}
// --- actions ----------------------------------------------
rmp::ui::row({ .grow_x = true }, [&] {
if (rmp::ui::button("Revert", { .enabled = _dirty })) {
_cfg = _saved;
_dirty = false;
}
rmp::ui::spacer();
if (rmp::ui::button("Apply",
{ .style = rmp::ui::Variant::PRIMARY,
.enabled = _dirty })) {
apply(_cfg);
// A word at the bottom of the screen, gone by
// itself in three seconds: nothing to close, and
// nothing in this layout moves to make room.
if (store(_cfg)) {
_saved = _cfg;
_dirty = false;
rmp::ui::notify("Saved");
} else {
// Still unsaved, so Apply stays lit: try again.
rmp::ui::notify(
"Not _saved: the disk refused it",
{ .color = rmp::ui::ColorRole::DANGER });
}
}
});
if (_dirty) {
rmp::ui::text(
"unsaved changes",
{ .color = rmp::ui::ColorRole::DANGER, .size = 14 });
}
if (_damaged) {
rmp::ui::text(
"the _saved settings were _damaged; these are the "
"defaults",
{ .color = rmp::ui::ColorRole::MUTED, .size = 14 });
}
});
});
});
rmp::ui::end();
}
private:
Settings _cfg;
Settings _saved; // what was on disk, to know if anything changed
bool _dirty = false;
bool _damaged = false; // the saved settings were edited or cut short
};
RMP_GAME(SettingsScene);
// ---------------------------------------------------------------------------
// Focus, keyboard and gamepad — which you did not have to write
// ---------------------------------------------------------------------------
//
// Everything above is already navigable. Nothing in this file asked for it:
//
// Tab / Down / d-pad down / left stick next control
// Shift+Tab / Up / d-pad up previous
// Enter / Space / gamepad bottom button activate; start typing in a field
// Enter / Escape / gamepad B stop typing (the focus stays)
// Left / Right / d-pad / stick move a slider
// Up / Down in an open dropdown walk its items; Enter picks one,
// Escape closes it unchanged
//
// The focused control draws the theme's focus ring. That colour is in the
// Theme rather than in each widget for a reason: a controller build where one
// widget forgot to draw it is a controller build that gets stuck.
//
// rmp::ui::focus("Fullscreen") start somewhere else than the first control
// rmp::ui::focused() what has it
// rmp::ui::set_navigation_enabled(false) if your game drives focus itself
//
// WHO GETS THE INPUT. The UI reads the pointer and the keyboard itself, so the
// game has to be told to keep its hands off:
//
// if (!rmp::ui::wants_pointer() && IsMouseButtonPressed(0)) shoot();
// if (!rmp::ui::wants_keyboard() && IsKeyDown(KEY_W)) walk();
//
// Without the second one, typing "Wolf" into the name field above walks the
// player across the level. wants_keyboard() is true only while a text field
// has the keyboard: from a click on it or the focus arriving on it, until
// Enter, Escape, a click elsewhere or the focus moving on.include/settings.h 27 lines#pragma once
// Plain data. This is the whole model, and it is the point of the example: the
// controls take a field of this, by reference, and write to it. Delete the UI
// and your settings still exist; they were never ours.
#include <array>
#include <string>
#include <string_view>
struct Settings {
bool fullscreen = false;
bool vsync = true;
bool subtitles = false;
float master = 0.8f;
float music = 0.5f;
float sensitivity = 0.35f;
int quality = 1;
int language = 0;
std::string player; // "Player" until the player says otherwise: see _ready()
};
// What the two dropdowns offer: a std::array the dropdown takes as a span, so
// nobody has to tell it how long the list is.
inline constexpr std::array<std::string_view, 4> QUALITY{ "Low", "Medium", "High",
"Ultra" };
inline constexpr std::array<std::string_view, 3> LANGUAGE{ "English", "Espanol",
"Francais" };https://omardev29.github.io/rmp-docs/examples/ui/05_inventory.html
grid with a column count worked out from the space available, scroll with clipping, tooltip() for what each item is -- under a resting pointer or the keyboard's focus -- and wants_pointer() keeping the game's hands off the UI's clicks. One panel per file under src/panels/.

From a clone of the framework:
rmp example 05_inventoryRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
use | left mouse button |
Every file of examples/ui/05_inventory, as it is at the commit this site documents (on GitHub).
src/main.cpp 89 lines// ---------------------------------------------------------------------------
// examples/ui/05_inventory/src/main.cpp
//
// grid and scroll: an inventory beside a scrolling list, both of them behaving
// when the window changes size -- which is the only reason either exists.
//
// The two ideas worth taking away:
//
// * grid(0, ...) works out its own column count from the space it has, and
// works it out again when that changes. A grid with a hard-coded 6 columns
// is a grid that is wrong on a phone in portrait.
// * scroll() clips and scrolls with the wheel or with a finger. Same gesture,
// same code, no branch on platform.
//
// One panel per file under src/panels/; the item table is in include/.
// Run it: `rmp example 05_inventory`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/input.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include "inventory.h"
class InventoryScene : public rmp::Scene {
public:
void _ready() override {
// The whole point: resize the window.
_icon = rmp::assets::load_texture("rabbit.png");
// What a click means to the game, by name.
rmp::input::action("use", MOUSE_BUTTON_LEFT);
}
void _update(float) override {
// The UI is reading the pointer, so the game must not act on the same
// click: picking an item must not also swing the sword. An action asked
// for by name already knows -- it is quiet while the UI wants the
// pointer -- so there is no `if (!rmp::ui::wants_pointer())` to
// remember here.
if (rmp::input::just_pressed("use")) {
TraceLog(LOG_INFO, "GAME: click in the world");
}
}
void _draw() override {
// grow: the frame is the whole window, so the row below can fill it.
// Without it begin() is a column that fits its content -- the right
// thing for a menu -- and a growing row would fill that column and no
// more.
rmp::ui::begin({ .grow = true });
rmp::ui::row({ .gap = 12, .grow_x = true, .grow_y = true }, [&] {
inventory_grid(_icon);
item_list();
});
rmp::ui::end();
}
private:
// An rmp::Texture and not a Texture2D: the handle owns the texture, and the
// scene owns the handle, so it goes when the scene does -- before the
// window closes. Copying it into a raw Texture2D would have destroyed the
// only owner on the same line.
rmp::Texture _icon;
};
RMP_GAME(InventoryScene);
// ---------------------------------------------------------------------------
// Notes
// ---------------------------------------------------------------------------
//
// WHY cell() EXISTS. The layout engine underneath wraps text, not elements, so
// a grid has to be built as real rows. cell() is what lets the grid count its
// items and start a row at the right moment. It is the same bargain as
// stack()/layer(): one extra call, in exchange for the layout knowing what you
// meant instead of guessing.
//
// SCROLL AND SIZE. A scroll area grows by default, so it takes the height its
// parent gives it and clips there: here, what the panel has left once its two
// lines of text are in. Its rows never push a parent past the window -- inside
// one that fits its contents, it is squeezed to the room that is left and
// clips there. Give it a height when you want a particular one.
//
// PERFORMANCE. Every item is rebuilt every frame, and that is fine: this is
// twelve, and the layout engine is measured in microseconds. A list long
// enough to matter would want to draw only the rows in view, and rmp::ui has
// no call yet that tells you where the area is or how far it has scrolled.include/inventory.h 34 lines#pragma once
#include <rmp/assets.h>
#include <array>
#include <string_view>
struct Item {
std::string_view name;
int count;
bool equipped;
std::string_view description; // the list's tooltip
};
inline constexpr int ITEM_COUNT = 12;
inline std::array<Item, ITEM_COUNT> items{ {
{ "Sword", 1, true, "Sharp at one end. Equipped." },
{ "Shield", 1, false, "Stops what the sword does not." },
{ "Potion", 12, false, "Twelve second chances." },
{ "Rope", 3, false, "Thirty feet, more or less." },
{ "Torch", 8, false, "Light for a cave, or for a fuse." },
{ "Map", 1, false, "Of somewhere else, unfortunately." },
{ "Key", 2, false, "Two keys, no doors yet." },
{ "Bread", 5, false, "Restores a little, tastes of a lot." },
{ "Coin", 240, false, "Spend it, or count it." },
{ "Gem", 4, false, "Worth a shop each." },
{ "Bow", 1, false, "Useless without the arrows." },
{ "Arrow", 60, false, "Useless without the bow." },
} };
inline int selected = 0;
// One panel per file under src/panels/. The grid draws each item with `icon`,
// which the scene owns.
void inventory_grid(const rmp::Texture &icon);
void item_list();src/panels/grid.cpp 38 lines// The grid. Every item goes in a cell(), which is what lets the grid count
// them and start a new row at the right moment.
#include "inventory.h"
#include <rmp/ui.h>
#include <string>
void inventory_grid(const rmp::Texture &icon) {
rmp::ui::panel({ .box = { .grow_x = true, .grow_y = true } }, [&] {
rmp::ui::text("Inventory");
// columns = 0: fit as many 88-unit cells as the width allows, and at
// least one. The grid measures the width it had last frame; the id
// keeps it the same grid whatever else comes and goes on screen, where
// an unnamed one is told apart by its order among the unnamed grids.
rmp::ui::grid({ .columns = 0, .min_cell = 88, .id = "inv" }, [&] {
for (int i = 0; i < ITEM_COUNT; ++i) {
rmp::ui::cell([&] {
rmp::ui::panel(
{ .box = { .padding = 6 },
.background = (i == selected)
? rmp::ui::current_theme().surface_hover
: rmp::ui::current_theme().surface },
[&] {
rmp::ui::image(icon, { .width = 40, .height = 40 });
rmp::ui::text(items[i].name, { .size = 13 });
if (items[i].count > 1) {
rmp::ui::text(
"x" + std::to_string(items[i].count),
{ .color = rmp::ui::ColorRole::MUTED, .size = 12 });
}
});
});
}
});
});
}src/panels/list.cpp 35 lines// The list. scroll() clips its contents; the wheel and a dragging finger both
// move it, and neither needs a line of code here. Each item says what it is
// with tooltip().
#include "inventory.h"
#include <rmp/ui.h>
#include <string>
void item_list() {
rmp::ui::panel({ .box = { .width = 240, .grow_y = true } }, [&] {
rmp::ui::text("All items");
rmp::ui::scroll({ .gap = 4, .id = "list" }, [&] {
for (int i = 0; i < ITEM_COUNT; ++i) {
// Two buttons could share a label across a long list, so the
// ids are made explicit. Identical labels in one frame are told
// apart automatically; this is for when you want the identity
// to survive the list being reordered.
const std::string id = "item" + std::to_string(i);
if (rmp::ui::button(items[i].name, { .id = id })) {
selected = i;
}
// About the button just above, and only that: shown when the
// pointer rests on it for half a second, or at once when the
// keyboard or a gamepad walks onto it. To the left, over the
// grid, where it hides no other item of the list.
rmp::ui::tooltip(items[i].description,
{ .side = rmp::ui::Align::CENTER_LEFT });
}
});
rmp::ui::text("scroll me", { .color = rmp::ui::ColorRole::MUTED, .size = 12 });
});
}https://omardev29.github.io/rmp-docs/examples/ui/06_style.html
The two themes, the five variants, the three sizes and the transition. Nothing in it names a colour — that is the point. Plus copy-modify-set for a Theme of your own.

From a clone of the framework:
rmp example 06_styleEvery file of examples/ui/06_style, as it is at the commit this site documents (on GitHub).
src/main.cpp 190 lines// ---------------------------------------------------------------------------
// examples/ui/06_style/src/main.cpp
//
// The two themes, the five variants, the three sizes, and the transition that
// ties them together.
//
// The idea worth taking away is that none of this is a colour parameter. You
// say what a button MEANS — primary, danger, ghost — and how important it is —
// small, medium, large — and the theme decides what that looks like. Which is
// why the light/dark switch at the top of this file is one line and does not
// need a single call site revisited:
//
// rmp::ui::set_theme(light ? rmp::ui::theme_light() : rmp::ui::theme_dark());
//
// If you had passed colours to widgets instead, that line would be a rewrite.
//
// Run it: `rmp example 06_style`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <string>
class StyleScene : public rmp::Scene {
public:
void _ready() override { apply_style(); }
void _draw() override {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::panel({ .box = { .grow_x = true } }, [this] {
rmp::ui::row({ .grow_x = true }, [this] {
rmp::ui::text("Style", { .size = rmp::ui::Size::LARGE });
rmp::ui::spacer();
// Both of these rebuild the theme and hand it back. Nothing else in
// the file knows or cares which one is active.
if (rmp::ui::checkbox("Light Theme", _light)) apply_style();
if (rmp::ui::checkbox("Reduce motion", _reduce)) apply_style();
});
});
// The rest is taller than the window, so it scrolls: the wheel, a finger,
// or the keyboard and the gamepad -- moving the focus to a control the
// area has clipped away brings it into view.
rmp::ui::scroll({ .id = "page" }, [this] {
variants();
sizes();
custom_theme_demo();
// The transition is on colour only — never on position or size. A
// control is always exactly where it was drawn, so an animation can
// never make you miss what you were aiming at. Drag the slider and
// watch the fill above it keep up.
rmp::ui::panel({ .box = { .grow_x = true } }, [this] {
rmp::ui::progress(_excitement);
rmp::ui::slider("Excitement", _excitement, 0.0f, 1.0f);
});
});
rmp::ui::end();
}
private:
bool _light = false;
bool _reduce = false; // the accessibility switch, see apply_style()
float _excitement = 0.35f;
int _pressed_count = 0;
// One place decides what the interface looks like, and it is not spread across
// the widgets. Everything else in this file just says what things mean.
void apply_style() {
rmp::ui::Theme t = _light ? rmp::ui::theme_light() : rmp::ui::theme_dark();
// "Reduce motion" is a theme field, not a global switch, because the
// transition is a property of the look and not of the machinery. 0 means
// every control snaps to its new colour on the frame it changes.
if (_reduce) t.transition = 0.0f;
rmp::ui::set_theme(t);
}
// -------------------------------------------------------------------
// The five variants. Read the call sites, not the colours: nothing here names
// a colour, and that is the point of the whole enum.
// -------------------------------------------------------------------
void variants() {
rmp::ui::panel({ .box = { .grow_x = true } }, [this] {
rmp::ui::text("Variants", { .size = rmp::ui::Size::LARGE });
rmp::ui::text(
"What the button means, not what colour it is.",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
rmp::ui::row({ .grow_x = true }, [this] {
if (rmp::ui::button("Start game", { .style = rmp::ui::Variant::PRIMARY }))
++_pressed_count;
if (rmp::ui::button("Load")) ++_pressed_count;
if (rmp::ui::button("Settings", { .style = rmp::ui::Variant::OUTLINE }))
++_pressed_count;
if (rmp::ui::button("Back", { .style = rmp::ui::Variant::GHOST }))
++_pressed_count;
if (rmp::ui::button("Delete", { .style = rmp::ui::Variant::DANGER }))
++_pressed_count;
});
// Disabled is a state, not a variant: it can happen to any of them, so
// it is a flag rather than a sixth entry in the enum.
rmp::ui::row({ .grow_x = true }, [] {
rmp::ui::button("Continue",
{ .style = rmp::ui::Variant::PRIMARY, .enabled = false });
rmp::ui::button("No save file yet", { .enabled = false });
});
rmp::ui::text(
"Buttons pressed: " + std::to_string(_pressed_count),
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
});
}
// -------------------------------------------------------------------
// The three sizes. They are steps in the theme's type scale, so they move
// together when someone changes the scale and stay in proportion at every
// window Size — which a hand-picked number would not.
// -------------------------------------------------------------------
static void sizes() {
rmp::ui::panel({ .box = { .grow_x = true } }, [] {
rmp::ui::text("Sizes", { .size = rmp::ui::Size::LARGE });
rmp::ui::row({ .grow_x = true }, [] {
rmp::ui::button("Small", { .size = rmp::ui::Size::SMALL });
rmp::ui::button("Medium", { .size = rmp::ui::Size::MEDIUM });
rmp::ui::button("Large", { .size = rmp::ui::Size::LARGE });
});
// The padding and the minimum touch height follow the type Size, so a
// large button is large all over rather than a normal one with bigger
// letters in it. On a touch screen the small one still never drops
// below the 44-unit touch target: there, a small button is still a
// button you hit with a thumb.
rmp::ui::text(
"A Size step moves the type, the padding and the minimum height "
"together.",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
// The same field takes an exact number when you genuinely need one.
// Reach for it for a title, not for a button.
rmp::ui::text("CHAPTER ONE", { .size = 44 });
});
}
// -------------------------------------------------------------------
// Copy-modify-set. A Theme is data, so customising it is not an API — it is
// assignment. There is no cascade, no selector and no stylesheet to learn.
// -------------------------------------------------------------------
void custom_theme_demo() {
rmp::ui::panel({ .box = { .grow_x = true } }, [this] {
rmp::ui::text("Your own Theme", { .size = rmp::ui::Size::LARGE });
rmp::ui::text(
"Start from one of ours, change what you want, set it back.",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
rmp::ui::row({ .grow_x = true }, [this] {
if (rmp::ui::button("Gold accent")) {
rmp::ui::Theme t = rmp::ui::current_theme();
t.primary = GOLD;
t.primary_hover = YELLOW;
t.primary_press = ORANGE;
rmp::ui::set_theme(t);
}
if (rmp::ui::button("Sharp corners")) {
rmp::ui::Theme t = rmp::ui::current_theme();
t.corner_radius = 0;
rmp::ui::set_theme(t);
}
if (rmp::ui::button("Bigger everything")) {
rmp::ui::Theme t = rmp::ui::current_theme();
t.font_size *= 1.15f;
t.font_size_small *= 1.15f;
t.font_size_large *= 1.15f;
rmp::ui::set_theme(t);
}
if (rmp::ui::button("Reset", { .style = rmp::ui::Variant::GHOST }))
apply_style();
});
});
}
};
RMP_GAME(StyleScene);https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html
scale() versus current_breakpoint(), and which to reach for. A sidebar that becomes a top strip when the window is taller than it is wide. Resize it: it takes the whole window with set_stretch(Stretch::NONE), where the other examples letterbox.

From a clone of the framework:
rmp example 07_responsiveEvery file of examples/ui/07_responsive, as it is at the commit this site documents (on GitHub).
src/main.cpp 173 lines// ---------------------------------------------------------------------------
// examples/ui/07_responsive/src/main.cpp
//
// Two mechanisms, and knowing which one to reach for is most of the skill.
//
// scale() makes everything BIGGER or smaller, together. It is
// automatic, derived from [window] and the real window,
// and you almost never touch it.
// current_breakpoint() changes the SHAPE of the layout. It is manual, and it
// is for the one thing scale cannot do: no combination of
// grow, fit and fixed turns a row into a column.
//
// The rule of thumb: if you are reaching for a breakpoint to pick a size, stop
// — scale already did that for you, and hard-coding around it is how a layout
// ends up looking right on exactly one machine. Reach for it when the layout
// has to become a different layout.
//
// Resize the window and watch the sidebar move under the content when the
// window becomes taller than it is wide. That is a phone held upright.
//
// Run it: `rmp example 07_responsive`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <array>
#include <string>
#include <string_view>
namespace {
constexpr std::array SECTIONS{ "World", "Bestiary", "Journal", "Crafting", "Map" };
constexpr int SECTION_COUNT = static_cast<int>(SECTIONS.size());
std::string_view breakpoint_name() {
switch (rmp::ui::current_breakpoint()) {
case rmp::ui::Breakpoint::COMPACT:
return "compact";
case rmp::ui::Breakpoint::MEDIUM:
return "medium";
case rmp::ui::Breakpoint::EXPANDED:
return "expanded";
}
return "?";
}
} // namespace
class ResponsiveScene : public rmp::Scene {
public:
void _ready() override {
// The whole window, whatever its shape -- resize it, that is the
// point. The examples' .toml letterboxes the game's area to the
// design's 16:9 ([window] stretch), and in that area the breakpoint
// never changes -- which is this example's point.
rmp::app::set_stretch(rmp::app::Stretch::NONE);
}
void _draw() override {
// grow: the frame is the whole window, so the sidebar and the content
// below can take all of it. Without it begin() fits its content, which is
// a menu's shape and not a screen's.
rmp::ui::begin(
{ .placement = rmp::ui::Align::TOP_CENTER, .padding = 12, .grow = true });
// A status line, so the breakpoint is visible while you drag the window.
// Nothing in a real game would draw this.
rmp::ui::row({ .grow_x = true }, [] {
rmp::ui::text(
std::string("Breakpoint: ").append(breakpoint_name()),
{ .color = rmp::ui::ColorRole::PRIMARY, .size = rmp::ui::Size::SMALL });
rmp::ui::spacer();
rmp::ui::text(
std::to_string(GetScreenWidth()) + "x" +
std::to_string(GetScreenHeight()) + " scale " +
std::to_string(rmp::ui::scale()).substr(0, 4),
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
});
// THE WHOLE EXAMPLE IS THESE SEVEN LINES. Two arrangements of the same two
// functions, and the only thing that picks between them is the shape of the
// window — not its size, which scale() has already handled.
if (rmp::ui::compact()) {
rmp::ui::column({ .grow_x = true, .grow_y = true }, [this] {
sidebar();
content();
});
} else {
rmp::ui::row({ .grow_x = true, .grow_y = true }, [this] {
sidebar();
content();
});
}
rmp::ui::end();
}
private:
int _selected = 0;
bool _show_grid = true;
// -------------------------------------------------------------------
// The two halves. Written once, arranged twice — which is the entire trick.
// Neither of them knows anything about the window.
// -------------------------------------------------------------------
void sidebar() {
// On a wide window this is a fixed-width column down the left. On a narrow
// one it is a full-width strip along the top, and the buttons run across
// instead of down. Same buttons, same state, same handlers.
const bool narrow = rmp::ui::compact();
auto items = [this] {
for (int i = 0; i < SECTION_COUNT; ++i) {
const bool active = (i == _selected);
if (rmp::ui::button(SECTIONS[i],
{ .style = active ? rmp::ui::Variant::PRIMARY
: rmp::ui::Variant::GHOST,
.size = rmp::ui::Size::SMALL })) {
_selected = i;
}
}
};
if (narrow) {
rmp::ui::panel({ .box = { .grow_x = true } }, [&] {
// A row that wraps would be better still, and "a row that wraps" is
// spelled grid({ .columns = 0 }) — see the grid below and
// ui/05_inventory. Kept as a plain row here so the shape change is
// the only thing this example is demonstrating.
rmp::ui::row({ .grow_x = true }, items);
});
} else {
rmp::ui::panel({ .box = { .width = 200, .grow_y = true } }, [&] {
rmp::ui::text(
"Sections",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
items();
});
}
}
void content() {
rmp::ui::panel({ .box = { .grow_x = true, .grow_y = true } }, [this] {
rmp::ui::text(SECTIONS[_selected], { .size = rmp::ui::Size::LARGE });
rmp::ui::checkbox("Show the grid", _show_grid);
if (_show_grid) {
// Nothing responsive to write here: columns = 0 works out how many
// fit in the width it is given and works it out again every frame.
// This is the composition answer to "a row that wraps", and it is
// why there is no wrap flag on row().
rmp::ui::scroll([] {
rmp::ui::grid({ .columns = 0, .min_cell = 110, .id = "tiles" }, [] {
for (int i = 0; i < 24; ++i) {
rmp::ui::cell([&] {
rmp::ui::panel({ .box = { .padding = 10 } }, [&] {
rmp::ui::text("Item " + std::to_string(i + 1),
{ .size = rmp::ui::Size::SMALL });
rmp::ui::progress(static_cast<float>(i % 10) / 9.0f);
});
});
}
});
});
}
});
}
};
RMP_GAME(ResponsiveScene);https://omardev29.github.io/rmp-docs/examples/ui/08_overlay.html
overlay(): a pause menu pushed as a scene of its own, blurred, that freezes the game below; and "Really quit?" drawn by the game scene itself -- an overlay with a panel() in it, which is all a dialog is. The veil takes the clicks, the first button the focus, and the balls go on behind the question. One scene per file under src/scenes/.

From a clone of the framework:
rmp example 08_overlayEvery file of examples/ui/08_overlay, as it is at the commit this site documents (on GitHub).
src/main.cpp 32 lines// ---------------------------------------------------------------------------
// examples/ui/08_overlay/src/main.cpp
//
// rmp::ui::overlay(): a pause menu, a "Really quit?", a game-over card --
// whatever has to be in front of the game, with the game dimmed or blurred
// behind it so that the eye goes where the player has to act.
//
// Two of them, and the difference between them is the point:
//
// the pause a scene of its own, PUSHED over the game. Its whole _draw()
// is one overlay(), blurred; the balls below stop because a
// pushed scene freezes what is under it by default.
// src/scenes/pause.cpp.
// the dialog "Really quit?", drawn by the game scene itself after its HUD:
// an overlay() with a panel() in it, which is all a dialog is
// -- there is no dialog() to learn. Nothing is pushed, so
// nothing stops: the balls go on behind the question. The
// overlay takes the clicks, the focus and Enter; the rest is
// the scene's to decide. src/scenes/game.cpp.
//
// The blur is a real one on every GPU raylib drives, OpenGL ES 2.0 and WebGL
// included. raylib's software renderer has no shaders, so the screenshots CI
// takes of this example show the veil alone.
//
// Run it: `rmp example 08_overlay`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "scenes/game.h"
RMP_GAME(GameScene);src/scenes/game.cpp 74 lines#include "game.h"
#include "pause.h"
#include <rmp/app.h>
#include <rmp/object.h>
#include <rmp/ui.h>
#include <array>
namespace {
// Where each ball starts, how fast it goes, and how it looks.
struct Ball {
Vector2 position;
Vector2 velocity;
float radius;
Color color;
};
constexpr std::array BALLS{
Ball{ { 120, 110 }, { 120, 80 }, 34, RED },
Ball{ { 300, 330 }, { -150, 95 }, 26, ORANGE },
Ball{ { 420, 160 }, { 100, -120 }, 40, GOLD },
Ball{ { 560, 300 }, { -90, -70 }, 30, LIME },
Ball{ { 680, 120 }, { 140, 110 }, 24, SKYBLUE },
Ball{ { 220, 220 }, { -110, -130 }, 36, VIOLET },
};
} // namespace
void GameScene::_ready() {
// Something to be in front of: balls bouncing off the edges of the
// window. A veil over an empty screen shows nothing, and a blur less.
for (const Ball &b : BALLS) {
rmp::Shape shape = rmp::circle(b.radius);
shape.color = b.color;
spawn({ .position = b.position,
.shape = shape,
.velocity = b.velocity,
.edges = rmp::Edge::BOUNCE });
}
}
void GameScene::_draw() {
// The HUD. This scene reads no keys, so it is no game being PLAYED, and
// its first button has the focus, as a menu's would: Enter pauses.
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT });
if (rmp::ui::button("Pause")) rmp::Scene::push<PauseScene>();
#if !defined(PLATFORM_IOS)
// Inert on iPhone: Apple rejects apps that terminate themselves.
if (rmp::ui::button("Quit")) _asking = true;
#endif
rmp::ui::end();
// The dialog. After end(), never inside it: an overlay is a frame of its
// own. The panel is the box; the overlay is the veil behind it, the
// clicks it takes from everything under it, and the focus on its first
// button -- Stay, so that Enter is the answer that loses nothing.
if (_asking) {
rmp::ui::overlay({ .dim = 0.6f }, [&] {
rmp::ui::panel([&] {
rmp::ui::text("Really quit?");
rmp::ui::text("The balls will stop for good.",
{ .color = rmp::ui::ColorRole::MUTED });
rmp::ui::row([&] {
if (rmp::ui::button("Stay")) _asking = false;
if (rmp::ui::button("Quit", { .style = rmp::ui::Variant::DANGER }))
rmp::app::quit();
});
});
});
}
}src/scenes/game.h 11 lines#pragma once
#include <rmp/scene.h>
class GameScene : public rmp::Scene {
public:
void _ready() override;
void _draw() override;
private:
bool _asking = false; // "Really quit?" is on screen
};src/scenes/pause.cpp 13 lines#include "pause.h"
#include <rmp/ui.h>
void PauseScene::_draw() {
// blur: how far, in design units -- CSS's blur(), the Gaussian's standard
// deviation. dim: how far towards the veil's colour, black unless you say
// otherwise. Six and 0.4 say "not now" and still show where you were.
rmp::ui::overlay({ .blur = 6, .dim = 0.4f }, [] {
rmp::ui::text("Paused", { .size = rmp::ui::Size::LARGE });
if (rmp::ui::button("Resume")) rmp::Scene::pop();
});
}src/scenes/pause.h 9 lines#pragma once
#include <rmp/scene.h>
// Every default untouched: pushed, it freezes the game, keeps it on screen
// behind the overlay, and takes the input.
class PauseScene : public rmp::Scene {
public:
void _draw() override;
};https://omardev29.github.io/rmp-docs/examples/ui/09_skinned.html
The other way to write rmp::ui: a game's shop screen designed rather than written. Every button and panel a nine-slice from one Aseprite file, icons as its named slices (slice()), a title in its own font with an outline, a soft shadow, sounds on hover and click, buttons that grow and shrink, a panel that slides in, a button that shake()s -- all of it one Theme with a Style per kind of widget -- and widgets you keep (Button, Label, Image, Panel, Checkbox, Slider, ProgressBar) as members of the scene, each with its callbacks; image_button() and on_event(). Its art is generated by tools/make_skinned_art.py.

From a clone of the framework:
rmp example 09_skinnedEvery file of examples/ui/09_skinned, as it is at the commit this site documents (on GitHub).
src/main.cpp 32 lines// ---------------------------------------------------------------------------
// examples/ui/09_skinned/src/main.cpp
//
// A game's shop screen, skinned: the other way to write rmp::ui.
//
// The examples before this one write the interface a call at a time, and a
// main menu is three of them. This one is what a screen DESIGNED by an artist
// looks like: every button and panel a picture from one Aseprite file, every
// icon a named slice of it, a title in a font of its own with an outline, a
// soft shadow under the shop, sounds on hover and click, buttons that grow
// under the pointer and shrink when pressed, a panel that slides in, a button
// that shakes when there is not enough money -- and widgets you KEEP, members
// of the scene, each with its look and its callbacks, the way a Godot scene
// keeps its nodes.
//
// Where each piece is:
//
// the look of everything ShopScene::_ready(): one Theme, with a Style for
// every button and every panel, sounds and motion
// the widgets src/scenes/shop.h: kept, with their callbacks
// the screen ShopScene::_draw(): where each one is shown
//
// The art is generated, as the art of every example is: tools/make_skinned_art.py.
//
// Run it: `rmp example 09_skinned`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "scenes/shop.h"
RMP_GAME(ShopScene);src/scenes/shop.cpp 126 lines#include "shop.h"
#include <rmp/audio.h>
#include <string>
namespace {
constexpr int STAR_PRICE = 3;
constexpr int STARS_TO_COLLECT = 5;
} // namespace
void ShopScene::_ready() {
_skin = rmp::assets::load_sheet("skin.aseprite");
// The look of the whole game, in one place: every button a wooden frame
// that stretches by its middle, a darker one while it is pressed; every
// panel the same frame, with a soft shadow, sliding in when it appears.
// Sounds on hover and click, and a "no" for a shake.
rmp::ui::Theme look = rmp::ui::theme_dark();
look.sounds = { .hover = "hover", .click = "click", .shake = "nope" };
look.motion = { .hover_scale = 1.04f, .press_scale = 0.96f };
look.styles.button = {
.skin = rmp::ui::Skin{ .normal = rmp::ui::slice(_skin, "button"),
.press = rmp::ui::slice(_skin, "button_down") },
.padding_x = 18,
.padding_y = 10,
.text = RAYWHITE,
.text_shadow = rmp::ui::TextShadow{},
};
look.styles.panel = {
.skin = rmp::ui::Skin{ .normal = rmp::ui::slice(_skin, "panel") },
.shadow = rmp::ui::Shadow{ .offset = { 0, 6 }, .blur = 10 },
.padding_x = 22,
.motion = rmp::ui::Motion{ .appear = 0.25f,
.appear_offset = 16,
.appear_scale = 0.96f },
};
rmp::ui::set_theme(look);
_title.style = { .text = GOLD,
.font = rmp::assets::load_font("title.ttf", 40),
.text_outline = rmp::ui::TextOutline{ .width = 2, .color = BLACK } };
_spinner.sprite.sheet = rmp::assets::load_sheet("spinner.aseprite");
_spinner.sprite.play("spin");
_buy.icon = rmp::ui::slice(_skin, "coin");
_sell.icon = rmp::ui::slice(_skin, "star");
_collection.fill_picture = rmp::ui::slice(_skin, "bar");
// Every click of every control, the immediate ones too: one hook.
rmp::ui::on_event([this](const rmp::ui::Event &e) {
if (e.kind == rmp::ui::EventKind::CLICK) ++_clicks;
});
}
void ShopScene::buy_star() {
if (_coins < STAR_PRICE) {
_buy.shake(); // and the theme plays its "nope"
rmp::ui::notify("Not enough coins", { .color = rmp::ui::ColorRole::DANGER });
return;
}
_coins -= STAR_PRICE;
++_stars;
}
void ShopScene::sell_star() {
if (_stars == 0) {
_sell.shake();
return;
}
--_stars;
_coins += STAR_PRICE - 1;
}
void ShopScene::show_shop() {
_shop.show([&] {
rmp::ui::row([&] {
_spinner.show();
rmp::ui::column([&] {
rmp::ui::row([&] {
rmp::ui::image(rmp::ui::slice(_skin, "coin"),
{ .width = 24, .height = 24 });
rmp::ui::text("Coins: " + std::to_string(_coins));
rmp::ui::image(rmp::ui::slice(_skin, "star"),
{ .width = 24, .height = 24 });
rmp::ui::text("Stars: " + std::to_string(_stars));
});
rmp::ui::text("Three coins a star. No refunds, café prices.");
});
});
rmp::ui::row([&] {
_buy.show();
_sell.show();
});
_collection.value = static_cast<float>(_stars) / STARS_TO_COLLECT;
_collection.show();
});
}
void ShopScene::show_settings() {
rmp::ui::overlay({ .dim = 0.5f }, [&] {
rmp::ui::panel([&] {
rmp::ui::text("Settings");
_sound.show();
_volume.show();
_close.show();
});
});
}
void ShopScene::_draw() {
rmp::ui::begin();
_title.show();
show_shop();
rmp::ui::row([&] {
if (rmp::ui::image_button(rmp::ui::slice(_skin, "gear"),
{ .width = 32, .height = 32, .id = "settings" }))
_settings = true;
rmp::ui::text("Clicks: " + std::to_string(_clicks),
{ .color = rmp::ui::ColorRole::MUTED });
});
rmp::ui::end();
if (_settings) show_settings();
}src/scenes/shop.h 52 lines#pragma once
#include <rmp/assets.h>
#include <rmp/audio.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
// The shop: coins to spend on stars, a settings panel behind the gear.
class ShopScene : public rmp::Scene {
public:
void _ready() override;
void _draw() override;
private:
void buy_star();
void sell_star();
void show_shop();
void show_settings();
rmp::SpriteSheet _skin; // skin.aseprite: the frames, the panel, the icons
int _coins = 5;
int _stars = 0;
int _clicks = 0; // every click of every control, counted by on_event()
bool _settings = false;
// A title in a font of its own, with an outline, so it reads on anything.
rmp::ui::Label _title{ .text = "The Star Shop", .size = rmp::ui::Size::LARGE };
// The star, turning: an animated sprite a kept Image plays by itself.
rmp::ui::Image _spinner{ .width = 48, .height = 48, .id = "spinner" };
// The shop: a panel whose own look comes from the theme, and whose
// children all write in gold.
rmp::ui::Panel _shop{ .id = "shop", .children = { .text = GOLD } };
rmp::ui::Button _buy{ .text = "Buy a star", .id = "buy", .on_click = [this] {
buy_star();
} };
rmp::ui::Button _sell{ .text = "Sell a star", .id = "sell", .on_click = [this] {
sell_star();
} };
rmp::ui::ProgressBar _collection{ .width = 300, .height = 18, .id = "collection" };
// The settings, which keep their own values.
rmp::ui::Checkbox _sound{ .text = "Sound", .checked = true, .on_change = [](bool on) {
rmp::audio::set_volume(rmp::audio::Bus::SFX,
on ? 1.0f : 0.0f);
} };
rmp::ui::Slider _volume{ .text = "Volume",
.value = 1.0f,
.step = 0.1f,
.width = 160,
.on_change = [](float v) {
rmp::audio::set_volume(rmp::audio::Bus::MASTER, v);
} };
rmp::ui::Button _close{ .text = "Close", .on_click = [this] { _settings = false; } };
};https://omardev29.github.io/rmp-docs/examples/ui/10_dialogue.html
One Yarn conversation, three ways, switched while it runs: a DialogueBox (a portrait, a name plate on the frame, a voice per Speaker), a DialogueBubble over whoever speaks with its tail pointing at them, and a DialogueStage whose cast slides in and comes forward, shaken by a <<quake>>. What the game hands the script: $cups bound to the scene's int (bind()), a typed function (on_function), a command (on_command), and Yarn's own <<wait 1>>. Kenney's art, from tools/make_story_assets.py.

From a clone of the framework:
rmp example 10_dialogueEvery file of examples/ui/10_dialogue, as it is at the commit this site documents (on GitHub).
src/main.cpp 171 lines// ---------------------------------------------------------------------------
// examples/ui/10_dialogue/src/main.cpp
//
// One Yarn conversation, shown three ways -- switch while it runs:
//
// Box a box along the bottom: a portrait, a name plate on the frame, a
// voice for each speaker. The classic RPG.
// Bubble a bubble over whoever speaks, its tail pointing at them, while the
// park goes on around it.
// Stage big portraits that slide in, the speaker in front, the rest
// dimmed; a quake shakes it. A visual novel.
//
// And what the game hands the dialogue: $cups is the scene's own int, bound
// (talk.bind), time_of_day() a typed function, <<quake>> a command. The
// script waits a second by itself (<<wait 1>>).
//
// The art is Kenney's (CC0): tools/make_story_assets.py. The words are
// resources/talk.yarn. Run it: `rmp example 10_dialogue`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/dialogue.h>
#include <rmp/scene.h>
#include <rmp/ui.h>
#include <array>
#include <string>
#include <string_view>
namespace {
constexpr float FRAME = 12; // panel.png's border, in its pixels
constexpr float PLATE = 10; // plate.png's
constexpr std::array<std::string_view, 3> MOODS{ "happy", "sad", "think" };
const Color PARK = { 109, 190, 106, 255 };
const Color INK = { 62, 39, 35, 255 };
const Color CREAM = { 255, 246, 226, 255 };
rmp::ui::Picture frame(std::string_view file, float border) {
return rmp::ui::NineSlice{ .texture = rmp::assets::load_texture(file),
.left = border,
.top = border,
.right = border,
.bottom = border,
.scale = 2 };
}
// Both of them, in every mood: one picture each, by speaker and #mood:.
std::vector<rmp::ui::Portrait> portraits() {
const auto picture = [](const std::string &file) -> rmp::ui::Picture {
return rmp::assets::load_texture(file);
};
std::vector<rmp::ui::Portrait> all;
for (const std::string who : { "mika", "sora" }) {
const std::string name = who == "mika" ? "Mika" : "Sora";
const std::string file = "portraits/" + who + "_";
all.push_back({ .speaker = name, .picture = picture(file + "neutral.png") });
for (const std::string_view mood : MOODS) {
all.push_back({ .speaker = name,
.mood = std::string(mood),
.picture = picture(file + std::string(mood) + ".png") });
}
}
return all;
}
} // namespace
class ParkScene : public rmp::Scene {
public:
void _ready() override {
background = PARK;
rmp::ui::set_font(rmp::assets::load_font("font.ttf", 16));
rmp::ui::Theme look = rmp::ui::theme_light();
look.text = INK;
look.sounds = { .click = "click", .volume = 0.5f };
look.styles.panel = { .skin =
rmp::ui::Skin{ .normal = frame("panel.png", FRAME) },
.padding_x = 26,
.padding_y = 20,
.gap = 10 };
look.styles.button = {
.skin = rmp::ui::Skin{ .normal = frame("button.png", PLATE),
.press = frame("button_down.png", PLATE) },
.padding_x = 20,
.padding_y = 10,
.text = INK
};
rmp::ui::set_theme(look);
// Two people in the park, for the bubble to stand over.
for (const auto &[name, x] :
{ std::pair{ "Mika", 400.0f }, std::pair{ "Sora", 580.0f } }) {
auto &person = spawn({ .position = { x, 180 } });
person.sprite.texture = rmp::assets::load_texture(
std::string("portraits/") + (name[0] == 'M' ? "mika" : "sora") +
"_neutral.png");
person.sprite.size = { 72, 96 };
_people.push_back(
{ .name = name, .object = person.handle(), .offset = { 0, -52 } });
}
_people[0].pitch = 1.25f;
_people[1].pitch = 0.85f;
start();
}
void _draw() override {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT, .padding = 12 });
rmp::ui::panel([this] {
rmp::ui::dropdown("Shown as", _style, { "Box", "Bubble", "Stage" });
rmp::ui::text(rmp::Text("Cups of tea: {cups}", { { "cups", _cups } }),
{ .wrap = false });
if (rmp::ui::button("Again")) start();
});
rmp::ui::end();
rmp::ui::begin({ .placement = rmp::ui::Align::BOTTOM_CENTER, .grow = true });
if (_style == 0) _box.show(_talk);
if (_style == 2) _stage.show(_talk);
rmp::ui::end();
if (_style == 1) {
rmp::ui::begin();
_bubble.show(_talk);
rmp::ui::end();
}
}
private:
void start() {
_talk = rmp::assets::load_dialogue("talk.yarn");
_talk.bind("$cups", _cups);
// Morning, afternoon or evening: the game's clock, not the script's.
_talk.on_function("time_of_day", []() -> std::string { return "afternoon"; });
_talk.on_command("quake", [this] { _stage.shake(); });
_talk.start();
const rmp::ui::DialogueFlow flow{
.letters_per_second = 40, .blip = "tap", .blip_every = 3, .blip_jitter = 0.05f
};
const rmp::ui::Style plate{ .skin = rmp::ui::Skin{ .normal = frame("plate.png",
PLATE) },
.padding_x = 18,
.padding_y = 6,
.text = CREAM };
const std::vector<rmp::ui::Speaker> voices{ { .name = "Mika", .pitch = 1.25f },
{ .name = "Sora", .pitch = 0.85f } };
_box = { .portraits = portraits(),
.speakers = voices,
.flow = flow,
.width = 640,
.name_offset = { 18, -16 },
.name_style = plate };
_bubble = { .speakers = _people, .flow = flow, .width = 240 };
_stage = { .portraits = portraits(),
.speakers = voices,
.flow = flow,
.portrait_height = 250,
.name_style = plate };
}
rmp::Dialogue _talk;
int _cups = 0;
int _style = 0;
std::vector<rmp::ui::BubbleSpeaker> _people;
rmp::ui::DialogueBox _box;
rmp::ui::DialogueBubble _bubble;
rmp::ui::DialogueStage _stage;
};
RMP_GAME(ParkScene);https://omardev29.github.io/rmp-docs/examples/ui/11_localization.html
A lantern stall in English, Spanish, Japanese and German, switched while it runs: every literal its own key in resources/lang.tsv, German in a file of its own (lang/de.tsv), {placeholders}, plurals in each language's forms, a context, and a font per language -- Japanese in Jigmo (CC0), cut down to the letters the table uses -- with each language's name in the menu in a font that has its letters (Style::font).

From a clone of the framework:
rmp example 11_localizationEvery file of examples/ui/11_localization, as it is at the commit this site documents (on GitHub).
src/main.cpp 137 lines// ---------------------------------------------------------------------------
// examples/ui/11_localization/src/main.cpp
//
// A lantern stall at a night market, in English, Spanish, Japanese and
// German -- switch while it runs. Nothing in this file translates anything:
//
// every literal button("Buy a lantern") is its own key in
// resources/lang.tsv, one column a language
// resources/lang/de.tsv German, in a file of its own: both shapes, merged
// {placeholders} "Hello, {name}!" keeps its key whatever the name
// plurals "{count} lantern|{count} lanterns": each language
// its own forms (Japanese has one)
// a context "Open" the stall and "Open" the door: two rows
// a font per language Japanese draws in jp.ttf (Jigmo, cut to what it
// needs); the rest in Kenney's pixel font
//
// `rmp text scan` keeps the tables in step with this file; `rmp text check`
// fails a language with a hole in it. The art is Kenney's and Jigmo's (CC0):
// tools/make_story_assets.py. Run it: `rmp example 11_localization`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/scene.h>
#include <rmp/text.h>
#include <rmp/ui.h>
#include <string>
#include <string_view>
namespace {
constexpr int PRICE = 3; // coins a lantern
constexpr int WORTH = 5; // coins a lantern sells for
constexpr float FRAME = 12; // panel.png's border
constexpr float PLATE = 10; // button.png's
const Color NIGHT = { 22, 24, 52, 255 };
const Color INK = { 62, 39, 35, 255 };
rmp::ui::Picture frame(std::string_view file, float border) {
return rmp::ui::NineSlice{ .texture = rmp::assets::load_texture(file),
.left = border,
.top = border,
.right = border,
.bottom = border,
.scale = 2 };
}
// Japanese needs its own letters: the UI's font follows the language.
void font_for(std::string_view language) {
rmp::ui::set_font(
rmp::assets::load_font(language == "ja" ? "jp.ttf" : "font.ttf", 16));
}
} // namespace
class MarketScene : public rmp::Scene {
public:
void _ready() override {
background = NIGHT;
rmp::ui::Theme look = rmp::ui::theme_light();
look.text = INK;
look.sounds = { .click = "click", .volume = 0.5f };
look.styles.panel = { .skin =
rmp::ui::Skin{ .normal = frame("panel.png", FRAME) },
.padding_x = 28,
.padding_y = 22,
.gap = 10 };
look.styles.button = {
.skin = rmp::ui::Skin{ .normal = frame("button.png", PLATE),
.press = frame("button_down.png", PLATE) },
.padding_x = 22,
.padding_y = 10,
.text = INK
};
rmp::ui::set_theme(look);
_japanese = rmp::assets::load_font("jp.ttf", 16);
_latin = rmp::assets::load_font("font.ttf", 16);
font_for(rmp::lang::current());
}
void _draw() override {
rmp::ui::begin();
rmp::ui::panel([this] {
rmp::ui::text("The Lantern Market",
{ .size = rmp::ui::Size::LARGE, .wrap = false });
rmp::ui::text(rmp::Text("Hello, {name}!", { { "name", "Ada" } }),
{ .wrap = false });
rmp::ui::text(rmp::Text("Open", { .context = "stall" }), { .wrap = false });
rmp::ui::text(
rmp::Text("{count} coin|{count} coins", { { "count", _coins } }),
{ .wrap = false });
rmp::ui::text(
rmp::Text("{count} lantern|{count} lanterns", { { "count", _lanterns } }),
{ .wrap = false });
if (rmp::ui::button("Buy a lantern")) {
if (_coins < PRICE) {
rmp::ui::notify("Not enough coins");
} else {
_coins -= PRICE;
++_lanterns;
}
}
if (rmp::ui::button("Sell everything") && _lanterns > 0) {
rmp::ui::notify(rmp::Text(
"Sold {count} for {coins}",
{ { "count", _lanterns }, { "coins", _lanterns * WORTH } }));
_coins += _lanterns * WORTH;
_lanterns = 0;
}
rmp::ui::text("Language",
{ .color = rmp::ui::ColorRole::MUTED, .wrap = false });
// Each language's name in its own words, in a font that has its
// letters, whatever the language is now.
rmp::ui::row([this] {
for (const std::string &code : rmp::lang::available()) {
rmp::ui::Button pick{ .text = rmp::Text(rmp::lang::name(code)),
.id = "language_" + code };
pick.style.font = code == "ja" ? _japanese : _latin;
if (pick.show()) {
rmp::lang::set(code);
font_for(code);
}
}
});
});
rmp::ui::end();
}
private:
rmp::Font _japanese; // jp.ttf: the Japanese name, whatever the language
rmp::Font _latin; // font.ttf: the others' names, in Japanese too
int _coins = 10;
int _lanterns = 0;
};
RMP_GAME(MarketScene);https://omardev29.github.io/rmp-docs/examples/ui/12_font.html
A menu in a font of your own: a title, its options and its credits, one scene each, every word in Hack Bold through one rmp::ui::set_font(). The font is baked again at every size it is drawn at, so a 48 title is as sharp as a 20 button.

From a clone of the framework:
rmp example 12_fontRead from the code below: the actions it defines with rmp::input::action, the ones that come defined that it reads by name, and the keys it asks raylib about directly.
| Action | Keys |
|---|---|
ui_cancel | Esc, gamepad right face right |
Every file of examples/ui/12_font, as it is at the commit this site documents (on GitHub).
src/main.cpp 29 lines// ---------------------------------------------------------------------------
// examples/ui/12_font/src/main.cpp
//
// A menu in a font of your own: a title screen, its options and its credits,
// one scene each, every word in Hack Bold.
//
// One call puts it on everything rmp::ui draws, from the title down to a
// dropdown's items:
//
// rmp::ui::set_font(rmp::assets::load_font("fonts/hack-bold.ttf", 20));
//
// The size you load it at does not limit the sizes it is drawn at. The UI
// keeps the font's FILE and bakes it again at each size it needs, so the
// title at 48 is as sharp as the buttons at 20 -- and the letters a language
// needs come when they are first drawn, not before.
//
// [ui] font in the .toml does the same for a whole game, from the first
// frame. set_font() is for when it changes: a setting, a language, a scene of
// its own. The examples share one .toml, so this one calls it.
//
// One scene per screen under src/scenes/, change<>() between them.
// Run it: `rmp example 12_font`.
// ---------------------------------------------------------------------------
#include <rmp/app.h>
#include "scenes/scenes.h"
RMP_GAME(TitleScene);src/scenes/credits.cpp 25 lines// The credits, which is where a font's author goes.
#include "scenes.h"
#include <rmp/input.h>
#include <rmp/ui.h>
void CreditsScene::_update(float) {
if (rmp::input::just_pressed("ui_cancel")) change<TitleScene>();
}
void CreditsScene::_draw() {
rmp::ui::begin();
rmp::ui::panel({ .box = { .width = 640 } }, [] {
rmp::ui::text("CREDITS", { .size = rmp::ui::Size::LARGE });
rmp::ui::text("Font: Hack Bold, by Source Foundry");
rmp::ui::text(
"MIT licence; derived from DejaVu and Bitstream Vera",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
rmp::ui::text(
"Made with raylib and rmp",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
if (rmp::ui::button("Back")) change<TitleScene>();
});
rmp::ui::end();
}src/scenes/options.cpp 29 lines// The options: every kind of control, and every one of them in the font.
#include "scenes.h"
#include <rmp/input.h>
#include <rmp/ui.h>
#include <array>
#include <string_view>
namespace {
constexpr std::array<std::string_view, 3> DIFFICULTY{ "Relaxed", "Normal", "Wide awake" };
} // namespace
void OptionsScene::_update(float) {
// Escape, or the gamepad's B: back to the title.
if (rmp::input::just_pressed("ui_cancel")) change<TitleScene>();
}
void OptionsScene::_draw() {
rmp::ui::begin();
rmp::ui::panel({ .box = { .width = 420 } }, [] {
rmp::ui::text("OPTIONS", { .size = rmp::ui::Size::LARGE });
rmp::ui::checkbox("Show hints", options.hints);
rmp::ui::slider("Text speed", options.text_speed, 0.0f, 1.0f, { .step = 0.1f });
rmp::ui::dropdown("Difficulty", options.difficulty, DIFFICULTY);
if (rmp::ui::button("Back")) change<TitleScene>();
});
rmp::ui::end();
}src/scenes/scenes.h 28 lines#pragma once
#include <rmp/scene.h>
// What the options change, and what outlives the screen that changed it.
struct Options {
bool hints = true;
float text_speed = 0.5f;
int difficulty = 1;
};
inline Options options;
class TitleScene : public rmp::Scene {
public:
void _ready() override;
void _draw() override;
};
class OptionsScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};
class CreditsScene : public rmp::Scene {
public:
void _update(float delta) override;
void _draw() override;
};src/scenes/title.cpp 34 lines// The title screen, and where the font is set.
#include "scenes.h"
#include <rmp/app.h>
#include <rmp/assets.h>
#include <rmp/ui.h>
void TitleScene::_ready() {
// Every scene after this one draws in it too: the font is the UI's, not
// the scene's. Setting it again when the title comes back costs nothing --
// the asset is loaded once, by name.
rmp::ui::set_font(rmp::assets::load_font("fonts/hack-bold.ttf", 20));
}
void TitleScene::_draw() {
rmp::ui::begin();
rmp::ui::text("NIGHT SHIFT", { .size = 48 });
rmp::ui::text("a game about staying awake",
{ .color = rmp::ui::ColorRole::MUTED, .size = rmp::ui::Size::SMALL });
rmp::ui::spacer(12);
if (rmp::ui::button("New game", { .style = rmp::ui::Variant::PRIMARY })) {
rmp::ui::notify("No game yet: this is a menu");
}
if (rmp::ui::button("Options")) change<OptionsScene>();
if (rmp::ui::button("Credits")) change<CreditsScene>();
#if !defined(PLATFORM_IOS)
// Inert on iPhone: Apple rejects apps that terminate themselves.
if (rmp::ui::button("Quit", { .style = rmp::ui::Variant::GHOST })) rmp::app::quit();
#endif
rmp::ui::end();
}https://omardev29.github.io/rmp-docs/publishing/index.html
A release is a git tag. rmp deploy checks the version the way CI
will, tags the commit and pushes the tag; CI then builds every target your game has turned on,
boots the ones it can, and attaches all of them to a GitHub release. From there each build goes
where its platform wants it: a zip to download, a folder on itch.io, a bundle for Google Play.
rmp deploy 1.2.0There is no version number anywhere in the project. The tag is the version: v1.2.0
becomes the version Android and iOS show, the Android version code and the name of the release, so
there is no number in a file to bump and none to forget. Releases and versions
has the whole of it: the shape a tag must have, what rmp deploy checks and in which
order, and how to take a tag back.
Four things are yours to decide once, and the first one cannot be changed afterwards.
Give the game its real identifiers. rmp new writes
com.example. ids for Android and iOS, and a release is refused while either one still
starts with com.example.: Google Play keeps an application id for good, so a game
published under a placeholder would keep the placeholder.
[android]
application_id = "com.yourname.yourgame"
[ios]
bundle_id = "com.yourname.yourgame"Choose the targets. [targets] enabled starts as
["all"], which is 17 of them. A target you switch off is not built,
not tested and not released, and the release does not wait for it. The ids and the groups are in
the configuration reference.
Decide where the saves go. A zip that players unpack and run, which is what
itch.io serves, wants [save] portable = true: the saves go in a folder beside the
executable, and deleting the game deletes them. An installer, or Steam and its cloud saves, wants
the default: the player's data folder.
Desktop and BSD archives has the
folders.
Add the secrets you need, on GitHub. Nothing is needed for a release on GitHub itself. Signing for Google Play, uploading to itch.io and testing on Firebase each read secrets from the repository's settings, listed below. Without its secret each one says so in a warning and does without: the App Bundle is signed with a throwaway key, and nothing is uploaded or tested.
Then push your commits, so the commit you tag is one CI can check out. A game made with
rmp new has a main branch that nothing ties to a remote yet: once
origin is added, the first rmp push pushes main and sets it
to track origin, and before that it says how to add one.
rmp push
rmp deploy 1.0.0One GitHub release per tag, with its notes generated by GitHub and, when the tag has a hyphen
in it (v1.2.0-rc1), marked as a pre-release. Attached to it:
resources/
folder beside it — packed into one file, resources.rres, on most targets — and
LICENSES.txt. The game finds its assets from whatever folder it is started in,
except on NetBSD and OpenBSD, where it has to be started in its own.
Desktop and BSD archives.web-build.zip: the page, its script, the WebAssembly module, the preloaded
assets and the web build's own LICENSES.txt.
The web build.THIRD_PARTY_LICENSES.md, and SHA256SUMS to check every download
against.The release is published only when every target that was built passed its checks. A tag that fails on any platform publishes nothing, so a release never has a hole where a platform should be.
| Page | What it covers |
|---|---|
| Releases and versions | Tags, version names and the Android version code; every check rmp deploy makes; what CI does with a tag; undoing one. |
| Desktop and BSD archives | What is in each zip, what a release is hardened with, the glibc floor on Linux, compressing with UPX, signing. |
| The web build | The files, hosting them, memory, size and the browser backend. |
| itch.io | Pushing every build to itch.io with butler, on every tag. |
| Google Play | The application id, signing the App Bundle, the version code, and Firebase Test Lab. |
| The App Store | What CI builds for iOS, what it leaves to Xcode on a Mac, and why. |
| Continuous integration | What every push checks, what only a tag builds, the size every release binary is held to, what is pinned, and how to read a red run. |
Everything CI needs that is not a secret lives in raylib_multiplatform.toml, next
to the rest of the game. Everything that is a secret lives in the repository's settings on GitHub,
under Settings → Secrets and variables → Actions, and nowhere else. These are all of them
— every name the workflows a game carries read:
| Name | Kind | For |
|---|---|---|
ANDROID_KEYSTORE_BASE64 | secret | Your upload keystore, base64-encoded. With it set, CI signs the App Bundle with your key. Google Play |
ANDROID_KEYSTORE_PASSWORD | secret | The keystore's password. |
ANDROID_KEY_ALIAS | secret | The key's alias inside the keystore. |
ANDROID_KEY_PASSWORD | secret | The key's password. |
ANDROID_SIGNER_CN | variable | Optional. The CN of your upload key, so CI checks the bundle is signed by that key and not merely by some key. |
BUTLER_API_KEY | secret | An itch.io API key, for butler. itch.io |
ITCH_USER, ITCH_GAME | variables | Optional. When set, they win over [deploy.itch] in the .toml. |
GCP_SA_KEY | secret | A Google Cloud service-account key, the whole JSON file, for Firebase Test Lab. Google Play |
FIREBASE_PROJECT, FIREBASE_DEVICE | variables | Optional. When set, they win over [deploy.firebase] in the .toml. |
FIREBASE_RESULTS_BUCKET | variable | Optional. A Cloud Storage bucket the Test Lab results are written to and fetched back from. |
IOS_SIMULATOR_TEST | variable | Optional. true turns on the iOS simulator boot test, which is off. The App Store |
https://omardev29.github.io/rmp-docs/publishing/releases.html
A release is an annotated git tag named vMAJOR.MINOR.PATCH.
rmp deploy makes it after checking everything CI would check, pushes it, and CI
builds every enabled target from that commit and publishes them as one GitHub release. The tag is
also the only place the version lives: the version Android and iOS show, the Android version
code and the name of the release are all read from it.
rmp deploy 1.2.0That tags the commit you are on as v1.2.0 — the v is added when you
leave it out — and pushes the tag to origin. Nothing else is pushed: the commit has
to be on GitHub already, which is one of the things rmp deploy checks before it
tags anything. On success it prints:
== checking v1.2.0 the way CI will ==
ok v1.2.0 is release-ready
* [new tag] v1.2.0 -> v1.2.0
pushed v1.2.0. CI builds every target and attaches them to the release.
gh run watch
to undo, if you were quick enough:
git push --delete origin v1.2.0 && git tag -d v1.2.0The tag is annotated, with the message Release v1.2.0: a real git object with an
author and a date, which is what git describe and most release tooling expect. A
lightweight tag pushed by hand builds just the same; rmp deploy makes the annotated
kind.
There is deliberately no version key in raylib_multiplatform.toml.
The build reads the tag CI is building, and everything that carries a version gets it from
there:
| Tag | Version name | Android version code | GitHub release |
|---|---|---|---|
v1.2.3 | 1.2.3 | 1002003 | a release |
v1.2.3-rc1 | 1.2.3-rc1 | 1002003 | marked as a pre-release |
v1.2.3+7 | 1.2.3+7 | 1002003 | a release |
v0.9.0 | 0.9.0 | 9000 | a release |
v1.2 | refused: not vMAJOR.MINOR.PATCH | ||
v01.2.3 | refused: a leading zero, which would share the code of v1.2.3 | ||
v0.0.0 | refused: its code would be 0, and Android's is positive; the first release is v0.0.1 | ||
| no tag | 0.0.0-dev | 1 | none |
The version name is the Android versionName, the iOS MARKETING_VERSION,
and the version itch.io shows for the upload (there it keeps its v:
v1.2.3). Every build that is not a tag build, on your machine or on a push, is
0.0.0-dev with version code 1.
The tag has to be v, three numbers separated by dots, and optionally a
- or + suffix of letters, digits, dots and hyphens. Anything else that
starts with v is refused — there is no fallback, because a release named
0.0.0-dev would be worse than no release:
configure: error: tag 'v1.2' is not vMAJOR.MINOR.PATCH (optionally -rc1 / +build).
Releases take their version from the tag and there is no fallback that would not be a lie.
Delete the tag and re-tag: git tag -d v1.2 && git push origin :refs/tags/v1.2A hyphen in the tag marks the GitHub release as a pre-release: v1.2.0-rc1,
v1.2.0-beta.2. It is built and published like any other tag, and it is labelled so
nobody watching the repository mistakes a candidate for the real thing.
rmp deploy 1.2.0-rc1A + suffix is build metadata, not a pre-release: v1.2.0+7 is published
as a normal release.
Google Play orders the builds of an app by an integer, the version code, and refuses an upload whose code is not higher than the last one it accepted. The framework packs the three numbers of the tag into that integer so that it rises whenever the version does:
versionCode = MAJOR * 1000000 + MINOR * 1000 + PATCHThat only works while MINOR and PATCH fit in three digits, so a tag
with either of them at 1000 or above is refused:
minor and patch must each stay below 1000 so the Android versionCode stays monotonic.
And Play refuses any code above 2100000000, so MAJOR stops at 2099:
major must stay at or below …. The highest version that fits is
v2099.999.999, code 2099999999.
Two things the arithmetic does not do for you:
v1.0.0 after v2.0.0 and the build gets a lower code than the one
Play already has, and Play refuses it.v1.2.3-rc1 and
v1.2.3 are both 1002003. Nothing uploads to Play automatically, so this
costs nothing until you hand Play both: upload one of them, never the two.Each check catches a mistake that would otherwise surface on CI, and finding it twenty minutes
into a run, on a tag that is already public, is the expensive way. They run in this order, and
the first that fails stops rmp deploy before it tags anything:
Nothing uncommitted. CI builds the commit, so a change that is only in your working tree would not be in the release. Staged or not, a change to a tracked file stops it (files git does not track are not part of any commit, and do not count): FAIL: uncommitted changes. Commit or stash them first.
The tag is new here. FAIL: the tag v1.2.0 already exists here.
The tag is new on origin. A version that has been pushed once
is not cut again: FAIL: v1.2.0 is already on the remote. Releases are not re-cut; bump the
version. When origin cannot be asked at all — no remote, no network — that
stops it too, with what git said.
Your branch is on origin. CI checks the tag out from GitHub,
so a tag on a commit that exists only on your machine builds nothing:
FAIL: origin/main does not exist. Push the branch first:, followed by
rmp push.
The
first rmp push of a branch with no upstream is git push -u origin
<branch>, which pushes it and ties it to origin; with no remote at all,
it stops and says how to add one.
The commit is the one origin has. HEAD must be
exactly what origin/<branch> points at, as of your last fetch:
FAIL: HEAD is not what origin/main points at (as of your last fetch). It suggests
rmp push, which pushes unless gh reports a CI run in flight.
The configuration, the way CI will read it. tools/configure.py
runs with the tag set the way CI sets it, so the whole .toml is validated, the tag is
parsed into a version name and code, and — in a game, not in the framework's own repository —
the ids are checked for placeholders. That last check is what stops a first release from going
out under com.example.:
== checking v1.2.0 the way CI will ==
configure: error: refusing to build a release with placeholder identifiers:
[android] application_id is still the example value 'com.example.my_game'
[ios] bundle_id is still the example value 'com.example.my-game'
A Google Play application id is PERMANENT: once published you can never change it.
Set real values in raylib_multiplatform.toml before tagging.An id is checked only when its platform is a target: with ios switched off in
[targets], the iOS bundle id is not looked at.
Tag and push. git tag -a v1.2.0 -m "Release v1.2.0", then
git push origin v1.2.0.
Every refusal exits with status 1, and leaves no tag behind.
Tagging with git directly skips the checks on your machine, not the ones on CI. In a game, the
first job of a tag run validates the configuration with the same placeholder check, and stops the
run if it fails. A tag that is not vMAJOR.MINOR.PATCH fails every job that builds,
at the step that generates its build files. Either way nothing is published, and the tag is left on GitHub to be
deleted — see Undoing a tag.
Only tags that start with v start a release run at all.
A tag runs the full matrix: every target [targets] enables, each built, checked and,
where CI can, booted (Continuous integration says what each one
gets). A push to the branch while a tag run is going does not cancel it: superseded branch runs
are cancelled, tag runs never are.
Then a release job collects what every target uploaded and publishes it. It runs
only when:
lint job passed — in a game, that is the workflows, the configuration, the
pinned versions, the licences and a frame drawn in software;[targets] is skipped, and a skipped one does not hold the release back — otherwise
turning a platform off would turn releases off with it.In the framework's own repository the release also waits for the jobs only it has: its
examples, the game it makes with rmp new, and this documentation, checked against the
commit being released.
When the release is published, the itch.io job pushes the builds to itch.io, if it is configured. Firebase Test Lab, if configured, runs alongside and does not hold the release back.
The release is named after the tag, its notes are generated by GitHub from what changed since the previous one, and these are its files. A target your game does not build has no file:
| File | What it is |
|---|---|
linux-x64-glibc-build.ziplinux-arm64-glibc-build.ziplinux-riscv64-glibc-build.ziplinux-x64-musl-build.ziplinux-x64-glibc-drm-build.ziplinux-arm64-glibc-drm-build.zip | Linux: the executable, its assets and LICENSES.txt. Desktop and BSD archives |
windows-x64-build.zipwindows-arm64-build.zip | Windows: the .exe, its assets and LICENSES.txt. |
macos-build.zip | macOS: one universal executable for Apple silicon and Intel, its assets and LICENSES.txt. |
bsd-freebsd-x86-64-build.zipbsd-freebsd-arm64-build.zipbsd-openbsd-x86-64-build.zipbsd-openbsd-arm64-build.zipbsd-netbsd-x86-64-build.zip | FreeBSD, OpenBSD and NetBSD, built in their own virtual machines. |
web-build.zip | The browser build. The web build |
the debug .apk | The Android debug build: installable on a phone, not what Play takes. It shows Google's test ads, whatever ids the .toml carries. |
the release .aab | The App Bundle signed with your upload key. Only there when the Android signing secrets are set. Google Play |
ios-raylib-xcframework.zip | The iOS engine, raylib.xcframework, for device and simulator. |
ios-app-simulator.zip | The game built for the iOS simulator: unsigned, and not installable on a device. The App Store |
THIRD_PARTY_LICENSES.md | Every vendored component, its licence, and whether the copy is modified. |
SHA256SUMS | The SHA-256 of every zip, APK and AAB above. |
One file never reaches a release: the App Bundle CI signs with a throwaway key when your
signing secrets are not set. It is uploaded to the run under its own artifact name,
android-unsigned-aab, with -NOT-FOR-PLAY in its file name. The release
job downloads every artifact of the run, that one included, and then leaves it out by name: it is
not in SHA256SUMS and not in the list of files the release attaches — so a bundle
Play would accept is the only kind a release can carry.
SHA256SUMS lists every archive by its file name, as the release has it. With the
files downloaded next to it:
sha256sum -c SHA256SUMS # every file it lists
sha256sum -c --ignore-missing SHA256SUMS # only the ones you downloadedEvery desktop and BSD archive carries LICENSES.txt beside the executable,
web-build.zip beside the page, the APK and the App Bundle among their assets, and the
iOS app in its bundle. Each is generated from the components block of
THIRD_PARTY_LICENSES.md for what that build contains: the full notice of every
component in it, with a line saying which copies are modified. So the web's notice names none of the
desktop-only pieces — GLFW, RGFW, glad, the Windows shims — that a .wasm does not
contain, and only the Android one credits raymob. It is the only third-party notice the game
ships, so turning it off needs a reason on record — where the credits are instead:
[deploy]
licenses = false raylib_multiplatform.toml:2: licenses = false
^^^^^^^^^^^^^^^^
configure: error: [deploy] licenses = false removes LICENSES.txt from every package, and it is the only third-party notice the game ships.
Say where the credits are instead: credits_note = "the Credits scene, from the main menu". If there is no such scene, leave licenses = true.[deploy]
licenses = false
credits_note = "the Credits scene, from the main menu"Before CI has published anything — the run is still going, or it failed — the
tag can simply go, from GitHub and from your machine. It is what rmp deploy prints
when it pushes:
git push --delete origin v1.2.0 && git tag -d v1.2.0Deleting the tag does not stop a run that has already started, so cancel the run as well,
from its page or with gh run cancel.
After the release is published, deleting the tag leaves the release where it is. Delete both at once:
gh release delete v1.2.0 --cleanup-tagThen cut the next version rather than the same one again. rmp deploy refuses a
version that is still on origin, and anything you already uploaded to Google Play has
spent its version code for good.
A tag run that went red for a reason that was not yours — a BSD package mirror having a bad day is the usual one — does not need a new tag. Re-run the failed jobs of that run; the release job, which was skipped, is evaluated again with them:
gh run rerun <run-id> --failedhttps://omardev29.github.io/rmp-docs/publishing/desktop.html
Every desktop and BSD target ships as a zip: the executable, its assets and the licence notice, nothing to install. CI makes one per target on a tag and attaches it to the release; every run that builds a target uploads the same zip as an artifact of the run.
Unpacked, an archive is a folder like this, with your [project] name as the
executable's name:
my_game my_game.exe on Windows
LICENSES.txt the notices of everything the game is built on
resources/
resources.rres every asset, in one encrypted pack| Archive | Executable | Assets |
|---|---|---|
linux-x64-glibc-build.zip | x86-64 ELF | the pack |
linux-arm64-glibc-build.zip | aarch64 ELF | the pack |
linux-riscv64-glibc-build.zip | RISC-V ELF | loose files |
linux-x64-musl-build.zip | x86-64 ELF, linked against musl | loose files |
linux-x64-glibc-drm-build.zip | x86-64 ELF, DRM/KMS | the pack |
linux-arm64-glibc-drm-build.zip | aarch64 ELF, DRM/KMS | the pack |
windows-x64-build.zip | x86-64 .exe | the pack |
windows-arm64-build.zip | ARM64 .exe | loose files |
macos-build.zip | universal Mach-O: arm64 and x86_64 in one file | the pack |
bsd-<os>-<arch>-build.zip | FreeBSD, OpenBSD or NetBSD ELF | the pack |
resources.rres is your resources/ folder packed into one file and
encrypted with [resources] rres_password. The password ends up inside the executable,
so this keeps casual hands off your art and nothing more; rmp new gives every game a
password of its own. The game reads the pack when there is one and the loose files when there is
not, so both shapes run the same game. rmp pack makes the same pack locally, and
rmp unpack deletes it.
Three archives carry the loose files instead, with a PACK_SKIPPED.txt in
resources/ that says why. The packer is built the way the game is, and for these
three it comes out as a program the machine making the archive cannot run.
linux-riscv64-glibc and windows-arm64 are built for another processor
than the one that builds them, so the packer is a program for that processor.
linux-x64-musl
is built for the same processor, but its packer is linked against musl, and the glibc build image
that makes the archive has no musl to run it with.
A game written in plain C, without the framework's src/rmp/ — the way out
examples/plain_c shows — gets the loose files and a PACK_SKIPPED.txt in
every archive: raw raylib cannot read the pack, and nothing of the framework's is there to read it
for the game. tools/ship_resources.sh makes that choice for the packaging steps of
linux-x64-glibc, linux-arm64-glibc, both DRM targets, macOS and the
BSDs, and the windows-x64 step makes the same one in PowerShell. The three archives
above never call it: they always carry the loose files, and their note gives the reason of the
paragraph above.
A release build reads ./resources/, and . is the folder the game
was started from — a file manager, a shortcut and a launcher each start it somewhere else. So
before it opens the pack or loads anything, a desktop release moves into the folder that holds the
executable, when that folder has a resources/ beside it, and says so in the log. It is
a change of directory rather than a different path, so a plain raylib call with a relative path
under resources/ finds its file too. The iOS app does the same with its bundle. A
release with no resources/ next to the executable — built in the project and started
from the project's root — keeps reading the working directory's.
A
game in plain C has no entry point of the framework's to do this, so its own main()
makes the same move under the same condition, as examples/plain_c shows.
NetBSD and OpenBSD are the exception: raylib cannot ask either system where an executable is,
so there the game reads resources/ from the working directory and logs
ASSETS: this system does not say where the executable is, so … is read from the working
directory, …. On those two, whatever launches the game has to start it in its own
folder.
On every desktop target it runs but NetBSD and OpenBSD, CI starts a release from somewhere
other than its folder. tools/shipped_check.sh, on macOS and on the BSDs, builds a
software-rendered release and starts it twice. First where it was built, from the project folder:
with no resources/ next to it, it has to stay where it was started and read the
root's. Then laid out the way the archive ships it, from another folder; on NetBSD and OpenBSD it
starts that one from its own folder and requires the log line above instead. The Linux x64 and ARM64 jobs unzip the archive
they ship and start it from another folder, the Windows job starts the .exe from one,
and the musl and DRM runs start it from /.
A
game reads files a player can change — its saves, its assets — and a memory mistake that a
debug build's sanitizers did not meet is
still in the release. So a release is compiled and linked with what makes such a mistake harder to
turn into anything worse, and each flag is checked against the toolchain first: one it does not
take is left out, never a broken build, and the configure log lists what was applied, after
=== RELEASE HARDENING:.
-fstack-protector-strong, and the cheap bounds checks of the C++ library, libstdc++'s
and libc++'s._FORTIFY_SOURCE where the C library is glibc. And the
executable is position-independent, so that ASLR moves it too and not only the libraries around
it.lld-link, whose defaults give the last three too. MinGW is asked for the last three,
which its linker gives by default anyway, and not for the stack protector, which there can mean
shipping a DLL beside the game._FORTIFY_SOURCE by itself. The web
has no stack to execute and no loader to move.Each
one was measured on linux-x64-glibc before it went in, and they cost about 2% of the
binary together. Position independence costs 5.5% more, mostly in the relocations the loader has to
apply, and is on all the same: without it the executable sits at the same address on every run.
-DRMP_RELEASE_PIE=OFF exists to measure that, not to ship. Every Linux job then reads
what the linker made of it off the binary, with tools/binary_check.py elf, and fails
on a release that lacks any of it:
python3 tools/binary_check.py elf --pie build/release/my_gamermp::save writes into one of two places, chosen by
[save] portable:
portable | Saves go to | Wanted by |
|---|---|---|
false (the default) | %APPDATA%\my_game on Windows,
~/Library/Application Support/my_game on macOS, ~/.local/share/my_game
on Linux and the BSDs — or $XDG_DATA_HOME/my_game when that variable holds an
absolute path | installers, and Steam's cloud saves |
true | a saves/ folder next to the executable | a zip the player unpacks and runs — itch.io's downloads: deleting the folder deletes the game, saves included |
[save]
portable = trueOnly Windows, Linux and FreeBSD have a folder next to the executable to use. macOS ignores
portable. NetBSD and OpenBSD cannot say where the executable is, so there a portable
build logs SAVE: [save] portable: this system does not say where the executable is; saving
in the user's folder instead and saves in the player's folder, as if portable
were false. When the folder next to the executable cannot be written — a portable build copied somewhere
read-only — the saves go to the player's folder instead and the log says so once, and a read
looks in both and takes the newer save, so nothing is lost in silence.
The Linux archives answer three questions a player's machine answers differently: which processor, which C library, and whether there is a desktop at all.
linux-x64-glibc and linux-arm64-glibc: the ordinary desktop build,
for every distribution built on glibc.linux-riscv64-glibc: the same for RISC-V.linux-x64-musl: for Alpine and the other musl distributions. musl and glibc are
two C libraries, not two versions of one: a glibc binary does not start on Alpine, and this one
does not start on Debian. It is linked dynamically, so that GLFW can open the system's X11 and GL
libraries when it starts.linux-x64-glibc-drm and linux-arm64-glibc-drm: DRM/KMS. The game
draws straight to the screen through the kernel, with no X11 and no Wayland — a Raspberry Pi, a
cabinet, a kiosk, a bare console. It links libdrm, libgbm,
libEGL and libGLESv2 from the system. Leave both out with
disabled = ["drm"].The desktop builds need nothing installed on the player's side but a desktop: GLFW opens
libX11 and libGL with dlopen when the game starts, so neither is a link-time
dependency. Release binaries are stripped of their debug symbols as they are linked, and the
x64 job fails if one still carries them.
A Linux binary records, for every symbol it imports, the glibc version that symbol came from,
and the loader refuses to start it on a system with an older glibc. CI builds on Ubuntu 24.04,
whose glibc is newer than Debian 12's, Ubuntu 22.04's or the Steam runtime's, and a binary
linked the ordinary way there would stop at version GLIBC_2.39 not found on all of
them.
[linux] glibc is the oldest glibc the shipped binary may ask for:
[linux]
glibc = "2.31"The default is "2.28": RHEL 8, Debian 10, and with room to spare Steam's
sniper runtime. With a floor set, tools/linux_build.sh compiles with
zig cc against that glibc's symbols, and tools/glibc_check.sh reads every
versioned symbol out of the finished binary and fails the build if one is newer than the floor —
naming the symbols. The game's own code is the same either way; this is a compatibility setting,
not a behaviour change. "" builds against whatever the build machine has, which is
right for a local build and wrong for a release. A version outside 2.17–2.99 is refused:
[linux]
glibc = "2.16" raylib_multiplatform.toml:2: glibc = "2.16"
^^^^^^^^^^^^^^
configure: error: [linux] glibc = '2.16' is not a version this can target.
Use 2.17 to 2.99, or "" to build against the host's glibc and target nothing in particular.
2.17 is RHEL 7, 2.28 is RHEL 8 and Debian 10, 2.31 is Ubuntu 20.04, Debian 11 and Steam's sniper runtime.The floor applies to linux-x64-glibc and linux-arm64-glibc, which are
built that way and checked. The rest are built differently:
libdrm, libgbm and
libEGL directly, and those were built against the build machine's glibc, so its floor
is the build machine's. Its job prints the floor the binary really has, on every run.linux-riscv64-glibc is built with the cross compiler in CI's
image against that image's own riscv64 glibc, Ubuntu 24.04's, so [linux] glibc does
not reach it. It needs glibc 2.38 or newer: Ubuntu 24.04, Debian 13 and Fedora 39 have
it, Debian 12 and Ubuntu 22.04 do not. Its job holds it to that floor of its own and fails
if the binary ever asks for more, naming the symbols that do.linux-x64-musl has no glibc to ask for.windows-x64 and windows-arm64: the first built with the Windows
runner's MinGW GCC, the second compiled with MSVC for ARM64 on an x64 machine. A release build opens
no console window behind the game.
.exe — MinGW with -static, MSVC with the
static C runtime — and the zip carries no DLL. Each Windows job reads the import tables of the
.exe it ships with tools/binary_check.py and fails on any DLL that is not
part of Windows 10, naming it and saying how to link it in instead. A libstdc++-6.dll
or a VCRUNTIME140.dll in that list is a game that starts on the machine that built it
and nowhere else..exe. tools/configure.py turns [icon] source into a
multi-resolution .ico that the build embeds, and making it needs Pillow: on your own
machine, a build without Pillow goes on without an icon and nothing fails over it. The Windows jobs
install Pillow at a version and with checksums pinned in thirdparty/FROZEN_VERSIONS.md,
fail when [icon] source exists and no icon resource came out of it, and check that the
.exe they ship carries the icon.[windows] backend is
"glfw" by default; "win32" and "rgfw" drop GLFW for a
smaller .exe and cover less — gamepads, several monitors, the clipboard..exe with Mesa's
software OpenGL placed beside it, since the runners have no GPU, and checks it draws. It starts it
with the compiler's folder, and every folder holding a MinGW runtime DLL, taken off
PATH: Windows looks for an imported DLL on PATH, so a runner with MinGW
there would start an .exe that no player's machine can. The three Mesa DLLs —
opengl32.dll, libgallium_wgl.dll and dxil.dll — are deleted
before packaging, and the packaging step fails if opengl32.dll or
libgallium_wgl.dll is in the zip: a copy shipped by mistake would force software
rendering on every player.macos-build.zip holds one executable with both an arm64 and an x86_64 slice, for
Apple silicon and Intel Macs, next to its resources/ folder. It is a plain executable,
not an .app bundle. CI checks both slices are in the file.
Like the Linux and BSD executables, it carries no icon:
[icon] source makes the app icon of Windows, Android and iOS only, because the
other targets ship a bare executable or a page, with no icon of their own to make from it.
It opens on macOS 10.15 on an Intel Mac and on macOS 11 on Apple silicon. Every slice of a Mach-O
records the oldest macOS it runs on, and a Mac older than that refuses to open it, with no message
that says why; left to itself the toolchain records the version of the SDK it built with, which is
the runner's own macOS. So CMakeLists.txt sets
CMAKE_OSX_DEPLOYMENT_TARGET to 10.15, the first macOS whose C++ library has the
std::filesystem that rmp::save uses, and the
arm64 slice starts at 11.0 even when the deployment target is lower, because that is the first
macOS that ran on Apple silicon. The macOS job reads the minimum out of each slice with
tools/binary_check.py macos and fails on one above those.
Nothing in the pipeline signs the Windows .exe or signs or notarises the macOS
executable, and the framework has no setting for either. What the framework does take into
account is what signing changes — it is the reason UPX is off for Windows by default, and
refused for macOS (below).
freebsd-x64, freebsd-arm64, openbsd-x64,
openbsd-arm64 and netbsd-x64 are each built inside a virtual machine of
that system, with its own compiler and its own packages. Their archives are named after the system
and the machine — bsd-freebsd-x86-64-build.zip,
bsd-openbsd-arm64-build.zip — and carry the pack like the others.
Some combinations are not built, each for a reason outside the framework: FreeBSD publishes no
RISC-V packages, the virtual machines CI builds in exist for neither OpenBSD nor NetBSD on RISC-V,
and NetBSD's ARM64 packages cannot be installed on its base system. RISC-V is covered by linux-riscv64-glibc.
The packages a BSD machine installs come from the systems' own mirrors, which change from day to day, and neither project offers a snapshot to pin to. These archives are on the GitHub release and not on itch.io, which has no BSD platform.
UPX
compresses an executable into one that unpacks itself in memory when it starts, at the cost of a
few milliseconds at every launch. On this framework's own game, built the way CI builds it, it
takes linux-x64-glibc from 1 234 656 bytes to 365 836, 70% smaller,
and linux-x64-glibc-drm, which links its graphics libraries instead of carrying them,
58%. [upx] says which targets get it:
[upx]
enabled = ["linux"]
disabled = ["linux-arm64-glibc-drm"]Groups expand and disabled is taken away afterwards, like [targets].
The groups here are all, linux, windows and
bsd, and all means every target that can be compressed — not every
target. The default is linux-x64-glibc, linux-arm64-glibc,
linux-x64-musl and linux-x64-glibc-drm.
To turn compression off, empty enabled.
Each target that cannot be compressed has its own reason, and naming one, in either list, is an error that says it, not a setting that quietly does nothing:
| Target | Why not |
|---|---|
macos, ios | the binary is code-signed; compressing it breaks the signature |
android | what ships is a .so inside an APK, which is already a zip — compressing it makes the APK bigger |
web | it is .wasm, and the browser fetches it gzipped anyway |
The refusal comes from tools/configure.py like every other mistake in the
.toml, at its line — on your machine, in rmp test config, long before a release would
package anything:
[upx]
enabled = ["macos"] raylib_multiplatform.toml:2: enabled = ["macos"]
^^^^^^^^^^^^^^^^^^^
configure: error: [upx] enabled: 'macos' cannot be compressed — the binary is code-signed; compressing it breaks the signature.
Remove it; there is no setting that makes it work.So does a name that is no target or group at all, and that message lists every name
[upx] knows:
[upx]
enabled = ["linux-x64"] raylib_multiplatform.toml:2: enabled = ["linux-x64"]
^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [upx] enabled: unknown target or group 'linux-x64'.
Known: all, bsd, freebsd-arm64, freebsd-x64, linux, linux-arm64-glibc, linux-arm64-glibc-drm, linux-riscv64-glibc, linux-x64-glibc, linux-x64-glibc-drm, linux-x64-musl, netbsd-x64, openbsd-arm64, openbsd-x64, windows, windows-arm64, windows-x64The trade-offs of the targets that can be compressed:
.exe that
has been UPX-packed is a shape Windows Defender associates with malware, and it gets quarantined
on some machines and not on others. If you sign your builds, turn it on.[upx] max_size_mb, 600 by default, is the
size above which a binary is shipped uncompressed with a line in the log, so a large game still
releases. Above 768 it is refused, and so is a value below 1, since that would skip everything —
emptying enabled says that better:[upx]
max_size_mb = 0 raylib_multiplatform.toml:2: max_size_mb = 0
^^^^^^^^^^^^^^^
configure: error: [upx] max_size_mb = 0 would skip every binary. To turn compression off, empty `enabled` instead — that says what you mean.UPX runs at its slowest and smallest setting, and every packed binary is verified with
upx -t before it goes into the zip. The version is pinned with a checksum in
thirdparty/FROZEN_VERSIONS.md.
The
default is exactly the targets whose packed binary CI starts. Each of those four jobs unzips the
archive it ships, compressed, starts what is in it and checks it draws:
linux-x64-glibc on every push, under a virtual X server; and on a full run
linux-arm64-glibc on a runner of its own architecture, linux-x64-musl on
Alpine under a virtual X server, and linux-x64-glibc-drm on a virtual DRM display. So
a compressed binary that does not launch is a red run.
linux-riscv64-glibc
is compressed only when you name it: no group and no default brings it in. UPX 5.2.0's RISC-V stub
dies with SIGTRAP on every Linux kernel before 6.3, which is what most RISC-V boards
ship. Its first act is memfd_create(MFD_EXEC), a flag those kernels refuse with
EINVAL; the x86-64 and ARM64 stubs try again without it, the RISC-V one does not. QEMU
runs on the host's newer kernel and never saw it; a RISC-V board with Linux 5.10 did. If your
players all run Linux 6.3 or later, name it in enabled for its 59%;
configure.py says so with a warning, and with [ci] riscv64 = "rise" the
board's job fails at its boot and the cross build ships the compressed archive. Every other target is started before
packaging compresses it, or as a separate software-rendered build, or not at all, so a binary
compressed there is checked by upx -t and never started. UPX supports those targets; turning it on for one ships a packed binary whose launch
nothing has seen.
https://omardev29.github.io/rmp-docs/publishing/web.html
The web build is the same game compiled to WebAssembly with Emscripten: four
static files that any web server can serve, and a browser plays. CI builds it on every push, opens
it in a headless browser and checks that the canvas shows the game; on a tag it goes into the
release as web-build.zip, and to itch.io as a game that plays in the page.
Locally, the web build needs the Emscripten SDK, activated in the shell you build from so that
EMSDK is set:
rmp web
python3 -m http.server 8000 --directory build/webThen open http://localhost:8000/my_game.html. Serve it: opening the file
straight from disk does not work, because the page fetches the other files. Without the SDK, rmp web stops at the start with
FAIL: the web build needs the emsdk: activate it first (source emsdk_env.sh, or
emsdk_env.ps1 on Windows), so that EMSDK is set.
rmp web is cmake --preset web and a build, with the output in
build/web/. The web preset is a release build, the same one CI makes.
| File | What it is |
|---|---|
my_game.html | The page: the canvas the game draws on, and the code that loads the rest. |
my_game.js | Emscripten's runtime and the glue between the browser and the game. |
my_game.wasm | The game itself — your code, the framework and raylib — compiled to WebAssembly. |
my_game.data | Your resources/ folder, packed for the browser and mounted at /resources/ before the game starts. |
web-build.zip holds these four and a LICENSES.txt of its own: the
notices of what the web build contains, which leaves out what only the desktop builds link — GLFW,
RGFW, glad, the Windows shims. The names come from [project] name; keep the files
together in one folder, since the page finds the others by name next to itself.
The .data file is whatever resources/ holds when you build, as it is:
the loose files, and also resources.rres if you have run rmp pack — in
which case everything is in it twice. rmp unpack before a web build keeps it to one
copy. CI builds the web from the loose files.
The files are static, so anything that serves files over HTTP hosts the game: a static site,
a bucket, a folder on a server you already have. CI itself serves them with Python's
http.server for its browser test. On itch.io the game plays in the page —
itch.io covers the upload.
What the browser changes, and what the framework does about it:
[window] fps and vsync do nothing on the
web, and the framework never calls SetTargetFPS() there.rmp::save writes to a folder kept in the browser's
IndexedDB, so a save survives a reload. The game starts only once that folder has been read
back, so its first scene finds the saves already there. The database is named after
[project] name, so games served from the same site keep their saves apart. Where the
browser has no IndexedDB or refuses it — a private window, storage switched off — the game still
runs, and its saves last as long as the tab.A WebAssembly module gets its memory when it starts. [web] memory is how much, in
megabytes:
[web]
memory = 256
grow = falseThe default, 64, is enough for menus and a handful of textures; a game that loads a tile atlas
and a few music tracks wants more. When it runs out, the tab dies with "Cannot enlarge memory
arrays" rather than a raylib error. grow = true lets the memory grow instead of
aborting, and costs a little speed on every access to the heap; a game that knows its ceiling is
better off raising memory and leaving grow off.
Below 16 nothing loads, and above 4096 is more than 32-bit WebAssembly can address at all, so both are refused:
[web]
memory = 8 raylib_multiplatform.toml:2: memory = 8
^^^^^^^^^^
configure: error: [web] memory = 8 has to be a whole number of megabytes between 16 and 4096. Below 16 nothing loads; above 4096 is past what a 32-bit wasm module can address at all.What the player downloads is mostly the .wasm and the .data. What
decides each:
-Oz), and unused functions are
dropped when it is linked..wasm.[raylib] disabled_modules takes
rmodels or raudio out of the build — the only two it accepts. On a desktop
the linker has removed most of what you do not call already; the web and Android are where it
shows..data, as they are in
resources/.[raylib]
disabled_modules = ["rmodels"]UPX is refused for the web, and the reason is the framework's: it is .wasm, and the
browser fetches it gzipped anyway.
Emscripten compiles the game either way. [web] backend chooses what raylib talks
to inside the browser:
"glfw", the default: raylib calls GLFW, which Emscripten provides in JavaScript.
The path raylib has shipped on the web for years."emscripten": raylib calls the browser through Emscripten's own API, with no
GLFW layer. One layer less; the keyboard mapping in raylib's code for it is still marked
unfinished, which is why it is not the default.Both are opened in a headless browser by the framework's own CI. RGFW, raylib's third web backend, needs ASYNCIFY, and is refused:
[web]
backend = "rgfw" raylib_multiplatform.toml:2: backend = "rgfw"
^^^^^^^^^^^^^^^^
configure: error: [web] backend = 'rgfw' cannot work here.
RGFW's web backend calls emscripten_sleep, which needs -sASYNCIFY. This framework deliberately has no ASYNCIFY: it hands the frame loop to emscripten_set_main_loop instead, and the measurement behind that decision is +26 % .wasm and +18 % download. Turning it on for one backend would put that cost on the build.
It BUILDS without it and then dies in the browser with "Please compile your program with async support" — which is how this was found: the boot test in .github/workflows/web-backends.yml opened it in Chromium.
Use one of emscripten, glfw.On every push — the web is in the fast lane — CI builds the game in its pinned image, checks
that the four files exist and are not empty, and then plays it: it serves the folder, opens the
page in headless Chromium, waits for the game to boot and draw, and takes a screenshot of the
canvas. The run fails when the game does not report a clean boot — the console has to say
RAY_TEST_BOOT_OK assets_failed=0, so an asset that is missing, or one that does not
decode, fails it — when a save written to IndexedDB does not read back, or when the share of the canvas that differs from its most common
colour is outside the range a real frame has — a blank canvas fails, and so does one that is all
noise. An error in the browser's console fails it too, unless it is one of the few messages a
headless browser prints on every clean run, and so does a file the page could not fetch. When the
frame is the wrong one, the screenshot is uploaded with the run as
web-canvas-capture, because a picture of the wrong frame says more than a ratio in a
log.
Chromium is the one Playwright pins, and Playwright is pinned by the framework's
package-lock.json.
https://omardev29.github.io/rmp-docs/publishing/itch.html
Once it is set up, every release tag puts your game on itch.io by itself: CI pushes each build itch.io can use to its own channel of your game's page with butler, itch.io's upload tool, and the web build plays in the page. It needs two names in the .toml and one secret on GitHub.
Make the game's page on itch.io, if it does not exist yet. Its address,
https://yourname.itch.io/your-game, holds the two names CI needs: your user name and
the game's slug.
Write them in the .toml. They are names, not secrets, so they live with the rest of the game:
[deploy.itch]
user = "yourname"
game = "your-game"Add the API key as a secret. Make a key on
itch.io's API keys page and store it in the
repository as BUTLER_API_KEY — under Settings → Secrets and variables →
Actions, or from a terminal:
gh secret set BUTLER_API_KEYRelease. The next tag publishes:
rmp deploy 1.0.0The two names go together. With one of them set and the other empty, CI would have no
user/game to push to and would skip the upload without anyone asking for that, so the
configuration refuses it:
[deploy.itch]
user = "yourname" raylib_multiplatform.toml:1: [deploy.itch]
^^^^^^^^^^^^^
configure: error: [deploy.itch] user and game go together, and game is empty.
The itch job needs both to build the target `user/game:channel`, so with one of them missing it skips and the release is never pushed.
Set game, or clear both to turn itch.io deployment off.Both may hold letters, digits, _ and -, and nothing else. Leave both
empty, as a new game has them, and itch.io is simply off: the job logs a warning and does
nothing, so a game that does not use itch.io never gets a red run over it.
The repository variables ITCH_USER and ITCH_GAME are read too, and
when set they win over the .toml. If a value in the .toml seems ignored, look there first.
A butler upload goes to a channel of the game, and itch.io works out the platform of a download from the channel's name, out of a fixed set it recognises. CI pushes these:
| Channel | What is pushed | itch.io sees |
|---|---|---|
linux-x64-glibc | the Linux x86-64 archive, unpacked | Linux |
linux-arm64-glibc | the Linux ARM64 archive, unpacked | Linux |
linux-riscv64-glibc | the Linux RISC-V archive, unpacked | a download with no platform: itch.io has no RISC-V |
windows-x64 | the Windows x86-64 archive, unpacked | Windows |
windows-arm64 | the Windows ARM64 archive, unpacked | Windows |
osx | the macOS archive, unpacked | macOS |
html5 | the web build, as a folder with index.html at its root | a game that plays in the browser |
android | the debug APK | Android |
The archives are unpacked before they are pushed, so the player gets a folder rather than a zip inside a zip, and butler can upload only what changed since the last version.
The web build is the one that is easy to get wrong by hand: itch.io plays an HTML5 game from an
index.html at the root of an uploaded folder, and a zip pushed as it is becomes a
file to download that nobody can play. So CI unpacks web-build.zip and copies
my_game.html to index.html before it pushes.
The Android channel gets the debug APK, the build CI makes on every run — Google Play is where the signed release bundle goes (Google Play). A debug build shows Google's test ads whatever ids the .toml carries, so a game with ads earns nothing from the APK players download here.
Some targets have no channel, on purpose, and stay on the GitHub release only:
linux-x64-musl: the same game as linux-x64-glibc for Alpine. A second
Linux x86-64 channel would show players two identical downloads, with no way on itch.io to say
which one is for them.linux-x64-glibc-drm and linux-arm64-glibc-drm: they boot straight
onto the screen with no desktop. Right for a kiosk or a Pi, wrong for a player who double-clicks
it inside a desktop session.ios: there is no way to install an iOS app from a downloaded file.Each push carries the tag as its version — v1.2.0, v and all — and
itch.io shows it on the page. The version also makes a push repeatable: running the same tag again
does not create a second build on itch.io.
This is the command each channel runs, with payload the unpacked build:
butler push payload yourname/your-game:html5 --userversion v1.2.0Only on a tag, and only after the GitHub release has been published: a tag whose build failed anywhere pushes nothing to itch.io either. Each channel is a job of its own, so one channel failing — an expired key, a network error — fails that job, visibly, and leaves the others to finish. A channel whose target you switched off finds no build to push and does nothing.
butler comes from CI's pinned image, at the version recorded in
thirdparty/FROZEN_VERSIONS.md and checked against its checksum when the image was
built. Nothing fetches it from the network while a release is being published.
A player who downloads from itch.io gets a folder, runs the game from it, and deletes the
folder when done. [save] portable = true keeps the saves inside that folder, so
deleting the game deletes them too:
[save]
portable = trueIt applies to the Windows and Linux builds; macOS, the web and Android keep their saves where those platforms keep them. Where the saves go has the folders.
https://omardev29.github.io/rmp-docs/publishing/google-play.html
Google Play takes a signed Android App Bundle — an .aab, not an APK,
and not the debug build. CI builds, signs and verifies one on every run. With your upload key in
four repository secrets, it signs with that key and a release tag attaches the bundle to the GitHub
release, ready to upload in the Play Console. Nothing is uploaded to Play for you.
Once an app is published on Google Play, its application id can never change: not renamed,
not moved. A different id is a different listing, without the installs and reviews of the old
one. It is [android] application_id:
[android]
application_id = "com.yourname.yourgame"Letters, digits and _, at least two parts separated by dots, each starting with
a letter; no -, which Apple's bundle ids allow and Android's do not, so the refusal
names the hyphen and writes the id the way Android takes it:
[android]
application_id = "com.yourname.your-game" raylib_multiplatform.toml:2: application_id = "com.yourname.your-game"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android] application_id = 'com.yourname.your-game' is not a valid Android application id.
It contains '-': an Android id takes letters, digits, '_' and '.', and nothing else.
A '-' is fine in an iOS bundle id and refused here: write 'com.yourname.your_game'.
It needs at least one dot and each segment must start with a letter, e.g. com.yourname.yourgame.rmp new writes com.example. followed by the game's name, and every com.example. id
is treated as a placeholder: rmp deploy refuses to tag a release under one, and so does
CI when a tag is pushed by hand —
refusing to build a release with placeholder identifiers. Only you know whether the
id you replace it with is one you want to live with.
Play needs the bundle signed with your upload key. You make it once, keep it, and hand it to CI as secrets.
Make an upload keystore, and keep it somewhere you will not lose it:
keytool -genkey -v -keystore upload.jks -keyalg RSA -keysize 2048 -validity 10000 -alias uploadTurn on Play App Signing in the Play Console, so Google can reset your upload key if you do lose it.
Add four repository secrets, with exactly these names, under Settings → Secrets and variables → Actions:
| Secret | Value |
|---|---|
ANDROID_KEYSTORE_BASE64 | the keystore file, base64-encoded on one line: base64 -w0 upload.jks |
ANDROID_KEYSTORE_PASSWORD | the keystore's password |
ANDROID_KEY_ALIAS | the key's alias — upload above |
ANDROID_KEY_PASSWORD | the key's password |
base64 -w0 upload.jks | gh secret set ANDROID_KEYSTORE_BASE64
gh secret set ANDROID_KEYSTORE_PASSWORD
gh secret set ANDROID_KEY_ALIAS
gh secret set ANDROID_KEY_PASSWORDOptionally, name the key. Set the repository variable
ANDROID_SIGNER_CN to the CN of your upload key's certificate. Without it, CI can only
check that the bundle is not signed with its throwaway key — which every wrong key passes too. With
it, CI checks the bundle is signed by that one.
The bundle is built and signed on every run, secrets or not — it is the one artifact you cannot afford to test for the first time on release day. What the secrets change is which key signs it:
| Signed with | Artifact of the run | On the release | |
|---|---|---|---|
| No signing secrets (the default) | a throwaway key made for that run | android-unsigned-aab, a file ending in -NOT-FOR-PLAY.aab | never |
ANDROID_KEYSTORE_BASE64 set | your upload key | android-release-aab | yes, on a tag |
Either way the bundle is then checked, not trusted: jarsigner -verify -strict has
to verify it, and the certificate that signed it is read back and compared — a run with your key
fails if the bundle carries the throwaway signature, if jarsigner reports errors in
the signer's certificate, or, with ANDROID_SIGNER_CN set, if the signer is anyone
else. A further step reads the compiler commands Gradle used for the bundle and fails unless the
game was compiled as a release.
The release build is minified, its unused resources removed, and it is not debuggable.
A release bundle can be built locally with Gradle. The signing configuration reads the key from the environment, never from a file in the repository:
python3 tools/configure.py
export ANDROID_KEYSTORE_FILE=/path/to/upload.jks
export ANDROID_KEYSTORE_PASSWORD=...
export ANDROID_KEY_ALIAS=upload
export ANDROID_KEY_PASSWORD=...
cd raymob && ./gradlew bundleReleaseGradle writes the bundle into a build folder of its own,
raymob/app/build/outputs/bundle/release/. Without ANDROID_KEYSTORE_FILE it comes out unsigned, which
is fine for a look and refused by Play.
Gradle reads the game's identity from raymob/generated.properties, which only
tools/configure.py writes — rmp android and a CMake configure run it for
you. On a fresh clone, or after rmp clean, the file is not there and Gradle stops
before building, saying to run python3 tools/configure.py first.
It is not the bundle a tag builds. The version comes from the tag CI is building, and a local
build has none, so its version name is 0.0.0-dev and its version code
1: a bundle to look at, not one to upload. What goes to Play is the bundle of the
tag's run.
rmp android builds the debug APK, which is what you install on your own phone
with adb install -r.
Play orders the builds of an app by its version code, and refuses an upload whose code is not
higher than the last one it took — for good: a code once uploaded is spent. The code comes from
the tag, MAJOR * 1000000 + MINOR * 1000 + PATCH, so it rises with every version you
tag in order (Releases and
versions has the limits). A pre-release shares its version's code: v1.2.0-rc1 and
v1.2.0 are both 1002000, so upload one of them, not both. Builds that are
not tags have code 1 and are not for Play.
The framework uploads nothing to Play: the bundle is on the GitHub release, and the Play Console is where it goes from there.
gh release download v1.2.0 --pattern '*.aab'Upload it to a track in the Play Console — an internal testing track first is the quick way to put a release on your own phones before anyone else gets it — and promote it from there.
[android] min_sdk, 24 by default
(Android 7.0), between 21 and 36.[android] gl_version is the OpenGL ES
version the game is compiled for and the one the manifest requires, so devices without it are not
offered the app. "ES20", the default and what rmp new writes, reaches
every device. "ES30" compiles raylib and the game for OpenGL ES 3.0, links
libGLESv3 and asks the device for a version-3 context: for a game that needs what
raylib's ES 3.0 path adds. "ES31" and "ES32" are refused: raylib has no
3.1 or 3.2 path, so they would compile for ES 3.0 all the same and only hide the game from more
devices. [android.features] keeps the app from devices in the same way, for a
gyroscope or an accelerometer the game cannot do without; false still declares the
sensor, as optional.[android.permissions] has internet and vibration, both off by
default; internet is turned on regardless when AdMob is in the build.[android] category, "game" by
default.Ads are off until the game turns them on: [android.admob] enabled is
false by default, and in the .toml rmp new writes. Its
rmp::ads calls, if it has any, compile and do nothing. On,
the Android build carries the Google Mobile Ads SDK, the AD_ID permission and the
INTERNET permission with it, and the duty to declare advertising-id collection in
Play's Data safety form:
[android.admob]
enabled = trueWith android switched off in [targets], none of that is built,
whatever enabled says.
The three ids, app_id, interstitial_id and
rewarded_id, are Google's official test ids until you replace them with your own,
which a game with ads does before it publishes. They go into the release build's manifest and SDK
as they are written, and the SDK stops an app at startup over an app id it cannot read, so while ads are on
each one has to have AdMob's shape — the app id ca-app-pub-, 16 digits,
~, 10 digits; a unit id the same with a /. An empty id, a malformed one,
or an app id and a unit id swapped is refused at its line:
[android.admob]
enabled = true
app_id = "ca-app-pub-3940256099942544/1033173712" raylib_multiplatform.toml:3: app_id = "ca-app-pub-3940256099942544/1033173712"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [android.admob] app_id = 'ca-app-pub-3940256099942544/1033173712' is not an AdMob app id.
An AdMob app id looks like ca-app-pub-<16 digits>~<10 digits> -- this one has a '/', which makes it an ad unit id.
Copy it from the AdMob console, or set [android.admob] enabled = false.The debug build never uses them. Whatever ids the .toml carries, the debug APK —
the one rmp android builds for your own phone, and the one Firebase Test Lab's robot
taps through — shows Google's test ads, because a tap on a real ad from either is invalid traffic,
which is how AdMob accounts get suspended. Only the release build, the App Bundle you upload to
Play, carries your ids.
Showing ads to players in the EEA or the UK requires a Google-certified consent platform, and the framework does not ship one: with ads on, that traffic is served badly or not at all until the game adds it.
CI never starts the Android build itself: an emulator inside a runner with no acceleration is
slow, and fails for reasons that have nothing to do with the game. Firebase Test Lab installs the
APK on one of Google's devices — by default MediumPhone.arm, one of Test Lab's Arm virtual devices (an emulator Google runs, with the GPU accelerated), or the physical model [deploy.firebase] device names — lets its robot explore the game for up to five minutes, and
reports whether it started and kept running.
It is optional, and off until it is configured:
[deploy.firebase]
project_id = "your-gcp-project"
device = "model=MediumPhone.arm,version=33,locale=en,orientation=portrait"project_id is a Google Cloud project id — lowercase letters, digits and hyphens —
and empty means off. device is the device to run on, in gcloud's
notation; the line above is the default. Google retires device models every few years, so check
that the one you name still exists with
gcloud firebase test android models list.
[deploy.firebase]
project_id = "My Game" raylib_multiplatform.toml:2: project_id = "My Game"
^^^^^^^^^^^^^^^^^^^^^^
configure: error: [deploy.firebase] project_id = 'My Game' must be a GCP project id (lowercase, digits, hyphens), or "" to leave it unset.Setting it up, once:
gcloud services enable testing.googleapis.com toolresults.googleapis.com.roles/cloudtesting.testAdmin and
roles/cloudtoolresults.testAdmin.GCP_SA_KEY.FIREBASE_RESULTS_BUCKET to a Cloud
Storage bucket, and give the service account roles/storage.objectAdmin on it: the
results are written there and fetched back into the run.The repository variables FIREBASE_PROJECT and FIREBASE_DEVICE are read
too, and when set they win over the .toml.
Test Lab runs on full runs only — a tag, or a run started by hand with full —
after the Android build. It sends the debug APK and refuses anything else,
because the robot taps whatever it finds, ads included, and only the debug build is safe to tap:
whatever ids the .toml carries, it shows Google's test ads, so the robot's taps never reach your
real ad units, where AdMob would count them as invalid traffic. The results are kept with the run
for seven days as firebase-testlab-results. A failure there fails its own job and does
not hold back the release.
There is no iOS equivalent here: Test Lab needs a signed .ipa for iOS, and that
needs an Apple developer account.
https://omardev29.github.io/rmp-docs/publishing/app-store.html
CI builds the iOS engine and a simulator build of your game, and checks the app it made. It does not archive, sign or upload anything to Apple, and that is deliberate: an app a phone will install has to be signed, and signing needs an Apple developer account and credentials that do not belong in CI. The step from a working build to TestFlight and the App Store is made in Xcode, on a Mac, from a project the framework generates.
iOS is in the full matrix: it builds on a tag, and on a run started with full, on
a macOS runner with its Xcode version pinned. The job:
raylib.xcframework, for devices and for the simulator, from the raylib-iOS
fork pinned as the submodule thirdparty/raylib-ios — upstream raylib has no iOS
backend, and the fork draws through ANGLE, OpenGL ES on top of Metal;raylib_multiplatform.toml;Info.plist has a
readable bundle identifier, and your resources/ folder is inside the bundle.Two files go to the release from it: ios-raylib-xcframework.zip, the engine, and
ios-app-simulator.zip, the app. The app is a debug build for the simulator, unsigned;
it runs in the iOS Simulator and cannot be installed on a phone.
Starting the app in the simulator is part of the job and switched off: the simulator on the
pinned runner does not come up reliably, and a step that is known not to work is off rather than
allowed to fail quietly. Set the repository variable IOS_SIMULATOR_TEST to
true to try it; it then installs the app, runs it, and requires the same boot and
render markers as every other platform.
On a Mac with Xcode, from the release's ios-app-simulator.zip:
unzip ios-app-simulator.zip
xcrun simctl boot "iPhone 16"
open -a Simulator
xcrun simctl install booted my_game.app
xcrun simctl launch --console booted com.yourname.yourgameArchiving, signing, TestFlight and submitting to the App Store are not automated. Apple only installs a signed app on a device, and signing takes a paid Apple Developer account, a provisioning profile and a certificate. Those cannot live in a public repository, and the framework does not ask for them as secrets either: the release path that touches Apple's credentials runs in Xcode, on your Mac, under your account.
For the same reason the iOS app is never run on Firebase Test Lab: Test Lab needs a signed
.ipa for iOS.
On a Mac with Xcode and an Apple developer account, from your game's folder:
Fetch the fork. A game made with rmp new has the submodule
registered and not checked out, since only iOS needs it:
git submodule update --init thirdparty/raylib-iosBuild the engine, raylib.xcframework with its device and
simulator slices, the same way CI does. Once, and again only when the submodule moves:
(cd thirdparty/raylib-ios/projects/scripts && bash build-ios-xcframework.sh)Set your team in the .toml, rather than in Xcode, so it survives the next
time the project is generated. [ios.settings] is copied into the Xcode project as
build settings, word for word:
[ios.settings]
DEVELOPMENT_TEAM = "ABCDE12345"
CODE_SIGN_STYLE = "Automatic"Generate the project and open it. tools/configure.py writes
ios/project.yml, and XcodeGen turns that into the Xcode project — CI uses the
XcodeGen version pinned in thirdparty/FROZEN_VERSIONS.md:
python3 tools/configure.py
cd ios && xcodegen generate
open my_game.xcodeprojRun it on your phone: select the device and press Run.
Archive it for TestFlight and the App Store from Xcode, with Product → Archive, and upload the archive from there.
The Xcode project is generated, so a change made to it by hand in Xcode is gone the next time
it is generated; whatever the project needs belongs in [ios],
[ios.settings] or the rest of the .toml.
| In the app | From |
|---|---|
| Bundle identifier | [ios] bundle_id. Like Android's id, a placeholder com.example. id is refused for a release. |
| Oldest iOS | [ios] deployment_target, "15.6" by default and no lower than 13.0: rmp::save uses std::filesystem, which Apple's C++ library has from iOS 13. |
| Version | The tag: v1.2.0 becomes the marketing version 1.2.0. The generator sets no build number; Xcode's CURRENT_PROJECT_VERSION can be given in [ios.settings] like any other build setting. |
| Name under the icon | [window] title. |
| Orientations | [window] orientation, the same setting Android reads. |
| Icon | [icon] source, as the app's icon set. |
| Launch screen | A plain one generated by Xcode. An app without a launch screen runs letterboxed at an old resolution, and App Review rejects it. |
| Full screen, no status bar, arm64 only | Fixed. |
| Assets | Your resources/ folder, copied into the bundle as a folder. The app changes into its bundle before it loads anything, so the same relative paths work as on a desktop. |
| Licence notices | LICENSES.txt at the root of the bundle, crediting the raylib-iOS fork and ANGLE too. Writing it needs the submodule checked out; without it, a configuration on your machine warns and writes no iOS notice, and the iOS job in CI refuses to go on. |
| Designated initialisers | Out of declaration order, an error, as in every other build: the project's OTHER_CPLUSPLUSFLAGS carry -Werror=reorder-init-list, since Clang only warns where GCC refuses. An OTHER_CPLUSPLUSFLAGS of your own in [ios.settings] is kept, after it. |
[ios]
deployment_target = "12.0" raylib_multiplatform.toml:2: deployment_target = "12.0"
^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [ios] deployment_target = '12.0' is below 13.0.
rmp::save uses std::filesystem, which Apple's C++ library only has from iOS 13. Use 13.0 or later; the default, 15.6, covers every iPhone Apple still updates.The game cannot quit itself. Apple's guidance is that an iOS app that
terminates itself appears to the player to have crashed, and App Review rejects that.
rmp::app::quit() logs a warning and does nothing on
iOS, so the same source ships everywhere and a Quit button is simply inert on a phone. Hide it
there if a dead button bothers you:
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endifraylib is prebuilt. The app links the fork's
raylib.xcframework, so [raylib] disabled_modules changes nothing on
iOS.
No ads. rmp::ads does nothing on
iOS; ads are implemented for Android only.
The frame is paced by the display. [window] fps is ignored on
iOS.
Apple requires submissions to be built with a recent Xcode and SDK, and raises that bar about
once a year. Building with a newer Xcode means updating the raylib-iOS fork and the ANGLE it
bundles to one that supports it, and moving the Xcode pin in
thirdparty/FROZEN_VERSIONS.md, which is where CI reads the runner and the Xcode
version from.
https://omardev29.github.io/rmp-docs/publishing/ci.html
Every game made with rmp new carries the framework's CI, and it runs
as soon as the game's repository is on GitHub. A push builds the targets that catch most mistakes,
starts the game and looks at the pixels it draws, in about ten minutes; a tag builds every target
the game enables — all 17 of them unless it switches some off — and publishes the
release. Building is the easy half: the point of the
pipeline is that a game which compiles and draws nothing is a red run.
| Event | What runs |
|---|---|
A push to main, a pull request | The fast lane: linux-x64-glibc, web, windows-x64 and android, and the lint job. Nothing at all with [ci] on_push = false. |
A tag starting with v | The full matrix — every target [targets] enables — then the GitHub release, then itch.io. |
| Started by hand | The fast lane, or the full matrix with full, or exactly the groups and targets targets lists, separated by commas. |
A push or pull request that changes only Markdown files or LICENSE runs nothing.
A target switched off in [targets] is never built, on any event.
gh workflow run ci.yml -f full=true # every enabled target, without a tag
gh workflow run ci.yml -f targets=drm # one group or target, built in full
gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macostargets
narrows what the .toml enables and can never add to it. It takes one group or target, or several
separated by commas, and builds what they come to together, each in full. A name that does not
exist, one whose targets the .toml all switched off, one given twice and an empty one between two
commas each stop the run in its first job, saying which item it was: a run that asked for a
platform and quietly did not build it would be a green that proved nothing about it.
The last line above is how to check a fix for a red fast lane on just the platforms it involves, before the next push.
A third input, image_digest, builds with another build image than the pinned one, to try a new image
before committing to it.
A new push to a branch cancels that branch's run still in progress — a run of a commit nobody
wants any more is minutes wasted. A tag's run is never cancelled. To push without killing a run
you are waiting for, use rmp push: it asks gh for the CI runs that have
not finished, refuses while there is one and names it, and rmp push force pushes
anyway.
The check needs gh, installed and signed in. Without it, or when gh
cannot list the runs, rmp push says so in one line and pushes without checking — and
a run in flight is cancelled all the same.
Running on every push is what keeps a mistake from waiting for the release to be found, and
for a public repository it costs nothing. A private repository pays in
Actions
minutes, from a monthly allowance, and a fast lane on every commit can spend it. One line of
the .toml turns those runs off:
[ci]
on_push = falseThen a push to a branch starts no run, and neither does a pull request. A tag
v* still builds every target and releases — which is what rmp deploy
pushes — and gh workflow run ci.yml runs the fast lane whenever you want it, or the
full matrix with -f full=true. true, the default, is the table
above.
It
is applied by writing the workflow, not by a condition inside it. GitHub reads a workflow's
on: before any of its expressions runs, so a run that should not exist cannot skip
itself from the inside; it can only not be started. So tools/configure.py writes the
push and pull_request triggers of .github/workflows/ci.yml
from this line, on the next build, between two marker lines:
on:
# BEGIN generated by tools/configure.py from [ci] on_push: edit the .toml, not this block
# [ci] on_push = false: no run on a push to a branch, and none on a pull
# request. A tag v* still builds every target and releases, and
# `gh workflow run ci.yml` runs the fast lane by hand.
push:
tags: ['v*']
# END generated from [ci] on_push
workflow_dispatch:Nothing else in the file is generated, so a game that turns pushes off still has the
framework's ci.yml in every other line. Commit ci.yml with the
.toml: GitHub runs the workflow that is committed, not the one on your disk. A
ci.yml whose triggers say something else than the .toml is refused, at
the .toml's line, by rmp test config and by the first job of CI, which
only compares and never writes:
[ci] on_push = false, and the triggers in .github/workflows/ci.yml are not the ones it writes.
rmp push
knows: with on_push = false a push starts no run and so cancels none, and it pushes
without asking gh. Unless ci.yml has changes that are not committed yet —
the commit being pushed may still have the old triggers, and then it checks as it always does.
linux-riscv64-glibc can be built and started three ways, and one line of the
.toml picks. "cross", what rmp new writes, cross-compiles it on
GitHub's amd64 runners and starts its archive under QEMU. The other two build and start it natively,
on a real RISC-V board, and keep the cross build as their fallback: when the board fails or never
comes, the cross build runs and ships, and the run's summary says so.
| Value | The board | For |
|---|---|---|
"rise" | a RISE runner
(ubuntu-24.04-riscv), lent free by the RISE project | an open-source repository; the framework's own setting |
"cloud-v" | a Cloud-V
Milk-V Pioneer, 64 cores ([self-hosted, milkv-pioneer]) | a private repository — most games — which RISE's offer to open source does not cover |
"cross" | none: amd64 and QEMU | a repository with neither app, which is how every game starts |
[ci]
riscv64 = "rise"Both boards run the same job, riscv64-native, which builds, packs and starts the game
inside the pinned raylib-build-riscv64 image, so the binary is the cross build's: one
size line, one glibc floor. Each provider needs its GitHub App installed on the repository first.
Without it, no board ever picks the job up, and it waits in GitHub's queue for a day before the
fallback runs, so a game stays on "cross" until an app is in. A board with no Docker
fails the job's first step, and the fallback ships. Anything but the three words is refused by
configure.py, at the line.
rmp
deploy asks whether the repository is public when the line says "rise": through
gh when it is installed and signed in, through GitHub's public API when it is not. A
private repository, or one it cannot tell, gets a warning that names "cloud-v", and the
tag is pushed all the same: the release ships, through the fallback if no board comes.
A target is booted when CI starts the game, lets it draw a bounded number of frames, and checks what it printed. It is checked statically when CI inspects the file it built without running it — its format, its architecture, what it links.
| Target | Lane | What CI does with it |
|---|---|---|
linux-x64-glibc | every push | Booted under a virtual X server. Then the archive it ships is unzipped and started from another folder: the binary a player gets, compressed when [upx] says so, has to find its resources/. Checked: x86-64 ELF, no debug sections, glibc no newer than [linux] glibc, linked hardened. |
linux-arm64-glibc | full | Booted under a virtual X server on an ARM64 runner, and its archive unzipped and started from another folder, as on x64. Checked: aarch64 ELF, the glibc floor, linked hardened. |
linux-riscv64-glibc | full | Cross-compiled; checked statically (RISC-V ELF), and held to a glibc floor of its own, 2.38, which the note on [linux] glibc in the .toml names because the setting does not reach this target. Checked as well: linked hardened. Built and started on a RISC-V board when [ci] riscv64 names one (below); otherwise, or when the board fails, the archive it ships is unzipped and started from another folder under QEMU, in the build image: the RISC-V binary and the RISC-V libraries it opens, emulated, drawing with Mesa's software OpenGL under a virtual X server. Not compressed unless named in [upx]: UPX's RISC-V stub dies on kernels before 6.3. |
linux-x64-musl | full | Checked: no glibc symbol in it, linked hardened, and what it asks the system for is musl and nothing else — musl's loader and musl's libc.so, read out of the binary. Then on Alpine, in an image of the framework's own pinned by digest, with the network off and started from /: a software-rendered release of the game is booted, and the binary the archive ships, compressed by default, is unzipped and started under a virtual X server. |
linux-x64-glibc-drm | full | The binary the archive ships, compressed by default, is unzipped and booted through DRM/KMS on a virtual display the kernel provides, started from /. Checked: it links libdrm and no X11 or Wayland, linked hardened; its real glibc floor is printed. Then, on the same display and in the build image, ./rmp run is started the way a Linux console starts it, with no display and XDG_SESSION_TYPE=tty: it has to choose DRM/KMS by itself, build build/debug-drm, check /dev before the game and boot it. |
linux-arm64-glibc-drm | full | Checked statically: aarch64, libdrm, no X11 or Wayland, linked hardened. Not run: a virtual display would not answer the question a Raspberry Pi's own display pipeline does. |
windows-x64 | every push | Checked: a PE whose imports are all part of Windows 10, carrying its icon when [icon] source exists. Booted on a real Windows runner, started from a folder that is not its own, with Mesa's software OpenGL next to the .exe and the compiler off PATH, with the player's data folder set to a path that is not ASCII and a save written there and read back. The three Mesa DLLs are deleted before packaging, and the zip is checked to carry neither opengl32.dll nor libgallium_wgl.dll. |
windows-arm64 | full | Cross-compiled; checked statically — an ARM64 PE, its imports all part of Windows 10, its icon — and never run. |
macos | full | Checked: a universal Mach-O with both slices, neither asking for a newer macOS than the deployment target — 10.15, and 11 for arm64. A software-rendered build of the game is booted on the runner, and a software-rendered release is started from the project folder where it was built and then, laid out as the archive ships it, from another folder. |
ios | full | Engine and simulator app built; the bundle checked for its identifier and its resources/. The simulator boot is off unless IOS_SIMULATOR_TEST is true. |
web | every push | Booted in headless Chromium: a screenshot of the canvas is measured, and a save is written to IndexedDB and read back. |
android | every push | Debug APK and signed App Bundle built, by Gradle working offline from the build image (below). Checked: the manifest and native library in the APK, the bundle's signature and signer, and that the bundle was compiled as a release. Not run, unless Firebase Test Lab is configured — then on Test Lab's device (by default MediumPhone.arm, an Arm virtual device), on full runs. |
freebsd-x64, freebsd-arm64, openbsd-x64, openbsd-arm64, netbsd-x64 | full | Built inside a virtual machine of each system. Checked: an ELF. A software-rendered build of the game is booted in the same machine, and a software-rendered release is started from the project folder where it was built and then, laid out as the archive ships it, from another folder. OpenBSD and NetBSD cannot say where an executable is, so there the shipped release is started from its own folder and has to log that it reads the working directory's resources/. |
Next to the platforms, the lint job runs on every push. In a game it checks the
workflows (actionlint, with shellcheck over every script in them), validates the configuration,
compares every pinned version across the files that state it, checks the
size budget when the game has one, checks every licence, runs the
game's own tests in tests/game/ — and says it skipped them when there are none — and
draws a frame with raylib's software renderer, in a debug build that runs under whatever
[dev] sanitize lists. In the framework's own repository it also runs the
framework's tests and gates, and jobs of its own run clang-tidy over its code, build and boot
every example, play the examples that have a script,
measure
what the framework's tests reach, run the
deep tests' short runs, make a game with
rmp new to test it — and a copy of that game in plain C, made the way
examples/plain_c says, booted and its release started from the project folder and
from another — and check this documentation against the commit.
A
release of the framework waits for every one of those jobs; in a game they are skipped, and the
release does not wait for them.
Every booted target but the web runs with RAY_TEST_MAX_FRAMES set, which makes the
game draw that many frames and exit. The web test cannot set it: it opens the page with
?ray_test_save=1, which asks the game for the save round trip the other targets do
under that variable, lets it run for fifteen seconds, screenshots the canvas, and closes the
browser — the game itself never exits. The game prints markers. The boot marker is printed on
every launch that opens a window, a player's included; the
frame read-back and the frame count happen only under RAY_TEST_MAX_FRAMES, and in a
normal run, with the variable unset, they do not exist. Every booted target requires the first
marker with assets_failed=0 —
the Linux runs, musl and DRM among them, Windows, macOS, the BSDs, the web, and the iOS simulator
when it is on — and the runs on Linux, Windows, macOS and the BSDs require all three; the web test reads the
boot marker from the browser's console and measures the canvas itself:
RAY_TEST_BOOT_OK assets_failed=0RAY_TEST_RENDER_OKRAY_TEST_DONE_FRAMESA
crash on the way out — in the game's stop hook, or as the window closes — comes after every marker,
and only the exit code catches it. So does a leak, which LeakSanitizer reports as a sanitized debug
build exits. These runs read the exit code, and fail on anything but 0: the Linux x64 and ARM64
boots and their archives started from another folder, the RISC-V archive under QEMU, the Windows boot, both starts on Alpine, the
DRM boot, the software-rendered runs on macOS and the BSDs and in the lint job, the
release started from another folder on macOS and the BSDs, and rmp test smoke and
rmp test render. The software-rendered runs and the two rmp test stages
fail on a sanitizer's report as well. The iOS simulator's boot is the one that does not: the app
is launched in the background and its log read, so a crash after its last frame passes there.
The markers come from tests/smoke_test.h, which every game carries. The share of
pixels is the gate everywhere because GPUs and software renderers disagree on the details of a
frame; where the frame is drawn by raylib's own software renderer it is identical on every system,
and the framework's own CI compares it with a recorded hash as well. A game has no recorded frame,
so its software render checks the boot, the pixels and that every frame of the budget was
drawn.
windows-arm64 and linux-arm64-glibc-drm are never run, and
linux-riscv64-glibc runs on a RISC-V board only when [ci] riscv64 names
one and the board answers; otherwise only under an emulator, which is not a RISC-V machine.linux-x64-glibc,
linux-arm64-glibc, linux-x64-musl and linux-x64-glibc-drm,
whose jobs start the archive they ship — the four [upx] compresses by default. On a target added to [upx] enabled beyond
those, it is only verified with upx -t.A
release is kept as small as it can be, and without a number written down nothing would notice it
growing by a third between two releases. So every release job — Linux, Windows, macOS, the BSDs and
the web, and Android once per ABI of the bundle — runs tools/size_check.py on its
binary as soon as it is final, and holds it to its line in tools/size_budget.txt: the
size as the linker wrote it and, for a target [upx] compresses, the size of the copy
that ships. Within 1.5% of the line, either way, it passes and says nothing. Past that it passes
with a warning that names the new number, in the log and on the run's summary page, where a passing
job's log is never read. Past 10% it fails. Over is a growth nobody wrote down; under is a stale
line, which would let the next growth through without a word. Growing is allowed: the line is where
it is written down, in the commit that grows it.
# binary kind unpacked packed
linux-x64-glibc elf 1310720 389120 # measured at 1a2b3c4
windows-x64 pe 2293760 - # measured at 1a2b3c4That is how a game's budget reads. Each line is a binary, what kind of file it is, its size unpacked, and its size packed or
- where UPX does not apply, with the commit it was measured on. Every check prints the
line it measured in that same format, pass or fail, so one run's log is all an update needs:
gh run view 12345678 --log | python3 tools/size_check.py --update -A
game starts without a budget: rmp new does not copy the framework's, whose sizes are
its own demo game's. A game's release jobs measure all the same, print each line and say the game
has no budget, and the lint job says so too instead of failing. To start one, run the
full matrix once — a tag, or gh workflow run ci.yml -f full=true — then create an empty
tools/size_budget.txt, fill it from that run's log with the line above, and commit it.
From then on the game is held to it exactly as the framework is: the lint job checks the
file on every push — a line for every binary an enabled target ships, none for one nothing ships, a
packed size exactly where [upx] compresses — and every release job holds its binary to
its line.
A green run should mean the same thing in six months as today, so what a build depends on is pinned wherever it can be:
ghcr.io/omardev29/raylib-build, named by its
sha256 digest and never by a tag, which could be moved. The image carries the compilers
and tools those jobs use — CMake, Ninja, Emscripten, the Android SDK and NDK, zig, UPX, butler,
actionlint and shellcheck, LLVM 18 with the runtimes the sanitizers need, cppcheck, and the Python
test tools — so none of them is fetched while a job runs. It is built for x86-64 and ARM64, each on
a runner of its own architecture, and each is checked before the image is published. Its own
packages come from a dated Ubuntu snapshot, and the build jobs print the image's manifest as their
first step, so a log says which toolchain produced it.--offline from it: the job downloads nothing, and a library the image lacks fails the
build at once, by name. --offline does not reach the wrapper, so a step first checks,
by the wrapper's own rule, that the Gradle it asks for is in the image, and fails naming it when it
is not. A game that adds a Gradle dependency of its own sets
[android] gradle_offline = false:
Gradle then downloads what the image lacks, and the job says so in a warning. rmp
android on your machine is never offline.-latest, and on macOS an explicit Xcode version, with a step that fails and lists
what is installed when the pinned one is gone. A label fixes the operating system, not every tool
GitHub installs on it: the Windows jobs build with the compilers the runner image carries. The
windows-x64 job builds with whichever compiler CMake finds first on the runner's
PATH, and prints which one built the .exe; the
windows-arm64 job builds with the newest Visual Studio the runner has, and has no
such step.sha256; Pillow, which the
Windows jobs install to make the icon, comes from PyPI with pip --require-hashes, so
no other file is accepted. Chromium itself, for the web test, comes through Playwright, pinned
by package-lock.json.ghcr.io/omardev29/raylib-run-alpine, by digest: Alpine itself pinned by its digest,
with the virtual X server, Mesa and the X libraries an Alpine desktop gives the game, and checked
when it is built by drawing on it. The job downloads nothing into it, and every container it starts
runs with the network off. No workflow takes an image from Docker Hub.
Every container that starts a game, here and in the DRM job, has an
init as its first process, so that a game that hangs is ended by its step's timeout instead of
holding the job until the job's own limit: a program that is a container's first process ignores a
SIGTERM it has no handler for.The versions live in thirdparty/FROZEN_VERSIONS.md, the first job reads them from
there and hands them to the others, and tools/versions_check.sh — part of
rmp test config and of the lint job — fails if any two places disagree. A game keeps
the pins it was made with; they change when the game changes them.
The exception is the BSDs. Their virtual-machine images and package mirrors move from day to day, and neither offers a snapshot to pin to, so those jobs install whatever the mirror serves that day. When a BSD job fails after the rest of the run passed, and nothing you changed explains it, suspect the mirror first. The arm64 machines are emulated on an x86-64 runner, which makes their jobs the slowest of a full run, and each BSD job is allowed two hours.
Two other exceptions are narrow. The job that boots DRM installs the kernel's extra modules on its runner when the virtual display driver is missing from it, after the binary it tests has already been built: it is the one place a Linux job downloads.
And the web test installs the system libraries Chromium needs with
playwright install --with-deps, which takes them from the runner's Ubuntu package
mirror at whatever version it serves that day; nothing pins or checksums them. The game it tests is
built before, in the image.
Pinning stops the world from breaking a build, and it also stops anyone from noticing that the
world moved. The framework's own repository runs a canary every Monday: the same
workflows against the newest build image, the newest runner images, the newest Xcode and the newest
Mesa, to find what the next bump of the pins will break before anyone needs it. It runs only in
omardev29/raylib_multiplatform, and rmp new does not copy it into a game:
a game's CI never runs it.
The workflows read these from the repository's settings and from nowhere else. Every one is optional: without it, what needs it is skipped — the itch.io upload, the Test Lab run — or done another way — the App Bundle signed with a throwaway key — and the run stays green.
| Name | Kind | Read by |
|---|---|---|
ANDROID_KEYSTORE_BASE64, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS, ANDROID_KEY_PASSWORD | secrets | the Android job, to sign the App Bundle with your upload key |
ANDROID_SIGNER_CN | variable | the Android job, to check the bundle's signer by name |
BUTLER_API_KEY | secret | the itch.io job |
ITCH_USER, ITCH_GAME | variables | the itch.io job, ahead of [deploy.itch] |
GCP_SA_KEY | secret | the Firebase Test Lab job |
FIREBASE_PROJECT, FIREBASE_DEVICE | variables | the Firebase Test Lab job, ahead of [deploy.firebase] |
FIREBASE_RESULTS_BUCKET | variable | the Firebase Test Lab job, for where its results go |
IOS_SIMULATOR_TEST | variable | the iOS job: true turns the simulator boot on |
The release itself needs none: it publishes with the run's own token.
Open the run on GitHub, or follow it from a terminal with gh run watch, and start
from the first job that failed: everything after it may only be its consequence. The job's name
says which platform — linux / x64, windows / x64,
apple / macos, bsd / build (freebsd, …), web / boot-test,
android / build — and the failing step says which stage. Most checks that fail
print a line starting with FAIL that says what they found.
| Red | What it usually means | On your machine |
|---|---|---|
config | The .toml is invalid, a tag build found a placeholder com.example. id, or the triggers of ci.yml are not what [ci] on_push writes. | rmp test config; for the triggers, any build, then commit ci.yml |
lint | A workflow does not lint, two pinned versions disagree, the size budget lacks a line or has a wrong one, a licence is unknown, a test in tests/game/ failed, or the software-rendered frame failed. | rmp test config, python3 tools/size_check.py --check-file, rmp test unit, rmp test render |
| A step that configures or generates, on a tag | The tag is not vMAJOR.MINOR.PATCH. | rmp deploy checks it before tagging. |
| A build step | The code does not compile on that platform's compiler. | rmp build release |
| A runtime test | The game did not boot, lost an asset — missing, or there and not decodable — drew nothing, or died before the end of its frame budget — or, in the runs that read the exit code, exited with an error, or, in a sanitized debug build, a sanitizer reported something. The captured output, or the report, is printed above the verdict. | rmp test smoke, rmp test render |
| The archive starts from any folder, or the release starts from any folder | Started away from its folder, the release did not find the resources/ beside it; or, in the release starts from any folder, started first from the project folder where it was built, with no resources/ beside it, it did not read the project's. Either way an asset failed to load, and the line starting with FAIL says which start it was. | sh tools/shipped_check.sh Ninja "" my_game |
the .exe imports nothing Windows does not ship, in windows / x64 or windows / arm64 | The .exe needs a DLL a player's Windows does not have — a compiler runtime linked dynamically — or lacks the icon [icon] source promises. The step names the DLL and how to link it in. | python tools/binary_check.py windows build/release/my_game.exe |
every slice runs on the macOS the build declares, in apple / macos | A slice of the binary asks for a newer macOS than CMAKE_OSX_DEPLOYMENT_TARGET; the step names the slice and the version. | python3 tools/binary_check.py macos build/release/my_game --min-os 10.15 |
It runs on older distributions than this one, or in linux / riscv64 The glibc it needs, against the floor the .toml gives it | The Linux binary needs a newer glibc than [linux] glibc — or, for linux-riscv64-glibc, than 2.38; the step lists the symbols that ask for it. | tools/glibc_check.sh on the binary |
| Linked hardened, in a Linux job, or It needs nothing but musl | The release lacks something it is linked with: read-only relocations (RELRO), symbols bound at start (BIND_NOW), a stack that is not executable, or, with RMP_RELEASE_PIE on, position independence; or a musl binary asks for a loader or a library that is not musl's. The step says which, and the linker flag that gives it. | python3 tools/binary_check.py elf --pie build/release/my_game |
| Within its size budget | A binary is more than 10% away from its line in tools/size_budget.txt, either way, or its line is ?, a size nobody has measured. The step prints the line measured on this run, ready to paste. Between 1.5% and 10% it is a warning, and the job stays green. | The size budget |
| A BSD job, after everything else passed | Most often the package mirror. If the step The VM script reached its end failed, the build script stopped early without saying so. | sh tools/render_check.sh Ninja "" my_game runs its check anywhere |
Gradle, from the image, in android / build | The build image does not carry the Gradle the wrapper asks for, so an offline build would have to download it; or, in the build that follows, a library the app needs is not in the image's Gradle home, and Gradle names it. | A game that added a Gradle dependency of its own: [android] gradle_offline = false |
The AAB check in android / build | The bundle is signed by a key other than the one the secrets name, or its certificate has errors. | Google Play |
release skipped on a tag | A platform job or the lint job failed or was cancelled, so nothing was published. | Fix it and re-run the failed jobs. |
The runtime tests say which marker is missing. Locally, rmp test smoke builds the
game, boots it for a few frames and makes the same two checks:
rmp test smoke
rmp test renderand stops with FAIL: the game did not boot, or an asset failed to load or
FAIL: the game booted and drew nothing when one of them is not there.
rmp test render builds the game for raylib's software renderer, with no window and no
GPU, and runs exactly the check the macOS and BSD jobs run.
Some jobs leave something to look at: the web test uploads its screenshot of the canvas as
web-canvas-capture when the frame was wrong, and the Windows test tries Mesa's
llvmpipe, softpipe and d3d12 drivers in turn and says which
ones failed before it gives up. A yellow warning on the itch.io or Firebase job is not a failure:
it is the job saying what is not configured, and skipping.
https://omardev29.github.io/rmp-docs/framework/index.html
What the framework is made of, the order it does things in, and the reasons behind
the shape it has. You do not need any of this to make a game. It is here for when you want to know
why something works the way it does, or what exactly happens between your _update and
the picture on the screen.
Three things. The rmp library: one header per module under
include/rmp/ and their implementation under src/rmp/, compiled into
your game. One configuration file, raylib_multiplatform.toml, which
tools/configure.py turns into what CMake, Gradle and Xcode read, so they cannot
disagree with it. And a CI that builds the game for 17 targets, starts it, and
checks that it drew.
.toml becomes the input of every build system, why a mistake in it stops
in the first second with the line it is on, and what each generated file is for.rmp test runs in your game.The decisions behind the API, each with its reason and, where there is one, the tool that keeps it true. They start from the rule above the others: a main menu is three function calls, and nothing is allowed to make it longer.
{ .speed = 320 }, and why their order is fixed.delta, the clock, and [app] max_delta.Contributing is for whoever changes the framework itself, a person or an agent: setting up a machine and the build image, the repository and what a new game is copied from, the rules with their reasons, writing tests, the verification ladder, CI, pull requests and the approval a change to the API needs, and keeping this site true to the code.
Maintaining is for whoever keeps the framework building after it is written: the framework as a system of repositories, generators, toolchains and images; every dependency, where its version is held and every file that names it; the build image and how a new one is made; Python; a playbook for upgrading each dependency; the changes the stores and GitHub force every year; and what to archive so a desktop build still works in decades.
https://omardev29.github.io/rmp-docs/framework/architecture.html
A game made with this framework is five layers deep. At the top is the code you write; under it, the modules you choose to use; under those, a small core that runs the frame; under that, raylib; and at the bottom, the 17 targets the same source is built for. Each layer only reaches down, never up.
The rest of this page takes the layers one at a time, from the top.
What a game is made of is deliberately small. The entry point is one line, the screens are scenes, the things in them are objects, the art is in a folder, and every setting is in one file.
The whole of src/main.cpp, as the framework ships it and as
rmp new copies it into a new game:
// Your game starts here, and this is all of it.
//
// RMP_GAME opens the window from [window] in raylib_multiplatform.toml, enters
// the scene you name, runs it every frame, and shuts everything down on the way
// out — on every target, including the two where main() is not a main() at
// all. Your work is in src/scenes/ and src/objects/.
#include <rmp/app.h>
#include "scenes/main_menu.h"
RMP_GAME(MainMenuScene);
RMP_GAME opens the window from [window] in
raylib_multiplatform.toml, enters the scene you name, runs the scene stack every
frame and closes everything on the way out. There is no InitWindow() to write and no
loop: those lines were the same in every game, and on the web and on iOS the loop is not even
yours to write — the browser and UIKit own it.
The first scene is named in
code and not in the .toml on purpose. Choosing a scene by name means a table from
names to types, and in C++ that table is built by objects that register themselves when the
program starts. A linker building a static library or an iOS framework throws away any object
file nothing refers to, and a self-registering object is exactly that: the game would build, run
on a desktop and find no scenes on a phone. So the type is named where the compiler can see
it.
A scene is one screen — a menu, a level, a pause overlay — and an object is anything inside
one: the player, a bullet, a coin. Both are classes you derive from
rmp::Scene and
rmp::Object, one per file, under src/.
A game made by rmp new starts with one, src/scenes/main_menu.cpp.
Every build system
collects src/ recursively, so a new file or a new folder needs no change to CMake,
Gradle or Xcode.
The art, the sounds and the levels go in resources/ and are loaded by name:
rmp::assets::load_texture("player.png"). While you develop they are read from that
folder; a release packs them into one resources.rres file, optionally encrypted, and
the same call reads them from there (rmp pack
does the packing by hand).
Everything a build system needs to know about the game — its name, its window, its
identifiers on the stores, the targets it is built for — is in
raylib_multiplatform.toml. It is the only file of that kind you edit:
tools/configure.py turns it into what CMake, Gradle and Xcode read, so the three
cannot disagree with it. The config pipeline follows
it all the way through, and Configuration lists every
key.
Everything the framework adds to raylib is under rmp::, one header per module.
There is no header that includes them all: a file that draws the HUD includes
rmp/ui.h and knows nothing of saving or sound. Why it is split this way
has the reasons and the measurements.
| Header | What it gives you | Built on |
|---|---|---|
rmp/ui.h | rmp::ui: menus, buttons, layout, themes, in screen space | Clay, the layout engine |
rmp/input.h | rmp::input: named actions bound to keys, buttons and sticks, and the pointer | raylib's input, sampled once a frame |
rmp/assets.h | rmp::assets and rmp::Texture and its siblings: loading by name, released by themselves | rres for the pack, cute_aseprite for sprite sheets |
rmp/tilemap.h | rmp::Tilemap: a level made in LDtk or Tiled | cJSON for LDtk, cute_tiled for Tiled |
rmp/audio.h | rmp::audio: sounds and music by name, three volume buses | raylib's raudio |
rmp/save.h | rmp::save and rmp::Value: save slots in the platform's own folder | cJSON, and Monocypher to seal a file |
rmp/random.h | rmp::random: one seeded generator you can replay | xoshiro128++, written out |
rmp/ads.h | rmp::ads: interstitial and rewarded ads | raymob's AdMob bridge on Android, once [android.admob] enabled turns it on; nothing anywhere else |
rmp/math.h | arithmetic: +, - and * on raylib's own vectors, and raylib-cpp's math classes for those who want methods | raylib's raymath, and the math headers of raylib-cpp |
rmp/behavior.h | rmp::behavior: the catalogue — movement, health, timers, spawners | the core's behavior engine |
rmp/scene.h | rmp::Scene and rmp::Camera | the core |
rmp/object.h | rmp::Object, rmp::Handle, rmp::Callback | the core |
rmp/app.h | RMP_GAME, rmp::app::quit() and rmp::global | the core |
Opt-in means two things here, and it is worth being exact about both.
You include what you use. Each header is a module you can take or leave, and
none of them is an umbrella for the others. A few do bring another one with them, and say why at
the top: rmp/scene.h includes rmp/object.h and
rmp/tilemap.h, because a scene holds its map by value and spawns objects;
rmp/object.h includes rmp/assets.h, because a sprite holds a texture by
value. Every public header also includes rmp/config.h, the values from the
.toml, so you never type that one.
You pay for what you use. A camera and a map are fields of every scene: a map
nobody loads draws nothing and stops nothing, and a camera nobody touches shows the world at the
design resolution as it is. The UI starts Clay on the
first rmp::ui::begin() of the game, and the sound device opens on the first call
that needs it, so a game with no menus has no UI arena and a game with no sound never opens the
device.
None of it walls raylib off. An
rmp::Texture converts to the Texture2D it wraps, so every raylib
function that takes one takes it; a scene can open the camera and draw with raylib directly; and
a game in plain C can skip the framework altogether and still
be built for every target but the two where the loop is not the game's to write, the web and
iOS.
Under the modules is the part every game uses, whether it includes a module or not: the code that runs a frame. It is five pieces, and their order within one frame is the subject of One frame.
RMP_ENTRY_POINT writes the program's entry point
for the platform it is compiled for, because there are three shapes of one. On Windows, Linux,
macOS, the BSDs and Android it is a main() with a loop. On the web the browser owns
the loop and calls a function back once a frame, through
emscripten_set_main_loop(). On iOS UIKit owns it, and the program is three callbacks.
All three do the same things in the same order around your code, and
RMP_GAME is that macro with the three hooks written for
you.
A
vector of owning pointers, and a queue of the transitions asked for during the frame.
change,
push,
replace and
pop only record; the stack changes when the frame is
over, because the call usually comes from inside the scene that is about to go.
Every object of every
scene lives in one pool of slots. A slot owns its object through a
std::unique_ptr and carries a generation number. A
rmp::Handle is the slot's index and that generation, so
a handle to an object that died stays dead even when the slot holds something new. Destruction is
deferred to the end of the frame, which is what makes the reference
spawn() returns good for the rest of it.
Arcade collision, written
for the framework: rectangles and circles, a uniform grid so only near pairs are tested, a swept
test so a fast object cannot pass through a thin one between two frames, and separation for the
pairs that are both solid. A solid object that
is not immovable is stopped by the map's solid cells one axis at a time, so it runs along a floor of tiles
without catching on the seams. It is not a physics engine, by decision: a rigid-body library
would make position a mirror of somebody else's body, and a Pong ball would need a
density and a friction to bounce.
A
behavior is a struct with an _update(rmp::Object &, float), or a
_late_update with the same signature when its whole job is to correct where the
object ended up, as GridSnap does, and no
virtual functions, so that it stays an aggregate. The engine finds
its optional hooks at compile time with requires, keeps one table of function
pointers per type, and owns the struct through a std::shared_ptr<void> that
carries its destructor. A behavior of yours and one of the catalogue's are the same kind of
thing; there is no base class and nothing to register.
In
a CMake build — the desktops, the BSDs and the web — the framework is compiled once into a static
library called rmp, and the game and every example written in C++ link it. The one file kept out of
the library is src/rmp/app/app.cpp: each executable compiles its own copy, because it
refers to the symbol the entry-point macro defines, and that reference is what turns a program
with no RMP_GAME into a link error that names what is missing. The Android build
and the iOS project compile src/ as a whole into the app, framework and game
together.
The library is
built only when src/rmp/ has sources. A game in plain C deletes that folder because
nothing in it is used: a game with no C++ of its own in
src/, outside src/rmp/, is linked to raylib alone, so a
src/rmp/ left behind would be the whole framework compiled for nothing in a CMake
build, and compiled into the game on Android and iOS, which take everything under
src/. With it gone the build has no framework library at all — only raylib, the
game's own C, and the headers that are plain C.
Those
headers are on a plain C game's include path on every target: rmp/config.h for the
values of the .toml, tests/smoke_test.h for the CI's hooks, and
<admob.h> from thirdparty/raymob for the ads as C functions,
which do nothing anywhere but Android.
Under the core is raylib 6.2, vendored in
thirdparty/raylib. The copy is modified, and says so: the zlib licence requires an
altered copy to be plainly marked, and its
PATCHES.md lists every change. It is raylib 6.2 as raylib_cmake_template carries
it — with raylib's own fixes from after 6.2 and the gaps its security audit left closed — with the
framework's patches on top. Most of those are build-system and platform-selection patches, so the
windowing backend can be chosen from the .toml; one makes Android's EGL ask for the
OpenGL ES version raylib was compiled for, and the DRM backend's card probe, Escape on its terminal
and its flow control are fixed.
Among
the libraries raylib bundles, three files are changed: the software renderer's nearest-texel
lookup is clamped to the texture, a fix of the framework's own that upstream does not have, so the
far edge of a texture reads its last texel and not the one past it; the OBJ loader takes raylib's
face fix from after 6.2; and RGFW's gamepad code builds on older kernel headers.
Licences has the rest.
The
iOS app is the one target that does not build this copy. It links a
raylib.xcframework built from a fork, omardev29/raylib-iOS, pinned at
tag 6.0.3-iOS as the submodule thirdparty/raylib-ios, so the changes
PATCHES.md lists are what every other target runs, not what iOS runs.
raylib is built in modules, and the framework leans on most of them:
| Module | What it does | Can a game leave it out? |
|---|---|---|
rcore | the window, input, timing | No: raylib requires it |
rlgl | the OpenGL layer under every draw call | No: raylib requires it |
rshapes | rectangles, circles, lines | No: rmp::ui draws every panel and button with it |
rtextures | images and textures | No: the asset layer and the CI render check are built on it |
rtext | fonts and text | No: the rres loader calls into it |
raudio | sound and music | Yes |
rmodels | 3D models and meshes | Yes |
Leaving one
out is [raylib]
disabled_modules, and configure.py refuses the modules in the third column
that say no, with the reason, before anything compiles. The iOS build links a prebuilt raylib and
ignores the setting.
[raylib]
disabled_modules = ["rshapes"] raylib_multiplatform.toml:2: disabled_modules = ["rshapes"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [raylib] disabled_modules: 'rshapes' cannot be disabled — rmp::ui draws every panel, button and border with it — DrawRectangleRounded and three others — and the UI is always compiled in, so there is nothing left to link against.At the bottom are the platforms the same source is built for: 17 targets in 6 families. A family is the set of targets one CI workflow builds.
| Target | What it is | Family | Groups it is in |
|---|---|---|---|
linux-x64-glibc | Linux x86-64 | linux | all, desktop, linux |
linux-arm64-glibc | Linux ARM64 | linux | all, desktop, linux |
linux-riscv64-glibc | Linux RISC-V | linux | all, desktop, linux |
linux-x64-musl | Linux x86-64 (musl / Alpine) | linux | all, linux |
windows-x64 | Windows x86-64 | windows | all, desktop, windows |
windows-arm64 | Windows ARM64 | windows | all, desktop, windows |
macos | macOS (universal) | apple | all, apple, desktop |
ios | iOS (simulator) | apple | all, apple, mobile |
web | Web (WebAssembly) | web | all, web |
android | Android | android | all, android, mobile |
freebsd-x64 | FreeBSD x86-64 | bsd | all, bsd |
freebsd-arm64 | FreeBSD ARM64 | bsd | all, bsd |
openbsd-x64 | OpenBSD x86-64 | bsd | all, bsd |
openbsd-arm64 | OpenBSD ARM64 | bsd | all, bsd |
netbsd-x64 | NetBSD x86-64 | bsd | all, bsd |
linux-x64-glibc-drm | Linux DRM/KMS (no X11) | linux | all, drm, linux |
linux-arm64-glibc-drm | Linux ARM64 DRM/KMS (no X11) | linux | all, drm, linux |
A target's name is <os>-<arch>-<libc>-<env>, and each part is
there only when it can differ. linux-x64-glibc and linux-x64-musl name
their C library because a binary built for one does not start on a system with the other: musl and
glibc are two libraries, not two versions of one. The last part is the windowing system —
drm draws straight to the screen with no X11 and no Wayland — and is absent when the
binary carries every backend and picks one when it starts. windows-x64 and
macos stop early because Windows has one C library and the macOS build is
universal.
Each family has its own build system underneath, all of them fed from the same
.toml: CMake for the desktops, the BSDs and the web, Gradle for Android, and an
Xcode project generated by XcodeGen for iOS. A push to the framework builds Linux x64, the web,
Android and Windows x64; a release tag builds every target, boots the ones a runner can boot, and
checks that each one drew — Testing says how.
https://omardev29.github.io/rmp-docs/framework/the-frame.html
Sixty times a second, or as often as the screen asks, the framework samples the
input, moves the world, draws it and tidies up. The order those happen in is the contract every
hook you write relies on: when _update runs, what _collision sees, why a
scene you leave is still there until the frame ends. This page follows one frame from the top,
and every step is pinned to the line of the framework that does it.
Almost every rule on this page has the same reason behind it. A hook is your code, and your code is entitled to do anything — spawn, destroy, change scene, quit — from anywhere. The order is built so that none of those can pull the floor out from under something still running.
RMP_GAME is
RMP_ENTRY_POINT with its three hooks written for
you, and the entry point is the code that calls the frame. Where the loop lives depends on the
platform, and only there:
main() with a
while loop, the ordinary raylib shape. On Android raylib's own native glue calls that
main().main() hands one frame
function to emscripten_set_main_loop() and the browser calls it every animation
frame. A while loop there would need Emscripten's ASYNCIFY, which rewrites and slows
the whole program; this shape does not.All
three do the same four things each time around: ask whether the game is still running, sample the
input, hand the frame hook a delta, and finish the frame. On the desktop that is the
whole loop:
while (keep_running()) {
begin_frame();
FRAME(step_delta());
end_frame();
}A
game stops running for one of three reasons, checked in one place so the platforms cannot drift
apart: the window was closed, rmp::app::quit() was
called, or the CI frame budget is spent. quit() only raises a flag, so the frame that
asked to quit finishes normally and the game shuts down exactly as it does when the window is
closed. On the web and iOS there is no window to close and WindowShouldClose() is
never called.
The
delta every hook receives is raylib's GetFrameTime() with two corrections:
a negative reading, or one that is not a number, becomes 0, and a reading longer than
[app] max_delta — a
twentieth of a second unless you change it — is cut down to it. A frame that stalled for half a
second, because the window was dragged or the debugger stopped, becomes a moment of slow motion
instead of a jump that carries a bullet through a wall. That is the one place the framework reads
the clock, in src/rmp/app/clock.cpp, and the number it hands out is remembered for the
rest of the frame: the UI animates by it too.
Time is a parameter says why.
The
runner first asks whether anyone can see the window
(out of sight, below), and then samples every input device once,
before it calls the frame hook. The keyboard, the mouse —
which a touch screen drives too — and the first gamepad are read into one snapshot, and every
pressed and
just_pressed of the frame answers from it.
Two scenes asking about the same key in the same frame cannot disagree, and a key is "just
pressed" for exactly one frame however many times it is asked about.
It is the runner's step and not the scene stack's, so it is the same whether the hook is
RMP_GAME's or a game's own on_frame, and it happens exactly once: a
second sample in the same frame would compare every key with itself, and every press of that frame
would be lost. tests/input_play.cpp drives one program through the real desktop runner
both ways, a hook of its own and a scene under frame(), and each press has to be seen
exactly once.
The first frame has nothing to compare against, so it compares against itself: a key already held when the game starts is held, not just pressed, and does not fire whatever it is bound to.
The
frame proper is frame(float delta) in src/rmp/app/app.cpp, the function
RMP_GAME's frame hook calls, and the first thing it does is open the UI's frame, which
advances the UI's animations by this frame's delta, and its scroll, once, however many
scenes draw a menu.
Before
anything else, begin_pace() in src/rmp/app/clock.cpp asks raylib whether the
window is minimized and whether it has the focus, and decides two things for the frame: whether
the scenes move, and whether anything is drawn.
[window] pause_unfocused
(off by default): the scenes stop, the clock stops, every sound and the music pause, and the last
picture is drawn again ten times a second. The top scene hears
_suspend() when it starts and
_resume() when the window has its focus back,
and the first delta after it is 0, so nothing jumps by the time the player was away.
Minimized under it is a pause too.There
is no #if for it: a browser stops calling a hidden tab's frame and a phone stops a
backgrounded app on their own, and raylib says a window there is never minimized. A frame that
draws nothing still polls the window's events itself, because raylib does that in
EndDrawing(), which does not run: without it the window would never hear it was
restored. And the frames raylib did not time are timed by the clock itself, so the first one
drawn after a minimized stretch is not handed the whole stretch as its delta.
Performance has what it saves.
Then
the scenes run. Not all of them: the stack is walked down from the top for as long as each scene
lets the one under it run (updates_below),
and from the lowest one that runs, back up to the top. Bottom up, because the world moves first
and whatever is layered over it reacts to where the world ended up.
For each of those scenes, in this order:
input_below). One that
does not reads every action as not pressed, so a game running under a HUD that took the input
simply does not shoot.on_click; holding and moving calls its
on_drag with the movement in world units, taken
through the scene's camera. Only visible objects with a shape and one of those two callbacks
are considered, and the topmost of them under the pointer wins: an object with neither callback
drawn on top does not stop the click reaching the one below. The UI gets first refusal: a button
drawn over the world takes the click, and the object
under it never hears it. This comes before everything else so a click is acted on in the frame it
happened._update(delta).
The scene sets up the frame, and its objects then move inside it.An object that is alive goes through these steps, and an object destroyed by any of them stops there:
_update, in the order they were added. A behavior
runs before the object's own code so that yours has the last word on what the frame leaves
behind._update(delta).position yourself is a teleport, not a journey the collision pass would sweep along.apply_force and the scene's
gravity times the object's
gravity_scale change the velocity, and
the velocity moves the object. A solid object
that is not immovable, in a scene with a
map, moves through the map one axis at a time and stops at its solid cells. On a frame whose delta
is 0 or less this step is skipped whole, forces included, which keeps a push made in
_ready for the first frame that can use it. The other steps still run.edges says
to do at the edge of the object's bounds — clamp, bounce, wrap or be destroyed._late_update, for the behavior whose job is to
correct where the object ended up — snapping it to a grid, say — which has to see the position
after the move, not before.An object spawned during this pass gets its _ready() at once, inside the
spawn() call, and its first _update on the next frame. A behavior added
during the pass is the same. One spawned before the pass — from the pointer's callbacks or the
scene's _update — is updated in this one; one spawned after it, from a collision, waits
for the next frame like the rest.
Once every object of the scene has moved, the scene's pairs are found and dealt with, in four passes, and the order of the passes is the point:
_collision reads the velocity it hit with, and a bounce that turns it round is left
alone.For
each touching pair, once per frame and whether or not either is solid, the notification goes to
both sides in this order: the first object's
_collision, then its behaviors', then the
second object's _collision and its behaviors', then the first object's
on_collision and the second's. Each side
is told if it was alive when its pair came up, even when the other side has just died: the shot
that kills an alien still counts as a hit.
Last of
all, the scene's camera settles on where things ended
up, after collision has had its say: it moves toward what it
follows, at a rate that is the same at any frame
rate, is clamped to its limits, and advances its
shake. Anything that reads the camera next — the draw, the pointer next frame — sees the settled
view.
The
frame is opened with BeginDrawing() and cleared. The colour is the
background of the lowest scene that is
drawn, because everything above it is drawn over it; when that is BLANK, the
default, the clear colour is the UI theme's background.
Then
the scenes draw, bottom up, from the lowest one the stack shows
(draws_below). Each one, in this order:
BeginMode2D() with the scene's camera, so what
follows is drawn in world units — fitted to the window the way
[window] stretch says. When the stretch
letterboxes, the world is also cut to the game's area, so the bars around it keep the clear
colour.layer and, within a layer, in the order they
were spawned. Each one draws its sprite, or its shape when it has no sprite, then its behaviors'
_draw, then its own _draw().EndMode2D(), and the cut with it._draw(), in
screen space. This is where a scene's rmp::ui::begin() and
rmp::ui::end() go, and end() is what draws the UI — over the world,
and standing still while the camera moves.Objects first and the scene's own drawing after is what puts a HUD over the game rather than under it, without either one saying so. The same layer-then-spawn order, walked backwards, is the order the pointer finds objects in: the last thing drawn is the first thing clicked.
A scene the input cannot reach is drawn exactly the same, UI included, but no widget in it can be hovered or pressed: the HUD under an open pause menu is visible and inert, and neither scene wrote a line about it.
Two
things of the interface's go around the scenes. When the last frame's
overlay() asked for a blur, this frame is drawn
into a texture from BeginDrawing() on, clear included, so that the overlay has the
picture under it to blur; after the last scene, if no overlay took it, the texture goes on screen
as it is. And after every scene, what rmp::ui::notify()
queued is drawn over everything, taking no input.
Between the last draw and EndDrawing(), the framework calls
SmokeTest_CaptureFrame from tests/smoke_test.h. In a normal run it returns
at once. Under the frame budget CI sets (RAY_TEST_MAX_FRAMES), on one chosen frame it
flushes raylib's batch, reads the frame back and checks it has something on it — and that is the
only place it can: before the flush the frame holds nothing but the clear, and after
EndDrawing() it may already be gone. Because the framework makes the call, a game
cannot put it in the wrong place. Testing has what CI
does with the result.
EndDrawing() puts the frame on screen, and where the frame rate is capped —
[window] fps, or vertical sync
with [window] vsync — it is
also where the frame waits. Then the UI's frame closes: a UI that drew nothing this frame lets go
of the pointer and the keyboard, so a pause menu that just closed under the cursor does not keep
the game's mouse.
And
when the focus has just moved, with its ring showing, onto a control a scroll area has clipped
away, the area is scrolled to show it — here, once every scene has drawn and the frame knows where
everything is.
Only now, with nothing mid-frame, does anything go away.
Destroyed objects are freed. An object stops updating and drawing the moment
destroy() is called on it, but its memory stays
until here. That is why the reference spawn()
returns is good for the whole frame, and why other in a _collision is
always a real object even when it is dying. Freeing a slot bumps its generation, so every
rmp::Handle to it stays empty — as it has been since
destroy() — even once the slot holds a new object.
Scene
changes are applied, in the order they were asked for, so push then
pop in one frame leaves the stack as it was. A
change ends every scene top down; a
push suspends the top and enters the new one; a
replace ends only the top; a
pop ends the top and resumes the one under it. A
scene that ends gets _end() first and its objects go after it, so a scene tidying up
can still walk what it spawned. A transition asked for from inside a _ready() or an
_end() that runs here belongs to the next frame.
This is why if (rmp::ui::button("Play")) change<GameScene>(); is safe inside
the menu's own _draw(): the menu is not destroyed until its _draw(), and
everything else in the frame, has finished.
Back
in the loop, outside frame(), the same last things happen on every platform. The
music stream is fed: here, and not in the scene stack, so it keeps playing under a pause menu that
freezes the game, and in a game that does not use scenes at all. A game with a frame hook of its
own has the UI's frame closed, which the runner opened before the hook; a begin() it
left without its end() is reported once and closed for it. The CI frame budget
advances, and on the budget's last frame the framework prints how many of the game's mistakes it
has reported, which a correct game keeps at 0. Last, the end of the frame is reported to whoever
is watching: nobody, unless a test that plays the game from
a script is, and then it sees the frame drawn and its scene changes applied.
Before
the first frame the entry point prepares the run: it tells the asset layer where this
executable's resources/ are, seeds rmp::random
from the wall clock — or from the seed a test that plays the game names — turns on [dev]
strict in a debug build that asks for it, has a debug build say each of the
framework's warnings on screen as well, with rmp::ui::notify(),
reads the CI frame budget, moves into the app
bundle on iOS or next to the executable in a desktop release, and opens the resource pack if there
is one.
The
move matters for a released game. It reads its files from ./resources/, and
. is the working directory, which is wherever the player started it from: a file
manager, a shortcut, another folder in a terminal. So a production build on a desktop — Windows,
Linux (DRM included), macOS, FreeBSD — changes into the executable's own folder when
there is a resources/ folder there, before the pack is opened, and the release starts
the same from anywhere. A change of
directory rather than an absolute path, so a plain raylib LoadTexture() of a
RMP_RESOURCES_PATH path keeps working too. Without a resources/ beside
it — a release run from the source tree, whose executable is in build/release/ — it keeps the
working directory. NetBSD and OpenBSD cannot say where an executable is, so there it keeps the
working directory and logs ASSETS: this system does not say where the executable is, so …
is read from the working directory, ….
Then
the ready hook. RMP_GAME's opens the window from [window] — vsync and a
resizable window first, the frame cap before InitWindow() because raylib's DRM backend
chooses the display mode from it, and never on the web or iOS, where the browser and the display
pace the frame — and only then makes your first scene and enters it, so its members and its
_ready() both load with the window open. A texture, a font or a sheet that was asked
for before that line is named once, as the window opens: it has nothing to draw. The window opens at [window] width by height; only under the
CI frame budget can RAY_TEST_WINDOW open it at another size, so that a
[window] stretch can be booted on a screen of another shape.
Right
after the ready hook, on every runner, Escape is taken back from raylib. InitWindow()
makes it the key that closes the window, and in a game it is the key for "back" and "pause":
rmp::ui goes back on it, and the factory ui_cancel action is bound to
it. After the hook is where every window is open — RMP_GAME's, or the one a game's
own on_ready opened — so the entry point calls SetExitKey(KEY_NULL)
there. The window's close button still closes the game. A SetExitKey() of your own in
on_ready is overwritten; to quit on a key, say so where the game reads its keys:
if (IsKeyPressed(KEY_ESCAPE)) rmp::app::quit();Then, under CI, a save is written to the platform's real folder and read back, and the boot is reported.
After the last frame, the order matters more than anywhere else, because the window owns the GPU context and everything holding a texture has to let go of it while the window still exists:
_end() and its objects.
Transitions still queued are dropped: a scene nobody will see does not get a _ready()
to load assets in.rmp::global, in
reverse order of first use — after the scenes, because a scene's _end() may write to
one.RMP_GAME's closes the window.On Android, rmp::app::quit() also finishes the Activity, so the app does not
linger in the recent-apps list. On iOS it does nothing at all and says so once: an app that closes
itself looks to the user as if it crashed, and App Review rejects it.
It says so
through the same once-only warning as a mistake in the game, so with
[dev] strict on, a debug iOS
build aborts at the first quit() — a Quit button pressed in the simulator is enough. A
game that keeps a Quit button can leave it out on iOS:
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endifA game that wants none of the scene stack writes its own three hooks and hands them to
RMP_ENTRY_POINT:
static void on_ready() {
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
}
static void on_frame(float delta) {
(void)delta;
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("My own frame", 20, 20, 20, DARKGRAY);
EndDrawing();
}
static void on_exit() { CloseWindow(); }
RMP_ENTRY_POINT(on_ready, on_frame, on_exit);Then none of steps 2 to 6 runs: on_frame is called where frame()
would have been, and what happens inside it is yours. What stays the framework's is the loop
around it — the three ways a run ends, the input snapshot of step 1, the clamped
delta, the CI frame budget, the music stream — and the start and the stop: the
resource pack, the seed, Escape taken back from raylib, and the ordered release of everything
loaded. The examples under UI are written this
way, because a menu on its own needs nothing more.
Every interesting property of a scene stack is an ordering property, so the tests check
transcripts rather than return values: tests/scene_test.cpp records which hooks ran,
in what order, across pushes, pops, changes made mid-frame and shutdown; and
tests/object_test.cpp and tests/behavior_test.cpp check that behaviors
run before the object's _update, that _late_update runs after the move,
that the edges come after the integration and that the draw order is layer first. The claims on
this page are pinned to the source lines they describe, and the site's build fails if one stops
matching.
https://omardev29.github.io/rmp-docs/framework/config-pipeline.html
A game built for 17 targets goes through four build systems: CMake,
Gradle, Xcode and GitHub Actions. Each of them needs the same handful of facts — what the game is
called, its identifiers on the stores, its window, which targets to build — and left to themselves
they would each keep their own copy and drift. So there is one file you write,
raylib_multiplatform.toml, one program that reads it, tools/configure.py,
and everything the build systems read is generated from the two.
The .toml is grouped by what each section is about:
[project]
name = "space_rocks"
[window]
title = "Space Rocks"
width = 960
height = 540
[app]
max_delta = 0.05
[targets]
enabled = ["desktop", "web", "android"]A key you leave out takes its default, so a game's file holds only what it changes.
Configuration lists every key with its default and
what it is for — and that page is itself generated from configure.py --print-schema
and the comments of the framework's own .toml, so it cannot describe a key that does
not exist.
Before
configure.py writes a single file it checks every value: its type, its range, the
values it may take, and the combinations that cannot work together. A mistake stops there, in
well under a second, with the line of the file it is on, what is wrong, and what to write
instead. The build never sees it.
[project]
name = "my game" raylib_multiplatform.toml:2: name = "my game"
^^^^^^^^^^^^^^^^
configure: error: [project] name = 'my game' is not usable as a filename.
Use letters, digits, '_' and '-', starting with a letter. It becomes the executable name on five operating systems.The wrong type is caught the same way. An array where a number goes would otherwise reach a generator as something it cannot format:
[window]
width = [800] raylib_multiplatform.toml:2: width = [800]
^^^^^^^^^^^^^
configure: error: [window] width = [800] must be an integer between 16 and 16384.Every key is held
to that, not only the ones somebody remembered to check: a test walks every key the defaults
have, gives it every type it is not, and expects a refusal that names its line. The empty value
is refused the same way, except where empty is a value with a meaning — [ui] font = ""
is raylib's built-in font, [linux] glibc = "" builds against the machine's own C
library — and a test names each of those exceptions too.
[window]
title = "" raylib_multiplatform.toml:2: title = ""
^^^^^^^^^^
configure: error: [window] title is empty. It is the title bar on desktop and the name under the app's icon on Android and iOS -- give the game a name.And so are two values that are each fine on their own and wrong together. A frame cap of 15
frames per second makes every frame longer than the default
[app] max_delta, so the game
would be handed less time than really passed, every frame, forever:
[window]
fps = 15 raylib_multiplatform.toml:2: fps = 15
^^^^^^^^
configure: error: [window] fps = 15 makes every frame 0.06667 s long, but [app]
max_delta = 0.05 hands the game at most that much per frame, so the
game would run at 75% speed forever. Raise fps to 20 or
more, raise max_delta to 0.06667 or more, or set max_delta = 0.The rule behind it is strict on purpose: a configuration mistake that reaches the compiler is a
bug in configure.py, not in the configuration. A mistake found twenty minutes into a
CI run on somebody else's machine costs twenty minutes and an explanation; the same mistake found
here costs a second and points at the line. And a refusal is only kept honest by a test that feeds
it the value it refuses: those live in tests/configure_test.py.
One
more check is kept for releases. When a game is released — by
rmp deploy, or by a version tag pushed
to its repository — configure.py also refuses an Android application id or an iOS
bundle id that is still a placeholder under com.example., the kind
rmp new writes, for a platform the game is built for. A Google Play application id
can never be changed once it is published, so this is the one mistake worth stopping a release
for, and the one not worth stopping a debug build for.
You
never have to. CMake runs it at the start of every configure, before project() —
the project's name comes out of it — and configures again by itself when the .toml
changes. Every rmp command that builds goes through CMake, so
rmp run after an edit to the
.toml picks the edit up.
Gradle and XcodeGen
never run the top-level CMake that calls it. Gradle builds the native code through a
CMakeLists.txt of its own, which reads what configure.py already wrote,
and it reads its own settings from raymob/generated.properties before any of that
starts. So the CI jobs for Android and iOS run python3 tools/configure.py themselves
before they build. The BSD jobs build inside
virtual machines that have no Python at all; there CI generates everything on the Linux runner
first and the files travel into the machine with the rest of the checkout. A CMake configure that
finds no Python 3.11 or newer falls back to what was generated last time, and says loudly that
edits to the .toml will not be seen.
A run writes a file only when its content changed, so configuring again after touching nothing rebuilds nothing.
| File | Holds | Read by |
|---|---|---|
cmake/generated/project.cmake | the project name, the pack password, the web memory settings, the windowing backend per platform | the top of CMakeLists.txt, before project() |
cmake/generated/raylib_flags.cmake | raylib's complete set of feature flags, with the modules [raylib] disabled_modules removed | CMake, and the Android build's own CMake |
cmake/generated/dev_toolchain.cmake, dev_linker.cmake and dev_sanitize.cmake | the compiler, the linker and the sanitizers from [dev] | debug builds only: a release never reads them |
cmake/generated/rmp_web_name.js | the name of the game's save database in the browser | the web build |
include/rmp/generated/config.h | every value a game can read in C or C++, as RMP_ macros | your code, through every public header — below |
raymob/generated.properties | the Android application id, minimum SDK, version, the OpenGL ES version to compile for, permissions, and whether AdMob is on and its ids | Gradle |
raymob/app/generated/AndroidManifest.xml | the manifest, with each permission and feature element kept or dropped | Gradle |
ios/project.yml | the iOS app: bundle id, deployment target, orientations, header paths, the compiler flag that refuses out-of-order initialisers, the licence notice | XcodeGen, which makes the Xcode project |
| the icons | Android's launcher icons, the iOS icon set and the Windows .ico, from [icon] source | each platform's build |
LICENSES.txt in cmake/generated/ for the desktops, and one each for the web, Android and iOS | the third-party notices that ship with the game | the release packages — see Licences |
The manifest is generated rather than templated through Gradle for a reason worth knowing: Gradle's placeholders can change the value of an attribute but cannot remove an element, and a permission is exactly an element you either ask for or do not.
The version is not in the .toml. A release takes it from its git tag —
v1.2.3 is version 1.2.3, and Android's version code is computed from it so it always
goes up — and every other build is 0.0.0-dev.
A
tag that starts with v is the release path, so one that does not read as
vMAJOR.MINOR.PATCH, in ASCII digits, is refused rather than published under a
made-up number. A pre-release or build suffix after it is accepted — v1.2.3-rc1,
v1.2.3+build — and shares the version code of v1.2.3. Minor and patch
each have to stay below 1000 for the code to keep going up.
A number
with a leading zero is refused too — v01.2.3 would be a second release name
with the version code of v1.2.3 — and so is
v0.0.0, whose code would be 0: the first release is v0.0.1. A tag
that does not start with v is not a release: it builds as 0.0.0-dev,
with a warning.
The values a game can use at run time — the window's size and title, the input dead zone, the
volumes the audio buses start at, the save settings, [app] max_delta — are written to
include/rmp/generated/config.h as macros. Every public header of the framework
includes it through rmp/config.h, so whichever header you were including anyway, they
are there:
const float centre_x = RMP_WINDOW_WIDTH / 2.0f;
const float centre_y = RMP_WINDOW_HEIGHT / 2.0f;
TraceLog(LOG_INFO, "%s starts at %.0f, %.0f", RMP_WINDOW_TITLE, centre_x, centre_y);They
are macros and not C++ constants because a game in plain C uses them too, and C has no namespaces
to put a constant in. Each one is named after its key: [window] width is
RMP_WINDOW_WIDTH.
Macros lists all of them, read from
configure.py --print-defines.
The values that only a build system needs — the store identifiers, the targets, the backend — never reach the header. A game cannot read what it has no use for, and a value read in two places is a value that can disagree with itself.
The same program answers the questions the CI and the tools ask, so none of them parses the
.toml on its own:
--check validates and writes nothing.--print-targets, --print-families and --print-matrix tell
the CI which targets are enabled and which jobs to run for them; a family with no enabled target
is skipped whole. --only
narrows what they print to the groups and targets it is given, separated by commas, and never adds
one the .toml switched off: it is what a run started by hand with
-f targets= hands it.--print-schema and --print-defines describe every key and every
generated macro, which is where this site's Configuration
and Macros pages come from.--config checks another file instead of the project's: every .toml
block on this site goes through it, and a block that shows a refusal prints the message
configure.py really gives, as on this page.Every file in the table is ignored by git, and the framework's own CI fails if one is ever tracked. Generated files that are committed go stale the first time somebody edits the source and forgets to regenerate; files that are written on every configure cannot.
rmp clean deletes them with the build
directory, and the next configure writes them again — all but the Android launcher icons and the
iOS icon set, which it leaves in place, because making the Android ones again needs Pillow. The Windows
.ico lives in cmake/generated/ and goes with the rest.
https://omardev29.github.io/rmp-docs/framework/performance.html
The framework sits on raylib and draws everything through it, so a frame can never be faster than raylib makes it. What the framework decides is how much it adds on top, and how much work it saves the game from doing at all. This page goes through both: the abstractions that cost nothing, the few that cost a function call, the places where the framework does less work than a hand-written raylib game would, and where OpenGL by hand still wins.
"Zero-cost abstraction" means two things here, and the framework holds both.
-ffunction-sections -fdata-sections and linked with --gc-sections
and link-time optimisation in release. The linker takes only the objects something references and
throws away every function nobody calls. A game that never touches rmp::ui ships no
UI code; a game that never loads an Aseprite file ships no Aseprite reader. The strongest form of
the rule is "a 2D game pays nothing for 3D": not one
byte of the 3D renderer, the physics or raylib's model loaders reaches a 2D binary.| Abstraction | What the compiler makes of it |
|---|---|
Options structs with designated initialisers ({ .speed = 320 }) |
A plain struct built on the stack. No builder, no map of names, no allocation. |
The math types (Vector2 and friends from raylib-cpp, the operators of
rmp/math.h) |
Header-only and inline: a + b * delta is the same instructions as
Vector2Add(a, Vector2Scale(b, delta)). |
RAII ownership (rmp::Texture, rmp::Sound, the scenes and
objects) |
A destructor that calls the Unload* you would have called. No reference
counting, no garbage collector, no pause. |
| No exceptions | No unwinding tables on the hot path, no try anywhere in the library: a failure is
a return value, a report once, or a default.
No exceptions says why. |
| Behaviors that leave out a hook | Hooks are found at compile time with requires. A behavior with no
_draw has a null entry in its table of hooks, and the frame never calls it. |
| Hot reload in a release, or off the desktop | changed() is a constant false; no file is ever watched. |
| Configuration | The .toml becomes #defines at configure time
(the config pipeline). Nothing is parsed when the
game starts. |
rmp::Callback, what every on_click and
on_hit is, is one call through a function pointer over the lambda you gave it. It is
move-only on purpose, so it carries none of std::function's copying machinery.rmp::Handle, rmp::Ref) checks a slot and
a generation number before it hands you the object: two loads and a compare, in exchange for never
reading an object that was destroyed.obj.get<B>() looks for a behavior by type among the few an
object carries. Keep the result in a local if you ask for it many times in one hook.rmp::input::pressed("jump")) is a lookup in a
small table, so the same name works for a key, a button and a touch.A naïve tilemap draws every tile every frame. Scene hands
Tilemap::draw() the camera's view, and only the tiles inside it are drawn: LDtk layers
through chunks of 16×16 cells, Tiled layers through their range of cells. Nothing is baked into a
render texture, so the map stays exact at any zoom and costs no video memory. Measured on a 400×400
map: 87 ms a frame drawn whole, 0.25 ms culled, with the same pixels
(ui_render_test checks that). See Tilemaps.
Objects go through a uniform grid sized to the objects themselves, so each one is tested only against its neighbours instead of against everything (the O(n²) a beginner writes). The map's solid tiles are never turned into colliders: when the map is read, every source of solidity is folded into one table, and an object is moved in steps of at most half a cell and pushed out by bisection against that table. A map of any size adds the same few lookups per moving object. Fast objects use a swept test, so they cannot pass through a wall between two frames.
rmp::ui is immediate mode on top of Clay, a layout engine written in C. Clay works
in one arena reserved once; every string the UI is given in a frame goes into a bump arena that is
reset at the next begin(). A menu redrawn every frame makes no heap allocation. Fonts
are baked once per size, and a glyph is added to the atlas only the first time a text uses it.
The framework reads the time once per frame and hands the same delta to every scene,
object and UI animation. Nothing asks the operating system for the time again in the middle of a
frame.
In a debug build on the desktop, the files a game asked to watch are checked at most every
0.25 s, by size and time; their bytes are read only when one of those moved. Asking
changed() every frame reads a flag.
A
minimized desktop window is not drawn at all. The world, the music and the clock go on, but the
loop skips BeginDrawing() and EndDrawing() and sleeps a thirtieth of a
second a frame instead of waiting for a vsync: a game left minimized on a laptop stops spending
the GPU and most of a core. With
[window] pause_unfocused
on, a window without the focus does not even move its scenes: it draws the same picture ten times
a second and pauses the sound. A browser and a phone do this for a hidden page or app on their
own, so the framework leaves them to it. The
frame has the order of it.
An rmp::Text keeps the words the code wrote and is
translated when it is drawn: one lookup in a hash table of the loaded tables, then the
placeholders filled. That is what makes
rmp::lang::set() change every screen at once, with
nothing to rebuild. A widget's identity is the text's key, never its translation, so changing the
language costs no layout memory either: the focus and the hover stay where they were.
Localization has the rest.
A .yarn file is compiled into instructions when it is loaded, or, in a release on
the desktop, when the game is built: rmp_yarnc runs over the game's scripts and their
bytes are compiled into the binary, so the release reads no script and parses nothing. Either way
a running conversation only steps a small stack machine from one line, choice or command to the
next. Dialogue says how to choose.
tools/size_budget.txt, and CI fails a growth of more than 10 % that nobody wrote
down. A 2D game's release is a few hundred KB packed.std::ifstream once added 19 % to
the Linux binary and 18 % to the web's .wasm; files are read with C's stdio
now, and a check refuses an iostream header in the library.std::to_chars brings libc++'s formatting tables into every static link: the Linux
release of the demo game was 1,510,904 bytes with it and 1,384,760 without. The framework writes
a number with printf's %g at the fewest digits that read back as the
same number, which gives the same digits to_chars would.-fvisibility=hidden and linked with --gc-sections, and what the system
looks up by name is marked to stay: the arm64 library went from 3,091,080 bytes to 1,108,688.| raylib by hand | rmp | OpenGL by hand | |
|---|---|---|---|
| Draw calls | rlgl batches quads and lines into one buffer and flushes when the texture, shader or blend mode changes | The same: every sprite, tile, shape and UI element is drawn through raylib, so it batches exactly as raylib does | Whatever you build: instancing, persistent mapped buffers, texture arrays, bindless |
| Per-object cost | Your loop | Your loop, plus one indirect call per hook a behavior defines | Your loop |
| Large maps | Every tile unless you cull by hand | Culled to the camera | Usually one draw per chunk from static buffers |
| Collisions | Pairs you test yourself | Grid broad phase and a solid table for the map | Not its business |
| UI | raygui, redrawn by hand | Clay layout, no allocation per frame | Not its business |
In practice: for a 2D game a frame costs what the same game written well in raylib costs, often less, because the culling, the grid and the arenas are things a game written in a hurry does not have. The framework never adds a draw call of its own beyond what it draws for you.
Where OpenGL by hand still wins: tens of thousands of moving sprites, particles that should live
on the GPU, or a renderer built around instancing. raylib's batch rebuilds its vertex buffer on the
CPU every frame, and the framework does not change that. A game that needs more can still call
rlgl or OpenGL directly inside an object's _draw(): the framework does not stand in
the way of either.
https://omardev29.github.io/rmp-docs/framework/testing.html
A framework that promises a game will run on 17 targets has to check it, and the rule it holds itself to is strict: anything that can be tested is tested, and a test asserts what actually happened, not that a command exited 0. A green check that ran nothing is worse than a red one, so every gate is also shown failing on the thing it was written to catch.
This page says what is tested and how it holds. To add a test of your own, of any kind, Contributing says how.
Everything below runs with rmp test in
the framework's repository, stage by stage, and in its CI on every push. The last section is what
the same command runs in a game.
The unit tests use doctest and run without a window, a GPU or a display. They cover the scene stack and its order of events, objects, handles,
behaviors and the catalogue, collision against objects and against maps, the camera, input, the
asset table, sprite animation, the LDtk and Tiled readers, saves and rmp::Value, the
diagnostics, and the random generator,
and the fix the framework carries in raylib's software renderer, read at the edges of a
texture,
and the terminal a DRM/KMS game hands back however it ends, from a program made to die each way
on a pseudo-terminal. Every file called tests/*_test.cpp is picked up by the
build, so a new test needs no change to CMake.
They run twice. Once in the order they are written, and once shuffled with a fixed seed, so a test that only passes because an earlier one left something behind is found, and found again the next time.
Both
runs are a debug build of the framework, so both run under the
sanitizers, and the build is configured with RMP_WERROR: a
compiler warning in the framework or in a test is an error there.
The
same stage then builds and runs tests/game/, the tests every game is given, against
the small game in the framework's own src/ — the copy every game starts from — so a
test a new game would fail on its first day fails here first. Below is
what they are.
Two kinds of test need something real underneath, and get it:
What
makes all of this possible without a window is the seam: time, input and randomness enter the
framework through a few functions a test replaces — one clock, which the game and the UI both read,
the game's input sampler and the UI's own, and one random generator.
Time is a parameter explains it, and
tools/seam_check.sh fails if any other file starts reading them on its own. The files it
allows are the seams themselves, and the list only gets shorter: a file on it that stops reading the
real thing fails until its line goes. The UI's text field is not on it. What it types — the
characters and Backspace — comes through the UI's own seam like the rest of its input, which is how
the layout test types into it, and its caret blinks on the game's clock like the rest of the UI.
The UI's layout
engine is pure computation, so with the text measurement and the pointer replaced by stubs and a
viewport injected, a whole menu can be laid out with no window at all.
tests/ui_layout_test.cpp checks what a person would check by hand once and never again:
that the menu is centred, that it stays centred when the window changes, that buttons do not
overlap, that the scale behaves at the extremes, and that a focused button can be pressed from the
keyboard;
that a pointer landing on a button is the interface's before the frame's interface has run, and
that a list scrolls to keep the focus in view.
Booting proves the window opened and the assets loaded, and nothing more. A broken shader or a
draw call that silently does nothing still boots and still exits cleanly. So the render stage
builds the game a second time against raylib's software renderer, which draws into plain memory —
no GPU, no window, no display server — and runs it for ten frames. It asserts three things from
the log: the game booted with every asset loaded, a frame was read back and had something on it,
and the run reached the end of its frames instead of dying on the way out. It also checks that the
window was asked for the vertical sync the .toml says.
Before any of that, it reads how the game ended. The markers are printed before the process exits, and two things come after them: a crash while the game shuts down, and LeakSanitizer's report of the memory nobody freed, which a sanitized debug build prints at exit. So a report from a sanitizer anywhere in the log fails the stage, with the first forty lines of it, and so does an exit status other than 0.
In the framework,
the frame is also hashed and compared with tests/fixtures/render_hash.txt. Software
rendering involves no driver, so the same frame comes out byte for byte on Linux x86-64 and on
macOS on Apple Silicon, and one golden hash covers both. A change to the frame that was meant is
recorded with rmp test render-update.
The frame is read back by the framework itself, between the last draw and
EndDrawing() — the only place it can be: before the batch is flushed the frame holds
nothing but the clear colour, and after it the frame may already be gone.
One frame has the detail.
The smoke
stage builds the game the ordinary way and runs it with a budget of ten frames
(RAY_TEST_MAX_FRAMES=10), after which it exits by itself. It passes only if no
sanitizer reported anything, the game exited with status 0, and it printed
RAY_TEST_BOOT_OK assets_failed=0 and RAY_TEST_RENDER_OK. Otherwise it
prints the log, or the report, and says which: a sanitizer reported the run above (exit
…), the game exited with status …, the game did not boot, or an asset
failed to load, or the game booted and drew nothing.
And
it holds the game to no mistake the framework reports. A mistake in the game that the framework says
once in the log — a widget outside begin()/end(), an action nobody
defined — is counted, and the last frame prints the count, RAY_TEST_REPORTS=0 when
there was none. Anything else fails the stage, with the warnings it counted: the framework
reported a mistake in the game (the WARNING lines above, said once each). That holds in a game
rmp new makes as much as in the framework; a game in plain C has no framework to report
anything, and prints no count.
The
count in assets_failed is of every load that gave nothing usable: a name with nothing
behind it, and a file that is there and does not decode — a picture, a sound, a song or a font cut
short. A corrupt file would otherwise leave a blank texture, silence or a stand-in font, and a boot
that looked clean.
The boot marker is a gate and not a message, which is a distinction worth stating: it is printed only when a window really exists. A boot marker that is always printed passes a game whose platform failed to start, and every job that reads the log would agree.
Under the same frame budget the game also writes a small save to the platform's real save folder, reads it back, compares and deletes it before it reports the boot. Where saves go is different on every platform, and this is how each one's folder is exercised at all.
In
CI the same markers are read on every target a runner can start, each in the most honest
place available, and every one of those checks wants assets_failed=0 on the boot
line, never the marker alone: a game with every texture missing still opens its window. A test
reads every workflow, script and tool and fails on a check that looks for the marker without
it. The Linux desktop builds boot under a virtual X display. The musl builds boot on Alpine, in
an image of the framework's own pinned by its digest and with the network off: a software-rendered
build of the game, and the binary the archive ships, under a virtual X display. What a musl binary
needs from the system is read out of it rather than proven by a boot — below.
The DRM build boots on a virtual kernel display,
and on the same display rmp run, started as on a Linux console with no desktop, has
to choose DRM/KMS by itself, build the game and boot it. The RISC-V build is started as its archive
ships it on a RISC-V board — RISE's, or Cloud-V's for a private repository — in the riscv64 build
image, and, when the board fails or none comes, under QEMU's emulation of a RISC-V processor,
inside the build image.
Windows boots on its runner with its save folder under a path that is not ASCII, the kind a player
called José has, and with the compiler off PATH, so that a DLL the runner has and a
player does not cannot be found. macOS and the BSDs run the render stage under the software renderer. The web build
is loaded in a headless browser that checks the canvas really has pixels on it. iOS is built for
the simulator, where booting it and reading the markers is a step a repository switches on.
Android is the exception: no CI job
reads its markers. When a project is configured for it, the debug APK is started in Firebase Test Lab, by
default on MediumPhone.arm, an Arm virtual device, under a Robo test, which explores the app with no test code of its own and has
no log to read the markers from. It proves the game starts on that device without crashing, and
no more. The robot taps whatever is on the screen,
and the debug build shows Google's test ads whatever ids the .toml carries, so none
of its taps lands on a real ad.
A
release is also started the way a player starts it: from somewhere other than its own folder. A
production build reads ./resources/, and a boot started from the folder where
resources/ happens to be passes whether or not the game finds its files on its own.
So tools/shipped_check.sh builds the release under the software renderer and starts
it twice, and each start must boot with assets_failed=0. First where it was built,
from the project folder, with no resources/ next to the executable: only a
resources/ beside it may move a release, so this one has to stay where it was started
and read the project's. Then laid out as the archive ships it, from another folder. The macOS and
BSD jobs run it, and so does the job that makes a game in plain C, whose own main()
does the moving instead of the framework's entry point. Linux x64, arm64 and RISC-V start the
unzipped archive from another folder, Windows starts the .exe from one, and the musl and DRM
containers start the game from /. On NetBSD and OpenBSD, which cannot say where an
executable is, the check starts the shipped release from its own folder and wants the line that
says so.
Every
container a workflow starts a game in — the musl boots on Alpine, the DRM boot and
rmp run on the virtual display — has an init as its first process, which Docker's
--init puts there. A program that is a container's first process ignores a SIGTERM it
has no handler for, so a game there that hung could not be ended by the step's timeout, and held
its job until the job's own limit ran out. A test reads every workflow and fails on a container that
starts a game — one that sets RAY_TEST_MAX_FRAMES, runs xvfb-run or runs
./rmp run — without one.
A boot on a CI runner proves the game starts on that runner, and a runner is a developer's
machine with everything installed. What a player's machine has to give the game is invisible from
there and written in the binary itself, and so is what a release was linked with, so CI reads them
out of it with tools/binary_check.py, which needs nothing but Python's standard
library:
.exe
imports. Both Windows jobs read the import table and the delay-load table of the
.exe they ship, before booting it, and fail on any DLL that is not part of every
Windows 10. A dynamically linked compiler runtime is named, with how to link it in instead. With
--require-icon it also wants the icon group in the resources, which is what Explorer
shows.--musl, its interpreter has to be musl's
loader and the one library it names musl's libc.so, or it has to be static and name
neither. A boot cannot say this: the Alpine it boots on has what the shipped binary needs, and a
static binary would boot on any Linux.The
readers are tested by the binaries stage, tests/binary_check_test.py,
against binaries it builds byte by byte rather than commits: an .exe with an import
table, a delay-load table and an icon group, a universal Mach-O with a minimum per slice, and ELF
files with and without each of the things the Linux reader asks for. Among
them are the shapes a broken build really has — a MinGW build that imports
libstdc++-6.dll, an MSVC one with the dynamic runtime that imports
VCRUNTIME140.dll, a Mac binary that asks for its build machine's macOS in both slices —
so the gate is seen red before it is trusted green.
The
29 examples are tests too. rmp test examples — kept out of the plain
rmp test, because it compiles all of them — runs one script, the one CI runs,
in
its two halves: boot, the first five steps below, and e2e, the sixth,
which CI runs in two jobs side by side.
int main(), or a loop on WindowShouldClose(), compiles everywhere and does
not run on the web or iOS, so it is refused. The one exception is the plain C example, which writes
its own main() and loop on purpose; it is allowed only while its own comment keeps
saying which platforms that rules out and why.[window] stretch draws the same picture, so the stretch example is booted twice more,
in a window taller than it is wide and in one wider than 16:9, letterboxed, and its last frame
read back: the bars are its clear colour, the world reaches every edge of the area between them, and
the court's lines are centred in the window.tests/input_play.cpp drives one program through the real desktop runner with keys
pressed through the input seam, once with a hook that reads the input itself and once with a
scene under frame(), and each press has to be seen exactly once.tests/e2e/ is played from it, and every picture the script
takes is compared with the one recorded for it — below. As many scripts were
found as were built and as were played, or the step fails.
They
are played side by side, as many at once as the machine has processors — or
as CMAKE_BUILD_PARALLEL_LEVEL says, when it is set, because each is a sanitized
program of a few hundred megabytes — the one with the most frames first. Each has a folder of its own, and a frame is a sixtieth of a second however busy the
machine is, so playing them together changes how long the step waits and nothing a script
draws. A
script still playing after ten minutes is stopped, and fails; macOS has no timeout,
and there nothing stops it.The screenshots are kept, because looking at a picture of every example is how most visual mistakes are found.
Every
one of these is a debug build of the framework, at -O0 and under the
sanitizers, and a frame drawn by raylib's software renderer is slow that
way. So this build, and only this one, compiles the three files of raylib a frame spends its time
in — rcore.c, which carries the rasteriser, rshapes.c and
rtext.c — at -O2 -ffp-contract=off, still under the sanitizers.
A
frame costs about a fifth of what it did: measured in the build image, Pong's script plays in 17
seconds instead of 85.
Turning
off contraction is what keeps the pixels: at -O2 a compiler may fuse a multiply and an
add into one instruction that rounds once instead of twice, and every picture is compared byte for
byte. It was adopted only once every picture the scripts take came out identical to the ones
-O0 draws.
The
rest of raylib stays at -O0: the image, model and sound loaders are where a malformed
file finds a memory bug, and an optimiser drops a read whose value nothing uses, which
AddressSanitizer then cannot see.
So
does every other build of raylib for the software renderer: the render stage's golden frame is
drawn at -O0 wherever it is compared.
Thirty
frames of a title screen prove that the title screen draws. A game in
examples/games has to be playable from start to finish —
win, lose, play again — so one of them is played. tests/platformer_play.cpp drives
the platformer through its real loop with a bot
that presses keys through the same seams a player's keyboard goes through and reads only what a
player can see: where things are. It plays a whole game at 60 frames a second, from the title
through every level to the flag, keeps the best run on disk, plays again and dies three times to
reach the game over screen; it jumps from the moving platform at 60 and at 240 frames a second;
and it plays to the flag again at 240. A game that can be won at one frame rate and not another is
not finished.
A
bot that reads positions is one way to play a game. The other is a script of what a player
presses, frame by frame, with what the screen has to show at the frames that matter. Three
moments of tests/e2e/games/01_pong.e2e: the first serve, the end of the first game,
and the last frame of the script:
1 press KEY_DOWN
19 release KEY_DOWN
19 shot arrows_move_red_only
639 expect scene PongScene
640 expect scene OverScene
641 shot red_wins
# Play again, from the keyboard: the button has the focus.
1430 tap KEY_ENTER
1430 expect scene PongScene
1432 shot again
1432 endEach
line starts with the frame it happens on. press and release hold a key
down and let it go, and tap holds it for one frame; the same three press the first
gamepad's buttons, by raylib's names for them — tap GAMEPAD_BUTTON_RIGHT_FACE_DOWN is
the bottom face button pressed once. A script has the gamepad's buttons and not its sticks, which
stay at rest. click x y presses the left mouse button for one frame at a point of the
window. shot takes the picture that frame drew, expect scene names the
scene that has to be on top once the frame is over, and end is the last frame. The
grammar refuses, with the line, a script that cannot mean what it says: input on frame 0, which has
nothing to compare a key with and so sees no press; a key or a button pressed again before it came
up; a shot name used twice; a script with no end, or one that checks nothing.
The
game that plays it is the example exactly as it ships — its own main.cpp and its own
entry point — built against the software renderer with tests/e2e/driver.cpp beside
it, which installs itself before main() through the framework's seams.
The driver, the script
reader and the comparison are compiled once, into a library every played example links; what one
of them plays — its script, its pictures, the folder a failure goes to — is four strings in a file
the build writes for it. Every frame
is exactly a sixtieth of a second and rmp::random starts from seed 1, so the run is the
same run every time — the menus included, since the
UI reads the game's clock. The script's keys, buttons and clicks reach rmp::input
and the UI's own navigation and pointer —
the
navigation through the same two functions that turn a real keyboard and gamepad into it, so what a
player navigates with and what a script presses cannot drift apart. Saves go to a fresh
folder, so last run's best score cannot change this one, and there is no sound device.
A
script can only press what the game reads through rmp::input or
rmp::ui: under the software renderer raylib's own keyboard and mouse never change, so
a game that asks raylib about a key directly never sees it go down.
On every frame, whatever the script checks, the driver also looks for a control the example has put where nobody can reach it: one that takes the focus, is not wholly inside the window, and is in no scroll area that could bring it in. Nobody could see that control or click it, and no shot would say so unless the script happened to look there, so the script fails, naming the control, the frame and the size of the window.
And
a mistake of the game's that the framework reports during the run — a widget outside
begin()/end(), an action nobody defined, a number that is not one — fails
the script at its end, one line each, in the log's own words. An example is what people
copy, and it makes none.
Every
shot is compared with the picture recorded for it — shot red_wins with
tests/e2e/golden/games/01_pong/red_wins.png — exactly, pixel for
pixel: the pictures are drawn by raylib's software renderer with a fixed step and a fixed seed, so
the same script gives the same bytes, and a tolerance would only be somewhere for a real change to
hide. A shot that differs fails the script with its line —
E2E FAIL <line>: <reason> — and leaves three pictures in
build/examples-check/e2e/: the one expected, the one drawn, and the expected one
darkened with every pixel that differs in red. The e2e job uploads them. A script fails as
well when the game stops before end, exits with a status other than 0, or a sanitizer
reports anything: it is a debug build of the framework, like every example.
Exact
means one compiler, one maths library and one renderer, so the comparison is enforced inside the
pinned build image, where CI runs it, and only reported anywhere else. The pictures are recorded
there too, and nowhere else: rmp test e2e-update refuses to run outside the image and
says how to run it inside, and every picture it changed is looked at before it is committed.
A
test holds the arrangement together. Every example in examples/games/,
examples/ui/, examples/scenes/ and examples/input/ has a
script, or a line in tests/e2e/pending.txt — a list that may only get shorter, and has
nothing left in it.
Every
other area of examples/ is named in the test with the reason it is not played — an ad
shows only on Android; the loading example's keys only play a sound, in a run with no sound
device; the platform examples are Android's own API, or never run at all; and the plain C example
has none of the seams the driver plays a game through — so a new area is a decision and not a
gap. Every shot has its picture and every picture a shot that takes it, and the build
refuses a script that plays no example.
Every script plays a way through and a way to fail: Pong lost and then won, and started again once with the mouse and once from the keyboard; Breakout's three balls lost, then its wall cleared; the platformer's world played to the flag, then every life lost to a fall; every screen of the menu example, with the keyboard, the gamepad and the mouse.
A script that cannot do what a player can is news about the example, and these have found what
no boot could.
Pong's
arrow keys moved both paddles.
Breakout
could not be won: its ball sped up 3 % a bounce and was four times its serve by the thirtieth
brick, faster than the paddle could follow, so its speed_up is 1.01.
In
Space Invaders the formation sped up without limit as it thinned, and the last alien came down
before a ship could get under it; it stops at four times the pace it starts at.
Drawing
the platformer's bats under the sanitizers — its bot plays the levels without drawing them — found
raylib's software renderer reading one texel past a texture at its far edge, which the framework
fixes in its copy of raylib.
The interface examples' scripts found the settings screen's Apply button and half of the style page below the bottom of their own window, a list whose focus walked out of sight, a tap on a button that reached the game underneath as well, and the menu and inventory examples reading Escape and the mouse from raylib, where no script and no gamepad could press them.
A
test asserts what it can see, and undefined behaviour is what a test cannot see: a signed overflow
that wraps to a harmless number, a read one past the end that finds a zero. So every debug build of
the framework — the library, every example and every test — runs under AddressSanitizer and
UndefinedBehaviorSanitizer, with LeakSanitizer on Linux, because the framework's own
[dev] sanitize lists both;
every report is fatal. The unit tests, the layout test, the render stage and the smoke stage all
run that way, and the boots read the report as well as the exit status. In CI those jobs set
RMP_REQUIRE_SANITIZERS=1, so a runner whose compiler cannot instrument the build fails
it instead of testing nothing in silence.
That
run is clang's, the framework's development compiler. rmp test sanitize builds the unit
tests and the headless layout test again with gcc, in a build directory of their own and with
warnings as errors: the second compiler instruments differently and warns about other things.
In
CI it is a step of the deep job, below. The clang builds leave alone what
cmake/sanitize_ignore.txt lists, each line with its reason, and the list may only name
vendored code, never the framework's. tests/sanitize_test.cpp holds the whole
arrangement to what it promises: it runs a small program that leaks, overflows a buffer and
overflows an integer on request, and each one has to be reported.
A
test that never runs a line cannot find what is wrong with it. rmp test coverage —
kept out of the plain rmp test, because it builds every test again — builds the unit
tests, the headless layout test and tests/input_play.cpp, the one program that drives
the real desktop runner, with clang's source-based coverage, in a debug build of their own and
without the sanitizers, which say nothing about which lines ran. It runs them and reads, line by
line, which lines of src/rmp/ ran.
The
tests link the whole framework library for this, and not only the parts they call, so a file no
test reaches is in the report at 0% instead of missing from it.
Two lists hold the result, and each moves one way only:
tools/coverage_floor.txt has the share of each file's lines the tests run,
rounded down. A file below its line fails. A file two points or more above it fails too, until the
line is raised in the commit that earned it: a ratchet nobody has to remember to turn is one that
does not stall. A file of src/rmp/ with no line fails, and so does a source file the
report does not hold, unless it has no code of its own. The floors run from 39 —
src/rmp/ui/render.cpp, which draws through raylib, where the headless tests do not
look — to 100.tools/untested_api.txt names every function of include/rmp/ a game
can call and no test does — one, rmp::Object::_draw(). clang reads the headers to find them, and a template counts
as called when any instance of it runs. A new public function no test calls fails: write the test.
A listed one a test calls, or one that is gone, fails until its line is removed.Which
lines a compiler counts, and which tests a machine can run, differ between machines, so both lists
were measured inside the pinned build image and are gates only there; anywhere else they are
printed. Inside it, the tests that skip on a machine without a sound device or the test locales may
not skip. bash tools/coverage_check.sh --update, in the image, raises the floors and
drops what is called; it never lowers a floor or adds a function, which is an edit somebody writes
by hand and a reviewer reads. Lines no test can run — a GPU, a store — go between two comment lines
and are counted apart, and the first of them has to say why:
// RMP_COVERAGE_OFF(<why>)
...
// RMP_COVERAGE_ONBefore any of that, the script builds, runs and reads back a program of two functions, one called and one not, and fails — never skips — when clang's profile runtime is missing or its tools come from another release of LLVM: a coverage run that measured nothing would print every floor as a note and pass.
The rest of rmp test is checks on the repository itself — each one written after
a mistake that could be described precisely enough for a machine to reject it:
| Stage | Fails when |
|---|---|
fmt | a file is not formatted the way .clang-format says |
config | the .toml is invalid, a pinned version disagrees with the file that controls it, or a vendored component's licence is not on record |
repo | something a build produced is tracked by git |
seam | a file of the framework reads the clock, the input devices, the screen size or raylib's random state on its own |
workflows | a reusable CI workflow asks for a permission its caller does not grant, or a step throws a build's output away, which is where the compiler's error is printed |
portable | a script uses something macOS's old bash or the BSDs do not have, or the BSD jobs' inline script is not plain ASCII |
shell | a script writes A && B || C, which runs C when B fails |
naming | a name breaks the naming rules in any branch of any #if |
style | a rule of the style guide that clang-tidy cannot see is broken in any branch of any #if: a C cast, NULL, a TODO, something newer than the oldest compiler a game is built with, a user-defined literal, i++ where ++i says the same |
ownership | the framework allocates or frees memory by hand, or calls a raylib Load* or Unload* outside the file that owns what it makes |
pointers | a declaration a game can name has a raw pointer or a C string in it — Pointers and RAII says what goes there instead |
cppcheck | cppcheck, a second static analyser with its own reading of the code, finds anything in src/rmp, or a suppression of one has no reason or no longer matches anything |
headers | a public header does not compile on its own, or lacks the .toml values |
cost | a public header's preprocessed size moved away from its budget |
gates | a check above stops failing on the mistake it exists for — each runs on a copy of the tree with one planted in it |
configure | tools/configure.py accepts something it should refuse, or the other way round, or the suite itself leaves a file the checkout generated changed |
rmp | the rmp command itself misbehaves — including when a file the framework tracks has not been classified as part of a new game or not |
binaries | the readers that judge a shipped .exe and Mac binary misread one — above |
size | tools/size_budget.txt lacks a line for a binary an enabled target ships, has one for a binary nothing ships, or gives a packed size where [upx] packs nothing, or the other way round; or the reader behind it misjudges a size — Continuous integration says what the budget holds |
Commands has the full list of stages with the
summary rmp help test prints for each.
A push to the framework runs every stage of rmp test that checks something — all but
the two that record a golden, and the one that takes hours — in its lint job, or in a
job of its own: examples, which builds and boots every example, e2e, which
plays the ones with a script — the two halves of rmp test examples —
coverage, which measures what the tests reach, and deep, the short runs
of the deep tests:
the
properties of rmp test property, RapidCheck's at a fixed seed and Hypothesis's
derandomized; rmp test fuzz, every input committed for a fuzz target replayed under
the sanitizers; and rmp test sanitize, above.
The
one that takes hours is rmp test mutation, Mull over the C++ and mutmut over the
Python, each module against a floor that only rises,
which
.github/workflows/deep.yml runs every Sunday, a job a module.
A
test of the command checks each stage, and each half of one, against the job that runs it.
clang-tidy,
which is rmp lint and not a stage, has a job of its own too, tidy.
What
a push runs of the deep tests is the same on every run — the same seeds, the same inputs — so that
a red is the commit's and never the dice's. The search is deep.yml's: every night it
fuzzes each target for ten minutes and runs the properties at a random seed, and what it finds
becomes an issue labelled nightly-finding, one per signature, with the command that
plays it again.
Like
the canary, it runs only in the framework's own repository.
Each
of these starts as soon as the configuration is read, beside the others and beside the platform
builds, so the run takes as long as its longest job rather than their sum. The same push
makes a new game with rmp new and runs that game's own checks, follows the recipe at
the top of examples/plain_c/src/main.c in a copy of that game, boots the result and
starts its release from the project folder and from another, checks this documentation site
against the commit, and builds the fast lane: Linux x64, the web, Android and Windows x64. A
release tag builds every target, and so can a run started by hand.
A
release of the framework waits for all of it: clang-tidy, the examples and their scripts, the new
game, the coverage, the short runs of the deep tests and the documentation as well as every
platform. The Linux jobs run
inside a build image pinned by digest, with every compiler and tool already in it, so a build does
not depend on a download succeeding.
The framework's own changes are checked in three sizes of run. They are pushed two pieces of work at a time, so that one fast lane covers both. When that run is red, the fix is checked on a debug lane: a run started by hand for exactly the platforms involved — Linux, Windows and macOS, with Android or iOS only when the bug is there — and every one of the framework's own jobs beside them:
gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macosThe full matrix of every target, about twenty minutes, runs once, when a whole piece of work is done — and on every release tag. A failure on a BSD after a green fast lane is a bug of that platform, fixed on its own.
The sanitized debug builds CI boots are drawn by raylib's software renderer, which links no window system and no graphics driver — all but one. The smoke stage runs once more in the job that boots the examples, under a virtual X display with Mesa's software OpenGL: a sanitized debug build that opens a real window, where LeakSanitizer meets the system's own libraries when the game exits.
The BSD builds run inside virtual machines, and a script that stops early can still exit 0 in one. So the check that ends the script writes a file once it has reached its verdict, and the step after it fails if the file is not there: nothing inside a script can catch its own early exit.
A
game made with rmp new has the same command, and runs the stages that make sense for
a game:
rmp test
rmp test unit
rmp test smokeconfig.toml through configure.py --check, the pinned versions,
and the licence record: a library added to thirdparty/ without its row in
THIRD_PARTY_LICENSES.md fails here. See Licences.unittests/game/, built with the game and run with no window:
below. With no .cpp in that folder the stage has nothing to
check, and says skip nothing matches tests/game/*.cpp instead of failing.rendersmokeBoth are debug builds, and a game's [dev] sanitize is [] until it lists
a sanitizer: with one listed, a report fails the stage the way it does in the framework. See
Configuration.
A game's CI runs the same stages in its own lint job, and builds its targets the
way the framework's does. The framework's own tests stay with the framework: they test the
framework, and a game is built on one that has passed them.
A
game made with rmp new has a folder for tests of its own, tests/game/,
and starts with one in it. Every .cpp there is built, with doctest, together with
every .cpp and .c under the game's src/ but
main.cpp and the framework's src/rmp/, into one program,
game_test, linked to the framework library. main.cpp stays out because
RMP_GAME there is the game's main(), and doctest brings its own: a test
file holds test cases and nothing else, and includes a scene the way src/main.cpp
does.
// ---------------------------------------------------------------------------
// Your game's own tests. Every .cpp in tests/game/ is one, and holds
// TEST_CASEs and nothing else: doctest brings the main(). `rmp test unit`
// builds them with your src/ -- every file in it but main.cpp -- and runs them
// with no window, and CI runs them on every push. Delete tests/game/ and
// neither asks for them again.
//
// rmp test unit build them and run them
// ./build/debug/game_test -tc="*menu*" one case, by name
//
// With no window there is no GPU: a texture comes back empty and a frame
// draws nothing, while files still load and your code still runs. What a test
// drives is what the framework takes in through a seam -- time is the delta
// you hand a hook, the dice are rmp::random::seed(), the devices are
// rmp::input::detail::DeviceState -- and what it reads is what your code
// keeps. Drawing is the boot's to check: `rmp test smoke`.
// ---------------------------------------------------------------------------
#include <doctest.h>
#include <rmp/assets.h>
#include "scenes/main_menu.h"
TEST_CASE("the main menu finds every file it loads") {
// A file renamed in resources/ and not in the code is a hole in the
// picture rather than a crash, so a game that boots can still be missing
// one. rmp::assets counts what it was asked for and what it could not
// read, and a scene's _ready() is where it asks.
const int asked = rmp::assets::requested_loads();
const int failed = rmp::assets::failed_loads();
MainMenuScene menu;
menu._ready();
CHECK(rmp::assets::failed_loads() == failed);
// A menu of yours that loads no file has nothing for this test to check:
// it says so, and passes. Test what your menu does instead.
WARN_MESSAGE(rmp::assets::requested_loads() > asked,
"the main menu loaded no file, so this test checked nothing");
}
It runs with no window, so there is no GPU: a texture comes back empty and a frame draws
nothing, while files still load and the game's code still runs. What a test drives is what the
framework takes in through its seams — the delta handed to a hook, the seed of
rmp::random, the input devices — and what it reads is what the game keeps. Drawing is
the boot's to check, in render and smoke.
rmp test unit
./build/debug/game_test -tc="*menu*"rmp test unit builds the program and runs every case; the program itself takes
doctest's options, such as one case by name. The game's CI runs the same program in its
lint job. Delete tests/game/ and neither asks for it again: the stage
and the job both say there is nothing to run, and pass.
https://omardev29.github.io/rmp-docs/framework/security.html
A game is a program that reads files and takes input from people who did not write it, and the language it is written in lets a mistake in memory become a crash, or worse. The framework cannot make that impossible. What it can do is make a release harder to exploit, catch the mistakes in development where they happen instead of where they crash, keep what the build depends on from changing under it, and keep secrets out of the repository. This page is every measure it takes, what each one protects against, what it costs — measured, where the framework measured it — and where it lives. The last section says plainly what is not done.
| Measure | Where it applies | In a game made with rmp new |
|---|---|---|
| The release, hardened | every desktop release: Linux and the BSDs, macOS and Windows in part | yes: it is the same CMakeLists.txt |
| Library checks in debug | every debug build on the desktop | yes |
| AddressSanitizer and UndefinedBehaviorSanitizer | every debug build of the framework on the desktop | off until [dev] sanitize lists them |
| Static analysis | the framework's own code: rmp lint, rmp test, the lint and tidy jobs | no: the framework's code is checked before a game gets it |
| What the tests reach | the framework's own code: rmp test coverage, the coverage job; the deep tests, the deep job | no: it measures the framework's tests |
| The shipped binary, read back | every release job in CI | yes: the same workflows |
| The supply chain, pinned | CI | yes, at the pins the game was made with |
| Secrets, signing, installing | the .toml, the Android job, the installer | yes |
The binary a player runs is compiled and linked so that a memory bug in it is harder to turn into anything worse than a crash. Release builds only: a debug build has the sanitizers instead, which find the bug rather than blunt it.
Every flag was measured before it went in, because a release is kept as small as it can be, and the rule is that a flag costing more than 3% of the stripped binary is not used. PIE is the one exception, taken on purpose; below is why.
Measured
on linux-x64-glibc as CI builds it — zig's compiler, link-time optimisation,
stripped — where the game is 1,149,120 bytes with none of these flags, and 352,524 after UPX
packs it:
| Flag, and what it does | Cost |
|---|---|
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3The C library checks the size of the buffer that memcpy, strcpy, sprintf and their kind write into, wherever the compiler can work it out, and stops the program instead of writing past it. | +3.6 KB (+0.32%) |
-fstack-protector-strongA guard value between a function's local arrays and its return address, checked before it returns: a write past a local buffer that reaches the return address stops the program instead of sending it somewhere else. | +20.2 KB (+1.80%) |
-fstack-clash-protectionA large allocation on the stack touches it page by page, so it cannot step over the guard page into another region of memory. | +0.3 KB (+0.03%) |
-Wl,-z,relro -Wl,-z,nowEvery library function is resolved when the program starts, and the table of their addresses is then made read-only, so a stray write cannot redirect a call. | nothing: zig's linker writes both already |
-Wl,-z,noexecstackThe stack is not executable, so code written onto it cannot run. | nothing: zig's linker writes it already |
-D_GLIBCXX_ASSERTIONS-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FASTThe C++ standard library's cheap checks: an index past the end of a container, or the first element of an empty one, stops the program instead of reading what follows. One define for libc++, one for libstdc++; each library ignores the other's. | +2.9 KB (+0.25%), with zig's libc++ |
| All of the above, together | +22.7 KB (+2.03%): 1,172,400 bytes, 357,056 packed |
-fPIE -pieThe executable is position-independent, so it is loaded at a different address on every run: PIE. | +61.9 KB (+5.52%) |
Fortify
is level 3 where the compiler has __builtin_dynamic_object_size — which lets it check
buffers whose size is only known while the game runs — and -D_FORTIFY_SOURCE=2 where it
does not. -U_FORTIFY_SOURCE comes first because Ubuntu's gcc defines it already, and a
second definition would be a warning. It is used only where the C library is glibc: musl ignores
it, and the BSDs' C libraries have their own.
On
linux-x64-musl the same flags cost +19.4 KB (+1.72%) together. The releases that
Ubuntu's gcc builds — linux-riscv64-glibc and the DRM pair — had every one of them
already, since that gcc turns them on by default, except the C++ library's checks:
_GLIBCXX_ASSERTIONS costs +8.0 KB (+0.72%) there.
Every flag is first tried on the toolchain at hand, and one it does not take is left out rather than breaking the build. A release configure says what it got; on Linux with glibc:
=== RELEASE HARDENING: stack-protector-strong, C++ library bounds checks, FORTIFY_SOURCE=3, stack-clash-protection, -Wl,-z,relro, -Wl,-z,now, -Wl,-z,noexecstack, pie ===
What the linker made of them is not taken on trust either: CI reads it back out of the binary.
Without PIE the executable sits at the same address on every run. The system's address randomisation still moves the libraries, the stack and the heap, but not the game's own code, which is the code an exploit most wants to find. So a Linux or BSD release is linked position-independent, at +5.5%, and the 3% rule gives way.
Most
of the cost is one table: 58.5 KB of the 61.9 is .rela.dyn, a relocation for every
pointer the loader has to fix when it places the program. The linker can pack those
(DT_RELR, -z pack-relative-relocs), but the packed form needs glibc 2.36,
and the oldest glibc a release supports, [linux] glibc, is 2.28. So they ship
unpacked.
PIE
is CMake's POSITION_INDEPENDENT_CODE, which gives gcc and clang -fPIE to
compile and -pie to link. It is on by default, and -DRMP_RELEASE_PIE=OFF
turns it off for a build directory — to measure what it costs, not to ship.
The flags above are what a Linux or BSD release gets. Elsewhere, the platform already does part of it, and the rest is chosen to fit:
windows-x64 in CI: -Wl,--dynamicbase (the
executable is loaded at a random address), -Wl,--nxcompat (data is not executable)
and -Wl,--high-entropy-va (the random address is drawn from the whole 64-bit space).
They are the linker's defaults already, and are asked for anyway where the linker takes them. The
stack protector is not used there, because with MinGW it can mean shipping
libssp-0.dll next to the game, and nothing checks for that.
With
MSVC, which builds windows-arm64: its defaults, /GS,
/DYNAMICBASE, /NXCOMPAT and /HIGHENTROPYVA, the same
protections. Control Flow Guard, /guard:cf, is not used: it could not be
measured.-fstack-protector-strong and -D_FORTIFY_SOURCE=2 by
itself, and Android has required PIE since 5.0.With
all of it in, these are the sizes of the framework's own demo game, each as its release job
measured it: unpacked, as the linker wrote it, and packed, after UPX, for the releases that are
packed. tools/size_budget.txt holds them, and every release is
held to its line. A game's own sizes are its own.
| Binary | Unpacked, bytes | Packed, bytes |
|---|---|---|
linux-x64-glibc | 1,384,712 | 453,528 |
linux-arm64-glibc | 1,271,376 | 415,768 |
linux-riscv64-glibc | 1,032,080 | — |
linux-x64-musl | 1,381,440 | 453,108 |
linux-x64-glibc-drm | 955,080 | 386,300 |
linux-arm64-glibc-drm | 860,984 | — |
windows-x64 | 2,375,168 | — |
windows-arm64 | 1,376,768 | — |
macos | 2,090,696 | — |
freebsd-x64 | 991,456 | — |
freebsd-arm64 | 888,688 | — |
openbsd-x64 | 1,083,064 | — |
openbsd-arm64 | 1,052,136 | — |
netbsd-x64 | 1,176,656 | — |
web | 574,669 | — |
android/arm64-v8a | 1,107,728 | — |
android/armeabi-v7a | 817,720 | — |
android/x86 | 1,211,840 | — |
android/x86_64 | 1,213,976 | — |
The OpenBSD arm64 line is worked out from an older measurement rather than read off a build, as its comment in the file says, and is held to the same rule until a run replaces it.
A
test asserts what it can see, and a mistake in memory or in arithmetic often gives it nothing to
see: a read one past
the end that finds a zero, a use of freed memory that still holds the old value, a signed overflow
that wraps to a harmless number. So every debug build of the framework on the desktop — the library,
every example, every test — runs under AddressSanitizer and UndefinedBehaviorSanitizer, because the
framework's own .toml says sanitize = ["address", "undefined"]. They are
compiled in, and each report stops the program at the line that did it, with the stack that got
there.
With
clang, the framework's development compiler, and with gcc, which names
float-cast-overflow because its undefined does not include it:
clang:
-fsanitize=address,undefined
-fno-sanitize-recover=all
-fno-omit-frame-pointer
-fsanitize-ignorelist=cmake/sanitize_ignore.txt
gcc:
-fsanitize=address,undefined,float-cast-overflow
-fno-sanitize-recover=all
-fno-omit-frame-pointer-fno-sanitize-recover=all makes every report the end of the run, and
-fno-omit-frame-pointer keeps the stack in a report readable. What was applied is
defined, for code that has to allow for it — a timing test, say:
-DRMP_SANITIZE=1 any of them
-DRMP_SANITIZE_ADDRESS=1 AddressSanitizer
-DRMP_SANITIZE_UNDEFINED=1 UndefinedBehaviorSanitizerWith
MSVC, which has AddressSanitizer and nothing else: /fsanitize=address to compile and
/INCREMENTAL:NO to link, which it requires, and the run-time checks (/RTC1)
taken out of the debug flags, which it cannot be combined with.
The
runtimes' own options are set in cmake/sanitizer_hooks.c, linked into every
instrumented program: AddressSanitizer also checks use after return and the order globals are
initialised in, and both sanitizers stop at the first report and print the stack. The environment
still wins — ASAN_OPTIONS, UBSAN_OPTIONS, LSAN_OPTIONS —
so one run can be changed while chasing one report.
LeakSanitizer can be told to ignore memory a system library keeps for the life of the process. The rule for that list is that a line names a system library by its file name, seen leaking in a real run, and never anything of the framework's or the game's; a test refuses a line that could match the framework's code, and a leak planted in a function of the framework's own has to be reported through the list. The list is empty.
The clang builds would also skip what cmake/sanitize_ignore.txt lists, each line with its reason, and the list may only name vendored code. It is empty. It held one line, which turned every sanitizer off for the Tiled reader over one null-pointer member access in its OFFSET_OF, and that hid a parser that read past the end of a map cut short and leaked on every refusal; cute_tiled is patched instead (thirdparty/cute_tiled/PATCHES.md) and fuzzed under the sanitizers like the framework's own code.
A
compiler that accepts -fsanitize=address is not one that can run it: Ubuntu's clang
takes the flag and then has no runtime to link, and a runtime can link and still refuse to start.
So cmake/sanitize.cmake builds a small program with the flags and runs it, in C++ and
in C. The C++ one makes a virtual call, which is what UndefinedBehaviorSanitizer's type check needs
from its runtime. When the build is cross-compiled, linking is the most it can know. A probe that
ran is remembered against the compilers, the flags and the hooks it ran with; one that failed is
never remembered, so installing the runtime is seen by the next configure.
When
the probe cannot run them together, each that runs on its own is kept; one that does not run at
all is a warning, and the debug build goes on without it — a condition of the machine, not a
mistake in the .toml. Unless the environment requires them, as CI does wherever a
debug build is a gate: there the configure fails, because a gate that quietly stopped
instrumenting passes by not looking.
RMP_REQUIRE_SANITIZERS=1 cmake --preset debugA configure that got them says so:
=== SANITIZERS: address, undefined ===
To
measure what they cost, one build directory can go without them:
-DRMP_SANITIZE=OFF.
cmake --preset debug -DRMP_SANITIZE=OFFThey
are never applied to the web, Android or iOS builds: the web build is a release, and Android and
iOS build through their own projects, which do not read [dev].
NetBSD's
GCC 10.5 ships an UndefinedBehaviorSanitizer runtime without its C++ half, so the type check of
virtual calls cannot link there. The probe sees it, and the build keeps every other check with
-fno-sanitize=vptr, and says so in a warning, rather than dropping the sanitizer
whole.
NetBSD
also gives every program address randomisation unless the program's ELF note says otherwise, and
its AddressSanitizer will not start with it. So every sanitized program there gets
paxctl +a after it is linked, and the probe gets it before it runs. A NetBSD without
paxctl does not get AddressSanitizer.
Independently of the sanitizers, every debug build on the desktop — the framework's and a game's — gets two more checks that need no runtime. Android's and iOS's debug builds are made by their own projects, and get neither.
-D_GLIBCXX_ASSERTIONS and
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE: the standard library
checks operator[], front() and back(), and in libc++ the
extensive set, which goes further than the release's fast one.-ftrivial-auto-var-init=pattern,
where the compiler has it (gcc 12 and later, clang): a local variable nobody initialised is filled
with a pattern that crashes when it is used, instead of a zero that happens to work.Fortify is not among them: it needs optimisation, and a debug build has none.
AddressSanitizer
is the expensive one. The framework's unit tests take 5.5 seconds without it and 18.6 with it,
3.4 times as long, and the framework's .toml puts its memory at two to three times;
UndefinedBehaviorSanitizer is cheap.
The
examples played from a script say the same from the other side: a frame of raylib's software
renderer, unoptimised and instrumented, is slow enough that the build that plays them compiles the
renderer's three files at -O2, still instrumented, and Pong's script then plays in 17
seconds instead of 85 — Testing says why the
pictures stay the same. None of it reaches a release.
A
sanitized program prints its report and exits with an error, and LeakSanitizer reports after the
program's last line of its own, when it exits. So the checks that boot a game do not stop at the
markers it prints: rmp test smoke and rmp test render fail on a
sanitizer's report anywhere in the output, with the first forty lines of it, and on any exit status
but 0 — a sanitizer reported the run above (exit …). Every example booted by
rmp test examples, and every one it plays from a
script, is held to its exit status the same way.
So
is every other start of a game in the tools and the workflows — a release started from another
folder, the musl build on Alpine, the DRM build on its virtual display, the RISC-V build under
emulation — but the iOS simulator's,
below; a test fails one that throws the status away. Testing has the runs
these checks are part of, and the second one with gcc, rmp test sanitize.
And
the arrangement is itself tested: tests/sanitize_test.cpp holds the defines to what
the compiler says it instrumented, and runs tests/sanitizer_canary.cpp, a program that
leaks, overflows a buffer or overflows an integer on request, and each one has to be caught.
A
game made with rmp new starts with sanitize = []: off, so that a fresh
clone on a compiler without the runtimes builds without a warning to explain. Turn them on when you
want your own game's mistakes found where they happen instead of where they crash:
[dev]
sanitize = ["address", "undefined"]Those
two are the ones that work on a game as it is, with the system's own libraries left
uninstrumented. [dev] sanitize
refuses the others by name, each with its reason — thread, memory,
leak, hwaddress, integer,
implicit-conversion and fuzzer:
[dev]
sanitize = ["address", "thread"] raylib_multiplatform.toml:2: sanitize = ["address", "thread"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [dev] sanitize: 'thread' is refused -- ThreadSanitizer has to see every library the game runs, the system's audio and GL drivers included, or it reports races that are not there -- and it cannot be combined with address.
Use "address" and "undefined", or [] for none.It
also refuses what a platform cannot give: undefined with
[dev] compiler = "msvc", any sanitizer with "mingw", whose GCC ships no
runtime, and address on OpenBSD, whose clang has none.
The sanitizers find what a run reaches. These read the framework's code without running it, on every push, and none of them costs the shipped game anything.
rmp lint runs clang-tidy with the framework's .clang-tidy over
src/, tests/ and examples/: the bugprone
checks, the static analyzer's path-by-path search for null dereferences, leaks and uses of freed
memory, the performance and portability checks, and the checks that hold
the style guide.
It
reads the C as well: the resource packer every desktop release runs, the plain C example and the
sanitizer hooks. A file with no compile command is a failure, never a guess at its
flags. Each
file is read by a clang-tidy of its own, as many at once as the machine has processors — or as
CMAKE_BUILD_PARALLEL_LEVEL says, when it is set — the costliest first, so the run does
not end on one processor while the others wait.
On
every push it runs in the framework's tidy job, beside the others.tools/lint_debt.txt,
a line per check and file with the number of warnings left. A warning it does not owe fails, a
count that grows fails, and a count higher than what is left fails too, so every fix lowers it for
good. Every line in it is one check, custom-rmp-raw-pointer: a raw pointer where
the guide wants a reference, a span or a handle.src/rmp/ and the headers it includes: rmp test cppcheck. The rule is
zero findings. One that is not a bug is suppressed on the line before it, with the reason after a
;; a suppression with no reason fails, and so does one that no longer matches
anything, so an excuse cannot outlive what it excused. A few are suppressed in the script itself,
by check or by file, each with its reason, and that list only shrinks.-Wall and -Wextra on every target built from the framework's sources
and the game's, and never on raylib or thirdparty/, whose headers are included as
system headers so that their warnings do not bury ours. MSVC keeps its own default level.
-DRMP_WERROR=ON makes every
one an error: the framework's unit tests, its lint job and the gcc run pass it. A game is never
made to, because a newer compiler on its author's machine must not stop a build that worked the
day before.rmp test pointers has clang read every public header and fails on a raw pointer
or a C string in any declaration a game can name: a pointer cannot say whether it may be null, who
owns it or how long it lives. The few pointers a game cannot reach are listed in
tools/pointer_ratchet.txt, each with its reason, and that list only shrinks.
Pointers and RAII says what the API hands out
instead.rmp test ownership fails on a bare new, delete,
malloc or free in the framework, and on a raylib
Load…/Unload… call outside the files that own what it makes, in the
framework or in an example — the two shapes a leak and a double free take. The files that must keep
such a call are listed with the reason, and the list only shrinks.The
sanitizers and the analysers judge the code a run reaches and the code they read; neither says how
much of the framework the tests run at all. rmp test coverage measures it, line by
line, with clang's source-based coverage over the unit tests, the headless layout test and the
one test that drives the real desktop runner. Two lists hold what it measured, and each moves one
way: tools/coverage_floor.txt, the share of each file of src/rmp/ the
tests run, which only rises, and tools/untested_api.txt, the public functions no test
calls, which only shrinks — a new function arrives with its test.
Both
are gates in the framework's coverage job, inside the build image they were measured
in, and a release of the framework waits for it.
Testing has the detail.
Coverage
says which lines ran, not whether a test would notice them wrong, and a test checks only the inputs
somebody thought of. The deep tests look for the rest — fuzzing, properties checked against
generated input, and mutation testing, which changes the code to see whether a test fails — in the
framework's deep job on every push and in a longer search at night;
Testing says where each one runs, and
below how little of the framework they reach yet.
A
flag the toolchain silently ignored is a flag that was never there, and a build machine is not a
player's machine. So CI reads what matters out of the binary it ships, with
tools/binary_check.py and a few scripts beside it, which need nothing but Python's
standard library or a shell. A game's CI runs the same steps.
binary_check.py elf, in every Linux release job, before UPX packs the binary:
RELRO, BIND_NOW and a stack that is not executable, read from its program headers and dynamic
section; and, given --pie whenever the build's cache says
-DRMP_RELEASE_PIE was on, that it is position-independent.
With
--musl it also reads what the musl build asks the system for: its loader has to be
musl's and the one library it names musl's C library — or it is static and names neither..exe importsbinary_check.py windows reads the import table and the delay-load table, and
fails on any DLL that is not part of every Windows 10: a compiler runtime the player would have to
install, named with how to link it in instead. With --require-icon it also wants the
icon.binary_check.py macos reads the minimum macOS out of every slice of the universal
binary and fails on one that asks for more than the build was told.tools/glibc_check.sh reads the glibc version every symbol the binary imports
asks for, and fails on one newer than [linux] glibc: the failure it prevents is a game
that runs on the machine that built it and on no older distribution. It holds the x64 and arm64
releases to that floor and the riscv64 one to its own; the DRM pair link their distribution's
graphics libraries directly, and their floor is reported rather than held.tools/android_release_check.py reads the compile commands Gradle used for the
release bundle and fails on a file of the game or the framework compiled at -O0, with
_DEBUG, or without RMP_PRODUCTION_BUILD.Every
release job holds the binary it ships to its line in tools/size_budget.txt,
unpacked and packed: within 1.5% either way it passes in silence; past that it passes with a
warning that names the new size, on the run's summary page as well as in its log; past 10% it
fails. A binary that grew is a growth nobody wrote down, and one that shrank leaves a line that
would hide the next growth. Growing is allowed — it is written down, in the commit that does it.
A game starts with no budget, and its jobs print the line to write when it wants one.
A green run should mean the same in six months as today, and a build should not depend on a download succeeding.
ghcr.io/omardev29/raylib-build, named by its sha256 digest in
thirdparty/FROZEN_VERSIONS.md and in every workflow that runs in it —
ci.yml, web-backends.yml and deep.yml — and in the
development container, .devcontainer/devcontainer.json;
tools/versions_check.sh reads every workflow and the container and fails if any two
disagree, or if
:latest appears outside the canary.
Inside
the image it also compares every pinned tool with the image's own manifest. The image is
built in its own repository, each
architecture on a runner of that architecture, checked there inside the image it built, and
published only then.ghcr.io/omardev29/raylib-run-alpine, pinned and checked the same way.ghcr.io. A digest makes an image look frozen; it is still a download from a registry
with anonymous rate limits.uses: in its workflows and fails on one that is not
a full commit, or does not say which version that commit is — and runs the same check on a
workflow that names a tag and one that pins a commit without its version, which it has to
refuse.sha256 kept in the repository
before it is used. Inside the image, a script that finds its tool at the wrong version fails
instead of fetching it. Pillow, which the Windows jobs install to make the icon, comes with
pip --require-hashes, so no other file is accepted.
There are exceptions, and What is pinned lists
them: the BSD jobs install from their system's package mirror, which has nothing to pin to, the
job that boots DRM installs a kernel module from Ubuntu's archive, and the web test the libraries
its browser needs.thirdparty/FROZEN_VERSIONS.md and compared with the image's manifest.rmp test config fails on a vendored component whose licence is copyleft,
non-commercial or unknown, and on one under a licence that asks for changes to be marked that is
neither pinned unmodified by its sha256 nor marked modified with its patches written
down. Licences has the whole record.The
.toml is committed with the game, so it holds no secret: every key, password and token
CI needs is a GitHub secret, set in the repository's settings.
Secrets and variables lists them, and
every one is optional.
Two values in it look like keys, and neither is a secret, because each ends up inside the game anyone can download:
[resources] rres_password
encrypts a release's resource pack. It keeps casual unpacking of the game's assets inconvenient,
and nothing more.[save] encrypt
seals a save with a key derived from [project] name. That stops a text editor, not a
determined player.The
Android job builds the release App Bundle on every run. With no upload key in the repository's
secrets it signs it with a throwaway key, made fresh on every run and never reused, says so in a
warning, and checks the bundle's signer is that key; the bundle is renamed
-NOT-FOR-PLAY.aab and uploaded under a name a release never attaches.
With
the upload key, it checks the signature verifies with no signer errors, that the signer is not
the throwaway key, and — when the repository variable ANDROID_SIGNER_CN names it —
that it is that key. Signing says how to
set it up.
The
one-line installer never uses sudo and never installs a package. On Linux, macOS and
the BSDs it writes only in your home folder: the framework in ~/.local/share/rmp, the
rmp command in ~/.local/bin, and a line in your shell's startup file, only
if that folder is not on your PATH already.
On
Windows it runs as yourself, with no administrator, in %LOCALAPPDATA% and your own
user PATH. What a build still needs — CMake, Ninja, a compiler — is printed
at the end with the command for your system, for you to run.
Where it puts things has the
detail.
It
is written for curl … | sh, where the shell runs it as it arrives: all of it is one
function, called on its last line, so a download cut short runs nothing. And the copy this site
serves is the framework's, byte for byte as it is at the commit these pages document — with the
line endings each file is checked out with — which the site's own build checks on every run.
At the commit these pages document, these do not exist:
include/rmp/
is held to the deep tests' rules on generated input but two:
rmp::app::quit() and
rmp::app::quit_requested(), which live in
the one file the property tests cannot link, the runner's. They are on
tests/property/waivers.txt, a list that only shrinks. Every reader is fuzzed: the
save file, the LDtk and Tiled maps, Aseprite sheets, the resource pack and the names the loaders
are given.binary_check.py windows reads what an .exe
imports, not how it was linked. Control Flow Guard is not used.https://omardev29.github.io/rmp-docs/framework/licences.html
The framework is free software under the MIT licence, and it is built on raylib,
whose zlib licence it keeps. Everything else it carries — the layout engine, the JSON reader, the
packer, the libraries raylib itself bundles — is on record with its licence, checked on every
build, and credited in a LICENSES.txt that ships with every package of your game.
The short version of what a game owes: keep that file with it, which the release builds do for
you.
The framework's own code — what is under src/rmp/ and include/rmp/,
the tools and the build files — is under the MIT licence in its LICENSE file. A game
may use it, change it, sell what it makes with it and keep its own code closed. MIT asks one thing
in return: that its copyright notice and licence text travel with copies of the software, which is
what the generated notice below does.
In a
game made with rmp new, the framework's
licence is not at the root of the repository. It sits in
thirdparty/raylib_multiplatform/LICENSE, as a component of the game like every other
one, because a LICENSE at the root would say the whole game is MIT. The game's own
code is its author's, under whatever licence they choose, or none.
raylib is by Ramon Santamaria and is under the zlib/libpng licence. The framework is built on it, is not affiliated with or endorsed by the raylib project, and ships a modified copy. The zlib licence asks three things, and the second is the one that matters here: an altered version must be plainly marked as altered, and not presented as the original.
So it is
marked. thirdparty/raylib/PATCHES.md
says in its first line that the copy is modified, and lists every change by file, line, where it
comes from and why. The copy is raylib 6.2 as raylib_cmake_template carries it — raylib's own fixes
from after 6.2 brought back, and the gaps its security audit left closed — and the framework's
patches on top: build-system and platform-selection changes, so the windowing backend can be chosen
from the .toml; one that makes Android's EGL ask for the OpenGL ES version raylib was
compiled for; the DRM backend's card probe, Escape on its terminal and no flow control;
and
one fix of the framework's own in the software renderer, which upstream does not have: its
nearest-texel lookup is clamped to the texture, so the far edge of a texture reads its last texel
and not the one past it. Each change is also commented at its site, and no document of the
framework may describe its raylib as unchanged.
Every vendored component has a row in the
components block of THIRD_PARTY_LICENSES.md: its licence, which
alternative the project takes when the upstream offers a choice, whether the copy is modified,
which platforms it reaches, and where its licence text is. The main ones:
| Component | Licence | Copy | Reaches |
|---|---|---|---|
| raylib | zlib | modified | every platform |
Clay, under rmp::ui | zlib | modified: one line, a C++ version check | every platform |
| cute_tiled, for Tiled maps | zlib or Unlicense — the Unlicense is taken | modified | every platform |
| cute_aseprite, for sprite sheets | zlib or Unlicense — the Unlicense is taken | unmodified | every platform |
raylib-cpp, behind rmp/math.h | zlib | the math headers only | every platform |
| rres, the resource pack | MIT | unmodified | every platform |
| cJSON, under saves and LDtk maps | MIT | unmodified | every platform |
| Monocypher, which seals a save | BSD-2 or CC0 — CC0 is taken | unmodified | every platform |
| tiny-AES-c, for an encrypted pack | Unlicense | unmodified | every platform |
| raymob, the Android glue | MIT | modified | Android only |
| raylib-iOS and ANGLE | zlib; BSD-3 | unmodified | iOS only |
| the rest of what raylib bundles: GLFW, miniaudio, the stb libraries, the decoders and loaders | zlib, MIT, public domain and similar | unmodified | where raylib uses them |
| rlsw, raylib's software renderer; RGFW; tinyobj_loader_c | MIT; zlib; MIT | modified: a fix of the framework's own; the gamepad code on older kernel headers; raylib's own OBJ face fix, newer than the release | rlsw and tinyobj_loader_c everywhere, RGFW on the desktop |
| doctest | MIT | unmodified | nowhere: the tests only, the framework's and a game's own |
| RapidCheck | BSD-2 | unmodified | nowhere: the framework's property tests only, and left out of a game |
Where an upstream offers a choice, the project takes the alternative that owes the least, and
says so in the file, so the choice is a decision on record rather than something inferred from a
build. Where it has altered a component, that component's directory has its own
PATCHES.md, as raylib does — even under MIT, which does not ask for one, because a
reader should not need to know which licence imposes what.
That
block is not documentation that can fall behind. tools/license_db.py --check runs in
the config stage of rmp test, in the framework and in every game, and
compares three things:
thirdparty/
with no row fails, and so does a row whose component is gone.thirdparty/FROZEN_VERSIONS.md or marked modified with a PATCHES.md
beside it.So adding a library to a game is adding a row to THIRD_PARTY_LICENSES.md, and
forgetting to is a red test, not a missing credit discovered after release.
The
same block is what configure.py generates the shipped notice from. There is one
LICENSES.txt per family of packages — the desktop packages, the web package, the
Android app, the iOS app — and each holds exactly the components that reach that family: the
Android notice credits raymob and no other does; GLFW is in the desktop notice and in neither the
web nor the Android one, because the browser build talks to Emscripten's own JavaScript GLFW and
contains no GLFW code; doctest and anything not compiled into a game are in none. Each component's licence is reproduced in full,
under a line saying whether this build's copy is unmodified, modified or partial; a public-domain
component, which owes no notice, gets a line saying so and where it comes from instead. The
framework's own MIT notice is in all of them, and the file
opens by saying the game is built on raylib, is not affiliated with it, and uses a modified
copy.
Where it goes:
.wasm.A component whose licence text cannot be found stops the configure step: a missing notice is a licence problem, and the moment to act on it is before anything is built.
The
iOS notice credits the raylib-iOS fork the app is built on, so it is never written without that
checkout. A plain configure with ios among the targets and the checkout missing warns
and writes no iOS notice; the iOS build in CI configures with --require-notices, which
turns that warning into a refusal, rather than ship an app with no notice or one with the fork
missing from it.
The licences the framework carries are all permissive: none of them asks a game to publish its source. What most of them ask is credit — their notice, kept with copies of the software — and the default does that.
LICENSES.txt with the game. The release builds put it where
it belongs; leave [deploy]
licenses at its default and there is nothing else to do.configure.py
will not take one without the other:[deploy]
licenses = false raylib_multiplatform.toml:2: licenses = false
^^^^^^^^^^^^^^^^
configure: error: [deploy] licenses = false removes LICENSES.txt from every package, and it is the only third-party notice the game ships.
Say where the credits are instead: credits_note = "the Credits scene, from the main menu". If there is no such scene, leave licenses = true.[deploy]
licenses = false
credits_note = "the Credits scene, from the main menu"thirdparty/ needs its
row in THIRD_PARTY_LICENSES.md; rmp test says so if it is missing, and
the generated notice credits it from then on.resources/rabbit.png, is from Kenney's Animal Pack under CC0,
and resources/License.txt beside it says so; whatever you put in
resources/ after that, its terms are between you and its author.https://omardev29.github.io/rmp-docs/framework/why/index.html
A framework is mostly decisions, and a decision you cannot see the reason for looks like an accident. These pages give the reasons: why a menu is three calls, why a hook starts with an underscore, why nothing throws, why every struct of options is ordered the way it is. Each one is a rule the framework holds itself to, and most of them are checked by a tool rather than remembered.
The three-function menu. The API has to be as simple as possible for the person making the game, and a main menu written in three calls is the measure. Every other decision on these pages is answerable to it.
_name is a method of yours the framework calls; on_name is a function
you hand to it. Two spellings, two directions.{ .speed = 320 }, why the order of the fields matters,
and why a behavior has no base class..toml — and
the one rule about them: a header never makes you use one.delta, where the clock is read, and what
[app] max_delta protects you from.A rule written only in a document is kept until the day someone has not read it. So wherever a
mistake can be described precisely, something in the framework's own checks rejects it — a
check of clang-tidy, a stage of rmp test,
clang-format or the compiler. The Guidelines list
every one of those rules with the tool that holds it, and where: in the framework, in its examples
and in a game.
https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html
The API has to be as simple as possible for the person using it. Complexity is allowed to exist for the advanced case; it is not allowed to stand in the way of the simple one. And there is a measure for it, which is not a slogan: a main menu is three calls.
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) rmp::app::quit();
rmp::ui::end();Anything that makes those lines longer is wrong, whatever else it buys. That is the rule above every other rule in the framework, and the rest of these pages answer to it.
The menu is short because everything it does not mention has an answer already. It is centred
in the window. It has no coordinates, sizes, fonts or hit boxes, and it keeps its proportions at
any window size, because every measurement is in design units scaled from
[window] width and height. It has a theme. The first button is focused,
so the keyboard or a gamepad can press it with nothing else written, and the arrows move between
the two. And a click on Play does not also reach the game drawn underneath, because the
UI takes the pointer before the world sees it.
None of that is hidden from the game that wants to change it. begin()
takes options for where the menu goes, button()
takes options for how it looks, a theme can be swapped at run time, and
the Clay layout engine underneath can be used
directly. The options are there for the case that needs them; the simple case does not have to
know they exist.
A feature gets into the framework by answering three questions, in this order.
The second question is the one that keeps the API small. A pause menu is not a feature of the
framework: it is a scene pushed on top of the game, and the defaults of a scene already make the
world underneath freeze, stay visible and stop hearing its actions and the pointer
(Scenes). A rigid-body physics
world is not a feature either. An object's position, rotation and
velocity are public fields, so a game that needs a tower that collapses can link a
physics library, step it in _update and write the position from it. If a real game
asks for that, it arrives as an example.
The rule is easiest to see in the defaults, because a default is where the simple case lives.
An object's
position, velocity, flip_x and the rest are public fields,
read and written directly: player.flip_x = player.velocity.x < 0; is the point. A
getter and a setter in front of each one would be ceremony between the game and its data, so the
clang-tidy check that asks for private members is switched off, and says why.
A scene carries a downward gravity, and every object's
gravity_scale is 0. A top-down game never
mentions gravity, and a platformer sets one field on the player.
Every object is on collision layer 1 and collides with layer 1, so the simple game never
mentions a layer. Objects are not solid by
default, because most things in a 2D game — bullets, coins, particles, triggers — are not walls,
and the two that are, the floor and the player, are the two you configure.
The three fields that say what a scene lets through to the one below default to exactly what
a pause menu wants, so a pause scene is a scene with a _draw() and nothing else.
The collision is the framework's own, not a physics engine's, and this rule is the reason given in its source: with a rigid-body library a Pong ball stops being a shape with a velocity and becomes a body with a density, a restitution, a friction, a damping and gravity switched off.
A behavior inherits from nothing and registers nowhere, so that it can be written
add<rmp::behavior::TopDown>({ .speed = 220 }). The price of a base class would
have been that line. Designated initialisers
explains why.
raylib makes Escape the
key that closes the window. In a game it is the key for "back" and "pause": a menu of
rmp::ui goes back on it and the ui_cancel action is bound to it, so the
entry point gives the key back to the game once the window is open, and a pause menu needs no line
to keep Escape from ending the game. The game that does want to quit on it writes that one line,
with rmp::app::quit().
rmp::app::quit() can be called from anywhere,
returns, and the game shuts down cleanly when the frame ends. There is no value to carry back up
the call stack and nothing to catch.
Every one of these could have been more general. Each would then have been something the simple game had to know about.
https://omardev29.github.io/rmp-docs/framework/why/the-access-rule.html
There are two ways for the framework to run your code, and the name says which one
it is. A method whose name starts with _ is one of yours that the framework calls:
you override it and never call it yourself. A function whose name starts with on_ is
one you hand to the framework, which keeps it and calls it when something happens.
These are the hooks, and there are exactly eight names:
| Hook | On a scene | On an object | On a behavior |
|---|---|---|---|
_ready | entering the stack | after spawn() | when it is added |
_update | every frame | every frame | every frame, before the move |
_late_update | every frame, after the move | ||
_draw | in screen space | after its sprite or shape | after the object is drawn |
_collision | once per touching pair per frame | the same | |
_end | leaving for good | on destruction | when removed, or the object dies |
_suspend | something was pushed over it | ||
_resume | it came off again |
A scene and an object override them as virtual functions; a behavior simply declares the ones it wants, and the framework finds them when it is compiled. Either way the rule is the same: you write it, the framework decides when it runs. One frame gives the exact order.
class Coin : public rmp::Object {
void _ready() override { shape = rmp::circle(8); }
void _update(float delta) override { rotation += 90 * delta; }
void _collision(rmp::Object &other) override {
if (other.solid) destroy();
}
};Sometimes a subclass is more than you want: one coin out of many needs to do something special when it is touched, or a scene wants to know when an object it spawned is clicked. Then you hand the framework a function instead, and the name says that is what you are doing.
auto &coin = spawn({ .position = { 300, 200 }, .size = { 16, 16 } });
coin.on_collision([](rmp::Object &self, rmp::Object &other) {
if (other.solid) {
score += 10;
self.destroy();
}
});
coin.on_click([](rmp::Object &self) { self.visible = false; });The functions the framework takes this way are
on_click,
on_drag and
on_collision on an object,
on_object on a map, and the
on_ fields of the behaviors that report something —
Health's on_death and
on_damage, Timer's
on_timeout, Spawner's
on_spawn. A game that writes its own entry point names its three hooks the same way,
on_ready, on_frame and on_exit, because those too are
functions it hands to the framework. Setting a callback a second time replaces the first: there is
no list of handlers, because a list of handlers is a signal system, and that is a bigger idea than
this needs.
The
two spellings never collide, which is the reason there are two. An object can override
_collision and carry an on_collision, and both run: the override first,
then its behaviors', then the function it was handed. Nobody has to choose between subclassing and
a callback, and reading either one, you know which way the call goes.
Because it is the one mark that is legal exactly where it is needed. In C++ a name that starts
with an underscore is reserved at global scope, for the compiler and the C library — and a hook is
never at global scope: it is a member of your class, where _ready is an ordinary,
legal name. That is also why the hooks of an entry point, which are free functions, are
on_ready and not _ready.
The scene's last hook is _end and not _exit for a related reason:
exit() is a function of the C library, and a member with that name in a class you
write would hide it.
The framework holds itself to the same rule.
clang-tidy is given the eight hook names and refuses any other method that starts with an
underscore, so a helper of the framework's never looks like a hook, and a private field is never
named like one: an object keeps the functions it was handed in members called
_click_handler, _drag_handler and _collision_handler.
Naming, in the Guidelines, has the whole table this rule is
a part of, and what each tool says about a name that breaks it.
One more spelling marks what is neither yours nor for you. A namespace called
detail, or a member whose name starts with detail_, belongs to the
framework and its tests. It is public only because C++ needs it to be — a template in a header has
to reach it — and it is not part of the API: the reference does not show it.
https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html
There is no header that includes the whole framework. There are
16 headers under include/rmp/, one for each part of the framework you
can name — the UI, the input, the assets, the audio — and a file includes the ones it uses. That
is what makes each module optional: you take the whole ecosystem, or you take one piece of it.
A file that draws the HUD looks like this:
#include <rmp/ui.h>
#include <string>
void draw_hud(int score, float health) {
rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER });
rmp::ui::row({ .gap = 24 }, [&] {
rmp::ui::text(std::to_string(score));
rmp::ui::progress(health);
});
rmp::ui::end();
}It knows about the interface and nothing else, so it recompiles when the UI changes and not when the asset pipeline does. And when it reaches for something it did not include, the compiler says so, by name:
#include <rmp/ui.h>
void draw_pause_hint() {
rmp::ui::begin();
if (rmp::input::just_pressed("pause")) rmp::ui::text("Paused");
rmp::ui::end();
}The compiler refuses it, saying among other things: input
That error is the truth: the file is missing rmp/input.h. An umbrella header would
have hidden it, and every file would have paid to compile all of the framework to use one part of
it. An example holds the framework to this:
it includes only rmp/ui.h, and the examples build fails if that stops being
enough.
Splitting is not free for the person using the framework: every header is one more thing they
have to know exists. So a new header has to be a part of the framework you can name and decide to
use or not — rmp::ui, rmp::audio, rmp::save. Anything else
goes into a header that already exists. Splitting for tidiness only taxes the reader, and the
number of includes a game needs is a number that should go down over time, never up.
A header under include/rmp/ declares what it needs from another one instead of
including it, wherever the language allows. Where it does not — a type held by value has to be
complete — the header includes the other one and says at its top why it could not avoid it. Those
are the exceptions, and they are few:
| Header | Includes | Because |
|---|---|---|
rmp/scene.h | rmp/object.h, rmp/tilemap.h | a scene spawns objects, and holds its map by value |
rmp/object.h | rmp/assets.h | a sprite holds its texture by value |
rmp/tilemap.h | rmp/object.h | a map's object factories are callbacks |
rmp/behavior.h | rmp/object.h, rmp/scene.h | the catalogue holds handles and callbacks by value, and a spawner hands you the scene |
If a pair of headers ever needed each other, one of them should not exist: they would be one module pretending to be two.
The
technique that makes most of this possible is moving the call into a .cpp. The
entry-point macros in rmp/app.h have to start the asset layer, sample the input
every frame and close the UI, but naming rmp::assets, rmp::input or
rmp::ui there would make every file with an entry point compile all three. So the macros call a handful of functions declared in rmp/app.h
and defined in src/rmp/app/app.cpp, which is the one file that includes the rest.
Every
public header includes rmp/config.h, the values from the .toml, so
RMP_WINDOW_WIDTH and the rest are simply there wherever you are writing and you
never type that include. It is the exception to the rule above, and it earns it by measurement:
it has one include, rmp/generated/config.h, the #defines the
.toml hands the code, which includes nothing, and parsing the two costs no more than
parsing an empty file. tools/header_check.sh compiles every public header on its
own and uses RMP_WINDOW_WIDTH after it, so a header that forgets it — or that only
compiles when something else was included first — fails the framework's tests rather than a
game's build.
The rule is about the framework's own headers. It was never a rule against the standard library
or raylib: <memory>, <vector>,
<string_view> and raylib.h are used where the job needs them. What
the framework does instead is measure what each include costs, and keep the number from creeping
up unnoticed.
tools/header_cost.py preprocesses a file that includes one public header and
nothing else, and counts the lines of code that come out. That count is the same on every run with
the same compiler, so it is what the gate compares, against tools/header_budget.txt,
inside the pinned build image the budget was measured in: a header that grows by more than a fifth
fails, and so does one that shrinks by as much, because a budget left too high would let the next
growth through. A header with no line in the budget fails everywhere. Milliseconds are reported too, because they
are what a person feels, but they are never gated: they depend on the machine.
The measurements are written down where the decisions are made, and some of them decided the API:
rmp::Callback
exists because <functional> measured 131 ms in every file that includes
rmp/object.h, which is every file with an object in it, and the part of
std::function the framework needs is small. It turned out to have a second reason,
in Ownership.rmp/math.h
is a header of its own because the C library's <math.h> under raymath is most of
its cost, and rmp/ui.h must not make a file that only draws menus pay for it.https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html
Almost everything in the framework that takes options takes a plain struct, and
the struct is written with C++20's designated initialisers: { .speed = 320 }. It is
the closest C++ has to named arguments, and it is why the API reads the way it does. It comes with
one rule the language imposes, and the framework is arranged around that rule so you rarely
meet it.
A call says what each value is, leaves out everything it does not change, and keeps working when a new option is added:
auto &wall = spawn({ .position = { 400, 225 }, .size = { 20, 200 } });
wall.solid = true;
wall.immovable = true;
auto &player = spawn({ .position = { 100, 300 }, .size = { 24, 40 }, .layer = 1 });
player.add<rmp::behavior::TopDown>({ .speed = 220 });The same shape runs through the whole framework: what
spawn() takes
(rmp::ObjectOptions), every container and widget
of rmp::ui, the volume and pitch of a sound, the options of a save, a raycast's query,
and every behavior in the catalogue. Each field has its default written next to it in the header,
so the defaults are visible in the one place you would look.
The rule: C++20 requires designated initialisers to be written in the order the fields are
declared. Here the struct declares grow_x, width, grow_y,
height:
rmp::ui::begin();
rmp::ui::column({ .width = 240, .grow_y = true }, [] {
rmp::ui::text("Inventory");
});
rmp::ui::end();Written the other way round, it does not compile:
rmp::ui::begin();
rmp::ui::column({ .grow_y = true, .width = 240 }, [] {
rmp::ui::text("Inventory");
});
rmp::ui::end();The compiler refuses it, saying among other things: declaration order
GCC and MSVC refuse it on their own. Clang, left to itself, only warns
(-Wreorder-init-list) and initialises the fields in declaration order anyway — and
Clang is what [dev] compiler builds your debug builds with unless you choose another,
while CI builds the Windows x64 release and the NetBSD one with GCC. A game that built clean on the
laptop would fail on those builds twenty minutes into CI.
So
the framework makes Clang refuse it too, in each of the three build systems. The rmp
library carries -Werror=reorder-init-list for Clang and AppleClang as a public option,
which every game, example and test that links it inherits, and Android's native build, which the
NDK's Clang compiles, carries the same flag.
The
iOS app is built by Xcode from a project of its own, and configure.py writes the same
flag into that project's OTHER_CPLUSPLUSFLAGS, ahead of any of the game's own in
[ios.settings], which are kept after it. Your own build gives the answer above, and so does every build in CI that could have
disagreed with it.
A configure that builds the tests checks that this
holds: it reads the options back off the rmp target and compiles one initialiser out
of order and the same one in order with them. The first must fail and the second must compile, or
the configure stops and says which.
Because
the rule cannot be switched off, every options struct in the framework is declared in the order its fields are most likely
to be written, rather than alphabetically or by importance: an image's options start with its
size, a button's with its style, a container's with its gap and padding. In rmp::ui,
an id is the last field of every struct that has one. And the sizing fields of a
container are interleaved by axis, grow_x, width, grow_y, height, rather than grouped
by kind: grouped, the most ordinary layout there is — a fixed-width sidebar that fills the height,
{ .width = 240, .grow_y = true } — would be illegal. This way round every combination
is in order.
Designated initialisers work on an aggregate: a struct with public fields and no constructors, no virtual functions and no virtual or private base. Give a struct a virtual function and the syntax stops working, with an error both compilers agree on:
struct Spin {
virtual ~Spin() = default;
float degrees_per_second = 90;
void _update(rmp::Object &self, float delta) {
self.rotation += degrees_per_second * delta;
}
};
Spin fast{ .degrees_per_second = 180 };The compiler refuses it, saying among other things: non-aggregate type
That is the whole reason a behavior inherits from nothing.
The obvious design — a Behavior base class with a virtual update — would
have turned add<TopDown>({ .speed = 220 }) into a constructor taking an options
struct, and every later read into something like get<TopDown>()->options.speed.
Without the base class, the fields are the configuration, and they stay live:
add<rmp::behavior::TopDown>({ .speed = 220 });
get<rmp::behavior::TopDown>()->speed = 400;A
behavior with a virtual function would compile up to the moment someone wrote its options, so
add() refuses one outright, with a sentence that says why. The hooks a behavior may
have are found at compile time with requires instead of through virtual
functions.
The same reasoning is why the small struct an rmp::Sprite
uses to track its animation is public: a private member would stop the sprite being an
aggregate.
A braced list on its own has no type, and a function template that forwards its arguments
cannot deduce one for it. So data passed to a scene through
change(), push() or
replace() cannot be a bare braced list:
rmp::Scene::change<GameScene>({ .level = 3, .hard = true });The compiler refuses it, saying among other things: no matching function for call to
Give the struct a name and it works, designators and all:
class GameScene : public rmp::Scene {
public:
struct Start {
int level = 1;
bool hard = false;
};
explicit GameScene(Start start) : _start(start) {}
private:
Start _start;
};
void play_level_three() {
rmp::Scene::change<GameScene>(GameScene::Start{ .level = 3, .hard = true });
}That is C++, not a decision of the framework's. spawn() does not have the problem,
because it is not variadic: it takes an rmp::ObjectOptions, and the braced list knows
what to become.
https://omardev29.github.io/rmp-docs/framework/why/ownership.html
Everything the framework hands you is owned by something that releases it at the
right moment, and you never free anything yourself. A texture lets go of the GPU when the last copy
of it goes; an object is freed by its scene; a scene by the stack; a callback by the object that
holds it. There is no Unload to remember, no delete to write, and no
order to get right on the way out.
The
framework holds itself to it. No owning raw pointer appears in its headers or its sources, and no
bare new, delete, malloc or free:
tools/ownership_check.sh rejects them, and its list of exceptions only ever gets
shorter. The two left are where raylib's C interface hands a buffer across and frees it itself.
Inside the framework, the choice of how to hold something follows one order of preference, from first choice to last:
| Form | When |
|---|---|
| a value | whatever fits: a Vector2, a Shape, a behavior, an options struct |
T & | something that certainly exists and keeps its identity for the length of the call |
std::span<T>, std::string_view | the caller's elements, or the caller's text, for the length of the call |
rmp::Ref<T> | something that may not be there and is not yours, within the frame |
rmp::Handle<T> | an object that can die, kept across frames |
std::unique_ptr<T> | sole ownership of something polymorphic or large |
There
is no T * in that list, and no C string: a game names neither in the API, and the
rest of the framework is held to the same rule. Pointers
and RAII, in the Guidelines, says why, what to write in each case instead, the few places a
pointer is allowed, and which tools refuse one where.
The optional reference is the one form of the framework's own. An
rmp::Ref<T> is empty or refers to something; it owns
nothing, and asking it is an if:
auto &player = spawn({ .size = { 26, 26 } });
player.add<rmp::behavior::Health>({ .hp = 3 });
if (auto health = player.get<rmp::behavior::Health>()) health->heal(1);get<B>() hands one back, empty when the
object has no B, and so does Handle::get(),
empty once the object is gone. It is not a T *, which cannot say whether it may be
null or whose it is, and not a std::optional<std::reference_wrapper<T>>,
which says the same for the price of <functional> in every file with an object
in it, and reads as health->get().hp.
Where there is always an answer, the answer is a reference:
scene() is a Scene &, because a
spawned object always has its scene. And a field that names an object is a handle, as
RayQuery::ignore, the object a ray passes
through, is the shooter's handle(). None of them is yours to free. Where the
framework does take ownership of something, it takes a std::unique_ptr, so the
hand-over is written in the signature.
An
rmp::Texture — like a Font,
Sound, Music, Shader or RenderTexture — is a
counted reference to one loaded resource. Copying it is one more reference; the last one to go
unloads it. Loading the same name twice gives the same texture back with the count at two, which
is what lets a hundred enemies share one sprite without anyone deciding who owns it.
rmp::Texture _rabbit;
void _ready() override { _rabbit = rmp::assets::load_texture("rabbit.png"); }
void _draw() override { DrawTexture(_rabbit, 100, 100, WHITE); }It converts to the raylib type it wraps, so every raylib function takes it. But only a variable converts. A temporary does not, because the texture would be unloaded at the end of the line and the raylib struct you kept would point at nothing:
Texture2D player = rmp::assets::load_texture("player.png");
DrawTexture(player, 0, 0, WHITE);The compiler refuses it, saying among other things: deleted function
Ownership
is also what makes the way out safe. A texture belongs to the GPU context, and the context belongs
to the window: unloading a texture after CloseWindow() is a write to something that no
longer exists. Because every texture is held by something with a lifetime — a scene, an object, a
global — the framework can release them in an order that works: the scenes and their objects
first, then the globals, then whatever is still loaded, and only then the window.
A scene owns its objects. spawn() makes one,
the scene keeps it, and what you get back is a reference that is good for the rest of the frame,
because an object that is destroyed is only freed when the frame ends.
Kept until the next frame, that reference can dangle. What you keep instead is a handle:
class Turret : public rmp::Object {
public:
rmp::Handle<rmp::Object> target;
void _update(float) override {
auto aim = target.get();
if (!aim) return; // it died, or there never was one
rotation = Vector2Angle({ 1, 0 }, Vector2Subtract(aim->position, position)) * RAD2DEG;
}
};A handle is the
object's slot and that slot's generation. When the object dies the generation goes up, so the
handle is empty from then on — and it stays dead even after the slot holds a
new object, which is the classic bug of keeping an index. Checking a handle is an integer
comparison. A handle can be typed, handle<Goblin>(), so the field you read
after the check needs no cast.
The scene stack owns its scenes. RMP_GAME makes the first one, and
change(), push() and
replace() make the next ones with std::make_unique and move them in on
the same line, so no code of yours ever holds a scene by pointer.
rmp::global<T>() is the state that outlives a
scene change: one instance per type, made the first time it is asked for, owned by the framework
and destroyed on the way out — in reverse order of first use, after the scenes and before the
window, so a global can hold a texture.
A function you hand to the framework — an on_collision, an on_click,
the on_ fields of the behaviors — is kept in an
rmp::Callback, not a std::function, and
there are two reasons.
The first is ownership. std::function has to be able to copy what it holds, so a
lambda that owns something only it should own cannot go into one:
#include <functional>
#include <memory>
std::function<void()> on_win = [save = std::make_unique<int>(3)] { (void)save; };The compiler refuses it, saying among other things: copy-constructible
A Callback moves and never copies, so the same lambda is fine:
auto &coin = spawn({ .position = { 400, 225 }, .size = { 16, 16 } });
auto bonus = std::make_unique<int>(10);
coin.on_collision([bonus = std::move(bonus)](rmp::Object &self, rmp::Object &) {
score += *bonus;
self.destroy();
});The
second is cost: <functional> is expensive to include, and every file with an
object in it would pay for it. A Callback is what the framework actually needs — the
captured state behind a shared pointer that carries its own destructor, and one function pointer to
call it — and nothing else. Setting it again replaces what it held, and destroys what that
captured.
A behavior added to an object belongs to the object.
add<B>() moves it into storage that never
moves it again, so the reference it returns, and the rmp::Ref
get<B>() returns, stay good for as long as the behavior is attached. Removing the behavior, or destroying
the object, runs its _end and frees it. A behavior's type is never erased into a
void * you would have to delete: the storage holds it in a shared pointer that knows
its destructor.
https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html
No function of the framework throws to tell you something went wrong. A texture
that fails to load is an empty texture; a key missing from a save reads as the default you gave
it; a mistake in how the game uses the framework is a warning, said once. You never need a
try around a call to rmp::.
Three reasons, and each would be enough on its own.
BeginDrawing() without its EndDrawing(), a UI frame open and a
scene change half applied. Something has to put all of that right, and a framework that never
throws never has to.Every failure is turned into a value at the place it happens, and the value is chosen so that the obvious code is also the correct code.
It has no texture in it,
valid() is false, and drawing it draws nothing — the same as raylib does with a zeroed
struct. A missing picture is a hole in the frame, not a dead process. The failure is still counted:
the boot line CI reads reports how many assets failed to load, and a boot with any failure is
red.
A file that is there and does not decode — a picture, a sound, a song or a font cut short or corrupt — is a failed load in the same way: what comes back is empty, the failure is counted, and the log says so once per name. A font is no exception. raylib answers a font it cannot read with its own built-in one, and the framework does not take that for the file you asked for: you get an empty font, and nothing is kept under the file's name, so the same name is tried again the next time it is asked for.
rmp::Texture _logo;
void _ready() override {
_logo = rmp::assets::load_texture("logo.png");
if (!_logo) TraceLog(LOG_WARNING, "no logo; the title is drawn as text");
}Reading a save never throws and never crashes on what it finds. read() returns a
Result that is true in an if only
when the save was read and checked, and whose
status says why when it was not: missing, cut
short, edited, or not a save at all. And every value read out of an
rmp::Value takes the default to use when the key is not
there or holds the wrong type, which is what lets an update to a game read the saves of the version
before it.
rmp::Value save;
const rmp::save::Result got = rmp::save::read("slot1", save);
if (got.status == rmp::save::Status::MODIFIED) {
TraceLog(LOG_WARNING, "the save was edited or damaged; starting over");
}
const int level = save["level"].as_int(1);
const float volume = save["settings"]["volume"].as_float(0.8f);Where the caller may want to know, the answer is an empty
rmp::Ref or a false:
get<B>() comes back empty when the object
has no such behavior, a Handle is empty once its
object is gone, and rmp::save::write() returns
whether the save reached the disk.
And
forgetting to ask does not crash either. Reaching through an empty one with -> or
* is a mistake in the game, said once in the log for each type, and the line goes to
a stand-in: a B made for the purpose, so a read gives the default and a write lands
nowhere. A type with no default constructor has no stand-in, and for that one the program ends
there, after the same message.
Asking for an input action
nobody defined, playing an animation tag that is not in the sheet, popping the last scene: these
are mistakes in the game, and the framework says so in the log — once per place in the code, not
sixty times a second — and carries on doing the harmless thing. The macro behind it, RMP_REPORT_ONCE
in src/rmp/internal.h, is described in Macros.
A warning in a log is easy to miss, so a debug build can make it impossible to miss.
[dev] strict = true turns the
first one into an abort with the message, in debug builds only:
[dev]
strict = trueNo sound device, a
disk that refused a write, a portable build in a folder it cannot write to: none of those is a
mistake in the game, and strict mode never aborts on them. The framework logs them once, plainly,
and the calls that depend on them do nothing, or return false, instead of failing — a
game on a machine with no sound card runs, silently, under strict mode too.
rmp::app::quit() is the case where an exception
is most tempting — unwind everything and leave — and it is a flag instead. The frame that asked
finishes, and the game shuts down in order.
The
C++ standard library does throw, in a few places the framework relies on — asking the operating
system for random bytes, converting a Windows path to UTF-8 — and those are caught where they
happen, in three places in src/rmp/save/save.cpp, and turned into a value: another source
for the random bytes, an empty path that the caller already treats as "cannot be used". None of
them escapes into your game.
It is also why the framework vendors only the math headers of raylib-cpp: its resource classes throw on a failed load, and the math ones have no failure to report.
The framework is not compiled with exceptions switched off, and nothing stops your own code using them. What it promises is the other direction: nothing it calls will throw at you to report a failure. The UI goes one step further. A container's contents are a lambda of yours, and if that lambda throws, the container is still closed on the way out, so the next frame's layout is not corrupted.
https://omardev29.github.io/rmp-docs/framework/why/macros.html
The framework is built on raylib, which is C, and it does not pretend otherwise:
raylib's macros — RAYWHITE, CLITERAL, DEG2RAD — are used
as they are, in the framework and in your game. The framework adds macros of its own only where a
macro is the one tool that can do the job, and keeps one rule about them: no header makes you use
one, except for the line that starts your game.
The clearest case. Depending on the platform, the entry point of a program is one of three
different things: a main() that runs a loop, a main() that hands one
frame function to the browser and returns, or three extern "C" functions that iOS
calls. No function and no template can define main() on one platform and three other
functions on another; the preprocessor can. So the entry point is a macro:
RMP_GAME(MainMenuScene);
RMP_GAME writes the three hooks for the scene stack and
hands them to RMP_ENTRY_POINT, which picks the shape
for the platform being compiled. A game that wants its own hooks calls
RMP_ENTRY_POINT directly, as One frame
shows. The bodies are written once, in rmp/app.h, and every platform-specific thing
they do is a call to a function compiled in src/rmp/app/app.cpp: the macro is only the
shape of the entry point.
One more macro rides along
with them, RMP_DECLARE_ENTRY_POINT_ONCE,
and its only job is to make two mistakes read like sentences. Each entry point defines a function
called rmp_entry_point_is_declared_exactly_once, and the framework refers to it. A
program with two entry points gets a duplicate definition of that name from the linker; a program
with none is told that name is missing — instead of a message about main that says
nothing to someone who never wrote one.
The
reference is the constructor of an object at namespace scope in src/rmp/app/app.cpp,
because a static initializer is the one kind of code every linker keeps. A reference from an
ordinary function would not do: in a program with no entry point nothing calls that function, and
a linker that discards unused sections throws it away, unresolved reference and all, before it
reports anything. At run time the constructor calls the empty function once.
Every value of
raylib_multiplatform.toml a game can read in code is a macro of
rmp/config.h, through the generated file it includes: RMP_WINDOW_WIDTH, RMP_WINDOW_TITLE,
RMP_MAX_DELTA and the rest. They are macros and not constants for two reasons. A game
in plain C uses them too, and C has no namespace to keep a constant in:
#include <rmp/config.h>
int main(void) {
InitWindow(RMP_WINDOW_WIDTH, RMP_WINDOW_HEIGHT, RMP_WINDOW_TITLE);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
EndDrawing();
}
CloseWindow();
return 0;
}And the preprocessor can test a macro, so code that only makes sense with a setting can be left out of the build when the setting is off. clang-tidy's suggestion to turn macros into an enum is switched off for exactly these.
Inside the framework,
one macro carries every diagnostic a game can trigger every frame — an action nobody defined, a
tag that is not in the sprite sheet, a pop() with nothing underneath. It is
RMP_REPORT_ONCE, in src/rmp/internal.h, and it is a macro because every place it is
written needs a variable of its own, and only a macro can declare one there for you.
#define RMP_REPORT_ONCE(...) \
do { \
static const char rmp_report_once_site = 0; \
::rmp::detail::report_once(&rmp_report_once_site, __VA_ARGS__); \
} while (0)Each place the macro is written gets its own static variable, and that variable's address is
the key. The report function keeps the keys it has seen and prints a line only for a new one, so a
mistake in a game's _update is one line in the log and not sixty a second. A second
form takes a key as well, so a missing action called "jump" and a missing action called "fire" are
two lines. Under [dev] strict
the first report aborts a debug build. It is the framework's own tool and not part of the API:
No exceptions says what it reports and what it
deliberately does not.
Its
message is a printf format, because it ends in raylib's TraceLog(), and
GCC and Clang check that format against the values like printf's own — as an error,
not a warning. A %s handed a number would print rubbish, and only on the one frame the
mistake happens, which in a diagnostic is the frame nobody is watching; it does not compile
instead.
Two
more macros come from the build system rather than from the .toml.
RMP_PRODUCTION_BUILD is 1 in a release build and 0 otherwise, so a game can keep debugging aids
out of what it ships:
#if !RMP_PRODUCTION_BUILD
DrawFPS(10, 10);
#endifEvery build system defines it — CMake from its PRODUCTION_BUILD option, Gradle per
build variant, the Xcode project per configuration — and the framework refuses to compile if one
forgets, with an #error that says so. That refusal exists because of how the
preprocessor treats a name it does not know: in an #if it is not an error, it is 0, and
a release build would quietly include everything meant only for debugging.
The other is RMP_RESOURCES_PATH, the folder assets are read from: the absolute path of the
project's resources/ while you develop, so the game finds its assets from any working
directory, and ./resources/ in a release. That is the CMake builds, the desktops and
the web. The two mobile builds define it their own way, the same in debug and release: the iOS
project as ./resources/, because the folder is copied into the app bundle under that
name and the app moves into its bundle when it starts, and Android's native build as an empty
string, because Gradle copies what is in resources/ to the root of the APK's
assets.
On a desktop the entry point moves into
the executable's folder when there is a resources/ beside it, before the first asset
is read, so that path means the same wherever the game was started from
(One frame has the detail). Each executable
gets its own, which is how an example with its own art reads its own folder.
The CMake options themselves keep CMake's own names, PRODUCTION_BUILD and
RESOURCES_PATH: they live in CMake's cache and never reach the preprocessor. What C++
sees is always spelled RMP_.
Clay, the layout engine under
rmp::ui, is a C library whose API is mostly macros: an element is
CLAY(...) { ... }. rmp::ui does not hand you that. Its containers are
functions that take a lambda, and behind them rmp/ui.h declares a function that opens
an element and one that closes it, both compiled in src/rmp/ui/, where they call
Clay's own functions rather than its macros. So no Clay type or macro appears in the header you
include, and there is no closing call to forget: the container closes when your lambda
returns.
Clay's macros are not forbidden to you, only kept out of your way. A game can include Clay and use them directly, and an example does.
raylib's
colours are macros, because raylib is C. A value the framework adds is a
constexpr constant in a namespace instead:
rmp::behavior::MAX_SPAWNED, how many
objects one Spawner keeps track of, is a constant of rmp::behavior.
Outside the cases above, that is the rule: a value the framework defines is a constant in a
namespace, where it cannot collide with anything.
Both halves are
checked. clang-tidy's cppcoreguidelines-macro-usage refuses a macro of the
framework's that is not one of the cases above — it is told their names, and a new one is a
question for review, not something to slip past it. And a query of the framework's own
.clang-tidy refuses a constant at namespace scope in a header that is not
inline constexpr: a plain const or constexpr there is a
copy in every file that includes it, where inline makes it one object for the whole
program.
The preprocessor has a single namespace, shared by raylib, the C library, every vendored
library and your game, and it runs before the compiler knows what a namespace is. Three rules
follow, and tools/naming_check.sh enforces all three:
RMP_, and never with
__ or an underscore and a capital letter, which belong to the compiler and the C
library. A vendored library's own switches keep their names, in the one file that configures
it.PI,
MIN, MAX, EPSILON: each is a macro on some platform, and a
constant with that name compiles everywhere except there. Naming
lists them.#if. When a macro is renamed, a test
of the old name does not fail: the old name is undefined, and undefined is 0.And one practical note. The platform
entry-point macros in rmp/app.h are the one place the framework's sources are exempt
from automatic formatting, because their bodies hold block comments, and every formatter mangles
a block comment inside a macro.
https://omardev29.github.io/rmp-docs/framework/why/delta-and-time.html
Every update hook is handed the time the frame took, in seconds, as a
parameter called delta. Nothing that moves the game reads the clock for itself: one
function reads it, and hands that number out. It is a small decision with two large
consequences: the framework can be tested without a window, and a game written with it plays the
same at any frame rate.
class Bullet : public rmp::Object {
public:
float seconds_left = 2.0f;
void _update(float delta) override {
seconds_left -= delta;
if (seconds_left <= 0) destroy();
}
};A scene's _update(delta), an object's
_update(delta), a behavior's
_update(self, delta) and the on_frame(delta) of a game with its own entry
point all get the same number, and it is always called delta — not dt,
not deltaTime — so the most common parameter in a game has one name everywhere you
read it.
Once
a frame, in one function of src/rmp/app/clock.cpp, which asks raylib for the frame time,
corrects it, remembers it, and hands it to the frame. It is the one call to
GetFrameTime() in the framework. Every entry point — the desktop loop, the browser's
callback, iOS's — goes through that function, so the correction applies to all of them, and to a
game that writes its own frame as much as to one that uses scenes.
Nothing downstream asks raylib what time it is. The scene stack passes delta to
the scenes, the scenes to their objects, the objects to their behaviors; the integrator moves an
object by its velocity times delta; the camera's smoothing, an animation's frame
timing, a Timer, a
Tween are all driven by the number they were
handed.
A test of the framework creates a scene, spawns objects into it and runs a frame of exactly 1/30 of a second, with no window and no GPU, and checks where everything ended up. It can do that because time arrives as an argument: a function that read the clock itself would give a different answer every run, and a test that fails one time in twenty teaches everyone to ignore red.
The rule is checked.
tools/seam_check.sh fails the framework's tests if any file under
src/rmp/ or include/rmp/ calls GetFrameTime(),
GetTime(), reads the keyboard, the mouse or the gamepad, asks for the screen size, or
uses raylib's random numbers — except a short list of files, each with the reason it is allowed,
and every one of them a seam itself. The same goes for the other things that change between two
runs. The game's input is sampled in one place, rmp::input, into a snapshot a test can
replace, and the UI samples the pointer, the keys it navigates with and what a text field types
through samplers of its own that a test replaces the same way. Randomness comes from
rmp::random, one generator with a seed: a test keeps
the fixed default and gets the same sequence every time, while a shipped game is seeded from the
wall clock when it starts, and current_seed()
tells you which run you are in.
The
UI has no clock of its own either. Its transitions, its scrolling, the repeat of a held arrow key,
the blink of a text field's caret, a tooltip's wait and a notice's time on screen take their time
from frame_time(), which is the delta the frame was handed: the number
step_delta() remembered.
In
a loop of the game's own with no runner to call step_delta(), it is the frame raylib
timed, clamped the same way. A menu and the game under it cannot disagree about how long a
frame took. The layout tests run the UI in a mode where no time passes unless the test says how
much does, so a layout comes out the same on every run.
A
text field is no exception. What it types — the characters and Backspace — comes through the UI's
seam, so a test types into it as a player would, and its caret blinks on
frame_time() like everything else in the UI, shown the moment the field takes the
keyboard and then for the first half of every second it types.
The
file is not on the check's list, so a GetTime() or a key read straight from raylib
there fails it, as in any other file that is not a seam.
One
clock is also what lets a whole game be played the same way twice. A test can fix the step, so that
every frame is exactly as long as it says whatever the machine took — still clamped by
[app] max_delta — and name the seed the run starts from. That is how the framework's tests
play an example game from a script and compare what it
draws, pixel for pixel. A game that reads GetTime() or GetFrameTime()
itself steps outside that: what it draws depends on how fast the machine was.
The
platformer's flag waves on the time its _update() adds up, and not on
GetTime(), for that reason.
A speed times delta is a distance, whatever the frame rate. That is the whole
trick, and the framework is built so you get it without thinking about it:
velocity
in units per second and the object moves the same distance in a second at 30 or 240 frames.apply_force is meant to be called every
frame, and is scaled by delta; apply_impulse
is meant to be called once, and is not. An impulse applied every frame would go twice as fast at
120 frames a second as at 60 — which is exactly the bug the two names exist to prevent.position += (target - position) * 0.1f, run
once a frame, follows twice as fast at 120 frames a second as at 60. The camera instead covers
1 - exp(-smoothing * delta) of the distance each frame, which comes to the same
fraction in a second at any frame rate.The framework checks this on a real game: the bot that plays the platformer example plays it to the flag at 60 frames a second and again at 240, and jumps from its moving platform at both.
Real elapsed time has no ceiling. Drag the window, stop at a breakpoint, let the disk stall, and the next frame time comes back as half a second. A bullet at 900 units a second then moves 450 units in one step — through the wall and out the other side, without ever overlapping it.
So the
delta the game is handed is clamped to
[app] max_delta, a
twentieth of a second unless you change it. A frame that really took longer arrives as a twentieth
of a second, and the game runs a moment of slow motion instead of teleporting. Nobody minds a
hitch; everybody minds falling out of the world.
[app]
max_delta = 0.050 switches the clamp off and hands the real time through, which makes a stalled frame the game's
problem. Sensible values are between a sixtieth and a tenth of a second, and
configure.py refuses the ones that cannot be meant — longer than a second, which
clamps nothing, or shorter than a frame at 240 Hz, which would clamp every frame:
[app]
max_delta = 0.001 raylib_multiplatform.toml:2: max_delta = 0.001
^^^^^^^^^^^^^^^^^
configure: error: [app] max_delta = 0.001 is shorter than a frame at 240 Hz, so every
frame would be clamped and the game would run in permanent slow
motion. That is never what anyone means. Use 0 to switch it off.It also refuses a frame cap that cannot coexist with the clamp: with
[window] fps at 15, every frame
is longer than a twentieth of a second, and the game would run at three quarters speed forever —
the config pipeline shows that refusal.
The clamp is half of the answer to tunnelling. The other half is the swept test in the collision pass, which catches a fast object crossing a thin one between two frames even at a perfectly normal frame rate, where no clamp applies.
The first frame of a game reports a
frame time of 0, and a delta of 0 or less is never integrated at all. That matters more than it
sounds: a push given in _ready() with apply_force waits in the object for
the first frame that has time in it, instead of being spent on a frame that could not move
anything. A negative frame time, which a clock that went backwards across a suspend could produce,
is handed to the game as 0.
https://omardev29.github.io/rmp-docs/framework/why/naming.html
The naming rules -- one spelling per kind, no prefixes, an underscore that never touches a dot -- are now part of the C++ style guide: Guidelines › Naming. This page stays so that links to it keep working.
https://omardev29.github.io/rmp-docs/framework/contributing/index.html
These pages are for whoever changes the framework itself: Omar, a teammate, and
the agents that work on it, on a laptop or in the cloud. They say what to install, where things
are, which rules hold and why, how a change is proved, and how it reaches main. To
make a game with the framework you need none of this: Getting
started is for that.
They are written for a person first and an agent second. An agent working in the repository
reads the framework's CLAUDE.md, which holds the same rules in fewer words; these
pages give the reason beside each one and every command in full, ready to paste. Like the rest of
this site they are checked against the framework: every rmp command on them is one
rmp help lists, every path exists, and the sentences about how the framework works
are pinned to its source.
Before any of the rest: the API has to be as simple as possible for the person making the game. Complexity may exist for the advanced case; it may not stand in the way of the simple one. The measure is a main menu, and it is three calls:
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) rmp::app::quit();
rmp::ui::end();A change that makes those lines longer is wrong, whatever else it buys. A feature gets in by answering three questions, in this order: is there a real game that needs it; can it be made from what already exists, in which case it is an example and not new API; and does it make the menu longer, in which case it is redesigned until it does not. The three-function menu has the whole argument.
Top to bottom is the order a change goes through, from an empty machine to a merged pull request:
rmp, a clone, the
pinned clang tools, Python, and the build image CI uses.rmp new copies into a game, and what a new file needs before it is accepted.main requires, the API-change approval, and the commits.Upgrading a dependency, rebuilding the build image and the changes the stores force every year are in Maintaining.
main. If an issue labelled
nightly-finding is open, it comes first.rmp fmt, rmp lint and rmp test on your machine, and the
slower stages the change calls for: rmp test examples, rmp test sanitize,
rmp test fuzz, rmp test coverage..toml.The
framework's CLAUDE.md is loaded by Claude Code in every session in the repository, and
.claude/skills/ holds the detail it loads on demand: the code style, API design, the
verified facts about Clay, and the verification ladder. Neither is copied into a game.
CLAUDE.md also keeps the list of mistakes that have already cost time once, each with
how it was found; read the entry for an area before changing it. Everything on these pages applies
to an agent the same way: the ladder before a pull request, the template filled in honestly, and
nightly-finding issues first.
https://omardev29.github.io/rmp-docs/framework/contributing/setup.html
Working on the framework needs what making a game needs, plus three things: the exact clang-format and clang-tidy the framework pins, Hypothesis for the Python property tests, and the build image CI runs in. The first two go on your laptop; the image is how your laptop sees what CI sees.
The commands below are for Linux, which is what the image and every Linux job of CI are. On a Mac or on Windows the image is the way to the same results.
rmp is written in
it.rmp push asks it whether a
CI run is in flight, and every command on CI uses
it.cppcheck
is optional on a laptop: rmp test skips its stage with a message when it is not
installed, and CI, which has it, fails instead of skipping. The same is true of Hypothesis, and of
the locales the unit tests build with glibc's localedef. A skip is a stage that did
not run, so say so when you report what you ran.
Install rmp the way a game maker does, with the one line on
Install rmp. Then clone the framework somewhere of your
own to work in:
git clone https://github.com/omardev29/raylib_multiplatform ~/raylib_multiplatform
cd ~/raylib_multiplatform
rmp helpInside
the clone, the rmp on your PATH hands every command to the clone's own
tools/rmp.py, so rmp test there is your working copy's
rmp test, whichever framework the installer put on your PATH.
rmp help run inside it lists the two commands only the framework has,
rmp lint and rmp example.
Three
commands are the exception: rmp new, rmp install and
rmp update act on the framework the rmp you typed belongs to, wherever you
type them. To make a game from your working copy — to try what a change does to a new game — run
the clone's own launcher by its path:
./rmp new ~/games/try_itKeep
the clone up to date with git, not with rmp update: rmp update only moves
a clone that sits on main with nothing of its own, and refuses one on a branch or with
local commits, which is what a working copy is.
git switch main
git pull --ff-onlyThe
framework pins clang-format and clang-tidy to 22.1.8 in thirdparty/FROZEN_VERSIONS.md.
The version matters: a clang-format one minor version away reformats files that were already
right, and every diff becomes noise; a clang-tidy of another version reports other things. The
build image installs both from PyPI, and a laptop can do the same, in a virtual environment of its
own, together with the Hypothesis the image carries:
python3 -m venv ~/.venvs/rmp-dev
~/.venvs/rmp-dev/bin/pip install clang-format==22.1.8 clang-tidy==22.1.8 hypothesis==6.168.5
export PATH="$HOME/.venvs/rmp-dev/bin:$PATH"Put the export line in your shell's startup file so every terminal has it. With
that folder first on your PATH, its python3 is the one the rmp launcher
finds first, so the Python tests import Hypothesis, and its clang-format and
clang-tidy are the ones rmp fmt and rmp lint run.
Check it with the configuration stage, which compares the tools on your PATH with the pin:
rmp test configA clang-format or clang-tidy of another version is a DRIFT line naming the version
it found, and a failed stage, before it has reformatted anything.
Every
Linux job of CI runs inside one image, ghcr.io/omardev29/raylib-build, pinned by its
digest in thirdparty/FROZEN_VERSIONS.md. It carries every compiler and tool those jobs
use, so a job downloads nothing, and it is the one place where a few checks are exact: the e2e
shots compared pixel for pixel, the coverage floors, the cost of each header, the versions against
the image's own manifest, and mutation testing, whose tools only it has. Running a check in it on
your machine gives the answer CI will give.
The image is public. Read its digest from the file, so it is always the pinned one, and pull it:
IMAGE=ghcr.io/omardev29/raylib-build@$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
podman pull "$IMAGE"Run the image on a second checkout, not on the one you build in. CMake remembers the folder a
build directory was configured in: inside the container your checkout is /work, and a
build/debug configured on your laptop at another path is refused there, and the other
way round. A git worktree is a second checkout of the same repository, sharing its branches:
git worktree add --detach ../raylib_multiplatform-image main
cd ../raylib_multiplatform-imageBefore each run, move it to the commit you want checked, detached, because a branch can be checked out in one worktree at a time and yours is in the first:
git switch --detach my-branchA worktree keeps its git data in the first checkout's .git, so the container needs
that folder too, read-only, at the same path:
IMAGE=ghcr.io/omardev29/raylib-build@$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
repo_git=$(git rev-parse --path-format=absolute --git-common-dir)
podman run --rm --init --network=none \
-v "$PWD":/work -v "$repo_git":"$repo_git":ro -w /work "$IMAGE" \
bash -c 'python3 tools/configure.py >/dev/null && xvfb-run -a ./rmp test'Every option there has a reason:
--init
puts an init process first in the container. Without it, bash -c '… && xvfb-run …'
hands its last command the place of process 1, and xvfb-run there waits for a signal
that never comes: the run hangs instead of failing, and a timeout cannot end it. Any container that
starts a game needs it.--network=none proves the run downloads nothing, which is the rule for every Linux
job.xvfb-run -a gives the stages that open a window — the UI on a real GPU, and the
smoke boot — a display, which the image does not have.:Z to the first -v.A plain clone instead of a worktree works the same, without the second -v.
With
Docker, tools/dev_shell.sh runs a command in the pinned image, read from the same file,
as your user rather than as root, with an init as the container's first process, and with no
command it opens a shell there. With podman, use the command above.
tools/dev_shell.sh bash tools/versions_check.sh
tools/dev_shell.shMost of the ladder runs on a laptop. What needs the image, and what each one does outside it:
| Check | In the image | Elsewhere |
|---|---|---|
The e2e shots, rmp test examples | compared with the goldens exactly | played, and the differences reported, not failed |
Recording the e2e goldens, rmp test e2e-update | records them | refused |
Coverage, rmp test coverage | held to tools/coverage_floor.txt and tools/untested_api.txt | measured and printed, with a Clang that has compiler-rt and the llvm tools of its own release; without them it fails rather than measure nothing |
The cost of each public header, rmp test cost | held to tools/header_budget.txt | a header with no line, or a line for a header that is gone, fails; the sizes are only reported |
Mutation testing, rmp test mutation | Mull and mutmut, against every floor | fails: Mull, built for the image's LLVM, and mutmut are only there |
Fuzzing, rmp test fuzz | libFuzzer | libFuzzer where Clang has compiler-rt; otherwise every input replayed, without fuzzing |
The pinned versions, rmp test config | also against the image's own manifest | against the files that use them |
The image's compilers are not your laptop's either, and two versions of GCC do not refuse the same code. A change to C++ that has only been built on the laptop has not been built where CI builds it.
Next: the repository.
https://omardev29.github.io/rmp-docs/framework/contributing/repository.html
The framework is one repository, omardev29/raylib_multiplatform. It is also the template every game is made from, so it holds two kinds of thing side by side: what a game gets, and what only the framework needs to check itself. Knowing which is which is most of knowing where a change goes.
The
framework's CLAUDE.md also names files beside the checkout: the maintainer keeps it
inside a folder of plans and progress notes. That folder is not part of the framework. No build,
test or workflow of the framework reads it, and a change to the framework never needs it.
| Path | What it is |
|---|---|
include/rmp/ | The public headers, one per module, and nothing else: no umbrella header, so a game includes the modules it uses. include/rmp/generated/ is written from the .toml and never committed. |
src/rmp/ | The library's implementation, compiled once into rmp, which the game and every example link. src/rmp/ui/ is the UI, the one place Clay is allowed; src/rmp/internal.h holds the seams — the clock, the reports, the resources root. |
src/main.cpp, src/scenes/ | The demo game: what every new game starts as. It stays small; a new mechanic goes to examples/. |
examples/ | One mini-project per example, by area — scenes/, input/, ui/, assets/, ads/, platform/, games/ and plain_c/. Each is built and booted by CI; most are played by a script. |
tests/ | The unit tests (tests/*_test.cpp, doctest, no window), the UI layout and render tests, the e2e scripts and their goldens (tests/e2e/), the properties, fuzz targets and mutation floors, the Python tests of the tools, and tests/game/, the tests every game is given. |
tools/ | tools/rmp.py, which is rmp; tools/configure.py, which turns the .toml into every build system's input; the gates, mostly tools/*_check.sh; and the lists the gates hold the tree to. |
cmake/ | What CMakeLists.txt includes: the sanitizers, the game's tests, the web build's helpers. cmake/generated/ is written from the .toml. |
thirdparty/ | Every vendored library, each with its licence row in THIRD_PARTY_LICENSES.md and, where altered, a PATCHES.md; and thirdparty/FROZEN_VERSIONS.md, every pinned version and digest, read by the checks. |
.github/workflows/ | ci.yml, which runs on every push to main and every pull request, and the reusable _*.yml per platform it calls; deep.yml, the nightly and weekly search; canary.yml, a weekly build against the versions the framework is not pinned to; autofix.yml; and web-backends.yml. |
raymob/, ios/ | The Android and iOS projects, partly generated from the .toml. |
resources/, branding/ | The demo game's assets and its icon. |
| The root | raylib_multiplatform.toml, CMakeLists.txt, CMakePresets.json, the launchers rmp, rmp.ps1 and rmp.cmd; README.md and TECHNICAL.md, the framework's own notes; CLAUDE.md and .claude/, the same rules for an agent; .clang-format and .clang-tidy. |
TECHNICAL.md has the whole tree, file by file, and a test fails when it names a file
that is gone or misses a public header or a source of src/rmp/.
Architecture has how the modules depend on one
another.
Every
build goes into a folder of its own under build/: build/debug for
rmp test and rmp run, build/release, build/lint
for the compile database clang-tidy reads, build/examples-check for the examples and
their scripts, build/coverage, build/fuzz, and the rest that
BUILD_DIRS in tools/rmp.py lists with what writes each one.
build/ itself is never a build: CMake refuses to configure there, and a workflow, a
tool or a page that names a folder of build/ that list does not have fails a test. A
new folder is a new line in that list.
rmp cleandeletes every build and everything generated from the .toml; the next command that
needs them makes them again.
A
game made with rmp new is a copy of the framework, made from an explicit list in
tools/rmp.py: INCLUDE names what a game needs, and
FRAMEWORK_ONLY names what it does not, each entry with the reason. The longest pattern
that matches a path decides. It is a list of what goes in, not of what stays out, because an
exclude list fails in silence: the next gate or fixture added to the framework would ride along
into every game, and nothing would say so.
So
every file the framework tracks has to be in one list or the other. A new file that is in neither
fails rmp test rmp, and the question it forces is the right one: does a game need
this? A game needs it when its build, its tests or its CI use it; otherwise it goes in
FRAMEWORK_ONLY, with a reason a reader will understand.
rmp new --listprints what a new game gets, without making one.
Some
files are the same in both and behave differently. .github/workflows/ci.yml is copied
byte for byte, but for the block of triggers [ci] on_push writes; the framework's own
jobs — its tests, its examples, its lint gates — are skipped in a game by a condition the first job
computes, never cut out of the copy. A step that names a file a game does not get must be one of
those skipped in a game. And every commit of the framework is proved to make a working game: the
rmp_new job makes one and runs that game's own checks on it.
The checks hold the tree to a few lists, so a new file is not finished until it is on the ones that concern it. Each line below is a test that fails without it.
| A new… | Needs |
|---|---|
| file of any kind | its entry in INCLUDE or FRAMEWORK_ONLY in tools/rmp.py, as above |
source in src/rmp/ | its line in TECHNICAL.md's tree; its line in tools/coverage_floor.txt, in the same commit; and its place in exactly one of the mutation floor files under tests/mutation/floors/ |
public header in include/rmp/ | to be a module a game can choose to use, with a name; its line in README.md and in TECHNICAL.md's tree; its line in tools/header_budget.txt, measured in the build image; to include rmp/config.h and compile on its own; and for each public function, a test that calls it, and a property that holds it or, written by hand for a reviewer to read, a line in tests/property/waivers.txt |
unit test, tests/*_test.cpp | nothing: every file of that name but the two UI tests, which are programs of their own, is built into unit_test |
| example | a folder examples/<area>/<name>/ with src/main.cpp, which makes it a target of its own; in games/, ui/, scenes/ and input/, a script under tests/e2e/ that plays it |
| vendored library | a licence decision first: its row in THIRD_PARTY_LICENSES.md, its pin by sha256 or its PATCHES.md, and its include folder on all four include lists — the rules say why |
| gate | a stage of rmp test, a step in CI, and a planted mistake it is seen to refuse — Coverage and gates |
folder under build/ | its line in BUILD_DIRS |
Next: the rules.
https://omardev29.github.io/rmp-docs/framework/contributing/rules.html
The framework's CLAUDE.md is its rulebook, written short for an agent
that reads it every session. This page is the same rules for a person, each with the reason it
exists. Most of them are held by a tool, so breaking one is a red check rather than a review
comment; where a Guidelines page has the detail, this page
links it instead of repeating it.
The API has to be as simple as possible for the person making the game, and a main menu is three
calls: rmp::ui::begin(), a rmp::ui::button() per choice,
rmp::ui::end(). A feature that makes that longer is redesigned until it does not. The
overview has the three questions every
feature answers, and the three-function
menu the whole argument. Every other rule here gives way to this one.
src/main.cpp is a dozen
lines and ends at RMP_GAME(MainMenuScene);, and stays that way. It is the first file a
new game's author opens, and what it shows them is how little a game needs. The demo game lives in
src/scenes/, and it is not where a new mechanic goes: that is an example.
Examples
are where to go big. Each is a small project of its own, built as its own target and booted by CI
with a screenshot, and the ones in games/, ui/, scenes/ and
input/ are played by a script whose frames are compared exactly. So an example is
documentation that cannot rot: the day it stops working, CI says so.
A
game in examples/games/ is playable from start to finish — win, lose, play again — or
it does not belong there. A script that cannot win a game is news about the game, and the fix goes
into the game, not into the script.
One spelling per kind of name, with no prefixes: types in PascalCase, constants
and enum members in CONSTANT_CASE, everything else in snake_case, a
private member with a leading underscore, and a leading underscore on a method only for the hooks
the framework calls. A constant is never named like somebody else's macro, and a macro starts with
RMP_. Naming has the table and the reason for
each line. clang-tidy, -Wshadow and tools/naming_check.sh check it, the
last in every branch of every #if, including the ones your platform does not
compile.
rmp/ui.h, rmp/assets.h,
rmp/input.h: each is a part of the framework you can name and decide to use or not.
Anything else goes into a header that already exists. Splitting for tidiness taxes the user,
because every header is one more thing they have to know exists.
One header per module says more.include/rmp/
forward-declares instead; where a type held by value makes that impossible, it includes the other
and says at its top why. That keeps one header from dragging the rest of the framework into every
file that includes it. The rule is about our headers only: the standard library, raylib and
raymath are used as the job needs, and what each costs to include is measured, not forbidden.rmp/config.h is in
every public header, and a game never types it: it brings in the values the
.toml hands the code, from a generated file that includes nothing else, so it costs
next to nothing. tools/header_check.sh compiles each public
header on its own, so one that forgets it fails there.tools/header_budget.txt holds
the preprocessed size of each public header, measured in the build image. In the image a header
that grows past its line fails; anywhere, a header without a line fails.Whatever
the framework allocates, opens or loads has an owner whose destructor gives it back. There is no
bare new, delete, malloc or free under
include/rmp/ or src/rmp/, and a raylib Load* or
Unload* appears only in the file that owns what it makes;
tools/ownership_check.sh refuses the rest, and its list of exceptions only shrinks. A
game never has anything of the framework's to free, so it can never free it twice.
No declaration a game
can name has a raw pointer or a C string in it. In its place: a value, a reference, a
std::span, a std::optional, two overloads, or rmp::Ref for
something that may be missing; std::string_view in and std::string out;
and rmp::Handle for an object kept from one frame to the next.
tools/pointer_check.py reads the headers' syntax tree and fails a public one; a pointer
in detail:: or in a private member is allowed only with its line and its reason in
tools/pointer_ratchet.txt, which only shrinks.
A
callback is the framework's own Callback, not std::function, on purpose:
std::function needs a callable it can copy, so a lambda that captures a
std::unique_ptr would stop compiling.
Pointers and RAII shows each replacement in code, and Ownership explains handles.
There
is no throw under src/rmp/ or include/rmp/, and a test of
the test campaign fails one. A mistake in the game gets a safe value and a report instead, below.
The one place exceptions exist is the property tests' own program, because RapidCheck's assertions
throw. No exceptions has the reasons.
A mistake the game can make
every frame — an input action nobody defined, a pop() with no scene under it — is
reported once, through RMP_REPORT_ONCE in src/rmp/internal.h, keyed by the place in
the code that says it (and with RMP_REPORT_ONCE_KEYED, by a value too), never through a
warned flag of its own. Sixty identical warnings a second would bury the one that
matters. With [dev] strict = true the first one aborts a debug build, at the line that
made it. A debug build also shows each one on screen, and a boot that reported one fails
rmp test smoke.
That
is for mistakes in the game, and only those. A condition of the machine — no sound device, a folder
it cannot write — is a plain TraceLog(), said once by the state that remembers it,
with a comment beside it saying why it is not a report: strict mode would abort a correct game on a
CI runner or a player's locked-down computer. Turning one of those into a report breaks strict
mode. And reading something never reports at all: reading rmp::Value through a path
that is not there creates nothing and says nothing.
A
.toml that cannot work fails in tools/configure.py, in its first second,
naming the exact line, what is wrong and what to write instead — not at
cmake --preset, and not on a runner twenty minutes later. Every combination that
cannot work is a refusal with a reason, and every refusal has a test in
tests/configure_test.py. A mistake in the configuration that reaches the compiler is a
bug in configure.py. The config pipeline
explains why.
Nothing secret goes in it: no keystore, token or password. Values yes, secrets no; a secret lives in the repository's GitHub secrets.
Every
vendored component has a row in THIRD_PARTY_LICENSES.md, and
tools/license_db.py --check, in rmp test config, fails one without it.
Copyleft fails, LGPL included, because neither iOS nor a static musl build can link dynamically;
non-commercial and unknown licences fail. A component under a licence that asks for changes to be
marked is either pinned unmodified by sha256 in thirdparty/FROZEN_VERSIONS.md or marked
modified with a PATCHES.md beside it. The raylib the framework ships is modified, so no
page may call it unchanged. Licences has the whole list.
A
vendored header goes on four include lists, not one: the rmp target in
CMakeLists.txt, Android's own CMakeLists.txt under raymob/,
the iOS project tools/configure.py generates, and the Windows job's pass over the
examples. Getting all but one of them right looks exactly like getting them all, until a platform
you did not build says file not found, so a test holds every folder under thirdparty/ with
a header to all four.
Every
debug build of the framework — the library, the examples, every test program — runs under
AddressSanitizer and UndefinedBehaviorSanitizer, because the framework's own [dev]
sanitize lists both. CI sets RMP_REQUIRE_SANITIZERS, so a machine that cannot
run them fails at configure instead of testing nothing in silence. A check that measures time
allows for the slowdown when RMP_SANITIZE is defined. Every target built from our
sources is compiled with -Wall -Wextra, and the framework's own checks with
RMP_WERROR, which makes a warning an error.
A release flag goes in only when it costs 3 % or less of the unpacked binary, measured on the build that ships; position-independent executables are the one exception, on by Omar's decision, because without them address randomisation moves everything but the program itself. Security has every flag with what it protects against and what it costs.
tools/size_budget.txt
holds the size of every binary a release ships, and a step of every release job holds it there:
within 1.5 % of its line it passes in silence, up to 10 % it passes with a warning that names the
new size, and past 10 % it fails — growing or shrinking. Growth is allowed; it is a decision, and
the commit that grows a binary writes the new line.
The size budget shows the file and how one run's log
updates it.
Every
compiler, tool and library the Linux jobs use is in the build image, pinned by digest. A download
during a job is a single point of failure that no pinning fixes: the checksum can be right and the
network still be down, and twenty minutes of jobs fail for a reason that has nothing to do with the
code. A new tool is a new image and a new digest, in thirdparty/FROZEN_VERSIONS.md and
in every workflow that names the image; tools/versions_check.sh fails when any two
disagree.
Anything that can be tested is tested, and a test asserts what actually happened, not that a command exited 0: a job can go green having run none of its script, and a suite can pass having run a part of its tests. For an option, that means every valid value, every invalid one, the wrong type, the empty value and the combinations that cannot work.
And a test you have not seen fail is not a test yet. Every test and every gate is seen red on the mistake it exists for — planted by hand, and found exactly once — before its green is trusted; the pull request says what was seen red.
When
a mistake can be described precisely, a machine rejects it: a clang-tidy check, a refusal in
configure.py, a test, a gate. A rule that lives only in a document is kept until the
day somebody has not read it. The pages on
tests,
examples and e2e,
properties, fuzzing and
mutation and coverage and gates
are how.
The second half of the framework's CLAUDE.md is a list of
mistakes that each cost a run, a day or a release once, every one found by reproducing it rather
than by reading code: that riscv64 runs under an emulator, that macOS ships bash 3.2, that a BSD
job's script can exit 0 having run half of itself, that pushing cancels a CI run, and more. Read the
entry for an area before you change it. It is cheaper than finding it again.
Code, comments, documentation and commit messages are in English. A name in a comment is spelled exactly as in the code, so a rename renames the comments too.
Next: writing tests.
https://omardev29.github.io/rmp-docs/framework/contributing/tests.html
The framework's tests run with no window, no GPU and no display, in milliseconds, under the sanitizers. They can, because everything that changes between two runs — the clock, the input devices, the size of the screen, the seed — enters the framework through a seam a test replaces. This page is how to write one: where the file goes, what it looks like, which seams there are, and how to see it fail before you trust it to pass.
Testing describes what the tests are and what each stage of
rmp test runs. This page is for adding to them.
A test goes in the file of the program that can run it. Each kind of file is found by a pattern, so a new file of a kind that is already there needs no change to CMake; a Python module may need a stage, below.
| What it tests | The file | Built into | Run by |
|---|---|---|---|
A module of src/rmp/ | tests/<module>_test.cpp | unit_test | rmp test unit |
| The interface's layout, headless | a case in tests/ui_layout_test.cpp | ui_layout_test, a program of its own | rmp test layout |
| The interface on a real GPU | a case in tests/ui_render_test.cpp | ui_render_test | rmp test ui-render |
| What holds for every input | tests/property/<module>_prop.cpp | property_test | rmp test property — Properties |
| A parser, fuzzed | tests/fuzz/<name>.cpp | fuzz_<name> | rmp test fuzz — Fuzzing |
| An example, played | tests/e2e/<area>/<name>.e2e | e2e_<area>_<name> | rmp test examples — Examples and e2e scripts |
A tool of tools/ | tests/<tool>_test.py | Python's unittest | the stage whose pattern finds it — below |
| A game's own code | tests/game/<name>_test.cpp | game_test | rmp test unit — below |
Every
tests/*_test.cpp but the two interface tests with a main() of their own
is compiled into unit_test, and the pattern is read again on every build: without
that, a new test file is not compiled until somebody happens to reconfigure, and a test that never
runs looks exactly like one that passes.
Files
a test reads — a map, a picture, a save cut short — go in tests/fixtures/. The build
compiles in the absolute path of that folder, so a test finds them whatever directory it is run
from.
Here is the smallest test file of the framework, whole: what it holds and why, at the top; doctest; the header of the module it tests; and one suite, named after the module, with a case for each thing the module promises.
// ---------------------------------------------------------------------------
// rmp::ads off Android: the stubs of thirdparty/raymob/admob.h, through the
// wrapper in src/rmp/ads/ads.cpp. What a game that shows ads does on a desktop,
// a browser or a CI runner -- every call compiles, links and does nothing --
// is what this holds. The real ads are Android's, and only a phone shows one.
// ---------------------------------------------------------------------------
#include <doctest.h>
#include <rmp/ads.h>
TEST_SUITE("ads") {
TEST_CASE("off Android an interstitial never loads, and showing it does nothing") {
CHECK_FALSE(rmp::ads::is_interstitial_loaded());
rmp::ads::request_interstitial();
CHECK_FALSE(rmp::ads::is_interstitial_loaded());
rmp::ads::show_interstitial();
CHECK_FALSE(rmp::ads::is_interstitial_loaded());
}
TEST_CASE("off Android a rewarded ad never loads and never earns anything") {
rmp::ads::request_rewarded();
CHECK_FALSE(rmp::ads::is_rewarded_loaded());
rmp::ads::show_rewarded();
CHECK_FALSE(rmp::ads::take_reward_earned());
CHECK(rmp::ads::reward_amount() == 0);
// The documented use: show it only when it has loaded, grant only
// what was earned -- which off Android is never.
if (rmp::ads::is_rewarded_loaded()) rmp::ads::show_rewarded();
CHECK_FALSE(rmp::ads::take_reward_earned());
}
}
The suite's name is not decoration. It is what you select a run by, and what a
mutation floor
selects the tests of its module by — tests/mutation/floors/random.txt runs
unit_test -ts=random.
A
test that needs the framework's own internals — the seams below — includes their headers by a
relative path after doctest and before the public headers, as tests/clock_test.cpp
does: #include "../src/rmp/internal.h" for the clock and the reports, and
#include "../src/rmp/ui/internal.h" for the interface.
rmp test unit
./build/debug/unit_test -ts=random
./build/debug/unit_test -tc="*fixed step*"
./build/debug/unit_test -sf="*clock_test.cpp"rmp test unit configures the debug build with the tests on, builds
unit_test and runs it; after that the program takes doctest's own options: a suite,
a case or a source file by name, with * for anything.
A
source file is matched against the whole path the compiler was given, which starts wherever the
checkout is, so its pattern begins with *.
The stage runs every case twice: in the order they are written, then shuffled with a fixed seed. A case that passes only because the one before it left something behind fails the second run, and fails it again on every run after, because the seed does not change. To play the shuffled run yourself:
bash tools/test_locales.sh build/test-locales
LOCPATH=build/test-locales ./build/debug/unit_test --order-by=rand --rand-seed=1337 --test-suite-exclude="audio: device"The
first line builds the two test locales a save is read back under — a decimal point that is a
comma, and one that is two bytes long — and the second points the run at them. Without them those
cases skip and say so; CI makes the skip a failure. The audio: device suite opens the
real sound device and runs in the first pass only.
Both runs are a debug build, so both are under AddressSanitizer and UndefinedBehaviorSanitizer, and the build has warnings as errors: a warning in a test fails the stage like a warning in the framework. Security says what the sanitizers catch.
A
seam is the one function through which the framework reads something that changes from run to run.
A test replaces it, and every answer the framework gives comes from what the test put there.
rmp test seam fails when any other file of src/rmp/ or
include/rmp/ reads the clock, the devices, the screen or the random state on its own,
because one such read is enough to make a test pass on one machine and fail on the next.
| What changes | The seam a test sets | Declared in | Put back with |
|---|---|---|---|
The keyboard, mouse and gamepad, as rmp::input reads them | rmp::input::detail::set_sample_provider(), with a function that fills a rmp::input::detail::DeviceState | include/rmp/input.h | rmp::input::detail::reset() |
| How long a frame is | set_fixed_delta(), in rmp::app::detail | src/rmp/internal.h | set_fixed_delta(0) |
| The seed a run starts from | set_test_seed(), in rmp::app::detail, or rmp::random::seed() itself | src/rmp/internal.h | set_test_seed(std::nullopt) |
| The pointer, as the interface reads it | set_pointer_provider(), in rmp::ui::detail | src/rmp/ui/internal.h | pointer_from_raylib |
| The keys and buttons the interface navigates with | set_nav_provider(), with a function that fills a NavState | src/rmp/ui/internal.h | nav_from_raylib |
| How wide a line of text is | set_measure_provider() | src/rmp/ui/internal.h | measure_with_raylib |
| What the keyboard typed into a text field | set_text_provider() | src/rmp/ui/internal.h | nullptr |
| The size of the window | set_test_viewport(), which also stops the interface drawing | src/rmp/ui/internal.h | set_test_viewport(0, 0) |
| What the framework says about a mistake in the game | set_report_sink(), report_count(), in rmp::detail | src/rmp/internal.h | set_report_sink({}) and reset_reports_for_tests() |
The
input has two seams, and that is on purpose: the game reads rmp::input and the
interface reads its own navigation. Keys fed to the first move the player and leave the menus deaf.
A test of a menu sets the second; a test of a game with a menu over it sets both.
A
test writes the devices it wants into a struct and hands the framework a function that copies it
out. rmp::input::detail::begin_frame() is one turn of the loop: everything about an
edge — the frame a key went down — is the difference between two of them, so a test that calls it
once is testing the wrong thing. This is the fixture tests/input_test.cpp starts every
case with, and a case of the kind it holds:
namespace {
// The devices the test holds down: there is nothing between this and
// what rmp::input answers.
struct {
rmp::input::detail::DeviceState devices;
} fake;
void fake_sample(rmp::input::detail::DeviceState &out) { out = fake.devices; }
// Every case starts from nothing and leaves nothing: the cases also run
// shuffled, and the next one may be anyone's.
struct Fixture {
Fixture() {
rmp::input::detail::reset();
fake.devices = rmp::input::detail::DeviceState{};
rmp::input::detail::set_sample_provider(fake_sample);
}
Fixture(const Fixture &) = delete;
Fixture &operator=(const Fixture &) = delete;
~Fixture() {
rmp::input::detail::reset();
fake.devices = rmp::input::detail::DeviceState{};
}
};
} // namespace
TEST_CASE_FIXTURE(Fixture, "jump is just pressed on the frame Space goes down, and only then") {
rmp::input::action("jump", KEY_SPACE);
rmp::input::detail::begin_frame();
CHECK_FALSE(rmp::input::just_pressed("jump"));
fake.devices.keys[KEY_SPACE] = true;
rmp::input::detail::begin_frame();
CHECK(rmp::input::just_pressed("jump"));
rmp::input::detail::begin_frame();
CHECK_FALSE(rmp::input::just_pressed("jump"));
CHECK(rmp::input::pressed("jump"));
}The
fixture puts things back in its destructor, and rmp::input::detail::reset() forgets
every action and every reading and puts raylib back as the provider.
Its
copies are deleted because a class that writes its destructor says what becomes of the rest:
rmp lint asks, with cppcoreguidelines-special-member-functions.
With
a fixed step, every frame hands the game exactly that many seconds, still clamped by
[app] max_delta, whatever the machine took; 0 goes back to the real clock. The
interface animates by the same number, so the menus and the game cannot disagree about how long a
frame was. The seed is what rmp::random starts a run from instead of the wall clock.
Together they are what lets a test — or a
script — get the same frame twice:
namespace {
// Back to the real clock and no seed, whatever a case did.
struct Fixture {
Fixture() { reset(); }
~Fixture() { reset(); }
Fixture(const Fixture &) = delete;
Fixture &operator=(const Fixture &) = delete;
static void reset() {
rmp::app::detail::set_fixed_delta(0);
rmp::app::detail::set_test_seed(std::nullopt);
}
};
constexpr float STEP = 1.0F / 60;
} // namespace
TEST_CASE_FIXTURE(Fixture, "a fixed step is what the game is handed, and what the interface animates by") {
rmp::app::detail::set_fixed_delta(STEP);
CHECK(rmp::app::detail::step_delta() == STEP);
CHECK(rmp::ui::detail::frame_time() == STEP);
}tests/clock_test.cpp
holds the clock itself to this, case by case. Code that reads GetTime() or
GetFrameTime() for itself is out of the test's reach: a game that does cannot be played
from a script, and the platformer's flag once did.
A
mistake in the game — an action nobody defined, a widget outside begin() and
end() — is said once, through RMP_REPORT_ONCE, and a test of that
mistake checks it was said, and said once. report_count() is how many have been said
since reset_reports_for_tests(), and a sink set with set_report_sink()
hears each line. A test that turns [dev] strict on to see the first report stop the
run replaces what stopping does, with set_strict_handler(), so that the test program
is not the thing that stops. The fixture of tests/report_test.cpp sets each of these
and puts each back.
What the machine does wrong — no sound device, a folder that cannot be written — is not a mistake in the game, and is a plain log line, never RMP_REPORT_ONCE: strict mode would stop a correct game on a CI runner. A test of such a path does not expect a report.
The
interface's layout is Clay's, and Clay's layout is arithmetic. With the text measurement and the
pointer replaced by functions of the test's, and a viewport given instead of a window, a whole menu
is laid out with no window and no GPU, and drawing is skipped. Then the test asks where each
control ended up with bounds_of(): the label, which occurrence of it, and which
begin()/end() pass of the frame.
namespace {
// Every glyph half its size wide, a line one size tall: the questions are
// about arrangement, not typography. The parameters are Clay's.
// NOLINTBEGIN(custom-rmp-raw-pointer): Clay's signature, not ours to choose
Clay_Dimensions measure_stub(Clay_StringSlice text, Clay_TextElementConfig *config,
void * /*user*/) {
// NOLINTEND(custom-rmp-raw-pointer)
const auto size = static_cast<float>(config->fontSize);
return Clay_Dimensions{ static_cast<float>(text.length) * size * 0.5F, size };
}
// No pointer at all: nothing is hovered, nothing is clicked.
void pointer_stub(Clay_Vector2 &position, bool &down) {
position = Clay_Vector2{ -1.0F, -1.0F };
down = false;
}
// The stubs and a window of 1280 x 720 for one case, and the real ones
// back after it, whatever it did: no focus left on a button either.
struct HeadlessUi {
HeadlessUi() {
rmp::ui::detail::set_measure_provider(measure_stub);
rmp::ui::detail::set_pointer_provider(pointer_stub);
rmp::ui::detail::set_test_viewport(1280, 720);
}
HeadlessUi(const HeadlessUi &) = delete;
HeadlessUi &operator=(const HeadlessUi &) = delete;
~HeadlessUi() {
rmp::ui::focus("");
rmp::ui::detail::set_measure_provider(rmp::ui::detail::measure_with_raylib);
rmp::ui::detail::set_pointer_provider(rmp::ui::detail::pointer_from_raylib);
rmp::ui::detail::set_test_viewport(0, 0);
}
};
void draw_menu() {
rmp::ui::begin();
rmp::ui::button("Play");
rmp::ui::button("Quit");
rmp::ui::end();
}
} // namespace
TEST_CASE_FIXTURE(HeadlessUi, "Play is above Quit") {
// Twice: the first frame has nothing laid out before it to hit-test against.
draw_menu();
draw_menu();
Clay_BoundingBox play{};
Clay_BoundingBox quit{};
REQUIRE(rmp::ui::detail::bounds_of("Play", 0, 0, &play));
REQUIRE(rmp::ui::detail::bounds_of("Quit", 0, 0, &quit));
CHECK(play.y + play.height <= quit.y);
}Such a case can go in two places, and they are not the same:
tests/ui_<what>_test.cpp of unit_test, written as above.
Its cases run shuffled among every other test of the framework, so the fixture puts the real
providers back and leaves nothing behind it — no focus, no frame with something in front, no
report. HeadlessUi in tests/ui_overlay_test.cpp is the whole of such a
fixture, the navigation and the reports included.tests/ui_layout_test.cpp, a program of its own whose main()
puts the stubs in place once, for every case: there a case is the drawing and the checks, with no
fixture. Its cases run in the order they are written, each in the interface the one before it
left, and the last one — Clay's ceiling on elements — leaves it unable to lay anything out again,
so a new case goes before that one. It is where a layout is checked at many window sizes:
rmp test layout lays the menu out at four.rmp test layout
cmake --preset debug -DBUILD_UI_TESTS=ON
cmake --build --preset debug --target ui_layout_test
./build/debug/ui_layout_test -tc="*dropdown*"With
no window there is nothing drawn, so what only drawing can show — the backdrop's blur, a shader
built for a phone's GPU — is tests/ui_render_test.cpp's: a hidden window on a real
GPU, the frame read back. rmp test ui-render runs it; CI runs it under a virtual
display.
The framework's rule is that a test you have not seen go red is not a test, it is a hope with a name. A test that has only ever passed may be testing nothing: a check on the wrong variable, a case the build never compiled, a seam the code under test does not read. The only proof that it can fail is to watch it fail on the mistake it is for.
When the fix is already written, take it out of the one file it is in and put it back, without touching anything else in the working tree:
git stash push -- src/rmp/app/clock.cpp
rmp test unit
git stash popWhat deserves a test is everything a header says the code does. A promise in a header comment with no test that would fail without it is not a feature yet: the framework once said for two phases that a scene collides against its map's solid tiles, and nothing did.
And what deserves a case is every input: for every option, the valid values, every invalid one, the wrong type, the empty one, and the combination that cannot work. A check that only ever sees plausible input has not been tested. For inputs nobody would think to write by hand, a property or a fuzz target looks for them.
A test that is a check on the repository — a gate — is seen red the same way, by planting the mistake it exists for: Coverage and the gates says how.
The
Python in tools/ is tested by tests/<tool>_test.py, with the standard
library's unittest. Every such module has to be found by the pattern of a stage of
rmp test, and a test of the command fails on one that is not: a file of tests no stage
runs passes in silence, everywhere, for good. A new module either matches a pattern a stage already
has, or comes with its stage.
rmp test configure
python3 -m unittest discover -s tests -p configure_test.py -k ConfigureLineTest -vA
test loads the tool it tests by its path, under the name tools.<name>, as
load_tool() in tests/campaign_test.py does. That is the name mutation
testing records a test's reach under: a test that imported the tool as plain
<name> reaches nothing a mutant can be checked against.
A
rejection of tools/configure.py is a case of its own in
tests/configure_test.py: every combination of the .toml that cannot work
is refused with the line it is on and a reason, and every refusal has a test that sees it
fire.
tests/game/#A
game made with rmp new keeps its own tests in tests/game/. Every
.cpp there is built with doctest and with everything in the game's src/
but main.cpp into one program, game_test, which runs with no window. The
framework runs the same folder against the small game in its own src/, the copy every
game starts from, so a test a new game would fail on its first day fails in the framework first.
rmp test unit
./build/debug/game_test -tc="*menu*"A game's test drives the game the way the framework would — the delta handed to a
hook, the seed of rmp::random, the input devices through the seam above — and reads
what the game keeps.
Testing has the file a game starts with.
rmp test coverage, whose floors only rise —
Coverage.rmp test sanitize, the unit and
layout tests again under gcc's sanitizers, which instrument differently and warn about other
things.rmp test fuzz, every committed input replayed.rmp test examples, every example built, booted and
played.https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html
An example is what people copy, so it is held to more than compiling: CI builds every one, boots it with no window, takes its picture and fails it on any mistake the framework reports. And an example of a game, a menu, a scene or the input is played — from a script of what a player presses, frame by frame — and every picture the script takes has to come out exactly like the one recorded for it.
Testing says what each step proves. This page is for adding an example, and for writing, playing and recording its script.
An
example is a small project laid out like a game: examples/<area>/<name>/
with src/main.cpp, include/ when it has headers, src/scenes/
when it has more than one scene, and resources/ when it brings art. Every one becomes a
target of its own, example_<area>_<name>, built and booted headless with a
screenshot. A new mechanic belongs here, in an example, and not in the framework's
src/main.cpp, which stays the dozen lines of the demo game.
A
game in examples/games/ is playable from start to finish — win, lose, play again — or it
does not belong there. A title screen that draws is not a game that plays, and the script
below is what proves the difference.
Before
anything is built, tools/examples_check.sh reads the shape of every file of every
example. An example uses the framework's entry point, RMP_GAME or
RMP_ENTRY_POINT, because that is the only loop that works on every target: the browser
owns its frame loop and iOS never calls main(). So it refuses an example that
writes its own int main()., one that drives its own frame loop with
WindowShouldClose()., and an on_frame that takes no delta. The one
exception is examples/plain_c/src/main.c, which leaves the framework on purpose and has
to keep saying which targets that rules out.
Every
example also needs a row in examples/README.md that links its folder: an example
nobody is pointed at is a file that rots unread. The check fails on an example with no link, and on
a link to an example that is gone. The documentation site gives every example a page of its own,
and its examples.toml says whether a browser plays it there; a new example is a line
in that file the day the site moves to the commit that has it.
rmp example games/01_pong
rmp test examples
bash tools/examples_build.sh bootrmp example builds one example and starts it in a window, to play it yourself.
rmp test examples is the whole check CI runs — every example built, booted and
played — and it compiles all of them, which is why the plain rmp test leaves it out.
bash tools/examples_build.sh boot is its first half, everything but the scripts.
The
boot builds each example against raylib's software renderer — no GPU, no window, no display, the
same pixels on every machine — and runs it for thirty frames. It passes when the example printed
RAY_TEST_BOOT_OK assets_failed=0, RAY_TEST_RENDER_OK and
RAY_TEST_DONE_FRAMES, wrote its picture, reported no mistake and exited with status 0,
inside three minutes. The picture is the last frame, in
build/examples-check/screenshots/example_<area>_<name>.png: look at it.
Looking at the pixels is how most of what is wrong with an example is found.
RMP_EXAMPLE_FRAMES=120 bash tools/examples_build.sh bootA picture of a later frame than the thirtieth is that variable away.
RAY_TEST_REPORTS=0#A
mistake in the game that the framework can see — an action nobody defined, a widget outside
begin() and end(), a number that is not one — is said once, as a warning in
the log, and counted. On the last frame of a run with a frame budget the framework prints the count,
RAY_TEST_REPORTS=0 when there was none.
An example makes none. Any other count fails its boot, and the failure prints the warnings that were counted, so the line to fix is in the log. The plain C example is the one exception: it has no framework to report anything, and prints no count.
A
script is tests/e2e/<area>/<name>.e2e, and it plays
examples/<area>/<name>: what a player presses, frame by frame, what the
screen has to show at the frames that matter, and which scene has to be on top. This is the whole of
the menu example's:
# examples/ui/01_menu, played: every screen, with the keyboard, the gamepad
# and the mouse; a disabled button that does nothing, and the quit dialog
# cancelled.
#
# One scene per screen, so each step says which is on top as well as what
# the screen shows; a scene changed to is on top from the next frame. A
# click is down for one frame and up the next, and a button fires on the
# way up; a screen that has just appeared can be clicked from its second
# frame, when its buttons have a place to be hit in. See tests/e2e/script.h
# for the grammar.
# --- the happy path: play, and back --------------------------------------------
# Play has the focus from the first frame: Enter alone presses it. The score
# is a point a frame.
1 tap KEY_ENTER
12 shot playing
12 expect scene PlayingScene
# Escape goes back to the menu. It read raylib's Escape key itself until this
# script, and so did nothing to anything a script or a gamepad could press;
# it is rmp::input's "ui_cancel" now.
13 tap KEY_ESCAPE
# The gamepad: the d-pad down to Options, A to open it. The new screen's
# first control has the focus, and the ring shows: a pad was used.
15 tap GAMEPAD_BUTTON_LEFT_FACE_DOWN
17 tap GAMEPAD_BUTTON_RIGHT_FACE_DOWN
28 shot options
28 expect scene OptionsScene
29 tap KEY_ENTER
# --- the failure path: a disabled button, and a dialog cancelled -------------
# Cloud saves is disabled: the click does nothing to it, and the ring goes,
# because the mouse is what is being used now. Music stays off.
31 click 400 269
42 shot music_off_cloud_disabled
# Back, then Quit, with the mouse: the dialog asks first.
43 click 400 325
47 click 400 297
58 shot really_quit
58 expect scene ConfirmScene
# Down to Cancel, Enter: the menu again, and nothing quit.
59 tap KEY_DOWN
61 tap KEY_ENTER
# Play once more, and back with the gamepad's B -- "ui_cancel" is bound to
# both.
63 tap KEY_ENTER
65 tap GAMEPAD_BUTTON_RIGHT_FACE_RIGHT
76 shot back_by_pad
76 expect scene MainMenuScene
76 end
Every line starts with the frame it happens on, counted from 0 at exactly a sixtieth of a second
each, and never going back. # starts a comment, wherever it is.
| Line | What it does |
|---|---|
12 press KEY_SPACE | holds the key down from this frame on |
40 release KEY_SPACE | lets it go from this frame on |
1 tap KEY_ENTER | down for this one frame, up the next |
15 tap GAMEPAD_BUTTON_LEFT_FACE_DOWN | the same three, for the first gamepad's buttons, by raylib's names; its sticks stay at rest |
31 click 400 269 | the left mouse button, down for this one frame at a point of the window, in pixels; the pointer stays there |
43 type " Onf" | characters typed in this frame into the text field that has the keyboard, between double quotes, so a space is one; tap KEY_BACKSPACE takes one off |
12 shot playing | the picture this frame drew, compared with tests/e2e/golden/<area>/<name>/playing.png |
640 expect scene OverScene | the scene on top once this frame is over: a class name, or its end, so OverScene matches one in an anonymous namespace |
76 end | the last frame: the game quits after it |
A script that cannot mean what it says is refused before the game starts, with the line it is on:
type with no quotes or nothing between them, a " or a #
inside them, a control character, a byte that is not UTF-8, more than sixteen characters, or two in
one frame;_ — it is a file name — or one used
twice;end, anything after it, or a script that checks nothing.The
build makes a target of every script, e2e_<area>_<name>: the example as it
ships, with tests/e2e/driver.cpp beside it. A script whose example is not there — renamed,
or the script put in the wrong folder — stops the configure with … plays no example: it has
to be …, because a script nothing plays looks exactly like one that passes. A plain C
example cannot have one: the driver plays a game through the framework's seams, and it has
none.
The
driver installs itself before main(), through the framework's seams, and the game does
not know it is there. Every frame is exactly a sixtieth of a second and rmp::random
starts from seed 1, so a run is the same run every time. What the script holds down reaches
rmp::input and the interface's own navigation and pointer, and the input of frame N+1
is set at the end of frame N, which is when a real keyboard changes. Saves go to a fresh folder, so
last run's best score cannot change this one, and there is no sound device.
A
script can press only what the game reads through rmp::input or
rmp::ui. Under the software renderer raylib's own keyboard and mouse never change, so a
game that asks raylib about a key itself never sees it go down — and a key read that way is one no
gamepad can press either.
Two things about menus decide a script's first lines: the first button of a screen has the focus already, so Enter alone presses it; and Space and Enter press the focused control of a menu on top, so a script that taps a game's Space under a pause menu resumes the game.
On
every frame, whatever the script checks, the driver fails a control the example put where nobody
can reach it: one that takes the focus, is not wholly inside the window, and is in no scroll area
that could bring it in. And
every mistake the framework reported during the run fails the script at its end, a line
each, in the log's own words.
rmp example, and choose two paths through it: one
that gets somewhere and one that fails. Pong is lost and then won; Breakout loses its three balls and
then clears its wall; the menu example walks every screen with the keyboard, the gamepad and the
mouse, then clicks a disabled button and cancels a dialog.shot at each moment that proves something, an
expect scene where the scene changes, and a comment above each step that says what
it is for. The scripts in tests/e2e/ are written that way, and they are the best guide
to frame arithmetic: a click is down for one frame and a button fires on the way up; a screen that
has just appeared can be clicked from its second frame.bash tools/examples_build.sh e2eThat
plays every script. A shot with no golden prints a line that starts E2E NOTE and leaves
<shot>.actual.png in build/examples-check/e2e/<area>/<name>/.
Once that run has configured the build, one script is its own program, built and played
alone:
cmake --build build/examples-check --target e2e_ui_01_menu
./build/examples-check/e2e_ui_01_menuIt
prints a line for every shot it took, with the picture's hash; a line for every check that failed,
E2E FAIL <line>: <reason>; and E2E PASS at end
when none did.
A script that cannot do what a player should is news about the example, and the fix goes in the example. Breakout's ball outran the paddle and Space Invaders' last alien landed before a ship could reach it: both were found by a script that could not win, and both were fixed in the game.
Every frame of a script is a frame of a sanitized debug build drawn in software, and a Pong point is 75 of them. A script proves its paths and stops; it does not play a whole match to show that scoring works. A script still playing after ten minutes is stopped, and fails.
Every
shot is compared with its golden, tests/e2e/golden/<area>/<name>/<shot>.png,
pixel for pixel, with no tolerance. A fixed step, a fixed seed and the software renderer give the
same bytes for the same script, so a tolerance would only be somewhere for a real change to hide.
Exact also means one compiler, one maths library and one renderer: the comparison is enforced
inside the pinned build image, where CI runs it, and anywhere else a difference is reported with a
line that starts E2E DIFF and does not fail.
A
shot that differs fails the script with its line and says how many pixels differ and where the first
one is. It leaves three pictures in build/examples-check/e2e/<area>/<name>/:
the one expected, the one drawn, and the expected one darkened with every pixel that differs in red.
CI's e2e job uploads that folder, so a red run carries its pictures.
A tolerance is for a shot that proves it needs one, with the reason written beside it. None does.
The
goldens are drawn by the compiler and renderer that compare them, so they are recorded inside the
build image and nowhere else. rmp test e2e-update plays every script and writes every
shot as its golden; outside the image it refuses before building anything, saying
RMP_E2E_UPDATE records the e2e goldens, and only inside the pinned build image: and how
to run it there. tools/dev_shell.sh starts a shell in the image, with the checkout
mounted:
tools/dev_shell.shand in that shell:
python3 tools/configure.py
./rmp test e2e-updateThe
image sees the checkout at another path than your machine does, so the next run on your machine
finds build/examples-check configured from somewhere else, says so, and starts that
folder again: a full build of the examples.
Then
look at every picture that changed before committing it. git status tests/e2e/golden/
lists them; open each one. A golden is what the script will hold the game to from then on, and a
picture recorded without being looked at holds the game to whatever it drew that day, bug
included.
A test holds the two sides together: every shot a script takes has its golden, and every golden is a shot some script takes. A shot renamed leaves an orphan, and the orphan fails until it is deleted.
Every
example in examples/games/, examples/ui/, examples/scenes/ and
examples/input/ has a script. The test that says so reads
tests/e2e/pending.txt, the examples of those areas still without one: a list that only
gets shorter, and is empty. So a new example in those areas comes with its script, its goldens and
nothing in that file.
Every
other area of examples/ is named in the same test with the reason it is not played: an ad
shows only on Android; the loading example's keys only play a sound, in a run with no sound device;
the platform examples are Android's own API, or never run; and the plain C example has none of the
seams the driver plays a game through. A new area is one or the other, written down — a decision,
not a gap.
The scripts are played side by side, one per processor, the longest first. Each is a sanitized program of a few hundred megabytes, so on a machine that is doing other things, give it fewer at once:
CMAKE_BUILD_PARALLEL_LEVEL=3 bash tools/examples_build.sh e2eEach script has its own folder and a frame is a sixtieth of a second however busy the machine
is, so how many run at once changes how long the step waits and nothing a script draws. In CI the
boot is the examples job and the scripts are the e2e job, side by side.
https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html
A unit test checks the cases its author thought of. The deep tests look for the ones nobody did: a property is checked against hundreds of generated inputs, a fuzz target is fed bytes nobody would write, and mutation testing changes the framework's code on purpose to see whether any test notices. The properties of the C++ and the fuzz targets run under AddressSanitizer and UndefinedBehaviorSanitizer, every report fatal.
Each has two halves. On every push the half that gives the same answer every time runs, so that a red is the commit's and never the dice's; and on a schedule the half that searches:
Every push: the deep job | The search, .github/workflows/deep.yml | |
|---|---|---|
| RapidCheck | a fixed seed, 200 cases a property | every night: a random seed, printed, and 5000 cases |
| Hypothesis | derandomized: the same 200 cases a test on every machine | every night: 5000 random cases a test |
| Fuzzing | every committed input replayed | every night: ten minutes of libFuzzer per target, from the committed corpus |
| Mutation | the floor files' own checks | every Sunday: every module, a job each |
rmp test property
is part of the plain rmp test: first the campaign's own checks —
tests/campaign_test.py, which holds every rule on this page to the files — then the
RapidCheck properties, then the Hypothesis ones. rmp test fuzz and
rmp test mutation are asked for by name. In CI the push's half is the
deep job.
A
property of a module is tests/property/<module>_prop.cpp. Every such file is
compiled into one program, property_test, with doctest's main() and
RapidCheck, and a new one needs no change to CMake. It says, in its header, what must hold for every
input, and then checks it. This is a whole one, the clock's:
// ---------------------------------------------------------------------------
// The framework's one clock (src/rmp/app/clock.cpp), held to the campaign's rules
// for any reading a machine or a test can hand it:
//
// - what a frame hands the game is a finite number of seconds, 0 or more,
// and never more than [app] max_delta when there is one -- a NaN or an
// infinity from the reading would be every position in the world the
// next frame;
// - a reading the clamp has nothing to say about goes through as it is,
// and one past max_delta is max_delta;
// - a fixed step is what every frame hands the game and what the UI reads
// back, whatever number the test fixed;
// - the test seed and the frame observer are kept as they were given.
//
// Nothing here is public API: rmp::app::detail is the seam the runners and
// tests/e2e/driver.cpp use.
// ---------------------------------------------------------------------------
#include "check.h"
#include "gen.h"
#include "../../src/rmp/internal.h"
#include <rmp/app.h>
#include <rmp/config.h>
#include <rmp/object.h> // rmp::Callback
#include <doctest.h>
#include <rapidcheck.h>
#include <cmath>
#include <cstdint>
#include <optional>
namespace {
// Back to the real clock, no seed, no observer, whatever a case did.
void reset_clock() {
rmp::app::detail::set_fixed_delta(0);
rmp::app::detail::set_test_seed(std::nullopt);
rmp::app::detail::set_frame_observer({});
rmp::app::detail::forget_steps_for_tests();
}
// What [app] max_delta allows a frame to be: no ceiling when it is 0.
bool within_ceiling(float seconds, float max) {
return !(max > 0) || !std::isfinite(max) || seconds <= max;
}
} // namespace
TEST_SUITE("property: clock") {
TEST_CASE("a frame is a finite number of seconds, 0 or more, whatever the reading") {
rmp::test::check(
"clamp_delta is a finite number of seconds, 0 or more, at most max", [] {
const float raw = *rmp::test::gen::hostile_float();
const float max = *rmp::test::gen::hostile_float();
const float out = rmp::app::detail::clamp_delta(raw, max);
RC_ASSERT(std::isfinite(out));
RC_ASSERT(out >= 0.0f);
RC_ASSERT(within_ceiling(out, max));
});
}
TEST_CASE("a reading the clamp has nothing to say about goes through as it is") {
rmp::test::check(
"clamp_delta keeps a reading inside the clamp, and cuts one past it", [] {
const float raw = *rmp::test::gen::hostile_float();
const float max = *rmp::test::gen::hostile_float();
RC_PRE(std::isfinite(raw) && raw >= 0.0f);
const float out = rmp::app::detail::clamp_delta(raw, max);
const bool clamps = max > 0 && std::isfinite(max) && raw > max;
RC_ASSERT(out == (clamps ? max : raw));
});
}
TEST_CASE("a fixed step is what every frame hands the game, clamped") {
rmp::test::check(
"step_delta and frame_delta hand over the fixed step, clamped, every frame",
[] {
reset_clock();
const float seconds = *rmp::test::gen::hostile_float();
const int frames = *rc::gen::inRange(1, 5);
rmp::app::detail::set_fixed_delta(seconds);
for (int i = 0; i < frames; ++i) {
const float step = rmp::app::detail::step_delta();
RC_ASSERT(std::isfinite(step));
RC_ASSERT(step >= 0.0f);
RC_ASSERT(within_ceiling(step, RMP_MAX_DELTA));
RC_ASSERT(rmp::app::detail::frame_delta() == step);
// A fixed step that is a number of seconds is that number,
// clamped; anything else is the real clock, which no
// window here has ticked.
if (std::isfinite(seconds) && seconds > 0) {
RC_ASSERT(step ==
rmp::app::detail::clamp_delta(seconds, RMP_MAX_DELTA));
}
}
reset_clock();
});
}
TEST_CASE("the test seed and the frame observer are kept as given") {
rmp::test::check(
"set_test_seed reads back, and the observer hears every frame_ended", [] {
reset_clock();
std::optional<std::uint64_t> seed;
if (*rc::gen::arbitrary<bool>()) {
seed = *rc::gen::arbitrary<std::uint64_t>();
}
rmp::app::detail::set_test_seed(seed);
RC_ASSERT(rmp::app::detail::test_seed() == seed);
static int heard = 0;
heard = 0;
const int frames = *rc::gen::inRange(0, 8);
rmp::app::detail::set_frame_observer([] { ++heard; });
for (int i = 0; i < frames; ++i) rmp::app::detail::frame_ended();
RC_ASSERT(heard == frames);
rmp::app::detail::set_frame_observer({});
rmp::app::detail::frame_ended();
RC_ASSERT(heard == frames);
reset_clock();
});
}
}
Each
property is a check() of tests/property/check.h: a description,
and a function whose RC_ASSERT lines must hold for whatever RapidCheck draws. It is one
doctest check, silent when it holds and counted in doctest's summary; when it does not hold, the
failure says the smallest input RapidCheck could shrink the counterexample to.
rc::check(). It prints and returns a bool, so a property
that fails through it is a line in the log and a green run.tests/property/gen.h.
RapidCheck's own floats almost never draw a NaN, and its strings almost never hold a NUL — exactly
the inputs the framework's rules are about. hostile_float() and
hostile_double() draw NaN, both infinities, the largest and smallest normals,
denormals, -0 and values past int's range half the time;
hostile_rect() four of those; hostile_string() a NUL inside, several-byte
UTF-8 and bytes that are not UTF-8; value() a rmp::Value tree, sometimes
deeper than a save reads back.tests/property/gen_prop.cpp: a
generator that quietly stopped drawing NaN would turn every property that relies on it green by not
looking.The
program runs at a fixed seed and 200 cases a property unless the environment says otherwise, so
rmp test and every push play the same cases. A seed of your own, more cases, or one
suite:
rmp test property
cmake --build --preset debug --target property_test
./build/debug/property_test -ts="property: random"
RC_PARAMS="seed=7 max_success=5000" ./build/debug/property_testWhen
a property fails, RapidCheck prints, as the program ends, an RC_PARAMS value of the form
reproduce=… that plays exactly that case again. Paste it in front of the program the
same way as the seed above.
The
properties hold the framework to four rules for any argument a game can pass: no undefined behaviour
on any input; a documented safe answer, and one report, for a game's mistake; no NaN kept in the
state; and nothing changed by a refusal. Every public function of include/rmp/ is held
to them, or is waived.
A property says which functions it holds with a comment above the case, one function a line, spelled as the coverage report prints it — as in the random generator's properties:
TEST_SUITE("property: random") {
// covers: rmp::random::seed(uint64_t)
// covers: rmp::random::value()tests/property/waivers.txt does not list
fails. A new public function arrives with its property.covers line is a property's, not a promise. It counts only in a file whose code
calls the function, so a comment cannot take a function off the waivers with nothing behind
it.RapidCheck's
RC_ASSERT throws an exception, which is allowed in the test programs that link
RapidCheck and nowhere else: nothing under src/rmp/ or include/rmp/
throws or includes RapidCheck, and a test fails the day something does.
What
a property finds is written down as a case of its own, in the module's unit tests, with a comment
that says which property found it. The property finds it again only when its seed happens to; the
named case checks it on every run. The random generator's properties found that
range() on floats could land on its upper end where rounding put it there, from one
seed; tests/unit_test.cpp holds that seed to it, by name:
TEST_CASE("range(float) never lands on max, even where rounding puts it there") {
// random_prop.cpp's counterexample: the seed whose first value() is
...The order is the one every test follows: the named case first, seen red on the code as it was, then the fix, then green — seen red first.
The
tools are Python, and their properties are Hypothesis's, in
tests/<what>_property_test.py, which the stage finds by that name.
tests/cpp_text_property_test.py is written as the one to copy:
import
hypothesis_profiles comes first. It loads the profile every property test shares and,
where Hypothesis is not installed, skips the module and says so.tools.<name>, the name mutation testing
records a test's reach under.There
are two profiles. ci is the default: derandomized, the same 200 cases a test on every
run and every machine, no example database and no deadline — the sanitizers and a loaded runner make
timings meaningless. nightly draws 5000 at random and keeps what it found in
build/hypothesis/, where a counterexample found once is tried first next time:
python3 -m unittest discover -s tests -p '*_property_test.py' -v
RMP_HYPOTHESIS_PROFILE=nightly python3 -m unittest discover -s tests -p cpp_text_property_test.py -v
RMP_REQUIRE_HYPOTHESIS=1 python3 -m unittest discover -s tests -p '*_property_test.py' -vThe
last line is how CI runs them: there, a missing Hypothesis is a failure, because the build image has
it and a skip would be a green that tested nothing. On your machine, install the version
thirdparty/FROZEN_VERSIONS.md pins. A counterexample prints the
@reproduce_failure line that plays it again, and becomes a named case in the tool's own
unit tests, like a RapidCheck one.
A
fuzz target is tests/fuzz/<name>.cpp, one parser of the framework fed whatever
bytes libFuzzer makes up. It includes tests/fuzz/harness.h, which makes a replay depend on
the input and nothing else: no log, resources from an empty folder of its own instead of the game's,
[dev] strict off, and the once-only reports forgotten before each input. The Tiled
reader's is the smallest:
// ---------------------------------------------------------------------------
// The Tiled reader (src/rmp/tilemap/tilemap.cpp over thirdparty/cute_tiled), fuzzed.
//
// The input is the bytes of a .json map, exactly as rmp::assets::load_data
// hands them over: no NUL after them. The oracle is the reader's promise --
// it returns a map or refuses one, never crashes, never reads past the bytes
// and never does UB on the way (cute_tiled is instrumented like our code:
// cmake/sanitize_ignore.txt leaves it nothing) -- and then everything
// tests/fuzz/map_walk.h asks of any map a reader accepted.
//
// Inputs: tests/fuzz/corpus/tiled/ (seeded with tests/fixtures/map_*.json and
// what fuzzing merged in) and tests/fuzz/regressions/tiled/.
// tests/fuzz/tiled.dict hands libFuzzer the keys cute_tiled knows.
//
// bash tools/fuzz.sh replay tiled every committed input, once
// bash tools/fuzz.sh run tiled 60 a minute of libFuzzer
// ---------------------------------------------------------------------------
#include "harness.h"
#include "map_walk.h"
#include "../../src/rmp/tilemap/tilemap_internal.h"
#include <rmp/tilemap.h>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <span>
// NOLINTNEXTLINE(readability-identifier-naming): libFuzzer's name
extern "C" int LLVMFuzzerInitialize(int * /*argc*/, char *** /*argv*/) {
rmp::test::fuzz::initialize();
return 0;
}
// NOLINTNEXTLINE(readability-identifier-naming): libFuzzer's name
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, std::size_t size) {
const std::span<const std::uint8_t> input = rmp::test::fuzz::input({ data, size });
if (input.size() > static_cast<std::size_t>(std::numeric_limits<int>::max()))
return 0;
rmp::Tilemap map;
rmp::tilemap::detail::Access::adopt(
map,
rmp::tilemap::detail::parse_map(input.data(), static_cast<int>(input.size()),
"fuzz.json"));
rmp::test::fuzz::maps::walk(map);
return 0;
}
Its
oracle is everything the reader's header promises about bad input: it returns, without undefined
behaviour, and refuses what it cannot read. A promise of its own that the sanitizers cannot see —
a refusal leaves its output as it was, what reads back writes the same — is a
require() of the harness, with the promise in words, which ends the run as a crash
with that line first, so the nightly issue is named after it.
tests/fuzz/value_json.cpp is one made of those.
A target comes with its inputs, committed:
tests/fuzz/corpus/<name>/, the inputs fuzzing found that
add coverage, merged in; seeded at first with real files of the format;tests/fuzz/regressions/<name>/, every input that once
failed, or sits at the edge of what the reader takes, each named for what it is —
tests/fuzz/regressions/value_json/ has 1e400 and
coins_1e309;tests/fuzz/<name>.dict, if it helps: the words of the
format, for libFuzzer to put together;tests/fuzz/<name>.options,
if it needs one: libFuzzer's flags for it, one a line, such as the longest input worth trying.Each of the two folders needs at least one input, and nothing may be committed for a target that does not exist. Every clone carries the corpus, so all of it together stays under 2 MB.
rmp test fuzz
bash tools/fuzz.sh replay value_json
bash tools/fuzz.sh run value_json 60
bash tools/fuzz.sh merge value_jsonrmp test fuzz
builds every target and replays every committed input, and it fails unless every file it named ran:
a replay that stopped early, saying nothing, would look like one that passed. run
fuzzes one target for that many seconds and merge adds what found new coverage to its
corpus.
Fuzzing
needs libFuzzer, which is clang's and comes with its compiler-rt. The build image has it; a machine
without it builds the same targets around tests/fuzz/replay_main.cpp, which replays
every input and cannot fuzz, and says so. To fuzz there:
tools/dev_shell.sh bash tools/fuzz.sh build
tools/dev_shell.sh bash tools/fuzz.sh run value_json 60What
a run finds is in build/fuzz/crashes/<name>/. It becomes two things: the input,
copied into regressions/<name>/ under a name that says what it is, which every
push replays from then on; and a named case in the module's unit tests built from it, which says in
a sentence what went wrong. tests/tilemap_test.cpp holds what the Tiled reader's
target found that way, case by case, beside the inputs in regressions/tiled/. Then the
fix.
A
target is linked to the framework library. One whose code is not in it — the e2e scripts' reader is
a part of the tests — names its extra source in tests/deep.cmake, the one line a new
target may add to that file.
Coverage says which lines ran; mutation testing says whether anything checked what they did. Mull, for the C++, and mutmut, for the Python, change one operator, constant or call at a time — a mutant — and run the module's tests against each. A mutant no test notices is a test nobody wrote, or a change nobody could see.
Each
module is a floor file, tests/mutation/floors/<module>.txt: what it mutates, which
tests must notice, the score that has to hold, and the mutants nobody can kill, each with why. The
random generator's:
# rmp::random (package P5). The pilot of 2026-10-11 killed 51 of 62 (82.26%):
# xoshiro's arithmetic had no known-answer test, and two comparisons at their
# edge (range(int) with max == min, chance()) no case. P5 measured it again in
# the image the same day, after the known-answer case, the two seeds whose
# first value() is 0 and 1 - 2^-24, and random_prop.cpp's reference
# generator: 81 of 81 detected, one equivalent -- 100%.
kind cxx
sources src/rmp/random/random.cpp
tests unit_test -ts=random
tests property_test -ts=*random
floor 100
equivalent cxx_lt_to_le:src/rmp/random/random.cpp:135:13 range(float)'s `min < max` at the clamp: the two differ only at min == max, where both sides answer min -- drawn is min, and nextafter(min, min) is min
| Line | What it says |
|---|---|
kind | cxx for Mull, py for mutmut |
sources | the files mutated |
tests | a test program and its doctest options, one a line, for the C++ — unit_test, ui_layout_test or property_test; the test files, or one class of a file, for the Python. A mutant killed by any of them is killed. |
select | for the Python only: which of mutmut's mutants count, by name |
floor | the score that has to hold, 0 to 100 |
equivalent | a mutant no test can kill, and why, in words |
The score is the mutants a test detected — killed, timed out, crashed — over every mutant but the equivalent ones, in percent. A mutant no test reaches counts against it.
update writes it. A lower floor is a
hand edit a reviewer reads.src/rmp/ is in exactly one floor file, but the few that only compile a
vendored library. A new file goes into its module's sources, or comes with its module's
file.-sf, -ts or
-tc that matches nothing runs no test, passes, and lets every mutant survive, which reads
as a module nobody tested. A source filter begins with *, because doctest matches the
whole path.Mull's
plugin has to match the clang that compiles, exactly, so the C++ modules run inside the build image,
which has both. One module is run; every module, one after another, is hours, and is
rmp test mutation:
bash tools/mutation.sh modules
tools/dev_shell.sh bash tools/mutation.sh run random
tools/dev_shell.sh bash tools/mutation.sh update randomA
Python module is mutated on a copy of the tree, under build/mutation/, and its tests
read the mutated copy. mutmut follows calls inside one process: code a test reaches only by starting
the tool as a program counts as reached by none, so a Python floor file lists the tests that call
the tool directly, and selects the functions they reach.
.github/workflows/deep.yml
is the search: every night at 03:00 UTC, ten minutes of fuzzing per target and the properties at a
random seed; every Sunday, every mutation module, one job each. It runs only in the framework's own
repository: a repository made from it is a copy, not a fork, and would open issues on itself. It can
also be started by hand, for one target or module:
gh workflow run deep.yml -f mode=nightly -f only=value_json -f seconds=60
gh workflow run deep.yml -f mode=weekly -f only=randomWhat
a job finds becomes an issue labelled nightly-finding, one per signature: a sanitizer's
report by its kind and the top three of the framework's own frames, a fuzz oracle by its promise, a
property by its case and assertion, a mutation module by falling below its floor — nothing that
changes from one run of the same failure to the next. Found again, it is a comment on its open
issue, never a second one. Found again after it was closed, it is a new issue that says it came
back. Each issue carries the command that plays it again, and the run keeps the input.
Those issues are taken first, before other work:
gh issue list --label nightly-findingOne is closed the way any bug is: played again on your machine with the command it gives, written
down as a named case — and, for a fuzz input, a file in regressions/ — seen red, fixed,
and seen green. What the night's fuzzing merged into a corpus is in the run's
fuzz-<target> artifact; committing it is a pull request, never the workflow's.
https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html
Two kinds of check hold the framework to what it says about itself. Coverage measures what the tests reach, and does not let it fall. The gates read the repository for mistakes that have happened once and can be described precisely enough for a machine to refuse — a rule written in a script cannot be forgotten the way a rule in a note is.
A
test that never runs a line cannot find what is wrong with it. rmp test coverage builds
the unit tests, the headless layout test and tests/input_play.cpp — the one program
that drives the real desktop runner — with clang's source-based coverage, runs them, and reads which
lines of src/rmp/ ran.
The
tests link the whole framework library for it, so a file no test reaches is in the report at 0%
instead of missing from it.
It
is a debug build of its own, without the sanitizers, which say nothing about which lines ran and
make the run several times slower.
Which lines a compiler counts, and which tests a machine can run — the sound device, the test locales — differ between machines, and the numbers were measured inside the pinned build image. So the floors are a gate there, and anywhere else the run prints them. The coverage CI job runs it in the image, and that is the run to believe; on your machine, run it there too:
rmp test coverage
tools/dev_shell.sh bash tools/coverage_check.sh
tools/dev_shell.sh bash tools/coverage_check.sh --updateThe
run writes build/coverage/: the report it read, a summary, this run's list of untested
functions, and build/coverage/html/, every source file with the count of each line
beside it — where to look for the lines a new test should reach.
Before anything else the script builds, runs and reads back a program of two functions, one called and one not, and fails — never skips — when clang's profile runtime is missing or its tools are of another release of LLVM: a coverage run that measured nothing would print every floor as a note and pass.
tools/coverage_floor.txt has one line per file of src/rmp/: its path and
the share of its lines the tests run, in percent, rounded down.
--update, in the image, raises the lines to what the run measured.src/rmp/ comes with its line, in the same commit. A file with lines
and no floor fails, and so does a floor for a file that is gone.--update never does; a floor that has to come down is
an edit somebody writes and a reviewer reads, with the reason in the commit.The
floors are the per-line export's: each line of a file counted once. The html index and
llvm-cov report count a line once for every function that maps it — a lambda's lines
twice — so their percentages are not the floor's, and the floor is what fails.
tools/untested_api.txt names every public function of include/rmp/ — in
rmp, outside every detail, public, not implicit, defaulted or deleted —
that no test calls. clang reads the headers to find them, and a template counts as called when any
instance of it runs. A new public function no test calls fails: write the test. A listed one a test
calls now, or one that is gone, fails until its line goes, which --update does.
Some lines cannot run under a test: a GPU call in a program with no window, a file of two gigabytes. They go between two comment lines, each on a line of its own, and are counted apart instead of against the file. The first says why:
// RMP_COVERAGE_OFF(<why>)
...
// RMP_COVERAGE_ONThe
Aseprite reader's refusal of a file past int's range is
one. A marker with no reason fails, and so does an
OFF with no ON. The markers are for lines that cannot run, not for lines nobody has written a test
for yet: those are what the floor is for.
The
framework's rule is that every deterministic mistake must be catchable by a gate, not by memory. If
a kind of bug can be described precisely, something automated rejects it — a clang-tidy check, a
rejection in tools/configure.py, a test, or a script. The scripts are
tools/*_check.sh, and each one reads the repository for one kind of mistake:
| Script | Refuses | Run by |
|---|---|---|
tools/repo_check.sh | a file a build produces tracked by git — a CMake cache, an object file, a log — and a tracked file the .gitignore ignores | rmp test repo |
tools/seam_check.sh | a file of the framework that reads the clock, the devices, the screen or the random state outside the seams; inside rmp, a raylib type whose name the framework has taken written without its leading :: | rmp test seam |
tools/workflow_check.sh | a reusable workflow that asks for a permission, an input or a secret its caller does not give it, which GitHub answers with a run of no jobs and no logs; a step that throws a build's output away | rmp test workflows |
tools/portable_check.sh | in tools/ and the rmp launcher, what macOS's bash 3.2 or the BSDs do not have — mapfile, readlink -f, sed -i without an argument and the rest; a byte that is not ASCII in the BSD jobs' inline script | rmp test portable |
tools/shell_pattern_check.sh | A && B || C in a script, the launcher or a workflow's run: block, a line continued with \ read as one: when B fails, C runs too | rmp test shell |
tools/naming_check.sh | the naming rules clang-tidy cannot see, in every branch of every #if: R1 to R8 — Naming | rmp test naming |
tools/style_check.sh | the style rules clang-tidy cannot see, in every branch of every #if: S1 to S8 — a C cast, NULL, a TODO, something newer than the oldest compiler a game is built with, a user-defined literal, i++ where ++i says the same, a silent interface call outside a frame, iostreams in the library | rmp test style |
tools/ownership_check.sh | O1, memory owned by hand in the framework; O2, a raylib Load* or Unload* outside the file that owns what it makes — Pointers and RAII | rmp test ownership |
tools/cppcheck_check.sh | a cppcheck finding in src/rmp; a suppression with no reason, or one that matches nothing any more | rmp test cppcheck |
tools/header_check.sh | a public header that does not compile on its own, or does not carry the .toml's values | rmp test headers |
tools/header_cost_check.sh | a public header whose preprocessed size moved off its line in tools/header_budget.txt, either way; a header with no line | rmp test cost |
tools/versions_check.sh | a pin in thirdparty/FROZEN_VERSIONS.md that disagrees with the file that controls it, or, inside the image, with the image's own manifest | rmp test config |
tools/examples_check.sh | an example with its own main() or its own loop; one with no link in examples/README.md | rmp test examples |
tools/render_check.sh | a game that does not boot, draw and exit cleanly under the software renderer; in the framework, a frame that does not hash to tests/fixtures/render_hash.txt | rmp test render; the macOS and BSD jobs |
tools/sanitize_check.sh | the unit and layout tests failing, or a sanitizer report, built with gcc and warnings as errors | rmp test sanitize; the deep job |
tools/coverage_check.sh | a file below its floor or above it, an untested public function — above | rmp test coverage; the coverage job |
tools/shipped_check.sh | a release that does not find its files when it is started from another folder | the macOS and BSD jobs, and the plain C one |
tools/glibc_check.sh | a Linux release that needs a newer glibc than [linux] glibc allows | the Linux release jobs |
A few gates are Python, because what they read is easier read that way:
tools/pointer_check.py,
rmp test pointers: a raw pointer or a C string in a declaration a game can name, read
from the headers' syntax tree.tools/license_db.py --check and tools/configure.py --check, both in
rmp test config: a vendored component with no licence row, and a .toml that
cannot work.tools/size_check.py, rmp test size and every release job: a shipped
binary off its size budget.tools/lint_debt.py,
behind rmp lint: clang-tidy, held to what the tree still owes — below.Testing lists every stage of rmp test
with what it fails on, and Enforcement says which rule
of the style guide each check holds.
A
gate is a test, and a test nobody has seen fail is a hope with a name. rmp test gates
runs tests/gates_red_test.py, which runs each script the way rmp test and CI
run it — on a scratch tree: the script and what it reads, copied from the repository's tracked files
into a temporary folder. Then it plants a mistake in the scratch, and the script has to say FAIL and
name it; and on the tree as it is, it has to pass.
class SeamCheckTest(GateTest):
SCRIPT = "seam_check.sh"
PATHS = ("src/rmp", "include/rmp")
def test_the_tree_as_it_is_passes(self):
self.assert_green()
def test_planted_a_clock_read_in_a_new_file(self):
self.tree.plant("src/rmp/later.cpp",
"#include <raylib.h>\nnamespace rmp {\n"
"float later() { return GetFrameTime(); }\n}\n")
self.assert_red("src/rmp/later.cpp reads time, input, randomness or the screen directly",
"3:float later() { return GetFrameTime(); }")Every
script of tools/*_check.sh is in the file's GATES list, and a test holds
the list to the folder: a new script fails until it has its line. The line says
here — a class in this file, with a test of the tree as it is and at least one
test_planted_ — or names the class elsewhere that plants it red, and why there.
The
render check, for one, is planted in tests/configure_test.py, with a stand-in for CMake
and for the game.
Planting
is not a formality. It found holes in gates that were passing: the repository check let
through an object file whose name git quotes, the seam check read a // inside a string
as a comment and missed the call after it, and the glibc check called a file that is no ELF at all
static. Each hole has its planted case in the file.
rmp test gates
python3 -m unittest discover -s tests -p gates_red_test.py -k SeamCheckTest -vStart from the mistake, written as one sentence a machine could check. Then pick the instrument that understands the most of it:
.clang-tidy, for what the
compiler parses — one branch of every #if;tools/configure.py, with its case in
tests/configure_test.py, for a .toml that cannot work;tools/, for what none of those see: every branch of every
#if, the shell, the workflows, the repository itself.A
query of the framework's own in .clang-tidy has one trap: it fails in silence. Its
regular expression takes no C escapes — "\\.h$" matches nothing; write [.] for a dot — and a query
that does not parse is one warning line and exit 0, after which the check never runs.
tools/lint_debt.py fails on that line, and a test in
tests/configure_test.py shows each check of the style guide firing on a probe of the
wrong way and staying quiet on the right one: a new query gets its probe there.
A script is wired in five places, and tests of the command and of the gates hold the last three:
tools/<what>_check.sh. Its header says what it
refuses and why — the mistake that happened, so nobody "fixes" the rule back — and how to run it.
It prints a FAIL line that names the file and line of every finding, and exits 1. It
runs on macOS's bash 3.2 and on the BSDs, and never writes A && B || C:
rmp test portable and rmp test shell read every script in
tools/. One that reads C or C++ blanks the comments and strings first, through
tools/cpp_text.py, so a comment may name what is forbidden.rmp test, in STAGES in tools/rmp.py: a name, the
summary rmp help test prints, and the command.lint job of .github/workflows/ci.yml, or in the
job of its own the test of the command names for it: every stage runs in CI, and a test of
rmp holds each to its job. A gate a game does not have is a step gated on the framework,
as the seam's is.GATES and its class in
tests/gates_red_test.py, as above.rmp new copies a list of files, and everything in
tools/ is the framework's unless that list names it. A gate a game's own CI runs is
named there, or a test of rmp new fails on the game that lacks it.The documentation site says what each stage refuses, so a new stage is a line on Testing, and a new rule of the style guide a row of Enforcement, the day the site moves to the commit that has it.
A rule the tree does not yet keep everywhere cannot be switched on as a gate, and leaving it off lets it slip further. So what is still owed is written down, and the gate holds the list: it may get shorter, and it may not get longer. Every one of them fails both ways — a new debt, and a debt that was paid and is still listed — so the list is always exactly what is left. None is ever made longer by a tool: that is an edit by hand, with its reason, for a reviewer to read.
| The file | Moves | Fails on |
|---|---|---|
tools/coverage_floor.txt | up | a file under its line, or two points over it; a file with no line — above |
tools/untested_api.txt | shorter | a public function no test calls that is not listed; a listed one that is called, or gone |
tests/property/waivers.txt | shorter | a public function no property covers that is not listed; a listed one a property covers, or that is gone — Properties |
the floor of tests/mutation/floors/<module>.txt | up | a score under it; a floor under the score rounded down to 5 — Mutation |
its equivalent lines | shorter | a listed mutant a test kills, or one that is gone |
tests/e2e/pending.txt | shorter, and empty | an example of a played area with no script and no line; a line for one that has a script — Examples |
tools/lint_debt.txt | down | a warning not owed; a count that grew; a count above what is left — below |
tools/pointer_ratchet.txt | shorter | a pointer in a detail namespace or a private member that is not listed; a line that matches nothing any more |
the allowlist in tools/seam_check.sh | shorter | another file reading the clock, the devices or the screen; a listed file that no longer does |
Two
more files are budgets rather than ratchets, and are held both ways because a number nobody
updated hides the next change as surely as a growth nobody wrote down.
tools/size_budget.txt is the size of every binary a release ships: within 1.5 % of its
line it passes in silence, past that with a warning that names the new number, and past 10 % it
fails.
tools/header_budget.txt is what each public header costs to include, measured and held
in the image; it fails a header that grew past its line and a line the header is well under.
tools/lint_debt.txt#rmp lint
is clang-tidy over src/, tests/ and examples/, with the
framework's .clang-tidy: the same run on your machine and in CI's tidy
job. It reads the compile database of the lint preset, which it configures, and a file
with no entry there is a failure rather than a guess at its flags.
What
the tree still owes the style guide is tools/lint_debt.txt, one line per check and
file — the check, the file, and how many warnings it owes:
custom-rmp-raw-pointer src/rmp/input/input.cpp 4NOLINT naming the check, with its reason, on the line it is about. Nothing is ever added to the
file.rmp lint
bash tools/lint.sh debt
rmp lint fixbash tools/lint.sh debt runs the same check and writes the lines down to what is
left: run it after paying a debt, and commit the file with the fix.
rmp lint fix applies what clang-tidy is sure of, one file at a time, and then formats.
Read every change it makes: misc-const-correctness's fix has written
const char const *, and made const a buffer a test writes into.
The
clang-tidy has to be the one thirdparty/FROZEN_VERSIONS.md pins, and is run with
--experimental-custom-checks: without that flag the framework's own checks in
.clang-tidy are not registered, and clang-tidy does not say so.
Enforcement has what the tree still owes, check by
check.
https://omardev29.github.io/rmp-docs/framework/contributing/ladder.html
A change is proved by running it, not by reading it: almost every bug this framework has had was found by looking at pixels, dumping a file or writing an assert. The ladder is what to run before a change leaves your machine, cheapest first, so that CI confirms what you already know instead of telling you something new twenty minutes later.
rmp fmt
rmp lint
rmp testAll three run on your laptop, and all three have to end clean. Not mostly clean: a warning left for later is the one the next change hides behind.
Formats
every C and C++ file under include/, src/, tests/ and
examples/ with the clang-format the framework pins. rmp fmt check only
reports the files it would change, which is what rmp test and CI do. Do not format by
hand, and do not reformat a file you are not otherwise changing.
Runs
clang-tidy over src/, tests/ and examples/, and over the C
the tools and the build compile, with the framework's .clang-tidy. What the tree
still owes the style guide is written down in tools/lint_debt.txt, a count per check
and file, and the run is held to it: a warning nobody owes fails, and so does a count that grew.
After a change that pays some of it off, lower the file to what is left:
bash tools/lint.sh debtNothing is ever added to it. A new warning is fixed, or silenced on its line with
// NOLINT(check) and the reason beside it. rmp lint fix applies what
clang-tidy is sure of and formats the result; read every change it makes, because some of its
fixes are wrong. What checks what lists every check and
where it holds.
Two
of the checks are the framework's own, and clang-tidy runs them only with
--experimental-custom-checks; rmp lint passes it. A clang-tidy run by hand
without the flag registers neither and says nothing about it.
Runs every stage below in this order and stops at the first that fails. Name a stage to run only that one; the first failure is usually all you need to run again.
| Stage | What it checks |
|---|---|
rmp test fmt | every file is clang-format clean |
rmp test config | the .toml, the pinned versions — your clang tools among them — and every licence |
rmp test repo | git tracks sources, not build output |
rmp test seam | nothing in src/rmp reads the clock, the input or the random state by itself |
rmp test workflows | every reusable workflow gets what it asks for |
rmp test portable | the scripts run on macOS's bash 3.2 and on the BSDs |
rmp test shell | no A && B || C in a script |
rmp test naming | the names, in every branch of every #if |
rmp test style | the rules of the style guide clang-tidy cannot see, in every branch |
rmp test ownership | nothing allocated or freed by hand, raylib's loads only in their owners |
rmp test pointers | no raw pointer and no C string a game can name |
rmp test cppcheck | cppcheck finds nothing in src/rmp, and each suppression says why |
rmp test headers | every public header compiles on its own |
rmp test cost | what each public header costs to include |
rmp test gates | each gate above, seen red on a mistake planted in a copy of the tree |
rmp test configure | tools/configure.py, every refusal |
rmp test rmp | the rmp command itself, and rmp new's manifest |
rmp test binaries | the readers that judge a shipped .exe and Mac binary |
rmp test size | every shipped binary has a size budget, and its reader works |
rmp test unit | the unit tests, in order and then shuffled, and tests/game/ |
rmp test layout | the UI laid out at four resolutions, with no window |
rmp test property | the test campaign's own checks, RapidCheck at its fixed seed, Hypothesis derandomized |
rmp test ui-render | the UI on a real GPU: a hidden window, read back |
rmp test render | a frame drawn in software, checked and hashed |
rmp test smoke | the game built, booted and seen to draw, with no mistake reported |
Commands has the list as rmp help test
prints it, and Testing what each stage does in detail. Every
stage is also a step of CI, in the lint job or in a job of its own, and a test holds
the two lists to each other.
Some
stages are left out of rmp test because they take minutes or hours, and run only when
named. The examples are the clearest case: building all of them on every check would keep a laptop
compiling a folder that only grows. Run each of these when the change is the kind it is for:
| Run | When the change touches | What it does |
|---|---|---|
rmp test examples | the public API, objects, collision, maps, scenes, input, the UI, or an example | builds every example for the software renderer, boots each one and saves a screenshot, plays the platformer to the flag at 60 and 240 Hz, and plays every e2e script |
rmp test sanitize | anything that parses, casts, indexes or frees | the unit and layout tests again, built by GCC under its AddressSanitizer and UndefinedBehaviorSanitizer, every warning an error: a second compiler finds what the first passed over |
rmp test fuzz | a reader of files: saves, rmp::Value, LDtk, Tiled, Aseprite, the resource pack, the loader | every fuzz target built in build/fuzz, and every committed input replayed under the sanitizers; it fails unless every file ran |
rmp test coverage | any code in src/rmp/, and any test of it | the tests built with Clang's coverage, every file held to its floor and every public function to having a test that calls it — a gate in the build image only |
rmp test mutation | rarely by hand: it takes hours, in the build image | Mull and mutmut over every module, each against its floor; bash tools/mutation.sh run MODULE does one |
rmp test render-update | the demo's frame, on purpose | records the frame's hash as the new golden |
rmp test e2e-update | an e2e shot, on purpose | records every shot as its golden, inside the build image only |
Outside
the image, rmp test examples plays every script and reports a shot that differs from
its golden without failing: outside the pinned build image: a difference is reported, not
enforced. The goldens are drawn by the image's compiler and renderer, and a pixel of
difference anywhere else proves nothing either way. A golden recorded on purpose is looked at,
picture by picture, before it is committed.
The tests, examples and e2e, properties, fuzzing and mutation and coverage and gates pages say how to write what each of these runs, and how to update a floor that a change has earned.
Your laptop is not CI. Before a pull request that changes C++, the build, or anything the image-only checks hold, run the ladder again in the pinned build image, on a checkout of its own, as Setting up shows:
IMAGE=ghcr.io/omardev29/raylib-build@$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
repo_git=$(git rev-parse --path-format=absolute --git-common-dir)
podman run --rm --init --network=none \
-v "$PWD":/work -v "$repo_git":"$repo_git":ro -w /work "$IMAGE" \
bash -c 'python3 tools/configure.py >/dev/null && xvfb-run -a ./rmp test'Replace ./rmp test with ./rmp test examples or
./rmp test coverage for the stages that are exact only there. The display
xvfb-run provides is what the UI render test and the smoke boot open their window on;
without one, the boot fails inside raylib's window code under the sanitizers instead of saying
what is wrong.
A test you have not seen fail is a hope with a name. Every test and every gate is seen red on the mistake it exists for before its green counts:
FAIL line that
says what it found, not a crash somewhere near it.rmp test gates does this for every tools/*_check.sh on every run: each
gate is copied with what it reads into a scratch tree, a mistake of its kind is planted, and the
gate has to say FAIL and name it. A new gate fails that stage until it has a planted
mistake of its own.
An assert proves the boxes are where you said; it does not prove the screen looks right.
rmp test examples leaves a screenshot of every example in
build/examples-check/screenshots/, and, for every e2e shot that differs, the expected
picture, the actual one and their difference in build/examples-check/e2e/. Open
them.
rmp example 01_pongbuilds one example and runs it in a window, by name or by its path under
examples/; rmp example alone lists them.
Report what actually happened: which stages ran, where — the laptop or the image — and what was skipped and why. A stage that skipped for a missing tool did not pass. For CI, name the run: a run number and its result is a fact, "CI passes" is a claim. The pull request template asks for exactly this, and Pull requests says how it is filled in.
Next: CI.
https://omardev29.github.io/rmp-docs/framework/contributing/ci.html
The framework's CI is one workflow, .github/workflows/ci.yml, and the
same file every game gets. On the framework it runs everything the ladder runs and more: the
platforms that catch most mistakes, beside the framework's own jobs. This page is what it runs,
how to ask it for more, how to read it when it is red, and how to wait for it.
Continuous integration, in Publishing, is the same workflow seen from a game: every target's jobs, what is pinned, and what each platform's red means. This page adds what only the framework runs.
Four things start a run of ci.yml, and every run begins with the config
job, which reads raylib_multiplatform.toml once and hands every other job the same
answers: the targets, whether this is the full matrix, whether this is the framework or a game, and
where linux-riscv64-glibc is built. From there a run branches three ways: the checks,
which only the framework's repository runs (but lint, which a game runs too, and
api, which only a pull request runs); the platforms, one reusable workflow per family
the .toml enables, each running what the fast set or the full matrix asks of it; and, on
a tag, the release, which waits for every check and platform it needs to be green.
ci.yml and the conditions that start them. A dashed box runs
only in the full matrix, or only on a pull request; the dashed blue arrow is the one fallback.The
one branch that can go two ways is RISC-V. With [ci] riscv64 = "rise", the framework's
setting, or "cloud-v", riscv64-native builds and starts
linux-riscv64-glibc natively, in the raylib-build-riscv64 image, on a RISC-V
board: a RISE runner, which RISE lends to
open-source projects, or a Cloud-V Milk-V
Pioneer, for a private repository. A board is the provider's to give, and a job it cannot serve
must not cost a release, so that job is the one allowed to fail without failing the run. When it
fails, or no board is ever free for it, the riscv64 job runs instead: the cross build
in the amd64 build image, started under QEMU. It ships, and the run's summary says that it fell
back. With "cross", what rmp new writes in a game, the cross build is the
only path. A job with no board waits in GitHub's queue, up to a day, before the fallback
starts.
deep.yml is the other workflow worth a picture: the search that runs while nobody
watches, and the issues it opens.
nightly-finding
issue per signature, found again as a comment.A
push to main and every pull request run the fast lane. A push to any other branch runs
nothing by itself: a branch is checked when its pull request is opened, and again on every push to
it. On a pull request, what is checked out is the branch merged into main, so a green
run says the merge works, not only the branch. A change to nothing but Markdown files or
LICENSE runs nothing.
The fast lane builds Linux x64, Windows x64, the web and Android, and starts the framework's own jobs beside them, all at once, so the run takes as long as its longest job:
| Job | What it runs | On your machine |
|---|---|---|
config | reads the .toml and decides what the run builds | rmp test config |
lint | every stage of rmp test but the properties, which are the deep job's: actionlint over the workflows, the pins, every gate, the tests of configure.py and of rmp, the unit tests, the UI layout and render tests, a game's tests, the software-rendered frame, the formatting and cppcheck | rmp test |
tidy | clang-tidy, held to tools/lint_debt.txt | rmp lint |
examples | every example built, booted and seen to draw; the platformer played by its bot; the smoke boot on a virtual display | rmp test examples, its first half |
e2e | every e2e script played, each shot compared with its golden exactly | rmp test examples, its second half, in the image |
coverage | what the tests run of src/rmp/, against its floors | rmp test coverage, in the image |
deep | the unit and layout tests under GCC's sanitizers, the properties at their fixed seeds, every committed fuzz input replayed | rmp test sanitize, rmp test property, rmp test fuzz |
docs | this site's main, checked against the commit | Keeping the docs true |
rmp_new | a game made with rmp new from the commit, and that game's own checks | ./rmp new, then rmp test in the game |
linux, windows, web, android | the fast lane's platforms: built, packaged, started where a runner can start them, and held to their size budget | rmp build release, rmp web, rmp android |
A release of the framework waits for every one of them. In a game the same file skips the framework's own jobs, which test files a game does not have.
The
framework is checked in three sizes of run, and the rule is to use the smallest that answers the
question. The fast lane, above, on every push to main and every pull request. When it
is red, the fix is checked
on a debug lane: a run started by hand that builds exactly the platforms involved,
with every framework job beside them. Linux, Windows and macOS by default; Android or iOS only when
the bug is there:
gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macos
gh workflow run ci.yml --ref my-branch -f targets=linux-x64-glibc,windows-x64,macos,androidtargets
takes targets and groups, separated by commas, and builds what they come to. A name that is not
one, a group the .toml switched off, a name given twice or an empty item between two
commas stops the run in its first job, naming the item and its position. --ref runs
the workflow on a branch instead of main.
The full matrix builds all 17 targets, in about twenty minutes, and runs on every release tag and once when a larger piece of work is done. Its targets are Linux x86-64, Linux ARM64, Linux RISC-V, Linux x86-64 (musl / Alpine), Windows x86-64, Windows ARM64, macOS (universal), iOS (simulator), Web (WebAssembly), Android, FreeBSD x86-64, FreeBSD ARM64, OpenBSD x86-64, OpenBSD ARM64, NetBSD x86-64, Linux DRM/KMS (no X11), Linux ARM64 DRM/KMS (no X11).
gh workflow run ci.yml -f full=truemacOS, iOS and the BSDs build only there, or on a debug lane that names them, and the BSDs build inside virtual machines, on their best effort. A failure on one of them after a green fast lane is a bug of that platform: it is fixed on its own, on a debug lane with that one target, and once fixed such a bug does not tend to come back.
Start from the first job that failed: what fails after it may only be its consequence. The
gh commands that take you there, with RUN the run's number from the
list:
gh run list --workflow ci.yml --limit 5
RUN=12345678
gh run view "$RUN"
gh run view "$RUN" --log-failed--log-failed prints the log of the failed steps only, which is where the
FAIL line is: almost every check here ends its failure with one that says what it
found. Then reproduce it on your machine with the command in the table above. A job that fails in
CI and passes on the laptop is the case for the
image, which is what CI ran it in.
| Red | Where to look |
|---|---|
lint | The failing step's name is the gate or the test that refused; each stage of rmp test it runs is a step there, running the same command. |
tidy | The warnings, by file and line, that tools/lint_debt.txt does not owe. |
examples | The example that did not build, boot or draw. Its screenshots are the run's example-screenshots artifact. |
e2e | A line E2E FAIL, the script's line number and the reason. The run's e2e-pictures artifact holds, for each shot that differed, the golden, what was drawn and their difference. |
coverage | A file below its floor, or far enough above it that the floor should rise, or a public function no test calls. The report is the coverage artifact. |
deep | A sanitizer's report under GCC; a property that failed, with the seed that replays it; or a committed fuzz input that failed again. |
docs | Not red: on anything but a tag it warns, and only a tag fails on it. The step says which page and why. |
rmp_new | What a game made from this commit fails: for instance a file the game needs that the manifest leaves out. |
| A platform | Reading a red run, in Publishing, goes through every platform's checks. |
gh run download "$RUN" -n e2e-pictures
gh run rerun "$RUN" --failedThe first fetches an artifact to look at. The second runs the failed jobs again; that is for a failure that was not the code's — a runner that died, a service that was down — and never a way to make a flaky test pass.
A
release binary within 1.5 % of its line in tools/size_budget.txt passes in silence.
Between 1.5 % and 10 % it passes with a warning, which appears on the run's summary page, where a
green job's log is never read; past 10 % its job fails. Either way the check printed the line it
measured, in the file's own format, and one run's log rewrites every line it measured:
gh run view "$RUN" --log | python3 tools/size_check.py --update -Commit that with the change that moved the size, and say in the message why it grew. A warning nobody acts on becomes the failure of whoever is next.
A
new run of a branch or a pull request cancels the run of the same branch or pull request still in
progress; a tag's run is never cancelled. That saves minutes on a commit nobody wants any more, and
it is how a full matrix of main started by hand dies twenty minutes in when someone
pushes to main.
rmp push
is git push with a question first: it asks gh for the last twenty runs of
ci.yml, on any branch, and while one has not finished it refuses and names it. The
first push of a branch also sets its upstream.
rmp push
rmp push forcermp push force pushes anyway. On main, use it only when killing the run
it named is what you meant. On a branch of your own, a push can only cancel your own pull
request's earlier run; the runs rmp push names there may be other people's, which the
push does not touch, and force is the right answer.
A fast lane takes minutes and a full matrix about twenty. Do not sit refreshing it, and do not
ask somebody else to come back and say whether it finished. A person can hand the waiting to
gh, which follows the run in the terminal and ends with its result:
gh run watch "$RUN" --exit-statusAn agent starts a monitor in the background instead and keeps working: a loop that asks every 45 seconds, prints each job that ends other than green the moment it does, and stops with a summary when the run completes.
prev=""
while true; do
s=$(gh run view "$RUN" --json jobs \
--jq '.jobs[] | select(.conclusion != null and .conclusion != "") | "\(.conclusion)\t\(.name)"' 2>/dev/null || true)
cur=$(printf '%s\n' "$s" | grep -v '^success' | sort || true)
comm -13 <(printf '%s\n' "$prev") <(printf '%s\n' "$cur") 2>/dev/null || true
prev=$cur
st=$(gh run view "$RUN" --json status --jq .status 2>/dev/null || echo unknown)
if [ "$st" = "completed" ]; then
gh run view "$RUN" --json jobs \
--jq '[.jobs[].conclusion] | group_by(.) | map("\(.[0])=\(length)") | join(" ")'
break
fi
sleep 45
doneEach part is there for a reason. It prints every ending that is not a success — failed,
cancelled, skipped, timed out — because a monitor that only waits for good news is silent through a
crash, and silence looks like still running. comm -13 prints each job once instead of
every 45 seconds. It ends by itself. A gh call that fails does not end the watch. And 45 seconds is often enough for jobs that take minutes, and polite to an API
with rate limits.
deep.ymlnightly-finding, one per signature, with the command that replays it. Those issues are
taken before anything else: Pull
requests says how.canary.ymlBoth run only in the framework's own repository, never in a game.
Next: pull requests.
https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html
main is changed only by pull request. Every change, from a person or
from an agent, goes up on a branch of its own, is checked by CI there, and is merged when every
check main requires is green — and, when it changes the public API or the
.toml, when Omar has approved it.
main, on a branch named for the change:
git switch main
git pull --ff-only
git switch -c save-reads-any-localermp pushgh. Its description starts from the
template, below; fill it in.
gh pr create --base main --template .github/pull_request_template.mdmain, and again on every push to
the branch. A red check is fixed on the branch, with the debug lane when a platform is involved:
CI.Much of the work is done by Claude Code in the cloud: many agents at once, at any hour, each on
a branch of its own, each opening a pull request like anybody else. They reach GitHub through
Claude's own GitHub connection, not through a token from somebody's machine. They follow the same
process to the letter — the ladder, the template, nightly-finding issues first — and
what one could not run where it ran, it says under Not verified instead of leaving it
out.
.github/pull_request_template.md is the description every pull request starts
with. It asks for what a reviewer needs to trust the change without running it again:
rmp fmt check, rmp lint and rmp test pass;rmp test examples, when the public API or an example changed;rmp test sanitize, when the change parses, casts or frees;rmp test fuzz, when a parser changed;rmp test coverage in the build image, when src/rmp/ changed;FRAMEWORK_REF bumped, when a page of this site is no longer
true: a pull request of the site's own, whose FRAMEWORK_REF moves to this change once
it is merged — Keeping the docs true;A pull request merges only with these checks green. They are the fast lane's jobs, by the names GitHub shows them under:
config, lint, tidy, examples,
e2e, coverage, deep, docs,
rmp_new, linux / x64, windows / x64,
web / build, android / build and api.
docs
is green even when this site no longer passes against the change: it warns there, so that the
framework is not held up by its documentation, and a release tag is what it blocks. The warning is
still a job to do, on the docs, before the next
release. The full matrix is not required on a pull request; it runs at the end of a larger piece of
work and on every tag.
The API is what the rule above every other protects: every public header is something a game's
author has to know exists, every function in it is one more thing to read, and every key of the
.toml is a promise to every game made from the framework. So a change to either is
Omar's decision, made on the pull request.
The api job of .github/workflows/ci.yml holds it. It runs on pull
requests only — on a push, a tag or a run started by hand it does nothing and passes — and it looks
at what the pull request changes:
include/ — today, the public headers include/rmp/*.h —
in any way, a comment included: a comment in a public header is the reference a game's author
reads;.toml: one of DEFAULTS in tools/configure.py
added, removed or renamed, or its default changed — a default is what every game that does not set
the key gets — or a key of the framework's own raylib_multiplatform.toml.When it finds one, it puts the label api-change on the pull request and fails, with
a message that says what changed and who approves it, unless the pull request also carries the
label api-approved. Only Omar adds that label: the job reads the pull request's events
to see who added it, and refuses it from anybody but the repository's owner. It is judged by the
base branch's own copy of tools/api_change.py, so a pull request cannot change the
judge it is judged by. Once he has, the api job is
run again — the next push to the branch runs it, or the failed jobs are re-run — and it passes:
gh run rerun "$RUN" --failedBefore you open one, the same script says what your branch would be labelled, against
origin/main, and changes nothing:
python3 tools/api_change.pyMake the decision easy: say in the description what a game's code looks like before and after, and how the change answers the three questions. A change that makes the three-function menu longer will not be approved however it is argued.
Every night the deep campaign
fuzzes every fuzz target and runs the properties at a random seed, and every Sunday it runs mutation
testing. What it finds is an issue labelled nightly-finding: one per signature — the
same crash found again is a comment on its issue, not a second one — with the one command that
plays it again and a link to the run that keeps the input. A bug found that way is real and has
not been fixed yet, so those issues are taken before any other work:
gh issue list --label nightly-findingTaking one is the seen-red protocol with the evidence handed to you:
tests/fuzz/regressions/<target>/ under a name that says what it is; a property's
counterexample becomes a named doctest case in the module's own tests; a Hypothesis failure becomes
an explicit example.Fixes # and the issue's number in its description, so
merging it closes the issue. If the same signature is found after it was closed, a new issue says
it came back.Properties, fuzzing and mutation has each kind in detail.
A
commit message is plain text in English: no Co-Authored-By line, and no trailer of any
other kind. An agent working for Omar commits in his name, which is the git identity his machines
already have.
The subject says what is true after the commit, and the reason when it fits, rather than naming a kind of change — not fix: save but something of the shape a save reads 0.5 back under a German locale: every number is converted in the C locale. A body, when there is one, says what was seen red and how. Where a change moves a number that is written down — a coverage floor, a size budget, a header's cost, the lint debt — the new line goes in the same commit as the change that earned it, so the history says why every number is what it is.
Everything else is done without asking. Omar is asked for:
.toml, through
api-approved, above;Next: keeping the docs true.
https://omardev29.github.io/rmp-docs/framework/contributing/docs.html
This site is its own repository, omardev29/rmp-docs,
and it documents one commit of the framework: the one written in its file
FRAMEWORK_REF. Every page is checked against that commit, so the site cannot drift
from the code by accident. It can only be behind it, and moving it forward is part of the work
that changed the code.
A page is an HTML fragment under content/, and the rules for writing one are in
AUTHORING.md. The first
of them outranks the rest: a page may not say anything that is not true of the framework at
FRAMEWORK_REF. Whatever a machine can check about that, the build checks:
rmp command a page shows exists and takes the argument it is given, read
from rmp help --json;rmp::, an RMP_ macro, a raylib function
— is one the headers declare, and every path is a file of the framework or of a new game;.toml
block goes through its configure.py;A sentence about how the framework works inside is pinned to the code that makes it true, with
data-fw-grep on its element, a file and a regular expression that has to match there:
<p data-fw-grep="tools/rmp.py::GLOBAL_COMMANDS = \("new", "install", "update"\)">Three
commands act on the framework the rmp you typed belongs to …</p>The day that line changes, the check fails and says which sentence to read again. A regular expression that spans from the function's head to the line meant, rather than matching the line alone, also fails when the line moves to another function.
Clone the site next to the framework: it looks for the framework in
../raylib_multiplatform, or wherever the environment variable RMP_FRAMEWORK or the
option --framework says. The compile checks read the framework's compile commands, so
configure them once:
git clone https://github.com/omardev29/rmp-docs ~/rmp-docs
(cd ~/raylib_multiplatform && python3 tools/configure.py && cmake --preset lint)
cd ~/rmp-docs
python3 tools/build.py check
python3 tools/build.py check --tier compile
python3 -m unittest discover -s testsThe first is every gate, in under a minute; python3 tools/build.py gates lists them
with what each one says. The second adds every C and C++ block compiled against the framework, a
block shown as a mistake run through the tool that has to refuse it, and every block held to the
framework's style rules. The third is the site's own tests. --tier project also makes each tutorial's game with
rmp new and builds and boots it after every page, which is what the site's CI runs,
and takes minutes. python3 tools/build.py serve builds the site and serves it on
localhost:8040 to look at.
The framework checkout should be at FRAMEWORK_REF; the build says so when it is
not, and when the framework has uncommitted changes.
The
framework's docs job checks this site's main against every push and every
pull request, with every block compiled. When the change breaks a page, the job says which page and
why, as a warning: the framework is not held up by its documentation. A release tag is: on a tag,
that job fails, and nothing is released while the site does not pass.
So a change to the public API, a command, an option or a message is followed by the pages it makes untrue, as part of the same piece of work:
main: its own CI fetches FRAMEWORK_REF from GitHub.FRAMEWORK_REF to the framework's commit, with the framework checked out at it:
git -C ../raylib_multiplatform fetch origin
git -C ../raylib_multiplatform switch --detach origin/main
git -C ../raylib_multiplatform rev-parse HEAD > FRAMEWORK_REFserve.--tier project, looks at the built site in a browser, and on
main deploys it.The template of the framework's pull request has a box for this: the docs updated, and
FRAMEWORK_REF moved, when a page changes.
Every day, a workflow of the site checks its main against the framework's
main, not against FRAMEWORK_REF, with every block compiled and every
tutorial built. When that fails it opens one issue on the site's repository, The docs do not
pass against the framework's main, comments on it every day it still fails, and closes it when
they pass again. An open one means the next bump of FRAMEWORK_REF has pages to fix,
and the issue's run says which.
Back to Contributing.
https://omardev29.github.io/rmp-docs/framework/maintaining/index.html
These pages are for whoever keeps the framework working after it is written: the person who bumps a dependency, rebuilds the build image, answers a store's new requirement, or comes back to the repository after a year away and needs it to build again. Contributing says how to make a change; Maintaining says what changes on its own, where every version is held, and what to do about each one.
The framework is built to need little: every dependency it compiles is a copy in the repository, every tool CI uses is pinned to a version and a checksum, and a check fails when two places that hold the same version disagree. Pinning stops the world from breaking a build. It does not stop the world from moving, and the pages here are about the places where it moves anyway.
ghcr.io/omardev29/raylib-build and the Alpine run image, how they are
built, verified and published, and every step of a bump, in order.| What | Moves on its own? | What it costs |
|---|---|---|
| The C and C++ code, raylib and the vendored libraries | No: they are copies in the repository | Nothing until you choose to upgrade one. A new compiler can bring new warnings. |
| The Linux, web and Android toolchain | No: one image, named by its digest | A rebuild when you want a newer tool; the image itself stays usable as long as a copy of it exists. |
| The Windows and macOS runners, Xcode | Yes: GitHub retires runner images and the Xcode versions on them | A pin bump when a pin disappears, every year or two. |
| Android: SDK, NDK, AGP, Gradle | Yes: Google Play raises the target API every year | A bump of the whole set, and an image rebuilt for it, once a year to keep publishing. |
| iOS: Xcode, the raylib-iOS fork, ANGLE | Yes: the App Store requires a recent Xcode | A new Xcode, and the fork made to build with it, once a year to keep publishing. |
| The BSDs | Yes: their package mirrors are rolling and old releases lose them | A version bump when a release ages out; best effort. |
| Python | Slowly: the generator and rmp use the standard library
only | Little. The test tools in the image are a lock regenerated with the image. |
| GitHub Actions | Yes: actions are pinned by commit, but runtimes are deprecated | Dependabot's monthly pull requests, read and merged. |
The order in which the cost arrives is the order of the list: the desktop builds keep working for years with no change at all; the stores ask for a change every year whether the game changed or not. The yearly round puts dates on it.
One
file holds the list: the versions block of thirdparty/FROZEN_VERSIONS.md.
It is not documentation that can drift: tools/versions_check.sh parses it and compares
every value with the file that really controls it — the Gradle files, the Gradle wrapper, every
workflow that names the image — and, inside the build image, with the manifest the image carries.
rmp test config runs it. A bump starts there, and the check names every other place
that has to follow.
The table below is that block, read from the framework at the commit this site documents:
| Key | Pinned to |
|---|---|
build_image_digest | sha256:6fb4255df4a97317… |
run_alpine_digest | sha256:5823e1e4fa870083… |
build_riscv64_digest | sha256:c3946112f78f4ac5… |
android_platform | android-36 |
android_build_tools | 36.0.0 |
android_ndk | 28.2.13676358 |
android_sdk_cmake | 3.31.6 |
android_compile_sdk | 36 |
android_target_sdk | 36 |
android_min_sdk | 24 |
agp | 8.13.2 |
gradle | 8.14.5 |
gradle_sha256 | 6f74b601422d6d6f… |
play_services_ads | 24.9.0 |
llvm | 18.1.3 |
cppcheck | 2.13.0 |
mull | 0.34.1 |
hypothesis | 6.168.5 |
mutmut | 3.8.0 |
pytest | 9.1.1 |
tcc_commit | e23dabed154a8495f3ac1ff3cc9d04fa1c207893 |
tcc | 0.9.28rc |
mingw_gcc | 13-posix |
lld | 18.1.3 |
xwin | 0.10.0 |
wine | 9.0 |
macos_runner | macos-26 |
xcode | 26.6 |
ninja_mac | 1.13.2 |
ninja_mac_sha256 | c99048673aa76596… |
xcodegen | 2.46.0 |
xcodegen_sha256 | 4d9e34b62172d645… |
windows_runner | windows-2025 |
mesa | 26.1.6 |
mesa_sha256 | 86b506ad38b8dae9… |
pillow | 12.3.0 |
pillow_sha256_cp311_win_amd64 | 8e95e1385e4998ae… |
pillow_sha256_cp312_win_amd64 | a2b55dd6b2a4c4b7… |
pillow_sha256_cp313_win_amd64 | 1cca606cd25738df… |
pillow_sha256_cp314_win_amd64 | fdafc9cce40277e0… |
upx | 5.2.0 |
upx_sha256_amd64 | 3db5d3294707439d… |
upx_sha256_arm64 | 55d48a61e8ffd171… |
upx_sha256_win64 | b471ebf1b7f20f4a… |
zig | 0.16.0 |
zig_sha256_x86_64 | 70e49664a74374b4… |
zig_sha256_aarch64 | ea4b09bfb22ec6f6… |
clang_format | 22.1.8 |
clang_tidy | 22.1.8 |
apt_snapshot | 20260801T000000Z |
ubuntu | 24.04 |
cmake | 3.30.3 |
ninja_linux | 1.12.1 |
emscripten | 3.1.61 |
actionlint | 1.7.12 |
butler | 15.24.0 |
freebsd | 15.1 |
openbsd | 7.9 |
netbsd | 10.1 |
sha256_cute_aseprite | 1c2c71f68151b854… |
sha256_doctest | a58efc9446d70ddd… |
sha256_rapidcheck | 517d44bb22a3719d… |
sha256_rres | 913d59b01a7617aa… |
sha256_cjson | 5dbda89922a5a397… |
What the block does not hold is in the table under it in the same file: raylib, Clay, raylib-cpp,
doctest and raymob are pinned by being committed, the raylib-iOS fork by its submodule commit,
Playwright by package-lock.json, and every GitHub Action by the full commit it resolves
to. Every dependency goes through all of
them.
rmp test on an untouched main first. A red before you change
anything is the world having moved, and the stage that is red says where.nightly-finding come first, as in any other session.https://omardev29.github.io/rmp-docs/framework/maintaining/how-it-fits.html
Architecture is the game's side: the layers a frame goes through. This page is the maintainer's side: the repositories, the programs that turn a checkout into a binary for each target, and the places where one part reads a version or a file from another. When something breaks after years of nobody touching it, the break is at one of these joints.
thirdparty/, the tools,
the tests, the examples, the workflows. A game is not a fork of it but a copy of the files
INCLUDE in tools/rmp.py lists, made by rmp new; from then on
the game keeps the framework it was made with, and only rmp update, run on purpose,
moves it.ghcr.io/omardev29/raylib-build, the toolchain of every Linux, web and
Android job, and ghcr.io/omardev29/raylib-run-alpine, the Alpine the musl build is
started on. The framework pins both by digest. The build image's Gradle home is warmed by building
the framework's Android project at a commit the image names, so the two repositories point at each
other: an Android bump moves
them in a set order.thirdparty/raylib-ios is the submodule, used by the iOS target only.FRAMEWORK_REF file. Its CI runs
in the build image the framework pins at that commit, read from the framework's
ci.yml, so the site never keeps a digest of its own. A daily workflow checks the
site against the framework's newest commit and keeps one issue open while they disagree.Plans and the record of what was decided live in a fourth repository of documents, checked out
around the framework on Omar's machine and beside it in the cloud; the framework's
CLAUDE.md says where. Nothing builds from it.
rmp (POSIX sh), rmp.ps1 and
rmp.cmd do one thing: find a Python that is 3.11 or newer and hand it
tools/rmp.py and every argument. Everything rmp does is in that one
file.tools/configure.py reads raylib_multiplatform.toml,
refuses anything wrong with the line it is on, and writes what every build system reads. CMake
runs it on every configure, before project(), because the project's own name comes
out of it; Gradle and XcodeGen never run CMake, so their jobs run it first.
The config pipeline has every file it writes.CMakePresets.json holds the presets a build is named
by — debug and release, their DRM twins, web, the headless memory build and the lint build.
CMakeLists.txt adds raylib from thirdparty/raylib, compiles the
framework once into the static rmp library, and links the game and every example
against it. The files under cmake/ are what it includes: the hook that runs the
generator, the Python it looks for, the sanitizers' probe, the riscv64 toolchain, the game's
resources and tests.raymob/, whose
raymob/app/src/main/cpp/CMakeLists.txt compiles the same sources with the NDK;
iOS through an Xcode project XcodeGen makes from what the generator writes. Neither reads the
top-level CMakeLists.txt, which is why a header path goes on four lists, not one
(CLAUDE.md, "A vendored header goes on FOUR include lists").resources.rres, LICENSES.txt generated from
THIRD_PARTY_LICENSES.md, and tools/size_check.py holding every binary to
its line in tools/size_budget.txt.Nothing in that path
downloads anything: there is no FetchContent, no package manager and no submodule
but iOS's. A clone, a Python of 3.11 or newer, CMake, Ninja and a compiler build the desktop game.
The generator uses Python's standard library only; Pillow, when it is there, makes the icons.
| Family | Compiler | Where CI builds it | Pinned by |
|---|---|---|---|
| Linux, glibc | zig's clang, aiming at the glibc floor of [linux] glibc, through tools/linux_build.sh | inside the build image, x64 on ubuntu-24.04, arm64 on ubuntu-24.04-arm | the image digest; zig |
| Linux, musl | zig, for musl | inside the build image; started on the Alpine run image | both digests |
| Linux, riscv64 | the image's riscv64-linux-gnu GCC, cmake/toolchain-riscv64-linux.cmake | inside the build image, started under QEMU there | the image digest |
| Linux, DRM | the image's own compiler: zig cannot link libdrm, gbm and EGL | inside the build image; started on vkms on a bare runner | the image digest |
| Web | Emscripten | inside the build image | emscripten, and the image's emsdk commit |
| Android | the NDK's clang, through Gradle | inside the build image, amd64, offline | the image digest, the Android set |
| Windows | the compiler CMake finds first on the runner | on the windows_runner runner image | the runner label only: see below |
| macOS and iOS | Apple's clang from the pinned Xcode | on the macos_runner runner image | xcode, xcodegen, ninja_mac |
| The BSDs | each system's own compiler | in a virtual machine started by cross-platform-actions | freebsd, openbsd, netbsd; their package mirrors are rolling |
ci.yml is the entry point. Its config job runs the generator and turns
the enabled targets into a matrix per family, then calls one reusable workflow per family —
_linux.yml, _web.yml, _windows.yml, _android.yml,
_apple.yml, _bsd.yml — beside the framework's own jobs: lint, tidy, the
examples, the e2e scripts, the new game, coverage, the deterministic deep tests, the docs and the
API gate. A tag adds the release, which gathers what every family packed, and the itch.io job
after it; a full run with Android enabled adds Firebase Test Lab.
CI says what each push runs.
Three more run on their own, on the framework's repository only:
deep.yml, every night (fuzzing, random seeds) and every Sunday (mutation), opening
an issue labelled nightly-finding per new failure;canary.yml, every Monday: the same reusable workflows against the floating
versions — the image's :latest, the newest runners, Xcode and Mesa — and a report of
what is newer than every pin;autofix.yml, after a red canary: an agent on the broken family's own runner that
proposes a fix as a draft pull request.web-backends.yml builds the web game once per [web] backend and checks
each build is the backend it asked for; it runs by hand and on a push that changes the files that
choose the backend.
The
build image is the joint most things go through. Every Linux, web and Android job, the lint and
tidy jobs, the examples and their scripts, coverage, the deep tests, the new game and this site's
own CI run inside it, at the one digest the framework names in ci.yml, in
web-backends.yml, three times in deep.yml and in
thirdparty/FROZEN_VERSIONS.md. Exactness lives there too: the e2e shots are compared
pixel for pixel, and the coverage floors and header costs are held, only inside it, because they
were measured there. The build image says
what is in it and how to make a new one.
Around the code sits a set of checks about as large as the code: tools/ holds a
gate per rule (naming, style, ownership, pointers, headers, licences, versions, workflows,
portability, shell patterns, seams, sizes), and tests/ holds tests of the tests — each
gate seen red on a planted mistake, the campaign's own rules, the workflows read as text. They are
what lets an agent or a person change one file without reading every other one. They are also
code to maintain: a renamed step in a workflow, a new compiler warning, a moved line in a vendored
file can turn one red with nothing wrong in the game. Upgrading
a dependency lists, for each bump, which of them to expect.
https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html
Everything the framework needs that it did not write, grouped by how it reaches a build, with the way each one is pinned and the check that holds the pin. The last section is a map of every file that names each dependency, made from the framework's tracked files when this site is built: the answer to "if I change this, what else do I look at?".
| Pinned by | Means | Used for |
|---|---|---|
| Being committed | The files in the repository are the version. Nothing to fetch, nothing that can disappear. | raylib, raylib-cpp, Clay, cute_tiled, raymob, doctest, and the rest of thirdparty/ |
Its content's sha256 | A committed copy that must not change without its licence row saying it is modified: tools/license_db.py recomputes the hash. | cute_aseprite, cJSON, rres, doctest, RapidCheck (the sha256_* keys) |
| A version and a checksum | A file fetched by address and refused unless its bytes hash to the pinned value. | everything the image downloads; zig and UPX outside it, Ninja, XcodeGen, Mesa, Pillow |
| A digest | An image named by its content. A tag can be moved; a digest cannot. | the build image, the Alpine run image, the image's Ubuntu base |
| A commit | A full commit hash, never a tag. | every GitHub Action, the raylib-iOS submodule, emsdk inside the image, the framework commit the image warms Gradle from |
| A snapshot | Every apt source of the image points at snapshot.ubuntu.com at one timestamp. | every package the image installs with apt |
| A lock | Every package of the graph with == and the hash of every file. | the image's Python test tools; Playwright's package-lock.json |
| A label | A name the provider resolves; it changes under you when the provider updates it. | the runner images (ubuntu-24.04, windows_runner, macos_runner) and the BSDs' package mirrors |
The last row is the weak one, and the only one that moves without a commit. Every other pin changes only when someone changes it.
These are part of every game, or of its tests. All of them are C or C++ that builds with any C++20 compiler and needs nothing at run time but the platform itself.
| Component | Version | Pin and patches | What it costs to upgrade |
|---|---|---|---|
raylib, in thirdparty/raylib | 6.2 | committed; raylib_cmake_template's copy, modified, every change in thirdparty/raylib/PATCHES.md and commented at its site, PATCHED (raylib_cmake_template) or PATCHED (raylib_multiplatform) | High: the patches carried over or dropped one by one, and raylib's own libraries (GLFW, miniaudio, the software renderer) with it. The render hash and the e2e shots can move. |
raylib-cpp, in thirdparty/raylib-cpp | 6.0.3, the math types only | committed; PATCHES.md | Low; it follows raylib's version. |
raylib-iOS, in thirdparty/raylib-ios | tag 6.0.3-iOS | a submodule pinned to a commit of the fork under the same account; ANGLE comes with it | High, and the one most likely to be forced: a new Xcode can need a new fork. |
raymob, in thirdparty/raymob and raymob/ | a committed snapshot | committed; patched, [rmp patch] at each site and PATCHES.md | Medium: C and Java, every patch re-applied. |
Clay, in thirdparty/clay | 0.14 | committed; two patches in PATCHES.md | High: Clay is before 1.0 and its API moves between minor versions; every file of src/rmp/ui/ uses it. |
| cute_tiled | a committed snapshot | committed; patched and hardened for any bytes, every site /* rmp patch */ | High for little gain: the patches are most of what makes it safe. |
| cute_aseprite | a committed snapshot | sha256_cute_aseprite, unmodified | Low; the fuzz corpus says whether the new one is as safe. |
| cJSON | 1.7.19 | sha256_cjson, unmodified | Low. |
| rres, with its compression and encryption | an upstream commit | sha256_rres, unmodified, external/ included | Low, but the encryption is what rmp::save seals with: a change there changes every save. |
| doctest | 2.5.0 | sha256_doctest | Low. It ships with every game's tests. |
| RapidCheck | an upstream commit | sha256_rapidcheck; the framework's only, stripped by rmp new | Low. |
There is no reason to upgrade any of these on a schedule. Each one is upgraded when a game needs something the new version has, or when a bug is found that upstream has fixed — and many of those fixes are carried as backports already. Upgrading raylib and the entries after it say how.
Every one of these is a row of the versions block, compared with the manifest the
image carries by tools/versions_check.sh when it runs inside the image.
| Tool | Key | What uses it |
|---|---|---|
| Ubuntu, and every apt package | ubuntu, apt_snapshot | GCC and Clang for the native builds, the X11, Wayland, GL and DRM headers, Xvfb, QEMU, the cross compilers, Python and PyYAML |
| CMake, Ninja | cmake, ninja_linux | every build; the framework asks for CMake 3.30 or newer |
| zig | zig | the Linux releases, for their glibc floor; the musl build |
| Emscripten | emscripten | the web build |
| The Android SDK, NDK, build tools and the SDK's CMake | android_* | the Android build, amd64 only |
| Gradle and AGP, and a Gradle home warmed for them | gradle, agp, play_services_ads | the Android build, offline |
| LLVM with compiler-rt, and Mull | llvm, mull | coverage, the sanitizers' runtimes, libFuzzer, mutation testing. Mull is built per LLVM release, which is what holds LLVM where it is. |
| cppcheck | cppcheck | the static analysis stage |
| clang-format, clang-tidy | clang_format, clang_tidy | the lint and tidy jobs; installed from PyPI at that exact version |
| Hypothesis, mutmut, pytest | hypothesis, mutmut, pytest | the Python property tests and mutation testing; Python |
| UPX | upx | packing the Linux releases |
| actionlint and shellcheck | actionlint | the workflow checks; actionlint reads no shell without shellcheck |
| butler | butler | publishing to itch.io |
| Where | Key | Pinned | Floats |
|---|---|---|---|
| Linux jobs | — (the label ubuntu-24.04, and ubuntu-24.04-arm) | everything that matters, inside the image | the host kernel, Docker, the runner's own tools; the DRM job's kernel module comes from Ubuntu's archive |
| Windows | windows_runner | Mesa for the render test and Pillow, by checksum; UPX | the compiler that builds the .exe, and MSVC (the warning) |
| macOS and iOS | macos_runner, xcode | Xcode, selected by version with a step that fails when it is gone; Ninja and XcodeGen by checksum, never Homebrew | the runner image itself, and what Apple's tools do on it |
| The BSDs | freebsd, openbsd, netbsd | the release of each system | the virtual machine's disk image and every package, installed from a rolling mirror |
rmp and most tools use the standard library only. What is not standard library is
optional on a laptop: Pillow for the icons, PyYAML for one workflow check, Hypothesis for the
Python properties. Python has all of it.package.json names Playwright and pngjs, locked by package-lock.json
and installed with npm ci; the browser Playwright downloads is keyed to its version.
Dependabot proposes their bumps monthly. Nothing a game ships uses Node.What has to exist outside the repository, and what stops if it does not:
| Service | What uses it | If it goes |
|---|---|---|
| GitHub: repositories, Actions, Pages | everything CI does; the installer's address; this site | CI, the installer and the site stop. A clone still builds the desktop game. |
ghcr.io | serving both images, by digest | every Linux, web and Android job stops until an archived copy is pushed to another registry (archive it). |
snapshot.ubuntu.com | rebuilding the build image | the image cannot be rebuilt at that snapshot; the published one keeps working. |
GitHub release assets, ziglang.org, dl.google.com, PyPI, Google's Maven, the itch.io broth | rebuilding the image; zig and UPX on a laptop; the Windows and macOS jobs' downloads | the rebuild, or that job, fails at the checksum or the download, never with a different file. |
| Docker Hub | only the image's Ubuntu base, by digest, when it is rebuilt; no workflow pulls from it | a rebuild needs the base from somewhere else. |
| The BSD projects' mirrors | the BSD jobs | those jobs, which are best effort. |
| Google Play, the App Store, itch.io, Firebase | publishing | publishing to that store. |
| Anthropic's API | the autofix agent, and the agents that work on the framework | nothing builds from it. |
The versions block of thirdparty/FROZEN_VERSIONS.md, read when this site
is built. A long digest is cut to its first sixteen characters.
| Key | Pinned to |
|---|---|
build_image_digest | sha256:6fb4255df4a97317… |
run_alpine_digest | sha256:5823e1e4fa870083… |
build_riscv64_digest | sha256:c3946112f78f4ac5… |
android_platform | android-36 |
android_build_tools | 36.0.0 |
android_ndk | 28.2.13676358 |
android_sdk_cmake | 3.31.6 |
android_compile_sdk | 36 |
android_target_sdk | 36 |
android_min_sdk | 24 |
agp | 8.13.2 |
gradle | 8.14.5 |
gradle_sha256 | 6f74b601422d6d6f… |
play_services_ads | 24.9.0 |
llvm | 18.1.3 |
cppcheck | 2.13.0 |
mull | 0.34.1 |
hypothesis | 6.168.5 |
mutmut | 3.8.0 |
pytest | 9.1.1 |
tcc_commit | e23dabed154a8495f3ac1ff3cc9d04fa1c207893 |
tcc | 0.9.28rc |
mingw_gcc | 13-posix |
lld | 18.1.3 |
xwin | 0.10.0 |
wine | 9.0 |
macos_runner | macos-26 |
xcode | 26.6 |
ninja_mac | 1.13.2 |
ninja_mac_sha256 | c99048673aa76596… |
xcodegen | 2.46.0 |
xcodegen_sha256 | 4d9e34b62172d645… |
windows_runner | windows-2025 |
mesa | 26.1.6 |
mesa_sha256 | 86b506ad38b8dae9… |
pillow | 12.3.0 |
pillow_sha256_cp311_win_amd64 | 8e95e1385e4998ae… |
pillow_sha256_cp312_win_amd64 | a2b55dd6b2a4c4b7… |
pillow_sha256_cp313_win_amd64 | 1cca606cd25738df… |
pillow_sha256_cp314_win_amd64 | fdafc9cce40277e0… |
upx | 5.2.0 |
upx_sha256_amd64 | 3db5d3294707439d… |
upx_sha256_arm64 | 55d48a61e8ffd171… |
upx_sha256_win64 | b471ebf1b7f20f4a… |
zig | 0.16.0 |
zig_sha256_x86_64 | 70e49664a74374b4… |
zig_sha256_aarch64 | ea4b09bfb22ec6f6… |
clang_format | 22.1.8 |
clang_tidy | 22.1.8 |
apt_snapshot | 20260801T000000Z |
ubuntu | 24.04 |
cmake | 3.30.3 |
ninja_linux | 1.12.1 |
emscripten | 3.1.61 |
actionlint | 1.7.12 |
butler | 15.24.0 |
freebsd | 15.1 |
openbsd | 7.9 |
netbsd | 10.1 |
sha256_cute_aseprite | 1c2c71f68151b854… |
sha256_doctest | a58efc9446d70ddd… |
sha256_rapidcheck | 517d44bb22a3719d… |
sha256_rres | 913d59b01a7617aa… |
sha256_cjson | 5dbda89922a5a397… |
For each dependency, how many files of each kind name it, and then every one of those files
with how often. It is a regular expression over the framework's tracked files (the vendored copy
itself left out, its PATCHES.md and the pins kept) and over this site's pages, run when
the site is built, so it is true of the commit this site documents. A count is where to look, not a
verdict: a file that names Gradle once in a comment is in it beside the file that builds with
it.
| Dependency | Product code | Build projects | Tools and gates | Tests | CI | Examples | Docs |
|---|---|---|---|---|---|---|---|
| raylib | 41 | 3 | 11 | 48 | 2 | 10 | 20 |
| raylib-cpp | 1 | 1 | 0 | 1 | 1 | 0 | 12 |
| raymob | 6 | 17 | 12 | 7 | 3 | 2 | 27 |
| raylib-iOS | 1 | 2 | 3 | 4 | 2 | 0 | 10 |
| Clay | 19 | 2 | 7 | 15 | 0 | 2 | 14 |
| cute_tiled | 4 | 3 | 4 | 6 | 1 | 0 | 10 |
| cute_aseprite | 4 | 2 | 6 | 6 | 1 | 0 | 8 |
| cJSON | 9 | 2 | 5 | 9 | 1 | 0 | 8 |
| rres | 14 | 4 | 17 | 12 | 4 | 3 | 20 |
| doctest | 0 | 2 | 8 | 72 | 2 | 0 | 13 |
| RapidCheck | 0 | 0 | 3 | 38 | 2 | 0 | 13 |
| Android build stack | 2 | 17 | 7 | 5 | 7 | 1 | 25 |
| Apple toolchain | 3 | 3 | 5 | 2 | 8 | 2 | 25 |
| Emscripten | 7 | 4 | 4 | 5 | 3 | 2 | 21 |
| zig | 1 | 1 | 4 | 3 | 1 | 0 | 9 |
| The build image | 0 | 1 | 14 | 8 | 11 | 0 | 13 |
| LLVM test tools | 0 | 2 | 9 | 50 | 3 | 0 | 14 |
| clang-format and clang-tidy | 10 | 3 | 11 | 6 | 1 | 1 | 31 |
| Python test tools | 0 | 0 | 6 | 15 | 2 | 0 | 12 |
| Pillow | 0 | 1 | 7 | 2 | 3 | 1 | 9 |
| PyYAML | 0 | 0 | 2 | 6 | 2 | 0 | 2 |
| Playwright | 0 | 0 | 0 | 0 | 4 | 0 | 4 |
| BSD virtual machines | 0 | 1 | 4 | 3 | 3 | 0 | 8 |
the window, input, audio and renderer; a modified copy. Its version: the committed files, and PATCHES.md.
include/rmp/math.h (6), src/rmp/assets/rres_impl.cpp (6), src/rmp/assets/assets.cpp (3), include/rmp/app.h (2), src/rmp/app/app.cpp (2), src/rmp/assets/loader_hook.cpp (2), src/rmp/assets/pack.cpp (2), src/rmp/save/save.cpp (2), src/rmp/ui/backdrop.cpp (2), include/rmp/assets.h (1), include/rmp/behavior.h (1), include/rmp/input.h (1), include/rmp/object.h (1), include/rmp/random.h (1), include/rmp/scene.h (1), include/rmp/tilemap.h (1), include/rmp/ui.h (1), src/rmp/app/clock.cpp (1), src/rmp/app/console.cpp (1), src/rmp/app/report.cpp (1), src/rmp/app/stretch.cpp (1), src/rmp/assets/animation_internal.h (1), src/rmp/assets/pack_internal.h (1), src/rmp/assets/resource.cpp (1), src/rmp/audio/audio.cpp (1), src/rmp/behavior/behavior_internal.h (1), src/rmp/dialogue/dialogue.cpp (1), src/rmp/internal.h (1), src/rmp/scene/camera.cpp (1), src/rmp/scene/object_internal.h (1), src/rmp/scene/scene_internal.h (1), src/rmp/text/text.cpp (1), src/rmp/tilemap/ldtk.cpp (1), src/rmp/tilemap/tiled_impl.cpp (1), src/rmp/tilemap/tilemap_internal.h (1), src/rmp/ui/context.cpp (1), src/rmp/ui/floating.h (1), src/rmp/ui/internal.h (1), src/rmp/ui/render.cpp (1), src/rmp/ui/rich.cpp (1), src/rmp/ui/ui_internal.h (1)CMakeLists.txt (8), raymob/app/src/main/cpp/CMakeLists.txt (3), ios/README.md (2)tools/configure.py (8), tools/naming_check.sh (8), tools/ownership_check.sh (5), tools/cppcheck_check.sh (3), tools/rmp.py (2), tools/android_release_check.py (1), tools/header_check.sh (1), tools/header_cost.py (1), tools/license_db.py (1), tools/pointer_check.py (1), tools/rres_pack.c (1)tests/configure_test.py (39), tests/rlsw_sample.c (8), tests/rmp_test.py (6), tests/android_release_check_property_test.py (3), tests/gates_red_test.py (3), tests/rlsw_test.cpp (3), tests/smoke_test.h (2), tests/ui_overlay_test.cpp (2), tests/ui_render_test.cpp (2), tests/aseprite_builder.h (1), tests/assets_test.cpp (1), tests/audio_device_test.cpp (1), tests/audio_test.cpp (1), tests/campaign_test.py (1), tests/console_canary.cpp (1), tests/e2e/compare.h (1), tests/e2e/driver.cpp (1), tests/e2e/script.cpp (1), tests/e2e_test.cpp (1), tests/fuzz/harness.h (1), tests/fuzz/map_walk.h (1), tests/fuzz/rres.cpp (1), tests/input_play.cpp (1), tests/ldtk_test.cpp (1), tests/pack_writer.h (1), tests/platformer_play.cpp (1), tests/property/animation_prop.cpp (1), tests/property/app_prop.cpp (1), tests/property/assets_prop.cpp (1), tests/property/audio_prop.cpp (1), tests/property/behavior_more_prop.cpp (1), tests/property/behavior_prop.cpp (1), tests/property/camera_prop.cpp (1), tests/property/core_prop.cpp (1), tests/property/gen.h (1), tests/property/input_prop.cpp (1), tests/property/ldtk_prop.cpp (1), tests/property/map_gen.h (1), tests/property/save_prop.cpp (1), tests/property/scene_prop.cpp (1), tests/property/tilemap_prop.cpp (1), tests/property/ui_look_prop.cpp (1), tests/property/ui_prop.cpp (1), tests/property/ui_text_prop.cpp (1), tests/property/value_prop.cpp (1), tests/tilemap_cull_test.cpp (1), tests/ui_style_test.cpp (1), tests/watch_test.cpp (1).github/workflows/web-backends.yml (2), .github/workflows/_release.yml (1)examples/ads/01_interstitial/src/main.cpp (1), examples/games/07_platformer/include/game.h (1), examples/games/07_platformer/include/objects.h (1), examples/games/08_dungeon/include/cast.h (1), examples/games/08_dungeon/include/dungeon.h (1), examples/games/08_dungeon/src/objects/monsters.cpp (1), examples/games/08_dungeon/src/objects/things.cpp (1), examples/plain_c/src/main.c (1), examples/platform/02_mobile_raymob/src/main.cpp (1), examples/platform/03_minimal_includes/src/hud.cpp (1)THIRD_PARTY_LICENSES.md (40), CLAUDE.md (15), thirdparty/raylib/PATCHES.md (9), TECHNICAL.md (6), README.md (5), thirdparty/FROZEN_VERSIONS.md (5), raylib_multiplatform.toml (4)manual/raylib/rlgl.html (6), framework/architecture.html (5), manual/raylib/raylib.html (5), framework/licences.html (4), manual/core/app.html (4), framework/contributing/coverage-and-gates.html (1), framework/why/one-header-per-module.html (1), getting-started/a-player.html (1), guidelines/macros.html (1), manual/basics/headers.html (1), manual/modules/assets.html (1), manual/platforms/android.html (1), manual/platforms/linux-console.html (1)the math types only: vectors, matrices, rectangles, colours. Its version: the committed files.
include/rmp/math.h (12)raymob/app/src/main/cpp/CMakeLists.txt (1)tests/configure_test.py (7).github/workflows/_windows.yml (1)THIRD_PARTY_LICENSES.md (6), thirdparty/raylib-cpp/PATCHES.md (4), thirdparty/FROZEN_VERSIONS.md (3), CLAUDE.md (2), TECHNICAL.md (2), README.md (1)manual/basics/headers.html (4), framework/architecture.html (2), framework/licences.html (1), framework/performance.html (1), framework/why/no-exceptions.html (1), manual/raylib/raylib.html (1)Android's native glue and its Java side; patched. Its version: the committed files, and PATCHES.md.
src/rmp/app/app.cpp (4), include/rmp/ads.h (3), src/rmp/save/save.cpp (3), src/rmp/text/text.cpp (2), src/rmp/ads/ads.cpp (1), src/rmp/save/cjson_impl.c (1)raymob/app/build.gradle (47), raymob/app/src/main/java/com/raylib/raymob/NativeLoader.java (16), raymob/README.md (14), CMakeLists.txt (9), raymob/app/src/main/cpp/CMakeLists.txt (7), raymob/app/proguard-rules.pro (5), raymob/app/src/admob/java/com/raylib/raymob/AdmobBridge.java (5), raymob/app/src/main/java/com/raylib/raymob/SoftKeyboard.java (4), raymob/app/src/noadmob/java/com/raylib/raymob/AdmobBridge.java (4), raymob/app/AndroidManifest.template.xml (2), cmake/sanitize.cmake (1), raymob/LICENSE (1), raymob/app/src/main/cpp/gl_version.cmake (1), raymob/app/src/main/java/com/raylib/raymob/DisplayManager.java (1), raymob/app/src/main/res/values/strings.xml (1), raymob/gradle.properties (1), raymob/settings.gradle (1)tools/configure.py (19), tools/rmp.py (15), tools/versions_check.sh (5), tools/android_release_check.py (3), tools/naming_check.sh (3), tools/dev_shell.sh (1), tools/header_check.sh (1), tools/header_cost.py (1), tools/license_db.py (1), tools/pointer_check.py (1), tools/size_check.py (1), tools/style_check.sh (1)tests/configure_test.py (97), tests/rmp_test.py (12), tests/configure_property_test.py (7), tests/ads_test.cpp (1), tests/android_release_check_property_test.py (1), tests/gates_red_test.py (1), tests/property/core_prop.cpp (1).github/workflows/_android.yml (24), .github/workflows/_windows.yml (3), .github/workflows/_firebase.yml (1)examples/platform/02_mobile_raymob/src/main.cpp (9), examples/README.md (4)TECHNICAL.md (41), thirdparty/FROZEN_VERSIONS.md (26), thirdparty/raymob/PATCHES.md (10), THIRD_PARTY_LICENSES.md (8), CLAUDE.md (7), .claude/skills/rmp-code-style/SKILL.md (1), README.md (1), raylib_multiplatform.toml (1)manual/platforms/android.html (20), manual/basics/project-layout.html (8), publishing/google-play.html (8), framework/architecture.html (5), framework/config-pipeline.html (5), manual/help/troubleshooting.html (4), manual/modules/ads.html (4), framework/testing.html (3), manual/basics/configuration.html (3), framework/licences.html (2), manual/raylib/plain-c.html (2), publishing/releases.html (2), framework/contributing/repository.html (1), framework/contributing/rules.html (1), framework/security.html (1), guidelines/naming.html (1), manual/platforms/index.html (1), manual/raylib/raylib.html (1), publishing/itch.html (1).gitignore (13), .clangd (1)the iOS backend, UIKit and EGL through ANGLE; a fork of a fork. Its version: the submodule's commit.
include/rmp/app.h (1)ios/README.md (12), ios/ANGLE-LICENSE.txt (7)tools/configure.py (18), tools/rmp.py (3), tools/license_db.py (2)tests/configure_test.py (5), tests/rmp_test.py (5), tests/rmp_property_test.py (1), tests/smoke_test.h (1).github/workflows/_apple.yml (8), .github/workflows/ci.yml (3)THIRD_PARTY_LICENSES.md (16), TECHNICAL.md (11), thirdparty/FROZEN_VERSIONS.md (4)manual/platforms/ios.html (9), publishing/app-store.html (9), framework/architecture.html (3), framework/licences.html (3), manual/raylib/rlgl.html (2), manual/basics/project-layout.html (1), manual/platforms/index.html (1).gitmodules (5)the UI's layout engine, used only under src/rmp/ui/. Its version: the committed file, and PATCHES.md.
src/rmp/ui/containers.cpp (166), src/rmp/ui/context.cpp (135), src/rmp/ui/controls.cpp (120), src/rmp/ui/widgets.cpp (99), src/rmp/ui/tooltip.cpp (81), src/rmp/ui/internal.h (77), src/rmp/ui/overlay.cpp (62), src/rmp/ui/notify.cpp (55), src/rmp/ui/render.cpp (41), src/rmp/ui/at.cpp (34), src/rmp/ui/look.cpp (22), src/rmp/ui/dialogue_ui.cpp (21), src/rmp/ui/rich.cpp (15), src/rmp/ui/clay_impl.cpp (4), src/rmp/ui/focus.cpp (3), src/rmp/ui/style.cpp (3), include/rmp/ui.h (2), src/rmp/ui/backdrop.cpp (2), src/rmp/ui/kept.cpp (2)CMakeLists.txt (2), raymob/app/src/main/cpp/CMakeLists.txt (1)tools/naming_check.sh (3), tools/cppcheck_check.sh (2), tools/configure.py (1), tools/header_check.sh (1), tools/header_cost.py (1), tools/lint.sh (1), tools/pointer_check.py (1)tests/ui_layout_test.cpp (150), tests/ui_style_test.cpp (86), tests/ui_floating_test.cpp (66), tests/ui_overlay_test.cpp (36), tests/property/ui_prop.cpp (24), tests/scene_test.cpp (18), tests/property/ui_text_prop.cpp (15), tests/hud_focus_test.cpp (14), tests/ui_render_test.cpp (14), tests/property/ui_look_prop.cpp (10), tests/input_test.cpp (6), tests/configure_test.py (3), tests/e2e/driver.cpp (2), tests/android_release_check_property_test.py (1), tests/e2e/ui/03_clay_direct.e2e (1)examples/ui/03_clay_direct/src/main.cpp (22), examples/README.md (1).claude/skills/rmp-ui-internals/SKILL.md (28), TECHNICAL.md (13), CLAUDE.md (5), .claude/skills/rmp-code-style/SKILL.md (3), THIRD_PARTY_LICENSES.md (3), thirdparty/FROZEN_VERSIONS.md (3), thirdparty/clay/PATCHES.md (3)manual/raylib/clay.html (55), framework/contributing/tests.html (9), manual/modules/ui.html (6), manual/raylib/raylib.html (2), framework/why/macros.html (1), manual/modules/ui-style.html (1), manual/raylib/index.html (1)the Tiled map reader; patched and hardened. Its version: the committed file, and PATCHES.md.
src/rmp/tilemap/tilemap.cpp (29), src/rmp/tilemap/tiled_impl.cpp (5), include/rmp/tilemap.h (1), src/rmp/tilemap/tilemap_internal.h (1)cmake/sanitize_ignore.txt (4), CMakeLists.txt (2), raymob/app/src/main/cpp/CMakeLists.txt (2)tools/naming_check.sh (3), tools/configure.py (1), tools/cppcheck_check.sh (1), tools/header_cost.py (1)tests/configure_test.py (9), tests/tilemap_test.cpp (9), tests/fuzz/tiled.cpp (3), tests/property/ldtk_prop.cpp (3), tests/campaign_test.py (1), tests/fuzz/tiled.dict (1).github/workflows/_windows.yml (1)thirdparty/cute_tiled/PATCHES.md (26), THIRD_PARTY_LICENSES.md (7), CLAUDE.md (3), thirdparty/FROZEN_VERSIONS.md (3), TECHNICAL.md (2), README.md (1)framework/security.html (2), framework/architecture.html (1), framework/licences.html (1), guidelines/pointers-and-raii.html (1).clang-tidy (3)the Aseprite reader. Its version: sha256_cute_aseprite.
src/rmp/assets/aseprite.cpp (41), src/rmp/assets/animation.cpp (10), src/rmp/assets/animation_internal.h (5), src/rmp/assets/aseprite_impl.cpp (2)CMakeLists.txt (2), raymob/app/src/main/cpp/CMakeLists.txt (1)tools/ownership_check.sh (10), tools/naming_check.sh (2), tools/configure.py (1), tools/cppcheck_check.sh (1), tools/header_cost.py (1), tools/make_aseprite_fixture.py (1)tests/animation_test.cpp (57), tests/configure_test.py (15), tests/property/animation_prop.cpp (10), tests/fuzz/aseprite.cpp (5), tests/aseprite_builder.h (2), tests/campaign_test.py (1).github/workflows/_windows.yml (1)CLAUDE.md (5), thirdparty/FROZEN_VERSIONS.md (4), TECHNICAL.md (3), THIRD_PARTY_LICENSES.md (3)framework/architecture.html (1), framework/licences.html (1), guidelines/enforcement.html (1), guidelines/pointers-and-raii.html (1).clang-tidy (3)JSON, for saves and LDtk. Its version: sha256_cjson.
src/rmp/tilemap/ldtk.cpp (88), src/rmp/save/save.cpp (34), src/rmp/save/json_internal.h (6), src/rmp/save/cjson_impl.c (4), src/rmp/save/number_internal.h (3), include/rmp/save.h (1), include/rmp/tilemap.h (1), src/rmp/save/save_internal.h (1), src/rmp/tilemap/tilemap_internal.h (1)CMakeLists.txt (1), raymob/app/src/main/cpp/CMakeLists.txt (1)tools/configure.py (2), tools/cppcheck_check.sh (2), tools/naming_check.sh (2), tools/license_db.py (1), tools/test_locales.sh (1)tests/ldtk_test.cpp (56), tests/fuzz/ldtk.cpp (14), tests/configure_test.py (8), tests/property/ldtk_prop.cpp (4), tests/save_test.cpp (3), tests/campaign_test.py (1), tests/fixtures/locale/rmp_twobyte (1), tests/property/map_gen.h (1), tests/property/value_model.h (1).github/workflows/_windows.yml (1)thirdparty/FROZEN_VERSIONS.md (7), TECHNICAL.md (4), THIRD_PARTY_LICENSES.md (4), CLAUDE.md (2), raylib_multiplatform.toml (1)framework/architecture.html (4), framework/licences.html (1), guidelines/pointers-and-raii.html (1).clang-tidy (3)the resource pack, its compression and its encryption. Its version: sha256_rres.
src/rmp/assets/pack.cpp (46), src/rmp/assets/pack_internal.h (12), src/rmp/assets/rres_impl.cpp (9), src/rmp/assets/assets.cpp (4), src/rmp/tilemap/tilemap.cpp (4), include/rmp/assets.h (3), src/rmp/assets/loader_hook.cpp (3), src/rmp/internal.h (2), src/rmp/save/save.cpp (2), include/rmp/app.h (1), src/rmp/app/app.cpp (1), src/rmp/save/save_internal.h (1), src/rmp/tilemap/tiled_impl.cpp (1), src/scenes/main_menu.cpp (1)CMakeLists.txt (24), raymob/app/build.gradle (3), cmake/sanitize.cmake (1), raymob/app/src/main/cpp/CMakeLists.txt (1)tools/rres_pack.c (15), tools/make_zero_pack.py (13), tools/configure.py (10), tools/rmp.py (7), tools/ship_resources.sh (7), tools/license_db.py (5), tools/ownership_check.sh (5), tools/.clang-tidy (4), tools/naming_check.sh (4), tools/shipped_check.sh (3), tools/lint.sh (2), tools/cppcheck_check.sh (1), tools/header_check.sh (1), tools/header_cost.py (1), tools/md5.c (1), tools/md5.h (1), tools/pointer_check.py (1)tests/assets_test.cpp (79), tests/configure_test.py (54), tests/fuzz/rres.cpp (33), tests/property/assets_prop.cpp (19), tests/pack_writer.h (10), tests/fuzz/resource_path.cpp (6), tests/fuzz/rres.dict (3), tests/animation_test.cpp (1), tests/campaign_test.py (1), tests/fixtures/pack_aes/hello.txt (1), tests/rmp_test.py (1), tests/watch_test.cpp (1).github/workflows/_linux.yml (13), .github/workflows/_windows.yml (11), .github/workflows/_apple.yml (2), .github/workflows/_bsd.yml (2)examples/assets/01_loading/src/main.cpp (3), examples/README.md (1), examples/plain_c/src/main.c (1)TECHNICAL.md (33), THIRD_PARTY_LICENSES.md (10), thirdparty/FROZEN_VERSIONS.md (7), raylib_multiplatform.toml (3), CLAUDE.md (2), .claude/skills/rmp-verify/SKILL.md (1), README.md (1)manual/modules/assets.html (10), framework/architecture.html (3), manual/basics/project-layout.html (2), manual/raylib/plain-c.html (2), publishing/desktop.html (2), framework/licences.html (1), getting-started/art-and-sound.html (1), guidelines/pointers-and-raii.html (1), manual/basics/the-rmp-command.html (1), manual/platforms/desktop.html (1), manual/raylib/rlgl.html (1), publishing/index.html (1), publishing/web.html (1).clang-tidy (4), .gitignore (1)the unit test framework, shipped with every game's tests. Its version: sha256_doctest.
cmake/game_tests.cmake (8), CMakeLists.txt (4)tools/finding.py (3), tools/naming_check.sh (2), tools/rmp.py (2), tools/sanitize_check.sh (2), tools/configure.py (1), tools/license_db.py (1), tools/lint.sh (1), tools/mutation.sh (1)tests/object_test.cpp (117), tests/ldtk_test.cpp (98), tests/camera_test.cpp (91), tests/collision_test.cpp (81), tests/tilemap_test.cpp (71), tests/behaviors_test.cpp (44), tests/input_test.cpp (44), tests/behavior_test.cpp (43), tests/map_collision_test.cpp (32), tests/ui_style_test.cpp (28), tests/behaviors_more_test.cpp (26), tests/audio_test.cpp (22), tests/campaign_test.py (17), tests/rmp_test.py (13), tests/stretch_test.cpp (9), tests/ui_layout_test.cpp (9), tests/animation_test.cpp (8), tests/property/check.h (8), tests/ui_overlay_test.cpp (8), tests/clock_test.cpp (6), tests/gates_red_test.py (6), tests/unit_test.cpp (6), tests/configure_test.py (5), tests/property/main.cpp (5), tests/audio_device_test.cpp (4), tests/save_test.cpp (4), tests/property/gen_prop.cpp (3), tests/ui_floating_test.cpp (3), tests/console_test.cpp (2), tests/deep.cmake (2), tests/dialogue_game_test.cpp (2), tests/game/main_menu_test.cpp (2), tests/ads_test.cpp (1), tests/assets_test.cpp (1), tests/dialogue_test.cpp (1), tests/e2e_test.cpp (1), tests/global_test.cpp (1), tests/hud_focus_test.cpp (1), tests/property/animation_prop.cpp (1), tests/property/app_prop.cpp (1), tests/property/assets_prop.cpp (1), tests/property/audio_prop.cpp (1), tests/property/behavior_more_prop.cpp (1), tests/property/behavior_prop.cpp (1), tests/property/camera_prop.cpp (1), tests/property/clock_prop.cpp (1), tests/property/collision_prop.cpp (1), tests/property/core_prop.cpp (1), tests/property/dialogue_game_prop.cpp (1), tests/property/dialogue_prop.cpp (1), tests/property/input_prop.cpp (1), tests/property/ldtk_prop.cpp (1), tests/property/object_gen.h (1), tests/property/object_prop.cpp (1), tests/property/random_prop.cpp (1), tests/property/save_prop.cpp (1), tests/property/scene_prop.cpp (1), tests/property/text_prop.cpp (1), tests/property/tilemap_prop.cpp (1), tests/property/ui_look_prop.cpp (1), tests/property/ui_prop.cpp (1), tests/property/ui_text_prop.cpp (1), tests/property/value_prop.cpp (1), tests/property/watch_prop.cpp (1), tests/report_test.cpp (1), tests/rlsw_test.cpp (1), tests/sanitize_test.cpp (1), tests/scene_test.cpp (1), tests/text_test.cpp (1), tests/tilemap_cull_test.cpp (1), tests/watch_test.cpp (1), tests/yarn_plan_test.cpp (1).github/workflows/ci.yml (2), .github/workflows/deep.yml (1)thirdparty/FROZEN_VERSIONS.md (9), CLAUDE.md (4), THIRD_PARTY_LICENSES.md (3), TECHNICAL.md (2), .claude/skills/rmp-verify/SKILL.md (1)framework/contributing/tests.html (13), framework/contributing/properties-fuzzing-mutation.html (8), framework/testing.html (4), framework/licences.html (3), framework/contributing/pull-requests.html (1), framework/contributing/repository.html (1), getting-started/your-first-scene.html (1), manual/basics/project-layout.html (1)the C++ property tests; the framework's only. Its version: sha256_rapidcheck.
tools/naming_check.sh (8), tools/rmp.py (4), tools/finding.py (2)tests/property/value_prop.cpp (111), tests/property/object_prop.cpp (101), tests/property/behavior_prop.cpp (86), tests/property/animation_prop.cpp (73), tests/property/app_prop.cpp (60), tests/property/input_prop.cpp (60), tests/property/camera_prop.cpp (59), tests/property/ldtk_prop.cpp (57), tests/property/tilemap_prop.cpp (57), tests/property/save_prop.cpp (52), tests/property/assets_prop.cpp (48), tests/property/collision_prop.cpp (48), tests/property/ui_prop.cpp (48), tests/property/random_prop.cpp (44), tests/property/ui_look_prop.cpp (44), tests/property/behavior_more_prop.cpp (43), tests/property/audio_prop.cpp (39), tests/property/dialogue_prop.cpp (34), tests/property/scene_prop.cpp (32), tests/rmp_test.py (24), tests/campaign_test.py (22), tests/property/core_prop.cpp (22), tests/deep.cmake (21), tests/property/text_prop.cpp (21), tests/property/dialogue_game_prop.cpp (14), tests/property/clock_prop.cpp (13), tests/property/ui_text_prop.cpp (12), tests/property/gen_prop.cpp (11), tests/property/gen.h (9), tests/property/watch_prop.cpp (8), tests/property/object_gen.h (7), tests/property/map_gen.h (6), tests/property/check.h (5), tests/property/value_model.h (3), tests/configure_test.py (2), tests/pack_writer.h (2), tests/property/main.cpp (1), tests/rmp_property_test.py (1).github/workflows/deep.yml (10), .github/workflows/ci.yml (4)TECHNICAL.md (8), CLAUDE.md (6), thirdparty/FROZEN_VERSIONS.md (5), THIRD_PARTY_LICENSES.md (4), .claude/skills/rmp-verify/SKILL.md (2)framework/contributing/properties-fuzzing-mutation.html (24), framework/licences.html (4), framework/contributing/rules.html (2), framework/testing.html (2), guidelines/index.html (2), framework/contributing/ci.html (1), framework/contributing/ladder.html (1), framework/contributing/tests.html (1)Gradle, AGP, the SDK, the NDK and AdMob's SDK. Its version: android_*, agp, gradle, play_services_ads.
src/rmp/app/app.cpp (1), src/scenes/main_menu.h (1)raymob/settings.gradle (13), raymob/gradlew (8), raymob/build.gradle (7), raymob/gradle.properties (7), raymob/gradlew.bat (7), raymob/app/build.gradle (6), raymob/app/AndroidManifest.template.xml (5), raymob/README.md (4), raymob/.gitignore (3), raymob/app/proguard-rules.pro (3), raymob/app/src/main/cpp/CMakeLists.txt (3), raymob/app/src/main/cpp/gl_version.cmake (3), CMakeLists.txt (2), raymob/app/src/admob/java/com/raylib/raymob/AdmobBridge.java (2), raymob/app/src/main/java/com/raylib/raymob/NativeLoader.java (2), raymob/gradle/wrapper/gradle-wrapper.properties (2), raymob/app/src/noadmob/java/com/raylib/raymob/AdmobBridge.java (1)tools/versions_check.sh (52), tools/configure.py (32), tools/rmp.py (21), tools/android_release_check.py (3), tools/size_check.py (2), tools/dev_shell.sh (1), tools/license_db.py (1)tests/configure_test.py (134), tests/rmp_test.py (26), tests/configure_property_test.py (8), tests/android_release_check_property_test.py (4), tests/size_check_test.py (1).github/workflows/_android.yml (44), .github/scripts/upstream_report.py (9), .github/scripts/canary_triage.py (8), .github/dependabot.yml (4), .github/workflows/_apple.yml (2), .github/workflows/_windows.yml (2), .github/workflows/_firebase.yml (1)examples/scenes/01_stack/src/main.cpp (1)TECHNICAL.md (35), thirdparty/FROZEN_VERSIONS.md (18), CLAUDE.md (6), raylib_multiplatform.toml (6), README.md (1), THIRD_PARTY_LICENSES.md (1)manual/platforms/android.html (25), publishing/ci.html (19), framework/config-pipeline.html (12), publishing/google-play.html (11), manual/basics/configuration.html (6), manual/basics/project-layout.html (5), framework/architecture.html (3), manual/help/troubleshooting.html (3), framework/why/macros.html (2), framework/index.html (1), framework/security.html (1), framework/testing.html (1), manual/basics/headers.html (1), manual/basics/index.html (1), manual/basics/the-rmp-command.html (1), manual/modules/ads.html (1), manual/platforms/index.html (1), publishing/itch.html (1), publishing/releases.html (1).gitignore (1)Xcode, XcodeGen and the macOS runner. Its version: xcode, xcodegen, macos_runner.
src/rmp/app/app.cpp (1), src/rmp/save/cjson_impl.c (1), src/scenes/main_menu.h (1)ios/README.md (14), CMakeLists.txt (3), cmake/sanitize.cmake (1)tools/configure.py (14), tools/install.sh (3), tools/api_change.py (1), tools/render_check.sh (1), tools/upx_pack.sh (1)tests/configure_test.py (20), tests/configure_property_test.py (7).github/workflows/_apple.yml (43), .github/workflows/canary.yml (16), .github/scripts/canary_triage.py (13), .github/workflows/ci.yml (8), .github/workflows/autofix.yml (4), .github/scripts/upstream_report.py (3), .github/workflows/_android.yml (2), .github/workflows/_release.yml (1)examples/plain_c/src/main.c (1), examples/scenes/01_stack/src/main.cpp (1)TECHNICAL.md (22), thirdparty/FROZEN_VERSIONS.md (9), raylib_multiplatform.toml (4), CLAUDE.md (2), README.md (1)publishing/app-store.html (23), manual/platforms/ios.html (17), manual/basics/configuration.html (7), framework/config-pipeline.html (6), framework/security.html (5), manual/basics/project-layout.html (5), framework/architecture.html (4), publishing/ci.html (4), manual/platforms/index.html (3), getting-started/install.html (2), manual/help/faq.html (2), framework/contributing/ci.html (1), framework/index.html (1), framework/why/designated-initialisers.html (1), framework/why/macros.html (1), manual/basics/headers.html (1), manual/basics/index.html (1), manual/core/objects.html (1), manual/help/troubleshooting.html (1), publishing/index.html (1).clangd (1), .gitignore (1)the web build's compiler. Its version: emscripten, and the image's emsdk commit.
include/rmp/app.h (9), src/rmp/app/app.cpp (7), src/rmp/save/save.cpp (6), src/rmp/text/text.cpp (4), src/rmp/ui/backdrop.cpp (2), src/rmp/app/watch.cpp (1), src/rmp/dialogue/yarn_vm.cpp (1)CMakeLists.txt (25), cmake/web/rmp_web.js (4), CMakePresets.json (3), cmake/sanitize.cmake (1)tools/configure.py (11), tools/rmp.py (9), tools/examples_check.sh (3), tools/versions_check.sh (3)tests/configure_test.py (20), tests/rmp_test.py (4), tests/rmp_property_test.py (3), tests/save_test.cpp (2), tests/smoke_test.h (1).github/workflows/web-backends.yml (9), .github/scripts/web_boot_test.js (3), .github/workflows/_web.yml (2)examples/plain_c/src/main.c (3), examples/ui/04_settings/src/main.cpp (2)TECHNICAL.md (14), raylib_multiplatform.toml (12), thirdparty/raylib/PATCHES.md (5), thirdparty/FROZEN_VERSIONS.md (4), .claude/skills/rmp-verify/SKILL.md (1), CLAUDE.md (1)manual/platforms/web.html (21), publishing/web.html (12), manual/raylib/raylib.html (6), manual/help/troubleshooting.html (5), framework/the-frame.html (2), manual/basics/the-rmp-command.html (2), framework/architecture.html (1), framework/licences.html (1), framework/security.html (1), getting-started/install.html (1), manual/core/app.html (1), manual/help/faq.html (1), manual/platforms/index.html (1), publishing/ci.html (1), publishing/desktop.html (1)the Linux cross-compiler that sets the glibc floor. Its version: zig, zig_sha256_*.
src/rmp/save/number_internal.h (1)CMakeLists.txt (7)tools/linux_build.sh (34), tools/versions_check.sh (6), tools/glibc_check.sh (4), tools/binary_check.py (1)tests/binary_check_test.py (3), tests/configure_test.py (3), tests/rmp_test.py (1).github/workflows/_linux.yml (6)CLAUDE.md (2), raylib_multiplatform.toml (2), thirdparty/FROZEN_VERSIONS.md (2), thirdparty/raylib/PATCHES.md (2)framework/security.html (11), manual/platforms/desktop.html (3), getting-started/install.html (1), publishing/ci.html (1), publishing/desktop.html (1).gitignore (2)every Linux, web and Android job's toolchain. Its version: build_image_digest.
raymob/app/src/main/cpp/CMakeLists.txt (1)tools/dev_shell.sh (6), tools/versions_check.sh (5), tools/coverage_check.sh (3), tools/examples_build.sh (3), tools/fuzz.sh (2), tools/mutation.sh (2), tools/coverage_report.py (1), tools/finding.py (1), tools/glibc_check.sh (1), tools/header_cost.py (1), tools/linux_build.sh (1), tools/rmp.py (1), tools/upx_pack.sh (1), tools/workflow_check.sh (1)tests/configure_test.py (6), tests/coverage_report_test.py (4), tests/e2e/driver.cpp (2), tests/api_change_test.py (1), tests/campaign_test.py (1), tests/configure_property_test.py (1), tests/gates_red_test.py (1), tests/rmp_test.py (1).github/workflows/_linux.yml (8), .github/workflows/ci.yml (6), .github/scripts/canary_triage.py (4), .github/workflows/deep.yml (4), .github/workflows/autofix.yml (2), .github/workflows/web-backends.yml (2), .github/dependabot.yml (1), .github/pull_request_template.md (1), .github/workflows/_android.yml (1), .github/workflows/_web.yml (1), .github/workflows/canary.yml (1)thirdparty/FROZEN_VERSIONS.md (8), TECHNICAL.md (6), .claude/skills/rmp-verify/SKILL.md (3), CLAUDE.md (3)framework/contributing/setup.html (10), getting-started/install.html (5), framework/contributing/properties-fuzzing-mutation.html (4), framework/security.html (3), framework/contributing/coverage-and-gates.html (2), framework/contributing/examples-and-e2e.html (2), framework/contributing/ladder.html (2), framework/contributing/repository.html (2), publishing/ci.html (1).devcontainer/devcontainer.json (1)coverage, the sanitizers' runtimes, libFuzzer and Mull. Its version: llvm, mull.
cmake/sanitize.cmake (2), CMakeLists.txt (1)tools/mutation.sh (17), tools/fuzz.sh (16), tools/coverage_check.sh (8), tools/mutation_report.py (8), tools/rmp.py (4), tools/coverage_report.py (2), tools/finding.py (2), tools/versions_check.sh (2), tools/configure.py (1)tests/campaign_test.py (18), tests/save_test.cpp (12), tests/coverage_report_test.py (5), tests/fuzz/aseprite.cpp (5), tests/fuzz/e2e_script.cpp (5), tests/fuzz/ldtk.cpp (5), tests/fuzz/replay_main.cpp (5), tests/deep.cmake (4), tests/fuzz/harness.h (4), tests/fuzz/rres.cpp (4), tests/fuzz/tiled.cpp (4), tests/unit_test.cpp (4), tests/fuzz/lang_tsv.cpp (3), tests/fuzz/test_window.cpp (3), tests/fuzz/value_json.cpp (3), tests/fuzz/yarn.cpp (3), tests/watch_test.cpp (3), tests/assets_test.cpp (2), tests/fuzz/e2e_script.dict (2), tests/fuzz/ldtk.dict (2), tests/fuzz/resource_path.cpp (2), tests/fuzz/save_decode.cpp (2), tests/fuzz/save_framed.cpp (2), tests/fuzz/save_sealed_flip.cpp (2), tests/fuzz/test_window.dict (2), tests/fuzz/tiled.dict (2), tests/configure_test.py (1), tests/fuzz/aseprite.dict (1), tests/fuzz/aseprite.options (1), tests/fuzz/e2e_script.options (1), tests/fuzz/lang_tsv.options (1), tests/fuzz/ldtk.options (1), tests/fuzz/map_walk.h (1), tests/fuzz/resource_path.options (1), tests/fuzz/rres.options (1), tests/fuzz/save_decode.options (1), tests/fuzz/save_framed.dict (1), tests/fuzz/save_framed.options (1), tests/fuzz/save_sealed_flip.options (1), tests/fuzz/test_window.options (1), tests/fuzz/tiled.options (1), tests/fuzz/value_json.dict (1), tests/fuzz/value_json.options (1), tests/fuzz/yarn.options (1), tests/ldtk_test.cpp (1), tests/property/assets_prop.cpp (1), tests/property/value_prop.cpp (1), tests/property/watch_prop.cpp (1), tests/rmp_test.py (1), tests/tilemap_test.cpp (1).github/workflows/ci.yml (4), .github/workflows/_linux.yml (1), .github/workflows/deep.yml (1)CLAUDE.md (10), TECHNICAL.md (8), .claude/skills/rmp-verify/SKILL.md (4), thirdparty/FROZEN_VERSIONS.md (2), raylib_multiplatform.toml (1)framework/contributing/properties-fuzzing-mutation.html (15), framework/contributing/setup.html (9), framework/contributing/coverage-and-gates.html (4), framework/testing.html (3), framework/contributing/ci.html (2), manual/help/troubleshooting.html (2), framework/contributing/ladder.html (1), framework/contributing/tests.html (1), manual/basics/configuration.html (1).clang-tidy (1), .devcontainer/devcontainer.json (1)the formatter and the linter. Its version: clang_format, clang_tidy.
include/rmp/app.h (4), src/rmp/scene/object.cpp (2), include/rmp/object.h (1), src/rmp/assets/aseprite_impl.cpp (1), src/rmp/behavior/behavior.cpp (1), src/rmp/behavior/behaviors.cpp (1), src/rmp/behavior/behaviors_ai.cpp (1), src/rmp/behavior/behaviors_world.cpp (1), src/rmp/tilemap/tiled_impl.cpp (1), src/rmp/tilemap/tilemap.cpp (1)CMakeLists.txt (5), CMakePresets.json (1), cmake/sanitize.cmake (1)tools/lint_debt.py (19), tools/rmp.py (16), tools/lint.sh (9), tools/versions_check.sh (8), tools/cppcheck_check.sh (6), tools/style_check.sh (4), tools/naming_check.sh (2), tools/.clang-tidy (1), tools/cpp_text.py (1), tools/lint_debt.txt (1), tools/pointer_check.py (1)tests/configure_test.py (46), tests/rmp_test.py (8), tests/deep.cmake (1), tests/e2e/target.h (1), tests/gates_red_test.py (1), tests/rmp_property_test.py (1).github/workflows/ci.yml (21)examples/.clang-tidy (2)CLAUDE.md (21), .claude/skills/rmp-code-style/SKILL.md (11), thirdparty/FROZEN_VERSIONS.md (5), TECHNICAL.md (2), .claude/skills/rmp-api-design/SKILL.md (1), .claude/skills/rmp-verify/SKILL.md (1)guidelines/enforcement.html (46), guidelines/formatting.html (35), guidelines/index.html (26), framework/contributing/coverage-and-gates.html (20), framework/contributing/setup.html (20), guidelines/const.html (17), guidelines/naming.html (11), guidelines/pointers-and-raii.html (10), framework/contributing/ladder.html (9), guidelines/google.html (9), guidelines/macros.html (8), framework/security.html (7), framework/testing.html (5), framework/why/macros.html (5), guidelines/modern-cpp.html (5), guidelines/strings.html (4), framework/contributing/repository.html (3), manual/basics/the-rmp-command.html (3), framework/contributing/ci.html (2), framework/contributing/rules.html (2), framework/why/index.html (2), framework/why/the-access-rule.html (2), framework/contributing/tests.html (1), framework/why/the-three-function-menu.html (1), publishing/ci.html (1).clang-tidy (10), .clang-format (2)Hypothesis, mutmut and pytest. Its version: hypothesis, mutmut, pytest.
tools/mutation.sh (22), tools/mutation_report.py (14), tools/versions_check.sh (9), tools/rmp.py (7), tools/finding.py (3), tools/configure.py (1)tests/campaign_test.py (24), tests/hypothesis_profiles.py (19), tests/rmp_property_test.py (5), tests/cpp_text_property_test.py (4), tests/rmp_test.py (4), tests/configure_property_test.py (3), tests/header_cost_property_test.py (3), tests/android_release_check_property_test.py (2), tests/binary_check_property_test.py (2), tests/configure_test.py (2), tests/license_db_property_test.py (2), tests/api_change_test.py (1), tests/binary_check_test.py (1), tests/gates_red_test.py (1), tests/text_tool_test.py (1).github/workflows/deep.yml (16), .github/workflows/ci.yml (5)CLAUDE.md (7), TECHNICAL.md (7), .claude/skills/rmp-verify/SKILL.md (4), thirdparty/FROZEN_VERSIONS.md (3)framework/contributing/properties-fuzzing-mutation.html (19), framework/contributing/setup.html (10), framework/testing.html (6), framework/contributing/ci.html (2), framework/contributing/ladder.html (2), framework/contributing/pull-requests.html (1), framework/contributing/tests.html (1), guidelines/index.html (1).gitignore (5)the icons: the .ico, Android's and iOS's. Its version: pillow, pillow_sha256_*.
CMakeLists.txt (2)tools/configure.py (16), tools/make_dungeon_assets.py (4), tools/make_example_art.py (4), tools/make_platformer_assets.py (4), tools/make_story_assets.py (4), tools/make_skinned_art.py (3), tools/rmp.py (1)tests/configure_test.py (7), tests/dialogue/yarn/TestCases/VeryLargeFileOfVariables.yarn (1).github/workflows/_windows.yml (20), .github/workflows/_android.yml (1), .github/workflows/_apple.yml (1)examples/ui/09_skinned/resources/License-art.txt (1)thirdparty/FROZEN_VERSIONS.md (4)manual/basics/project-layout.html (4), publishing/desktop.html (3), framework/config-pipeline.html (2), manual/basics/the-rmp-command.html (2), manual/platforms/desktop.html (2), framework/security.html (1), manual/platforms/android.html (1), publishing/ci.html (1)the workflow checks read the YAML with it. Its version: the image's apt snapshot.
tools/workflow_check.sh (12), tools/shell_pattern_check.sh (2)tests/configure_test.py (47), tests/configure_property_test.py (18), tests/campaign_test.py (9), tests/rmp_test.py (8), tests/api_change_test.py (4), tests/gates_red_test.py (3).github/workflows/ci.yml (5), .github/workflows/_linux.yml (2)CLAUDE.md (3)publishing/ci.html (1)the web boot test's browser. Its version: package-lock.json.
.github/workflows/_web.yml (4), .github/workflows/web-backends.yml (3), .github/dependabot.yml (1), .github/scripts/web_boot_test.js (1)thirdparty/FROZEN_VERSIONS.md (2)publishing/ci.html (3), publishing/web.html (2), manual/basics/project-layout.html (1)package-lock.json (10), package.json (1)FreeBSD, OpenBSD and NetBSD, started by cross-platform-actions. Its version: freebsd, openbsd, netbsd.
cmake/configure_hook.cmake (1)tools/configure.py (26), tools/size_budget.txt (5), tools/portable_check.sh (2), tools/render_check.sh (1)tests/configure_test.py (15), tests/rmp_test.py (3), tests/size_check_test.py (3).github/workflows/_bsd.yml (10), .github/workflows/_itch.yml (5), .github/scripts/canary_triage.py (3)raylib_multiplatform.toml (10), CLAUDE.md (3), TECHNICAL.md (3), thirdparty/FROZEN_VERSIONS.md (3)publishing/desktop.html (7), publishing/ci.html (6), publishing/releases.html (5), framework/security.html (1)The regular expressions are DEPENDENCIES in generated.py, the module
of this site's build that makes the table; a test there fails on one that matches nothing in the
framework. A new dependency gets its line in the same pull request that adds it.
https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html
One image carries the whole toolchain of every Linux, web and Android job, so that a job downloads nothing and a green run means the same toolchain built it as last time. It lives in its own repository, raylib-build-image, and the framework names it by digest. This page is how to keep it: what is in it, how a new one is made and published, and the order of every step that pins it.
| Image | Built from | Runs | Pinned in the framework by |
|---|---|---|---|
ghcr.io/omardev29/raylib-build | Dockerfile, with python/, smoke/ and verify/; workflow docker-image.yaml | every Linux, web and Android job, the framework's own jobs, this site's CI; amd64 and arm64 | build_image_digest |
ghcr.io/omardev29/raylib-run-alpine | alpine/; workflow alpine-image.yaml | the musl build, started on Alpine; amd64 only | run_alpine_digest |
The two workflows never rebuild each other: a change under alpine/ publishes only the
Alpine image, a change to the rest only the build image.
| Layer | Pinned by |
|---|---|
| The base | ubuntu:24.04 by digest, the UBUNTU_DIGEST argument |
| Every apt package | every source rewritten to snapshot.ubuntu.com at APT_SNAPSHOT, so an install resolves to the same bytes on any day |
| Every download | a sha256 beside its version: CMake, Ninja, zig, UPX, butler, actionlint, Mull, the Android command-line tools |
| Emscripten | emsdk fetched by commit, EMSDK_COMMIT, never by tag |
| The Python test tools | the hash lock (Python) |
| The Gradle home | warmed by building the framework at GRADLE_WARM_COMMIT, and proven offline before the image is published |
Every version is an ARG at the top of the Dockerfile: one place to bump.
Rebuilding the same Dockerfile gives the same contents, but not the same digest — the
image records when it was built — which does not matter, because the framework pins the digest of
the one that was published and verified.
The image
writes /etc/raylib-build-image.json: every pinned version, and the architecture. The
versions of what came from apt or pip — LLVM, cppcheck, Mull, the Python test tools — are read from
the installed tool, not copied from an argument, so the manifest says what is in the image. Every
container job prints it first, so a red log says which toolchain produced it, and
tools/versions_check.sh, run inside the image, compares it with the framework's
versions block: a framework that asks for an SDK the image does not have fails there,
not twenty minutes into Gradle.
Two checks, and each has to do the job of the tool, not print its version:
Dockerfile itself, invokes every
tool a CI job invokes. From smoke/ it builds, runs, merges and reports a profiled
binary; makes cppcheck refuse an out-of-bounds write and accept clean C++20; has ASan, UBSan and
LSan each stop the mistake it exists for; runs libFuzzer for a hundred runs; makes Mull report the
one mutant smoke/mull.c leaves alive; and makes mutmut kill the one mutant only a
Hypothesis property can kill. A broken image fails to build.verify/image.sh, runs in the image that was
just built, on a runner of its own architecture, and checks the manifest's architecture is the
one asked for.The architectures are not the same image: arm64 has no Android SDK, no riscv64 libraries, an empty Gradle home, and no actionlint or butler, because the NDK's host tools are x86-64 only and those jobs run on amd64. The manifest leaves those keys out on arm64 rather than fake them.
| Event in the image repository | What happens |
|---|---|
| A pull request | both architectures built and verified, nothing pushed |
A manual run on a branch other than main | the same: built, verified, nothing pushed — not even :latest, which the canary floats to |
A push to main that changes the Dockerfile, python/, smoke/, verify/ or the workflow | each architecture built on a runner of its own (ubuntu-24.04, ubuntu-24.04-arm), pushed by digest, pulled back and verified at that digest; then one job makes the multi-architecture list of the two, checks it holds exactly those two, tags it with the commit, only then moves :latest, and writes the list's digest to the run's summary |
The layer cache goes to a registry tag, :buildcache, not to the Actions cache:
the image is around ten gigabytes, past what a repository's Actions cache holds. Both packages
must stay public: the framework's jobs, and the jobs of every game made from it, pull them with
their own token.
Any change to the image — a newer tool, a new package, a newer snapshot — goes the same way.
ARG (and its
sha256), on a branch. For a new apt package, add it to the install list; for a new
snapshot, change APT_SNAPSHOT, and check the two Python pins apt owns
(the lock).docker build -t raylib-build .
docker run --rm -e EXPECT_ARCH=amd64 -v "$PWD/verify:/verify:ro" raylib-build bash -l /verify/image.shtools/versions_check.sh told nothing yet — it will
report the drift you are about to fix, which proves it is reading the new manifest.main. The workflow publishes,
and the summary of that run gives the list's digest. Never pin :latest; never pin
the digest of one architecture's image.OLD=$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
NEW=sha256:... # from the image run's summary
grep -rl "$OLD" .github/workflows thirdparty/FROZEN_VERSIONS.md | xargs sed -i "s/$OLD/$NEW/g"
bash tools/versions_check.shci.yml (PINNED_IMAGE), in web-backends.yml,
three times in deep.yml — a job's container: cannot read a variable — and
in thirdparty/FROZEN_VERSIONS.md; tools/versions_check.sh fails while any
two disagree. This site follows by itself: its CI reads the image from the framework's
ci.yml at FRAMEWORK_REF.rmp test,
rmp test examples, rmp test coverage, and the size lines from a release
build. What moves says what to expect.CLAUDE.md, "What does not wait for
him").The image's Gradle home is warmed by building the framework's Android project at
GRADLE_WARM_COMMIT, and the Android job builds offline from it. So a change to Gradle,
AGP, the SDK levels or AdMob's version needs a framework commit that the image is built from, and
an image the framework then pins:
raymob/app/build.gradle,
raymob/build.gradle and raymob/gradle/wrapper/gradle-wrapper.properties
(with the wrapper's sha256), and the same values in the versions block.
Push it. The Android job of that branch fails offline, because the image does not have the new
dependencies yet; that is expected.GRADLE_WARM_COMMIT set to that commit, and the SDK, NDK
and build tools arguments set to the same values. The build warms the home from it, with AdMob on
and off, and proves both builds offline from a clean tree before it can publish.tools/versions_check.sh holds the framework's Gradle files, its
versions block and the image's manifest to one set.The warm commit has to stay fetchable for as long as anyone may rebuild the image: the build
fetches it from the framework's repository by its full hash. A commit a pull request carries stays
reachable on GitHub through the pull request's own ref, even after its branch is deleted; a commit
of a branch pushed without one, and then deleted or rewritten, does not. Open the pull request
before the image is built, or point the next image's warm commit at the merged commit on
main.
LLVM is held where it is by Mull, which is built for one LLVM release and refused by the image
for any other (MULL_LLVM_VERSION). Moving LLVM means a Mull for it, and the
-18 in the names of the tools the Dockerfile, the manifest step and the
framework's coverage and mutation scripts call — llvm-config-18,
mull-runner-18, the clang plugin's path. If no Mull exists for the LLVM wanted, the
choice is between keeping LLVM and dropping mutation of the C++ from the image; that is Omar's.
The largest bump: the base digest, the snapshot, the package names that changed between
releases, the two Python pins apt owns, the system compilers, and the ubuntu key —
which the manifest step writes as a literal, not from an argument. The image's Python moves with
it, so the lock is regenerated. Do it alone, in its own pull request, with a full matrix after.
| Changed in the image | What can go red | What to do |
|---|---|---|
| GCC or Clang | new warnings (the framework builds its checks with warnings as errors); the e2e shots and the render hash, if the code generation changed a float | fix the warning in the code; a moved shot is re-recorded in the image with rmp test e2e-update, every picture looked at, and a moved golden needs behaviour-approved |
| zig, UPX, any compiler | the size budget, past 1.5 % a warning and past 10 % a failure | the new lines from the release run, tools/size_check.py --update, with the reason in the pull request |
| GCC's headers | the cost of each public header, tools/header_budget.txt | the new numbers from tools/header_cost.py, run in the image |
| LLVM | the coverage floors (another release counts lines differently) and the mutation floors | raise with tools/coverage_check.sh --update; a floor that has to come down is a hand edit a reviewer reads, never a script's |
| clang-format, clang-tidy | files that were formatted, warnings nobody owed | their own bump |
| Emscripten | the web build, its size line, the web boot test | a full web run, and the web size line |
| The Android set | the Android build, offline | the Android bump |
| The apt snapshot | any of the above at once | a snapshot bump is every package's bump: do it alone |
The musl build is started on Alpine, twice: the headless build, which renders the golden frame,
and the archive a player downloads, under xvfb-run on Mesa's llvmpipe. The image is
Alpine by digest with exactly those packages and nothing else — no compiler, no Python — and a
small GLX program, built against the same Alpine, that opens every library GLFW opens, makes a
context, insists the renderer is llvmpipe and reads two drawn pixels back. The build runs it, and
alpine/verify/image.sh runs it again on the built image, with --init and
no network as the framework runs it, before anything is published.
Its packages are not pinned to versions, because Alpine keeps one version per package per
release branch and deletes the one it replaces; there is no snapshot service to point at. What CI
runs is frozen by the digest. A rebuild installs whatever its branch has that day, and the image's
/etc/raylib-run-alpine.json lists every installed package with its version, so two
builds can be compared line by line.
It is
pinned in two places, RUN_IMAGE in _linux.yml's musl-x64-run
job and run_alpine_digest in thirdparty/FROZEN_VERSIONS.md, and
tools/versions_check.sh fails while they disagree. A bump is a push to
alpine/ on the image repository's main, which builds it, verifies it at
its digest and only then tags it. Locally:
docker build -t raylib-run-alpine alpine/
docker run --rm --init --network none -e EXPECT_ARCH=amd64 \
-v "$PWD/alpine/verify:/verify:ro" raylib-run-alpine sh /verify/image.shWhen the Alpine release it is built on stops getting fixes, move the base to a newer release by digest, and run the musl jobs; nothing else depends on which Alpine it is.
The published image is the toolchain. Rebuilding it depends on a dozen outside addresses still serving the same bytes — the Ubuntu snapshot above all — and some of them will not, one day. Keep every digest the framework has pinned in a place of your own: Ten years and more has the commands.
https://omardev29.github.io/rmp-docs/framework/maintaining/python.html
Every build of every game runs Python: CMake calls the generator on each configure,
and rmp is a Python program. That makes Python look like the riskiest dependency the
framework has. It is not, because the part every build runs uses nothing but Python's standard
library. The packages that are hard to keep pinned belong to the test campaign, inside the build
image, and a game never runs them.
| What | When | Needs |
|---|---|---|
tools/configure.py, the generator | every CMake configure, and before every Gradle and Xcode build | the standard library; Pillow for the icons, if it is there |
tools/rmp.py, behind rmp | every command | the standard library |
The gates in tools/ written in Python, and the Python inside the shell gates | rmp test, the lint job | the standard library; PyYAML for the workflow check |
The tests of the tools, tests/*_test.py | rmp test | the standard library; PyYAML for a few |
The property tests, tests/*_property_test.py | rmp test property, and every night | Hypothesis |
| Mutation testing of the Python | rmp test mutation, every Sunday | mutmut, which drives pytest |
The asset makers, tools/make_example_art.py and tools/make_platformer_assets.py | by hand, when an example's art is remade | Pillow |
CI's own scripts, .github/scripts/ | the canary and its report | the standard library |
The
.toml is read with tomllib, which Python has had since 3.11, so that is
the floor. tools/rmp.py is kept parseable by 3.8, so an older Python prints a sentence
saying which version it is instead of a syntax error.
CMake
does not take the first Python it finds. cmake/find_python.cmake asks each name in
turn — python3, then the versioned names, then python and
py — to import tomllib, and takes the first that can: on Windows
python3.exe is often the Store's stub, and macOS's own python3 is older than
3.11. The versioned names stop at the newest Python that existed when the list was written; a newer
one is found through python3, which is what every system installs it as. Add its
versioned name to the list, and to the POSIX launcher's, which is the same, when one is
released.
The
generator says it in its first lines: standard library only, Pillow optional. The rule is what
lets a game made today configure on a Python of years from now without a package manager. The
standard library modules it and rmp use are core ones — tomllib,
json, re, pathlib, subprocess,
argparse, hashlib, struct, shutil — and the
POSIX ones, fcntl, pwd and grp, imported inside the
functions that only run on Linux, as winreg is inside the ones that only run on
Windows.
| Package | Used for | In the build image | On a laptop without it |
|---|---|---|---|
| Pillow | the icons: the Windows .ico, Android's launcher icons, iOS's; the asset makers | from apt, at the snapshot's version | no icon is made, and the build goes on. The Windows jobs install it by hash
(pillow and its pillow_sha256_* keys) |
| PyYAML | the workflow check, and the tests that read a workflow as YAML | from apt | skipped, and said; inside the image a missing PyYAML fails instead |
| Hypothesis | the Python properties | from the lock | each property module says so and is skipped; CI requires it, so a skip there is a failure |
| mutmut and pytest | mutation testing of the Python | from the lock | the mutation stage fails: it runs only in the image |
| clang-format, clang-tidy | formatting and linting; they are Python wheels that carry the binaries | from PyPI, by version | pip install clang-format==… clang-tidy==… at the clang_format version (Setting up) |
The clang tools are pinned by version and not by hash: the image installs them with
pip install and the version, and tools/versions_check.sh compares the
binary on PATH with the pin. A wheel republished under the same version would not be
noticed. That is the one Python install in the image without a hash.
The image's test tools come from two files in the image repository:
python/requirements-ci.in, the top-level pins, and
python/requirements-ci.txt, the lock made from it by python/lock.py, which
the image installs with --require-hashes --only-binary=:all:. The lock pins the whole
graph with == and keeps, for each package, the hash of every wheel pip can pick for the
image's CPython on both of its architectures — downloaded and hashed by lock.py and
checked against the digest PyPI publishes.
Three things make it harder than a plain lock, and each is why a regeneration fails:
dpkg -s python3-yaml python3-pygments) and put them in
requirements-ci.in before locking. Everything that depends on them is held back with
them — that is why mutmut's interface library is not at its newest.lock.py refuses it; pin the
newest release that has both.lock.py runs in a build of the image, with the network, and pip-tools in a
throw-away virtual environment. The command is in its docstring and in the image's README.python/requirements-ci.in.docker run --rm -v "$PWD":/w -w /w ghcr.io/omardev29/raylib-build:latest sh -c '
apt-get update -qq && apt-get install -y -qq python3-venv >/dev/null &&
python3 -m venv /tmp/v && /tmp/v/bin/pip install -q pip-tools==7.6.2 &&
/tmp/v/bin/python python/lock.py'python/requirements-ci.txt: every package that moved is a
change in what the tests run.hypothesis, mutmut and
pytest keys of thirdparty/FROZEN_VERSIONS.md, and the new digest.This site is built by one standard library script, build.py in its
tools folder, with the same floor. Its property tests need Hypothesis and its browser checks a hash-pinned requirements
file of their own, beside them in its tests; neither is needed to build the site.
They are a test campaign, not the build. If, years from now, mutmut or Hypothesis no longer
installs on any Python the image can carry, the generator, rmp, every gate that is
standard library only and every game are untouched: what stops is the properties of the tools and
the mutation scores of the Python. Keep the last image that has them, by its digest, for the day a
change needs them, and run the rest of the ladder on a newer one. What the floors and the waivers
mean is in Properties, fuzzing and
mutation.
https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html
Every dependency below is pinned, so none of them has to move until there is a reason: a store's requirement, a runner that no longer has the pinned version, a bug upstream has fixed, a feature a game needs. When there is one, this page says what the upgrade touches. Each entry gives where the version is, what moves with it, what to expect red, and what is recorded again afterwards.
rmp test config
runs tools/versions_check.sh, which names a copy that was left behind.CLAUDE.md,
"Never weaken a gate to get green").FRAMEWORK_REF bumped.thirdparty/raylib, a committed copy of a release; RAYLIB_VERSION in
thirdparty/raylib/src/raylib.h says which.thirdparty/raylib/PATCHES.md, which says where it comes from, and is
commented at its site: PATCHED (raylib_cmake_template) for the template's, whose copy
this is, and PATCHED (raylib_multiplatform) for the framework's own. Each row says what to do with it: the
backports are dropped once the new release has them; the build-system and backend fixes are
re-applied; the fixes of our own are re-applied unless upstream has fixed it — and for those, a
test says which. Copy the new release over the old one, then walk the table, top to bottom.EscapeIsTheGamesKeyTest scans every backend for a key that closes the window
without being the exit key; DrmCardProbeTest reads the DRM card probe;
tests/rlsw_test.cpp calls the software renderer's texture lookup at its edges;
tests/configure_test.py compares raylib's platform list with the branches that select
them. A patch that was lost turns one of them red.tests/fixtures/render_hash.txt) and the e2e shots, if anything
drawn changed; the size lines; tools/ownership_check.sh, which reads raylib's
Load* and Unload* names from raylib.h live; this site's
names gate, which checks every raylib function a page names against the headers.rmp test render-update, the e2e goldens with
rmp test e2e-update in the image, every changed picture looked at; a moved golden is
behaviour-approved.PATCHES.md stays, rewritten for the new release, and
THIRD_PARTY_LICENSES.md says the version.thirdparty/clay/clay.h, one committed file; two patches in its
PATCHES.md, both commented at the site: the C++ version guard (NetBSD's GCC 10 reports
an older C++ under -std=c++20) and the two sizing loops that froze on a layout too
large for a float.src/rmp/ui/ uses it. The facts the UI depends on — one id scheme, strings Clay keeps by
pointer, the rectangle Clay emits after an image, a floating element that captures the pointer, the
way it measures text a word at a time — are verified one by one in the
rmp-ui-internals skill, and each has to be checked again on the new version.tests/ui_layout_test.cpp and the UI's other tests, tests/property/ui_text_prop.cpp,
every e2e shot of a menu.The four readers of files a game loads. Each one is fed bytes it should not trust, so each one
has a fuzz target in tests/fuzz/ and a committed corpus under
tests/fuzz/corpus/; after an upgrade, rmp test fuzz replays every committed
input under the sanitizers, and the nightly campaign searches further.
default: branches skip a key the parser does not
know (a map saved by a recent Tiled has many), and every reader stops at the end of its input. Each
site is /* rmp patch */ and a row of thirdparty/cute_tiled/PATCHES.md.
tests/fixtures/map_modern.json is rejected by the unpatched parser and accepted by
ours: if it fails after an upgrade, the patch was lost.sha256_cute_aseprite; the new hash is the one
tools/license_db.py prints. prepare_aseprite() in
src/rmp/assets/aseprite.cpp walks every chunk before cute_aseprite sees the bytes, so a new
chunk type is the thing to read the changelog for.sha256_cjson. src/rmp/save/cjson_impl.c sets its nesting
limit to the save format's maximum depth and deliberately does not turn on its locale support; the
save code writes numbers itself and parses under the C locale. Run tools/test_locales.sh
after an upgrade.sha256_rres over every file, external/ included — the
compression and the encryption rmp::save seals saves with. A change in the encryption
changes what an old save reads as, and the save tests are what notice: a player's saves must
still open after the upgrade.Android's native glue, in C under thirdparty/raymob and in Java under
raymob/app/src. Every patch is marked [rmp patch] and listed in
thirdparty/raymob/PATCHES.md: a heap overflow, a bound check that checked nothing, a
detach of the game's own thread, the JNI discipline the C side follows, and a key release sent as a
second press. RaymobJniDisciplineTest fails on a call that skips the helpers. Upgrade
only for a reason; the Android build and Firebase Test Lab are the proof.
The iOS backend is a submodule, thirdparty/raylib-ios, pinned to a commit of the fork
under the same account. It is the dependency most likely to be forced: a new Xcode or a new iOS SDK
can need a change in it, and its upstream is one person's port. To move it:
git -C thirdparty/raylib-ios fetch origin
git -C thirdparty/raylib-ios checkout COMMIT
git add thirdparty/raylib-iosA fix of your own goes to the fork first, as a commit there, and the submodule then points at
it. The row in thirdparty/FROZEN_VERSIONS.md's table and the licence rows — ANGLE's
included — follow. The iOS simulator job is the proof; an App Store build is the real one.
Pinned by content (sha256_doctest, sha256_rapidcheck). doctest ships
with every game's tests; RapidCheck is the framework's only. RapidCheck's own doctest integration
does not compile, and tests/property/check.h is the few lines that replace it: an
upgrade checks those still match.
SDK
levels, build tools, NDK, AGP, Gradle and JDK move together: AGP's version decides the Gradle
it needs and the highest API it supports. The keys are the android_* ones,
agp, gradle and gradle_sha256, and the files are
raymob/app/build.gradle, raymob/build.gradle and
raymob/gradle/wrapper/gradle-wrapper.properties. The image carries the SDK and a Gradle
home warmed for the set, so this is the
Android bump, in both repositories.
AdMob's SDK, play_services_ads, can move on its own: an AAR built against a lower
SDK works under a higher one. It is still in the warmed Gradle home, so a new version is an image
too.
The
keys are macos_runner and xcode. The Apple jobs select Xcode by version,
and a step fails, listing what the runner has, when the pinned one is gone — GitHub keeps a few
Xcode versions per runner image and removes old ones. That failure is the signal to bump: pick a
version the runner lists, run the debug lane on macos and ios, and look at
the canary, which already builds with the newest one. XcodeGen and the macOS Ninja are downloaded
by version and sha256 (xcodegen, ninja_mac and their hashes),
never from Homebrew.
windows_runner is the runner label. The compiler that builds the
.exe comes with it, pinned by nobody (the
warning).mesa and mesa_sha256: the software OpenGL the Windows render test runs
on. Test only; the release zip is checked not to carry it.win_amd64 wheel hash, from PyPI, as a new pillow_sha256_cp3XX_win_amd64
key.upx_sha256_win64, with the UPX version.The
keys are clang_format and clang_tidy, and the image's
CLANG_TOOLS_VERSION. A new clang-format reformats files that were already right, and a
new clang-tidy finds warnings nobody owed. So the bump is three commits, in one pull request:
rmp fmt over the whole tree, alone in its commit, so the review can skip it.NOLINT that names the check
and says why;
tools/lint_debt.txt only goes down (bash tools/lint.sh debt lowers it,
nothing adds to it). Read every automatic fix: misc-const-correctness's have been
wrong. Check that the CustomChecks still run: they need
--experimental-custom-checks, and a query that no longer parses is one warning line and
nothing else; ClangTidyGuidelineTest shows each firing on a probe.This site's Guidelines compile their examples through the same clang-tidy, and its
enforcement gate reads the framework's .clang-tidy: a check that was
renamed or removed shows there too.
EMSDK_COMMIT and EMSCRIPTEN_VERSION in the image, emscripten
in the framework. A new one can change the web build's size, its JavaScript, and what
web-backends.yml fingerprints for each backend: run it by hand. Never add
ASYNCIFY back to get a while loop (CLAUDE.md, "Web has no
while loop").ZIG_VERSION, its hashes, and ZIG_WARM_GLIBC, which must
be the [linux] glibc default), and in the framework as zig and
zig_sha256_*, which tools/linux_build.sh uses when it downloads it on a
laptop. zig is before 1.0 and changes its command line between versions; the script is what
moves.CMAKE_VERSION and NINJA_VERSION, the cmake and
ninja_linux keys. The framework asks for CMake 3.30 or newer; Android's CMake is the
SDK's own, android_sdk_cmake.UPX_VERSION, and upx with its three hashes. Every packed
size line moves.src/rmp, and a suppression says why on its line.uses: is a full commit with its tag in a comment, and a test fails on one that is not.
Dependabot proposes their bumps monthly, in both repositories. Merge them: an action whose runtime
GitHub deprecates stops running on its own date, pinned or not.ubuntu-24.04 and ubuntu-24.04-arm are written in the workflows, not in
the versions block. When GitHub retires them, every occurrence moves in one commit,
in this site's workflows too. The jobs run in the image, so what changes is the host: Docker, the
kernel the DRM job loads vkms into.freebsd, openbsd and netbsd keys are read by the generator
when it makes the BSD matrix. An old release loses its package mirror: move to a release
cross-platform-actions supports, which can mean bumping that action too. The BSD
targets are best effort, and a failure there after a green fast lane is a platform-specific bug
fixed once.package.json and package-lock.json; Dependabot's npm pull requests.
The browser it downloads is keyed to its version.The canary's upstream report says what is newer than the pins it knows how to ask about: the NDK, AGP, Gradle, Mesa, the macOS Ninja and XcodeGen. It never fails a build; it is information. Everything else — raylib, Clay, Emscripten, zig, LLVM, the clang tools — is looked up by hand, and only when there is a reason to upgrade.
https://omardev29.github.io/rmp-docs/framework/maintaining/dialogue-and-text.html
Two parts of the framework follow something outside it: rmp::Dialogue
follows Yarn Spinner, whose language moves with its releases, and rmp::Text follows
CLDR's plural rules and the way each platform names its language. This page is what to know to
keep both true: where each piece came from, what holds it to the original, and what to do when
the original moves.
src/rmp/dialogue/ is a port to C++ of
Yarn Spinner's compiler and runtime,
which are C# and MIT. It is not a copy and not a binding: there is no ANTLR, no protobuf and no
.NET, the whole of it is the standard library, and nothing in it throws. Its licence row in
THIRD_PARTY_LICENSES.md points at src/rmp/dialogue/LICENSE-YarnSpinner.md,
which ships in every game's LICENSES.txt, and
src/rmp/dialogue/PATCHES.md says, file by file, which C# it follows and what differs:
| File | Follows |
|---|---|
src/rmp/dialogue/yarn_parse.cpp | the lexer and parser grammars and the indentation lexer — hand-written, a line at a time |
src/rmp/dialogue/yarn_compile.cpp | the compiler, the node-group compiler, the code generator and the type solver |
src/rmp/dialogue/yarn_vm.cpp, src/rmp/dialogue/yarn_value.cpp | the virtual machine, the dialogue, the library of functions and the saliency strategies |
src/rmp/dialogue/yarn_markup.cpp | the markup parser, with select,
plural and ordinal by the framework's own CLDR table |
src/rmp/dialogue/yarn_bytes.cpp | the compiled program's format: one of ours instead of protobuf, for the embedded build |
src/rmp/dialogue/dialogue.cpp | rmp::Dialogue and
load_dialogue(): the framework's side, translation included |
The one difference in behaviour that is a choice, not a gap: the machine has a budget — a
hundred thousand instructions between two things it shows, and a detour stack of 256 nodes — so a
script that loops without ever reaching a line stops with an error instead of hanging the game.
The case that found it, a node that detours into itself before any line, is in
tests/dialogue_test.cpp.
Yarn Spinner's test cases are vendored, as they are, in tests/dialogue/yarn/, with
their licence and the commit they were taken at in tests/dialogue/yarn/COMMIT. A test
case is a .yarn script and a test plan that says, step by step, what a run of it must
produce — each line, each set of options, which one is chosen, each command — and the scripts that
must not compile say so. tests/yarn_plan_test.cpp compiles every one and plays every
plan; it is part of unit_test, so rmp test runs it.
Every case passes. A case that does not, after a new Yarn release, is listed in
tests/dialogue/yarn_unsupported.txt with the reason, and the runner holds that list:
a listed case that passes fails the run until its line is taken out. The list only shrinks, and it
is empty today.
tests/dialogue/yarn/ with the new release's test cases, and write its
commit in tests/dialogue/yarn/COMMIT.rmp test unit. Each failing case names its script and the step where the
run went another way.src/rmp/dialogue/ that follows it, a test of the
framework's own for anything the cases do not show.src/rmp/dialogue/PATCHES.md and the
licence notice if it changed. What cannot be ported yet goes in
tests/dialogue/yarn_unsupported.txt, with why.tests/property/dialogue_prop.cpp compiles and plays
scripts made of random Yarn statements, and requires that nothing crashes and nothing runs
forever; tests/property/text_prop.cpp does the same for any table, any key and any
arguments, and holds the number formatting to std::to_chars' digits.tests/fuzz/yarn.cpp feeds the compiler and the machine
arbitrary bytes and tests/fuzz/lang_tsv.cpp the table reader; their corpora are
replayed on every push.dialogue, dialogue_ui and
text of tests/mutation/floors/ are measured every week.tests/ui_layout_test.cpp
— typing, choices, timers, moods, the stage, the bubble — and rich text's pixels are read back on
a GPU in tests/ui_render_test.cpp.rmp_yarnc (tools/rmp_yarnc.cpp) is the same compiler built for the
machine that builds the game. CMake runs it over every .yarn of a game's resources/ when
[dialogue] build asks for
it, and links the bytes it writes into the game. It is not built when cross-compiling, which is why
Android, iOS and the web compile their scripts at runtime. A change to the compiler is a change to
both: there is one compiler.
src/rmp/text/text.cpp is rmp::Text and rmp::lang: the table
reader, the lookup and its fallback chain, placeholders, the CLDR plural rules and the system
language of every platform. Three things in it follow the outside world:
src/rmp/text/text.cpp, and tools/text_tool.py holds how many forms
each language has, to check the tables. Adding a language is a line in both, and a case in
tests/text_test.cpp's plural rules; a language in neither takes the last form.GetUserDefaultLocaleName, the native activity's configuration,
navigator.language — and only CI's matrix compiles them all. The tests set the
language through a seam, so none depends on the machine's.[lang] languages, the
per-language files are looked for under a list of common codes in src/rmp/text/text.cpp.tools/text_tool.py is rmp text scan and rmp text check:
a scanner of C++ literals the framework translates and of Yarn line ids, and a checker of the
tables against [lang] languages. It writes a Yarn line the way Yarn Spinner's own
string table does, its expressions numbered {0}, {1}, because that is what
the machine fills. Its tests, tests/text_tool_test.py, plant each mistake the checker
is for; tools/ink_to_yarn.py has its own in tests/ink_to_yarn_test.py, and
the story it converts is played by the C++ in tests/dialogue_test.cpp.
A number written into a text or a line goes through shortest_number(), in
src/rmp/save/number_internal.h: the fewest significant digits that read back as the same
number, laid out as C# lays it out, since Yarn's numbers are C#'s. It does not call a
floating-point std::to_chars on purpose: that one brings libc++'s formatting tables
into every static link, and cost the demo game 126 KB on Linux
(Performance). The property in
tests/property/text_prop.cpp holds its digits to to_chars' on any double
and any float.
https://omardev29.github.io/rmp-docs/framework/maintaining/yearly.html
A pinned build does not change by itself. What changes is around it: a store that will not accept an app built with last year's SDK, a runner that no longer has the Xcode the framework pins, a BSD release whose packages are gone. None of them breaks the code. Each of them breaks a job, or a publication, on a date somebody else chose.
| What | How often | What breaks if nothing is done | Where to act |
|---|---|---|---|
| Google Play's target API level | every year, near the end of the summer | a new app or an update is refused by the Play Console; the build still works | the Android set, and the Android bump |
| The App Store's required Xcode and SDK | every year, in the spring | an upload is refused; the build still works | Xcode, and the raylib-iOS fork if the new SDK needs it |
| Xcode versions on GitHub's macOS runners | a few per runner image, old ones removed | the Apple jobs fail at the step that selects Xcode, naming what the runner has | xcode; macos_runner when the image itself is retired |
| GitHub's runner images | every year or two, announced ahead | a job whose label no longer exists never starts | windows_runner, macos_runner, and the Linux labels in the workflows |
| Node runtimes for actions | every year or two | an action on a retired runtime stops running | Dependabot's pull requests |
| BSD releases | OpenBSD about twice a year, FreeBSD and NetBSD less often | the release's package mirror goes, and that BSD job cannot install its packages | freebsd, openbsd, netbsd |
| The Python on the Windows runners | when the runner image moves | no Pillow hash for that Python, so the icon step refuses the install | a new pillow_sha256_* key |
| Signing credentials | Apple's certificates and profiles every year; Android's upload key never | an Apple upload is refused; a lost Android upload key cannot be replaced without Play's help | the store's console; the repository's secrets, never the .toml |
Desktop Linux, the web and the BSDs' code have no store and no yearly gate. A Linux release built years ago still starts on a new distribution: it asks for an old glibc on purpose, and glibc keeps its old symbols.
Pinning
hides that the world moved. Every Monday the framework's repository runs the same reusable
workflows as CI against the floating versions — the image's :latest, the newest macOS
and Windows runners, the newest Xcode and Mesa — and its report leads with what moved between the
pin and what it found, then the error. A red canary is the yearly round arriving early: it says
which pin will break, before anyone needs to publish.
After a red canary, autofix.yml starts an agent on the failing family's own runner
that proposes a fix as a draft pull request. It can change the versions block, not the
workflows — the token it has cannot push to .github/workflows — which is why every
floating pin lives in thirdparty/FROZEN_VERSIONS.md. Its pull request is a proposal;
it goes through review like any other.
main:
gh workflow run ci.yml -f full=true. A release tagged from it is a known-good point to
come back to.Everything else waits for a reason. A dependency that is old and works is not a task.
| Family | A year with no change to the code |
|---|---|
| Linux, all of it | nothing, while the image exists and the runner label does |
| Web | nothing; browsers keep running old WebAssembly and WebGL |
| Windows | a runner label every year or two; the compiler on it floats |
| macOS | an Xcode pin, often once a year |
| Android | the Android set and an image, once a year, to keep publishing |
| iOS | an Xcode, and sometimes the fork, once a year, to keep publishing |
| The BSDs | a release bump when one ages out; best effort |
https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html
The framework is meant to be usable long after anyone works on it every day, on desktop Linux above all. This page is about that horizon: which parts last because of what they are, which parts rot on a schedule or by accident, what has to be kept somewhere of your own, and how much of the machinery around the code one person needs to run.
CMAKE_CXX_STANDARD is 20, written down, so a newer
compiler's default does not change what the code means. The libraries are committed, not fetched:
nothing has to still exist upstream.FetchContent, no package manager. And a generator that uses Python's standard library
only (Python).[linux] wayland = true builds GLFW's Wayland backend in as well. On a
machine with no desktop at all there is the DRM target. A web build is WebAssembly and WebGL, which
browsers do not drop.CLAUDE.md (the rules and every mistake
that has cost time once, with how it was found), the skills under .claude/skills/,
TECHNICAL.md, the comments at each patch site, every PATCHES.md, and this
site, checked against the code.| How | What | What to do about it |
|---|---|---|
| On a schedule | the stores' SDK requirements; GitHub's runner images, Xcode versions and action runtimes; BSD releases | the yearly round |
| By an outside service going | the Ubuntu snapshot, the release assets, PyPI and Maven files the image was built from; ghcr.io; GitHub itself | archive: the image already holds every one of those files |
| Without a pin at all | the BSDs' package mirrors; the Windows runner's compiler; the Alpine packages of a rebuild | expect a red that nobody caused there first |
| Slowly, from inside | the gates that read other files as text — a workflow's step names, a vendored file's lines, a tool's output — and the floors measured with one toolchain | a gate that is wrong is fixed in the gate, with the test that shows it was wrong |
| When nobody looks | the scheduled workflows, which GitHub turns off after 60 days without activity | turn them back on, and run the canary first |
Two ways to build, and both should keep working:
Exact: the same compilers, the same libraries, the same checks CI ran, bit for bit. It needs a
container engine that can still run an x86-64 or arm64 Linux image, and the archive below. Load it,
then run the ladder in it as Setting
up describes, with --network=none: nothing in it needs the network.
What will exist then: the distribution's compiler, CMake and Python. The framework needs
[linux] wayland = true,
or libdrm, gbm, EGL and GLES for the DRM target.Then a clone and rmp build release. That binary asks for the glibc of the machine
that built it; for one that also starts on older distributions, build it as CI does, with
tools/linux_build.sh, which uses zig to aim at the floor [linux] glibc sets.
What can go wrong is small and visible: a new
compiler's warning in a framework check built with warnings as errors (a game's build is not); a
deprecation in CMake; a Python that removed a module. Each one is a red with a line number, not a
mystery. What will not match is exactness: the e2e shots and the coverage floors were measured in
the image, and are reported, not enforced, outside it.
Keep these in a place you control, outside GitHub, and add to it every time a pin moves:
skopeo copies a multi-architecture image to a file and back
without changing a digest:
DIGEST=$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md)
skopeo copy --all --preserve-digests \
"docker://ghcr.io/omardev29/raylib-build@$DIGEST" \
"oci-archive:raylib-build-${DIGEST#sha256:}.tar"run_alpine_digest and ghcr.io/omardev29/raylib-run-alpine.
Each build image is around ten gigabytes per architecture; they compress well. To serve one again,
copy it back to any registry with the same command reversed, and point the digest's places at that
registry.git clone --mirror of the framework, the
image repository, this site, and the raylib-iOS fork the submodule points at — a commit only the
fork has is the one thing no other copy holds.The image is the important one. It is the only copy of every file it was built from that sits in one place: the Ubuntu packages at that snapshot, CMake, zig, Emscripten, the Android SDK and NDK, the Gradle home, LLVM and Mull, the locked Python tools. With it, every Linux, web and Android build can be repeated with no network; without it, a rebuild depends on every one of those addresses serving the same bytes years later.
The workflows are GitHub's format and run only there. Everything they check, though, is a stage
of rmp test or a script under tools/ that runs on a laptop or in the
image: every stage has a step in CI, and a test holds the two to each other. So if GitHub's CI went
away, the checks would not: the ladder in the image is the same set, run by hand. What would be
lost is what only a hosted runner gives — macOS and Windows machines, the BSD virtual machines, the
scheduled campaign — and the installer's and this site's addresses.
The framework was built by many agents at once, and its rules and gates are what let them work without stepping on each other. One person keeping it alive needs less of that machinery each day, but not less of the gates: they are what make a change safe to merge after a year away, when nobody remembers the caveat that a gate encodes. What changes is how much of it runs, and when.
| A change to | Run |
|---|---|
| anything | rmp fmt check, rmp lint, rmp test |
| the public API, an example, a scene, the input or the UI | and rmp test examples, in the image |
| something that parses, casts or frees | and rmp test sanitize; a parser, rmp test fuzz |
the framework's code under src/rmp | and rmp test coverage, in the image |
| a dependency or the image | all of it, and the full matrix once |
Three things make the time go furthest:
And when a gate is wrong — a test that reads a workflow's text after the text moved for a good reason — fix the gate, with the test that shows it was wrong. A gate turned off to get green stops protecting the next person, who after a year away is you.
https://omardev29.github.io/rmp-docs/guidelines/index.html
How C++ is written here: in the framework, in its examples, and in a game that wants to read like them. In the framework and the examples the rules on these pages are mandatory, and a tool holds every one a tool can tell apart from its mistake; in a game they are advice, and the game decides how much of the tooling it takes. When a question has more than one good answer, three sources decide it, in this order.
const,
no raw pointer, and nothing owned by hand,
text in and out, the
C++ written where C would also compile and macros — and
the framework's own decisions in why it is built this way,
such as one header per module and
no exceptions.A rule written only in a document is kept until the day somebody has not read it. So wherever a
mistake can be described precisely, a tool refuses it: a check of clang-tidy, which
rmp lint runs; a gate, which is a stage of
rmp test; clang-format; or the compiler.
One line per page of these Guidelines, with every tool that page names and where it holds — in the
framework (its include/, src/ and tests/), in its examples,
and in a game made with rmp new:
| Rules | Checked by | Framework | Examples | A game |
|---|---|---|---|---|
| Naming: one spelling per kind, no prefix, no name hiding another, no constant named like a macro, no retired name | readability-identifier-naming, clang-diagnostic-shadow; tools/naming_check.sh, rules R1 to R8, in every branch of every #if | yes | yes | no |
Formatting: 4 spaces, 90 columns, no alignment, char *p, { 1, 2 } | .clang-format; rmp fmt applies it, rmp fmt check and rmp test fmt refuse a file it would change | yes | yes | yes: rmp fmt formats and rmp fmt check refuses, when the game runs them |
const: on every local and method that changes nothing, not on a parameter in a declaration, inline constexpr in a header | misc-const-correctness, readability-make-member-function-const, readability-avoid-const-params-in-decls, performance-unnecessary-value-param, custom-rmp-header-constant | yes | yes, but for readability-make-member-function-const and readability-avoid-const-params-in-decls | no |
| Pointers and RAII: no raw pointer, no C string a game can name, an optional asked before it is read, nothing owned by hand, raylib's resources loaded only by their owners | custom-rmp-raw-pointer, cppcoreguidelines-owning-memory, cppcoreguidelines-no-malloc, bugprone-unchecked-optional-access; tools/pointer_check.py; tools/ownership_check.sh O1 O2 | yes, with what tools/lint_debt.txt and tools/pointer_ratchet.txt still owe, and tools/ownership_check.sh in include/rmp/ and src/rmp/ only | yes, but for tools/pointer_check.py and O1, which read only the framework's own code, and with what tools/lint_debt.txt still owes | no |
Strings: a view in, a std::string out, never a view's data() to raylib, nothing newer than the oldest compiler | tools/pointer_check.py, custom-rmp-raw-pointer, bugprone-dangling-handle, bugprone-suspicious-stringview-data-usage; tools/style_check.sh S4 S5 | yes, but for S4 in tests/, which build only on CI's compilers | yes, but for tools/pointer_check.py, which reads only include/rmp/ | no |
Modern C++: std::array, static_cast, enum class, nullptr, no varargs, int, explicit, ++i, designated initialisers in order, C++20 as GCC 10.5 has it | modernize-avoid-c-arrays, modernize-avoid-c-style-cast, cppcoreguidelines-use-enum-class, modernize-use-nullptr, modernize-avoid-variadic-functions, google-runtime-int, google-runtime-float, google-explicit-constructor, cppcoreguidelines-special-member-functions, modernize-use-auto, modernize-use-using, modernize-use-std-numbers, google-build-using-namespace, google-default-arguments; tools/style_check.sh S1 S2 S4 S5 S6; -Werror=reorder-init-list | yes, but for S4 in tests/ | yes, but for modernize-use-auto | only the order of designated initialisers, which the compiler refuses |
Macros: only for what a function cannot do, named RMP_ | cppcoreguidelines-macro-usage, readability-identifier-naming; tools/naming_check.sh R5 R6 R7 | yes | yes | no |
Where Google's guide and these agree: no unnamed namespace or global using-declaration in a header, no overloaded unary &, no TODO | google-build-namespaces, google-global-names-in-headers, google-runtime-operator, google-build-explicit-make-pair; tools/style_check.sh S3 | yes | yes | no |
| No finding of a second analyser, and a reason beside every suppression | tools/cppcheck_check.sh | yes: src/rmp/ | no | no |
| Warnings on the code we write | -Wall -Wextra | yes, as errors in the framework's own checks | yes | yes, as warnings |
What checks what takes the same rules one by one, with each check's exact reach, the checks the framework switches off and why, and what the code still owes. The build of this site holds both tables to the framework's own configuration: a check said to run there runs there.
The rest of what the framework checks is not about how the code reads, and holds it together instead:
| Rule | Checked by | Framework | Examples | A game |
|---|---|---|---|---|
Every public header compiles on its own and carries the .toml values | tools/header_check.sh | yes: include/rmp/ | no | no |
| What each public header costs to include | tools/header_cost.py, against tools/header_budget.txt | yes: include/rmp/ | no | no |
| Nothing in the framework reads the clock, the input or the random state on its own | tools/seam_check.sh | yes: src/rmp/ | no | no |
A mistake in the .toml stops before the build | tools/configure.py, and tests/configure_test.py for each refusal | yes | no: they are built with the framework's | yes |
| Every vendored component has a licence the project can ship | tools/license_db.py | yes | no | yes: rmp test config |
| No memory error and no undefined behaviour in a run | AddressSanitizer and UndefinedBehaviorSanitizer in every debug build, from cmake/sanitize.cmake; tools/sanitize_check.sh for a second compiler | yes | yes | no, until its [dev] sanitize lists them |
| Every release binary stays the size it was measured at, unless the growth is written down | tools/size_check.py, against tools/size_budget.txt | yes | no | yes, from the day it commits a budget of its own |
| No file of the framework falls below the share of its lines its tests are written down to run, and no public function arrives without a test that calls it | tools/coverage_report.py, against tools/coverage_floor.txt and tools/untested_api.txt | yes: src/rmp/ and include/rmp/ | no | no |
| Generated input looks for what no test was written for: properties against generated values, every committed fuzz input replayed, each module's mutation score held to a floor that only rises; and nothing in the framework throws | tools/fuzz.sh, tools/mutation.sh against tests/mutation/floors/, RapidCheck and Hypothesis, all held together by tests/campaign_test.py | yes | no | no |
Each is a stage of rmp test or a step of the framework's CI, and
Testing has where and when each one runs.
Each rule is shown in code, and the code on these pages is checked the way the framework's own
is. A block that shows the right way is compiled against the framework's headers, and passes,
with nothing to say, clang-tidy with the framework's .clang-tidy, clang-format with its
.clang-format, and its text gates: tools/naming_check.sh,
tools/style_check.sh, tools/ownership_check.sh and, for a block that is a
public header, tools/pointer_check.py. A block that shows the wrong way says what refuses
it, and the build of this site runs that tool on it and fails if it stays quiet; what the tool
printed is under the block, from that run, never typed. A block that does not compile at all is
shown with what the compiler said.
A
game made with rmp new gets two things from these pages, and the rest is advice:
.clang-format, so rmp fmt lays out the game's code
the framework's way, and rmp fmt check refuses a file that is not. Neither runs
unless the game runs it: its rmp test and its CI leave the layout alone.-Werror=reorder-init-list, which the framework's library hands every
target that links it: under Clang, designated initialisers out of declaration order are an error,
as they already are under GCC and MSVC.Its
own code is also compiled with the warnings the framework's is: -Wall -Wextra under
GCC and Clang, with -Wno-missing-field-initializers, because leaving fields of an
options struct out — { .width = 8 } — is how the API is written. That is every build
CMake makes, the desktop's and the web's; Android's and iOS's own projects build without them.
They stay warnings:
a newer compiler on its author's machine must not stop a build that was fine yesterday. A game can
configure with -DRMP_WERROR=ON to make them errors, as the framework's own checks do.
The vendored libraries are included as system headers, so the warnings are about the game's code
and not about theirs.
It does not get the framework's .clang-tidy, its text gates or its cppcheck:
rmp lint is a command of the framework's own repository, and in a game it says so and
stops.
There
is no setting in the .toml for it. A game that wants the framework's checks on its
own code copies the framework's .clang-tidy into its root and runs clang-tidy itself.
The game already has what clang-tidy needs: its CMakePresets.json is the framework's,
and the lint preset writes the compile database without building anything.
cp ~/.local/share/rmp/.clang-tidy .
cmake --preset lint
clang-tidy -p build/lint --experimental-custom-checks --warnings-as-errors='*' \
--header-filter='.*/(include|src|tests)/.*' \
--exclude-header-filter='.*/(include/rmp|src/rmp|thirdparty|generated|build)/.*' \
$(find src tests -name '*.cpp' -not -path 'src/rmp/*').clang-tidy is
the one of the framework rmp runs from: the clone rmp install made, in
~/.local/share/rmp on Linux and macOS
and in %LOCALAPPDATA%\rmp on Windows.--experimental-custom-checks
runs the two queries of the framework's own, the raw pointer and the constant in a header; without
it clang-tidy skips them and says nothing. The framework pins clang-tidy 22.1.8, in
thirdparty/FROZEN_VERSIONS.md, and its file is written for that one.--warnings-as-errors='*' makes a finding fail the run, which is what a check is
for. The framework's file says WarningsAsErrors: '' because rmp lint
counts its warnings against a list of what the framework still owes.--header-filter
reports the game's own headers in include/, src/ and tests/.
The framework's file names the folders it reports by the framework's layout, and a header in a
game's include/, where the examples keep theirs, is not among them: without the flag,
a C cast there passes in silence.--exclude-header-filter
keeps the framework's copy in include/rmp/ and src/rmp/ out of the
report: the framework answers for those files, and its lint still owes some of them a few raw
pointers.RMP_, the framework's prefix. A game whose
own macros take the game's name instead, as Macros
advises, writes that name in its copy's MacroDefinitionPrefix; with 'RMP_'
left there, clang-tidy refuses #define PONG_SHOW(value) in the game's code.The last line hands it every source of the game's own — src/ and
tests/, without the framework's copy in src/rmp/. clang-tidy then says
nothing about the game rmp new writes, its test included, and refuses a C cast added
to its main menu, or to a header of its own in include/, the way the framework's lint
would.
https://omardev29.github.io/rmp-docs/guidelines/naming.html
Every name in the framework is spelled according to what it is, one spelling per
kind, with no prefixes. The point is that you can tell what a name is at the place it is used,
without going to look at where it was declared: Align::TOP_LEFT is a constant of a
type, current_theme() is a function, _slot is somebody's private field.
The examples follow the same rules, and a game that follows them reads like the framework it is
built on.
| What | Spelling | Example |
|---|---|---|
| Types: class, struct, enum, alias, template parameter | PascalCase | rmp::ui::ButtonOptions |
| Enum members | CONSTANT_CASE | rmp::ui::Align::TOP_LEFT |
Constants: every constexpr, and a const at namespace, class or static scope | CONSTANT_CASE | rmp::behavior::MAX_SPAWNED |
| Functions, methods, variables, parameters, public fields, namespaces | snake_case | rmp::ui::current_theme(), gravity_scale |
| Private and protected data members | _snake_case | _slot, _generation |
| The hooks the framework calls on your type — these eight and no other method | _snake_case | _ready _update _late_update _draw _collision _end _suspend _resume |
| Functions you hand to the framework | on_snake_case | on_click, on_ready |
| File-scope state in the framework's sources and tests | a struct per concern, read as concern.field | loop.quit_requested, pool.slots |
| File-scope state in an example | snake_case | health, portrait |
The framework's macros, and every value the .toml generates | RMP_ and CONSTANT_CASE | RMP_GAME, RMP_WINDOW_WIDTH |
In code, all of it at once:
namespace layer {
constexpr unsigned PLAYER = 1U << 0;
constexpr unsigned ENEMY = 1U << 1;
} // namespace layer
enum class Weapon { SWORD, BOW };
class Goblin : public rmp::Object {
public:
int hp = 20;
void _ready() override {
collision_layer = layer::ENEMY;
collision_mask = layer::PLAYER;
}
void hit(const int damage) {
hp -= damage;
++_hits_taken;
}
private:
int _hits_taken = 0;
Weapon _weapon = Weapon::SWORD;
};Not a reviewer. Three tools hold the table, over different parts of the tree, and each mistake below is shown with what its tool prints about it:
| Tool | What it sees | Where it looks |
|---|---|---|
readability-identifier-naming, in the framework's .clang-tidy; rmp lint | every declaration the compiler parses: types, enum members, constants, functions, variables, members and their underscore, the eight hook names, macros | src/, tests/ and examples/, and the headers they include |
-Wshadow, through clang-tidy; rmp lint | a local or a parameter that hides a file-state group | the same files |
tools/naming_check.sh; rmp test naming | what a compiler cannot: every branch of every #if, a name where it is used, a macro named like someone else's, a retired name | include/, src/, tests/ and examples/ |
A
game made with rmp new gets none of the three: the framework's .clang-tidy
and tools/naming_check.sh stay in the framework, and a game has the first two, which come with that file, only if it
switches the framework's clang-tidy on. The table is still the one to follow, because a game's code
sits next to the framework's names in every line it writes. What
checks what has every rule of these pages in one table.
No k in front of a constant, no g_ in front of a global, no trailing
underscore. The spelling of the name itself says what it is, so a prefix would be saying it twice.
A type and a value never look alike where they are used. raylib's own types are PascalCase too,
so rmp::Texture sits next to Texture2D
without looking foreign; the namespace is what says whose is whose.
rmp test naming refuses it: R2constexpr int kMaxLives = 3;rmp test naming refuses it: R1int g_score = 0;rmp test naming refuses it: R8struct Counter {
int count_ = 0;
};rmp lint refuses it: readability-identifier-namingclass player_state {};constexpr int MAX_LIVES = 3;
class PlayerState {
public:
int count = 0;
};CONSTANT_CASE means "known when the program is compiled". const float half =
width / 2; inside a function is a variable that happens not to change, and stays
snake_case.
foo_.x and other._x are both wrong, in the framework as in a game. A
private field belongs to its object, so another object reaches it through a method that says what
is taken. In the framework's own code that reads other.slot() or
object.take_force(). The one place x._name appears is a call to a hook:
the collision pass calling a._collision(b).
rmp test naming refuses it: R4class Wallet {
public:
[[nodiscard]] bool richer_than(const Wallet &other) const {
return _coins > other._coins;
}
private:
int _coins = 0;
};class Wallet {
public:
[[nodiscard]] int coins() const { return _coins; }
[[nodiscard]] bool richer_than(const Wallet &other) const {
return _coins > other.coins();
}
private:
int _coins = 0;
};Only the eight hooks wear it, and clang-tidy is told those eight names and refuses any other method that starts with an underscore. So a private field never takes a hook's name, and a helper never looks like a hook. The access rule is the other half of this.
rmp lint refuses it: readability-identifier-namingclass Cannon : public rmp::Object {
public:
void _ready() override { _fire(); }
private:
void _fire() {}
};class Cannon : public rmp::Object {
public:
void _ready() override { fire(); }
private:
void fire() {}
};The g_ prefix existed to make a global visible at every use. Without it, plain
names collide: a variable started next to a function started(), a
variable called index, log or free next to a C library that
declares those on some platforms and not on others, a parameter scale silently hiding
the file's scale. A struct per concern keeps the mark — context.started
cannot be anything but file state — and cannot collide with a function. -Wshadow
catches the local that hides a group. In the examples, where one variable is often the whole
story, a plain name reads better and the same -Wshadow applies.
rmp lint refuses it: clang-diagnostic-shadowstruct Pass {
int number = 0;
} pass;
void draw(const int pass) { DrawText(TextFormat("pass %d", pass), 10, 10, 20, WHITE); }struct ThisPass {
int number = 0;
} this_pass;
void draw(const int pass) {
this_pass.number = pass;
DrawText(TextFormat("pass %d", this_pass.number), 10, 10, 20, WHITE);
}The preprocessor runs before the compiler and knows nothing of namespaces. PI and
DEG2RAD are raylib's macros, EPSILON is raymath's, MIN and
MAX are defined by the BSDs' system headers, CHECK by the test library,
DEBUG by raymob's debug build. A constant with one of those names is replaced on
exactly the platforms that define it: the build is green on Linux and red on NetBSD. This one
compiles on Linux, which is the trouble with it:
rmp test naming refuses it: R6constexpr int MAX = 10;So a constant is named after what the number is for — NEAR_ZERO,
TOLERANCE, MAX_ENEMIES — and pi is not a constant of yours at all: it is
std::numbers::pi_v<float>, and clang-tidy refuses pi written out as a
number:
rmp lint refuses it: modernize-use-std-numbersfloat full_turn() { return 2.0f * 3.14159265f; }#include <numbers>
constexpr int MAX_ENEMIES = 10;
float full_turn() { return 2.0f * std::numbers::pi_v<float>; }RMP_#Never with __ or an underscore and a capital, which belong to the compiler and the
C library. A value from the .toml is named after its table and key: [window]
width is RMP_WINDOW_WIDTH, [project] name is
RMP_PROJECT_NAME. A vendored library's own switches keep their names, in the one file
that configures it. Macros has the rest.
rmp test naming refuses it: R5#define TILE_SIZE 16A number does not need a macro at all; a constant does it with a type:
constexpr int TILE_SIZE = 16;A
renamed macro left behind in an #if is not an error: the preprocessor reads an
undefined name as 0. An old spelling of the portable-saves switch in an #if would have
switched portable saves off, on Windows only, with nothing saying so. The compiler has nothing to
say about the block below; tools/naming_check.sh knows the names that are gone:
rmp test naming refuses it: R7#if APP_SAVE_PORTABLE
constexpr bool PORTABLE_SAVES = true;
#else
constexpr bool PORTABLE_SAVES = false;
#endif#if RMP_SAVE_PORTABLE
constexpr bool PORTABLE_SAVES = true;
#else
constexpr bool PORTABLE_SAVES = false;
#endifSo a search for a name finds its explanations too, and a rename renames the comments with it. No tool checks a comment; this one is for whoever reviews the change.
clang-tidy reads what the compiler parses, and the compiler parses one branch of every
#if: on a Linux machine, the web, iOS, Android and Windows code is not there for it.
It sees a name where it is declared, not where it is used, so other._coins is not its
business. And it says nothing about a macro named like someone else's. That is what
tools/naming_check.sh is for: it blanks the comments and the strings, reads the text
of every branch, and holds rules R1 to R8 over all of it.
The last rule, R8, is there because clang-tidy does not name a declaration a macro expands: a variable declared inside a macro's body is invisible to it, however it is spelled. The script reads the text, so it sees the name in the macro's definition.
https://omardev29.github.io/rmp-docs/guidelines/formatting.html
Nobody formats the framework's code by hand. .clang-format says how
it is laid out, rmp fmt lays it out that way, and rmp test fmt refuses a
file that is not. What follows is what that file decides, why, and what clang-format says about
code written any other way — so that you can write it right the first time, and read the diff it
makes when you do not.
| Command | What it does | Where |
|---|---|---|
rmp fmt | formats every file in place | in the framework: include/, src/, tests/ and examples/; in a game: its own include/, src/ and tests/, and not the files that came with the framework: src/rmp/, include/rmp/ and tests/smoke_test.h |
rmp fmt check | fails on a file clang-format would change, and changes nothing | the same files |
rmp test fmt | the same, as a stage of rmp test | the framework, and its CI's lint job |
A
game made with rmp new gets the framework's .clang-format, so
rmp fmt lays its code out the same way and rmp fmt check refuses a file
that is not; neither the
game's rmp test nor its
CI runs them.
It leaves the framework's own sources alone because a different clang-format would rewrite them
for no reason of the game's.
The version is pinned,
and it matters: clang-format one minor version out reformats files that were already right. The
framework pins clang-format 22.1.8 in thirdparty/FROZEN_VERSIONS.md, and its
tools/versions_check.sh says so when the one on your PATH is another. Each
block on this page shown refused is what that version says about it.
Four spaces and no tab, where LLVM's style, which the file starts from, has two. A brace opens on the line of what it belongs to.
rmp test fmt refuses itstruct Ship {
int hp = 3;
float speed = 120.0f;
};struct Ship {
int hp = 3;
float speed = 120.0f;
};A line is at most 90 columns, not LLVM's 80: wide enough for a declaration of the public headers and the comment after it, which is a shape nearly every line of them has. A longer one is broken where clang-format breaks it:
rmp test fmt refuses itvoid announce(const int level, const int lives) { DrawText(TextFormat("Level %d, %d lives left", level, lives), 10, 10, 20, WHITE); }void announce(const int level, const int lives) {
DrawText(TextFormat("Level %d, %d lives left", level, lives), 10, 10, 20, WHITE);
}No
column of = signs, no comments padded out to line up, no table squared with spaces.
A column lined up with a ruler looks tidy in the commit that wrote it and costs something every time
after: renaming one field moves twenty lines, the diff of a one-line change is a paragraph, and
git blame stops pointing at whoever wrote the code and points at whoever moved the
spaces. Code takes its shape from its structure, not from padding.
rmp test fmt refuses itstruct Theme {
Color background = { 18, 18, 22, 255 }; // behind everything
Color surface_hover = { 60, 60, 76, 255 }; // a button under the pointer
};struct Theme {
Color background = { 18, 18, 22, 255 }; // behind everything
Color surface_hover = { 60, 60, 76, 255 }; // a button under the pointer
};One column is left, and clang-format keeps it: the backslashes that carry a macro over several lines line up just past the macro's longest line, so a new longest line moves every one of them.
An
if that leaves early stays on one line, and so does a short loop or a short
function. if (!ready) return; reads as a guard; a guard spread over three lines stops
looking like one. Without braces: a block gets lines of its own.
rmp test fmt refuses itvoid step(const bool ready) {
if (!ready)
return;
jump();
}void step(const bool ready) {
if (!ready) return;
jump();
}A function that fits on a line is written on one, and a block does not start with an empty line:
rmp test fmt refuses itclass Ship {
public:
[[nodiscard]] int hp() const {
return _hp;
}
private:
int _hp = 3;
};class Ship {
public:
[[nodiscard]] int hp() const { return _hp; }
private:
int _hp = 3;
};An access specifier stands at the
column of its class, so public: and private: read as the headings they
are:
rmp test fmt refuses itclass Coin {
public:
int value = 10;
};class Coin {
public:
int value = 10;
};A namespace does not indent what is in it, and its closing brace says which namespace it closes, however short it is:
rmp test fmt refuses itnamespace layer {
constexpr unsigned PLAYER = 1U << 0;
}namespace layer {
constexpr unsigned PLAYER = 1U << 0;
} // namespace layerA
case is indented inside its switch:
rmp test fmt refuses itfloat speed_for(const State state) {
switch (state) {
case State::IDLE:
return 0.0f;
case State::RUNNING:
return 120.0f;
}
return 0.0f;
}float speed_for(const State state) {
switch (state) {
case State::IDLE:
return 0.0f;
case State::RUNNING:
return 120.0f;
}
return 0.0f;
}int &x, and { 1, 2 }#The
& of a reference sits against the name, not the type — as the * of a
pointer does, which is how raylib writes it: const char *text. There is no pointer in
the framework's own code to show it on (Pointers and
RAII says why), but every call into raylib's C has one.
rmp test fmt refuses itvoid heal(int& hp, int amount);void heal(int &hp, int amount);A braced list keeps a space inside each brace, as raylib's colours are written. LLVM's style closes them up, and every colour of the theme would change.
rmp test fmt refuses itconstexpr Color SKY = Color{135, 206, 235, 255};constexpr Color SKY = { 135, 206, 235, 255 };It does not sort the includes. They are in the order they were written, and each one may say after it what it is for; sorting them would scramble that, and in code that speaks to C the order of includes can matter.
#include <string_view> // a name on the way in
#include <vector> // the enemies on screenIt never rewraps a comment. The framework's file headers carry trees, tables and paragraphs wrapped by hand, and a formatter that rewraps them destroys the part of the code that took longest to write.
And
it does not touch the entry-point macros of rmp/app.h, which sit between
// clang-format off and // clang-format on: their bodies hold block
comments, and every formatter mangles a /* */ inside a macro's continued lines. They are
the only code of the framework's own it is told to leave alone;
the vendored libraries and the headers generated from the .toml are left out whole, by
.clang-format-ignore.
A header is .h and a source file .cpp, and a header starts with
#pragma once: every compiler the framework builds with understands it, and it cannot
get out of step with the file's name the way an include guard can. clang-tidy has a check that
would refuse it, portability-avoid-pragma-once, and the framework's
.clang-tidy turns it off. Nothing checks that a header has it, and every header of the
framework does
but one: tests/smoke_test.h, which the plain C example includes too, has an include
guard.
#pragma once
namespace game {
inline constexpr int START_LIVES = 3;
} // namespace gamehttps://omardev29.github.io/rmp-docs/guidelines/const.html
constWhat does not change is marked as not changing: a local, a reference, a method, a
parameter's copy, a constant. The reader learns at the declaration that the value at the bottom of
the function is the one at the top, and the compiler holds the code to it. Where the value is known
when the code compiles, it is constexpr, and the compiler works it out.
Google's
guide asks for const "whenever it makes sense". This framework makes it a rule
without the "whenever": clang-tidy's misc-const-correctness runs over the framework,
its tests and its examples, and nothing in them is left that it refuses
but two lines that carry a NOLINT with the reason. It is not
about bugs, it is about the reader.
rmp lint refuses it: misc-const-correctnessint score_for(const int coins, const int seconds) {
int bonus = seconds < 60 ? 100 : 0;
return coins * 10 + bonus;
}int score_for(const int coins, const int seconds) {
const int bonus = seconds < 60 ? 100 : 0;
return coins * 10 + bonus;
}The same goes for a loop's variable, which is a new local on every turn, and for a reference
that is only read through, which is a const &:
rmp lint refuses it: misc-const-correctnessint total(const std::vector<int> &scores) {
int sum = 0;
for (int score : scores) sum += score;
return sum;
}int total(const std::vector<int> &scores) {
int sum = 0;
for (const int score : scores) sum += score;
return sum;
}A method that reads the object and writes nothing is const, so it can be called on
a const object and says at the declaration that it is safe to call anywhere.
clang-tidy's readability-make-member-function-const refuses one that is not, in the
framework and its tests; the examples leave the readability checks out.
rmp lint refuses it: readability-make-member-function-constclass Wallet {
public:
[[nodiscard]] bool can_pay(const int price) { return _coins >= price; }
private:
int _coins = 0;
};class Wallet {
public:
[[nodiscard]] bool can_pay(const int price) const { return _coins >= price; }
private:
int _coins = 0;
};A
parameter taken by value is a local of the function, and the same rule holds for it: when the
function does not change it, it is const. But only where the function is defined.
In a declaration that const means nothing to the caller, who hands over a copy either
way, and clang-tidy refuses it there:
rmp lint refuses it: readability-avoid-const-params-in-declsvoid heal(const int amount);class Ship {
public:
void heal(int amount);
private:
int _hp = 3;
};
void Ship::heal(const int amount) { _hp += amount; }The half in the definition has no check: clang-tidy does not look at parameters. It is a question for whoever reviews the change.
A parameter that is expensive to copy and only read is not a copy at all: it is a
const reference. clang-tidy refuses the copy, in the framework and in the
examples:
rmp lint refuses it: performance-unnecessary-value-paramint count_walls(Level level) { return static_cast<int>(level.walls.size()); }int count_walls(const Level &level) { return static_cast<int>(level.walls.size()); }Text and sequences have a better answer than a const reference:
a std::string_view and
a std::span.
constexpr: known when it compiles#A value the code can know when it compiles is constexpr, and a function that can
work one out is constexpr too, so it can be used for one. The name says it:
a constexpr is CONSTANT_CASE (Naming).
constexpr float GRAVITY = 980.0f;
constexpr int TILE_SIZE = 16;
constexpr int tiles_across(const int width) { return width / TILE_SIZE; }
constexpr int LEVEL_TILES = tiles_across(800);No tool can say that a value could have been constexpr and is not; clang-tidy has
no such check. It is the other question for review — except in a header, where the rule is
stricter and is checked.
inline constexpr#A
constant at namespace scope in a header is inline constexpr. A const or
a constexpr there has internal linkage, so every file that includes the header gets a
copy of its own; inline makes it one object for the whole program, and
constexpr makes it known when the code compiles. The framework's
.clang-tidy holds a query of its own for this, custom-rmp-header-constant,
which reads every header its lint reaches — the framework's, its tests' and the examples':
rmp lint refuses it: custom-rmp-header-constant#pragma once
namespace game {
constexpr int START_LIVES = 3;
} // namespace game#pragma once
namespace game {
inline constexpr int START_LIVES = 3;
} // namespace gameIt runs only with clang-tidy's --experimental-custom-checks, which
rmp lint passes; a clang-tidy started without it reads the same file and runs
everything else, saying nothing about this one.
consteval: only when it compiles#A function that must never run while the game does is consteval: every call is
worked out by the compiler, and a call it cannot work out does not compile. A collision layer is a
bit, and the bit is known when the code is written:
consteval unsigned layer_bit(const int index) { return 1U << index; }
constexpr unsigned PLAYER = layer_bit(0);
constexpr unsigned ENEMY = layer_bit(1);const int index = GetRandomValue(0, 3);
const unsigned layer = layer_bit(index);The compiler refuses it, saying among other things: constant expression
constinit: state that starts known#State
at file scope that changes while the game runs, and whose first value is known when the code
compiles, is constinit: it is set before any code runs, so no other file's start-up
can read it before it is ready. The framework's random number generator is held this way, so that
its first value is the same every time.
constinit struct {
unsigned seed = 1;
int draws = 0;
} generator;A value only the running game can produce does not compile there:
constinit struct {
int seed = GetRandomValue(0, 100);
} generator;The compiler refuses it, saying among other things: constant initializer
Both
are C++20, and both are in the oldest compiler a game is built with, NetBSD's GCC 10.5. What that
compiler does not have is a constexpr std::string or
std::vector: a group of file state that holds one cannot be constinit
there, and is set at start-up instead.
| Rule | Check | Where |
|---|---|---|
A local, or a reference, that does not change is const | misc-const-correctness | the framework, its tests, the examples |
A method that changes nothing is const | readability-make-member-function-const | the framework and its tests |
No const on a by-value parameter in a declaration | readability-avoid-const-params-in-decls | the framework and its tests |
A const by-value parameter in the definition | none: a review question | |
A read-only parameter that is costly to copy is a const reference | performance-unnecessary-value-param | the framework, its tests, the examples |
constexpr, consteval, constinit wherever they fit | none: a review question | |
A namespace constant in a header is inline constexpr | custom-rmp-header-constant | every header the lint reaches |
Every check here is clang-tidy, with the framework's .clang-tidy, run by
rmp lint over src/, tests/ and examples/. A game
does not get that file: there, these rules are a recommendation, and nothing holds a game to them
unless it switches the framework's clang-tidy on. What checks what has
every rule of these pages in one table.
https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html
No raw pointer: not in what the framework hands a game, not in its own sources, not in its tests or its examples. And nothing freed by hand: whatever is owned is owned by something that frees it when it goes. The two rules are one idea from two sides — every thing has an owner you can see, and everything that refers to it says how.
A pointer asks whoever reads it three questions — may it be null, who owns what it points at, how long does that live — and its type answers none of them. Each form below answers all three, so a signature written with them needs no comment to be used right. Google's guide allows a pointer for an optional argument or a result that may be missing; this framework does not, and has a type for each of those cases instead.
| What you mean | What you write |
|---|---|
| a small thing, copied | the value: a Vector2, a Shape, an options struct |
| a result that may not be there | std::optional<T> |
| an argument that may be left out | two overloads: load_map(name) and load_map(name, level) |
| something that is certainly there, for the length of the call | T & |
| the caller's elements, for the length of the call | std::span<T> |
| the caller's text, for the length of the call | std::string_view |
| something that may be missing and is not yours, within the frame | rmp::Ref<T> |
| an object kept from one frame to the next | rmp::Handle<T> |
| something that is yours alone | a value, or a std::unique_ptr<T> when it is polymorphic or large |
rmp lint refuses it: custom-rmp-raw-pointervoid reset(int *score) { *score = 0; }void reset(int &score) { score = 0; }The framework's API reads the same way. A spawned object always has its scene, so
scene() is a Scene &; a control
that edits a value takes it by reference, as slider
does.
std::optional, for an answer that may not be there#rmp lint refuses it: custom-rmp-raw-pointerconst Door *first_open(const std::vector<Door> &doors) {
for (const Door &door : doors) {
if (!door.locked) return &door;
}
return nullptr;
}#include <optional>
std::optional<Vector2> first_open(const std::vector<Door> &doors) {
for (const Door &door : doors) {
if (!door.locked) return door.position;
}
return std::nullopt;
}And what reads it asks first. * on an empty std::optional is
undefined behaviour, not an error, so clang-tidy refuses a read that nothing before it has
checked:
rmp lint refuses it: bugprone-unchecked-optional-accessconst std::optional<Vector2> door = first_open();
DrawCircleV(*door, 8, GREEN);if (const std::optional<Vector2> door = first_open()) DrawCircleV(*door, 8, GREEN);std::span, for the caller's elements#A pointer and a count are two arguments that have to agree, and nothing makes them. A
std::span is the two in one, from a std::array, a
std::vector or a list written in place.
rmp lint refuses it: custom-rmp-raw-pointerfloat average(const float *values, const int count) {
float sum = 0;
for (int i = 0; i < count; ++i) sum += values[i];
return count > 0 ? sum / static_cast<float>(count) : 0;
}#include <span>
float average(std::span<const float> values) {
float sum = 0;
for (const float value : values) sum += value;
return values.empty() ? 0 : sum / static_cast<float>(values.size());
}It
works the other way too: raycast_all writes
every hit along a ray into a span of yours, as many as it holds, and says how many it wrote.
std::array<rmp::RayHit, 8> hits{};
const int count = raycast_all({ .from = { 0, 200 }, .to = { 800, 200 } }, hits);
DrawText(TextFormat("%d in the way", count), 10, 10, 20, WHITE);rmp::Ref, for something that may be missing#An
rmp::Ref<T> is empty, or refers to something; it owns
nothing, and asking it is an if. It is what
get<B>() hands back, empty when the object
has no B, and what Handle::get() hands
back, empty once the object is gone. Keep it within the frame; across frames, keep the handle.
rmp lint refuses it: custom-rmp-raw-pointerrmp::behavior::Health *health_of(rmp::Object &object) {
if (auto health = object.get<rmp::behavior::Health>()) return &*health;
return nullptr;
}auto &player = spawn({ .size = { 26, 26 } });
player.add<rmp::behavior::Health>({ .hp = 3 });
if (auto health = player.get<rmp::behavior::Health>()) health->heal(1);Reaching
into an empty one without asking is a mistake in the game, and the framework says so once, in the
log; the line that forgot the if then writes to a stand-in made for the purpose
instead of taking the game down. [dev] strict stops a debug build there instead,
and a type with no default constructor has no stand-in: there, the one mistake ends the
program.
It is a type of the framework's own because the standard library's spelling,
std::optional<std::reference_wrapper<T>>, costs
<functional> in every file with an object in it, and reads
health->get().hp.
Everything
a game can name — every function, field, variable and alias in include/rmp/ outside a
detail namespace and outside a private member — is read by
tools/pointer_check.py: clang dumps each header's declarations and the script refuses a
pointer, a C string, or an alias that hides one. Reading the declarations and not the text is the
point: a comment is not a declaration, a private member is not public, and
using SampleFn = ... is seen through.
rmp test pointers refuses it#pragma once
#include <string_view>
namespace rmp {
class Object;
Object *find(std::string_view name);
} // namespace rmp#pragma once
#include <string_view>
namespace rmp {
class Object;
template <class T> class Ref;
Ref<Object> find(std::string_view name);
} // namespace rmpNowhere but here, and each place for a reason:
extern "C" function and its parameters: a fuzzer's entry
point takes its input as a pointer, because that is its C interface.operator->, which the language requires to return one. It is
how health->hp reads, on a Ref and on a Handle.rmp::Ref: its one member is the optional reference, so
that nothing else has to hold one..c file — the resource packer, the plain C example, the sanitizer hooks — is C
because it has to be, and C has nothing else.raylib is not on the list. A raylib function that takes an address takes it in a call, and an address in a call is not a pointer anybody declared:
Camera3D camera = { .position = { 10, 10, 10 }, .up = { 0, 1, 0 }, .fovy = 45 };
UpdateCamera(&camera, CAMERA_ORBITAL);The
rule is newer than some of the code. In the public headers, the pointers a game cannot reach — in
a detail namespace or a private member — are listed in
tools/pointer_ratchet.txt, each with its reason, and the list only shrinks: a new one
fails until it is replaced or written down, and a line that matches nothing any more fails
too.
Everywhere
else — the framework's sources, its tests, its examples — what the code still owes the rule is
counted, file by file, in tools/lint_debt.txt. rmp lint fails a pointer
that is not owed there, and a count that grew; the counts only go down.
What
is owned is a value or a std::unique_ptr, and it is freed by its destructor: no
new, no delete, no malloc, no free. A
delete nobody wrote cannot be forgotten, and one nobody wrote cannot run twice. The
order of the way out is the order the owners go, which is what makes it safe to free a texture
before the window that its memory belongs to.
Two
files of the framework allocate with the C allocator, and tools/ownership_check.sh
names them with the reason: raylib's file-loading callback and the resource pack's reader hand
raylib bytes that raylib frees itself, with UnloadFileData(). That is raylib's C
interface, not an ownership the framework chose, and the list only shrinks.
rmp lint refuses it: cppcoreguidelines-owning-memoryint wave_hp() {
auto *boss = new Enemy();
const int hp = boss->hp;
delete boss;
return hp;
}int wave_hp() {
const Enemy boss;
return boss.hp;
}When it has to be on the heap — something polymorphic, or too big to move about — it is a
std::unique_ptr, made with std::make_unique, and the hand-over is written
in the signature. That is how a scene is made: change()
makes the next one with std::make_unique, and the stack owns it from there.
#include <memory>
struct State {
virtual ~State() = default;
[[nodiscard]] virtual float speed() const = 0;
};
struct Walking : State {
[[nodiscard]] float speed() const override { return 120.0f; }
};
std::unique_ptr<State> first_state() { return std::make_unique<Walking>(); }raylib
hands out textures, sounds and fonts that are freed by a matching Unload. In a
scene, an object or an example, a forgotten one is a leak and a second one is a double free, so a
raylib Load* or Unload* appears only in the few files of the framework
that own what it makes. A game loads through rmp::assets, which hands back a handle
that frees the resource when its last copy goes:
rmp test ownership refuses it: O2const Texture2D rabbit = LoadTexture("rabbit.png");
DrawTexture(rabbit, 100, 100, WHITE);
UnloadTexture(rabbit);const rmp::Texture rabbit = rmp::assets::load_texture("rabbit.png");
DrawTexture(rabbit, 100, 100, WHITE);Ownership has what owns what in the framework —
assets, objects and their handles, scenes, globals, callbacks — and why a callback is an
rmp::Callback and not a std::function.
RAII is not only
for memory. A container of the UI is opened by the function that takes its body and closed by a
guard in that same function. The body is a lambda, so a return in it ends the body and
not the container, and the guard closes the container even if the body throws: one left open would
spoil the whole frame.
rmp::ui::panel([&] {
rmp::ui::text("Paused");
if (rmp::ui::button("Resume")) resume();
if (rmp::ui::button("Quit")) quit();
});| Rule | Tool | Where |
|---|---|---|
| No raw pointer and no C string in a declaration a game can name | tools/pointer_check.py, rmp test pointers, against tools/pointer_ratchet.txt | the declarations in include/rmp/ |
| No raw pointer anywhere else | custom-rmp-raw-pointer, a query of the framework's .clang-tidy; rmp lint, against tools/lint_debt.txt | src/, tests/, examples/, and the bodies of the headers' inline functions |
A std::optional is asked before it is read | bugprone-unchecked-optional-access; rmp lint | src/, tests/, examples/ |
No new, delete, malloc or free | tools/ownership_check.sh O1, rmp test ownership | include/rmp/ and src/rmp/ |
| The same, as clang-tidy sees it | cppcoreguidelines-owning-memory and cppcoreguidelines-no-malloc; rmp lint | src/, tests/, examples/ |
raylib's Load* and Unload* only in the files that own what they make | tools/ownership_check.sh O2, rmp test ownership | include/rmp/, src/rmp/ and the examples' C++ |
custom-rmp-raw-pointer runs only with clang-tidy's
--experimental-custom-checks, which rmp lint passes. A game gets none of
these tools: the rules are recommended to it, and the clang-tidy checks among them hold it only if
it switches the framework's clang-tidy on. What checks what has every
rule of these pages in one table.
https://omardev29.github.io/rmp-docs/guidelines/strings.html
Text goes into a function as a std::string_view and comes out of one
as a std::string — or as a view whose comment says how long it is good for. No
declaration a game can name has a C string in it. Where text has to reach raylib, which is C and
wants a const char * that ends in a zero, it goes through a std::string
and never through a view's data().
std::string_view#One parameter type takes a literal, a std::string and another view, and copies
none of them. A const char * may be null, and has to end in a zero nobody can see; a
const std::string & turns every literal handed to it into a
std::string first. So the framework's functions that take a name take a view —
load_texture,
input::pressed,
audio::play, every label of
rmp::ui — and
tools/pointer_check.py refuses a C string in any declaration a game can name:
rmp test pointers refuses it#pragma once
namespace rmp {
void say(const char *line);
} // namespace rmp#pragma once
#include <string_view>
namespace rmp {
void say(std::string_view line);
} // namespace rmpOutside the public headers a const char * is a raw pointer like any other, and
clang-tidy refuses it as one (Pointers and
RAII). A const std::string & parameter passes every tool; it is a question
for review.
std::string, or a view that says how long#A function that makes text hands it back as a std::string, which owns it:
save::directory() does. A view handed back
is a view of something that lives elsewhere, so it is only right when that something outlives the
call, and its comment says until when.
The
view Value::as_string() hands back is good
while that value is alive and unchanged, and the one
Sprite::playing() hands back for as long as
the sheet is loaded; each comment says so. A view of a std::string that dies at the end of the line,
or of the function, is refused:
rmp lint refuses it: bugprone-dangling-handlestd::string_view title_for(const int level) {
const std::string title = "Level " + std::to_string(level);
return title;
}std::string title_for(const int level) { return "Level " + std::to_string(level); }std::string#raylib's text functions take a const char * and read until they find a zero. A
std::string_view has no zero after its last character: it may be a piece of a longer
text, and its data() carries on into whatever comes next. The compiler will not turn
a view into a pointer, so the mistake is to reach for data():
void say(std::string_view line) {
DrawText(line, 10, 10, 20, WHITE);
}The compiler refuses it, saying among other things: const char
rmp lint refuses it: bugprone-suspicious-stringview-data-usagevoid say(std::string_view line) {
DrawText(line.data(), 10, 10, 20, WHITE);
}A std::string
made from the view ends in a zero, and lives until the end of the statement: long enough for the
call. The framework passes a name to raylib this way.
void say(std::string_view line) {
DrawText(std::string(line).c_str(), 10, 10, 20, WHITE);
}The UI takes the other way out: it copies every piece of text it is given into memory of its own that lasts until the next frame, because the layout library under it keeps the pointer it is given and reads it later. So a temporary is safe there:
rmp::ui::begin();
rmp::ui::text(std::to_string(score));
rmp::ui::end();Text from raylib comes back the other way as a const char *, and goes into a
std::string before it goes anywhere else. A rmp::Value
takes a literal, a std::string and a view, and does not take a
const char *, which might be null:
rmp::Value settings = rmp::Value::object();
settings["folder"] = GetWorkingDirectory();The compiler refuses it, saying among other things: const char
rmp::Value settings = rmp::Value::object();
settings["folder"] = std::string(GetWorkingDirectory());With what every compiler a game is built with has: std::to_string and
+ for a std::string, and raylib's TextFormat for a line to
draw.
std::string lives_text(const int lives) { return std::to_string(lives) + " lives"; }
void draw_lives(const int lives) {
DrawText(TextFormat("%d lives", lives), 10, 10, 20, WHITE);
}Not
<format>: the oldest compiler a game
is built with, NetBSD's GCC 10.5, does not have it. It compiles on a newer one, so tools/style_check.sh refuses it, in every
branch of every #if:
rmp test style refuses it: S4#include <format>
#include <string>
std::string lives_text(const int lives) { return std::format("{} lives", lives); }And
not "Pong"sv: Google's guide has no user-defined literals, the standard library's
included, and neither does the framework. A std::string_view constant is spelt out,
and a literal turns into one by itself.
rmp test style refuses it: S5using namespace std::string_view_literals;
constexpr auto TITLE = "Pong"sv;constexpr std::string_view TITLE = "Pong";| Rule | Tool | Where |
|---|---|---|
| No C string in a declaration a game can name | tools/pointer_check.py, rmp test pointers | the declarations in include/rmp/ |
No const char * anywhere else | custom-rmp-raw-pointer; rmp lint, against tools/lint_debt.txt | src/, tests/, examples/ |
| No view that outlives what it views | bugprone-dangling-handle; rmp lint | src/, tests/, examples/ |
No data() of a view where a C string is wanted | bugprone-suspicious-stringview-data-usage; rmp lint | src/, tests/, examples/ |
No <format>, no user-defined literal | tools/style_check.sh S4 and S5, rmp test style | include/, src/ and examples/; S5 in tests/ too |
A game gets none of these tools: in a game, these rules are a recommendation, and the clang-tidy checks among them hold it only if it switches the framework's clang-tidy on. What checks what has every rule of these pages in one table.
https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html
raylib is C, and the framework is C++ written on top of it. Where C++ has a way of saying something that knows more than C's — how long an array is, which conversion a cast means, which scope a name belongs to — the code here uses it, and a check holds it there. raylib's own types and calls stay as they are: a call into raylib is where the C++ ends, and that boundary is written down below wherever a rule meets it.
Each rule says why, shows the way the framework refuses and the way it takes, and names what
checks it and where. "The framework" is its include/, src/ and
tests/; the examples have a .clang-tidy of their own; and a game made with
rmp new gets none of these checks, only the advice. What
checks what has every rule of these pages in one table.
A C array forgets its length the moment it is passed anywhere, and cannot be copied or
returned. std::array knows its size, copies like any other value, and works with a
range-for and the standard algorithms:
rmp lint refuses it: modernize-avoid-c-arraysint high_scores[5] = {};#include <array>
std::array<int, 5> high_scores{};
int best() {
int top = 0;
for (const int score : high_scores) top = score > top ? score : top;
return top;
}raylib takes C arrays as a pointer and a count, and that call is the boundary: the array hands
over data() and its size, converted to the int raylib asks for.
const std::array corners{ Vector2{ 0, 0 }, Vector2{ 40, 0 }, Vector2{ 20, 30 } };
DrawTriangleFan(corners.data(), static_cast<int>(corners.size()), RED);Let the compiler count when the list is the whole array. A size written by hand that is larger than the list compiles, and fills the rest with zeros, which no check notices; written without a size, the array is exactly as long as what is in it:
#include <array>
constexpr std::array LANES{ 120.0f, 240.0f, 360.0f };Checked by
modernize-avoid-c-arrays, in the framework and in the examples.
A C cast does whatever it takes to make the types fit: a value conversion, a reinterpretation of
the bits, a const thrown away. static_cast says which conversion was meant,
does only that one, and is the one a reader can search for. Converting a float to an
int is the usual case in a game, and it is the one a C cast hides best:
rmp lint refuses it: modernize-avoid-c-style-castint whole_seconds(float seconds) { return (int)seconds; }int whole_seconds(const float seconds) { return static_cast<int>(seconds); }A conversion that cannot lose anything can be written with braces instead, which refuse to compile one that could. Google's guide prefers that form wherever it applies:
#include <cstdint>
std::int64_t total(const int score) { return std::int64_t{ score } * 1000; }clang-tidy parses one branch of every #if, the one of the machine it runs on, so a
cast in the Android branch is invisible to a lint run on Linux. The style gate reads every
branch:
rmp test style refuses it: S1#if defined(PLATFORM_ANDROID)
const int columns = (int)(GetScreenWidth() / 64.0f);
#else
const int columns = static_cast<int>(GetScreenWidth() / 64.0f);
#endif
DrawRectangle(0, 0, columns, columns, RED);Checked by
modernize-avoid-c-style-cast, in the framework and in the examples, and by rule S1 of
tools/style_check.sh, the style stage of rmp test, over every
branch of the framework's and the examples' code. The plain C example and
tests/smoke_test.h, which is compiled as C, are exempt: a cast is the language
there.
The members of a plain enum are names in the enclosing scope and turn into
int without being asked: LEFT collides with the next enum that has a
LEFT, and LEFT + 3 compiles. An enum class keeps its
members to itself, and converts only when a cast says so:
rmp lint refuses it: cppcoreguidelines-use-enum-classenum Direction { LEFT, RIGHT };enum class Direction { LEFT, RIGHT };
int step(const Direction direction) { return direction == Direction::LEFT ? -1 : 1; }raylib's enums — KEY_SPACE, LOG_INFO — are C's, and are used as raylib
declares them. Checked by cppcoreguidelines-use-enum-class, in the framework and in the
examples.
NULL and 0 are integers that happen to convert to a pointer, so an
overload that takes an int can be chosen over the one that takes a pointer.
nullptr has a type of its own and converts only to a pointer. The rule against raw
pointers (Pointers and RAII) leaves it few places to
appear, most of them where a C function asks for a pointer:
rmp lint refuses it: modernize-use-nullptr#include <ctime>
std::time_t now() { return std::time(0); }#include <ctime>
std::time_t now() { return std::time(nullptr); }Checked by modernize-use-nullptr, in the framework and in the examples, and
NULL by rule S2 of tools/style_check.sh, in every branch.
A function declared with ... takes anything and checks nothing: the types of what
it reads are whatever its body says they are, and a wrong one is undefined behaviour, not an error.
A list of values of one type is a std::span (or an initializer list); values of
several types are a template:
rmp lint refuses it: modernize-avoid-variadic-functions#include <cstdarg>
int sum(int count, ...) {
va_list values;
va_start(values, count);
int total = 0;
for (int i = 0; i < count; ++i) total += va_arg(values, int);
va_end(values);
return total;
}#include <span>
int sum(std::span<const int> values) {
int total = 0;
for (const int value : values) total += value;
return total;
}A std::array, a std::vector or a braced list passes to it as it is.
Calling raylib's variadic functions — TraceLog(), TextFormat() —
is the boundary, and allowed: the rule is about defining one.
The
framework defines two, on purpose, side by side: the functions behind its said-once warnings,
which hand a printf format to TraceLog(), one of them with a key. Each
carries a NOLINT with the reason, and a format(printf) attribute, so GCC
and Clang check every format against its values as an error. Macros has the
details. Checked by modernize-avoid-variadic-functions, in the framework and in the
examples.
How wide long is depends on the platform: 64 bits on 64-bit Linux and macOS, 32 on
Windows and on the web. A game that ships to all of them has two different types under one name. int is the
integer, and when a value needs a known size, <cstdint> names it:
rmp lint refuses it: google-runtime-intlong total_score = 0;#include <cstdint>
std::int64_t total_score = 0;Unsigned types are for bits — a collision mask, a generation counter that is meant to wrap — and
not for saying a number is never negative. float and double are the
floating-point types; long double is a different size on every compiler:
rmp lint refuses it: google-runtime-floatlong double elapsed = 0;Checked by google-runtime-int and google-runtime-float, in the framework
and in the examples. That an unsigned number is a bit pattern is a question for review.
A constructor that takes one argument is also a conversion, used wherever the compiler finds
the argument's type and wants the class: a float passed where
Meters is expected becomes one without a word. explicit makes that a
decision of the caller's:
rmp lint refuses it: google-explicit-constructorstruct Meters {
Meters(float value) : value(value) {}
float value;
};struct Meters {
explicit Meters(const float amount) : value(amount) {}
float value;
};The
framework's API makes a few conversions on purpose, because without them the simple call would be
longer: a number, a bool or a piece of text becomes an
rmp::Value, so a save is filled the way it reads.
rmp::Value save;
save["score"] = 3;
save["name"] = "Omar";
save["alive"] = true;Each of those conversions carries a NOLINT and its reason beside it;
Google's guide and this one lists them.
Checked by google-explicit-constructor, in the framework and in the examples.
A class that writes its own destructor is managing something, and the copy the compiler writes for it copies the handle and not the thing: two copies, two destructors, one thing released twice. A class that writes one of the destructor, the copy and the move says what becomes of the others:
rmp lint refuses it: cppcoreguidelines-special-member-functionsclass Voice {
public:
explicit Voice(const Sound sound) : _sound(sound) {}
~Voice() { StopSound(_sound); }
private:
Sound _sound;
};class Voice {
public:
explicit Voice(const Sound sound) : _sound(sound) {}
Voice(const Voice &) = delete;
Voice &operator=(const Voice &) = delete;
~Voice() { StopSound(_sound); }
private:
Sound _sound;
};A
class whose copy is deleted is not asked for its moves, which go with it, and a lone
= default destructor manages nothing and is not asked for anything. Checked by
cppcoreguidelines-special-member-functions, in the framework and in the examples.
Google's rule: deduce a type only when that makes the code clearer to someone who does not know it. A cast already names the type, so writing it again on the left says it twice:
rmp lint refuses it: modernize-use-autoconst float width = static_cast<float>(GetScreenWidth());
DrawLineV(Vector2{ 0, 0 }, Vector2{ width, 0 }, RED);const auto width = static_cast<float>(GetScreenWidth());
DrawLineV(Vector2{ 0, 0 }, Vector2{ width, 0 }, RED);Elsewhere the type is written: const int lives = 3; tells the reader something
auto would make them work out. Checked by modernize-use-auto in the
framework only — the examples switch the modernize family off, keeping only the rules
this page names — and the rest of Google's rule is a question for review.
An alias reads left to right like an assignment, and can be a template; a
typedef can be neither:
rmp lint refuses it: modernize-use-usingtypedef int Score;using Score = int;Checked by modernize-use-using, in the framework and in the examples.
A constant typed in by hand is as precise as the hand that typed it. C++20 has them in
<numbers>, exact to the type you ask for. raylib's PI is a macro,
which is also why no constant of yours can be called that
(Macros):
rmp lint refuses it: modernize-use-std-numbersconstexpr float HALF_TURN = 3.14159265f;#include <numbers>
constexpr float HALF_TURN = std::numbers::pi_v<float>;Checked by modernize-use-std-numbers, in the framework and in the examples. It
recognises a literal; a use of raylib's macro is not something it reports.
Google's rule: i++ promises the value from before the increment, and when nothing
reads that value the promise is noise — and, for an iterator, a copy. The prefix form says what is
meant:
rmp test style refuses it: S6int lives = 3;
lives--;
DrawText(TextFormat("lives %i", lives), 10, 10, 20, RED);int lives = 3;
--lives;
for (int i = 0; i < lives; ++i) DrawCircle(20 + (i * 30), 20, 10, RED);Where the old value is the point, the postfix form is the right one, and the gate lets it be:
int next_id = 1;
const int id = next_id++;
TraceLog(LOG_INFO, "spawned %d, next %d", id, next_id);Checked by rule S6 of
tools/style_check.sh, in every branch of the framework and the examples; this site holds
every block on its pages to the same rule.
Google's rule. "Pong"sv and 10ms are short, and each needs a
using namespace to work, which brings every other name of that namespace with it. The
type, written out, says the same thing to a reader who has never seen the suffix:
rmp test style refuses it: S5#include <string_view>
using namespace std::string_view_literals;
constexpr auto TITLE = "Pong"sv;#include <string_view>
constexpr std::string_view TITLE = "Pong";Checked by rule S5 of tools/style_check.sh, the standard library's literals
included, in every branch of the framework and the examples.
A using-directive pours a whole namespace into the file, names that arrive in a later version of the library included. Writing the namespace keeps every name's origin where it is used:
rmp lint refuses it: google-build-using-namespace#include <vector>
using namespace std;
vector<int> scores;#include <vector>
std::vector<int> scores;Checked by google-build-using-namespace, in the framework and in the examples.
A default argument belongs to the declaration the call is compiled against, not to the function that runs: called through the base class, an override gets the base's default whatever its own says. An overload that forwards says it once:
rmp lint refuses it: google-default-argumentsclass Shape {
public:
virtual ~Shape() = default;
virtual void grow(float by = 1.0f) = 0;
};class Shape {
public:
Shape() = default;
Shape(const Shape &) = delete;
Shape &operator=(const Shape &) = delete;
virtual ~Shape() = default;
void grow() { grow(1.0f); }
virtual void grow(float by) = 0;
};Checked by google-default-arguments, in the framework and in the examples.
A pointer and a count are a std::span, which carries both and cannot be given one
without the other. A result that may not be there is a std::optional, which says so
in its type instead of in a comment about -1:
rmp lint refuses it: custom-rmp-raw-pointerint total(const int *values, int count) {
int sum = 0;
for (int i = 0; i < count; ++i) sum += values[i];
return sum;
}#include <optional>
#include <string_view>
std::optional<int> level_number(const std::string_view name) {
if (name.size() != 7 || !name.starts_with("level_")) return std::nullopt;
return name.back() - '0';
}Pointers and RAII has the rest: a reference that
may be empty is an rmp::Ref, and an object kept across frames
is an rmp::Handle. Checked by
custom-rmp-raw-pointer, a query of the framework's own .clang-tidy, in the
framework and in the examples.
The options of every call in the API are a struct written with designated initialisers, and C++20 wants them in the order the fields are declared. GCC and MSVC refuse them out of order; Clang only warns, so the framework hands every target that links it the flag that makes Clang refuse too — a game's included:
struct Point {
float x = 0;
float y = 0;
};
const Point p{ .y = 2, .x = 1 };
DrawCircleV(Vector2{ p.x, p.y }, 4, RED);The compiler refuses it, saying among other things: declaration order
struct Point {
float x = 0;
float y = 0;
};
const Point p{ .x = 1, .y = 2 };
DrawCircleV(Vector2{ p.x, p.y }, 4, RED);Checked by the compiler, with -Werror=reorder-init-list under Clang, everywhere: the framework, the
examples and a game. Designated
initialisers has why the fields are ordered the way they would be written.
A
game is built for every target from the same sources, and the oldest compiler among them is
NetBSD's GCC 10.5. It takes the C++20 the framework is written in — std::span,
std::optional, concepts through requires, designated initialisers,
<numbers>, constinit — and not what arrived in GCC 11 and later:
<format>, <source_location>, std::bit_cast,
using enum, and what C++23 added. A use of one compiles on a laptop and fails on
NetBSD, in CI:
rmp test style refuses it: S4#include <bit>
#include <cstdint>
std::uint32_t bits_of(const float value) { return std::bit_cast<std::uint32_t>(value); }#include <cstdint>
#include <cstring>
std::uint32_t bits_of(const float value) {
std::uint32_t bits = 0;
std::memcpy(&bits, &value, sizeof bits);
return bits;
}The
same compiler reports __cplusplus as 201709L under
-std=c++20, because C++20 was not final when it shipped: test for a feature, not for the
version number. Checked by rule S4 of tools/style_check.sh, in every branch of the code
a game compiles: include/, src/ and the examples. The framework's tests
build only on the CI image's compilers and are exempt.
https://omardev29.github.io/rmp-docs/guidelines/macros.html
The preprocessor runs before the compiler knows what a type, a scope or a namespace
is: a macro replaces its name on every line after it — in its file, in every file that includes it,
and in every header included after it, raylib's and the C library's among them. So the rule is
short. A macro is for what nothing else in the language can
do, and everything else is a constexpr constant, a function or a template. Every macro
the framework and its examples write is named RMP_.
This page is the rule as it applies to any code written here. The framework's own macros — the
entry point, the values of the .toml, the said-once warning — are explained one by one
in why the framework has the macros it has.
A constant made with #define has no type, so 3 is whatever the
expression around it makes of it, and no scope, so it replaces that word everywhere after it — in
your files and in every header included after it. A constexpr constant has both, and is
just as known when the program compiles:
rmp lint refuses it: cppcoreguidelines-macro-usage#define RMP_LIVES 3constexpr int LIVES = 3;In a header, a constant at namespace scope is inline constexpr, one object for the
whole program; const has why.
A function-like macro pastes its arguments in as text: the one below, handed
i++, increments twice; an argument of the wrong type is an error inside the expansion;
and a debugger cannot step into it. A constexpr function does the same work at compile time when it can, and is a
function the rest of the time:
rmp lint refuses it: cppcoreguidelines-macro-usage#define RMP_SQUARE(x) ((x) * (x))template <class T> constexpr T square(const T x) { return x * x; }
static_assert(square(3) == 9);Four things no function can do, and they are the four the framework's own macros do.
Code at file scope. A program's entry point is a main() on a
desktop, a function handed to the browser on the web and three extern "C" functions on
iOS. No function can define a function, so the entry point is a macro, and a game writes it once:
RMP_GAME(MainMenuScene);The call site. A function receives a value; it cannot see how the call was
spelt, and it cannot give each place that calls it a variable of its own. A macro can do both. This
one prints the expression it was handed as well as its value, through the # operator,
which turns an argument into a string:
#define RMP_SHOW(value) TraceLog(LOG_INFO, "%s = %d", #value, value)
const int lives = 3;
RMP_SHOW(lives);The
framework's said-once warning is the other half of the same case: every place RMP_REPORT_ONCE is
written gets a static variable of its own, whose address is the key that makes it say
its line once, and only a macro can declare one there.
Conditional compilation. The same source is built for every target, and some of
it only makes sense on one of them. That is an #if on a macro the platform defines:
#if defined(PLATFORM_ANDROID)
const int touch_target = 44;
#else
const int touch_target = 32;
#endif
DrawRectangle(0, 0, touch_target, touch_target, RED);A value from the .toml. What
raylib_multiplatform.toml says reaches the code as macros, RMP_WINDOW_WIDTH
and the rest, because a game in plain C reads them too and because #if can test them.
The .toml writes them; a game only reads them:
const Vector2 centre{ RMP_WINDOW_WIDTH / 2.0f, RMP_WINDOW_HEIGHT / 2.0f };
DrawCircleV(centre, 8, RED);Checked by
cppcoreguidelines-macro-usage, in the framework and in the examples. It refuses a macro
whose body is only a literal, which could be a constant, and a macro with parameters, which could
be a function; it lets through one that uses # or ##, which nothing else
can do, and one that wraps a compiler's __attribute__, as the framework's check of
printf formats does. The framework's own macros that it would refuse are named to it one by one, in its
AllowedRegexp, so a new one in the framework is a question for whoever reviews it, not
something that slips past. clang-tidy's suggestion to turn the .toml's values
into an enum, modernize-macro-to-enum, is switched off for them: the C entry point
reads them too.
The preprocessor has one namespace, shared by raylib, the C library, every vendored library and
the game, and two macros of the same name are one silently replacing the other. So every macro
written here starts with RMP_; names that start with two underscores, or with one and
a capital letter, belong to the compiler and the C library:
rmp test naming refuses it: R5#define NAME_OF(x) #x#define RMP_NAME_OF(x) #xChecked by
readability-identifier-naming, which is given RMP_ as the macros' prefix, in
the framework and in the examples, and by rule R5 of tools/naming_check.sh in every
branch of every #if. A vendored library's own switches keep their names, in the one file
of the framework that configures it, and the script lists each of those by file.
A game's own macros are a different case: RMP_ is the framework's prefix, and a
game's macro that took it could one day meet one of the framework's. Google's rule decides there —
the project's own name, in capitals, as the prefix. Nothing in a game checks it, and a game that
switches the framework's clang-tidy on
writes its own prefix in the copy, which asks for RMP_.
An #if on a macro nobody defines is not an error: the name is 0. When a macro is
renamed, every test of the old name keeps compiling and quietly takes the other branch. The CMake
option is PRODUCTION_BUILD, and what the code sees is
RMP_PRODUCTION_BUILD; written the CMake way, this draws the frame rate in every build,
a release included:
rmp test naming refuses it: R7#if !PRODUCTION_BUILD
DrawFPS(10, 10);
#endif#if !RMP_PRODUCTION_BUILD
DrawFPS(10, 10);
#endifChecked
by rule R7 of tools/naming_check.sh, which keeps the list of retired names, in every
branch of the framework and the examples. For RMP_PRODUCTION_BUILD the framework goes
further: every build system defines it, and src/rmp/app/app.cpp refuses to compile if one
forgets.
The other direction of the same collision: a constant called PI compiles until the
file includes raylib.h, which defines PI as a number, and then the
declaration is a number followed by an equals sign:
constexpr float PI = 3.14159265f;The compiler refuses it, saying among other things: expected unqualified-id
Here the error is immediate. With a macro that only some platforms define — MIN and
MAX on the BSDs, DEBUG in Android's debug build — it compiles everywhere
except there. Naming has the rule and the list; rule R6 of
tools/naming_check.sh refuses a constant named like a macro of the vendored headers, or
like one of the C library's and the BSDs' that are known to collide.
Outside the entry point, nothing in the API asks for a macro. rmp::ui sits on Clay,
whose API is macros, and hands a game functions that take a lambda instead;
the rule has how. A game that wants Clay's macros
can include Clay and use them.
| Rule | Checked by | Where |
|---|---|---|
| A macro only for what nothing else can do | cppcoreguidelines-macro-usage | the framework and the examples |
Every macro starts with RMP_ | readability-identifier-naming, and R5 of tools/naming_check.sh in every branch | the framework and the examples |
No retired name in an #if | R7 of tools/naming_check.sh | the framework and the examples |
| No constant named like a macro | R6 of tools/naming_check.sh | the framework and the examples |
A game gets none of these checks. The two of clang-tidy's hold its code if it
switches the framework's clang-tidy on;
tools/naming_check.sh stays in the framework. The rules are the same advice for its
code, and
what checks what has the whole list.
https://omardev29.github.io/rmp-docs/guidelines/google.html
Google's C++ Style Guide decides every question the framework's own rules leave open. Where the framework has decided otherwise, the decision was made for a reason, and this page lists each one: what Google says, what the framework does instead, why, and what holds the code to it. Where the two agree and a tool checks it, that is at the end.
Above both sits the rule that outranks the others: the API is as simple as possible for whoever uses it, and a main menu is three functions. More than one difference below comes from there.
Google
spells functions PascalCase, constants and enumerators kName, and a
class's data members with a trailing underscore, table_. The framework spells
functions snake_case, constants and enumerators CONSTANT_CASE, and private
members with a leading one, _table. One spelling per kind of name, so a type, a value
and a constant never look alike where they are used — and raylib's types are
PascalCase too, so the framework's sit beside Texture2D and
Vector2 without looking foreign. Naming has the
whole table.
Google
moved its enumerators from ENUM_NAME to kEnumName because the
upper-case names collided with macros. The framework keeps the upper case and answers the
collision with a check instead: rule R6 of tools/naming_check.sh refuses a constant
named like a macro of the vendored headers, or like one of the C library's and the BSDs' that are
known to collide.
The
private member's underscore is at the front so that it never touches a dot or an arrow:
other._table is refused (rule R4), and so is table_.size() (rule R3).
Checked by readability-identifier-naming and tools/naming_check.sh,
in the framework and the examples.
Google
asks for #define guards named after the file's path. A header here starts with
#pragma once instead: one line that cannot be misspelt, copied into the wrong file or
collide with another guard, and every compiler the framework builds with supports it.
portability-avoid-pragma-once, which would refuse it, is switched off. Nothing checks
that a header has it; a header without it is a question for review,
and the framework has one: tests/smoke_test.h, which the plain C example includes too,
keeps a guard.
Google:
avoid forward declarations, include the header you need. Its decision makes one exception, for
entities your project owns, when a forward declaration is the better way to fix a slowdown. That is
the case here, and it is measured rather than assumed: the framework's headers forward-declare each
other instead of including, a header that cannot — rmp/scene.h holds an
rmp::Tilemap by value — says why at its top, and tools/header_budget.txt
holds what each one costs to include. One header per module has the
numbers. A header from outside the framework — the standard library's, raylib's — is included, as
Google says.
Google
indents by 2 and stops at 80 columns; the framework indents by 4 and stops at 90. Google writes
char* c; the framework writes char *c, as raylib does. Google indents
public: by one space; the framework puts it at the class's own indentation. Google
writes a braced list as {1, 2}; the framework as { 1, 2 }, so the theme's
colour literals keep their spaces. Google sorts includes into five groups, alphabetically; the
framework orders them by hand, each with a comment saying what it is for. Both let a brief
if go without braces; the framework writes every guard that way, if (!ready)
return;, and switches off readability-braces-around-statements, which would
refuse it. All of it is
.clang-format, which rmp fmt applies; Formatting
has each setting.
Google names a source file .cc. The framework's are .cpp, and so are a
game's, from the src/main.cpp that rmp new writes.
Google
recommends const in APIs and says const on a local variable is "neither
encouraged nor discouraged". The framework requires it on every local that does not change, so the
value at the bottom of a function is known, at its declaration, to be the one at the top. On a
by-value parameter the two agree that const stays out of the declaration, where it
means nothing to the caller. Google's guide says nothing of the definition; the framework puts it
there. Checked by misc-const-correctness, in the framework and the
examples. const has the rest.
Google also warns
against making a function harder to read so that it can be constexpr. The framework
asks for constexpr, consteval and constinit wherever they
apply. The two pull against each other only where making a function constexpr would
make it worse to read, and no tool checks either: it is a question for review.
Google
uses a pointer to say "this may be absent": a const T * for an optional input, a
T * for an optional output, a returned pointer when the result may be null. The
framework's rule allows no raw pointer outside the few places
Pointers and RAII names, most of them the C
libraries it is built on: a result that may be missing is a std::optional,
an optional input is a second overload, a reference that may be empty is an
rmp::Ref, and an object kept across frames is an
rmp::Handle. A pointer asks its reader whether it may be
null, who owns it and how long it lives, and its type answers none of the three. Checked by
custom-rmp-raw-pointer in the framework and the examples, and by
tools/pointer_check.py on every declaration a game can name.
Pointers and RAII has the replacements.
Each of these is a rule of Google's that the framework breaks on purpose, in a known place.
Google
does not allow <filesystem>. The framework uses it in two files:
src/rmp/app/app.cpp, to find the folder the executable is in, and
src/rmp/save/save.cpp, for the save folder and its files, and on Windows to turn the wide
paths the system hands back into UTF-8 and back. The standard library does both on every platform
the framework ships to, which nothing else the framework has would.
It
has one cost a game sees: Apple's C++ library has it only from iOS 13, so
tools/configure.py refuses an [ios] deployment_target below that. No tool
keeps it to those two files: a use anywhere else is a question for review.
Google's guide asks for C++20 and
no nonstandard extensions. The framework asks CMake for C++20 and leaves CMake's default for
extensions alone, so GCC and Clang compile with -std=gnu++20. Two builds use the
standard without GNU's extensions: the iOS project, which tools/configure.py writes,
asks for c++20, and
MSVC, which builds windows-arm64, has no GNU mode at all. The code compiles
under both.
The
framework's rule is no C variadic function (Modern
C++), and it has two, side by side: the functions behind its said-once warnings, which hand
a printf format to raylib's TraceLog(), one of them with a key. Each is
marked with a format(printf) attribute through a macro of the framework's internal
header, so GCC and Clang check every format against its values, as an error. That is the form in
which Google allows a nonstandard extension: a portability wrapper, defined once, in a header the
framework's sources share.
Google allows an
object with static storage duration only when its destructor does nothing, because destructors at
exit run in an order nobody chooses. The framework's file-scope state is a struct per concern, and
some of those hold vectors and strings. What they hold is released before the window closes, in
an order written down in src/rmp/app/app.cpp — scenes, then globals, then the interface's
font, then sounds, then everything left in the resource table — rather than by destructors at
exit.
Google
makes a class's data members private, and keeps struct for passive data.
rmp::Object is a class whose
position,
velocity and
shape are public fields, and every options struct
is public data. ball.position.x += 4; is
the simplest way to move a ball, and a setter would make it longer for nothing:
misc-non-private-member-variables-in-classes is switched off for that reason.
Google requires explicit on every one-argument constructor and conversion operator,
and grants a waiver for types designed to be interchangeable. The framework's API has a few such
conversions, each because the simple call would be longer without it, and each with a
NOLINT for google-explicit-constructor and its reason beside it:
bool, a number or a piece of text becomes an rmp::Value:
save["score"] = 3;;Value::Ref, what save["score"] gives, reads as the
Value it names;rmp::Texture, rmp::Font, rmp::Sound and the
rest — passes where raylib takes the plain struct, DrawTexture(logo, 0, 0, WHITE), from
a named handle only;rmp::Callback, so it can be written
straight into a behavior's options;rmp::ui::Size becomes the size of a control:
.size = 34 and .size = rmp::ui::Size::LARGE both read as what they mean.A new conversion in the API is refused by google-explicit-constructor until it is
given the same: a NOLINT and a reason someone reviewing it can accept.
Google
asks for a TODO with a name in brackets after it, so that it can be traced to someone. The framework has no
TODO at all: a comment says what is, and what is to be done goes in the plan, where somebody reads
it. Checked by rule S3 of tools/style_check.sh, which also refuses FIXME
and XXX, in the framework and the examples.
Google
starts every file with its licence. The framework's licence is the repository's
LICENSE, and the vendored libraries' are in THIRD_PARTY_LICENSES.md; a
file starts with what it is for, and why it is built the way it is.
Google
suggests thinking about splitting a function past about 40 lines, and sets no limit. The framework
sets none either: readability-function-cognitive-complexity is switched off, because a
render switch is one function on purpose.
Google
says not to design for shared ownership without a very good reason. A
rmp::Callback keeps the lambda it was given in a
std::shared_ptr<void>, and its ownership is still single — a
Callback cannot be copied. The shared_ptr is there because it carries the
lambda's deleter inside it, which erases the lambda's type with no delete of the
framework's and without <functional>.
Ownership has why not
std::function.
Google's first choice for converting one arithmetic type to another is braces,
std::int64_t{ x }, which refuse to compile a conversion that loses anything; the
framework writes static_cast, and braces where they apply. Google's advice for reading
one type's bits as another is std::bit_cast, which the oldest compiler a game is built
with does not have: copying the bytes with std::memcpy does the same, and compiles
there.
Modern C++ has both.
Google's
advice on using a macro to compile code conditionally is not to. A framework built from one source
for every platform cannot avoid it, and it is one of the four uses of a macro the framework
allows. What it costs is that a compiler, and clang-tidy, read only the branch of the machine they
run on, so the framework's text gates — tools/naming_check.sh and
tools/style_check.sh — read every branch.
Google: no macro defined in a
header, and none used to declare a piece of an API, without a waiver. rmp/app.h
defines RMP_GAME, the line that starts a game, because a
program's entry point is a different set of functions on each platform and only the preprocessor
can choose among them. It is named, with the framework's few other macros, in
cppcoreguidelines-macro-usage's list of allowed ones, and a new one is a question for
review. Macros has the rule.
| Google's rule | Checked by |
|---|---|
| No exceptions: the framework throws none, and catches the standard library's where it can throw (No exceptions) | a throw under src/rmp/ or include/rmp/: tests/campaign_test.py, in rmp test property; the catching: review |
| C++ casts, not C's | modernize-avoid-c-style-cast, and S1 of tools/style_check.sh |
nullptr, not NULL or 0 | modernize-use-nullptr, and S2 |
++i unless the old value is used | S6 |
| No user-defined literals | S5 |
int, and <cstdint>'s fixed widths | google-runtime-int |
float and double, never long double | google-runtime-float |
explicit conversions | google-explicit-constructor |
| No default argument on a virtual function | google-default-arguments |
| No using-directive | google-build-using-namespace |
| No unnamed namespace in a header | google-build-namespaces |
| No using-declaration at global scope in a header | google-global-names-in-headers |
No overloaded unary & | google-runtime-operator |
std::make_pair deduces its types | google-build-explicit-make-pair |
A namespace constant in a header has no internal linkage: it is inline constexpr | custom-rmp-header-constant |
Single owners; std::unique_ptr for what moves | cppcoreguidelines-owning-memory, cppcoreguidelines-no-malloc, and O1 of tools/ownership_check.sh |
| Designated initialisers only in C++20's order | the compiler, with -Werror=reorder-init-list under Clang |
| Type deduction where it makes the code clearer | modernize-use-auto, for a cast, in the framework; review for the rest |
RTTI in tests only: nothing in the framework uses dynamic_cast or typeid | review |
| No modules and no coroutines | review |
"S1", "S2", "S5" and "S6" are rules of tools/style_check.sh, the style
stage of rmp test. Every check in the table runs in the framework, and all but
modernize-use-auto, O1 and the test that looks for a throw in the
examples too; what checks
what has each one's exact reach.
https://omardev29.github.io/rmp-docs/guidelines/enforcement.html
A rule that only a document states lasts until the day somebody has not read the
document. So each rule on these pages names the tool that refuses its mistake, and this page puts
them in one table, with where each one holds: in the framework (its include/,
src/ and tests/), in its examples, and in a game made with
rmp new. The build of this site holds the table to the framework's own configuration,
so a check that is said to run runs.
rmp lint runs.clang-tidy over the sources of src/,
tests/ and examples/, and the headers they reach, with the flags each file
is built with. Whole families run — bugprone, clang-analyzer,
performance, portability, misc, modernize,
readability — minus what is switched off below, and the style guide's checks are named
one by one. Two of them are queries the framework writes itself, which
clang-tidy runs only with --experimental-custom-checks, and rmp lint
passes it.examples/.clang-tidymodernize and readability families, which
push a more elaborate spelling of correct code at someone learning raylib, and takes back the ones
that are rules of these pages. An example teaches the C++ a game should write.tools/lint_debt.txt, a count per check and
file. rmp lint fails on a warning the list does not owe and on a count that grew, and
the list only shrinks. A new warning is fixed, or carries a NOLINT with its reason on
the line.rmp test#if or because no
check of its says it: tools/naming_check.sh (rules R1 to R8, the naming
stage), tools/style_check.sh (S1 to S9, style),
tools/ownership_check.sh (O1 to O3, ownership),
tools/pointer_check.py, which reads the public headers' declarations
(pointers), and tools/cppcheck_check.sh, a second analyser over
src/rmp (cppcheck)..clang-format, which rmp fmt appliesrmp fmt formats and rmp fmt check refuses a file it would change, when the
game runs them: its rmp test and its CI do not.-Wall
-Wextra under GCC and Clang: the desktop and the web, and not Android's or iOS's own
projects. The framework's own checks build with RMP_WERROR,
which makes a warning an error; a game's warnings stay warnings unless it asks for the same.
Designated initialisers out of order are an error everywhere."Yes" in a column says the rule is checked there; what follows it says how far. A game gets
.clang-format and the compiler's flags: rmp lint and the text gates are
commands of the framework's own repository, and a game chooses its own checks.
| Rule | Checked by | Framework | Examples | A game |
|---|---|---|---|---|
| Names spelled by kind: types, constants, functions and variables, private members, the eight hooks | readability-identifier-naming | yes | yes | no |
| A local never hides a name around it | clang-diagnostic-shadow, which is -Wshadow given to clang-tidy | yes | yes | no |
No g_ name, no kName, no underscore touching a dot, no trailing underscore, in every branch | tools/naming_check.sh R1 R2 R3 R4 R8 | yes | yes | no |
Every macro starts with RMP_ | readability-identifier-naming; tools/naming_check.sh R5 in every branch | yes | yes | no |
| No constant named like somebody else's macro | tools/naming_check.sh R6 | yes | yes | no |
| No retired name | tools/naming_check.sh R7 | yes | yes | no |
The layout: 4 spaces, 90 columns, char *p, no alignment, includes in the order written | .clang-format | yes, in CI | yes, in CI | yes: rmp fmt formats and rmp fmt check refuses, when the game runs them |
const on every local that does not change, and on what a pointer points to when nothing writes through it | misc-const-correctness | yes | yes | no |
const on a by-value parameter in the definition, never the declaration | readability-avoid-const-params-in-decls, the declaration's half | yes | no: the examples switch readability off | no |
A constant at namespace scope in a header is inline constexpr | custom-rmp-header-constant | yes | yes, in their own headers | no |
| No raw pointer, outside the C libraries' boundary | custom-rmp-raw-pointer | yes, with what tools/lint_debt.txt owes | yes, with what tools/lint_debt.txt owes | no |
| No raw pointer and no C string in a declaration a game can name | tools/pointer_check.py, against tools/pointer_ratchet.txt | yes: include/rmp/ | no | no |
Nothing owned by hand: no new, delete, malloc or free | cppcoreguidelines-owning-memory, cppcoreguidelines-no-malloc; tools/ownership_check.sh O1 in include/rmp/ and src/rmp/ | yes | yes, the clang-tidy checks | no |
raylib's Load* and Unload* only in the files that own what they make | tools/ownership_check.sh O2 | yes: include/rmp/ and src/rmp/ | yes | no |
A std::optional is checked before it is read | bugprone-unchecked-optional-access | yes | yes | no |
A std::string_view never reaches a C function through data() | bugprone-suspicious-stringview-data-usage | yes | yes | no |
std::array, not a C array | modernize-avoid-c-arrays | yes | yes | no |
static_cast, never a C cast | modernize-avoid-c-style-cast; tools/style_check.sh S1 in every branch | yes | yes | no |
enum class | cppcoreguidelines-use-enum-class | yes | yes | no |
nullptr, never NULL or 0 | modernize-use-nullptr; tools/style_check.sh S2 in every branch | yes | yes | no |
| No C variadic function | modernize-avoid-variadic-functions | yes, but for the two behind the said-once warnings, each with its reason | yes | no |
int, and a fixed width when the size matters | google-runtime-int | yes | yes | no |
No long double | google-runtime-float | yes | yes | no |
A one-argument constructor is explicit | google-explicit-constructor | yes, but for the API's deliberate conversions | yes | no |
| A class that manages something says what its copies do | cppcoreguidelines-special-member-functions | yes | yes | no |
auto where a cast already names the type | modernize-use-auto | yes | no: the examples switch modernize off | no |
using, not typedef | modernize-use-using | yes | yes | no |
std::numbers, not a typed-in constant | modernize-use-std-numbers | yes | yes | no |
No using namespace | google-build-using-namespace | yes | yes | no |
| No unnamed namespace in a header | google-build-namespaces | yes | yes | no |
| No using-declaration at global scope in a header | google-global-names-in-headers | yes | yes | no |
No overloaded unary & | google-runtime-operator | yes | yes | no |
std::make_pair deduces its types | google-build-explicit-make-pair | yes | yes | no |
| No default argument on a virtual function | google-default-arguments | yes | yes | no |
++i where the old value is not read | tools/style_check.sh S6 | yes | yes | no |
| No user-defined literal | tools/style_check.sh S5 | yes | yes | no |
| Nothing newer than the oldest compiler a game is built with | tools/style_check.sh S4 | yes, but not in tests/, which build only on CI's compilers | yes | no |
No iostreams in the library: a file is read through C's stdio or raylib | tools/style_check.sh S8; one std::ifstream made every release a fifth bigger | yes: src/rmp/ and include/rmp/ | no | no |
No // comment that ends in a backslash: it takes the next line with it | tools/style_check.sh S9; GCC warns about it, Clang and clang-tidy never do | yes | yes | no |
| cute_aseprite reads only what the framework walked first | tools/ownership_check.sh O3: its two loads only in src/rmp/assets/animation.cpp | yes | yes | no |
No TODO, FIXME or XXX | tools/style_check.sh S3 | yes | yes | no |
| Designated initialisers in declaration order | -Werror=reorder-init-list under Clang; GCC and MSVC refuse them anyway | yes | yes | yes |
| A macro only for what a function cannot do | cppcoreguidelines-macro-usage, told the framework's own by name | yes | yes | no |
| No finding of a second analyser, and a reason beside every suppression | tools/cppcheck_check.sh | yes: src/rmp/ | no | no |
| Warnings on the code we write | -Wall -Wextra | yes, as errors in the framework's checks | yes | yes, as warnings |
Some rules have no tool that can tell the right way from the wrong one. They are questions a reviewer asks:
const on a by-value
parameter in a definition — clang-tidy does not look at parameters — and constexpr,
consteval and constinit wherever they apply (const);std::array given a size larger than its list, whose rest is filled with zeros
(Modern C++);auto beyond a cast
(Modern C++);#pragma once at the top of a header, and <filesystem> in
src/rmp/app/app.cpp and src/rmp/save/save.cpp only
(Google's guide);Each check the framework's .clang-tidy switches off fights a decision the framework
has already made, and the file says which next to it. In the same words:
| Check | Why it is off |
|---|---|
bugprone-easily-swappable-parameters | Every (float x, float y) in a 2D framework, which is all of them. |
bugprone-narrowing-conversions | float and int mixing is what raylib's own API does; the static analyser catches the cases that lose data. |
misc-non-private-member-variables-in-classes | The options structs and rmp::Object are public data by design (Google's guide). |
misc-no-recursion | The layout walk is a tree walk. |
misc-include-cleaner | It wants an #include for every raylib symbol, and raylib is one header. |
misc-use-anonymous-namespace, misc-use-internal-linkage | static at file scope is the deliberate spelling: main.cpp is the file a newcomer reads first, and it has a plain C twin among the examples, so the two keep the same shape. Google allows either. |
modernize-use-trailing-return-type | auto f() -> int is not the style, nor Google's. |
modernize-use-nodiscard | It would decorate the whole API for the few calls where it matters. |
modernize-macro-to-enum | The values the .toml generates are macros on purpose: the C entry point reads them too (Macros). |
modernize-use-designated-initializers | It suggests them inside the framework's implementation, where the field order is Clay's, not the framework's. |
portability-avoid-pragma-once | #pragma once is the framework's decision, and every compiler it builds with supports it (Google's guide). |
performance-enum-size | Pinning an underlying type on a public enum is churn in the ABI for bytes nobody is short of. |
readability-redundant-member-init | In an options struct every field shows its default, even where the default is what the type would give anyway, and one field that does not is worse. |
readability-use-std-min-max | The explicit if (dt > 0.1f) clamps are written that way, with a comment saying why the bound is what it is. |
readability-use-concise-preprocessor-directives | #if defined(A) || defined(B) and #if defined(A) are written the same way on purpose. |
readability-identifier-length | dt, t and o are the vocabulary. |
readability-magic-numbers | It is a game, and a touch target is a number: 44. |
readability-braces-around-statements | A guard on one line is the style, and .clang-format is set to keep it there (Google's guide). |
readability-implicit-bool-conversion | raylib returns int for booleans. |
readability-function-cognitive-complexity | A render switch is one function on purpose (Google's guide). |
readability-uppercase-literal-suffix | 1.0f, not 1.0F. |
readability-avoid-nested-conditional-operator, readability-math-missing-parentheses | Switched off with the others; .clang-tidy gives no reason beside them. |
And for the examples,
examples/.clang-tidy switches off misc-unused-parameters: a hook takes
float delta whether this example's _update uses it or not, and the
signature is the API's. It keeps readability-identifier-naming,
readability-misleading-indentation and readability-misplaced-array-index
from the family it switches off, and these six from modernize, each a rule of these
pages: modernize-avoid-c-arrays, modernize-avoid-c-style-cast,
modernize-use-nullptr, modernize-avoid-variadic-functions,
modernize-use-std-numbers and modernize-use-using.
A rule that arrives after the code it judges finds the code breaking it. The framework writes
that down instead of switching the rule off, and each list only shrinks: what clang-tidy still
finds is tools/lint_debt.txt; the pointers left in its headers, each with its reason,
are tools/pointer_ratchet.txt; the files allowed to own memory or raylib resources by
hand, each with its reason, are in tools/ownership_check.sh; and what cppcheck may not
say, each with its reason, is in tools/cppcheck_check.sh or on the line itself.
A game made with rmp new gets the formatter, rmp fmt, and the compiler's
flags, which hold its designated initialisers to their order. None of the rest runs on its code:
the rules are the advice the framework follows, and a game that wants to read like it can follow
them too, and can switch the framework's
clang-tidy on for its own code. What a game gets
says the same from the game's side.
https://omardev29.github.io/rmp-docs/index.html
A C++20 framework for shipping raylib games to 17 targets from one codebase — Windows, Linux, macOS, the web, Android, iOS and the three BSDs — with CI that builds every one of them and, on each one its runners can run, boots the game and checks that it put pixels on the screen.
You write the game. A main menu is three calls:
rmp::ui::begin();
if (rmp::ui::button("Play")) play();
if (rmp::ui::button("Quit")) quit();
rmp::ui::end();That is a centred, responsive menu that a mouse, a keyboard, a gamepad and a finger can all use. No coordinates, no sizes, no fonts to load. Everything else the framework has is there when that default is not what you want, and costs nothing until then.
Underneath, it is raylib, and raylib stays yours: inside a scene you call
DrawTexture, DrawCircle or BeginMode2D exactly as you
would without the framework. What the framework adds lives under rmp::, one header
per module, and a game includes only the ones it uses.