On this page
  1. Resource
  2. valid, operator bool
  3. name
  4. changed, reload
  5. raw
  6. operator const T &

Resource handles

class #include <rmp/assets.h> include/rmp/assets.h:125

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)

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 make a full one, from a reference the resource table has already counted.

valid, operator bool

bool valid() const
explicit operator bool() const

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

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)

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:

if (rabbit.changed()) rabbit.reload();

Debug builds on the desktop only, like rmp::Value::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

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 &

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.