From b51a15abb93a0dd0fc491419d12ea58637ebf089 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Tue, 31 Jul 2012 17:34:35 +0200 Subject: Removed 'virtual' from methods of Image Maybe it used to be necessary for these methods to be virtual, but this is no longer the case. Hence we can avoid wasting CPU ticks searching through virtual function tables, especially for frequently used methods like getWidth, getHeight and setAlpha. MapLayer::getTile was inlined. Reviewed-by: Erik Schilling --- src/map.cpp | 5 ----- src/map.h | 3 ++- src/resources/image.cpp | 15 ++++++++------- src/resources/image.h | 18 +++++------------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index fa3d9a4c..b647d5d5 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -116,11 +116,6 @@ void MapLayer::setTile(int x, int y, Image *img) setTile(x + y * mWidth, img); } -Image* MapLayer::getTile(int x, int y) const -{ - return mTiles[x + y * mWidth]; -} - void MapLayer::draw(Graphics *graphics, int startX, int startY, int endX, int endY, diff --git a/src/map.h b/src/map.h index ed247eb7..8d87c5be 100644 --- a/src/map.h +++ b/src/map.h @@ -108,7 +108,8 @@ class MapLayer /** * Get tile image, with x and y in layer coordinates. */ - Image *getTile(int x, int y) const; + Image *getTile(int x, int y) const + { return mTiles[x + y * mWidth]; } /** * Draws this layer to the given graphics context. The coordinates are diff --git a/src/resources/image.cpp b/src/resources/image.cpp index b7e6c200..7e592198 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -576,11 +576,17 @@ Image *Image::getSubImage(int x, int y, int width, int height) // Create a new clipped sub-image #ifdef USE_OPENGL if (mUseOpenGL) - return new SubImage(this, mGLImage, x, y, width, height, + return new SubImage(this, mGLImage, + mBounds.x + x, + mBounds.y + y, + width, height, mTexWidth, mTexHeight); #endif - return new SubImage(this, mSDLSurface, x, y, width, height); + return new SubImage(this, mSDLSurface, + mBounds.x + x, + mBounds.y + y, + width, height); } void Image::SDLterminateAlphaCache() @@ -647,8 +653,3 @@ SubImage::~SubImage() #endif mParent->decRef(); } - -Image *SubImage::getSubImage(int x, int y, int w, int h) -{ - return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h); -} diff --git a/src/resources/image.h b/src/resources/image.h index b1831ada..b762bf2a 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -84,7 +84,7 @@ class Image : public Resource /** * Frees the resources created by SDL. */ - virtual void unload(); + void unload(); /** * Tells is the image is loaded @@ -95,13 +95,13 @@ class Image : public Resource /** * Returns the width of the image. */ - virtual int getWidth() const + int getWidth() const { return mBounds.w; } /** * Returns the height of the image. */ - virtual int getHeight() const + int getHeight() const { return mBounds.h; } /** @@ -113,7 +113,7 @@ class Image : public Resource /** * Sets the alpha value of this image. */ - virtual void setAlpha(float alpha); + void setAlpha(float alpha); /** * Returns the alpha value of this image. @@ -127,7 +127,7 @@ class Image : public Resource * @return NULL if creation failed and a valid * object otherwise. */ - virtual Image *getSubImage(int x, int y, int width, int height); + Image *getSubImage(int x, int y, int width, int height); /** * Tells if the image has got an alpha channel @@ -270,14 +270,6 @@ class SubImage : public Image ~SubImage(); - /** - * Creates a new image with the desired clipping rectangle. - * - * @return NULL if creation failed and a valid - * image otherwise. - */ - Image *getSubImage(int x, int y, int width, int height); - private: Image *mParent; }; -- cgit v1.2.3-60-g2f50