Architecture
A game made with this framework is five layers deep. At the top is the code you write; under it, the modules you choose to use; under those, a small core that runs the frame; under that, raylib; and at the bottom, the 17 targets the same source is built for. Each layer only reaches down, never up.
The rest of this page takes the layers one at a time, from the top.
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 copies it into a new game:
// Your game starts here, and this is all of it.
//
// RMP_GAME opens the window from [window] in raylib_multiplatform.toml, enters
// the scene you name, runs it every frame, and shuts everything down on the way
// out — on every target, including the two where main() is not a main() at
// all. Your work is in src/scenes/ and src/objects/.
#include <rmp/app.h>
#include "scenes/main_menu.h"
RMP_GAME(MainMenuScene);
RMP_GAME opens the window from [window] in
raylib_multiplatform.toml, enters the scene you name, runs the scene stack every
frame and closes everything on the way out. There is no InitWindow() to write and no
loop: those lines were the same in every game, and on the web and on iOS the loop is not even
yours to write — the browser and UIKit own it.
The first scene is named in
code and not in the .toml on purpose. Choosing a scene by name means a table from
names to types, and in C++ that table is built by objects that register themselves when the
program starts. A linker building a static library or an iOS framework throws away any object
file nothing refers to, and a self-registering object is exactly that: the game would build, run
on a desktop and find no scenes on a phone. So the type is named where the compiler can see
it.
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 and
rmp::Object, one per file, under src/.
A game made by rmp new starts with one, src/scenes/main_menu.cpp.
Every build system
collects src/ recursively, so a new file or a new folder needs no change to CMake,
Gradle or Xcode.
The art, the sounds and the levels go in resources/ and are loaded by name:
rmp::assets::load_texture("player.png"). While you develop they are read from that
folder; a release packs them into one resources.rres file, optionally encrypted, and
the same call reads them from there (rmp pack
does the packing by hand).
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 follows
it all the way through, and Configuration 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
has the reasons and the measurements.
| Header | What it gives you | Built on |
|---|---|---|
rmp/ui.h | rmp::ui: menus, buttons, layout, themes, in screen space | Clay, the layout engine |
rmp/input.h | rmp::input: named actions bound to keys, buttons and sticks, and the pointer | raylib's input, sampled once a frame |
rmp/assets.h | rmp::assets and rmp::Texture and its siblings: loading by name, released by themselves | rres for the pack, cute_aseprite for sprite sheets |
rmp/tilemap.h | rmp::Tilemap: a level made in LDtk or Tiled | cJSON for LDtk, cute_tiled for Tiled |
rmp/audio.h | rmp::audio: sounds and music by name, three volume buses | raylib's raudio |
rmp/save.h | rmp::save and rmp::Value: save slots in the platform's own folder | cJSON, and Monocypher to seal a file |
rmp/random.h | rmp::random: one seeded generator you can replay | xoshiro128++, written out |
rmp/ads.h | rmp::ads: interstitial and rewarded ads | raymob's AdMob bridge on Android, once [android.admob] enabled turns it on; nothing anywhere else |
rmp/math.h | arithmetic: +, - and * on raylib's own vectors, and raylib-cpp's math classes for those who want methods | raylib's raymath, and the math headers of raylib-cpp |
rmp/behavior.h | rmp::behavior: the catalogue — movement, health, timers, spawners | the core's behavior engine |
rmp/scene.h | rmp::Scene and rmp::Camera | the core |
rmp/object.h | rmp::Object, rmp::Handle, rmp::Callback | the core |
rmp/app.h | RMP_GAME, rmp::app::quit() and rmp::global | the core |
Opt-in means two things here, and it is worth being exact about both.
You include what you use. Each header is a module you can take or leave, and
none of them is an umbrella for the others. A few do bring another one with them, and say why at
the top: rmp/scene.h includes rmp/object.h and
rmp/tilemap.h, because a scene holds its map by value and spawns objects;
rmp/object.h includes rmp/assets.h, because a sprite holds a texture by
value. Every public header also includes rmp/config.h, the values from the
.toml, so you never type that one.
You pay for what you use. A camera and a map are fields of every scene: a map
nobody loads draws nothing and stops nothing, and a camera nobody touches shows the world at the
design resolution as it is. The UI starts Clay on the
first rmp::ui::begin() of the game, and the sound device opens on the first call
that needs it, so a game with no menus has no UI arena and a game with no sound never opens the
device.
None of it walls raylib off. An
rmp::Texture converts to the Texture2D it wraps, so every raylib
function that takes one takes it; a scene can open the camera and draw with raylib directly; and
a game in plain C can skip the framework altogether and still
be built for every target but the two where the loop is not the game's to write, the web and
iOS.
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.
- The app and the frame loop
RMP_ENTRY_POINTwrites 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 amain()with a loop. On the web the browser owns the loop and calls a function back once a frame, throughemscripten_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, andRMP_GAMEis 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,push,replaceandpoponly 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_ptrand carries a generation number. Armp::Handleis 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 referencespawn()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. A solid object that is notimmovableis 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 makepositiona 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_updatewith the same signature when its whole job is to correct where the object ended up, asGridSnapdoes, and no virtual functions, so that it stays an aggregate. The engine finds its optional hooks at compile time withrequires, keeps one table of function pointers per type, and owns the struct through astd::shared_ptr<void>that carries its destructor. A behavior of yours and one of the catalogue's are the same kind of thing; there is no base class and nothing to register.
In
a CMake build — the desktops, the BSDs and the web — the framework is compiled once into a static
library called rmp, and the game and every example written in C++ link it. The one file kept out of
the library is src/rmp/app/app.cpp: each executable compiles its own copy, because it
refers to the symbol the entry-point macro defines, and that reference is what turns a program
with no RMP_GAME into a link error that names what is missing. The Android build
and the iOS project compile src/ as a whole into the app, framework and game
together.
The library is
built only when src/rmp/ has sources. A game in plain C deletes that folder because
nothing in it is used: a game with no C++ of its own in
src/, outside src/rmp/, is linked to raylib alone, so a
src/rmp/ left behind would be the whole framework compiled for nothing in a CMake
build, and compiled into the game on Android and iOS, which take everything under
src/. With it gone the build has no framework library at all — only raylib, the
game's own C, and the headers that are plain C.
Those
headers are on a plain C game's include path on every target: rmp/config.h for the
values of the .toml, tests/smoke_test.h for the CI's hooks, and
<admob.h> from thirdparty/raymob for the ads as C functions,
which do nothing anywhere but Android.
raylib 6.2, modified#
Under the core is raylib 6.2, vendored in
thirdparty/raylib. The copy is modified, and says so: the zlib licence requires an
altered copy to be plainly marked, and its
PATCHES.md lists every change. It is raylib 6.2 as raylib_cmake_template carries
it — with raylib's own fixes from after 6.2 and the gaps its security audit left closed — with the
framework's patches on top. Most of those are build-system and platform-selection patches, so the
windowing backend can be chosen from the .toml; one makes Android's EGL ask for the
OpenGL ES version raylib was compiled for, and the DRM backend's card probe, Escape on its terminal
and its flow control are fixed.
Among
the libraries raylib bundles, three files are changed: the software renderer's nearest-texel
lookup is clamped to the texture, a fix of the framework's own that upstream does not have, so the
far edge of a texture reads its last texel and not the one past it; the OBJ loader takes raylib's
face fix from after 6.2; and RGFW's gamepad code builds on older kernel headers.
Licences has the rest.
The
iOS app is the one target that does not build this copy. It links a
raylib.xcframework built from a fork, omardev29/raylib-iOS, pinned at
tag 6.0.3-iOS as the submodule thirdparty/raylib-ios, so the changes
PATCHES.md lists are what every other target runs, not what iOS runs.
raylib is built in modules, and the framework leans on most of them:
| Module | What it does | Can a game leave it out? |
|---|---|---|
rcore | the window, input, timing | No: raylib requires it |
rlgl | the OpenGL layer under every draw call | No: raylib requires it |
rshapes | rectangles, circles, lines | No: rmp::ui draws every panel and button with it |
rtextures | images and textures | No: the asset layer and the CI render check are built on it |
rtext | fonts and text | No: the rres loader calls into it |
raudio | sound and music | Yes |
rmodels | 3D models and meshes | Yes |
Leaving one
out is [raylib]
disabled_modules, and configure.py refuses the modules in the third column
that say no, with the reason, before anything compiles. The iOS build links a prebuilt raylib and
ignores the setting.
[raylib]
disabled_modules = ["rshapes"] raylib_multiplatform.toml:2: disabled_modules = ["rshapes"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
configure: error: [raylib] disabled_modules: 'rshapes' cannot be disabled — rmp::ui draws every panel, button and border with it — DrawRectangleRounded and three others — and the UI is always compiled in, so there is nothing left to link against.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 <os>-<arch>-<libc>-<env>, and each part is
there only when it can differ. linux-x64-glibc and linux-x64-musl name
their C library because a binary built for one does not start on a system with the other: musl and
glibc are two libraries, not two versions of one. The last part is the windowing system —
drm draws straight to the screen with no X11 and no Wayland — and is absent when the
binary carries every backend and picks one when it starts. windows-x64 and
macos stop early because Windows has one C library and the macOS build is
universal.
Each family has its own build system underneath, all of them fed from the same
.toml: CMake for the desktops, the BSDs and the web, Gradle for Android, and an
Xcode project generated by XcodeGen for iOS. A push to the framework builds Linux x64, the web,
Android and Windows x64; a release tag builds every target, boots the ones a runner can boot, and
checks that each one drew — Testing says how.