summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-08-10 18:30:46 +0300
committerAndrei Karas <akaras@inbox.ru>2016-08-10 18:35:33 +0300
commit7ba901978bf2f5ba96bd85d18c226490e39580c9 (patch)
treee616fa65cb7e9b64fa3e32fdf32f4e3ff8831b69
parentfe8e481910ec72c9d70b00737f89d5780f1a3cc5 (diff)
downloadmv-7ba901978bf2f5ba96bd85d18c226490e39580c9.tar.gz
mv-7ba901978bf2f5ba96bd85d18c226490e39580c9.tar.bz2
mv-7ba901978bf2f5ba96bd85d18c226490e39580c9.tar.xz
mv-7ba901978bf2f5ba96bd85d18c226490e39580c9.zip
Use xml loader in particle effects.
-rw-r--r--src/particle/particle.cpp9
-rw-r--r--src/particle/particleengine.cpp11
-rw-r--r--src/resources/loaders/xmlloader.cpp14
-rw-r--r--src/resources/loaders/xmlloader.h4
4 files changed, 29 insertions, 9 deletions
diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp
index 9d755276d..11e36728b 100644
--- a/src/particle/particle.cpp
+++ b/src/particle/particle.cpp
@@ -38,6 +38,7 @@
#include "resources/image/image.h"
#include "resources/loaders/imageloader.h"
+#include "resources/loaders/xmlloader.h"
#include "utils/delete2.h"
#include "utils/dtor.h"
@@ -410,14 +411,17 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile,
const size_t pos = particleEffectFile.find('|');
const std::string dyePalettes = (pos != std::string::npos)
? particleEffectFile.substr(pos + 1) : "";
- XML::Document doc(particleEffectFile.substr(0, pos),
+ XML::Document *doc = Loader::getXml(particleEffectFile.substr(0, pos),
UseResman_true,
SkipError_false);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ if (!doc)
+ return nullptr;
+ const XmlNodePtrConst rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "effect"))
{
logger->log("Error loading particle: %s", particleEffectFile.c_str());
+ doc->decRef();
return nullptr;
}
@@ -537,6 +541,7 @@ Particle *Particle::addEffect(const std::string &restrict particleEffectFile,
mChildParticles.push_back(newParticle);
}
+ doc->decRef();
return newParticle;
}
diff --git a/src/particle/particleengine.cpp b/src/particle/particleengine.cpp
index 6fd9a79f9..5486076c4 100644
--- a/src/particle/particleengine.cpp
+++ b/src/particle/particleengine.cpp
@@ -32,6 +32,7 @@
#include "resources/dye/dye.h"
#include "resources/loaders/imageloader.h"
+#include "resources/loaders/xmlloader.h"
#include "utils/dtor.h"
@@ -134,14 +135,19 @@ Particle *ParticleEngine::addEffect(const std::string &restrict
const size_t pos = particleEffectFile.find('|');
const std::string dyePalettes = (pos != std::string::npos)
? particleEffectFile.substr(pos + 1) : "";
- XML::Document doc(particleEffectFile.substr(0, pos),
+ XML::Document *doc = Loader::getXml(
+ particleEffectFile.substr(0, pos),
UseResman_true,
SkipError_false);
- const XmlNodePtrConst rootNode = doc.rootNode();
+ if (!doc)
+ return nullptr;
+
+ const XmlNodePtrConst rootNode = doc->rootNode();
if (!rootNode || !xmlNameEqual(rootNode, "effect"))
{
logger->log("Error loading particle: %s", particleEffectFile.c_str());
+ doc->decRef();
return nullptr;
}
@@ -261,6 +267,7 @@ Particle *ParticleEngine::addEffect(const std::string &restrict
mChildParticles.push_back(newParticle);
}
+ doc->decRef();
return newParticle;
}
diff --git a/src/resources/loaders/xmlloader.cpp b/src/resources/loaders/xmlloader.cpp
index b834c8788..de227a1cb 100644
--- a/src/resources/loaders/xmlloader.cpp
+++ b/src/resources/loaders/xmlloader.cpp
@@ -33,7 +33,9 @@ namespace
{
struct ResourceLoader final
{
- std::string path;
+ const std::string path;
+ const UseResman useResman;
+ const SkipError skipError;
static Resource *load(const void *const v)
{
@@ -48,16 +50,20 @@ namespace
rl->path.c_str());
return nullptr;
}
- Resource *const res = nullptr;
+ Resource *const res = new XML::Document(rl->path,
+ rl->useResman,
+ rl->skipError);
return res;
}
};
} // namespace
-XML::Document *Loader::getXml(const std::string &idPath)
+XML::Document *Loader::getXml(const std::string &idPath,
+ const UseResman useResman,
+ const SkipError skipError)
{
- ResourceLoader rl = { idPath};
+ ResourceLoader rl = { idPath, useResman, skipError };
return static_cast<XML::Document*>(resourceManager->get(
idPath, ResourceLoader::load, &rl));
}
diff --git a/src/resources/loaders/xmlloader.h b/src/resources/loaders/xmlloader.h
index d898a0092..4133271fa 100644
--- a/src/resources/loaders/xmlloader.h
+++ b/src/resources/loaders/xmlloader.h
@@ -29,7 +29,9 @@
namespace Loader
{
- XML::Document *getXml(const std::string &idPath) A_WARN_UNUSED;
+ XML::Document *getXml(const std::string &idPath,
+ const UseResman useResman,
+ const SkipError skipError) A_WARN_UNUSED;
} // namespace Loader