Breaking Out of C++:
When Scenes Become Data
Up until now, RoboEngine had a dirty little secret: every time you launched the executable, it rebuilt the exact same demo world directly in C++. Sure, we could save and load JSON files, but only to a single hardcoded path, and launching the app always overwrote your reality with whatever was baked into FirstApp’s constructor.
I finally cut that cord.
Armed with “Game Engine Architecture (3rd), Chapter 7: Resources and File Systems”, I deleted the C++ scene-building code from our earliest Vulkan Tutorial and replaced it with a single command: open content/scenes/vases.scene.json at startup.
Along for the ride came a proper File menu (New, Open, Save, Save As), a custom ImGui file picker, and unsaved-change tracking.
It’s a huge milestone: RoboEngine is no longer locked to its own hardcoded demo; it can now create, edit, and boot into anyone’s content.
Before:
Trapped in the Constructor
Previously, FirstApp’s constructor hand-assembled our test scene using three helper functions (loadMesh, loadPointLight, and loadPointLights):
// World is +Z up: scale.z stretches the vases' height, while the floor quad lies in the XY plane
loadMesh("content/models/flat_vase.obj", {-0.5f, 0.0f, 0.0f}, {3.0f, 3.0f, 1.5f});
loadMesh("content/models/smooth_vase.obj", { 0.5f, 0.0f, 0.0f}, {3.0f, 3.0f, 1.5f});
loadMesh("content/models/quad.obj", { 0.0f, 0.0f, 0.0f}, {5.0f, 5.0f, 1.0f});
loadPointLights(); // Builds a "Lights" group with six colored, orbiting lights in a ring
Meanwhile, the editor’s File menu had just two rigid buttons: Save and Load, both glued to content/scenes/main.scene.json. If you wanted to change what the engine booted into, you had to crack open C++ and recompile.
Anatomy of a .scene.json File
Our classic demo world now lives inside a 406-line JSON file housing 10 entities: the two vases, the floor quad, a parent Lights group, and its six orbiting point lights. Each entity records its file ID, its parent’s ID (null for root objects), and a map of components keyed by the exact display names from our Component Table:
{
"id": 5,
"parent": 4,
"components": {
"Name": { "name": "Point Light 0" },
"Transform": { "translation": [-1.0, -1.0, 1.0], "rotation": [0, 0, 0], "scale": [1, 1, 1] },
"Point Light": { "color": [1, 0.1, 0.1], "intensity": 0.2, "radius": 0.1 },
"Orbit": { "center": [0, 0, 0], "axis": [0, 0, 1], "speed": 1.0 }
}
}
At the very top sits “version”: 2, signaling our +Z up coordinate system. Older Version 1 files were authored in −Y up, so the loader politely refuses them rather than dumping your world onto its side.
One Line to Boot the World
With scenes living on disk, FirstApp shed roughly 70 lines of code and two includes; it no longer touches models or components at all. Startup is now just a path constant and a single function call:
// first_app.hpp
static constexpr const char *STARTUP_SCENE = "content/scenes/vases.scene.json";
// first_app.cpp
// Boot into the demo scene; if missing, open an empty world and report why in the menu bar
editor->openSceneFile(scene, STARTUP_SCENE);
openSceneFile is the exact same workhorse used by the File menu: it waits for the GPU to finish any frames in flight, loads the new scene, wipes the undo stack, and records the active file path. Better yet, if a file is missing or malformed, it aborts before clearing the current scene—so a bad file never wipes out your work.
Building an ImGui File Picker (ReFilePicker)
Rather than pulling in platform-specific OS dialog libraries, I built ReFilePicker, a 240-line modal file browser rendered entirely in ImGui. It looks identical across operating systems, requires zero external dependencies, and boils down to two calls:
picker.open(ReFilePicker::Mode::Open, "Open Scene", startDir, ".scene.json");
// Every frame:
std::string chosen;
if (picker.draw(chosen)) { /* Fires once on the frame a file is confirmed */ }
Under the hood, std::filesystem scans the current directory, sorting folders first and filtering files by extension (case-insensitively). You can jump up a folder, refresh, double-click files, or hit Enter in the filename box. In Save mode, it automatically appends .scene.json if missing and warns you before overwriting an existing file; in Open mode, the Open button stays locked until the typed name matches a real file on disk.
Best of all, whenever the chosen file sits inside the project’s working directory, ReFilePicker converts it into a relative path—keeping scene references portable instead of hardcoding D:\… paths into your data.
A Real File Menu & Dirty Tracking
With the picker ready, the editor gained a full suite of standard file commands:
| Command | Shortcut | Behavior |
| New Scene | Ctrl+N | Clears the world (prompts first if you have unsaved changes) |
| Open Scene… | Ctrl+O | Launches the picker in the current scene’s folder (or content/scenes) |
| Save Scene | Ctrl+S | Saves directly to the open file, or falls back to Save As if untitled |
| Save Scene As… | Ctrl+Shift+S | Opens the picker in Save mode, defaulting to the current name or new.scene.json |
To prevent accidental data loss, the editor now tracks currentScenePath alongside a sceneDirty flag. Every recorded edit, undo, or redo flips sceneDirty on, slapping a classic asterisk onto the window title (RoboEngine – vases.scene.json *), while saving, opening, or starting fresh clears it. Try to hit New or Open while dirty, and an “Unsaved Changes” modal steps in to ask whether you want to discard or cancel.
Traps & Mobs Along the Way
Wiring up file dialogs and dirty flags in an immediate-mode UI comes with a few classic gotchas:
One choke point for dirty tracking.
- By routing every undo recording through a single recordChange(…) helper that also sets sceneDirty = true, dirty tracking became completely automatic: if an action can be undone, the engine knows the scene needs saving.
Open ImGui popups at the exact ID level you draw them.
- ImGui matches OpenPopup and BeginPopupModal using the current window and ID stack. Calling OpenPopup directly from inside a File menu item produces a different ID hash than drawing the modal at the root level later in the frame.
- The fix: menu items simply flip boolean flags (confirmDiscardRequested or openRequested), and a single drawFileDialogs() function opens and renders every modal from one consistent scope.
Never mutate a list while looping over it.
- Clicking a folder inside ReFilePicker triggers changeDirectory(), which clears and refills the entries vector currently being iterated. Instead of changing folders mid-loop, a click simply stores enterDir and executes the directory swap safely after the loop finishes.
Validate before you destroy.
- Before calling scene.clear(), the loader parses the JSON and verifies it contains an entities array and a supported format version. If anything looks wrong, or if vases.scene.json is missing at launch, the engine leaves your current scene intact (or starts cleanly with an empty scene) and prints the reason right in the status bar.
Relative paths need the right launch folder.
- Because STARTUP_SCENE and model paths resolve relative to the process working directory, launching the binary from the wrong folder means content/ won’t be found, resulting in a harmless empty scene rather than a crash.
Don’t spam glfwSetWindowTitle.
- updateWindowTitle() checks the title string every frame, but only calls into GLFW when the text actually changes (such as when the dirty * appears or disappears).
Next Up on the Quest
Now that RoboEngine boots from data instead of hardcoded C++, it’s time to make building the engine itself effortless. In our next DevBlog, we’ll tackle ditching prebuilt GLFW binaries and compiling GLFW straight from source as a static library, eliminating one more manual setup step before you can hit build and run!
