00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "AssetGroup.h"
00018 #include "GameManager.h"
00019
00020
00021
00022
00023 u32 AssetGroup::mIDCount = 0;
00024
00025
00026 AssetGroup::AssetGroup(const std::string &name, const std::string &dirName)
00027 : mName(name)
00028 {
00029 mID = mIDCount++;
00030 mBaseDir = (GameManager::Instance()->getDevice()->getFileSystem()
00031 ->getAbsolutePath(dirName.c_str())).c_str();
00032
00033 init();
00034 }
00035
00036
00037 AssetGroup::~AssetGroup()
00038 {
00039 clear();
00040 }
00041
00042
00043 void AssetGroup::init()
00044 {
00045 GameManager::Instance()->getAssetManager()->getAssetProcessors(this, mAssetProcessors);
00046 loadAssets();
00047 }
00048
00049
00050 void AssetGroup::clear()
00051 {
00052 removeAssets();
00053 }
00054
00055
00056 u32 AssetGroup::getID() const
00057 {
00058 return mID;
00059 }
00060
00061
00062 const std::string& AssetGroup::getName() const
00063 {
00064 return mName;
00065 }
00066
00067
00068 const std::string& AssetGroup::getBaseDir() const
00069 {
00070 return mBaseDir;
00071 }
00072
00073
00074 AssetProcessor* AssetGroup::getAssetProcessor(const std::string &baseName)
00075 {
00076
00077 vector<AssetProcessor*>::iterator it;
00078
00079 for(it = mAssetProcessors.begin(); it != mAssetProcessors.end(); it++)
00080 {
00081 AssetProcessor *processor = *it;
00082
00083 if(processor->getBaseName() == baseName)
00084 return processor;
00085 }
00086
00087
00088 return NULL;
00089 }
00090
00091
00092 void AssetGroup::loadAssets()
00093 {
00094 vector<AssetProcessor*>::iterator it;
00095
00096 for(it = mAssetProcessors.begin(); it != mAssetProcessors.end(); it++)
00097 (*it)->loadAssets();
00098 }
00099
00100
00101 bool AssetGroup::reloadAsset(const std::string &name)
00102 {
00103
00104 std::string assetType;
00105 size_t pos;
00106
00107 pos = name.find("/");
00108 if(pos == std::string::npos)
00109 {
00110 pos = name.find("\"");
00111 if(pos == std::string::npos)
00112 {
00113 return false;
00114 }
00115 }
00116
00117 assetType = name.substr(0, pos);
00118
00119
00120 std::string assetName = name.substr(pos+1, name.size()-pos);
00121
00122
00123 vector<AssetProcessor*>::iterator it;
00124
00125 for(it = mAssetProcessors.begin(); it != mAssetProcessors.end(); it++)
00126 {
00127 AssetProcessor *processor = *it;
00128
00129 if(processor->getBaseName() == assetType)
00130 {
00131 processor->reloadAsset(assetName);
00132 break;
00133 }
00134 }
00135
00136
00137 return false;
00138 }
00139
00140
00141 void AssetGroup::reloadAssets()
00142 {
00143 vector<AssetProcessor*>::iterator it;
00144
00145 for(it = mAssetProcessors.begin(); it != mAssetProcessors.end(); it++)
00146 (*it)->reloadAssets();
00147 }
00148
00149
00150 bool AssetGroup::removeAsset(const std::string &name)
00151 {
00152
00153 std::string assetType;
00154 size_t pos;
00155
00156 pos = name.find("/");
00157 if(pos == std::string::npos)
00158 {
00159 pos = name.find("\"");
00160 if(pos == std::string::npos)
00161 {
00162 return false;
00163 }
00164 }
00165
00166 assetType = name.substr(0, pos);
00167
00168
00169 std::string assetName = name.substr(pos+1, name.size()-pos);
00170
00171
00172 vector<AssetProcessor*>::iterator it;
00173
00174 for(it = mAssetProcessors.begin(); it != mAssetProcessors.end(); it++)
00175 {
00176 AssetProcessor *processor = *it;
00177
00178 if(processor->getBaseName() == assetType)
00179 {
00180 processor->removeAsset(assetName);
00181 break;
00182 }
00183 }
00184
00185
00186 return false;
00187 }
00188
00189
00190 void AssetGroup::removeAssets()
00191 {
00192 vector<AssetProcessor*>::iterator it;
00193
00194 for(it = mAssetProcessors.begin(); it != mAssetProcessors.end(); it++)
00195 (*it)->removeAssets();
00196 }
00197
00198