diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-11-01 20:04:43 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-11-01 20:04:43 +0100 |
commit | 38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad (patch) | |
tree | 81d0e898790264114683cca9cfd3355bea114415 /src/resources | |
parent | c5e341f7b5f5e4efcabd09e00e177bb873db8097 (diff) | |
parent | 1f69108501c4bf51f3adac9ffbf7a7631fb12b9a (diff) | |
download | mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.tar.gz mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.tar.bz2 mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.tar.xz mana-38f7cd9a9a49dc91b1c2e69b48308bd16d4b5aad.zip |
Merge branch '0.5' of gitorious.org:mana/mana
Conflicts:
src/being.cpp
src/client.cpp
src/commandhandler.cpp
src/gui/setup_video.cpp
src/gui/socialwindow.cpp
src/gui/viewport.cpp
src/gui/widgets/browserbox.cpp
src/gui/widgets/itemcontainer.cpp
src/imageparticle.cpp
src/localplayer.cpp
src/localplayer.h
src/map.cpp
src/net/tmwa/beinghandler.cpp
src/particle.cpp
src/particle.h
src/player.cpp
src/player.h
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/ambientlayer.cpp | 4 | ||||
-rw-r--r-- | src/resources/ambientoverlay.cpp | 4 | ||||
-rw-r--r-- | src/resources/image.cpp | 115 | ||||
-rw-r--r-- | src/resources/image.h | 67 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 15 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 6 | ||||
-rw-r--r-- | src/resources/theme.cpp | 2 | ||||
-rw-r--r-- | src/resources/theme.h | 2 | ||||
-rw-r--r-- | src/resources/userpalette.cpp | 42 | ||||
-rw-r--r-- | src/resources/userpalette.h | 3 |
10 files changed, 208 insertions, 52 deletions
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 50fe8bd9..b662ddeb 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -33,7 +33,7 @@ AmbientLayer::AmbientLayer(Image *img, float parallax, mKeepRatio(keepRatio) { - if (keepRatio && !mImage->isAnOpenGLOne() + if (keepRatio && !mImage->useOpenGL() && defaultScreenWidth != 0 && defaultScreenHeight != 0 && graphics->getWidth() != defaultScreenWidth @@ -92,7 +92,7 @@ void AmbientLayer::update(int timePassed, float dx, float dy) void AmbientLayer::draw(Graphics *graphics, int x, int y) { - if (!mImage->isAnOpenGLOne() || !mKeepRatio) + if (!mImage->useOpenGL() || !mKeepRatio) graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); else diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index 64a46676..aba12f84 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -34,7 +34,7 @@ AmbientOverlay::AmbientOverlay(Image *img, float parallax, mKeepRatio(keepRatio) { - if (keepRatio && !mImage->isAnOpenGLOne() + if (keepRatio && !mImage->useOpenGL() && defaultScreenWidth != 0 && defaultScreenHeight != 0 && graphics->getWidth() != defaultScreenWidth @@ -92,7 +92,7 @@ void AmbientOverlay::update(int timePassed, float dx, float dy) void AmbientOverlay::draw(Graphics *graphics, int x, int y) { - if (!mImage->isAnOpenGLOne() || !mKeepRatio) + if (!mImage->useOpenGL() || !mKeepRatio) graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); else diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 82799bce..63f1bd2c 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -22,12 +22,14 @@ #include "resources/image.h" #include "resources/dye.h" +#include "resources/resourcemanager.h" #ifdef USE_OPENGL #include "openglgraphics.h" #endif #include "log.h" +#include "configuration.h" #include <SDL_image.h> #include <SDL_rotozoom.h> @@ -37,17 +39,23 @@ bool Image::mUseOpenGL = false; int Image::mTextureType = 0; int Image::mTextureSize = 0; #endif +bool Image::mEnableAlphaCache = false; + +// The low CPU mode is disabled per default +bool Image::mDisableTransparency = false; Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): mAlpha(1.0f), - mHasAlphaChannel(hasAlphaChannel), mSDLSurface(image), - mAlphaChannel(alphaChannel) + mAlphaChannel(alphaChannel), + mHasAlphaChannel(hasAlphaChannel) { #ifdef USE_OPENGL mGLImage = 0; #endif + mUseAlphaCache = Image::mEnableAlphaCache; + mBounds.x = 0; mBounds.y = 0; @@ -68,9 +76,10 @@ Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): #ifdef USE_OPENGL Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight): mAlpha(1.0f), - mHasAlphaChannel(true), mSDLSurface(0), mAlphaChannel(0), + mHasAlphaChannel(true), + mUseAlphaCache(false), mGLImage(glimage), mTexWidth(texWidth), mTexHeight(texHeight) @@ -166,12 +175,28 @@ Image *Image::load(SDL_Surface *tmpImage) return _SDLload(tmpImage); } +void Image::SDLcleanCache() +{ + ResourceManager *resman = ResourceManager::getInstance(); + + for (std::map<float, SDL_Surface*>::iterator + i = mAlphaCache.begin(), i_end = mAlphaCache.end(); + i != i_end; ++i) + { + if (mSDLSurface != i->second) + resman->scheduleDelete(i->second); + i->second = 0; + } + mAlphaCache.clear(); +} + void Image::unload() { mLoaded = false; if (mSDLSurface) { + SDLcleanCache(); // Free the image surface. SDL_FreeSurface(mSDLSurface); mSDLSurface = NULL; @@ -189,7 +214,7 @@ void Image::unload() #endif } -bool Image::isAnOpenGLOne() const +bool Image::useOpenGL() { #ifdef USE_OPENGL return mUseOpenGL; @@ -200,29 +225,64 @@ bool Image::isAnOpenGLOne() const bool Image::hasAlphaChannel() { - if (mLoaded) - return mHasAlphaChannel; + if (!mLoaded) + return false; #ifdef USE_OPENGL if (mUseOpenGL) return true; #endif - return false; + return mHasAlphaChannel; +} + +SDL_Surface *Image::getByAlpha(float alpha) +{ + std::map<float, SDL_Surface*>::iterator it = mAlphaCache.find(alpha); + if (it != mAlphaCache.end()) + return (*it).second; + return 0; } void Image::setAlpha(float alpha) { + if (!useOpenGL() && mDisableTransparency) + return; + if (mAlpha == alpha) return; if (alpha < 0.0f || alpha > 1.0f) return; - mAlpha = alpha; - if (mSDLSurface) { + if (mUseAlphaCache) + { + SDL_Surface *surface = getByAlpha(mAlpha); + if (!surface) + { + if (mAlphaCache.size() > 100) + SDLcleanCache(); + + mAlphaCache[mAlpha] = mSDLSurface; + } + surface = getByAlpha(alpha); + if (surface) + { + mAlphaCache.erase(alpha); + mSDLSurface = surface; + mAlpha = alpha; + return; + } + else + { + mSDLSurface = Image::SDLduplicateSurface(mSDLSurface); + } + } + + mAlpha = alpha; + if (!hasAlphaChannel()) { // Set the alpha value this image is drawn at @@ -263,6 +323,10 @@ void Image::setAlpha(float alpha) SDL_UnlockSurface(mSDLSurface); } } + else + { + mAlpha = alpha; + } } Image* Image::SDLmerge(Image *image, int x, int y) @@ -371,6 +435,14 @@ Image* Image::SDLgetScaledImage(int width, int height) return scaledImage; } +SDL_Surface* Image::SDLduplicateSurface(SDL_Surface* tmpImage) +{ + if (!tmpImage || !tmpImage->format) + return NULL; + + return SDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE); +} + Image *Image::_SDLload(SDL_Surface *tmpImage) { if (!tmpImage) @@ -560,25 +632,40 @@ Image *Image::getSubImage(int x, int y, int width, int height) return new SubImage(this, mSDLSurface, x, y, width, height); } +void Image::SDLterminateAlphaCache() +{ + SDLcleanCache(); + mUseAlphaCache = false; +} + //============================================================================ // SubImage Class //============================================================================ SubImage::SubImage(Image *parent, SDL_Surface *image, - int x, int y, int width, int height): + int x, int y, int width, int height): Image(image), mParent(parent) { - mParent->incRef(); - - mHasAlphaChannel = mParent->hasAlphaChannel(); - mAlphaChannel = mParent->SDLgetAlphaChannel(); + if (mParent) + { + mParent->incRef(); + mParent->SDLterminateAlphaCache(); + mHasAlphaChannel = mParent->hasAlphaChannel(); + mAlphaChannel = mParent->SDLgetAlphaChannel(); + } + else + { + mHasAlphaChannel = false; + mAlphaChannel = 0; + } // Set up the rectangle. mBounds.x = x; mBounds.y = y; mBounds.w = width; mBounds.h = height; + mUseAlphaCache = false; } #ifdef USE_OPENGL diff --git a/src/resources/image.h b/src/resources/image.h index 3e8ad551..1db52ca0 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -39,6 +39,8 @@ #include <SDL_opengl.h> #endif +#include <map> + class Dye; class Position; @@ -111,16 +113,10 @@ class Image : public Resource { return mBounds.h; } /** - * Tells if the image was loaded using OpenGL or SDL + * Tells if the system is using OpenGL or SDL * @return true if OpenGL, false if SDL. */ - bool isAnOpenGLOne() const; - - /** - * Tells if the image has got an alpha channel - * @return true if it's true, false otherwise. - */ - bool hasAlphaChannel(); + static bool useOpenGL(); /** * Sets the alpha value of this image. @@ -141,10 +137,24 @@ class Image : public Resource */ virtual Image *getSubImage(int x, int y, int width, int height); + /** + * Tells if the image has got an alpha channel + * @return true if it's true, false otherwise. + */ + bool hasAlphaChannel(); // SDL only public functions /** + * Disable the transparency handling (for low CPUs in SDL Mode) + */ + static void SDLdisableTransparency() + { mDisableTransparency = true; } + + static bool SDLisTransparencyDisabled() + { return mDisableTransparency; } + + /** * Gets an scaled instance of an image. * * @param width The desired width of the scaled image. @@ -169,6 +179,15 @@ class Image : public Resource Uint8 *SDLgetAlphaChannel() const { return mAlphaChannel; } + SDL_Surface* SDLduplicateSurface(SDL_Surface* tmpImage); + + void SDLcleanCache(); + + void SDLterminateAlphaCache(); + + static void SDLsetEnableAlphaCache(bool n) + { mEnableAlphaCache = n; } + #ifdef USE_OPENGL // OpenGL only public functions @@ -188,18 +207,17 @@ class Image : public Resource protected: - // ----------------------- - // Generic protected members - // ----------------------- + // ----------------------- + // Generic protected members + // ----------------------- SDL_Rect mBounds; bool mLoaded; float mAlpha; - bool mHasAlphaChannel; - // ----------------------- - // SDL protected members - // ----------------------- + // ----------------------- + // SDL protected members + // ----------------------- /** SDL Constructor */ Image(SDL_Surface *image, bool hasAlphaChannel = false, @@ -208,14 +226,27 @@ class Image : public Resource /** SDL_Surface to SDL_Surface Image loader */ static Image *_SDLload(SDL_Surface *tmpImage); + SDL_Surface *getByAlpha(float alpha); + SDL_Surface *mSDLSurface; /** Alpha Channel pointer used for 32bit based SDL surfaces */ Uint8 *mAlphaChannel; + bool mHasAlphaChannel; + + /** Alpha cache: The cache stores a copy of the image + for specific requested opacities, hence, increasing + the image disply speed */ + std::map<float, SDL_Surface*> mAlphaCache; + bool mUseAlphaCache; + static bool mEnableAlphaCache; + + /** Stores whether the transparency is disabled */ + static bool mDisableTransparency; - // ----------------------- - // OpenGL protected members - // ----------------------- + // ----------------------- + // OpenGL protected members + // ----------------------- #ifdef USE_OPENGL /** * OpenGL Constructor. diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index c63b626e..00e4726e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -533,3 +533,18 @@ SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) return tmp; } + +void ResourceManager::scheduleDelete(SDL_Surface* surface) +{ + mDeletedSurfaces.insert(surface); +} + +void ResourceManager::clearScheduled() +{ + for (std::set<SDL_Surface*>::iterator i = mDeletedSurfaces.begin(), + i_end = mDeletedSurfaces.end(); i != i_end; ++i) + { + SDL_FreeSurface(*i); + } + mDeletedSurfaces.clear(); +} diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 28ab4725..870182e4 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -26,6 +26,7 @@ #include <map> #include <string> #include <vector> +#include <set> class Image; class ImageSet; @@ -205,6 +206,10 @@ class ResourceManager */ SDL_Surface *loadSDLSurface(const std::string &filename); + void scheduleDelete(SDL_Surface* surface); + + void clearScheduled(); + /** * Returns an instance of the class, creating one if it does not * already exist. @@ -227,6 +232,7 @@ class ResourceManager static ResourceManager *instance; typedef std::map<std::string, Resource*> Resources; typedef Resources::iterator ResourceIterator; + std::set<SDL_Surface*> mDeletedSurfaces; Resources mResources; Resources mOrphanedResources; time_t mOldestOrphan; diff --git a/src/resources/theme.cpp b/src/resources/theme.cpp index 0316b0bf..aa28af36 100644 --- a/src/resources/theme.cpp +++ b/src/resources/theme.cpp @@ -398,6 +398,8 @@ static int readColorType(const std::string &type) "BUTTON", "BUTTON_DISABLED", "TAB", + "PARTY_CHAT_TAB", + "PARTY_SOCIAL_TAB", "BACKGROUND", "HIGHLIGHT", "TAB_FLASH", diff --git a/src/resources/theme.h b/src/resources/theme.h index 6798bed5..3a5aa41a 100644 --- a/src/resources/theme.h +++ b/src/resources/theme.h @@ -127,6 +127,8 @@ class Theme : public Palette, public ConfigListener BUTTON, BUTTON_DISABLED, TAB, + PARTY_CHAT_TAB, + PARTY_SOCIAL_TAB, BACKGROUND, HIGHLIGHT, TAB_FLASH, diff --git a/src/resources/userpalette.cpp b/src/resources/userpalette.cpp index 5067c794..a6b5bc03 100644 --- a/src/resources/userpalette.cpp +++ b/src/resources/userpalette.cpp @@ -33,21 +33,24 @@ #include <math.h> const std::string ColorTypeNames[] = { - "Being", - "Player", - "Self", - "GM", - "NPC", - "Monster", - "Party", - "Guild", - "Particle", - "Experience", - "Pickup", - "Hit Player Monster", - "Hit Monster Player", - "Hit Critical", - "Miss" + "ColorBeing", + "ColorPlayer", + "ColorSelf", + "ColorGM", + "ColorNPC", + "ColorMonster", + "ColorParty", + "ColorGuild", + "ColorParticle", + "ColorExperience", + "ColorPickup", + "ColorHitPlayerMonster", + "ColorHitMonsterPlayer", + "ColorHitCritical", + "ColorHitLocalPlayerMonster", + "ColorHitLocalPlayerCritical", + "ColorHitLocalPlayerMiss", + "ColorMiss" }; std::string UserPalette::getConfigName(const std::string &typeName) @@ -96,9 +99,16 @@ UserPalette::UserPalette(): addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects")); addColor(PICKUP_INFO, 0x28dc28, STATIC, _("Pickup Notification")); addColor(EXP_INFO, 0xffff00, STATIC, _("Exp Notification")); - addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, _("Player Hits Monster")); + addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, + _("Other Player Hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, _("Monster Hits Player")); addColor(HIT_CRITICAL, 0xff0000, RAINBOW, _("Critical Hit")); + addColor(HIT_LOCAL_PLAYER_MONSTER, 0x00ff00, STATIC, + _("Local Player Hits Monster")); + addColor(HIT_LOCAL_PLAYER_CRITICAL, 0xff0000, RAINBOW, + _("Local Player Critical Hit")); + addColor(HIT_LOCAL_PLAYER_MISS, 0x00ffa6, STATIC, + _("Local Player Miss")); addColor(MISS, 0xffff00, STATIC, _("Misses")); commit(true); } diff --git a/src/resources/userpalette.h b/src/resources/userpalette.h index 82bcea1c..be02db10 100644 --- a/src/resources/userpalette.h +++ b/src/resources/userpalette.h @@ -49,6 +49,9 @@ class UserPalette : public Palette, public gcn::ListModel HIT_PLAYER_MONSTER, HIT_MONSTER_PLAYER, HIT_CRITICAL, + HIT_LOCAL_PLAYER_MONSTER, + HIT_LOCAL_PLAYER_CRITICAL, + HIT_LOCAL_PLAYER_MISS, MISS, USER_COLOR_LAST }; |