17 mCurrentScene(nullptr),
28 static bool sRegistrationsApplied =
false;
29 if (!sRegistrationsApplied)
32 for (
auto& entry : pending)
37 sRegistrationsApplied =
true;
43 mTextureCache = std::make_shared<TextureCache>(mRenderer);
44 mModelCache = std::make_shared<ModelCache>(mRenderer);
46 mModelCache->CreateQuad2D();
50 mTextureCache->LoadTexturesFromPackage();
51 mModelCache->LoadModelsFromPackage();
56 mTextureCache->LoadTexturesFromFolder(textureFolder.string());
57 mModelCache->LoadModelsFromFolder(modelsFolder.string());
59 mMaterialCache = std::make_shared<MaterialCache>(mRenderer);
60 mMaterialCache->CreateBuildInMaterials();
66 if(!startScene.empty())
79 mCurrentScene->Shutdown();
82 mCurrentScene = std::move(mNextScene);
83 mCurrentScene->Initialize();
89 mCurrentScene->Update(deltaTime);
97 mCurrentScene->Draw();
105 mCurrentScene->Shutdown();
107 mMaterialCache->ReleaseAll();
108 mModelCache->ReleaseAll();
109 mTextureCache->ReleaseAll();
119 static std::vector<std::pair<std::string, Factory>> pending;
141 auto& map = GetMap();
142 return map.emplace(name, std::move(factory)).second;
147 std::unique_ptr<Scene> scene =
nullptr;
148 auto& map = GetMap();
149 auto it = map.find(name);
152 scene = (it->second)(sm);
Defines a generic application interface for rendering-based programs.
Defines an abstract interface for rendering backends.
~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.
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.
Aggregates pointers to global rendering resource managers.
TextureCache * textureCache
MaterialCache * materialCache