SDL::Texture::ColorCache Struct Reference

#include <sdl_texture.hpp>

List of all members.

Public Member Functions

 ColorCache ()
 ~ColorCache ()
void operator= (const ColorCache &other)
SDL_Surface *& operator[] (const Color &color)

Static Public Member Functions

static void ref (SDL_Surface *surface)
static int hash (const Color &color)

Public Attributes

SDL_Surface * data [CACHE_SIZE]

Static Public Attributes

static const int HASHED_BITS = 3
static const int CACHE_SIZE = 1 << (HASHED_BITS * 3)


Detailed Description

Definition at line 40 of file sdl_texture.hpp.


Constructor & Destructor Documentation

SDL::Texture::ColorCache::ColorCache (  )  [inline]

Definition at line 63 of file sdl_texture.hpp.

References CACHE_SIZE, and data.

00064       {
00065         memset(data, 0, CACHE_SIZE * sizeof(SDL_Surface *));
00066       }

SDL::Texture::ColorCache::~ColorCache (  )  [inline]

Definition at line 68 of file sdl_texture.hpp.

References CACHE_SIZE, and data.

00069       {
00070         std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
00071       }


Member Function Documentation

static void SDL::Texture::ColorCache::ref ( SDL_Surface *  surface  )  [inline, static]

Definition at line 45 of file sdl_texture.hpp.

Referenced by operator=().

00046       {
00047         if(surface)
00048         {
00049           surface->refcount++;
00050         }
00051       }

static int SDL::Texture::ColorCache::hash ( const Color color  )  [inline, static]

Definition at line 53 of file sdl_texture.hpp.

References Color::blue, Color::green, HASHED_BITS, and Color::red.

Referenced by operator[]().

00054       {
00055         return
00056       ((int) (color.red * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1) * 2) |
00057       ((int) (color.green * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1)) |
00058       ((int) (color.blue * ((1 << HASHED_BITS) - 1)) << 0);
00059       }

void SDL::Texture::ColorCache::operator= ( const ColorCache other  )  [inline]

Definition at line 73 of file sdl_texture.hpp.

References CACHE_SIZE, data, and ref().

00074       {
00075         std::for_each(other.data, other.data + CACHE_SIZE, ref);
00076         std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
00077         memcpy(data, other.data, CACHE_SIZE * sizeof(SDL_Surface *));
00078       }

SDL_Surface*& SDL::Texture::ColorCache::operator[] ( const Color color  )  [inline]

Definition at line 80 of file sdl_texture.hpp.

References data, and hash().

00081       {
00082         return data[hash(color)];
00083       }


Member Data Documentation

const int SDL::Texture::ColorCache::HASHED_BITS = 3 [static]

Definition at line 42 of file sdl_texture.hpp.

Referenced by hash().

const int SDL::Texture::ColorCache::CACHE_SIZE = 1 << (HASHED_BITS * 3) [static]

Definition at line 43 of file sdl_texture.hpp.

Referenced by ColorCache(), operator=(), and ~ColorCache().

SDL_Surface* SDL::Texture::ColorCache::data[CACHE_SIZE]

Definition at line 61 of file sdl_texture.hpp.

Referenced by ColorCache(), operator=(), operator[](), and ~ColorCache().


The documentation for this struct was generated from the following file:
Generated on Mon Nov 16 03:38:18 2009 for SuperTux by  doxygen 1.5.1