From 8bde9095c5840b8d62ebafe11beaed98877d6ac2 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 9 Oct 2005 03:34:45 +0000 Subject: * 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. --- src/resources/image.cpp | 75 +++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 43 deletions(-) (limited to 'src/resources/image.cpp') 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) -- cgit v1.2.3-60-g2f50