athanggupte / ApexGameEngine

Apex Game Engine
MIT License
4 stars 1 forks source link

Snapshot generator and loader for ResourceManager #31

Closed athanggupte closed 2 years ago

athanggupte commented 2 years ago

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:

  1. OnScenePlay: Create a snapshot of the current state of the ResourceManager and save it for later use and then continue with scene->OnPlay().
  2. 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:

Cons:

athanggupte commented 2 years ago

Added the base enhancement (without extra performance optimization) in 8912ef88c6bbd7415e996b576b9fb27312a44806.