Resource Manager - JayhawkZombie/EECS581Project GitHub Wiki
The Engine contains a multi-threaded single-threaded (for now while working on a new multi-threaded loader) resource manager and loader that you should take advantage of. Loading items from disk, especially textures and large configuration files, is quite slow. Loading should be done in a thread that is not the main thread so that the Engine can continue to operate smoothly.
The Engine can only respond to events and render from inside the main thread, so blocking the main thread with file IO will stall the main thread and can lead to a multitude of negative issues:
- FPS Stuttering
- Slow animations
- Missed events
- Barrage of events that piled up
- Process marked unresponsive
- Process killed
The worst thing would be if the Engine's main process was killed or marked as unresponsive. Thus, all file IO should be done in a separate thread.
The resource manager does this and had a dedicated thread that can be woken up when there are new resources in the queue.
To use the resource manager, include the SFEngine/Source/Headers/Resources/ResourceManager.h
file (though you shouldn't have to if you have already included the BaseEngineInterface.h
file)
The following methods are available for you to use:
std::shared_ptr<sf::Texture> LoadTexture(const std::string &path, const std::string &ID)
- Request a texture to be loaded off disk. Path is relative to the executable.
- Give the texture an ID to identify it. Future requests for the same ID will return the texture already loaded
bool ReleaseTexture(const std::string &ID)
- Request to release a resource
Experimental void ForceClearTextures()
- Force the deallocation of all loaded textures
The other resource types follow the same paradigm and are self-explanatory.
std::shared_ptr<sf::Font> LoadFont(const std::string &path, const std::string &ID)
bool ReleaseFont(const std::string &path)
void ForceClearFonts()
std::shared_ptr<sf::Shader> LoadShader(const std::string &path, const std::string &ID)
bool ReleaseShader(const std::string &path)
void ForceClearShaders()
std::shared_ptr<sf::SoundBuffer> LoadSoundBuffer(const std::string &path, const std::string &ID)
bool ReleaseSoundBuffer(const std::string &path)
void ForceClearSoundBuffers()
void StreamMusic(const std::string &path)
- Stream music off the disk
- Avoids loading large music files
- Best used for long music files
void PauseMusic(const std::string &path)
- Pauses the music playing
void PlayMusic(const std::string &path)
- Plays the music out of memory
- Best used for short audio clips, like effect sounds