Problem: Since resources can be added to the ResourceManager via scripts, stopping and playing the scene results in a failing assertion as the scripts attempt to add the same resource to the registry again.
Proposed mechanism:
OnScenePlay: Create a snapshot of the current state of the ResourceManager and save it for later use and then continue with scene->OnPlay().
OnSceneStop: Load the snapshot created during OnScenePlay to get delete all resources added via user scripts from the registry and their references from the pools. The reference counting in the shared_ptrs should delete the data from memory and thus automate garbage collection.
Possible enhancement to consider:
(Memory vs load time)
For scripts which add a lot of resources during creeation, the delay due to load time may be noticeable for several consecutive runs. Thus, instead of deleting the resources from the RM inside OnSceneStop, another snapshot can be created and cached for the next run. Then the references from this cached snapshot can be copied to the pools during LoadAllResources rather than creating or loading the resources from disk again.
Pros:
Expect faster load times as memory allocations and disk accesses will be reduced.
Cons:
More memory usage as resources will not be cleared from memory.
Problem: Since resources can be added to the ResourceManager via scripts, stopping and playing the scene results in a failing assertion as the scripts attempt to add the same resource to the registry again.
Proposed mechanism:
OnScenePlay
: Create a snapshot of the current state of the ResourceManager and save it for later use and then continue withscene->OnPlay()
.OnSceneStop
: Load the snapshot created duringOnScenePlay
to get delete all resources added via user scripts from the registry and their references from the pools. The reference counting in the shared_ptrs should delete the data from memory and thus automate garbage collection.Possible enhancement to consider: (Memory vs load time) For scripts which add a lot of resources during creeation, the delay due to load time may be noticeable for several consecutive runs. Thus, instead of deleting the resources from the RM inside
OnSceneStop
, another snapshot can be created and cached for the next run. Then the references from this cached snapshot can be copied to the pools duringLoadAllResources
rather than creating or loading the resources from disk again.Pros:
Cons: