The Nebula Device 3: Resources::StreamResourceLoader Class Reference

The Nebula Device 3

Resources::StreamResourceLoader Class Reference

#include <streamresourceloader.h>

Inheritance diagram for Resources::StreamResourceLoader:

Resources::ResourceLoader Core::RefCounted CoreAnimation::StreamAnimationLoader Direct3D9::D3D9StreamShaderLoader Direct3D9::D3D9StreamTextureLoader Resources::D3D9TextureStreamer Win360::D3D9StreamMeshLoader CoreGraphics::StreamShaderLoader CoreGraphics::StreamTextureLoader Resources::TextureStreamer CoreGraphics::StreamMeshLoader

Detailed Description

Base class for resource loaders which load their resource from an IO::Stream. Handles the details of synchronous vs. asynchronous resource loading. Subclasses only need to override the SetupResourceFromStream() virtual method.

(C) 2008 Radon Labs GmbH

Public Member Functions

 StreamResourceLoader ()
 constructor
virtual ~StreamResourceLoader ()
 destructor
virtual bool CanLoadAsync () const
 override in subclass: return true if asynchronous loading is supported (default is true)
virtual bool OnLoadRequested ()
 called by resource when a load is requested
virtual void OnLoadCancelled ()
 called by resource to cancel a pending load
virtual bool OnPending ()
 call frequently while after OnLoadRequested() to put Resource into loaded state
virtual void OnAttachToResource (const Ptr< Resource > &res)
 called when the resource loader is attached to its resource
virtual void OnRemoveFromResource ()
 called when the resource loader is removed from its resource
bool IsAttachedToResource () const
 return true if attached to resource
const Ptr< Resource > & GetResource () const
 get pointer to resource
Resource::State GetState () const
 return current state
virtual void Reset ()
 resets loader-stats e.g. state
int GetRefCount () const
 get the current refcount
void AddRef ()
 increment refcount by one
void Release ()
 decrement refcount and destroy object if refcount is zero
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
const Util::StringGetClassName () const
 get the class name
Util::FourCC GetClassFourCC () const
 get the class FourCC code

Static Public Member Functions

static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA3_DEBUG builds only!)

Protected Member Functions

virtual bool SetupResourceFromStream (const Ptr< IO::Stream > &stream)
 override in subclass: setup the resource from the provided stream
void SetState (Resource::State s)
 set current state

Member Function Documentation

bool Resources::StreamResourceLoader::CanLoadAsync (  )  const [virtual]

override in subclass: return true if asynchronous loading is supported (default is true)

Indicate whether this resource loader supports asynchronous loading. The default is true. Override this method in a subclass and return false otherwise.

Reimplemented from Resources::ResourceLoader.

Reimplemented in Direct3D9::D3D9StreamShaderLoader.

bool Resources::StreamResourceLoader::OnLoadRequested (  )  [virtual]

called by resource when a load is requested

Handle the generic load request. In the asynchronous case, this method will fire a ReadStream message and go into pending state. The client will then call OnPending() periodically which checks whether the ReadStream message has been handled and continue accordingly. In the synchronous state the method will create an IO::Stream object and call the SetupResourceFromStream() method directly.

Reimplemented from Resources::ResourceLoader.

Reimplemented in Resources::D3D9TextureStreamer.

void Resources::StreamResourceLoader::OnLoadCancelled (  )  [virtual]

called by resource to cancel a pending load

This method is called when the currently pending asynchronous load request should be cancelled.

Reimplemented from Resources::ResourceLoader.

bool Resources::StreamResourceLoader::OnPending (  )  [virtual]

call frequently while after OnLoadRequested() to put Resource into loaded state

This method is called periodically by the client when the resource is in pending state. The pending ReadStream message will be checked, and if it has been handled successfully the SetupResourceFromStream() method will be called and the Resource will go into Loaded state. If anything goes wrong, the resource will go into Failed state.

Reimplemented from Resources::ResourceLoader.

bool Resources::StreamResourceLoader::SetupResourceFromStream ( const Ptr< IO::Stream > &  stream  )  [protected, virtual]

override in subclass: setup the resource from the provided stream

The SetupResourceFromStream should be overwritten by the subclass and is called when the stream containing the resource data is available (right from OnLoadRequested() in the synchronous state, or at some later time from OnPending() in the asynchronous state. Subclasses should setup the resource object of this loader from the stream content and return true on success, or false on failure.

Reimplemented in CoreAnimation::StreamAnimationLoader, and Resources::D3D9TextureStreamer.

int Core::RefCounted::GetRefCount (  )  const [inline, inherited]

get the current refcount

Return the current refcount of the object.

void Core::RefCounted::AddRef (  )  [inline, inherited]

increment refcount by one

Increment the refcount of the object.

void Core::RefCounted::Release (  )  [inline, inherited]

decrement refcount and destroy object if refcount is zero

Decrement the refcount and destroy object if refcount is zero.

const Util::String & Core::RefCounted::GetClassName (  )  const [inline, inherited]

get the class name

Get the class name of the object.

Util::FourCC Core::RefCounted::GetClassFourCC (  )  const [inline, inherited]

get the class FourCC code

Get the class FourCC of the object.

void Core::RefCounted::DumpRefCountingLeaks (  )  [static, inherited]

dump refcounting leaks, call at end of application (NEBULA3_DEBUG builds only!)

This method should be called as the very last before an application exits.