# raylib_multiplatform: the whole documentation, in reading order ============================================================================== # Getting started > Install the rmp command once, make a game with it, run it, and then build that game up one page at a time. Source: 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. ## What you need - **Python 3.11** or newer, **CMake 3.30** or newer and **Ninja** on your PATH, and a C++ compiler. A Linux distribution's own `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. - **git**, to get the framework and to keep your game in. - On a Linux desktop, the X11 development libraries. ### On Linux, in one command 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** ```shell sudo apt install build-essential cmake ninja-build python3 git \ libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev libgl1-mesa-dev ``` Ubuntu 24.04's `cmake` is 3.28; take a newer one from Kitware's own apt repository, or `pipx install cmake`. **Fedora** ```shell sudo dnf install gcc-c++ cmake ninja-build python3 git \ libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa-libGL-devel ``` **Arch** ```shell sudo pacman -S --needed base-devel cmake ninja python git \ libx11 libxrandr libxi libxcursor libxinerama mesa ``` **Alpine**, 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`: ```shell doas apk add build-base cmake samurai python3 git linux-headers \ libx11-dev libxrandr-dev libxi-dev libxcursor-dev libxinerama-dev mesa-dev ``` Or install nothing on the machine at all, and work inside the image CI builds in: [In the build image, with Podman](https://omardev29.github.io/rmp-docs/getting-started/install.html#in-the-build-image). 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) says which, and how the game reaches the screen. ## Install rmp One line, in a terminal. On Linux and macOS: ```shell curl -fsSL https://omardev29.github.io/rmp-docs/install.sh | sh ``` On Windows, in PowerShell: ```powershell irm https://omardev29.github.io/rmp-docs/install.ps1 | iex ``` It 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](https://omardev29.github.io/rmp-docs/getting-started/install.html) 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: ```shell rmp help ``` ## Make a game ```shell rmp new my_game cd my_game rmp run ``` `rmp 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`: ```shell git commit -m "New game" ``` ## What is yours 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 tutorial 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. 1. [Your first scene](https://omardev29.github.io/rmp-docs/getting-started/your-first-scene.html): a menu of your own, and a second screen to go to. 2. [A player](https://omardev29.github.io/rmp-docs/getting-started/a-player.html): an object that moves with the keyboard, a gamepad, the mouse or a finger. 3. [Coins and bats](https://omardev29.github.io/rmp-docs/getting-started/coins-and-bats.html): something to collect, something to avoid, and a game over. 4. [A pause menu](https://omardev29.github.io/rmp-docs/getting-started/a-pause-menu.html): a scene on top of the game. 5. [Art and sound](https://omardev29.github.io/rmp-docs/getting-started/art-and-sound.html): pictures and sounds, loaded by name. 6. [Saving a record](https://omardev29.github.io/rmp-docs/getting-started/saving-a-record.html): the best score, kept between sessions. 7. [Ship it](https://omardev29.github.io/rmp-docs/getting-started/ship-it.html): real app ids, the checks, and a release built for every platform. ============================================================================== # Install rmp > One line in a terminal puts rmp on your PATH, on Linux, macOS, the BSDs and Windows: what each line runs, where it puts things, how to update it, and how to remove it. Source: 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. ## The line On Linux and macOS: ```shell curl -fsSL https://omardev29.github.io/rmp-docs/install.sh | sh ``` The same script, fetched with what each system has. None of the three BSDs has `curl` in its base system: ```shell 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, NetBSD ``` On Windows, in PowerShell — Windows PowerShell 5.1 or PowerShell 7: ```powershell irm https://omardev29.github.io/rmp-docs/install.ps1 | iex ``` Then open a new terminal and check: ```shell rmp help ``` A 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](https://omardev29.github.io/rmp-docs/install.sh) and [install.ps1](https://omardev29.github.io/rmp-docs/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. ## What it needs 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) has the packages for each system, and what comes after. ## Where it puts things | | 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. ## Running it again, and updating 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: ```shell rmp update ``` It 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](https://omardev29.github.io/rmp-docs/manual/basics/the-rmp-command.html#a-game-keeps-its-own-rmp) explains why. ## From a clone of your own 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: ```shell git clone https://github.com/omardev29/raylib_multiplatform ~/raylib_multiplatform ~/raylib_multiplatform/rmp install ``` On 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. ## In your editor 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. ## In the build image, with Podman 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: ```shell 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-dev ``` That 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`: ```shell ./rmp build ./rmp test ./rmp build windows ``` A 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. ## In a container, nothing installed 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. ## Uninstalling Nothing is installed anywhere else, so removing it is deleting what the table above lists. On Linux, macOS and the BSDs: ```shell rm ~/.local/bin/rmp rm -rf ~/.local/share/rmp ``` and, 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/index.html#make-a-game). ============================================================================== # Your first scene > Replace the menu rmp new made with one of your own, a title with Play and Quit, and add the scene that Play goes to. Source: 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. ## Where the game starts Open `src/main.cpp`. You will not change it in this tutorial, and it is worth reading once: [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/src/main.cpp#L1-L13) ```cpp // 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 #include "scenes/main_menu.h" RMP_GAME(MainMenuScene); ``` [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#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. ## Name the game `rmp new` named the window after the folder. Give the game its real name in `raylib_multiplatform.toml`, under `[window]`: raylib_multiplatform.toml ```toml [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. ## The menu A scene is a class that derives from [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html) and overrides the hooks it needs. Replace the whole of the template's menu, header first: src/scenes/main_menu.h ```cpp #pragma once // The title screen: the game's name, Play and Quit. #include class MainMenuScene : public rmp::Scene { public: void _draw() override; }; ``` The menu needs one hook, [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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`: src/scenes/main_menu.cpp ```cpp #include "main_menu.h" #include "game.h" #include #include 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(); } #if !defined(PLATFORM_IOS) if (rmp::ui::button("Quit")) rmp::app::quit(); #endif rmp::ui::end(); } ``` Everything between [`rmp::ui::begin()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#begin) and [`rmp::ui::end()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#change) 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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 menu's test 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: tests/game/main_menu_test.cpp ```cpp // 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 #include #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](https://omardev29.github.io/rmp-docs/framework/testing.html#game-tests) has the rest. ## A second scene Play goes to `GameScene`, which does not exist yet. Make two new files in `src/scenes/`, a header and its code: src/scenes/game.h ```cpp #pragma once // The game. For now, a screen that says so and a way back. #include class GameScene : public rmp::Scene { public: void _draw() override; }; ``` src/scenes/game.cpp ```cpp #include "game.h" #include "main_menu.h" #include void GameScene::_draw() { rmp::ui::begin(); rmp::ui::text("The game goes here."); if (rmp::ui::button("Back")) rmp::Scene::change(); rmp::ui::end(); } ``` The game has nothing in it yet: a line of text, and a way back. Each scene's header includes only ``; 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. ## The hooks 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_ready) | Once, when the scene starts. The window exists by then, so this is where a scene loads what it needs. | | [`_update(float delta)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_update) | Every frame, before anything is drawn. `delta` is the seconds since the last frame. | | [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_draw) | Every frame, after the scene's objects have been drawn, in screen space. | | [`_suspend()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_suspend) and [`_resume()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_resume) | When another scene is put on top of this one, and when it comes off again. | | [`_end()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_end) | Once, when the scene ends for good. | The [Scenes](https://omardev29.github.io/rmp-docs/manual/core/scenes.html) chapter of the manual has the rest: the stack of scenes, and passing data from one to the next. The [Interface](https://omardev29.github.io/rmp-docs/manual/modules/ui.html) chapter has the rest of `rmp::ui`. ## Run it ```shell rmp run ``` The 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. The menu after this page, built from its code. ============================================================================== # A player > Put a player in the game scene, an object moved by a behavior from the catalogue, by the mouse or a finger, and by the input actions it reads. Source: 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. ## An object 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: src/objects/player.h ```cpp #pragma once // The rabbit: what it looks like, what it collides as, and how it moves. #include class Player : public rmp::Object { public: void _ready() override; void _update(float delta) override; }; ``` src/objects/player.cpp ```cpp #include "player.h" #include #include #include 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({ .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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) is mostly public fields that you read and write directly: [`position`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#position), [`velocity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#velocity), [`shape`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_ready) runs once, as soon as the object is in its scene; [`_update()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_update) runs every frame. ### A behavior 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/TopDown.html). 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#add): `get()->speed = 400` would be a power-up. ### The mouse, or a finger `_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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer_down) is the mouse button, or a finger, held down. - [`rmp::input::consumed_pointer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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 `` 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. ## Actions `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: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#just_pressed), 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) when that key is pressed. ## The game scene The game scene now has a player in it instead of the text. Replace both of its files: src/scenes/game.h ```cpp #pragma once // The game: the player, in an arena the size of the design resolution. #include class GameScene : public rmp::Scene { public: void _ready() override; void _update(float delta) override; }; ``` src/scenes/game.cpp ```cpp #include "game.h" #include "../objects/player.h" #include "main_menu.h" #include 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({ .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(); } ``` [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#background) is the colour the frame is cleared with. There is no pause menu yet, so for now `pause` goes back to the menu. ## Run it ```shell rmp run ``` Play, 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 game after this page, built from its code and started in its game scene. The manual has a chapter for each thing this page touched: [Objects](https://omardev29.github.io/rmp-docs/manual/core/objects.html), [Behaviors](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html), [Input](https://omardev29.github.io/rmp-docs/manual/modules/input.html) and the [Camera](https://omardev29.github.io/rmp-docs/manual/core/camera.html). ============================================================================== # Coins and bats > Something to collect and something to avoid: objects spawned at random, collision layers, a behavior that chases, lives, and a game over scene pushed on top of the game. Source: 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. ## Who collides with whom 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: src/objects/layers.h ```cpp #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 layer ``` Each object has two of these numbers: [`collision_layer`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collision_layer) is what it is, and [`collision_mask`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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: src/objects/player.cpp ```cpp #include "player.h" #include "layers.h" #include #include #include 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({ .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](https://omardev29.github.io/rmp-docs/manual/core/collision.html) chapter of the manual has the rest: solid objects that push each other apart, and the edges of the world. ## The game scene 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: src/scenes/game.h ```cpp #pragma once // The game: the rabbit, the coins and the bats, in an arena the size of the // design resolution. #include 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 _player; // kept across frames, so a handle int _coins = 0; float _next_bat = 1; // seconds until the next bat comes }; ``` src/scenes/game.cpp ```cpp #include "game.h" #include "../objects/layers.h" #include "../objects/player.h" #include "game_over.h" #include "main_menu.h" #include #include #include #include #include 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({ .position = { ARENA.width / 2, ARENA.height / 2 }, .edges = rmp::Edge::CLAMP, .bounds = ARENA, }); player.add({ .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(); _next_bat -= delta; if (_next_bat <= 0) { spawn_bat(); _next_bat = SECONDS_PER_BAT; } } void GameScene::_draw() { const int lives = _player->get()->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({ .target = _player, .speed = rmp::random::range(70.0f, 120.0f), }); } void GameScene::caught() { rmp::Scene::push(_coins); } ``` ### Coins A coin needs no class of its own: it is a plain [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html), which is what [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) makes when it is not given a type. Its shape is a gold circle, made with [`rmp::circle()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#circle), and it goes somewhere random in the arena: [`rmp::random::range()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_collision), which runs when the coin touches something its layers allow, and that can only be the player: - [`self.destroy()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ### Bats A bat starts just outside the arena, above it or below it, which [`rmp::random::chance(0.5f)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#chance) decides. It chases the player with another behavior from the catalogue, [`rmp::behavior::Follow`](https://omardev29.github.io/rmp-docs/reference/behaviors/Follow.html), 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) made by [`player.handle()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ### Lives The player gets a second behavior, [`rmp::behavior::Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html), 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html#hurt_by) says what costs one: touching anything on the bats' layer. - After a bite the player cannot be bitten again for 0.6 seconds, `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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html#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. ### The score `_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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Align), and a [`row`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get). The scene draws its interface after its objects, so the score is always on top of the game. ## Game over 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/`: src/scenes/game_over.h ```cpp #pragma once // Pushed on top of the game when the rabbit is caught. The game stays on // screen, frozen, underneath. #include class GameOverScene : public rmp::Scene { public: explicit GameOverScene(int coins) : _coins(coins) {} void _draw() override; private: int _coins; }; ``` src/scenes/game_over.cpp ```cpp #include "game_over.h" #include "game.h" #include "main_menu.h" #include #include 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(); } if (rmp::ui::button("Menu")) rmp::Scene::change(); rmp::ui::end(); } ``` [`rmp::Scene::push(_coins)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#push) 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()`, 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. ## Run it ```shell rmp run ``` Gather 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. The game after this page, built from its code and started in its game scene. ============================================================================== # A pause menu > Pause the game by pushing a scene on top of it, see what the scene stack's defaults freeze, and give phones a button to pause with. Source: 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. ## The pause scene Two new files in `src/scenes/`: src/scenes/pause.h ```cpp #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 class PauseScene : public rmp::Scene { public: void _update(float delta) override; void _draw() override; }; ``` src/scenes/pause.cpp ```cpp #include "pause.h" #include "main_menu.h" #include #include 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(); rmp::ui::end(); } ``` [`rmp::Scene::pop()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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()`, 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. ## What a scene lets through 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#updates_below) | `false` | The scene below keeps running. | | [`draws_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#draws_below) | `true` | The scene below stays on screen. | | [`input_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. ## Pausing 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: src/scenes/game.cpp ```cpp #include "game.h" #include "../objects/layers.h" #include "../objects/player.h" #include "game_over.h" #include "pause.h" #include #include #include #include #include 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({ .position = { ARENA.width / 2, ARENA.height / 2 }, .edges = rmp::Edge::CLAMP, .bounds = ARENA, }); player.add({ .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(); _next_bat -= delta; if (_next_bat <= 0) { spawn_bat(); _next_bat = SECONDS_PER_BAT; } } void GameScene::_draw() { const int lives = _player->get()->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(); } #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({ .target = _player, .speed = rmp::random::range(70.0f, 120.0f), }); } void GameScene::caught() { rmp::Scene::push(_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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#a-button-in-the-hud) 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. ## Run it ```shell rmp run ``` P, Escape or the gamepad's Start button pauses, and the same key resumes. Resume does too, and Menu leaves the game. ============================================================================== # Art and sound > Give the rabbit, the coins and the bats pictures and sounds copied from the framework's examples, loaded by name from resources/, and see what a release does with that folder. Source: 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. ## The files Run these from the game's folder. They copy from the framework you cloned into your home folder when you installed `rmp`: resources/coin.aseprite ```shell cp ~/raylib_multiplatform/examples/games/07_platformer/resources/coin.aseprite resources/ ``` resources/bat.aseprite ```shell cp ~/raylib_multiplatform/examples/games/07_platformer/resources/bat.aseprite resources/ ``` resources/coin.ogg ```shell cp ~/raylib_multiplatform/examples/games/07_platformer/resources/coin.ogg resources/ ``` resources/hurt.ogg ```shell cp ~/raylib_multiplatform/examples/games/07_platformer/resources/hurt.ogg resources/ ``` resources/music.ogg ```shell 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. ## A picture for the rabbit The player gets its picture in place of the white box, in its `_ready()`. Replace the player's code: src/objects/player.cpp ```cpp #include "player.h" #include "layers.h" #include #include #include #include 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({ .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")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_texture) 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ## Coins that spin, bats that flap 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: src/scenes/game.cpp ```cpp #include "game.h" #include "../objects/layers.h" #include "../objects/player.h" #include "game_over.h" #include "pause.h" #include #include #include #include #include #include #include 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({ .position = { ARENA.width / 2, ARENA.height / 2 }, .edges = rmp::Edge::CLAMP, .bounds = ARENA, }); player.add({ .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(); _next_bat -= delta; if (_next_bat <= 0) { spawn_bat(); _next_bat = SECONDS_PER_BAT; } } void GameScene::_draw() { const int lives = _player->get()->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(); } #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({ .target = _player, .speed = rmp::random::range(70.0f, 120.0f), }); } void GameScene::caught() { rmp::Scene::push(_coins); } ``` [`rmp::assets::load_sheet()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#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")`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#play) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#scale) applies to what the object collides as as well, so the bigger bat bites from where it is drawn. ## Sound [`rmp::audio::play("coin")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#play) 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. ### Music The music starts with the menu, so the menu gets a `_ready()`. Replace both of its files: src/scenes/main_menu.h ```cpp #pragma once // The title screen: the game's name, Play and Quit. #include class MainMenuScene : public rmp::Scene { public: void _ready() override; void _draw() override; }; ``` src/scenes/main_menu.cpp ```cpp #include "main_menu.h" #include "game.h" #include #include #include 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(); } #if !defined(PLATFORM_IOS) if (rmp::ui::button("Quit")) rmp::app::quit(); #endif rmp::ui::end(); } ``` [`rmp::audio::music("music")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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. ## resources/ in a release 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: ```shell rmp pack rmp run rmp unpack ``` `rmp 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. ## Run it ```shell rmp run ``` Music on the menu, a rabbit in the arena, and spinning coins and flapping bats, each with its sound. The [Sprites](https://omardev29.github.io/rmp-docs/manual/modules/sprites.html), [Assets](https://omardev29.github.io/rmp-docs/manual/modules/assets.html) and [Audio](https://omardev29.github.io/rmp-docs/manual/modules/audio.html) chapters of the manual go further into each. The game after this page, built from its code and started in its game scene. ============================================================================== # Saving a record > Keep the best score between sessions with rmp::save and rmp::Value, and show it on the menu and on the game over screen. Source: 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. ## The record 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`: src/record.h ```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); ``` src/record.cpp ```cpp #include "record.h" #include #include 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html): 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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](https://omardev29.github.io/rmp-docs/manual/modules/saving.html) chapter of the manual shows how to tell them apart. ## Keeping it 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: src/scenes/game.cpp ```cpp #include "game.h" #include "../objects/layers.h" #include "../objects/player.h" #include "../record.h" #include "game_over.h" #include "pause.h" #include #include #include #include #include #include #include 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({ .position = { ARENA.width / 2, ARENA.height / 2 }, .edges = rmp::Edge::CLAMP, .bounds = ARENA, }); player.add({ .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(); _next_bat -= delta; if (_next_bat <= 0) { spawn_bat(); _next_bat = SECONDS_PER_BAT; } } void GameScene::_draw() { const int lives = _player->get()->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(); } #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({ .target = _player, .speed = rmp::random::range(70.0f, 120.0f), }); } void GameScene::caught() { const bool record = keep_if_best(_coins); rmp::Scene::push(_coins, record); } ``` The game over scene takes a second argument, and says so when there is a new best: src/scenes/game_over.h ```cpp #pragma once // Pushed on top of the game when the rabbit is caught. The game stays on // screen, frozen, underneath. #include class GameOverScene : public rmp::Scene { public: GameOverScene(int coins, bool record) : _coins(coins), _record(record) {} void _draw() override; private: int _coins; bool _record; }; ``` src/scenes/game_over.cpp ```cpp #include "game_over.h" #include "game.h" #include "main_menu.h" #include #include 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(); } if (rmp::ui::button("Menu")) rmp::Scene::change(); rmp::ui::end(); } ``` ## Showing it The menu shows the record under the title, once there is one: src/scenes/main_menu.h ```cpp #pragma once // The title screen: the game's name, the best score, Play and Quit. #include class MainMenuScene : public rmp::Scene { public: void _ready() override; void _draw() override; private: int _best = 0; // read once, when the menu opens }; ``` src/scenes/main_menu.cpp ```cpp #include "main_menu.h" #include "../record.h" #include "game.h" #include #include #include #include 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(); } #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. ## Where it goes 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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. ## Run it ```shell rmp run ``` Gather 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. ============================================================================== # Ship it > Give the game its real app ids, run the checks CI runs, put it on GitHub, and tag a release that CI builds for every platform. Source: 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. ## Real app ids `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`: raylib_multiplatform.toml ```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: ```toml [android] application_id = "com.yourname.coin-rabbit" ``` ```text 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. ## Check it ```shell rmp test ``` In 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](https://omardev29.github.io/rmp-docs/getting-started/your-first-scene.html) — 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`. ## Put it on GitHub 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: ```shell git add -A git commit -m "Coin Rabbit" git remote add origin https://github.com/yourname/my_game.git rmp push ``` A 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`](https://omardev29.github.io/rmp-docs/publishing/ci.html#on-push), stops them: a push then starts nothing, a release tag still builds everything, and `rmp push` has no run to look for. ## Release ```shell rmp deploy 1.0.0 ``` `rmp 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](https://omardev29.github.io/rmp-docs/publishing/index.html) section has that, and everything else about where each build goes: [releases and versions](https://omardev29.github.io/rmp-docs/publishing/releases.html), [itch.io](https://omardev29.github.io/rmp-docs/publishing/itch.html), [Google Play](https://omardev29.github.io/rmp-docs/publishing/google-play.html) and [the App Store](https://omardev29.github.io/rmp-docs/publishing/app-store.html). ## What next The game you built uses most of what the framework has: scenes, objects, behaviors, input, the interface, assets, audio and saving. The [Manual](https://omardev29.github.io/rmp-docs/manual/index.html) takes each of them further, and the [Examples](https://omardev29.github.io/rmp-docs/examples/index.html) are whole games to read, from Pong to a platformer whose levels are made in an editor. ============================================================================== # Manual > Every part of the framework, explained by what it is for, with the reasons it works the way it does. Source: 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](https://omardev29.github.io/rmp-docs/reference/index.html) lists every name; this is where they are put together. It starts with the core every game uses — the app, [scenes](https://omardev29.github.io/rmp-docs/manual/core/scenes.html), objects — and goes on to the modules a game takes when it needs them. ============================================================================== # Basics > What a game made with the framework is before any of its code runs: the folder, the config file, the command that builds it, and the headers it includes. Source: 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. - [Project layout](https://omardev29.github.io/rmp-docs/manual/basics/project-layout.html) — what `rmp new` puts in a game's folder, which parts you edit and which belong to the framework, and what the build generates. - [Configuration](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html) — `raylib_multiplatform.toml`: the one file that drives CMake, Gradle and Xcode, and what happens when a value in it is wrong. - [The rmp command](https://omardev29.github.io/rmp-docs/manual/basics/the-rmp-command.html) — building, running, testing and shipping a game from one command, on every shell. - [Headers](https://omardev29.github.io/rmp-docs/manual/basics/headers.html) — one header per module, no umbrella, and the `RMP_` values every header carries from the config. When the folder builds and runs, the [core](https://omardev29.github.io/rmp-docs/manual/core/index.html) is next: the app, the scenes it moves between and the objects in them. ============================================================================== # Project layout > What a game made with rmp new contains, which parts of it are yours and which are the framework's, and what the build generates and never commits. Source: 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. ## Making a game ```shell rmp new my_game # makes my_game/, here cd my_game rmp run # build it and play it ``` The 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: - Sets the store identities to placeholders built from the name: `[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. - Gives `[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. - Starts the game without ads and on OpenGL ES 2.0: `[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. - Writes a short `README.md` for the game, which says which parts of the folder are the game's. - Makes it a git repository on a branch called `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. - Runs the new game's own `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. ### What a new game gets The copy is an explicit list, not "everything except". `rmp new --list` prints it, one path per line, without making anything: ```shell rmp new --list ``` A 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](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#tcc)). And it gets the [development container](https://omardev29.github.io/rmp-docs/getting-started/install.html#in-a-container), so it can be opened in one with nothing installed. ## The folder This is the top of a new game. The comments say whose each entry is. ```text 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) ``` ### What is yours | 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](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html). | | `src/main.cpp` | The entry point: one line, `RMP_GAME(MainMenuScene);`, naming the first scene. See [The app](https://omardev29.github.io/rmp-docs/manual/core/app.html). | | `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](https://omardev29.github.io/rmp-docs/framework/testing.html#game-tests). | ### What is the framework's 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](https://omardev29.github.io/rmp-docs/manual/basics/the-rmp-command.html#a-game-keeps-its-own-rmp) 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](https://omardev29.github.io/rmp-docs/examples/index.html), each one a small game of its own that can be read and copied from. ## Every file under src/ is compiled 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 ``, the ads as C functions, which do nothing off Android. [Plain C](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html) 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. ## resources/ 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](https://omardev29.github.io/rmp-docs/manual/modules/assets.html) has the whole of loading, and [the loading example](https://omardev29.github.io/rmp-docs/examples/assets/01_loading.html) 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](https://omardev29.github.io/rmp-docs/manual/core/app.html#where-a-release-finds-its-files) 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/ `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. ## What the build generates 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](https://omardev29.github.io/rmp-docs/manual/basics/headers.html#rmp-config-h). | | `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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html), `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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ci-on_push). [Continuous integration](https://omardev29.github.io/rmp-docs/publishing/ci.html#when-it-runs) 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. ============================================================================== # Configuration > raylib_multiplatform.toml is the one file that says what the game is called, how it opens and where it ships, and every build system is generated from it. Source: 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](https://omardev29.github.io/rmp-docs/reference/configuration.html). ## One file for every build system 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](https://omardev29.github.io/rmp-docs/manual/basics/project-layout.html#what-the-build-generates). ### When it runs 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. ## How a key is read 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`: raylib_multiplatform.toml ```toml [window] title = "Space Rocks" # this is [window] title width = 1280 # and this is [window] width height = 720 ``` The 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: ```toml [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](https://omardev29.github.io/rmp-docs/manual/basics/project-layout.html#making-a-game). ### Reading a value in your code 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: ```cpp const float centre_x = RMP_WINDOW_WIDTH / 2.0f; // [window] width TraceLog(LOG_INFO, "%s starting", RMP_PROJECT_NAME); // [project] name ``` They 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](https://omardev29.github.io/rmp-docs/manual/basics/headers.html#rmp-config-h) explains the file, and the [macros reference](https://omardev29.github.io/rmp-docs/reference/macros.html#from-the-toml) lists every one with the key it comes from. ## A wrong value stops the build at once 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: ```toml [window] titel = "Space Rocks" ``` ```text raylib_multiplatform.toml:2: titel = "Space Rocks" ^^^^^^^^^^^^^^^^^^^^^ configure: error: unknown key [window.titel] in raylib_multiplatform.toml ``` Every 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: ```toml [targets] enabled = "all" ``` ```text 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: ```toml [window] orientation = ["landscape"] ``` ```text 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: ```toml [window] title = "" ``` ```text 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: ```toml [window] fps = 15 ``` ```text 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. ## What is not in it **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. ## The sections 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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-targets) | Which platforms the game is built for, by group or by exact id. | | [`[android]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-android), [`[ios]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-android-display), [`[android.permissions]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-android-permissions), [`[android.features]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html). | | [`[icon]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-icon) | The picture the Android, iOS and Windows icons are made from, and the colour behind Android's adaptive icon. | | [`[app]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-ui) | The theme, font, font size and scale [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) starts with, and the ceiling on its layout tree. | | [`[input]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-input) | The analogue stick's dead zone. See [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html). | | [`[audio]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-audio) | The volumes the three buses of [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) start at. | | [`[save]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-save) | Where [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) puts the saves, whether they are sealed by default, and the version of your save format. | | [`[resources]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-resources) | The password the asset pack is encrypted with. | | [`[raylib]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-raylib) | raylib modules a game does not use, left out to shrink the binary. | | [`[web]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-web) | The browser build's memory, whether it may grow, and which layer raylib talks to. | | [`[linux]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-linux), [`[windows]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-upx) | Which shipped binaries are compressed with UPX. A target that cannot be compressed is refused by name, with the reason. | | [`[dev]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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](https://omardev29.github.io/rmp-docs/publishing/ci.html#on-push). | | [`[deploy]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-deploy), [`[deploy.itch]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-deploy-itch), [`[deploy.firebase]`](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-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] and [window] `[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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) lays a menu out at before scaling it to the real window, and the area the [camera](https://omardev29.github.io/rmp-docs/manual/core/camera.html) 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](https://omardev29.github.io/rmp-docs/manual/core/app.html#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. ### [targets] `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. ```toml [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] and [ios]: identities you cannot change `[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: what the game is compiled for `[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. ```toml [android] gl_version = "ES31" ``` ```text 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. ``` ### [android.admob]: off until the game has an ad 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) 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: ```toml [android.admob] enabled = true app_id = "" ``` ```text 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]: debug builds, not the build that ships `[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. ### [dev] c_compiler: the C of a debug build, compiled by tcc 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. | ```toml [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. ### [dev] sanitize: a debug build that checks memory 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. raylib_multiplatform.toml ```toml [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--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: ```toml [dev] sanitize = ["thread"] ``` ```text 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. ============================================================================== # The rmp command > rmp builds, runs, tests and ships a game, and makes new ones: one Python file behind a launcher for every shell. Source: 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](https://omardev29.github.io/rmp-docs/reference/commands.html), which is read from `rmp help` itself. ## Getting it The installer gets the framework and puts `rmp` on your PATH, in one line: ```shell curl -fsSL https://omardev29.github.io/rmp-docs/install.sh | sh ``` ```powershell irm https://omardev29.github.io/rmp-docs/install.ps1 | iex ``` [Install rmp](https://omardev29.github.io/rmp-docs/getting-started/install.html) 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: ```shell ~/raylib_multiplatform/rmp install ``` Building a game also needs [Python](https://www.python.org/downloads/) 3.11 or newer, [CMake](https://cmake.org/), 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) names. The one command for each of Debian and Ubuntu, Fedora, Arch and Alpine is in [Getting started](https://omardev29.github.io/rmp-docs/getting-started/index.html#linux-packages), and [the build image](https://omardev29.github.io/rmp-docs/getting-started/install.html#in-the-build-image) needs none of them on your machine. ## The launchers 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).` ## Where it works `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. ### A game keeps its own rmp 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: ```shell RMP_NO_DELEGATE=1 rmp test ``` ## Every day ```shell rmp 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 explains one, with examples ``` ### rmp run and rmp build `rmp 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](https://omardev29.github.io/rmp-docs/manual/core/app.html#where-a-release-finds-its-files) 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 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) has the whole of it. ### rmp web and rmp android `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: ```shell rmp web python3 -m http.server 8000 --directory build/web ``` and then `localhost:8000/my_game.html` in the browser, with the game's name in place of `my_game`. [Web](https://omardev29.github.io/rmp-docs/manual/platforms/web.html) 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](https://omardev29.github.io/rmp-docs/manual/platforms/android.html) has the rest. ### rmp build windows and rmp run windows 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. ```shell 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 Wine ``` Microsoft'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 `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. ```shell 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, signed ``` `rmp 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: ```shell export ANDROID_KEYSTORE_FILE=~/keys/upload.jks export ANDROID_KEYSTORE_PASSWORD=... export ANDROID_KEY_ALIAS=upload export ANDROID_KEY_PASSWORD=... rmp package android ``` The 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](https://omardev29.github.io/rmp-docs/publishing/google-play.html) says how to make an upload key. ### rmp test `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](https://omardev29.github.io/rmp-docs/framework/testing.html#game-tests). | | `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`](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers) 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 `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 and rmp unpack `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 `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 and rmp deploy `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`](https://omardev29.github.io/rmp-docs/publishing/ci.html#on-push) 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 and rmp update `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](https://omardev29.github.io/rmp-docs/getting-started/install.html) explains them. ### rmp new and rmp help `rmp new my_game` makes a game; `rmp new --list` prints what a game gets without making one. [Project layout](https://omardev29.github.io/rmp-docs/manual/basics/project-layout.html#making-a-game) 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. ## What it answers with | 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. ## Without rmp Nothing in a game requires `rmp`: underneath, it is plain CMake with presets, and the `.toml` is applied by the configure step itself. ```shell cmake --preset debug # configures AND generates everything from the .toml cmake --build --preset debug ./build/debug/my_game ``` The 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. ============================================================================== # Headers > One header per module and no umbrella: what each of the framework's headers gives a game, and the RMP_ values every one of them carries from the config. Source: 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. ## Include what you use A file that draws the HUD includes `rmp/ui.h` and nothing else of the framework's: ```cpp #include #include 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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. ## The headers | Header | What it gives | Manual | |---|---|---| | `rmp/app.h` | The entry point — [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) and [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_ENTRY_POINT) — closing the app with [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit), and [`rmp::global()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global). Reference: [`rmp::app`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html). | [The app](https://omardev29.github.io/rmp-docs/manual/core/app.html) | | `rmp/scene.h` | [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html), the stack of scenes, spawning and raycasting, and [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html). | [Scenes](https://omardev29.github.io/rmp-docs/manual/core/scenes.html), [Camera](https://omardev29.github.io/rmp-docs/manual/core/camera.html) | | `rmp/object.h` | [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html), [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html), [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html), [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html), the shapes, the edges and the ray queries. | [Objects](https://omardev29.github.io/rmp-docs/manual/core/objects.html), [Collision](https://omardev29.github.io/rmp-docs/manual/core/collision.html) | | `rmp/behavior.h` | The catalogue of [`rmp::behavior`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html): movement, tweens, timers, spawners, health. | [Behaviors](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html) | | `rmp/input.h` | [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html): named actions with up to eight bindings each, axes and directions, and the pointer. | [Input](https://omardev29.github.io/rmp-docs/manual/modules/input.html) | | `rmp/ui.h` | [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html): menus, buttons, text, layout, the controls of a settings screen, and themes. | [Interface](https://omardev29.github.io/rmp-docs/manual/modules/ui.html) | | `rmp/assets.h` | [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html): loading from `resources/` by name, and the counted handles that release what they own — [`rmp::Texture`, `rmp::Font`, `rmp::Sound`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-detail-Resource.html) and the rest — with [`rmp::SheetData`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html) behind an Aseprite sheet. | [Assets](https://omardev29.github.io/rmp-docs/manual/modules/assets.html), [Sprites](https://omardev29.github.io/rmp-docs/manual/modules/sprites.html) | | `rmp/tilemap.h` | [`rmp::Tilemap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html) and [`rmp::MapObject`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html): levels from LDtk, and from Tiled. | [Tilemaps](https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html) | | `rmp/audio.h` | [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html): sound effects and music by name, and three volume buses. | [Audio](https://omardev29.github.io/rmp-docs/manual/modules/audio.html) | | `rmp/save.h` | [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) and [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html): saving the game, in the right folder on every platform. | [Saving](https://omardev29.github.io/rmp-docs/manual/modules/saving.html) | | `rmp/random.h` | [`rmp::random`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html): one seeded generator, so a run can be reproduced. | [Random](https://omardev29.github.io/rmp-docs/manual/modules/random.html) | | `rmp/ads.h` | [`rmp::ads`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html): interstitial and rewarded ads, real on Android once `[android.admob] enabled` turns them on, and silently nothing otherwise. | [Ads](https://omardev29.github.io/rmp-docs/manual/modules/ads.html) | | `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](https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html) | | `rmp/config.h` | The `RMP_` values from `raylib_multiplatform.toml`. Every header above includes it, so you never write it. | [Below](https://omardev29.github.io/rmp-docs/manual/basics/headers.html#rmp-config-h) | 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. ### rmp/math.h This header exists for one line: ```cpp 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 `` 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. ## Which header brings which 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::Callback`s. | | `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 ``, 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. ## rmp/config.h The values a game reads from `raylib_multiplatform.toml` arrive as macros: ```cpp 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 `#define`s, 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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html) 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](https://omardev29.github.io/rmp-docs/reference/macros.html#from-the-toml) 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. ### Set by the build, not the .toml 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: ```cpp #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](https://omardev29.github.io/rmp-docs/manual/core/app.html#where-a-release-finds-its-files) has the detail. The web, Android and iOS read the copy packaged with the game. ============================================================================== # Core > What every game is made of: the app that runs it, the scenes it moves between, and the objects in them. Source: 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. - [The app](https://omardev29.github.io/rmp-docs/manual/core/app.html) — the entry point, the frame, quitting, and the state that outlives a scene. - [Scenes](https://omardev29.github.io/rmp-docs/manual/core/scenes.html) — the screens of the game, and the stack that moves between them. - [Objects](https://omardev29.github.io/rmp-docs/manual/core/objects.html) — what lives in a scene: spawning, the fields, the hooks, destroying, handles and callbacks. - [Collision](https://omardev29.github.io/rmp-docs/manual/core/collision.html) — colliders, solid objects, layers and masks, the edges of the world, the map's solid cells, raycasts. - [Behaviors](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html) — plain structs that make an object move or act a certain way, the catalogue, and writing your own. - [Camera](https://omardev29.github.io/rmp-docs/manual/core/camera.html) — what part of the world is on screen: following, smoothing, limits, zoom, shake. ============================================================================== # The app > The entry point that opens the window, runs the frame and closes everything on every platform, how a game asks to quit, and the state that outlives a scene. Source: 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. ## The entry point This is the whole of `src/main.cpp` in a new game: [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/src/main.cpp#L1-L13) ```cpp // 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 #include "scenes/main_menu.h" RMP_GAME(MainMenuScene); ``` [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#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. ### Why the first scene is named in code 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 the first scene Before your first scene exists, the app: 1. tells the asset layer where `resources/` is; 2. seeds [`rmp::random`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html) from the clock, so a shipped game plays a different sequence every launch; 3. switches on `[dev] strict` when the build is a debug build and the `.toml` asks for it; 4. in a debug build, has the warnings the framework says once in the log shown on screen as well, as [notices](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#the-frameworks-warnings-on-screen); 5. on iOS, moves into the app bundle, where the resources are; in a release build on a desktop, moves into the executable's folder when there is a `resources/` folder in it (see [where a release finds its files](https://omardev29.github.io/rmp-docs/manual/core/app.html#where-a-release-finds-its-files)); 6. opens the asset pack if there is one, so that a scene can load files from its first line; 7. opens the window: always resizable, with vsync when `[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`; 8. puts your first scene on the stack, which runs its `_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](https://omardev29.github.io/rmp-docs/manual/core/app.html#the-escape-key). ### Where a release finds its files 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. ## The frame 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](https://omardev29.github.io/rmp-docs/manual/core/scenes.html) is built on: 1. **Input.** The keyboard, the mouse — whose position raylib also takes from the first touch — and the first gamepad are read once, before anything of the game runs, and the UI starts its frame. Reading once is what stops two scenes in the same frame disagreeing about what is held down. 2. **Update**, from the bottom of the stack upwards, for every scene that is running. For each one: the pointer is offered to its objects ([`on_click`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_click), [`on_drag`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_drag)), then the scene's [`_update()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_update) runs, then its [objects](https://omardev29.github.io/rmp-docs/manual/core/objects.html#the-frame-of-an-object) update and move, then the [collision pass](https://omardev29.github.io/rmp-docs/manual/core/collision.html) resolves where they ended up, and last the [camera](https://omardev29.github.io/rmp-docs/manual/core/camera.html) follows. 3. **Draw**, from the bottom upwards, for every scene that is visible. The screen is cleared with the background of the lowest of them; then for each scene its map and its objects are drawn through its camera, and its own [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_draw) runs after, in screen space. The [notices](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#notices) go last, over everything. 4. **Present.** The frame goes to the screen and the UI ends its frame. 5. **Deferred work.** Objects destroyed during the frame are freed, and the scene changes asked for during the frame are applied, in the order they were asked for. 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. ### delta 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. ### The frame rate 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. ## A window of another size `[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`. ```toml [window] stretch = "expand" ``` [`rmp::app::stretch()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#stretch) is the mode in use, starting from the `.toml`'s, and [`rmp::app::set_stretch()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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()`: ```cpp 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](https://omardev29.github.io/rmp-docs/manual/core/camera.html#the-window-is-not-the-design-size), 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#scale-and-design-units), which keeps inside the game's area. [The stretch example](https://omardev29.github.io/rmp-docs/examples/scenes/02_stretch.html) is a court in all three modes, with a key and a button to go round them and a window to resize. Android and a Linux consoleOn [Android](https://omardev29.github.io/rmp-docs/manual/platforms/android.html), and on [a Linux console](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) with no desktop, every mode is a letterbox. raylib keeps the window at the size `InitWindow()` asked for there and scales that to the display itself, so the framework never sees a window of another shape: `expand` shows no more of the world, and `none` is letterboxed too. The desktop and the web follow the mode. ## Quitting ```cpp if (rmp::ui::button("Quit")) rmp::app::quit(); ``` [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit_requested) says whether it has been called, for code that wants to skip work on the way out. ### Per platform | 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: ```cpp #if !defined(PLATFORM_IOS) if (rmp::ui::button("Quit")) rmp::app::quit(); #endif ``` [iOS](https://omardev29.github.io/rmp-docs/manual/platforms/ios.html) has the rest of what is different there. ### The Escape key 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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: ```cpp 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`. ## The way out 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: 1. Every scene leaves the stack, top down, getting its [`_end()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_end), and its objects are destroyed after it, each getting theirs. 2. Every [global](https://omardev29.github.io/rmp-docs/manual/core/app.html#rmp-global) is destroyed, in the reverse of the order they were first used. 3. The UI's font, the sounds that are playing, and every texture, font and sound still held are released. 4. The window closes. 5. The sound device and the asset pack, which own nothing on the graphics card, close last. 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) as a member releases it safely without anyone writing an unload. ## State that outlives a scene 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global): [examples/scenes/01_stack/include/progress.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/include/progress.h#L1-L10) ```cpp #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(), and there is exactly one for the life of the app. struct Progress { int best_score = 0; int runs = 0; }; ``` ```cpp ++rmp::global().runs; Progress &progress = rmp::global(); if (score > progress.best_score) progress.best_score = score; ``` [The scene-stack example](https://omardev29.github.io/rmp-docs/examples/scenes/01_stack.html) 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](https://omardev29.github.io/rmp-docs/manual/core/scenes.html#passing-data-to-the-next-scene) 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html); see [Saving](https://omardev29.github.io/rmp-docs/manual/modules/saving.html). 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.` ## Without scenes `RMP_GAME` is built on a lower-level entry point, [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_ENTRY_POINT), which takes three functions of yours instead of a scene and runs them on the same platform runners: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html)'s actions and [`pointer_screen()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html) 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. ============================================================================== # Scenes > A scene is one screen of the game — a menu, a level, a pause overlay — and the stack of them is how the game moves from one to the next. Source: 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. ## A scene is a class Derive from [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html) and override what the scene needs. Every hook has an empty default, so a scene that only draws overrides only `_draw()`: ```cpp #include #include #include class MainMenuScene : public rmp::Scene { void _draw() override { rmp::ui::begin(); if (rmp::ui::button("Play")) rmp::Scene::change(); if (rmp::ui::button("Quit")) rmp::app::quit(); rmp::ui::end(); } }; ``` The game starts with one scene, named once in `src/main.cpp`: ```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. ## The hooks These are the methods a scene overrides, and when each one runs. | Hook | Runs | |---|---| | [`_ready()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_ready) | Once, when the scene enters the stack. The window exists by then, so this is where assets load. | | [`_update(float delta)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_update) | Every frame, unless a scene on top of it freezes it (see below). `delta` is the seconds since the last frame. | | [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_draw) | Every frame, in screen space, after the scene's objects and its map have been drawn. | | [`_suspend()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_suspend) | When another scene is pushed on top of this one. It is still alive and still owns everything it owned. | | [`_resume()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_resume) | When the scene on top of it comes off again. | | [`_end()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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. ## Moving between scenes The four calls that change the stack are static, because navigation is a service and not a property of one scene: `rmp::Scene::change()` reads the same from inside a scene, from a callback, or from anywhere else. | Call | What it does | |---|---| | [`change(args...)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#change) | Clears the stack and starts `T`. Every scene that was on it gets `_end()`, top down. | | [`push(args...)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#push) | Puts `T` on top. The scene underneath is suspended, not ended. | | [`replace(args...)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#replace) | Swaps the top scene only. Whatever is under it is untouched and stays suspended. | | [`pop()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. ### All of it happens at the end of the frame 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()` 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()`. ### Passing data to the next scene 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: ```cpp 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: ```cpp rmp::Scene::change(3, Difficulty::HARD); ``` No dictionary to look things up in, and no globals. To use designated initialisers, give the struct a name — `change(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. ## What a scene lets through When a scene is pushed on top of another, three fields decide what still reaches the one underneath: A scene pushed on top: the game below is drawn and frozen — [examples/scenes/01_stack](https://omardev29.github.io/rmp-docs/examples/scenes/01_stack.html), a frame its e2e script compares exactly. | Field | Default | Means | |---|---|---| | [`updates_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#updates_below) | `false` | The scene below keeps running. | | [`draws_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#draws_below) | `true` | The scene below stays on screen. | | [`input_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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: ```cpp 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(); rmp::ui::end(); } }; ``` With its `begin()`/`end()` pair turned into an [`rmp::ui::overlay()`](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#overlays), the same scene dims or blurs the frozen game behind its menu, and takes every click and the focus while it is up. ## What else a scene holds [`camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#camera) What part of the world is on screen. It starts on the centre of the design resolution, so while the window is the design size an untouched camera is the identity, one world unit to a pixel; on a window of any other size it fits the world the way [`[window] stretch`](https://omardev29.github.io/rmp-docs/manual/core/app.html#a-window-of-another-size) says, with that centre in the middle, and world `{ 0, 0 }` is no longer the top-left corner. See [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html). [`map`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#map) The level, loaded from a file made in a level editor. The scene draws it under everything and collides against its solid tiles; a menu scene simply never sets it. [`gravity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#gravity) The world's gravity in units per second squared, `{ 0, 980 }` by default. Each object says how much of it applies to it, and none does until it asks. [`background`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#background) The colour the frame is cleared with. `BLANK`, the default, means the theme's. Only the lowest scene that is drawn chooses it: the ones above are drawn over it. ## Objects belong to a scene A scene owns its objects. [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) 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: ```cpp 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. ============================================================================== # Objects > rmp::Object is everything that lives in a scene: how one is spawned, the fields that place and draw it, its hooks, how it is destroyed, and how to keep hold of one across frames. Source: 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. ```cpp 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. ## Spawning [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) is a method of the [scene](https://omardev29.github.io/rmp-docs/manual/core/scenes.html), 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: ```cpp auto &bullet = spawn({ .position = muzzle, .size = { 4, 10 } }); bullet.velocity = aim * 900; ``` The options are an [`rmp::ObjectOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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](https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html) has the reasons. ### The reference is good for the frame 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](https://omardev29.github.io/rmp-docs/manual/core/objects.html#keeping-an-object-handles). ### Order: options, _ready, then your lines 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. ### Spawning from somewhere else Inside an object, [`scene()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#scene) is the scene it lives in, and spawning into it is `scene().spawn(...)`. A [`Spawner`'s `on_spawn`](https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html#on_spawn) and a map's [object factory](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#on_object) 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()`. ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#current), the scene on top of the stack. ## Your own kind of object When an object needs code of its own, derive from [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) and spawn your type with `spawn()`: ```cpp 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({ .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: Does not compile ```cpp spawn(); ``` 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 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. ### Where it is | Field | Default | Is | |---|---|---| | [`position`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#position) | `{ 0, 0 }` | The centre of the object, in world units. | | [`velocity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#velocity) | `{ 0, 0 }` | World units per second. The scene moves the object by it every frame. | | [`scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#scale) | `{ 1, 1 }` | Multiplies the shape, the collider and the sprite. | | [`rotation`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ### What it looks like | Field | Default | Is | |---|---|---| | [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#sprite) | empty | A picture. When it has one, the sprite is what is drawn. | | [`shape`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#shape) | none | A rectangle or a circle, drawn when there is no sprite. | | [`flip_x`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#flip_x), [`flip_y`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#flip_y) | `false` | Mirror the sprite left to right, or top to bottom. | | [`visible`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#visible) | `true` | `false` is not drawn and cannot be clicked, and is still updated and collided. | | [`layer`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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](https://omardev29.github.io/rmp-docs/manual/core/collision.html#layers-and-masks). ### How it behaves in the world | Field | Default | Is | |---|---|---| | [`gravity_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale) | `0` | How much of the scene's gravity applies to it. Nothing falls until it asks to. | | [`edges`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#edges) | `Edge::NONE` | What it does at the edge of its bounds: clamp, bounce, wrap, be destroyed, or leave. | | [`bounds`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#bounds) | empty | The area `edges` applies to; empty is the map's bounds, or the camera's view without a map. | | [`collider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collider) | none | What it collides as, when that is not its shape or its picture. | | [`solid`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#solid), [`immovable`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#immovable) | `false` | Whether a contact pushes it apart from what it touches, and whether it is the one that gets pushed. | | [`collision_layer`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collision_layer), [`collision_mask`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collision_mask) | `1` | Which layers it is on, and which it collides with. | Gravity belongs to the scene, [`gravity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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](https://omardev29.github.io/rmp-docs/manual/core/collision.html), and `edges` and `bounds` are explained there too. ## Shapes A [`rmp::Shape`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#rect) and [`rmp::circle()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ## Sprites An object with a [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) 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: ```cpp 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#play) 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](https://omardev29.github.io/rmp-docs/manual/modules/sprites.html) has the whole of it. ## The hooks 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_update) | Every frame it is alive, after its behaviors' `_update` and before it is moved by its velocity. | | [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_collision) | Once per frame for each object it touches, on both of them, whether or not either is solid. | | [`_end()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_end) | When it is destroyed: drop the loot, tell somebody. | ## The frame of an object Every frame, in the scene's update, each living object goes through the same steps, in the order they were spawned: 1. its behaviors' `_update`, in the order they were added; 2. its own `_update()`, so your code has the last word on what the frame leaves behind; 3. it moves: the forces applied to it and its share of gravity change its velocity, and the velocity moves it — and a solid object that is not immovable is stopped by the map's solid cells on the way; 4. its `edges` rule is applied; 5. its sprite's animation advances; 6. its behaviors' `_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. ## Destroying an object ```cpp destroy(); ``` [`destroy()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#destroy) 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#object_count) counts the live ones, and an object destroyed earlier in the frame is already not counted. ## Keeping an object: handles Within a frame, a reference. Between frames, a handle. An [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) remembers an object and knows when it is gone: ```cpp rmp::Handle _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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#handle) makes one. It converts to `true` while the object is alive, `->` and `*` reach it, and [`get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html#get) returns it as an [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html), 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()` 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. ## Callbacks When a subclass is more than you want, an object takes functions instead: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_collision) | Every frame it touches another object, after the hooks. | Itself and the other object. | | [`on_click`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_click) | When the pointer is pressed on it and released on it. | Itself. | | [`on_drag`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ### The pointer 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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`: ```cpp 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. ### rmp::Callback What a callback is stored in is an [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html), 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: Does not compile ```cpp 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. ## Forces and impulses 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.** ```cpp 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#apply_force) | 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#apply_impulse) | Changes the velocity at once: `velocity += i / mass`. | A jump, a hit, an explosion, a serve. | [Pong](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) 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. ============================================================================== # Collision > What an object collides as, how solid objects are pushed apart, who collides with whom through layers and masks, the edges of the world, the map's solid cells, and raycasts. Source: 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. ## What an object collides as An object collides as the first of these it has: 1. its [`collider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collider), when one is set; 2. its [`shape`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#shape); 3. the box of its sprite's current picture. 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. ```cpp 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 centre ``` A collider is a [`rmp::Shape`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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: ```cpp DrawRectangleLinesEx(world_collider(), 1, LIME); ``` ## Being told When two objects touch, both are told, through the hook and the callback: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_collision) and its behaviors', then the second's, then the first's [`on_collision`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Projectile.html), which destroys it on a hit by default — only the enemy's first behavior is reached. A [`Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) that has to count that hit goes on before any other behavior. ## Solid and immovable 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#solid) | Pushed apart, or only told? | `false`: only told. | | [`immovable`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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: ```cpp 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](https://omardev29.github.io/rmp-docs/manual/core/collision.html#the-maps-solid-cells), 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: ```cpp class Puck : public rmp::Object { void _collision(rmp::Object &other) override { if (other.solid) velocity.x = -velocity.x; // still the speed it hit with } }; ``` ## Layers and masks 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collision_layer) | `1` | The layers this object is on, one bit each. | | [`collision_mask`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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: [examples/games/04_top_down/include/layers.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/04_top_down/include/layers.h#L1-L18) ```cpp #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](https://omardev29.github.io/rmp-docs/examples/games/04_top_down.html), where each of the three cases above is a pair of fields. Then say what each kind of object is and what it meets: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html#hurt_by) speaks the same bits, naming the layers whose touch costs a hit point. ## The edges of the world What an object does when it reaches the edge of its world is one field, [`edges`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#edges), because it is five answers to one question: | [`rmp::Edge`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) 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. ## The map's solid cells A scene with a [`map`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html) collides against it; [Tilemaps](https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html) 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. - A fast object moves in steps no longer than half the smallest cell, or half its own size, so a fall faster than a tile per frame still lands on the floor. - The step that would end inside a solid cell is narrowed down to the point of contact, and the velocity along that axis becomes zero: the landing, or the head on the ceiling. - An object that starts inside a solid cell — placed in a wall, or pushed into one — is moved out the shortest way, up winning a tie, which is the right answer for something pushed into the floor. One buried too deep to get out within a cell plus its own size stays where it is and stops, visibly stuck rather than falling out of the world. - Pushing two solid objects apart never moves one into a solid cell: a push that would is undone, so a moving platform cannot shove the player through a wall. 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#solid_at) or [`map.solid_in(rectangle)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#solid_in). A rectangle only touching a solid cell is not in it: a box standing on the floor is not in the floor. ## Fast objects 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`](https://omardev29.github.io/rmp-docs/manual/core/app.html#delta), which stops a stalled frame from turning into one enormous step. ## Raycasts 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. ```cpp if (rmp::RayHit hit = raycast(muzzle, muzzle + aim * 400)) { auto &spark = spawn({ .position = hit.point, .size = { 3, 3 } }); spark.velocity = hit.normal * 120; } ``` [`raycast()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#raycast) tests the segment from one point to the other against the scene's objects and returns the nearest hit, an [`rmp::RayHit`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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 query The longer form takes an [`rmp::RayQuery`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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()`: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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: ```cpp std::array 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)`. ### What a ray sees 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. ## One scene at a time 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. ============================================================================== # Behaviors > A behavior is a plain struct that makes an object move or act a certain way: adding, reading, pausing and removing them, the catalogue in rmp::behavior, configuring them from the editor, and writing your own. Source: 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. ```cpp auto &player = spawn({ .position = { 200, 225 }, .size = { 26, 26 } }); player.add({ .speed = 240 }); ``` ## What a behavior is 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: ```cpp 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: ```cpp auto &coin = spawn({ .position = { 300, 200 }, .shape = rmp::circle(8) }); coin.add({ .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()->options.speed`. Without one, the fields *are* the configuration. And the behaviors in [`rmp::behavior`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html) 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. ## Adding, reading, removing | Call | Does | |---|---| | [`add({ ... })`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#add) | Attaches a `B` made from the braces, runs its `_ready` if it has one, and returns a reference to it. | | [`get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get) | The object's `B`, as an [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html): empty when it has none. | | [`has()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#has) | Whether it has one. | | [`remove()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#remove) | Takes it off, running its `_end` if it has one. | | [`enable(on)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#enable) | Pauses it with `false` and resumes it with `true`, keeping its fields and its `ours`. | | [`enabled()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#enabled) | Whether it has one and it is not paused. | The fields stay live after the behavior is added. A power-up is one line: ```cpp auto &player = spawn({ .size = { 26, 26 } }); player.add({ .speed = 240 }); if (auto walk = player.get()) 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. ```cpp auto &guard = spawn({ .size = { 16, 16 } }); guard.add(); guard.enable(false); // stands still, and remembers where it was going if (!guard.enabled()) guard.enable(); ``` 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 hooks a behavior can have 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](https://omardev29.github.io/rmp-docs/manual/core/collision.html#being-told). | | `_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`](https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html) 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: Does not compile ```cpp auto &coin = spawn({ .size = { 8, 8 } }); coin.add({ .points = 10 }); ``` The compiler refuses it, saying among other things: `a behavior needs` ## What a behavior keeps: ours 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`: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/behaviors/Platformer.html#grounded) reads `ours` for you. [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) keeps its animation state the same way. ## None of them chooses for you 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](https://omardev29.github.io/rmp-docs/examples/input/01_actions.html) 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. ## The catalogue Each one has a page in the reference with every field and its default. All of them come with `rmp/behavior.h`. ### TopDown ```cpp auto &hero = spawn({ .size = { 16, 16 } }); hero.add({ .speed = 180, .eight_way = false }); ``` [`TopDown`](https://omardev29.github.io/rmp-docs/reference/behaviors/TopDown.html) 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](https://omardev29.github.io/rmp-docs/manual/modules/input.html) 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_` 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. ### Platformer ```cpp auto &hero = spawn({ .size = { 14, 22 } }); hero.add({ .speed = 200, .jump = 650, .air_jumps = 1 }); ``` [`Platformer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Platformer.html) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale) to 0. A heavier character is its own field, `get()->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. ### Runner ```cpp auto &runner = spawn({ .size = { 20, 36 } }); runner.add({ .speed = 300, .accelerate = 8, .duck_action = "duck" }); ``` [`Runner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Runner.html) 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](https://omardev29.github.io/rmp-docs/examples/games/05_endless_runner.html) is one, with a `Spawner` measuring by its distance. ### Ball ```cpp auto &ball = spawn({ .position = { 400, 225 }, .shape = rmp::circle(7) }); ball.add({ .speed = 340 }); ball.apply_impulse({ 1, 0.35f }); // the serve, and it is the game's ``` [`Ball`](https://omardev29.github.io/rmp-docs/reference/behaviors/Ball.html) 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](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) and [Breakout](https://omardev29.github.io/rmp-docs/examples/games/02_breakout.html) are both a `Ball`. ### Projectile ```cpp auto &shot = spawn({ .position = muzzle, .size = { 4, 4 } }); shot.velocity = aim; shot.add({ .speed = 600 }); ``` [`Projectile`](https://omardev29.github.io/rmp-docs/reference/behaviors/Projectile.html) 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. ### Follow ```cpp auto &bat = spawn({ .size = { 12, 8 } }); bat.add({ .target = player_handle, .speed = 90, .stop_distance = 20 }); ``` [`Follow`](https://omardev29.github.io/rmp-docs/reference/behaviors/Follow.html) 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. ### Tween ```cpp auto &lift = spawn({ .position = { 200, 300 }, .size = { 64, 12 } }); lift.add({ .property = rmp::behavior::Property::POSITION_X, .from = 200, .to = 500, .seconds = 3, .ping_pong = true, }); ``` [`Tween`](https://omardev29.github.io/rmp-docs/reference/behaviors/Tween.html) moves one property of its object from `from` to `to` over `seconds`, along an [`Ease`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#Ease): `LINEAR`, or `IN`, `OUT` and `IN_OUT`, the default, which start slow, end slow, or both. The [`Property`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#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. ### GridSnap ```cpp auto &piece = spawn({ .size = { 24, 24 } }); piece.add({ .cell = { 24, 24 } }); ``` [`GridSnap`](https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html) 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. ### Parallax ```cpp auto &sky = spawn({ .layer = -10 }); sky.add({ .texture = "sky.png", .factor = 0.2f }); ``` [`Parallax`](https://omardev29.github.io/rmp-docs/reference/behaviors/Parallax.html) 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. ### Spawner ```cpp auto &source = spawn({ .position = { 900, 380 } }); source.add({ .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({ .seconds = 6 }); }, }); ``` [`Spawner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html) 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html). 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#MAX_SPAWNED) objects, and a larger `max_alive` is reported once and held to that. ### Timer ```cpp auto &cannon = spawn({ .position = { 100, 100 }, .size = { 20, 20 } }); cannon.add({ .seconds = 0.8f, .on_timeout = [](rmp::Object &self) { self.rotation += 45; }, }); ``` [`Timer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Timer.html) 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. ### Lifespan ```cpp auto &spark = spawn({ .size = { 3, 3 } }); spark.add({ .seconds = 0.5f }); ``` [`Lifespan`](https://omardev29.github.io/rmp-docs/reference/behaviors/Lifespan.html) destroys its object after `seconds`: particles, bullets, a message that fades. ### Health ```cpp auto &hero = spawn({ .size = { 26, 26 } }); hero.add({ .hp = 5, .invulnerable_for = 0.8f, .destroy_on_death = false, .on_death = [](rmp::Object &) { TraceLog(LOG_INFO, "game over"); }, .hurt_by = layer::ENEMY, }); ``` [`Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) 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](https://omardev29.github.io/rmp-docs/manual/core/collision.html#layers-and-masks) 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`](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html#hitbox) is never counted by `hurt_by`: the Hitbox decides, so one touch never costs twice. [The top-down game](https://omardev29.github.io/rmp-docs/examples/games/04_top_down.html) gives its player a `TopDown` and a `Health` hurt by the enemies. ### Area ```cpp auto &door = spawn({ .position = { 400, 200 }, .size = { 32, 48 } }); door.collision_layer = 0; door.collision_mask = layer::PLAYER; door.add({ .on_enter = [](rmp::Object &, rmp::Object &who) { TraceLog(LOG_INFO, "welcome"); (void)who; }, .on_exit = [](rmp::Object &, rmp::Object &) { TraceLog(LOG_INFO, "goodbye"); }, }); ``` [`Area`](https://omardev29.github.io/rmp-docs/reference/behaviors/Area.html) 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](https://omardev29.github.io/rmp-docs/manual/core/collision.html#layers-and-masks) — 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](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html), 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. ### Hitbox ```cpp auto &spikes = spawn({ .position = { 300, 300 }, .size = { 32, 8 } }); spikes.collision_layer = layer::TRAP; spikes.add({ .damage = 1, .hits = layer::PLAYER, .knockback = 250 }); ``` [`Hitbox`](https://omardev29.github.io/rmp-docs/reference/behaviors/Hitbox.html) 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. ### Collectible ```cpp auto &coin = spawn({ .position = { 200, 200 }, .shape = rmp::circle(5) }); coin.add({ .collected_by = layer::PLAYER, .sound = "coin", .magnet = 40, .on_collect = [](rmp::Object &, rmp::Object &) { ++coins; }, }); ``` [`Collectible`](https://omardev29.github.io/rmp-docs/reference/behaviors/Collectible.html) 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`](https://omardev29.github.io/rmp-docs/manual/modules/audio.html), 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. ### Shooter ```cpp auto &turret = spawn({ .position = { 400, 120 }, .size = { 16, 16 } }); turret.add({ .automatic = true, .every = 1.2f, .target = player_handle, .range = 220, .speed = 180, .count = 3, .spread = 30, }); ``` [`Shooter`](https://omardev29.github.io/rmp-docs/reference/behaviors/Shooter.html) 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: ```cpp auto &archer = spawn({ .size = { 16, 16 } }); archer.add({ .action = "fire", .on_shoot = [](rmp::Scene &s, Vector2 at, Vector2 velocity) { auto &arrow = s.spawn({ .position = at, .size = { 10, 2 }, .velocity = velocity }); arrow.add({ .seconds = 1.5f }); }, }); ``` ### Orbit ```cpp for (int i = 0; i < 3; ++i) { auto &blade = spawn({ .size = { 6, 6 } }); blade.add({ .centre = player_handle, .radius = 40, .degrees_per_second = 180, .face = rmp::behavior::Face::OUTWARD, .index = i, .of = 3 }); } ``` [`Orbit`](https://omardev29.github.io/rmp-docs/reference/behaviors/Orbit.html) 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. ### Animator ```cpp auto &hero = spawn({ .size = { 16, 16 } }); hero.sprite.sheet = rmp::assets::load_sheet("hero.aseprite"); hero.add({ .run = "walk" }); hero.get()->rules.push_back( { .tag = "dash", .when = [](rmp::Object &) { return dashing; } }); ``` [`Animator`](https://omardev29.github.io/rmp-docs/reference/behaviors/Animator.html) 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#AnimationRule) is a `tag` and a `when`. `playing()` is the tag it chose last. ### Draggable ```cpp auto &slot = spawn({ .position = { 500, 300 }, .size = { 40, 40 } }); slot.add(); auto &gem = spawn({ .position = { 200, 300 }, .shape = rmp::circle(8) }); gem.add({ .on_drop = [](rmp::Object &, rmp::Object &) { TraceLog(LOG_INFO, "socketed"); }, }); ``` [`Draggable`](https://omardev29.github.io/rmp-docs/reference/behaviors/Draggable.html) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Condition.html): a callback that answers, and an empty one answers no. ### Patrol ```cpp auto &guard = spawn({ .position = { 100, 100 }, .size = { 16, 16 } }); guard.add({ .waypoints = { { 100, 100 }, { 300, 100 }, { 300, 220 } }, .speed = 60, .wait = 0.5f, .ping_pong = true, }); ``` [`Patrol`](https://omardev29.github.io/rmp-docs/reference/behaviors/Patrol.html) 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. ### Pathfind ```cpp auto &rat = spawn({ .size = { 10, 10 } }); rat.add({ .target = player_handle, .speed = 90, .clearance = 5 }); ``` [`Pathfind`](https://omardev29.github.io/rmp-docs/reference/behaviors/Pathfind.html) 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#find_path) 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. ```cpp const auto way = rmp::find_path(map, { 40, 40 }, { 400, 300 }, { .diagonal = false }); if (way.empty()) TraceLog(LOG_INFO, "walled in"); ``` ### Chase ```cpp auto &hound = spawn({ .position = { 300, 200 }, .size = { 14, 14 } }); hound.add({ .waypoints = { { 300, 200 }, { 420, 200 } } }); hound.add(); hound.add({ .target = player_handle, .speed = 110, .sight = 160, .fov = 120, .on_spot = [](rmp::Object &, rmp::Object &) { TraceLog(LOG_INFO, "there you are"); }, }); ``` [`Chase`](https://omardev29.github.io/rmp-docs/reference/behaviors/Chase.html) 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(false)`](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html#enable)) 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. ### StateMachine ```cpp auto &boss = spawn({ .size = { 32, 32 } }); boss.add({ .target = player_handle }); boss.add({ .automatic = true, .count = 8, .spread = 360 }); rmp::behavior::StateMachine mind; mind.states.push_back({ .name = "hunt", .enables = rmp::behavior::kinds() }); mind.states.push_back({ .name = "volley", .on_enter = [](rmp::Object &self) { self.velocity = {}; }, .enables = rmp::behavior::kinds() }); mind.transitions.push_back({ .from = "hunt", .to = "volley", .when = [](rmp::Object &self) { return self.get()->seconds_in_state() > 3; } }); mind.transitions.push_back({ .from = "volley", .to = "hunt", .when = [](rmp::Object &self) { return self.get()->seconds_in_state() > 2; } }); boss.add(std::move(mind)); ``` [`StateMachine`](https://omardev29.github.io/rmp-docs/reference/behaviors/StateMachine.html) is named states and the moves between them: an enemy that idles, patrols, chases and flees; a boss's phases. A [`State`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#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()`. 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#Transition) 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. ## From the editor 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: ```cpp 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; 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](https://omardev29.github.io/rmp-docs/examples/games/08_dungeon.html) is built this way: every monster, trap and pickup is an entity with these fields, and its code is which behaviors each one carries. ## Writing your own 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html), so a lambda can go straight into the braces: ```cpp #include // 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 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({ .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. ============================================================================== # Camera > rmp::Camera decides which part of a scene's world is on screen: following an object, smoothing that is the same at any frame rate, limits, zoom, shake, and converting between world and screen. Source: https://omardev29.github.io/rmp-docs/manual/core/camera.html Every scene has a [`camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#camera), an [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html), 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. ```cpp 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 level ``` ## Where it starts The 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#position) | the centre of the design resolution | The world point at the centre of the view. | | [`zoom`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#zoom) | `1` | 2 shows everything twice as big. Zero or less counts as 1. | | [`rotation`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#rotation) | `0` | Degrees, clockwise, as raylib's `Camera2D` counts them. | | [`follow`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#follow) | empty | A handle to the object to keep centred. | | [`smoothing`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#smoothing) | `0` | How fast it catches up with that object, per second; 0 snaps. | | [`limits`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#limits) | empty | A rectangle of the world the view never leaves. | ## What it frames 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html) 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 is not the design size 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`](https://omardev29.github.io/rmp-docs/manual/core/app.html#a-window-of-another-size)'s to say, and the camera is where it happens. What the camera shows, [`view()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#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: ```cpp rmp::app::set_stretch(rmp::app::Stretch::EXPAND); camera.zoom = RMP_WINDOW_HEIGHT / VIEW_HEIGHT; // 225 world units of height at the design size ``` That is [the platformer](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html)'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. Carefulraylib has one scissor, not a stack of them. An object that calls `BeginScissorMode()` and `EndScissorMode()` in its own `_draw()` ends the letterbox's cut with them, for the rest of its scene's world. [The stretch example](https://omardev29.github.io/rmp-docs/examples/scenes/02_stretch.html) 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](https://omardev29.github.io/rmp-docs/manual/core/app.html#a-window-of-another-size). ## Following With [`follow`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#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 a rate `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 [`limits`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#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. ```cpp camera.limits = map.bounds(); // the level, whatever its size camera.limits = { 0, 0, 0, RMP_WINDOW_HEIGHT }; // a runner: free across, pinned top to bottom ``` Each 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](https://omardev29.github.io/rmp-docs/examples/games/05_endless_runner.html) 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 and rotation `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. ## Shake ```cpp camera.shake(8, 0.35f); // up to 8 world units, fading out over 0.35 seconds ``` That is [Breakout](https://omardev29.github.io/rmp-docs/examples/games/02_breakout.html)'s, when a ball is lost. [`shake(strength, seconds)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#shake) 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#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. ## World and screen | Call | Gives | |---|---| | [`to_world(screen)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#to_world) | The world point under a point of the screen, in pixels from its top-left corner. | | [`to_screen(world)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#to_screen) | Where a world point is on the screen. | | [`view()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#view) | The rectangle of the world that is visible, ignoring rotation. | | [`raylib()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html) 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()`: ```cpp rmp::Handle _player; void _draw() override { if (!_player) return; const Vector2 above = camera.to_screen({ _player->position.x, _player->position.y - 30 }); DrawText("!", static_cast(above.x), static_cast(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()`](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#boxes-over-the-world), which goes through the camera by itself. ### Drawing in world units yourself 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: ```cpp 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](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) draws its net this way for that reason. ## What reads the camera Besides drawing, five things in the framework take the camera into account, so they follow it without anything written: - an object's `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; - the [`Parallax`](https://omardev29.github.io/rmp-docs/reference/behaviors/Parallax.html) 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. ============================================================================== # Modules > The parts of the framework a game takes when it needs them — input, the interface, assets, sprites, levels, sound, saving, random numbers and ads — each one header of its own. Source: 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](https://omardev29.github.io/rmp-docs/manual/basics/headers.html). - [Input](https://omardev29.github.io/rmp-docs/manual/modules/input.html) — named actions with any number of bindings, movement in eight directions in one call, the mouse and a finger as one pointer, and who gets to hear a press. - [Interface](https://omardev29.github.io/rmp-docs/manual/modules/ui.html) — menus, HUDs and settings screens in immediate mode, playable with a mouse, a finger, a keyboard or a gamepad. - [Interface layout](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html) — rows, columns, panels, stacks, grids, scrolling, and how big each thing is. - [Interface controls](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html) — checkboxes, sliders, dropdowns and text fields that write into your variables. - [Interface style](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html) — themes, variants, sizes, transitions, breakpoints and fonts. - [Assets](https://omardev29.github.io/rmp-docs/manual/modules/assets.html) — files in `resources/`, loaded by name, the same from loose files or from a pack. - [Sprites](https://omardev29.github.io/rmp-docs/manual/modules/sprites.html) — what an object looks like: a texture, or an Aseprite file whose tags are its animations. - [Tilemaps](https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html) — levels designed in LDtk or Tiled, drawn, collided with, and turned into objects. - [Audio](https://omardev29.github.io/rmp-docs/manual/modules/audio.html) — sound effects and music by name, on volume buses a settings screen can move. - [Saving](https://omardev29.github.io/rmp-docs/manual/modules/saving.html) — [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) and [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html): a tree of data written to the right folder on every platform. - [Localization](https://omardev29.github.io/rmp-docs/manual/modules/localization.html) — every text the framework draws translated from the game's tables, with placeholders, plurals and a font per language; `rmp text` keeps the tables in step with the code. - [Dialogue](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html) — conversations written in Yarn Spinner 3, shown as a box, a bubble or a visual novel's stage, started by a Talker. - [Random](https://omardev29.github.io/rmp-docs/manual/modules/random.html) — random numbers you can reproduce. - [Ads](https://omardev29.github.io/rmp-docs/manual/modules/ads.html) — interstitial and rewarded ads on Android, and the same calls doing nothing everywhere else. ============================================================================== # Input > Named actions with as many bindings as you like, movement in eight directions in one call, the mouse and a finger as one pointer, and the rule that decides who hears a press. Source: https://omardev29.github.io/rmp-docs/manual/modules/input.html [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html) 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. ```cpp 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 `. 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. Without scenes A game written with `RMP_ENTRY_POINT` and no scenes has no scene stack, so the third rule of [who hears a press](https://omardev29.github.io/rmp-docs/manual/modules/input.html#who-hears-a-press) never applies to it, and the interface's two rules apply as they do anywhere. [`pointer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer) goes through the camera of the scene on top, and with no scene there is no camera: there it is [`pointer_screen()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer_screen), the position in the window's pixels, and nothing is reported. ## Actions An action is a name and the bindings that press it, as many as you like. [`rmp::input::action`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#action) takes the name first and the bindings after it: ```cpp 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: Does not compile ```cpp rmp::input::action("jump", 32); // an int is not a key ``` The 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. ### Defining one again replaces it 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: ```cpp 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.` ### Reading an action Three questions, each asked by name: | Call | True | |---|---| | [`pressed("jump")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pressed) | Every frame any of its bindings is held down. | | [`just_pressed("jump")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#just_pressed) | The frame one of them goes down. | | [`just_released("jump")`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#just_released) | 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. ### Half of a stick 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#stick) is the one place you write something that is not a plain raylib constant: ```cpp 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. ### Which gamepad 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. ## The actions that come with it 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#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](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) does exactly that ([main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/01_pong/src/main.cpp#L68-L81)): ```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)); } ``` ## Moving: vector and axis [`rmp::input::vector()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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: ```cpp velocity = rmp::input::vector() * 200; ``` Three things are decided for you in that line: - **It is normalised.** Holding right and down gives a vector of length 1, not 1.41, so going diagonally is not 41 % faster than going straight. Only a vector longer than 1 is shortened: a stick pushed halfway still gives half. - **+Y is down**, as in raylib's screen coordinates and an object's `position`, so "up" gives a negative Y and nothing has to be flipped. - **Opposite directions cancel.** Left and right held together give 0, which is what a player mashing both keys expects. [`rmp::input::axis()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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: ```cpp velocity.x = rmp::input::axis() * 180; ``` Both take your own actions too, in the order negative then positive: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#axis_value) gives one axis from -1 to +1, dead zone applied, and is never routed: ```cpp float turn = rmp::input::axis_value(GAMEPAD_AXIS_RIGHT_X); ``` ## The dead zone 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`: ```toml [input] deadzone = 0.25 ``` Past 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: ```toml [input] deadzone = 1.0 ``` ```text 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#deadzone) reads it and [`rmp::input::set_deadzone()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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: ```cpp static float deadzone = rmp::input::deadzone(); if (rmp::ui::slider("Stick dead zone", deadzone, 0.0f, 0.5f)) rmp::input::set_deadzone(deadzone); ``` ## The pointer 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer_screen) | Where it is, in pixels, from the top-left of the window. | | [`pointer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#position), which starts at the middle of that size, in the middle of the game's area, scaled as [`[window] stretch`](https://omardev29.github.io/rmp-docs/manual/core/app.html#a-window-of-another-size) 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer_delta) | How far it moved since the last frame, in pixels. Zero on the first frame. | | [`pointer_down()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer_down) | The left button, or a finger, is held. | | [`pointer_pressed()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer_pressed) | The frame it goes down. | | [`pointer_released()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#consumed_pointer) first — or bind the button to an action, which asks for you: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_click) already gives the interface first refusal. ## Who hears a press 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: ```cpp 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), always ``` The 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. ### The three rules 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. 1. **Mouse bindings go quiet while the interface wants the pointer**: while [`rmp::ui::wants_pointer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. 2. **Key and gamepad bindings go quiet while the interface wants the keyboard**: while [`rmp::ui::wants_keyboard()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#typing-is-having-the-keyboard)). Gamepad buttons and sticks go with the keyboard. 3. **Every action goes quiet in a scene that another one covers**, unless every scene above it set [`input_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#input_below), which is `false` by default. A covered scene is usually not updated at all; when the one on top sets [`updates_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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](https://omardev29.github.io/rmp-docs/manual/core/scenes.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#consumed_pointer) and [`consumed_keyboard()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#consumed_keyboard) answer whether anything above the caller is holding that device: a scene on top, or the interface. ### What routing does not cover 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#a-button-in-the-hud) has the rest, and what to say when the guess is wrong. ## A whole example `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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/input/01_actions/src/main.cpp#L1-L103) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include 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(); // 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); ``` ```shell rmp example 01_actions ``` Escape is the game's key raylib makes Escape the key that closes the window. The entry point takes that away once the ready hook has returned, in every runner and whoever opened the window, so an action bound to `KEY_ESCAPE` — the `pause` action above, `ui_cancel` — reads as pressed and the game carries on. The window's close button still closes it. Because it happens after the ready hook, a `SetExitKey()` of the game's own there, a first scene's `_ready()` included, is overwritten. A game that quits on a key says so with [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) (see [the Escape key](https://omardev29.github.io/rmp-docs/manual/core/app.html#the-escape-key)): `rmp::input::action("quit", KEY_Q, GAMEPAD_BUTTON_MIDDLE_LEFT); if (rmp::input::just_pressed("quit")) rmp::app::quit();` ## Dropping to raylib Nothing 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#consumed_pointer) or [`consumed_keyboard()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#consumed_keyboard) first. ============================================================================== # Interface > rmp::ui draws menus, HUDs and settings screens in immediate mode — a main menu is three calls — and plays the same with a mouse, a finger, a keyboard or a gamepad. Source: https://omardev29.github.io/rmp-docs/manual/modules/ui.html [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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. Simple mode: a menu of buttons, the default theme — [examples/ui/01_menu](https://omardev29.github.io/rmp-docs/examples/ui/01_menu.html) Full mode: retained widgets with a skin, nine-slices and a pixel font — [examples/ui/09_skinned](https://omardev29.github.io/rmp-docs/examples/ui/09_skinned.html) ```cpp 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: - [Interface layout](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html) — rows, columns, panels, grids, scrolling lists, and how big each thing is. - [Interface controls](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html) — checkboxes, sliders, dropdowns and text fields, which write straight into your variables. - [Interface style](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html) — themes, variants, sizes, breakpoints and fonts. ## Two ways to write it 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: ```cpp rmp::ui::begin(); if (rmp::ui::button("Play")) play(); if (rmp::ui::button("Quit")) quit(); rmp::ui::end(); ``` Simple: a call each frame ```cpp 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(); } ``` Full: widgets you keep 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html), `text()` and [`Label`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html), `image()` and [`Image`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html), `panel()` and [`Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html), `checkbox()` and [`Checkbox`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html), `slider()` and [`Slider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html), `dropdown()` and [`Dropdown`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html), `text_input()` and [`TextInput`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html), `progress()` and [`ProgressBar`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html). The pages that follow show each control both ways, side by side; [widgets you keep](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep) has every field and callback of the full one. ## Immediate mode In the simple way there are no widget objects. A call to [`button()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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`. ## Where it goes In a game made of scenes, a scene's interface goes in its [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#background) itself. A scene underneath another one keeps drawing its interface when the scene on top lets it (see [what a scene lets through](https://omardev29.github.io/rmp-docs/manual/core/scenes.html#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: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#shutdown) starts it again, the same way the first one did. ## The three rules That is all of them. 1. **[`end()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`. 2. **Describe it where it is drawn.** In a scene's `_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()`](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#boxes-over-the-world). 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.` 3. **Interaction uses the previous frame's layout.** When `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()`](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#overlays) 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. ## Buttons and text [`rmp::ui::button`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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(); ``` Simple: a call each frame ```cpp 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(); } ``` Full: widgets you keep [`ButtonOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ButtonOptions) has four fields, written in this order: | Field | Default | Means | |---|---|---| | [`style`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ButtonOptions-style) | `Variant::NORMAL` | What the button means — normal, primary, danger, outline, ghost. The theme decides what that looks like; see [variants](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#variants). | | [`size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ButtonOptions-size) | the theme's | `Size::SMALL`, `MEDIUM` or `LARGE`, or a number of design units. See [sizes](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#sizes). | | [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ButtonOptions-enabled) | `true` | `false` draws it in the theme's disabled colours; it cannot be pressed and the focus skips it. | | [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ButtonOptions-id) | none | A name that stays the same whatever the label says. See [labels are ids](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#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](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#filling-the-window), it is the window's width less the padding. Its height is at least the theme's [`min_touch_size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#an-image-you-can-press), pressed the same way. A screen where every button has its own look, icon, sounds and callbacks is easier with [widgets you keep](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep), and a look for every button of the game is [a style in the theme](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#styles); neither changes a line of a menu written the simple way. [`rmp::ui::text`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#text) draws a string, in one of the theme's colours, at one of its sizes: ```cpp 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 }); ``` Simple: a call each frame ```cpp 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(); } ``` Full: widgets you keep [`TextOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOptions) is [`color`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOptions-color) — a [`ColorRole`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ColorRole), not a colour — [`size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOptions-size) and [`wrap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOptions-wrap). With `wrap` on, the default, a line too long for the space it is given breaks between words; off, it is never broken. ## Labels are ids 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. ```cpp 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: ```cpp 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#naming-a-container). ## Focus, keyboard and gamepad 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](https://omardev29.github.io/rmp-docs/manual/modules/input.html) 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#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](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#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](https://omardev29.github.io/rmp-docs/manual/core/app.html#the-escape-key)). ### Nothing to start 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#a-button-in-the-hud). Having the focus and showing it are two things. The focus ring — the theme's [`focus`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-focus) colour, [`focus_ring`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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. ### Moving it yourself A screen does not need to put the focus anywhere: its first control already has it. [`rmp::ui::focus()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ```cpp 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#set_navigation_enabled) turns keyboard and gamepad handling off, for a game that drives the focus itself; [`navigation_enabled()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ### Scenes on top of scenes When two scenes draw, the one on top holds the focus. A scene underneath that input cannot reach — the scene above left [`input_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. ### A button in the HUD 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](https://omardev29.github.io/rmp-docs/manual/modules/input.html), 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: ```cpp 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(); 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-focus_first) says it for them: `false` is a HUD whatever the scene reads, `true` a menu whose first control takes the focus. ```cpp 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()`](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#overlays) gives its first control the focus whatever the scene under it reads. ## Overlays 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ```cpp 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: - **The veil takes the pointer everywhere.** A click outside the menu does not reach the game, and `wants_pointer()` is true wherever the pointer is — at a `dim` of 0 too, where there is no veil to see. - **What was drawn before it is inert.** From the next frame, the interface described before it in the frame takes no input: the HUD behind a dialog cannot be hovered, focused or pressed. - **Its first control has the focus**, so Enter and the gamepad's bottom face button press it the moment it appears, whatever the scene underneath reads. [`OverlayOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#OverlayOptions), in this order: | Field | Default | Means | |---|---|---| | [`placement`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#OverlayOptions-placement) | `Align::CENTER` | Where its content sits, as a frame's `placement`. | | [`blur`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#OverlayOptions-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#OverlayOptions-dim) | `0.45` | From 0 to 1: how far what is underneath goes towards `veil`. | | [`veil`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#OverlayOptions-veil) | black | The colour it is dimmed towards. | ### A pause menu 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](https://omardev29.github.io/rmp-docs/manual/core/scenes.html#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. ### A dialog 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ```cpp 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](https://omardev29.github.io/rmp-docs/examples/ui/08_overlay.html) 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 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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. ## Boxes over the world [`rmp::ui::at()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp std::vector> _enemies; void _draw() override { rmp::ui::begin(); for (const rmp::Handle &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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#AtOptions) says where it sits: | Field | Default | Means | |---|---|---| | [`anchor`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#AtOptions-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#AtOptions-offset) | `{ 0, 0 }` | Design units, after projecting: `{ 0, -8 }` lifts the box clear of the sprite. | | [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#AtOptions-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](https://omardev29.github.io/rmp-docs/examples/games/04_top_down.html) 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. ## Tooltips [`rmp::ui::tooltip()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#tooltip) is a line about the control declared just before it: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TooltipOptions-side) | `Align::TOP_CENTER` | Which side of the control it appears on. | | [`delay`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TooltipOptions-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](https://omardev29.github.io/rmp-docs/examples/ui/05_inventory.html) describes every item this way. ## Notices [`rmp::ui::notify()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NotifyOptions) is [`seconds`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NotifyOptions-seconds) on screen, 3 by default, at the end of which it fades out, and the [`color`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NotifyOptions-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. ### The framework's warnings, on screen 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)`. ## Telling the game to keep its hands off 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#overlays)'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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#boxes-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](https://omardev29.github.io/rmp-docs/manual/modules/input.html#who-hears-a-press). Wherever the game reads raylib's input directly, they are the check: ```cpp if (!rmp::ui::wants_pointer() && IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) shoot(); if (!rmp::ui::wants_keyboard() && IsKeyDown(KEY_W)) walk(); ``` ## Touch 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: - **Hover only while a finger is down.** A touch screen has no pointer at rest, and the last place tapped would otherwise stay lit up. - **No button is shorter than `min_touch_size`**, even a small one: a small button on a phone is still pressed with a thumb. - **The edges are kept clear.** `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. ## Scale and design units 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: ```text 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`](https://omardev29.github.io/rmp-docs/manual/core/app.html#a-window-of-another-size) 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#breakpoints-and-scale) 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#scrolling), 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#fonts). [`rmp::ui::scale()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#scale) reads the factor in use. [`rmp::ui::set_scale()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```toml [ui] scale = 1.5 ``` Scale 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#breakpoints-and-scale). ## Configuration 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#themes). | | `font` | `""` | A font file in `resources/`; empty is raylib's built-in font. See [fonts](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#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: ```toml [ui] max_elements = 1024 ``` ## What is underneath The layout engine is [Clay](https://github.com/nicbarker/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 `` 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](https://omardev29.github.io/rmp-docs/manual/raylib/clay.html) has the rest of the rules, and [the Clay example](https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html) does it next to `rmp::ui` calls in the same frame. ## The examples Every example is a small project the framework builds and boots in CI, and each of these is one idea: - [Menu](https://omardev29.github.io/rmp-docs/examples/ui/01_menu.html) — the three-call menu, a confirm screen, a HUD, one scene per screen. - [Layout](https://omardev29.github.io/rmp-docs/examples/ui/02_layout.html) — rows, columns, panels, stacks, spacers, images and progress bars. - [Clay direct](https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html) — Clay's own API next to `rmp::ui`. - [Settings](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html) — every control, writing into one struct that is saved, and a notice that says so. - [Inventory](https://omardev29.github.io/rmp-docs/examples/ui/05_inventory.html) — a grid that works out its columns, a scrolling list, and a tooltip on every item. - [Style](https://omardev29.github.io/rmp-docs/examples/ui/06_style.html) — both themes, every variant and size. - [Responsive](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) — one layout that turns from a row into a column on a narrow screen. - [Overlay](https://omardev29.github.io/rmp-docs/examples/ui/08_overlay.html) — a pause menu pushed and blurred, and a dialog drawn by the game scene itself. - [Skinned](https://omardev29.github.io/rmp-docs/examples/ui/09_skinned.html) — a shop drawn by an artist: nine-slice skins from one Aseprite file, icons by slice name, an animated sprite, shadows, outlines, a font of its own, motion, sounds and the widgets you keep, each with its callbacks. - [Font](https://omardev29.github.io/rmp-docs/examples/ui/12_font.html) — a title screen, its options and its credits, one scene each, all in a font of your own through one `set_font()`. The main menu of the first one is the whole idea in one file: [examples/ui/01_menu/src/scenes/main_menu.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/scenes/main_menu.cpp#L1-L19) ```cpp // The whole point: a main menu. #include "screens.h" #include 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(); if (rmp::ui::button("Options")) change(); if (rmp::ui::button("Quit")) change(); rmp::ui::end(); } ``` ============================================================================== # Interface layout > Rows, columns, panels, stacks, grids and scrolling lists, and the three ways anything in rmp::ui is sized — fit, grow and fixed — in design units that follow the screen. Source: 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. Rows, columns and cards — [examples/ui/02_layout](https://omardev29.github.io/rmp-docs/examples/ui/02_layout.html) One layout that changes with the window — [examples/ui/07_responsive](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#row) | Its children left to right. | | [`column`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#column) | Its children top to bottom. | | [`panel`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#panel) | A column with a background, padding and rounded corners: a dialog, a card. | | [`center`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#center) | Fills the space it is given and puts its contents in the middle of it. | | [`stack`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#stack) and [`layer`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#layer) | Layers in the same box, the later ones on top. | | [`grid`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#grid) and [`cell`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#cell) | Equal columns, as many rows as it takes. | | [`scroll`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#scroll) | Clips its contents and scrolls them. | | [`spacer`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#spacer) | Not a container: it eats the space left over, or leaves a gap of a given size. | ## The frame begin() opens [`begin()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions) says otherwise: | Field | Default | Means | |---|---|---| | [`placement`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-placement) | `Align::CENTER` | Where the column sits on the screen. | | [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-gap) | the theme's `gap` | Between the things in the column. | | [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-padding) | the theme's `panel_padding` | Kept clear around the edge of the screen. | | [`grow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-grow) | `false` | `true`: the column fills the window, less the padding, instead of fitting what is in it. See [filling the window](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#filling-the-window). | | [`focus_first`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#scale-and-design-units). [`Align`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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. ## Sizing: fit, grow, fixed 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-grow_x), [`grow_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-width), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-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: ```cpp rmp::ui::panel({ .box = { .width = 240, .grow_y = true } }, [&] { rmp::ui::text("Sections"); }); ``` ### Filling the window 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 })`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#FrameOptions-grow) makes the column fill the window, less the padding, on both axes, so whatever grows inside it reaches the edges: ```cpp 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](https://omardev29.github.io/rmp-docs/examples/ui/05_inventory.html) and [responsive](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) 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: ```cpp 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. ## Gap, padding and where children sit Rows, columns and panels take [`BoxOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions) — a panel inside its `.box` — and three of its fields decide the space around things: | Field | Default | Means | |---|---|---| | [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-gap) | the theme's `gap`, 12 | Between children, in design units. | | [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-padding) | none; a panel's is the theme's `panel_padding`, 20 | Inside the container, the same on all four sides. | | [`items`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#BoxOptions-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. ```cpp 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 }); }); ``` ### Spacers [`spacer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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. ## Panels A [`panel`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions) holds the layout in `.box` and the look after it: | Field | Default | Means | |---|---|---| | [`box`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-box) | `{}` | The layout, as a column takes it, except that its padding defaults to the theme's `panel_padding`. | | [`background`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-background) | the theme's `panel` | The fill. `{ 0, 0, 0, 0 }` means the theme's. | | [`radius`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-radius) | the theme's `corner_radius` | Of the corners, in design units; 0 is square. | | [`border`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#PanelOptions-border_width) | 1 | The width of an outline you set, in design units. | ```cpp 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 }); }); }); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#styles) for that look and how to take it away. A kept [`Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) can also be clicked, and styles everything inside it: [Panel](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#panel). ## Centring and layers [`center()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#stack) puts things on top of each other. Every child of a stack has to be a [`layer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#layer); each layer fills the stack, centres what is in it, and is drawn over the layers written before it: ```cpp 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. ## Grids A [`grid`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#grid) lays its items out in equal columns and starts a new row when one fills. Each item goes in a [`cell()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-columns) at 0 the grid works out how many cells of [`min_cell`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-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. ```cpp 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. [`GridOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions): | 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-gap) | the theme's `gap` | Between cells and between rows. | | [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-padding) | none | Inside the grid. | | [`grow_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-grow_x) | `true` | Take the width it is offered. | | [`grow_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-grow_y) | `false` | Fill the parent's height instead of fitting the rows. | | [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#GridOptions-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. ## Scrolling [`scroll()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: [examples/ui/05_inventory/src/panels/list.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory/src/panels/list.cpp#L1-L36) ```cpp // 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 #include 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#filling-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-height) makes it a window of a fixed size onto a longer list: ```cpp 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); } }); ``` [`ScrollOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions): | Field | Default | Means | |---|---|---| | [`horizontal`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-horizontal) | `false` | Clip and scroll left to right. | | [`vertical`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-vertical) | `true` | Clip and scroll top to bottom. | | [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-gap) | the theme's `gap` | Between children. | | [`padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-padding) | none | Inside the area. | | [`grow_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-grow_x), [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-width) | `true`, 0 | Fill the parent's width, or a fixed one. | | [`grow_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-grow_y), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-height) | `true`, 0 | Fill the parent's height, or a fixed one. | | [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ScrollOptions-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. ## Images and progress bars [`rmp::ui::image`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions) changes that: | Field | Default | Means | |---|---|---| | [`grow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-grow) | `false` | Fill the space available on both axes; the picture is stretched to it. | | [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-width), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-height) | 0 | A size in design units; 0 is the texture's own. | | [`tint`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-tint) | `WHITE` | Multiplies the picture's colours; `WHITE` leaves them as they are. | ```cpp rmp::ui::image(portrait, { .width = 96, .height = 96 }); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep What it draws is any [`rmp::ui::Picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html): an [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture), a part of one, the frame an [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) shows, a slice of an Aseprite file, a nine-slice. [Pictures](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#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: ```cpp 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: ```cpp rmp::ui::image(minimap.texture, { .width = 160, .height = 160 }); ``` [`rmp::ui::progress`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#progress) is a bar, filled to a fraction from 0 to 1 — clamped, so a health of -5 draws empty rather than going wrong: ```cpp rmp::ui::progress(health, { .width = 180 }); rmp::ui::progress(mana, { .width = 180, .height = 8, .fill = SKYBLUE }); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep [`ProgressOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions): [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-width) (0 fills the space available), [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-height) (by default 0.6 of the theme's type size), [`radius`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-radius) (by default half the height, for round ends), [`fill`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-fill) and [`track`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-track) (the theme's `primary` and `surface` unless set), and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ProgressOptions-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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html) with a [`fill_picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill_picture); see [widgets you keep](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep). ## Naming a container Containers are anonymous unless you give them an `id` — [`BoxOptions::id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ```cpp rmp::ui::panel({ .box = { .id = "inventory" } }, [&] { rmp::ui::text("Inventory"); }); ``` ## A whole layout `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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/02_layout/src/main.cpp#L1-L169) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include 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. ``` ============================================================================== # Interface controls > Checkboxes, sliders, dropdowns and text fields that take your variable by reference; the widgets you keep, Godot style, with their own style and callbacks; and the events every control sends. Source: 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep), each with its own style and callbacks, and every control sends [events](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#events). Checkboxes, sliders, a dropdown and a text field — [examples/ui/04_settings](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html), a frame its e2e script compares exactly. ```cpp 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(); ``` ## The state model 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: [examples/ui/04_settings/include/settings.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/04_settings/include/settings.h#L1-L28) ```cpp #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 #include #include 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 QUALITY{ "Low", "Medium", "High", "Ultra" }; inline constexpr std::array 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: ```cpp 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#labels-are-ids). ## What they have in common 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#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. ## Checkbox [`rmp::ui::checkbox`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp if (rmp::ui::checkbox("Light theme", light)) rmp::ui::set_theme(light ? rmp::ui::theme_light() : rmp::ui::theme_dark()); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#CheckboxOptions) is [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#CheckboxOptions-enabled) and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#CheckboxOptions-id). ## Slider [`rmp::ui::slider`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#slider) sets a `float` between a minimum and a maximum: ```cpp 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 }); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep - **With the pointer**, press on the rail and drag: the value follows where the pointer is along it. The area that takes the press is a little taller than the rail, which is thinner than a finger. While a drag lasts the slider holds the pointer — `wants_pointer()` stays true — even when the pointer leaves the rail. - **With the keyboard or a gamepad**, while it has the focus, Left and Right — or the d-pad, or the left stick — move it one step per press, then twelve steps a second while held. A step is `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`. [`SliderOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions): | Field | Default | Means | |---|---|---| | [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-width) | 0 | Of the rail, in design units; 0 fills the space available. | | [`step`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-step) | 0 | 0 is continuous; otherwise the value snaps to `min` plus a multiple of it. | | [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-enabled) | `true` | As above. | | [`show_value`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-show_value) | `true` | Draw the position after the rail, as a percentage of the range. | | [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#SliderOptions-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()`. ## Dropdown [`rmp::ui::dropdown`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#dropdown) picks one string of a list. The value it writes is an index into that list: ```cpp if (rmp::ui::dropdown("Quality", quality, { "Low", "Medium", "High", "Ultra" })) apply_quality(quality); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions) is [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions-width) — of the field, in design units, 0 filling the space available — [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions-enabled) and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DropdownOptions-id). Two dropdowns that both have a "Low" in them are still two lists: an item belongs to its dropdown, not to its text. ## Text field [`rmp::ui::text_input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#text_input) edits a `std::string` of yours, in UTF-8: ```cpp static std::string name; rmp::ui::text_input("Name", name, { .placeholder = "your name", .max_length = 16 }); ``` Simple: a call each frame ```cpp 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(); } ``` Full: a widget you keep While the field is typing — which is not the same as having the focus; see [below](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#typing-is-having-the-keyboard) — 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions): | Field | Default | Means | |---|---|---| | [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-width) | 0 | Of the field, in design units; 0 fills the space available. | | [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-enabled) | `true` | As above. | | [`placeholder`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-id) | none | As above. | | [`max_length`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextInputOptions-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. ### Typing is having the keyboard 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. - **It takes the keyboard** when it is clicked, when the focus is moved onto it — by Tab, Up or Down, the d-pad, or `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. - **It gives the keyboard back** on Enter or the bottom face button, on Escape or the right face button, on a press of the pointer anywhere else, and when the focus moves on. Space is typed, not taken as Enter. The focus stays on the field, so Enter again starts typing again. - **Tab, Up and Down leave a field** like any other control, and the keyboard goes with the focus: off this field, and into the next one if that is a field too. While a field is typing, [`rmp::ui::wants_keyboard()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#wants_keyboard) is true, and every [rmp::input](https://omardev29.github.io/rmp-docs/manual/modules/input.html) 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. ## A settings screen [The settings example](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html) 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) when it is applied. ```shell rmp example 04_settings ``` ## Widgets you keep Everything 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. ```cpp rmp::ui::Button play{ .text = "Play", .variant = rmp::ui::Variant::PRIMARY, .style = { .shadow = rmp::ui::Shadow{} }, .on_click = [this] { change(); }, }; 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. - **Every field can change between frames.** `play.text = "Continue";` and the next `show()` draws it. - **It cannot be copied.** Its callbacks are [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html)s, which hold lambdas that capture what they like, a `std::unique_ptr` too, and cannot be copied; keep the widget where it lives. - **It remembers what it is doing** in `ours`, a [`KeptState`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState) — [`hovered`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-hovered), [`pressed`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-pressed), [`focused`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-focused) and the [`shakes`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#KeptState-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`](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#motion), plays its `shake` sound and sends [`EventKind::SHAKE`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#EventKind-SHAKE): "that did not work". It starts at the next `show()`. - **`style`** is its own [style](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#styles), over everything around it, and **`id`** is the [same id](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#labels-are-ids) 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`. ### Button [`rmp::ui::Button`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html): text, an icon, or both. ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#text) | "" | The label; empty for a button that is only its icon. | | [`icon`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#icon) | none | A [picture](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#pictures) before the label, or alone. | | [`icon_size`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#icon_above) | `false` | `true` puts the icon over the label, as a toolbar tile. | | [`variant`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#variant) | `NORMAL` | What it means, as `ButtonOptions::style`. | | [`size`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#size) | the theme's | A step or design units, as `ButtonOptions::size`. | | [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#width), [`height`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#height) | 0 | Above 0, a fixed size in design units; 0, sized as `button()` is. | | [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#enabled) | `true` | `false`: disabled colours, no press, no focus. | | [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#id) | "" | Only for two buttons with one label. | | [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#style) | empty | Its look. | | `on_click`, `on_hover`, `on_unhover`, `on_press`, `on_release`, `on_focus`, `on_blur` | empty | See the table above. | [`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#show) is `true` on the frame it was clicked; [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#hovered), [`pressed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#pressed) and [`focused()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html#focused) say what it is doing now. An icon-only button has no padding and is the size of its picture, as [`image_button()`](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#an-image-you-can-press) is. ### Label [`rmp::ui::Label`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html) 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`: ```cpp rmp::ui::Label credits{ .text = "Credits", .color = rmp::ui::ColorRole::MUTED, .on_click = [] { rmp::ui::notify("Made with raylib"); } }; ``` Its fields: [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#text); [`color`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#color), a `ColorRole` used when the style sets no text colour; [`size`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#size) and [`wrap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#wrap), as `TextOptions` has them; [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#id); [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#style); and `on_click`, `on_hover`, `on_unhover`. [`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#show) is `true` on the frame it was clicked, and [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html#hovered) says whether the pointer is on it. ### Image [`rmp::ui::Image`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html) is a picture with a style — a frame behind it, a shadow, a tint — that can be clicked. With a [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#sprite) that has a sheet, it plays the sprite's animation, one step of the game's clock every `show()`: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#picture) | none | What it shows, unless `sprite` has a texture or a sheet. | | [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#sprite) | none | An animated picture, advanced every `show()`. | | [`grow`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#grow) | `false` | Fill the space available, as `ImageOptions::grow`. | | [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#width), [`height`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#height) | 0 | Above 0, a fixed size in design units; 0, the picture's own. | | [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#enabled) | `true` | `false`: never clicked. | | [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#id) | "" | Its id; images have no label to go by. | | [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#show) is `true` on the frame it was clicked; [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#hovered) and [`pressed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html#pressed) say what it is doing. ### Panel [`rmp::ui::Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) is a container with a look of its own, [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#style), and a look for everything inside it, [`children`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#children) — see [a look for everything inside a container](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#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. ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#row) | `false` | Its children left to right; `false`, top to bottom. | | [`box`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#box) | fit | Its layout — sizing, padding, gap, alignment — as `panel()` takes it. | | [`background`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#background) | `true` | `false`: a bare row or column, with no fill unless its style gives one, that still styles its children. | | [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#id) | "" | Its id: one per clickable panel, so each is told apart. | | [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#style), [`children`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#show) lays it out with `body` inside it and is `true` on the frame it was clicked; [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#hovered) and [`pressed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#pressed) say what it is doing. ### Checkbox, Slider, Dropdown, TextInput 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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html) | [`checked`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#checked) (`false`) | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#text), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html#style) | | [`Slider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html) | [`value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#value) (0), kept from [`min`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#min) (0) to [`max`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#max) (1) | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#text), [`step`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#step), [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#width), [`show_value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#show_value), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html#style) | | [`Dropdown`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html) | [`selected`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#selected) (0), an index into [`items`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#items) | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#text), [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#width), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html#style) | | [`TextInput`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html) | [`value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#value) (""), what is typed | [`text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#text) (its label), [`placeholder`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#placeholder), [`max_length`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#max_length), [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#width), [`enabled`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#enabled), [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html#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. ### ProgressBar [`rmp::ui::ProgressBar`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html) is a bar with a look of its own: the style is the track's — its background, its skin — and [`fill`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill) and [`fill_picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill_picture) are the bar's. A nine-slice as the fill stretches with the bar and keeps its ends: ```cpp rmp::ui::ProgressBar hp{ .value = health, .width = 200, .fill_picture = bar_art }; hp.show(); ``` | Field | Default | Is | |---|---|---| | [`value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#value) | 0 | From 0 to 1, clamped. | | [`width`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#width) | 0 | In design units; 0 fills the space available. | | [`height`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#height) | -1 | -1 is from the type size. | | [`radius`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#radius) | -1 | -1 is round ends. | | [`fill`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill) | none | The bar's colour; none is the theme's `primary`. | | [`fill_picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#fill_picture) | none | The filled part as a picture, tinted by the style's `tint`. | | [`id`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#id), [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#style) | | As every other. | | `on_hover`, `on_unhover` | empty | A bar is never pressed. | [`show()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#show) returns nothing, and [`hovered()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html#hovered) says whether the pointer is on it: what a bar's tooltip needs. ## Events Everything a control does, as it happens, is an [`Event`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event): the pointer arriving and leaving, a press, a click, the focus coming and going, a value changing. The [sounds](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#sounds) of the theme and of a style play on these; [`on_event()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp rmp::ui::on_event([](const rmp::ui::Event &e) { if (e.kind == rmp::ui::EventKind::CLICK) ++clicks; }); ``` An event has three fields: [`kind`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event-kind), what happened; [`widget`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event-widget), a [`WidgetKind`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#WidgetKind) — `BUTTON`, `LABEL`, `IMAGE`, `PANEL`, `CHECKBOX`, `SLIDER`, `DROPDOWN`, `TEXT_INPUT` or `PROGRESS`; and [`name`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Event-name), the control's label, or its id when it has one, valid during the call only. | [`EventKind`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ============================================================================== # Interface style > Themes as plain data, variants that say what a button means, sizes as steps of a type scale, colour transitions, breakpoints for the shape of a layout, styles per widget, pictures, nine-slices and skins, shadows and outlines, motion, sounds, and the fonts the interface draws with. Source: 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#styles) says so for that widget and everything inside it, over the theme, and the simple calls stay as they are. The light theme and button variants — [examples/ui/06_style](https://omardev29.github.io/rmp-docs/examples/ui/06_style.html) A skin: pictures, nine-slices and a font of the game — [examples/ui/09_skinned](https://omardev29.github.io/rmp-docs/examples/ui/09_skinned.html) ```cpp 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 }); ``` ## Themes A [`rmp::ui::Theme`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#current_theme) returns the one theme in use, and [`set_theme()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#theme_dark) and [`theme_light()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`: ```toml [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: ```toml [ui] theme = "blue" ``` ```text 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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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. ## Colours Each colour of the theme has a job, and these are all of them: | Field | Paints | |---|---| | [`background`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-panel) | A panel, and a dropdown's open list. | | [`surface`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-surface_hover), [`surface_press`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-border) | An outline button, an unticked checkbox, a dropdown's open list; and normal buttons and panels when `border_width` is above 0. | | [`text`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-text) | Text, the labels of normal, outline and ghost buttons and of every control. | | [`text_muted`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-text_muted) | Muted text, a slider's percentage, a text field's placeholder. | | [`text_on_accent`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-text_on_accent) | The label of a primary or danger button, and the dot of a ticked checkbox. | | [`primary`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-primary), [`primary_hover`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-primary_hover), [`primary_press`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-danger), [`danger_hover`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-danger_hover), [`danger_press`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-danger_press) | A danger button in its three states; also danger text. | | [`disabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-disabled), [`disabled_text`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ColorRole), never a colour of its own: `TEXT` is `text`, `MUTED` is `text_muted`, `PRIMARY` is `primary` and `DANGER` is `danger`. ## Variants A button's `style` is a [`Variant`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Variant): what the button is for, not what colour it is. | Variant | For | Looks | |---|---|---| | [`NORMAL`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Variant-NORMAL) | Most buttons; the default. | A filled `surface`. | | [`PRIMARY`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Variant-PRIMARY) | The one thing you want pressed on this screen. | `primary`, with `text_on_accent`. | | [`DANGER`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Variant-DANGER) | Something destructive, which should look it. | `danger`, with `text_on_accent`. | | [`OUTLINE`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Variant-OUTLINE) | A secondary action. | An outline and a label; it fills in under the pointer. | | [`GHOST`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Variant-GHOST) | Toolbars, "back" links. | The label alone, in either theme, until the pointer is on it. | ```cpp 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`. ## Sizes 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: ```cpp rmp::ui::button("Play", { .size = rmp::ui::Size::LARGE }); rmp::ui::text("Chapter One", { .size = 34 }); ``` | Step | Theme field | Default | |---|---|---| | [`Size::SMALL`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Size-SMALL) | [`font_size_small`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-font_size_small) | 0.8 × `[ui] font_size` | | [`Size::MEDIUM`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Size-MEDIUM) | [`font_size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-font_size) | `[ui] font_size`, 20 unless set | | [`Size::LARGE`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Size-LARGE) | [`font_size_large`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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: ```cpp 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); ``` ## Metrics The rest of the theme is measurements, every one in design units: | Field | Default | Is | |---|---|---| | [`padding_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-padding_x) | 20 | Inside a button, left and right of the label. | | [`padding_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-padding_y) | 12 | Inside a button, above and below it. | | [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-gap) | 12 | Between siblings. | | [`panel_padding`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-panel_padding) | 20 | Inside a panel, and around what `begin()` lays out. | | [`corner_radius`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-corner_radius) | 8 | Of buttons, panels and the controls' fields; 0 is square. | | [`border_width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-border_width) | 0 dark, 1 light | The outline of normal buttons and of panels; 0 draws none. | | [`control_size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-control_size) | 22 | A checkbox's box, and the height of a slider's drag area. | | [`track_thickness`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-track_thickness) | 6 | A slider's rail. | | [`focus_ring`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-focus_ring) | 2 | The outline on the focused control. | | [`min_touch_size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-transition) | 0.12 | Seconds, not design units: how long a colour takes to change. See below. | ## Transitions 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#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: ```cpp rmp::ui::Theme theme = rmp::ui::current_theme(); theme.transition = reduce_motion ? 0.0f : 0.12f; rmp::ui::set_theme(theme); ``` ## Breakpoints and scale Two mechanisms make an interface fit a screen, and knowing which to reach for is most of the skill. The [scale](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#scale-and-design-units) 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. ```cpp if (rmp::ui::compact()) { rmp::ui::column([&] { sidebar(); content(); }); } else { rmp::ui::row([&] { sidebar(); content(); }); } ``` [`current_breakpoint()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#current_breakpoint) classifies the screen by its **aspect ratio**, width over height, and [`compact()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#compact) is the case that comes up: | Breakpoint | Width ÷ height | In practice | |---|---|---| | [`COMPACT`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Breakpoint-COMPACT) | below 1 | A phone held upright, a narrow window. | | [`MEDIUM`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Breakpoint-MEDIUM) | 1 up to 1.6 | A tablet, a small desktop window, 4:3. | | [`EXPANDED`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Breakpoint-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`](https://omardev29.github.io/rmp-docs/manual/core/app.html#a-window-of-another-size) `"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](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) turns a sidebar and its content from a row into a column as the window is resized. ## Styles A [`rmp::ui::Style`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#widgets-you-keep) has one in its `style` field: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-background_hover) | `Color` | The fill under the pointer. Given without a `background`, it is used alone over the theme's fill. | | [`background_press`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-background_press) | `Color` | The fill while held down; alone too, like the one above. | | [`background_disabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-background_disabled) | `Color` | The fill when `enabled` is false. | | [`skin`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-skin) | [`Skin`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin) | Pictures instead of the fill, one per state. See [skins](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#skins). | | [`tint`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-tint) | `Color` | Multiplies the colours of a skin or an image; `WHITE` leaves them as drawn. | | [`border`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-border) | `Color` | The outline's colour, drawn when `border_width` is above 0. | | [`border_width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-border_width) | `float` | The outline's width in design units; 0 draws none. | | [`radius`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-radius) | `float` | The corners, in design units; 0 is square. | | [`shadow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-shadow) | [`Shadow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Shadow) | A soft shadow under the box. See [shadows and outlines](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#shadows-and-outlines). | | [`padding_x`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-padding_x) | `float` | Inside, left and right, in design units. On a panel it is its padding all round. | | [`padding_y`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-padding_y) | `float` | Inside, above and below. | | [`gap`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-gap) | `float` | Between the children of a container. | | [`text`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-text) | `Color` | The colour of its text, over the role a call gives it. | | [`text_disabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-text_disabled) | `Color` | The same, when `enabled` is false. | | [`font`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-font) | [`rmp::Font`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Font) | A font you loaded. The interface draws with that font's *file*; see [fonts](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#fonts). An empty one is inherited. | | [`font_size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-font_size) | `float` | What `Size::MEDIUM` is here, in design units. `SMALL` and `LARGE` follow it, in proportion. | | [`text_outline`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-text_outline) | [`TextOutline`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOutline) | An outline around every letter. | | [`text_shadow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-text_shadow) | [`TextShadow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextShadow) | A copy of the text under it, offset. | | [`motion`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-motion) | [`Motion`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion) | How it moves under the pointer, as it appears and when it shakes. See [motion](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#motion). | | [`sounds`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-sounds) | [`Sounds`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds) | A sound per event. See [sounds](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#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. ### Where a style comes from A field a widget's own style leaves unset is looked for, in this order, and the first that sets it wins: 1. the widget's own `style`; 2. the `children` style of the [`Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html)s it is inside, the nearest first; 3. the theme's style for its kind of widget, [`Theme::styles`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-styles); 4. the theme's own colours and metrics, as the rest of this page describes them. Inside a widget, [`current_theme()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ### One style for every widget of a kind [`Theme::styles`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-sounds) and [`motion`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Theme-motion): silent. ```cpp 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 look for everything inside a container A kept [`Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) has two styles, the way a Godot container has its own theme override and one for its children: [`style`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#style) is how the panel itself looks, and [`children`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#children) is a style every widget inside it inherits, however deep. Panels nest, and the nearest one's wins: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html#background) 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 number that is no number 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. ## Pictures 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html), and a picture is made from whatever you have, without naming it: | From | Is | |---|---| | an [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) | The whole texture. | | `{ texture, Rectangle{ … } }` | A part of it: an atlas, a sheet laid out by hand. | | an [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) | 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html), which plays it. | | a [`NineSlice`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice) | A picture that stretches by its middle. See below. | | [`slice(sheet, name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#slice) | A slice of an Aseprite file, by its name. | ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#size) is its size in pixels of the source, and [`sliced()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#sliced) is true when it has nine-slice margins. Its fields are public — [`texture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#texture), [`sheet`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#sheet), [`source`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#source), the margins [`left`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#left), [`top`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#top), [`right`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#right), [`bottom`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#bottom) and [`slice_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html#slice_scale) — but one of the constructors normally sets them. ### Nine-slices A [`NineSlice`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-texture) | empty | The picture. | | [`sheet`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-sheet) | empty | Or an Aseprite sheet's texture, when `texture` is empty. | | [`source`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-source) | all of it | The part of the texture to cut, in pixels. | | [`left`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-left), [`top`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-top), [`right`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-right), [`bottom`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-bottom) | 0 | The margins, in pixels of the source. | | [`scale`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#NineSlice-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. ### Slices of an Aseprite file 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#slice) 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#nine_slice) is the same slice as a `NineSlice`, to change its scale or keep it: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html#slices); [sprites](https://omardev29.github.io/rmp-docs/manual/modules/sprites.html#slices) says what is read from the file. ### An image you can press [`rmp::ui::image_button`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp if (rmp::ui::image_button(gear)) open_settings(); if (rmp::ui::image_button(gear, { .width = 64, .height = 64, .id = "settings" })) open_settings(); ``` [`ImageButtonOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageButtonOptions): [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageButtonOptions-width) and [`height`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageButtonOptions-height) in design units, 0 for the picture's own size; [`enabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageButtonOptions-enabled); and [`id`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageButtonOptions-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. ## Skins A [`Skin`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin) is pictures instead of a flat fill, one per state. Only [`normal`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin-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: ```cpp const rmp::ui::Style wooden{ .skin = rmp::ui::Skin{ .normal = up, .press = down } }; ``` | Field | Shown | When it is missing | |---|---|---| | [`normal`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin-normal) | at rest | no skin at all: the theme's fill | | [`hover`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin-hover) | under the pointer | `normal`, drawn a second time on top, faintly, to light it | | [`press`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin-press) | held down | `normal`, darker | | [`disabled`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin-disabled) | `enabled = false` | `normal`, grey and a little transparent | | [`focus`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Skin-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. ## Shadows and outlines A [`Shadow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp const rmp::ui::Style card{ .shadow = rmp::ui::Shadow{ .offset = { 0, 6 }, .blur = 12 } }; ``` | Field | Default | Is | |---|---|---| | [`offset`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Shadow-offset) | `{ 0, 4 }` | Where it falls, in design units: down a little, as light from above. | | [`blur`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Shadow-blur) | 8 | How far it fades out past the box; 0 is one hard shadow. | | [`spread`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Shadow-spread) | 0 | How much bigger than the box it is before it fades. | | [`color`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Shadow-color) | black at 90 of 255 | Its colour at the box. | Text has two of its own. A [`TextOutline`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOutline) draws copies of the text around it, so a title reads over any background — [`width`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOutline-width) in design units (1 by default; keep it from 1 to 3, every copy is drawn), [`color`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextOutline-color) black. A [`TextShadow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextShadow) is one copy under it — [`offset`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextShadow-offset) `{ 1, 2 }` design units, [`color`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#TextShadow-color) black at 160 of 255. A box's own outline is `border` and `border_width`. ```cpp 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{} } }; ``` ## Motion A [`Motion`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion) is movement. The framework's themes have a little of it, in [their styles](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#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. ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-hover_scale) | 1 | How big under the pointer: 1.05 is 5 % bigger. | | [`press_scale`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-press_scale) | 1 | How big while held: 0.95 is 5 % smaller. | | [`hover_lift`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-speed) | 0.12 | Seconds hover and press take to get there. | | [`appear`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-appear_offset) | 0 | How far below it starts as it appears, in design units, sliding up. | | [`appear_scale`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-appear_scale) | 1 | How big it starts as it appears, growing to 1. | | [`shake`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-shake) | 0.4 | Seconds a `shake()` lasts. | | [`shake_strength`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Motion-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. ## Sounds A [`Sounds`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds) names a sound for each thing a control does, by the name [`rmp::audio::play()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-hover) | the pointer arrives on a control | | [`press`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-press) | the pointer goes down on it | | [`release`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-release) | …and comes up | | [`click`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-click) | it is pressed: the pointer, Enter, the gamepad's A button | | [`focus`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-focus) | the keyboard or gamepad focus arrives | | [`change`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-change) | a checkbox, slider, dropdown or text field changes its value | | [`open`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-open) | a dropdown opens its list | | [`close`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-close) | …and closes it | | [`shake`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-shake) | a widget's `shake()` starts | | [`volume`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Sounds-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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-SoundName.html), written as a string — a literal, a `std::string` or a `std::string_view`, copied — with [`view()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-SoundName.html#view) to read it, [`empty()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-SoundName.html#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](https://omardev29.github.io/rmp-docs/manual/modules/audio.html) 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()`](https://omardev29.github.io/rmp-docs/manual/modules/ui-controls.html#events). ## Fonts 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](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#scale-and-design-units). 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: ```toml [ui] font = "ui.ttf" font_size = 24 ``` `font_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. ### Changing it while the game runs [`set_font()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#font_name) says which it is now. A language with other letters, an accessibility setting for a plainer face: ```cpp rmp::ui::set_font(dyslexia_friendly ? "plain.ttf" : "ui.ttf"); ``` ### A font for one widget [`Style::font`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style-font) gives one widget, or everything in a panel, a font of its own: one the game loaded with [`rmp::assets::load_font`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#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: ```cpp 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 } }; ``` ### Every letter, on demand 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`. ============================================================================== # Assets > Put your files in resources/ and load them by name; the handles count themselves, free themselves, and read the same from loose files or from an encrypted pack. Source: 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. ## Loading by name Everything in [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) 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: ```cpp 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_texture) | [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) | A picture on the GPU, to draw. | | [`load_image(name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_image) | [`rmp::Image`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Image) | A picture in memory, to read pixels from or make a texture out of. | | [`load_font(name, size)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_font) | [`rmp::Font`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Font) | A `.ttf` or `.otf`, baked at one size, from 1 to 1024. | | [`load_sound(name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_sound) | [`rmp::Sound`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Sound) | A short sound, decoded into memory. Most games play sounds by name with [rmp::audio](https://omardev29.github.io/rmp-docs/manual/modules/audio.html) instead. | | [`load_sheet(name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_sheet) | [`rmp::SpriteSheet`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SpriteSheet) | An Aseprite file, with its frames and tags. See [Sprites](https://omardev29.github.io/rmp-docs/manual/modules/sprites.html). | | [`load_map(name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_map) | [`rmp::Tilemap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html) | A level made in LDtk or Tiled. See [Tilemaps](https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html). | | [`load_data(name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_data) | `std::vector` | The bytes of any other file. | ```cpp 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 dialogue = rmp::assets::load_data("dialogue.json"); ``` ### A name is a path below resources/ 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. ```cpp 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. ### The fonts are baked at a size 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#every-letter-on-demand). ## The handles `rmp::Texture`, `rmp::Image`, `rmp::Font` and `rmp::Sound` are the same thing for different raylib types: a [counted reference](https://omardev29.github.io/rmp-docs/reference/classes/rmp-detail-Resource.html) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html) — the texture, the frames and the tags of an `.aseprite` — and converts to that. ### Copies share 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: ```cpp 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 it ``` That 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. ### When they free 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-detail-Resource.html#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. Does not compile ```cpp 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. ### Handles that are empty A handle can hold nothing: one that was never assigned, one that was moved from, and one whose load failed. [`valid()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-detail-Resource.html#valid) says which, and so does the handle in an `if`: ```cpp 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. ### What is not a handle 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](https://omardev29.github.io/rmp-docs/manual/modules/audio.html). 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. ## Any other file: load_data 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. ```cpp const std::vector 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. ## JSON: load_value Tuning numbers, a table of items, the lines of a dialogue: a JSON file in `resources/` is read into an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html), the same value a [save](https://omardev29.github.io/rmp-docs/manual/modules/saving.html) is, with [`load_value()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#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. ```cpp 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); ``` ## Hot reload 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#changed) says when that file is different from what was read — a number tuned, a sprite redrawn and saved in any editor — and [`reload()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#reload) reads it again. Nothing is read behind the game's back: the game asks, and decides when. ```cpp 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. - **A file half saved is not a change made.** A file that is not JSON now, or a picture that does not decode, leaves the Value or the texture as it was; `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. - **Only the desktop's Debug build watches.** A release reads its resources from the pack, which does not change; a phone and a browser have no file anyone edits. There, and with the pack open in a Debug build (`rmp pack`), `changed()` is always `false` and costs nothing. - **What has no file never changes.** A Value made in code, read from a save, or taken out of another — `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. ## Plain raylib works too 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: ```cpp 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 exceptionraylib's `LoadMusicStream()` opens the file itself and never sees the pack, so a song loaded that way exists only as a loose file. `rmp::audio::music("song")` reads it through the pack like everything else. ## Where resources/ is 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. ## The pack 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](https://github.com/raysan5/rres), by raylib's author, and the packer is part of the framework, so nothing has to be installed or bought. ```shell 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 again ``` At 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: - `ASSETS: Using resource pack … (… entries)` - `ASSETS: No resource pack found, using loose files from …` - `ASSETS: … is cut short or corrupt, using loose files` [`rmp::assets::using_pack()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#init) before the first scene, which finds the pack, and [`rmp::assets::shutdown()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#shutdown) after the last. ### The loose files are the fallback 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. ### Which releases ship it 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 password 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: ```toml [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: ```toml [resources] rres_password = "" ``` ```text 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. What the encryption is for It stops someone opening your game's folder and copying the art out of it. It does not stop someone determined: the password is inside the executable you give them, the names of the files in the pack are stored in the clear, and on the releases that ship loose files there is no encryption at all. It is a lock on the door, not a safe. `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. ## When a load fails 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#requested_loads) is how many loads the game asked for, and [`failed_loads()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#failed_loads) how many of them failed, which means: - a name that is neither in the pack nor in the folder; - a file that is there and does not decode: a picture, and so a texture made from it, a sound, a font, or a song that [rmp::audio](https://omardev29.github.io/rmp-docs/manual/modules/audio.html) cannot stream; - an `.aseprite` file that cannot be read as one; - a map file that does not parse, or a Tiled map whose tileset file cannot be read. 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. ### How CI notices 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. ============================================================================== # Sprites > What an object looks like: a texture, or an Aseprite file whose tags are the animations you play by name. Source: https://omardev29.github.io/rmp-docs/manual/modules/sprites.html An object's [`sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ## A picture Give the sprite a texture and the object draws it, centred on its position and turned, scaled and flipped with it: ```cpp sprite.texture = rmp::assets::load_texture("ship.png"); ``` An object with a sprite draws the sprite; one without draws its [`shape`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#shape). The rest of [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) says how the picture is put on the screen: | Field | Default | Means | |---|---|---| | [`texture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#texture) | empty | A loose picture, for an object that does not animate. | | [`sheet`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#sheet) | empty | An Aseprite sheet. When there is one, it is drawn and `texture` is not. | | [`source`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#size) | `{0,0}` | The size to draw at, before the object's `scale`; the picture's own size when empty. | | [`tint`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#tint) | `WHITE` | Multiplies the picture's colours. White leaves them alone; its alpha fades the picture. | | [`speed`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#scale) multiplies its size, [`rotation`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#rotation) turns it, [`flip_x`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#flip_x) and [`flip_y`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#flip_y) mirror it, [`visible`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#visible) hides it without taking the object out of the game, and [`layer`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#layer) decides what is drawn on top of what. ### Flipping and tinting 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. ```cpp 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: ```cpp sprite.tint = RED; // the hit flash sprite.tint = Fade(WHITE, 0.5f); // half transparent, colours unchanged sprite.tint = WHITE; // back to the picture as drawn ``` ### One frame of a bigger picture A 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: ```cpp sprite.texture = rmp::assets::load_texture("items.png"); sprite.source = Rectangle{ 32, 0, 16, 16 }; // the third 16-pixel icon of the first row ``` For anything that animates, use a sheet instead: it knows its own frames and how long each one lasts. ## An animated sheet [`rmp::assets::load_sheet()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_sheet) reads an `.aseprite` or `.ase` file, and [`play()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#play) starts one of its animations by name: ```cpp 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. ### Choosing the animation every frame `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. ```cpp 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](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) does exactly this for its player, with a `hurt` tag on top and the art turned to face the way it moves: [player.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/objects/player.cpp#L64-L76). ### Once, and then stop 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#finished) turns true: ```cpp 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. ### The rest of the clock [`playing()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#playing) The name of the tag last started with `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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#stop) Holds the current frame, as a finished animation does. [`frame_index()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#frame_index) and [`set_frame(i)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#set_frame) The frame showing, as an index into the whole sheet, and a way to put it somewhere. A sheet nobody called `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. [`speed`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#speed) Multiplies how fast the frames go by: 2 shows each for half its time. Negative plays the tag backwards. The 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. ## The Aseprite workflow [Aseprite](https://www.aseprite.org/) files are read directly; there is no export step and no JSON beside the picture. The whole of the workflow is: 1. Draw the frames on one canvas. The canvas is the size of every frame. 2. Set each frame's duration (Frame Properties). That time, in milliseconds, is how long the frame shows in the game. 3. Tag each animation: select its frames and add a tag with the name you will pass to `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. 4. Save the `.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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SheetTag-name) of each [`rmp::SheetTag`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ### Slices 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html#slices), in the file's order, up to 256 of them. Each [`rmp::SheetSlice`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SheetSlice) has its [`name`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SheetSlice-name); its [`bounds`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SheetSlice-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SheetSlice-nine) set and its middle in [`center`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#SheetSlice-center), relative to the bounds. [`slice(name)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html#slice) finds one — the first, when two share a name — or an empty one, and [`slice_count()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html#slice_count) says how many there are. ```cpp 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html#slices-of-an-aseprite-file). ### Directions from movement The [`rmp::behavior::TopDown`](https://omardev29.github.io/rmp-docs/reference/behaviors/TopDown.html) 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](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html#topdown) has the rest. ## Collision and the picture An object with no `shape` and no [`collider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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: ```cpp 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 frame ``` ## When something is wrong A 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: ```toml [dev] strict = true ``` A 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](https://omardev29.github.io/rmp-docs/manual/modules/assets.html#when-a-load-fails): `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. ============================================================================== # Tilemaps > Levels designed in LDtk (or Tiled): the scene draws the map, stops solid objects at its walls, and turns what you placed in the editor into objects. Source: 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. A level made in LDtk — [examples/games/07_platformer](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) Only what the camera shows is drawn — [examples/games/08_dungeon](https://omardev29.github.io/rmp-docs/examples/games/08_dungeon.html) ## Loading a level The map is a field of the scene. Assign it in `_ready()`: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_map) picks the reader by the file's extension: | File | Editor | Status | |---|---|---| | `.ldtk` | [LDtk](https://ldtk.io) | The one the framework tests and keeps up to date. | | `.json` | [Tiled](https://www.mapeditor.org/) | 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html) 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. ## What the scene does with it Draws it Underneath every object, layer by layer from the bottom, inside the scene's [`camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. Stops solid objects at its solid cells An object that is [`solid`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#solid) and not [`immovable`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Platformer.html) behavior counts the floor as ground. A coin, a trigger, a bullet or a platform the game moves by hand is not stopped. Becomes the edge of the world An object whose [`edges`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#edges) say what to do at the edge of the world — clamp, bounce, wrap — and whose [`bounds`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ## Levels from LDtk An LDtk project can hold many levels. Without a name, `load_map()` loads the first; with one, it loads the level of that identifier: ```cpp 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. ### Setting up the project - **Images next to it.** The tileset images go in `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 cells.** An IntGrid layer value whose identifier is `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`. - **Layers.** Tiles, AutoLayer, and IntGrid layers with an auto-layer ruleset are drawn, bottom to top, each with its own grid size, offset and opacity, every tile flipped and faded as LDtk placed it. A layer hidden in LDtk is not drawn and is still solid, which is the shape of a collision layer nobody needs to see. - **Levels in separate files.** With "Save levels to separate files" on, each level is a `.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`. - **The format.** The reader follows the JSON format of LDtk 1.5 and later. A project saved by an older LDtk is read anyway and says once that saving it again in a current LDtk is the fix. Not read: level backgrounds, parallax, IntGrid values other than `solid`, and the fields of a level itself. ### The world In LDtk's GridVania and Free layouts every level has a place in one world, and the map keeps it: [`bounds()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#neighbour_at) 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: ```cpp 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({ .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(std::string(next), _player->position); } std::string _name; Vector2 _arrival; rmp::Handle _player; }; ``` Both answers are `std::string_view`s 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#level) is the identifier of the level loaded. The platformer in [examples/games/07_platformer](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) is a world of three levels side by side in a GridVania layout, walked through exactly like this: [level.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/scenes/level.cpp#L140-L148). ## Objects from the editor An LDtk entity, or an object on a Tiled object layer, is a [`rmp::MapObject`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html): a type, a position, a size and a set of properties. A factory says what to make of each type, and [`spawn_objects()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#spawn_objects) runs them all: ```cpp 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({ .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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#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. - A second factory for the same type replaces the first. Two factories for one type is never what anybody means, and running both would spawn the object twice. - The position is the **centre**, as it is for every [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html). The editors give a corner or a pivot; the conversion is done once, when the map is read, so no factory has to. ### Properties 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#property_int); a float is cut towards zero | | Float | float | [`property_float(key, fallback)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#property_float); an int is read too | | Bool | bool | [`property_bool(key, fallback)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#property_bool) | | String, Multilines | string, file | [`property_string(key, fallback)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#property_string) | | 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#property_point): the world position of the centre of that cell | | Array | | `property_point(key, i)` for each `i` below [`property_count(key)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#property_count) | A point comes back in the same world units as `position`, so a patrol route drawn in LDtk is used as it comes: ```cpp map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) { auto &bat = s.spawn({ .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. ### Linking objects to each other Every LDtk entity has an [`iid`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html#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. ```cpp map.on_object("Key", [](rmp::Scene &s, const rmp::MapObject &o) { auto &key = s.spawn({ .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({ .position = o.position }); door.iid = o.iid; }); ``` The key and the door keep `std::string`s, and not what the map hands them: a `MapObject`'s names and the text of its properties are `std::string_view`s 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 `iid`s of what is gone in an [`rmp::global`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global) and skips them in its factories. ### Objects with no factory 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** object with an area — a rectangle drawn on an object layer — is solid. That is the right default for a wall or a platform drawn as a shape. - A Tiled point, or anything with no width or no height, is a marker and is not solid: an invisible collider at a spawn point is not what anybody drew. - An **LDtk** entity is never solid on its own. Its box is only how big it looks in the editor; walls in LDtk are IntGrid. ## Levels from Tiled A Tiled map is the `.json` Tiled saves. What the reader expects of it: - **CSV tile layers.** A map whose layers are compressed or base64 is refused, and the log says where the setting is: Map, Map Properties, Tile Layer Format, CSV. CSV is Tiled's default for a new map. - **Tilesets embedded, or saved as JSON.** A tileset kept in a `.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 tiles.** Every tile of a layer whose class is `solid` is solid; so is a tile the tileset gives a bool property `solid` set to true. - **Objects.** The object's class is its `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. ## Asking the map 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#solid_at) | Whether a solid cell is under a point, on any layer. | | [`solid_in(rect)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#solid_in) | 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#tile_at) | 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#bounds) | The level's rectangle in the world. | | [`tile_size()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#tile_size) | One cell of the map's grid. | | [`layer_count()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#layer_count), [`object_count()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#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: ```cpp // 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#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. ```cpp // 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()`](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html#pathfind) searches. ## A whole level, from the platformer [examples/games/07_platformer](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) 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: [examples/games/07_platformer/src/scenes/level.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/scenes/level.cpp#L1-L215) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include 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({ .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({ .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({ .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({ .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({ .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({ .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({ .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({ .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({ .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({ .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(); // 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(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(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(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(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(); rmp::ui::end(); } } // namespace game ``` ## When a map cannot be read A map that is missing or does not parse is an empty map: [`valid()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#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](https://omardev29.github.io/rmp-docs/manual/modules/assets.html#when-a-load-fails), and so does a tileset image that is not there or does not decode, so the boot check in CI sees them. ============================================================================== # Audio > Sound effects and music by name, three volume buses a settings screen can move, and a sound device that opens itself — or is quietly absent. Source: https://omardev29.github.io/rmp-docs/manual/modules/audio.html [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) 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. ## Playing a sound ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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](https://omardev29.github.io/rmp-docs/manual/modules/assets.html#the-pack) in a release and out of the folder while you work, like every other asset. ### How it sounds 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#PlayOptions-volume) | `1` | 0 to 1, for this play; multiplied by the `SFX` bus and by `MASTER`. | | [`pitch`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#PlayOptions-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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#PlayOptions-pan) | `0` | -1 is the left speaker, 0 the centre, 1 the right; clamped to that range. | ```cpp 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](https://omardev29.github.io/rmp-docs/manual/modules/random.html), it is also the same sequence of footsteps every run. ### Sounds overlap 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. ## Music ```cpp class LevelScene : public rmp::Scene { void _ready() override { rmp::audio::music("level1"); } }; ``` [`music()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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: ```cpp rmp::audio::music("victory", false); // once, then silence ``` [`stop_music()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#stop_music), or `music("")`, stops the music and lets the track go. [`music_playing()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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. ### Streamed, from memory 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. Not through raylibraylib's own `LoadMusicStream()` opens the file by itself and never sees the pack, so a song loaded that way is missing from a release that ships one. Play music with `rmp::audio::music()`. ## The files it reads | 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. ## Volume: three buses A settings screen offers three volumes, and those are the three buses of [`rmp::audio::Bus`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#Bus): `MASTER` Everything. `MUSIC` The music, under `MASTER`. `SFX` Every sound effect, under `MASTER`, 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]`: ```toml [audio] master = 1.0 music = 0.8 sfx = 1.0 ``` A 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: ```toml [audio] music = 1.5 ``` ```text 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#set_volume) moves a bus and [`volume()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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. ```cpp 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](https://omardev29.github.io/rmp-docs/manual/modules/saving.html), as [examples/ui/04_settings](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html) does. ## The sound device 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#available) says whether the device is open and working. It is false until the first sound, and asking does not open anything. ### A machine with no sound 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: ```toml [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. ### On the web 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. ## A sound you hold yourself For raylib's own sound functions there is a handle: `rmp::assets::load_sound()` returns an [`rmp::Sound`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Sound) that converts to raylib's `Sound`, opening the device first if it has to. ```cpp 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. ## When a sound is not there A name that finds no file, or finds one that does not decode, plays nothing, and says which of the two it was, once: - `AUDIO: no sound called "…" in resources/ (looked for …)` - `AUDIO: no music called "…" in resources/ (looked for …)` - `AUDIO: "…" is in resources/ but could not be decoded (raylib here reads .wav, .ogg, .mp3 and .qoa)` - `AUDIO: "…" is in resources/ but could not be streamed (raylib here reads .wav, .ogg, .mp3 and .qoa)` 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](https://omardev29.github.io/rmp-docs/manual/modules/assets.html#when-a-load-fails): 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. ============================================================================== # Saving > rmp::Value is a tree you fill and read with defaults; rmp::save writes it to a file that survives crashes, tells edited from damaged, and lands in the right folder on every platform. Source: https://omardev29.github.io/rmp-docs/manual/modules/saving.html A save is a [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) — a tree of numbers, strings, lists and objects — written to a slot with [`rmp::save::write()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#write) and read back with [`rmp::save::read()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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. ```cpp 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: ```cpp 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 read ``` There 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. ## rmp::Value A Value is one of six things — exactly what JSON can hold, so a real structure fits and not only flat pairs: | [`Type`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#as_bool) | | `NUMBER` | a `double`: every integer up to 253 is exact | [`as_int(fallback)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#as_int), [`as_float(fallback)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#as_float) | | `STRING` | text | [`as_string(fallback)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#as_string) | | `LIST` | Values in order | `v[i]`, [`size()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#size) | | `OBJECT` | keys naming Values, in the order they were added | `v["key"]`, [`contains()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#contains), [`key(i)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#key) | Assigning makes the Value what was assigned, and assigning through a key or an index makes whatever path leads there: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#list) and [`rmp::Value::object()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#object) make an empty one of each; [`push()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#push) appends to a list, and turns a Value that holds nothing into one first. [`erase(key)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#erase) 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()`](https://omardev29.github.io/rmp-docs/manual/modules/assets.html#json-load_value), which remembers the file, so a Debug build can [reload](https://omardev29.github.io/rmp-docs/manual/modules/assets.html#hot-reload) it while the game runs. ### Reading never creates anything 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`: ```cpp rmp::Value v; const int coins = v["stats"]["coins"].as_int(0); // 0, and v is still empty ``` That 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. ### A write that cannot land 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. ### Walking a Value you did not write Reading a save never needs [`type()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#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)`: ```cpp rmp::Value v; rmp::save::read("slot1", v); const rmp::Value &items = v["inventory"]; std::vector 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. ## Writing and reading [`write(slot, value)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#write) 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. ### What a read tells you [`read(slot, value)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#read) fills the Value you hand it, by reference, and returns a [`Result`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#Result) that is true in an `if` only when the save was read and checked. When it is false, [`status`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#Result-status) says why, because each reason is a different thing to tell a player: | [`Status`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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. ```cpp 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](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html) does. ### Slots, and where they are [`exists(slot)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#exists) Whether there is a save in that slot — what decides if a title screen offers "Continue". It does not open the file, so a damaged save exists too. [`remove(slot)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#remove) Deletes it. False when there was nothing to delete. [`directory()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#directory) The folder saves are written to this session, with a trailing separator. ## Where saves go 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%\\` | | macOS | `~/Library/Application Support//` | | Linux and the BSDs | `$XDG_DATA_HOME//` when that is set to an absolute path, otherwise `~/.local/share//` | | 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. ### Portable saves 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. ## The .toml ```toml [save] portable = false encrypt = false version = 1 ``` `portable` Saves next to the executable, as above. Off by default: the user's data folder is what installers and Steam Cloud expect. `encrypt` Whether `write()` seals the file by default. See below. `version` The version of *your* save format, a whole number from 1 up, stored in every file. Nothing in `[save]` is a secret, and there is no password to put there; a key the section does not have is refused: ```toml [save] password = "hunter2" ``` ```text raylib_multiplatform.toml:2: password = "hunter2" ^^^^^^^^^^^^^^^^^^^^ configure: error: unknown key [save.password] in raylib_multiplatform.toml ``` ### Changing what a save means Most 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#version), and the game moves the old meaning to the new one as it reads: ```cpp 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. ```toml [save] version = 2 ``` The version is a counter that only goes up, from 1: ```toml [save] version = 0 ``` ```text 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. ``` ## Sealed saves 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: ```cpp 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: ```cpp rmp::save::read("slot1", v, { .sealed_only = false }); ``` What sealing is forIt stops a player opening the file and giving themselves a thousand coins, and it catches an edit even when whoever made it knew to fix the checksum. It is not security: the key is derived from `[project] name` and lives in the game you hand out, and nothing stops someone determined. Because the key comes from the name, games with different names cannot read each other's sealed saves — and **renaming the project makes the old sealed saves unreadable**: they read as `MODIFIED`. 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. ## The file Every save is one line of ASCII, then the payload: ```text rmp-save 1 {"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. ============================================================================== # Localization > The game in more than one language: every text the framework draws is an rmp::Text, a literal translates itself from the game's tables, values go in placeholders, plurals follow each language's rules, and rmp text keeps the tables in step with the code. Source: https://omardev29.github.io/rmp-docs/manual/modules/localization.html Every text the framework draws is an [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html). 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: English — [examples/ui/11_localization](https://omardev29.github.io/rmp-docs/examples/ui/11_localization.html) Japanese, the same code — [examples/ui/11_localization](https://omardev29.github.io/rmp-docs/examples/ui/11_localization.html) ```cpp 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. ## A literal is translated, a runtime string is not 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: ```cpp 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 is ``` A 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. ## Values go in placeholders A text with a value in it keeps its key fixed by naming the value instead of printing it: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-TextArg.html) 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. ## Plurals 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](https://cldr.unicode.org/index/cldr-spec/plural-rules). The first number among the arguments chooses: ```cpp 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. ## The same words, two meanings "Open" a door and "Open" a file are one key in English and two words in many languages. A [`context`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#TextOptions) tells them apart: it is a column of the table, and two rows with the same key and different contexts are two texts. ```cpp 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. ## The tables Translations live in `resources/`, in tab-separated files, and the game can use either shape or both; they are merged when the game starts. - **One table, a column per language** — `lang.tsv` in `resources/` ([`[lang] file`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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: ```text 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ñol ``` - **One file per language** — `es.tsv` in a `lang` folder of `resources/` ([`[lang] folder`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ## Which language The game starts in the language the player chose last time, if [`rmp::lang::set()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html) is the rest: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#set) changes every screen at once — the next frame draws in it, nothing is reloaded — and saves the choice with [rmp::save](https://omardev29.github.io/rmp-docs/manual/modules/saving.html), so the next run starts in it. [`available()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#available) is `[lang] languages` in its order, or every column and file the tables have. [`translate()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#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. ## A font per language 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ui-font) lacks gets a font of its own: ```toml [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 menu of languages, each in its own letters 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style) names its font: ```cpp 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](https://omardev29.github.io/rmp-docs/manual/core/app.html)). [`examples/ui/11_localization`](https://omardev29.github.io/rmp-docs/examples/ui/11_localization.html) — 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. ## Keeping the tables in step: rmp text ```shell 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 wrong ``` `rmp 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](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#translation), 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ## What is not translated - The window's title, [`[window] title`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-title), which is the game's name. - Any string made while the game runs, as above. - Text the game draws with raylib itself (`DrawText()`); pass it through [`rmp::lang::translate()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#translate) first. ============================================================================== # Dialogue > Conversations written in Yarn Spinner 3 and run by rmp::Dialogue — lines, choices, variables, commands and functions from the game — shown by three presenters of the interface or by your own code, started by a Talker, translated like every other text, and compiled when the game loads or when it is built. Source: https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html A conversation is written in a `.yarn` file in `resources/`, in [Yarn Spinner](https://docs.yarnspinner.dev/)'s language, version 3, and run by an [`rmp::Dialogue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html). 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`. DialogueBox — [examples/ui/10_dialogue](https://omardev29.github.io/rmp-docs/examples/ui/10_dialogue.html) DialogueBubble — [examples/ui/10_dialogue](https://omardev29.github.io/rmp-docs/examples/ui/10_dialogue.html) DialogueStage — [examples/ui/10_dialogue](https://omardev29.github.io/rmp-docs/examples/ui/10_dialogue.html) ## A script ```text title: Start --- <> <> Mika: Welcome, traveller. #line:welcome #mood:happy <> Mika: Back again? #line:again <> Mika: I have not seen you before. #line:first <> <> Mika: What will it be? You have {$gold} gold. #line:ask -> Buy a [wave]potion[/wave] <= 5>> #line:buy <> <> Mika: A fine choice. #line:fine -> Ask about the tower #line:tower <> -> Leave #line:leave Mika: Safe travels. #line:safe === title: Tower --- Mika: [shake]Nobody[/shake] comes back from the tower. #line:nobody <> Mika: But you have the key... #line:key <> === ``` 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; `<>` 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](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#what-runs). ## Running it yourself ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_dialogue) reads and compiles the file. A script with a mistake gives a Dialogue that is not [`loaded()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#loaded), and [`errors()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#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: ```cpp 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: - **A line** — [`has_line()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#has_line). [`line()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#line) is an [`rmp::DialogueLine`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#advance) goes on. - **A choice** — [`has_options()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#has_options). [`options()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#options) are [`rmp::DialogueOption`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#DialogueOption)s, and one whose condition failed is there with `available` false: show it greyed out, or not at all. [`choose(i)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#choose) takes the one at that place. - **A command nobody handles** — [`has_command()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#has_command) and its text in [`command()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#command); the game does what it says and calls `advance()`. A command with a handler (below) never waits. [`running()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#running) is true from [`start()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#start) to the end of the conversation or a [`stop()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#stop), and [`node()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#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](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#talker). ## The game's commands and functions A script asks the game to do something with a command, `<>`, 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: ```cpp // has_item("key") in an expression: a string in, a bool out. talk.on_function("has_item", [](std::string item) -> bool { return carries(item); }); // <>: two words, as two strings. talk.on_command("walk", [](std::string who, std::string where) { walk_to(who, where); }); // <>: 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html), 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 `<>` a word that is not a number, is a mistake said once — in the log, on screen in a debug build, and in [`errors()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#errors) — and the call is not made. Write the result's type (`-> bool`): it is what [`rmp yarn ysls`](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#editors) tells the editor. The untyped forms take every argument as it comes, for a function or a command that takes any number of them: ```cpp talk.on_command("give", [](std::span words) { for (const std::string &item : words) give(item); // <> }); talk.on_function("sum", [](rmp::DialogueValue &result, std::span 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#has_command), for a game that reads [`command()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#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`](https://omardev29.github.io/rmp-docs/manual/modules/random.html), so a scripted run of the game is reproducible. There is no overloading: one name, one function. ### Checked before it runs [`start()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#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 `<>` names that is not there, a call of the wrong kind — is said the same way, once, and kept in `errors()`. [`rmp yarn check`](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#rmp-yarn) finds all of it before the game is even built. ## Commands that wait 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: ```cpp 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#wait) holds the dialogue for that long, and [`wait_until(done)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#wait_until) until `done()` is true; called anywhere else, either is a mistake said once. Yarn's own `<>` 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#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: ```cpp 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. ## Variables, and saving them ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#save) puts everything the conversation remembers — its variables, how many times each node was visited, which `<>` blocks and line groups have been seen — into an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html), and [`load()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#load) takes it back, so a conversation picks up where the player left it with [rmp::save](https://omardev29.github.io/rmp-docs/manual/modules/saving.html). A variable a script declares has the type of its declaration; one the game sets has the type of the value. ### The game's own variables 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. ```cpp 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(); }); ``` ```text <> You have {$gold} coins. <> ``` The script declares a bound variable, with the type it has (`<>`): 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#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](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#talker) has `on_load` for it. ## Showing it: the presenters The interface has three widgets that show a Dialogue, each kept in the scene and shown every frame between [`begin()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#begin) and [`end()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueBox.html) | 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DialogueBubble) | A bubble over the speaker's head, drawn in the world with [`rmp::ui::at()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#at) over the object each `BubbleSpeaker` names, the choices in it. | goes on | | [`DialogueStage`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueStage.html) | 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`](https://omardev29.github.io/rmp-docs/examples/ui/10_dialogue.html) 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. ### How a line is typed and goes on Every presenter has a [`flow`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DialogueFlow): - `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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Portrait) 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](https://omardev29.github.io/rmp-docs/manual/modules/ui-style.html) — 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 [`Style`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#Style)s 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 look and a voice for each speaker A [`Speaker`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ```cpp 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`. ### The box's layout ```cpp 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's tail 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. ### The stage's entrances, focus, shakes and flashes ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueStage.html#shake) shakes the whole stage, dying away, and [`flash()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueStage.html#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`. ### A presenter of your own When none of the three is the layout a game wants, it writes its own around the two pieces they are made of: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#DialogueMemory) is what they remember between frames: keep one, as a presenter does. ### Rich text The markup of a line is drawn a letter at a time by [`rmp::ui::rich_text()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#rich_text), which a game can use for any text of its own: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#rich_text_length). ## Someone to talk to: Talker [`rmp::behavior::Talker`](https://omardev29.github.io/rmp-docs/reference/behaviors/Talker.html) 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: ```cpp auto &mika = spawn({ .position = { 200, 120 }, .size = { 16, 16 } }); mika.add({ .dialogue = "wizard.yarn", .node = "Start", .range = 32, .player = player_handle, .on_talk = [](rmp::Dialogue &talk) { rmp::Scene::push(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](https://omardev29.github.io/rmp-docs/manual/core/behaviors.html). 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. ```cpp npc.add({ .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`](https://omardev29.github.io/rmp-docs/examples/games/09_after_school.html) 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 `<>` the dialogue waits on, a timed choice and three endings, in English and Spanish. ## Translated like every other text A line's `#line:` id is the key of its translation in the game's [tables](https://omardev29.github.io/rmp-docs/manual/modules/localization.html#tables), as `line:welcome`, and the `.yarn` holds the text in [`[lang] default`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ## Checking the scripts: rmp yarn check ```shell rmp yarn check # every resources/**/*.yarn rmp yarn check resources/intro.yarn # one ``` `rmp 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. ### In the editor The [Yarn Spinner extension for VS Code](https://marketplace.visualstudio.com/items?itemName=SecretLab.yarn-spinner) 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: ```shell 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. ```cpp // 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](https://github.com/mfussenegger/nvim-lint): ```text 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" } ``` ## Compiled when it loads, or when the game is built [`[dialogue] build`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ## Written in Ink ```shell python3 tools/ink_to_yarn.py story.ink resources/story.yarn ``` A story written in [Ink](https://www.inklestudios.com/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. ## What of Yarn runs 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html#set_saliency)); `<>`, `<>`, `<>` and `<>` with types, enums and smart variables; `<>`, `<>` and `<>`; 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](https://omardev29.github.io/rmp-docs/framework/maintaining/dialogue-and-text.html) is how that is kept so. ============================================================================== # Random > Random numbers you can reproduce: one seeded generator for the whole game, with the handful of shapes a game actually asks for. Source: https://omardev29.github.io/rmp-docs/manual/modules/random.html [`rmp::random`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html) 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. ## The numbers ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#value) | A float from 0 up to, never reaching, 1. | | [`range(min, max)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#range) 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#chance) | `true` with probability `p`: 0 is never, 1 is always. | | [`in_circle(radius)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#in_circle) | A point spread evenly over the whole disc, not bunched at the middle and not only on the rim. | | [`direction()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#direction) | A vector of length 1, pointing anywhere. | | [`index(count)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#index) | 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: Does not compile ```cpp 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)`. ### Picking and shuffling `index()` picks one of a list: ```cpp const std::vector greetings = { "Hello!", "Nice day.", "Watch out." }; const std::string &line = greetings[rmp::random::index(static_cast(greetings.size()))]; ``` and shuffles one, from the last element down, each swapped with one at or before it: ```cpp std::vector bag = { 0, 1, 2, 3, 4, 5, 6 }; for (int i = static_cast(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](https://omardev29.github.io/rmp-docs/examples/games/06_tetris.html): 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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/06_tetris/src/main.cpp#L221-L233)). [examples/games/03_space_invaders](https://omardev29.github.io/rmp-docs/examples/games/03_space_invaders.html) 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 seed 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#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: ```cpp TraceLog(LOG_INFO, "seed %llu", static_cast(rmp::random::current_seed())); ``` [`seed(n)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#seed) 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: ```cpp 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. ### What "the same run" takes 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html) 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. ### Tests are reproducible on their own 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](https://omardev29.github.io/rmp-docs/framework/testing.html#e2e), 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`. ## Why not rand() 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. Not for secretsA sequence you can reproduce from one number is a sequence someone else can predict. Nothing that has to be unguessable — a token, a password, shuffling cards for real money — belongs on `rmp::random`. ============================================================================== # Ads > Interstitial and rewarded AdMob ads on Android, and the same calls compiling to nothing everywhere else, so ad code needs no #ifdef. Source: https://omardev29.github.io/rmp-docs/manual/modules/ads.html [`rmp::ads`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) 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](https://omardev29.github.io/rmp-docs/manual/modules/ads.html#configuring-admob), and do nothing on every other platform, so the same game code builds on all 17 targets without a single `#ifdef`. ## Every ad goes the same way 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#request_interstitial) | [`request_rewarded()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#request_rewarded) | | Has it loaded? | [`is_interstitial_loaded()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#is_interstitial_loaded) | [`is_rewarded_loaded()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#is_rewarded_loaded) | | Show it | [`show_interstitial()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#show_interstitial) | [`show_rewarded()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#show_rewarded) | | The reward | | [`take_reward_earned()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#take_reward_earned) and [`reward_amount()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html#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. ## Interstitials 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: ```cpp 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(); } rmp::ui::end(); } }; ``` An ad that has not arrived is simply skipped: the player is never kept waiting for one. ## Rewarded ads 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. ```cpp 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: - **The button is only live when there is an ad.** A button that does nothing when pressed reads as a broken game; a disabled one says "not yet" honestly. - **The reward is polled, every frame.** The flag waits until it is taken, so it does not matter on which frame the ad network reports it. 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](https://omardev29.github.io/rmp-docs/examples/ads/02_rewarded.html) is this flow, end to end; [examples/ads/01_interstitial](https://omardev29.github.io/rmp-docs/examples/ads/01_interstitial.html) shows both kinds side by side. ## Everywhere but Android 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 ``, 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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html#ads-in-plain-c), which has `` on its include path on every target: ```c #include void level_finished(void) { if (IsInterstitialAdLoaded()) ShowInterstitialAd(); RequestInterstitialAd(); } void every_frame(int *coins) { if (TakeRewardEarned()) *coins += GetRewardAmount(); } ``` ## Configuring AdMob 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]`: ```toml [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_id` Your AdMob app's id. It goes into the Android manifest of the release build. `interstitial_id`, `rewarded_id` The ad unit each kind is loaded from. These are Google's test ids The three ids above are the defaults, and they are the ones Google publishes for testing: they serve test ads. Replace them with your own before you publish. Clicking real ads from your own build is invalid traffic, and invalid traffic is how AdMob accounts get suspended. Your 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: ```toml [android.admob] enabled = true interstitial_id = "ca-app-pub-3940256099942544~3347511713" ``` ```text 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. ``` ### With ads off ```toml [android.admob] enabled = false ``` With `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: ```toml [android.admob] enabled = "no" ``` ```text raylib_multiplatform.toml:2: enabled = "no" ^^^^^^^^^^^^^^ configure: error: [android.admob] enabled = 'no' must be true or false. ``` ## Consent Not implementedShowing ads to players in the European Economic Area or the United Kingdom requires a consent platform certified by Google, and the framework does not ship one. With ads on, that traffic is served badly or not at all until the game adds one. Google's own, the User Messaging Platform, is already inside the Google Mobile Ads library the build links, so adding it is a consent request and a form in the Android code, not a new dependency. ============================================================================== # Working with raylib and Clay > The framework is built on raylib and hides none of it: what it does in your place, and how to reach raylib, Clay, rlgl and plain C yourself. Source: 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. - [raylib in your game](https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html) — what the framework owns (the window, the frame, the clock), what you are free to call in `_update()` and `_draw()`, and the handful of raylib calls that would fight it. - [Dropping to Clay](https://omardev29.github.io/rmp-docs/manual/raylib/clay.html) — writing Clay's own elements in the same frame as `rmp::ui`, and the rules that make it work: ids, strings, images. - [rlgl and OpenGL](https://omardev29.github.io/rmp-docs/manual/raylib/rlgl.html) — raylib's GL layer from a game, which OpenGL each target really runs, and what raw OpenGL costs you. - [Plain C](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html) — the opt-out: your own `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. ============================================================================== # raylib in your game > What the framework calls on raylib in your place — the window, the frame, the clock — and everything else, which is yours to call from your scenes. Source: 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. ## What the framework owns [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#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](https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html#escape-is-the-games-key). | | `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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#camera). | | `EndDrawing()` | Every frame, after the last scene's `_draw()`. | | `CloseWindow()` | Once, at the very end, after every scene, every [`rmp::global`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global) and every resource that lives on the GPU has been released. | The sound device is not on that list on purpose: [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html); 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](https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html#running-a-release-build). ### One frame, in order Every frame of a game made with `RMP_GAME` is the same sequence, and every hook you write has a fixed place in it: 1. The input devices are sampled, once, for the whole frame — by the loop itself, which does the same before the frame hook of a game written with `RMP_ENTRY_POINT`. 2. The scenes are updated from the bottom of the stack upwards, skipping the ones a scene above freezes. For each one: the pointer, first — a click or a drag on one of its objects calls that object's `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. 3. `BeginDrawing()`, and the clear — into a texture instead of the screen while an [`overlay()` blurs](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#the-blur) what is under it. 4. Every scene that is visible, from the bottom up: `BeginMode2D()` with its camera, its map, its objects, `EndMode2D()`, and then its own `_draw()` — outside the camera, in screen space. 5. The [notices](https://omardev29.github.io/rmp-docs/manual/modules/ui.html#notices) of `rmp::ui::notify()`, over everything. 6. `EndDrawing()`. 7. The scene changes asked for during the frame — `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](https://omardev29.github.io/rmp-docs/manual/core/scenes.html) hooks say which space they draw in. ### And when the game ends 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit), or a CI run reached its frame budget. ## What stays yours All of raylib: shapes, textures, text, models, shaders, sound, input, files, the window's state. Most headers under `include/rmp/` already include ``, so a scene can call raylib with nothing more than the header it already has. ### In `_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. ```cpp 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); } ``` ### Input: raylib's, or routed 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html) 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. ```cpp // 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)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pressed) is exactly `IsKeyDown(KEY_W)`, never routed. The type of the argument says which of the two you asked for. The [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) 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. ### Escape is the game's key 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`](https://omardev29.github.io/rmp-docs/reference/macros.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit), which ends the game the way the close button does: ```cpp if (IsKeyPressed(KEY_ESCAPE)) rmp::app::quit(); ``` ### In `_draw()`, screen space — and the world when you open the camera A scene's [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#raylib): ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_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. ### 3D 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()`: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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](https://omardev29.github.io/rmp-docs/manual/platforms/ios.html)). ### What you load yourself 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: ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_texture), whose [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#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. ## What never to call 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()` The window is the framework's, from before your first `_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 The frame is already open when `_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 The browser and the display link pace the frame there, and the framework hands them the loop for that reason. A frame cap is a wait inside their callback, which only stalls it. The cap you want is `[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: ```cpp #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()` The framework asks it every frame on the targets that have a window to close. On the web it is never called: there it returns `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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit_requested). `exit()`, `std::exit()`, `abort()` They end the process where it stands: your scenes never get `_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.` A `while` loop that draws A loading screen that loops on `BeginDrawing()` 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. ## Include what you use 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 `` 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 | |---|---| | ``, 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. | | `` | raylib's GL layer. See [rlgl and OpenGL](https://omardev29.github.io/rmp-docs/manual/raylib/rlgl.html). | | `` | The layout engine under `rmp::ui`. See [Dropping to Clay](https://omardev29.github.io/rmp-docs/manual/raylib/clay.html). | | `` | Android's extras — vibration, the soft keyboard, the sensors — declared on Android only. See [Android](https://omardev29.github.io/rmp-docs/manual/platforms/android.html). | The values from `raylib_multiplatform.toml` — `RMP_WINDOW_WIDTH`, `RMP_WINDOW_TITLE` and the rest, listed on the [macros](https://omardev29.github.io/rmp-docs/reference/macros.html#from-the-toml) page — come with every `rmp/` header, so you never include `rmp/config.h` yourself unless the file includes none of them. ## Telling the platforms apart 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: ```cpp #if !RMP_PRODUCTION_BUILD DrawFPS(10, 10); #endif ``` ============================================================================== # Dropping to Clay > Writing Clay's own elements in the same frame as rmp::ui, for what the small API does not have — and the rules about ids, strings and images that make it work. Source: https://omardev29.github.io/rmp-docs/manual/raylib/clay.html `rmp::ui` is a small surface over [Clay](https://github.com/nicbarker/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 `` 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, next to rmp::ui 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: ```cpp #include #include #include // 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#begin) and [`rmp::ui::end()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ## The example `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`](https://omardev29.github.io/rmp-docs/reference/macros.html#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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/03_clay_direct/src/main.cpp#L1-L141) ```cpp // --------------------------------------------------------------------------- // 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 // // 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 #include #include #include #include // 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. ``` ## Where your elements go `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](https://omardev29.github.io/rmp-docs/manual/modules/ui-layout.html#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: ```cpp 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. ## Ids 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. - **Ask with the macro you made it with.** `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)`. - **Use labels no rmp::ui control in the scene uses.** `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. - **One id, one element, per frame.** Two elements with the same id are Clay's error, and the framework prints each kind of Clay error once rather than every frame, in Clay's own words after `UI: clay: …`. With `[dev] strict = true` the first one stops a debug build where it happened. ## Strings 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. - A string built at run time has to stay alive until `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. ```cpp 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(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. ## Images An image element points `.image.imageData` at a `Texture2D` — raylib's struct, not an [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#image) does all of this for you, copying the struct into the frame arena and carrying its [`tint`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#ImageOptions-tint) the same way; drop to Clay for an image only when it has to sit somewhere `rmp::ui` cannot put it. ## Sizes are pixels 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ## Hover and the pointer `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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ## What the renderer draws 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: ```cpp 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. ## What it costs 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`. ============================================================================== # rlgl and OpenGL > raylib's GL layer from a game: where in the frame it is safe, which OpenGL each target really runs, and what raw OpenGL costs. Source: 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. ## Where in the frame `` 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_draw) | Drawing, in screen space. It is the hook that runs between `BeginDrawing()` and `EndDrawing()`. | | An object's [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_draw) | Drawing, in world space: it runs inside the scene's camera. | | A scene's [`_ready()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_ready) | Creating GPU resources — textures, render textures, shaders. The window, and the GL context with it, exists by then. | | A scene's [`_end()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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. ## The batch 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. ## Leave the state as you found it 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: ```cpp 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. ## Which OpenGL each target runs 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](https://omardev29.github.io/rmp-docs/manual/platforms/android.html). 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. ### Shaders 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: ```cpp 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/`. ## Raw OpenGL 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: - **The versions differ** by target, as the table above says, so a GL call that is fine on a desktop's OpenGL 3.3 may not exist on the web's ES 2.0. - **The software renderer has no GL at all.** `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. - **The queue comes first.** Call `rlDrawRenderBatchActive()` before your own GL calls, so raylib's queued drawing reaches the GPU before them. - **The state goes back.** raylib keeps its own idea of what is bound and enabled; a raw call that changes it behind rlgl's back changes it for every draw that follows. 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: ```cpp using GetIntegerv = void (*)(unsigned int, int *); auto get_integerv = reinterpret_cast(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. ============================================================================== # Plain C > The opt-out: a game in plain C with its own main() and nothing of rmp::, which keeps the build, the generated identifiers and the pipeline — and what it gives up, target by target. Source: 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. ## The example `examples/plain_c` is that game: one C file, raylib, the framework's headers that are plain C — `` and `` — and a `while` loop of its own. Its header is the recipe and the list of what changes: [examples/plain_c/src/main.c](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/plain_c/src/main.c#L1-L118) ```c // =========================================================================== // 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 /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 , 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 , as below: [window] and // the rest of the .toml as plain #defines, in C. // the smoke-test hooks -> , 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 #include // [window] from raylib_multiplatform.toml, as #defines #include // 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`: ```shell rm src/main.cpp && rm -r src/rmp/ src/scenes/ tests/game/ cp /examples/plain_c/src/main.c src/ rmp run ``` `tests/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. ## How the build tells 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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html#the-release-packages)). 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 `#define`s: 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 `` is ([below](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html#ads-in-plain-c)): ```c 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. ## What you keep - The build for the targets that can run the file (below), configured from `raylib_multiplatform.toml` as it is for every game: `rmp run`, `rmp build release` and `cmake --preset debug` work the same. - The identifiers and the icons: the Android application id, the iOS bundle id, and the Android icons, the iOS AppIcon and the Windows `.ico` generated from `[icon] source`. - The version from the git tag, the pinned toolchains, CI and the release. - raylib itself, all of it, at the version and with the patches the framework vendors. ## What you give up | 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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html#ads-in-plain-c)). 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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html#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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html#the-smoke-test). | ## Ads The ads survive without `rmp::`. [`rmp::ads`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) is a wrapper over the C functions in ``, 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](https://omardev29.github.io/rmp-docs/manual/modules/ads.html#everywhere-but-android), and `[android.admob]` turns them on as it does for any game. ```c void game_over(void) { if (IsInterstitialAdLoaded()) ShowInterstitialAd(); RequestInterstitialAd(); } ``` ## Which targets run it 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: ```toml [targets] enabled = ["all"] disabled = ["web", "ios"] ``` To have the web or iOS back, keep the framework's entry point: [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#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. ## The smoke test 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 ``, 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. ## The release packages 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. ============================================================================== # Platforms > Every target the framework builds, how a game chooses its own in [targets], and what CI does with each one — on every push, and on a release. Source: 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: - [Desktop](https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html) — Windows, macOS, Linux (glibc, musl, DRM/KMS, RISC-V) and the BSDs. - [Linux from a console](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) — on a machine with no desktop, `rmp` builds for DRM/KMS by itself: the screen and the keyboard from `/dev`, sudo or the groups, and the terminal it gives back. - [Web](https://omardev29.github.io/rmp-docs/manual/platforms/web.html) — Emscripten, a browser that owns the frame loop, memory, saves and sound. - [Android](https://omardev29.github.io/rmp-docs/manual/platforms/android.html) — raymob, Gradle generated from the `.toml`, permissions, signing. - [iOS](https://omardev29.github.io/rmp-docs/manual/platforms/ios.html) — Xcode through XcodeGen, the raylib-iOS fork, and an app that is not allowed to quit. ## Every target | 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 `---`, 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. ### Families 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. ## Choosing a game's targets `[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: ```toml [targets] enabled = ["all"] disabled = ["ios"] ``` That is everything but iOS. The same lists take exact target names, and mix them with groups: ```toml [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: ```toml [targets] enabled = "all" ``` ```text 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. ## What CI does with each target 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: ```shell 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,macos ``` Building 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#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/publishing/index.html). ============================================================================== # Desktop > Windows, macOS, Linux — glibc with its version floor, musl, DRM/KMS with no desktop at all, RISC-V — and the BSDs: how each is built, what ships, and what to know. Source: 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. ## Running a release build 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 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: ```shell python tools/binary_check.py windows build/release/my_game.exe ``` The 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. ### The windowing backend `[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: ```toml [windows] backend = "win32" ``` ### Building on Windows `rmp` comes as `rmp.ps1` for PowerShell and `rmp.cmd` for cmd. The `rmp` [the installer](https://omardev29.github.io/rmp-docs/getting-started/install.html) 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, and compression Saves go to `%APPDATA%\\`, 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. ## macOS 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) 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//`. `[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: ```toml [upx] enabled = ["linux", "macos"] ``` ```text 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 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. | ### The glibc floor 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. ### X11 and Wayland 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](https://omardev29.github.io/rmp-docs/getting-started/index.html#linux-packages). On a console with no desktop, `rmp` builds for DRM/KMS instead, and needs none of them: [Linux from a console](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html). 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. ```toml [linux] wayland = true ``` One 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: ```toml [linux] backend = "rgfw" wayland = true ``` ```text 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 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. ### RISC-V `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](https://omardev29.github.io/rmp-docs/publishing/ci.html#riscv64)) — 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. ### DRM/KMS: no desktop at all 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) has all of it. Anywhere else, the `release-drm` preset builds the release by hand: ```shell cmake --preset release-drm cmake --build --preset release-drm ``` CI 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"]`. ### Linux saves and compression Saves go to `$XDG_DATA_HOME//` when that variable is set to an absolute path, and to `~/.local/share//` 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](https://omardev29.github.io/rmp-docs/publishing/desktop.html#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. ## The BSDs 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//`, 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](https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html#running-a-release-build)). 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. ============================================================================== # Linux from a console > On a Linux console with no desktop, rmp builds the game for DRM/KMS by itself: what decides it, the folders it builds in, what to install, the screen and the keyboard from /dev, sudo and the groups, and the terminal it gives back. Source: 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. ## What decides it Once per command, before anything is configured, `rmp` asks these in order, and the first that answers decides: 1. `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. 2. Not Linux: the desktop. DRM/KMS is a Linux backend. 3. `DISPLAY` or `WAYLAND_DISPLAY` is set: the desktop. There is one to open a window on. 4. Logged in over SSH — `SSH_CONNECTION`, `SSH_CLIENT` or `SSH_TTY` is set — with no display: the desktop, and a note saying so. 5. `XDG_SESSION_TYPE=tty`, which logind sets for a text login: DRM/KMS. 6. The terminal `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. 7. Anything else: the desktop. With a terminal and no display, a note says why. 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: ```shell RMP_DRM=1 rmp run ``` When 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. ## Its own two folders 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. ```shell rmp run # builds build/debug-drm/my_game, checks /dev, starts it rmp build release # builds build/release-drm/my_game ``` Without `rmp`, the same presets by hand: ```shell cmake --preset debug-drm cmake --build --preset debug-drm ``` CMake 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`](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers) says. ## What to install 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](https://omardev29.github.io/rmp-docs/getting-started/install.html) 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` | ```shell sudo apt install libdrm-dev libgbm-dev libegl1-mesa-dev libgles2-mesa-dev ``` It 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. ## The screen and the keyboard 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: - **No card.** The cards that count are the ones raylib tries, in its order: `/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. - **A card something else holds.** When another program is the DRM master of the card the game would take — a desktop on another virtual console, most likely — `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. - **A card or an input device you cannot open.** `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. - **No input device at all.** A note, and the game starts: it reads the keys of the terminal it runs on, and no mouse or gamepad. The smoke stage of `rmp test` boots the game on the console's screen, and asks the same before it does. ### Two ways out: sudo once, or the groups 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: ```shell 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 again ``` `rmp 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. ### Never sudo rmp `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. ## Saves under sudo A game started with sudo is root, and saves as root. With sudo's defaults its home is root's, so [`rmp::save`](https://omardev29.github.io/rmp-docs/manual/modules/saving.html) writes to `/root/.local/share//` 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. ## The terminal comes back 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. ## While it runs 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](https://omardev29.github.io/rmp-docs/manual/core/app.html#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. ## When it does not work | 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. | ## What CI proves 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. ============================================================================== # Web > The web target: Emscripten, a browser that owns the frame loop and why that rules out ASYNCIFY, memory, saves in IndexedDB, sound that waits for the player, and how to serve a build. Source: 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. ## Building and running it ```shell rmp web python3 -m http.server 8000 --directory build/web ``` and 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. ## The browser owns the loop 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: - **No `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()`. - **No `WindowShouldClose()`.** On the web raylib's version waits with `emscripten_sleep()`, which needs ASYNCIFY; the framework never calls it there. - **No `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. - **No backend that needs ASYNCIFY.** See below. [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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. ## The backend 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. ```toml [web] backend = "rgfw" ``` ```text 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. ## Graphics 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](https://omardev29.github.io/rmp-docs/manual/raylib/rlgl.html) has what else differs. ## Memory 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. ```toml [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`. ## Assets 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. ## Saves 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//`, and [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) 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. ## Sound 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. ## Serving a build Any static web server that serves the four files from one folder will run the game; the page is `.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](https://omardev29.github.io/rmp-docs/publishing/web.html). ## What CI checks 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. ============================================================================== # Android > The Android target: raymob around raylib, a Gradle build generated from the .toml, the application id, permissions and orientation, the OpenGL ES version a game compiles for, ads that are off until asked for, and signing for the Play Store. Source: 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. ## Building it ```shell rmp android adb install -r ``` `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. ## The application id ```toml [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: ```toml [android] application_id = "com.my-game.app" ``` ```text 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: ```toml [android] application_id = "com.raylib.raymob.mygame" ``` ```text 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](https://omardev29.github.io/rmp-docs/publishing/releases.html). ## What the .toml decides | 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. ```toml [android] min_sdk = 26 [android.display] into_cutout = false [android.permissions] vibration = true ``` ### `gl_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 `` 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](https://omardev29.github.io/rmp-docs/manual/raylib/rlgl.html#shaders) 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: ```toml [android] gl_version = "ES31" ``` ```text 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. ``` ## Assets and saves 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. ## Android-only extras: raymob `` 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: ```cpp #include #ifdef __ANDROID__ #include #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](https://omardev29.github.io/rmp-docs/examples/platform/02_mobile_raymob.html). ## Ads `[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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) 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. ```toml [android.admob] enabled = true ``` The 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: ```toml [android.admob] enabled = true app_id = "ca-app-pub-3940256099942544/1033173712" ``` ```text 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. ## Leaving the app [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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. ## Signing for Google Play 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: ```shell keytool -genkey -v -keystore upload.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload ``` CI 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`: ```shell python3 tools/configure.py cd raymob ./gradlew bundleRelease ``` Gradle 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. ## When a Gradle build is killed 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. ## What CI checks 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#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](https://omardev29.github.io/rmp-docs/publishing/index.html). ### Gradle in CI 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: raylib_multiplatform.toml ```toml [android] gradle_offline = false ``` Then 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. ============================================================================== # iOS > The iOS target: an Xcode project generated by XcodeGen from the .toml, raylib from a pinned fork, an entry point UIKit calls, an app that must not quit, and signing that stays out of CI. Source: 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 it 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: ```shell 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.xcodeproj ``` `raylib.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: ```shell xcodebuild -project my_game.xcodeproj -scheme my_game \ -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build ``` ### The raylib-iOS fork `thirdparty/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.` ## What the .toml decides `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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html): 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: ```toml [ios] deployment_target = "12.4" ``` ```text 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. ## The entry point 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`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) writes those three on iOS — it expands to [`RMP_IOS_FUNCS`](https://omardev29.github.io/rmp-docs/reference/macros.html#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. ## An iOS app does not quit 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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: ```cpp 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. ## Signing stays out of CI 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: ```toml [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: ```shell 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.yourgame ``` ## What CI checks iOS 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. ============================================================================== # Help > When something goes wrong, and the questions that come up before it does. Source: 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. - [Troubleshooting](https://omardev29.github.io/rmp-docs/manual/help/troubleshooting.html) — real problems, the messages they print, and what to do about each. - [Questions](https://omardev29.github.io/rmp-docs/manual/help/faq.html) — what people ask before, or instead of, reading the rest of the manual. 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. ============================================================================== # Troubleshooting > Real problems and the messages they print — a missing Python, a refused .toml, a build directory left over from the other build type, assets that fail to load, a window with nothing in it — and what to do about each. Source: 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. ## Before anything builds ### Python is missing, or too old `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. ### A tool is not on the PATH `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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html#install) 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. ### The .toml is refused `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: ```toml [window] fps = 15 ``` ```text 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: ```toml [window] orientation = ["landscape"] ``` ```text 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 release is refused 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](https://omardev29.github.io/rmp-docs/publishing/releases.html). ## Building ### build/ is not a build 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`. ### A sanitizer the .toml lists is not there With [`[dev] sanitize`](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers) 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--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. ### A sanitizer stopped the game 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 link error about the entry point 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`. ### A handle that will not convert This does not compile, on purpose: Does not compile ```cpp 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. ### Compiling the framework outside its build `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. ### Raw OpenGL links on the desktop and not in the tests `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](https://omardev29.github.io/rmp-docs/manual/raylib/rlgl.html). ## Assets ### A release build finds nothing 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: - `ASSETS: no … next to the executable; reading the working directory's, …` — there is no `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. - `ASSETS: this system does not say where the executable is, so … is read from the working directory, …` — OpenBSD and NetBSD, where raylib cannot say where the executable is. Start the game from its own folder there. ### An asset failed to load 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: - **A misspelt name.** A name is the path below `resources/`: `"sprites/player.png"`, not `"resources/sprites/player.png"`, and with `/` between folders on every system. - **A file that is there and does not decode.** A picture, a font or a sound cut short, or in a format raylib does not read, counts as failed the same as a missing one, and says once `ASSETS: '…' is in … but could not be decoded`; a font is not replaced by raylib's built-in one under its name, it comes back empty. A song `rmp::audio::music()` cannot stream counts too, and says `AUDIO: "…" is in resources/ but could not be streamed`. - **A pack that does not match the game.** A packed picture that will not open says `ASSETS: '…' not usable from pack (corrupt, or another password), falling back to loose file`, and a packed sound or font `ASSETS: '…' not usable from pack, falling back to loose file`. That is a pack made with a different `[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. ### A sound does not play `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](https://omardev29.github.io/rmp-docs/manual/platforms/web.html). ## A window with nothing in it ### The game booted and drew nothing `rmp test smoke` says `FAIL: the game booted and drew nothing` when the frame it reads back is blank. Things that come to that: - **Every texture is empty** because the assets were not found — see above. An empty texture draws nothing rather than crashing: a hole in the picture, not a dead process. - **The last scene was popped.** The framework refuses, and says `SCENE: pop() with … scene(s) on the stack would leave nothing to draw; ignoring. Did you mean rmp::app::quit()?` - **The interface hit its ceiling.** `UI: more than max_elements (…) elements in one frame. The interface will not lay out again until the game is restarted.` Raise `[ui] max_elements`, or draw less at once. - **Drawing in the wrong space.** A scene's `_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](https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html). - **The web build ran out of memory.** The tab stops with Emscripten's "Cannot enlarge memory arrays". Raise `[web] memory`. ### A key does nothing 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. ### Escape does not close the window 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) when the game reads it — see [Escape is the game's key](https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html#escape-is-the-games-key). ## On one platform only ### Linux: "version GLIBC_… not found" 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](https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html) for the floor, and for the targets it does not apply to. ### Linux console: a refusal before the game, a black screen, no keyboard 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html#when-it-does-not-work) 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html#terminal) after a crash. ### Linux on Wayland: the window has no position 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. ### Windows: the executable is quarantined 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. ### Web: a blank page, or no build at all 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`. ### Android: the sources changed after a build 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. ### iOS: Quit does nothing On purpose: `APP: quit() does nothing on iOS — Apple rejects apps that terminate themselves (QA1561). Ignoring.` See [iOS](https://omardev29.github.io/rmp-docs/manual/platforms/ios.html) for why, and for hiding the button there. ### OpenBSD and NetBSD: portable saves are not portable `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. ## In CI ### There is no remote to push to `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 run was cancelled 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. ### A BSD job failed, and nothing you changed explains it 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. ### The Android bundle is called NOT-FOR-PLAY CI signed it with a throwaway key because the signing secrets are not set. See [Android](https://omardev29.github.io/rmp-docs/manual/platforms/android.html) for the four secrets that make it a bundle Google Play accepts. ### The iOS app is built but never started 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. ============================================================================== # Questions > What people ask about the framework before they ask anything else: raylib, scenes, main(), targets, saves, players' machines, libraries and licences. Source: https://omardev29.github.io/rmp-docs/manual/help/faq.html Short answers, each with a link to where the long one is. ## The framework ### Is it ready to ship a game with? 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. ### Can I still call raylib? 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](https://omardev29.github.io/rmp-docs/manual/raylib/raylib.html) lists them and why. ### Do I have to use scenes? No. [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) is built on a lower-level entry point, [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#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: ```cpp #include 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); ``` ### Can I write my own `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](https://omardev29.github.io/rmp-docs/manual/raylib/plain-c.html). In C++ with the framework, the entry-point macro writes `main()` for you, and a second one is a link error. ### Does it use exceptions? 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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`. ### Which C++? 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. ## Targets ### Which platforms does it build 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 turns any of them off in `[targets]`. See [Platforms](https://omardev29.github.io/rmp-docs/manual/platforms/index.html). ### Can I build for a platform I do not have? 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. ### Which targets does a push build? 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](https://omardev29.github.io/rmp-docs/manual/platforms/index.html#what-ci-does-with-each-target). ### Do I need GitHub? 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. ### Does it run on a Raspberry Pi? 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](https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html). 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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html). ## Players ### Do players need to install anything? 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](https://omardev29.github.io/rmp-docs/publishing/desktop.html) has each one. ### Where do saves go? | Target | Folder | |---|---| | Windows | `%APPDATA%\\`, or `saves\` next to the `.exe` with `[save] portable = true` | | macOS | `~/Library/Application Support//` | | Linux and the BSDs | `$XDG_DATA_HOME//` or `~/.local/share//`, 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//` | | Android | The app's private storage, in `saves/` | | iOS | The app's `Library/Application Support/` | `` is `[project] name`. [`rmp::save::directory()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#directory) says which folder a running game is using. ### Does a release start from any folder? 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](https://omardev29.github.io/rmp-docs/manual/platforms/desktop.html#running-a-release-build), and [Troubleshooting](https://omardev29.github.io/rmp-docs/manual/help/troubleshooting.html#a-release-build-finds-nothing) when it finds nothing. ## The project ### Why is there no version in the .toml? 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](https://omardev29.github.io/rmp-docs/publishing/releases.html). ### How do I make the game smaller? 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#size-budget). ```toml [raylib] disabled_modules = ["rmodels"] ``` The modules do not reach iOS, which links a prebuilt raylib. ### Can I add another library? 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. ### What licence is my game under? 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. ============================================================================== # Examples > The framework's examples: small, complete projects, each showing one part of it, and whole games playable from start to finish. Source: 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: ```shell rmp example rmp example 01_pong rmp example games/01_pong ``` ## Ads [**Interstitial**source Full-screen ads between levels: request, check, show, request the next one.](https://omardev29.github.io/rmp-docs/examples/ads/01_interstitial.html) [**Rewarded**source Watch an ad, get a reward — and only if the player actually finished it.](https://omardev29.github.io/rmp-docs/examples/ads/02_rewarded.html) ## Assets [**Loading**playable Loading by name — the same code whether it comes from loose files or a packed, AES-encrypted resources.rres.](https://omardev29.github.io/rmp-docs/examples/assets/01_loading.html) ## Games [**Pong**playable rmp::behavior::Ball and Edge::CLAMP, two players, first to seven.](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) [**Breakout**playable 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.](https://omardev29.github.io/rmp-docs/examples/games/02_breakout.html) [**Space invaders**playable 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.](https://omardev29.github.io/rmp-docs/examples/games/03_space_invaders.html) [**Top down**playable 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.](https://omardev29.github.io/rmp-docs/examples/games/04_top_down.html) [**Endless runner**playable Parallax, Runner, a Spawner by distance and a camera that follows, with a little smoothing.](https://omardev29.github.io/rmp-docs/examples/games/05_endless_runner.html) [**Tetris**playable The honest one: a Tetris is a 10×20 array and the rules of Tetris, and the framework does not pretend otherwise.](https://omardev29.github.io/rmp-docs/examples/games/06_tetris.html) [**Platformer**playable 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.](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) [**Dungeon**playable 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.](https://omardev29.github.io/rmp-docs/examples/games/08_dungeon.html) [**After school**playable 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.](https://omardev29.github.io/rmp-docs/examples/games/09_after_school.html) ## Input [**Actions**playable 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.](https://omardev29.github.io/rmp-docs/examples/input/01_actions.html) ## Platform [**Mobile raymob**source The raymob mobile API: vibration, soft keyboard, sensors, orientation, app storage.](https://omardev29.github.io/rmp-docs/examples/platform/02_mobile_raymob.html) [**Minimal includes**source The proof that rmp/ui.h stands alone. One translation unit that includes 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/03_minimal_includes.html) ## Scenes [**Stack**playable 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.](https://omardev29.github.io/rmp-docs/examples/scenes/01_stack.html) [**Stretch**playable [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/02_stretch.html) ## UI [**Menu**playable 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.](https://omardev29.github.io/rmp-docs/examples/ui/01_menu.html) [**Layout**playable row, column, panel, center, stack/layer, spacer, plus image and progress.](https://omardev29.github.io/rmp-docs/examples/ui/02_layout.html) [**Clay direct**playable The escape hatch. Clay's own macros in the same frame as rmp::ui, for anything the small API does not expose yet.](https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html) [**Settings**playable Checkbox, slider, dropdown, text input — and the focus/keyboard/gamepad navigation you get without writing any.](https://omardev29.github.io/rmp-docs/examples/ui/04_settings.html) [**Inventory**playable 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.](https://omardev29.github.io/rmp-docs/examples/ui/05_inventory.html) [**Style**playable The two themes, the five variants, the three sizes and the transition.](https://omardev29.github.io/rmp-docs/examples/ui/06_style.html) [**Responsive**playable scale() versus current_breakpoint(), and which to reach for.](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) [**Overlay**playable 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.](https://omardev29.github.io/rmp-docs/examples/ui/08_overlay.html) [**Skinned**playable The other way to write rmp::ui: a game's shop screen designed rather than written.](https://omardev29.github.io/rmp-docs/examples/ui/09_skinned.html) [**Dialogue**playable 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 <>.](https://omardev29.github.io/rmp-docs/examples/ui/10_dialogue.html) [**Localization**playable 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).](https://omardev29.github.io/rmp-docs/examples/ui/11_localization.html) [**Font**playable 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/ui/12_font.html) ## Plain c [**Plain C**source The opt-out. A C entry point with your own main(): raylib, plus two headers of ours that are C -- for the [window] values and for the CI hooks -- and none of rmp::.](https://omardev29.github.io/rmp-docs/examples/plain_c.html) ============================================================================== # Plain C > The opt-out. A C entry point with your own main(): raylib, plus two headers of ours that are C -- for the [window] values and for the CI hooks -- and none of rmp::. Source: 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 -- `` for the `[window]` values and `` 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. Not playable here 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. ## Run it From a clone of the framework: ```shell rmp example plain_c ``` ## The code Every file of `examples/plain_c`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/plain_c)). **`src/main.c` 117 lines** [src/main.c](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/plain_c/src/main.c) ```c // =========================================================================== // 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 /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 , 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 , as below: [window] and // the rest of the .toml as plain #defines, in C. // the smoke-test hooks -> , 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 #include // [window] from raylib_multiplatform.toml, as #defines #include // 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; } ``` ============================================================================== # Ads > The examples under examples/ads/. Source: https://omardev29.github.io/rmp-docs/examples/ads/index.html - [Interstitial](https://omardev29.github.io/rmp-docs/examples/ads/01_interstitial.html) — Full-screen ads between levels: request, check, show, request the next one. - [Rewarded](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. ============================================================================== # Interstitial > Full-screen ads between levels: request, check, show, request the next one. Source: https://omardev29.github.io/rmp-docs/examples/ads/01_interstitial.html Full-screen ads between levels: request, check, show, request the next one. Not playable here Ads are shown on Android only: in a browser every `rmp::ads` call does nothing, so there would be nothing to see. ## Run it From a clone of the framework: ```shell rmp example 01_interstitial ``` ## Keys Read 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` | ## The code Every file of `examples/ads/01_interstitial`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ads/01_interstitial)). **`src/main.cpp` 78 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ads/01_interstitial/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 . 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 #include // rmp::ads #include // 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); ``` ============================================================================== # Rewarded > Watch an ad, get a reward — and only if the player actually finished it. Source: 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. Not playable here Ads are shown on Android only: in a browser every `rmp::ads` call does nothing, so there would be nothing to see. ## Run it From a clone of the framework: ```shell rmp example 02_rewarded ``` ## The code Every file of `examples/ads/02_rewarded`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ads/02_rewarded)). **`src/main.cpp` 108 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ads/02_rewarded/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include 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. ``` ============================================================================== # Assets > The examples under examples/assets/. Source: https://omardev29.github.io/rmp-docs/examples/assets/index.html - [Loading](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`. ============================================================================== # Loading > Loading by name — the same code whether it comes from loose files or a packed, AES-encrypted resources.rres. Source: 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/`](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/assets/01_loading/resources), which is all an example has to do to read its own. ## Run it From a clone of the framework: ```shell rmp example 01_loading ``` ## Keys Read 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` | ## The code Every file of `examples/assets/01_loading`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/assets/01_loading)). **`src/main.cpp` 93 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/assets/01_loading/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include // 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 level = rmp::assets::load_data("level1.json"); TraceLog(LOG_INFO, "level1.json: %d bytes", static_cast(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); ``` ============================================================================== # Games > The examples under examples/games/. Source: https://omardev29.github.io/rmp-docs/examples/games/index.html - [Pong](https://omardev29.github.io/rmp-docs/examples/games/01_pong.html) — `rmp::behavior::Ball` and `Edge::CLAMP`, two players, first to seven. - [Breakout](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. - [Space invaders](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. - [Top down](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. - [Endless runner](https://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. - [Tetris](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. - [Platformer](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) — **A level designed in [LDtk](https://ldtk.io).** Three levels side by side in one world — a meadow, a desert, a snowfield — with Kenney's Pixel Platformer art. - [Dungeon](https://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. - [After school](https://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. ============================================================================== # Pong > rmp::behavior::Ball and Edge::CLAMP, two players, first to seven. Source: 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.** ## Run it From a clone of the framework: ```shell rmp example 01_pong ``` ## Keys Read 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` | ## The code Every file of `examples/games/01_pong`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/01_pong)). **`src/main.cpp` 186 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/01_pong/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include 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({ .position = { 40, MID_Y } }); left.shape.color = theme.primary; _left = left.handle(); auto &right = spawn({ .position = { RMP_WINDOW_WIDTH - 40, MID_Y } }); right.up = "p2_up"; right.down = "p2_down"; right.shape.color = theme.danger; _right = right.handle(); // 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({ .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(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(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 _left; rmp::Handle _right; rmp::Handle _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(); }); } } // namespace RMP_GAME(PongScene); ``` ============================================================================== # Breakout > 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. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 02_breakout ``` ## Keys Read 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` | ## The code Every file of `examples/games/02_breakout`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/02_breakout)). **`src/main.cpp` 159 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/02_breakout/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include 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 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({ .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("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("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(column) * (BRICK_WIDTH + 4), 60 + static_cast(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 _paddle; rmp::Handle _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(); }); } } // namespace RMP_GAME(BreakoutScene); ``` ============================================================================== # Space invaders > 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. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 03_space_invaders ``` ## Keys Read 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` | ## The code Every file of `examples/games/03_space_invaders`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/03_space_invaders)). **`src/main.cpp` 211 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/03_space_invaders/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include #include #include 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 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({ .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("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(std::max(_alive, ALIENS / 4)); _march += _march_speed * delta * static_cast(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("You win"); } else if (lowest > PLAYER_Y - 30) { rmp::Scene::push("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(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()->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(column) * 44, 70 + static_cast(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({ .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(); } // 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(); } // 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 _player; std::array, 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(); }); } } // namespace RMP_GAME(InvadersScene); ``` ============================================================================== # Top down > 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. Source: 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`. ## Run it From a clone of the framework: ```shell rmp example 04_top_down ``` ## Keys Read 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` | ## The code Every file of `examples/games/04_top_down`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/04_top_down)). **`src/main.cpp` 197 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/04_top_down/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include "layers.h" #include 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({ .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({ .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("You died"); }, .hurt_by = layer::ENEMY, }); _player = player.handle(); for (int i = 0; i < ENEMIES; ++i) add_enemy(560 + static_cast(i) * 30); } void _update(float) override { if (rmp::input::just_pressed("ui_accept")) shoot(); } void _draw() override { auto health = _player->get(); rmp::ui::begin({ .placement = rmp::ui::Align::TOP_LEFT }); rmp::ui::row({ .gap = 16 }, [&] { rmp::ui::progress(static_cast(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 &foe : _foes) { const auto enemy = foe.get(); if (!enemy) continue; // shot down: its Health destroyed it const float hp = static_cast(enemy->get()->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("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({ .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({ .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()->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(); shot.add({ .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 _player; std::vector> _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(); }); } } // namespace RMP_GAME(TopDownScene); ``` **`include/layers.h` 17 lines** [include/layers.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/04_top_down/include/layers.h) ```cpp #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 ``` ============================================================================== # Endless runner > Parallax, Runner, a Spawner by distance and a camera that follows, with a little smoothing. Source: https://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`](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/tools/make_example_art.py). ## Run it From a clone of the framework: ```shell rmp example 05_endless_runner ``` ## The code Every file of `examples/games/05_endless_runner`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/05_endless_runner)). **`src/main.cpp` 162 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/05_endless_runner/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include 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({ .speed = 320, .accelerate = 6 }); // One rock and it is over. `hurt_by` is what makes touching a rock // cost something. player.add({ .hp = 1, .invulnerable_for = 0, .destroy_on_death = false, // it stays on screen under the overlay .on_death = [](rmp::Object &) { rmp::Scene::push("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()->distance(); rmp::ui::begin({ .placement = rmp::ui::Align::TOP_CENTER }); rmp::ui::text(TextFormat("%d m", static_cast(distance / 10)), { .size = 40 }); rmp::ui::end(); } private: void add_layer(const char *art, float factor, float y) { spawn({ .layer = -10 }) .add({ .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({ .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 _player; rmp::Handle _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(); }); } } // namespace RMP_GAME(RunnerScene); ``` ============================================================================== # Tetris > The honest one: a Tetris is a 10×20 array and the rules of Tetris, and the framework does not pretend otherwise. Source: 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`. ## Run it From a clone of the framework: ```shell rmp example 06_tetris ``` ## Keys Read 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` | ## The code Every file of `examples/games/06_tetris`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/06_tetris)). **`src/main.cpp` 280 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/06_tetris/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include #include 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, 4>; // (x, y) of each of the four struct Piece { Cells cells; Color color; }; constexpr std::array 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(cell[0]) * CELL, PREVIEW.y + static_cast(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(x), static_cast(y), static_cast(CELL) - 1, static_cast(CELL) - 1, color); } static void draw_cell(int x, int y, Color color) { draw_block(ORIGIN.x + static_cast(x) * CELL, ORIGIN.y + static_cast(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(record ? "New best!" : "Game over"); } std::array, 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 _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(); }); } } // namespace RMP_GAME(TetrisScene); ``` ============================================================================== # Platformer > 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. Source: https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html **A level designed in [LDtk](https://ldtk.io).** 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`, 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`](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/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/`. ## Run it From a clone of the framework: ```shell rmp example 07_platformer ``` ## Keys Read 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` | ## The code Every file of `examples/games/07_platformer`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer)). **`src/main.cpp` 51 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 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 #include "game.h" RMP_GAME(game::TitleScene); ``` **`include/game.h` 161 lines** [include/game.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/include/game.h) ```cpp #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 #include #include #include #include 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() -- 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 gone; // The iids of the doors the player holds a key for. std::vector keys; }; Run &run(); void new_run(); bool contains(const std::vector &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 _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 game ``` **`include/objects.h` 170 lines** [include/objects.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/include/objects.h) ```cpp #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 #include #include #include 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 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 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 game ``` **`src/art.cpp` 94 lines** [src/art.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/art.cpp) ```cpp // The run, the best run, and drawing from tiles.png. #include "game.h" #include #include #include #include #include #include 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(column) * TILE, static_cast(row) * TILE, TILE, TILE }; } void draw_scaled_tile(int index, Vector2 at, float scale) { const Texture2D &tiles = rmp::global().tiles; DrawTexturePro(tiles, source_of(index), Rectangle{ at.x, at.y, TILE * scale, TILE * scale }, Vector2{}, 0, WHITE); } } // namespace Run &run() { return rmp::global(); } void new_run() { rmp::global() = Run{}; } bool contains(const std::vector &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().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(i) * 11 * scale), at.y }, scale); } } void draw_seconds(float seconds, Vector2 at, float scale) { const int tenths = static_cast(std::floor(seconds * 10)); draw_number(tenths / 10, at, scale); const float after = static_cast(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 game ``` **`src/objects/enemies.cpp` 97 lines** [src/objects/enemies.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/objects/enemies.cpp) ```cpp // 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 #include #include namespace game { void Enemy::_collision(rmp::Object &other) { if (_dying >= 0 || (other.collision_layer & layer::PLAYER) == 0) return; auto &player = static_cast(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(_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 game ``` **`src/objects/player.cpp` 99 lines** [src/objects/player.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/objects/player.cpp) ```cpp // 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 #include #include #include #include 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({ .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(); 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(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 game ``` **`src/objects/things.cpp` 228 lines** [src/objects/things.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/objects/things.cpp) ```cpp // 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 #include #include 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(_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(row) * TILE + 1 < world_collider().height; ++row) draw_tile(tiles::DOOR, { at.x, at.y + static_cast(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(column) * TILE + 1 < width; ++column) draw_tile(tiles::SPIKES, { at.x + static_cast(column) * TILE, at.y }); } void Spikes::_collision(rmp::Object &other) { if (is_player(other)) static_cast(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(position.x) - (width / 2); const auto y = static_cast(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(_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(scene()).win(); } } // namespace game ``` **`src/scenes/end.cpp` 35 lines** [src/scenes/end.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/scenes/end.cpp) ```cpp // 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 #include 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(""); } if (rmp::ui::button("Menu")) { rmp::audio::play("select"); rmp::Scene::change(); } }); } } // namespace game ``` **`src/scenes/level.cpp` 214 lines** [src/scenes/level.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/scenes/level.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include 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({ .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({ .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({ .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({ .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({ .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({ .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({ .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({ .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({ .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({ .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(); // 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(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(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(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(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(); rmp::ui::end(); } } // namespace game ``` **`src/scenes/pause.cpp` 37 lines** [src/scenes/pause.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/scenes/pause.cpp) ```cpp // 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 #include #include 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(); } }); } } // namespace game ``` **`src/scenes/title.cpp` 65 lines** [src/scenes/title.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/07_platformer/src/scenes/title.cpp) ```cpp // 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 #include #include #include #include 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(""); } // 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 game ``` ============================================================================== # Dungeon > 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. Source: https://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 `Collectible`s with a magnet, chests, levers, the altar and the stairs `Area`s, spikes a `Hitbox` a `Timer` turns on and off with `enable()`, 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`](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/tools/make_dungeon_assets.py). ## Run it From a clone of the framework: ```shell rmp example 08_dungeon ``` ## Keys Read 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` | ## The code Every file of `examples/games/08_dungeon`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon)). **`src/main.cpp` 46 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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); 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 #include "dungeon.h" RMP_GAME(game::TitleScene); ``` **`include/cast.h` 59 lines** [include/cast.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/include/cast.h) ```cpp #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 #include #include #include 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 hero); void add_things(LevelScene &scene, rmp::Handle 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 game ``` **`include/dungeon.h` 134 lines** [include/dungeon.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/include/dungeon.h) ```cpp #pragma once // --------------------------------------------------------------------------- // What every file of the dungeon shares: the collision layers, the run that // outlives a level, the scenes, and the look. // --------------------------------------------------------------------------- #include #include #include #include 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 _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 game ``` **`src/look.cpp` 121 lines** [src/look.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/look.cpp) ```cpp // 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 #include #include #include #include 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(); } void new_run() { rmp::global() = 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().tiles; const Rectangle source{ static_cast(index % COLUMNS) * TILE, std::floor(static_cast(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(color.a / RINGS) }; BeginBlendMode(BLEND_ADDITIVE); for (int i = 0; i < RINGS; ++i) { DrawCircleV(at, radius * static_cast(RINGS - i) / RINGS, step); } EndBlendMode(); } } // namespace game ``` **`src/objects/effects.cpp` 128 lines** [src/objects/effects.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/objects/effects.cpp) ```cpp // Sparks and rising numbers: small objects that fade and go, made of the // catalogue's Tween and Lifespan. #include "cast.h" #include #include #include #include #include #include #include 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().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> 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 &h) { return !h; }); for (const rmp::Handle &h : lit) { const auto object = h.get(); if (!object->visible || !object->enabled()) continue; const Light &light = *object->get(); 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(); } 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({ .property = rmp::behavior::Property::ALPHA, .from = 255, .to = 0, .seconds = SPARK_LIFE, .ease = rmp::behavior::Ease::IN }); spark.add({ .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({ .text = std::string(text), .color = color }); words.add({ .seconds = TEXT_LIFE }); } } // namespace game ``` **`src/objects/hero.cpp` 119 lines** [src/objects/hero.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/objects/hero.cpp) ```cpp // 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 #include #include #include #include #include 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({ .speed = SPEED, .idle = "", .walk = "" }); add(); add({ .radius = 78, .color = { 255, 200, 140, 80 } }); add({ .hp = run().hp, .max_hp = run().max_hp, .invulnerable_for = GRACE, .destroy_on_death = false, .on_death = [](rmp::Object &self) { static_cast(self.scene()).hero_died(); }, .on_damage = [](rmp::Object &self, int amount) { run().hp = self.get()->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(); if (health && health->dead()) { velocity = Vector2{}; enable(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()->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({ .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({ .seconds = SWING_LASTS }); slash.add( { .angle = std::atan2(facing.y, facing.x) * 180 / std::numbers::pi_v }); rmp::audio::play("swing", { .volume = 0.5f }); } } // namespace game ``` **`src/objects/monsters.cpp` 206 lines** [src/objects/monsters.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/objects/monsters.cpp) ```cpp // 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 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 #include #include #include #include #include #include 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 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({ .damage = 1, .hits = layer::HERO, .knockback = TOUCH_KNOCKBACK }); m.add( { .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(); 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( { .damage = 1, .hits = layer::HERO, .knockback = 160, .destroy_on_hit = true }); shot.add({ .destroy_on_wall = true }); shot.add({ .seconds = BOLT_LIFE }); shot.add( { .radius = BOLT_GLOW, .color = Color{ 150, 80, 255, 170 }, .flicker = false }); } } // namespace bool boss_lives() { return static_cast(boss); } void add_monsters(rmp::Scene &scene, rmp::Handle 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({ .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() }); 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()->hp == 1; } }); mind.transitions.push_back( { .from = "flee", .to = "hunt", .when = [](rmp::Object &self) { return self.get()->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({ .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()->on_death = [](rmp::Object &self) { sparks(self.scene(), self.position, FIRE, 40); self.scene().camera.shake(6, 0.6f); static_cast(self.scene()).announce("The Sanctum falls silent"); }; cyclops.add({ .target = hero, .speed = BOSS_SPEED, .clearance = 6 }); cyclops.add({ .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() }); mind.states.push_back({ .name = "volley", .on_enter = [](rmp::Object &self) { self.velocity = {}; }, .enables = b::kinds() }); 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()->seconds_in_state() > HUNT_SECONDS; } }); mind.transitions.push_back( { .from = "volley", .to = "hunt", .when = [](rmp::Object &self) { return self.get()->seconds_in_state() > VOLLEY_SECONDS; } }); cyclops.add(std::move(mind)); cyclops.get()->automatic = true; cyclops.add({ .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 game ``` **`src/objects/things.cpp` 246 lines** [src/objects/things.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/objects/things.cpp) ```cpp // 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 #include #include #include #include #include #include #include #include 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(index % COLUMNS) * TILE, std::floor(static_cast(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>> 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({ .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({ .radius = 14, .color = GEM_LIGHT, .flicker = false }); if (velocity.x != 0 || velocity.y != 0) g.add(); } 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 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({ .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({ .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({ .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({ .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({ .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( { .seconds = SPIKES_EVERY, .on_timeout = [](rmp::Object &self) { const bool up = !self.enabled(); self.enable(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({ .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(); altar.add({ .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({ .radius = 14, .color = Color{ 255, 230, 120, 110 } }); // Picked up with the pointer and laid on the altar: a heart more. rune.add({ .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({ .on_inside = [&scene, to](rmp::Object &, rmp::Object &who) { if (is_hero(who)) scene.go_down(to); } }); stairs.add({ .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({ .on_enter = [&scene](rmp::Object &self, rmp::Object &who) { if (is_hero(who) && self.visible) scene.win(); } }); exit.add({ .radius = 36, .color = Color{ 255, 220, 120, 130 } }); exit.enable(false); exit.add({ .seconds = 0.25f, .on_timeout = [](rmp::Object &self) { if (self.visible || boss_lives()) return; self.visible = true; self.enable(true); sparks(self.scene(), self.position, SHINE, 24); } }); }); } } // namespace game ``` **`src/scenes/end.cpp` 29 lines** [src/scenes/end.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/scenes/end.cpp) ```cpp // The end of a run, won or lost, over the level it ended in. #include "dungeon.h" #include 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("Crypt"); } if (rmp::ui::button("Title")) rmp::Scene::change(); }); }); } } // namespace game ``` **`src/scenes/level.cpp` 150 lines** [src/scenes/level.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/scenes/level.cpp) ```cpp // A level: the map, the hero, what LDtk placed, and the HUD over it all. #include "dungeon.h" #include "cast.h" #include #include #include #include #include #include #include #include #include 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(tile % COLUMNS) * TILE, std::floor(static_cast(tile) / COLUMNS) * TILE, TILE, TILE } }; } // The torchlight's edge: the screen darkens towards its borders. void shade_edges() { const auto w = static_cast(GetScreenWidth()); const auto h = static_cast(GetScreenHeight()); const Color dark{ 10, 4, 6, static_cast(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(w), static_cast(dy), dark, clear); DrawRectangleGradientV(0, static_cast(h - dy), static_cast(w), static_cast(dy), clear, dark); DrawRectangleGradientH(0, 0, static_cast(dx), static_cast(h), dark, clear); DrawRectangleGradientH(static_cast(w - dx), 0, static_cast(dx), static_cast(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.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(); 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(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(level); } void LevelScene::win() { if (_over) return; _over = true; rmp::Scene::push(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(run().hp) / static_cast(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(); 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 game ``` **`src/scenes/pause.cpp` 24 lines** [src/scenes/pause.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/scenes/pause.cpp) ```cpp // The pause: the level frozen and blurred behind it. #include "dungeon.h" #include #include 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(); }); }); } } // namespace game ``` **`src/scenes/title.cpp` 64 lines** [src/scenes/title.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/08_dungeon/src/scenes/title.cpp) ```cpp // The title: the Crypt behind the menu, the camera drifting through it. #include "dungeon.h" #include #include #include #include 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("Crypt"); } #if !defined(PLATFORM_IOS) if (rmp::ui::button("Quit")) rmp::app::quit(); #endif }); rmp::ui::end(); } } // namespace game ``` ============================================================================== # After school > 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. Source: https://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; `<>` 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`](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/tools/make_story_assets.py). ## Run it From a clone of the framework: ```shell rmp example 09_after_school ``` ## Keys Read 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` | ## The code Every file of `examples/games/09_after_school`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school)). **`src/main.cpp` 41 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include "school.h" RMP_GAME(game::TitleScene); ``` **`include/school.h` 128 lines** [include/school.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/include/school.h) ```cpp #pragma once // --------------------------------------------------------------------------- // What every file of the afternoon shares: the story so far, the people, the // scenes and the look. // --------------------------------------------------------------------------- #include #include #include #include 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 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 _you; rmp::Handle _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 game ``` **`src/look.cpp` 109 lines** [src/look.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/look.cpp) ```cpp // 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 #include #include #include #include #include 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 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 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 game ``` **`src/people.cpp` 39 lines** [src/people.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/people.cpp) ```cpp // Everyone who walks through town: which way they look, and who is drawn in // front of whom. #include "school.h" #include #include #include 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(self.position.y); } void face(rmp::Object &who, Vector2 at) { if (auto character = who.get()) { character->facing = { at.x - who.position.x, at.y - who.position.y }; } } } // namespace game ``` **`src/scenery.cpp` 53 lines** [src/scenery.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/scenery.cpp) ```cpp // 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 #include #include #include 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 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(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 game ``` **`src/scenes/end.cpp` 91 lines** [src/scenes/end.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/scenes/end.cpp) ```cpp // 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 #include #include #include #include #include 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 &lanterns() { static std::array 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(); }); rmp::ui::end(); } } // namespace game ``` **`src/scenes/pause.cpp` 27 lines** [src/scenes/pause.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/scenes/pause.cpp) ```cpp // The pause: the town waits below. #include "school.h" #include #include 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(); } }); }); } } // namespace game ``` **`src/scenes/title.cpp` 73 lines** [src/scenes/title.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/scenes/title.cpp) ```cpp // The title: the town behind the menu, the camera drifting over it, and the // language you read it in. #include "school.h" #include #include #include #include #include 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(); } if (rmp::ui::button("New afternoon")) { new_story(); rmp::Scene::change(); } // 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 game ``` **`src/scenes/town.cpp` 300 lines** [src/scenes/town.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/scenes/town.cpp) ```cpp // 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 <> 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 #include #include #include #include #include #include #include #include #include #include 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 <> goes, by the names LDtk gives them, and who is in town. struct Town { std::map> places; std::map, std::less<>> people; }; Town &town() { return rmp::global(); } 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 them = walker->second; const Vector2 to = place->second; if (const auto o = them.get()) { if (auto path = o->get()) 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(); 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({ .speed = SPEED, .idle = "", .walk = "" }); you.add({ .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({ .speed = STROLL, .clearance = FEET.x / 2 }); them.add(); rmp::behavior::Talker talker = rmp::behavior::Talker::from(o); talker.player = _you; talker.on_load = [this](rmp::Dialogue &d) { prepare(d); }; const rmp::Handle me = them.handle(); talker.on_talk = [this, me](rmp::Dialogue &) { talking(me); }; talker.on_done = [this] { done_talking(); }; them.add(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 me = home.handle(); talker.on_talk = [this, me](rmp::Dialogue &) { talking(me); }; talker.on_done = [this] { done_talking(); }; home.add(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( { .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 speaker) { _speaker = speaker; _stage.ours = {}; const auto them = speaker.get(); const auto talker = them ? them->get() : rmp::Ref{}; // 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(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(true); save_story(); if (_ending.empty()) return; forget_story(); rmp::Scene::change(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(); 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(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::Ref{}; 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::Ref{}; 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 game ``` **`src/story.cpp` 76 lines** [src/story.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/games/09_after_school/src/story.cpp) ```cpp // 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 #include #include #include 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(); } 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(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 game ``` ============================================================================== # Input > The examples under examples/input/. Source: https://omardev29.github.io/rmp-docs/examples/input/index.html - [Actions](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. ============================================================================== # Actions > 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. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 01_actions ``` ## Keys Read 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` | ## The code Every file of `examples/input/01_actions`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/input/01_actions)). **`src/main.cpp` 102 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/input/01_actions/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include 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(); // 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); ``` ============================================================================== # Platform > The examples under examples/platform/. Source: https://omardev29.github.io/rmp-docs/examples/platform/index.html - [Mobile raymob](https://omardev29.github.io/rmp-docs/examples/platform/02_mobile_raymob.html) — The raymob mobile API: vibration, soft keyboard, sensors, orientation, app storage. - [Minimal includes](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 `` 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. ============================================================================== # Mobile raymob > The raymob mobile API: vibration, soft keyboard, sensors, orientation, app storage. Source: 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. Not playable here It calls raymob's Android API — vibration, the soft keyboard, the sensors — which a browser does not have. ## Run it From a clone of the framework: ```shell rmp example 02_mobile_raymob ``` ## Keys Read 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` | ## The code Every file of `examples/platform/02_mobile_raymob`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/platform/02_mobile_raymob)). **`src/main.cpp` 78 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/platform/02_mobile_raymob/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 , 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 #include // RMP_ENTRY_POINT #ifdef __ANDROID__ #include #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(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); ``` ============================================================================== # Minimal includes > The proof that rmp/ui.h stands alone. One translation unit that includes 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. Source: 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 `` 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. Not playable here It has no `main()` on purpose: it is compiled and never run, to prove that rmp/ui.h stands alone. ## Run it From a clone of the framework: ```shell rmp example 03_minimal_includes ``` ## The code Every file of `examples/platform/03_minimal_includes`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/platform/03_minimal_includes)). **`src/hud.cpp` 65 lines** [src/hud.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/platform/03_minimal_includes/src/hud.cpp) ```cpp // --------------------------------------------------------------------------- // What you include is what you use. // // There is no umbrella header. `#include ` gives you the interface // layer and NOTHING else: no entry point, no asset layer, no ads, no // and no 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 <- this file // src/main.cpp #include // // 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 #include 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(); } ``` ============================================================================== # Scenes > The examples under examples/scenes/. Source: https://omardev29.github.io/rmp-docs/examples/scenes/index.html - [Stack](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. - [Stretch](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. ============================================================================== # Stack > 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. Source: 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()` for the score that survives the transition. **Start here.** ## Run it From a clone of the framework: ```shell rmp example 01_stack ``` ## Keys Read 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` | ## The code Every file of `examples/scenes/01_stack`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack)). **`src/main.cpp` 39 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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()` 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 #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** [include/progress.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/include/progress.h) ```cpp #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(), 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** [src/scenes/game.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/scenes/game.cpp) ```cpp #include "game.h" #include "pause.h" #include "progress.h" #include #include #include #include namespace { constexpr float PLAYER_SPEED = 220.0f; // units per second } // namespace void GameScene::_ready() { ++rmp::global().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(_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(); rmp::ui::end(); } void GameScene::_end() { Progress &p = rmp::global(); if (_score > p.best_score) p.best_score = _score; } ``` **`src/scenes/game.h` 22 lines** [src/scenes/game.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/scenes/game.h) ```cpp #pragma once #include #include class GameScene : public rmp::Scene { public: // Constructor arguments cross a transition the way arguments normally // cross into an object: Scene::change(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 _player; }; ``` **`src/scenes/main_menu.cpp` 31 lines** [src/scenes/main_menu.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/scenes/main_menu.cpp) ```cpp #include "main_menu.h" #include "game.h" #include "progress.h" #include #include #include void MainMenuScene::_draw() { rmp::ui::begin(); rmp::ui::text("Scene stack example"); // change() 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(1); const Progress &p = rmp::global(); 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** [src/scenes/main_menu.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/scenes/main_menu.h) ```cpp #pragma once #include class MainMenuScene : public rmp::Scene { public: void _draw() override; }; ``` **`src/scenes/pause.cpp` 17 lines** [src/scenes/pause.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/scenes/pause.cpp) ```cpp #include "pause.h" #include "main_menu.h" #include 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(); }); } ``` **`src/scenes/pause.h` 10 lines** [src/scenes/pause.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/01_stack/src/scenes/pause.h) ```cpp #pragma once #include // Every default untouched. This is the whole example's point: // push() 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; }; ``` ============================================================================== # Stretch > [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. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 02_stretch ``` ## Keys Read 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` | ## The code Every file of `examples/scenes/02_stretch`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/02_stretch)). **`src/main.cpp` 143 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/scenes/02_stretch/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include 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); ``` ============================================================================== # UI > The examples under examples/ui/. Source: https://omardev29.github.io/rmp-docs/examples/ui/index.html - [Menu](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. - [Layout](https://omardev29.github.io/rmp-docs/examples/ui/02_layout.html) — `row`, `column`, `panel`, `center`, `stack`/`layer`, `spacer`, plus `image` and `progress`. - [Clay direct](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. - [Settings](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. - [Inventory](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. - [Style](https://omardev29.github.io/rmp-docs/examples/ui/06_style.html) — The two themes, the five variants, the three sizes and the transition. - [Responsive](https://omardev29.github.io/rmp-docs/examples/ui/07_responsive.html) — `scale()` versus `current_breakpoint()`, and which to reach for. - [Overlay](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. - [Skinned](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. - [Dialogue](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 `<>`. - [Localization](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`). - [Font](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()`. ============================================================================== # Menu > 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. Source: 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.** ## Run it From a clone of the framework: ```shell rmp example 01_menu ``` ## Keys Read 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` | ## The code Every file of `examples/ui/01_menu`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu)). **`src/main.cpp` 49 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #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** [src/scenes/confirm.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/scenes/confirm.cpp) ```cpp // Two buttons with the same label, in different screens. #include "screens.h" #include #include 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(); rmp::ui::end(); } ``` **`src/scenes/main_menu.cpp` 18 lines** [src/scenes/main_menu.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/scenes/main_menu.cpp) ```cpp // The whole point: a main menu. #include "screens.h" #include 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(); if (rmp::ui::button("Options")) change(); if (rmp::ui::button("Quit")) change(); rmp::ui::end(); } ``` **`src/scenes/options.cpp` 29 lines** [src/scenes/options.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/scenes/options.cpp) ```cpp // One step up: options on the widgets. #include "screens.h" #include #include 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(); rmp::ui::end(); } ``` **`src/scenes/playing.cpp` 29 lines** [src/scenes/playing.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/scenes/playing.cpp) ```cpp // A HUD: not everything is a centred menu. #include "screens.h" #include #include #include 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(); } 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** [src/scenes/screens.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/01_menu/src/scenes/screens.h) ```cpp #pragma once // One scene per screen, one file per scene under src/scenes/. Going from one // to the next is rmp::Scene::change(): the scene on screen ends, the next // one starts, at the end of the frame the button was pressed in. #include // 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; }; ``` ============================================================================== # Layout > row, column, panel, center, stack/layer, spacer, plus image and progress. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 02_layout ``` ## The code Every file of `examples/ui/02_layout`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/02_layout)). **`src/main.cpp` 168 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/02_layout/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include 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. ``` ============================================================================== # Clay direct > The escape hatch. Clay's own macros in the same frame as rmp::ui, for anything the small API does not expose yet. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 03_clay_direct ``` ## The code Every file of `examples/ui/03_clay_direct`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/03_clay_direct)). **`src/main.cpp` 140 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/03_clay_direct/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 // // 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 #include #include #include #include // 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. ``` ============================================================================== # Settings > Checkbox, slider, dropdown, text input — and the focus/keyboard/gamepad navigation you get without writing any. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 04_settings ``` ## The code Every file of `examples/ui/04_settings`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/04_settings)). **`src/main.cpp` 274 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/04_settings/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include "settings.h" #include #include 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(s.quality)]); TraceLog(LOG_INFO, "SETTINGS: applied (master %.2f, quality %s)", static_cast(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(QUALITY.size()) - 1); s.language = std::clamp(v["language"].as_int(s.language), 0, static_cast(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** [include/settings.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/04_settings/include/settings.h) ```cpp #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 #include #include 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 QUALITY{ "Low", "Medium", "High", "Ultra" }; inline constexpr std::array LANGUAGE{ "English", "Espanol", "Francais" }; ``` ============================================================================== # Inventory > 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. Source: 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/`. ## Run it From a clone of the framework: ```shell rmp example 05_inventory ``` ## Keys Read 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` | ## The code Every file of `examples/ui/05_inventory`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory)). **`src/main.cpp` 89 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #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** [include/inventory.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory/include/inventory.h) ```cpp #pragma once #include #include #include 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 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** [src/panels/grid.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory/src/panels/grid.cpp) ```cpp // 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 #include 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** [src/panels/list.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/05_inventory/src/panels/list.cpp) ```cpp // 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 #include 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 }); }); } ``` ============================================================================== # Style > The two themes, the five variants, the three sizes and the transition. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 06_style ``` ## The code Every file of `examples/ui/06_style`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/06_style)). **`src/main.cpp` 190 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/06_style/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include 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); ``` ============================================================================== # Responsive > scale() versus current_breakpoint(), and which to reach for. Source: 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. ## Run it From a clone of the framework: ```shell rmp example 07_responsive ``` ## The code Every file of `examples/ui/07_responsive`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/07_responsive)). **`src/main.cpp` 173 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/07_responsive/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include namespace { constexpr std::array SECTIONS{ "World", "Bestiary", "Journal", "Crafting", "Map" }; constexpr int SECTION_COUNT = static_cast(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(i % 10) / 9.0f); }); }); } }); }); } }); } }; RMP_GAME(ResponsiveScene); ``` ============================================================================== # Overlay > 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. Source: 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/`. ## Run it From a clone of the framework: ```shell rmp example 08_overlay ``` ## The code Every file of `examples/ui/08_overlay`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/08_overlay)). **`src/main.cpp` 32 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/08_overlay/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include "scenes/game.h" RMP_GAME(GameScene); ``` **`src/scenes/game.cpp` 74 lines** [src/scenes/game.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/08_overlay/src/scenes/game.cpp) ```cpp #include "game.h" #include "pause.h" #include #include #include #include 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(); #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** [src/scenes/game.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/08_overlay/src/scenes/game.h) ```cpp #pragma once #include 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** [src/scenes/pause.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/08_overlay/src/scenes/pause.cpp) ```cpp #include "pause.h" #include 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** [src/scenes/pause.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/08_overlay/src/scenes/pause.h) ```cpp #pragma once #include // 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; }; ``` ============================================================================== # Skinned > The other way to write rmp::ui: a game's shop screen designed rather than written. Source: 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`. ## Run it From a clone of the framework: ```shell rmp example 09_skinned ``` ## The code Every file of `examples/ui/09_skinned`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/09_skinned)). **`src/main.cpp` 32 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/09_skinned/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include "scenes/shop.h" RMP_GAME(ShopScene); ``` **`src/scenes/shop.cpp` 126 lines** [src/scenes/shop.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/09_skinned/src/scenes/shop.cpp) ```cpp #include "shop.h" #include #include 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(_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** [src/scenes/shop.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/09_skinned/src/scenes/shop.h) ```cpp #pragma once #include #include #include #include // 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; } }; }; ``` ============================================================================== # Dialogue > 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 <>. Source: 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 `<>`. 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 `<>`. Kenney's art, from [`tools/make_story_assets.py`](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/tools/make_story_assets.py). ## Run it From a clone of the framework: ```shell rmp example 10_dialogue ``` ## The code Every file of `examples/ui/10_dialogue`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/10_dialogue)). **`src/main.cpp` 171 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/10_dialogue/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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, <> a command. The // script waits a second by itself (<>). // // The art is Kenney's (CC0): tools/make_story_assets.py. The words are // resources/talk.yarn. Run it: `rmp example 10_dialogue`. // --------------------------------------------------------------------------- #include #include #include #include #include #include #include #include namespace { constexpr float FRAME = 12; // panel.png's border, in its pixels constexpr float PLATE = 10; // plate.png's constexpr std::array 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 portraits() { const auto picture = [](const std::string &file) -> rmp::ui::Picture { return rmp::assets::load_texture(file); }; std::vector 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 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 _people; rmp::ui::DialogueBox _box; rmp::ui::DialogueBubble _bubble; rmp::ui::DialogueStage _stage; }; RMP_GAME(ParkScene); ``` ============================================================================== # Localization > 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). Source: 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`). ## Run it From a clone of the framework: ```shell rmp example 11_localization ``` ## The code Every file of `examples/ui/11_localization`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/11_localization)). **`src/main.cpp` 137 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/11_localization/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include #include #include 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); ``` ============================================================================== # Font > 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(). Source: 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. ## Run it From a clone of the framework: ```shell rmp example 12_font ``` ## Keys Read 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` | ## The code Every file of `examples/ui/12_font`, as it is at the commit this site documents ([on GitHub](https://github.com/omardev29/raylib_multiplatform/tree/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/12_font)). **`src/main.cpp` 29 lines** [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/12_font/src/main.cpp) ```cpp // --------------------------------------------------------------------------- // 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 #include "scenes/scenes.h" RMP_GAME(TitleScene); ``` **`src/scenes/credits.cpp` 25 lines** [src/scenes/credits.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/12_font/src/scenes/credits.cpp) ```cpp // The credits, which is where a font's author goes. #include "scenes.h" #include #include void CreditsScene::_update(float) { if (rmp::input::just_pressed("ui_cancel")) change(); } 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(); }); rmp::ui::end(); } ``` **`src/scenes/options.cpp` 29 lines** [src/scenes/options.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/12_font/src/scenes/options.cpp) ```cpp // The options: every kind of control, and every one of them in the font. #include "scenes.h" #include #include #include #include namespace { constexpr std::array 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(); } 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(); }); rmp::ui::end(); } ``` **`src/scenes/scenes.h` 28 lines** [src/scenes/scenes.h](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/12_font/src/scenes/scenes.h) ```cpp #pragma once #include // 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** [src/scenes/title.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/examples/ui/12_font/src/scenes/title.cpp) ```cpp // The title screen, and where the font is set. #include "scenes.h" #include #include #include 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(); if (rmp::ui::button("Credits")) change(); #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(); } ``` ============================================================================== # Publishing > A release is a git tag: rmp deploy checks it and pushes it, and CI builds every target the game has turned on and attaches them to a GitHub release. Source: 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. ```shell rmp deploy 1.2.0 ``` There 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](https://omardev29.github.io/rmp-docs/publishing/releases.html) 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. ## Before the first release Four things are yours to decide once, and the first one cannot be changed afterwards. 1. **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. raylib_multiplatform.toml ```toml [android] application_id = "com.yourname.yourgame" [ios] bundle_id = "com.yourname.yourgame" ``` 2. **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](https://omardev29.github.io/rmp-docs/reference/configuration.html#section-targets). 3. **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](https://omardev29.github.io/rmp-docs/publishing/desktop.html#where-the-saves-go) has the folders. 4. **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. ```shell rmp push rmp deploy 1.0.0 ``` ## What a release holds One 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: - A zip per desktop and BSD target: the executable, its assets in a `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](https://omardev29.github.io/rmp-docs/publishing/desktop.html). - `web-build.zip`: the page, its script, the WebAssembly module, the preloaded assets and the web build's own `LICENSES.txt`. [The web build](https://omardev29.github.io/rmp-docs/publishing/web.html). - The Android debug APK, and the signed App Bundle when the signing secrets are set. [Google Play](https://omardev29.github.io/rmp-docs/publishing/google-play.html). - The iOS engine as an xcframework, and a simulator build of the app. [The App Store](https://omardev29.github.io/rmp-docs/publishing/app-store.html). - `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. ## Where each build goes | Page | What it covers | |---|---| | [Releases and versions](https://omardev29.github.io/rmp-docs/publishing/releases.html) | 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](https://omardev29.github.io/rmp-docs/publishing/desktop.html) | What is in each zip, what a release is hardened with, the glibc floor on Linux, compressing with UPX, signing. | | [The web build](https://omardev29.github.io/rmp-docs/publishing/web.html) | The files, hosting them, memory, size and the browser backend. | | [itch.io](https://omardev29.github.io/rmp-docs/publishing/itch.html) | Pushing every build to itch.io with butler, on every tag. | | [Google Play](https://omardev29.github.io/rmp-docs/publishing/google-play.html) | The application id, signing the App Bundle, the version code, and Firebase Test Lab. | | [The App Store](https://omardev29.github.io/rmp-docs/publishing/app-store.html) | What CI builds for iOS, what it leaves to Xcode on a Mac, and why. | | [Continuous integration](https://omardev29.github.io/rmp-docs/publishing/ci.html) | 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. | ## Secrets and variables 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](https://omardev29.github.io/rmp-docs/publishing/google-play.html#signing) | | `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](https://omardev29.github.io/rmp-docs/publishing/itch.html) | | `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](https://omardev29.github.io/rmp-docs/publishing/google-play.html#firebase-test-lab) | | `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/app-store.html#what-ci-builds) | NeverNever put a secret in `raylib_multiplatform.toml`. The file is committed, so anything in it is readable by everyone who can read the repository, for as long as the history exists. The keys the .toml does have under `[deploy]` — an itch.io user name, a Google Cloud project id — are names, not credentials. ============================================================================== # Releases and versions > A release is a vMAJOR.MINOR.PATCH tag that rmp deploy checks and pushes; the version name and the Android version code come from it, and CI turns it into a GitHub release. Source: 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. ## A release is a tag ```shell rmp deploy 1.2.0 ``` That 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: ```text == 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.0 ``` The 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. ## The version comes from the tag 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: ```text 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.2 ``` ### Pre-releases A 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. ```shell rmp deploy 1.2.0-rc1 ``` A `+` suffix is build metadata, not a pre-release: `v1.2.0+7` is published as a normal release. ## The Android version code 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: ```text versionCode = MAJOR * 1000000 + MINOR * 1000 + PATCH ``` That 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: - **Nothing compares a tag with the previous one.** The code rises only if your tags do. Tag `v1.0.0` after `v2.0.0` and the build gets a lower code than the one Play already has, and Play refuses it. - **A pre-release shares its version's code.** `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. ## What rmp deploy checks 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: 1. **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.` 2. **The tag is new here.** `FAIL: the tag v1.2.0 already exists here.` 3. **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. 4. **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 `, which pushes it and ties it to `origin`; with no remote at all, it stops and says how to add one. 5. **The commit is the one `origin` has.** `HEAD` must be exactly what `origin/` 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. 6. **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.`: ```text == 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. 7. **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. ### A tag pushed by hand 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](https://omardev29.github.io/rmp-docs/publishing/releases.html#undoing-a-tag). Only tags that start with `v` start a release run at all. ## What CI does with a tag A tag runs the full matrix: every target `[targets]` enables, each built, checked and, where CI can, booted ([Continuous integration](https://omardev29.github.io/rmp-docs/publishing/ci.html) 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: - the `lint` job passed — in a game, that is the workflows, the configuration, the pinned versions, the licences and a frame drawn in software; - and no platform job failed or was cancelled. A platform you switched off in `[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](https://omardev29.github.io/rmp-docs/publishing/itch.html) 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. ## What the release holds 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.zip` `linux-arm64-glibc-build.zip` `linux-riscv64-glibc-build.zip` `linux-x64-musl-build.zip` `linux-x64-glibc-drm-build.zip` `linux-arm64-glibc-drm-build.zip` | Linux: the executable, its assets and `LICENSES.txt`. [Desktop and BSD archives](https://omardev29.github.io/rmp-docs/publishing/desktop.html#linux) | | `windows-x64-build.zip` `windows-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.zip` `bsd-freebsd-arm64-build.zip` `bsd-openbsd-x86-64-build.zip` `bsd-openbsd-arm64-build.zip` `bsd-netbsd-x86-64-build.zip` | FreeBSD, OpenBSD and NetBSD, built in their own virtual machines. | | `web-build.zip` | The browser build. [The web build](https://omardev29.github.io/rmp-docs/publishing/web.html) | | 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](https://omardev29.github.io/rmp-docs/publishing/google-play.html) | | `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](https://omardev29.github.io/rmp-docs/publishing/app-store.html) | | `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. ### Checking a download `SHA256SUMS` lists every archive by its file name, as the release has it. With the files downloaded next to it: ```shell sha256sum -c SHA256SUMS # every file it lists sha256sum -c --ignore-missing SHA256SUMS # only the ones you downloaded ``` ### The licence notices Every 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: raylib_multiplatform.toml ```toml [deploy] licenses = false ``` ```text 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. ``` raylib_multiplatform.toml ```toml [deploy] licenses = false credits_note = "the Credits scene, from the main menu" ``` ## Undoing a tag **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: ```shell git push --delete origin v1.2.0 && git tag -d v1.2.0 ``` Deleting 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: ```shell gh release delete v1.2.0 --cleanup-tag ``` Then 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: ```shell gh run rerun --failed ``` ============================================================================== # Desktop and BSD archives > What is in the zip CI makes for each Windows, macOS, Linux and BSD target, what each asks of a player's machine — no DLL, macOS 10.15, the Linux glibc floor — what it is hardened with, and what compressing with UPX costs. Source: https://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. ## What an archive holds Unpacked, an archive is a folder like this, with your `[project] name` as the executable's name: ```text 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---build.zip` | FreeBSD, OpenBSD or NetBSD ELF | the pack | ### The pack, and when there is none `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. ### It starts from any folder 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 `/`. ## Built to be hard to exploit A game reads files a player can change — its saves, its assets — and a memory mistake that a debug build's [sanitizers](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#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:`. - **Linux, macOS and the BSDs:** the stack protector, `-fstack-protector-strong`, and the cheap bounds checks of the C++ library, libstdc++'s and libc++'s. - **Linux and the BSDs**, on top of that: stack-clash protection; relocations made read-only once the loader is done, and every symbol bound at start (RELRO and BIND_NOW); a stack that is not executable; and `_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. - **Windows:** MSVC's defaults are the stack protector, ASLR, data execution prevention and high-entropy addresses; Clang building for Microsoft's ABI links with `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. - **macOS, iOS and Android** are position-independent by the platform's rule, and Android's toolchain adds the stack protector and `_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: ```shell python3 tools/binary_check.py elf --pie build/release/my_game ``` ## Where the saves go [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) 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 | raylib_multiplatform.toml ```toml [save] portable = true ``` Only 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. ## Linux 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. ### The glibc floor 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: raylib_multiplatform.toml ```toml [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: raylib_multiplatform.toml ```toml [linux] glibc = "2.16" ``` ```text 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: - **DRM** links the system's `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 `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. - **Nothing to install.** A player's machine has Windows and nothing else, so the compiler's C and C++ runtimes are linked into the `.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. - **The icon.** Windows keeps a program's icon inside the `.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. - **The windowing backend.** `[windows] backend` is `"glfw"` by default; `"win32"` and `"rgfw"` drop GLFW for a smaller `.exe` and cover less — gamepads, several monitors, the clipboard. - **Tested on a real Windows.** CI starts the x64 `.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 `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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) 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. ## Signing 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](https://omardev29.github.io/rmp-docs/publishing/desktop.html#compressing-with-upx)). ## FreeBSD, OpenBSD and NetBSD `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. ## Compressing with UPX 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: raylib_multiplatform.toml ```toml [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: raylib_multiplatform.toml ```toml [upx] enabled = ["macos"] ``` ```text 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: raylib_multiplatform.toml ```toml [upx] enabled = ["linux-x64"] ``` ```text 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-x64 ``` The trade-offs of the targets that can be compressed: - **Windows** is available and off by default. An unsigned `.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. - **The BSDs** are available and off by default, because nothing has tested a packed BSD binary. - **A binary that is too big is left alone.** UPX itself refuses files past about 768 MB, and fails rather than declining. `[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: raylib_multiplatform.toml ```toml [upx] max_size_mb = 0 ``` ```text 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. ============================================================================== # The web build > The browser build is four static files compiled with Emscripten; this is what each one is, how to host them, and what decides their memory and their size. Source: 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. ## Building it Locally, the web build needs the Emscripten SDK, activated in the shell you build from so that `EMSDK` is set: ```shell rmp web python3 -m http.server 8000 --directory build/web ``` Then 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. ## The files | 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. ## Hosting it 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](https://omardev29.github.io/rmp-docs/publishing/itch.html) covers the upload. What the browser changes, and what the framework does about it: The frame The browser owns the loop: the game draws a frame each time the browser asks the page for one. `[window] fps` and `vsync` do nothing on the web, and the framework never calls `SetTargetFPS()` there. Saves [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) 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. Sound Browsers keep a page silent until the player does something. A click or a touch unlocks the sound, and so does a key press: a game played from the keyboard from its title screen on is not silent until the first click. A gamepad button does not count as a gesture to the browser. ## Memory A WebAssembly module gets its memory when it starts. `[web] memory` is how much, in megabytes: raylib_multiplatform.toml ```toml [web] memory = 256 grow = false ``` The 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: raylib_multiplatform.toml ```toml [web] memory = 8 ``` ```text 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. ``` ## Size What the player downloads is mostly the `.wasm` and the `.data`. What decides each: - **The code** is compiled for size (`-Oz`), and unused functions are dropped when it is linked. - **No ASYNCIFY.** The framework hands the frame loop to the browser instead of running a loop of its own, which is what lets it build without Emscripten's ASYNCIFY: that rewrites every function that could be on the stack while the game waits, and the framework's own measurement of it was a quarter more `.wasm`. - **raylib modules you do not use.** `[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. - **Your assets** make up the `.data`, as they are in `resources/`. raylib_multiplatform.toml ```toml [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. ## The browser backend 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: raylib_multiplatform.toml ```toml [web] backend = "rgfw" ``` ```text 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. ``` ## What CI checks 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`. ============================================================================== # itch.io > On every release tag CI pushes each build itch.io can use to your game's page with butler; it needs a user, a game and one secret. Source: 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. ## Setting it up 1. **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. 2. **Write them in the .toml.** They are names, not secrets, so they live with the rest of the game: raylib_multiplatform.toml ```toml [deploy.itch] user = "yourname" game = "your-game" ``` 3. **Add the API key as a secret.** Make a key on [itch.io's API keys page](https://itch.io/user/settings/api-keys) and store it in the repository as `BUTLER_API_KEY` — under *Settings → Secrets and variables → Actions*, or from a terminal: ```shell gh secret set BUTLER_API_KEY ``` 4. **Release.** The next tag publishes: ```shell rmp deploy 1.0.0 ``` The 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: raylib_multiplatform.toml ```toml [deploy.itch] user = "yourname" ``` ```text 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. ## Channels 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](https://omardev29.github.io/rmp-docs/publishing/google-play.html)). 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. - The BSD builds: itch.io has no BSD platform. - `ios`: there is no way to install an iOS app from a downloaded file. ## Versions 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: ```shell butler push payload yourname/your-game:html5 --userversion v1.2.0 ``` ## When it runs Only 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. ## Saves in a downloaded build 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: raylib_multiplatform.toml ```toml [save] portable = true ``` It applies to the Windows and Linux builds; macOS, the web and Android keep their saves where those platforms keep them. [Where the saves go](https://omardev29.github.io/rmp-docs/publishing/desktop.html#where-the-saves-go) has the folders. ============================================================================== # Google Play > Google Play takes a signed App Bundle: CI builds and verifies one on every run, signs it with your upload key from four repository secrets, and can run the game in Firebase Test Lab. Source: 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. ## The application id is permanent 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`: raylib_multiplatform.toml ```toml [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: raylib_multiplatform.toml ```toml [android] application_id = "com.yourname.your-game" ``` ```text 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. ## Signing Play needs the bundle signed with your *upload key*. You make it once, keep it, and hand it to CI as secrets. 1. **Make an upload keystore**, and keep it somewhere you will not lose it: ```shell keytool -genkey -v -keystore upload.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload ``` Turn on **Play App Signing** in the Play Console, so Google can reset your upload key if you do lose it. 2. **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 | ```shell 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_PASSWORD ``` 3. **Optionally, 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. NeverNever commit the keystore, and never write its passwords in `raylib_multiplatform.toml` or anywhere else in the repository. Whoever has the upload key and its passwords can publish as you. ### What CI does with them 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. ### Signing on your own machine 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: ```shell 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 bundleRelease ``` Gradle 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`. ## The version code 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](https://omardev29.github.io/rmp-docs/publishing/releases.html#the-android-version-code) 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. ## Uploading The framework uploads nothing to Play: the bundle is on the GitHub release, and the Play Console is where it goes from there. ```shell 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. ## What Play asks of the build - **A recent target SDK.** The app targets and compiles against API 36, which Play requires of new apps and of updates from 2026-08-31. Play raises that requirement about once a year, and meeting it means moving the Android SDK, the NDK, the Android Gradle plugin and Gradle together, as one set. - **16 KB pages.** The native code is built with NDK r28, whose default is the 16 KB ELF page alignment Play requires alongside that target. - **The oldest Android** is `[android] min_sdk`, 24 by default (Android 7.0), between 21 and 36. - **Who is offered the app.** `[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. - **What it asks for.** Every permission is visible on the listing. `[android.permissions]` has `internet` and `vibration`, both off by default; `internet` is turned on regardless when AdMob is in the build. - **How Play files it.** `[android] category`, `"game"` by default. ## Ads, and the Data safety form 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) 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: raylib_multiplatform.toml ```toml [android.admob] enabled = true ``` With `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: raylib_multiplatform.toml ```toml [android.admob] enabled = true app_id = "ca-app-pub-3940256099942544/1033173712" ``` ```text 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. ## Firebase Test Lab 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: raylib_multiplatform.toml ```toml [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`. raylib_multiplatform.toml ```toml [deploy.firebase] project_id = "My Game" ``` ```text 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: 1. Create or pick a Google Cloud project, and give it Blaze billing: Test Lab has no free quota. 2. Enable its APIs: `gcloud services enable testing.googleapis.com toolresults.googleapis.com`. 3. Create a service account with the roles `roles/cloudtesting.testAdmin` and `roles/cloudtoolresults.testAdmin`. 4. Create a JSON key for it, and store the whole file as the secret `GCP_SA_KEY`. 5. Optionally, set the repository variable `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. ============================================================================== # The App Store > What CI builds for iOS — the engine and a simulator build of the app — and why archiving, signing and TestFlight are left to Xcode on a Mac. Source: 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. ## What CI builds 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: 1. builds `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; 2. generates the Xcode project from `raylib_multiplatform.toml`; 3. builds the app for the simulator, without signing; 4. checks what it built: the executable is a Mach-O, the bundle's `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. ### Trying the simulator build On a Mac with Xcode, from the release's `ios-app-simulator.zip`: ```shell 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.yourgame ``` ## What CI does not do, and why Archiving, 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. ## Onto a phone, and to the App Store On a Mac with Xcode and [an Apple developer account](https://developer.apple.com/), from your game's folder: 1. **Fetch the fork.** A game made with `rmp new` has the submodule registered and not checked out, since only iOS needs it: ```shell git submodule update --init thirdparty/raylib-ios ``` 2. **Build the engine**, `raylib.xcframework` with its device and simulator slices, the same way CI does. Once, and again only when the submodule moves: ```shell (cd thirdparty/raylib-ios/projects/scripts && bash build-ios-xcframework.sh) ``` 3. **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: raylib_multiplatform.toml ```toml [ios.settings] DEVELOPMENT_TEAM = "ABCDE12345" CODE_SIGN_STYLE = "Automatic" ``` 4. **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`: ```shell python3 tools/configure.py cd ios && xcodegen generate open my_game.xcodeproj ``` 5. **Run it on your phone**: select the device and press Run. 6. **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. ## What the generated project sets | 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. | raylib_multiplatform.toml ```toml [ios] deployment_target = "12.0" ``` ```text 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. ``` ## What is different on iOS - **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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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: ```cpp #if !defined(PLATFORM_IOS) if (rmp::ui::button("Quit")) rmp::app::quit(); #endif ``` - **raylib is prebuilt.** The app links the fork's `raylib.xcframework`, so `[raylib] disabled_modules` changes nothing on iOS. - **No ads.** [`rmp::ads`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) does nothing on iOS; ads are implemented for Android only. - **The frame is paced by the display.** `[window] fps` is ignored on iOS. ## Keeping up with Xcode 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. ============================================================================== # Continuous integration > What CI builds, boots and checks for each target on a push and on a tag, the size it holds every release binary to, what it pins so the build cannot change under you, and how to read a run that went red. Source: 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. ## When it runs | 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`](https://omardev29.github.io/rmp-docs/publishing/ci.html#on-push). | | 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. ```shell 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,macos ``` `targets` 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. ### Only when you ask: [ci] on_push 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](https://docs.github.com/en/billing/concepts/product-billing/github-actions), from a monthly allowance, and a fast lane on every commit can spend it. One line of the `.toml` turns those runs off: raylib_multiplatform.toml ```toml [ci] on_push = false ``` Then 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: ```yaml 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. ### RISC-V on RISC-V: [ci] riscv64 `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](https://riscv-runners.riseproject.dev/) 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](https://cloud-v.co/github-riscv-runner) 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 | raylib_multiplatform.toml ```toml [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. ## What each target gets 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](https://omardev29.github.io/rmp-docs/publishing/desktop.html#hardening). | | `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](https://omardev29.github.io/rmp-docs/manual/platforms/linux-console.html) 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#gradle-offline)). 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#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`](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers) 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](https://omardev29.github.io/rmp-docs/framework/testing.html#e2e), measure [what the framework's tests reach](https://omardev29.github.io/rmp-docs/framework/testing.html#coverage), run the [deep tests' short runs](https://omardev29.github.io/rmp-docs/framework/testing.html#ci), 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. ### What booted means 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=0` A window opened, and every asset the game asked for was found and decoded: a file that is there and cannot be read as an image, a sound, a song or a font counts as failed, the same as a missing one. Neither stops a game from starting, which is why the count is part of the marker. `RAY_TEST_RENDER_OK` A frame was read back, and the share of its pixels that differ from its most common colour is in a sane range. A broken shader or a lost texture still boots and still exits cleanly; a blank frame does not pass this. `RAY_TEST_DONE_FRAMES` The game drew every frame of its budget without dying: a crash in the middle of a run fails here. It is printed at the end of the last frame, before the game shuts down, so a crash while it shuts down comes after it. A 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. ### What no job checks - `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. - On macOS and the BSDs, what is booted is a software-rendered build of the game, not the executable that ships; the shipped one is checked statically. - A binary compressed with UPX is started only on `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`. - iOS is not started unless you turn the simulator test on, and Android is not started unless Firebase Test Lab is configured. - Nothing here plays your game. A game that boots and draws and is broken from its second screen on passes every gate. Test your game on the platforms you ship. ## The size budget 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. ```text # binary kind unpacked packed linux-x64-glibc elf 1310720 389120 # measured at 1a2b3c4 windows-x64 pe 2293760 - # measured at 1a2b3c4 ``` That 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: ```shell 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. ## What is pinned 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: - **The build image, by digest.** The Linux builds, the web and Android builds, the lint job and the itch.io upload run inside `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. - **Gradle, from the image.** The image also carries a Gradle home warmed for the framework's Gradle wrapper, its Android build plugin and the AdMob SDK, and the Android job runs Gradle with `--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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#android-gradle_offline): Gradle then downloads what the image lacks, and the job says so in a warning. `rmp android` on your machine is never offline. - **The runners and Xcode.** Runner images by explicit label, never `-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. - **Every download** the other jobs make — Ninja and XcodeGen on macOS, Mesa and UPX on Windows — at a fixed version, checked against its `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`. - **The Alpine the musl build is started on** is the framework's own image, `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. - **Every GitHub Action**, by the full commit it resolves to, with the tag in a comment beside it. 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. ## The canary 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. ## Secrets and variables 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. ## Reading a red run 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#android-gradle_offline) | | 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](https://omardev29.github.io/rmp-docs/publishing/google-play.html#signing) | | `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: ```shell rmp test smoke rmp test render ``` and 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. ============================================================================== # The framework > How raylib_multiplatform is put together — its layers, one frame in order, the config pipeline, how it is tested, its licences — why it is built the way it is, how to work on it, and how to keep it alive for years. Source: 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. ## In short 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. ## How it is put together [Architecture](https://omardev29.github.io/rmp-docs/framework/architecture.html) The five layers, from your code down to the targets: what each one is responsible for, which libraries sit where, and how the modules depend on one another. [One frame](https://omardev29.github.io/rmp-docs/framework/the-frame.html) Everything that happens between one picture and the next, in the order the framework does it: input, the scenes and their objects, collision, the camera, drawing, and the changes that wait for the end of the frame. [The config pipeline](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html) How one `.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. [Performance](https://omardev29.github.io/rmp-docs/framework/performance.html) What the framework costs over raylib, and what it saves you: how the scenes, the behaviors, the map, the collisions and the UI keep a frame cheap, which abstractions cost nothing and which cost a little, and how it all compares with raylib and with OpenGL by hand. [Testing](https://omardev29.github.io/rmp-docs/framework/testing.html) Unit tests with no window, a frame rendered in software and compared, the game booted on every target a runner can start, every example run, a game played by a bot and the examples played from a script, what the tests reach measured — and what `rmp test` runs in your game. [Security](https://omardev29.github.io/rmp-docs/framework/security.html) Every safety measure the framework takes: the release hardened flag by flag, every debug build under the sanitizers, two static analysers, what the tests reach, the shipped binary read back, the supply chain pinned, secrets kept out of the repository — what each one costs, and what is not done. [Licences](https://omardev29.github.io/rmp-docs/framework/licences.html) The framework's MIT licence, the modified raylib under it, every component it carries, and the notice that ships with your game. ## Why it is built this way 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](https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html): a main menu is three function calls, and nothing is allowed to make it longer. - [Naming](https://omardev29.github.io/rmp-docs/guidelines/naming.html) and [the access rule](https://omardev29.github.io/rmp-docs/framework/why/the-access-rule.html): what a name tells you before you look it up. - [One header per module](https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html): no umbrella header, and every include measured. - [Designated initialisers](https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html): options as `{ .speed = 320 }`, and why their order is fixed. - [Ownership](https://omardev29.github.io/rmp-docs/framework/why/ownership.html): nothing to free, and a handle for what you keep. - [No exceptions](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html): what the framework does instead of throwing. - [Macros](https://omardev29.github.io/rmp-docs/framework/why/macros.html): where one is the right tool, and the rule about them. - [Time is a parameter](https://omardev29.github.io/rmp-docs/framework/why/delta-and-time.html): `delta`, the clock, and `[app] max_delta`. ## Working on it [Contributing](https://omardev29.github.io/rmp-docs/framework/contributing/index.html) 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. ## Keeping it alive [Maintaining](https://omardev29.github.io/rmp-docs/framework/maintaining/index.html) 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. ============================================================================== # Architecture > The five layers of a game made with raylib_multiplatform — your code, the modules, the core, raylib, and the targets — and what each one is responsible for. Source: 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. Each layer is built on the one under it. A box with a link goes to its page. The rest of this page takes the layers one at a time, from the top. ## Your game 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 entry point The whole of `src/main.cpp`, as the framework ships it and as [`rmp new`](https://omardev29.github.io/rmp-docs/reference/commands.html#new) copies it into a new game: [src/main.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/src/main.cpp#L1-L13) ```cpp // 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 #include "scenes/main_menu.h" RMP_GAME(MainMenuScene); ``` [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#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. ### Scenes, objects and resources 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html) and [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html), 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#pack) does the packing by hand). ### One configuration file 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](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html) follows it all the way through, and [Configuration](https://omardev29.github.io/rmp-docs/reference/configuration.html) lists every key. ## The modules 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](https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html) has the reasons and the measurements. | Header | What it gives you | Built on | |---|---|---| | `rmp/ui.h` | [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html): menus, buttons, layout, themes, in screen space | Clay, the layout engine | | `rmp/input.h` | [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html): named actions bound to keys, buttons and sticks, and the pointer | raylib's input, sampled once a frame | | `rmp/assets.h` | [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) and [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) and its siblings: loading by name, released by themselves | rres for the pack, cute_aseprite for sprite sheets | | `rmp/tilemap.h` | [`rmp::Tilemap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html): a level made in LDtk or Tiled | cJSON for LDtk, cute_tiled for Tiled | | `rmp/audio.h` | [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html): sounds and music by name, three volume buses | raylib's raudio | | `rmp/save.h` | [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) and [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html): save slots in the platform's own folder | cJSON, and Monocypher to seal a file | | `rmp/random.h` | [`rmp::random`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html): one seeded generator you can replay | xoshiro128++, written out | | `rmp/ads.h` | [`rmp::ads`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html): interstitial and rewarded ads | raymob's AdMob bridge on Android, once `[android.admob] enabled` turns it on; nothing anywhere else | | `rmp/math.h` | [arithmetic](https://omardev29.github.io/rmp-docs/manual/basics/headers.html#rmp-math-h): `+`, `-` 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html): the catalogue — movement, health, timers, spawners | the core's behavior engine | | `rmp/scene.h` | [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html) and [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) | the core | | `rmp/object.h` | [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html), [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html), [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html) | the core | | `rmp/app.h` | [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME), [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) and [`rmp::global`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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](https://omardev29.github.io/rmp-docs/examples/plain_c.html) 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. ## The core 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](https://omardev29.github.io/rmp-docs/framework/the-frame.html). The app and the frame loop [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#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`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) is that macro with the three hooks written for you. The scene stack A vector of owning pointers, and a queue of the transitions asked for during the frame. [`change`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#change), [`push`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#push), [`replace`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#replace) and [`pop`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. The object storage 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) returns good for the rest of it. Collision and the map 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#solid). A solid object that is not [`immovable`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. The behavior engine 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html) 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` 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 `` from `thirdparty/raymob` for the ads as C functions, which do nothing anywhere but Android. ## raylib 6.2, modified Under the core is [raylib](https://www.raylib.com/) 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`](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/thirdparty/raylib/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](https://omardev29.github.io/rmp-docs/framework/licences.html) 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ```toml [raylib] disabled_modules = ["rshapes"] ``` ```text 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. ``` ## The targets 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 `---`, 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](https://omardev29.github.io/rmp-docs/framework/testing.html) says how. ============================================================================== # One frame > Everything the framework does between one picture and the next, in the order src/rmp/app/app.cpp and src/rmp/scene/scene.cpp do it, and why the order is what it is. Source: 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. One frame. Each step links to its section below. 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. ## Who calls the frame [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) is [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#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: - **Windows, Linux, macOS, the BSDs and Android**: a `main()` with a `while` loop, the ordinary raylib shape. On Android raylib's own native glue calls that `main()`. - **The web**: the browser owns the loop. `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. - **iOS**: UIKit owns the loop and calls three functions the macro defines. 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: ```text 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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](https://omardev29.github.io/rmp-docs/framework/why/delta-and-time.html) says why. ## 1. Input, once The runner first asks whether anyone can see the window ([out of sight](https://omardev29.github.io/rmp-docs/framework/the-frame.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pressed) and [`just_pressed`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#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. ### The window out of sight 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. - **Minimized** (on the desktop): the scenes move, the music plays and the clock runs, but nothing is drawn, and the loop sleeps a thirtieth of a second instead of waiting for a vsync nobody sees. The world does not stop because its player looked away. - **Out of focus, with [`[window] pause_unfocused`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_suspend) when it starts and [`_resume()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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](https://omardev29.github.io/rmp-docs/framework/performance.html#asleep) has what it saves. ## 2. Update 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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: 1. **Whether input reaches it.** A scene hears the input only if every scene above it lets it through ([`input_below`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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. 2. **The pointer.** A press and a release on the same object call its [`on_click`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_click); holding and moving calls its [`on_drag`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. 3. **The scene's [`_update(delta)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_update).** The scene sets up the frame, and its objects then move inside it. 4. **Its objects**, one at a time, in the order they were spawned — [below](https://omardev29.github.io/rmp-docs/framework/the-frame.html#objects). 5. **Collision**, once every object has moved — [below](https://omardev29.github.io/rmp-docs/framework/the-frame.html#collision). 6. **The camera**, last — [below](https://omardev29.github.io/rmp-docs/framework/the-frame.html#camera). ### Each object An object that is alive goes through these steps, and an object destroyed by any of them stops there: 1. **Its behaviors' `_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. 2. **Its [`_update(delta)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_update).** 3. **Where it is, remembered** — after your code, so that writing `position` yourself is a teleport, not a journey the collision pass would sweep along. 4. **The move.** The forces from [`apply_force`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#apply_force) and the scene's [`gravity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#gravity) times the object's [`gravity_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale) change the velocity, and the velocity moves the object. A [`solid`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#solid) object that is not [`immovable`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. 5. **The edges**: what [`edges`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#edges) says to do at the edge of the object's bounds — clamp, bounce, wrap or be destroyed. 6. **The animation clock** of its sprite, here and not in the draw, so a scene that runs without being drawn still has time passing in it. 7. **Its behaviors' `_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. ### Collision 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: 1. **Rewind** an object the swept test caught: one that crossed something between two frames without ever overlapping it is put back where it met it. Only when both are solid — a bullet passing through a coin is told, and keeps going. 2. **Separate** the pairs that are both solid: each moves half the overlap, or the movable one moves all of it when the other is immovable. A push that would end inside a solid cell of the map is undone, so a moving platform cannot shove the player through a wall. 3. **Notify**, so your code reads the positions as they were resolved. 4. **Take the velocity out of the contact**: whoever was pushed loses the part of its velocity going into what pushed it, and keeps the rest. After the notification, so a `_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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_collision), then its behaviors', then the second object's `_collision` and its behaviors', then the first object's [`on_collision`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ### The camera Last of all, the scene's [`camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) settles on where things ended up, after collision has had its say: it moves toward what it [`follow`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#follow)s, at a rate that is the same at any frame rate, is clamped to its [`limits`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#limits), and advances its shake. Anything that reads the camera next — the draw, the pointer next frame — sees the settled view. ## 3. Draw The frame is opened with `BeginDrawing()` and cleared. The colour is the [`background`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#draws_below)). Each one, in this order: 1. **The camera opens**: `BeginMode2D()` with the scene's camera, so what follows is drawn in world units — fitted to the window the way [`[window] stretch`](https://omardev29.github.io/rmp-docs/manual/core/camera.html) says. When the stretch letterboxes, the world is also cut to the game's area, so the bars around it keep the clear colour. 2. **The map**, under everything, because it is the level the objects stand on — only the tiles that reach into what the camera shows ([Tilemaps](https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html)). 3. **The objects** that are alive and visible, sorted by [`layer`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_draw). 4. **The camera closes**: `EndMode2D()`, and the cut with it. 5. **The scene's [`_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#notify) queued is drawn over everything, taking no input. ## 4. The CI capture 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](https://omardev29.github.io/rmp-docs/framework/testing.html#render) has what CI does with the result. ## 5. Present `EndDrawing()` puts the frame on screen, and where the frame rate is capped — [`[window] fps`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-fps), or vertical sync with [`[window] vsync`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ## 6. Apply what was deferred Only now, with nothing mid-frame, does anything go away. **Destroyed objects are freed.** An object stops updating and drawing the moment [`destroy()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#destroy) is called on it, but its memory stays until here. That is why the reference [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#change) ends every scene top down; a [`push`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#push) suspends the top and enters the new one; a [`replace`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#replace) ends only the top; a [`pop`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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();` is safe inside the menu's own `_draw()`: the menu is not destroyed until its `_draw()`, and everything else in the frame, has finished. ## After the frame 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](https://omardev29.github.io/rmp-docs/framework/testing.html#e2e) is, and then it sees the frame drawn and its scene changes applied. ## Before the first frame, and after the last Before the first frame the entry point prepares the run: it tells the asset layer where this executable's `resources/` are, seeds [`rmp::random`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html) from the wall clock — or from the seed a test that plays the game names — turns on [`[dev] strict`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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: ```cpp 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: 1. **The scenes**, top down, each with its `_end()` and its objects. Transitions still queued are dropped: a scene nobody will see does not get a `_ready()` to load assets in. 2. **The globals** from [`rmp::global`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global), in reverse order of first use — after the scenes, because a scene's `_end()` may write to one. 3. **The UI** and its font, **the sounds and music**, and then **every texture, font and sound still loaded**. 4. **The stop hook**: `RMP_GAME`'s closes the window. 5. **The sound device and the resource pack**, which hold no GPU objects and can go after 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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: ```cpp #if !defined(PLATFORM_IOS) if (rmp::ui::button("Quit")) rmp::app::quit(); #endif ``` ## A game that owns its frame A game that wants none of the scene stack writes its own three hooks and hands them to [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_ENTRY_POINT): ```cpp 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](https://omardev29.github.io/rmp-docs/examples/ui/index.html) are written this way, because a menu on its own needs nothing more. NoteBoth input layers work in a game that owns its frame. [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html) answers from the snapshot the runner took before `on_frame`, exactly as it does under `RMP_GAME`. With no scene on the stack there is no camera to go through, so `rmp::input::pointer()` is the pointer's position on the screen, the same as `rmp::input::pointer_screen()`, with nothing said in the log. `rmp::ui` needs nothing either: with no `frame()` to open the UI's frame, the first `rmp::ui::begin()` of a frame opens it and `rmp::ui::end()` closes it. NoteWith your own frame, the CI capture happens after `EndDrawing()` instead of before it. That works under the software renderer CI boots the examples with, where the frame is still in memory after it is presented, and nowhere else. ## How the order is kept 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. ============================================================================== # The config pipeline > How raylib_multiplatform.toml becomes what CMake, Gradle, Xcode and the CI read, why a mistake in it stops in configure.py with the line, and what each generated file is for. Source: 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. One file in; every build system's input out. Every file in the left column is generated, and none of them is committed: they are written again on every configure. ## One file The `.toml` is grouped by what each section is about: raylib_multiplatform.toml ```toml [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](https://omardev29.github.io/rmp-docs/reference/configuration.html) 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. NeverPut a secret in it. The `.toml` is committed, and some of its values end up in the shipped binary. Signing keys, store tokens and passwords live in the CI's secrets, which the workflows read and the `.toml` never mentions. Even [`[resources] rres_password`](https://omardev29.github.io/rmp-docs/reference/configuration.html#resources-rres_password) is obfuscation and says so: it is inside the binary that uses it. ## Refused before anything compiles 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. ```toml [project] name = "my game" ``` ```text 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: ```toml [window] width = [800] ``` ```text 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. ```toml [window] title = "" ``` ```text 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#app-max_delta), so the game would be handed less time than really passed, every frame, forever: ```toml [window] fps = 15 ``` ```text 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#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. ## Who runs it 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#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. ## What it writes | 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](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html#config-h) | | `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](https://omardev29.github.io/rmp-docs/framework/licences.html) | 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 generated header 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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/macros.html#toml-RMP_WINDOW_WIDTH). [Macros](https://omardev29.github.io/rmp-docs/reference/macros.html#from-the-toml) 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. ## Questions it answers 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=`](https://omardev29.github.io/rmp-docs/publishing/ci.html#when-it-runs) hands it. - `--print-schema` and `--print-defines` describe every key and every generated macro, which is where this site's [Configuration](https://omardev29.github.io/rmp-docs/reference/configuration.html) and [Macros](https://omardev29.github.io/rmp-docs/reference/macros.html) 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. ## Nothing generated is committed 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#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. ============================================================================== # Performance > What the framework costs over raylib and what it saves: the abstractions that compile to nothing, the few that cost a call, how the map, the collisions, the UI and the build keep a frame and a binary small, and how it compares with raylib and with OpenGL by hand. Source: 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. ## The rule: you pay for what you use "Zero-cost abstraction" means two things here, and the framework holds both. - **What you do not use costs nothing.** The framework is a static library compiled with `-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"](https://omardev29.github.io/rmp-docs/framework/architecture.html): not one byte of the 3D renderer, the physics or raylib's model loaders reaches a 2D binary. - **What you use costs about what you would have written yourself.** A helper is not worth having if writing the raylib calls by hand would be faster. Where an abstraction does cost something, it is one indirect call or one lookup, said below. ## What compiles to nothing | 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](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html) 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 `#define`s at configure time ([the config pipeline](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html)). Nothing is parsed when the game starts. | ## What costs a call, and why it is worth it - **A behavior's hook** is one indirect call through a table of function pointers built for its type at compile time. That is the price of a virtual function, without a base class or a vtable pointer in the behavior. A hook the behavior does not define is not called at all. - **`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. - **A handle** (`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()`** 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. - **An action by name** (`rmp::input::pressed("jump")`) is a lookup in a small table, so the same name works for a key, a button and a touch. ## Where the framework does less work than a hand-written game ### The map draws only what the camera sees 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](https://omardev29.github.io/rmp-docs/manual/modules/tilemaps.html). ### Collisions: a grid, and no tile colliders 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. ### The UI allocates nothing per frame `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. ### One clock 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. ### Hot reload that costs a bool 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 window nobody sees draws nothing 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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](https://omardev29.github.io/rmp-docs/framework/the-frame.html#out-of-sight) has the order of it. ### A translated text is one lookup An [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#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](https://omardev29.github.io/rmp-docs/manual/modules/localization.html) has the rest. ### A Yarn script is compiled once 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](https://omardev29.github.io/rmp-docs/manual/modules/dialogue.html#build) says how to choose. ## The binary - **Size is budgeted.** Every binary a release ships has a line in `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. - **No iostreams in the library.** One `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. - **A number in a sentence cost 126 KB once.** A floating-point `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. - **Android exports only what Java and the system call.** The game is one shared library, and a shared library keeps everything it exports. With every symbol exported, a game that never loads a dialogue carried the Yarn compiler. The release is compiled with `-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. - **Hardening costs little.** FORTIFY_SOURCE, the stack protector and stack-clash protection together cost 2.0 % of the binary. PIE costs 5.5 % and stays on for security reasons ([Security](https://omardev29.github.io/rmp-docs/framework/security.html) says why). - **Debug is slow on purpose.** The framework's own Debug runs under ASan and UBSan, about three times slower. A game's Debug has no sanitizers unless the game asks for them, and on x86-64 Linux it can compile its C with tcc to build in a fraction of the time. Measure performance in a release. ## Compared with raylib and with OpenGL | | 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. ============================================================================== # Testing > How the framework is tested — unit tests with no window, under the sanitizers, the UI laid out headless, a frame rendered in software and compared, every target booted, every example booted, every game, menu, scene and input example played from a script and its frames compared, what the tests reach measured — and what rmp test runs in a game. Source: 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](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html) says how. Everything below runs with [`rmp test`](https://omardev29.github.io/rmp-docs/reference/commands.html#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. ## Unit tests, with no window 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](https://omardev29.github.io/rmp-docs/framework/testing.html#sanitize), 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](https://omardev29.github.io/rmp-docs/framework/testing.html#game-tests) is what they are. Two kinds of test need something real underneath, and get it: - **Locales.** A save has to read back the same on a machine whose decimal point is not a dot. The test run builds two locales from source for it — one with a comma, one with the Arabic decimal separator, which is two bytes long — and points the tests at them, and CI fails if they cannot be built rather than skipping the tests that need them. - **The sound device.** One suite opens the real audio device at a master volume of 0 and reads back what the mixer produced, to check that a sound plays where it should between the speakers. On a CI runner with no sound card it runs against the audio library's null backend. It runs once, not in the shuffled pass. 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](https://omardev29.github.io/rmp-docs/framework/why/delta-and-time.html) 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, laid out headless 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. ## A frame, in software 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](https://omardev29.github.io/rmp-docs/framework/the-frame.html#capture) has the detail. ## Booting the game 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](https://omardev29.github.io/rmp-docs/framework/testing.html#binaries). 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. ## What ships, read out of the binary 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: - **What a Windows `.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. - **Which macOS each slice needs.** The macOS job reads the deployment target back out of the CMake cache, then the minimum macOS out of every slice of the universal binary, and fails on a slice that asks for more — allowing 11.0 for arm64, which the toolchain raises any lower target to. - **How a Linux binary was linked.** Every Linux job reads its release before UPX packs it: the relocated data read-only once the loader is done (RELRO), every symbol bound at start (BIND_NOW), a stack that is not executable, and — the release being linked position-independent — an executable ASLR can move. A flag a toolchain ignored was never there, and this is where that shows. - **What a musl binary asks the system for.** With `--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. ## Every example, booted 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. 1. Every C++ example has the shape of an entry point that works on every platform: its own `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. 2. Every example directory became a build target, and the number of targets is the number of directories — a pattern that stops matching would otherwise look exactly like a folder where everything passes. 3. Every example with an entry point is built against the software renderer, booted for a budget of frames, and required to boot with no asset missing, draw, exit cleanly, leave a screenshot and make no mistake the framework reports. The plain C example is booted like the rest: it calls the C smoke-test hooks the entry point calls for every other example, and has no framework to report anything. 4. At the design size every `[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. 5. The platformer is played to the end — [below](https://omardev29.github.io/rmp-docs/framework/testing.html#platformer) — and `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. 6. Every example with a script in `tests/e2e/` is played from it, and every picture the script takes is compared with the one recorded for it — [below](https://omardev29.github.io/rmp-docs/framework/testing.html#e2e). 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](https://omardev29.github.io/rmp-docs/framework/testing.html#sanitize), 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. ## The platformer, played Thirty frames of a title screen prove that the title screen draws. A game in [examples/games](https://omardev29.github.io/rmp-docs/examples/games/index.html) 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](https://omardev29.github.io/rmp-docs/examples/games/07_platformer.html) 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. ## Examples played from a script 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: ```text 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 end ``` Each 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](https://omardev29.github.io/rmp-docs/framework/why/delta-and-time.html). 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 : ` — 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](https://omardev29.github.io/rmp-docs/framework/licences.html#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. ## Sanitizers 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`](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers) 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](https://omardev29.github.io/rmp-docs/framework/testing.html#ci). 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. ## What the tests reach 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: A floor per file, which only rises `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. The public functions no test calls, a list that only shrinks `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: ```text // RMP_COVERAGE_OFF() ... // RMP_COVERAGE_ON ``` Before 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 gates 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html) 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html#instead) 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](https://omardev29.github.io/rmp-docs/framework/testing.html#binaries) | | `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](https://omardev29.github.io/rmp-docs/publishing/ci.html#size-budget) says what the budget holds | [Commands](https://omardev29.github.io/rmp-docs/reference/commands.html#test) has the full list of stages with the summary `rmp help test` prints for each. ## In CI 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: ```shell gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macos ``` The 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. ## In your game A game made with `rmp new` has the same command, and runs the stages that make sense for a game: ```shell rmp test rmp test unit rmp test smoke ``` `config` The game's `.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](https://omardev29.github.io/rmp-docs/framework/licences.html). `unit` The game's own tests, in `tests/game/`, built with the game and run with no window: [below](https://omardev29.github.io/rmp-docs/framework/testing.html#game-tests). With no `.cpp` in that folder the stage has nothing to check, and says `skip nothing matches tests/game/*.cpp` instead of failing. `render` The game built against the software renderer, booted for ten frames, and checked for a clean boot, pixels on the screen and a clean exit. A game has no golden hash: its title screen is its author's to change. `smoke` The game built the ordinary way and booted with a frame budget, which must report every asset loaded and a frame drawn, and exit with status 0. Both 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](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers). 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. ### The game's own tests 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. [tests/game/main_menu_test.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/game/main_menu_test.cpp#L1-L42) ```cpp // --------------------------------------------------------------------------- // 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 #include #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`. ```shell 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. ============================================================================== # Security > Every safety measure the framework takes — the release hardened flag by flag, every debug build under the sanitizers, two static analysers, what its tests reach, the shipped binary read back, the supply chain pinned, secrets kept out of the repository — what each one protects against, what it costs, and what is not done. Source: 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. ## At a glance | Measure | Where it applies | In a game made with `rmp new` | |---|---|---| | [The release, hardened](https://omardev29.github.io/rmp-docs/framework/security.html#release) | every desktop release: Linux and the BSDs, macOS and Windows in part | yes: it is the same `CMakeLists.txt` | | [Library checks in debug](https://omardev29.github.io/rmp-docs/framework/security.html#debug-checks) | every debug build on the desktop | yes | | [AddressSanitizer and UndefinedBehaviorSanitizer](https://omardev29.github.io/rmp-docs/framework/security.html#sanitizers) | every debug build of the framework on the desktop | off until `[dev] sanitize` lists them | | [Static analysis](https://omardev29.github.io/rmp-docs/framework/security.html#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](https://omardev29.github.io/rmp-docs/framework/security.html#coverage) | 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](https://omardev29.github.io/rmp-docs/framework/security.html#binaries) | every release job in CI | yes: the same workflows | | [The supply chain, pinned](https://omardev29.github.io/rmp-docs/framework/security.html#supply-chain) | CI | yes, at the pins the game was made with | | [Secrets, signing, installing](https://omardev29.github.io/rmp-docs/framework/security.html#secrets) | the `.toml`, the Android job, the installer | yes | ## The release, hardened 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](https://omardev29.github.io/rmp-docs/framework/security.html#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](https://omardev29.github.io/rmp-docs/framework/security.html#pie) is why. ### What each flag protects against, and what it costs 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=3` The 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-strong` A 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-protection` A 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,now` Every 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,noexecstack` The 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_FAST` The 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` `-pie` The executable is position-independent, so it is loaded at a different address on every run: [PIE](https://omardev29.github.io/rmp-docs/framework/security.html#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](https://omardev29.github.io/rmp-docs/framework/security.html#binaries). ### PIE, over the rule 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. ### On the other platforms 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: macOS The stack protector and the C++ library's checks. PIE and a stack that is not executable are the platform's own and always on. The cost was not measured on a Mac; the figures above come from the same compiler on Linux. Windows With MinGW, which builds `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. Web Nothing: a WebAssembly module has no executable stack and no loader to randomise. The browser runs it in its sandbox. Android The NDK compiles with `-fstack-protector-strong` and `-D_FORTIFY_SOURCE=2` by itself, and Android has required PIE since 5.0. iOS PIE and the stack protector are Xcode's defaults. ### What a release weighs 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](https://omardev29.github.io/rmp-docs/framework/security.html#size-budget). 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. ## Every debug build, under the sanitizers 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. AddressSanitizer A read or a write past a buffer — on the heap, on the stack or in a global — a use after free or after return, a double free, and a global that reads another file's global before that one was initialised. LeakSanitizer Memory nobody freed, reported when the program exits. It is part of AddressSanitizer where the runtime turns it on by itself, which is Linux, and it is left to that; asking for it on macOS stops every program. UndefinedBehaviorSanitizer A signed overflow, a shift past the width of its type, a float converted to an integer it does not fit, a misaligned or null access, a virtual call on an object of the wrong type. ### The flags With clang, the framework's development compiler, and with gcc, which names `float-cast-overflow` because its `undefined` does not include it: ```text 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: ```text -DRMP_SANITIZE=1 any of them -DRMP_SANITIZE_ADDRESS=1 AddressSanitizer -DRMP_SANITIZE_UNDEFINED=1 UndefinedBehaviorSanitizer ``` With 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. ### Whether they really run 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. ```shell RMP_REQUIRE_SANITIZERS=1 cmake --preset debug ``` A configure that got them says so: `=== SANITIZERS: address, undefined ===` To measure what they cost, one build directory can go without them: `-DRMP_SANITIZE=OFF`. ```shell cmake --preset debug -DRMP_SANITIZE=OFF ``` They 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 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. ### The library checks, in every debug build 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. ### What they cost 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](https://omardev29.github.io/rmp-docs/framework/testing.html#examples) says why the pictures stay the same. None of it reaches a release. ### A report fails the run 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](https://omardev29.github.io/rmp-docs/framework/testing.html#e2e), 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](https://omardev29.github.io/rmp-docs/framework/security.html#not-done); a test fails one that throws the status away. [Testing](https://omardev29.github.io/rmp-docs/framework/testing.html#sanitize) 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. ### In a game 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: ```toml [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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#dev-sanitize) refuses the others by name, each with its reason — `thread`, `memory`, `leak`, `hwaddress`, `integer`, `implicit-conversion` and `fuzzer`: ```toml [dev] sanitize = ["address", "thread"] ``` ```text 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. ## Static analysis 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. clang-tidy, with the Clang Static Analyzer `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](https://omardev29.github.io/rmp-docs/guidelines/index.html). 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. The debt, which only shrinks What the code still owes the style guide is written down in `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. cppcheck A second analyser, with its own value-flow analysis rather than clang's, over `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. The compiler's own warnings `-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. No raw pointer in the API `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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) says what the API hands out instead. Nothing owned by hand `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. ## What the tests reach 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](https://omardev29.github.io/rmp-docs/framework/testing.html#coverage) 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](https://omardev29.github.io/rmp-docs/framework/testing.html#ci) says where each one runs, and [below](https://omardev29.github.io/rmp-docs/framework/security.html#not-done) how little of the framework they reach yet. ## The shipped binary, read back 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. How a Linux release was linked `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. What a Windows `.exe` imports `binary_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. Which macOS each slice needs `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. Which glibc a Linux release needs `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. That an Android release is a release `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`. ### The size budget 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. ## The supply chain, pinned A green run should mean the same in six months as today, and a build should not depend on a download succeeding. The build image, by digest The Linux, web and Android builds, the lint job and the framework's own jobs — clang-tidy, the examples and their scripts, the coverage, the deep tests, the new game, the documentation — run inside `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](https://github.com/omardev29/raylib-build-image), each architecture on a runner of that architecture, checked there inside the image it built, and published only then. The Alpine image, by digest The Alpine the musl build is started on is an image of the framework's own, `ghcr.io/omardev29/raylib-run-alpine`, pinned and checked the same way. Nothing from Docker Hub A test reads every image every workflow names and fails on one that does not come from `ghcr.io`. A digest makes an image look frozen; it is still a download from a registry with anonymous rate limits. Every action, by commit Every GitHub Action a workflow uses is named by the full commit it resolves to, with the tag in a comment beside it: a tag can be moved, a commit cannot. A test of the framework reads every `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. Every download, by checksum Every file a job fetches by address — zig and UPX outside the image, Ninja and XcodeGen on macOS, Mesa and UPX on Windows — is checked against a `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](https://omardev29.github.io/rmp-docs/publishing/ci.html#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. The test tools, by hash The Python test tools the image carries are installed from a requirements file that pins every package and the hash of every file, and their versions are pinned in `thirdparty/FROZEN_VERSIONS.md` and compared with the image's manifest. Every licence, on record `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](https://omardev29.github.io/rmp-docs/framework/licences.html) has the whole record. The canary Pinning stops the world from breaking a build, and also hides that the world moved. Every Monday the framework's repository runs the same workflows against the floating versions — the newest build image, runners, Xcode and Mesa — to find what the next bump will break before anyone needs it. [The canary](https://omardev29.github.io/rmp-docs/publishing/ci.html#the-canary) has the detail; a game never runs it. ## Secrets, signing, installing ### No secret in the repository 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](https://omardev29.github.io/rmp-docs/publishing/ci.html#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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#resources-rres_password) encrypts a release's resource pack. It keeps casual unpacking of the game's assets inconvenient, and nothing more. - [`[save] encrypt`](https://omardev29.github.io/rmp-docs/reference/configuration.html#save-encrypt) seals a save with a key derived from `[project] name`. That stops a text editor, not a determined player. ### The Android release, signed 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](https://omardev29.github.io/rmp-docs/publishing/google-play.html#signing) says how to set it up. ### The installer 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](https://omardev29.github.io/rmp-docs/getting-started/install.html#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. ## What is not done At the commit these pages document, these do not exist: - **Two public functions not held by a property.** Every public function of `include/rmp/` is held to the deep tests' rules on generated input but two: [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) and [`rmp::app::quit_requested()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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. - **No reading of how a Windows, macOS or BSD release was linked.** The BSD releases are hardened like Linux's, Fortify aside, and the Windows ones by their linker's defaults, and nothing reads it back out of the binary: `binary_check.py windows` reads what an `.exe` imports, not how it was linked. Control Flow Guard is not used. - **No exit status from the iOS simulator.** The boot there, which a repository switches on, reads the game's markers and not how it exited. - **No measurement of the hardening's cost on macOS or the BSDs.** The figures above are Linux's. ============================================================================== # Licences > The framework is MIT and built on a modified raylib; every library it carries is on record with its licence, checked on every build, and credited in a LICENSES.txt that ships with the game. What that means for a game made with it. Source: 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: MIT 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#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, modified 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`](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/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. ## Everything it carries 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. ## A new dependency is a licence decision 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: - **The tree and the record, both ways.** A component in `thirdparty/` with no row fails, and so does a row whose component is gone. - **The record and the text.** Each row's licence text is found on disk and recognised, and it has to say what the row says: a row cannot claim MIT for a file that says GPL. - **The rules.** A copyleft licence fails — GPL, AGPL, MPL and the rest, and LGPL too, because LGPL's way out is dynamic linking, which a static build and iOS do not have. A non-commercial licence fails. A licence the tool cannot recognise fails. And a zlib or Apache component, whose licence asks for changes to be marked, is either pinned unmodified by its sha256 in `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. ## LICENSES.txt, generated 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: - **Desktop and the BSDs:** next to the executable in every package the release builds. - **The web:** in the package, beside the page and the `.wasm`. - **Android:** inside the APK and the App Bundle, among the app's assets. - **iOS:** at the root of the app bundle. 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. ## What a game owes 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. - **Ship `LICENSES.txt` with the game.** The release builds put it where it belongs; leave [`[deploy] licenses`](https://omardev29.github.io/rmp-docs/reference/configuration.html#deploy-licenses) at its default and there is nothing else to do. - **Or give the credits inside the game.** A credits screen that reproduces the same notices satisfies the same licences, and then a loose text file next to the executable is only noise. Turning the file off says where the credits are instead, and `configure.py` will not take one without the other: ```toml [deploy] licenses = false ``` ```text 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. ``` raylib_multiplatform.toml ```toml [deploy] licenses = false credits_note = "the Credits scene, from the main menu" ``` - **Record what you add.** A library added under `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. - **Your art and sound are yours to license.** The notice covers code. The picture a new game starts with, `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. ============================================================================== # Why it is built this way > The decisions that give the framework its shape, each with the reason behind it and the check that keeps it true. Source: 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 rule above the others [The three-function menu](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 making the game, and a main menu written in three calls is the measure. Every other decision on these pages is answerable to it. ## How the code reads [Naming](https://omardev29.github.io/rmp-docs/guidelines/naming.html) One spelling per kind of name, so a type, a value and a constant never look alike where they are used, and no prefix carries meaning a dot can carry better. It is a rule of style, so it lives with the rest of the style guide, in the Guidelines. [The access rule](https://omardev29.github.io/rmp-docs/framework/why/the-access-rule.html) `_name` is a method of yours the framework calls; `on_name` is a function you hand to it. Two spellings, two directions. [Designated initialisers](https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html) Why options are written `{ .speed = 320 }`, why the order of the fields matters, and why a behavior has no base class. [Macros](https://omardev29.github.io/rmp-docs/framework/why/macros.html) Where a macro is the right tool — the entry point, the values from the `.toml` — and the one rule about them: a header never makes you use one. ## How the framework holds together [One header per module](https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html) No umbrella header, headers that do not include each other, and the cost of every include measured rather than guessed. [Ownership](https://omardev29.github.io/rmp-docs/framework/why/ownership.html) Everything is owned by something that releases it: a texture, an object, a scene, a callback. No raw pointer in the API, nothing you have to free, and the handle for what you keep across frames. [No exceptions](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html) What the framework does instead of throwing, and why throwing in the middle of a frame is not an option. [Time is a parameter](https://omardev29.github.io/rmp-docs/framework/why/delta-and-time.html) Why every hook is handed `delta`, where the clock is read, and what `[app] max_delta` protects you from. ## Checked, not remembered 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#test), clang-format or the compiler. [The Guidelines](https://omardev29.github.io/rmp-docs/guidelines/index.html#checked) list every one of those rules with the tool that holds it, and where: in the framework, in its examples and in a game. ============================================================================== # The three-function menu > The rule that outranks every other in the framework — the API is as simple as possible for the person making the game — and the three questions a feature has to answer to get in. Source: 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. ```cpp 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. ## What the three lines do not say 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#begin) takes options for where the menu goes, [`button()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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](https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html). The options are there for the case that needs them; the simple case does not have to know they exist. ## The three questions A feature gets into the framework by answering three questions, in this order. 1. **Is there a real game that needs it?** "Someone might want it" is a no. The games under [examples/games](https://omardev29.github.io/rmp-docs/examples/games/index.html) are where needs come from, and each of them has to be playable from the title screen to winning, losing and playing again before it counts. 2. **Can it be made from what already exists?** Then it is a pattern, and the place for a pattern is an example, not a new function. 3. **Does it make the three-function menu longer?** Then it is redesigned until it does not. 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](https://omardev29.github.io/rmp-docs/manual/core/scenes.html#what-a-scene-lets-through)). 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. ## What the rule decided The rule is easiest to see in the defaults, because a default is where the simple case lives. Fields, not accessors 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. Nothing falls until it asks to A scene carries a downward gravity, and every object's [`gravity_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale) is 0. A top-down game never mentions gravity, and a platformer sets one field on the player. Collide with everything, resolve nothing Every object is on collision layer 1 and collides with layer 1, so the simple game never mentions a layer. Objects are not [`solid`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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 pause menu writes no policy 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. A Pong ball is one line 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 is a struct A behavior inherits from nothing and registers nowhere, so that it can be written `add({ .speed = 220 })`. The price of a base class would have been that line. [Designated initialisers](https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html) explains why. Escape goes back; it does not quit 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit). Leaving is one call that returns [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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. ============================================================================== # The access rule > Why a method the framework calls on your type starts with an underscore, why a function you hand to the framework starts with on_, and why the two can live on the same object. Source: 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. ## _name: the framework calls your method 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](https://omardev29.github.io/rmp-docs/framework/the-frame.html) gives the exact order. ```cpp 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(); } }; ``` ## on_name: you hand the framework a function 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. ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_click), [`on_drag`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_drag) and [`on_collision`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#on_collision) on an object, [`on_object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#on_object) on a map, and the `on_` fields of the behaviors that report something — [`Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html)'s `on_death` and `on_damage`, [`Timer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Timer.html)'s `on_timeout`, [`Spawner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html)'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. ## Both at once 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. ## Why an underscore 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html), in the Guidelines, has the whole table this rule is a part of, and what each tool says about a name that breaks it. ## The third kind: detail 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. ============================================================================== # One header per module > Why there is no rmp.h that includes everything, why the framework's headers avoid including each other, and how the cost of every include is measured instead of argued about. Source: 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: ```cpp #include #include 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: Does not compile ```cpp #include 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](https://omardev29.github.io/rmp-docs/examples/platform/03_minimal_includes.html) holds the framework to this: it includes only `rmp/ui.h`, and the examples build fails if that stops being enough. ## A header is a module you can name 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. ## Our headers do not include each other 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. ## The one header every header includes 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 `#define`s 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 standard library is allowed; its cost is measured The rule is about the framework's own headers. It was never a rule against the standard library or raylib: ``, ``, `` 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html) exists because `` 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](https://omardev29.github.io/rmp-docs/framework/why/ownership.html#callbacks). - `rmp/math.h` is a header of its own because the C library's `` under raymath is most of its cost, and `rmp/ui.h` must not make a file that only draws menus pay for it. ============================================================================== # Designated initialisers > Why options are written as { .field = value }, why the fields of every options struct are declared in the order you would write them, and why a behavior has no base class. Source: 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. ## What it buys A call says what each value is, leaves out everything it does not change, and keeps working when a new option is added: ```cpp 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({ .speed = 220 }); ``` The same shape runs through the whole framework: what [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) takes ([`rmp::ObjectOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ## Declaration order 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`: ```cpp 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: Does not compile ```cpp 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. ## Only an aggregate can be written this way 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: Does not compile ```cpp 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](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#add) inherits from nothing. The obvious design — a `Behavior` base class with a virtual `update` — would have turned `add({ .speed = 220 })` into a constructor taking an options struct, and every later read into something like `get()->options.speed`. Without the base class, the fields *are* the configuration, and they stay live: ```cpp add({ .speed = 220 }); get()->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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) uses to track its animation is public: a private member would stop the sprite being an aggregate. ## Through a template, the type needs a name 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#change), `push()` or `replace()` cannot be a bare braced list: Does not compile ```cpp rmp::Scene::change({ .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: ```cpp 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::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. ============================================================================== # Ownership > Why everything in the framework is owned by something that releases it — textures, objects, scenes, callbacks, behaviors — why its API has no raw pointer, what you keep across frames, and why Callback exists instead of std::function. Source: 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. ## What owns what 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Shape), a behavior, an options struct | | `T &` | something that certainly exists and keeps its identity for the length of the call | | `std::span`, `std::string_view` | the caller's elements, or the caller's text, for the length of the call | | [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) | something that may not be there and is not yours, within the frame | | [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) | an object that can die, kept across frames | | `std::unique_ptr` | 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html), 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) is empty or refers to something; it owns nothing, and asking it is an `if`: ```cpp auto &player = spawn({ .size = { 26, 26 } }); player.add({ .hp = 3 }); if (auto health = player.get()) health->heal(1); ``` [`get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get) hands one back, empty when the object has no `B`, and so does [`Handle::get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html#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>`, which says the same for the price of `` 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ## Assets An [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#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. ```cpp 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: Does not compile ```cpp 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. ## Objects, and the handle that outlives them A scene owns its objects. [`spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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: ```cpp class Turret : public rmp::Object { public: rmp::Handle 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()`, so the field you read after the check needs no cast. ## Scenes and globals The scene stack owns its scenes. `RMP_GAME` makes the first one, and [`change()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global) 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. ## Callbacks: why not std::function 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html), 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: Does not compile ```cpp #include #include std::function on_win = [save = std::make_unique(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: ```cpp auto &coin = spawn({ .position = { 400, 225 }, .size = { 16, 16 } }); auto bonus = std::make_unique(10); coin.on_collision([bonus = std::move(bonus)](rmp::Object &self, rmp::Object &) { score += *bonus; self.destroy(); }); ``` The second is cost: `` 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. ## Behaviors A behavior added to an object belongs to the object. [`add()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#add) moves it into storage that never moves it again, so the reference it returns, and the `rmp::Ref` `get()` 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. ============================================================================== # No exceptions > Why nothing in the framework throws to report a failure, what it does instead — empty resources, defaults, results, warnings said once — and what that leaves to your game. Source: 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::`. ## Why Three reasons, and each would be enough on its own. - **Many game builds switch exceptions off.** A library that reports failure by throwing cannot be used by a game compiled without them. - **raylib is C.** An exception thrown inside a callback that raylib's C code is running — and on the web and on iOS the whole frame is such a callback — would have to unwind through C frames, which C++ does not define. - **A frame is a sequence that has to finish.** Throwing out of the middle of one leaves `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. ## What it does instead 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. ### An asset that fails to load is empty 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. ```cpp 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"); } ``` ### A read has a default Reading a save never throws and never crashes on what it finds. `read()` returns a [`Result`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#Result) that is true in an `if` only when the save was read and checked, and whose [`status`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) 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. ```cpp 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); ``` ### A lookup can come back empty Where the caller may want to know, the answer is an empty [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) or a `false`: [`get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get) comes back empty when the object has no such behavior, a [`Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) is empty once its object is gone, and [`rmp::save::write()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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. ### A mistake in the game is said once 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](https://omardev29.github.io/rmp-docs/framework/why/macros.html#report-once). A warning in a log is easy to miss, so a debug build can make it impossible to miss. [`[dev] strict = true`](https://omardev29.github.io/rmp-docs/reference/configuration.html#dev-strict) turns the first one into an abort with the message, in debug builds only: raylib_multiplatform.toml ```toml [dev] strict = true ``` ### A condition of the machine is not a mistake No 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. ### Leaving is a flag [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#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. ## Exceptions from underneath 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. ## What it leaves to your game 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. ============================================================================== # Macros > Macros are not the enemy — where the framework uses one because nothing else can do the job, the one rule it keeps about them, and how their names stay out of everyone else's way. Source: 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 entry point 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: ```cpp RMP_GAME(MainMenuScene); ``` [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) writes the three hooks for the scene stack and hands them to [`RMP_ENTRY_POINT`](https://omardev29.github.io/rmp-docs/reference/macros.html#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](https://omardev29.github.io/rmp-docs/framework/the-frame.html#own-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`](https://omardev29.github.io/rmp-docs/reference/macros.html#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. ## The values from the .toml 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: ```c #include 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. ## Said once 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. ```text #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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#dev-strict) the first report aborts a debug build. It is the framework's own tool and not part of the API: [No exceptions](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html) 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. ## Set by the build 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: ```cpp #if !RMP_PRODUCTION_BUILD DrawFPS(10, 10); #endif ``` Every 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](https://omardev29.github.io/rmp-docs/framework/the-frame.html#start-and-stop) 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_`. ## The rule: a header never makes you write one 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](https://omardev29.github.io/rmp-docs/examples/ui/03_clay_direct.html). ## What the framework adds is a constant 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#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. ## One namespace for every macro 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: - **Every macro of the framework starts with `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. - **No constant is named like somebody else's macro.** `PI`, `MIN`, `MAX`, `EPSILON`: each is a macro on some platform, and a constant with that name compiles everywhere except there. [Naming](https://omardev29.github.io/rmp-docs/guidelines/naming.html) lists them. - **No retired name is left in an `#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. ============================================================================== # Time is a parameter > Why every hook is handed delta instead of reading the clock, where the framework reads it, what [app] max_delta protects a game from, and why the same game plays the same at 60 and 240 frames a second. Source: 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. ```cpp 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)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_update), an object's [`_update(delta)`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#_update), 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. ## Where the clock is read 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`](https://omardev29.github.io/rmp-docs/reference/behaviors/Timer.html), a [`Tween`](https://omardev29.github.io/rmp-docs/reference/behaviors/Tween.html) are all driven by the number they were handed. ### So it can be tested 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html), 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#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](https://omardev29.github.io/rmp-docs/framework/testing.html#e2e) 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. ### So it plays the same at any frame rate 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 is integrated for you.** Set [`velocity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#velocity) in units per second and the object moves the same distance in a second at 30 or 240 frames. - **Forces and impulses are two calls.** [`apply_force`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#apply_force) is meant to be called every frame, and is scaled by `delta`; [`apply_impulse`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. - **The camera's smoothing is a rate.** The usual `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. ## [app] max_delta 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. raylib_multiplatform.toml ```toml [app] max_delta = 0.05 ``` 0 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: ```toml [app] max_delta = 0.001 ``` ```text 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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html#validation) 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 frame with no time in it 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. Noteraylib's `GetFrameTime()` is still there, and your own code can call it. It is the raw number: unclamped, and different from the `delta` the rest of the frame was given. Use `delta`. ============================================================================== # Naming (moved) > The naming rules moved to Guidelines › Naming, with the rest of the C++ style guide. Source: 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html). This page stays so that links to it keep working. ============================================================================== # Contributing > How to work on the framework itself: setting up a machine, the repository, the rules, writing tests, the verification ladder, CI, pull requests and keeping the docs true. Source: 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](https://omardev29.github.io/rmp-docs/getting-started/index.html) 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. ## The rule that outranks the others 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: ```cpp 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](https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html) has the whole argument. ## The order to read them in Top to bottom is the order a change goes through, from an empty machine to a merged pull request: 1. [Setting up](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html): `rmp`, a clone, the pinned clang tools, Python, and the build image CI uses. 2. [The repository](https://omardev29.github.io/rmp-docs/framework/contributing/repository.html): what lives where, what `rmp new` copies into a game, and what a new file needs before it is accepted. 3. [The rules](https://omardev29.github.io/rmp-docs/framework/contributing/rules.html): the framework's rules for its own code, each with the reason it exists. 4. Writing tests: [unit tests, the headless UI, render and smoke](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html); [examples as tests, and the scripts that play them](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html); [properties, fuzzing and mutation](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html); [coverage, and the gates](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html). 5. [The verification ladder](https://omardev29.github.io/rmp-docs/framework/contributing/ladder.html): what to run before a change leaves your machine, in order, and when the slow stages are worth their time. 6. [CI](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html): what a push and a pull request run, the debug lane, the full matrix, and how to read a red run. 7. [Pull requests](https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html): the branch, the template, the checks `main` requires, the API-change approval, and the commits. 8. [Keeping the docs true](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html): this site, the commit it documents, and the check that says when a change broke a page. Upgrading a dependency, rebuilding the build image and the changes the stores force every year are in [Maintaining](https://omardev29.github.io/rmp-docs/framework/maintaining/index.html). ## A change, in short 1. A branch of its own, from an up-to-date `main`. If an issue labelled `nightly-finding` is open, it comes first. 2. The change, and a test that fails without it. Every test and every gate is seen red on the mistake it exists for before it is trusted green. 3. `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`. 4. Where it matters, the same in the build image, which is what CI runs. 5. A pull request that fills in the template: what changed and why, what ran where, what was seen red, and what is not verified. 6. Every required check green, and Omar's approval when the change touches the public API or the `.toml`. 7. The pages of this site that the change makes untrue, fixed in the same stretch of work. ## For an agent 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. ============================================================================== # Setting up > What a machine needs to work on the framework: rmp, a clone, the pinned clang-format and clang-tidy, Python with Hypothesis, and the pinned build image CI runs in, with podman or Docker. Source: 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. ## What a laptop needs - **git**, and **Python 3.11** or newer: `rmp` is written in it. - **CMake 3.30** or newer, **Ninja**, and a C++20 compiler: GCC or Clang. - On Linux, the X11 development headers, or on a console with no desktop the DRM/KMS ones. [Install rmp](https://omardev29.github.io/rmp-docs/getting-started/install.html#what-it-needs) says how the installer lists what is missing, with the command for your system. - **The sanitizer runtimes.** Every debug build of the framework runs under AddressSanitizer and UndefinedBehaviorSanitizer. GCC's come with most distributions; Clang's are compiler-rt, a package of its own. Without them a debug build goes on unsanitized and says so in a CMake warning, which on the framework is a reason to stop, not to read past. - **clang-format and clang-tidy 22.1.8**, exactly: [below](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#clang-tools). - **Hypothesis**, for the Python property tests: [below](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#clang-tools), in the same place. - **gh**, GitHub's command line, signed in: `rmp push` asks it whether a CI run is in flight, and every command on [CI](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html) uses it. - **podman** or **Docker**, for [the image](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#the-image). 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. ## rmp, and a clone to work in Install `rmp` the way a game maker does, with the one line on [Install rmp](https://omardev29.github.io/rmp-docs/getting-started/install.html). Then clone the framework somewhere of your own to work in: ```shell git clone https://github.com/omardev29/raylib_multiplatform ~/raylib_multiplatform cd ~/raylib_multiplatform rmp help ``` Inside 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: ```shell ./rmp new ~/games/try_it ``` Keep 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. ```shell git switch main git pull --ff-only ``` ## clang-format, clang-tidy and Hypothesis The 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: ```shell 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: ```shell rmp test config ``` A 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. ## The build image 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: ```shell IMAGE=ghcr.io/omardev29/raylib-build@$(sed -nE 's/^build_image_digest +//p' thirdparty/FROZEN_VERSIONS.md) podman pull "$IMAGE" ``` ### A checkout of its own 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: ```shell git worktree add --detach ../raylib_multiplatform-image main cd ../raylib_multiplatform-image ``` Before 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: ```shell git switch --detach my-branch ``` A worktree keeps its git data in the first checkout's `.git`, so the container needs that folder too, read-only, at the same path: ```shell 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. - Rootless podman maps your user to root inside the container, so what it writes in the checkout is yours. On a system with SELinux, add `: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. ```shell tools/dev_shell.sh bash tools/versions_check.sh tools/dev_shell.sh ``` ## What only the image has Most 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 repository > What lives where in the framework's repository, the repositories beside it, what rmp new copies into a game and why that list is explicit, and what a new file needs before the checks accept it. Source: https://omardev29.github.io/rmp-docs/framework/contributing/repository.html The framework is one repository, [omardev29/raylib_multiplatform](https://github.com/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 repositories beside it [raylib_multiplatform](https://github.com/omardev29/raylib_multiplatform) The framework: the library, its tests, its examples, its tools and its CI. Every code change goes here. [rmp-docs](https://github.com/omardev29/rmp-docs) This site, checked against one commit of the framework. [Keeping the docs true](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html) is about it. [raylib-build-image](https://github.com/omardev29/raylib-build-image) The build image every Linux job runs in, and the Alpine image the musl build is started on. A new tool for CI is a new image, and a new digest in the framework. 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. ## What lives where | 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](https://omardev29.github.io/rmp-docs/framework/architecture.html) has how the modules depend on one another. ### build/ 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. ```shell rmp clean ``` deletes every build and everything generated from the `.toml`; the next command that needs them makes them again. ## What a game gets: the manifest 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. ```shell rmp new --list ``` prints 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. ## What a new file needs 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///` 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](https://omardev29.github.io/rmp-docs/framework/contributing/rules.html#dependencies) say why | | gate | a stage of `rmp test`, a step in CI, and a planted mistake it is seen to refuse — [Coverage and gates](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html) | | folder under `build/` | its line in `BUILD_DIRS` | Next: [the rules](https://omardev29.github.io/rmp-docs/framework/contributing/rules.html). ============================================================================== # The rules > The framework's rules for its own code, written for a person: where a change goes, names, headers, ownership, how the framework tells a game it made a mistake, the .toml, dependencies, sanitizers, the size budget, the image, and testing to the point of paranoia. Source: 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](https://omardev29.github.io/rmp-docs/guidelines/index.html) page has the detail, this page links it instead of repeating it. ## The rule that outranks the others 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](https://omardev29.github.io/rmp-docs/framework/contributing/index.html#the-rule) has the three questions every feature answers, and [the three-function menu](https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html) the whole argument. Every other rule here gives way to this one. ## Where a change goes `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. ## Names 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html) 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. ## Headers - **A new header is a module a game can choose.** `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](https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html) says more. - **The framework's headers do not include each other.** A header under `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. - **What a header costs is written down.** `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. ## Ownership and pointers 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) shows each replacement in code, and [Ownership](https://omardev29.github.io/rmp-docs/framework/why/ownership.html) explains handles. ## Nothing throws 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](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html) has the reasons. ## Telling the game it made a mistake 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. ## The .toml 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](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html) 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. ## A new dependency is a licence decision 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](https://omardev29.github.io/rmp-docs/framework/licences.html) 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. ## Debug is sanitized, release is hardened 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](https://omardev29.github.io/rmp-docs/framework/security.html) has every flag with what it protects against and what it costs. ## Every shipped binary has a size budget `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](https://omardev29.github.io/rmp-docs/publishing/ci.html#size-budget) shows the file and how one run's log updates it. ## A Linux job downloads nothing 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. ## Tested to the point of paranoia 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](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html), [examples and e2e](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html), [properties, fuzzing and mutation](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html) and [coverage and gates](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html) are how. ## What has already cost time The second half of [the framework's `CLAUDE.md`](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/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. ## Language 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). ============================================================================== # Writing a unit test > Where a new test of the framework goes, the shape of a test file, the seams through which a test sets the clock, the input and the interface, the interface laid out with no window, a test seen red before it is trusted, and the tests a game keeps in tests/game/. Source: 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](https://omardev29.github.io/rmp-docs/framework/testing.html) describes what the tests are and what each stage of `rmp test` runs. This page is for adding to them. ## Where a test goes 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](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html#python). | What it tests | The file | Built into | Run by | |---|---|---|---| | A module of `src/rmp/` | `tests/_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/_prop.cpp` | `property_test` | `rmp test property` — [Properties](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html#rapidcheck) | | A parser, fuzzed | `tests/fuzz/.cpp` | `fuzz_` | `rmp test fuzz` — [Fuzzing](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html#fuzzing) | | An example, played | `tests/e2e//.e2e` | `e2e__` | `rmp test examples` — [Examples and e2e scripts](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html) | | A tool of `tools/` | `tests/_test.py` | Python's `unittest` | the stage whose pattern finds it — [below](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html#python) | | A game's own code | `tests/game/_test.cpp` | `game_test` | `rmp test unit` — [below](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html#game) | 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. ## A test file 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. [tests/ads_test.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/ads_test.cpp#L1-L33) ```cpp // --------------------------------------------------------------------------- // 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 #include 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](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html#mutation) 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. ### Running it ```shell 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: ```shell 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](https://omardev29.github.io/rmp-docs/framework/security.html#sanitizers) says what the sanitizers catch. ## The seams 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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#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. ### The input 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: ```cpp 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`. ### The clock and the seed 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](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html#e2e) — get the same frame twice: ```cpp 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. ### What the framework says 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, with no window 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. ```cpp 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(config->fontSize); return Clay_Dimensions{ static_cast(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: - **In a `tests/ui__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. - **In `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. ```shell 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. ## Seen red first 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. 1. Write the test before the fix, or take the fix out for a moment. 2. Run it, and read the failure. It has to fail at the check you wrote, saying what you meant it to say — not a compile error, not a crash somewhere else, not a different check. 3. Put the fix in, and see the same test pass. 4. Say in the commit message how it was seen red. 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: ```shell git stash push -- src/rmp/app/clock.cpp rmp test unit git stash pop ``` What 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](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html) 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](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#gates-red) says how. ## Tests of the tools The Python in `tools/` is tested by `tests/_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. ```shell rmp test configure python3 -m unittest discover -s tests -p configure_test.py -k ConfigureLineTest -v ``` A test loads the tool it tests by its path, under the name `tools.`, 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 `` 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. ## In a game: `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. ```shell 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](https://omardev29.github.io/rmp-docs/framework/testing.html#game-tests) has the file a game starts with. ## After the test - Framework code added or tested: `rmp test coverage`, whose floors only rise — [Coverage](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#coverage). - Anything that parses, casts or frees touched: `rmp test sanitize`, the unit and layout tests again under gcc's sanitizers, which instrument differently and warn about other things. - A parser touched: `rmp test fuzz`, every committed input replayed. - The public API touched: `rmp test examples`, every example built, booted and played. ============================================================================== # Examples and e2e scripts > An example is a test: built, booted under the software renderer, photographed, and held to no mistake the framework reports; and the games, menus, scenes and input are played from a script, frame by frame, their pictures compared exactly with goldens recorded only in the build image. Source: 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](https://omardev29.github.io/rmp-docs/framework/testing.html#examples) says what each step proves. This page is for adding an example, and for writing, playing and recording its script. ## An example is a test An example is a small project laid out like a game: `examples///` 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__`, 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](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html#e2e) is what proves the difference. ### Its shape 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. ### The boot ```shell rmp example games/01_pong rmp test examples bash tools/examples_build.sh boot ``` `rmp 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__.png`: look at it. Looking at the pixels is how most of what is wrong with an example is found. ```shell RMP_EXAMPLE_FRAMES=120 bash tools/examples_build.sh boot ``` A picture of a later frame than the thirtieth is that variable away. ### No mistake reported: `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: what a player presses A script is `tests/e2e//.e2e`, and it plays `examples//`: 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: [tests/e2e/ui/01_menu.e2e](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/e2e/ui/01_menu.e2e#L1-L57) ```text # 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///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: - input on frame 0: the first frame has nothing to compare a key with, so a press there is held and never pressed — the first input goes on frame 1; - a key pressed while it is down, released while it is up or in the frame it went down, or pressed again in the frame it comes up or the frame after its tap: it would never come up, so the second press would be no press at all; and a click in the frame of another click or the frame after it, for the same reason; - a `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; - a shot name that is not lower case, digits and `_` — it is a file name — or one used twice; - no `end`, anything after it, or a script that checks nothing. The build makes a target of every script, `e2e__`: 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. ### What the driver does to the game 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. ## Writing one 1. Play the example yourself, with `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. 2. Write the script: the input, a `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. 3. Play it, on your machine. Outside the build image a shot that has no golden yet is not a failure: the run writes the picture it took and says so, and you look at it. 4. Move the frames until each picture shows what it should, and play it again. 5. Record the goldens inside the build image, look at every one, and commit them with the script. ```shell bash tools/examples_build.sh e2e ``` That plays every script. A shot with no golden prints a line that starts `E2E NOTE` and leaves `.actual.png` in `build/examples-check/e2e///`. Once that run has configured the build, one script is its own program, built and played alone: ```shell cmake --build build/examples-check --target e2e_ui_01_menu ./build/examples-check/e2e_ui_01_menu ``` It prints a line for every shot it took, with the picture's hash; a line for every check that failed, `E2E FAIL : `; 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. ## Goldens: exact, and only from the image Every shot is compared with its golden, `tests/e2e/golden///.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///`: 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. ### Recording them 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: ```shell tools/dev_shell.sh ``` and in that shell: ```shell python3 tools/configure.py ./rmp test e2e-update ``` The 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. ## Which examples are played 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: ```shell CMAKE_BUILD_PARALLEL_LEVEL=3 bash tools/examples_build.sh e2e ``` Each 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. ============================================================================== # Properties, fuzzing and mutation > The deep tests, for whoever adds to them: a RapidCheck property with the shared generators and a // covers: line, Hypothesis for the Python, a fuzz target with its corpus and regressions, a counterexample made a named case, mutation floors that only rise, and the nightly and weekly runs that open a nightly-finding issue. Source: 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. ## What runs when 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 RapidCheck property A property of a module is `tests/property/_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: [tests/property/clock_prop.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/property/clock_prop.cpp#L1-L127) ```cpp // --------------------------------------------------------------------------- // 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 #include #include // rmp::Callback #include #include #include #include #include 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 seed; if (*rc::gen::arbitrary()) { seed = *rc::gen::arbitrary(); } 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. - **The description is a string literal, and no two are alike.** It is the key a reproduce string finds the property by: two properties with one description would both be replayed against one case. - **Never RapidCheck's own `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. - **Draw what a game can hand the framework by mistake**, from `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. - **A new generator is held to what it promises**, in `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: ```shell 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_test ``` When 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. ### Every public function, held by a property 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](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/property/random_prop.cpp#L102-L105): ```text TEST_SUITE("property: random") { // covers: rmp::random::seed(uint64_t) // covers: rmp::random::value() ``` - **A public function no property covers and `tests/property/waivers.txt` does not list fails.** A new public function arrives with its property. - **The waivers only shrink.** A waived function a property covers fails until its line goes, and so does a line for a function that is gone. - **A `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. ## A counterexample becomes a named case 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: ```text 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](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html#red-first). ## Hypothesis, for the Python The tools are Python, and their properties are Hypothesis's, in `tests/_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. - **The tool is loaded by its path, as `tools.`**, the name mutation testing records a test's reach under. - **The strategies lean on what the code decides on.** Text drawn at random almost never writes the start of a raw string literal; the scanner's property mixes those pieces in on purpose. 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: ```shell 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' -v ``` The 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 A fuzz target is `tests/fuzz/.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: [tests/fuzz/tiled.cpp](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/fuzz/tiled.cpp#L1-L50) ```cpp // --------------------------------------------------------------------------- // 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 #include #include #include #include // 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 input = rmp::test::fuzz::input({ data, size }); if (input.size() > static_cast(std::numeric_limits::max())) return 0; rmp::Tilemap map; rmp::tilemap::detail::Access::adopt( map, rmp::tilemap::detail::parse_map(input.data(), static_cast(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//`**, the inputs fuzzing found that add coverage, merged in; seeded at first with real files of the format; - **`tests/fuzz/regressions//`**, 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/.dict`**, if it helps: the words of the format, for libFuzzer to put together; - **`tests/fuzz/.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. ```shell rmp test fuzz bash tools/fuzz.sh replay value_json bash tools/fuzz.sh run value_json 60 bash tools/fuzz.sh merge value_json ``` `rmp 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: ```shell tools/dev_shell.sh bash tools/fuzz.sh build tools/dev_shell.sh bash tools/fuzz.sh run value_json 60 ``` What a run finds is in `build/fuzz/crashes//`. It becomes two things: the input, copied into `regressions//` 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. ## Mutation testing 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/.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: [tests/mutation/floors/random.txt](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/tests/mutation/floors/random.txt#L1-L13) ```text # 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. - **The floor only rises.** Below it fails; and a floor below the score, rounded down to 5, fails too, until it is raised in the commit that earned it. `update` writes it. A lower floor is a hand edit a reviewer reads. - **The equivalent mutants only shrink.** One a test now kills, or one that is gone — Mull's ids carry the line, so moved code makes them new — fails until its line goes. - **Every file of `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. - **A test filter has to select something.** A `-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`: ```shell bash tools/mutation.sh modules tools/dev_shell.sh bash tools/mutation.sh run random tools/dev_shell.sh bash tools/mutation.sh update random ``` A 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. ## The nightly and weekly runs `.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: ```shell 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=random ``` What 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: ```shell gh issue list --label nightly-finding ``` One 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-` artifact; committing it is a pull request, never the workflow's. ============================================================================== # Coverage and the gates > What the tests reach, measured in the build image and held per file to a floor that only rises; every tools/*_check.sh and what it refuses; how each gate is seen red on a planted mistake, how to add one, and the files of the repository that only ever move one way. Source: 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. ## Coverage, measured in the image 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: ```shell rmp test coverage tools/dev_shell.sh bash tools/coverage_check.sh tools/dev_shell.sh bash tools/coverage_check.sh --update ``` CarefulThe image sees the checkout at another path than your machine does, and CMake refuses to configure a build folder again from another source directory. A folder the image configured — `build/coverage`, `build/fuzz` — is removed before the same script runs on your machine, and the other way round: `rm -rf build/coverage`. The 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. ### A floor per file, which only rises `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. - **A file below its line fails.** And 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. `--update`, in the image, raises the lines to what the run measured. - **A new file of `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. - **Nothing lowers a floor but a hand.** `--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. ### The public functions no test calls, which only shrink `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. ### Lines no test can run 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: ```text // RMP_COVERAGE_OFF() ... // RMP_COVERAGE_ON ``` The Aseprite reader's refusal of a file past `int`'s range is [one](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/src/rmp/assets/aseprite.cpp#L417-L420). 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 gates 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html) | `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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) | `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](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#coverage) | `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](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#lint-debt). [Testing](https://omardev29.github.io/rmp-docs/framework/testing.html#gates) lists every stage of `rmp test` with what it fails on, and [Enforcement](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) says which rule of the style guide each check holds. ## Every gate, seen red 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. ```text 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 \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. ```shell rmp test gates python3 -m unittest discover -s tests -p gates_red_test.py -k SeamCheckTest -v ``` ## Adding a gate Start from the mistake, written as one sentence a machine could check. Then pick the instrument that understands the most of it: - a clang-tidy check, or a query of the framework's own in `.clang-tidy`, for what the compiler parses — one branch of every `#if`; - a rejection in `tools/configure.py`, with its case in `tests/configure_test.py`, for a `.toml` that cannot work; - a unit test, for a behaviour; - a script in `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: 1. **The script**, `tools/_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. 2. **A stage** of `rmp test`, in `STAGES` in `tools/rmp.py`: a name, the summary `rmp help test` prints, and the command. 3. **A step in CI**, in the `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. 4. **Seen red**: its line in `GATES` and its class in `tests/gates_red_test.py`, as [above](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#gates-red). 5. **Whether a game gets it.** `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](https://omardev29.github.io/rmp-docs/framework/testing.html#gates), and a new rule of the style guide a row of [Enforcement](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html#table), the day the site moves to the commit that has it. ## Files that only move one way 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](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#floors) | | `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](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html#covers) | | the `floor` of `tests/mutation/floors/.txt` | up | a score under it; a floor under the score rounded down to 5 — [Mutation](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html#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](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html#played) | | `tools/lint_debt.txt` | down | a warning not owed; a count that grew; a count above what is left — [below](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html#lint-debt) | | `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: ```text custom-rmp-raw-pointer src/rmp/input/input.cpp 4 ``` - **A warning nobody owes fails.** A new warning is fixed, or carries a `NOLINT` naming the check, with its reason, on the line it is about. Nothing is ever added to the file. - **More than a line owes fails**, and every warning of that check and file is printed, because the new one cannot be told from the old ones. - **Fewer than a line owes fails too**: the debt was paid, and the line comes down to what is left, so the next warning is caught. ```shell rmp lint bash tools/lint.sh debt rmp lint fix ``` `bash 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](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html#debt) has what the tree still owes, check by check. ============================================================================== # The verification ladder > What to run before a change leaves your machine, in order: rmp fmt, rmp lint, every stage of rmp test, the slower stages and when each is worth its time, the same run inside the build image, and the seen-red-first protocol. Source: 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. ## Every time ```shell rmp fmt rmp lint rmp test ``` All 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. ### rmp fmt 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. ### rmp lint 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: ```shell bash tools/lint.sh debt ``` Nothing 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](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) 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. ### rmp test 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](https://omardev29.github.io/rmp-docs/reference/commands.html#test) has the list as `rmp help test` prints it, and [Testing](https://omardev29.github.io/rmp-docs/framework/testing.html) 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. ## When the change calls for more 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](https://omardev29.github.io/rmp-docs/framework/contributing/tests.html), [examples and e2e](https://omardev29.github.io/rmp-docs/framework/contributing/examples-and-e2e.html), [properties, fuzzing and mutation](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html) and [coverage and gates](https://omardev29.github.io/rmp-docs/framework/contributing/coverage-and-gates.html) pages say how to write what each of these runs, and how to update a floor that a change has earned. ## The same, inside the image 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](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#the-image) shows: ```shell 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. ## Seen red first 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: 1. Write the test, or the gate. 2. Put the mistake back: revert the fix, or plant the error by hand. Check that the text you changed was found exactly once, because a plant that did not apply proves nothing. 3. Run it. It has to fail, and its message has to name the mistake: a `FAIL` line that says what it found, not a crash somewhere near it. 4. Take the mistake out again, and see it pass. 5. Write down what you saw: the command, and the line it failed with. It goes in the commit message and in the pull request. `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. ## When the change is visual, look at it 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. ```shell rmp example 01_pong ``` builds one example and runs it in a window, by name or by its path under `examples/`; `rmp example` alone lists them. ## Say what ran 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](https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html) says how it is filled in. Next: [CI](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html). ============================================================================== # CI > What the framework's CI runs for a push and a pull request, the debug lane and the full matrix, how to read a red run job by job, the size budget's warnings, and how to wait for a run without polling it. Source: 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](https://omardev29.github.io/rmp-docs/publishing/ci.html), 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. ## The paths a run takes 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. The jobs of `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](https://riscv-runners.riseproject.dev/) runner, which RISE lends to open-source projects, or a [Cloud-V](https://cloud-v.co/github-riscv-runner) 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. The nightly and weekly search. Every failure is one `nightly-finding` issue per signature, found again as a comment. ## What a push and a pull request run 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](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html) | | `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. ## Asking for more: the debug lane and the full matrix 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: ```shell 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,android ``` `targets` 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). ```shell gh workflow run ci.yml -f full=true ``` macOS, 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. ## Reading a red run 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: ```shell 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](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#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](https://omardev29.github.io/rmp-docs/publishing/ci.html#reading-a-red-run), in Publishing, goes through every platform's checks. | ```shell gh run download "$RUN" -n e2e-pictures gh run rerun "$RUN" --failed ``` The 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. ### The size budget's warnings 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: ```shell 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. ## Pushing without killing a run 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. ```shell rmp push rmp push force ``` `rmp 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. ## Waiting for a run: never poll it 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: ```shell gh run watch "$RUN" --exit-status ``` An 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. ```shell 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 done ``` Each 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. ## The workflows that run on their own `deep.yml` Every night it fuzzes every target for ten minutes and runs the properties at a random seed; every Sunday it runs mutation testing, a job per module. What it finds becomes an issue labelled `nightly-finding`, one per signature, with the command that replays it. Those issues are taken before anything else: [Pull requests](https://omardev29.github.io/rmp-docs/framework/contributing/pull-requests.html#nightly-findings) says how. `canary.yml` Every week, the same build against the versions the framework is not pinned to — the newest image, Xcode, Mesa — to learn what is about to break before a pin has to move. Its failure blocks nothing. Both 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). ============================================================================== # Pull requests > How a change reaches the framework's main: a branch, the ladder, the pull request template, the checks main requires, Omar's approval for a change to the public API or the .toml, nightly-finding issues first, and plain commits. Source: 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. ## From a branch to main 1. Start from an up-to-date `main`, on a branch named for the change: ```shell git switch main git pull --ff-only git switch -c save-reads-any-locale ``` An agent works in a git worktree of its own as well, so that two tasks on one machine never share a checkout. 2. Make the change, with its test seen red first, and run [the ladder](https://omardev29.github.io/rmp-docs/framework/contributing/ladder.html). 3. Push the branch. The first push sets its upstream: ```shell rmp push ``` 4. Open the pull request, on GitHub or with `gh`. Its description starts from the template, below; fill it in. ```shell gh pr create --base main --template .github/pull_request_template.md ``` 5. CI runs the fast lane on the branch merged into `main`, 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](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html). 6. When every required check is green, and the approval is there if the change needs one, it is merged. ## Agents in the cloud 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. ## The template `.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: What changed, and why The change in a few sentences, and the reason for it: the bug and how it showed, or the game that needs the feature. For a feature, how it answers the three questions of [the three-function menu](https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html#admission). The ladder Which stages ran, and where: on the laptop, and in the pinned build image. Name a stage that skipped, and why. Seen red first For each new test and gate, the mistake it was seen to fail on, and the line it failed with. Not verified What the change could affect that nothing here ran: a platform only the full matrix builds, a check only the image has. An honest list is worth more than a green one; it says where the next person should look. The checklist Each box is ticked, or says why it does not apply: - `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; - the docs updated, and `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](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html); - no secret anywhere in the change; - the commits plain, below. ## The checks main requires 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](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html), 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. ## A change to the API needs Omar's approval 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: - any file under `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; - a key of the `.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: ```shell gh run rerun "$RUN" --failed ``` Before you open one, the same script says what your branch would be labelled, against `origin/main`, and changes nothing: ```shell python3 tools/api_change.py ``` Make 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. ## nightly-finding issues first 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: ```shell gh issue list --label nightly-finding ``` Taking one is the seen-red protocol with the evidence handed to you: 1. Play it again with the command in the issue, in the build image, and see it fail. 2. Make it a case that runs on every push: a fuzz input goes into `tests/fuzz/regressions//` 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. 3. Fix it, and see that case pass. 4. Open the pull request with `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](https://omardev29.github.io/rmp-docs/framework/contributing/properties-fuzzing-mutation.html) has each kind in detail. ## Commits 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. ## What needs a person Everything else is done without asking. Omar is asked for: - a change to the public API or to a key of the `.toml`, through `api-approved`, above; - an architectural decision: what the framework is, rather than how one piece of it works; - a serious problem; - anything on GitHub itself: its settings, labels, branch protection and secrets, and anything wrong with it. Next: [keeping the docs true](https://omardev29.github.io/rmp-docs/framework/contributing/docs.html). ============================================================================== # Keeping the docs true > This site documents one commit of the framework, FRAMEWORK_REF, and is checked against it: how to tell when a framework change made a page untrue, fix the page, move the commit, and run the same checks the site's CI runs. Source: https://omardev29.github.io/rmp-docs/framework/contributing/docs.html This site is its own repository, [omardev29/rmp-docs](https://github.com/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. ## What the site checks A page is an HTML fragment under `content/`, and the rules for writing one are in [AUTHORING.md](https://github.com/omardev29/rmp-docs/blob/main/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: - every `rmp` command a page shows exists and takes the argument it is given, read from `rmp help --json`; - every name written in code — `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; - every C and C++ block compiles against the framework's headers, and every `.toml` block goes through its `configure.py`; - every sentence pinned to the source still holds, and every message quoted is one the framework prints; - no count the framework can change is typed: the number of targets, examples or headers comes from the framework when the site is built. 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: ```text

Three commands act on the framework the rmp you typed belongs to …

``` 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. ## Running the checks 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: ```shell 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 tests ``` The 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. ## When a framework change makes a page untrue 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: 1. Merge the framework's pull request. The site documents commits that are on the framework's `main`: its own CI fetches `FRAMEWORK_REF` from GitHub. 2. On a branch of the site, fix every page the warning named, and any page that says something the change made untrue that no check could see. Search the site for the name you changed. 3. Move `FRAMEWORK_REF` to the framework's commit, with the framework checked out at it: ```shell git -C ../raylib_multiplatform fetch origin git -C ../raylib_multiplatform switch --detach origin/main git -C ../raylib_multiplatform rev-parse HEAD > FRAMEWORK_REF ``` 4. Run the checks above until they pass, and look at the pages you changed with `serve`. 5. Open the site's pull request. Its CI builds the framework's examples at that commit, runs every check with `--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. ## How far behind the site is 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/contributing/index.html). ============================================================================== # Maintaining > How to keep the framework alive for years with one person: every moving part and where it is pinned, the build image, Python, upgrading each dependency, the yearly round the stores impose, and what to keep so it still builds in decades. Source: 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. ## The pages [How it all fits](https://omardev29.github.io/rmp-docs/framework/maintaining/how-it-fits.html) The framework as a system: the repositories, the command, the generator, the build systems, the toolchain of each family of targets, the workflows and the image, and what each one reads from the others. [Every dependency](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html) Each library, tool, SDK and service the framework depends on, where its version is held, what checks it, and a map, read from the tree, of every file that names it. [The build image](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html) What is in `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. [Python](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html) What Python the framework needs and why, the parts that are standard library only and the parts that are not, and how the image's hash-locked test tools are updated. [Upgrading a dependency](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html) A playbook per dependency: where its version is, what else has to move with it, the patches to carry over, the gates that will go red, and what is re-recorded afterwards. [The dialogue and the text](https://omardev29.github.io/rmp-docs/framework/maintaining/dialogue-and-text.html) The Yarn Spinner port and the test cases that hold it to the original, how a new Yarn release is taken in, the translation tables and their tools, and how a language is added. [The yearly round](https://omardev29.github.io/rmp-docs/framework/maintaining/yearly.html) What forces a change even when nobody touches the code: the stores' requirements, the runner images GitHub retires, the BSD releases, the scheduled workflows that stop by themselves. [Ten years and more](https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html) What rots first and what lasts, what to archive so a desktop build still works with no network and no GitHub, and how to run the framework with one person and little time. ## In short | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/yearly.html) puts dates on it. ## Where every version lives 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](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html) goes through all of them. ## Before a maintenance session 1. Read [Setting up](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html) if the machine is new: Python 3.11 or newer, CMake, Ninja, the pinned clang tools, and Docker or podman for the image. 2. Run `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. 3. Look at the last canary run and its upstream report: it says what is newer than every pin, and what breaks with it ([the canary](https://omardev29.github.io/rmp-docs/framework/maintaining/yearly.html#canary)). 4. Open issues labelled `nightly-finding` come first, as in any other session. 5. One dependency per pull request. A bump that moves two things at once cannot be bisected when the matrix goes red twenty minutes later. ============================================================================== # How it all fits > The framework as a system — its repositories, the rmp command, the generator, CMake, Gradle and Xcode, the toolchain of every family of targets, the workflows and the build image — and what each part reads from the others. Source: https://omardev29.github.io/rmp-docs/framework/maintaining/how-it-fits.html [Architecture](https://omardev29.github.io/rmp-docs/framework/architecture.html) 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. ## The repositories Every arrow is a pin: a digest, a commit, or a copy. None of them moves unless someone moves it. [raylib_multiplatform](https://github.com/omardev29/raylib_multiplatform) The framework: the library, the vendored libraries under `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. [raylib-build-image](https://github.com/omardev29/raylib-build-image) Two images: `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](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#android-bump) moves them in a set order. [raylib-iOS](https://github.com/omardev29/raylib-iOS) raylib has no iOS backend of its own. The framework's comes from a fork of a third party's port, kept under the same account so that the commit it pins cannot vanish with somebody else's repository; `thirdparty/raylib-ios` is the submodule, used by the iOS target only. [rmp-docs](https://github.com/omardev29/rmp-docs) This site, made of HTML fragments and of the framework's headers by one Python script, and checked against the framework at the commit in its `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. ## From a checkout to a binary 1. **The launcher.** `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. 2. **The generator.** `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](https://omardev29.github.io/rmp-docs/framework/config-pipeline.html) has every file it writes. 3. **CMake.** `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. 4. **Gradle and Xcode.** Android builds through `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"). 5. **Packaging.** A release is packed by the release job of each family: UPX on the Linux targets whose packed binary CI starts, the resources bundled into one `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. ## Who builds each family | 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 | Not pinned The compiler that builds the shipped Windows `.exe` is whichever one CMake finds first on the runner's PATH — the runner's MinGW GCC — and it moves with the runner image. The job reads it back from the CMake cache and prints it, so a failure can be matched to a compiler afterwards, but nothing holds it still. The MSVC that checks the examples compile floats the same way. On Windows, a red run that nobody caused is the first thing to suspect it of. ## The workflows `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](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html) 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 image, in the middle 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](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html) says what is in it and how to make a new one. ## The gates around it 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](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html) lists, for each bump, which of them to expect. ============================================================================== # Every dependency > Every library, toolchain, SDK, runner, Python and Node package and outside service the framework depends on — how each one is pinned, what checks the pin, and a map, read from the tree, of every file that names it. Source: 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?". ## The kinds of pin | 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. ## The code that is compiled in 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](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#raylib) and the entries after it say how. ## The toolchain inside the build image 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](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html) | | 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 | ## The runners and what they bring | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/how-it-fits.html#families)) | | 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 | ## Python and Node Python, 3.11 or newer Every build needs it: CMake runs the generator on every configure. The generator, `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](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html) has all of it. Node, for the web test only `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. ## The outside services 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](https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html#archive)). | | `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. | ## Every pin, as the framework holds 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…` | ## What names each dependency 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](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-raylib) | 41 | 3 | 11 | 48 | 2 | 10 | 20 | | [raylib-cpp](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-raylib-cpp) | 1 | 1 | 0 | 1 | 1 | 0 | 12 | | [raymob](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-raymob) | 6 | 17 | 12 | 7 | 3 | 2 | 27 | | [raylib-iOS](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-raylib-ios) | 1 | 2 | 3 | 4 | 2 | 0 | 10 | | [Clay](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-clay) | 19 | 2 | 7 | 15 | 0 | 2 | 14 | | [cute_tiled](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-cute-tiled) | 4 | 3 | 4 | 6 | 1 | 0 | 10 | | [cute_aseprite](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-cute-aseprite) | 4 | 2 | 6 | 6 | 1 | 0 | 8 | | [cJSON](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-cjson) | 9 | 2 | 5 | 9 | 1 | 0 | 8 | | [rres](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-rres) | 14 | 4 | 17 | 12 | 4 | 3 | 20 | | [doctest](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-doctest) | 0 | 2 | 8 | 72 | 2 | 0 | 13 | | [RapidCheck](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-rapidcheck) | 0 | 0 | 3 | 38 | 2 | 0 | 13 | | [Android build stack](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-android-build-stack) | 2 | 17 | 7 | 5 | 7 | 1 | 25 | | [Apple toolchain](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-apple-toolchain) | 3 | 3 | 5 | 2 | 8 | 2 | 25 | | [Emscripten](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-emscripten) | 7 | 4 | 4 | 5 | 3 | 2 | 21 | | [zig](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-zig) | 1 | 1 | 4 | 3 | 1 | 0 | 9 | | [The build image](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-the-build-image) | 0 | 1 | 14 | 8 | 11 | 0 | 13 | | [LLVM test tools](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-llvm-test-tools) | 0 | 2 | 9 | 50 | 3 | 0 | 14 | | [clang-format and clang-tidy](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-clang-format-and-clang-tidy) | 10 | 3 | 11 | 6 | 1 | 1 | 31 | | [Python test tools](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-python-test-tools) | 0 | 0 | 6 | 15 | 2 | 0 | 12 | | [Pillow](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-pillow) | 0 | 1 | 7 | 2 | 3 | 1 | 9 | | [PyYAML](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-pyyaml) | 0 | 0 | 2 | 6 | 2 | 0 | 2 | | [Playwright](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-playwright) | 0 | 0 | 0 | 0 | 4 | 0 | 4 | | [BSD virtual machines](https://omardev29.github.io/rmp-docs/framework/maintaining/dependencies.html#dep-bsd-virtual-machines) | 0 | 1 | 4 | 3 | 3 | 0 | 8 | **raylib135 files** the window, input, audio and renderer; a modified copy. Its version: the committed files, and PATCHES.md. - **Product code** (41): `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) - **Build projects** (3): `CMakeLists.txt` (8), `raymob/app/src/main/cpp/CMakeLists.txt` (3), `ios/README.md` (2) - **Tools and gates** (11): `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** (48): `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) - **CI** (2): `.github/workflows/web-backends.yml` (2), `.github/workflows/_release.yml` (1) - **Examples** (10): `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) - **Docs, pins and config** (7): `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) - **This site** (13): `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) **raylib-cpp16 files** the math types only: vectors, matrices, rectangles, colours. Its version: the committed files. - **Product code** (1): `include/rmp/math.h` (12) - **Build projects** (1): `raymob/app/src/main/cpp/CMakeLists.txt` (1) - **Tests** (1): `tests/configure_test.py` (7) - **CI** (1): `.github/workflows/_windows.yml` (1) - **Docs, pins and config** (6): `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) - **This site** (6): `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) **raymob76 files** Android's native glue and its Java side; patched. Its version: the committed files, and PATCHES.md. - **Product code** (6): `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) - **Build projects** (17): `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 and gates** (12): `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** (7): `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) - **CI** (3): `.github/workflows/_android.yml` (24), `.github/workflows/_windows.yml` (3), `.github/workflows/_firebase.yml` (1) - **Examples** (2): `examples/platform/02_mobile_raymob/src/main.cpp` (9), `examples/README.md` (4) - **Docs, pins and config** (8): `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) - **This site** (19): `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) - **Other** (2): `.gitignore` (13), `.clangd` (1) **raylib-iOS23 files** the iOS backend, UIKit and EGL through ANGLE; a fork of a fork. Its version: the submodule's commit. - **Product code** (1): `include/rmp/app.h` (1) - **Build projects** (2): `ios/README.md` (12), `ios/ANGLE-LICENSE.txt` (7) - **Tools and gates** (3): `tools/configure.py` (18), `tools/rmp.py` (3), `tools/license_db.py` (2) - **Tests** (4): `tests/configure_test.py` (5), `tests/rmp_test.py` (5), `tests/rmp_property_test.py` (1), `tests/smoke_test.h` (1) - **CI** (2): `.github/workflows/_apple.yml` (8), `.github/workflows/ci.yml` (3) - **Docs, pins and config** (3): `THIRD_PARTY_LICENSES.md` (16), `TECHNICAL.md` (11), `thirdparty/FROZEN_VERSIONS.md` (4) - **This site** (7): `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) - **Other** (1): `.gitmodules` (5) **Clay59 files** the UI's layout engine, used only under src/rmp/ui/. Its version: the committed file, and PATCHES.md. - **Product code** (19): `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) - **Build projects** (2): `CMakeLists.txt` (2), `raymob/app/src/main/cpp/CMakeLists.txt` (1) - **Tools and gates** (7): `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** (15): `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** (2): `examples/ui/03_clay_direct/src/main.cpp` (22), `examples/README.md` (1) - **Docs, pins and config** (7): `.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) - **This site** (7): `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) **cute_tiled29 files** the Tiled map reader; patched and hardened. Its version: the committed file, and PATCHES.md. - **Product code** (4): `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) - **Build projects** (3): `cmake/sanitize_ignore.txt` (4), `CMakeLists.txt` (2), `raymob/app/src/main/cpp/CMakeLists.txt` (2) - **Tools and gates** (4): `tools/naming_check.sh` (3), `tools/configure.py` (1), `tools/cppcheck_check.sh` (1), `tools/header_cost.py` (1) - **Tests** (6): `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) - **CI** (1): `.github/workflows/_windows.yml` (1) - **Docs, pins and config** (6): `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) - **This site** (4): `framework/security.html` (2), `framework/architecture.html` (1), `framework/licences.html` (1), `guidelines/pointers-and-raii.html` (1) - **Other** (1): `.clang-tidy` (3) **cute_aseprite28 files** the Aseprite reader. Its version: sha256_cute_aseprite. - **Product code** (4): `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) - **Build projects** (2): `CMakeLists.txt` (2), `raymob/app/src/main/cpp/CMakeLists.txt` (1) - **Tools and gates** (6): `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** (6): `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) - **CI** (1): `.github/workflows/_windows.yml` (1) - **Docs, pins and config** (4): `CLAUDE.md` (5), `thirdparty/FROZEN_VERSIONS.md` (4), `TECHNICAL.md` (3), `THIRD_PARTY_LICENSES.md` (3) - **This site** (4): `framework/architecture.html` (1), `framework/licences.html` (1), `guidelines/enforcement.html` (1), `guidelines/pointers-and-raii.html` (1) - **Other** (1): `.clang-tidy` (3) **cJSON35 files** JSON, for saves and LDtk. Its version: sha256_cjson. - **Product code** (9): `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) - **Build projects** (2): `CMakeLists.txt` (1), `raymob/app/src/main/cpp/CMakeLists.txt` (1) - **Tools and gates** (5): `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** (9): `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) - **CI** (1): `.github/workflows/_windows.yml` (1) - **Docs, pins and config** (5): `thirdparty/FROZEN_VERSIONS.md` (7), `TECHNICAL.md` (4), `THIRD_PARTY_LICENSES.md` (4), `CLAUDE.md` (2), `raylib_multiplatform.toml` (1) - **This site** (3): `framework/architecture.html` (4), `framework/licences.html` (1), `guidelines/pointers-and-raii.html` (1) - **Other** (1): `.clang-tidy` (3) **rres76 files** the resource pack, its compression and its encryption. Its version: sha256_rres. - **Product code** (14): `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) - **Build projects** (4): `CMakeLists.txt` (24), `raymob/app/build.gradle` (3), `cmake/sanitize.cmake` (1), `raymob/app/src/main/cpp/CMakeLists.txt` (1) - **Tools and gates** (17): `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** (12): `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) - **CI** (4): `.github/workflows/_linux.yml` (13), `.github/workflows/_windows.yml` (11), `.github/workflows/_apple.yml` (2), `.github/workflows/_bsd.yml` (2) - **Examples** (3): `examples/assets/01_loading/src/main.cpp` (3), `examples/README.md` (1), `examples/plain_c/src/main.c` (1) - **Docs, pins and config** (7): `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) - **This site** (13): `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) - **Other** (2): `.clang-tidy` (4), `.gitignore` (1) **doctest97 files** the unit test framework, shipped with every game's tests. Its version: sha256_doctest. - **Build projects** (2): `cmake/game_tests.cmake` (8), `CMakeLists.txt` (4) - **Tools and gates** (8): `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** (72): `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) - **CI** (2): `.github/workflows/ci.yml` (2), `.github/workflows/deep.yml` (1) - **Docs, pins and config** (5): `thirdparty/FROZEN_VERSIONS.md` (9), `CLAUDE.md` (4), `THIRD_PARTY_LICENSES.md` (3), `TECHNICAL.md` (2), `.claude/skills/rmp-verify/SKILL.md` (1) - **This site** (8): `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) **RapidCheck56 files** the C++ property tests; the framework's only. Its version: sha256_rapidcheck. - **Tools and gates** (3): `tools/naming_check.sh` (8), `tools/rmp.py` (4), `tools/finding.py` (2) - **Tests** (38): `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) - **CI** (2): `.github/workflows/deep.yml` (10), `.github/workflows/ci.yml` (4) - **Docs, pins and config** (5): `TECHNICAL.md` (8), `CLAUDE.md` (6), `thirdparty/FROZEN_VERSIONS.md` (5), `THIRD_PARTY_LICENSES.md` (4), `.claude/skills/rmp-verify/SKILL.md` (2) - **This site** (8): `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) **Android build stack65 files** Gradle, AGP, the SDK, the NDK and AdMob's SDK. Its version: android_*, agp, gradle, play_services_ads. - **Product code** (2): `src/rmp/app/app.cpp` (1), `src/scenes/main_menu.h` (1) - **Build projects** (17): `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 and gates** (7): `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** (5): `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) - **CI** (7): `.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** (1): `examples/scenes/01_stack/src/main.cpp` (1) - **Docs, pins and config** (6): `TECHNICAL.md` (35), `thirdparty/FROZEN_VERSIONS.md` (18), `CLAUDE.md` (6), `raylib_multiplatform.toml` (6), `README.md` (1), `THIRD_PARTY_LICENSES.md` (1) - **This site** (19): `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) - **Other** (1): `.gitignore` (1) **Apple toolchain50 files** Xcode, XcodeGen and the macOS runner. Its version: xcode, xcodegen, macos_runner. - **Product code** (3): `src/rmp/app/app.cpp` (1), `src/rmp/save/cjson_impl.c` (1), `src/scenes/main_menu.h` (1) - **Build projects** (3): `ios/README.md` (14), `CMakeLists.txt` (3), `cmake/sanitize.cmake` (1) - **Tools and gates** (5): `tools/configure.py` (14), `tools/install.sh` (3), `tools/api_change.py` (1), `tools/render_check.sh` (1), `tools/upx_pack.sh` (1) - **Tests** (2): `tests/configure_test.py` (20), `tests/configure_property_test.py` (7) - **CI** (8): `.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** (2): `examples/plain_c/src/main.c` (1), `examples/scenes/01_stack/src/main.cpp` (1) - **Docs, pins and config** (5): `TECHNICAL.md` (22), `thirdparty/FROZEN_VERSIONS.md` (9), `raylib_multiplatform.toml` (4), `CLAUDE.md` (2), `README.md` (1) - **This site** (20): `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) - **Other** (2): `.clangd` (1), `.gitignore` (1) **Emscripten46 files** the web build's compiler. Its version: emscripten, and the image's emsdk commit. - **Product code** (7): `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) - **Build projects** (4): `CMakeLists.txt` (25), `cmake/web/rmp_web.js` (4), `CMakePresets.json` (3), `cmake/sanitize.cmake` (1) - **Tools and gates** (4): `tools/configure.py` (11), `tools/rmp.py` (9), `tools/examples_check.sh` (3), `tools/versions_check.sh` (3) - **Tests** (5): `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) - **CI** (3): `.github/workflows/web-backends.yml` (9), `.github/scripts/web_boot_test.js` (3), `.github/workflows/_web.yml` (2) - **Examples** (2): `examples/plain_c/src/main.c` (3), `examples/ui/04_settings/src/main.cpp` (2) - **Docs, pins and config** (6): `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) - **This site** (15): `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) **zig20 files** the Linux cross-compiler that sets the glibc floor. Its version: zig, zig_sha256_*. - **Product code** (1): `src/rmp/save/number_internal.h` (1) - **Build projects** (1): `CMakeLists.txt` (7) - **Tools and gates** (4): `tools/linux_build.sh` (34), `tools/versions_check.sh` (6), `tools/glibc_check.sh` (4), `tools/binary_check.py` (1) - **Tests** (3): `tests/binary_check_test.py` (3), `tests/configure_test.py` (3), `tests/rmp_test.py` (1) - **CI** (1): `.github/workflows/_linux.yml` (6) - **Docs, pins and config** (4): `CLAUDE.md` (2), `raylib_multiplatform.toml` (2), `thirdparty/FROZEN_VERSIONS.md` (2), `thirdparty/raylib/PATCHES.md` (2) - **This site** (5): `framework/security.html` (11), `manual/platforms/desktop.html` (3), `getting-started/install.html` (1), `publishing/ci.html` (1), `publishing/desktop.html` (1) - **Other** (1): `.gitignore` (2) **The build image48 files** every Linux, web and Android job's toolchain. Its version: build_image_digest. - **Build projects** (1): `raymob/app/src/main/cpp/CMakeLists.txt` (1) - **Tools and gates** (14): `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** (8): `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) - **CI** (11): `.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) - **Docs, pins and config** (4): `thirdparty/FROZEN_VERSIONS.md` (8), `TECHNICAL.md` (6), `.claude/skills/rmp-verify/SKILL.md` (3), `CLAUDE.md` (3) - **This site** (9): `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) - **Other** (1): `.devcontainer/devcontainer.json` (1) **LLVM test tools80 files** coverage, the sanitizers' runtimes, libFuzzer and Mull. Its version: llvm, mull. - **Build projects** (2): `cmake/sanitize.cmake` (2), `CMakeLists.txt` (1) - **Tools and gates** (9): `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** (50): `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) - **CI** (3): `.github/workflows/ci.yml` (4), `.github/workflows/_linux.yml` (1), `.github/workflows/deep.yml` (1) - **Docs, pins and config** (5): `CLAUDE.md` (10), `TECHNICAL.md` (8), `.claude/skills/rmp-verify/SKILL.md` (4), `thirdparty/FROZEN_VERSIONS.md` (2), `raylib_multiplatform.toml` (1) - **This site** (9): `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) - **Other** (2): `.clang-tidy` (1), `.devcontainer/devcontainer.json` (1) **clang-format and clang-tidy65 files** the formatter and the linter. Its version: clang_format, clang_tidy. - **Product code** (10): `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) - **Build projects** (3): `CMakeLists.txt` (5), `CMakePresets.json` (1), `cmake/sanitize.cmake` (1) - **Tools and gates** (11): `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** (6): `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) - **CI** (1): `.github/workflows/ci.yml` (21) - **Examples** (1): `examples/.clang-tidy` (2) - **Docs, pins and config** (6): `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) - **This site** (25): `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) - **Other** (2): `.clang-tidy` (10), `.clang-format` (2) **Python test tools36 files** Hypothesis, mutmut and pytest. Its version: hypothesis, mutmut, pytest. - **Tools and gates** (6): `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** (15): `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) - **CI** (2): `.github/workflows/deep.yml` (16), `.github/workflows/ci.yml` (5) - **Docs, pins and config** (4): `CLAUDE.md` (7), `TECHNICAL.md` (7), `.claude/skills/rmp-verify/SKILL.md` (4), `thirdparty/FROZEN_VERSIONS.md` (3) - **This site** (8): `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) - **Other** (1): `.gitignore` (5) **Pillow23 files** the icons: the .ico, Android's and iOS's. Its version: pillow, pillow_sha256_*. - **Build projects** (1): `CMakeLists.txt` (2) - **Tools and gates** (7): `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** (2): `tests/configure_test.py` (7), `tests/dialogue/yarn/TestCases/VeryLargeFileOfVariables.yarn` (1) - **CI** (3): `.github/workflows/_windows.yml` (20), `.github/workflows/_android.yml` (1), `.github/workflows/_apple.yml` (1) - **Examples** (1): `examples/ui/09_skinned/resources/License-art.txt` (1) - **Docs, pins and config** (1): `thirdparty/FROZEN_VERSIONS.md` (4) - **This site** (8): `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) **PyYAML12 files** the workflow checks read the YAML with it. Its version: the image's apt snapshot. - **Tools and gates** (2): `tools/workflow_check.sh` (12), `tools/shell_pattern_check.sh` (2) - **Tests** (6): `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) - **CI** (2): `.github/workflows/ci.yml` (5), `.github/workflows/_linux.yml` (2) - **Docs, pins and config** (1): `CLAUDE.md` (3) - **This site** (1): `publishing/ci.html` (1) **Playwright10 files** the web boot test's browser. Its version: package-lock.json. - **CI** (4): `.github/workflows/_web.yml` (4), `.github/workflows/web-backends.yml` (3), `.github/dependabot.yml` (1), `.github/scripts/web_boot_test.js` (1) - **Docs, pins and config** (1): `thirdparty/FROZEN_VERSIONS.md` (2) - **This site** (3): `publishing/ci.html` (3), `publishing/web.html` (2), `manual/basics/project-layout.html` (1) - **Other** (2): `package-lock.json` (10), `package.json` (1) **BSD virtual machines19 files** FreeBSD, OpenBSD and NetBSD, started by cross-platform-actions. Its version: freebsd, openbsd, netbsd. - **Build projects** (1): `cmake/configure_hook.cmake` (1) - **Tools and gates** (4): `tools/configure.py` (26), `tools/size_budget.txt` (5), `tools/portable_check.sh` (2), `tools/render_check.sh` (1) - **Tests** (3): `tests/configure_test.py` (15), `tests/rmp_test.py` (3), `tests/size_check_test.py` (3) - **CI** (3): `.github/workflows/_bsd.yml` (10), `.github/workflows/_itch.yml` (5), `.github/scripts/canary_triage.py` (3) - **Docs, pins and config** (4): `raylib_multiplatform.toml` (10), `CLAUDE.md` (3), `TECHNICAL.md` (3), `thirdparty/FROZEN_VERSIONS.md` (3) - **This site** (4): `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. ============================================================================== # The build image > What the build image and the Alpine run image hold, how they are built, verified and published, every step of a bump in order — the Android one included, where the image and the framework point at each other — and what moves in the framework afterwards. Source: 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](https://github.com/omardev29/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. ## Two images | 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. ## What frozen means here | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html#lock)) | | 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 manifest 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. ## Checked before it is published Two checks, and each has to do the job of the tool, not print its version: - **The smoke check**, a step of the `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. - **The verify script**, `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. ## How it is published | 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. ## A bump, step by step Any change to the image — a newer tool, a new package, a newer snapshot — goes the same way. 1. **In the image repository**, change the `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](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html#lock)). 2. **Build it on the branch** with a manual run: both architectures built and verified, nothing published. Or build it locally: ```shell docker build -t raylib-build . docker run --rm -e EXPECT_ARCH=amd64 -v "$PWD/verify:/verify:ro" raylib-build bash -l /verify/image.sh ``` 3. **Try the framework in it before publishing**: in a checkout of the framework, the whole ladder in the local image ([a checkout of its own](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#a-checkout-for-the-image)), with `tools/versions_check.sh` told nothing yet — it will report the drift you are about to fix, which proves it is reading the new manifest. 4. **Merge to the image repository's `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. 5. **In the framework**, on a branch, replace the digest everywhere it is written and change every key that moved: ```shell 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.sh ``` The digest is in `ci.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`. 6. **Run what the image is exact about**, in the new image: `rmp test`, `rmp test examples`, `rmp test coverage`, and the size lines from a release build. [What moves](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#after) says what to expect. 7. **The pull request** says what moved in the image, what moved in the framework because of it, and what was re-recorded. Once the image repository's verify workflow is green on both architectures, the pull request that pins an image a card of the plan builds merges on a review by an agent that did not write it (`CLAUDE.md`, "What does not wait for him"). ### The Android bump: two repositories, in order 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: 1. In the framework, on a branch: the new set in `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. 2. In the image repository: `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. 3. Publish, take the digest, and pin it on the same framework branch. Its Android job is green now, and `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`. ### The LLVM bump 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. ### A new Ubuntu 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. ## What moves in the framework after a bump | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#clang-tools) | | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#android-bump) | | The apt snapshot | any of the above at once | a snapshot bump is every package's bump: do it alone | ## The Alpine run image 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: ```shell 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.sh ``` When 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. ## Keep a copy 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](https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html#archive) has the commands. ============================================================================== # Python > Where the framework runs Python, why 3.11 is the floor, which parts are standard library only and which are not, how the build image's hash-locked test tools are regenerated, and what a new Python can break. Source: 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. ## Where Python runs | 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 | ## Why 3.11 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. ## Standard library only 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. Keeping it so Python removes old standard library modules after a deprecation of a few releases. None the build uses is on that path. When a new Python is released, run `rmp test configure` and `rmp test rmp` under it: those are the generator's and the command's own tests, and they need nothing installed. ## The packages that are not | 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](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#clang-tools)) | 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 lock 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: 1. **Two pins belong to apt.** PyYAML and Pygments are installed by apt (Pygments as a dependency of cppcheck), and pip cannot uninstall a Debian package, so the lock pins them to the exact versions the apt snapshot has. Move the snapshot and those two may move: read the new versions from the image (`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. 2. **Wheels only, for two architectures.** A release that has no wheel for aarch64, or that only ships a source archive, cannot be locked. `lock.py` refuses it; pin the newest release that has both. 3. **It is made inside the image.** The interpreter the lock is for is the image's, so `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. ### Updating Hypothesis, mutmut or pytest 1. In the image repository, change the version in `python/requirements-ci.in`. 2. Regenerate the lock inside the current image: ```shell 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' ``` 3. Read the diff of `python/requirements-ci.txt`: every package that moved is a change in what the tests run. 4. Build the image ([the build image](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#bump)), whose smoke check runs a Hypothesis property and a mutmut mutant before it publishes. 5. In the framework, the same versions in the `hypothesis`, `mutmut` and `pytest` keys of `thirdparty/FROZEN_VERSIONS.md`, and the new digest. 6. Run the properties and one mutation shard in the new image. A new Hypothesis can find a counterexample the old one never generated: that is a bug found, and it is fixed in the code. ## This site's Python 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. ## If the test tools stop installing 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/contributing/properties-fuzzing-mutation.html). ============================================================================== # Upgrading a dependency > A playbook for each dependency of the framework — where its version is held, what has to move with it, the patches to carry over, the checks that will go red and what is re-recorded afterwards. Source: 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. ## The rules of every upgrade - **One dependency per pull request.** Two at once cannot be told apart when a run goes red. - **The pin and every copy of it in the same commit.** `rmp test config` runs `tools/versions_check.sh`, which names a copy that was left behind. - **A gate that goes red is information.** It is answered by fixing the code, or by re-measuring a number the dependency really changed, with the reason written down. A floor is never lowered and a list that only shrinks never grows to make a bump pass (`CLAUDE.md`, "Never weaken a gate to get green"). - **The full matrix once, at the end.** A debug lane on the families the dependency touches while working ([CI](https://omardev29.github.io/rmp-docs/framework/contributing/ci.html#more)), the whole matrix before merging. - **The docs after.** A page of this site that names a version or a behaviour that moved is fixed in the same stretch of work, and `FRAMEWORK_REF` bumped. ## The vendored code ### raylib Where `thirdparty/raylib`, a committed copy of a release; `RAYLIB_VERSION` in `thirdparty/raylib/src/raylib.h` says which. The patches Every change is a row of `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. What holds the patches `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. What moves with it raylib-cpp, whose version follows raylib's; the raylib-iOS fork, which is its own copy of raylib and should be the same release, or a game can call a function iOS does not have; the vendored libraries inside raylib (GLFW, miniaudio, the software renderer), which come with it. Expect red The render hash (`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. Re-record The render hash with `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`. Licence raylib stays modified: `PATCHES.md` stays, rewritten for the new release, and `THIRD_PARTY_LICENSES.md` says the version. ### Clay Where `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. Why it is expensive Clay is before 1.0, its API moves between minor versions, and every file under `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. Expect red `tests/ui_layout_test.cpp` and the UI's other tests, `tests/property/ui_text_prop.cpp`, every e2e shot of a menu. When Only for a fix a game needs. The frozen copy has no deadline: it is C, in one file. ### cute_tiled, cute_aseprite, cJSON, rres 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. cute_tiled Patched and hardened: the six `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. cute_aseprite Unmodified, pinned by `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. cJSON Unmodified, `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. rres Unmodified, `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. ### raymob 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. ### raylib-iOS and ANGLE 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: ```shell git -C thirdparty/raylib-ios fetch origin git -C thirdparty/raylib-ios checkout COMMIT git add thirdparty/raylib-ios ``` A 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. ### doctest and RapidCheck 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. ## The Android set 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](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#android-bump), in both repositories. AGP 9 Do not move to AGP 9 without rewriting `raymob/app/build.gradle` first: Gradle 9 removes `gradle.buildFinished`, AGP 9 removes `applicationVariants`, and that file uses both. That rewrite is the largest single piece of Android work ahead. 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. ## Xcode and the macOS runner 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 - `windows_runner` is the runner label. The compiler that builds the `.exe` comes with it, pinned by nobody ([the warning](https://omardev29.github.io/rmp-docs/framework/maintaining/how-it-fits.html#families)). - `mesa` and `mesa_sha256`: the software OpenGL the Windows render test runs on. Test only; the release zip is checked not to carry it. - Pillow: one hash per Python version the runner can have. When the runner's Python moves to a version with no hash in the block, the install refuses and the icon step fails: add that version's `win_amd64` wheel hash, from PyPI, as a new `pillow_sha256_cp3XX_win_amd64` key. - `upx_sha256_win64`, with the UPX version. ## clang-format and clang-tidy 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: 1. The versions, in the image and in the framework. 2. `rmp fmt` over the whole tree, alone in its commit, so the review can skip it. 3. Every new clang-tidy warning fixed, or carried with a `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. ## The tools inside the image Emscripten `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 In the image (`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 and Ninja The image's `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 The image's `UPX_VERSION`, and `upx` with its three hashes. Every packed size line moves. LLVM and Mull Together or not at all: [the LLVM bump](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#llvm-bump). The coverage floors and every mutation floor are measured again. cppcheck From the apt snapshot. A newer one finds new things; the rule is zero findings in `src/rmp`, and a suppression says why on its line. actionlint and shellcheck actionlint by version and hash, shellcheck from apt. actionlint reads no shell without shellcheck: the image's smoke check proves both run. butler By version and hash; itch.io's publishing only. ## CI's own pins GitHub Actions Every `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. The Linux runner labels `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. The BSDs The `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. Playwright `package.json` and `package-lock.json`; Dependabot's npm pull requests. The browser it downloads is keyed to its version. ## Finding out what is newer 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. ============================================================================== # The dialogue and the text > How the Yarn Spinner port, its conformance suite, the translation tables and the tools that keep them are maintained: what came from where, what holds them to the original, how a new Yarn release is taken in, and how a language is added. Source: 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. ## The Yarn Spinner port `src/rmp/dialogue/` is a port to C++ of [Yarn Spinner](https://github.com/YarnSpinnerTool/YarnSpinner)'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`. ## Held to Yarn Spinner's own tests 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. ### Taking in a new Yarn release 1. Replace `tests/dialogue/yarn/` with the new release's test cases, and write its commit in `tests/dialogue/yarn/COMMIT`. 2. Run `rmp test unit`. Each failing case names its script and the step where the run went another way. 3. Read what changed in the C# between the two commits — the grammars, the compiler, the machine — and port it to the file of `src/rmp/dialogue/` that follows it, a test of the framework's own for anything the cases do not show. 4. Write the difference into `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. ## The other guards - **Properties.** `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. - **Fuzzing.** `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. - **Mutation.** The modules `dialogue`, `dialogue_ui` and `text` of `tests/mutation/floors/` are measured every week. - **The presenters** are laid out headless in `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`. ## The embedded build `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`](https://omardev29.github.io/rmp-docs/reference/configuration.html#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. ## The text and its tables `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: - **The plural rules.** The cardinal rules of the shipped languages are a small table in `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. - **The system language.** One branch per platform — the environment, CoreFoundation, `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. - **The codes a folder is searched for.** With no `[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`. ## Numbers 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](https://omardev29.github.io/rmp-docs/framework/performance.html#binary)). The property in `tests/property/text_prop.cpp` holds its digits to `to_chars`' on any double and any float. ============================================================================== # The yearly round > What forces a change to the framework even when nobody touches its code — the stores' yearly requirements, the runner images and Xcode versions GitHub retires, the BSD releases, the scheduled workflows that stop by themselves — and a checklist to go through once a year. Source: 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 forces a change | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#android), and [the Android bump](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#android-bump) | | The App Store's required Xcode and SDK | every year, in the spring | an upload is refused; the build still works | [Xcode](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#apple), and the [raylib-iOS fork](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#raylib-ios) 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](https://omardev29.github.io/rmp-docs/framework/maintaining/upgrading.html#windows) | | 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. ## The canary 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. Scheduled workflows stop GitHub disables a repository's scheduled workflows after 60 days with no activity in it. A framework left alone for a season stops running its canary, its nightly campaign and this site's daily drift check, and nothing says so. When you come back, re-enable them in the repository's Actions tab, and run the canary by hand first: it says what moved while nobody was looking. ## Once a year 1. **Read the last canary run** and its upstream report: what is newer than every pin, and what fails with it. 2. **The Android set**, if a game is to be published or updated on Google Play in the coming year: the target API the Play Console asks for, and the AGP, Gradle and NDK that support it. One pull request in each repository, [in order](https://omardev29.github.io/rmp-docs/framework/maintaining/build-image.html#android-bump). 3. **Xcode**, if the App Store's requirement moved: the new version on the pinned runner, or the runner that has it; the iOS simulator job; the fork, if it needs a change. 4. **The runner labels** GitHub has announced it will retire. 5. **Dependabot's pull requests** for actions and Playwright, in both repositories, merged once their runs are green. 6. **The BSD releases**, when a pinned one has lost its packages. 7. **The full matrix** once, after the bumps, on `main`: `gh workflow run ci.yml -f full=true`. A release tagged from it is a known-good point to come back to. 8. **Archive** the image digests pinned that year ([Ten years and more](https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html#archive)). Everything else waits for a reason. A dependency that is old and works is not a task. ## What each family costs | 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 | ============================================================================== # Ten years and more > What in the framework lasts and what rots, what a desktop Linux build needs decades from now, what to archive so it still builds with no network and no GitHub, and how to keep the whole thing going with one person and little time. Source: 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. ## What lasts The source C++20 for the framework, C for raylib and the libraries it vendors. Compilers keep accepting the standard a project asks for: `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. The build CMake with a recent minimum, 3.30, so the policies it relies on are new ones that later versions keep; no `FetchContent`, no package manager. And a generator that uses Python's standard library only ([Python](https://omardev29.github.io/rmp-docs/framework/maintaining/python.html)). The binaries already shipped A Linux release asks for an old glibc on purpose, through zig, and glibc keeps its old symbols; it opens X11 and OpenGL through the system's libraries. On a Wayland desktop it runs through XWayland, and `[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. The knowledge The reasons are written beside the code: `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. ## What rots | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/yearly.html) | | 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](https://omardev29.github.io/rmp-docs/framework/maintaining/long-term.html#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 | ## A desktop Linux build, decades from now Two ways to build, and both should keep working: ### With the archived image 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](https://omardev29.github.io/rmp-docs/framework/contributing/setup.html#a-checkout-for-the-image) describes, with `--network=none`: nothing in it needs the network. ### With the system's own tools What will exist then: the distribution's compiler, CMake and Python. The framework needs - a C and C++20 compiler, GCC or Clang; - CMake 3.30 or newer and Ninja; - Python 3.11 or newer, with nothing installed; - the X11 and OpenGL development headers — Wayland's too with `[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. Try it before you need it The image path is proved every day by CI. The system path is proved by nothing, and it is the one that will be left. Once a year, build and run `rmp test` in a container of the newest release of a mainstream distribution, with its own packages — the canary's job for the far future. A red there is the cheapest one you will ever fix. ## What to archive Keep these in a place you control, outside GitHub, and add to it every time a pin moves: 1. **Every image the framework has pinned**, with its index, so its digest still means the same bytes. `skopeo` copies a multi-architecture image to a file and back without changing a digest: ```shell 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" ``` The same for `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. 2. **Every repository, whole**: `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. 3. **The signing material**: the Android upload keystore and its passwords, Apple's certificates. They are not in any repository, on purpose; a lost Android upload key cannot be replaced by you. 4. **A released build of each game**, every target, as the release attached it: the proof of what worked, to compare against. 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. ## Without GitHub 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. ## With one person 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: - **Few, large maintenance sessions.** Once a year, the round; otherwise, a dependency only when a game needs it. Every bump between them is risk with no game asking for it. - **The nightly issues first.** The campaign opens one issue per new signature, with the command that replays it. One found and fixed is a crash a player never meets. - **Best effort where it is written down.** The BSDs are best effort; a red BSD job after a green fast lane is a platform-specific bug, fixed once, and never a reason to hold the rest. What a target ships, or dropping one, is Omar's decision and nobody else's. 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. ============================================================================== # Guidelines > How C++ is written in the framework and its examples: which rules decide, in what order, every rule with the tool that holds it and where, and what a game gets of them. Source: 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. ## Who decides 1. **The API is as simple as possible for whoever uses it.** This outranks every other rule. A main menu is three functions, and a rule that would make it longer loses, whatever else it buys. [The three-function menu](https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html) says why. 2. **The rules on these pages**, each with its reason: the [naming table](https://omardev29.github.io/rmp-docs/guidelines/naming.html), [the layout](https://omardev29.github.io/rmp-docs/guidelines/formatting.html), [`const`](https://omardev29.github.io/rmp-docs/guidelines/const.html), [no raw pointer, and nothing owned by hand](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html), [text in and out](https://omardev29.github.io/rmp-docs/guidelines/strings.html), [the C++ written where C would also compile](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html) and [macros](https://omardev29.github.io/rmp-docs/guidelines/macros.html) — and the framework's own decisions in [why it is built this way](https://omardev29.github.io/rmp-docs/framework/why/index.html), such as [one header per module](https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html) and [no exceptions](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html). 3. **[Google's C++ Style Guide](https://google.github.io/styleguide/cppguide.html)**, for everything the first two leave open. Where the framework has decided otherwise its decision holds, and [Google's guide, and where this one differs](https://omardev29.github.io/rmp-docs/guidelines/google.html) lists each place with its reason. ## Every rule, and what holds it 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`](https://omardev29.github.io/rmp-docs/reference/commands.html#lint) runs; a gate, which is a stage of [`rmp test`](https://omardev29.github.io/rmp-docs/reference/commands.html#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](https://omardev29.github.io/rmp-docs/guidelines/naming.html): 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](https://omardev29.github.io/rmp-docs/guidelines/formatting.html): 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`](https://omardev29.github.io/rmp-docs/guidelines/const.html): 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html): 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](https://omardev29.github.io/rmp-docs/guidelines/strings.html): 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++](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html): `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](https://omardev29.github.io/rmp-docs/guidelines/macros.html): 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](https://omardev29.github.io/rmp-docs/guidelines/google.html#agreement): 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](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) 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](https://omardev29.github.io/rmp-docs/framework/testing.html) has where and when each one runs. ## Shown, and checked like the code 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. ## What a game gets 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. ### Switching on the framework's clang-tidy 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. ```shell 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/*') ``` - The `.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. - The copy asks every macro defined to start with `RMP_`, the framework's prefix. A game whose own macros take the game's name instead, as [Macros](https://omardev29.github.io/rmp-docs/guidelines/macros.html#prefix) 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. ============================================================================== # Naming > One spelling for each kind of name in the framework, the reasons each spelling was chosen, each mistake as the tool that refuses it says it, and where each tool looks. Source: 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. ## The table | What | Spelling | Example | |---|---|---| | Types: class, struct, enum, alias, template parameter | `PascalCase` | [`rmp::ui::ButtonOptions`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#MAX_SPAWNED) | | Functions, methods, variables, parameters, public fields, namespaces | `snake_case` | [`rmp::ui::current_theme()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#current_theme), [`gravity_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME), [`RMP_WINDOW_WIDTH`](https://omardev29.github.io/rmp-docs/reference/macros.html#toml-RMP_WINDOW_WIDTH) | In code, all of it at once: ```cpp 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; }; ``` ## Who checks it, and where 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy). 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](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has every rule of these pages in one table. ## The reasons, and the mistakes ### One spelling per kind, and no prefixes 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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) sits next to `Texture2D` without looking foreign; the namespace is what says whose is whose. Compiles; `rmp test naming` refuses it: `R2` ```cpp constexpr int kMaxLives = 3; ``` Compiles; `rmp test naming` refuses it: `R1` ```cpp int g_score = 0; ``` Compiles; `rmp test naming` refuses it: `R8` ```cpp struct Counter { int count_ = 0; }; ``` Compiles; `rmp lint` refuses it: `readability-identifier-naming` ```cpp class player_state {}; ``` ```cpp 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`. ### An underscore never touches a dot `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)`. Compiles; `rmp test naming` refuses it: `R4` ```cpp class Wallet { public: [[nodiscard]] bool richer_than(const Wallet &other) const { return _coins > other._coins; } private: int _coins = 0; }; ``` ```cpp 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; }; ``` ### A leading underscore on a method means the framework calls it 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](https://omardev29.github.io/rmp-docs/framework/why/the-access-rule.html) is the other half of this. Compiles; `rmp lint` refuses it: `readability-identifier-naming` ```cpp class Cannon : public rmp::Object { public: void _ready() override { _fire(); } private: void _fire() {} }; ``` ```cpp class Cannon : public rmp::Object { public: void _ready() override { fire(); } private: void fire() {} }; ``` ### File state is grouped, and the dot is the mark 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. Compiles; `rmp lint` refuses it: `clang-diagnostic-shadow` ```cpp struct Pass { int number = 0; } pass; void draw(const int pass) { DrawText(TextFormat("pass %d", pass), 10, 10, 20, WHITE); } ``` ```cpp 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); } ``` ### A constant's name must not be somebody else's macro 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: Compiles; `rmp test naming` refuses it: `R6` ```cpp constexpr 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`, and clang-tidy refuses pi written out as a number: Compiles; `rmp lint` refuses it: `modernize-use-std-numbers` ```cpp float full_turn() { return 2.0f * 3.14159265f; } ``` ```cpp #include constexpr int MAX_ENEMIES = 10; float full_turn() { return 2.0f * std::numbers::pi_v; } ``` ### Macros start with `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](https://omardev29.github.io/rmp-docs/framework/why/macros.html) has the rest. Compiles; `rmp test naming` refuses it: `R5` ```cpp #define TILE_SIZE 16 ``` A number does not need a macro at all; a constant does it with a type: ```cpp constexpr int TILE_SIZE = 16; ``` ### A retired name is not an error, it is 0 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: Compiles; `rmp test naming` refuses it: `R7` ```cpp #if APP_SAVE_PORTABLE constexpr bool PORTABLE_SAVES = true; #else constexpr bool PORTABLE_SAVES = false; #endif ``` ```cpp #if RMP_SAVE_PORTABLE constexpr bool PORTABLE_SAVES = true; #else constexpr bool PORTABLE_SAVES = false; #endif ``` ### A name in a comment is spelled like the code So 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. ## What a compiler cannot see 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. ============================================================================== # Formatting > How the framework's code is laid out, what clang-format does to code that is laid out any other way, the reasons behind the settings that are not LLVM's, and who runs it. Source: 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. ## Who runs it, and where | 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, 90 columns, braces on the line 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. Compiles; `rmp test fmt` refuses it ```cpp struct Ship { int hp = 3; float speed = 120.0f; }; ``` ```cpp 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: Compiles; `rmp test fmt` refuses it ```cpp void announce(const int level, const int lives) { DrawText(TextFormat("Level %d, %d lives left", level, lives), 10, 10, 20, WHITE); } ``` ```cpp void announce(const int level, const int lives) { DrawText(TextFormat("Level %d, %d lives left", level, lives), 10, 10, 20, WHITE); } ``` ## No alignment 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. Compiles; `rmp test fmt` refuses it ```cpp struct Theme { Color background = { 18, 18, 22, 255 }; // behind everything Color surface_hover = { 60, 60, 76, 255 }; // a button under the pointer }; ``` ```cpp 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. ## A guard on one line 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. Compiles; `rmp test fmt` refuses it ```cpp void step(const bool ready) { if (!ready) return; jump(); } ``` ```cpp 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: Compiles; `rmp test fmt` refuses it ```cpp class Ship { public: [[nodiscard]] int hp() const { return _hp; } private: int _hp = 3; }; ``` ```cpp class Ship { public: [[nodiscard]] int hp() const { return _hp; } private: int _hp = 3; }; ``` ## Classes, namespaces and switches An access specifier stands at the column of its class, so `public:` and `private:` read as the headings they are: Compiles; `rmp test fmt` refuses it ```cpp class Coin { public: int value = 10; }; ``` ```cpp 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: Compiles; `rmp test fmt` refuses it ```cpp namespace layer { constexpr unsigned PLAYER = 1U << 0; } ``` ```cpp namespace layer { constexpr unsigned PLAYER = 1U << 0; } // namespace layer ``` A `case` is indented inside its `switch`: Compiles; `rmp test fmt` refuses it ```cpp float speed_for(const State state) { switch (state) { case State::IDLE: return 0.0f; case State::RUNNING: return 120.0f; } return 0.0f; } ``` ```cpp 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) says why), but every call into raylib's C has one. Compiles; `rmp test fmt` refuses it ```cpp void heal(int& hp, int amount); ``` ```cpp 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. Compiles; `rmp test fmt` refuses it ```cpp constexpr Color SKY = Color{135, 206, 235, 255}; ``` ```cpp constexpr Color SKY = { 135, 206, 235, 255 }; ``` ## What clang-format leaves alone 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. ```cpp #include // a name on the way in #include // the enemies on screen ``` It 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`. ## Files 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. ```cpp #pragma once namespace game { inline constexpr int START_LIVES = 3; } // namespace game ``` ============================================================================== # const > const on everything that does not change, constexpr for what is known when the code compiles, inline constexpr for a constant in a header, consteval and constinit where they fit — each with its reason, and the check that refuses the mistake. Source: https://omardev29.github.io/rmp-docs/guidelines/const.html What 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. ## A local that does not change Compiles; `rmp lint` refuses it: `misc-const-correctness` ```cpp int score_for(const int coins, const int seconds) { int bonus = seconds < 60 ? 100 : 0; return coins * 10 + bonus; } ``` ```cpp 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 &`: Compiles; `rmp lint` refuses it: `misc-const-correctness` ```cpp int total(const std::vector &scores) { int sum = 0; for (int score : scores) sum += score; return sum; } ``` ```cpp int total(const std::vector &scores) { int sum = 0; for (const int score : scores) sum += score; return sum; } ``` ## A method that changes nothing 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. Compiles; `rmp lint` refuses it: `readability-make-member-function-const` ```cpp class Wallet { public: [[nodiscard]] bool can_pay(const int price) { return _coins >= price; } private: int _coins = 0; }; ``` ```cpp class Wallet { public: [[nodiscard]] bool can_pay(const int price) const { return _coins >= price; } private: int _coins = 0; }; ``` ## A parameter's copy, in the definition 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: Compiles; `rmp lint` refuses it: `readability-avoid-const-params-in-decls` ```cpp void heal(const int amount); ``` ```cpp 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: Compiles; `rmp lint` refuses it: `performance-unnecessary-value-param` ```cpp int count_walls(Level level) { return static_cast(level.walls.size()); } ``` ```cpp int count_walls(const Level &level) { return static_cast(level.walls.size()); } ``` Text and sequences have a better answer than a `const` reference: [a `std::string_view`](https://omardev29.github.io/rmp-docs/guidelines/strings.html) and [a `std::span`](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html#spans). ## `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](https://omardev29.github.io/rmp-docs/guidelines/naming.html)). ```cpp 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. ## In a header: `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': Compiles; `rmp lint` refuses it: `custom-rmp-header-constant` ```cpp #pragma once namespace game { constexpr int START_LIVES = 3; } // namespace game ``` ```cpp #pragma once namespace game { inline constexpr int START_LIVES = 3; } // namespace game ``` It 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: ```cpp consteval unsigned layer_bit(const int index) { return 1U << index; } constexpr unsigned PLAYER = layer_bit(0); constexpr unsigned ENEMY = layer_bit(1); ``` Does not compile ```cpp 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. ```cpp constinit struct { unsigned seed = 1; int draws = 0; } generator; ``` A value only the running game can produce does not compile there: Does not compile ```cpp 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. ## Who checks what | 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy). [What checks what](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has every rule of these pages in one table. ============================================================================== # Pointers and RAII > No raw pointer anywhere — what to write instead, the few places one is allowed and why — and nothing owned by hand: every resource freed by the thing that holds it. Each mistake shown with what refuses it. Source: 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. ## Why no raw pointer 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](https://omardev29.github.io/rmp-docs/guidelines/google.html#pointers) 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 to write instead | What you mean | What you write | |---|---| | a small thing, copied | the value: a `Vector2`, a [`Shape`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Shape), an options struct | | a result that may not be there | `std::optional` | | an argument that may be left out | two overloads: [`load_map(name)`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_map) 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`](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html#spans) | | the caller's text, for the length of the call | [`std::string_view`](https://omardev29.github.io/rmp-docs/guidelines/strings.html) | | something that may be missing and is not yours, within the frame | [`rmp::Ref`](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html#ref) | | an object kept from one frame to the next | [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) | | something that is yours alone | a value, or a `std::unique_ptr` when it is polymorphic or large | ### A reference, for what is there Compiles; `rmp lint` refuses it: `custom-rmp-raw-pointer` ```cpp void reset(int *score) { *score = 0; } ``` ```cpp void reset(int &score) { score = 0; } ``` The framework's API reads the same way. A spawned object always has its scene, so [`scene()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#scene) is a `Scene &`; a control that edits a value takes it by reference, as [`slider`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#slider) does. ### `std::optional`, for an answer that may not be there Compiles; `rmp lint` refuses it: `custom-rmp-raw-pointer` ```cpp const Door *first_open(const std::vector &doors) { for (const Door &door : doors) { if (!door.locked) return &door; } return nullptr; } ``` ```cpp #include std::optional first_open(const std::vector &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: Compiles; `rmp lint` refuses it: `bugprone-unchecked-optional-access` ```cpp const std::optional door = first_open(); DrawCircleV(*door, 8, GREEN); ``` ```cpp if (const std::optional 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. Compiles; `rmp lint` refuses it: `custom-rmp-raw-pointer` ```cpp float 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(count) : 0; } ``` ```cpp #include float average(std::span values) { float sum = 0; for (const float value : values) sum += value; return values.empty() ? 0 : sum / static_cast(values.size()); } ``` It works the other way too: [`raycast_all`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#raycast_all) writes every hit along a ray into a span of yours, as many as it holds, and says how many it wrote. ```cpp std::array 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) is empty, or refers to something; it owns nothing, and asking it is an `if`. It is what [`get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get) hands back, empty when the object has no `B`, and what [`Handle::get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html#get) hands back, empty once the object is gone. Keep it within the frame; across frames, keep the handle. Compiles; `rmp lint` refuses it: `custom-rmp-raw-pointer` ```cpp rmp::behavior::Health *health_of(rmp::Object &object) { if (auto health = object.get()) return &*health; return nullptr; } ``` ```cpp auto &player = spawn({ .size = { 26, 26 } }); player.add({ .hp = 3 }); if (auto health = player.get()) 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>`, costs `` in every file with an object in it, and reads `health->get().hp`. ### In a public header 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. Compiles; `rmp test pointers` refuses it ```cpp #pragma once #include namespace rmp { class Object; Object *find(std::string_view name); } // namespace rmp ``` ```cpp #pragma once #include namespace rmp { class Object; template class Ref; Ref find(std::string_view name); } // namespace rmp ``` ## Where a pointer is allowed Nowhere but here, and each place for a reason: - **A type of a C library the framework speaks to** — Clay, cJSON, cute_tiled, cute_aseprite, rres. Their API is pointers, and that is not a choice the framework made. - **An `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`. - **Inside `rmp::Ref`**: its one member is the optional reference, so that nothing else has to hold one. - **C**: a `.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: ```cpp 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. ## RAII: the owner frees it 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. Compiles; `rmp lint` refuses it: `cppcoreguidelines-owning-memory` ```cpp int wave_hp() { auto *boss = new Enemy(); const int hp = boss->hp; delete boss; return hp; } ``` ```cpp 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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#change) makes the next one with `std::make_unique`, and the stack owns it from there. ```cpp #include 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 first_state() { return std::make_unique(); } ``` ### A raylib resource has an owner too 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: Compiles; `rmp test ownership` refuses it: `O2` ```cpp const Texture2D rabbit = LoadTexture("rabbit.png"); DrawTexture(rabbit, 100, 100, WHITE); UnloadTexture(rabbit); ``` ```cpp const rmp::Texture rabbit = rmp::assets::load_texture("rabbit.png"); DrawTexture(rabbit, 100, 100, WHITE); ``` [Ownership](https://omardev29.github.io/rmp-docs/framework/why/ownership.html) 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`. ### What you open closes itself 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. ```cpp rmp::ui::panel([&] { rmp::ui::text("Paused"); if (rmp::ui::button("Resume")) resume(); if (rmp::ui::button("Quit")) quit(); }); ``` ## Who checks what | 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy). [What checks what](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has every rule of these pages in one table. ============================================================================== # Strings > Text goes in as a std::string_view and comes out as a std::string, never as a C string; how it reaches raylib's C without reading past its end; and what builds text in a game the oldest compiler can still build. Source: 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()`. ## In: `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`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_texture), [`input::pressed`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pressed), [`audio::play`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#play), every label of [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#button) — and `tools/pointer_check.py` refuses a C string in any declaration a game can name: Compiles; `rmp test pointers` refuses it ```cpp #pragma once namespace rmp { void say(const char *line); } // namespace rmp ``` ```cpp #pragma once #include namespace rmp { void say(std::string_view line); } // namespace rmp ``` Outside the public headers a `const char *` is a raw pointer like any other, and clang-tidy refuses it as one ([Pointers and RAII](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html)). A `const std::string &` parameter passes every tool; it is a question for review. ## Out: a `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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#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()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#as_string) hands back is good while that value is alive and unchanged, and the one [`Sprite::playing()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html#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: Compiles; `rmp lint` refuses it: `bugprone-dangling-handle` ```cpp std::string_view title_for(const int level) { const std::string title = "Level " + std::to_string(level); return title; } ``` ```cpp std::string title_for(const int level) { return "Level " + std::to_string(level); } ``` ## To raylib: through a `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()`: Does not compile ```cpp void say(std::string_view line) { DrawText(line, 10, 10, 20, WHITE); } ``` The compiler refuses it, saying among other things: `const char` Compiles; `rmp lint` refuses it: `bugprone-suspicious-stringview-data-usage` ```cpp void 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. ```cpp 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: ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) takes a literal, a `std::string` and a view, and does not take a `const char *`, which might be null: Does not compile ```cpp rmp::Value settings = rmp::Value::object(); settings["folder"] = GetWorkingDirectory(); ``` The compiler refuses it, saying among other things: `const char` ```cpp rmp::Value settings = rmp::Value::object(); settings["folder"] = std::string(GetWorkingDirectory()); ``` ## Building text 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. ```cpp 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 ``: [the oldest compiler a game is built with](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#floor), 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`: Compiles; `rmp test style` refuses it: `S4` ```cpp #include #include 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. Compiles; `rmp test style` refuses it: `S5` ```cpp using namespace std::string_view_literals; constexpr auto TITLE = "Pong"sv; ``` ```cpp constexpr std::string_view TITLE = "Pong"; ``` ## Who checks what | 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 ``, 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy). [What checks what](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has every rule of these pages in one table. ============================================================================== # Modern C++ > The C++ the framework and its examples write where C would also compile — std::array, static_cast, enum class, nullptr, no varargs, fixed-width integers, ++i — and the C++20 the oldest compiler a game is built with can take. Source: 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](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has every rule of these pages in one table. ## std::array, not a C array 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: Compiles; `rmp lint` refuses it: `modernize-avoid-c-arrays` ```cpp int high_scores[5] = {}; ``` ```cpp #include std::array 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. ```cpp const std::array corners{ Vector2{ 0, 0 }, Vector2{ 40, 0 }, Vector2{ 20, 30 } }; DrawTriangleFan(corners.data(), static_cast(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: ```cpp #include constexpr std::array LANES{ 120.0f, 240.0f, 360.0f }; ``` Checked by `modernize-avoid-c-arrays`, in the framework and in the examples. ## static_cast, never a C cast 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: Compiles; `rmp lint` refuses it: `modernize-avoid-c-style-cast` ```cpp int whole_seconds(float seconds) { return (int)seconds; } ``` ```cpp int whole_seconds(const float seconds) { return static_cast(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: ```cpp #include 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: Compiles; `rmp test style` refuses it: `S1` ```cpp #if defined(PLATFORM_ANDROID) const int columns = (int)(GetScreenWidth() / 64.0f); #else const int columns = static_cast(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. ## enum class 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: Compiles; `rmp lint` refuses it: `cppcoreguidelines-use-enum-class` ```cpp enum Direction { LEFT, RIGHT }; ``` ```cpp 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. ## nullptr, never NULL or 0 `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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html)) leaves it few places to appear, most of them where a C function asks for a pointer: Compiles; `rmp lint` refuses it: `modernize-use-nullptr` ```cpp #include std::time_t now() { return std::time(0); } ``` ```cpp #include 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. ## No C variadic functions 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: Compiles; `rmp lint` refuses it: `modernize-avoid-variadic-functions` ```cpp #include 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; } ``` ```cpp #include int sum(std::span 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](https://omardev29.github.io/rmp-docs/framework/why/macros.html#report-once) has the details. Checked by `modernize-avoid-variadic-functions`, in the framework and in the examples. ## int, and a fixed width when the size matters 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, `` names it: Compiles; `rmp lint` refuses it: `google-runtime-int` ```cpp long total_score = 0; ``` ```cpp #include 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: Compiles; `rmp lint` refuses it: `google-runtime-float` ```cpp long 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 one-argument constructor is explicit 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: Compiles; `rmp lint` refuses it: `google-explicit-constructor` ```cpp struct Meters { Meters(float value) : value(value) {} float value; }; ``` ```cpp 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html), so a save is filled the way it reads. ```cpp 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](https://omardev29.github.io/rmp-docs/guidelines/google.html#implicit-conversions) lists them. Checked by `google-explicit-constructor`, in the framework and in the examples. ## A class that manages something says what its copies do 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: Compiles; `rmp lint` refuses it: `cppcoreguidelines-special-member-functions` ```cpp class Voice { public: explicit Voice(const Sound sound) : _sound(sound) {} ~Voice() { StopSound(_sound); } private: Sound _sound; }; ``` ```cpp 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. ## auto where the type is already on the line 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: Compiles; `rmp lint` refuses it: `modernize-use-auto` ```cpp const float width = static_cast(GetScreenWidth()); DrawLineV(Vector2{ 0, 0 }, Vector2{ width, 0 }, RED); ``` ```cpp const auto width = static_cast(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. ## using, not typedef An alias reads left to right like an assignment, and can be a template; a `typedef` can be neither: Compiles; `rmp lint` refuses it: `modernize-use-using` ```cpp typedef int Score; ``` ```cpp using Score = int; ``` Checked by `modernize-use-using`, in the framework and in the examples. ## std::numbers, not a typed-in π A constant typed in by hand is as precise as the hand that typed it. C++20 has them in ``, 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](https://omardev29.github.io/rmp-docs/guidelines/macros.html#names)): Compiles; `rmp lint` refuses it: `modernize-use-std-numbers` ```cpp constexpr float HALF_TURN = 3.14159265f; ``` ```cpp #include constexpr float HALF_TURN = std::numbers::pi_v; ``` 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. ## ++i 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: Compiles; `rmp test style` refuses it: `S6` ```cpp int lives = 3; lives--; DrawText(TextFormat("lives %i", lives), 10, 10, 20, RED); ``` ```cpp 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: ```cpp 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. ## No user-defined literals 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: Compiles; `rmp test style` refuses it: `S5` ```cpp #include using namespace std::string_view_literals; constexpr auto TITLE = "Pong"sv; ``` ```cpp #include 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. ## No using namespace 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: Compiles; `rmp lint` refuses it: `google-build-using-namespace` ```cpp #include using namespace std; vector scores; ``` ```cpp #include std::vector scores; ``` Checked by `google-build-using-namespace`, in the framework and in the examples. ## No default argument on a virtual function 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: Compiles; `rmp lint` refuses it: `google-default-arguments` ```cpp class Shape { public: virtual ~Shape() = default; virtual void grow(float by = 1.0f) = 0; }; ``` ```cpp 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. ## std::span and std::optional instead of a pointer 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`: Compiles; `rmp lint` refuses it: `custom-rmp-raw-pointer` ```cpp int total(const int *values, int count) { int sum = 0; for (int i = 0; i < count; ++i) sum += values[i]; return sum; } ``` ```cpp #include #include std::optional 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) has the rest: a reference that may be empty is an [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html), and an object kept across frames is an [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html). Checked by `custom-rmp-raw-pointer`, a query of the framework's own `.clang-tidy`, in the framework and in the examples. ## Designated initialisers, in declaration order 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: Does not compile ```cpp 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` ```cpp 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](https://omardev29.github.io/rmp-docs/framework/why/designated-initialisers.html) has why the fields are ordered the way they would be written. ## C++20, as the oldest compiler speaks it 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, ``, `constinit` — and not what arrived in GCC 11 and later: ``, ``, `std::bit_cast`, `using enum`, and what C++23 added. A use of one compiles on a laptop and fails on NetBSD, in CI: Compiles; `rmp test style` refuses it: `S4` ```cpp #include #include std::uint32_t bits_of(const float value) { return std::bit_cast(value); } ``` ```cpp #include #include 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. ============================================================================== # Macros > A macro only for what a function, a constant or a template cannot do — the call site, code generated at file scope, conditional compilation, a value from the .toml — always named RMP_, and the checks that hold both halves. Source: 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](https://omardev29.github.io/rmp-docs/framework/why/macros.html). ## A constant is constexpr 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: Compiles; `rmp lint` refuses it: `cppcoreguidelines-macro-usage` ```cpp #define RMP_LIVES 3 ``` ```cpp constexpr int LIVES = 3; ``` In a header, a constant at namespace scope is `inline constexpr`, one object for the whole program; [const](https://omardev29.github.io/rmp-docs/guidelines/const.html) has why. ## A function is a function 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: Compiles; `rmp lint` refuses it: `cppcoreguidelines-macro-usage` ```cpp #define RMP_SQUARE(x) ((x) * (x)) ``` ```cpp template constexpr T square(const T x) { return x * x; } static_assert(square(3) == 9); ``` ## When a macro is the right tool 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: ```cpp 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: ```cpp #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: ```cpp #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: ```cpp 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. ## Every macro starts with RMP_ 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: Compiles; `rmp test naming` refuses it: `R5` ```cpp #define NAME_OF(x) #x ``` ```cpp #define RMP_NAME_OF(x) #x ``` Checked 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy) writes its own prefix in the copy, which asks for `RMP_`. ## A name that no longer exists is 0 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: Compiles; `rmp test naming` refuses it: `R7` ```cpp #if !PRODUCTION_BUILD DrawFPS(10, 10); #endif ``` ```cpp #if !RMP_PRODUCTION_BUILD DrawFPS(10, 10); #endif ``` Checked 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. ## A constant is never named like a macro 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: Does not compile ```cpp 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html) 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. ## No header makes you write one 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](https://omardev29.github.io/rmp-docs/framework/why/macros.html#the-rule) has how. A game that wants Clay's macros can include Clay and use them. ## What checks it | 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy); `tools/naming_check.sh` stays in the framework. The rules are the same advice for its code, and [what checks what](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has the whole list. ============================================================================== # Google's guide, and where this one differs > Every place the framework's rules and Google's C++ Style Guide part ways or pull against each other, with the reason the framework's rule is what it is and what holds the code to it — and where the two agree. Source: https://omardev29.github.io/rmp-docs/guidelines/google.html [Google's C++ Style Guide](https://google.github.io/styleguide/cppguide.html) 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](https://omardev29.github.io/rmp-docs/framework/why/the-three-function-menu.html). More than one difference below comes from there. ## Where the framework's rule wins ### Naming 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](https://omardev29.github.io/rmp-docs/guidelines/naming.html) 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. ### #pragma once 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. ### Forward declarations between the framework's own headers 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](https://omardev29.github.io/rmp-docs/framework/why/one-header-per-module.html) has the numbers. A header from outside the framework — the standard library's, raylib's — is included, as Google says. ### Formatting 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](https://omardev29.github.io/rmp-docs/guidelines/formatting.html) has each setting. ### .cpp 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. ### const and constexpr, further than Google 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](https://omardev29.github.io/rmp-docs/guidelines/const.html) 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. ### No raw pointer, even where Google uses one 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html#allowed) 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`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html), and an object kept across frames is an [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html). 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) has the replacements. ## Deviations, recorded Each of these is a rule of Google's that the framework breaks on purpose, in a known place. ### Google does not allow ``. 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. ### -std=gnu++20 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. ### Two variadic functions The framework's rule is no C variadic function ([Modern C++](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#varargs)), 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. ### Statics that are not trivially destructible 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. ### Public data members Google makes a class's data members private, and keeps `struct` for passive data. [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) is a class whose [`position`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#position), [`velocity`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#velocity) and [`shape`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#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. ### Implicit conversions 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: - a `bool`, a number or a piece of text becomes an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html): `save["score"] = 3;`; - a `Value::Ref`, what `save["score"]` gives, reads as the `Value` it names; - an asset's handle — `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; - a lambda becomes an [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html), so it can be written straight into a behavior's options; - a number or a [`rmp::ui::Size`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#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. ### No TODO, with or without a name 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. ## Where the two read differently ### The top of a file 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. ### Long functions 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. ### shared_ptr inside a Callback Google says not to design for shared ownership without a very good reason. A [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html) keeps the lambda it was given in a `std::shared_ptr`, 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 ``. [Ownership](https://omardev29.github.io/rmp-docs/framework/why/ownership.html#callbacks) has why not `std::function`. ### Casts 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++](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#casts) has both. ### Conditional compilation 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. ### A macro in a header 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`](https://omardev29.github.io/rmp-docs/reference/macros.html#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](https://omardev29.github.io/rmp-docs/guidelines/macros.html) has the rule. ## Where they agree, and what checks it | Google's rule | Checked by | |---|---| | No exceptions: the framework throws none, and catches the standard library's where it can throw ([No exceptions](https://omardev29.github.io/rmp-docs/framework/why/no-exceptions.html)) | 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 ``'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](https://omardev29.github.io/rmp-docs/guidelines/enforcement.html) has each one's exact reach. ============================================================================== # What checks what > Every rule of the Guidelines and the tool that holds it — a check of clang-tidy, a gate of rmp test, clang-format or the compiler — with where it holds: the framework, its examples, a game; and every check the framework switches off, with the reason. Source: 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. ## The tools clang-tidy, which `rmp lint` runs The checks of the framework's `.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-tidy` The same file for the examples, narrowed: it switches off the `modernize` 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. What the tree still owes clang-tidy's warnings that the framework has not yet paid are listed in `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. The text gates, stages of `rmp test` What clang-tidy cannot see, because it parses one branch of every `#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` applies The layout of the code. The framework's CI fails on a file it would change; in a game, `rmp 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. The compiler Every target CMake builds from the framework's sources and a game's is compiled with `-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. ## Rule by rule "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](https://omardev29.github.io/rmp-docs/guidelines/naming.html): types, constants, functions and variables, private members, the eight hooks | `readability-identifier-naming` | yes | yes | no | | [A local never hides a name around it](https://omardev29.github.io/rmp-docs/guidelines/naming.html) | `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](https://omardev29.github.io/rmp-docs/guidelines/naming.html), in every branch | `tools/naming_check.sh` `R1` `R2` `R3` `R4` `R8` | yes | yes | no | | [Every macro starts with `RMP_`](https://omardev29.github.io/rmp-docs/guidelines/macros.html#prefix) | `readability-identifier-naming`; `tools/naming_check.sh` `R5` in every branch | yes | yes | no | | [No constant named like somebody else's macro](https://omardev29.github.io/rmp-docs/guidelines/macros.html#names) | `tools/naming_check.sh` `R6` | yes | yes | no | | [No retired name](https://omardev29.github.io/rmp-docs/guidelines/macros.html#retired) | `tools/naming_check.sh` `R7` | yes | yes | no | | [The layout](https://omardev29.github.io/rmp-docs/guidelines/formatting.html): 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](https://omardev29.github.io/rmp-docs/guidelines/const.html), 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](https://omardev29.github.io/rmp-docs/guidelines/const.html) | `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`](https://omardev29.github.io/rmp-docs/guidelines/const.html) | `custom-rmp-header-constant` | yes | yes, in their own headers | no | | [No raw pointer](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html), 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) | `tools/pointer_check.py`, against `tools/pointer_ratchet.txt` | yes: `include/rmp/` | no | no | | [Nothing owned by hand](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html): 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](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html) | `tools/ownership_check.sh` `O2` | yes: `include/rmp/` and `src/rmp/` | yes | no | | [A `std::optional` is checked before it is read](https://omardev29.github.io/rmp-docs/guidelines/pointers-and-raii.html#optional) | `bugprone-unchecked-optional-access` | yes | yes | no | | [A `std::string_view` never reaches a C function through `data()`](https://omardev29.github.io/rmp-docs/guidelines/strings.html) | `bugprone-suspicious-stringview-data-usage` | yes | yes | no | | [`std::array`, not a C array](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#arrays) | `modernize-avoid-c-arrays` | yes | yes | no | | [`static_cast`, never a C cast](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#casts) | `modernize-avoid-c-style-cast`; `tools/style_check.sh` `S1` in every branch | yes | yes | no | | [`enum class`](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#enum-class) | `cppcoreguidelines-use-enum-class` | yes | yes | no | | [`nullptr`, never `NULL` or `0`](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#nullptr) | `modernize-use-nullptr`; `tools/style_check.sh` `S2` in every branch | yes | yes | no | | [No C variadic function](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#varargs) | `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](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#integers) | `google-runtime-int` | yes | yes | no | | [No `long double`](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#integers) | `google-runtime-float` | yes | yes | no | | [A one-argument constructor is `explicit`](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#explicit) | `google-explicit-constructor` | yes, but for the API's deliberate conversions | yes | no | | [A class that manages something says what its copies do](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#special-members) | `cppcoreguidelines-special-member-functions` | yes | yes | no | | [`auto` where a cast already names the type](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#auto) | `modernize-use-auto` | yes | no: the examples switch `modernize` off | no | | [`using`, not `typedef`](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#using) | `modernize-use-using` | yes | yes | no | | [`std::numbers`, not a typed-in constant](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#numbers) | `modernize-use-std-numbers` | yes | yes | no | | [No `using namespace`](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#using-namespace) | `google-build-using-namespace` | yes | yes | no | | [No unnamed namespace in a header](https://omardev29.github.io/rmp-docs/guidelines/google.html#agreement) | `google-build-namespaces` | yes | yes | no | | [No using-declaration at global scope in a header](https://omardev29.github.io/rmp-docs/guidelines/google.html#agreement) | `google-global-names-in-headers` | yes | yes | no | | [No overloaded unary `&`](https://omardev29.github.io/rmp-docs/guidelines/google.html#agreement) | `google-runtime-operator` | yes | yes | no | | [`std::make_pair` deduces its types](https://omardev29.github.io/rmp-docs/guidelines/google.html#agreement) | `google-build-explicit-make-pair` | yes | yes | no | | [No default argument on a virtual function](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#virtual-defaults) | `google-default-arguments` | yes | yes | no | | [`++i` where the old value is not read](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#increment) | `tools/style_check.sh` `S6` | yes | yes | no | | [No user-defined literal](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#literals) | `tools/style_check.sh` `S5` | yes | yes | no | | [Nothing newer than the oldest compiler a game is built with](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#floor) | `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`](https://omardev29.github.io/rmp-docs/guidelines/google.html#todo) | `tools/style_check.sh` `S3` | yes | yes | no | | [Designated initialisers in declaration order](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#designated) | `-Werror=reorder-init-list` under Clang; GCC and MSVC refuse them anyway | yes | yes | yes | | [A macro only for what a function cannot do](https://omardev29.github.io/rmp-docs/guidelines/macros.html) | `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 | ## Written down, not checked 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](https://omardev29.github.io/rmp-docs/guidelines/const.html)); - a `std::array` given a size larger than its list, whose rest is filled with zeros ([Modern C++](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#arrays)); - an unsigned type only for bits, and `auto` beyond a cast ([Modern C++](https://omardev29.github.io/rmp-docs/guidelines/modern-cpp.html#integers)); - `#pragma once` at the top of a header, and `` in `src/rmp/app/app.cpp` and `src/rmp/save/save.cpp` only ([Google's guide](https://omardev29.github.io/rmp-docs/guidelines/google.html#deviations)); - everything Google's guide says that no check of these pages states. ## Switched off, and why 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](https://omardev29.github.io/rmp-docs/guidelines/google.html#public-data)). | | `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](https://omardev29.github.io/rmp-docs/guidelines/macros.html#when)). | | `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](https://omardev29.github.io/rmp-docs/guidelines/google.html#pragma-once)). | | `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](https://omardev29.github.io/rmp-docs/guidelines/google.html#formatting)). | | `readability-implicit-bool-conversion` | raylib returns `int` for booleans. | | `readability-function-cognitive-complexity` | A render switch is one function on purpose ([Google's guide](https://omardev29.github.io/rmp-docs/guidelines/google.html#function-length)). | | `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`. ## What the framework still owes 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. ## In a game 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](https://omardev29.github.io/rmp-docs/guidelines/index.html#switching-on-clang-tidy) for its own code. [What a game gets](https://omardev29.github.io/rmp-docs/guidelines/index.html#in-a-game) says the same from the game's side. ============================================================================== # Reference > Every public name in the framework, read from its headers, and every .toml key and rmp command, read from the tools that handle them, at the commit this site documents. Source: https://omardev29.github.io/rmp-docs/reference/index.html Every page in this section is generated from the framework, at the commit the footer names. The names come from its headers: a signature here is the header's signature, a sentence is the header's comment, and every entry links to the line that declares it. Two pages come from the framework's tools instead, run rather than parsed, so what they say is what the tool does: the configuration keys from `tools/configure.py --print-schema`, explained by the comments of the framework's own `.toml`, and the commands from `rmp help`. The values the `.toml` turns into macros, on the macros page, come from `configure.py` the same way. The macros the build passes to the compiler have no header to be read from: their entries are written for this site, and checked against the build files that set them. - [Namespaces](https://omardev29.github.io/rmp-docs/reference/namespaces/index.html) — `rmp` and its modules: `rmp::ui`, `rmp::input`, `rmp::assets` and the rest, each with its functions, its types and its options. - [Classes](https://omardev29.github.io/rmp-docs/reference/classes/index.html) — the types with pages of their own: [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html), [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html), [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) and the others. - [Behaviors](https://omardev29.github.io/rmp-docs/reference/behaviors/index.html) — the catalogue in `rmp::behavior`. - [Macros](https://omardev29.github.io/rmp-docs/reference/macros.html) — `RMP_GAME` and the rest: the ones the headers define, the ones the `.toml` generates and the ones the build passes. - [Configuration](https://omardev29.github.io/rmp-docs/reference/configuration.html) — every key of `raylib_multiplatform.toml`, with its default. - [Commands](https://omardev29.github.io/rmp-docs/reference/commands.html) — every `rmp` command. Two conventions hold everywhere. A name starting with `_` is a hook: you override it, the framework calls it. A name in `detail` — `rmp::detail`, or a member called `detail_`something — belongs to the framework and its tests, and is not shown. ============================================================================== # Commands > Every rmp command, read from the framework's own tool. Source: https://omardev29.github.io/rmp-docs/reference/commands.html Every `rmp` command, as `rmp help` describes it at the commit this site documents. `rmp help ` prints the same page in a terminal. ## For a game ### `rmp run [sudo|windows]` Build the game in debug, then play it; only what changed is compiled again. On a Linux console with no desktop it builds for DRM/KMS (build/debug-drm/) and first checks that the game can open the screen and read the keyboard, saying what to do when it cannot; sudo builds as you and starts only the game as root. RMP_DRM=1 or 0 overrides what rmp decides. | `rmp run` | build, then start the game | |---|---| | `rmp run sudo` | on a console: the game as root, the build as you | | `rmp run windows` | on Linux: the Windows .exe, built and started under Wine | | `rmp clean` | if a build goes strange, start from nothing | ### `rmp build [release|windows]` Compile the game without running it: debug into build/debug/ by default, or release into build/release/ (optimised, reading ./resources/: the one next to the executable when there is one, as in a shipped package, and the working directory's otherwise — so run it from the project folder). Each has its folder: switching between them rebuilds nothing. On a Linux console with no desktop, build/debug-drm/ and build/release-drm/, for DRM/KMS. On Linux, `windows` builds the release .exe for Windows: with MinGW-w64 into build/windows/, or with `windows clang-cl` into build/windows-clang-cl/, against Microsoft's own C runtime, which xwin downloads into ~/.xwin (XWIN_DIR) the first time, once you accept Microsoft's licence. | `rmp build` | writes build/debug/ | |---|---| | `rmp build release` | writes build/release/, as CI ships it | | `rmp build windows` | on Linux: build/windows/.exe (MinGW-w64) | | `rmp build windows clang-cl` | the same with clang-cl and lld-link | ### `rmp web` Build build/web/.html with Emscripten; activate the emsdk first, so that EMSDK is set. | `rmp web` | writes build/web/.html | |---|---| | `python3 -m http.server -d build/web` | then open localhost:8000/.html | ### `rmp package [desktop|windows|web|android]` Make, on this machine, the archive a release job would upload, into build/package/: the release binary, the resource pack and LICENSES.txt, packed with UPX where `[upx] asks`, zipped. desktop is this machine's own target; windows is the .exe made on Linux (add clang-cl for clang-cl); web is the page, zipped; android is the release .aab and .apk, signed with your upload key: set ANDROID_KEYSTORE_FILE, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS and ANDROID_KEY_PASSWORD. | `rmp package` | build/package/-.zip | |---|---| | `rmp package windows` | build/package/-windows-x64.zip, made on Linux | | `rmp package web` | build/package/-web.zip, ready to upload | | `rmp package android` | build/package/-android.aab and .apk, signed | ### `rmp android` Build a debug APK with Gradle; it needs the Android SDK and NDK. | `rmp android` | prints the APK it wrote | |---|---| | `adb install -r ` | puts it on a connected phone | ### `rmp test [stage]` Check the project. With no stage, every one of them; name a stage to run only that one. | `rmp test` | everything | |---|---| | `rmp test smoke` | build, boot and see it draw | | `rmp test config` | the .toml, the pinned versions, the licences | Its stages, in the order `rmp test` runs them: | Stage | Checks | In | In `rmp test` | |---|---|---|---| | `fmt` | every file is clang-format clean | framework | yes | | `config` | the .toml, the pinned versions and every licence | game and framework | yes | | `repo` | the index tracks sources, not build output | framework | yes | | `seam` | nothing in src/rmp reads the clock, input or `rand()` itself | framework | yes | | `workflows` | every reusable workflow gets what it asks for | framework | yes | | `portable` | the scripts run on macOS's bash 3.2 and the BSDs | framework | yes | | `shell` | no `A && B \|\| C` in the shell | framework | yes | | `naming` | the names follow the convention, every #if branch | framework | yes | | `style` | the style rules clang-tidy cannot see, every #if branch | framework | yes | | `ownership` | nothing owned by hand: new/delete, raylib's Load*/Unload* | framework | yes | | `pointers` | no raw pointer and no C string a game can name | framework | yes | | `cppcheck` | cppcheck over src/rmp: no finding, each suppression says why | framework | yes | | `headers` | every public header stands alone | framework | yes | | `cost` | what each public header costs to include | framework | yes | | `gates` | each tools/*_check.sh seen red on a planted mistake | framework | yes | | `text` | every language `[lang] ships` has every text | game and framework | yes | | `yarn` | every Yarn script compiles, against what the C++ registers | game and framework | yes | | `text-tool` | rmp text's and rmp yarn's tools, each mistake seen | framework | yes | | `configure` | tools/configure.py, every rejection | framework | yes | | `rmp` | this command itself | framework | yes | | `api` | the API-change gate: what a pull request changes of the API | framework | yes | | `binaries` | the readers that judge a shipped .exe and Mac binary | framework | yes | | `size` | every shipped binary has a size budget, and its reader works | framework | yes | | `unit` | the unit tests in two orders, and tests/game/ | framework | yes | | `unit` | your tests in tests/game/, with no window | game | yes | | `layout` | the UI layout at four resolutions, headless | framework | yes | | `property` | properties: RapidCheck on the C++, Hypothesis on the Python | framework | yes | | `ui-render` | the UI on a real GPU: a hidden window, read back | framework | yes | | `render` | draw a frame in software and check it | game and framework | yes | | `smoke` | build the game, boot it, see it draw | game and framework | yes | | `examples` | boot every example, play the platformer and the e2e scripts | framework | only by name | | `sanitize` | the unit and layout tests again, under gcc's ASan and UBSan | framework | only by name | | `fuzz` | every fuzz target built, and every committed input replayed | framework | only by name | | `mutation` | Mull and mutmut against every floor (build image, hours) | framework | only by name | | `coverage` | what the tests run of src/rmp, against its floors | framework | only by name | | `render-update` | record the frame as the new golden hash | framework | only by name | | `e2e-update` | record every e2e shot as its golden (inside the build image) | framework | only by name | ### `rmp fmt [check]` Format your C and C++ with clang-format — the version pinned in thirdparty/FROZEN_VERSIONS.md. | `rmp fmt` | rewrite what needs it | |---|---| | `rmp fmt check` | only report what it would change | ### `rmp pack` Bundle resources/ into resources/resources.rres, encrypted, the way a release ships it. | `rmp pack` | the game reads the pack from now on | |---|---| | `rmp unpack` | back to the loose files while you add art | ### `rmp text scan|check` scan reads src/ and include/ for every literal the framework translates — the first argument of `rmp::ui`'s text functions and of `rmp::Text`, the .text, .placeholder and .items of a kept widget — the line ids of resources/**/*.yarn and what a debug build saw that the tables lack (build/debug/lang_seen.tsv), and adds a row to `[lang] file` for each that is not there. It never deletes a translation: a row nothing uses any more gets an x in its unused column. check fails on a text a language of `[lang] languages` lacks, a placeholder a translation lost or added, and a plural with the wrong number of forms; `rmp test` runs it. | `rmp text scan` | add the new texts to resources/lang.tsv | |---|---| | `rmp text check` | what a translation lacks or got wrong | ### `rmp yarn check|ysls` check compiles every resources/**/*.yarn with the framework's own compiler (rmp_yarnc --check), each error as file:line:column, with the types of the functions the C++ registers (on_function("name", [&](std::string s) -> bool {...})) told to it; a function a script calls that nothing registers is an error, a command nothing handles a warning. Name files to check only those. `rmp test` runs it. ysls writes rmp.ysls.json beside resources/: the commands and functions the C++ registers, typed and with the comment above each, which the Yarn Spinner extension for VS Code reads to complete and check them. | `rmp yarn check` | every script, against the game's C++ | |---|---| | `rmp yarn check resources/intro.yarn` | one script | | `rmp yarn ysls` | VS Code learns the C++ commands | ### `rmp unpack` Delete resources/resources.rres, so that the game reads the loose files in resources/ again. | `rmp unpack` | loose files again | |---|---| | `rmp pack` | bundle them again | ### `rmp clean` Delete build/ — every build in it: debug, release, web and the rest — and every file generated from raylib_multiplatform.toml; the next build makes them again. | `rmp clean` | everything, gone | |---|---| | `rmp run` | rebuild from nothing, and play | ### `rmp push [force]` Run git push — refused while a CI run is in flight, because the push would cancel it; with `[ci] on_push` = false a push starts no run, and nothing is checked. The first push of a branch sets its upstream on origin. | `rmp push` | push, or say which run it would kill | |---|---| | `rmp push force` | push anyway, and cancel the run | ### `rmp deploy VERSION` Release a version: check it the way CI will, tag it, push the tag. CI builds every target and attaches them to the release. | `rmp deploy 1.2.0` | tags v1.2.0 (the v is added) | |---|---| | `rmp deploy 1.2.0-rc1` | a pre-release, marked as one | | `rmp push` | first, if your last commit is not on GitHub yet | ### `rmp new DIR` Make a new game in DIR: a copy of what a game needs from this framework, named after the folder, ready to build and to ship. | `rmp new my_game` | makes my_game/, here | |---|---| | `rmp new ~/games/space_rocks` | anywhere; the name is the folder's | | `rmp new --list` | what a new game gets, without making one | ### `rmp install [force]` Put this framework's rmp on your PATH: a link in ~/.local/bin, and a line in your shell's startup file only when that folder is not on PATH yet. On Windows, a shim in %LOCALAPPDATA%\Programs\rmp and that folder on your user PATH. Running it again changes nothing; force replaces another rmp that is in the way. The installer runs it for you. | `rmp install` | link it, or say it already is | |---|---| | `rmp install force` | replace a different rmp that is in the way | | `rmp help` | then, in a new terminal | ### `rmp update` Update the framework that this rmp comes from: fetch origin and move main forward to it. A clone with changes of its own, on another branch or with commits origin does not have is refused, never merged. A game is not touched: it keeps the framework it was made with. | `rmp update` | prints the commit before and after | |---|---| | `rmp new my_game` | a new game gets the updated framework | ### `rmp help [command]` Show the commands, or one command in detail. | `rmp help` | every command | |---|---| | `rmp help deploy` | one of them | | `rmp help --json` | every command and test stage, for a tool to read | ## In the framework's own repository ### `rmp lint [fix]` Run clang-tidy over src/, tests/ and examples/; a warning tools/lint_debt.txt does not owe fails. | `rmp lint` | report | |---|---| | `rmp lint fix` | apply what clang-tidy is sure of, then format | ### `rmp example [name]` Build and run one example from examples/, by name or by path. | `rmp example` | list them | |---|---| | `rmp example 01_pong` | a bare name, when it is unique | | `rmp example games/01_pong` | or the path under examples/ | ============================================================================== # Configuration > Every key of the .toml, read from the framework's own tool. Source: https://omardev29.github.io/rmp-docs/reference/configuration.html Every key of `raylib_multiplatform.toml`: its default, what it takes, and what it is for. Read from `tools/configure.py --print-schema` at the commit this site documents; the explanations are the comments of the framework's own .toml. A key left out takes its default. A value `configure.py` refuses stops the build before anything is compiled, and the message names the line. ## `[project]` ### `name` name = "ray_test" string Binary name, CMake target, Xcode scheme, artifact names. Letters, digits, `_` and `-` only — no spaces, because it becomes a filename on five OSes. ## `[window]` ### `title` title = "Raylib is Multiplatform!" string title The title bar on desktop, and the app's name under its icon on ```cpp Android and iOS. ``` width The window's size when it opens on desktop, and the DESIGN height resolution: `rmp::ui` lays out at this size and scales to the real ```cpp one, and the camera starts centred on it. ``` ### `width` width = 800 int title The title bar on desktop, and the app's name under its icon on ```cpp Android and iOS. ``` width The window's size when it opens on desktop, and the DESIGN height resolution: `rmp::ui` lays out at this size and scales to the real ```cpp one, and the camera starts centred on it. ``` ### `height` height = 450 int title The title bar on desktop, and the app's name under its icon on ```cpp Android and iOS. ``` width The window's size when it opens on desktop, and the DESIGN height resolution: `rmp::ui` lays out at this size and scales to the real ```cpp one, and the camera starts centred on it. ``` ### `orientation` orientation = "landscape" string one of `"landscape"`, `"portrait"`, `"unspecified"` "landscape" | "portrait" | "unspecified" — applied to Android and iOS at once: the Android manifest's screenOrientation and iOS's supported orientations. Nothing else reads it; on desktop the window's shape is width x height. ### `vsync` vsync = true bool Wait for the screen's refresh before showing each frame: no tearing, and no frames drawn that nobody sees. Without it a desktop game runs as fast as the GPU allows. The web paces the frame itself, so there it changes nothing. ### `fps` fps = 0 int A cap in frames per second; 0 is no cap. With vsync on, the screen already paces the game and this is rarely needed. Ignored on the web and on iOS, where the platform paces the frame. On DRM (no desktop) it also picks the display mode: 144 asks for a 144 Hz mode. 1/fps may not be longer than `[app] max_delta`, or the game would run in slow motion. ### `stretch` stretch = "none" string one of `"expand"`, `"letterbox"`, `"none"` How the world fits a window that is not width x height — a desktop window dragged bigger, a phone of another shape, a TV: ```text "none" the world at 1:1: a bigger window shows more of it and a smaller one less. Nothing is scaled. "letterbox" the design scaled to fit and centred, the rest of the window bars of the clear colour. Every player sees the same part of the world, and rmp::ui keeps the interface inside it. "expand" scaled to fit 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 screen, at the sides on a 21:9 one. For a level that scrolls anyway. ``` A scene can change it at any moment with `rmp::app::set_stretch()`. A .toml without this line gets "none". ### `pause_unfocused` pause_unfocused = false bool Pause the game while its window is out of focus: the scenes stop, the clock stands still (no giant step on the way back), music and sounds pause, and the last picture stays on screen. Off is what most games do: they keep running. A minimized desktop window never draws whatever this says — it keeps moving, sleeps between frames and draws nothing. ## `[app]` ### `max_delta` max_delta = 0.05 float The longest step the game logic is ever handed, in seconds. `GetFrameTime()` returns real elapsed time and real elapsed time has no ceiling: drag the window, stop at a breakpoint, let the disk stall, and it comes back half a second. A bullet at 900 units/s then moves 450 units in one step — through the wall and out the other side, because at no point did it overlap. Clamping turns that into an instant of slow motion, which is the trade every game wants: nobody minds a hitch, everybody minds falling out of the world. It is half of the answer to tunnelling. The other half is the swept test in the collision pass, which catches a fast object against a thin one even at a perfectly normal frame rate. 0.05 is a twentieth of a second. Sensible values are between 1/60 (0.0167) and 1/10 (0.1). 0 switches the clamp off and hands the real number through. ## `[targets]` ### `enabled` enabled = ["all"] list a list of `all`, `android`, `apple`, `bsd`, `desktop`, `drm`, `freebsd-arm64`, `freebsd-x64`, `ios`, `linux`, `linux-arm64-glibc`, `linux-arm64-glibc-drm` and 13 more Which platforms to build. Groups expand and deduplicate; there is no precedence to reason about because there are no conflicts. ```text groups : all | desktop | mobile | linux | windows | apple | bsd | web | android | drm exact : linux-x64-glibc linux-arm64-glibc linux-riscv64-glibc linux-x64-musl linux-x64-glibc-drm linux-arm64-glibc-drm windows-x64 windows-arm64 macos ios web android freebsd-x64 freebsd-arm64 openbsd-x64 openbsd-arm64 netbsd-x64 ``` A target name is ---, and a segment is only there when it can differ: windows-x64 stops early because Windows has one C library, macos stops at the OS because it is universal. No libc suffix on Linux would have meant "you have to know it is glibc", which is knowledge the name should carry. linux-x64-glibc-drm and linux-arm64-glibc-drm are DRM/KMS: the game draws straight to the screen with no X11 and no Wayland, from a bare TTY. A Raspberry Pi, an arcade cabinet, a kiosk, or just developing from a console. Both segments before `drm` can differ and are spelled out for that reason — DRM is a kernel interface and exists on every architecture, and a machine with no desktop is far likelier to be a Pi than an x86 box, hence arm64; and the binary links libdrm, gbm and EGL directly instead of dlopening them, so a musl one would be a separate target. Both are glibc. The x64 one builds and RUNS in CI on a vkms virtual display; the arm64 one is built and checked, because what it exists for is a Pi's own vc4/v3d pipeline and a virtual display would not be answering that question. Neither honours `[linux] glibc`: they link the distribution's libdrm, gbm and EGL directly, so their floor is the build machine's. The jobs print it. To leave them out: disabled = ["drm"]. ### `disabled` disabled = [] list a list of `all`, `android`, `apple`, `bsd`, `desktop`, `drm`, `freebsd-arm64`, `freebsd-x64`, `ios`, `linux`, `linux-arm64-glibc`, `linux-arm64-glibc-drm` and 13 more Subtracted from whatever `enabled` expanded to. Use it to keep a group and drop one member: enabled = ["all"], disabled = ["ios"]. ## `[android]` ### `application_id` application_id = "com.example.raytest" string IRREVERSIBLE ON GOOGLE PLAY. Once an app is published under this id you can never change it — you would have to ship a new listing and lose your installs. Get it right before your first upload. CI refuses to build a tag while this still says com.example.*. ### `min_sdk` min_sdk = 24 int The oldest Android the app installs on, as an API level: 24 is Android 7.0. 21 to 36. ### `gl_version` gl_version = "ES20" string one of `"ES20"`, `"ES30"` ES20 | ES30. What raylib and your game are compiled for on Android (GRAPHICS_API_OPENGL_ES2 or _ES3), and the OpenGL ES version the manifest requires: a device without it is not offered your app on the Play Store. ES20 reaches every device, and is what a game made with `rmp new` starts with. ES30 is for a game that needs what raylib's ES 3.0 path adds. (The framework's own .toml has ES30, so that its CI compiles the ES 3.0 path.) ### `category` category = "game" string one of `"accessibility"`, `"audio"`, `"game"`, `"image"`, `"maps"`, `"news"`, `"productivity"`, `"social"`, `"video"` How the Play Store files your app (android:appCategory): ```text game | audio | video | image | social | news | maps | productivity | accessibility ``` This is NOT what puts the icon in the app drawer — that part is fixed and not yours to set, because an app without it installs and then appears nowhere. ### `gradle_offline` gradle_offline = true bool Where CI's Android job gets Gradle and the libraries the app builds with. true: from the build image, which carries them, and Gradle runs with --offline — the job downloads nothing, and a library the image lacks fails the build at once, by name. false: Gradle downloads what the image lacks, and the job says so in a warning; for a game that adds a Gradle dependency of its own. Your machine is not affected: `rmp android` is never offline. ## `[android.display]` ### `keep_on` keep_on = true bool never sleep while playing ### `immersive` immersive = true bool hide the system bars ### `into_cutout` into_cutout = true bool draw behind the notch ## `[android.permissions]` ### `internet` internet = false bool What the app asks the system for. Every one of these is visible on your Play listing, so ask for nothing you do not use. android.permission.INTERNET — forced on when AdMob is enabled ### `vibration` vibration = false bool What the app asks the system for. Every one of these is visible on your Play listing, so ask for nothing you do not use. android.permission.VIBRATE — needed by raymob's `Vibrate()` ## `[android.features]` ### `gyroscope` gyroscope = false bool Hardware. true = the Play Store hides your app from devices that lack it. false still declares the sensor as optional, which is what you want unless the game is unplayable without it. ### `accelerometer` accelerometer = false bool Hardware. true = the Play Store hides your app from devices that lack it. false still declares the sensor as optional, which is what you want unless the game is unplayable without it. ## `[android.admob]` ### `enabled` enabled = false bool Ads, and off unless you turn them on: a game made with `rmp new` starts with false. (The framework's own .toml has true, so that its CI builds the ads path.) true brings, on Android: - the Google Mobile Ads SDK in the APK, and `MobileAds.initialize()` at startup - the AD_ID permission, and INTERNET with it - an advertising-id declaration you owe Play's Data safety form false builds none of that, and your code does not change: the `rmp::ads` calls (rmp/ads.h) stay compilable and do nothing, exactly as they do off Android. It also turns itself off when "android" is not in [targets], however you removed it: by name, or by leaving out a group like "mobile". ### `app_id` app_id = "ca-app-pub-3940256099942544~3347511713" string Google's official TEST ids. Replace with your own before publishing. Clicking real ads from your own build is the fastest way to get an AdMob account suspended. ### `interstitial_id` interstitial_id = "ca-app-pub-3940256099942544/1033173712" string Google's official TEST ids. Replace with your own before publishing. Clicking real ads from your own build is the fastest way to get an AdMob account suspended. ### `rewarded_id` rewarded_id = "ca-app-pub-3940256099942544/5224354917" string Google's official TEST ids. Replace with your own before publishing. Clicking real ads from your own build is the fastest way to get an AdMob account suspended. ## `[ios]` ### `bundle_id` bundle_id = "com.example.raytest" string Same warning as Android: this is your App Store identity. ### `deployment_target` deployment_target = "15.6" string The oldest iOS the app runs on: 13.0 at the least, because `rmp::save` uses std::filesystem and Apple's C++ library has it from iOS 13. ### `settings` settings = {} table Raw Xcode build settings, copied verbatim into the generated XcodeGen spec. For a device build you will need something like: ```text DEVELOPMENT_TEAM = "ABCDE12345" CODE_SIGN_STYLE = "Automatic" ``` ## `[icon]` ### `source` source = "branding/icon.png" string One square PNG, 1024x1024 recommended. The app icon on Android, iOS and Windows comes out of this one file: every Android density, the round variant, the adaptive foreground, the Play Store asset, the iOS AppIcon, and the multi-resolution .ico that gets embedded into the Windows .exe. The other targets ship a bare executable (macOS, Linux, the BSDs) or a page (web), with no icon of their own to make from it. Deliberately NOT in resources/: everything in there is packed into resources.rres and shipped with the game, and your launcher icon is a build input, not a game asset. ### `adaptive_background` adaptive_background = "#3DDC84" string Behind the adaptive icon on Android 8+. Hex, or "" to use the source image as its own background. ## `[raylib]` ### `disabled_modules` disabled_modules = [] list a list of `raudio`, `rmodels` Modules you do not use, to shrink the binary. rcore and rlgl are mandatory and are not listed on purpose. ```text rmodels | raudio ``` rtextures, rtext and rshapes cannot be disabled: the asset layer and the CI render gate are built on rtextures, rres calls into rtext, and `rmp::ui` draws every panel and button with rshapes. configure.py says so if you try. NOTE: this does not affect iOS, which links a prebuilt xcframework. ## `[web]` ### `memory` memory = 64 int How much memory the WebAssembly module is allowed. memory Megabytes reserved at startup (Emscripten's TOTAL_MEMORY). 64 is ```cpp enough for a menu and a handful of textures. A game that loads a tile atlas and a few tracks wants more, and the failure mode is specific: the tab dies with "Cannot enlarge memory arrays". ``` grow Let it grow past `memory` instead of aborting. It costs a little ```cpp speed on every heap access — every pointer goes through a bounds check that cannot be hoisted — so a game that knows its ceiling is better off raising `memory` and leaving this off. ``` ### `grow` grow = false bool How much memory the WebAssembly module is allowed. memory Megabytes reserved at startup (Emscripten's TOTAL_MEMORY). 64 is ```cpp enough for a menu and a handful of textures. A game that loads a tile atlas and a few tracks wants more, and the failure mode is specific: the tab dies with "Cannot enlarge memory arrays". ``` grow Let it grow past `memory` instead of aborting. It costs a little ```cpp speed on every heap access — every pointer goes through a bounds check that cannot be hoisted — so a game that knows its ceiling is better off raising `memory` and leaving this off. ``` ### `backend` backend = "glfw" string one of `"emscripten"`, `"glfw"` backend What raylib talks to in the browser. THE COMPILER IS EMSCRIPTEN IN ```cpp ALL THREE CASES — that is not what this chooses. It chooses whether there is a layer between raylib and the browser, and it is the same question [windows] backend and [linux] backend answer for their platforms. ``` ```text glfw raylib calls GLFW, and Emscripten emulates GLFW in JavaScript (that is what -sUSE_GLFW=3 links). The path raylib has shipped for years and the one every web example on the internet is built with. THE DEFAULT. emscripten raylib calls the browser through Emscripten's own API, with nothing in between. New in raylib 6.0 (platforms/rcore_web_emscripten.c). One layer less and no JavaScript shim to download. rgfw REFUSED, and not out of caution: RGFW's web backend calls emscripten_sleep, which needs -sASYNCIFY, and this framework deliberately has none — the browser owns the frame loop through emscripten_set_main_loop precisely so that it does not. It builds fine and then dies in the tab with "Please compile your program with async support". Found by opening it in a real browser; see .github/workflows/web-backends.yml. ``` ```cpp BOTH OF THESE ARE VERIFIED IN A BROWSER, not just built: the boot job in web-backends.yml opens each one in headless Chromium and screenshots the canvas. For `emscripten` that matters more than usual — raylib 6.0 ships the backend without wiring it into the build, and it compiles only through local patches to raylib's (thirdparty/raylib/PATCHES.md). WHY NOT `emscripten` BY DEFAULT YET, having read both backends: they implement the same functions and stub out the same ones — monitor enumeration and SetGamepadMappings, neither of which means anything in a browser. Where they differ is in unfinished detail, and it is in the one raylib calls new: rcore_web_emscripten.c carries `TODO: keyCodes should be mapped to raylib/GLFW3 Key values` and `TODO: Add char codes`, so key constants are not guaranteed to be the ones raylib documents, and drop-files is `TODO: Implement GLFW3 alternative for drop callback`. The GLFW path has none of those. Upstream is going the same way — rcore_web.c itself carries `TODO: Replace GLFW-web by Emscripten?` — and this stays an option and not the default while the keyboard mapping is unfinished. ``` ## `[input]` ### `deadzone` deadzone = 0.2 float deadzone How much of an analogue stick's travel reads as zero, 0..0.95. ```cpp Sticks drift as they wear, so 0 means a character that walks on its own on a controller that has seen some use; too much and the stick feels dead before it moves. 0.2 is the value most engines settle on. It rescales rather than clipping: just past the dead zone the stick reads a little above zero, not a sudden 0.2. Without that, every character starts moving at a fifth of full speed. Keyboard and d-pad are unaffected — they are on or off and have no travel to ignore. rmp::input::set_deadzone() changes it at runtime, which is what a settings slider does. ``` ## `[audio]` ### `master` master = 1.0 float The volumes `rmp::audio` starts at, each a fraction from 0 (silent) to 1 (full). MASTER scales everything; MUSIC and SFX scale their own on top of it, so music = 0.8 under master = 0.5 plays at 40 %. A settings screen changes them at runtime with `rmp::audio::set_volume()` — these are only the start. Nothing here opens the sound device: it opens the first time something is played, so a game with no sound never touches it. ### `music` music = 0.8 float The volumes `rmp::audio` starts at, each a fraction from 0 (silent) to 1 (full). MASTER scales everything; MUSIC and SFX scale their own on top of it, so music = 0.8 under master = 0.5 plays at 40 %. A settings screen changes them at runtime with `rmp::audio::set_volume()` — these are only the start. Nothing here opens the sound device: it opens the first time something is played, so a game with no sound never touches it. ### `sfx` sfx = 1.0 float The volumes `rmp::audio` starts at, each a fraction from 0 (silent) to 1 (full). MASTER scales everything; MUSIC and SFX scale their own on top of it, so music = 0.8 under master = 0.5 plays at 40 %. A settings screen changes them at runtime with `rmp::audio::set_volume()` — these are only the start. Nothing here opens the sound device: it opens the first time something is played, so a game with no sound never touches it. ## `[save]` ### `portable` portable = false bool `rmp::save` — saving the game. Nothing here is a secret, and nothing may be. portable: where the saves go. ```text false the user's data folder: %APPDATA%\ on Windows, ~/Library/Application Support/ on macOS, ~/.local/share/ on Linux and the BSDs. What installers and Steam Cloud expect. true a saves/ folder next to the executable. What a zip from itch.io wants: delete the folder and the game is gone, saves included. Only Windows, Linux and FreeBSD have such a place; macOS, Android, iOS and web ignore it, and NetBSD and OpenBSD cannot say where the executable is, so there the saves go to the user's folder and the log says so once. If the 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 -- never lost in silence: reads look in both folders and take the newer save. ``` encrypt: whether `rmp::save::write()` seals the file by default. Sealed means ```text unreadable and any edit detected, and with it on a plain file reads as modified -- nobody swaps in a save of their own. The key is derived from [project] name, so it lives in the binary: that stops a text editor, not a determined player, and renaming the project makes old sealed saves unreadable. Every save has a checksum either way. ``` version: the version of YOUR save format. Adding a key never needs a bump -- ```text a missing key reads as its default. Bump it when a key changes meaning, and migrate on read: if (v.version() < 2) v["coins"] = v["gold"].as_int(0); ``` ### `encrypt` encrypt = false bool `rmp::save` — saving the game. Nothing here is a secret, and nothing may be. portable: where the saves go. ```text false the user's data folder: %APPDATA%\ on Windows, ~/Library/Application Support/ on macOS, ~/.local/share/ on Linux and the BSDs. What installers and Steam Cloud expect. true a saves/ folder next to the executable. What a zip from itch.io wants: delete the folder and the game is gone, saves included. Only Windows, Linux and FreeBSD have such a place; macOS, Android, iOS and web ignore it, and NetBSD and OpenBSD cannot say where the executable is, so there the saves go to the user's folder and the log says so once. If the 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 -- never lost in silence: reads look in both folders and take the newer save. ``` encrypt: whether `rmp::save::write()` seals the file by default. Sealed means ```text unreadable and any edit detected, and with it on a plain file reads as modified -- nobody swaps in a save of their own. The key is derived from [project] name, so it lives in the binary: that stops a text editor, not a determined player, and renaming the project makes old sealed saves unreadable. Every save has a checksum either way. ``` version: the version of YOUR save format. Adding a key never needs a bump -- ```text a missing key reads as its default. Bump it when a key changes meaning, and migrate on read: if (v.version() < 2) v["coins"] = v["gold"].as_int(0); ``` ### `version` version = 1 int `rmp::save` — saving the game. Nothing here is a secret, and nothing may be. portable: where the saves go. ```text false the user's data folder: %APPDATA%\ on Windows, ~/Library/Application Support/ on macOS, ~/.local/share/ on Linux and the BSDs. What installers and Steam Cloud expect. true a saves/ folder next to the executable. What a zip from itch.io wants: delete the folder and the game is gone, saves included. Only Windows, Linux and FreeBSD have such a place; macOS, Android, iOS and web ignore it, and NetBSD and OpenBSD cannot say where the executable is, so there the saves go to the user's folder and the log says so once. If the 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 -- never lost in silence: reads look in both folders and take the newer save. ``` encrypt: whether `rmp::save::write()` seals the file by default. Sealed means ```text unreadable and any edit detected, and with it on a plain file reads as modified -- nobody swaps in a save of their own. The key is derived from [project] name, so it lives in the binary: that stops a text editor, not a determined player, and renaming the project makes old sealed saves unreadable. Every save has a checksum either way. ``` version: the version of YOUR save format. Adding a key never needs a bump -- ```text a missing key reads as its default. Bump it when a key changes meaning, and migrate on read: if (v.version() < 2) v["coins"] = v["gold"].as_int(0); ``` ## `[windows]` ### `backend` backend = "glfw" string one of `"glfw"`, `"rgfw"`, `"win32"` Which windowing backend Windows uses. ```text "glfw" the default, and what raylib uses everywhere else. Mature, and it is what the CI matrix is tested against. "win32" raylib 6.0's native Win32 backend: no GLFW at all, one dependency fewer and a smaller .exe. "rgfw" RGFW, a single-header windowing library. Also no GLFW, also smaller, and the same caveat as win32 applies. ``` "win32" is a real option and a young one. It does not cover everything GLFW does — gamepads, multi-monitor, the clipboard and some keyboard cases are thinner — so it is right for a simple game and wrong as a default. Try it, measure the .exe, and keep it only if nothing you use is missing. ## `[upx]` ### `enabled` enabled = ["linux-x64-glibc", "linux-arm64-glibc", "linux-x64-musl", "linux-x64-glibc-drm"] list a list of `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` and 5 more Compress the shipped binary with UPX. Measured on linux-x64-glibc at commit cf7b676, built the way CI builds it — hardened, PIE, stripped: 1 234 656 bytes down to 365 836, a 70 % cut. linux-x64-musl the same, 1 232 872 to 365 196; linux-x64-glibc-drm, which links its graphics libraries instead of carrying them, 748 616 to 310 540, 58 %. CI holds every packed binary to the same boot and render gate as an unpacked one — see the last paragraph. Groups expand and deduplicate exactly like [targets], and `disabled` is subtracted afterwards, so there is no precedence to reason about. ```text groups : all | linux | windows | bsd exact : linux-x64-glibc linux-arm64-glibc linux-riscv64-glibc linux-x64-musl linux-x64-glibc-drm linux-arm64-glibc-drm windows-x64 windows-arm64 freebsd-x64 freebsd-arm64 openbsd-x64 openbsd-arm64 netbsd-x64 ``` `all` here is NOT every target. macOS and iOS are refused because the binary is code-signed and compressing it breaks the signature; Android because what ships is a .so inside an APK, which is already a zip, so compressing it makes the APK BIGGER; web because it is .wasm and the browser fetches it gzipped. Naming any of them is an error with the reason, not a silent no-op. LINUX-RISCV64-GLIBC IS PACKED ONLY WHEN NAMED (Omar, 2026-11-15): no group and no default brings it in, and naming it is a warning. UPX 5.2.0's riscv64 stub dies with SIGTRAP on every kernel before 6.3 — most RISC-V boards' vendor kernels, RISE's 5.10 among them — because `memfd_create(MFD_EXEC)` is EINVAL there and, unlike the amd64 and arm64 stubs, it never tries again without the flag. QEMU runs on the host's newer kernel and never saw it. A patched stub is no way out: UPX's licence exception covers only the unmodified one. A game whose players all run Linux 6.3 or later may name it for its 59 % (962 752 bytes to 391 504, measured at c0369ec). WINDOWS IS AVAILABLE AND NOT ON BY DEFAULT, and that is deliberate: an unsigned .exe that has been UPX-packed is a shape Windows Defender associates with malware, and it gets quarantined on some machines and not others. If you sign your builds, turn it on and you get the same 70-odd per cent. If you do not, the download saving is not worth a fraction of your players being told your game is a virus. BSD is untested territory for this and is off by default for that reason alone: upx publishes no FreeBSD/OpenBSD/NetBSD build, so the VMs would have to install it from ports. THE DEFAULT IS EXACTLY THE TARGETS WHOSE PACKED BINARY CI STARTS. Each of these four jobs unzips the archive it ships — UPX-packed — starts what is in it, and checks it puts pixels on the screen: linux-x64-glibc on every push, under a virtual X server; linux-arm64-glibc on a full run, on an ARM64 runner; linux-x64-musl on a full run, on Alpine under Xvfb; and linux-x64-glibc-drm on a full run, on a vkms display. So if UPX ever produced a stub that does not launch, CI finds out. linux-riscv64-glibc's archive is started too, on a RISC-V board and under QEMU, unpacked: see above. linux-arm64-glibc-drm is never executed — built and checked statically — so turning UPX on there would ship a packed binary whose launch nobody has observed. ### `disabled` disabled = [] list a list of `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` and 5 more Compress the shipped binary with UPX. Measured on linux-x64-glibc at commit cf7b676, built the way CI builds it — hardened, PIE, stripped: 1 234 656 bytes down to 365 836, a 70 % cut. linux-x64-musl the same, 1 232 872 to 365 196; linux-x64-glibc-drm, which links its graphics libraries instead of carrying them, 748 616 to 310 540, 58 %. CI holds every packed binary to the same boot and render gate as an unpacked one — see the last paragraph. Groups expand and deduplicate exactly like [targets], and `disabled` is subtracted afterwards, so there is no precedence to reason about. ```text groups : all | linux | windows | bsd exact : linux-x64-glibc linux-arm64-glibc linux-riscv64-glibc linux-x64-musl linux-x64-glibc-drm linux-arm64-glibc-drm windows-x64 windows-arm64 freebsd-x64 freebsd-arm64 openbsd-x64 openbsd-arm64 netbsd-x64 ``` `all` here is NOT every target. macOS and iOS are refused because the binary is code-signed and compressing it breaks the signature; Android because what ships is a .so inside an APK, which is already a zip, so compressing it makes the APK BIGGER; web because it is .wasm and the browser fetches it gzipped. Naming any of them is an error with the reason, not a silent no-op. LINUX-RISCV64-GLIBC IS PACKED ONLY WHEN NAMED (Omar, 2026-11-15): no group and no default brings it in, and naming it is a warning. UPX 5.2.0's riscv64 stub dies with SIGTRAP on every kernel before 6.3 — most RISC-V boards' vendor kernels, RISE's 5.10 among them — because `memfd_create(MFD_EXEC)` is EINVAL there and, unlike the amd64 and arm64 stubs, it never tries again without the flag. QEMU runs on the host's newer kernel and never saw it. A patched stub is no way out: UPX's licence exception covers only the unmodified one. A game whose players all run Linux 6.3 or later may name it for its 59 % (962 752 bytes to 391 504, measured at c0369ec). WINDOWS IS AVAILABLE AND NOT ON BY DEFAULT, and that is deliberate: an unsigned .exe that has been UPX-packed is a shape Windows Defender associates with malware, and it gets quarantined on some machines and not others. If you sign your builds, turn it on and you get the same 70-odd per cent. If you do not, the download saving is not worth a fraction of your players being told your game is a virus. BSD is untested territory for this and is off by default for that reason alone: upx publishes no FreeBSD/OpenBSD/NetBSD build, so the VMs would have to install it from ports. THE DEFAULT IS EXACTLY THE TARGETS WHOSE PACKED BINARY CI STARTS. Each of these four jobs unzips the archive it ships — UPX-packed — starts what is in it, and checks it puts pixels on the screen: linux-x64-glibc on every push, under a virtual X server; linux-arm64-glibc on a full run, on an ARM64 runner; linux-x64-musl on a full run, on Alpine under Xvfb; and linux-x64-glibc-drm on a full run, on a vkms display. So if UPX ever produced a stub that does not launch, CI finds out. linux-riscv64-glibc's archive is started too, on a RISC-V board and under QEMU, unpacked: see above. linux-arm64-glibc-drm is never executed — built and checked statically — so turning UPX on there would ship a packed binary whose launch nobody has observed. ### `max_size_mb` max_size_mb = 600 int Skip compression when the binary is bigger than this, in megabytes. UPX cannot pack a file past roughly 768 MB, and it does not decline politely when it happens: it exits non-zero, which fails the release of a game whose only problem is that it is large. The default leaves 168 MB of headroom, so what you get instead is a line in the log and an uncompressed binary that ships. Raise it if you have measured your own ceiling, lower it if you would rather not spend the packing minute on anything sizeable. To turn compression off entirely, empty `enabled` above. Setting this to 0 is rejected, because it says the wrong thing. ## `[linux]` ### `backend` backend = "glfw" string one of `"glfw"`, `"rgfw"` Which windowing backend Linux uses, and whether it talks to Wayland natively. backend "glfw" (default) or "rgfw". GLFW is what the CI matrix is tested ```cpp against; RGFW is smaller and younger — and on Linux it is X11-ONLY, so it cannot be combined with wayland = true. The generator refuses that pair rather than letting the build pick one. Neither key reaches the DRM targets: DRM talks to the kernel directly and has no windowing backend and no compositor at all. ``` wayland false (default) builds GLFW against X11 only, so on a Wayland desktop ```cpp the game runs through XWayland — an extra hop, and the reason fractional scaling and per-monitor DPI misbehave there. true builds BOTH backends into the binary and lets GLFW pick at startup: a Wayland session gets Wayland natively, an X11 session gets X11 natively, and neither is a fallback for the other. It needs libwayland-dev, wayland-protocols and libxkbcommon-dev on the build machine. Both, and not Wayland alone: a Wayland-only binary does not start on an X11 session at all, and the machine that runs the game is not the one that built it, so that is not a choice to make at build time. Off by default because raylib 6.0's Wayland path is the less travelled one. One difference you WILL see, and it is Wayland's design and not a bug: there is no window position. GetWindowPosition() and SetWindowPosition() do not work, and GLFW logs a warning the first time something asks. A game that remembers where its window was cannot do that on Wayland, natively or otherwise. ``` ### `wayland` wayland = false bool Which windowing backend Linux uses, and whether it talks to Wayland natively. backend "glfw" (default) or "rgfw". GLFW is what the CI matrix is tested ```cpp against; RGFW is smaller and younger — and on Linux it is X11-ONLY, so it cannot be combined with wayland = true. The generator refuses that pair rather than letting the build pick one. Neither key reaches the DRM targets: DRM talks to the kernel directly and has no windowing backend and no compositor at all. ``` wayland false (default) builds GLFW against X11 only, so on a Wayland desktop ```cpp the game runs through XWayland — an extra hop, and the reason fractional scaling and per-monitor DPI misbehave there. true builds BOTH backends into the binary and lets GLFW pick at startup: a Wayland session gets Wayland natively, an X11 session gets X11 natively, and neither is a fallback for the other. It needs libwayland-dev, wayland-protocols and libxkbcommon-dev on the build machine. Both, and not Wayland alone: a Wayland-only binary does not start on an X11 session at all, and the machine that runs the game is not the one that built it, so that is not a choice to make at build time. Off by default because raylib 6.0's Wayland path is the less travelled one. One difference you WILL see, and it is Wayland's design and not a bug: there is no window position. GetWindowPosition() and SetWindowPosition() do not work, and GLFW logs a warning the first time something asks. A game that remembers where its window was cannot do that on Wayland, natively or otherwise. ``` ### `glibc` glibc = "2.28" string glibc The OLDEST glibc the shipped binary is allowed to need, or "" to build ```cpp against whatever the build machine has. A Linux binary records, per imported symbol, the glibc version that symbol came from, and the loader refuses to start anything it cannot satisfy. CI builds on Ubuntu 24.04, which is glibc 2.39 — and 2.39 does not exist on Debian 12, Ubuntu 22.04, RHEL 8, or inside Steam's sniper runtime. Nothing about the build hints at this: it compiles, links, and runs perfectly on the machine that made it, and dies elsewhere with "version GLIBC_2.39 not found". THE FIX COSTS NOTHING, and that is measured rather than hoped. Every symbol in this project asking for a modern glibc is either libm (powf, hypot, fmod, acosf) or one of the pthread/dl functions glibc 2.34 folded into libc. There is not one new API in the whole thing, so the floor is a build setting. With this set, tools/linux_build.sh compiles with zig cc, which ships glibc stubs back to 2.17 — and at the same optimisation level it renders a byte-identical frame to gcc, so this is a compatibility change and not a behaviour change. There is nothing to install on the player's side either: GLFW opens libX11 and libGL with dlopen at runtime, so the binary's only hard dependencies are libc, libm, libpthread and libdl. 2.17 RHEL/CentOS 7. The floor zig can reach; everything else is EOL. 2.28 RHEL 8 (supported to 2029), Debian 10, Ubuntu 18.10. 2.31 Ubuntu 20.04, Debian 11 — and Steam Runtime 3 "sniper", which is what a game on Steam runs inside today. "" build against this machine. Fine locally, wrong for a release. 2.28 is the default because it clears the oldest distribution still getting security updates, and clears sniper with room to spare. It reaches linux-x64-glibc and linux-arm64-glibc: those are built by tools/linux_build.sh, and tools/glibc_check.sh fails the build if the binary asks for more. Two kinds of target it does not reach: linux-riscv64-glibc is cross-compiled with the distribution's GNU toolchain against Ubuntu 24.04's glibc, and 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 fails if that grows. The DRM targets link the distribution's libdrm, gbm and EGL directly; their floor is the build machine's glibc, and their jobs print it. ``` ## `[dialogue]` ### `build` build = "auto" string `rmp::Dialogue` — conversations in Yarn Spinner 3 (.yarn files in resources/). build Where a script is compiled: ```cpp "runtime" when the game loads it: edit, reload, see it at once. "embedded" when the game is built, into the executable: nothing to compile at start, 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" runtime in a debug build, embedded in a release. ``` ## `[lang]` ### `default` default = "en" string `rmp::Text` and `rmp::lang` — the game in more than one language. A literal the framework is handed ("Play") is looked up in the tables below by its text; what is not there is shown as written. Nothing here is required. default The language every other falls back to: es-MX, then es, then this, ```cpp then the text as the code wrote it. ``` file A table in resources/ with one column per language: ```cpp keycontextenes... ("" for none) ``` folder A folder in resources/ with one table per language, es.tsv: ```cpp keycontexttext. Both may be used; they are merged. ``` collect A debug build writes the texts it showed that the tables lack to ```cpp lang_seen.tsv next to the executable; `rmp text scan` adds them. ``` languages The languages the game ships, in the order a language menu lists ```cpp them. [] is every language the tables have. With a list, `rmp text check` fails on a text one of them lacks, and the player's system language is only chosen when it is one of them. ``` fonts A font per language, for an alphabet the `[ui] font` does not have: ```cpp fonts = { ja = "jp.ttf" }. The UI changes font with the language. ``` ### `file` file = "lang.tsv" string `rmp::Text` and `rmp::lang` — the game in more than one language. A literal the framework is handed ("Play") is looked up in the tables below by its text; what is not there is shown as written. Nothing here is required. default The language every other falls back to: es-MX, then es, then this, ```cpp then the text as the code wrote it. ``` file A table in resources/ with one column per language: ```cpp keycontextenes... ("" for none) ``` folder A folder in resources/ with one table per language, es.tsv: ```cpp keycontexttext. Both may be used; they are merged. ``` collect A debug build writes the texts it showed that the tables lack to ```cpp lang_seen.tsv next to the executable; `rmp text scan` adds them. ``` languages The languages the game ships, in the order a language menu lists ```cpp them. [] is every language the tables have. With a list, `rmp text check` fails on a text one of them lacks, and the player's system language is only chosen when it is one of them. ``` fonts A font per language, for an alphabet the `[ui] font` does not have: ```cpp fonts = { ja = "jp.ttf" }. The UI changes font with the language. ``` ### `folder` folder = "lang" string `rmp::Text` and `rmp::lang` — the game in more than one language. A literal the framework is handed ("Play") is looked up in the tables below by its text; what is not there is shown as written. Nothing here is required. default The language every other falls back to: es-MX, then es, then this, ```cpp then the text as the code wrote it. ``` file A table in resources/ with one column per language: ```cpp keycontextenes... ("" for none) ``` folder A folder in resources/ with one table per language, es.tsv: ```cpp keycontexttext. Both may be used; they are merged. ``` collect A debug build writes the texts it showed that the tables lack to ```cpp lang_seen.tsv next to the executable; `rmp text scan` adds them. ``` languages The languages the game ships, in the order a language menu lists ```cpp them. [] is every language the tables have. With a list, `rmp text check` fails on a text one of them lacks, and the player's system language is only chosen when it is one of them. ``` fonts A font per language, for an alphabet the `[ui] font` does not have: ```cpp fonts = { ja = "jp.ttf" }. The UI changes font with the language. ``` ### `collect` collect = true bool `rmp::Text` and `rmp::lang` — the game in more than one language. A literal the framework is handed ("Play") is looked up in the tables below by its text; what is not there is shown as written. Nothing here is required. default The language every other falls back to: es-MX, then es, then this, ```cpp then the text as the code wrote it. ``` file A table in resources/ with one column per language: ```cpp keycontextenes... ("" for none) ``` folder A folder in resources/ with one table per language, es.tsv: ```cpp keycontexttext. Both may be used; they are merged. ``` collect A debug build writes the texts it showed that the tables lack to ```cpp lang_seen.tsv next to the executable; `rmp text scan` adds them. ``` languages The languages the game ships, in the order a language menu lists ```cpp them. [] is every language the tables have. With a list, `rmp text check` fails on a text one of them lacks, and the player's system language is only chosen when it is one of them. ``` fonts A font per language, for an alphabet the `[ui] font` does not have: ```cpp fonts = { ja = "jp.ttf" }. The UI changes font with the language. ``` ### `languages` languages = [] list `rmp::Text` and `rmp::lang` — the game in more than one language. A literal the framework is handed ("Play") is looked up in the tables below by its text; what is not there is shown as written. Nothing here is required. default The language every other falls back to: es-MX, then es, then this, ```cpp then the text as the code wrote it. ``` file A table in resources/ with one column per language: ```cpp keycontextenes... ("" for none) ``` folder A folder in resources/ with one table per language, es.tsv: ```cpp keycontexttext. Both may be used; they are merged. ``` collect A debug build writes the texts it showed that the tables lack to ```cpp lang_seen.tsv next to the executable; `rmp text scan` adds them. ``` languages The languages the game ships, in the order a language menu lists ```cpp them. [] is every language the tables have. With a list, `rmp text check` fails on a text one of them lacks, and the player's system language is only chosen when it is one of them. ``` fonts A font per language, for an alphabet the `[ui] font` does not have: ```cpp fonts = { ja = "jp.ttf" }. The UI changes font with the language. ``` ### `fonts` fonts = {} table `rmp::Text` and `rmp::lang` — the game in more than one language. A literal the framework is handed ("Play") is looked up in the tables below by its text; what is not there is shown as written. Nothing here is required. default The language every other falls back to: es-MX, then es, then this, ```cpp then the text as the code wrote it. ``` file A table in resources/ with one column per language: ```cpp keycontextenes... ("" for none) ``` folder A folder in resources/ with one table per language, es.tsv: ```cpp keycontexttext. Both may be used; they are merged. ``` collect A debug build writes the texts it showed that the tables lack to ```cpp lang_seen.tsv next to the executable; `rmp text scan` adds them. ``` languages The languages the game ships, in the order a language menu lists ```cpp them. [] is every language the tables have. With a list, `rmp text check` fails on a text one of them lacks, and the player's system language is only chosen when it is one of them. ``` fonts A font per language, for an alphabet the `[ui] font` does not have: ```cpp fonts = { ja = "jp.ttf" }. The UI changes font with the language. ``` ## `[ui]` ### `theme` theme = "dark" string one of `"dark"`, `"light"` `rmp::ui` — the interface layer. Nothing here is required: with every key at its default a menu is still three lines of code. theme "dark" or "light". Only which one the app starts with — an ```cpp in-game appearance setting is rmp::ui::set_theme(theme_light()). ``` font "" uses the font built into raylib: no asset, no licence, works on ```cpp every target. It is a pixel font, drawn at whatever size the text asks for. Point it at a .ttf in resources/ for something less retro: it is baked at every size the interface draws, so SMALL, MEDIUM and LARGE are each sharp. ``` font_size In DESIGN units, i.e. at the `[window] resolution` above. The UI ```cpp scales it from there, so this is a size you pick once. ``` scale 0 = automatic, derived from `[window] and` the real window size. ```cpp Set a number to pin it (an "interface size" option would do this). ``` max_elements Ceiling on the UI tree; it is what sizes the layout arena. ```cpp 512 is plenty for menus and HUDs — Clay's own default of 8192 would reserve megabytes for three buttons. ``` ### `font` font = "" string `rmp::ui` — the interface layer. Nothing here is required: with every key at its default a menu is still three lines of code. theme "dark" or "light". Only which one the app starts with — an ```cpp in-game appearance setting is rmp::ui::set_theme(theme_light()). ``` font "" uses the font built into raylib: no asset, no licence, works on ```cpp every target. It is a pixel font, drawn at whatever size the text asks for. Point it at a .ttf in resources/ for something less retro: it is baked at every size the interface draws, so SMALL, MEDIUM and LARGE are each sharp. ``` font_size In DESIGN units, i.e. at the `[window] resolution` above. The UI ```cpp scales it from there, so this is a size you pick once. ``` scale 0 = automatic, derived from `[window] and` the real window size. ```cpp Set a number to pin it (an "interface size" option would do this). ``` max_elements Ceiling on the UI tree; it is what sizes the layout arena. ```cpp 512 is plenty for menus and HUDs — Clay's own default of 8192 would reserve megabytes for three buttons. ``` ### `font_size` font_size = 20 int `rmp::ui` — the interface layer. Nothing here is required: with every key at its default a menu is still three lines of code. theme "dark" or "light". Only which one the app starts with — an ```cpp in-game appearance setting is rmp::ui::set_theme(theme_light()). ``` font "" uses the font built into raylib: no asset, no licence, works on ```cpp every target. It is a pixel font, drawn at whatever size the text asks for. Point it at a .ttf in resources/ for something less retro: it is baked at every size the interface draws, so SMALL, MEDIUM and LARGE are each sharp. ``` font_size In DESIGN units, i.e. at the `[window] resolution` above. The UI ```cpp scales it from there, so this is a size you pick once. ``` scale 0 = automatic, derived from `[window] and` the real window size. ```cpp Set a number to pin it (an "interface size" option would do this). ``` max_elements Ceiling on the UI tree; it is what sizes the layout arena. ```cpp 512 is plenty for menus and HUDs — Clay's own default of 8192 would reserve megabytes for three buttons. ``` ### `scale` scale = 0 int `rmp::ui` — the interface layer. Nothing here is required: with every key at its default a menu is still three lines of code. theme "dark" or "light". Only which one the app starts with — an ```cpp in-game appearance setting is rmp::ui::set_theme(theme_light()). ``` font "" uses the font built into raylib: no asset, no licence, works on ```cpp every target. It is a pixel font, drawn at whatever size the text asks for. Point it at a .ttf in resources/ for something less retro: it is baked at every size the interface draws, so SMALL, MEDIUM and LARGE are each sharp. ``` font_size In DESIGN units, i.e. at the `[window] resolution` above. The UI ```cpp scales it from there, so this is a size you pick once. ``` scale 0 = automatic, derived from `[window] and` the real window size. ```cpp Set a number to pin it (an "interface size" option would do this). ``` max_elements Ceiling on the UI tree; it is what sizes the layout arena. ```cpp 512 is plenty for menus and HUDs — Clay's own default of 8192 would reserve megabytes for three buttons. ``` ### `max_elements` max_elements = 512 int `rmp::ui` — the interface layer. Nothing here is required: with every key at its default a menu is still three lines of code. theme "dark" or "light". Only which one the app starts with — an ```cpp in-game appearance setting is rmp::ui::set_theme(theme_light()). ``` font "" uses the font built into raylib: no asset, no licence, works on ```cpp every target. It is a pixel font, drawn at whatever size the text asks for. Point it at a .ttf in resources/ for something less retro: it is baked at every size the interface draws, so SMALL, MEDIUM and LARGE are each sharp. ``` font_size In DESIGN units, i.e. at the `[window] resolution` above. The UI ```cpp scales it from there, so this is a size you pick once. ``` scale 0 = automatic, derived from `[window] and` the real window size. ```cpp Set a number to pin it (an "interface size" option would do this). ``` max_elements Ceiling on the UI tree; it is what sizes the layout arena. ```cpp 512 is plenty for menus and HUDs — Clay's own default of 8192 would reserve megabytes for three buttons. ``` ## `[dev]` ### `compiler` compiler = "clang" string one of `"clang"`, `"default"`, `"gcc"`, `"mingw"`, `"msvc"` Debug builds only, the ones that never ship: `rmp run`, `rmp test` and every `debug` preset — and the software-render check CI runs on every push (the lint job, the BSD and macOS jobs), which is a Debug build too. The release and web builds a player gets never read this section. clang | gcc | mingw | msvc | default mingw looks for x86_64-w64-mingw32-gcc before plain `gcc`, which is what makes it work from MSYS2. Plain "gcc" on Windows is how you pick up a stray compiler from a Git-for-Windows shell and end up with a build that asks for X11. ### `c_compiler` c_compiler = "same" string What compiles the C: raylib, GLFW, RGFW, miniaudio, cJSON. same | tcc | auto ```text same [dev] compiler's own C compiler. tcc the Tiny C Compiler: builds raylib and GLFW in about a second, and optimises nothing. x86-64 Linux only; the C++ compiler above still compiles the C++ and links the game, with GNU ld. tcc has no sanitizers, so the C it compiles is not instrumented. auto tcc where it is installed and can work, same anywhere else. ``` The framework keeps "same", so its Debug builds sanitize raylib too; `rmp new` writes "auto" for a game, whose Debug build is for iterating fast. See [what tcc compiles, where it is used, and what it cannot do](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#tcc). ### `linker` linker = "auto" string one of `"auto"`, `"default"`, `"lld"`, `"mold"` What compiles the C: raylib, GLFW, RGFW, miniaudio, cJSON. same | tcc | auto ```text same [dev] compiler's own C compiler. tcc the Tiny C Compiler: builds raylib and GLFW in about a second, and optimises nothing. x86-64 Linux only; the C++ compiler above still compiles the C++ and links the game, with GNU ld. tcc has no sanitizers, so the C it compiles is not instrumented. auto tcc where it is installed and can work, same anywhere else. ``` The framework keeps "same", so its Debug builds sanitize raylib too; `rmp new` writes "auto" for a game, whose Debug build is for iterating fast. auto | mold | lld | default ### `strict` strict = false bool What compiles the C: raylib, GLFW, RGFW, miniaudio, cJSON. same | tcc | auto ```text same [dev] compiler's own C compiler. tcc the Tiny C Compiler: builds raylib and GLFW in about a second, and optimises nothing. x86-64 Linux only; the C++ compiler above still compiles the C++ and links the game, with GNU ld. tcc has no sanitizers, so the C it compiles is not instrumented. auto tcc where it is installed and can work, same anywhere else. ``` The framework keeps "same", so its Debug builds sanitize raylib too; `rmp new` writes "auto" for a game, whose Debug build is for iterating fast. true: a framework warning aborts a DEBUG build ### `sanitize` sanitize = [] list a list of `address`, `undefined` What a Debug build is instrumented with: address | undefined, or [] for none. The framework lists both and `rmp new` writes [] for a game: turn them on when you want the game's mistakes found where they happen instead of where they crash. A compiler without the runtime builds without, and says so. See [what each sanitizer catches and costs, and what configure.py refuses, with its reason](https://omardev29.github.io/rmp-docs/manual/basics/configuration.html#sanitizers). ## `[resources]` ### `rres_password` rres_password = "raylib-template" string Obfuscation, not security: the password ends up inside the binary. It exists so casual unpacking of your assets is inconvenient, nothing more. ## `[deploy]` ### `licenses` licenses = true bool Ship a LICENSES.txt next to the binary, with the full notice of everything vendored — raylib, Clay, rres and whatever comes later. Generated from the licence files in thirdparty/, so adding a dependency updates it and forgetting to add one is a build error. Turn it off ONLY if your game already gives the credits inside it: a credits scene satisfies the same licences, and a loose .txt next to the executable is then just noise. On by default, because most games do not have that scene. With licenses = false, credits_note has to say where the credits ARE — it is the record of the decision, and configure.py refuses false with it empty. ### `credits_note` credits_note = "" string Ship a LICENSES.txt next to the binary, with the full notice of everything vendored — raylib, Clay, rres and whatever comes later. Generated from the licence files in thirdparty/, so adding a dependency updates it and forgetting to add one is a build error. Turn it off ONLY if your game already gives the credits inside it: a credits scene satisfies the same licences, and a loose .txt next to the executable is then just noise. On by default, because most games do not have that scene. With licenses = false, credits_note has to say where the credits ARE — it is the record of the decision, and configure.py refuses false with it empty. e.g. "the Credits scene, from the main menu" ## `[deploy.itch]` ### `user` user = "" string Leave empty to skip publishing. The API key is a GitHub secret (BUTLER_API_KEY), never here. ### `game` game = "" string Leave empty to skip publishing. The API key is a GitHub secret (BUTLER_API_KEY), never here. ## `[deploy.firebase]` ### `project_id` project_id = "" string Runs the debug APK in Firebase Test Lab. The default device, MediumPhone.arm, is one of Test Lab's Arm virtual devices; a physical model (gcloud firebase test android models list --filter=physical) runs it on a phone. Needs the GCP_SA_KEY secret and a Blaze billing account. Empty = skip. ### `device` device = "model=MediumPhone.arm,version=33,locale=en,orientation=portrait" string Runs the debug APK in Firebase Test Lab. The default device, MediumPhone.arm, is one of Test Lab's Arm virtual devices; a physical model (gcloud firebase test android models list --filter=physical) runs it on a phone. Needs the GCP_SA_KEY secret and a Blaze billing account. Empty = skip. ## `[ci]` ### `on_push` on_push = true bool Whether CI runs on every push to main and on every pull request — the fast lane, on every commit. false runs it only when you ask: a tag v* still builds every target and releases (that is what rmp deploy pushes), and `gh workflow run ci.yml` runs the fast lane by hand. Pull requests stop too. It is the one part of .github/workflows/ci.yml that is yours to change, and you change it here: tools/configure.py writes the push and pull_request triggers from this line, between the BEGIN and END lines in ci.yml, on the next build. Commit ci.yml with the .toml. A ci.yml that says otherwise is refused here, at this line, and by CI's first step. ### `riscv64` riscv64 = "rise" string Where linux-riscv64-glibc is built and started, when the full matrix or a release builds it: ```text "rise" natively, on a RISE RISC-V runner (real hardware, free for open source: https://riscv-runners.riseproject.dev/). "cloud-v" natively, on a Cloud-V board (https://cloud-v.co/github-riscv-runner): the native choice for a private repository, which RISE's open-source offer does not cover. "cross" cross-compiled on GitHub's amd64 runners and started under QEMU. ``` "rise" and "cloud-v" need the provider's GitHub App installed on this repository; without it the job waits in GitHub's queue for a board that never comes. When the board fails, the cross build runs instead and ships. ============================================================================== # Macros > The macros a game writes: the entry point, and the values the .toml sets. Source: https://omardev29.github.io/rmp-docs/reference/macros.html The framework's macros are all spelled `RMP_`: the preprocessor has one namespace, shared with raylib, the C library and the game. ### `RMP_DECLARE_ENTRY_POINT_ONCE` #define RMP_DECLARE_ENTRY_POINT_ONCE macro [include/rmp/app.h:291](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L291-L292) A symbol that exists only so that two errors read like sentences. ```text TWO entry points in one program -> it is defined twice, and the linker names it. (`main` collides too, but "duplicate symbol _main" does not say which of your files to look at.) NO entry point at all -> src/rmp/app/app.cpp references it, so the linker asks for it by this name, next to the "undefined reference to `main`" that alone tells a newcomer nothing about what to write. Checked by EntryPointGuardTest, which links one. ``` It is emitted by RMP_ENTRY_POINT rather than by RMP_GAME because the examples use the entry point directly, without scenes, and they are entry points too. ### `RMP_IOS_FUNCS` #define RMP_IOS_FUNCS(READY, FRAME, STOP) macro [include/rmp/app.h:307](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L307-L333) iOS. UIKit owns the run loop, so this runner is three callbacks instead of a `main()`. iOS rcore declares: extern void `ios_ready()`; `ios_update(bool)`; `ios_destroy()`; extern "C" so the symbols match the C declarations in rcore_ios.c. UIKit owns the run loop and offers no way to return from it, so the CI path tears down and exits explicitly. Outside CI that branch never runs. ### `RMP_WEB_FUNCS` #define RMP_WEB_FUNCS(READY, FRAME, STOP) macro [include/rmp/app.h:352](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L352-L373) Web. The browser owns the frame loop, and giving it to the browser is worth a paragraph because the alternative is expensive in a way that is invisible. A while loop in a browser only works if you build with -s ASYNCIFY, which rewrites the whole program so its stack can be unwound and restored at any suspension point. That instrumentation is not billed to the loop: it is billed to every function in the binary that might be on the stack when it happens, in code size and in speed, whether or not the frame ever yields. raylib says so itself, in the comment above `WindowShouldClose()` on web: "`WindowShouldClose()` is not called on a web-ready raylib application if using `emscripten_set_main_loop()`". That call is the only `emscripten_sleep()` in raylib, so not calling it is what lets ASYNCIFY go away entirely. fps = 0 means requestAnimationFrame, which is the right answer on web — do NOT call `SetTargetFPS()` here. The 1 is "simulate an infinite loop", so `main()` never returns and nothing after the call runs, which is exactly the contract the desktop while loop has. ### `RMP_DESKTOP_FUNCS` #define RMP_DESKTOP_FUNCS(READY, FRAME, STOP) macro [include/rmp/app.h:379](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L379-L398) Everywhere else — Windows, Linux, macOS, the BSDs and Android, where raylib's own `android_main()` calls `main()` — a `main()` that owns the frame loop: the ordinary raylib shape, ended by the window's X, [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) or the CI frame budget, and then the same stop sequence as the other two. ### `RMP_ENTRY_POINT` #define RMP_ENTRY_POINT(READY, FRAME, STOP) macro [include/rmp/app.h:407](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L407-L411) The entry point. Give it your three hooks; it picks the right runner — RMP_IOS_FUNCS on iOS, RMP_WEB_FUNCS on the web, RMP_DESKTOP_FUNCS everywhere else. RMP_GAME uses it, and a game with no scenes can call it directly: ```cpp RMP_ENTRY_POINT(on_ready, on_frame, on_exit); ``` Defined per platform: | When | Expands to | |---|---| | `#if defined(PLATFORM_IOS)` | `RMP_IOS_FUNCS(READY, FRAME, STOP)` | | `#elif defined(PLATFORM_WEB) \|\| defined(__EMSCRIPTEN__)` | `RMP_WEB_FUNCS(READY, FRAME, STOP)` | | `#else` | `RMP_DESKTOP_FUNCS(READY, FRAME, STOP)` | ### `RMP_GAME` #define RMP_GAME(SceneType) macro [include/rmp/app.h:448](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L448-L455) The whole of src/main.cpp: give it your first scene's type, and it opens the window, enters that scene, runs the stack every frame and closes everything on the way out. It is RMP_ENTRY_POINT with the three hooks written for you. ### `RMP_UI_FONT_SIZE` #define RMP_UI_FONT_SIZE macro [include/rmp/ui.h:67](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L67) `[ui] font_size` in design units. This 20 is only the fallback for a rmp/config.h that does not define it, and matches the .toml's default. ## Set by the .toml Every value of `raylib_multiplatform.toml` a game can read in C or C++ is a macro of the generated `rmp/config.h`, which every public header includes. The values here are the framework's own; a game's are whatever its .toml says. | Macro | From | The framework's value | |---|---|---| | `RMP_PROJECT_NAME` | [`[project] name`](https://omardev29.github.io/rmp-docs/reference/configuration.html#project-name) | `"ray_test"` | | `RMP_WINDOW_TITLE` | [`[window] title`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-title) | `"Raylib is Multiplatform!"` | | `RMP_WINDOW_WIDTH` | [`[window] width`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-width) | `800` | | `RMP_WINDOW_HEIGHT` | [`[window] height`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-height) | `450` | | `RMP_WINDOW_VSYNC` | [`[window] vsync`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-vsync) | `1` | | `RMP_WINDOW_FPS` | [`[window] fps`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-fps) | `0` | | `RMP_WINDOW_PAUSE_UNFOCUSED` | [`[window] pause_unfocused`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-pause_unfocused) | `0` | | `RMP_WINDOW_STRETCH` | [`[window] stretch`](https://omardev29.github.io/rmp-docs/reference/configuration.html#window-stretch) | `1` | | `RMP_RRES_PASSWORD` | [`[resources] rres_password`](https://omardev29.github.io/rmp-docs/reference/configuration.html#resources-rres_password) | `"raylib-template"` | | `RMP_UI_THEME` | [`[ui] theme`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ui-theme) | `"dark"` | | `RMP_UI_FONT` | [`[ui] font`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ui-font) | `""` | | `RMP_UI_FONT_SIZE` | [`[ui] font_size`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ui-font_size) | `20` | | `RMP_UI_SCALE` | [`[ui] scale`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ui-scale) | `0.0f` | | `RMP_UI_MAX_ELEMENTS` | [`[ui] max_elements`](https://omardev29.github.io/rmp-docs/reference/configuration.html#ui-max_elements) | `512` | | `RMP_LANG_DEFAULT` | [`[lang] default`](https://omardev29.github.io/rmp-docs/reference/configuration.html#lang-default) | `"en"` | | `RMP_LANG_FILE` | [`[lang] file`](https://omardev29.github.io/rmp-docs/reference/configuration.html#lang-file) | `"lang.tsv"` | | `RMP_LANG_FOLDER` | [`[lang] folder`](https://omardev29.github.io/rmp-docs/reference/configuration.html#lang-folder) | `"lang"` | | `RMP_LANG_COLLECT` | [`[lang] collect`](https://omardev29.github.io/rmp-docs/reference/configuration.html#lang-collect) | `1` | | `RMP_LANG_LANGUAGES` | [`[lang] languages`](https://omardev29.github.io/rmp-docs/reference/configuration.html#lang-languages) | `""` | | `RMP_LANG_FONTS` | [`[lang] fonts`](https://omardev29.github.io/rmp-docs/reference/configuration.html#lang-fonts) | `""` | | `RMP_INPUT_DEADZONE` | [`[input] deadzone`](https://omardev29.github.io/rmp-docs/reference/configuration.html#input-deadzone) | `0.2f` | | `RMP_AUDIO_MASTER` | [`[audio] master`](https://omardev29.github.io/rmp-docs/reference/configuration.html#audio-master) | `1.0f` | | `RMP_AUDIO_MUSIC` | [`[audio] music`](https://omardev29.github.io/rmp-docs/reference/configuration.html#audio-music) | `0.8f` | | `RMP_AUDIO_SFX` | [`[audio] sfx`](https://omardev29.github.io/rmp-docs/reference/configuration.html#audio-sfx) | `1.0f` | | `RMP_SAVE_PORTABLE` | [`[save] portable`](https://omardev29.github.io/rmp-docs/reference/configuration.html#save-portable) | `0` | | `RMP_SAVE_ENCRYPT` | [`[save] encrypt`](https://omardev29.github.io/rmp-docs/reference/configuration.html#save-encrypt) | `0` | | `RMP_SAVE_VERSION` | [`[save] version`](https://omardev29.github.io/rmp-docs/reference/configuration.html#save-version) | `1` | | `RMP_MAX_DELTA` | [`[app] max_delta`](https://omardev29.github.io/rmp-docs/reference/configuration.html#app-max_delta) | `0.05f` | | `RMP_DEV_STRICT` | [`[dev] strict`](https://omardev29.github.io/rmp-docs/reference/configuration.html#dev-strict) | `0` | ## Set by the build Macros no header defines: the build passes them to the compiler, for the framework and for your game. | Macro | What it is | |---|---| | `RMP_PRODUCTION_BUILD` | 1 in a release build and 0 in a debug one, on every platform: `rmp build release`, `rmp web` and every build CI ships are 1; `rmp build` and `rmp run` are 0. A build system that forgets it is a compile error in `src/rmp/app/app.cpp`, not a quiet debug build, so `#if RMP_PRODUCTION_BUILD` is safe to write. | | `RMP_SANITIZE` | Defined, as 1, in a debug build that runs under a sanitizer `[dev] sanitize` lists and the compiler could run; not defined otherwise, and never in a release. For code that has to allow for the slowdown, such as a timing test: `#if defined(RMP_SANITIZE)`. The CMake option of the same name is on by default, and `-DRMP_SANITIZE=OFF` builds one debug folder without them, to measure what they cost. | | `RMP_SANITIZE_ADDRESS` | Defined, as 1, when that build runs under AddressSanitizer (`"address"`). | | `RMP_SANITIZE_UNDEFINED` | Defined, as 1, when that build runs under UndefinedBehaviorSanitizer (`"undefined"`). | | `RMP_RESOURCES_PATH` | The folder loose resources are read from, ending in a slash. A game does not need it: `rmp::assets` resolves a name against the pack first and this folder second, and so does plain raylib's `LoadTexture()` on a path inside it. | ## Read by the build Names that are not macros at all: switches of the build itself, given to CMake with `-D` or set in the environment. | Name | Is | What it does | |---|---|---| | `RMP_WERROR` | a CMake option | `-DRMP_WERROR=ON` makes a compiler warning in the game's code and the framework's an error. Off unless asked for: the framework's own checks turn it on, and a game is never made to, because a newer compiler on its author's machine must not stop a build that was fine yesterday. | | `RMP_RELEASE_PIE` | a CMake option | On by default: a Linux or BSD release is linked position-independent, so ASLR can move the executable too. `-DRMP_RELEASE_PIE=OFF` only to measure what it costs. | | `RMP_REQUIRE_SANITIZERS` | an environment variable | `1` turns a sanitizer `[dev] sanitize` lists and the compiler cannot run from a warning into a failed configure. CI sets it where a debug build is a gate. | | `RMP_TARGET_DRM` | a CMake option | `-DRMP_TARGET_DRM=ON` builds for DRM/KMS: raylib's DRM platform, straight to the screen through the kernel, with no X11 and no Wayland. The `debug-drm` and `release-drm` presets turn it on, in `build/debug-drm` and `build/release-drm`, and `rmp` uses them on a Linux console with no desktop; the DRM targets' CI jobs pass it to the release preset. | | `RMP_DRM` | an environment variable | What `rmp` builds for on Linux, whatever it would decide by itself: `1` for DRM/KMS, as on a console with no desktop, and `0` for the desktop. Unset or empty, `rmp` decides; any other value is refused, and so is `1` anywhere but Linux. The installer reads it too, to list the headers that build needs. | | `RMP_ACCEPT_MICROSOFT_LICENSE` | an environment variable | `1` says you accept Microsoft's licence for its C runtime and Windows SDK, which `rmp build windows clang-cl` has xwin download into `~/.xwin` the first time. Unset, `rmp` asks on a terminal and refuses anywhere else; nothing is downloaded until the licence is accepted. | | `XWIN_DIR` | an environment variable | Where `rmp build windows clang-cl` keeps Microsoft's C runtime and Windows SDK, which xwin downloads once; `~/.xwin` when unset. | ============================================================================== # Namespaces > Every namespace of the framework, and what is in it. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/index.html Every namespace of the framework, and what is in it. | Name | What it is | |---|---| | [`rmp`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html) | rmp/app.h — the entry point, closing the app, and how the world fits the window. | | [`rmp::ads`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html) | `rmp::ads` — interstitial and rewarded ads. | | [`rmp::app`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html) | rmp/app.h — the entry point, closing the app, and how the world fits the window. | | [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) | `rmp::assets::` — loading from resources/ | | [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) | rmp/audio.h — sound effects and music, by name. | | [`rmp::behavior`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html) | rmp/behavior.h — the catalogue. | | [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html) | `rmp::input` — named actions, and who gets to hear them. | | [`rmp::lang`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html) | `rmp::Text` and `rmp::lang` — the game in more than one language. | | [`rmp::random`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html) | `rmp::random` — numbers you can reproduce. | | [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) | rmp/save.h — `rmp::Value`, and saving the game. | | [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) | `rmp::ui` — the interface layer. | ============================================================================== # rmp > rmp/app.h — the entry point, closing the app, and how the world fits the window. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html namespace `#include ` `#include ` `#include ` `#include ` `#include ` `#include ` `#include ` `#include ` `#include ` `#include ` ## On pages of their own - [`rmp::SheetData`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html) — Everything read out of an .aseprite: the packed texture, the frames and the tags. - [`rmp::DialogueValue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html) — A value of the Yarn language: a number, a string or a bool. - [`rmp::Dialogue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html) — A conversation: a compiled Yarn script, where it is in it, and what it remembers. - [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) — What an Object draws in place of its shape when it has one: a texture or a sheet, placed by `origin` around the object's position and turned, scaled and flipped with the object. - [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html) — A function the framework keeps and calls later with arguments of types A...: what `on_click()`, `on_drag()`, `on_collision()` and `Tilemap::on_object()` store, and the type of the `on_` fields of the behaviors. - [`rmp::Condition`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Condition.html) — A question the framework asks later with arguments of types A...: a StateMachine's transition, an Animator's rule, whether a Draggable may be dropped. - [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) — An optional reference: something that may not be there, and is not yours. - [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) — A reference to an object that is safe to keep across frames. - [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) — An entity in a scene: the player, an enemy, a bullet, a coin, a platform. - [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) — A tree: nothing, a bool, a number, a string, a list or an object — exactly what JSON holds, so a real structure fits and not only flat pairs. - [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) — The camera - [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html) — A screen of the game — a main menu, a level, a pause overlay — with its own objects, `map` and `camera`. - [`rmp::TextArg`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-TextArg.html) — One placeholder's value: a name and a number or a text. - [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) — A text the framework draws: translated when it was a literal, as it is when it was made at runtime. - [`rmp::MapObject`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html) — One object placed in the map, as `spawn_objects()` hands it to the factory registered for its `type`: where it is, how big, and its properties. - [`rmp::Tilemap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html) — A level read from an LDtk or a Tiled file: its tile layers, which cells are solid, and the objects placed in it. - [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) — rmp::Dialogue -- conversations written in Yarn Spinner 3. - [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) — rmp/save.h — rmp::Value, and saving the game. - [`rmp::lang`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html) — rmp::Text and rmp::lang -- the game in more than one language. ## From `rmp/app.h` rmp/app.h — the entry point, closing the app, and how the world fits the window. ## [`rmp::global`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global)() — the state that outlives a scene change ```cpp rmp::global().coins += 10; ``` 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. There is no registration, no name, no lookup: the TYPE is the key. WHY IT IS CALLED [`global`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#global) AND NOT SOMETHING SOFTER. Because that is what it is, and a name that hides it would get used for things that should have been passed as arguments. A scene owns its state and loses it when it leaves the stack — which is exactly right for the enemies and exactly wrong for the player's progress. This is for the second kind, and the blunt name is there so that reaching for it is a decision rather than a habit. It is not a singleton in the pattern sense: T knows nothing about this, needs no `instance()` method, no private constructor and no macro. Any default- constructible type works, including a plain struct you wrote a minute ago. THE ORDER IT IS DESTROYED IN is reverse of first use, and it happens while the window is still open — so a global holding an [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) releases it against a GL context that still exists. That is not free of charge to get right; see `begin_stop()` in src/rmp/app/app.cpp. ### `global` template T &global() function [include/rmp/app.h:240](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L240-L254) ## From `rmp/assets.h` `rmp::assets::` — loading from resources/ ## A sprite sheet, read straight out of an Aseprite file ### `SheetFrame` struct SheetFrame struct [include/rmp/assets.h:241](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L241-L244) One frame of a sheet: where it is in the packed texture, and how long it shows. | Field | Type | Default | What it is | |---|---|---|---| | `source` | `Rectangle` | `{}` | Where this frame is in the packed texture | | `seconds` | `float` | `0` | From the file, so it plays at the speed you drew it | ### `SheetTag` struct SheetTag struct [include/rmp/assets.h:248](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L248-L254) One tag of the .aseprite: a named run of frames, and the direction Aseprite plays it in. Its name is what `sprite.play("walk")` looks for. | Field | Type | Default | What it is | |---|---|---|---| | `name` | `std::string` | | The tag's name in Aseprite | | `from` | `int` | `0` | The first frame, an index into [`SheetData::frames`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html#frames) | | `to` | `int` | `0` | Inclusive, the way Aseprite counts | | `ping_pong` | `bool` | `false` | Aseprite's "Ping-pong" direction: forwards, then back | | `reverse` | `bool` | `false` | Aseprite's "Reverse" direction: last frame first | ### `SheetSlice` struct SheetSlice struct [include/rmp/assets.h:260](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L260-L265) One slice of the .aseprite: a named rectangle the artist drew with the slice tool — an icon of an atlas, the frame of a button. With "9-Slices" ticked in Aseprite it also has a centre, which is what makes it a nine-slice ([`rmp::ui::nine_slice()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#nine_slice)). Read from the first frame the slice has a key on. | Field | Type | Default | What it is | |---|---|---|---| | `name` | `std::string` | | The slice's name in Aseprite | | `bounds` | `Rectangle` | `{}` | Where it is in the PACKED texture, in pixels | | `nine` | `bool` | `false` | It has 9-slices: `center` is its middle | | `center` | `Rectangle` | `{}` | The middle, relative to `bounds`; only when `nine` | ### `SpriteSheet` using SpriteSheet = detail::Resource alias [include/rmp/assets.h:311](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L311) A loaded sprite sheet, from [`rmp::assets::load_sheet()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_sheet). It shares and releases like the handles below, and `raw()` is its SheetData. ### `Texture`, `Image`, `Font`, `Sound`, `Music`, `Shader`, `RenderTexture` using Texture = detail::Resource using Image = detail::Resource<::Image, detail::ResourceKind::IMAGE> using Font = detail::Resource<::Font, detail::ResourceKind::FONT> using Sound = detail::Resource<::Sound, detail::ResourceKind::SOUND> using Music = detail::Resource<::Music, detail::ResourceKind::MUSIC> using Shader = detail::Resource<::Shader, detail::ResourceKind::SHADER> using RenderTexture = detail::Resource alias [include/rmp/assets.h:319](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L319) The resource handles: each one is a detail::Resource around the raylib struct it is named after (Texture2D and RenderTexture2D for the two textures), and converts to it wherever raylib takes one. [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture), [`rmp::Image`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Image), [`rmp::Font`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Font) and [`rmp::Sound`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Sound) come from the loaders in [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) below. Nothing in [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) returns an [`rmp::Music`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Music), [`rmp::Shader`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Shader) or [`rmp::RenderTexture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#RenderTexture); music is played by name through [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) instead. ## From `rmp/behavior.h` rmp/behavior.h — the catalogue. ### `PathOptions` struct PathOptions struct [include/rmp/behavior.h:71](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L71-L75) How [`rmp::find_path()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#find_path) looks for a way through a map. | Field | Type | Default | What it is | |---|---|---|---| | `diagonal` | `bool` | `true` | Eight directions; false = four. A corner is never cut | | `clearance` | `float` | `0` | Keeps this many units from every solid cell: half the walker's width | ### `find_path` std::vector find_path(const Tilemap &map, Vector2 from, Vector2 to, const PathOptions &options = {}) function [include/rmp/behavior.h:82](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L82-L83) The way from `from` to `to` across the map's cells, around its solid ones: the centres of the cells to walk through, ending on `to` itself. A* on the grid, with diagonal steps that never cut the corner of a solid cell. Empty when there is no way, when either end is outside the map or solid, and for a map with no cells. `from` itself is not on it. ## From `rmp/dialogue.h` [`rmp::Dialogue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html) — conversations written in Yarn Spinner 3. ### `DialogueMarkup` struct DialogueMarkup struct [include/rmp/dialogue.h:103](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L103-L112) A piece of a line's markup: [wave]these words[/wave] is "wave" at the place of the first word, for as many characters (code points) as they have. Positions are in the line's `text`. | Field | Type | Default | What it is | |---|---|---|---| | `name` | `std::string` | | "wave", "color", "speed"...: what is in the brackets first | | `position` | `int` | `0` | The first character it covers, in code points of `text` | | `length` | `int` | `0` | How many it covers; 0 for a self-closing [pause=0.4/] | | `properties` | `std::vector>` | | Name = value, as written | std::string property(std::string_view key) const A property's value, or "" when the markup has none of that name. ### `DialogueLine` struct DialogueLine struct [include/rmp/dialogue.h:115](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L115-L122) A line of the conversation, ready to show. | Field | Type | Default | What it is | |---|---|---|---| | `id` | `std::string` | | Its #line: id, the key of its translation | | `speaker` | `std::string` | | Who says it ("Mika: ..."), or empty | | `text` | `std::string` | | What is said, in the current language, without the speaker or markup | | `markup` | `std::vector` | | Where the markup was, in `text` | | `tags` | `std::vector` | | Its #hashtags, without the # | ### `DialogueOption` struct DialogueOption struct [include/rmp/dialogue.h:125](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L125-L131) One of the choices the player has now. | Field | Type | Default | What it is | |---|---|---|---| | `id` | `std::string` | | Its #line: id, the key of its translation | | `text` | `std::string` | | In the current language, without markup | | `available` | `bool` | `true` | False: its condition failed; shown disabled, or not at all | | `markup` | `std::vector` | | Where the markup was, in `text` | | `tags` | `std::vector` | | Its #hashtags, without the # | ### `DialogueSaliency` enum class DialogueSaliency : std::uint8_t enum [include/rmp/dialogue.h:134](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L134-L139) How a line group (=>) or a node group (when:) picks among what can run. | Value | | Means | |---|---|---| | `FIRST` | | The first whose conditions pass | | `BEST` | | The one with the most conditions that pass | | `LEAST_SEEN` | | The least seen, the most specific of those: the default | | `RANDOM_LEAST_SEEN` | | As LEAST_SEEN, a random one among equals | ## From `rmp/object.h` rmp/object.h — an entity inside a scene, and the handle that outlives it. ## Shapes ### `ShapeKind` enum class ShapeKind enum [include/rmp/object.h:69](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L69) Which of the two a Shape is. RECTANGLE is a box of `size` and CIRCLE a disc of `radius`. NONE is no shape at all: nothing is drawn, and a `collider` of NONE means the object collides as its `shape`, or as its sprite's frame. | Value | | Means | |---|---|---| | `NONE` | | | | `RECTANGLE` | | | | `CIRCLE` | | | ### `Shape` struct Shape struct [include/rmp/object.h:75](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L75-L87) A rectangle or a circle around an object's centre, moved by `offset` and sized by the object's `scale`. An Object's `shape` is what it draws when it has no sprite and, unless its `collider` says otherwise, what it collides as. [`rect()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#rect) and [`circle()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#circle) make one. | Field | Type | Default | What it is | |---|---|---|---| | `kind` | `ShapeKind` | `ShapeKind::NONE` | Declaration order IS the order these get written in a designated initialiser, because C++20 requires that and rejects any other order. Kind first because [`rect()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#rect)/[`circle()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#circle) set it, then the sizing, then the appearance. | | `size` | `Vector2` | `{}` | RECTANGLE: width and height | | `radius` | `float` | `0` | CIRCLE | | `offset` | `Vector2` | `{}` | From the object's centre | | `color` | `Color` | `WHITE` | The fill, or the outline when not filled | | `filled` | `bool` | `true` | False draws the outline only | | `thickness` | `float` | `1` | The outline's width when filled = false; a CIRCLE ignores it | ### `rect`, `circle` Shape rect(Vector2 size) Shape circle(float radius) function [include/rmp/object.h:90](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L90) The two spellings that read like what they make. ## The edge of the world ### `Edge` enum class Edge enum [include/rmp/object.h:157](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L157-L163) What an object does at the edge of its `bounds` — the map's, or the view's, when `bounds` is empty. CLAMP and BOUNCE act as soon as `world_bounds()` crosses an edge; WRAP and DESTROY wait until it is entirely outside. Bounds that are not a finite box do nothing, said once. | Value | | Means | |---|---|---| | `NONE` | | The default: objects may leave, and do | | `CLAMP` | | Stops at the edge a paddle, a player, a cursor | | `BOUNCE` | | Flips the velocity a Pong or Breakout ball | | `WRAP` | | Comes back the other side Asteroids | | `DESTROY` | | Is discarded once it has left bullets, particles (it has to have been inside) | ## What `spawn()` takes. The order is the order it gets written in ### `ObjectOptions` struct ObjectOptions struct [include/rmp/object.h:607](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L607-L618) The starting values [`Scene::spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) gives a new object. Each field sets the Object field of the same name, except `size`, which is a shorter way to write `shape`: ```cpp auto &wall = spawn({ .position = { 400, 225 }, .size = { 20, 200 } }); ``` | Field | Type | Default | What it is | |---|---|---|---| | `position` | `Vector2` | `{}` | THE CENTRE, in world units | | `size` | `Vector2` | `{}` | Shorthand for a RECTANGLE shape of this size | | `shape` | `Shape` | `{}` | The full form; used instead of `size` when set | | `velocity` | `Vector2` | `{}` | World units per second | | `scale` | `Vector2` | `{ 1, 1 }` | Multiplies the shape, the collider and the sprite | | `rotation` | `float` | `0` | Degrees, as raylib counts them | | `layer` | `int` | `0` | Draw order: a higher layer draws on top | | `visible` | `bool` | `true` | False: not drawn, but still updated and collided | | `edges` | `Edge` | `Edge::NONE` | What happens at the edge of `bounds` | | `bounds` | `Rectangle` | `{}` | {0,0,0,0} = the map's bounds, or the view without a map | ### `RayQuery` struct RayQuery struct [include/rmp/object.h:946](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L946-L965) What [`Scene::raycast()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#raycast) and [`Scene::raycast_all()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#raycast_all) test: the segment from `from` to `to`, against the scene's objects. The map's tiles are not hit; ask [`Tilemap::solid_at()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#solid_at) about those. Down here, below Object, and not with the block about raycasting above, because `ignore` is a handle and a handle needs Object complete. | Field | Type | Default | What it is | |---|---|---|---| | `from` | `Vector2` | `{}` | Where the ray starts, in world units | | `to` | `Vector2` | `{}` | Where it ends; nothing beyond it is hit | | `mask` | `unsigned` | `0xFFFFFFFFu` | The same layers as the collision pass | | `ignore` | `Handle` | `{}` | Normally whoever is shooting: `.ignore = self.handle()`. Empty ignores nothing, and so does the handle of an object that is gone. | | `solid_only` | `bool` | `false` | Only objects that are `solid`. A ground check 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 resolves. Without this the nearest hit under a character is whatever trigger happens to be there, and the character walks through the floor. Last in the struct, because added before the others it would shift a POSITIONAL initialiser — `RayQuery{ a, b, mask, self.handle() }` — onto the wrong fields. A designated one does not mind: it names its fields, in the order they are declared, and a new one in between is simply left out. | ### `RayHit` struct RayHit struct [include/rmp/object.h:968](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L968-L976) RayHit lives below Object too, for the same reason. | Field | Type | Default | What it is | |---|---|---|---| | `object` | `Handle` | | What was hit; a handle, so it is safe to keep across frames | | `point` | `Vector2` | `{}` | Where, in world coordinates | | `normal` | `Vector2` | `{}` | The surface normal there, pointing back at the ray | | `distance` | `float` | `0` | From the ray's origin | explicit operator bool() const `if (auto hit = raycast(a, b))` is the shape this is for. ## From `rmp/text.h` [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) and [`rmp::lang`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html) — the game in more than one language. ### `TextOptions` struct TextOptions struct [include/rmp/text.h:47](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L47-L49) What else a translated text can say: the context that tells two texts with the same words apart ("Open" a door, "Open" a file). | Field | Type | Default | What it is | |---|---|---|---| | `context` | `std::string_view` | `{}` | The row's context column; empty: none | ============================================================================== # rmp::ads > rmp::ads — interstitial and rewarded ads. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ads.html namespace `#include ` `rmp::ads` — interstitial and rewarded ads. Real calls on Android, no-ops everywhere else, so ad code compiles on every target without a single #ifdef. And when `[android.admob] enabled` = false in raylib_multiplatform.toml, the Google Mobile Ads SDK is not in the build at all and these still compile and still do nothing. The chain behind them: thirdparty/raymob/admob.c (JNI) -> NativeLoader.java -> AdmobBridge.java. The ad unit ids come from [android.admob]. A wrapper, not a layer: src/rmp/ads/ads.cpp forwards these to the C functions in , and that header stays out of yours. Those stay C because they are the real JNI boundary, and because a game in plain C — the shape of examples/plain_c/src/main.c — has no namespace to call into and can call them directly: #include , which is on a plain C game's include path on every target and compiles to no-ops off Android, as these do. examples/ads/01_interstitial and examples/ads/02_rewarded are both kinds of ad, end to end. Typical use: ```cpp rmp::ads::request_rewarded(); // preload, e.g. in on_ready() ... if (rmp::ads::is_rewarded_loaded()) rmp::ads::show_rewarded(); if (rmp::ads::take_reward_earned()) grant(rmp::ads::reward_amount()); ``` Before shipping with ads on, read the consent (UMP) warning in README.md. ## Interstitial ### `request_interstitial` void request_interstitial() function [include/rmp/ads.h:39](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L39) Start preloading one. Do it early; loading takes seconds. ### `is_interstitial_loaded` bool is_interstitial_loaded() function [include/rmp/ads.h:42](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L42) Has one finished loading? ### `show_interstitial` void show_interstitial() function [include/rmp/ads.h:45](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L45) Show it. The ad is consumed: request another one to show again. ## Rewarded ### `request_rewarded` void request_rewarded() function [include/rmp/ads.h:51](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L51) Start preloading a rewarded ad, from `[android.admob] rewarded_id`. Do it early, and again after each one is shown: loading takes seconds. ### `is_rewarded_loaded` bool is_rewarded_loaded() function [include/rmp/ads.h:54](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L54) Has one finished loading? A button that shows it should be live only then. ### `show_rewarded` void show_rewarded() function [include/rmp/ads.h:59](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L59) Show it. The ad is consumed: request another one to show again. Nothing happens when none has loaded, and the reward is not here: it arrives through `take_reward_earned()`, and only if the player watched enough of the ad. ### `take_reward_earned` bool take_reward_earned() function [include/rmp/ads.h:63](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L63) True once per earned reward, and clears the flag. Poll it from the game loop; the amount is then in `reward_amount()`. ### `reward_amount` int reward_amount() function [include/rmp/ads.h:67](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ads.h#L67) The amount of the last reward earned, as set on the ad unit in AdMob. 0 until one is earned, and always 0 off Android. ============================================================================== # rmp::app > rmp/app.h — the entry point, closing the app, and how the world fits the window. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html namespace `#include ` rmp/app.h — the entry point, closing the app, and how the world fits the window. You write `on_ready()`, `on_frame(float)` and `on_exit()`; RMP_ENTRY_POINT writes the runner for your platform. There are three, and the difference between them is who owns the frame loop: ```text desktop we do: a main() with a while loop, the ordinary raylib shape. web the browser does. See the PLATFORM_WEB block below — this is not a style choice, a while loop there costs you ASYNCIFY. iOS UIKit does, so there is no loop to write and nothing to return to: three callbacks it calls instead. ``` All three do the same things around your code: start the smoke test, open the asset pack, run you, report to CI whether any asset failed to load, and close the pack afterwards. None of it is yours to remember. WHAT THIS HEADER DOES NOT INCLUDE, and why it matters. Not rmp/ui.h and not rmp/assets.h, although a run closes the UI and opens the asset pack. Naming [`rmp::ui::shutdown()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#shutdown) or [`rmp::assets::init()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#init) here would make every translation unit with an entry point pay for the whole interface layer. So the macros DO nothing themselves: they call the functions in `rmp::app::detail`, compiled once in src/rmp/app/app.cpp, which is where those includes live. A macro is only the platform's entry-point shape. The rule that comes out of it, and it governs every header we add: 1. Include none of our headers. Forward-declare instead. 2. If a namespace or a by-value type makes that impossible, include it and write down here why. 3. If two headers end up needing each other, one of them should not exist. rmp/config.h IS THE ONE EXCEPTION, and it is in every public header of ours rather than just this one. It costs nothing — one include, of the generated file of #defines, which includes nothing; 27 ms against an empty file's 28, which is below measurement noise — and rule 1 exists for compile time and coupling, so a leaf header that costs neither is not what the rule is aimed at. What it buys is that RMP_WINDOW_* and the rest are simply THERE, in scenes and objects and everywhere else, with nothing to remember. See rmp/config.h. ### `quit` void quit() function [include/rmp/app.h:104](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L104) Ask the app to close. Call it from anywhere — a menu callback, a game-over screen, ten frames deep in your own code. It does not need to know where `main()` is, and there is no value to propagate back up through your call stack. ```cpp if (rmp::ui::button("Quit")) rmp::app::quit(); ``` It RETURNS. What it does is raise a flag that the entry point checks at the top of the next iteration, so the frame you are in finishes normally and then the stop hook runs, the window closes and the asset pack is released — the same shutdown as closing the window with the X. That is the whole reason not to call std::`exit()` yourself: std::exit ends the process immediately, so the stop hook never runs, `CloseWindow()` never runs, and on Android the Activity is left behind while its process disappears. It is not an exception either, and deliberately: exceptions are switched off in plenty of game builds, unwinding through raylib's C frames is undefined, and throwing mid-frame would leave `BeginDrawing()` unbalanced and a UI frame open. A flag costs one branch per frame and cannot leave anything half done. Per platform: ```text desktop, BSD, Web the frame loop ends and main() returns Android plus ANativeActivity_finish(), so the Activity actually goes away instead of leaving a task behind iOS NOTHING. It logs a warning and returns. ``` ```cpp Apple's QA1561 is explicit: an iOS app that terminates itself "will appear to the user to have crashed", and App Review rejects apps that crash or appear to. A Quit control also fails the Human Interface Guidelines by itself. So the same source ships everywhere and the button is simply inert on iPhone — hide it with #if !defined(PLATFORM_IOS) if a dead control bothers you. ``` ### `quit_requested` bool quit_requested() function [include/rmp/app.h:108](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L108) Has `quit()` been called? The entry point uses this; you are unlikely to need it unless you want to skip work on the way out. ### `Stretch` enum class Stretch enum [include/rmp/app.h:148](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L148) How the world fits a window that is not the size `[window] says` — a desktop window dragged wider, a phone of another shape, a TV. The `[window] width` and height are the DESIGN size: what the game was drawn for. s below is how much bigger the window is than that, min(width / design width, height / design height): the most the whole design fits. ```text NONE the world at 1:1 around the camera: a bigger window shows more of it and a smaller one less, and nothing is scaled. What every game got before there was a choice. LETTERBOX the design, scaled by s and centred, the rest of the window bars of the clear colour. Every player sees exactly the same part of the world, the interface stays inside it, and nothing is ever 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. A level that scrolls anyway, where seeing further is fine. ``` The camera and the pointer follow it: [`Camera::view()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html#view), `to_world()`, [`rmp::input::pointer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer) and a click on an object are right in every mode, and [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) keeps the interface inside the game's area. A game that draws its world in `_draw()` with its own `BeginMode2D()` goes through `scene.camera.raylib()` to get it too. | Value | | Means | |---|---|---| | `NONE` | | | | `LETTERBOX` | | | | `EXPAND` | | | ### `stretch` Stretch stretch() function [include/rmp/app.h:151](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L151) The mode in use. It starts as `[window] stretch` in raylib_multiplatform.toml. ### `set_stretch` void set_stretch(Stretch mode) function [include/rmp/app.h:157](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/app.h#L157) Change it, from anywhere and at once: the next thing that asks — the camera, the pointer, the interface — sees the new mode. The examples share one .toml, so the ones that need another mode set it here, in their first scene's `_ready()`. ============================================================================== # rmp::assets > rmp::assets:: — loading from resources/ Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html namespace `#include ` `#include ` ## From `rmp/assets.h` `rmp::assets::` — loading from resources/ ### `init` void init() function [include/rmp/assets.h:335](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L335) Detect and open the resource pack, if there is one, and route raylib's own file loading through it. Called for you by the entry point; calling it twice is harmless. ### `shutdown` void shutdown() function [include/rmp/assets.h:339](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L339) Release the pack and unhook raylib's loaders. Called for you after your stop hook. ### `using_pack` bool using_pack() function [include/rmp/assets.h:342](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L342) True when assets are being served from a .rres pack. ### `load_image`, `load_texture` rmp::Image load_image(std::string_view name) rmp::Texture load_texture(std::string_view name) function [include/rmp/assets.h:353](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L353) Load by resource name (e.g. "rabbit.png"). Nothing to unload: the returned value releases itself when the last copy goes, and asking twice for the same name gives you the SAME resource with the reference count at two. A name that is in neither the pack nor resources/ gives an empty resource rather than a crash, and so does a file that is there and does not decode — a font included: not raylib's built-in one in its place. `valid()` tells them apart, and drawing an empty one draws nothing — a hole in the picture, not a dead process. Both count in `failed_loads()`. ### `load_sound` rmp::Sound load_sound(std::string_view name) function [include/rmp/assets.h:358](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L358) The sound device opens on the first call, the same lazy way [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) opens it; on a machine with no device this comes back empty. ### `load_font` rmp::Font load_font(std::string_view name, int font_size) function [include/rmp/assets.h:364](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L364) font_size is the baked glyph size, and it is part of the cache key: the same font at 16 and at 32 is two resources, because it is two textures. It is 1 to 1024: anything else is an empty font, a failed load and one warning — a negative size aborted inside stb_truetype. ### `load_sheet` rmp::SpriteSheet load_sheet(std::string_view name) function [include/rmp/assets.h:372](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L372) An .aseprite or .ase from resources/. Every frame is packed into one texture in a single row, so drawing a hundred enemies from the same sheet is one texture bind. Tags, frame ranges and per-frame durations come with it. On a machine with no GPU the texture is left empty and the metadata is still there, which is what lets tests/animation_test.cpp exist. ### `load_map` rmp::Tilemap load_map(std::string_view name) rmp::Tilemap load_map(std::string_view name, std::string_view level) function [include/rmp/assets.h:386](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L386) A level: an LDtk project (.ldtk) or a Tiled map (.json), told apart by the extension. See rmp/tilemap.h for what each editor's conventions mean here, and which of the two is maintained. The tileset images — and an LDtk project's separate level files — are loaded by FILE NAME through the same asset layer, so they come out of resources.rres in a release and out of resources/ while developing without the map knowing which. `level` picks an LDtk level by its identifier; without it, the first level. Tiled maps have one level and ignore it. Returns an empty map and says why if it cannot be read: `map = rmp::assets::load_map("world.ldtk");` ### `load_data` std::vector load_data(std::string_view name) function [include/rmp/assets.h:394](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L394) The bytes of a file — a level, a shader's source, JSON, anything whose meaning only the caller knows — as a vector that frees itself. Not cached: every call reads the file again. Empty when the name is in neither the pack nor resources/. Empty when it is not there ### `load_value` rmp::Value load_value(std::string_view name) function [include/rmp/assets.h:404](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L404) A JSON file — tuning numbers, a table of items, dialogue — read into an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html), which remembers its file: while a Debug build runs on the desktop, `if (tuning.changed()) tuning.reload();` picks up an edit made in any text editor ([`rmp::Value::changed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#changed) says how). An empty Value, said once, when the file is not there or is not JSON. Include rmp/save.h to use it: ```cpp #include static rmp::Value tuning = rmp::assets::load_value("tuning.json"); ``` ### `requested_loads`, `failed_loads` int requested_loads() int failed_loads() function [include/rmp/assets.h:410](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L410) How many `rmp::assets::` loads were asked for, and how many gave nothing usable: nothing in the pack and nothing on disk, or a file that is there and does not decode. The entry point reports these to the CI boot gate; you are unlikely to need them yourself. ## From `rmp/dialogue.h` [`rmp::Dialogue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html) — conversations written in Yarn Spinner 3. ### `load_dialogue` Dialogue load_dialogue(std::string_view file) Dialogue load_dialogue(std::span files) function [include/rmp/dialogue.h:388](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L388) A .yarn file of resources/, compiled. Its errors, if any, are in `errors()`, said in the log and, in a debug build, on screen. ============================================================================== # rmp::audio > rmp/audio.h — sound effects and music, by name. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html namespace `#include ` rmp/audio.h — sound effects and music, by name. ```cpp rmp::audio::play("coin"); // coin.wav, coin.ogg... rmp::audio::play("hit", { .volume = 0.7f, .pitch = 1.2f }); rmp::audio::music("level1"); // starts, or replaces rmp::audio::set_volume(rmp::audio::Bus::SFX, 0.5f); ``` NO LIFE CYCLE IN SIGHT, the same way [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) has none. The device opens on the first call that needs it — exactly as [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) opens Clay on its first `begin()` — so a game with no sound never opens it. The music is streamed, and the `UpdateMusicStream()` it needs every frame is the app's job, not yours. And everything is released on the way out, before the device closes, in the order that does not crash. A MACHINE WITH NO SOUND IS NOT AN ERROR. A CI runner, a server, a headless box: the device fails to open, the framework says so once, and every call here becomes a silent no-op. The game runs — under `[dev] strict` too, which aborts on mistakes in the game and this is not one. THE NAMES ARE LOGICAL. "coin" finds coin.wav, coin.ogg, coin.mp3 or coin.qoa in resources/ — in that order, the first that exists — and "coin.ogg" finds exactly that. So a sound can be re-exported in another format without touching the code, and the pack and the loose files are the same to it, as they are to every other asset. OVERLAPPING IS THE DEFAULT. Playing the same effect while it is still playing starts another voice (up to four) instead of restarting the first, so a machine gun sounds like one and not like a stuck record. On the web, browsers keep audio muted until the player has clicked, touched or pressed a key. That is the browser's rule and not something a game can get round; a game that starts its music on the title screen is heard from the first such input on. A gamepad button does not count — browsers do not treat it as a gesture — so a gamepad-only player hears nothing until then. ### `Bus` enum class Bus enum [include/rmp/audio.h:48](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L48) The three volumes a settings screen offers, and what they multiply. MASTER scales everything; MUSIC and SFX scale their own on top of it. The starting values come from `[audio] in` raylib_multiplatform.toml. | Value | | Means | |---|---|---| | `MASTER` | | | | `MUSIC` | | | | `SFX` | | | ### `PlayOptions` struct PlayOptions struct [include/rmp/audio.h:52](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L52-L56) How one `play()` sounds. Declaration order is the order they are written in, as C++20 requires. | Field | Type | Default | What it is | |---|---|---|---| | `volume` | `float` | `1.0f` | This play only; times the SFX bus, times MASTER | | `pitch` | `float` | `1.0f` | 2 = an octave up, 0.5 = an octave down; 1/16..16, clamped | | `pan` | `float` | `0.0f` | -1 = left, 0 = centre, 1 = right (raylib 6's range) | ### `play` void play(std::string_view name, const PlayOptions &options = {}) function [include/rmp/audio.h:61](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L61) A sound effect. Loaded the first time it is asked for and kept, so the second play costs nothing; a name that does not exist — a name with a NUL byte inside is no file's — says so once and plays nothing. ### `music` void music(std::string_view name, bool loop = true) function [include/rmp/audio.h:67](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L67) Start the music, looping, or replace whatever is playing. Asking for the track that is already playing is NOT a restart — a scene that calls music("level1") in its `_ready()` does not jump the song back to the start every time the player dies and the scene is changed to itself. ### `stop_music` void stop_music() function [include/rmp/audio.h:70](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L70) Stop the music and let the track go; music("") does the same. Nothing happens when none is playing. ### `music_playing` bool music_playing() function [include/rmp/audio.h:73](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L73) Whether music is playing right now. False with no device. ### `set_volume`, `volume` void set_volume(Bus bus, float volume) float volume(Bus bus) function [include/rmp/audio.h:78](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L78) 0..1, clamped; a NaN is ignored rather than stored. Takes effect at once, on the music already playing too. Never opens the device: a settings screen can show and move the sliders in a game that has made no sound yet. ### `available` bool available() function [include/rmp/audio.h:83](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/audio.h#L83) Whether the device is open and working. False until the first sound, and false for good on a machine with none — asking does not open it. ============================================================================== # rmp::behavior > rmp/behavior.h — the catalogue. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html namespace `#include ` rmp/behavior.h — the catalogue. ```cpp ball.add({ .speed = 320 }); player.add({ .speed = 220 }); ``` A behavior is any struct with `void _update(rmp::Object &, float)`. The model is explained above [`Object::add`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#add) in rmp/object.h, and the part worth repeating here is that every one of these is a struct exactly like one of yours: there is no extension API, because there is nothing to extend. THE FIELDS ARE THE CONFIGURATION, and they are hot: ```cpp player.get()->speed = 400; // a power-up ``` NONE OF THEM CHOOSES A DIRECTION FOR YOU. A behavior contributes behaviour, not intention: which way the Pong ball is served is a rule of the game, and picking it would be the framework deciding something that is not its to decide. So a Ball starts still, a Projectile travels the way you pushed it, a Follow chases the handle you gave it, and a TopDown reads the actions you named. WHAT THEY WRITE IS A NUMBER. A behavior writes into its object — the position, the velocity, the scale — only finite numbers: a field that is NaN or an infinity, or one so large the arithmetic overflows, leaves the object as it was, and the behavior says so once (a field that is NaN is named). A hook handed a delta that is not a number of seconds, 0 or more, counts it as 0 and says so once; the framework never hands one. PAUSED, NOT REMOVED. `object.enable(false)` stops a behavior's hooks and keeps its state; a Chase pauses the Patrol it interrupts that way, and a StateMachine's states say which behaviors run while they are on. FROM THE EDITOR. The behaviors a level designer places — Patrol, Chase, Orbit, Shooter, Hitbox, Collectible — have `B::from(const MapObject &)`, which reads the entity's fields by the names written above each of them, and leaves every field the entity does not have at its default: ```cpp map.on_object("Bat", [](rmp::Scene &s, const rmp::MapObject &o) { auto &bat = s.spawn({ .position = o.position }); bat.add(rmp::behavior::Patrol::from(o)); }); ``` WHAT IS NOT HERE, and why, in short: `tetromino`, `formation` and `paddle` are three games with a different name on them. ## On pages of their own - [`rmp::behavior::TopDown`](https://omardev29.github.io/rmp-docs/reference/behaviors/TopDown.html) — Eight directions, and the sprite chosen from the one you are facing. - [`rmp::behavior::Platformer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Platformer.html) — Gravity, jumping, ground, coyote time and a buffered jump. - [`rmp::behavior::Runner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Runner.html) — Constant forward motion that SPEEDS UP over time, with a jump and a duck. - [`rmp::behavior::Ball`](https://omardev29.github.io/rmp-docs/reference/behaviors/Ball.html) — Bounces, keeps its pace, and leaves a paddle at an angle that depends on where it hit. - [`rmp::behavior::Projectile`](https://omardev29.github.io/rmp-docs/reference/behaviors/Projectile.html) — Travels the way you pushed it and is discarded when it leaves or hits. - [`rmp::behavior::Follow`](https://omardev29.github.io/rmp-docs/reference/behaviors/Follow.html) — Chases a handle, with a speed and a distance it stops at. - [`rmp::behavior::Tween`](https://omardev29.github.io/rmp-docs/reference/behaviors/Tween.html) — Moves one property of its object from `from` to `to` over `seconds`, along an Ease. - [`rmp::behavior::GridSnap`](https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html) — Squares the position with a grid, AFTER everything that moves it. - [`rmp::behavior::Parallax`](https://omardev29.github.io/rmp-docs/reference/behaviors/Parallax.html) — A background layer that scrolls at its own factor and repeats itself with no seam. - [`rmp::behavior::Spawner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html) — Produces objects every N seconds, or every N units TRAVELLED. - [`rmp::behavior::Timer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Timer.html) — Calls you every N seconds. - [`rmp::behavior::Lifespan`](https://omardev29.github.io/rmp-docs/reference/behaviors/Lifespan.html) — Discarded after N seconds. - [`rmp::behavior::Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) — Hit points, a window of invulnerability with a blink, and death. - [`rmp::behavior::Area`](https://omardev29.github.io/rmp-docs/reference/behaviors/Area.html) — A region that says who comes and goes: a trigger, a door's sensor, a pit, a shop's counter. - [`rmp::behavior::Hitbox`](https://omardev29.github.io/rmp-docs/reference/behaviors/Hitbox.html) — What hurts: a sword's swing, a spike, a bullet, an explosion. - [`rmp::behavior::Talker`](https://omardev29.github.io/rmp-docs/reference/behaviors/Talker.html) — Someone to talk to. - [`rmp::behavior::Collectible`](https://omardev29.github.io/rmp-docs/reference/behaviors/Collectible.html) — A coin, a key, a heart. - [`rmp::behavior::Shooter`](https://omardev29.github.io/rmp-docs/reference/behaviors/Shooter.html) — Fires. - [`rmp::behavior::Patrol`](https://omardev29.github.io/rmp-docs/reference/behaviors/Patrol.html) — Goes from waypoint to waypoint — round in a loop, or back and forth with `ping_pong` — waiting `wait` seconds at each. - [`rmp::behavior::Pathfind`](https://omardev29.github.io/rmp-docs/reference/behaviors/Pathfind.html) — Walks to a target, or to a point, around the map's walls: `rmp::find_path()`, asked again every `repath_every` seconds, and followed at `speed`. - [`rmp::behavior::Chase`](https://omardev29.github.io/rmp-docs/reference/behaviors/Chase.html) — Sees a target and goes after it. - [`rmp::behavior::Orbit`](https://omardev29.github.io/rmp-docs/reference/behaviors/Orbit.html) — Circles a handle or a point: a shield of blades, a moon, a fairy. - [`rmp::behavior::Animator`](https://omardev29.github.io/rmp-docs/reference/behaviors/Animator.html) — Plays the tag that fits what the object is doing: `die` once its Health is dead, `hurt` while it is invulnerable after a hit, `jump` and `fall` in the air (with gravity), `run` while it moves and `idle` while it does not — and mirrors it with flip_x by the way it moves. - [`rmp::behavior::Draggable`](https://omardev29.github.io/rmp-docs/reference/behaviors/Draggable.html) — Picked up with the pointer and put down somewhere. - [`rmp::behavior::StateMachine`](https://omardev29.github.io/rmp-docs/reference/behaviors/StateMachine.html) — Named states and the moves between them: an enemy that idles, patrols, chases and flees; a boss's phases. ## Tween: animate one property, with easing, looping and ping-pong ### `Ease` enum class Ease enum [include/rmp/behavior.h:284](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L284) The curve a Tween's value follows from `from` to `to` over its `seconds`. LINEAR moves at a constant rate; IN starts slow and speeds up; OUT starts fast and slows into `to`; IN_OUT is slow at both ends and fastest in the middle. The last three are quadratic, and a ping_pong's way back runs the same curve in reverse. | Value | | Means | |---|---|---| | `LINEAR` | | | | `IN` | | | | `OUT` | | | | `IN_OUT` | | | ### `Property` enum class Property enum [include/rmp/behavior.h:288](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L288-L295) Which field of its object a Tween writes, on every update it runs. ALPHA takes 0 to 255 and clamps to that range. | Value | | Means | |---|---|---| | `POSITION_X` | | Position.x, the centre | | `POSITION_Y` | | Position.y, the centre | | `SCALE_X` | | Scale.x | | `SCALE_Y` | | Scale.y | | `ROTATION` | | Rotation, in degrees | | `ALPHA` | | The shape's colour, or the sprite's tint | ## World and production ### `MAX_SPAWNED` inline constexpr int MAX_SPAWNED = 64 constant [include/rmp/behavior.h:380](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L380) How many of its own objects one Spawner keeps track of, which is the largest `max_alive` it can enforce. A fixed array and not a std::vector because costs 92 ms in every translation unit that includes a behavior, and a spawner that needs hundreds of things alive at once is a pool, not a spawner. A `max_alive` above this warns once and is treated as this. ## Moving on its own ### `Face` enum class Face enum [include/rmp/behavior.h:906](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L906-L910) Which way an Orbit turns its object. | Value | | Means | |---|---|---| | `NONE` | | Its rotation is left alone | | `CENTRE` | | It looks at what it circles | | `OUTWARD` | | It looks away from it | ## The sprite, the pointer and the brain ### `AnimationRule` struct AnimationRule struct [include/rmp/behavior.h:940](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L940-L943) A rule of an Animator: play `tag` while `when` says so. The rules are asked in order, before anything the Animator works out itself. | Field | Type | Default | What it is | |---|---|---|---| | `tag` | `std::string` | | The tag played while `when` says so | | `when` | `Condition` | | Asked with the object, every update | ### `State` struct State struct [include/rmp/behavior.h:1022](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1022-L1030) One state of a StateMachine: what it does on the way in, every frame, on the way out, and which behaviors run while it is on. | Field | Type | Default | What it is | |---|---|---|---| | `name` | `std::string` | | What transitions and `go()` call it | | `on_enter` | `Callback` | | Once, as the machine moves into it | | `on_update` | `Callback` | | (the object, delta) | | `on_exit` | `Callback` | | Once, as the machine moves out of it | | `enables` | `std::vector` | | The behaviors that run in this state: [`rmp::behavior::kinds`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-behavior.html#kinds)(). Every behavior some state names is paused in the states that do not. | ### `Transition` struct Transition struct [include/rmp/behavior.h:1033](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1033-L1037) A move from one state to another, taken when `when` says so. | Field | Type | Default | What it is | |---|---|---|---| | `from` | `std::string` | | "" = from any state | | `to` | `std::string` | | The state it moves to | | `when` | `Condition` | | Asked with the object every update; yes takes the move | ### `kinds` template std::vector kinds() function [include/rmp/behavior.h:1040](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1040-L1042) The behaviors a State turns on, by type: `.enables = kinds()`. ============================================================================== # rmp::input > rmp::input — named actions, and who gets to hear them. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html namespace `#include ` `rmp::input` — named actions, and who gets to hear them. Two things raylib deliberately does not decide for you, and a game needs both on its first day. ```cpp rmp::input::action("jump", KEY_SPACE, KEY_W, GAMEPAD_BUTTON_RIGHT_FACE_DOWN); if (rmp::input::just_pressed("jump")) player.jump(); ``` A name and as many bindings as you like. The TYPE of each one says which device it belongs to — raylib's KeyboardKey, MouseButton and GamepadButton are different enums in C++ — so the dispatch happens at compile time and passing anything else is a compile error that names the argument. And moving in eight directions, with keyboard, d-pad and stick at once, with no configuration at all: ```cpp player.velocity = rmp::input::vector() * speed; ``` THE PART THAT IS NOT OBVIOUS is who gets to hear an action. A finger that presses a UI button must not also fire the gun underneath it, and that has to be true without anyone writing an `if`. So a query BY NAME is routed: ```cpp rmp::input::just_pressed("fire") // silent while the UI wants the pointer rmp::input::pressed(KEY_W) // raw, exactly IsKeyDown, never routed ``` The argument type says which of the two you asked for, and you can see it at the call site without going to look anything up. ### `stick` constexpr detail::Binding stick(::GamepadAxis axis, int sign) function [include/rmp/input.h:84](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L84-L87) Half of an analogue stick, as a binding. The one place you write something that is not a plain raylib constant: ```cpp rmp::input::action("left", KEY_A, rmp::input::stick(GAMEPAD_AXIS_LEFT_X, -1)); ``` `sign` is -1 or +1 and says which way counts. Anything else is clamped to those two, because a stick has two halves and there is no third thing to mean. ### `action` template void action(std::string_view name, First first, Rest... rest) function [include/rmp/input.h:95](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L95-L98) Define an action. At least one binding — an action with none is a mistake the compiler can catch, so it does. REGISTERING THE SAME NAME AGAIN REPLACES IT. It does not add to it. That is what makes calling these from a scene's `_ready()` safe when the player enters that scene twenty times, which is where they naturally get written. ## Reading actions ### `pressed` bool pressed(std::string_view name) function [include/rmp/input.h:126](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L126) Held down ### `just_pressed` bool just_pressed(std::string_view name) function [include/rmp/input.h:127](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L127) The frame it goes down ### `just_released` bool just_released(std::string_view name) function [include/rmp/input.h:128](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L128) The frame it comes up ### `pressed`, `just_pressed`, `just_released` bool pressed(::KeyboardKey key) bool pressed(::MouseButton button) bool pressed(::GamepadButton button) bool just_pressed(::KeyboardKey key) bool just_pressed(::MouseButton button) bool just_pressed(::GamepadButton button) bool just_released(::KeyboardKey key) bool just_released(::MouseButton button) bool just_released(::GamepadButton button) function [include/rmp/input.h:132](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L132) BY DEVICE these are raw: exactly IsKeyDown and friends, never routed, for when you want to know regardless of who else is listening. ### `axis_value` float axis_value(::GamepadAxis which) function [include/rmp/input.h:145](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L145) The raw position of an analogue axis, -1..+1, with the dead zone applied. A stick that reports past its end reads its end, and one that reports something that is not a number reads 0. ## Directions ### `axis` float axis(std::string_view negative, std::string_view positive) function [include/rmp/input.h:154](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L154) -1, 0 or +1 from two actions, or the analogue value when a stick is what is moving them. `negative` and `positive` pressed at once gives 0, which is what a player mashing both keys expects. ### `vector` Vector2 vector(std::string_view left, std::string_view right, std::string_view up, std::string_view down) function [include/rmp/input.h:162](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L162-L163) A direction from four actions, NORMALISED — so going diagonally is not 41 % faster than going straight. That is the single most common bug in 2D movement code and it costs one line here instead of being everybody's to remember. +Y is DOWN, matching raylib's screen coordinates and [`rmp::Object::position`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#position), so "up" gives a negative Y and nothing has to be flipped on the way out. ### `axis`, `vector` float axis() Vector2 vector() function [include/rmp/input.h:180](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L180) The movement every game starts with, already bound: `axis()` is axis("move_left", "move_right"), and `vector()` is vector("move_left", "move_right", "move_up", "move_down"). A game that never calls `action()` moves with the keyboard, a d-pad and a stick at once, because these come defined out of the box: ```cpp move_left KEY_A, KEY_LEFT d-pad left left stick -X move_right KEY_D, KEY_RIGHT d-pad right left stick +X move_up KEY_W, KEY_UP d-pad up left stick -Y move_down KEY_S, KEY_DOWN d-pad down left stick +Y ui_accept KEY_ENTER, KEY_SPACE bottom face button ui_cancel KEY_ESCAPE right face button ``` They are ordinary actions: action("move_left", ...) replaces one, and `axis()` and `vector()` read what it was given from then on. ## The pointer ### `pointer_screen` Vector2 pointer_screen() function [include/rmp/input.h:190](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L190) In pixels, top-left origin ### `pointer`, `pointer_delta` Vector2 pointer() Vector2 pointer_delta() function [include/rmp/input.h:198](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L198) In WORLD units, through the current scene's camera — what you compare an object's position with — and so through `[window] stretch` as well: on a letterboxed window, a pointer on a bar is outside the world. Same as `pointer_screen()` while the camera is where it starts AND the window is the design size — under NONE too, a bigger window puts the design's middle in its middle — and in a game with no scenes (RMP_ENTRY_POINT), which has no camera to go through. `pointer_delta`: How far it moved since the last frame, in pixels ### `pointer_down`, `pointer_pressed`, `pointer_released` bool pointer_down() bool pointer_pressed() bool pointer_released() function [include/rmp/input.h:202](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L202) The left mouse button, which a touch presses too: held, the frame it goes down, the frame it comes up. Raw like `pressed(MOUSE_BUTTON_LEFT)`, never routed. ## Escape hatches ### `deadzone`, `set_deadzone` float deadzone() void set_deadzone(float value) function [include/rmp/input.h:218](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L218) The dead zone below which a stick reads as zero. From `[input] deadzone` in raylib_multiplatform.toml; set it here to change it at runtime, clamped to 0..0.95 so a slider cannot switch the sticks off. NaN changes nothing, and is said once. ### `consumed_pointer`, `consumed_keyboard` bool consumed_pointer() bool consumed_keyboard() function [include/rmp/input.h:223](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/input.h#L223) Is anything above the caller holding the input? Useful for drawing a different cursor, or for code that wants the reason rather than the answer. ============================================================================== # rmp::lang > rmp::Text and rmp::lang -- the game in more than one language. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html namespace `#include ` [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) and `rmp::lang` — the game in more than one language. ```cpp rmp::ui::button("Play"); // translated rmp::ui::text(rmp::Text("{count} gem|{count} gems", { { "count", gems } })); rmp::ui::button(rmp::Text("Open", { .context = "door" })); rmp::lang::set("es"); ``` Every text the framework is handed is an [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html). A literal written in the call becomes one by itself, and it is TRANSLATED: its own words are the key looked up in the game's tables (resources/lang.tsv, resources/lang/.tsv, `[lang] in` raylib_multiplatform.toml), and what is not there is shown as written. A string made at runtime — a std::string, `TextFormat()`'s answer — is shown as it is and never looked up: it has no stable key. A value that changes goes into a placeholder instead, so the key stays the same: [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html)("Score: {score}", { { "score", score } }). Placeholders are {name}; {{ and }} are a brace. A text with a number in it can have plural forms, separated by |, in the order of the language's CLDR categories: English and Spanish one|other, Russian and Polish one|few|many|other, Japanese and Chinese other alone. The first number among the arguments chooses. The language is the player's system language, the one [`rmp::lang::set()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#set) chose (and saved), or `[lang] default`; es-MX falls back to es, then to the default, then to the text as written. Right-to-left and complex shaping (Arabic, Hebrew, the Indic scripts) are not supported: their text is drawn left to right, letter by letter. ### `set` void set(std::string_view code) function [include/rmp/text.h:140](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L140) Change the language, everywhere at once: the next frame draws in it. "es", "es-MX", "ja". Saved, so the next run starts in it. An unknown code shows the default language's texts. ### `current` std::string current() function [include/rmp/text.h:143](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L143) The language in use. ### `available` std::vector available() function [include/rmp/text.h:147](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L147) The languages a language menu offers: `[lang] languages`, in its order, or, with no list, every column and file the tables have. ### `name` std::string name(std::string_view code) function [include/rmp/text.h:151](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L151) A language's own name, for that menu: the table's row "language.name" in that language's column, or the code when the table has none. ### `translate` std::string translate(std::string_view key, std::string_view context = {}) function [include/rmp/text.h:154](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L154) The text `key` in the current language, as [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) would draw it. ============================================================================== # rmp::random > rmp::random — numbers you can reproduce. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html namespace `#include ` `rmp::random` — numbers you can reproduce. ```cpp float angle = rmp::random::range(0.0f, 360.0f); Vector2 spot = rmp::random::in_circle(80); ``` It exists for two reasons and the second one is the one that surprises people. 1. TESTS. raylib's `GetRandomValue()` keeps its state inside raylib and is seeded from the clock, so a test of anything that varies — a spawner's jitter, a tween's wobble, a wander — would give a different answer every run. A test that fails one time in twenty is worse than no test: it teaches everyone to ignore the colour red. 1. THE GAME. Same seed, same run. That is what makes a roguelike seed shareable, what makes "it happened at minute 12" reproducible from a bug report, and what lets a replay be a list of inputs instead of a video. The generator is xoshiro128++: about ten lines, no allocation, no global C state, and good enough for a game by a wide margin. It is NOT for anything that needs to be unguessable — no shuffling of cards for money, no tokens. ### `seed` void seed(uint64_t value) function [include/rmp/random.h:34](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L34) Start the sequence. Called for you at startup with a value taken from the clock, so a game that never mentions seeds still behaves differently each time. Call it yourself to get the same run twice. ### `current_seed` uint64_t current_seed() function [include/rmp/random.h:44](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L44) What the current sequence started from. This is the number you print in a bug report, or show on the pause screen of a roguelike. IT IS ALWAYS TRUE, including before anything calls `seed()`: an unseeded run starts from a fixed default seed rather than from a state with no number on it, so handing this back always gives the sequence the process was running. A headless test never goes through the entry point, so it never gets the clock and never has to seed to be reproducible. ### `value` float value() function [include/rmp/random.h:46](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L46) 0..1, never reaching 1 ### `range` float range(float min, float max) int range(int min, int max) function [include/rmp/random.h:53](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L53) From min up to, never reaching, max — or down to it, when max is the smaller; min itself when they are equal. Any two floats, -FLT_MAX to FLT_MAX included. A NaN or an infinite end is a mistake in the game: said once, and the answer is min, or max when min is the one that is not a number, or 0. One number of the sequence each call, whatever the ends. ### `chance` bool chance(float probability) function [include/rmp/random.h:62](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L62) True with that probability, 0..1: never at 0 or below, always at 1 or above. A NaN is never, and said once. ### `in_circle`, `direction` Vector2 in_circle(float radius) Vector2 direction() function [include/rmp/random.h:66](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L66) Uniform inside the disc, not on the rim. A NaN or infinite radius is the centre, {0, 0}, and said once. `direction`: A unit vector, any angle ### `index` int index(int count) function [include/rmp/random.h:71](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/random.h#L71) Pick one. Returns 0 for an empty range, which is the only answer that does not require the caller to have checked first. ============================================================================== # rmp::save > rmp/save.h — rmp::Value, and saving the game. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html namespace `#include ` rmp/save.h — [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html), and saving the game. ```cpp rmp::Value v; v["level"] = 7; v["name"] = "Omar"; v["unlocked"].push("forest"); rmp::save::write("slot1", v); rmp::Value v; if (rmp::save::read("slot1", v)) { int level = v["level"].as_int(1); // 1 when the key is not there } ``` EVERY READ HAS A DEFAULT, AND NOTHING THROWS. A save written by yesterday's version is not corrupt, it is missing the keys that were added since — and a missing key reading as its default is what lets an update ship without a migration nine times out of ten. A key of the wrong type reads as the default too. For the tenth time, `[save] version` in the .toml is stored in the file and `v.version()` hands it back: ```cpp if (v.version() < 2) v["coins"] = v["gold"].as_int(0); ``` WHAT A FAILED READ TELLS YOU. `read()` is true or false in an `if`, and when it is false, .status says why — because "there is no save yet", "the file was cut short" (the power went during a write) and "the file has been changed" are three different messages to show a player: ```cpp const rmp::save::Result r = rmp::save::read("slot1", v); if (r.status == rmp::save::Status::MODIFIED) show("this save was edited"); ``` WHERE IT GOES. The user's data folder, or next to the executable with `[save] portable` — see `directory()`. A write goes to a temporary file first and replaces the old save only once it is complete, so a crash mid-write leaves the previous save intact. On the web it lands in the browser's IndexedDB and survives a reload. SEALED SAVES are tamper RESISTANCE, not security: the key is in the binary. They stop a player opening the file in a text editor and giving themselves a thousand coins, and any change to a sealed file is detected. Nothing stops someone determined, and nothing here pretends to. The JSON underneath is cJSON, and it appears in no header: this file is all a game ever sees of it. ### `Status` enum class Status enum [include/rmp/save.h:307](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L307-L313) Why `read()` did or did not fill the Value. A slot name `read()` refuses is UNREADABLE too. | Value | | Means | |---|---|---| | `OK` | | Read, checked, and `out` filled | | `MISSING` | | Nothing saved in that slot yet: the first run | | `TRUNCATED` | | Cut short, as a write the power went out on would be | | `MODIFIED` | | The checksum or the seal does not match: edited, or damaged | | `UNREADABLE` | | Not a save at all, or one from a newer framework | ### `Result` struct Result struct [include/rmp/save.h:317](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L317-L320) A read's outcome. True in an `if` only when it is OK, so the three-line load stays three lines; .status is there when the reason matters. | Field | Type | Default | What it is | |---|---|---|---| | `status` | `Status` | `Status::MISSING` | Why; MISSING until a `read()` sets it | explicit operator bool() const OK, and only OK ### `WriteOptions` struct WriteOptions struct [include/rmp/save.h:324](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L324-L326) How `write()` stores a save. Declaration order is the order they are written in, as C++20 requires. | Field | Type | Default | What it is | |---|---|---|---| | `encrypted` | `bool` | `RMP_SAVE_ENCRYPT != 0` | `[save] encrypt` decides the default | ### `ReadOptions` struct ReadOptions struct [include/rmp/save.h:329](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L329-L336) What `read()` accepts as a save. | Field | Type | Default | What it is | |---|---|---|---| | `sealed_only` | `bool` | `RMP_SAVE_ENCRYPT != 0` | With `[save] encrypt` on, a PLAIN file reads as MODIFIED: anyone can write one — the format is documented and a plain save shows it — and accepting it would let a player replace a sealed save with their own. A game that turns sealing on in an update reads its players' old plain saves with { .sealed_only = false } for as long as they may have one. | ### `write` bool write(std::string_view slot, const Value &value, const WriteOptions &options = {}) function [include/rmp/save.h:347](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L347) A slot is a file name without the extension: letters, digits, '_', '-' and '.', not starting with '.', at most 64 of them. Anything else is refused and said once — a slot name is not a place to put a path. False when it could not be written; the previous save, if any, is intact. Also false, and said once, for a Value that could not be read back: 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. ### `read` Result read(std::string_view slot, Value &out, const ReadOptions &options = {}) function [include/rmp/save.h:352](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L352) Fills `out` and says so. On anything but OK, `out` is left exactly as it was, so a game can fill it with defaults first and read over them. A file holding a number too large for a double (1e400) is UNREADABLE: no save holds one. ### `exists`, `remove` bool exists(std::string_view slot) bool remove(std::string_view slot) function [include/rmp/save.h:357](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L357) Whether there is a save in that slot, in any folder `read()` looks in. It does not open it, so a file that would read as TRUNCATED or MODIFIED exists too. False, without a warning, for a slot name `write()` would refuse. `remove`: False when there was nothing to remove ### `directory` std::string directory() function [include/rmp/save.h:365](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L365) Where saves are written: the folder `[save] portable` asked for if it can be written, otherwise the user's data folder — never where the .toml asked for if that turned out to be read-only. With a trailing separator. With `[save] portable`, `read()` looks in both folders and takes the newer save, so a session that had to fall back and the next one that did not agree. ============================================================================== # rmp::ui > rmp::ui — the interface layer. Source: https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html namespace `#include ` `rmp::ui` — the interface layer. The whole point, in four lines: ```cpp rmp::ui::begin(); if (rmp::ui::button("Play")) play(); if (rmp::ui::button("Quit")) quit(); rmp::ui::end(); ``` That is a centred, responsive main menu. No coordinates, no sizes, no anchors, no fonts, no hitboxes, and it looks the same at 800x600 as it does at 4K. Everything else in this header is what you reach for when the default is not what you want — and you only pay for it when you use it. Three rules worth knowing, and that is genuinely all of them: 1. `end()` draws. So the `begin()`/`end()` pair goes between `BeginDrawing()` and `EndDrawing()`, and before `SmokeTest_CaptureFrame()` if you keep that. 2. Describe it where it is drawn: in a scene's `_draw()`, in screen space. Not in `_update()`, which draws nothing, and not in an object's `_draw()`, which runs under the camera — `at()` is how a box follows the world. A call in the wrong place is reported once, and does nothing. Each `begin()`/`end()` pair is a pass, and a frame may hold several: a HUD and the pause menu over it, or a screen and its `overlay()`. 3. Interaction uses the previous frame's geometry. A button cannot be clicked on the very first frame it appears — 16 ms at 60 fps. This is inherent to immediate mode; see TECHNICAL.md for why the alternative is worse. The layout engine underneath is Clay, and it is deliberately invisible: not one of its types appears in this header, so it can be replaced without any of your code changing. ## On pages of their own - [`rmp::ui::Picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html) — Anything `rmp::ui` can show. - [`rmp::ui::SoundName`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-SoundName.html) — The name of a sound, as `rmp::audio::play()` takes it ("click" is click.wav, click.ogg...): written as a string, `.click = "click"`. - [`rmp::ui::DialogueBox`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueBox.html) — The classic box: along the bottom of the screen, the speaker's portrait and name beside the line, the choices as buttons under it. - [`rmp::ui::DialogueStage`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueStage.html) — A visual novel's stage: big portraits of who is on it, the speaker in front and the rest dimmed, and the line in a box under them. - [`rmp::ui::Button`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html) — A button: text, an icon, or both. - [`rmp::ui::Label`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html) — Text, as `text()` draws it, with a style of its own: a title in another font, with an outline. - [`rmp::ui::Image`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html) — A picture with a style — a frame, a shadow — that can be clicked. - [`rmp::ui::Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) — A container: a panel with a look of its own (`style`), and a look for everything inside it (`children`), which every descendant inherits — the nearest container's wins. - [`rmp::ui::Checkbox`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html) — A checkbox that holds its own value. - [`rmp::ui::Slider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html) — A slider that holds its own value. - [`rmp::ui::Dropdown`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html) — A dropdown that holds its items and its choice. - [`rmp::ui::TextInput`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html) — A text field that holds its own text. - [`rmp::ui::ProgressBar`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html) — A progress bar with a look of its own: the style is the track's (its background, its skin), `fill` and `fill_picture` the bar's. ## Vocabulary ### `Align` enum class Align enum [include/rmp/ui.h:83](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L83-L93) Where content sits inside the space it was given. Read them as a 3x3 grid: three verticals (top/center/bottom) crossed with three horizontals (left/center/right). | Value | | Means | |---|---|---| | `TOP_LEFT` | | | | `TOP_CENTER` | | | | `TOP_RIGHT` | | | | `CENTER_LEFT` | | | | `CENTER` | | | | `CENTER_RIGHT` | | | | `BOTTOM_LEFT` | | | | `BOTTOM_CENTER` | | | | `BOTTOM_RIGHT` | | | ### `Variant` enum class Variant enum [include/rmp/ui.h:103](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L103) What a control *means*, not what colour it is. The theme decides the colour, so restyling the game never means revisiting every call site. ```text normal a filled surface: the default, and most buttons primary the one thing you want pressed on this screen danger destructive, and it should look like it outline an outline and a label, no fill: a secondary action ghost just the label until you point at it: toolbars, "back" links ``` | Value | | Means | |---|---|---| | `NORMAL` | | | | `PRIMARY` | | | | `DANGER` | | | | `OUTLINE` | | | | `GHOST` | | | ### `ColorRole` enum class ColorRole enum [include/rmp/ui.h:107](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L107) Which colour of the theme a piece of text uses: TEXT is the theme's text, MUTED its text_muted, PRIMARY its primary and DANGER its danger. | Value | | Means | |---|---|---| | `TEXT` | | | | `MUTED` | | | | `PRIMARY` | | | | `DANGER` | | | ### `Size` enum class Size enum [include/rmp/ui.h:119](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L119) The three type steps. Anywhere a size is asked for you can write one of these or a plain number of design units — it is the same field either way: ```cpp rmp::ui::text("Chapter One", { .size = rmp::ui::Size::LARGE }); rmp::ui::text("Chapter One", { .size = 34 }); ``` The steps are what you want almost always: they come from the theme, so they move together when someone changes the type scale, and they stay in proportion at every screen size. A number is the escape hatch. SMALL, MEDIUM and LARGE are the theme's font_size_small, font_size and font_size_large. | Value | | Means | |---|---|---| | `SMALL` | | | | `MEDIUM` | | | | `LARGE` | | | ## Pictures ### `NineSlice` struct NineSlice struct [include/rmp/ui.h:165](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L165-L178) A picture that stretches without stretching its corners: the classic "9-patch". The four margins cut the source into a 3x3 grid; the corners are drawn at their size, the edges stretch along one axis and the middle along both. That is how one small frame becomes a button of any length. ```cpp rmp::ui::NineSlice frame{ .texture = ui_art, .source = { 0, 0, 24, 24 }, .left = 8, .top = 8, .right = 8, .bottom = 8 }; ``` Or read from Aseprite, where an artist draws it: a slice with 9-slices on gives its own margins — [`rmp::ui::nine_slice`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#nine_slice)(sheet, "button"). | Field | Type | Default | What it is | |---|---|---|---| | `texture` | `rmp::Texture` | | The picture | | `sheet` | `rmp::SpriteSheet` | | Or an Aseprite sheet's, when `texture` is empty | | `source` | `Rectangle` | `{}` | The part of it to cut; {0,0,0,0} = all of it | | `left` | `float` | `0` | The margins, in pixels of the SOURCE: the left column | | `top` | `float` | `0` | The top row | | `right` | `float` | `0` | The right column | | `bottom` | `float` | `0` | The bottom row | | `scale` | `float` | `0` | How big a source pixel is drawn, in design units: the corners are left * scale design units wide, and grow with the UI's scale like everything else. 0 = 1, so a 24-pixel frame is drawn as drawn. Pixel art wants a whole number: 2, 3, 4. | ### `slice` Picture slice(const rmp::SpriteSheet &sheet, std::string_view name) function [include/rmp/ui.h:227](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L227) A named slice of an Aseprite file, as a Picture: the part of the first frame the slice covers, with its 9-slice margins when the slice has them. This is how one .aseprite becomes an atlas of icons, by name: ```cpp static rmp::SpriteSheet icons = rmp::assets::load_sheet("icons.aseprite"); rmp::ui::image(rmp::ui::slice(icons, "coin")); ``` A name the sheet does not have is an empty Picture, said once. ### `nine_slice` NineSlice nine_slice(const rmp::SpriteSheet &sheet, std::string_view name) function [include/rmp/ui.h:231](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L231) The same slice as a NineSlice, to change its scale or hand it on. A slice without 9-slices comes back with all four margins 0, said once. ## Looks: shadows, outlines, skins, sounds and motion ### `Shadow` struct Shadow struct [include/rmp/ui.h:243](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L243-L248) A soft shadow under a box: under a button, a panel, an image. Drawn as a few rounded rectangles that get fainter outwards, which reads as blurred on every target — the software renderer and OpenGL ES 2.0 included — and costs a handful of rectangles. Sizes are in design units. | Field | Type | Default | What it is | |---|---|---|---| | `offset` | `Vector2` | `{ 0, 4 }` | Where it falls: down a little, as light from above | | `blur` | `float` | `8` | How far it fades out past the box; 0 = a hard shadow | | `spread` | `float` | `0` | How much bigger than the box it is before it fades | | `color` | `Color` | `CLITERAL(Color){ 0, 0, 0, 90 }` | At the box; fainter outwards | ### `TextOutline` struct TextOutline struct [include/rmp/ui.h:252](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L252-L255) An outline around every letter, so a title reads over any background. In design units; drawn as copies of the text around it, so keep it small: 1 to 3. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `1` | How far it reaches past each letter, in design units | | `color` | `Color` | `CLITERAL(Color){ 0, 0, 0, 255 }` | Its colour | ### `TextShadow` struct TextShadow struct [include/rmp/ui.h:258](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L258-L261) A copy of the text under it, offset: the shadow of a letter. | Field | Type | Default | What it is | |---|---|---|---| | `offset` | `Vector2` | `{ 1, 2 }` | Design units | | `color` | `Color` | `CLITERAL(Color){ 0, 0, 0, 160 }` | Its colour | ### `Skin` struct Skin struct [include/rmp/ui.h:267](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L267-L273) Pictures instead of a flat colour, one per state. Only `normal` is needed: a state without its own picture shows `normal`, tinted the way the colours of that state would be — lighter under the pointer, darker pressed, grey disabled. Give the others when the artist drew them. | Field | Type | Default | What it is | |---|---|---|---| | `normal` | `Picture` | | At rest | | `hover` | `Picture` | | Under the pointer | | `press` | `Picture` | | Held down | | `disabled` | `Picture` | | Enabled = false | | `focus` | `Picture` | | Has the keyboard or gamepad focus (the ring is still drawn) | ### `Sounds` struct Sounds struct [include/rmp/ui.h:313](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L313-L324) Sounds, by name. Each event has its own; one that is not set is inherited from what is around it and, at the end, from the Theme. An EMPTY name is silence: `.hover = ""` turns off a hover sound set further out. | Field | Type | Default | What it is | |---|---|---|---| | `hover` | `std::optional` | | The pointer arrives on a control | | `press` | `std::optional` | | The pointer goes down on it | | `release` | `std::optional` | | ...and comes up | | `click` | `std::optional` | | It was pressed: pointer, Enter, the A button | | `focus` | `std::optional` | | The keyboard or gamepad focus arrives | | `change` | `std::optional` | | A checkbox, slider, dropdown or field changed | | `open` | `std::optional` | | A dropdown opened | | `close` | `std::optional` | | ...and closed | | `shake` | `std::optional` | | `Shake()`: "no", a wrong password | | `volume` | `std::optional` | | 0..1, for all of them; 1 when nobody sets it | ### `Motion` struct Motion struct [include/rmp/ui.h:330](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L330-L348) Movement, which the framework's own themes leave all off: a button that grows under the pointer is a choice of style, and a game that wants it says so here. Nothing here moves the LAYOUT: a control is drawn bigger, lifted or sliding, but it is laid out — and clicked — where it always was. | Field | Type | Default | What it is | |---|---|---|---| | `hover_scale` | `float` | `1` | 1.05: 5% bigger under the pointer | | `press_scale` | `float` | `1` | 0.95: 5% smaller while held down | | `hover_lift` | `float` | `0` | How far the box rises under the pointer, in design units, its shadow falling further below it: a card lifting off the table. | | `speed` | `float` | `0.12f` | How long hover and press take to get there, in seconds. | | `appear` | `float` | `0` | Arriving: the first frame a box is drawn, it fades in over `appear` seconds, sliding up from `appear_offset` design units below and growing from `appear_scale`. 0 = it is simply there. Panels and overlays are where this is for. | | `appear_offset` | `float` | `0` | Arriving: the first frame a box is drawn, it fades in over `appear` seconds, sliding up from `appear_offset` design units below and growing from `appear_scale`. 0 = it is simply there. Panels and overlays are where this is for. | | `appear_scale` | `float` | `1` | Arriving: the first frame a box is drawn, it fades in over `appear` seconds, sliding up from `appear_offset` design units below and growing from `appear_scale`. 0 = it is simply there. Panels and overlays are where this is for. | | `shake` | `float` | `0.4f` | `Shake()`: how long, and how far side to side, in design units. | | `shake_strength` | `float` | `8` | `Shake()`: how long, and how far side to side, in design units. | ### `Style` struct Style struct [include/rmp/ui.h:365](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L365-L400) How ONE thing looks: a button, a panel, a label. Every field is optional, and one that is not set comes from around it: the `children` style of the containers it is in (the nearest wins), then the Theme's style for its kind (theme.styles.button, theme.styles.panel...), then the Theme's colours and metrics. ```cpp const rmp::ui::Style gold{ .background = GOLD, .text = BLACK, .radius = 0, .shadow = rmp::ui::Shadow{}, .text_outline = rmp::ui::TextOutline{ .color = WHITE }, }; rmp::ui::Button buy{ .text = "Buy", .style = gold }; ``` `Theme::styles` holds one for every kind of widget, under them all. Written in the order you would think of them: the box, its spacing, its text, and how it feels. Designated initialisers have to follow that order. | Field | Type | Default | What it is | |---|---|---|---| | `background` | `std::optional` | | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | | `background_hover` | `std::optional` | | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | | `background_press` | `std::optional` | | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | | `background_disabled` | `std::optional` | | Its fill. On a button, checkbox, dropdown or field, the hover and press colours are worked out from it — a little lighter, a little darker — unless you give them. | | `skin` | `std::optional` | | Pictures instead of the fill, per state. See Skin. | | `tint` | `std::optional` | | Multiplies the colours of a skin or an image: WHITE leaves them as drawn. | | `border` | `std::optional` | | The outline's colour; shown when border_width > 0 | | `border_width` | `std::optional` | | Design units; 0 = none | | `radius` | `std::optional` | | Of the corners, design units; 0 = square | | `shadow` | `std::optional` | | Under the box | | `padding_x` | `std::optional` | | Inside, left and right | | `padding_y` | `std::optional` | | Inside, above and below | | `gap` | `std::optional` | | Between the children of a container | | `text` | `std::optional` | | The colour of its text | | `text_disabled` | `std::optional` | | ...when enabled = false | | `font` | `rmp::Font` | | A font you loaded: `.font = rmp::assets::load_font("title.ttf", 32)`. The interface draws with that FILE, baked by itself at every size it needs, with any letter a text asks for — so the size you loaded it at does not matter, and the text stays sharp. Empty = inherited. | | `font_size` | `std::optional` | | Design units: what `Size::MEDIUM` is here | | `text_outline` | `std::optional` | | A font you loaded: `.font = rmp::assets::load_font("title.ttf", 32)`. The interface draws with that FILE, baked by itself at every size it needs, with any letter a text asks for — so the size you loaded it at does not matter, and the text stays sharp. Empty = inherited. | | `text_shadow` | `std::optional` | | A font you loaded: `.font = rmp::assets::load_font("title.ttf", 32)`. The interface draws with that FILE, baked by itself at every size it needs, with any letter a text asks for — so the size you loaded it at does not matter, and the text stays sharp. Empty = inherited. | | `motion` | `std::optional` | | How it moves; see Motion | | `sounds` | `Sounds` | | Per event; see Sounds | ## The theme ### `Theme` struct Theme struct [include/rmp/ui.h:420](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L420-L534) Every colour and metric the widgets are drawn with. A default-constructed Theme is the dark theme: `theme_dark()` returns exactly that. | Field | Type | Default | What it is | |---|---|---|---| | `background` | `Color` | `CLITERAL(Color){ 18, 18, 22, 255 }` | The colour behind the interface; no widget paints it. [`rmp::app`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html) clears every frame with it unless the scene sets [`rmp::Scene::background`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#background); in a plain raylib loop, pass it to `ClearBackground()` yourself. | | `panel` | `Color` | `CLITERAL(Color){ 30, 30, 38, 255 }` | The fill of `panel()` and of a dropdown's open list. | | `surface` | `Color` | `CLITERAL(Color){ 44, 44, 56, 255 }` | A NORMAL button at rest, the field of a dropdown and of a text input, a slider's rail, an unticked checkbox's box, and the track of `progress()`. | | `surface_hover` | `Color` | `CLITERAL(Color){ 60, 60, 76, 255 }` | A NORMAL, OUTLINE or GHOST button under the pointer; also a checkbox's row, a dropdown's field and the items of its open list. | | `surface_press` | `Color` | `CLITERAL(Color){ 26, 26, 34, 255 }` | What surface_hover paints, while the pointer is held down on it. | | `border` | `Color` | `CLITERAL(Color){ 70, 70, 88, 255 }` | The outline of an OUTLINE button, of an unticked checkbox's box and of a dropdown's open list; and, when border_width > 0, of a NORMAL button and of a panel that has no border of its own. | | `text` | `Color` | `CLITERAL(Color){ 235, 235, 242, 255 }` | [`Text()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) with `ColorRole::TEXT`, the label of a NORMAL, OUTLINE or GHOST button, the labels of the controls, and what a dropdown or a text input shows. | | `text_muted` | `Color` | `CLITERAL(Color){ 150, 150, 168, 255 }` | [`Text()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) with `ColorRole::MUTED`, a slider's percentage, and the placeholder of an empty text input. | | `text_on_accent` | `Color` | `CLITERAL(Color){ 255, 255, 255, 255 }` | The label of a PRIMARY or DANGER button, and the dot of a ticked checkbox. | | `primary` | `Color` | `CLITERAL(Color){ 88, 120, 245, 255 }` | A PRIMARY button at rest, `text()` with `ColorRole::PRIMARY`, a ticked checkbox, the filled part of a slider, and the bar of `progress()`. | | `primary_hover` | `Color` | `CLITERAL(Color){ 110, 140, 255, 255 }` | A PRIMARY button under the pointer. | | `primary_press` | `Color` | `CLITERAL(Color){ 70, 98, 210, 255 }` | A PRIMARY button while the pointer is held down on it. | | `danger` | `Color` | `CLITERAL(Color){ 220, 72, 80, 255 }` | A DANGER button at rest, and `text()` with `ColorRole::DANGER`. | | `danger_hover` | `Color` | `CLITERAL(Color){ 236, 96, 104, 255 }` | A DANGER button under the pointer. | | `danger_press` | `Color` | `CLITERAL(Color){ 184, 56, 64, 255 }` | A DANGER button while the pointer is held down on it. | | `disabled` | `Color` | `CLITERAL(Color){ 60, 60, 70, 255 }` | The fill of a control whose `enabled` is false: a button, a checkbox's box, a slider's filled part, a text input's field. | | `disabled_text` | `Color` | `CLITERAL(Color){ 110, 110, 124, 255 }` | The label of a control whose `enabled` is false, and the value a disabled dropdown or text input shows. | | `focus` | `Color` | `CLITERAL(Color){ 130, 170, 255, 255 }` | The outline on whatever the keyboard or gamepad is pointing at. Without it a controller build is unusable, so it is a theme colour rather than something each widget decides. | | `font_size` | `float` | `RMP_UI_FONT_SIZE` | `[ui] font_size` | | `font_size_small` | `float` | `RMP_UI_FONT_SIZE * 0.8f` | `Size::SMALL` | | `font_size_large` | `float` | `RMP_UI_FONT_SIZE * 1.4f` | `Size::LARGE` | | `padding_x` | `float` | `20` | Inside a button, left and right of the label | | `padding_y` | `float` | `12` | Inside a button, above and below the label | | `gap` | `float` | `12` | Between siblings | | `panel_padding` | `float` | `20` | Inside a `panel()`, and around what `begin()` lays out | | `corner_radius` | `float` | `8` | Of buttons, panels and the controls' fields; 0 = square | | `border_width` | `float` | `0` | 0 = the default Theme draws no borders | | `control_size` | `float` | `22` | A checkbox's box; the height of a slider's drag area | | `track_thickness` | `float` | `6` | A slider's rail | | `focus_ring` | `float` | `2` | The outline on the focused control | | `transition` | `float` | `0.12f` | How long a control takes to reach its new colour, in seconds. Nothing about the layout moves — only colour — so this can never make a button arrive somewhere else than where you clicked. 0 turns it off, which is both the "reduce motion" setting and what a test wants. | | `min_touch_size` | `float` | `44` | The shortest a button can be. It follows the button's type size, so a SMALL one may be shorter, except on Android and iOS, where no button is. 44 design units is Apple's touch target guidance and close to Material's 48dp — it is the difference between a menu you can use with a thumb and one you cannot. | | `sounds` | `Sounds` | `{}` | Sounds and motion every widget starts from. Silent in `theme_dark()` and `theme_light()`; the motion they have is the buttons' and the panels', in `styles` below. | | `motion` | `Motion` | `{}` | Sounds and motion every widget starts from. Silent in `theme_dark()` and `theme_light()`; the motion they have is the buttons' and the panels', in `styles` below. | | `styles` | | `{}` | One Style per kind of widget, under every widget of it | ### `current_theme`, `set_theme` const Theme ¤t_theme() void set_theme(const Theme &t) function [include/rmp/ui.h:544](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L544) The theme every widget is drawn with: `current_theme()` reads it, `set_theme()` copies a new one over it. There is one stored copy, so the reference `current_theme()` returns sees every later `set_theme()`, and a widget drawn after the call already uses the new one. Both work at any time, before the window exists too; until the first `set_theme()` it is the one `[ui] theme` names. A metric `set_theme()` is handed that is NaN, below 0 or past 4096 design units (transition: 60 seconds) is the game's mistake: said once by its name, and `theme_dark()`'s is kept in its place. ### `theme_dark`, `theme_light` Theme theme_dark() Theme theme_light() function [include/rmp/ui.h:555](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L555) The two that come with the framework. Which one starts is `[ui] theme` in raylib_multiplatform.toml; these let you switch at runtime, which is what an in-game "appearance" setting does: ```cpp if (rmp::ui::checkbox("Light Theme", light)) rmp::ui::set_theme(light ? rmp::ui::theme_light() : rmp::ui::theme_dark()); ``` They return a copy, so the usual copy-modify-set still applies on top. ## Fonts ### `set_font` void set_font(std::string_view name) void set_font(const rmp::Font &font) function [include/rmp/ui.h:572](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L572) The global font, by its name in resources/ ("" = raylib's built-in one). ### `font_name` std::string_view font_name() function [include/rmp/ui.h:577](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L577) The global font's name right now: the last `set_font()`, or `[ui] font`. ## Scale ### `scale` float scale() function [include/rmp/ui.h:597](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L597) The factor in use right now. ### `set_scale` void set_scale(float s) function [include/rmp/ui.h:602](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L602) Pin it, above 0 and at most 16. 0 goes back to automatic; NaN or below 0 is a mistake, said once, and automatic too, and past 16 is 16, said once. This is how you would implement an "interface size" accessibility option. ## Breakpoints ### `Breakpoint` enum class Breakpoint enum [include/rmp/ui.h:631](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L631) The shape of the screen, by width / height: COMPACT below 1 (taller than it is wide), MEDIUM from 1 up to 1.6, EXPANDED at 1.6 and wider. | Value | | Means | |---|---|---| | `COMPACT` | | | | `MEDIUM` | | | | `EXPANDED` | | | ### `current_breakpoint` Breakpoint current_breakpoint() function [include/rmp/ui.h:637](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L637) Which Breakpoint the game's area is right now: the window, or under [`rmp::app::Stretch::LETTERBOX`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#Stretch-LETTERBOX) the world inside its bars — the design's shape, whatever the window does. It reads the size when it is called, so it needs no `begin()` first; a window with no height yet is MEDIUM. ### `compact` bool compact() function [include/rmp/ui.h:640](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L640) Shorthand for the case that comes up: `current_breakpoint()` == `Breakpoint::COMPACT`. ## The frame ### `FrameOptions` struct FrameOptions struct [include/rmp/ui.h:649](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L649-L676) How `begin()` lays out the frame: a root that fills the screen, holding one column that everything you declare goes into. The defaults are the centred menu that `begin()` with no arguments opens. | Field | Type | Default | What it is | |---|---|---|---| | `placement` | `Align` | `Align::CENTER` | Where the root's content sits | | `gap` | `float` | `-1` | Between children; -1 = the theme's | | `padding` | `float` | `-1` | Inside the root; -1 = the theme's | | `grow` | `bool` | `false` | False: the column FITS what is in it, so a child that grows fills the column and no more — which is what makes the buttons of a menu one width. true: the column fills the window, less the padding, on both axes, so a child with grow_x or grow_y reaches the edges: a sidebar and a content area that take the whole screen. What does not grow is still placed by `placement`. `rmp::ui::begin({ .grow = true }); rmp::ui::row({ .grow_x = true, .grow_y = true }, [&] { side(); main(); }); rmp::ui::end();` | | `focus_first` | `std::optional` | `{}` | Whether the frame's first control takes the focus by itself, so that Enter and the A button press it the moment it appears. Left unset, the framework decides: yes — which is what keeps a menu three functions long — unless the scene drawing it reads the keys the interface navigates with (Enter, Space, the arrows, Tab, the d-pad, the A button, the left stick) through [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html). That scene is being played, so this is a HUD over it: its controls take no focus and no key until the player presses Tab, and Escape, the B button or a click elsewhere hands the keys back to the game. true or false decides it yourself. `rmp::ui::begin({ .placement = rmp::ui::Align::TOP_RIGHT, .focus_first = false });` | ### `begin` void begin() void begin(const FrameOptions &o) function [include/rmp/ui.h:680](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L680) Open the UI for this frame. The default is a centred column, which is what makes a main menu three functions. ### `end` void end() function [include/rmp/ui.h:685](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L685) Lay out, resolve interaction, and draw. Call it between `BeginDrawing()` and `EndDrawing()`. ## Overlays ### `OverlayOptions` struct OverlayOptions struct [include/rmp/ui.h:715](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L715-L725) How `overlay()` covers what is under it, and where its content goes. | Field | Type | Default | What it is | |---|---|---|---| | `placement` | `Align` | `Align::CENTER` | Where its content sits, as `FrameOptions::placement` | | `blur` | `float` | `0` | How far to blur what is underneath: the Gaussian's standard deviation in design units, as CSS's `blur()` means it; 0 = no blur, which costs one rectangle. A real blur on every GPU raylib drives, OpenGL ES 2.0 and WebGL included. raylib's software renderer has no shaders, so there — and wherever a shader cannot be built — the veil comes alone. | | `dim` | `float` | `0.45f` | 0..1: how far what is underneath goes towards `veil` | | `veil` | `Color` | `CLITERAL(Color){ 0, 0, 0, 255 }` | What it is dimmed towards | ### `overlay` template void overlay(const OverlayOptions &o, Body &&body) template void overlay(Body &&body) function [include/rmp/ui.h:744](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L744-L748) A frame in front of everything drawn before it. See above. ## Widgets ### `ButtonOptions` struct ButtonOptions struct [include/rmp/ui.h:758](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L758-L769) How a `button()` looks, how big it is, and whether it can be pressed. | Field | Type | Default | What it is | |---|---|---|---| | `style` | `Variant` | `Variant::NORMAL` | What it means; the theme picks its colours | | `size` | `detail::Sizing` | `{}` | One of the three steps, or a number of design units. The padding and the minimum touch height follow the type size, so a large button is a large button all over rather than a normal one with bigger letters. | | `enabled` | `bool` | `true` | False = the theme's disabled colours; no press, no focus | | `id` | `std::string_view` | `{}` | Only needed when two buttons share a label AND the UI is conditional. Identical labels in one frame are already told apart automatically. Empty means none. It is hashed on the spot, so a temporary is fine. | ### `TextOptions` struct TextOptions struct [include/rmp/ui.h:772](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L772-L776) How `text()` paints a string: its colour, its size, and whether it wraps. | Field | Type | Default | What it is | |---|---|---|---| | `color` | `ColorRole` | `ColorRole::TEXT` | Which theme colour it is painted in | | `size` | `detail::Sizing` | `{}` | A step, a number, or nothing for the theme's | | `wrap` | `bool` | `true` | Break between words to fit; false = never broken to fit | ### `RichTextOptions` struct RichTextOptions struct [include/rmp/ui.h:787](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L787-L793) Text with markup, drawn a letter at a time: Yarn's markup, which a dialogue line already carries -- ```cpp rmp::ui::rich_text("A [wave]strange[/wave] [color=#ffcc00]light[/color]!"); ``` ```text [b] bold [color=#rrggbb] or [color=red] [size=30] in design units [wave] [shake] [rainbow]: moving letters ``` Its `visible` letters, the rest held back: a typewriter counts them up. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `0` | Wrap at this many design units; 0 = the width it is given | | `size` | `detail::Sizing` | `{}` | A step, a number, or nothing for the theme's | | `color` | `ColorRole` | `ColorRole::TEXT` | The colour of what no `[color] paints` | | `visible` | `int` | `-1` | How many letters show; -1 = every one | | `id` | `std::string_view` | `{}` | As `ButtonOptions::id:` two with one text | ### `rich_text` void rich_text(const rmp::Text &text) void rich_text(const rmp::Text &text, const RichTextOptions &o) function [include/rmp/ui.h:794](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L794) ### `rich_text_length` int rich_text_length(const rmp::Text &text) function [include/rmp/ui.h:798](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L798) How many letters a rich text has once its markup is gone: where a typewriter stops. ### `button` bool button(const rmp::Text &label) bool button(const rmp::Text &label, const ButtonOptions &o) function [include/rmp/ui.h:805](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L805) True on the frame it is pressed: the pointer released over it, or, while it has the focus, Enter or the gamepad's accept button. Reads as it looks: ```cpp if (rmp::ui::button("Play")) play(); ``` ### `ImageButtonOptions` struct ImageButtonOptions struct [include/rmp/ui.h:810](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L810-L817) How `image_button()` is sized, and whether it can be pressed. Sizes are in design units. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `0` | 0 = the picture's own width, scaled | | `height` | `float` | `0` | 0 = the picture's own height, scaled | | `enabled` | `bool` | `true` | False = the disabled tint; no press, no focus | | `id` | `std::string_view` | `{}` | It has no label to be told apart by, so two image buttons that come and go are told apart by this. Empty = by its order among the unnamed ones. | ### `image_button` bool image_button(const Picture &picture) bool image_button(const Picture &picture, const ImageButtonOptions &o) function [include/rmp/ui.h:825](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L825) A button that is a picture: an icon, an inventory slot, a skinned "Play" drawn by your artist. Pressed like `button()`, focusable like `button()`, and it wears theme.styles.button — its skin behind the picture, its sounds. ```cpp if (rmp::ui::image_button(gear)) open_settings(); ``` ### `text` void text(const rmp::Text &s) void text(const rmp::Text &s, const TextOptions &o) function [include/rmp/ui.h:832](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L832) The string is copied immediately, so a temporary is safe: ```cpp rmp::ui::text(std::to_string(score)); ``` ## Containers ### `BoxOptions` struct BoxOptions struct [include/rmp/ui.h:859](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L859-L878) Shared by every container. All measurements are in design units and are scaled; -1 means "whatever the theme says". | Field | Type | Default | What it is | |---|---|---|---| | `gap` | `float` | `-1` | Between children | | `padding` | `float` | `-1` | Inside this container; -1 = none, panel_padding in a panel | | `items` | `Align` | `Align::CENTER` | Where children sit in the leftover space | | `grow_x` | `bool` | `false` | Sizing is interleaved by axis — x then y — rather than grouped by kind, and that is not cosmetic. Designated initialisers have to be written in declaration order, so grouping them as grow_x, grow_y, width, height would make { .width = 240, .grow_y = true } illegal: a fixed-width sidebar that fills the height, which is about the most ordinary thing anyone writes. This way round, every combination is legal. | | `width` | `float` | `0` | > 0 = a fixed width, overriding fit/grow | | `grow_y` | `bool` | `false` | Fill the parent's height instead of fitting content | | `height` | `float` | `0` | > 0 = a fixed height, overriding fit/grow | | `id` | `std::string_view` | `{}` | A stable name for the container: the same element from frame to frame, whatever else is on screen. Nothing in `rmp::ui` needs it — it is for a test that finds an element by name, as tests/ui_layout_test.cpp does. Unnamed containers are anonymous, which is what almost all of them want. | ### `PanelOptions` struct PanelOptions struct [include/rmp/ui.h:881](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L881-L891) A panel is a box with a background, which is what makes it visible. | Field | Type | Default | What it is | |---|---|---|---| | `box` | `BoxOptions` | `{}` | The layout, as `column()` takes it, except that a padding of -1 is the theme's panel_padding rather than none. | | `background` | `Color` | `CLITERAL(Color){ 0, 0, 0, 0 }` | {0,0,0,0} = the theme's panel | | `radius` | `float` | `-1` | -1 = the theme's | | `border` | `Color` | `CLITERAL(Color){ 0, 0, 0, 0 }` | {0,0,0,0} = the theme's border, drawn only when the theme's border_width is above 0 (it is 1 in `theme_light()`, 0 in `theme_dark()`). | | `border_width` | `float` | `-1` | Of `border`, when set; -1 = 1 design unit | ### `ImageOptions` struct ImageOptions struct [include/rmp/ui.h:900](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L900-L905) How `image()` sizes and tints a texture. Sizes are in design units. | Field | Type | Default | What it is | |---|---|---|---| | `grow` | `bool` | `false` | Fill the space available | | `width` | `float` | `0` | Otherwise: 0 = the texture's own width, scaled | | `height` | `float` | `0` | 0 = the texture's own height, scaled | | `tint` | `Color` | `WHITE` | Multiplies the texture's colours; WHITE leaves them as they are | ### `ProgressOptions` struct ProgressOptions struct [include/rmp/ui.h:908](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L908-L915) How `progress()` sizes and colours its bar. Sizes are in design units. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `0` | 0 = fill the space available | | `height` | `float` | `-1` | -1 = derived from the theme's font size | | `radius` | `float` | `-1` | -1 = half the height, for round ends | | `fill` | `Color` | `CLITERAL(Color){ 0, 0, 0, 0 }` | {0,0,0,0} = the theme's primary | | `track` | `Color` | `CLITERAL(Color){ 0, 0, 0, 0 }` | {0,0,0,0} = the theme's surface | | `id` | `std::string_view` | `{}` | Names the bar, as `BoxOptions::id` names a container | ### `row` template void row(const BoxOptions &o, Body &&body) template void row(Body &&body) function [include/rmp/ui.h:942](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L942-L946) Left to right. ### `column` template void column(const BoxOptions &o, Body &&body) template void column(Body &&body) function [include/rmp/ui.h:952](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L952-L956) Top to bottom. ### `panel` template void panel(const PanelOptions &o, Body &&body) template void panel(Body &&body) function [include/rmp/ui.h:962](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L962-L966) A column with a background and padding: the thing you put a dialog in. ### `center` template void center(Body &&body) function [include/rmp/ui.h:972](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L972-L976) Takes all the space it is given and puts its contents in the middle of it. ### `stack`, `layer` template void stack(Body &&body) template void layer(Body &&body) function [include/rmp/ui.h:987](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L987-L991) Layers, drawn back to front. Each child has to be a `layer()`: ```cpp rmp::ui::stack([&]{ rmp::ui::layer([&]{ rmp::ui::image(background); }); rmp::ui::layer([&]{ rmp::ui::text("PAUSED"); }); }); ``` The explicit `layer()` is not ceremony — it is what tells the layout which things are supposed to overlap and which are ordinary children. ### `spacer` void spacer() void spacer(float fixed) function [include/rmp/ui.h:1005](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1005) Eats the space left over, which is how you push things apart: ```cpp rmp::ui::row({ .grow_x = true }, []{ rmp::ui::text("Health"); rmp::ui::spacer(); // <- shoves the score to the right rmp::ui::text("999"); }); ``` ## More widgets ### `image` void image(const Texture2D &texture) void image(const Texture2D &texture, const ImageOptions &o) void image(const Picture &picture) void image(const Picture &picture, const ImageOptions &o) void image(const rmp::Texture &texture) void image(const rmp::Texture &texture, const ImageOptions &o) function [include/rmp/ui.h:1020](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1020) The Texture2D is copied on the way in, so the struct you pass may be a temporary. What the copy holds is a GPU handle, though, so the texture itself has to stay loaded until `end()` has drawn the frame: keep the [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) that owns it, as a member or a global. A temporary [`rmp::Texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#Texture) does not compile here — `image(rmp::assets::load_texture("icon.png"))` would unload the texture at the semicolon. By default it is drawn at its own size, scaled with the rest of the UI. ### `progress` void progress(float fraction) void progress(float fraction, const ProgressOptions &o) function [include/rmp/ui.h:1032](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1032) A bar. `fraction` is 0..1 and is clamped; NaN — hp / max_hp with no max_hp — is an empty bar, said once. ## Grid and scroll ### `GridOptions` struct GridOptions struct [include/rmp/ui.h:1041](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1041-L1052) How `grid()` counts its columns, spaces its cells, and how much room it takes. Measurements are in design units, and -1 means the default given beside it. | Field | Type | Default | What it is | |---|---|---|---| | `columns` | `int` | `0` | 0 = as many as fit, at least one, recomputed as the window changes | | `min_cell` | `float` | `96` | Only used when columns = 0 | | `gap` | `float` | `-1` | Between cells and between rows; -1 = the theme's | | `padding` | `float` | `-1` | Inside the grid; -1 = none | | `grow_x` | `bool` | `true` | A grid almost always wants the width it is offered | | `grow_y` | `bool` | `false` | Fill the parent's height instead of fitting the rows | | `id` | `std::string_view` | `{}` | A name for the grid. columns = 0 reads the width the grid had last frame and finds it by this name; without one, by its order among the unnamed grids of the pass, which a grid that comes and goes before it changes. | ### `ScrollOptions` struct ScrollOptions struct [include/rmp/ui.h:1056](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1056-L1071) How `scroll()` clips its contents, spaces them, and how much room it takes. Measurements are in design units, and -1 means the default given beside it. | Field | Type | Default | What it is | |---|---|---|---| | `horizontal` | `bool` | `false` | Vertical by default, which is what lists want | | `vertical` | `bool` | `true` | Clip and scroll top to bottom | | `gap` | `float` | `-1` | Between children; -1 = the theme's | | `padding` | `float` | `-1` | Inside the area; -1 = none | | `grow_x` | `bool` | `true` | Fill the parent's width | | `width` | `float` | `0` | > 0 = a fixed width, overriding grow_x | | `grow_y` | `bool` | `true` | Fill the parent's height, and clip there. In a parent that fits its contents, that is the room left in the window: the rows never push it. | | `height` | `float` | `0` | > 0 = a fixed height, overriding grow_y | | `id` | `std::string_view` | `{}` | A name for the area. Without one it is told apart by its order among the unnamed scroll areas of the pass, so an area that comes and goes before it changes which one it is. | ### `grid` template void grid(const GridOptions &o, Body &&body) function [include/rmp/ui.h:1117](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1117-L1121) Equal columns, as many rows as it takes. Each item goes in a `cell()`, which is what lets the grid count them and start a new row at the right moment — the layout engine underneath wraps text, not elements, so the rows are real rows. ```cpp rmp::ui::grid(4, [&]{ for (auto &item : inventory) rmp::ui::cell([&]{ rmp::ui::image(item.icon); }); }); ``` With columns = 0 it works out how many fit in the width it has and works it out again when the window changes, which is what an inventory should do rather than staying at the number someone typed on a desktop. ### `cell`, `grid` template void cell(Body &&body) template void grid(int columns, Body &&body) template void grid(Body &&body) function [include/rmp/ui.h:1124](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1124-L1128) One item in a grid. Every child of a grid has to be one. ### `scroll` template void scroll(const ScrollOptions &o, Body &&body) template void scroll(Body &&body) function [include/rmp/ui.h:1138](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1138-L1142) Clips its contents and scrolls them. The wheel works, and so does dragging with a finger — the same gesture on a phone. ## Controls that own a value ### `CheckboxOptions` struct CheckboxOptions struct [include/rmp/ui.h:1162](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1162-L1165) Whether a `checkbox()` can be toggled, and the name that tells it apart. | Field | Type | Default | What it is | |---|---|---|---| | `enabled` | `bool` | `true` | False = the theme's disabled colours; no toggle, no focus | | `id` | `std::string_view` | `{}` | As `ButtonOptions::id:` for a shared label | ### `SliderOptions` struct SliderOptions struct [include/rmp/ui.h:1168](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1168-L1174) How a `slider()` is sized, stepped and shown. Sizes are in design units. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `0` | 0 = fill the space available | | `step` | `float` | `0` | 0 = continuous; otherwise snap to multiples | | `enabled` | `bool` | `true` | False = the theme's disabled colours; no drag, no focus | | `show_value` | `bool` | `true` | Draw the position, as a percentage, after the bar | | `id` | `std::string_view` | `{}` | As `ButtonOptions::id:` for a shared label | ### `DropdownOptions` struct DropdownOptions struct [include/rmp/ui.h:1177](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1177-L1181) How a `dropdown()` is sized, and whether it can be opened. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `0` | Of the field, in design units; 0 = fill the space available | | `enabled` | `bool` | `true` | False = the disabled text colour; no opening, no focus | | `id` | `std::string_view` | `{}` | As `ButtonOptions::id:` for a shared label | ### `TextInputOptions` struct TextInputOptions struct [include/rmp/ui.h:1185](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1185-L1197) How a `text_input()` is sized, what it shows while it is empty, and how much it takes. | Field | Type | Default | What it is | |---|---|---|---| | `width` | `float` | `0` | Of the field, in design units; 0 = fill the space available | | `enabled` | `bool` | `true` | False = the theme's disabled colours; no typing, no focus | | `placeholder` | `rmp::Text` | `{}` | Shown in the theme's text_muted while the field is empty and does not have the focus. It is copied, so a temporary is fine. | | `id` | `std::string_view` | `{}` | As `ButtonOptions::id:` for a shared label | | `max_length` | `int` | `0` | The most CHARACTERS it holds — what the player counts, so an "é" is one and not the two bytes it takes. 0 = no limit. Typing stops at it, and a longer value you hand in is cut to it on the frame the field is drawn, never inside a character. | ### `checkbox` bool checkbox(const rmp::Text &label, bool &value) bool checkbox(const rmp::Text &label, bool &value, const CheckboxOptions &o) function [include/rmp/ui.h:1201](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1201) A box that flips `value` when it is clicked, or activated from the keyboard or a gamepad while it has the focus. True on the frame it flipped. ### `slider` bool slider(const rmp::Text &label, float &value, float min, float max) bool slider(const rmp::Text &label, float &value, float min, float max, const SliderOptions &o) function [include/rmp/ui.h:1211](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1211) A bar that sets `value` between min and max: dragged, or moved with left and right while it has the focus, one `step` (or 5% of the range) per press, then twelve a second while held. `value` is clamped to the range, and snapped to `step` when there is one, on every call; true on any frame that changed it. Nothing is drawn when max <= min — nor when an end is NaN or an infinity, which is said once. A value that is NaN is set to min, and a step that is not a positive number is none, each said once. ### `dropdown` bool dropdown(const rmp::Text &label, int &selected, std::span items) bool dropdown(const rmp::Text &label, int &selected, std::span items, const DropdownOptions &o) bool dropdown(const rmp::Text &label, int &selected, std::initializer_list items) bool dropdown(const rmp::Text &label, int &selected, std::initializer_list items, const DropdownOptions &o) function [include/rmp/ui.h:1226](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1226-L1227) `selected` is the index into `items`, and is kept inside it. ```cpp rmp::ui::dropdown("Quality", quality, { "Low", "Medium", "High" }); ``` A list written in place, as above, or any array of string_views you keep — std::array, std::vector, a C array — they are copied on the way in. A click, or Enter or the A button while it has the focus, opens the list. Open and focused, up and down walk its items instead of moving the focus, Enter or A picks the one they are on, and Escape or B closes it without changing anything. True on the frame `selected` changed. Nothing is drawn for an empty list. ### `text_input` bool text_input(const rmp::Text &label, std::string &value) bool text_input(const rmp::Text &label, std::string &value, const TextInputOptions &o) function [include/rmp/ui.h:1245](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1245) Edits your string, in UTF-8 — what the player types goes on the end, and Backspace takes off the last character, never half of one — and only while the field has the keyboard; `TextInputOptions::max_length` caps it. True on the frame it changed. It takes the keyboard when it is clicked, when the focus is moved onto it (Tab, the arrows, the d-pad, `focus()`), or when Enter, Space or the A button is pressed while it has the focus — but not from the focus a screen gives its first control by itself. It gives it back on Enter or the A button (Space is typed), on Escape or the B button, and on a click anywhere else; the focus stays on it. Tab, up and down move the focus on from a field as from any other control, and take the keyboard with them. ## Over the world, over a control, over everything ### `AtOptions` struct AtOptions struct [include/rmp/ui.h:1258](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1258-L1264) Where `at()` puts its box, relative to the point it follows. | Field | Type | Default | What it is | |---|---|---|---| | `anchor` | `Align` | `Align::BOTTOM_CENTER` | The point of the box that sits on the world position: BOTTOM_CENTER puts the box above it, which is where a health bar or a name goes. | | `offset` | `Vector2` | `{ 0, 0 }` | Design units, after projecting: { 0, -8 } lifts it | | `id` | `std::string_view` | `{}` | A stable name for the box, as `BoxOptions::id` | ### `at` template void at(Vector2 world, const AtOptions &o, Body &&body) template void at(Vector2 world, Body &&body) function [include/rmp/ui.h:1295](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1295-L1299) A box over a point of the WORLD, wherever the scene's camera shows it — zoomed, scrolled, shaken and stretched with it. Between `begin()` and `end()`, in the scene's `_draw()`, like everything else here: ```cpp rmp::ui::begin(); for (const rmp::Handle &e : enemies) if (e) rmp::ui::at(e->position, [&] { rmp::ui::progress(e->hp / 10.0f); }); rmp::ui::end(); ``` What it paints does not take the pointer: a click on the enemy under its health bar still reaches the enemy. A control inside it is a control like any other — it can be clicked and focused where it is drawn. While the point is off the screen the box is not drawn at all, and nothing in it takes the pointer, the focus or the keys. Without scenes there is no camera, and the world is the screen. ## Dialogue presenters ### `Portrait` struct Portrait struct [include/rmp/ui.h:1336](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1336-L1340) A speaker's picture, and one for each mood a line's #mood:happy names. | Field | Type | Default | What it is | |---|---|---|---| | `speaker` | `std::string` | | The name before the colon of a line: "Mika" | | `mood` | `std::string` | `{}` | Empty: the picture for any mood without its own | | `picture` | `Picture` | `{}` | A texture, an atlas region, a sprite's frame or a nine-slice | ### `Speaker` struct Speaker struct [include/rmp/ui.h:1344](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1344-L1350) Who speaks, as they look and sound: their lines in a box of their own, their name plate, their voice. Unset fields are the presenter's. | Field | Type | Default | What it is | |---|---|---|---| | `name` | `std::string` | | The name before the colon of a line: "Mika" | | `blip` | `SoundName` | `{}` | Their blip; empty: the flow's | | `pitch` | `float` | `1` | Their blip's pitch: 1.3 higher, 0.8 lower | | `style` | `Style` | `{}` | Over the presenter's style, for their lines | | `name_style` | `Style` | `{}` | Over the presenter's name_style | ### `DialogueSide` enum class DialogueSide enum [include/rmp/ui.h:1353](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1353-L1356) Which side of the box a portrait sits on. | Value | | Means | |---|---|---| | `LEFT` | | Before the line | | `RIGHT` | | After it | ### `DialogueChoices` enum class DialogueChoices enum [include/rmp/ui.h:1359](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1359-L1363) Where a box puts the choices. | Value | | Means | |---|---|---| | `IN_BOX` | | In the box, in place of the line | | `ABOVE` | | In a panel of their own above the box, at its right | | `CENTER` | | In a panel in the middle of the screen | ### `DialogueFlow` struct DialogueFlow struct [include/rmp/ui.h:1366](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1366-L1376) How a presenter types a line out, and goes on. | Field | Type | Default | What it is | |---|---|---|---| | `letters_per_second` | `float` | `45` | The typewriter; 0 = the whole line at once | | `blip` | `SoundName` | `{}` | A sound as the letters appear | | `blip_every` | `int` | `2` | Letters between two blips | | `blip_jitter` | `float` | `0` | Each blip's pitch moves by up to this: 0.08 = 8 % | | `auto_advance` | `float` | `0` | Seconds a whole line stays before it goes on; 0 = wait | | `skip_seen` | `bool` | `false` | A line already read goes by at once | | `voices` | `std::string` | `{}` | A recorded line: the sound named voices + its id ("vo/hello") | | `choice_seconds` | `float` | `0` | A timed choice: seconds to choose; 0 = no timer | | `default_choice` | `int` | `0` | What a timed choice takes when the time is up | ### `DialogueMemory` struct DialogueMemory struct [include/rmp/ui.h:1379](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1379-L1399) What a presenter remembers from one frame to the next. | Field | Type | Default | What it is | |---|---|---|---| | `line_id` | `std::string` | | The line on screen | | `shown` | `float` | `0` | Letters typed so far | | `length` | `int` | `0` | Letters in the line | | `waited` | `float` | `0` | Seconds since it was all shown, or of a [pause] | | `choice_left` | `float` | `0` | Seconds left of a timed choice | | `blips` | `int` | `0` | Blips played for this line | | `history` | `std::vector>` | | Speaker, line: read so far | | `seen` | `std::vector` | | The ids of the lines read | | `stage` | `std::vector` | | DialogueStage: who is on stage, left to right | | `entered` | `std::vector` | | DialogueStage: seconds each has been on stage | | `focus` | `std::vector` | | DialogueStage: 0..1, how much each is the speaker | | `shaking` | `float` | `-1` | DialogueStage: seconds into a `shake()`; -1 = none | | `shake_strength` | `float` | `0` | ...how far, in design units | | `shake_seconds` | `float` | `0` | ...how long | | `flashing` | `float` | `-1` | DialogueStage: seconds into a `flash()`; -1 = none | | `flash_seconds` | `float` | `0` | ...how long | | `flash_color` | `Color` | `WHITE` | ...of which colour | | `showing_history` | `bool` | `false` | `Toggle_history()`: the backlog instead of the box | ### `dialogue_line` bool dialogue_line(rmp::Dialogue &dialogue, DialogueMemory &memory, const DialogueFlow &flow, const RichTextOptions &text = {}) function [include/rmp/ui.h:1407](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1407-L1408) A presenter's pieces, for a presenter of your own: the dialogue's line, typed out where the call is in your layout — its `[speed] and` [pause], its blips and recorded voice, auto-advance, skip-seen, and a click or Enter going on (on the line, or the next button it draws after it). True while there is a line. The `flow` blip is the one played: a Speaker's is yours to put in it. ### `dialogue_choices` bool dialogue_choices(rmp::Dialogue &dialogue, DialogueMemory &memory, const DialogueFlow &flow, const Style &choice_style = {}) function [include/rmp/ui.h:1411](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1411-L1412) The choices, as buttons in a column where the call is, and a timed choice's bar. True while there are choices. ### `BubbleSpeaker` struct BubbleSpeaker struct [include/rmp/ui.h:1441](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1441-L1449) Who a bubble points at: a speaker by name, and the object that speaks. | Field | Type | Default | What it is | |---|---|---|---| | `name` | `std::string` | | The speaker of the lines it says | | `object` | `rmp::Handle` | `{}` | What it is drawn over; empty: where the UI puts it | | `offset` | `Vector2` | `{ 0, -18 }` | From the object's position, in world units | | `blip` | `SoundName` | `{}` | Their blip; empty: the flow's | | `pitch` | `float` | `1` | Their blip's pitch | | `style` | `Style` | `{}` | Over the bubble's style, for their lines | ### `DialogueBubble` struct DialogueBubble struct [include/rmp/ui.h:1453](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1453-L1470) A bubble over the speaker's head, in the world ([`rmp::ui::at()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#at)), the choices in it too. The world goes on around it. | Field | Type | Default | What it is | |---|---|---|---| | `speakers` | `std::vector` | `{}` | Who says what, and over which object | | `flow` | `DialogueFlow` | `{}` | The typewriter, the blips, auto-advance, timed choices | | `width` | `float` | `220` | Design units: the line wraps inside it | | `tail` | `float` | `10` | Design units: the tail under it, to the speaker; 0 = none | | `tail_color` | `Color` | `CLITERAL(Color){ 0, 0, 0, 0 }` | The tail's colour; { 0, 0, 0, 0 } = the bubble's background, or the theme's panel. A bubble of art draws its own: give it a tail_picture. | | `tail_picture` | `Picture` | `{}` | Drawn in the tail's place, 2 tails wide, 1 tall | | `pauses_world` | `bool` | `false` | The world goes on around a bubble | | `style` | `Style` | `{}` | The bubble | | `choice_style` | `Style` | `{}` | Each choice | | `ours` | `DialogueMemory` | | Its state between frames; yours to read | bool show(rmp::Dialogue &dialogue) Draws the line or the choices, and takes the player's answer. True while the dialogue has something to show. ### `TooltipOptions` struct TooltipOptions struct [include/rmp/ui.h:1506](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1506-L1511) How `tooltip()` places its line, and how long it waits. | Field | Type | Default | What it is | |---|---|---|---| | `side` | `Align` | `Align::TOP_CENTER` | Which side of the control it appears on | | `delay` | `float` | `0.5f` | Seconds the pointer rests on the control before it shows; infinity: never by the pointer, by the focus alone. | ### `tooltip` void tooltip(const rmp::Text &text) void tooltip(const rmp::Text &text, const TooltipOptions &o) function [include/rmp/ui.h:1522](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1522) A line about the control declared just before it, shown while the pointer rests on that control, or while the keyboard or gamepad focus is on it: ```cpp if (rmp::ui::button("Sell")) sell(item); rmp::ui::tooltip("Gives you half of what it cost"); ``` The text is copied. One with no control before it in the frame is reported once and shows nothing. An empty one shows nothing and is no mistake: `tooltip(item.description)` for an item without one. ### `NotifyOptions` struct NotifyOptions struct [include/rmp/ui.h:1526](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1526-L1529) How long `notify()` keeps a message, and its colour. | Field | Type | Default | What it is | |---|---|---|---| | `seconds` | `float` | `3` | On screen for this long, then it fades out | | `color` | `ColorRole` | `ColorRole::TEXT` | Which theme colour the text is painted in | ### `notify` void notify(const rmp::Text &text) void notify(const rmp::Text &text, const NotifyOptions &o) function [include/rmp/ui.h:1543](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1543) A short message at the bottom of the screen that goes away by itself: "Saved", "Achievement unlocked". Call it from anywhere — `_update()`, a callback, a frame with no UI — because it only queues: the framework draws what is queued over everything else, and it never takes the pointer or the focus. The newest few are shown, one above the other. (In a game with its own frame hook they are drawn over the frame's first `begin()`/`end()`, there being no telling which `end()` is the last; and a frame of its that describes no interface draws none, so they wait, no older, for the next one that does.) In a debug build the framework's own warnings arrive here too: a mistake it reports once in the log (an action nobody defined, a widget outside `begin()`/`end()`) is also said on screen, where it cannot scroll past. ## Input, and who gets it ### `wants_pointer` bool wants_pointer() function [include/rmp/ui.h:1572](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1572) The pointer is over the interface, or the interface is using it (dragging a slider). "Over the interface" is over anything it paints as a surface: every control, every box with a background colour or a border (a panel, a progress bar, an open dropdown list), an image, and a scroll area, empty part included — but not where a scroll area has clipped its contents away. Plain text with nothing behind it is NOT: a score drawn over the game does not stop the game being clicked through it. ### `wants_keyboard` bool wants_keyboard() function [include/rmp/ui.h:1580](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1580) A text field has the keyboard, so the keys are its own: see `text_input()`. Having the focus is not enough — a field the player pressed Enter on keeps the focus and gives the keyboard back. And a HUD over a game being played that the player walked into with Tab, or whose control the game chose with `focus()`, has the keys until Escape, the B button, a click elsewhere or `set_navigation_enabled(false)`: see `FrameOptions::focus_first`. ## Focus, keyboard and gamepad ### `focus` void focus(std::string_view id) function [include/rmp/ui.h:1625](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1625) Give a named control the focus — when a menu opens, or to point a controller at something other than the first control. Pass "" to clear it. A focus asked for by name is drawn straight away: you meant it, and a text field given it takes the keyboard. `id` is the control's label, or its explicit .id. Outside `begin()`/`end()` — in a scene's `_ready()`, say — it waits for the next frame that draws controls and lands on the first one carrying that name, whichever scene draws it; if that frame has none, the request is dropped and the screen keeps its own default. On a HUD over a game being played it is the game choosing that control, as Tab would be: the keys are the interface's until Escape, the B button or a click elsewhere. ### `focused` std::string_view focused() function [include/rmp/ui.h:1628](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1628) What has the focus right now, or "" if nothing does. ### `set_navigation_enabled`, `navigation_enabled` void set_navigation_enabled(bool on) bool navigation_enabled() function [include/rmp/ui.h:1634](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1634) Turn keyboard and gamepad navigation off if your game drives focus itself, and ask whether it is on. It starts on. Turning it off also gives back the keys of a HUD the player walked into with Tab, and turning it on again does not take them back. ## Events ### `EventKind` enum class EventKind enum [include/rmp/ui.h:1653](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1653-L1665) What a control did. | Value | | Means | |---|---|---| | `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` | | `Shake()` was called on it | ### `WidgetKind` enum class WidgetKind enum [include/rmp/ui.h:1668](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1668-L1678) Which kind of widget an event came from. | Value | | Means | |---|---|---| | `BUTTON` | | | | `LABEL` | | | | `IMAGE` | | | | `PANEL` | | | | `CHECKBOX` | | | | `SLIDER` | | | | `DROPDOWN` | | | | `TEXT_INPUT` | | | | `PROGRESS` | | | ### `Event` struct Event struct [include/rmp/ui.h:1682](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1682-L1686) One event. `name` is the control's label, or its id when it has one; it is valid during the call only. | Field | Type | Default | What it is | |---|---|---|---| | `kind` | `EventKind` | `EventKind::CLICK` | What happened | | `widget` | `WidgetKind` | `WidgetKind::BUTTON` | To which kind of widget | | `name` | `std::string_view` | `{}` | Its label or id | ### `on_event` void on_event(rmp::Callback hook) function [include/rmp/ui.h:1690](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1690) The one hook every event goes to, after its sound. Setting it again replaces it; an empty one — [`rmp::ui::on_event({})`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#on_event) — turns it off. ## Widgets you keep ### `KeptState` struct KeptState struct [include/rmp/ui.h:1729](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1729-L1734) What a kept widget remembers between frames. | Field | Type | Default | What it is | |---|---|---|---| | `hovered` | `bool` | `false` | The pointer is on it | | `pressed` | `bool` | `false` | Held down on it | | `focused` | `bool` | `false` | It has the focus | | `shakes` | `int` | `0` | `Shake()` calls not yet started | ## Lifecycle ### `shutdown` void shutdown() function [include/rmp/ui.h:1997](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1997) Called for you by the entry point macro, before `on_exit()` — while the window is still open, because releasing a font after `CloseWindow()` would be touching a GL context that no longer exists. There is no `init()`: the UI starts itself on the first `begin()`, by which time there is a window. A game that never draws UI allocates nothing. ============================================================================== # Classes > The framework's classes and structs that have pages of their own. Source: https://omardev29.github.io/rmp-docs/reference/classes/index.html The framework's classes and structs that have pages of their own. | Name | What it is | |---|---| | [`Resource handles`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-detail-Resource.html) | The RAII half, written once for every handle type. | | [`rmp::Callback`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html) | A function the framework keeps and calls later with arguments of types A...: what `on_click()`, `on_drag()`, `on_collision()` and `Tilemap::on_object()` store, and the type of the `on_` fields of the behaviors. | | [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) | The camera | | [`rmp::Condition`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Condition.html) | A question the framework asks later with arguments of types A...: a StateMachine's transition, an Animator's rule, whether a Draggable may be dropped. | | [`rmp::Dialogue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html) | A conversation: a compiled Yarn script, where it is in it, and what it remembers. | | [`rmp::DialogueValue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html) | A value of the Yarn language: a number, a string or a bool. | | [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) | A reference to an object that is safe to keep across frames. | | [`rmp::MapObject`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html) | One object placed in the map, as `spawn_objects()` hands it to the factory registered for its `type`: where it is, how big, and its properties. | | [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) | An entity in a scene: the player, an enemy, a bullet, a coin, a platform. | | [`rmp::Ref`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html) | An optional reference: something that may not be there, and is not yours. | | [`rmp::Scene`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html) | A screen of the game — a main menu, a level, a pause overlay — with its own objects, `map` and `camera`. | | [`rmp::SheetData`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html) | Everything read out of an .aseprite: the packed texture, the frames and the tags. | | [`rmp::Sprite`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html) | What an Object draws in place of its shape when it has one: a texture or a sheet, placed by `origin` around the object's position and turned, scaled and flipped with the object. | | [`rmp::Text`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html) | A text the framework draws: translated when it was a literal, as it is when it was made at runtime. | | [`rmp::TextArg`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-TextArg.html) | One placeholder's value: a name and a number or a text. | | [`rmp::Tilemap`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html) | A level read from an LDtk or a Tiled file: its tile layers, which cells are solid, and the objects placed in it. | | [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) | A tree: nothing, a bool, a number, a string, a list or an object — exactly what JSON holds, so a real structure fits and not only flat pairs. | | [`rmp::ui::Button`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html) | A button: text, an icon, or both. | | [`rmp::ui::Checkbox`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html) | A checkbox that holds its own value. | | [`rmp::ui::DialogueBox`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueBox.html) | The classic box: along the bottom of the screen, the speaker's portrait and name beside the line, the choices as buttons under it. | | [`rmp::ui::DialogueStage`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueStage.html) | A visual novel's stage: big portraits of who is on it, the speaker in front and the rest dimmed, and the line in a box under them. | | [`rmp::ui::Dropdown`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html) | A dropdown that holds its items and its choice. | | [`rmp::ui::Image`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html) | A picture with a style — a frame, a shadow — that can be clicked. | | [`rmp::ui::Label`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html) | Text, as `text()` draws it, with a style of its own: a title in another font, with an outline. | | [`rmp::ui::Panel`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html) | A container: a panel with a look of its own (`style`), and a look for everything inside it (`children`), which every descendant inherits — the nearest container's wins. | | [`rmp::ui::Picture`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html) | Anything `rmp::ui` can show. | | [`rmp::ui::ProgressBar`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html) | A progress bar with a look of its own: the style is the track's (its background, its skin), `fill` and `fill_picture` the bar's. | | [`rmp::ui::Slider`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html) | A slider that holds its own value. | | [`rmp::ui::SoundName`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-SoundName.html) | The name of a sound, as `rmp::audio::play()` takes it ("click" is click.wav, click.ogg...): written as a string, `.click = "click"`. | | [`rmp::ui::TextInput`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html) | A text field that holds its own text. | ============================================================================== # Resource handles > The RAII half, written once for every handle type. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-detail-Resource.html class `#include ` [include/rmp/assets.h:125](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L125-L220) The RAII half, written once for every handle type. Copy shares, move steals, and the last handle to a resource going away is what unloads it. ### `Resource` explicit Resource(Slot *slot) function [include/rmp/assets.h:131](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L131) An empty handle: `valid()` is false until a loader's result is assigned to it. The Slot constructor is how the loaders in [`rmp::assets`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html) make a full one, from a reference the resource table has already counted. ### `valid`, `operator bool` bool valid() const explicit operator bool() const function [include/rmp/assets.h:157](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L157) True when this handle holds a resource. False for one that failed to load, was never assigned, or was moved from; `if (texture)` asks the same. ### `name` std::string_view name() const function [include/rmp/assets.h:162](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L162-L164) The name it was loaded under — "ui.ttf", "player.aseprite" — or "" for an empty handle. Valid while this handle holds it. ### `changed`, `reload` bool changed() const requires(K == ResourceKind::TEXTURE) bool reload() requires(K == ResourceKind::TEXTURE) function [include/rmp/assets.h:177](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L177-L181) A texture loaded from a file in resources/ remembers it: `changed()` is true once the file differs from what the texture holds — the sprite redrawn and saved while the game runs — and `reload()` loads it again in place, so every handle to it draws the new picture: ```cpp if (rabbit.changed()) rabbit.reload(); ``` Debug builds on the desktop only, like [`rmp::Value::changed()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#changed); elsewhere, and for an empty handle, `changed()` is false and `reload()` does nothing. `changed()` compares two numbers: ask it every frame. `reload()` is false, and the texture as it was, when the file does not decode now. ### `raw` const T &raw() const function [include/rmp/assets.h:191](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L191-L195) An empty resource yields a zeroed raylib struct rather than a crash. raylib draws nothing for one of those, which is the behaviour a missing asset should have: a hole in the picture, not a dead process. ### `operator const T &` operator const T &() const & function [include/rmp/assets.h:205](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L205) Only an LVALUE converts. `DrawTexture(rabbit, ...)` compiles; `Texture2D t = load_texture("x.png");` does NOT, and that is the point — it converted, the temporary handle died on the same line, and `t` was a texture that had already been unloaded. The README and four examples had it, and so did the UI's own font. The deleted `&&` overload is what refuses the temporary: a `const &`-qualified function on its own would still accept one, because a const reference binds to an rvalue. ============================================================================== # rmp::Callback > A function the framework keeps and calls later with arguments of types A...: what on_click(), on_drag(), on_collision() and Tilemap::on_object() store, and the type of the `on_` fields of the behaviors. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Callback.html class `#include ` [include/rmp/object.h:186](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L186-L267) template class Callback A function the framework keeps and calls later with arguments of types A...: what `on_click()`, `on_drag()`, `on_collision()` and [`Tilemap::on_object()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html#on_object) store, and the type of the `on_` fields of the behaviors. A lambda converts to it; it moves and does not copy. ### `Callback` template requires(!std::is_same_v, Callback>) Callback(F &&fn) function [include/rmp/object.h:209](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L209-L213) So that a lambda can be written straight into a designated initialiser, which is the whole point of the behavior structs being aggregates. ### `set` template void set(F &&fn) function [include/rmp/object.h:217](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L217-L231) Stores `fn` in place of whatever was there. A function that cannot be called with A... is a compile error that says so. ### `clear` void clear() function [include/rmp/object.h:234](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L234-L237) Drops the stored function, and with it whatever it captured. ### `operator bool` explicit operator bool() const function [include/rmp/object.h:240](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L240) Whether a function is stored. ### `operator()` void operator()(A... args) const function [include/rmp/object.h:242](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L242-L244) Calls the stored function with `args`; an empty Callback does nothing. ============================================================================== # rmp::Camera > The camera Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html class `#include ` [include/rmp/scene.h:91](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L91-L191) class Camera The camera Owned by the scene, because the framing is a property of the context and not of any one object. Four things in this framework depend on it — the default `bounds`, [`rmp::input::pointer()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#pointer) in world units, the hit test behind on_click, and [`rmp::behavior::Parallax`](https://omardev29.github.io/rmp-docs/reference/behaviors/Parallax.html) — and they all read it from here. ```cpp camera.follow = player.handle(); camera.limits = map.bounds(); // never shows the void outside the map ``` It starts centred on the design resolution (`[window] width` x height), so a scene that never mentions it draws exactly where it always did: at that size the camera is the identity. `position` is the CENTRE of what is visible. On a window of another size it fits the world the way `[window] stretch` says ([`rmp::app::stretch()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#stretch)): under LETTERBOX and EXPAND the design is scaled into the window before `zoom` is applied, so `zoom = 2` is twice as big as the stretch drew it, and `view()`, `to_world()` and the pointer follow. Under NONE a bigger window shows more of the world at 1:1, as it always did. The app opens it around the map and the objects and closes it before [`Scene::_draw()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#_draw), which is why [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) inside `_draw()` does not drift with the view. Under LETTERBOX the map and the objects are also cut to the game's area, so the bars keep the clear colour. To draw in world units yourself: `BeginMode2D(camera.raylib())`. Two details that are written wrong by hand more often than not: - `limits` win over `follow`: when the player nears the edge of the map the camera stops and the player keeps going, instead of a black strip. - Smoothing is a rate with delta in the exponent, not a lerp per frame, and shake is a separate offset that decays on its own and never touches `position`. Both are explained where they are declared below. A number that is not finite — NaN or an infinity, the mark of a division by zero somewhere in the game — in a field below, an argument of `shake()` or the position of the object it follows never reaches what it draws or where it is: the camera uses the safe value the field names, and says so once in the log (`[dev] strict` stops a debug build there). ### `position` Vector2 position{ RMP_WINDOW_WIDTH / 2.0f, RMP_WINDOW_HEIGHT / 2.0f } field [include/rmp/scene.h:97](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L97) The world point at the centre of the view. While `follow` has a target the camera writes it every frame, and `limits` clamp it. One that is not a finite number goes back to the middle of the design — or to the target it follows — on the next frame. ### `zoom` float zoom = 1.0f field [include/rmp/scene.h:101](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L101) 2 = everything twice as big, on top of the stretch. From 1/1024 to 1024: past either end it stops there, and one that is not a positive number is 1. ### `rotation` float rotation = 0 field [include/rmp/scene.h:103](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L103) Degrees, clockwise, like raylib's Camera2D. Not a number: unturned. ### `follow` Handle follow field [include/rmp/scene.h:109](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L109) Follow this object: every frame, after it has moved, the camera centres on it. Empty = the camera stays where you left it. A handle, so a target that dies simply stops being followed. A target whose position is not a finite number is waited for: not followed on that axis until it is. ### `smoothing` float smoothing = 0 field [include/rmp/scene.h:124](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L124) How fast `follow` catches up, per second. 0 = it snaps, which is the default and what every one-screen game wants. 5 is a gentle drift, 20 is nearly a snap. It is a RATE and not a lerp factor per frame: the camera covers the same fraction of the distance in a second whether that second was 30 frames or 144, because delta is in the exponent — 1 - exp(-smoothing * delta). The per-frame `position += (target - position) * 0.1` that every tutorial writes follows twice as fast at 120 Hz as at 60, which is the bug this exists to not have. A NEW target is snapped to, not glided to: a level that opens with the camera drifting in from the middle of the screen is the other half of the same classic bug. An infinite rate snaps too, and so does one that is negative or not a number. ### `limits` Rectangle limits{} field [include/rmp/scene.h:133](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L133) Never show outside this rectangle, in world units. One axis at a time: a zero width or a zero height means "unbounded on that axis", so a runner pins y with `{ 0, 0, 0, RMP_WINDOW_HEIGHT }` and follows x freely. Empty = no limits. A limit narrower than the view centres the view on it. Applied AFTER the smoothing, so a smoothed camera still never shows the void past the edge of the level. An axis whose edge or size is not a finite number is unbounded. ### `shake` void shake(float strength, float seconds = 0.3f) function [include/rmp/scene.h:154](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L154) Shake the view: up to `strength` world units, fading to nothing over `seconds`. A hit, an explosion, a landing. The shake NEVER TOUCHES `position` or `view()`: it is an offset applied only to what is drawn, `raylib()` and the two conversions that go with it. So an object clamped to the view does not jitter, and the camera is exactly where it was when the shake ends — nothing to restore. And a click during a shake still lands on what is under the pointer, because `to_world()` converts through the same shaken camera that drew it. The drawn view is clamped to `limits` like the position is, so a shake near the edge of the level shakes inwards and never shows the void. Shaking again while a shake is running keeps the STRONGER of the two — measured against what the running one is doing now, not what it started at — rather than adding them, so a burst of hits cannot build a shake that throws the screen across the room. A short strong hit on a long shake lasts at least as long as the long one had left. A strength or duration that is not a positive finite number is ignored, and one that is not a finite number at all is said once. ### `shake_offset` Vector2 shake_offset() const function [include/rmp/scene.h:158](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L158) How far the shake asks to move the view right now; {0,0} when still. Near a limit less of it shows: `raylib()` clamps the result. ### `view`, `to_screen`, `to_world` Rectangle view() const Vector2 to_screen(Vector2 world) const Vector2 to_world(Vector2 screen) const function [include/rmp/scene.h:165](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L165) What is visible, in world units, ignoring rotation: the game's area of the window divided by the zoom and the stretch's scale. The window under NONE; the design under LETTERBOX, whatever the window; under EXPAND the design and more, the way the window is longer than the design's shape — taller on a 4:3 monitor, wider on a 21:9 one. ### `raylib` Camera2D raylib() const function [include/rmp/scene.h:172](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L172) The raylib camera this is, for `BeginMode2D()` in your own drawing. The stretch is in it: `offset` is the middle of the game's area, and `zoom` is this zoom times the stretch's scale. ============================================================================== # rmp::Condition > A question the framework asks later with arguments of types A...: a StateMachine's transition, an Animator's rule, whether a Draggable may be dropped. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Condition.html class `#include ` [include/rmp/object.h:274](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L274-L311) template class Condition A question the framework asks later with arguments of types A...: a StateMachine's transition, an Animator's rule, whether a Draggable may be dropped. A Callback that answers: a lambda returning something that converts to bool converts to it, and an empty one answers false. It moves and does not copy, for the reasons Callback gives. ### `Condition` template requires(!std::is_same_v, Condition>) Condition(F &&fn) function [include/rmp/object.h:284](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L284-L298) So that a lambda can be written straight into a designated initialiser. ### `operator bool` explicit operator bool() const function [include/rmp/object.h:301](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L301) Whether a function is stored. ### `operator()` bool operator()(A... args) const function [include/rmp/object.h:303](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L303-L307) The stored function's answer; an empty Condition answers false. ============================================================================== # rmp::Dialogue > A conversation: a compiled Yarn script, where it is in it, and what it remembers. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html class `#include ` [include/rmp/dialogue.h:224](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L224-L383) class Dialogue A conversation: a compiled Yarn script, where it is in it, and what it remembers. It draws nothing — the presenters of rmp/ui.h do, or the game. Moved, never copied. ### `Dialogue` Dialogue() function [include/rmp/dialogue.h:226](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L226) No script: `loaded()` is false ### `loaded`, `errors`, `has_node` bool loaded() const std::span errors() const bool has_node(std::string_view node) const function [include/rmp/dialogue.h:235](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L235) Whether a script is loaded and compiled; when not, `errors()` says why, a line each, as file:line:column: what is wrong. ### `start`, `stop`, `running`, `node` bool start(std::string_view node = "Start") void stop() bool running() const std::string node() const function [include/rmp/dialogue.h:240](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L240) Run from a node's first line. False when there is no such node. `running`: Started, not yet finished `node`: The node it is in, or empty ### `has_line`, `line`, `has_options`, `options`, `has_command`, `command` bool has_line() const const DialogueLine &line() const bool has_options() const std::span options() const bool has_command() const std::string_view command() const function [include/rmp/dialogue.h:247](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L247) What it is waiting for: a line to be read, a choice, or a command the game did not handle. Nothing of the three when it is not running. `line`: Empty when there is none `command`: Its text, {expressions} filled ### `advance` void advance() function [include/rmp/dialogue.h:255](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L255) On, past the line or the command. ### `choose` void choose(int index) function [include/rmp/dialogue.h:258](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L258) The option chosen, by its place in `options()`. When none is available, any number goes on past the options. ### `on_command` template void on_command(std::string_view name, F &&handler) function [include/rmp/dialogue.h:270](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L270-L289) <> calls `handler`, and the dialogue goes on by itself — or waits, when the handler calls `wait()` or `wait_until()`. A command nobody handles waits in `has_command()`. Typed: each word after the name arrives as the parameter asks, and a script that gives the wrong number of words, or a word that is not a number where one goes, is a mistake said once, the command not run: ```cpp talk.on_command("walk", [&](std::string who, float speed) { ... }); talk.on_command("shake", [&] { camera.shake(); }); ``` Or every word as written: [&](std::span words) { ... }. ### `on_function` template void on_function(std::string_view name, F &&function) function [include/rmp/dialogue.h:297](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L297-L317) `name(...)` in an expression. Typed: the parameters say what it takes and the result what it gives, and a call with the wrong number or kind of arguments is a mistake said once, never a call: ```cpp talk.on_function("has_item", [&](std::string item) -> bool { ... }); ``` Or untyped: [&]([`rmp::DialogueValue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html) &out, std::span args). Write the result type (-> bool): `rmp yarn ysls` reads it for the editor. ### `wait`, `wait_until` void wait(float seconds) template void wait_until(F &&done) function [include/rmp/dialogue.h:326](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L326) From inside a command's handler: the dialogue waits after the command, for `seconds`, or until `done()` is true (asked once a frame, from `waiting()`). <> waits by itself, when the game has no "wait". ```cpp talk.on_command("walk", [&](std::string where) { mika.walk_to(where); talk.wait_until([&] { return mika.arrived(); }); }); ``` ### `waiting` bool waiting() function [include/rmp/dialogue.h:336](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L336) Whether a command holds the dialogue: no line, no options, until its wait is over. Asking is what moves it on: once a frame, the presenters do it, or the game's own loop. ### `variable`, `set_variable` DialogueValue variable(std::string_view name) const void set_variable(std::string_view name, const DialogueValue &value) function [include/rmp/dialogue.h:339](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L339) $variables: what the script set, and what the game sets for it. ### `bind`, `visits` void bind(std::string_view name, int &variable) void bind(std::string_view name, float &variable) void bind(std::string_view name, bool &variable) void bind(std::string_view name, std::string &variable) void bind(std::string_view name, rmp::Callback get, rmp::Callback set) int visits(std::string_view node) const function [include/rmp/dialogue.h:349](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L349) A $variable that IS one of the game's: the script reads it and writes it, and nothing is copied. The script declares it, with its type (<>); a binding of another type, or of a variable the script does not declare, is a mistake said once. [`save()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) leaves bound variables out: they are the game's to save. The variable must outlive the dialogue. ```cpp talk.bind("$gold", player.gold); ``` `visits`: `Visited_count()` ### `save`, `load` void save(rmp::Value &out) const void load(const rmp::Value &in) function [include/rmp/dialogue.h:360](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L360) Everything the conversation remembers — variables, visits, what was seen once — into an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) for [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html), and back. ### `set_saliency` void set_saliency(DialogueSaliency saliency) function [include/rmp/dialogue.h:364](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L364) How line groups and node groups choose; LEAST_SEEN unless set. ### `Dialogue` explicit Dialogue(std::unique_ptr state) function [include/rmp/dialogue.h:367](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L367) The script's own: for the loaders below. ============================================================================== # rmp::DialogueValue > A value of the Yarn language: a number, a string or a bool. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html class `#include ` [include/rmp/dialogue.h:59](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L59-L98) class DialogueValue A value of the Yarn language: a number, a string or a bool. ### `Kind` enum class Kind : std::uint8_t enum [include/rmp/dialogue.h:62](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L62-L66) Which of Yarn's three types it holds. | Value | | Means | |---|---|---| | `NUMBER` | | A number; Yarn has one kind, a float | | `STRING` | | A piece of text | | `BOOL` | | True or false | ### `DialogueValue` DialogueValue(float number) DialogueValue(int number) DialogueValue(double number) DialogueValue(bool value) DialogueValue(std::string text) template // NOLINTNEXTLINE(google-explicit-con function [include/rmp/dialogue.h:71](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L71) Each one implicit, so `out = 3;` or `set_variable("$met", true)` reads as Yarn does. `DialogueValue`: A number `DialogueValue`: A number, as a float `DialogueValue`: A number, as a float `DialogueValue`: A bool `DialogueValue`: A string ### `kind` Kind kind() const function [include/rmp/dialogue.h:88](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L88) Which type it holds ### `as_number` float as_number() const function [include/rmp/dialogue.h:89](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L89) A string read as a number; a bool 1 or 0 ### `as_bool` bool as_bool() const function [include/rmp/dialogue.h:90](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L90) A number not 0; a string "true" ### `as_string` std::string as_string() const function [include/rmp/dialogue.h:91](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L91) As a line shows it: 2, 2.5, True ============================================================================== # rmp::Handle > A reference to an object that is safe to keep across frames. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html class `#include ` [include/rmp/object.h:434](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L434-L481) template class Handle A reference to an object that is safe to keep across frames. It gives the object back while it is alive, and nothing from the moment `destroy()` is called on it, even once its slot holds another object. [`Object::handle()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#handle) makes one; T is the type `get()` hands back. ### `get`, `operator bool`, `operator->`, `operator*` Ref get() const explicit operator bool() const T *operator->() const T &operator*() const function [include/rmp/object.h:459](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L459-L462) Empty until it points at something, and empty again the moment that something stops existing. A default-constructed handle has generation 0, which no live slot ever has. -> and * on a handle whose object is gone are the empty Ref's: said once, and a stand-in instead of a crash. Ask first: ```cpp if (target) target->hp -= 1; ``` ### `Handle` Handle(unsigned index, unsigned generation) function [include/rmp/object.h:479](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L479-L480) Public so [`Object::handle()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#handle) can build one without befriending every instantiation. Not for calling: the index and generation are ours. ============================================================================== # rmp::MapObject > One object placed in the map, as spawn_objects() hands it to the factory registered for its `type`: where it is, how big, and its properties. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-MapObject.html struct `#include ` [include/rmp/tilemap.h:89](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L89-L130) struct MapObject One object placed in the map, as `spawn_objects()` hands it to the factory registered for its `type`: where it is, how big, and its properties. ### `name` std::string_view name field [include/rmp/tilemap.h:90](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L90) The Tiled object's name; "" for an LDtk entity ### `type` std::string_view type field [include/rmp/tilemap.h:91](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L91) The LDtk entity; Tiled's `class` ### `iid` std::string_view iid field [include/rmp/tilemap.h:92](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L92) LDtk's unique id, what an EntityRef field holds ### `position` Vector2 position{} field [include/rmp/tilemap.h:93](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L93) THE CENTRE, like [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html); the editors give a corner ### `size` Vector2 size{} field [include/rmp/tilemap.h:94](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L94) Width and height in world units; {0,0} for a Tiled point ### `rotation` float rotation = 0 field [include/rmp/tilemap.h:95](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L95) Tiled's, in degrees clockwise; 0 for an LDtk entity ### `gid` int gid = 0 field [include/rmp/tilemap.h:96](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L96) 0 when it is not a tile object ### `property_bool`, `property_int`, `property_float` bool property_bool(std::string_view key, bool fallback = false) const int property_int(std::string_view key, int fallback = 0) const float property_float(std::string_view key, float fallback = 0) const function [include/rmp/tilemap.h:102](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L102) A property by name — an LDtk field, a Tiled custom property — or `fallback` when the object has none by that name or it holds another kind. `property_int()` also reads a float, cut towards zero, and `property_float()` also reads an int. ### `property_string` std::string_view property_string(std::string_view key, std::string_view fallback = "") const function [include/rmp/tilemap.h:106](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L106-L107) The map's text, or `fallback` as it was given: its lifetime is yours. ### `property_point`, `property_count` Vector2 property_point(std::string_view key, Vector2 fallback = {}) const Vector2 property_point(std::string_view key, int index, Vector2 fallback = {}) const int property_count(std::string_view key) const function [include/rmp/tilemap.h:115](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L115-L116) An LDtk Point field, as the WORLD position of the centre of the cell it names — the same units as `position`, so a patrol route or a platform's destination is used as it comes. A list of them (Array) is read by index; `property_count()` is how many there are, and 1 for any other field that exists. Enums read as text, colours as "#rrggbb", and an EntityRef as the iid of the entity it points at. ============================================================================== # rmp::Object > An entity in a scene: the player, an enemy, a bullet, a coin, a platform. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html class `#include ` [include/rmp/object.h:629](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L629-L939) class Object An entity in a scene: the player, an enemy, a bullet, a coin, a platform. [`Scene::spawn()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#spawn) makes one and the scene owns it; its public fields are the whole of its configuration, read and written directly. Derive from it to override the hooks (_ready, _update, _draw, _collision, _end), add behaviors to it with `add()`, or hand it functions with `on_click()`, `on_drag()` and `on_collision()`. ## Transform ### `position` Vector2 position{} field [include/rmp/object.h:645](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L645) THE CENTRE. See the header comment. ### `scale` Vector2 scale{ 1, 1 } field [include/rmp/object.h:646](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L646) Multiplies the shape, the collider and the sprite ### `rotation` float rotation = 0 field [include/rmp/object.h:647](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L647) Degrees, as raylib counts them ### `velocity` Vector2 velocity{} field [include/rmp/object.h:648](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L648) Integrated every frame, by us ### `mass` float mass = 1.0f field [include/rmp/object.h:649](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L649) Only apply_force / apply_impulse read it ## Appearance ### `sprite` Sprite sprite field [include/rmp/object.h:652](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L652) If there is a sprite, the sprite is drawn ### `shape` Shape shape field [include/rmp/object.h:653](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L653) Otherwise this is ### `flip_x` bool flip_x = false field [include/rmp/object.h:654](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L654) Mirrors the sprite left to right ### `flip_y` bool flip_y = false field [include/rmp/object.h:655](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L655) Mirrors the sprite top to bottom ### `visible` bool visible = true field [include/rmp/object.h:656](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L656) False: not drawn, but still updated and collided ### `layer` int layer = 0 field [include/rmp/object.h:657](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L657) Draw order; ties break on creation order ## World ### `gravity_scale`, `edges`, `bounds` float gravity_scale = 0 Edge edges = Edge::NONE Rectangle bounds{} field [include/rmp/object.h:664](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L664) 0 means gravity does not touch this object, and that default is not negotiable: a top-down game cannot have things falling over. The scene carrying a downward gravity that nobody uses until they ask is what lets one Object serve a platformer and a Zelda. `edges`: What happens at the edge of `bounds` `bounds`: Empty = the map's bounds, or the view without a map ### `collider` Shape collider field [include/rmp/object.h:676](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L676) What it collides AS. NONE means "the same as `shape`", or the sprite's frame when there is no shape — which is right until it is not, and the moment it is not is the most common step up in the whole API: a character's sprite includes hair, a cape and air, and nobody wants to collide with the air. ```cpp player.sprite.sheet = sheet; // drawn as the picture player.collider = rmp::rect({ 20, 44 }); // collided as a box ``` ### `solid`, `immovable` bool solid = false bool immovable = false field [include/rmp/object.h:701](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L701) Three fields, three different questions, and keeping them apart is what makes the common case free: ```text collider what shape? deduced from shape/sprite solid resolve, or notify? false: notify only immovable who gets moved? false: this one does ``` `solid` is false by default because most objects in a 2D game are not walls — bullets, coins, particles, pickups, triggers — and the two that are are exactly the two you configure: ```cpp ground.solid = true; ground.immovable = true; player.solid = true; player.gravity_scale = 1; ``` Whoever is pushed apart loses the part of its velocity going INTO the contact, after the _collision hooks have run — so a box resting on another starts from rest when the one below moves away, a jump off it keeps its jump, and a hook that flips the velocity to bounce loses nothing. The scene's map counts as ground too: an object that is solid and not immovable is stopped by the map's solid cells as it moves, each axis on its own, so it runs along a floor of tiles without catching on the seams. ### `collision_layer`, `collision_mask` unsigned collision_layer = 1 unsigned collision_mask = 1 field [include/rmp/object.h:720](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L720) Godot's model, because it is the right one. Two objects interact when either one's mask touches the other's layer. Both default to 1, so everything collides with everything and the simple case pays nothing — the Pong in 01-principles.md never mentions a layer. Without them there are three things you cannot say, and they turn up in about the fourth game anybody writes: that the player's bullet must not hit the player, that enemies pass through each other but not through walls, and that a trigger sees the player and nothing else. The alternative is an `if` at the top of every _collision, which is the mechanical work this framework exists to absorb. ```cpp namespace layer { constexpr unsigned PLAYER = 1 << 0, ENEMY = 1 << 1, BULLET = 1 << 2, WORLD = 1 << 3; } bullet.collision_layer = layer::BULLET; bullet.collision_mask = layer::ENEMY | layer::WORLD; // not the player ``` `collision_layer`: Which layers I am ON `collision_mask`: Which layers I collide WITH ## What you override, all of it empty by default ### `_ready` virtual void _ready() hook [include/rmp/object.h:726](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L726) 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`, `_draw`, `_end` virtual void _update(float delta) virtual void _draw() virtual void _end() hook [include/rmp/object.h:733](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L733) Every frame the object is alive, after its behaviors' _update and before it is moved by its velocity. A new object's first _update depends on where in the frame it was spawned: before the object pass — from the scene's _update or an on_click — it is the same frame; during the pass — from an object's or a behavior's _update — or after it, from a _collision, it is the frame after. `_draw`: The sprite and the shape draw themselves `_end`: On destruction: drop loot, tell somebody ### `_collision` virtual void _collision(Object &other) hook [include/rmp/object.h:741](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L741) Once per pair per frame, on BOTH objects: a touching b calls `a._collision(b)` and `b._collision(a)`. It fires whether or not either one is `solid` — solid decides whether they are pushed apart, not whether you are told. ## Forces ### `apply_force`, `apply_impulse` void apply_force(Vector2 force) void apply_impulse(Vector2 impulse) function [include/rmp/object.h:757](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L757) The difference between these two is the whole physics API: ```text if you call it every frame it is a force; if you call it once it is an impulse. ``` Both exist because using the wrong one gives exactly the bug you would expect. A force applied once barely moves anything, and an impulse applied every frame goes twice as fast at 120 fps as at 60. Either one that is not a number — or that would leave the velocity past what a float holds — is refused and said once, and so is a frame that would: the object stops where it is rather than carrying a NaN into its position and from there into everything it touches. `apply_force`: Sustained: velocity += f/mass*delta `apply_impulse`: Instant: velocity += i/mass ## Behaviors ### `add`, `get`, `has`, `remove` template B &add(B value = {}) template Ref get() const template bool has() const template void remove() function [include/rmp/object.h:807](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L807) A behavior is ANY struct with `void _update(rmp::Object &, float)`. It inherits from nothing, has no virtuals and registers nowhere: ```cpp struct Spin { float degrees_per_second = 90; void _update(rmp::Object &self, float delta) { self.rotation += degrees_per_second * delta; } }; coin.add({ .degrees_per_second = 180 }); ``` That is the whole model, and the absence of a base class is not taste: a struct with a base and virtual functions stops being an aggregate in C++20, and `{ .speed = 320 }` no longer compiles against it. The usual workaround — a nested options struct and a constructor taking it — turns every later read into `get()->opts.speed`. Without inheritance the fields ARE the configuration, hot: ```cpp if (auto move = player.get()) move->speed = 400; ``` get() is an `rmp::Ref:` empty when the object has no B, and the `if` is how you ask. And the part that was not aimed for and turns out to be the best of it: one of yours and one of ours are literally the same thing. There is no extension API to learn because there is no extension. The optional hooks are detected at compile time with `requires`, so what you do not declare costs nothing: ```cpp _update(Object &, float) every frame, BEFORE the integrator _late_update(Object &, float) every frame, AFTER it ``` One of those two is required and the rest are optional. ```cpp _ready(Object &) once, when it is added _draw(Object &) after the object is drawn _collision(Object &, Object &other) once per pair per frame _end(Object &) when removed, or the object dies ``` _late_update is not decoration. Behaviors run before the velocity is integrated, because that is what lets one WRITE velocity — and a behavior whose job is to correct where the object ENDED UP therefore has nowhere to run. [`rmp::behavior::GridSnap`](https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html) is exactly that: it exists to leave a puzzle piece square with the grid, and rounding the position the object had before it moved would round the wrong number. ### `enable`, `enabled` template void enable(bool on = true) template bool enabled() const function [include/rmp/object.h:825](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L825-L827) Pauses a behavior without taking it off, and resumes it. A paused one keeps its fields and what it was keeping track of, and 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. How an enemy stops patrolling while it chases: ```cpp self.enable(false); ``` Nothing happens for an object without a B, and enabled() is false for it. A behavior is enabled when it is added, and adding it again replaces it with an enabled one. ## Callbacks, for when a subclass is more than you want ### `on_click`, `on_drag`, `on_collision` template void on_click(F &&fn) template void on_drag(F &&fn) template void on_collision(F &&fn) function [include/rmp/object.h:854](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L854-L856) The other half of the underscore rule: `_name` is yours and we call it, `on_name` is ours and you hand us a function. They coexist without ambiguity, which is the whole reason the rule exists — an object can override _collision AND carry an on_collision, and both run. ```cpp coin.on_collision([&](rmp::Object &self, rmp::Object &other) { if (&other == &player) { score += 10; self.destroy(); } }); ``` Setting one twice replaces it. There is no list, because a list of handlers is a signal system, and that is a bigger idea than this needs. on_drag is handed how far the pointer moved since the last frame while it holds this object, in WORLD units — through the scene's camera, so adding it to the position keeps the object under the finger at any zoom: ```cpp piece.on_drag([](rmp::Object &self, Vector2 moved) { self.position.x += moved.x; self.position.y += moved.y; }); ``` ## Identity and life ### `handle` template Handle handle() const function [include/rmp/object.h:866](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L866-L868) `handle()` is the plain one and handle() is the typed one, which is what a behavior holding a target wants: `if (!target) return;` and then `target->hp` without a cast. ### `scene` Scene &scene() const function [include/rmp/object.h:872](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L872) The scene that spawned it. An object no scene spawned — a member, a local, a test's — has none: asking is said once, and answers [`Scene::current()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html#current). ### `world_bounds` Rectangle world_bounds() const function [include/rmp/object.h:879](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L879) The axis-aligned box this object occupies right now, from the sprite or the shape. Empty when it has neither, which is what an invisible logic object is. With no `collider` and no `shape`, this box is what the object collides as, and an empty one collides with nothing. A shape's mirrored scale or negative size is still a size: the same box. ### `world_collider` Rectangle world_collider() const function [include/rmp/object.h:887](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L887) The box the collider occupies right now: `collider` if it has one, else `world_bounds()`. For debug drawing and for a game doing its own query — the collision pass works with the precise shape and not with this box, so a circle collides as a circle. A shape whose box is not a finite number — a NaN or an infinity in its position, size or scale — is nowhere, and collides with nothing. ### `destroy` void destroy() function [include/rmp/object.h:891](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L891) Deferred: the object stops updating and drawing IMMEDIATELY, and its memory is released after the frame. Calling it twice is harmless. ### `alive` bool alive() const function [include/rmp/object.h:895](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L895) False from the moment `destroy()` is called, not from the moment the memory goes away. ============================================================================== # rmp::Ref > An optional reference: something that may not be there, and is not yours. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Ref.html class `#include ` [include/rmp/object.h:383](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L383-L406) template class Ref An optional reference: something that may not be there, and is not yours. ```cpp if (auto health = player.get()) health->hp -= 1; ``` What [`Object::get`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#get)() and [`Handle::get()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html#get) hand back. It is empty, or it refers to something; it owns nothing, and asking it is the `if` above — true when there is something, and then -> and * reach it. Keep it within the frame, like the reference `spawn()` returns; across frames, keep the Handle. Not a `T *`: a pointer cannot say whether it may be null or whose it is, and this type says both. Not std::optional> either, which says the same for the price of in every file with an object in it, and reads as `health->get().hp`. REACHING INTO AN EMPTY ONE is a mistake in the game, and is said once, per type: * and -> then reach a stand-in, a default T made for the purpose and made again on every use, so the line that forgot the `if` writes to nothing instead of taking the player's game down with it. (`[dev] strict` stops a debug build there instead.) A type with no default constructor has no stand-in, and that one mistake ends the program — with the same message. ### `Ref` explicit Ref(T &target) function [include/rmp/object.h:388](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L388) Refers to `target`, which stays whoever's it was. ### `operator bool` explicit operator bool() const function [include/rmp/object.h:391](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L391) True when it refers to something. ### `operator*`, `operator->`, `operator==` T &operator*() const T *operator->() const bool operator==(const Ref &ref, std::nullptr_t) function [include/rmp/object.h:393](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L393-L396) What it refers to — or, empty, the stand-in above, and a line in the log. ============================================================================== # rmp::Scene > A screen of the game -- a main menu, a level, a pause overlay -- with its own objects, `map` and `camera`. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Scene.html class `#include ` [include/rmp/scene.h:200](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L200-L423) class Scene A screen of the game — a main menu, a level, a pause overlay — with its own objects, `map` and `camera`. Derive from it and override the hooks you need. The app keeps scenes on a stack: the top one runs, and the ones below it run, draw and hear input as far as updates_below, draws_below and input_below let them. The static functions — `change()`, `push()`, `replace()`, `pop()`, `current()`, `depth()` — are that stack, and work from anywhere. ## What you override ### `_ready` virtual void _ready() hook [include/rmp/scene.h:219](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L219) Once, when the scene enters the stack. The window exists by now, so this is where assets load. ### `_end` virtual void _end() hook [include/rmp/scene.h:226](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L226) Once, when it leaves for good. Not called for a suspend — see _suspend. It is `_end` and not `_exit` because `exit()` is a POSIX function, and a member called `exit()` in a class the user writes is a name that shadows it in a way nobody enjoys debugging. ### `_suspend`, `_resume` virtual void _suspend() virtual void _resume() hook [include/rmp/scene.h:232](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L232) The scene stops being updated for a while, and later starts again: a scene was pushed on top of it and came off again, or — for the scene on top, under `[window] pause_unfocused` — the window lost its focus and got it back. The scene is still alive and still owns everything it owned. ### `_update` virtual void _update(float delta) hook [include/rmp/scene.h:237](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L237) Every frame, bottom of the stack upwards, skipping whatever the scene above freezes. `delta` is seconds since the last frame. ### `_draw` virtual void _draw() hook [include/rmp/scene.h:243](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L243) Every frame, in SCREEN SPACE. The app closes the camera before calling this, so [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) inside it cannot drift with the view — a pause menu stays where it is while the player moves. To draw in world coordinates, open the camera yourself for the few lines that need it. ## What this scene lets through to whatever is underneath it The defaults ARE a pause menu: push a scene with none of these touched and the world below freezes, stays visible, and stops receiving input. That is why a pause scene in this framework writes no policy at all. ### `updates_below` bool updates_below = false field [include/rmp/scene.h:252](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L252) The scene below keeps running ### `draws_below` bool draws_below = true field [include/rmp/scene.h:253](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L253) The scene below stays on screen ### `input_below` bool input_below = false field [include/rmp/scene.h:254](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L254) The scene below still sees input ### `background` Color background = BLANK field [include/rmp/scene.h:259](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L259) The colour the frame is cleared with. BLANK means "the theme's", which is what almost every scene wants. Only the LOWEST drawing scene's choice is used: the ones above it are drawn over what is already there. ### `gravity` Vector2 gravity{ 0, 980 } field [include/rmp/scene.h:266](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L266) The world's gravity, in units per second squared, pointing down the way everyone expects. It belongs to the scene and not to each object because direction and magnitude are a property of the world; each object then says how much of it applies to it, through [`Object::gravity_scale`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#gravity_scale), which is 0 by default. Nothing falls until something asks to. ### `map` Tilemap map field [include/rmp/scene.h:280](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L280) The level, designed in LDtk or in Tiled (rmp/tilemap.h says which reads what). A field and not something you draw: ```cpp map = rmp::assets::load_map("world.ldtk"); ``` and the scene draws it underneath everything, stops a solid object that moves at its solid cells, and `object.bounds` left empty comes to mean THE MAP'S bounds rather than the view's. An empty map costs nothing, and a menu scene simply never touches it. That is what turns the editor from a file format into the place you design the level: you put the enemies in it and they turn up in the game. ### `camera` Camera camera{} field [include/rmp/scene.h:284](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L284) The framing. See [`rmp::Camera`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Camera.html) above; a scene that never touches it draws in screen units, exactly as before it existed. ## Objects spawn() default-constructs T, applies the options, puts it in this scene and calls its `_ready()`. T only has to be default-constructible — there is no `using Object::Object;` and no forwarding constructor to write, which is the usual toll for this pattern. Whatever your type needs goes in its fields or in its `_ready()`. It returns T&, and that reference is good for the whole frame you got it in, because destruction is deferred to the end of the frame: ```cpp auto &bullet = spawn({ .position = muzzle }); bullet.velocity = aim * 900; ``` Kept across frames it can dangle. That is what [`rmp::Handle`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Handle.html) is for. ### `spawn` template T &spawn(const ObjectOptions &options = {}) function [include/rmp/scene.h:303](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L303-L319) ### `destroy` void destroy(Object &object) function [include/rmp/scene.h:323](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L323) Same as `object.destroy()`. Deferred: it stops updating and drawing at once, and the memory goes after the frame. Twice is harmless. ### `object_count` int object_count() const function [include/rmp/scene.h:327](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L327) How many live objects this scene has. Objects destroyed earlier in this frame are already not counted. ## Raycasting See the block above RayQuery in rmp/object.h for what it is for and why it walks the collision grid instead of the object list. ```cpp if (auto hit = raycast(muzzle, muzzle + aim * 400)) { ... } auto hit = raycast({ .from = muzzle, .to = target, .mask = layer::ENEMY, .ignore = self.handle() }); ``` ### `raycast` RayHit raycast(Vector2 from, Vector2 to) const RayHit raycast(const RayQuery &query) const function [include/rmp/scene.h:339](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L339) ### `raycast_all` int raycast_all(const RayQuery &query, std::span out) const function [include/rmp/scene.h:348](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L348) Every hit along the ray, nearest first, as many as `out` holds. Returns how many were written. Everything the ray passes through, for a piercing shot or a line of sight that has to know what is in the way: ```cpp std::array hits; const int n = raycast_all({ .from = a, .to = b }, hits); ``` ## Navigation ### `change` template static void change(A &&...args) static function [include/rmp/scene.h:375](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L375-L378) Clear the stack and go. Everything on it gets `_end()`, top down. ### `push` template static void push(A &&...args) static function [include/rmp/scene.h:381](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L381-L384) Put one on top. What was there is suspended, not ended. ### `replace` template static void replace(A &&...args) static function [include/rmp/scene.h:389](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L389-L392) Swap the top one only. What is underneath is untouched and stays suspended — this is level 3 becoming level 4 without disturbing the pause menu that put you there. ### `pop` static void pop() static function [include/rmp/scene.h:398](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L398) Take the top one off and resume what was under it. Popping the last scene is refused with a warning rather than leaving the app with nothing to draw: on desktop that is a black window, and on iOS there is no way to get back. Call [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) if leaving is what you meant. ### `current` static Scene ¤t() static function [include/rmp/scene.h:401](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L401) The top of the stack. Never null while the app is running. ### `depth` static int depth() static function [include/rmp/scene.h:404](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/scene.h#L404) How many scenes are on the stack. ============================================================================== # rmp::SheetData > Everything read out of an .aseprite: the packed texture, the frames and the tags. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-SheetData.html struct `#include ` [include/rmp/assets.h:272](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L272-L307) struct SheetData Everything read out of an .aseprite: the packed texture, the frames and the tags. The tables are vectors and the sheet owns them: a resource slot holds the whole SheetData behind a shared_ptr, so the language frees them with it and there is no size limit on frames or tags. The texture is the one thing here raylib owns, and the table unloads it before the sheet goes. ### `texture`, `width`, `height`, `frames`, `tags`, `slices` Texture2D texture{} int width = 0 int height = 0 std::vector frames std::vector tags std::vector slices field [include/rmp/assets.h:275](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L275) Every frame side by side in one row. Empty (id 0) when there was no GPU to upload to; the frames and tags are there all the same. `width`: One frame's width, not the packed texture's `height`: One frame's height, which is the packed texture's too `frames`: In the file's order `tags`: In the file's order `slices`: In the file's order ### `frame_count`, `tag_count` int frame_count() const int tag_count() const function [include/rmp/assets.h:283](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L283) How many frames and tags the file had. ### `frame` const SheetFrame &frame(int index) const function [include/rmp/assets.h:286](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L286-L290) The frame at `index`, or an empty one (no source, 0 seconds) out of range. ### `slice_count` int slice_count() const function [include/rmp/assets.h:292](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L292) How many slices the file had. ### `slice` const SheetSlice &slice(std::string_view name) const function [include/rmp/assets.h:295](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L295-L300) The slice called `name`, or an empty one (no name, no bounds) when there is none. The first one, when two share a name. ### `tag` const SheetTag &tag(int index) const function [include/rmp/assets.h:302](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/assets.h#L302-L306) The tag at `index`, or an empty one (no name, frames 0 to 0) out of range. ============================================================================== # rmp::Sprite > What an Object draws in place of its shape when it has one: a texture or a sheet, placed by `origin` around the object's position and turned, scaled and flipped with the object. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Sprite.html struct `#include ` [include/rmp/object.h:103](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L103-L144) struct Sprite What an Object draws in place of its shape when it has one: a texture or a sheet, placed by `origin` around the object's position and turned, scaled and flipped with the object. A sheet also animates; `play()` picks the tag. ### `texture` rmp::Texture texture field [include/rmp/object.h:104](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L104) A loose picture, when there is no animation ### `sheet` rmp::SpriteSheet sheet field [include/rmp/object.h:105](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L105) An .aseprite; `sheet` wins over `texture` ### `source` Rectangle source{} field [include/rmp/object.h:106](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L106) {0,0,0,0} = the whole texture, or the sheet's frame ### `origin` Vector2 origin{ 0.5f, 0.5f } field [include/rmp/object.h:107](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L107) NORMALISED, and centred by default ### `size` Vector2 size{} field [include/rmp/object.h:108](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L108) {0,0} = the source's own size ### `tint` Color tint = WHITE field [include/rmp/object.h:109](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L109) Multiplies the picture's colours; WHITE leaves them as they are ### `speed` float speed = 1.0f field [include/rmp/object.h:110](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L110) 2 = twice as fast, 0 = frozen, -1 = backwards ## Animation, when there is a sheet ### `play`, `stop`, `finished`, `playing` void play(std::string_view tag, bool loop = true) void stop() bool finished() const std::string_view playing() const function [include/rmp/object.h:125](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L125) ```cpp player.sprite.sheet = rmp::assets::load_sheet("player.aseprite"); player.sprite.play("walk"); // "walk" is a tag of YOURS ``` A literal, a std::string or a std::string_view, as it comes. `playing()` hands back the sheet's own name for the tag, or "" when nothing plays: valid for as long as the sheet is loaded, and the characters after it are a NUL, which tests/animation_test.cpp holds it to. A tag that is not in the sheet WARNS ONCE and does nothing — it does not land on a blank frame, and it does not fill the console sixty times a second saying so. ### `frame_index`, `set_frame` int frame_index() const void set_frame(int index) function [include/rmp/object.h:131](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L131) The escape hatch: drive the frames yourself. ### `ours` struct { … } ours field [include/rmp/object.h:136](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/object.h#L136-L143) What it is keeping track of. See the note on `ours` in rmp/behavior.h: public because a private member would stop this being an aggregate. ============================================================================== # rmp::Text > A text the framework draws: translated when it was a literal, as it is when it was made at runtime. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Text.html class `#include ` [include/rmp/text.h:82](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L82-L133) class Text A text the framework draws: translated when it was a literal, as it is when it was made at runtime. ### `Text` template // NOLINTNEXTLINE(google-explicit-const template requires(std::convertible_to && !std::is_array_v) Text(const S &runtime) // NOLINT(google-explicit-constructor): every string is a Text Text(std::string_view key, const TextOptions &options) Text(std::string_view key, std::initializer_list args, const TextOptions &options = {}) function [include/rmp/text.h:88](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L88-L91) A literal: translated, and the key is its own words. A reference to the array, so a literal and a runtime string are told apart by their type. ### `key`, `context`, `translated`, `args` std::string_view key() const std::string_view context() const bool translated() const std::span args() const function [include/rmp/text.h:106](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L106) What the tables are looked up by: the text as the code wrote it. ### `str` std::string str() const function [include/rmp/text.h:113](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L113) The text to show: translated into the current language, its plural form chosen and its placeholders filled. ### `id` std::string id() const function [include/rmp/text.h:117](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L117) The identity a widget keeps across languages: the key and its context, never the translation — so focus and hover survive [`rmp::lang::set()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-lang.html#set). ============================================================================== # rmp::TextArg > One placeholder's value: a name and a number or a text. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-TextArg.html class `#include ` [include/rmp/text.h:52](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L52-L78) class TextArg One placeholder's value: a name and a number or a text. ### `TextArg` template requires(std::is_arithmetic_v && !std::is_same_v && !std::is_same_v) TextArg(std::string_view name, N value) TextArg(std::string_view name, std::string_view value) function [include/rmp/text.h:55](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L55-L60) A number: it fills {name}, and chooses the plural form. ### `name` std::string_view name() const function [include/rmp/text.h:64](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L64) The {name} it fills ### `numeric` bool numeric() const function [include/rmp/text.h:65](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L65) A number, not a text ### `number` double number() const function [include/rmp/text.h:66](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L66) The number; 0 for a text ### `text` std::string text() const function [include/rmp/text.h:68](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/text.h#L68) The value as it is written into the text. ============================================================================== # rmp::Tilemap > A level read from an LDtk or a Tiled file: its tile layers, which cells are solid, and the objects placed in it. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Tilemap.html class `#include ` [include/rmp/tilemap.h:137](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L137-L224) class Tilemap A level read from an LDtk or a Tiled file: its tile layers, which cells are solid, and the objects placed in it. Every Scene has one in `map`, which [`rmp::assets::load_map()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_map) fills; it moves and does not copy. ### `Tilemap` Tilemap() function [include/rmp/tilemap.h:142](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L142) Declared here and defined in tilemap.cpp, all of them: MapData is incomplete in this header, and even a defaulted constructor written here would instantiate the unique_ptr's deleter against it. ### `valid`, `operator bool` bool valid() const explicit operator bool() const function [include/rmp/tilemap.h:155](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L155) Whether a map is loaded: false for an empty one, and for one whose file was missing or did not parse. Every query below then answers zero, empty or false, and `on_object()` registers nothing. ### `bounds` Rectangle bounds() const function [include/rmp/tilemap.h:158](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L158) In world units ### `tile_size` Vector2 tile_size() const function [include/rmp/tilemap.h:159](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L159) One cell, in world units ### `layer_count` int layer_count() const function [include/rmp/tilemap.h:160](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L160) How many tile layers; 0 is the bottom one ### `object_count` int object_count() const function [include/rmp/tilemap.h:161](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L161) How many MapObjects it holds ## The levels of an LDtk world ### `level`, `neighbour_at` std::string_view level() const std::string_view neighbour_at(Vector2 world_position) const function [include/rmp/tilemap.h:176](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L176) The level this map is, and the OTHER level of its world at a point — "" while the point is still in this one, or in none. So walking into the next level is ```cpp const std::string_view next = map.neighbour_at(player.position); if (!next.empty()) rmp::Scene::change(std::string(next), player.position); ``` and the new scene loads that level and puts the player back where it was: the coordinates are the world's, so they still mean the same place. Tiled maps and LDtk's linear layouts have no world, and always say "". Views of the parsed map, each followed by a NUL: valid while it is loaded. ## Object layers -> objects in the scene ### `on_object`, `spawn_objects` void on_object(std::string_view type, Callback factory) void spawn_objects(Scene &into) function [include/rmp/tilemap.h:190](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L190) A type with no factory registered comes out as a plain [`rmp::Object`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html) with the position, the size and a collider — and `solid` already set WHEN THE EDITOR GAVE IT AN AREA, which is the right default for a wall or a platform drawn in the editor. A point, and anything else whose width or height is zero, is a marker rather than a shape and comes out non-solid: an invisible collider at a spawn point is not what anybody drew. Registering the same class twice REPLACES, because two factories for one class is never what anybody means. ## Queries, for whatever you want to do yourself ### `tile_at` int tile_at(int layer, int column, int row) const function [include/rmp/tilemap.h:198](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L198) The tile in one cell of one layer, as its global tile id: 0 when the cell is empty, outside the layer, or there is no map. Layers count from 0 in the order the file has them, and the cell is in that layer's own grid. For LDtk it is the topmost tile of the cell. ### `solid_at` bool solid_at(Vector2 world_position) const function [include/rmp/tilemap.h:202](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L202) Whether a solid cell is under a point, in world units, on any layer: an LDtk IntGrid cell painted with `solid`, any tile of a Tiled layer whose class is `solid`, or a tile its tileset marks solid. False with no map. ### `solid_in` bool solid_in(Rectangle world_rect) const function [include/rmp/tilemap.h:205](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L205) Whether a solid cell covers any of the rectangle. Only touching it is not: a box standing on the floor is not in the floor. ### `draw` void draw() const void draw(Rectangle area) const function [include/rmp/tilemap.h:212](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/tilemap.h#L212) Drawn by the scene, underneath everything. Here because a game that wants the map somewhere else in its own order can call it. The scene draws only what its camera shows — `draw(area)`, with `area` the world rectangle in view — so a level a hundred screens long costs what one screen costs; `draw()` is every tile. ============================================================================== # rmp::Value > A tree: nothing, a bool, a number, a string, a list or an object -- exactly what JSON holds, so a real structure fits and not only flat pairs. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html class `#include ` [include/rmp/save.h:64](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L64-L221) class Value A tree: nothing, a bool, a number, a string, a list or an object — exactly what JSON holds, so a real structure fits and not only flat pairs. ### `Type` enum class Type enum [include/rmp/save.h:70](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L70) What a Value holds, one kind per JSON value. NONE is nothing: a missing key, an index out of range, a default-constructed Value, and JSON's null. BOOL is true or false, NUMBER a double, STRING text. LIST is values in order, and OBJECT is keys naming values, in the order they were added. | Value | | Means | |---|---|---| | `NONE` | | | | `BOOL` | | | | `NUMBER` | | | | `STRING` | | | | `LIST` | | | | `OBJECT` | | | ### `Value` template requires std::is_same_v // NOLINTNEXTLINE(google-explicit-constructor): v["alive"] = true; a bool is a Value Value(B b) template requires(std::is_arithmetic_v && !std::is_same_v) // NOLINTNE template requires(std::is_convertible_v && !std::is_pointer_v && !std::is_null_pointer_v) // NOLINTNEXTLINE(goo function [include/rmp/save.h:76](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L76-L79) A template so that only a real bool gets here: as a plain `Value(bool)`, every pointer in the program would quietly convert to `true`. ### `list`, `object` static Value list() static Value object() static function [include/rmp/save.h:100](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L100) An empty list or object, for when "nothing yet" has to be one of them: v["inventory"] = [`rmp::Value::list()`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html#list); ## Reading: never throws, never changes anything ### `as_bool`, `as_int`, `as_float` bool as_bool(bool fallback = false) const int as_int(int fallback = 0) const float as_float(float fallback = 0) const function [include/rmp/save.h:109](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L109) The fallback when this is not of that type — a missing key is NONE. Types are not converted: a number is not a bool and "7" is not 7. as_int truncates towards zero and clamps to int's range; as_float clamps to float's, so a number in a save never reads as an infinity. ### `as_string` std::string_view as_string(std::string_view fallback = "") const function [include/rmp/save.h:114](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L114) Valid while this Value is alive and unchanged — and adding to the object or list that holds it moves it. The fallback's lifetime is yours. ### `type` Type type() const function [include/rmp/save.h:118](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L118) What this holds. Reading never needs it — a read of the wrong type gives its fallback — but walking a Value you did not write does. ### `size` int size() const function [include/rmp/save.h:122](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L122) Elements of a list, keys of an object; 0 for anything else. A member assigned NONE counts as absent, here and in `key()`, `contains()`, == and the file: nothing and missing read the same. ### `contains` bool contains(std::string_view key) const function [include/rmp/save.h:124](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L124) Whether this is an object with that key. False for anything else. ### `key` std::string_view key(int index) const function [include/rmp/save.h:127](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L127) The i-th key of an object, in the order the keys were added; "" out of range. With operator[](key) it is how to walk an object you did not write. ## Structure ### `operator[]` const Value &operator[](std::string_view key) const const Value &operator[](int index) const Ref operator[](std::string_view key) Ref operator[](int index) function [include/rmp/save.h:142](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L142) [] on a const Value reads: a missing key, an index out of range, or a Value of another type is NONE. [] on a non-const Value gives a Ref — a path into this Value that READS exactly like the const one, creating nothing, and WRITES by creating what is missing on the way: v["a"]["b"].`as_int(1)` leaves v as it was, v["a"]["b"] = 1 builds both objects. So reading a save never grows it, and a read never says anything. A write that cannot land — through a number read from an old save, at a negative index, past the end of a list (`size()` appends one) — goes nowhere and is said once: turning a number into an object behind your back would lose it. ### `push` void push(Value value) function [include/rmp/save.h:149](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L149) Append. NONE becomes a list first; anything else that is not a list is left alone and said once. ### `erase` bool erase(std::string_view key) function [include/rmp/save.h:151](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L151) Remove a key from an object. False when it was not there. ### `version` int version() const function [include/rmp/save.h:155](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L155) The `[save] version` this came from, when [`rmp::save::read()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html#read) filled it; a Value made in code is of this build's version. Not compared by ==. ### `changed` bool changed() const function [include/rmp/save.h:171](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L171) A Value read with [`rmp::assets::load_value()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_value) remembers its file in resources/: `changed()` is true once the file differs from what this Value holds — edited and saved while the game runs — and `reload()` reads it again into this Value, which keeps remembering it: ```cpp if (tuning.changed()) tuning.reload(); speed = tuning["speed"].as_float(200); ``` Debug builds on the desktop only: a release reads its resources from the pack, which does not change, and everywhere else `changed()` is false. Cheap enough for every frame: `changed()` compares two numbers, and the file itself is looked at four times a second at most. A Value made in code, read from a save or taken out of another (tuning["enemy"]) has no file: `changed()` is false and `reload()` does nothing. Neither is compared by ==. ### `reload` bool reload() function [include/rmp/save.h:174](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L174) Reads the file again into this Value; false, and this Value as it was, when it has no file or the file is not JSON now (half saved, say). ### `operator==` bool operator==(const Value &a, const Value &b) function [include/rmp/save.h:178](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L178) Same type and same contents, keys in any order. A true equality: a NaN equals a NaN, so a Value always equals itself and every copy of it. ## `Value::Ref` class [include/rmp/save.h:233](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L233-L301) What [] on a non-const Value gives: the root it started from and the keys and indices it went through, looked up again on every use — so a Ref kept while other keys are added never points at moved memory. You do not name this type; you index, read and assign through it: ```cpp v["player"]["x"] = 3; // creates "player" int x = v["player"]["x"].as_int(0); // creates nothing const rmp::Value &p = v["player"]; // the Value itself, to read ``` To fill a whole subtree, build it and assign it: v["player"] = player; ### `get` const Value &get() const function [include/rmp/save.h:236](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L236) Reading: the Value this names, or NONE where the path leads nowhere. ### `operator const Value &` operator const Value &() const function [include/rmp/save.h:240](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L240) The Value it names, wherever a `const rmp::Value &` is wanted: a Ref passes where a Value is read. ### `as_bool`, `as_int`, `as_float`, `as_string`, `type`, `size`, `contains`, `key` bool as_bool(bool fallback = false) const int as_int(int fallback = 0) const float as_float(float fallback = 0) const std::string_view as_string(std::string_view fallback = "") const Type type() const int size() const bool contains(std::string_view key) const std::string_view key(int index) const function [include/rmp/save.h:242](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L242-L244) Value's reads, answered from `get()`: they create nothing. ### `operator[]` Ref operator[](std::string_view key) const Ref operator[](int index) const function [include/rmp/save.h:260](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L260) Deeper, still creating nothing. ### `operator=` Ref &operator=(Value value) function [include/rmp/save.h:265](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L265) Writing: the path is created, then assigned. A Ref assigned from a Ref copies the VALUE, never the path — v["a"] = v["b"] copies b into a. ### `push`, `erase` void push(Value value) bool erase(std::string_view key) function [include/rmp/save.h:279](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/save.h#L279) Value's `push()` and `erase()` on the Value this names. `push()` creates the path first, like a write; `erase()` creates nothing and is false when the path leads nowhere. ============================================================================== # rmp::ui::Button > A button: text, an icon, or both. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Button.html struct `#include ` [include/rmp/ui.h:1737](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1737-L1770) struct Button A button: text, an icon, or both. ### `text` rmp::Text text field [include/rmp/ui.h:1738](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1738) The label; empty for an icon-only button ### `icon` Picture icon{} field [include/rmp/ui.h:1739](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1739) Shown before the label, or alone ### `icon_size`, `icon_above`, `variant`, `size`, `width`, `height`, `enabled`, `id`, `style`, `on_click`, `on_hover`, `on_unhover`, `on_press`, `on_release`, `on_focus`, `on_blur` float icon_size = 0 bool icon_above = false Variant variant = Variant::NORMAL detail::Sizing size{} float width = 0 float height = 0 bool enabled = true std::string id{} Style style{} rmp::Callback<> on_click rmp::Callback<> on_hover rmp::Callback<> on_unhover rmp::Callback<> on_press rmp::Callback<> on_release rmp::Callback<> on_focus rmp::Callback<> on_blur field [include/rmp/ui.h:1742](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1742) The icon's height in design units; 0 = the label's type size (or the picture's own height when there is no label). `icon_above`: True: the icon over the label, as a toolbar tile `variant`: As `ButtonOptions::style` `size`: A step or design units, as `ButtonOptions::size` `width`: > 0 = a fixed width; 0 = as the immediate one `height`: > 0 = a fixed height `enabled`: False = drawn disabled; no press, no change, no focus `id`: As `ButtonOptions::id:` only for two with one label `style`: Its own look; see Style `on_click`: Clicked: released on it, or Enter or A with the focus `on_hover`: The pointer arrived on it `on_unhover`: ...and left `on_press`: The pointer went down on it `on_release`: ...and came up `on_focus`: The keyboard or gamepad focus arrived `on_blur`: ...and left ### `show` bool show() function [include/rmp/ui.h:1761](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1761) Lays it out here, runs the callbacks of what happened, and says whether it was clicked — `if (play.show())` works as well as on_click. Lays it out here ### `shake`, `hovered`, `pressed`, `focused` void shake() bool hovered() const bool pressed() const bool focused() const function [include/rmp/ui.h:1764](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1764) Shakes it side to side (its style's Motion), plays its `shake` sound and sends `EventKind::SHAKE:` "that did not work". Starts at the next `show()`. `shake`: Shakes it, as `Button::shake()` does `hovered`: The pointer is on it `pressed`: Held down on it `focused`: It has the focus ### `ours` KeptState ours field [include/rmp/ui.h:1769](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1769) What it remembers; read it with the methods above ============================================================================== # rmp::ui::Checkbox > A checkbox that holds its own value. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Checkbox.html struct `#include ` [include/rmp/ui.h:1851](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1851-L1869) struct Checkbox A checkbox that holds its own value. ### `text` rmp::Text text field [include/rmp/ui.h:1852](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1852) The label beside it ### `checked` bool checked = false field [include/rmp/ui.h:1853](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1853) Its value: ticked or not ### `enabled` bool enabled = true field [include/rmp/ui.h:1854](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1854) False = drawn disabled; no press, no change, no focus ### `id` std::string id{} field [include/rmp/ui.h:1855](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1855) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1856](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1856) Its own look; see Style ### `on_change` rmp::Callback on_change field [include/rmp/ui.h:1857](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1857) The new value ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1858](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1858) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1859](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1859) ...and left ### `on_focus` rmp::Callback<> on_focus field [include/rmp/ui.h:1860](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1860) The keyboard or gamepad focus arrived ### `on_blur` rmp::Callback<> on_blur field [include/rmp/ui.h:1861](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1861) ...and left ### `show` bool show() function [include/rmp/ui.h:1863](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1863) True on the frame it changed ### `shake` void shake() function [include/rmp/ui.h:1864](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1864) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1865](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1865) The pointer is on it ### `focused` bool focused() const function [include/rmp/ui.h:1866](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1866) It has the focus ### `ours` KeptState ours field [include/rmp/ui.h:1868](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1868) What it remembers; read it with the methods above ============================================================================== # rmp::ui::DialogueBox > The classic box: along the bottom of the screen, the speaker's portrait and name beside the line, the choices as buttons under it. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueBox.html struct `#include ` [include/rmp/ui.h:1416](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1416-L1438) struct DialogueBox The classic box: along the bottom of the screen, the speaker's portrait and name beside the line, the choices as buttons under it. ### `portraits` std::vector portraits{} field [include/rmp/ui.h:1417](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1417) By speaker, and by mood ### `speakers` std::vector speakers{} field [include/rmp/ui.h:1418](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1418) A box, a name plate and a voice each ### `flow` DialogueFlow flow{} field [include/rmp/ui.h:1419](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1419) The typewriter, the blips, auto-advance, timed choices ### `height` float height = 0 field [include/rmp/ui.h:1420](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1420) Design units; 0 = as the line needs ### `width` float width = 0 field [include/rmp/ui.h:1421](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1421) Design units; 0 = as wide as it is given ### `portrait_size` float portrait_size = 96 field [include/rmp/ui.h:1422](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1422) Design units, square ### `portrait_side` DialogueSide portrait_side = DialogueSide::LEFT field [include/rmp/ui.h:1423](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1423) Which side of the line ### `name_offset`, `choices`, `pauses_world`, `style`, `name_style`, `choice_style`, `ours` Vector2 name_offset{ 0, 0 } DialogueChoices choices = DialogueChoices::IN_BOX bool pauses_world = true Style style{} Style name_style{} Style choice_style{} DialogueMemory ours field [include/rmp/ui.h:1426](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1426) The name plate over the box's top edge, moved this far from its top-left corner ({ 16, -18 }: a tab on the frame); { 0, 0 } = above the line. `choices`: Where the choices go `pauses_world`: For `rmp::behavior::Talker:` the scene below waits `style`: The box `name_style`: The name plate `choice_style`: Each choice `ours`: Its state between frames; yours to read ### `show`, `toggle_history` bool show(rmp::Dialogue &dialogue) void toggle_history() function [include/rmp/ui.h:1436](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1436) Draws the line or the choices, and takes the player's answer. True while the dialogue has something to show. `toggle_history`: The lines read so far, in place of the box ============================================================================== # rmp::ui::DialogueStage > A visual novel's stage: big portraits of who is on it, the speaker in front and the rest dimmed, and the line in a box under them. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-DialogueStage.html struct `#include ` [include/rmp/ui.h:1474](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1474-L1503) struct DialogueStage A visual novel's stage: big portraits of who is on it, the speaker in front and the rest dimmed, and the line in a box under them. ### `portraits` std::vector portraits{} field [include/rmp/ui.h:1475](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1475) By speaker, and by mood ### `speakers` std::vector speakers{} field [include/rmp/ui.h:1476](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1476) A box, a name plate and a voice each ### `flow` DialogueFlow flow{} field [include/rmp/ui.h:1477](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1477) The typewriter, the blips, auto-advance, timed choices ### `portrait_height` float portrait_height = 300 field [include/rmp/ui.h:1478](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1478) Design units ### `enter_seconds`, `enter_offset` float enter_seconds = 0.3f float enter_offset = 80 field [include/rmp/ui.h:1480](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1480) Who comes on stage slides in from their side and fades in, in this long. `enter_offset`: ...from this far, in design units ### `focus_seconds`, `focus_lift`, `focus_scale`, `pauses_world`, `style`, `name_style`, `choice_style`, `dimmed`, `ours` float focus_seconds = 0.15f float focus_lift = 10 float focus_scale = 1.04f bool pauses_world = true Style style{} Style name_style{} Style choice_style{} Color dimmed = CLITERAL(Color){ 120, 120, 130, 255 } DialogueMemory ours field [include/rmp/ui.h:1484](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1484) The speaker comes forward — full colour, a little higher and bigger — in this long, and whoever stops speaking goes back as long. `focus_lift`: Design units the speaker rises `focus_scale`: The speaker's size against the rest `pauses_world`: For `rmp::behavior::Talker:` the scene below waits `style`: The box under the portraits `name_style`: The name plate `choice_style`: Each choice `dimmed`: The tint of who is not speaking `ours`: Its state between frames; yours to read ### `show` bool show(rmp::Dialogue &dialogue) function [include/rmp/ui.h:1497](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1497) Draws the stage, the line or the choices, and takes the player's answer. True while the dialogue has something to show. ### `shake` void shake(float strength = 12, float seconds = 0.4f) function [include/rmp/ui.h:1500](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1500) The whole stage shakes, from `strength` design units down to none: a command's, <> -> `stage.shake()`. ### `flash` void flash(Color color = WHITE, float seconds = 0.3f) function [include/rmp/ui.h:1502](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1502) The screen goes `color` and back, over `seconds`: a flash, a cut. ============================================================================== # rmp::ui::Dropdown > A dropdown that holds its items and its choice. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Dropdown.html struct `#include ` [include/rmp/ui.h:1898](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1898-L1918) struct Dropdown A dropdown that holds its items and its choice. ### `text` rmp::Text text field [include/rmp/ui.h:1899](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1899) The label beside it ### `items` std::vector items field [include/rmp/ui.h:1900](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1900) The choices, in order ### `selected` int selected = 0 field [include/rmp/ui.h:1901](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1901) The index of the one chosen ### `width` float width = 0 field [include/rmp/ui.h:1902](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1902) Of the field, in design units; 0 = fill the space available ### `enabled` bool enabled = true field [include/rmp/ui.h:1903](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1903) False = drawn disabled; no press, no change, no focus ### `id` std::string id{} field [include/rmp/ui.h:1904](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1904) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1905](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1905) Its own look; see Style ### `on_change` rmp::Callback on_change field [include/rmp/ui.h:1906](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1906) The new index ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1907](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1907) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1908](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1908) ...and left ### `on_focus` rmp::Callback<> on_focus field [include/rmp/ui.h:1909](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1909) The keyboard or gamepad focus arrived ### `on_blur` rmp::Callback<> on_blur field [include/rmp/ui.h:1910](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1910) ...and left ### `show` bool show() function [include/rmp/ui.h:1912](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1912) True on the frame `selected` changed ### `shake` void shake() function [include/rmp/ui.h:1913](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1913) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1914](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1914) The pointer is on it ### `focused` bool focused() const function [include/rmp/ui.h:1915](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1915) It has the focus ### `ours` KeptState ours field [include/rmp/ui.h:1917](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1917) What it remembers; read it with the methods above ============================================================================== # rmp::ui::Image > A picture with a style -- a frame, a shadow -- that can be clicked. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Image.html struct `#include ` [include/rmp/ui.h:1794](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1794-L1815) struct Image A picture with a style — a frame, a shadow — that can be clicked. With a sprite that has a sheet, it plays the sprite's animation: `sprite.play("idle")`. ### `picture` Picture picture{} field [include/rmp/ui.h:1795](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1795) What it shows, unless `sprite` has something ### `sprite` rmp::Sprite sprite{} field [include/rmp/ui.h:1796](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1796) An animated picture, advanced every `show()` ### `grow` bool grow = false field [include/rmp/ui.h:1797](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1797) As ImageOptions ### `width` float width = 0 field [include/rmp/ui.h:1798](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1798) > 0 = fixed, in design units ### `height` float height = 0 field [include/rmp/ui.h:1799](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1799) > 0 = fixed, in design units ### `enabled` bool enabled = true field [include/rmp/ui.h:1800](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1800) False = drawn disabled; no press, no change, no focus ### `id` std::string id{} field [include/rmp/ui.h:1801](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1801) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1802](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1802) Tint, skin behind it, shadow, border ### `on_click` rmp::Callback<> on_click field [include/rmp/ui.h:1803](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1803) Clicked: released on it, or Enter or A with the focus ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1804](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1804) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1805](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1805) ...and left ### `on_press` rmp::Callback<> on_press field [include/rmp/ui.h:1806](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1806) The pointer went down on it ### `on_release` rmp::Callback<> on_release field [include/rmp/ui.h:1807](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1807) ...and came up ### `show` bool show() function [include/rmp/ui.h:1809](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1809) Lays it out here; true on the frame it was clicked ### `shake` void shake() function [include/rmp/ui.h:1810](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1810) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1811](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1811) The pointer is on it ### `pressed` bool pressed() const function [include/rmp/ui.h:1812](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1812) Held down on it ### `ours` KeptState ours field [include/rmp/ui.h:1814](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1814) What it remembers; read it with the methods above ============================================================================== # rmp::ui::Label > Text, as text() draws it, with a style of its own: a title in another font, with an outline. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Label.html struct `#include ` [include/rmp/ui.h:1774](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1774-L1790) struct Label Text, as `text()` draws it, with a style of its own: a title in another font, with an outline. Clickable when it has an on_click. ### `text` rmp::Text text field [include/rmp/ui.h:1775](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1775) What it says ### `color` ColorRole color = ColorRole::TEXT field [include/rmp/ui.h:1776](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1776) Used when the style sets no text colour ### `size` detail::Sizing size{} field [include/rmp/ui.h:1777](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1777) A step or design units, as `TextOptions::size` ### `wrap` bool wrap = true field [include/rmp/ui.h:1778](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1778) Break between words to fit; false = never broken ### `id` std::string id{} field [include/rmp/ui.h:1779](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1779) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1780](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1780) Its own look; see Style ### `on_click` rmp::Callback<> on_click field [include/rmp/ui.h:1781](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1781) Clicked: released on it, or Enter or A with the focus ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1782](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1782) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1783](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1783) ...and left ### `show` bool show() function [include/rmp/ui.h:1785](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1785) True on the frame it was clicked ### `shake` void shake() function [include/rmp/ui.h:1786](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1786) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1787](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1787) The pointer is on it ### `ours` KeptState ours field [include/rmp/ui.h:1789](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1789) What it remembers; read it with the methods above ============================================================================== # rmp::ui::Panel > A container: a panel with a look of its own (`style`), and a look for everything inside it (`children`), which every descendant inherits -- the nearest container's wins. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Panel.html struct `#include ` [include/rmp/ui.h:1827](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1827-L1848) struct Panel A container: a panel with a look of its own (`style`), and a look for everything inside it (`children`), which every descendant inherits — the nearest container's wins. Clickable as a whole when it has an on_click: an inventory slot, a card. ```cpp rmp::ui::Panel shop{ .style = { .background = DARKBROWN, .shadow = rmp::ui::Shadow{} }, .children = { .text = GOLD, .font = title_font }, }; shop.show([&] { buy.show(); sell.show(); }); ``` ### `row` bool row = false field [include/rmp/ui.h:1828](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1828) Children left to right; false = top to bottom ### `box` BoxOptions box{} field [include/rmp/ui.h:1829](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1829) Its layout, as `panel()` takes it ### `background` bool background = true field [include/rmp/ui.h:1830](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1830-L1831) False: a bare row or column, which still styles its children ### `id` std::string id{} field [include/rmp/ui.h:1832](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1832) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1833](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1833) Its own look; see Style ### `children` Style children{} field [include/rmp/ui.h:1834](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1834) The look of everything inside it ### `on_click` rmp::Callback<> on_click field [include/rmp/ui.h:1835](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1835) Clicked: released on it, or Enter or A with the focus ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1836](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1836) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1837](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1837) ...and left ### `on_press` rmp::Callback<> on_press field [include/rmp/ui.h:1838](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1838) The pointer went down on it ### `on_release` rmp::Callback<> on_release field [include/rmp/ui.h:1839](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1839) ...and came up ### `show`, `shake`, `hovered`, `pressed` template bool show(Body &&body) void shake() bool hovered() const bool pressed() const function [include/rmp/ui.h:1842](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1842) Lays it out with `body` inside it; true on the frame it was clicked. `show`: Lays it out here `shake`: Shakes it, as `Button::shake()` does `hovered`: The pointer is on it `pressed`: Held down on it ### `ours` KeptState ours field [include/rmp/ui.h:1847](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1847) What it remembers; read it with the methods above ============================================================================== # rmp::ui::Picture > Anything rmp::ui can show. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Picture.html struct `#include ` [include/rmp/ui.h:181](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L181-L217) struct Picture Anything [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) can show. See above. ### `texture`, `sheet`, `source` rmp::Texture texture rmp::SpriteSheet sheet Rectangle source{} field [include/rmp/ui.h:184](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L184) The pixels, and the part of them that is this picture. Normally you do not set these yourself: one of the constructors below does. `texture`: A loose texture `sheet`: Or an Aseprite sheet, which owns its texture `source`: {0,0,0,0} = the whole texture ### `left`, `top`, `right`, `bottom`, `slice_scale` float left = 0 float top = 0 float right = 0 float bottom = 0 float slice_scale = 0 field [include/rmp/ui.h:189](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L189) Nine-slice margins, in source pixels, and the size of one source pixel in design units (0 = 1). All four 0: the picture simply stretches. ### `Picture` Picture(rmp::Texture whole) Picture(rmp::Texture atlas, Rectangle part) Picture(const rmp::Sprite &sprite) Picture(const NineSlice &nine) function [include/rmp/ui.h:199](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L199) The whole texture. ### `empty` bool empty() const function [include/rmp/ui.h:212](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L212) True when there is nothing to draw: no texture, or one that did not load. ### `size` Vector2 size() const function [include/rmp/ui.h:214](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L214) The size of the picture in source pixels: its part, or the whole texture. ### `sliced` bool sliced() const function [include/rmp/ui.h:216](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L216) True when it has nine-slice margins. ============================================================================== # rmp::ui::ProgressBar > A progress bar with a look of its own: the style is the track's (its background, its skin), `fill` and `fill_picture` the bar's. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-ProgressBar.html struct `#include ` [include/rmp/ui.h:1946](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1946-L1964) struct ProgressBar A progress bar with a look of its own: the style is the track's (its background, its skin), `fill` and `fill_picture` the bar's. ### `value` float value = 0 field [include/rmp/ui.h:1947](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1947) 0..1, clamped ### `width` float width = 0 field [include/rmp/ui.h:1948](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1948) 0 = the space available ### `height` float height = -1 field [include/rmp/ui.h:1949](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1949) -1 = from the type size ### `radius` float radius = -1 field [include/rmp/ui.h:1950](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1950) -1 = round ends ### `fill` Color fill = CLITERAL(Color){ 0, 0, 0, 0 } field [include/rmp/ui.h:1951](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1951) {0,0,0,0} = the theme's primary ### `fill_picture` Picture fill_picture{} field [include/rmp/ui.h:1952](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1952-L1953) The filled part as a picture: a nine-slice stretches with it ### `id` std::string id{} field [include/rmp/ui.h:1954](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1954) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1955](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1955) Its own look; see Style ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1956](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1956) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1957](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1957) ...and left ### `show` void show() function [include/rmp/ui.h:1959](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1959) Lays it out here ### `shake` void shake() function [include/rmp/ui.h:1960](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1960) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1961](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1961) The pointer is on it ### `ours` KeptState ours field [include/rmp/ui.h:1963](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1963) What it remembers; read it with the methods above ============================================================================== # rmp::ui::Slider > A slider that holds its own value. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-Slider.html struct `#include ` [include/rmp/ui.h:1872](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1872-L1895) struct Slider A slider that holds its own value. ### `text` rmp::Text text field [include/rmp/ui.h:1873](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1873) The label beside it ### `value` float value = 0 field [include/rmp/ui.h:1874](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1874) Its value, kept from min to max ### `min` float min = 0 field [include/rmp/ui.h:1875](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1875) The value at the left end ### `max` float max = 1 field [include/rmp/ui.h:1876](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1876) The value at the right end ### `step` float step = 0 field [include/rmp/ui.h:1877](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1877) As SliderOptions ### `width` float width = 0 field [include/rmp/ui.h:1878](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1878) 0 = fill the space available ### `show_value` bool show_value = true field [include/rmp/ui.h:1879](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1879) Draw the position, as a percentage, after the bar ### `enabled` bool enabled = true field [include/rmp/ui.h:1880](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1880) False = drawn disabled; no press, no change, no focus ### `id` std::string id{} field [include/rmp/ui.h:1881](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1881) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1882](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1882) Its own look; see Style ### `on_change` rmp::Callback on_change field [include/rmp/ui.h:1883](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1883) The new value ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1884](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1884) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1885](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1885) ...and left ### `on_focus` rmp::Callback<> on_focus field [include/rmp/ui.h:1886](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1886) The keyboard or gamepad focus arrived ### `on_blur` rmp::Callback<> on_blur field [include/rmp/ui.h:1887](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1887) ...and left ### `show` bool show() function [include/rmp/ui.h:1889](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1889) True on any frame that changed it ### `shake` void shake() function [include/rmp/ui.h:1890](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1890) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1891](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1891) The pointer is on it ### `focused` bool focused() const function [include/rmp/ui.h:1892](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1892) It has the focus ### `ours` KeptState ours field [include/rmp/ui.h:1894](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1894) What it remembers; read it with the methods above ============================================================================== # rmp::ui::SoundName > The name of a sound, as rmp::audio::play() takes it ("click" is click.wav, click.ogg...): written as a string, `.click = "click"`. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-SoundName.html class `#include ` [include/rmp/ui.h:279](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L279-L308) class SoundName The name of a sound, as [`rmp::audio::play()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#play) takes it ("click" is click.wav, click.ogg...): written as a string, `.click = "click"`. Giving one is what brings the sound player into the game, so a UI that never names a sound carries none of [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html)'s decoders. ### `SoundName` template // NOLINTNEXTLINE(google-explicit SoundName(std::string_view name) SoundName(const std::string &name) function [include/rmp/ui.h:284](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L284-L288) An array, not a pointer: what a string literal is. Implicit, and C, for `.click = "click"`. ### `view` std::string_view view() const function [include/rmp/ui.h:297](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L297) The name, as [`rmp::audio::play()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html#play) takes it; valid while this SoundName is. ### `empty` bool empty() const function [include/rmp/ui.h:299](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L299) True for "": silence, which turns off a sound set further out. ### `operator==` bool operator==(const SoundName &a, std::string_view b) function [include/rmp/ui.h:301](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L301-L303) True when it is that name: `sounds.click == "click"`. ============================================================================== # rmp::ui::TextInput > A text field that holds its own text. Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-ui-TextInput.html struct `#include ` [include/rmp/ui.h:1921](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1921-L1942) struct TextInput A text field that holds its own text. ### `text` rmp::Text text field [include/rmp/ui.h:1922](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1922) The label ### `value` std::string value field [include/rmp/ui.h:1923](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1923) What is typed ### `placeholder` rmp::Text placeholder{} field [include/rmp/ui.h:1924](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1924) Shown, muted, while it is empty ### `max_length` int max_length = 0 field [include/rmp/ui.h:1925](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1925) In characters; 0 = no limit ### `width` float width = 0 field [include/rmp/ui.h:1926](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1926) Of the field, in design units; 0 = fill the space available ### `enabled` bool enabled = true field [include/rmp/ui.h:1927](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1927) False = drawn disabled; no press, no change, no focus ### `id` std::string id{} field [include/rmp/ui.h:1928](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1928) As `ButtonOptions::id:` for a shared label ### `style` Style style{} field [include/rmp/ui.h:1929](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1929) Its own look; see Style ### `on_change` rmp::Callback on_change field [include/rmp/ui.h:1930](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1930) The text, after the change ### `on_hover` rmp::Callback<> on_hover field [include/rmp/ui.h:1931](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1931) The pointer arrived on it ### `on_unhover` rmp::Callback<> on_unhover field [include/rmp/ui.h:1932](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1932) ...and left ### `on_focus` rmp::Callback<> on_focus field [include/rmp/ui.h:1933](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1933) The keyboard or gamepad focus arrived ### `on_blur` rmp::Callback<> on_blur field [include/rmp/ui.h:1934](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1934) ...and left ### `show` bool show() function [include/rmp/ui.h:1936](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1936) True on any frame the text changed ### `shake` void shake() function [include/rmp/ui.h:1937](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1937) Shakes it, as `Button::shake()` does ### `hovered` bool hovered() const function [include/rmp/ui.h:1938](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1938) The pointer is on it ### `focused` bool focused() const function [include/rmp/ui.h:1939](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1939) It has the focus ### `ours` KeptState ours field [include/rmp/ui.h:1941](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/ui.h#L1941) What it remembers; read it with the methods above ============================================================================== # Behaviors > The catalogue of behaviors in rmp::behavior: what each one does to the object that has it. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/index.html The catalogue of behaviors in rmp::behavior: what each one does to the object that has it. | Name | What it is | |---|---| | [`rmp::behavior::Animator`](https://omardev29.github.io/rmp-docs/reference/behaviors/Animator.html) | Plays the tag that fits what the object is doing: `die` once its Health is dead, `hurt` while it is invulnerable after a hit, `jump` and `fall` in the air (with gravity), `run` while it moves and `idle` while it does not — and mirrors it with flip_x by the way it moves. | | [`rmp::behavior::Area`](https://omardev29.github.io/rmp-docs/reference/behaviors/Area.html) | A region that says who comes and goes: a trigger, a door's sensor, a pit, a shop's counter. | | [`rmp::behavior::Ball`](https://omardev29.github.io/rmp-docs/reference/behaviors/Ball.html) | Bounces, keeps its pace, and leaves a paddle at an angle that depends on where it hit. | | [`rmp::behavior::Chase`](https://omardev29.github.io/rmp-docs/reference/behaviors/Chase.html) | Sees a target and goes after it. | | [`rmp::behavior::Collectible`](https://omardev29.github.io/rmp-docs/reference/behaviors/Collectible.html) | A coin, a key, a heart. | | [`rmp::behavior::Draggable`](https://omardev29.github.io/rmp-docs/reference/behaviors/Draggable.html) | Picked up with the pointer and put down somewhere. | | [`rmp::behavior::Follow`](https://omardev29.github.io/rmp-docs/reference/behaviors/Follow.html) | Chases a handle, with a speed and a distance it stops at. | | [`rmp::behavior::GridSnap`](https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html) | Squares the position with a grid, AFTER everything that moves it. | | [`rmp::behavior::Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) | Hit points, a window of invulnerability with a blink, and death. | | [`rmp::behavior::Hitbox`](https://omardev29.github.io/rmp-docs/reference/behaviors/Hitbox.html) | What hurts: a sword's swing, a spike, a bullet, an explosion. | | [`rmp::behavior::Lifespan`](https://omardev29.github.io/rmp-docs/reference/behaviors/Lifespan.html) | Discarded after N seconds. | | [`rmp::behavior::Orbit`](https://omardev29.github.io/rmp-docs/reference/behaviors/Orbit.html) | Circles a handle or a point: a shield of blades, a moon, a fairy. | | [`rmp::behavior::Parallax`](https://omardev29.github.io/rmp-docs/reference/behaviors/Parallax.html) | A background layer that scrolls at its own factor and repeats itself with no seam. | | [`rmp::behavior::Pathfind`](https://omardev29.github.io/rmp-docs/reference/behaviors/Pathfind.html) | Walks to a target, or to a point, around the map's walls: `rmp::find_path()`, asked again every `repath_every` seconds, and followed at `speed`. | | [`rmp::behavior::Patrol`](https://omardev29.github.io/rmp-docs/reference/behaviors/Patrol.html) | Goes from waypoint to waypoint — round in a loop, or back and forth with `ping_pong` — waiting `wait` seconds at each. | | [`rmp::behavior::Platformer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Platformer.html) | Gravity, jumping, ground, coyote time and a buffered jump. | | [`rmp::behavior::Projectile`](https://omardev29.github.io/rmp-docs/reference/behaviors/Projectile.html) | Travels the way you pushed it and is discarded when it leaves or hits. | | [`rmp::behavior::Runner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Runner.html) | Constant forward motion that SPEEDS UP over time, with a jump and a duck. | | [`rmp::behavior::Shooter`](https://omardev29.github.io/rmp-docs/reference/behaviors/Shooter.html) | Fires. | | [`rmp::behavior::Spawner`](https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html) | Produces objects every N seconds, or every N units TRAVELLED. | | [`rmp::behavior::StateMachine`](https://omardev29.github.io/rmp-docs/reference/behaviors/StateMachine.html) | Named states and the moves between them: an enemy that idles, patrols, chases and flees; a boss's phases. | | [`rmp::behavior::Talker`](https://omardev29.github.io/rmp-docs/reference/behaviors/Talker.html) | Someone to talk to. | | [`rmp::behavior::Timer`](https://omardev29.github.io/rmp-docs/reference/behaviors/Timer.html) | Calls you every N seconds. | | [`rmp::behavior::TopDown`](https://omardev29.github.io/rmp-docs/reference/behaviors/TopDown.html) | Eight directions, and the sprite chosen from the one you are facing. | | [`rmp::behavior::Tween`](https://omardev29.github.io/rmp-docs/reference/behaviors/Tween.html) | Moves one property of its object from `from` to `to` over `seconds`, along an Ease. | ============================================================================== # rmp::behavior::Animator > Plays the tag that fits what the object is doing: `die` once its Health is dead, `hurt` while it is invulnerable after a hit, `jump` and `fall` in the air (with gravity), `run` while it moves and `idle` while it does not -- and mirrors it with flip_x by the way it moves. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Animator.html behavior `#include ` [include/rmp/behavior.h:951](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L951-L975) struct Animator Plays the tag that fits what the object is doing: `die` once its Health is dead, `hurt` while it is invulnerable after a hit, `jump` and `fall` in the air (with gravity), `run` while it moves and `idle` while it does not — and mirrors it with flip_x by the way it moves. 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. Runs after everything has moved. Added to an object with `add()`; the framework calls its `_late_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `idle` | `std::string` | `"idle"` | Standing still, on the ground | | `run` | `std::string` | `"run"` | Moving faster than `moving_at` | | `jump` | `std::string` | `"jump"` | In the air, going up (with gravity) | | `fall` | `std::string` | `"fall"` | In the air, coming down (with gravity) | | `hurt` | `std::string` | `"hurt"` | While its Health is invulnerable after a hit | | `die` | `std::string` | `"die"` | Played once, not looped | | `moving_at` | `float` | `10` | Units per second under which it stands still | | `flip` | `bool` | `true` | Sets flip_x while it moves left; the art faces right | | `rules` | `std::vector` | | Asked first, in order | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `playing` std::string_view playing() const function [include/rmp/behavior.h:963](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L963) The tag it chose at its last update; "" when it chose none. ============================================================================== # rmp::behavior::Area > A region that says who comes and goes: a trigger, a door's sensor, a pit, a shop's counter. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Area.html behavior `#include ` [include/rmp/behavior.h:554](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L554-L583) struct Area A region that says who comes and goes: a trigger, a door's sensor, a pit, a shop's counter. It is the object it is on — its collider, its layers — so it sees what that object collides with, and solid or not is the object's business (a trigger is not solid, which is the default). ```cpp door.collision_mask = layer::PLAYER; door.add({ .on_enter = [](rmp::Object &, rmp::Object &who) { open_the_door(who); } }); ``` Five moments, each told with the area and the other object: ```text 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 ``` 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. Added to an object with `add()`; the framework calls its `_update`, `_collision` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `on_enter` | `Callback` | | (the area, who came in) | | `on_stay` | `Callback` | | (the area, who is still touching) | | `on_exit` | `Callback` | | (the area, who left) | | `on_inside` | `Callback` | | (the area, who is wholly inside now) | | `on_outside` | `Callback` | | (the area, who is no longer wholly inside) | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `overlapping` std::span> overlapping() const function [include/rmp/behavior.h:563](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L563-L565) Who touched it in the last collision pass, as handles: one destroyed since then reads empty. ### `contains` bool contains(const Object &other) const function [include/rmp/behavior.h:567](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L567) Whether `other` touched it in the last collision pass. ============================================================================== # rmp::behavior::Ball > Bounces, keeps its pace, and leaves a paddle at an angle that depends on where it hit. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Ball.html behavior `#include ` [include/rmp/behavior.h:242](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L242-L250) struct Ball Bounces, keeps its pace, and leaves a paddle at an angle that depends on where it hit. STARTS STILL — see the note at the top of this file. ```cpp ball.add({ .speed = 320 }); ball.apply_force({ 1, 0.35f }); // the serve, and it is the game's ``` _update normalises the velocity to `speed` ONLY when it is not zero, and the two properties that fall out of that are what make the serve one line: only the DIRECTION of the push counts, so nobody has to think about magnitudes, and `velocity = {}` is a stable state, so stopping the ball between points is one assignment rather than removing the behavior. Added to an object with `add()`; the framework calls its `_ready`, `_collision`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `speed` | `float` | `300` | The pace it KEEPS, not the one it leaves at | | `max_bounce_deg` | `float` | `60` | How far a hit near the end of a paddle tilts it | | `speed_up` | `float` | `1.02f` | Per bounce off a solid. 1 = constant | ============================================================================== # rmp::behavior::Chase > Sees a target and goes after it. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Chase.html behavior `#include ` [include/rmp/behavior.h:865](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L865-L903) struct Chase Sees a target and goes after it. It sees it within `sight` units, 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, and a Pathfind, when there is one, finds the way; without one it runs straight at the target. After `lose_after` seconds without seeing it, it gives up: on_lose, back home with `return_home`, and the Patrol resumes. From the editor: "speed" (Float), "sight" (Float), "fov" (Float). Added to an object with `add()`; the framework calls its `_ready`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `target` | `Handle` | | Whom it looks for; the game sets it, usually the player | | `speed` | `float` | `120` | Units per second while it chases | | `sight` | `float` | `160` | How far it sees; 0 = any distance | | `fov` | `float` | `360` | Degrees of its view, centred on the way it faces | | `line_of_sight` | `bool` | `true` | Solid map cells hide the target | | `lose_after` | `float` | `2` | Seconds without seeing it before it gives up | | `return_home` | `bool` | `true` | Goes back where it started after giving up | | `stop_distance` | `float` | `0` | Stops this close to the target | | `on_spot` | `Callback` | | (the chaser, the target), when a chase starts | | `on_lose` | `Callback` | | When it gives up | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `chasing` bool chasing() const function [include/rmp/behavior.h:878](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L878) Whether it is chasing now. ### `sees` bool sees() const function [include/rmp/behavior.h:880](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L880) Whether it saw the target at its last update. ### `from` static Chase from(const MapObject &object) static function [include/rmp/behavior.h:884](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L884) A Chase with the fields the map's entity has by these names — speed, sight, fov — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file. ============================================================================== # rmp::behavior::Collectible > A coin, a key, a heart. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Collectible.html behavior `#include ` [include/rmp/behavior.h:674](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L674-L704) struct Collectible A coin, a key, a heart. Touched by an object on a layer of `collected_by`, it calls on_collect, plays its sound, stops colliding and vanishes — it rises, grows and fades for `vanish_seconds` — and is destroyed. Within `magnet` of a collector it flies to it first. What a coin is worth is the game's: on_collect is where it counts. From the editor: "magnet" (Float). Added to an object with `add()`; the framework calls its `_update`, `_collision` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `collected_by` | `unsigned` | `0xFFFFFFFFu` | The layers that pick it up | | `sound` | `std::string` | | Played by [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) when it is picked up; "" = silent | | `magnet` | `float` | `0` | Within this many units of a collector it flies to it; 0 = never | | `magnet_speed` | `float` | `360` | How fast, in units per second | | `vanish_seconds` | `float` | `0.25f` | How long it takes to go; 0 = at once | | `on_collect` | `Callback` | | (the pickup, who picked it up), once | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `collected` bool collected() const function [include/rmp/behavior.h:683](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L683) Whether it has been picked up: from then on it only vanishes. ### `from` static Collectible from(const MapObject &object) static function [include/rmp/behavior.h:687](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L687) A Collectible with the fields the map's entity has by these names — magnet — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file. ============================================================================== # rmp::behavior::Draggable > Picked up with the pointer and put down somewhere. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Draggable.html behavior `#include ` [include/rmp/behavior.h:983](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L983-L1018) struct Draggable Picked up with the pointer and put down somewhere. 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 centred on it with `centre_on_drop`. Let go anywhere else it goes back where it was picked up, with `return_if_rejected`, or stays, snapped to `snap`, and with `throwable` keeps the pointer's speed and slides to a stop. Added to an object with `add()`; the framework calls its `_ready`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `snap` | `Vector2` | `{}` | The grid it lands on; {0,0} = none | | `throwable` | `bool` | `false` | Keeps the pointer's speed when let go | | `friction` | `float` | `6` | How fast a throw slows: the share of its speed lost per second | | `bounds` | `Rectangle` | `{}` | Where it can be dragged; {0,0,0,0} = anywhere | | `drop_on` | `unsigned` | `0xFFFFFFFFu` | The layers of the Areas it can be dropped on | | `return_if_rejected` | `bool` | `true` | No Area took it: back where it was picked up | | `centre_on_drop` | `bool` | `true` | Dropped on an Area: put on its centre | | `accepts` | `Condition` | | (this, the area); empty = every Area does | | `on_pick` | `Callback` | | The first time it moves under the pointer | | `on_drop` | `Callback` | | (this, the area it was dropped on) | | `on_reject` | `Callback` | | Let go where no Area took it | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `held` bool held() const function [include/rmp/behavior.h:997](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L997) Whether the pointer holds it now. ### `drop` void drop(Object &self) function [include/rmp/behavior.h:1000](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1000) Lets go of it here, as the pointer letting go would: onto the Area under it, or back, or where it is. ============================================================================== # rmp::behavior::Follow > Chases a handle, with a speed and a distance it stops at. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Follow.html behavior `#include ` [include/rmp/behavior.h:266](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L266-L273) struct Follow Chases a handle, with a speed and a distance it stops at. A handle and not a pointer, because the thing being chased is exactly the thing most likely to die while being chased. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `target` | `Handle` | | What it chases; empty or gone = it keeps its velocity | | `speed` | `float` | `150` | Units per second while chasing | | `stop_distance` | `float` | `0` | Within this many units of the target's centre it stops | | `acceleration` | `float` | `0` | 0 = instant | ============================================================================== # rmp::behavior::GridSnap > Squares the position with a grid, AFTER everything that moves it. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/GridSnap.html behavior `#include ` [include/rmp/behavior.h:337](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L337-L342) struct GridSnap Squares the position with a grid, AFTER everything that moves it. That is what keeps a puzzle piece from sitting on half a pixel when it rotates or falls, and it is why this declares _late_update and not _update. Added to an object with `add()`; the framework calls its `_late_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `cell` | `Vector2` | `{ 32, 32 }` | The grid's spacing per axis; 0 = that axis is left alone | | `offset` | `Vector2` | `{}` | Where the grid's origin is | ============================================================================== # rmp::behavior::Health > Hit points, a window of invulnerability with a blink, and death. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html behavior `#include ` [include/rmp/behavior.h:478](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L478-L530) struct Health Hit points, a window of invulnerability with a blink, and death. Added to an object with `add()`; the framework calls its `_ready`, `_update`, `_collision`, `_end` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `hp` | `int` | `3` | Hit points left, and the number it starts with | | `max_hp` | `int` | `0` | 0 = whatever hp starts at, so `{ .hp = 5 }` needs no second number | | `invulnerable_for` | `float` | `0.6f` | 0 = no window | | `blink_hz` | `float` | `12` | Blinks per second while invulnerable; 0 = no blink | | `destroy_on_death` | `bool` | `true` | Destroy the object when it dies, after on_death | | `on_death` | `Callback` | | Once, when `damage()` takes hp to 0 | | `on_damage` | `Callback` | | The amount that actually landed | | `hurt_by` | `unsigned` | `0` | WHICH LAYERS HURT. 0, the default, is "nothing does": contact costs nothing until a game says which contact costs something, and then it says it once here instead of writing the same `if` at the top of every _collision. `player.add({ .hp = 3, .hurt_by = layer::ENEMY });` It is the OTHER object's `collision_layer` that is tested, the same numbers [`rmp::Object::collision_mask`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Object.html#collision_mask) uses — so a spike, an enemy and a bullet are one layer each and a player is hurt by whichever it names. The invulnerable window applies, which is what stops standing inside a fire costing sixty hearts a second. | | `damage_on_hit` | `int` | `1` | What one touch costs | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `damage`, `heal` bool damage(Object &self, int amount = 1) void heal(int amount = 1) function [include/rmp/behavior.h:505](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L505) Returns whether it landed. Damage during the invulnerable window does not, which is what stops one spike costing three hearts in three frames. ### `invulnerable` bool invulnerable() const function [include/rmp/behavior.h:510](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L510) Whether the window after a hit is still open, during which `damage()` lands nothing. ### `dead` bool dead() const function [include/rmp/behavior.h:513](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L513) Whether hp is 0 or less. A death through `damage()` is final: `heal()` does nothing after it. ============================================================================== # rmp::behavior::Hitbox > What hurts: a sword's swing, a spike, a bullet, an explosion. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Hitbox.html behavior `#include ` [include/rmp/behavior.h:593](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L593-L618) struct Hitbox What hurts: a sword's swing, a spike, a bullet, an explosion. On touching an object with an [`rmp::behavior::Health`](https://omardev29.github.io/rmp-docs/reference/behaviors/Health.html) on one of the layers it `hits`, it calls that Health's `damage()` — the invulnerable window, on_damage and the once-only death all apply — and pushes it away. A Health's `hurt_by` does not count an object with a Hitbox: the Hitbox is what decides, so nothing is hurt twice for one touch. From the editor: "damage" (Int), "knockback" (Float). Added to an object with `add()`; the framework calls its `_update`, `_collision` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `damage` | `int` | `1` | What one hit costs | | `hits` | `unsigned` | `0xFFFFFFFFu` | The layers it hurts; the collision layers decide who it touches | | `knockback` | `float` | `0` | The impulse that pushes the one hit away from it | | `destroy_on_hit` | `bool` | `false` | Discarded after its first hit, landed or not: a bullet | | `once_per_target` | `bool` | `false` | Hits each object once at most: a sword's one swing | | `on_hit` | `Callback` | | (the hitbox, who it hurt), when the damage landed | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `from` static Hitbox from(const MapObject &object) static function [include/rmp/behavior.h:605](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L605) A Hitbox with the fields the map's entity has by these names — damage, knockback — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file. ============================================================================== # rmp::behavior::Lifespan > Discarded after N seconds. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Lifespan.html behavior `#include ` [include/rmp/behavior.h:458](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L458-L471) struct Lifespan Discarded after N seconds. Particles, bullets. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `seconds` | `float` | `1` | How long the object lasts before it is destroyed | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ============================================================================== # rmp::behavior::Orbit > Circles a handle or a point: a shield of blades, a moon, a fairy. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Orbit.html behavior `#include ` [include/rmp/behavior.h:917](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L917-L932) struct Orbit Circles a handle or a point: a shield of blades, a moon, a fairy. Several on one centre spread around it evenly with `index` and `of`. From the editor: "radius" (Float), "speed" (Float, degrees_per_second), "angle" (Float). Added to an object with `add()`; the framework calls its `_late_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `centre` | `Handle` | | What it circles, while it is there | | `point` | `Vector2` | `{}` | What it circles without a centre | | `radius` | `float` | `48` | Units from the centre | | `degrees_per_second` | `float` | `90` | Negative turns the other way | | `angle` | `float` | `0` | Degrees, where it is now; it is where it starts too | | `face` | `Face` | `Face::NONE` | Which way it turns its object as it goes round | | `index` | `int` | `0` | This one's place among `of` on the same centre | | `of` | `int` | `1` | How many share the centre, spread evenly | ### `from` static Orbit from(const MapObject &object) static function [include/rmp/behavior.h:929](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L929) A Orbit with the fields the map's entity has by these names — radius, speed, angle — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file. ============================================================================== # rmp::behavior::Parallax > A background layer that scrolls at its own factor and repeats itself with no seam. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Parallax.html behavior `#include ` [include/rmp/behavior.h:352](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L352-L372) struct Parallax A background layer that scrolls at its own factor and repeats itself with no seam. Twenty lines everybody writes wrong the first time: the texture has to be drawn TWICE with the offset taken modulo its width, and it has to be recomputed when the window changes size. Added to an object with `add()`; the framework calls its `_ready`, `_draw`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `texture` | `std::string` | | A name for [`rmp::assets::load_texture`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-assets.html#load_texture) | | `factor` | `float` | `0.5f` | 1 = scrolls with the world, 0 = pinned to the screen | | `speed` | `float` | `0` | Units per second of its own, for a sky that drifts | | `y` | `float` | `0` | Where the top of the strip sits | | `tint` | `Color` | `WHITE` | Multiplies the texture's colours; WHITE = drawn as it is | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ============================================================================== # rmp::behavior::Pathfind > Walks to a target, or to a point, around the map's walls: rmp::find_path(), asked again every `repath_every` seconds, and followed at `speed`. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Pathfind.html behavior `#include ` [include/rmp/behavior.h:822](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L822-L854) struct Pathfind Walks to a target, or to a point, around the map's walls: [`rmp::find_path()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp.html#find_path), asked again every `repath_every` seconds, and followed at `speed`. Top-down: it moves on both axes. A Chase on the same object steers it. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `target` | `Handle` | | Where it goes, while it is there | | `goal` | `std::optional` | | Where it goes without a target; empty = it stays | | `speed` | `float` | `100` | Units per second | | `diagonal` | `bool` | `true` | Eight directions; false = four | | `clearance` | `float` | `0` | Keeps this far from the walls; see PathOptions | | `repath_every` | `float` | `0.5f` | Seconds between two searches while it walks | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `path` std::span path() const function [include/rmp/behavior.h:831](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L831-L836) The cells still ahead, the last one the goal. ### `arrived` bool arrived() const function [include/rmp/behavior.h:838](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L838) Whether it is where it was going: at the goal, or with no way there. ============================================================================== # rmp::behavior::Patrol > Goes from waypoint to waypoint -- round in a loop, or back and forth with `ping_pong` -- waiting `wait` seconds at each. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Patrol.html behavior `#include ` [include/rmp/behavior.h:785](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L785-L817) struct Patrol Goes from waypoint to waypoint — round in a loop, or back and forth with `ping_pong` — waiting `wait` seconds at each. With no waypoints it walks the floor instead: left and right at `speed`, turning at a wall and, with `turn_at_ledges`, before a drop, which is a platformer's goomba. The way it goes sets flip_x, and its sprite plays `walk` and `idle` when its sheet has them — unless the object has an Animator, which then chooses. Waypoints are for what flies or walks top-down: it moves straight to each, on both axes. Floor walking moves only along x, and gravity is the object's. From the editor: "path" (Array; the entity's own position is the first waypoint), "speed" (Float), "wait" (Float), "ping_pong" (Bool). Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `waypoints` | `std::vector` | | World positions; empty = it walks the floor | | `speed` | `float` | `60` | Units per second | | `wait` | `float` | `0` | Seconds it stays at each waypoint | | `ping_pong` | `bool` | `false` | Back and forth; false = from the last straight to the first | | `turn_at_ledges` | `bool` | `true` | Walking the floor: turns before a drop | | `walk` | `std::string` | `"walk"` | The tag played while it moves; "" = none | | `idle` | `std::string` | `"idle"` | The tag played while it waits; "" = none | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `heading_for` int heading_for() const function [include/rmp/behavior.h:795](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L795) The waypoint it is heading for, an index into `waypoints`. ### `from` static Patrol from(const MapObject &object) static function [include/rmp/behavior.h:799](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L799) A Patrol with the fields the map's entity has by these names — path, speed, wait, ping_pong — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file. ============================================================================== # rmp::behavior::Platformer > Gravity, jumping, ground, coyote time and a buffered jump. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Platformer.html behavior `#include ` [include/rmp/behavior.h:147](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L147-L184) struct Platformer Gravity, jumping, ground, coyote time and a buffered jump. The last two are what separates a platformer that feels right from one that does not, and neither is something a player can name — they only notice their absence. Added to an object with `add()`; the framework calls its `_ready`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `speed` | `float` | `260` | Units per second while a direction is held | | `acceleration` | `float` | `0` | 0 = instant | | `gravity` | `float` | `2000` | Units per second squared, pulling down while off the ground | | `jump` | `float` | `700` | The upward speed a jump starts with, in units per second | | `air_jumps` | `int` | `0` | 1 = a double jump | | `coyote_time` | `float` | `0.1f` | Still jumpable for this long after walking off a ledge. Named after the coyote who keeps running for a moment past the cliff. | | `jump_buffer` | `float` | `0.12f` | A jump pressed this long before landing still fires on landing. | | `left` | `std::string` | | Which actions move and jump it. Empty = move_left, move_right and ui_accept, the actions that come as standard. | | `right` | `std::string` | | Which actions move and jump it. Empty = move_left, move_right and ui_accept, the actions that come as standard. | | `jump_action` | `std::string` | | Which actions move and jump it. Empty = move_left, move_right and ui_accept, the actions that come as standard. | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `grounded` bool grounded() const function [include/rmp/behavior.h:168](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L168) Whether it was standing on something at its last update: a solid object or a solid map cell just under its feet, while not moving up. ============================================================================== # rmp::behavior::Projectile > Travels the way you pushed it and is discarded when it leaves or hits. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Projectile.html behavior `#include ` [include/rmp/behavior.h:253](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L253-L261) struct Projectile Travels the way you pushed it and is discarded when it leaves or hits. Added to an object with `add()`; the framework calls its `_ready`, `_collision`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `speed` | `float` | `0` | 0 = keep whatever velocity it was given | | `destroy_on_hit` | `bool` | `true` | Discarded on touching any object it collides with | | `destroy_on_wall` | `bool` | `false` | Discarded when its centre is in a solid map cell | ============================================================================== # rmp::behavior::Runner > Constant forward motion that SPEEDS UP over time, with a jump and a duck. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Runner.html behavior `#include ` [include/rmp/behavior.h:193](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L193-L225) struct Runner Constant forward motion that SPEEDS UP over time, with a jump and a duck. A Platformer with the x fixed is not this, and the difference is `accelerate` and `distance()`: in an endless runner the speed climbs on its own, and the distance travelled is both the score and the clock the difficulty hangs off — and a Spawner with `every_distance` and `track` set to the runner produces by that same distance rather than by time. Added to an object with `add()`; the framework calls its `_ready`, `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `speed` | `float` | `320` | Units per second, right now | | `accelerate` | `float` | `6` | How much `speed` gains per second. 0 = constant | | `max_speed` | `float` | `900` | The most `speed` is allowed to reach, units per second | | `gravity` | `float` | `2200` | Units per second squared, pulling down while off the ground | | `jump` | `float` | `720` | The upward speed a jump starts with, in units per second | | `air_jumps` | `int` | `0` | 1 = a double jump | | `jump_action` | `std::string` | | Empty = ui_accept | | `duck_action` | `std::string` | | Held to duck; empty = it never ducks | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `distance` float distance() const function [include/rmp/behavior.h:206](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L206) How far it has run, in units: `speed` summed over every update since it was added. It counts the running, not where the object got to. ### `ducking` bool ducking() const function [include/rmp/behavior.h:209](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L209) Whether `duck_action` was held at its last update. That is all ducking does here: a smaller collider or another animation is the game's to set. ============================================================================== # rmp::behavior::Shooter > Fires. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Shooter.html behavior `#include ` [include/rmp/behavior.h:723](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L723-L767) struct Shooter Fires. On an action held down, on its own every `every` seconds, or at a target — one bullet or a pattern of them: `count` spread over `spread` degrees, the whole pattern turned by `rotate_per_shot` after each volley, which is how a spiral is made. THE BULLET is a circle of `bullet_radius` in `bullet_color`, with a Projectile (gone at a wall or a hit), a Lifespan of `bullet_life` and a Hitbox of `damage` on the layers of `hits`. Or it is whatever `on_shoot` makes, handed the scene, where it leaves from and its velocity: ```cpp .on_shoot = [](rmp::Scene &s, Vector2 at, Vector2 velocity) { auto &arrow = s.spawn({ .position = at, .velocity = velocity }); arrow.sprite.texture = rmp::assets::load_texture("arrow.png"); } ``` From the editor: "every" (Float), "speed" (Float), "count" (Int), "spread" (Float), "rotate" (Float, rotate_per_shot), "range" (Float). Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `action` | `std::string` | | Fires while it is held; "" = never on input | | `automatic` | `bool` | `false` | Fires every `every` seconds on its own | | `every` | `float` | `0.25f` | The least time between two volleys, in seconds | | `target` | `Handle` | | Aims at it; while it is set and gone, it does not fire | | `range` | `float` | `0` | With a target: fires only when it is this close; 0 = any distance | | `direction` | `Vector2` | `{}` | Where it aims without a target; {0,0} = the way it faces | | `speed` | `float` | `360` | The bullets', in units per second | | `count` | `int` | `1` | Bullets per volley | | `spread` | `float` | `0` | Degrees the volley covers; 360 = all around, evenly | | `rotate_per_shot` | `float` | `0` | Degrees the pattern turns after each volley | | `offset` | `Vector2` | `{}` | Where the bullets leave from, from its centre | | `sound` | `std::string` | | Played by [`rmp::audio`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-audio.html) on each volley; "" = silent | | `bullet_radius` | `float` | `4` | The default bullet's | | `bullet_color` | `Color` | `WHITE` | The default bullet's fill | | `bullet_life` | `float` | `2` | Seconds before it is discarded | | `damage` | `int` | `1` | What the default bullet's Hitbox costs | | `hits` | `unsigned` | `0` | The layers the bullets hit; 0 = its own mask, less its own layer | | `on_shoot` | `Callback` | | Makes the bullet instead: (the scene, where it leaves from, its velocity). | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `fire` bool fire(Object &self) function [include/rmp/behavior.h:747](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L747) Fires a volley now, if `every` has passed since the last; true if it did. ### `shots` int shots() const function [include/rmp/behavior.h:749](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L749) How many volleys it has fired. ### `from` static Shooter from(const MapObject &object) static function [include/rmp/behavior.h:753](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L753) A Shooter with the fields the map's entity has by these names — every, speed, count, spread, rotate, range — and the defaults for the rest. See "FROM THE EDITOR" at the top of this file. ============================================================================== # rmp::behavior::Spawner > Produces objects every N seconds, or every N units TRAVELLED. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Spawner.html behavior `#include ` [include/rmp/behavior.h:388](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L388-L431) struct Spawner Produces objects every N seconds, or every N units TRAVELLED. By distance is not the same as a Timer, and the difference is the whole reason this is not one: in an endless runner the speed climbs, so "every two seconds" puts the obstacles further and further apart and the game gets EASIER the faster you go, which is the opposite of the intention. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `every_seconds` | `float` | `0` | One of these two, not both | | `every_distance` | `float` | `0` | Units travelled between spawns; wins if both are set | | `jitter` | `float` | `0` | +/- this much, uniformly | | `max_alive` | `int` | `0` | 0 = no limit, and it is a cap on the LIVE ones | | `track` | `Handle` | | Where "travelled" is measured from. Empty = this object's own position. | | `on_spawn` | `Callback` | | Makes what is spawned, given the scene and where `track` (or this object) is now. Every object it adds counts towards `max_alive`. Empty = the Spawner does nothing. | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `alive` int alive() const function [include/rmp/behavior.h:404](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L404) How many of the objects it made are still alive RIGHT NOW. It goes down when they die, which is the whole difference between a cap and a quota. ### `jitter_amount` float jitter_amount() const function [include/rmp/behavior.h:430](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L430) A fresh random amount between -jitter and +jitter from [`rmp::random::range`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-random.html#range), or 0 when `jitter` is 0 or less or not a finite number: what each interval after the first is moved by. ============================================================================== # rmp::behavior::StateMachine > Named states and the moves between them: an enemy that idles, patrols, chases and flees; a boss's phases. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/StateMachine.html behavior `#include ` [include/rmp/behavior.h:1049](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1049-L1075) struct StateMachine Named states and the moves between them: an enemy that idles, patrols, chases and flees; a boss's phases. It starts in `initial` at its first update, asks the transitions in order every frame — the first whose `from` matches and whose `when` says yes is taken — and runs the state's on_update. `go()` moves by name, at its next update. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `states` | `std::vector` | | Every state it can be in, by name | | `initial` | `std::string` | | "" = the first state | | `transitions` | `std::vector` | | Asked in order; the first that says yes is taken | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `go` void go(std::string_view name) function [include/rmp/behavior.h:1057](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1057) Moves to the state called `name` at its next update; a name it does not have is said once and changes nothing. ### `state` std::string_view state() const function [include/rmp/behavior.h:1059](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1059) The state it is in; "" before its first update. ### `seconds_in_state` float seconds_in_state() const function [include/rmp/behavior.h:1061](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L1061) How long it has been in it, in seconds. ============================================================================== # rmp::behavior::Talker > Someone to talk to. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Talker.html behavior `#include ` [include/rmp/behavior.h:631](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L631-L665) struct Talker Someone to talk to. When `player` is within `range` and `action` is pressed — or as soon as it is within range, with no action — it loads `dialogue` (a .yarn of resources/, once), starts it at `node` and hands it to on_talk, where the game shows it: a presenter of [`rmp::ui`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html) in a scene pushed on top when it should pause the world (DialogueBox and DialogueStage), or a DialogueBubble drawn in this scene's `_draw()`. `in_range()` is for the prompt over its head — [`rmp::ui::at`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-ui.html#at)(self.position, ...) "Talk". `once` talks a single time; the dialogue's variables and visits stay with it. From the editor: "dialogue" (String), "node" (String), "range" (Float), "once" (Bool). Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `dialogue` | `std::string` | | The .yarn file | | `node` | `std::string` | `"Start"` | Where it starts | | `range` | `float` | `40` | World units between the two positions | | `player` | `Handle` | `{}` | Who talks to it | | `action` | `std::string` | `"interact"` | The [`rmp::input`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html) action; "" = on arriving | | `once` | `bool` | `false` | Talks the first time only | | `on_load` | `Callback` | | The conversation was loaded, before it first starts: where the game binds its variables and registers its functions and commands. | | `on_talk` | `Callback` | | The conversation started: show it | | `on_done` | `Callback<>` | | ...and finished | | `ours` | `struct { … }` | | What it is keeping track of; not yours to write. | ### `in_range` bool in_range() const function [include/rmp/behavior.h:644](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L644) Close enough to talk ### `talking` bool talking() const function [include/rmp/behavior.h:645](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L645-L647) A conversation is running ### `conversation` Dialogue &conversation() function [include/rmp/behavior.h:648](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L648) What it says ### `from` static Talker from(const MapObject &object) static function [include/rmp/behavior.h:652](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L652) A Talker with the fields the map's entity has by these names — dialogue, node, range, once — and the defaults for the rest. ============================================================================== # rmp::behavior::Timer > Calls you every N seconds. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Timer.html behavior `#include ` [include/rmp/behavior.h:434](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L434-L455) struct Timer Calls you every N seconds. Shooting, blinking, a countdown. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `seconds` | `float` | `1` | Between calls; 0 = it never fires | | `repeat` | `bool` | `true` | False = one call, and then it is spent | | `on_timeout` | `Callback` | | Called with the object the Timer is on. A frame longer than `seconds` calls it once for every interval that frame covered, so a countdown keeps time on a slow machine — up to a thousand: more than that owed in one frame is an interval far shorter than any frame, and the rest of the time is dropped and said once. | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ============================================================================== # rmp::behavior::TopDown > Eight directions, and the sprite chosen from the one you are facing. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/TopDown.html behavior `#include ` [include/rmp/behavior.h:98](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L98-L142) struct TopDown Eight directions, and the sprite chosen from the one you are facing. The eight-way movement is free and correct because [`rmp::input::vector()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-input.html#vector) normalises: going diagonally is NOT 41 % faster, which is the bug in half the raylib tutorials on the internet. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `speed` | `float` | `220` | Design units per second | | `eight_way` | `bool` | `true` | False = four directions only | | `acceleration` | `float` | `0` | 0 = instant, which is what nearly all 2D wants | | `idle` | `std::string` | `"idle"` | THE ANIMATION NAMES ARE YOURS: they are the tags in your .aseprite, and "idle" and "walk" are only the defaults, not a convention imposed on you. The tag actually chosen is "_" if the sheet has it and "" with flip_x if it does not, so a two-, four- or eight-direction sheet all work with nothing configured. `idle` is played as it is, with no suffix. With no sheet on the object's sprite only flip_x is set, and an empty name plays nothing. THE ART FACES RIGHT. flip_x is set while facing left, to mirror the frames that have no direction of their own — `walk` without a suffix, `idle`, or a sprite with no sheet — so those must be drawn facing east. A tag with a suffix is drawn for its direction and plays unflipped. | | `walk` | `std::string` | `"walk"` | THE ANIMATION NAMES ARE YOURS: they are the tags in your .aseprite, and "idle" and "walk" are only the defaults, not a convention imposed on you. The tag actually chosen is "_" if the sheet has it and "" with flip_x if it does not, so a two-, four- or eight-direction sheet all work with nothing configured. `idle` is played as it is, with no suffix. With no sheet on the object's sprite only flip_x is set, and an empty name plays nothing. THE ART FACES RIGHT. flip_x is set while facing left, to mirror the frames that have no direction of their own — `walk` without a suffix, `idle`, or a sprite with no sheet — so those must be drawn facing east. A tag with a suffix is drawn for its direction and plays unflipped. | | `suffixes` | `std::array` | `{ "e", "ne", "n", "nw", "w", "sw", "s", "se" }` | THE ANIMATION NAMES ARE YOURS: they are the tags in your .aseprite, and "idle" and "walk" are only the defaults, not a convention imposed on you. The tag actually chosen is "_" if the sheet has it and "" with flip_x if it does not, so a two-, four- or eight-direction sheet all work with nothing configured. `idle` is played as it is, with no suffix. With no sheet on the object's sprite only flip_x is set, and an empty name plays nothing. THE ART FACES RIGHT. flip_x is set while facing left, to mirror the frames that have no direction of their own — `walk` without a suffix, `idle`, or a sprite with no sheet — so those must be drawn facing east. A tag with a suffix is drawn for its direction and plays unflipped. | | `left` | `std::string` | | Which actions move it. Empty = the move_* actions that come as standard. | | `right` | `std::string` | | Which actions move it. Empty = the move_* actions that come as standard. | | `up` | `std::string` | | Which actions move it. Empty = the move_* actions that come as standard. | | `down` | `std::string` | | Which actions move it. Empty = the move_* actions that come as standard. | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `direction` Vector2 direction() const function [include/rmp/behavior.h:127](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L127) The last non-zero direction, normalised. What a game reads to fire a weapon the way the character is looking. ### `sector` int sector() const function [include/rmp/behavior.h:130](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L130) Which of the eight sectors `ours.facing` is in, as an index into `suffixes`. ============================================================================== # rmp::behavior::Tween > Moves one property of its object from `from` to `to` over `seconds`, along an Ease. Source: https://omardev29.github.io/rmp-docs/reference/behaviors/Tween.html behavior `#include ` [include/rmp/behavior.h:300](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L300-L332) struct Tween Moves one property of its object from `from` to `to` over `seconds`, along an Ease. With neither `loop` nor `ping_pong` it stops exactly on `to` and `finished()` turns true. Added to an object with `add()`; the framework calls its `_update` with the object it is on. ## Fields | Field | Type | Default | What it is | |---|---|---|---| | `property` | `Property` | `Property::POSITION_Y` | The field it writes | | `from` | `float` | `0` | The value at the start of a pass, in that field's unit | | `to` | `float` | `0` | The value at the end of a pass | | `seconds` | `float` | `1` | How long one pass takes; 0 = straight to `to` | | `ease` | `Ease` | `Ease::IN_OUT` | The curve of each pass | | `loop` | `bool` | `false` | Start again from `from` at the end of each pass | | `ping_pong` | `bool` | `false` | Turn back at each end, forever; wins over `loop` | | `ours` | `struct { … }` | | What it is keeping track of. Readable, because sometimes you want it; not yours to write. It is one PUBLIC member and not a private block because a struct with a private member is not an aggregate in C++20, and then `{ .speed = 320 }` stops compiling — which is the whole design. The name is the fence. | ### `finished` bool finished() const function [include/rmp/behavior.h:312](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L312) Whether it has stopped on `to`: a tween with neither `loop` nor `ping_pong` does at the end of its pass, and one of 0 seconds at once, whatever those two say. ### `restart` void restart() function [include/rmp/behavior.h:314](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/behavior.h#L314-L318) Starts it again from `from`, going forwards, as if it had just been added. ============================================================================== # raylib_multiplatform > A C++20 framework for shipping raylib games to every platform from one codebase, with CI that builds them, boots the ones its runners can run and checks they draw. Source: https://omardev29.github.io/rmp-docs/index.html A C++20 framework for shipping [raylib](https://www.raylib.com/) 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: ```cpp 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. [**Getting started**Install `rmp`, make a game, and build it up one step at a time.](https://omardev29.github.io/rmp-docs/getting-started/index.html) [**Manual**Every part of the framework, explained: scenes, objects, input, the interface, assets, saving.](https://omardev29.github.io/rmp-docs/manual/index.html) [**Reference**Every public name, read from the headers themselves.](https://omardev29.github.io/rmp-docs/reference/index.html) [**The framework**How it is built, and why it is built that way.](https://omardev29.github.io/rmp-docs/framework/index.html)