Completed implementation of Model LOD system

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40117
This commit is contained in:
kearwood
2012-10-05 02:23:00 +00:00
parent 2fd05171b7
commit 7f7651efbd
10 changed files with 157 additions and 39 deletions

View File

@@ -46,26 +46,45 @@ KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) {
}
KRModelManager::~KRModelManager() {
for(map<std::string, KRModel *>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){
for(std::multimap<std::string, KRModel *>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr){
delete (*itr).second;
}
m_models.empty();
}
KRModel *KRModelManager::loadModel(const char *szName, KRDataBlock *pData) {
KRModel *pModel = new KRModel(*m_pContext, szName, pData);
m_models[szName] = pModel;
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower);
KRModel *pModel = new KRModel(*m_pContext, lowerName, pData);
m_models.insert(std::pair<std::string, KRModel *>(pModel->getName(), pModel));
return pModel;
}
KRModel *KRModelManager::getModel(const char *szName) {
std::map<std::string, KRModel *>::iterator itr_match = m_models.find(szName);
if(itr_match == m_models.end()) {
fprintf(stderr, "ERROR: Model not found: %s\n", szName);
return NULL;
} else {
return itr_match->second;
std::vector<KRModel *> KRModelManager::getModel(const char *szName) {
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower);
std::vector<KRModel *> matching_models;
std::pair<std::multimap<std::string, KRModel *>::iterator, std::multimap<std::string, KRModel *>::iterator> range = m_models.equal_range(lowerName);
for(std::multimap<std::string, KRModel *>::iterator itr_match = range.first; itr_match != range.second; itr_match++) {
matching_models.push_back(itr_match->second);
}
std::sort(matching_models.begin(), matching_models.end(), KRModel::lod_sort_predicate);
if(matching_models.size() == 0) {
fprintf(stderr, "ERROR: Model not found: %s\n", lowerName.c_str());
}
return matching_models;
}
KRModel *KRModelManager::getFirstModel() {
@@ -73,7 +92,7 @@ KRModel *KRModelManager::getFirstModel() {
return (*model_itr).second;
}
std::map<std::string, KRModel *> KRModelManager::getModels() {
std::multimap<std::string, KRModel *> KRModelManager::getModels() {
return m_models;
}