Lysa Nodes  0.0
Lysa Nodes — Scene Graph for the Lysa Engine
Engine context

lysa::ContextConfiguration and lysa::Lysa

Every Lysa application is anchored by a lysa::ContextConfiguration aggregate and a lysa::Lysa instance that consumes it and initialises the graphics device, virtual filesystem, and event bus.

In Main.cpp the configuration is declared at file scope so it can be mutated in lysaMain (to pick the graphics backend) before the engine is constructed:

import lysa;
import lysa.nodes;
lysa::ContextConfiguration contextConfiguration {
.loggingConfiguration {
.loggingMode = lysa::LOGGING_MODE_STDOUT,
.logLevelMin = lysa::LogLevel::INFO,
},
};

Key fields of ContextConfiguration

Field Default Effect
backendConfiguration.backend VULKAN Graphics API (VULKAN or DIRECTX)
deltaTime 1.0/60.0 Fixed timestep for PHYSICS_PROCESS events
framesInFlight 2 Number of GPU frames in flight (double-buffering)
maxShadowMapsPerScene 20 Upper bound on active shadow maps
resourcesCapacity see below GPU pool sizes for meshes, images, materials

Accessing the context at runtime

After lysa::Lysa is constructed the singleton is reachable everywhere via lysa::ctx():

// Subscribe to a global engine event
lysa::ctx().events.subscribe(lysa::MainLoopEvent::PROCESS,
[](const lysa::Event& e) { ... });
// Open a file through the virtual filesystem
auto stream = lysa::ctx().fs.openReadStream("app://res/config.json");
// Schedule a one-shot deferred operation on the next frame
lysa::ctx().defer.push([] { /* safe to run on the main GPU thread */ });
// Signal the main loop to exit
lysa::ctx().exit = true;

Initialisation order

lysa::Lysa must be the first member of the Application class. C++ initialises members in declaration order, so placing lysa first guarantees the engine context exists before the window and scene are constructed:

class Application {
// ...
private:
lysa::Lysa lysa; // creates the engine context first
MainWindow window; // needs the context
std::unique_ptr<RotatingAssetScene> scene; // needs the window
};

Entry point

int lysaMain() {
if constexpr (vireo::getPlatform() == vireo::Platform::WINDOWS) {
contextConfiguration.backendConfiguration.backend = vireo::Backend::DIRECTX;
}
Application().run();
return 0;
}
Note
lysaMain uses if constexpr so the DirectX branch is compiled only on Windows.

Next : Rendering window