assetBase.h

Engine/source/assets/assetBase.h

More...

Classes:

Detailed Description

Public Variables

StringTableEntry assetAutoUnloadField 
StringTableEntry assetCategoryField 
StringTableEntry assetDescriptionField 
StringTableEntry assetInternalField 
StringTableEntry assetNameField 
StringTableEntry assetPrivateField 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#ifndef _ASSET_BASE_H_
 24#define _ASSET_BASE_H_
 25
 26#ifndef _ASSET_DEFINITION_H_
 27#include "assetDefinition.h"
 28#endif
 29
 30#ifndef _STRINGUNIT_H_
 31#include "string/stringUnit.h"
 32#endif
 33
 34#ifndef _ASSET_FIELD_TYPES_H_
 35#include "assets/assetFieldTypes.h"
 36#endif
 37
 38//-----------------------------------------------------------------------------
 39
 40class AssetManager;
 41
 42//-----------------------------------------------------------------------------
 43
 44extern StringTableEntry assetNameField;
 45extern StringTableEntry assetDescriptionField;
 46extern StringTableEntry assetCategoryField;
 47extern StringTableEntry assetInternalField;
 48extern StringTableEntry assetPrivateField;
 49extern StringTableEntry assetAutoUnloadField;
 50
 51//#define ASSET_BASE_ASSETNAME_FIELD         "AssetName"
 52//#define ASSET_BASE_ASSETDESCRIPTION_FIELD  "AssetDescription"
 53//#define ASSET_BASE_ASSETCATEGORY_FIELD     "AssetCategory"
 54//#define ASSET_BASE_ASSETINTERNAL_FIELD     "AssetInternal"
 55//#define ASSET_BASE_ASSETPRIVATE_FIELD      "AssetPrivate"
 56//#define ASSET_BASE_AUTOUNLOAD_FIELD        "AssetAutoUnload"
 57
 58//-----------------------------------------------------------------------------
 59
 60class AssetBase : public SimObject
 61{
 62   friend class AssetManager;
 63
 64   typedef SimObject Parent;
 65
 66   AssetManager*           mpOwningAssetManager;
 67   bool                    mAssetInitialized;
 68   AssetDefinition*        mpAssetDefinition;
 69   U32                     mAcquireReferenceCount;
 70
 71public:
 72   AssetBase();
 73   virtual ~AssetBase();
 74
 75   /// Engine.
 76   static void initPersistFields();
 77   virtual void copyTo(SimObject* object);
 78
 79   /// Asset configuration.
 80   inline void             setAssetName(const char* pAssetName)              { if (mpOwningAssetManager == NULL) mpAssetDefinition->mAssetName = StringTable->insert(pAssetName); }
 81   inline StringTableEntry getAssetName(void) const                          { return mpAssetDefinition->mAssetName; }
 82   void                    setAssetDescription(const char* pAssetDescription);
 83   inline StringTableEntry getAssetDescription(void) const                   { return mpAssetDefinition->mAssetDescription; }
 84   void                    setAssetCategory(const char* pAssetCategory);
 85   inline StringTableEntry getAssetCategory(void) const                      { return mpAssetDefinition->mAssetCategory; }
 86   void                    setAssetAutoUnload(const bool autoUnload);
 87   inline bool             getAssetAutoUnload(void) const                    { return mpAssetDefinition->mAssetAutoUnload; }
 88   void                    setAssetInternal(const bool assetInternal);
 89   inline bool             getAssetInternal(void) const                      { return mpAssetDefinition->mAssetInternal; }
 90   inline bool             getAssetPrivate(void) const                       { return mpAssetDefinition->mAssetPrivate; }
 91   inline StringTableEntry getAssetType(void) const                          { return mpAssetDefinition->mAssetType; }
 92
 93   inline S32              getAcquiredReferenceCount(void) const             { return mAcquireReferenceCount; }
 94   inline bool             getOwned(void) const                              { return mpOwningAssetManager != NULL; }
 95
 96   // Asset Id is only available once registered with the asset manager.
 97   inline StringTableEntry getAssetId(void) const                            { return mpAssetDefinition->mAssetId; }
 98
 99   /// Expanding/Collapsing asset paths is only available once registered with the asset manager.
100   StringTableEntry        expandAssetFilePath(const char* pAssetFilePath) const;
101   StringTableEntry        collapseAssetFilePath(const char* pAssetFilePath) const;
102
103   virtual bool            isAssetValid(void) const                          { return true; }
104
105   void                    refreshAsset(void);
106
107   /// Declare Console Object.
108   DECLARE_CONOBJECT(AssetBase);
109
110protected:
111   virtual void            initializeAsset(void) {}
112   virtual void            onAssetRefresh(void) {}
113
114protected:
115   static bool             setAssetName(void *obj, const char *array, const char *data)           { static_cast<AssetBase*>(obj)->setAssetName(data); return false; }
116   static const char*      getAssetName(void* obj, const char* data)           { return static_cast<AssetBase*>(obj)->getAssetName(); }
117   static bool             writeAssetName(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetName() != StringTable->EmptyString(); }
118
119   static bool             setAssetDescription(void *obj, const char *array, const char *data)    { static_cast<AssetBase*>(obj)->setAssetDescription(data); return false; }
120   static const char*      getAssetDescription(void* obj, const char* data)    { return static_cast<AssetBase*>(obj)->getAssetDescription(); }
121   static bool             writeAssetDescription(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetDescription() != StringTable->EmptyString(); }
122
123   static bool             setAssetCategory(void *obj, const char *array, const char *data)       { static_cast<AssetBase*>(obj)->setAssetCategory(data); return false; }
124   static const char*      getAssetCategory(void* obj, const char* data)       { return static_cast<AssetBase*>(obj)->getAssetCategory(); }
125   static bool             writeAssetCategory(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetCategory() != StringTable->EmptyString(); }
126
127   static bool             setAssetAutoUnload(void *obj, const char *array, const char *data)     { static_cast<AssetBase*>(obj)->setAssetAutoUnload(dAtob(data)); return false; }
128   static const char*      getAssetAutoUnload(void* obj, const char* data)     { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetAutoUnload()); }
129   static bool             writeAssetAutoUnload(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetAutoUnload() == false; }
130
131   static bool             setAssetInternal(void *obj, const char *array, const char *data)       { static_cast<AssetBase*>(obj)->setAssetInternal(dAtob(data)); return false; }
132   static const char*      getAssetInternal(void* obj, const char* data)       { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetInternal()); }
133   static bool             writeAssetInternal(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetInternal() == true; }
134
135   static const char*      getAssetPrivate(void* obj, const char* data)        { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetPrivate()); }
136
137private:
138   void                    acquireAssetReference(void);
139   bool                    releaseAssetReference(void);
140
141   /// Set asset manager ownership.
142   void                    setOwned(AssetManager* pAssetManager, AssetDefinition* pAssetDefinition);
143};
144
145#endif // _ASSET_BASE_H_
146
147