Sirikata
|
ResourceLoader manages the loading of resources into Ogre. More...
#include <ResourceLoader.hpp>
Classes | |
struct | ResourceData |
Public Types | |
typedef std::tr1::function< void()> | LoadedCallback |
Public Member Functions | |
ResourceLoader (Context *ctx, const Duration &per_frame_time) | |
Create a ResourceLoader. | |
~ResourceLoader () | |
void | loadMaterial (const String &name, Mesh::MeshdataPtr mesh, const Mesh::MaterialEffectInfo &mat, const Transfer::URI &uri, TextureBindingsMapPtr textureFingerprints, LoadedCallback cb) |
void | loadBillboardMaterial (const String &name, const String &texuri, const Transfer::URI &uri, TextureBindingsMapPtr textureFingerprints, LoadedCallback cb) |
void | loadSkeleton (const String &name, Mesh::MeshdataPtr mesh, const std::set< String > &animationList, LoadedCallback cb) |
void | loadMesh (const String &name, Mesh::MeshdataPtr mesh, const String &skeletonName, TextureBindingsMapPtr textureFingerprints, LoadedCallback cb) |
void | loadTexture (const String &name, LoadedCallback cb) |
void | unloadResource (const String &name) |
void | tick () |
Private Types | |
enum | ResourceType { ResourceTypeMaterial, ResourceTypeTexture, ResourceTypeSkeleton, ResourceTypeMesh } |
typedef std::tr1::function< void()> | Task |
typedef std::map< String, ResourceData > | RefCountMap |
Private Member Functions | |
void | loadMaterialWork (const String &name, Mesh::MeshdataPtr mesh, const Mesh::MaterialEffectInfo &mat, const Transfer::URI &uri, TextureBindingsMapPtr textureFingerprints, LoadedCallback cb) |
void | loadBillboardMaterialWork (const String &name, const String &texuri, const Transfer::URI &uri, TextureBindingsMapPtr textureFingerprints, LoadedCallback cb) |
void | loadSkeletonWork (const String &name, Mesh::MeshdataPtr mesh, const std::set< String > &animationList, LoadedCallback cb) |
void | loadMeshWork (const String &name, Mesh::MeshdataPtr mesh, const String &skeletonName, TextureBindingsMapPtr textureFingerprints, LoadedCallback cb) |
void | loadTextureWork (const String &name, LoadedCallback cb) |
void | unloadResourceWork (const String &name, ResourceType type) |
void | incRefCount (const String &name, ResourceType type) |
void | decRefCount (const String &name) |
void | resetRenderQueues () |
Private Attributes | |
const Duration | mPerFrameTime |
TimeProfiler::Stage * | mProfilerStage |
std::queue< Task > | mTasks |
RefCountMap | mRefCounts |
bool | mNeedRenderQueuesReset |
ResourceLoader manages the loading of resources into Ogre.
It works asynchronously and handles scheduling loading of resources so they don't consume too much time, thereby attempting to maintain good frame rates. Since it coordinates all loading of resources for a single Ogre instance, it also makes sure each resources is loaded only once by deduplicating requests (some of which can't be known to be duplicates until we reach the point of loading, e.g. because two meshes use the same texture).
ResourceLoader also keeps track of usage so it can *unload* resources when they are no longer required. This means that even if you know Ogre has loaded a resource, you should request it be loaded and unloaded at the appropriate times.
The ResourceLoader is created and driven by OgreRenderer. You shouldn't instantiate this class yourself.
typedef std::tr1::function<void()> Sirikata::Graphics::ResourceLoader::LoadedCallback |
typedef std::map<String, ResourceData> Sirikata::Graphics::ResourceLoader::RefCountMap [private] |
typedef std::tr1::function<void()> Sirikata::Graphics::ResourceLoader::Task [private] |
enum Sirikata::Graphics::ResourceLoader::ResourceType [private] |
Sirikata::Graphics::ResourceLoader::ResourceLoader | ( | Context * | ctx, |
const Duration & | per_frame_time | ||
) |
Create a ResourceLoader.
per_frame_time | maximum amount of time to spend loading resources. This isn't a guarantee, rather a best effort. Single resource loading tasks that exceed this time can't be avoided. |
References Sirikata::TimeProfiler::addStage(), mProfilerStage, and Sirikata::Context::profiler.
Sirikata::Graphics::ResourceLoader::~ResourceLoader | ( | ) |
References mProfilerStage.
void Sirikata::Graphics::ResourceLoader::decRefCount | ( | const String & | name | ) | [private] |
References Sirikata::Logging::detailed, mRefCounts, mTasks, OGRERL_LOG, and unloadResourceWork().
Referenced by unloadResource().
void Sirikata::Graphics::ResourceLoader::incRefCount | ( | const String & | name, |
ResourceType | type | ||
) | [private] |
References mRefCounts.
Referenced by loadBillboardMaterial(), loadMaterial(), loadMesh(), loadSkeleton(), and loadTexture().
void Sirikata::Graphics::ResourceLoader::loadBillboardMaterial | ( | const String & | name, |
const String & | texuri, | ||
const Transfer::URI & | uri, | ||
TextureBindingsMapPtr | textureFingerprints, | ||
LoadedCallback | cb | ||
) |
void Sirikata::Graphics::ResourceLoader::loadBillboardMaterialWork | ( | const String & | name, |
const String & | texuri, | ||
const Transfer::URI & | uri, | ||
TextureBindingsMapPtr | textureFingerprints, | ||
LoadedCallback | cb | ||
) | [private] |
References Sirikata::Mesh::MaterialEffectInfo::Texture::affecting, Sirikata::Mesh::MaterialEffectInfo::Texture::AMBIENT, Sirikata::Mesh::MaterialEffectInfo::Texture::color, Sirikata::Mesh::MaterialEffectInfo::Texture::magFilter, Sirikata::Mesh::MaterialEffectInfo::Texture::maxMipLevel, Sirikata::Mesh::MaterialEffectInfo::Texture::minFilter, Sirikata::Mesh::MaterialEffectInfo::Texture::mipBias, Sirikata::Mesh::MaterialEffectInfo::reflectivity, Sirikata::Mesh::MaterialEffectInfo::Texture::SAMPLER_FILTER_LINEAR_MIPMAP_LINEAR, Sirikata::Mesh::MaterialEffectInfo::Texture::SAMPLER_TYPE_2D, Sirikata::Mesh::MaterialEffectInfo::Texture::samplerType, Sirikata::Mesh::MaterialEffectInfo::shininess, Sirikata::Mesh::MaterialEffectInfo::Texture::texCoord, Sirikata::Mesh::MaterialEffectInfo::textures, Sirikata::Mesh::MaterialEffectInfo::Texture::uri, Sirikata::Mesh::MaterialEffectInfo::Texture::WRAP_MODE_NONE, Sirikata::Mesh::MaterialEffectInfo::Texture::wrapS, Sirikata::Mesh::MaterialEffectInfo::Texture::wrapT, and Sirikata::Mesh::MaterialEffectInfo::Texture::wrapU.
Referenced by loadBillboardMaterial().
void Sirikata::Graphics::ResourceLoader::loadMaterial | ( | const String & | name, |
Mesh::MeshdataPtr | mesh, | ||
const Mesh::MaterialEffectInfo & | mat, | ||
const Transfer::URI & | uri, | ||
TextureBindingsMapPtr | textureFingerprints, | ||
LoadedCallback | cb | ||
) |
References incRefCount(), loadMaterialWork(), mTasks, and ResourceTypeMaterial.
Referenced by Sirikata::Graphics::PriorityDownloadPlanner::loadMeshdata().
void Sirikata::Graphics::ResourceLoader::loadMaterialWork | ( | const String & | name, |
Mesh::MeshdataPtr | mesh, | ||
const Mesh::MaterialEffectInfo & | mat, | ||
const Transfer::URI & | uri, | ||
TextureBindingsMapPtr | textureFingerprints, | ||
LoadedCallback | cb | ||
) | [private] |
Referenced by loadMaterial().
void Sirikata::Graphics::ResourceLoader::loadMesh | ( | const String & | name, |
Mesh::MeshdataPtr | mesh, | ||
const String & | skeletonName, | ||
TextureBindingsMapPtr | textureFingerprints, | ||
LoadedCallback | cb | ||
) |
References incRefCount(), loadMeshWork(), mTasks, and ResourceTypeMesh.
Referenced by Sirikata::Graphics::PriorityDownloadPlanner::loadMeshdata().
void Sirikata::Graphics::ResourceLoader::loadMeshWork | ( | const String & | name, |
Mesh::MeshdataPtr | mesh, | ||
const String & | skeletonName, | ||
TextureBindingsMapPtr | textureFingerprints, | ||
LoadedCallback | cb | ||
) | [private] |
FIXME: set bounds, bounding radius here
Referenced by loadMesh().
void Sirikata::Graphics::ResourceLoader::loadSkeleton | ( | const String & | name, |
Mesh::MeshdataPtr | mesh, | ||
const std::set< String > & | animationList, | ||
LoadedCallback | cb | ||
) |
References incRefCount(), loadSkeletonWork(), mTasks, and ResourceTypeSkeleton.
Referenced by Sirikata::Graphics::PriorityDownloadPlanner::loadMeshdata().
void Sirikata::Graphics::ResourceLoader::loadSkeletonWork | ( | const String & | name, |
Mesh::MeshdataPtr | mesh, | ||
const std::set< String > & | animationList, | ||
LoadedCallback | cb | ||
) | [private] |
Referenced by loadSkeleton().
void Sirikata::Graphics::ResourceLoader::loadTexture | ( | const String & | name, |
LoadedCallback | cb | ||
) |
References incRefCount(), loadTextureWork(), mTasks, and ResourceTypeTexture.
Referenced by Sirikata::Graphics::Skybox::imageDownloadFinished(), and Sirikata::Graphics::PriorityDownloadPlanner::loadDependentTextures().
void Sirikata::Graphics::ResourceLoader::loadTextureWork | ( | const String & | name, |
LoadedCallback | cb | ||
) | [private] |
Referenced by loadTexture().
void Sirikata::Graphics::ResourceLoader::resetRenderQueues | ( | ) | [private] |
References mNeedRenderQueuesReset.
Referenced by tick().
void Sirikata::Graphics::ResourceLoader::tick | ( | ) |
void Sirikata::Graphics::ResourceLoader::unloadResource | ( | const String & | name | ) |
References decRefCount().
Referenced by Sirikata::Graphics::PriorityDownloadPlanner::checkRemoveAsset(), and Sirikata::Graphics::Skybox::unload().
void Sirikata::Graphics::ResourceLoader::unloadResourceWork | ( | const String & | name, |
ResourceType | type | ||
) | [private] |
References mNeedRenderQueuesReset, ResourceTypeMaterial, ResourceTypeMesh, ResourceTypeSkeleton, and ResourceTypeTexture.
Referenced by decRefCount().
bool Sirikata::Graphics::ResourceLoader::mNeedRenderQueuesReset [private] |
Referenced by resetRenderQueues(), tick(), and unloadResourceWork().
const Duration Sirikata::Graphics::ResourceLoader::mPerFrameTime [private] |
Referenced by tick().
Referenced by ResourceLoader(), tick(), and ~ResourceLoader().
Referenced by decRefCount(), and incRefCount().
std::queue<Task> Sirikata::Graphics::ResourceLoader::mTasks [private] |
Referenced by decRefCount(), loadBillboardMaterial(), loadMaterial(), loadMesh(), loadSkeleton(), loadTexture(), and tick().