summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 15:43:26 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-14 15:43:26 +0000
commitb7170d13fd71fb624c06c4536974a7cd3f77591b (patch)
tree7f7583407e79423b08f98a50d897f6e30ac886dd
parenta120ea5cb0a57c9d3bd8677269bd65cf79dad933 (diff)
downloadmana-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.gz
mana-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.bz2
mana-b7170d13fd71fb624c06c4536974a7cd3f77591b.tar.xz
mana-b7170d13fd71fb624c06c4536974a7cd3f77591b.zip
Rewrote Spriteset to work with Image* instead of BITMAP*
-rw-r--r--src/graphic/graphic.cpp23
-rw-r--r--src/graphic/graphic.h2
-rw-r--r--src/graphic/image.cpp46
-rw-r--r--src/graphic/image.h49
-rw-r--r--src/gui/inventory.cpp9
-rw-r--r--src/main.cpp34
-rw-r--r--src/main.h1
-rw-r--r--src/resources/image.cpp43
-rw-r--r--src/resources/image.h44
9 files changed, 110 insertions, 141 deletions
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 0e5b9a32..7678506b 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -196,20 +196,21 @@ GraphicEngine::GraphicEngine() {
gui_bitmap = this->buffer;
// Load the sprite sets
- BITMAP *npcbmp = load_bitmap("data/graphic/npcset.bmp", NULL);
- BITMAP *emotionbmp = load_bitmap("data/graphic/emotionset.bmp", NULL);
- BITMAP *tilesetbmp = load_bitmap("data/graphic/tileset.bmp", NULL);
- BITMAP *monsterbitmap = load_bitmap("data/graphic/monsterset.bmp", NULL);
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *npcbmp = resman->getImage("graphic/npcset.bmp");
+ Image *emotionbmp = resman->getImage("graphic/emotionset.bmp");
+ Image *tilesetbmp = resman->getImage("graphic/tileset.bmp");
+ Image *monsterbitmap = resman->getImage("graphic/monsterset.bmp");
if (!npcbmp) error("Unable to load npcset.bmp");
if (!emotionbmp) error("Unable to load emotionset.bmp");
if (!tilesetbmp) error("Unable to load tileset.bmp");
if (!monsterbitmap) error("Unable to load monsterset.bmp");
- npcset = new Spriteset(npcbmp, 50, 80, 0, 0);
- emotionset = new Spriteset(emotionbmp, 19, 19, 0, 0);
- tileset = new Spriteset(tilesetbmp, 32, 32, 0, 0);
- monsterset = new Spriteset(monsterbitmap, 60, 60, 30, 40);
+ npcset = new Spriteset(npcbmp, 50, 80);
+ emotionset = new Spriteset(emotionbmp, 19, 19);
+ tileset = new Spriteset(tilesetbmp, 32, 32);
+ monsterset = new Spriteset(monsterbitmap, 60, 60);
}
GraphicEngine::~GraphicEngine() {
@@ -341,12 +342,12 @@ void GraphicEngine::refresh() {
int mf = node->frame + node->action;
if (node->action == MONSTER_DEAD) {
- monsterset->spriteset[sprnum + 8 * MONSTER_DEAD]->draw(
- buffer, node->text_x, node->text_y);
+ monsterset->spriteset[sprnum + 8 * MONSTER_DEAD]->draw(buffer,
+ node->text_x + 30, node->text_y + 40);
}
else {
monsterset->spriteset[sprnum + 8 * mf]->draw(buffer,
- node->text_x, node->text_y);
+ node->text_x + 30, node->text_y + 40);
}
if (node->action != STAND) {
diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h
index ed62bf79..063410cf 100644
--- a/src/graphic/graphic.h
+++ b/src/graphic/graphic.h
@@ -39,7 +39,7 @@
#include "../gui/inventory.h"
#include "../gui/npc.h"
#include "../gui/status.h"
-#include "../../data/graphic/gfx_data.h"
+#include "../resources/resourcemanager.h"
#include "image.h"
#include <allegro.h>
diff --git a/src/graphic/image.cpp b/src/graphic/image.cpp
index 008c4017..44b611f6 100644
--- a/src/graphic/image.cpp
+++ b/src/graphic/image.cpp
@@ -18,52 +18,20 @@
* along with The Mana World; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * By ElvenProgrammer aka Eugenio Favalli (umperio@users.sourceforge.net)
+ * $Id$
*/
#include "image.h"
-
-// VideoImage
-
-VideoImage::VideoImage(BITMAP *src, int offset_x, int offset_y):
- src(src),
- offset_x(offset_x),
- offset_y(offset_y)
+Spriteset::Spriteset(Image *img, int width, int height)
{
-}
-
-VideoImage::~VideoImage() {
- destroy_bitmap(src);
-}
-
-void VideoImage::draw(BITMAP *dst, int x, int y) {
- //SDL_Rect dst_rect;
- //dst_rect.x = x + offset_x;
- //dst_rect.y = y + offset_y;
- //SDL_BlitSurface(src, NULL, dst, &dst_rect);
-
- masked_blit(src, dst, 0, 0, x + offset_x, y + offset_y, src->w, src->h);
-}
-
-
-// Spriteset
-
-Spriteset::Spriteset(BITMAP *bmp, int width, int height, int offx, int offy)
-{
- /*
- * We're creating sub bitmaps here for plain convenience. With SDL this'll
- * probably need to be done different.
- */
int x, y;
- for (y = 0; y + height <= bmp->h; y += height)
+ for (y = 0; y + height <= img->getHeight(); y += height)
{
- for (x = 0; x + width <= bmp->w; x += width)
+ for (x = 0; x + width <= img->getWidth(); x += width)
{
- spriteset.push_back(new VideoImage(
- create_sub_bitmap(bmp, x, y, width, height),
- offx, offy));
+ spriteset.push_back(img->getSubImage(x, y, width, height));
}
}
}
@@ -74,7 +42,3 @@ Spriteset::~Spriteset()
delete spriteset[i];
}
}
-
-int Spriteset::getProperty(DATAFILE *datafile, int type) {
- return atoi(get_datafile_property(datafile, type));
-}
diff --git a/src/graphic/image.h b/src/graphic/image.h
index 1bc43ef4..b732d4cf 100644
--- a/src/graphic/image.h
+++ b/src/graphic/image.h
@@ -21,42 +21,15 @@
* $Id$
*/
-#ifndef _IMAGE_H
-#define _IMAGE_H
+#ifndef _TMW_SPRITESET_H
+#define _TMW_SPRITESET_H
#include <allegro.h>
#include <string>
#include <vector>
#include <iostream>
#include "../log.h"
-
-/**
- * A video image stored in memory.
- */
-class VideoImage {
- private:
- BITMAP *src;
- int offset_x, offset_y;
-
- public:
- /**
- * Creates a VideoImage
- * @param src is a reference to a BITMAP
- * @param offset_x is the x offset from where to start drawing
- * @param offset_y is the y offset from where to start drawing
- */
- VideoImage(BITMAP *src, int offset_x, int offset_y);
-
- /**
- * Destructor
- */
- virtual ~VideoImage();
-
- /**
- * Draws a sprite
- */
- void draw(BITMAP *dest, int x, int y);
-};
+#include "../resources/image.h"
/**
* Stores a complete set of sprites.
@@ -64,25 +37,17 @@ class VideoImage {
class Spriteset {
public:
// Vector storing the whole spriteset.
- std::vector<VideoImage*> spriteset;
+ std::vector<Image*> spriteset;
/*
- * Cuts the passed bitmap in a grid of sub bitmaps.
+ * Cuts the passed image in a grid of sub images.
*/
- Spriteset::Spriteset(BITMAP *bmp, int w, int h, int offx, int offy);
+ Spriteset::Spriteset(Image *img, int w, int h);
/**
- * Destructor
+ * Destructor.
*/
~Spriteset();
-
- private:
- /**
- * Helper function to get offset
- * @param datafile is a reference to the whole spriteset
- * @param type is the property of the datafile object
- */
- int getProperty(DATAFILE *datafile, int type);
};
#endif
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp
index 8662841e..c77dcfdd 100644
--- a/src/gui/inventory.cpp
+++ b/src/gui/inventory.cpp
@@ -22,6 +22,8 @@
*/
#include "inventory.h"
+#include "../resources/resourcemanager.h"
+#include "../resources/image.h"
#include <sstream>
InventoryWindow::InventoryWindow():
@@ -29,9 +31,10 @@ InventoryWindow::InventoryWindow():
{
setSize(322, 60);
- BITMAP *itembmp = load_bitmap("data/graphic/items.bmp", NULL);
- if (!itembmp) error("Unable to load items.bmp");
- itemset = new Spriteset(itembmp, 20, 20, 0, 0);
+ ResourceManager *resman = ResourceManager::getInstance();
+ Image *itemImg = resman->getImage("graphic/items.bmp");
+ if (!itemImg) error("Unable to load items.bmp");
+ itemset = new Spriteset(itemImg, 20, 20);
for (int i = 0; i < INVENTORY_SIZE; i++) {
items[i].id = -1;
diff --git a/src/main.cpp b/src/main.cpp
index b296e373..d2af2a28 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -296,28 +296,22 @@ void init_engine() {
ResourceManager *resman = ResourceManager::getInstance();
login_wallpaper = resman->getImage("graphic/login.bmp");
+ Image *playerImg = resman->getImage("graphic/playerset.bmp");
+ Image *hairImg = resman->getImage("graphic/hairset.bmp");
+
if (!login_wallpaper) error("Couldn't load login.bmp");
+ if (!playerImg) error("Couldn't load playerset.bmp");
+ if (!hairImg) error("Couldn't load hairset.bmp");
+
+ // Stretch some bitmaps while they haven't been replaced with higher res
+ Image *scaledPlayerImg = playerImg->getScaledInstance(
+ playerImg->getWidth() * 2, playerImg->getHeight() * 2);
+ Image *scaledHairImg = hairImg->getScaledInstance(
+ hairImg->getWidth() * 2, hairImg->getHeight() * 2);
+
+ playerset = new Spriteset(scaledPlayerImg, 160, 120);
+ hairset = new Spriteset(scaledHairImg, 40, 40);
- BITMAP *playerbitmap = load_bitmap("data/graphic/playerset.bmp", NULL);
- if (!playerbitmap) error("Couldn't load playerset.bmp");
- // Stretch the bitmap while it hasn't been replaced with higher res yet
- BITMAP *playerbitmap2 = create_bitmap(
- playerbitmap->w * 2, playerbitmap->h * 2);
- stretch_blit(playerbitmap, playerbitmap2,
- 0, 0, playerbitmap->w, playerbitmap->h,
- 0, 0, playerbitmap2->w, playerbitmap2->h);
- playerset = new Spriteset(playerbitmap2, 160, 120, 0, 0);
- destroy_bitmap(playerbitmap);
-
- BITMAP *hairbitmap = load_bitmap("data/graphic/hairset.bmp", NULL);
- if (!hairbitmap) error("Couldn't load hairset.bmp");
- // Stretch the bitmap while it hasn't been replaced with higher res yet
- BITMAP *hairbitmap2 = create_bitmap(hairbitmap->w * 2, hairbitmap->h * 2);
- stretch_blit(hairbitmap, hairbitmap2,
- 0, 0, hairbitmap->w, hairbitmap->h,
- 0, 0, hairbitmap2->w, hairbitmap2->h);
- hairset = new Spriteset(hairbitmap2, 40, 40, 0, 0);
- destroy_bitmap(hairbitmap);
// TODO: Remove Allegro config file usage from GUI look
init_gui(buffer, "data/Skin/aqua.skin");
diff --git a/src/main.h b/src/main.h
index c65bc021..bd85463d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -39,7 +39,6 @@
#include "log.h"
#include "game.h"
#include "net/protocol.h"
-#include "../data/graphic/gfx_data.h"
#include <allegro.h>
#ifdef WIN32
#include <winalleg.h>
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index fb36f400..b7739351 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -64,7 +64,7 @@ void Image::unload()
}
-int Image::getWidth()
+int Image::getWidth() const
{
if (image != NULL) {
return image->w;
@@ -72,7 +72,7 @@ int Image::getWidth()
return 0;
}
-int Image::getHeight()
+int Image::getHeight() const
{
if (image != NULL) {
return image->h;
@@ -80,17 +80,26 @@ int Image::getHeight()
return 0;
}
-Image* Image::createSubImage(int x, int y, int width, int height)
+Image* Image::getSubImage(int x, int y, int width, int height)
{
// Create a new clipped sub-image
return new SubImage(this, image, x, y, width, height);
}
+Image* Image::getScaledInstance(int width, int height)
+{
+ return new ScaledImage(this, image, width, height);
+}
+
bool Image::draw(BITMAP *screen, int x, int y)
{
// Check that preconditions for blitting are met.
if (screen == NULL || image == NULL) return false;
+ //SDL_Rect dst_rect;
+ //dst_rect.x = x + offset_x;
+ //dst_rect.y = y + offset_y;
+ //SDL_BlitSurface(src, NULL, dst, &dst_rect);
// Draw the image onto the screen.
draw_sprite(screen, image, x, y);
//if (SDL_BlitSurface(image, NULL, screen, &screenRect) < 0) {
@@ -120,6 +129,8 @@ void Image::drawPattern(BITMAP *screen, int x, int y, int w, int h)
}
}
+//============================================================================
+
SubImage::SubImage(Image *parent, BITMAP *image,
int x, int y, int width, int height):
Image(create_sub_bitmap(image, x, y, width, height)),
@@ -138,12 +149,10 @@ SubImage::~SubImage()
{
if (image) {
destroy_bitmap(image);
+ image = NULL;
}
- parent->decRef();
-}
-
-void SubImage::unload()
-{
+ // TODO: Enable when no longer a problem
+ //parent->decRef();
}
bool SubImage::draw(BITMAP *screen, int x, int y)
@@ -159,3 +168,21 @@ bool SubImage::draw(BITMAP *screen, int x, int y)
return true;
}
+
+//============================================================================
+
+ScaledImage::ScaledImage(Image *parent, BITMAP *bmp, int width, int height):
+ Image(create_bitmap(width, height))
+{
+ if (image) {
+ stretch_blit(bmp, image, 0, 0, bmp->w, bmp->h, 0, 0, width, height);
+ }
+}
+
+ScaledImage::~ScaledImage()
+{
+ if (image) {
+ destroy_bitmap(image);
+ image = NULL;
+ }
+}
diff --git a/src/resources/image.h b/src/resources/image.h
index 8f956324..0452cd4a 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -28,10 +28,9 @@
//#include <SDL/SDL.h>
#include <allegro.h>
-/**
- * A clipped version of a larger image.
- */
+// Forward declarations
class SubImage;
+class ScaledImage;
/**
* Defines a class for loading and storing images.
@@ -60,24 +59,29 @@ class Image : public Resource
/**
* Frees the resources created by SDL.
*/
- void unload();
+ virtual void unload();
/**
* Returns the width of the image.
*/
- int getWidth();
+ virtual int getWidth() const;
/**
* Returns the height of the image.
*/
- int getHeight();
+ virtual int getHeight() const;
/**
* Creates a new image with the desired clipping rectangle.
* @return <code>NULL</code> if creation failed and a valid
* object otherwise.
*/
- Image* createSubImage(int x, int y, int width, int height);
+ virtual Image* getSubImage(int x, int y, int width, int height);
+
+ /**
+ * Creates a scaled version of this image.
+ */
+ virtual Image* getScaledInstance(int width, int height);
/**
* Blits the internal image onto the screen.
@@ -85,12 +89,12 @@ class Image : public Resource
* @return <code>true</code> if the image was blitted properly
* <code>false</code> otherwise.
*/
- bool draw(BITMAP *screen, int x, int y);
+ virtual bool draw(BITMAP *screen, int x, int y);
/**
* Does a pattern fill on the given area.
*/
- void drawPattern(BITMAP *screen, int x, int y, int w, int h);
+ virtual void drawPattern(BITMAP *screen, int x, int y, int w, int h);
protected:
//SDL_Rect screenRect;
@@ -117,11 +121,6 @@ class SubImage : public Image
~SubImage();
/**
- * Redefines unload to not do anything.
- */
- void unload();
-
- /**
* Draws the clipped image onto the screen.
* @return <code>true</code> if drawing was succesful
* <code>false</code> otherwise.
@@ -138,4 +137,21 @@ class SubImage : public Image
//unsigned int referenceCount;
};
+/**
+ * A scaled version of an image.
+ */
+class ScaledImage : public Image
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ScaledImage(Image *parent, BITMAP *image, int width, int height);
+
+ /**
+ * Destructor.
+ */
+ ~ScaledImage();
+};
+
#endif