SDLTexture::ColorCache Struct Reference

#include <sdl_texture.hpp>

List of all members.

Public Member Functions

 ColorCache ()
 ColorCache (const ColorCache &)
 ~ColorCache ()
ColorCacheoperator= (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_Surfacedata [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 35 of file sdl_texture.hpp.


Constructor & Destructor Documentation

SDLTexture::ColorCache::ColorCache (  )  [inline]

Definition at line 58 of file sdl_texture.hpp.

References CACHE_SIZE, and data.

00059     {
00060       memset(data, 0, CACHE_SIZE * sizeof(SDL_Surface *));
00061     }

SDLTexture::ColorCache::ColorCache ( const ColorCache  ) 

SDLTexture::ColorCache::~ColorCache (  )  [inline]

Definition at line 65 of file sdl_texture.hpp.

References CACHE_SIZE, and data.

00066     {
00067       std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
00068     }


Member Function Documentation

static void SDLTexture::ColorCache::ref ( SDL_Surface surface  )  [inline, static]

Definition at line 40 of file sdl_texture.hpp.

Referenced by operator=().

00041     {
00042       if(surface)
00043       {
00044         surface->refcount++;
00045       }
00046     }

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

Definition at line 48 of file sdl_texture.hpp.

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

Referenced by operator[]().

00049     {
00050       return
00051         ((int) (color.red * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1) * 2) |
00052         ((int) (color.green * ((1 << HASHED_BITS) - 1)) << (HASHED_BITS - 1)) |
00053         ((int) (color.blue * ((1 << HASHED_BITS) - 1)) << 0);
00054     }

ColorCache& SDLTexture::ColorCache::operator= ( const ColorCache other  )  [inline]

Definition at line 70 of file sdl_texture.hpp.

References CACHE_SIZE, data, and ref().

00071     {
00072       if (this != &other)
00073       {
00074         std::for_each(other.data, other.data + CACHE_SIZE, ref);
00075         std::for_each(data, data + CACHE_SIZE, SDL_FreeSurface);
00076         memcpy(data, other.data, CACHE_SIZE * sizeof(SDL_Surface *));
00077       }
00078       return *this;
00079     }

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

Definition at line 81 of file sdl_texture.hpp.

References data, and hash().

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


Member Data Documentation

const int SDLTexture::ColorCache::HASHED_BITS = 3 [static]

Definition at line 37 of file sdl_texture.hpp.

Referenced by hash().

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

Definition at line 38 of file sdl_texture.hpp.

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

SDL_Surface* SDLTexture::ColorCache::data[CACHE_SIZE]

Definition at line 56 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 Apr 21 03:38:28 2014 for SuperTux by  doxygen 1.5.1