Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

spritecache.cpp

Go to the documentation of this file.
00001 #include <vector>
00002 #include <string>
00003 #include <iostream>
00004 
00005 #include "graphics.h"
00006 #include "spritecache.h"
00007 
00008 SpriteCache::SpriteCache()
00009 {
00010 }
00011 
00012 SpriteCache::~SpriteCache()
00013 {
00014         for(unsigned int i = 0; i < cache.size(); i++) {
00015                 Graphics::UntexturizeSurface (cache[i].surface);
00016                 Graphics::freeImage(cache[i].surface);
00017         }
00018 
00019         // clear all elements
00020         cache.clear();
00021 }
00022 
00024 Surface *SpriteCache::Find(string n)
00025 {
00026         SpriteCacheInfo sci;
00027         sci.name = n;
00028 
00029         for(unsigned int i = 0; i < cache.size(); i++)
00030                 if (cache[i].name == sci.name)
00031                         return cache[i].surface;
00032 
00033         cout << "loading " << n << endl;
00034 
00035         // load image
00036         Surface *f = Graphics::loadImage(n);
00037         sci.surface = Graphics::displayFormat(f, true);
00038         Graphics::TexturizeSurface (sci.surface); cout << "Tex = " << sci.surface->tex << endl;
00039         Graphics::freeImage(f);
00040 
00041         cache.push_back(sci);
00042 
00043         // return a ptr to the surface
00044         return sci.surface;
00045 }
00046 

Generated on Sun Dec 8 12:02:20 2002 for nnc by doxygen1.3-rc1