Project Session

#include <safi/editor/project_session.h>

The editor is a single binary that boots into a Hub screen when no project is open and into the editor view once one is. SafiProjectSession is that switch: hub_active decides which UI the debug overlay draws, and project records the currently-open project.

Opening a project re-roots the asset system, loads the default scene into the live world, and bumps the recents list. Closing clears the world and returns to the Hub. The same window, renderer, and world are reused throughout.

Struct

typedef struct SafiProjectSession {
    bool            hub_active;   /* true → draw Hub, false → draw editor */
    bool            has_project;  /* true once a project has been opened  */
    SafiProjectInfo project;      /* the open project (valid iff has_project) */
} SafiProjectSession;

The component is declared and defined inside project_session.c rather than in the central component registry, so worlds that never install a session (such as the gltf_viewer sample) are unaffected — the accessors below guard on the component id being zero and report "no Hub".

API

void safi_project_session_install(ecs_world_t *world, bool start_in_hub);
bool safi_project_session_open   (ecs_world_t *world, const SafiProjectInfo *info);
void safi_project_session_close  (ecs_world_t *world);

/* UI accessors — safe even where no session was installed. */
bool                   safi_project_session_hub_active(const ecs_world_t *world);
const SafiProjectInfo *safi_project_session_current   (const ecs_world_t *world);
  • install registers the singleton. Pass start_in_hub = true when the editor launched without a --project argument.
  • open re-roots assets to info->path, loads its default scene, touches recents, and switches to the editor view. Returns false (and stays in the Hub) if the scene fails to load.
  • close clears the world and returns to the Hub.

Typical use

The editor binary wires it up in main:

safi_app_init(&app, &desc);
ecs_world_t *world = safi_app_world(&app);

safi_project_set_templates_dir(SAFI_TEMPLATES_DIR);
safi_project_session_install(world, project_dir == NULL);

if (project_dir) {
    SafiProjectInfo info;
    if (safi_project_load(project_dir, &info))
        safi_project_session_open(world, &info);
}
safi_app_run(&app);

The Hub UI calls open when a project is picked, and the Scene panel's Close Project button calls close.

See also