diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-29 22:00:35 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-08-29 22:00:35 +0000 |
commit | 5352c44d1ab542c64c421afcc690b200f7231a9d (patch) | |
tree | 4695c79a788c3ab9daeaf2972052a6ea9821bf13 /src/resources | |
parent | 52a7af6227d0b2ff94ff2c8fecd708d4d6a71466 (diff) | |
download | mana-5352c44d1ab542c64c421afcc690b200f7231a9d.tar.gz mana-5352c44d1ab542c64c421afcc690b200f7231a9d.tar.bz2 mana-5352c44d1ab542c64c421afcc690b200f7231a9d.tar.xz mana-5352c44d1ab542c64c421afcc690b200f7231a9d.zip |
Clean up of the ConfigListener and Resource interfaces.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/image.cpp | 18 | ||||
-rw-r--r-- | src/resources/image.h | 7 | ||||
-rw-r--r-- | src/resources/music.cpp | 8 | ||||
-rw-r--r-- | src/resources/music.h | 4 | ||||
-rw-r--r-- | src/resources/resource.cpp | 10 | ||||
-rw-r--r-- | src/resources/resource.h | 9 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 7 | ||||
-rw-r--r-- | src/resources/soundeffect.cpp | 8 | ||||
-rw-r--r-- | src/resources/soundeffect.h | 5 |
9 files changed, 33 insertions, 43 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 5ea45842..6910bd55 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -31,8 +31,8 @@ bool Image::useOpenGL = false; #endif -Image::Image(SDL_Surface *image): - image(image) +Image::Image(const std::string &idPath, SDL_Surface *image): + Resource(idPath), image(image) { // Default to opaque alpha = 1.0f; @@ -44,7 +44,9 @@ Image::Image(SDL_Surface *image): } #ifdef USE_OPENGL -Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight): +Image::Image(const std::string &idPath, GLuint glimage, int width, int height, + int texWidth, int texHeight): + Resource(idPath), glimage(glimage), texWidth(texWidth), texHeight(texHeight) @@ -64,7 +66,7 @@ Image::~Image() unload(); } -Image* Image::load(void* buffer, unsigned int bufferSize) +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); @@ -234,7 +236,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize) return NULL; } - return new Image(texture, width, height, realWidth, realHeight); + return new Image(idPath, texture, width, height, realWidth, realHeight); } #endif @@ -254,7 +256,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize) return NULL; } - return new Image(image); + return new Image(idPath, image); } void Image::unload() @@ -330,7 +332,7 @@ 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), parent(parent) { parent->incRef(); @@ -344,7 +346,7 @@ 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) + Image("", image, width, height, texWidth, texHeight), parent(parent) { parent->incRef(); diff --git a/src/resources/image.h b/src/resources/image.h index a4a65787..6fc4e89a 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -58,7 +58,7 @@ class Image : public Resource * otherwise. */ static Image* - load(void* buffer, unsigned int bufferSize); + load(void* buffer, unsigned int bufferSize, const std::string &idPath); /** * Frees the resources created by SDL. @@ -113,9 +113,10 @@ class Image : public Resource * Constructor. */ #ifdef USE_OPENGL - Image(GLuint glimage, int width, int height, int texWidth, int texHeight); + Image(const std::string &idPath, GLuint glimage, int width, int height, + int texWidth, int texHeight); #endif - Image(SDL_Surface *image); + Image(const std::string &idPath, SDL_Surface *image); SDL_Rect bounds; bool loaded; diff --git a/src/resources/music.cpp b/src/resources/music.cpp index 9cc848ad..ba9f6df7 100644 --- a/src/resources/music.cpp +++ b/src/resources/music.cpp @@ -23,8 +23,8 @@ #include "music.h" -Music::Music(Mix_Chunk *music): - music(music) +Music::Music(const std::string &idPath, Mix_Chunk *music): + Resource(idPath), music(music) { channel = -1; } @@ -36,7 +36,7 @@ Music::~Music() music = NULL; } -Music* Music::load(void* buffer, unsigned int bufferSize) +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); @@ -48,7 +48,7 @@ Music* Music::load(void* buffer, unsigned int bufferSize) // Now free the SDL_RWops data SDL_FreeRW(rw); - return new Music(tmpMusic); + return new Music(idPath, tmpMusic); } bool Music::play(int loops) diff --git a/src/resources/music.h b/src/resources/music.h index b8d493e2..4858eb86 100644 --- a/src/resources/music.h +++ b/src/resources/music.h @@ -48,7 +48,7 @@ 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); + static Music *load(void* buffer, unsigned int bufferSize, const std::string &idPath); /** * Plays the music. @@ -72,7 +72,7 @@ class Music : public Resource /** * Constructor. */ - Music(Mix_Chunk *music); + Music(const std::string &idPath, Mix_Chunk *music); //Mix_Music *music; Mix_Chunk *music; diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index e13ec359..5c1df52d 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -28,8 +28,8 @@ #include "resourcemanager.h" -Resource::Resource(): - mRefCount(0) +Resource::Resource(const std::string &idPath): + mRefCount(0), mIdPath(idPath) { } @@ -38,12 +38,6 @@ Resource::~Resource() } void -Resource::setIdPath(const std::string &idPath) -{ - mIdPath = idPath; -} - -void Resource::incRef() { mRefCount++; diff --git a/src/resources/resource.h b/src/resources/resource.h index 09c12c90..ce3a62fb 100644 --- a/src/resources/resource.h +++ b/src/resources/resource.h @@ -35,14 +35,7 @@ class Resource /** * Constructor */ - Resource(); - - /** - * Sets the id path of this resource. This path is used to notify the - * resource manager when this resource is deleted. - */ - void - setIdPath(const std::string &idPath); + Resource(const std::string &idPath); /** * Increments the internal reference count. diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index b443c715..3567ac35 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -150,19 +150,19 @@ ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath) case MUSIC: { // Let the music class load it - resource = Music::load(buffer, fileSize); + resource = Music::load(buffer, fileSize, idPath); } break; case IMAGE: { // Let the image class load it - resource = Image::load(buffer, fileSize); + resource = Image::load(buffer, fileSize, idPath); } break; case SOUND_EFFECT: { // Let the sound effect class load it - resource = SoundEffect::load(buffer, fileSize); + resource = SoundEffect::load(buffer, fileSize, idPath); } break; default: @@ -174,7 +174,6 @@ ResourceManager::get(const E_RESOURCE_TYPE &type, const std::string &idPath) if (resource) { resource->incRef(); - resource->setIdPath(idPath); resources[idPath] = resource; } diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp index 30d405d3..7c77d5b7 100644 --- a/src/resources/soundeffect.cpp +++ b/src/resources/soundeffect.cpp @@ -23,8 +23,8 @@ #include "soundeffect.h" -SoundEffect::SoundEffect(Mix_Chunk *soundEffect): - soundEffect(soundEffect) +SoundEffect::SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect): + Resource(idPath), soundEffect(soundEffect) { } @@ -34,7 +34,7 @@ SoundEffect::~SoundEffect() soundEffect = NULL; } -SoundEffect* SoundEffect::load(void* buffer, unsigned int bufferSize) +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); @@ -45,7 +45,7 @@ SoundEffect* SoundEffect::load(void* buffer, unsigned int bufferSize) // Now free the SDL_RWops data SDL_FreeRW(rw); - return new SoundEffect(tmpSoundEffect); + return new SoundEffect(idPath, tmpSoundEffect); } bool SoundEffect::play(int loops, int volume) diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h index 69d9823d..bd1c3c00 100644 --- a/src/resources/soundeffect.h +++ b/src/resources/soundeffect.h @@ -48,7 +48,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); + static SoundEffect *load(void* buffer, unsigned int bufferSize, + const std::string &idPath); /** * Plays the sample. @@ -65,7 +66,7 @@ class SoundEffect : public Resource /** * Constructor. */ - SoundEffect(Mix_Chunk *soundEffect); + SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect); Mix_Chunk *soundEffect; }; |