diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-04-07 08:37:23 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-04-07 08:37:23 +0000 |
commit | 64d58b9a7e057e6d829107678b1570082be1093f (patch) | |
tree | f95a940521150e8f5bbab1bba520c956c8b2aed9 /src/particle.cpp | |
parent | 36a53a1d5e3b558dafe200a6929948e7730c94f0 (diff) | |
download | mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.gz mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.bz2 mana-64d58b9a7e057e6d829107678b1570082be1093f.tar.xz mana-64d58b9a7e057e6d829107678b1570082be1093f.zip |
Added XML::Document class which simplifies parsing an XML document and
automatically cleans it up again.
Diffstat (limited to 'src/particle.cpp')
-rw-r--r-- | src/particle.cpp | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/src/particle.cpp b/src/particle.cpp index dcb2eed3..ba5386f6 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -217,35 +217,17 @@ Particle::addEffect(const std::string &particleEffectFile, { Particle *newParticle = NULL; - // XML parser initialisation stuff - int size; - ResourceManager *resman = ResourceManager::getInstance(); - char *data = (char*) resman->loadFile(particleEffectFile.c_str(), size); - - if (!data) { - logger->log("Warning: Particle engine could not find %s !", - particleEffectFile.c_str()); - return NULL; - } - - xmlDocPtr doc = xmlParseMemory(data, size); - free(data); + XML::Document doc(particleEffectFile); + xmlNodePtr rootNode = doc.rootNode(); - if (!doc) { - logger->log("Warning: Particle engine found syntax error in %s!", - particleEffectFile.c_str()); - return NULL; - } - - xmlNodePtr rootNode = xmlDocGetRootElement(doc); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect")) { - logger->log("Warning: %s is not a valid particle effect definition file!", - particleEffectFile.c_str()); - xmlFreeDoc(doc); + logger->log("Error loading particle: %s", particleEffectFile.c_str()); return NULL; } + ResourceManager *resman = ResourceManager::getInstance(); + // Parse particles for_each_xml_child_node(effectChildNode, rootNode) { @@ -302,8 +284,6 @@ Particle::addEffect(const std::string &particleEffectFile, mChildParticles.push_back(newParticle); } - xmlFreeDoc(doc); - return newParticle; } |