summaryrefslogtreecommitdiff
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
parent1b1a7cea1c6b81438bacc86b93cb80a78430790f (diff)
downloadmv-5994a6198ac35ea149a7211213dc296ee7406f44.tar.gz
mv-5994a6198ac35ea149a7211213dc296ee7406f44.tar.bz2
mv-5994a6198ac35ea149a7211213dc296ee7406f44.tar.xz
mv-5994a6198ac35ea149a7211213dc296ee7406f44.zip
Move imageset load function from resourcemanager into separate file.
-rw-r--r--src/CMakeLists.txt4
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/theme.cpp3
-rw-r--r--src/gui/widgets/browserbox.cpp4
-rw-r--r--src/gui/widgets/emotepage.cpp4
-rw-r--r--src/particle/particleemitter.cpp3
-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
12 files changed, 138 insertions, 51 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e06fb2507..2b9db603c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -721,6 +721,8 @@ SET(SRCS
resources/resource.h
resources/loaders/imageloader.cpp
resources/loaders/imageloader.h
+ resources/loaders/imagesetloader.cpp
+ resources/loaders/imagesetloader.h
resources/loaders/musicloader.cpp
resources/loaders/musicloader.h
resources/loaders/subimageloader.cpp
@@ -1417,6 +1419,8 @@ SET(DYE_CMD_SRCS
resources/resource.h
resources/loaders/imageloader.cpp
resources/loaders/imageloader.h
+ resources/loaders/imagesetloader.cpp
+ resources/loaders/imagesetloader.h
resources/loaders/musicloader.cpp
resources/loaders/musicloader.h
resources/loaders/subimageloader.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b49dca49..98be2ad80 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -392,6 +392,8 @@ SRC += events/actionevent.h \
resources/resource.h \
resources/loaders/imageloader.cpp \
resources/loaders/imageloader.h \
+ resources/loaders/imagesetloader.cpp \
+ resources/loaders/imagesetloader.h \
resources/loaders/musicloader.cpp \
resources/loaders/musicloader.h \
resources/loaders/subimageloader.cpp \
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 638b57c28..d17f1ae85 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -38,6 +38,7 @@
#include "resources/dye/dyepalette.h"
#include "resources/loaders/imageloader.h"
+#include "resources/loaders/imagesetloader.h"
#include "resources/loaders/subimageloader.h"
#include "resources/resourcemanager/resourcemanager.h"
@@ -650,7 +651,7 @@ Image *Theme::getImageFromTheme(const std::string &path)
ImageSet *Theme::getImageSetFromTheme(const std::string &path,
const int w, const int h)
{
- return resourceManager->getImageSet(resolveThemePath(path), w, h);
+ return Loader::getImageSet(resolveThemePath(path), w, h);
}
static int readColorType(const std::string &type)
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index ba0698b5f..97ad5ce85 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -47,7 +47,7 @@
#include "resources/loaders/imageloader.h"
-#include "resources/resourcemanager/resourcemanager.h"
+#include "resources/loaders/imagesetloader.h"
#include "utils/stringutils.h"
#include "utils/timer.h"
@@ -129,7 +129,7 @@ BrowserBox::BrowserBox(const Widget2 *const widget,
mSkin = theme->load(skin, "browserbox.xml");
if (mInstances == 0)
{
- mEmotes = resourceManager->getImageSet(
+ mEmotes = Loader::getImageSet(
"graphics/sprites/chatemotes.png", 17, 18);
}
mInstances ++;
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
index 0d186e82d..5d5a7b434 100644
--- a/src/gui/widgets/emotepage.cpp
+++ b/src/gui/widgets/emotepage.cpp
@@ -26,7 +26,7 @@
#include "resources/imageset.h"
-#include "resources/resourcemanager/resourcemanager.h"
+#include "resources/loaders/imagesetloader.h"
#include "utils/delete2.h"
@@ -42,7 +42,7 @@ EmotePage::EmotePage(const Widget2 *const widget) :
Widget(widget),
MouseListener(),
WidgetListener(),
- mEmotes(resourceManager->getImageSet(
+ mEmotes(Loader::getImageSet(
"graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)),
mVertexes(new ImageCollection),
mSelectedIndex(-1)
diff --git a/src/particle/particleemitter.cpp b/src/particle/particleemitter.cpp
index 1cfe93f6e..a4c565393 100644
--- a/src/particle/particleemitter.cpp
+++ b/src/particle/particleemitter.cpp
@@ -35,6 +35,7 @@
#include "resources/dye/dye.h"
#include "resources/loaders/imageloader.h"
+#include "resources/loaders/imagesetloader.h"
#include "resources/loaders/subimageloader.h"
#include "resources/resourcemanager/resourcemanager.h"
@@ -396,7 +397,7 @@ ImageSet *ParticleEmitter::getImageSet(XmlNodePtrConst node)
}
else
{
- imageset = resourceManager->getImageSet(
+ imageset = Loader::getImageSet(
XML::getProperty(node, "imageset", ""),
XML::getProperty(node, "width", 0),
XML::getProperty(node, "height", 0));
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)