My Project
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
ParaEngine::CParaWorldAsset Class Reference

the asset manager class in ParaEngine. More...

#include <ParaWorldAsset.h>

Inheritance diagram for ParaEngine::CParaWorldAsset:
ParaEngine::IAttributeFields ParaEngine::IObject ParaEngine::CRefCounted

Public Types

typedef boost::signals2::signal< void()> DeviceEvent_Callback_t
 
- Public Types inherited from ParaEngine::IAttributeFields
typedef ParaEngine::weak_ptr< IObject, IAttributeFieldsWeakPtr_type
 
- Public Types inherited from ParaEngine::IObject
typedef ParaEngine::weak_ptr< IObjectWeakPtr_type
 

Public Member Functions

 ATTRIBUTE_DEFINE_CLASS (CParaWorldAsset)
 
virtual IAttributeFieldsGetChildAttributeObject (const std::string &sName)
 get attribute by child object. More...
 
virtual int GetChildAttributeObjectCount (int nColumnIndex=0)
 get the number of child objects (row count) in the given column. More...
 
virtual int GetChildAttributeColumnCount ()
 we support multi-dimensional child object. More...
 
virtual IAttributeFieldsGetChildAttributeObject (int nRowIndex, int nColumnIndex=0)
 
virtual int InstallFields (CAttributeClass *pClass, bool bOverride)
 this class should be implemented if one wants to add new attribute. More...
 
 ATTRIBUTE_METHOD1 (CParaWorldAsset, IsAsyncLoading_s, bool *)
 
 ATTRIBUTE_METHOD1 (CParaWorldAsset, SetAsyncLoading_s, bool)
 
 ATTRIBUTE_METHOD1 (CParaWorldAsset, IsAssetManifestEnabled_s, bool *)
 
 ATTRIBUTE_METHOD1 (CParaWorldAsset, EnableAssetManifest_s, bool)
 
 ATTRIBUTE_METHOD1 (CParaWorldAsset, IsUseLocalFileFirst_s, bool *)
 
 ATTRIBUTE_METHOD1 (CParaWorldAsset, SetUseLocalFileFirst_s, bool)
 
 ATTRIBUTE_METHOD (CParaWorldAsset, DeleteTempDiskTextures_s)
 
TextureAssetManagerGetTextureManager ()
 
CVertexBufferPoolManagerGetVertexBufferPoolManager ()
 
TextureEntityGetTexture (const string &sIdentifier)
 
TextureEntityGetDefaultTexture (int nTextureID)
 
TextureEntityLoadTexture (const string &sIdentifier, const string &sTextureFileName, TextureEntity::_SurfaceType nSurfaceType=TextureEntity::StaticTexture)
 
SpriteFontAssetManagerGetFontManager ()
 
SpriteFontEntityGetFont (const string &sIdentifier)
 
SpriteFontEntityLoadGDIFont (const string &sIdentifier, const string &pstrFont, DWORD dwSize, bool bIsBold=true)
 
DatabaseAssetManagerGetDatabaseManager ()
 
DatabaseEntityGetDatabase (const string &sIdentifier)
 
DatabaseEntityLoadDatabase (const string &sIdentifier, const string &fileName)
 
MeshEntityManagerGetMeshManager ()
 
MeshEntityGetMesh (const string &sIdentifier)
 
MeshEntityLoadMesh (const string &sIdentifier, const string &sMeshFileName)
 
ParaXEntityManagerGetParaXManager ()
 
ParaXEntityGetParaX (const string &sIdentifier)
 
ParaXEntityLoadParaX (const string &sIdentifier, const string &fileName)
 
ParaXEntityLoadParaXByID (int nAssetID)
 the asset are feched from the current model asset database. More...
 
CSequenceManagerGetSequenceManager ()
 
SequenceEntityLoadSequence (const string &sName)
 
EffectManagerGetEffectManager ()
 
CEffectFileLoadEffectFile (const string &sIdentifier, const string &sEffectFile)
 
DynamicVertexBufferEntityGetDynamicBuffer (DynamicVBAssetType nBufferType)
 
BufferPickingManagerGetBufferPickingManager ()
 
CBufferPickingGetBufferPick (const string &sIdentifier)
 
CBufferPickingLoadBufferPick (const string &sIdentifier)
 
bool RefreshAsset (const char *filename)
 refresh asset if it is already loaded. More...
 
void RenderFrameMove (float fElapsedTime)
 called before every render frame More...
 
void LoadAsset ()
 initialize all assets created so far to accelerate loading during game play. More...
 
void UnloadAsset ()
 uninitialize all assets created so far to save some memory
 
bool UnloadAssetByKeyName (const string &keyname)
 unload a given asset by key name. More...
 
void GarbageCollectAll ()
 Garbage Collect(free resources of) all unused entity. More...
 
void Cleanup ()
 
HRESULT InitDeviceObjects ()
 Desc: Initialize scene objects that has not yet been initialized. More...
 
HRESULT RestoreDeviceObjects ()
 
HRESULT InvalidateDeviceObjects ()
 
HRESULT DeleteDeviceObjects ()
 
HRESULT RendererRecreated ()
 callback of listening the event that renderer was recreated on Android/WP8 all opengl related id has already become invalid at this time, no need to release them, just recreate them all in this function.
 
bool DoAssetSearch (string &AssetFile, const char *searchDir)
 given a source asset, it will first see if the asset already exist. More...
 
void CreateAttributeModel ()
 expose attribute model for all asset manager types
 
bool IsAsyncLoading () const
 whether to enable async loading for all subsequently loaded assets, such as texture, etc. More...
 
void SetAsyncLoading (bool val)
 
bool IsAssetManifestEnabled () const
 whether to enable asset manifest files
 
void EnableAssetManifest (bool val)
 
bool IsUseLocalFileFirst () const
 if true, asset manifest's GetFile() will return null, if a local disk or zip file is found even there is an entry in the assetmanifest. More...
 
void SetUseLocalFileFirst (bool val)
 
- Public Member Functions inherited from ParaEngine::IAttributeFields
virtual int GetAttributeClassID ()
 attribute class ID should be identical, unless one knows how overriding rules work. More...
 
virtual const char * GetAttributeClassName ()
 a static string, describing the attribute class object's name
 
virtual const char * GetAttributeClassDescription ()
 a static string, describing the attribute class object
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetName_s, const char **)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, SetName_s, const char *)
 
 ATTRIBUTE_METHOD (IAttributeFields, PrintObject_s)
 
 ATTRIBUTE_METHOD (IAttributeFields, AddRef_s)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetRefCount_s, int *)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, SetTime_s, int)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetTime_s, int *)
 
 ATTRIBUTE_METHOD (IAttributeFields, Release_s)
 
virtual const std::string & GetIdentifier ()
 
virtual void SetIdentifier (const std::string &sID)
 
virtual bool IsModified ()
 whether some of the fields are modified.It is up to the implementation class to provide this functionality if necessary. More...
 
virtual void SetModified (bool bModified)
 set whether any field has been modified. More...
 
virtual bool ValidateFields ()
 validate all fields and return true if validation passed. More...
 
virtual string GetValidationMessage ()
 get the recent validation message due to the most recent call to ValidateFields()
 
virtual bool ResetField (int nFieldID)
 Reset the field to its initial or default value. More...
 
virtual bool InvokeEditor (int nFieldID, const std::string &sParameters)
 Invoke an (external) editor for a given field. More...
 
virtual bool AddChildAttributeObject (IAttributeFields *pChild, int nRowIndex=-1, int nColumnIndex=0)
 add child object. More...
 
virtual void * QueryObjectByName (const std::string &sObjectType)
 convert to object of a given type. More...
 
virtual void * QueryObject (int nObjectType)
 convert to object of a given type. More...
 
virtual int GetTime ()
 get the current local time in case it is animated in milli seconds frames. More...
 
virtual void SetTime (int nTime)
 
virtual CDynamicAttributeFieldGetDynamicField (const std::string &sName)
 Get a dynamic field with a given name. More...
 
virtual CDynamicAttributeFieldGetDynamicField (int nIndex)
 Get a dynamic field with a given index. More...
 
virtual const char * GetDynamicFieldNameByIndex (int nIndex)
 get field name by index
 
virtual int GetDynamicFieldCount ()
 how many dynamic field this object currently have. More...
 
virtual int SetDynamicField (const std::string &sName, const CVariable &value)
 set a dynamic field with a given name. More...
 
virtual int AddDynamicField (const std::string &sName, ATTRIBUTE_FIELDTYPE dwType)
 add dynamic field and return field index
 
virtual void RemoveAllDynamicFields ()
 remove all dynamic fields
 
virtual int SaveDynamicFieldsToString (std::string &output)
 save only text dynamic fields to fieldname = value text strings. More...
 
virtual int LoadDynamicFieldsFromString (const std::string &input)
 load only text dynamic fields from string More...
 
CAttributeClassGetAttributeClass ()
 get the main attribute class object. More...
 
void PrintObject ()
 print the content of this object to a text file at temp/doc/[ClassName].txt. More...
 
- Public Member Functions inherited from ParaEngine::IObject
virtual void Clone (IObject *obj) const
 Clone the object's contains to a pointer. More...
 
virtual IObjectClone () const
 Clone the object's contains and return a pointer to the newly created object. More...
 
virtual bool Equals (const IObject *obj) const
 Compare the object with another object. More...
 
virtual const ITypeGetType () const
 
virtual std::string ToString () const
 
WeakPtr_typeGetWeakReference ()
 get weak reference object. More...
 
virtual int ProcessObjectEvent (const ObjectEvent &event)
 this function is only used to backward compatibility of ParaObject:AddEvent() function. More...
 
- Public Member Functions inherited from ParaEngine::CRefCounted
void addref () const
 add reference count of the object. More...
 
bool delref () const
 decrease reference count of the object. More...
 
int GetRefCount () const
 get the reference count
 
virtual int Release ()
 
CRefCountedAddToAutoReleasePool ()
 addref and releases the ownership sometime soon automatically (usually at the end of the current frame). More...
 

Static Public Member Functions

static CParaWorldAssetGetSingleton ()
 
- Static Public Member Functions inherited from ParaEngine::IAttributeFields
static HRESULT GetAttributeClassID_s (IAttributeFields *cls, int *p1)
 
static HRESULT GetAttributeClassName_s (IAttributeFields *cls, const char **p1)
 
static bool OpenWithDefaultEditor (const char *sFilename, bool bWaitOnReturn=false)
 Open a given file with the default registered editor in the game engine. More...
 

Public Attributes

DeviceEvent_Callback_t OnInitDeviceObjects
 
DeviceEvent_Callback_t OnRestoreDeviceObjects
 
DeviceEvent_Callback_t OnInvalidateDeviceObjects
 
DeviceEvent_Callback_t OnDeleteDeviceObjects
 
DeviceEvent_Callback_t OnRendererRecreated
 
DeviceEvent_Callback_t OnCleanup
 

Protected Attributes

bool m_bUseAssetSearch
 this will be set to true when the manager class is created if there is a fill called temp/assetmap.txt if this is true, all mesh and paraX mesh files will be checked for existence if the file does not exist, it will search if there is a mapping in the m_AssetMap, if there is no valid, it will search the disk using the file name and extensions and automatically generate a new mapping item, m_AssetMap will be read and written to disk file temp/assetmap.txt at loading and exiting time
 
map< string, string > m_AssetMap
 this is only used when m_bUseAssetSearch is true. More...
 
- Protected Attributes inherited from ParaEngine::IObject
WeakPtr_type m_weak_reference
 
- Protected Attributes inherited from ParaEngine::CRefCounted
int m_refcount
 

Additional Inherited Members

- Protected Member Functions inherited from ParaEngine::IAttributeFields
virtual CAttributeClassCreateAttributeClass ()
 initialize fields
 
virtual CDynamicAttributesSetGetDynamicAttributes (bool bCreateIfNotExist=false)
 

Detailed Description

the asset manager class in ParaEngine.

it contains sub managers for mesh, animated mesh, texture, font, sprite, database, buffer, effect, flash texture, occlusion query, archives, etc. it also provides the get and load functions for all above asset types. All assets are reference counted and can be garbage collected on demand. All device related asset are automatically restored when device changes.

Note
: each asset uses its asset file path as the internal key; it may also contain a shotcut key; however, in most cases, the shotcut key is empty. shortcut key is used to get certain asset with a shorter and user friendly name.

Member Function Documentation

§ DoAssetSearch()

bool CParaWorldAsset::DoAssetSearch ( string &  AssetFile,
const char *  searchDir 
)

given a source asset, it will first see if the asset already exist.

if the file does not exist, it will search if there is a mapping in the m_AssetMap, if there is no valid, it will search the disk using the file name and extensions; if the file name is found somewhere else, it will automatically generate a new mapping item in m_AssetMap, m_AssetMap will be read and written to disk file assetmap.txt at loading and exiting time

Note
: Normally this function is only called when m_bUseAssetSearch is true. Both the asset load and get function in the asset manager classes need to call this function.
Parameters
AssetFile[in|out] asset file to search for, the result file will be assigned to it as well.
searchDirwhere to search the file if it is found.
Returns
: return true if found.

§ GarbageCollectAll()

void CParaWorldAsset::GarbageCollectAll ( )

Garbage Collect(free resources of) all unused entity.

§ GetChildAttributeColumnCount()

int ParaEngine::CParaWorldAsset::GetChildAttributeColumnCount ( )
virtual

we support multi-dimensional child object.

by default objects have only one column.

Reimplemented from ParaEngine::IAttributeFields.

§ GetChildAttributeObject()

IAttributeFields * ParaEngine::CParaWorldAsset::GetChildAttributeObject ( const std::string &  sName)
virtual

get attribute by child object.

used to iterate across the attribute field hierarchy.

Reimplemented from ParaEngine::IAttributeFields.

§ GetChildAttributeObjectCount()

int ParaEngine::CParaWorldAsset::GetChildAttributeObjectCount ( int  nColumnIndex = 0)
virtual

get the number of child objects (row count) in the given column.

please note different columns can have different row count.

Reimplemented from ParaEngine::IAttributeFields.

§ InitDeviceObjects()

HRESULT CParaWorldAsset::InitDeviceObjects ( )

Desc: Initialize scene objects that has not yet been initialized.

Asset must be the first to be initialized. Otherwise, the global device object will not be valid

§ InstallFields()

int ParaEngine::CParaWorldAsset::InstallFields ( CAttributeClass pClass,
bool  bOverride 
)
virtual

this class should be implemented if one wants to add new attribute.

This function is always called internally.

Reimplemented from ParaEngine::IAttributeFields.

§ IsAsyncLoading()

bool ParaEngine::CParaWorldAsset::IsAsyncLoading ( ) const

whether to enable async loading for all subsequently loaded assets, such as texture, etc.

Enabled by default.

§ IsUseLocalFileFirst()

bool ParaEngine::CParaWorldAsset::IsUseLocalFileFirst ( ) const

if true, asset manifest's GetFile() will return null, if a local disk or zip file is found even there is an entry in the assetmanifest.

§ LoadAsset()

void CParaWorldAsset::LoadAsset ( )

initialize all assets created so far to accelerate loading during game play.

§ LoadParaXByID()

ParaXEntity * CParaWorldAsset::LoadParaXByID ( int  nAssetID)

the asset are feched from the current model asset database.

§ LoadTexture()

TextureEntity * CParaWorldAsset::LoadTexture ( const string &  sIdentifier,
const string &  sTextureFileName,
TextureEntity::_SurfaceType  nSurfaceType = TextureEntity::StaticTexture 
)
Parameters
sIdentifierusually same as sTextureFileName
sTextureFileNameif the file name ends with _a{0-9}{0-9}{0-9}.xxx, it will be regarded as a texture sequence. and the nSurfaceType will be ignored and forced to TextureSequence
nSurfaceTypedefault to TextureEntity::StaticTexture
Returns

§ RefreshAsset()

bool CParaWorldAsset::RefreshAsset ( const char *  filename)

refresh asset if it is already loaded.

it will search for all refreshable asset type, such as textures and mesh, etc. if found, it will call the Refresh() method on the asset entity and return true, or return false.

§ RenderFrameMove()

void CParaWorldAsset::RenderFrameMove ( float  fElapsedTime)

called before every render frame

Parameters
fElapsedTimein seconds

§ UnloadAssetByKeyName()

bool CParaWorldAsset::UnloadAssetByKeyName ( const string &  keyname)

unload a given asset by key name.

This function is rarely used, except for some specify situation, such as Loading a new replacement file that overwrite existing asset entity. currently only texture and model files are supported.

Parameters
keynamethe asset key, we will automatically determine the asset type by its extension (assuming key is filename)
Returns
: true if we have found one and unloaded the asset. Please note, we will only unload if the asset is not being downloaded (asynchronously).

Member Data Documentation

§ m_AssetMap

map<string, string> ParaEngine::CParaWorldAsset::m_AssetMap
protected

this is only used when m_bUseAssetSearch is true.

m_AssetMap will be read and written to disk file temp/assetmap.txt at loading and exiting time file format: on each line, it is string=string, where the second string may be none.


The documentation for this class was generated from the following files: