summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-05-25 20:48:35 +0300
committerAndrei Karas <akaras@inbox.ru>2016-05-25 20:48:35 +0300
commit5994a6198ac35ea149a7211213dc296ee7406f44 (patch)
treeeec718594fd23da29f9d39e4c0fb00409d514a8e /src/resources
parent1b1a7cea1c6b81438bacc86b93cb80a78430790f (diff)
downloadmanaverse-5994a6198ac35ea149a7211213dc296ee7406f44.tar.gz
manaverse-5994a6198ac35ea149a7211213dc296ee7406f44.tar.bz2
manaverse-5994a6198ac35ea149a7211213dc296ee7406f44.tar.xz
manaverse-5994a6198ac35ea149a7211213dc296ee7406f44.zip
Move imageset load function from resourcemanager into separate file.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/animation/simpleanimation.cpp4
-rw-r--r--src/resources/loaders/imagesetloader.cpp77
-rw-r--r--src/resources/loaders/imagesetloader.h43
-rw-r--r--src/resources/resourcemanager/resourcemanager.cpp34
-rw-r--r--src/resources/resourcemanager/resourcemanager.h7
-rw-r--r--src/resources/sprite/spritedef.cpp4
6 files changed, 124 insertions, 45 deletions
diff --git a/src/resources/animation/simpleanimation.cpp b/src/resources/animation/simpleanimation.cpp
index bc67ad747..dd88eba4a 100644
--- a/src/resources/animation/simpleanimation.cpp
+++ b/src/resources/animation/simpleanimation.cpp
@@ -32,7 +32,7 @@
#include "resources/dye/dye.h"
-#include "resources/resourcemanager/resourcemanager.h"
+#include "resources/loaders/imagesetloader.h"
#include "utils/delete2.h"
@@ -159,7 +159,7 @@ void SimpleAnimation::initializeAnimation(const XmlNodePtr animationNode,
if (!imagePath.empty() && !dyePalettes.empty())
Dye::instantiate(imagePath, dyePalettes);
- const ImageSet *const imageset = resourceManager->getImageSet(
+ const ImageSet *const imageset = Loader::getImageSet(
XML::getProperty(animationNode, "imageset", ""),
XML::getProperty(animationNode, "width", 0),
XML::getProperty(animationNode, "height", 0));
diff --git a/src/resources/loaders/imagesetloader.cpp b/src/resources/loaders/imagesetloader.cpp
new file mode 100644
index 000000000..ad3868cc3
--- /dev/null
+++ b/src/resources/loaders/imagesetloader.cpp
@@ -0,0 +1,77 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "logger.h"
+
+#include "resources/image.h"
+#include "resources/imageset.h"
+
+#include "resources/loaders/imageloader.h"
+#include "resources/loaders/imagesetloader.h"
+
+#include "resources/resourcemanager/resourcemanager.h"
+
+#include "utils/checkutils.h"
+#include "utils/stringutils.h"
+
+#include "debug.h"
+
+struct ImageSetLoader final
+{
+ std::string path;
+ int w;
+ int h;
+ static Resource *load(const void *const v)
+ {
+ if (!v)
+ return nullptr;
+
+ const ImageSetLoader *const
+ rl = static_cast<const ImageSetLoader *const>(v);
+
+ Image *const img = Loader::getImage(rl->path);
+ if (!img)
+ {
+ reportAlways("Image loading error: %s", rl->path.c_str());
+ return nullptr;
+ }
+ ImageSet *const res = new ImageSet(img, rl->w, rl->h);
+ img->decRef();
+ return res;
+ }
+};
+
+ImageSet *Loader::getImageSet(const std::string &imagePath,
+ const int w,
+ const int h)
+{
+ ImageSetLoader rl = { imagePath, w, h };
+ const std::string str = std::string(
+ imagePath).append(
+ "[").append(toString(
+ w)).append(
+ "x").append(toString(
+ h)).append(
+ "]");
+ return static_cast<ImageSet*>(resourceManager->get(str,
+ ImageSetLoader::load, &rl));
+}
diff --git a/src/resources/loaders/imagesetloader.h b/src/resources/loaders/imagesetloader.h
new file mode 100644
index 000000000..320958f07
--- /dev/null
+++ b/src/resources/loaders/imagesetloader.h
@@ -0,0 +1,43 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2016 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef RESOURCES_LOADERS_IMAGESETLOADER_H
+#define RESOURCES_LOADERS_IMAGESETLOADER_H
+
+#include <string>
+
+#include "localconsts.h"
+
+class ImageSet;
+
+namespace Loader
+{
+ /**
+ * Creates a image set based on the image referenced by the given
+ * path and the supplied sprite sizes
+ */
+ ImageSet *getImageSet(const std::string &imagePath,
+ const int w,
+ const int h) A_WARN_UNUSED;
+} // namespace Loader
+
+#endif // RESOURCES_LOADERS_IMAGESETLOADER_H
diff --git a/src/resources/resourcemanager/resourcemanager.cpp b/src/resources/resourcemanager/resourcemanager.cpp
index aca30726b..2f32b7c71 100644
--- a/src/resources/resourcemanager/resourcemanager.cpp
+++ b/src/resources/resourcemanager/resourcemanager.cpp
@@ -527,40 +527,6 @@ Resource *ResourceManager::get(const std::string &idPath,
return resource;
}
-struct ImageSetLoader final
-{
- std::string path;
- int w, h;
- static Resource *load(const void *const v)
- {
- if (!v)
- return nullptr;
-
- const ImageSetLoader *const
- rl = static_cast<const ImageSetLoader *const>(v);
-
- Image *const img = Loader::getImage(rl->path);
- if (!img)
- {
- reportAlways("Image loading error: %s", rl->path.c_str());
- return nullptr;
- }
- ImageSet *const res = new ImageSet(img, rl->w, rl->h);
- img->decRef();
- return res;
- }
-};
-
-ImageSet *ResourceManager::getImageSet(const std::string &imagePath,
- const int w, const int h)
-{
- ImageSetLoader rl = { imagePath, w, h };
- std::stringstream ss;
- ss << imagePath << "[" << w << "x" << h << "]";
- return static_cast<ImageSet*>(get(ss.str(), ImageSetLoader::load, &rl));
-}
-
-
struct SubImageSetLoader final
{
ResourceManager *manager;
diff --git a/src/resources/resourcemanager/resourcemanager.h b/src/resources/resourcemanager/resourcemanager.h
index 13c99df63..2c54aeb5a 100644
--- a/src/resources/resourcemanager/resourcemanager.h
+++ b/src/resources/resourcemanager/resourcemanager.h
@@ -133,13 +133,6 @@ class ResourceManager final : public MemoryCounter
*/
bool addResource(const std::string &idPath, Resource *const resource);
- /**
- * Creates a image set based on the image referenced by the given
- * path and the supplied sprite sizes
- */
- ImageSet *getImageSet(const std::string &imagePath,
- const int w, const int h) A_WARN_UNUSED;
-
ImageSet *getSubImageSet(Image *const parent,
const int width,
const int height) A_WARN_UNUSED;
diff --git a/src/resources/sprite/spritedef.cpp b/src/resources/sprite/spritedef.cpp
index 25c5952e3..7fa53a105 100644
--- a/src/resources/sprite/spritedef.cpp
+++ b/src/resources/sprite/spritedef.cpp
@@ -39,7 +39,7 @@
#include "resources/dye/dye.h"
-#include "resources/resourcemanager/resourcemanager.h"
+#include "resources/loaders/imagesetloader.h"
#include "resources/sprite/spritereference.h"
@@ -241,7 +241,7 @@ void SpriteDef::loadImageSet(const XmlNodePtr node,
std::string imageSrc = XML::getProperty(node, "src", "");
Dye::instantiate(imageSrc, palettes);
- ImageSet *const imageSet = resourceManager->getImageSet(imageSrc,
+ ImageSet *const imageSet = Loader::getImageSet(imageSrc,
width, height);
if (!imageSet)