The resource manager manages resources. Groundbreaking news, I know. In short, the resource manager loads and manages Textures, Sounds, Scripts, Fonts, etc. More...
#include <ResourceManager.hpp>
Collaboration diagram for BARE2D::ResourceManager:Static Public Member Functions | |
| static ShaderProgram | loadShaders (std::string &vertShaderPath, std::string &fragShaderPath) |
| Loads some shaders. Combines both to give a full shader program. Does not cache. More... | |
| static ShaderProgram | loadShadersFromSource (std::string &vertShaderSource, std::string &fragShaderSource) |
| Loads some shaders from their source. Does not cache. More... | |
| static Texture | loadTexture (std::string &texturePath) |
| Loads a texture if it isn't already in the cache. More... | |
| static MutableTexture * | createMutableTexture (std::string &textureName, unsigned int width, unsigned int height, GLenum minMagFilter=GL_LINEAR, unsigned int channels=4, GLenum format=GL_RGBA) |
| Creates a new mutable texture, or replaces one that exists with a new texture. More... | |
| static MutableTexture * | loadMutableTexture (std::string &textureName) |
| Gets a texture from the cache, or creates a new, empty texture. More... | |
| static Sound | loadSound (std::string &soundPath) |
| Loads a sound from the filepath given from the cache or from the file if the cache doesn't contain it. More... | |
| static Music | loadMusic (std::string &musicPath) |
| Loads some music from the filepath given from the cache or from the file if the cache doesn't contain it. More... | |
| static LuaScript | loadScript (std::string &scriptPath) |
| Loads a script from the filepath given from the cache or from the file if it's not already in the cache. More... | |
| static LuaScript | loadScriptFromSource (std::string &scriptSource, std::string name) |
| Creates and caches a script from the given source code. More... | |
| static Font | loadFont (std::string &fontPath, int size) |
| Loads a font to the cache. More... | |
| static void | clearCaches () |
| Clears the various caches. This is useful for debugging. More... | |
| static void | setAssetsPathPrefix (std::string prefix) |
| Changes the prefix that will be prepended to all paths when resources are loaded. More... | |
| static std::string | getAssetsPathPrefix () |
| Returns the assets path prefix. Pretty simple. More... | |
| static void | setTexturePathPrefix (std::string prefix) |
| Changes the prefix that will be prepended to all texture paths when they're loaded. More... | |
Static Private Attributes | |
| static std::string | m_assetsPathPrefix = "" |
| static std::string | m_texturePathPrefix = "" |
| static Cache< std::string, Texture > * | m_textures = new Cache<std::string, Texture>() |
| static Cache< std::string, MutableTexture > * | m_mutableTextures = new Cache<std::string, MutableTexture>() |
| static Cache< std::string, Sound > * | m_sounds = new Cache<std::string, Sound>() |
| static Cache< std::string, Music > * | m_music = new Cache<std::string, Music>() |
| static Cache< std::string, LuaScript > * | m_scripts = new Cache<std::string, LuaScript>() |
| static Cache< std::string, Font > * | m_fonts = new Cache<std::string, Font>() |
The resource manager manages resources. Groundbreaking news, I know. In short, the resource manager loads and manages Textures, Sounds, Scripts, Fonts, etc.
Definition at line 20 of file ResourceManager.hpp.
|
static |
Clears the various caches. This is useful for debugging.
Definition at line 283 of file ResourceManager.cpp.
References BARE2D::Logger::getInstance(), BARE2D::Logger::log(), m_fonts, m_mutableTextures, m_scripts, m_sounds, and m_textures.
Here is the call graph for this function:
|
static |
Creates a new mutable texture, or replaces one that exists with a new texture.
| width | The width of the texture |
| height | The height of the texture. |
| textureName | The identifier for the cache |
| minMagFilter | The GLenum which corresponds to how minimizing and magnifying is going to be handled. Generally, GL_LINEAR or GL_NEAREST. Defaults to GL_LINEAR |
| channels | The number of colour channels. For RGBA, it's 4. For just red, it's one. etc. etc. Defaults to 4. |
| format | The format of texture data. Generally GL_RGBA, GL_RED, etc. Defaults to GL_RGBA. |
Definition at line 110 of file ResourceManager.cpp.
References BARE2D::GLContext::bindTexture(), BARE2D::MutableTexture::channels, BARE2D::Texture::filepath, BARE2D::MutableTexture::format, BARE2D::GLContextManager::getContext(), BARE2D::Texture::height, BARE2D::Texture::id, loadMutableTexture(), m_mutableTextures, and BARE2D::Texture::width.
Here is the call graph for this function:
|
static |
Returns the assets path prefix. Pretty simple.
Definition at line 299 of file ResourceManager.cpp.
References m_assetsPathPrefix.
Referenced by BARE2D::ShaderProgram::compileShaders().
Here is the caller graph for this function:
|
static |
Loads a font to the cache.
| fontPath | The path to load the font from |
| size | The size of the font to load it as. |
Definition at line 263 of file ResourceManager.cpp.
References BARE2D::Font::init(), m_assetsPathPrefix, and m_fonts.
Here is the call graph for this function:
|
static |
Loads some music from the filepath given from the cache or from the file if the cache doesn't contain it.
| musicPath | The path to load the music from |
Definition at line 186 of file ResourceManager.cpp.
References m_assetsPathPrefix, m_music, BARE2D::Music::music, BARE2D::SDL_MIXER_LOAD_FAILURE, and BARE2D::throwFatalError().
Here is the call graph for this function:
|
static |
Gets a texture from the cache, or creates a new, empty texture.
| textureName | The "filepath" of the texture, this is used to identify the texture in the cache. |
Definition at line 153 of file ResourceManager.cpp.
References m_mutableTextures.
Referenced by createMutableTexture().
Here is the caller graph for this function:
|
static |
Loads a script from the filepath given from the cache or from the file if it's not already in the cache.
| scriptPath | The path to load the script from. |
Definition at line 211 of file ResourceManager.cpp.
References BARE2D::LuaScript::inited, m_assetsPathPrefix, BARE2D::LuaScript::m_path, BARE2D::LuaScript::m_script, m_scripts, and BARE2D::IOManager::readFileToBuffer().
Referenced by BARE2D::XMLData::read().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Creates and caches a script from the given source code.
| scriptSource | The actual source code (Lua) of the script |
| name | The name of the script |
Definition at line 244 of file ResourceManager.cpp.
References BARE2D::LuaScript::inited, BARE2D::LuaScript::m_path, BARE2D::LuaScript::m_script, and m_scripts.
|
static |
Loads some shaders. Combines both to give a full shader program. Does not cache.
| vertShaderPath | The path to the vertex shader |
| fragShaderPath | The path to the fragment shader |
Definition at line 22 of file ResourceManager.cpp.
References BARE2D::ShaderProgram::compileShaders(), fragShaderSource, m_assetsPathPrefix, and vertShaderSource.
Here is the call graph for this function:
|
static |
Loads some shaders from their source. Does not cache.
| vertShaderSource | The source to compile from. |
| fragShaderSource | The source to compile from. |
Definition at line 32 of file ResourceManager.cpp.
References BARE2D::ShaderProgram::compileShadersFromSource(), fragShaderSource, and vertShaderSource.
Here is the call graph for this function:
|
static |
Loads a sound from the filepath given from the cache or from the file if the cache doesn't contain it.
| soundPath | The path to load the sound from. |
Definition at line 161 of file ResourceManager.cpp.
References BARE2D::Sound::chunk, m_assetsPathPrefix, m_sounds, BARE2D::SDL_MIXER_LOAD_FAILURE, and BARE2D::throwFatalError().
Here is the call graph for this function:
|
static |
Loads a texture if it isn't already in the cache.
| texturePath | A path to the texture to be loaded, including the actual name of the texture ("assets/texture.png" for example) |
Definition at line 41 of file ResourceManager.cpp.
References BARE2D::GLContext::bindTexture(), BARE2D::decodePNG(), BARE2D::Texture::filepath, BARE2D::GLContextManager::getContext(), BARE2D::Texture::height, BARE2D::Texture::id, m_assetsPathPrefix, m_texturePathPrefix, m_textures, BARE2D::IOManager::readFileToBuffer(), BARE2D::TEXTURE_FAILURE, BARE2D::throwFatalError(), and BARE2D::Texture::width.
Referenced by BARE2D::XMLData::read().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Changes the prefix that will be prepended to all paths when resources are loaded.
| prefix | The path to prepend on any load. |
Definition at line 294 of file ResourceManager.cpp.
References m_assetsPathPrefix.
|
static |
Changes the prefix that will be prepended to all texture paths when they're loaded.
| prefix | The path to prepend on texture loads. |
Definition at line 304 of file ResourceManager.cpp.
References m_texturePathPrefix.
|
staticprivate |
Definition at line 130 of file ResourceManager.hpp.
Referenced by getAssetsPathPrefix(), loadFont(), loadMusic(), loadScript(), loadShaders(), loadSound(), loadTexture(), and setAssetsPathPrefix().
|
staticprivate |
Definition at line 138 of file ResourceManager.hpp.
Referenced by clearCaches(), and loadFont().
|
staticprivate |
Definition at line 136 of file ResourceManager.hpp.
Referenced by loadMusic().
|
staticprivate |
Definition at line 134 of file ResourceManager.hpp.
Referenced by clearCaches(), createMutableTexture(), and loadMutableTexture().
|
staticprivate |
Definition at line 137 of file ResourceManager.hpp.
Referenced by clearCaches(), loadScript(), and loadScriptFromSource().
|
staticprivate |
Definition at line 135 of file ResourceManager.hpp.
Referenced by clearCaches(), and loadSound().
|
staticprivate |
Definition at line 131 of file ResourceManager.hpp.
Referenced by loadTexture(), and setTexturePathPrefix().
|
staticprivate |
Definition at line 133 of file ResourceManager.hpp.
Referenced by clearCaches(), and loadTexture().