CSceneManager is a singleton that manages scenes in a stack(FILO) structure during gameplay. Transitions ensure consistent state changes and safe resource management, while smart pointer-based handling allows shared resources to be reused without reloading, enabling efficient memory use and fast switching.
Remove the scene from the top of the stack, then add a new scene.
1. Create a new scene. 2. Load new scene resources, reusing shared resources from the top scene. 3. Execute PopScene(). 4. Add the new scene to the top of the stack. 5. Execute Enter() on the new scene.
Remove all scenes, then add a new scene to the top of the stack.
1. Load new scene resources, carrying over shared resources from the previous scene. 2. Execute ClearScenes(). 3. Add the new scene to the top of the stack. 4. Execute Enter() on the new scene.
Scene Transition Resource Management (Code Breakdown)
⚠️ Note: This code has been simplified to illustrate the scene transition resource management approach.
Each Resource Manager holds resources using only std::weak_ptr. This maintains weak references without taking ownership of the resources, and the actual memory is automatically released when all references are gone in the scene that owns the resources via shared_ptr.
The CScene abstract class manages various resources such as CTexture, CFont, CSFX, CBGM using std::shared_ptr. This ensures that each scene clearly owns the resources it needs, and calling UnloadResources() clears the vectors to release all references. With smart pointer-based reference management, unused resources can be safely release.
SwapScene() first creates the new scene and loads its resources, then calls Exit() on the existing scene, unloads its resources, and removes it from the stack. During this transition, shared resources between the previous and current scenes are reused without reloading, minimizing transition delays and improving memory usage efficiency.
Conclusion
The scene stack structure of CSceneManager and its smart pointer-based resource management enhance not only simple scene swapping but also the stability of transitions and the reliability of memory management. This allows various scene transition patterns to be applied as needed and supports flexible architecture extension and long-term maintainability across the framework.