assetBase.h
Engine/source/assets/assetBase.h
Classes:
class
Public Variables
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//----------------------------------------------------------------------------- 59class AssetBase : public SimObject 60{ 61 friend class AssetManager; 62 63 typedef SimObject Parent; 64 65protected: 66 AssetManager* mpOwningAssetManager; 67 bool mAssetInitialized; 68 AssetDefinition* mpAssetDefinition; 69 U32 mAcquireReferenceCount; 70 71public: 72 enum AssetErrCode 73 { 74 Failed, 75 Ok, 76 NotLoaded, 77 BadFileReference, 78 InvalidFormat, 79 DependencyNotFound, 80 FileTooLarge, 81 UsingFallback, 82 Extended 83 }; 84 85 static const String mErrCodeStrings[AssetErrCode::Extended + 1]; 86 static String getAssetErrstrn(U32 errCode) 87 { 88 if (errCode > AssetErrCode::Extended) return "undefined error"; 89 return mErrCodeStrings[errCode]; 90 }; 91 92 AssetBase(); 93 virtual ~AssetBase(); 94 95 /// Engine. 96 static void initPersistFields(); 97 virtual void copyTo(SimObject* object); 98 99 /// Asset configuration. 100 inline void setAssetName(const char* pAssetName) { if (mpOwningAssetManager == NULL) mpAssetDefinition->mAssetName = StringTable->insert(pAssetName); } 101 inline StringTableEntry getAssetName(void) const { return mpAssetDefinition->mAssetName; } 102 void setAssetDescription(const char* pAssetDescription); 103 inline StringTableEntry getAssetDescription(void) const { return mpAssetDefinition->mAssetDescription; } 104 void setAssetCategory(const char* pAssetCategory); 105 inline StringTableEntry getAssetCategory(void) const { return mpAssetDefinition->mAssetCategory; } 106 void setAssetAutoUnload(const bool autoUnload); 107 inline bool getAssetAutoUnload(void) const { return mpAssetDefinition->mAssetAutoUnload; } 108 void setAssetInternal(const bool assetInternal); 109 inline bool getAssetInternal(void) const { return mpAssetDefinition->mAssetInternal; } 110 inline bool getAssetPrivate(void) const { return mpAssetDefinition->mAssetPrivate; } 111 inline StringTableEntry getAssetType(void) const { return mpAssetDefinition->mAssetType; } 112 113 inline S32 getAcquiredReferenceCount(void) const { return mAcquireReferenceCount; } 114 inline bool getOwned(void) const { return mpOwningAssetManager != NULL; } 115 116 // Asset Id is only available once registered with the asset manager. 117 inline StringTableEntry getAssetId(void) const { return mpAssetDefinition->mAssetId; } 118 119 /// Expanding/Collapsing asset paths is only available once registered with the asset manager. 120 StringTableEntry expandAssetFilePath(const char* pAssetFilePath) const; 121 StringTableEntry collapseAssetFilePath(const char* pAssetFilePath) const; 122 123 virtual bool isAssetValid(void) const { return true; } 124 125 void refreshAsset(void); 126 127 S32 getAssetDependencyFieldCount(const char* pFieldName); 128 void clearAssetDependencyFields(const char* pFieldName); 129 void addAssetDependencyField(const char* pFieldName, const char* pAssetId); 130 131 bool saveAsset(); 132 133 /// Declare Console Object. 134 DECLARE_CONOBJECT(AssetBase); 135 136protected: 137 virtual void initializeAsset(void) {} 138 virtual void onAssetRefresh(void) {} 139 140protected: 141 static bool setAssetName(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetName(data); return false; } 142 static const char* getAssetName(void* obj, const char* data) { return static_cast<AssetBase*>(obj)->getAssetName(); } 143 static bool writeAssetName(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetName() != StringTable->EmptyString(); } 144 145 static bool setAssetDescription(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetDescription(data); return false; } 146 static const char* getAssetDescription(void* obj, const char* data) { return static_cast<AssetBase*>(obj)->getAssetDescription(); } 147 static bool writeAssetDescription(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetDescription() != StringTable->EmptyString(); } 148 149 static bool setAssetCategory(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetCategory(data); return false; } 150 static const char* getAssetCategory(void* obj, const char* data) { return static_cast<AssetBase*>(obj)->getAssetCategory(); } 151 static bool writeAssetCategory(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetCategory() != StringTable->EmptyString(); } 152 153 static bool setAssetAutoUnload(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetAutoUnload(dAtob(data)); return false; } 154 static const char* getAssetAutoUnload(void* obj, const char* data) { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetAutoUnload()); } 155 static bool writeAssetAutoUnload(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetAutoUnload() == false; } 156 157 static bool setAssetInternal(void *obj, const char *array, const char *data) { static_cast<AssetBase*>(obj)->setAssetInternal(dAtob(data)); return false; } 158 static const char* getAssetInternal(void* obj, const char* data) { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetInternal()); } 159 static bool writeAssetInternal(void* obj, StringTableEntry pFieldName) { return static_cast<AssetBase*>(obj)->getAssetInternal() == true; } 160 161 static const char* getAssetPrivate(void* obj, const char* data) { return Con::getBoolArg(static_cast<AssetBase*>(obj)->getAssetPrivate()); } 162 163private: 164 void acquireAssetReference(void); 165 bool releaseAssetReference(void); 166 167 /// Set asset manager ownership. 168 void setOwned(AssetManager* pAssetManager, AssetDefinition* pAssetDefinition); 169}; 170 171#endif // _ASSET_BASE_H_ 172 173