void SceneNodeWrapper::readChildren(const DataProxy& dict) { std::map<std::pair<std::string, std::string>, bool> visited; for(auto& pair : dict) { const std::string& type = pair.second.get("type", ""); if(type == "") { LOG(ERROR) << "Skipped malformed child definition: no type defined"; continue; } // autogenerate object id if it's not defined auto objectId = pair.second.get<std::string>("name"); std::string id = objectId.first; if (!objectId.second) { std::stringstream ss(""); ss << type << counter++; id = ss.str(); pair.second.put("name", id); } if(mChildren.count(type) == 0) { mChildren[type] = ObjectCollection(); } visited[std::make_pair(type, id)] = true; if(mChildren[type].count(id) != 0) { mChildren[type][id]->read(pair.second); continue; } LOG(TRACE) << "Creating child " << type << " \"" << id << "\""; DataProxy params; OgreObject* child = mObjectManager->create(pair.second, mOwnerId, mSceneManager, type, params, this); if(!child) { LOG(ERROR) << "Failed to create child " << type << " \"" << id << "\""; continue; } mChildren[type][id] = child; } for(auto pair : mChildren) { for(auto childsOfType : pair.second) { auto key = std::make_pair(pair.first, childsOfType.first); if(visited.count(key) == 0) { mChildren[key.first][key.second]->destroy(); mChildren[key.first].erase(childsOfType.first); if(mChildren[key.first].size() == 0) { mChildren.erase(key.first); } } } } }
const ObjectCollection GetObjects() const { return ObjectCollection(*this); }
ObjectCollection GetObjects() { return ObjectCollection(*this); }