summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 03:34:45 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 03:34:45 +0000
commit8bde9095c5840b8d62ebafe11beaed98877d6ac2 (patch)
tree537f717a339d1247cae222eb7a354ea5dbe8babf /src/resources
parenta246c08cef5e4d598fc07a681eb971bfbcf01519 (diff)
downloadmana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.gz
mana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.bz2
mana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.xz
mana-8bde9095c5840b8d62ebafe11beaed98877d6ac2.zip
* Made Sprite into an interface implemented by both FloorItem and Being, which
hook themselves into the map on construction. The improved fringe layer is working as expected now. * Made sure TMW compiles without warnings even when using "-Wconversion -Wshadow -Wcast-qual -Wwrite-strings -ansi -pedantic", lots of cleanups. * Added two new small tilesets that contain the desert tiles that are twice and three times the height of a normal tile. One well in new_3-1 has been converted to use the new double tiles for testing purposes.
Diffstat (limited to 'src/resources')
-rw-r--r--src/resources/image.cpp75
-rw-r--r--src/resources/image.h15
-rw-r--r--src/resources/iteminfo.cpp115
-rw-r--r--src/resources/iteminfo.h96
-rw-r--r--src/resources/music.cpp41
-rw-r--r--src/resources/music.h16
-rw-r--r--src/resources/soundeffect.cpp22
-rw-r--r--src/resources/soundeffect.h12
8 files changed, 151 insertions, 241 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 27fc6497..266f46e3 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -28,28 +28,28 @@
#include "../log.h"
#ifdef USE_OPENGL
-bool Image::useOpenGL = false;
+bool Image::mUseOpenGL = false;
#endif
Image::Image(const std::string &idPath, SDL_Surface *image):
- Resource(idPath), image(image)
+ Resource(idPath), mImage(image)
{
// Default to opaque
alpha = 1.0f;
bounds.x = 0;
bounds.y = 0;
- bounds.w = image->w;
- bounds.h = image->h;
+ bounds.w = mImage->w;
+ bounds.h = mImage->h;
}
#ifdef USE_OPENGL
Image::Image(const std::string &idPath, GLuint glimage, int width, int height,
- int texWidth, int texHeight):
+ int texWidth, int texHeight):
Resource(idPath),
- glimage(glimage),
- texWidth(texWidth),
- texHeight(texHeight)
+ mGLImage(glimage),
+ mTexWidth(texWidth),
+ mTexHeight(texHeight)
{
// Default to opaque
alpha = 1.0f;
@@ -66,7 +66,8 @@ Image::~Image()
unload();
}
-Image* Image::load(void* buffer, unsigned int bufferSize, const std::string &idPath)
+Image* Image::load(void *buffer, unsigned int bufferSize,
+ const std::string &idPath)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
@@ -154,7 +155,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize, const std::string &idP
}
#ifdef USE_OPENGL
- if (useOpenGL)
+ if (mUseOpenGL)
{
int width = tmpImage->w;
int height = tmpImage->h;
@@ -264,40 +265,27 @@ void Image::unload()
loaded = false;
#ifdef USE_OPENGL
- if (useOpenGL) {
- return;
- }
+ if (mUseOpenGL) return;
#endif
- if (!image) {
- return;
- }
+ if (!mImage) return;
// Free the image surface.
- SDL_FreeSurface(image);
- image = NULL;
-}
-
-int Image::getWidth() const
-{
- return bounds.w;
-}
-
-int Image::getHeight() const
-{
- return bounds.h;
+ SDL_FreeSurface(mImage);
+ mImage = NULL;
}
Image *Image::getSubImage(int x, int y, int width, int height)
{
// Create a new clipped sub-image
#ifdef USE_OPENGL
- if (useOpenGL) {
- return new SubImage(this, glimage, x, y, width, height, texWidth, texHeight);
+ if (mUseOpenGL) {
+ return new SubImage(this, mGLImage, x, y, width, height,
+ mTexWidth, mTexHeight);
}
#endif
- return new SubImage(this, image, x, y, width, height);
+ return new SubImage(this, mImage, x, y, width, height);
}
void Image::setAlpha(float a)
@@ -305,13 +293,13 @@ void Image::setAlpha(float a)
alpha = a;
#ifdef USE_OPENGL
- if (useOpenGL) {
+ if (mUseOpenGL) {
return;
}
#endif
// Set the alpha value this image is drawn at
- SDL_SetAlpha(image, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha));
+ SDL_SetAlpha(mImage, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha));
}
float Image::getAlpha()
@@ -322,7 +310,7 @@ float Image::getAlpha()
#ifdef USE_OPENGL
void Image::setLoadAsOpenGL(bool useOpenGL)
{
- Image::useOpenGL = useOpenGL;
+ Image::mUseOpenGL = useOpenGL;
}
#endif
@@ -332,9 +320,9 @@ void Image::setLoadAsOpenGL(bool useOpenGL)
SubImage::SubImage(Image *parent, SDL_Surface *image,
int x, int y, int width, int height):
- Image("", image), parent(parent)
+ Image("", image), mParent(parent)
{
- parent->incRef();
+ mParent->incRef();
// Set up the rectangle.
bounds.x = x;
@@ -345,10 +333,11 @@ SubImage::SubImage(Image *parent, SDL_Surface *image,
#ifdef USE_OPENGL
SubImage::SubImage(Image *parent, GLuint image,
- int x, int y, int width, int height, int texWidth, int texHeight):
- Image("", image, width, height, texWidth, texHeight), parent(parent)
+ int x, int y, int width, int height,
+ int texWidth, int texHeight):
+ Image("", image, width, height, texWidth, texHeight), mParent(parent)
{
- parent->incRef();
+ mParent->incRef();
// Set up the rectangle.
bounds.x = x;
@@ -361,14 +350,14 @@ SubImage::SubImage(Image *parent, GLuint image,
SubImage::~SubImage()
{
#ifdef USE_OPENGL
- if (!useOpenGL) {
- image = NULL;
+ if (!mUseOpenGL) {
+ mImage = NULL;
}
#else
- image = NULL;
+ mImage = NULL;
#endif
- parent->decRef();
+ mParent->decRef();
}
Image *SubImage::getSubImage(int x, int y, int w, int h)
diff --git a/src/resources/image.h b/src/resources/image.h
index 6fc4e89a..a7d5cdf1 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -70,13 +70,14 @@ class Image : public Resource
* Returns the width of the image.
*/
virtual int
- getWidth() const;
+ getWidth() const { return bounds.w; }
+
/**
* Returns the height of the image.
*/
virtual int
- getHeight() const;
+ getHeight() const { return bounds.h; }
/**
* Creates a new image with the desired clipping rectangle.
@@ -122,12 +123,12 @@ class Image : public Resource
bool loaded;
#ifdef USE_OPENGL
- GLuint glimage;
- int texWidth, texHeight;
+ GLuint mGLImage;
+ int mTexWidth, mTexHeight;
- static bool useOpenGL;
+ static bool mUseOpenGL;
#endif
- SDL_Surface *image;
+ SDL_Surface *mImage;
float alpha;
};
@@ -162,7 +163,7 @@ class SubImage : public Image
getSubImage(int x, int y, int width, int height);
private:
- Image *parent;
+ Image *mParent;
};
#endif
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
deleted file mode 100644
index 69090dcb..00000000
--- a/src/resources/iteminfo.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World 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.
- *
- * The Mana World 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 The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#include "iteminfo.h"
-
-ItemInfo::ItemInfo() :
- image(0), name(""),
- description(""), type(0),
- weight(0), slot(0)
-{
-}
-
-ItemInfo::~ItemInfo()
-{
-}
-
-void ItemInfo::setImage(short image)
-{
- this->image = image;
-}
-
-short ItemInfo::getImage()
-{
- return image;
-}
-
-void ItemInfo::setArt(short art)
-{
- this->art = art;
-}
-
-short ItemInfo::getArt()
-{
- return art;
-}
-
-void ItemInfo::setName(const std::string &name)
-{
- this->name = name;
-}
-
-std::string ItemInfo::getName()
-{
- return name;
-}
-
-void ItemInfo::setDescription(const std::string &description)
-{
- this->description = description;
-}
-
-std::string ItemInfo::getDescription()
-{
- return description;
-}
-
-void ItemInfo::setEffect(const std::string &effect)
-{
- this->effect = effect;
-}
-
-std::string ItemInfo::getEffect()
-{
- return effect;
-}
-
-void ItemInfo::setType(short type)
-{
- this->type = type;
-}
-
-short ItemInfo::getType()
-{
- return type;
-}
-
-void ItemInfo::setWeight(short weight)
-{
- this->weight = weight;
-}
-
-short ItemInfo::getWeight()
-{
- return weight;
-}
-
-void ItemInfo::setSlot(char slot)
-{
- this->slot = slot;
-}
-
-char ItemInfo::getSlot()
-{
- return slot;
-}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 937911af..c515fd1c 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -37,52 +37,80 @@ class ItemInfo
/**
* Constructor.
*/
- ItemInfo();
+ ItemInfo():
+ mImage(0),
+ mArt(0),
+ mType(0),
+ mWeight(0),
+ mSlot(0)
+ {
+ }
- void setImage(short image);
-
- short getImage();
-
- void setArt(short art);
-
- short getArt();
-
- void setName(const std::string &name);
-
- std::string getName();
-
- void setDescription(const std::string &description);
+ void
+ setArt(short art) { mArt = art; }
- std::string getDescription();
+ short
+ getArt() { return mArt; }
- void setEffect(const std::string &effect);
+ void
+ setName(const std::string &name) { mName = name; }
- std::string getEffect();
+ std::string
+ getName() { return mName; }
- void setType(short type);
+ void
+ setImage(short image) { mImage = image; }
- short getType();
-
- void setWeight(short weight);
+ short
+ getImage() { return mImage; }
- short getWeight();
-
- void setSlot(char slot);
-
- char getSlot();
+ void
+ setDescription(const std::string &description)
+ {
+ mDescription = description;
+ }
+
+ std::string
+ getDescription() { return mDescription; }
+
+ void
+ setEffect(const std::string &effect) { mEffect = effect; }
+
+ std::string
+ getEffect() { return mEffect; }
+
+ void
+ setType(short type) { mType = type; }
+
+ short
+ getType() { return mType; }
+
+ void
+ setWeight(short weight) { mWeight = weight; }
+
+ short
+ getWeight() { return mWeight; }
+
+ void
+ setSlot(char slot) { mSlot = slot; }
+
+ char
+ getSlot() { return mSlot; }
protected:
/**
* Destructor.
*/
- ~ItemInfo();
-
- short image, art;
- std::string name;
- std::string description;
- std::string effect;
- short type, weight;
- char slot;
+ ~ItemInfo() {}
+
+ short mImage;
+ short mArt;
+ std::string mName;
+ std::string mDescription;
+ std::string mEffect;
+ short mType;
+ short mWeight;
+ char mSlot;
};
#endif
diff --git a/src/resources/music.cpp b/src/resources/music.cpp
index ba9f6df7..09e2752a 100644
--- a/src/resources/music.cpp
+++ b/src/resources/music.cpp
@@ -24,19 +24,20 @@
#include "music.h"
Music::Music(const std::string &idPath, Mix_Chunk *music):
- Resource(idPath), music(music)
+ Resource(idPath),
+ mChunk(music),
+ mChannel(-1)
{
- channel = -1;
}
Music::~Music()
{
//Mix_FreeMusic(music);
- Mix_FreeChunk(music);
- music = NULL;
+ Mix_FreeChunk(mChunk);
}
-Music* Music::load(void* buffer, unsigned int bufferSize, const std::string &idPath)
+Music*
+Music::load(void *buffer, unsigned int bufferSize, const std::string &idPath)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
@@ -44,39 +45,41 @@ Music* Music::load(void* buffer, unsigned int bufferSize, const std::string &idP
// Use Mix_LoadMUS to load the raw music data
//Mix_Music* music = Mix_LoadMUS_RW(rw); Need to be implemeted
Mix_Chunk *tmpMusic = Mix_LoadWAV_RW(rw, 0);
-
+
// Now free the SDL_RWops data
SDL_FreeRW(rw);
return new Music(idPath, tmpMusic);
}
-bool Music::play(int loops)
+bool
+Music::play(int loops)
{
/*
* Warning: loops should be always set to -1 (infinite) with current
* implementation to avoid halting the playback of other samples
*/
-
+
/*if (Mix_PlayMusic(music, loops))
return true;*/
- Mix_VolumeChunk(music, 120);
- channel = Mix_PlayChannel(-1, music, loops);
- if (channel != -1)
- return true;
- return false;
+ Mix_VolumeChunk(mChunk, 120);
+ mChannel = Mix_PlayChannel(-1, mChunk, loops);
+
+ return mChannel != -1;
}
-bool Music::stop()
+void
+Music::stop()
{
/*
* Warning: very dungerous trick, it could try to stop channels occupied
* by samples rather than the current music file
*/
-
+
//Mix_HaltMusic();
- if (channel != -1)
- Mix_HaltChannel(channel);
- // Never fails
- return true;
+
+ if (mChannel != -1)
+ {
+ Mix_HaltChannel(mChannel);
+ }
}
diff --git a/src/resources/music.h b/src/resources/music.h
index 4858eb86..9cf75928 100644
--- a/src/resources/music.h
+++ b/src/resources/music.h
@@ -48,7 +48,8 @@ class Music : public Resource
* @return <code>NULL</code> if the an error occurred, a valid pointer
* otherwise.
*/
- static Music *load(void* buffer, unsigned int bufferSize, const std::string &idPath);
+ static Music*
+ load(void* buffer, unsigned int bufferSize, const std::string &idPath);
/**
* Plays the music.
@@ -58,15 +59,14 @@ class Music : public Resource
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- virtual bool play(int loops);
+ virtual bool
+ play(int loops);
/**
* Stops the music.
- *
- * @return <code>true</code> if the playback was stopped properly
- * <code>false</code> otherwise.
*/
- virtual bool stop();
+ virtual void
+ stop();
protected:
/**
@@ -75,8 +75,8 @@ class Music : public Resource
Music(const std::string &idPath, Mix_Chunk *music);
//Mix_Music *music;
- Mix_Chunk *music;
- int channel;
+ Mix_Chunk *mChunk;
+ int mChannel;
};
#endif
diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp
index 7c77d5b7..3340e5ea 100644
--- a/src/resources/soundeffect.cpp
+++ b/src/resources/soundeffect.cpp
@@ -24,34 +24,36 @@
#include "soundeffect.h"
SoundEffect::SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect):
- Resource(idPath), soundEffect(soundEffect)
+ Resource(idPath),
+ mChunk(soundEffect)
{
}
SoundEffect::~SoundEffect()
{
- Mix_FreeChunk(soundEffect);
- soundEffect = NULL;
+ Mix_FreeChunk(mChunk);
}
-SoundEffect* SoundEffect::load(void* buffer, unsigned int bufferSize, const std::string &idPath)
+SoundEffect*
+SoundEffect::load(void *buffer, unsigned int bufferSize,
+ const std::string &idPath)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
// Use Mix_LoadWAV_RW to load the raw music data
Mix_Chunk *tmpSoundEffect = Mix_LoadWAV_RW(rw, 0);
-
+
// Now free the SDL_RWops data
SDL_FreeRW(rw);
return new SoundEffect(idPath, tmpSoundEffect);
}
-bool SoundEffect::play(int loops, int volume)
+bool
+SoundEffect::play(int loops, int volume)
{
- Mix_VolumeChunk(soundEffect, volume);
- if (Mix_PlayChannel(-1, soundEffect, loops) != -1)
- return true;
- return false;
+ Mix_VolumeChunk(mChunk, volume);
+
+ return Mix_PlayChannel(-1, mChunk, loops) != -1;
}
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index bd1c3c00..92b0016a 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -37,7 +37,8 @@ class SoundEffect : public Resource
/**
* Destructor.
*/
- virtual ~SoundEffect();
+ virtual
+ ~SoundEffect();
/**
* Loads a sample from a buffer in memory.
@@ -48,8 +49,8 @@ class SoundEffect : public Resource
* @return <code>NULL</code> if the an error occurred, a valid pointer
* otherwise.
*/
- static SoundEffect *load(void* buffer, unsigned int bufferSize,
- const std::string &idPath);
+ static SoundEffect*
+ load(void* buffer, unsigned int bufferSize, const std::string &idPath);
/**
* Plays the sample.
@@ -60,7 +61,8 @@ class SoundEffect : public Resource
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- virtual bool play(int loops, int volume);
+ virtual bool
+ play(int loops, int volume);
protected:
/**
@@ -68,7 +70,7 @@ class SoundEffect : public Resource
*/
SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect);
- Mix_Chunk *soundEffect;
+ Mix_Chunk *mChunk;
};
#endif