# 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>`

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()`.
