21 mCurrentScene(nullptr),
31 const auto start = std::chrono::steady_clock::now();
34 static bool sRegistrationsApplied =
false;
35 if (!sRegistrationsApplied)
38 for (
auto& entry : pending)
43 sRegistrationsApplied =
true;
49 mTextureCache = std::make_shared<TextureCache>(mRenderer);
50 mModelCache = std::make_shared<ModelCache>(mRenderer);
51 mModelCache->CreateQuad2D();
53 mMaterialCache = std::make_shared<MaterialCache>(mRenderer);
54 mMaterialCache->CreateBuildInMaterials();
57 mTextRenderer->StoreFontAtlasesInFiles(
false);
61 LOG_INFO(
"Loading assets from package.");
62 mTextureCache->LoadTexturesFromPackage();
63 mModelCache->LoadModelsFromPackage();
64 mTextRenderer->LoadFontsFromPackage();
68 LOG_INFO(
"Loading assets from folders.");
70 mTextureCache->LoadTexturesFromFolder(textureFolder.string());
72 mModelCache->LoadModelsFromFolder(modelsFolder.string());
74 mTextRenderer->LoadFontsFromFolder(fontsFolder.string());
81 if(!startScene.empty())
86 const auto end = std::chrono::steady_clock::now();
88 std::chrono::duration<float, std::milli>(end - start).count();
90 LOG_INFO(
"SceneManager initialized in " +
91 std::to_string(initMs) +
" ms.");
98 using clock = std::chrono::steady_clock;
99 auto start = clock::now();
101 std::string oldSceneName = mCurrentScene ?
typeid(*mCurrentScene).name() :
"None";
102 std::string newSceneName =
typeid(*mNextScene).name();
106 mCurrentScene->Shutdown();
109 mCurrentScene = std::move(mNextScene);
111 LOG_INFO(
"Switching scene: " + oldSceneName +
" -> " + newSceneName);
113 mCurrentScene->Initialize();
114 mNextScene =
nullptr;
116 auto end = clock::now();
117 auto durationMs = std::chrono::duration<float, std::milli>(end - start).count();
119 LOG_INFO(
"Scene '" + newSceneName +
"' loaded in " + std::to_string(durationMs) +
" ms");
124 mCurrentScene->Update(deltaTime);
132 mCurrentScene->Draw();
140 mCurrentScene->Shutdown();
142 mMaterialCache->ReleaseAll();
143 mModelCache->ReleaseAll();
144 mTextureCache->ReleaseAll();
145 mTextRenderer->Shutdown();
155 static std::vector<std::pair<std::string, Factory>> pending;
177 auto& map = GetMap();
178 return map.emplace(name, std::move(factory)).second;
183 std::unique_ptr<Scene> scene =
nullptr;
184 auto& map = GetMap();
185 auto it = map.find(name);
188 scene = (it->second)(sm);
195 return mTextRenderer;
Defines a generic application interface for rendering-based programs.
Defines an abstract interface for rendering backends.
Manages scenes, resource caches, and scene transitions within the rendering engine.
~SceneManager()
Destructor. Cleans up resources and active scenes.
virtual void Draw()
Draws the active scene using the associated renderer.
IApplication * GetApplication()
Returns the application associated with this SceneManager.
static std::string sStartSceneName
static bool RegisterScene(const std::string &name, Factory factory)
Registers a scene type with a name string.
virtual void Update(float deltaTime)
Updates the currently active scene.
static std::vector< std::pair< std::string, Factory > > & GetPendingRegistrations()
Type alias for the factory used to create scenes.
virtual void Shutdown()
Releases all scene-related resources and shuts down the manager.
void LoadScene(std::string sceneName)
Loads a new scene by name.
std::function< std::unique_ptr< Scene >(SceneManager &)> Factory
virtual void Initialize()
Initializes the current scene and related caches.
static std::unique_ptr< Scene > CreateScene(const std::string &name, SceneManager &sm)
Creates a scene instance by its registered name.
SceneManager(IRenderer *renderer, IApplication *app)
Constructs a SceneManager instance.
RenderResourceContext GetRenderResourceContext() const
Retrieves the current RenderResourceContext.
std::shared_ptr< TextRenderer > GetTextRenderer()
static boost::filesystem::path GetFontsFolderPath()
Returns absolute path to Content/Fonts.
static boost::filesystem::path GetTextureFolderPath()
Returns absolute path to Content/Textures.
static boost::filesystem::path GetModelsFolderPath()
Returns absolute path to Content/Models.
static bool IsPackageProvided()
Checks whether packed assets (Pack.bin / Pack.json) exist.
Engine-wide logging system for runtime diagnostics and performance tracking.
Aggregates pointers to global rendering resource managers.
TextureCache * textureCache
MaterialCache * materialCache