src/tool/resource_manager.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Resource Manager: Load resources (images/sprites) suitable for SDL
00020  *                   Load directly or from refernece in xml resource profile
00021  ******************************************************************************
00022  * 2005/09/21: Jean-Christophe Duberga (jcduberga@gmx.de) 
00023  *             Initial version
00024  * 
00025  * TODO:       Keep reference to resources, better exceptions
00026  *****************************************************************************/
00027 
00028 #ifndef _RESOURCE_MANAGER_H
00029 #define _RESOURCE_MANAGER_H
00030 
00031 #include <string>
00032 #include "xml_document.h"
00033 #include "../graphic/sprite.h"
00034 
00035 class Profile 
00036 { 
00037  public:
00038   XmlReader *doc;
00039   std::string filename;
00040   std::string relative_path;
00041 
00042   Profile();
00043   ~Profile();
00044 };
00045 
00046 class ResourceManager
00047 {
00048  public:
00049    ResourceManager();
00050    ~ResourceManager();
00051 
00052    void AddDataPath( std::string base_path);
00053    Surface LoadImage( const std::string ressource_str, bool alpha = false, bool set_colorkey = false, Uint32 colorkey = 0);
00054 
00055    Profile *LoadXMLProfile( const std::string xml_filename, bool relative_path);
00056    void UnLoadXMLProfile( Profile *profile);
00057 
00058    Color LoadColor( const Profile *profile, const std::string resource_name);
00059    Surface LoadImage( const Profile *profile, const std::string resource_name); 
00060    Sprite *LoadSprite( const Profile *profile, const std::string resource_name); 
00061 
00062  private:
00063    std::string base_path;
00064 
00065    xmlpp::Element * GetElement( const Profile *profile, const std::string ressource_type, const std::string ressource_name);
00066 };
00067 
00068 extern ResourceManager resource_manager;
00069 
00070 #endif /* _RESOURCE_MANAGER_H */

Generated on Mon Jan 1 13:10:59 2007 for Wormux by  doxygen 1.4.7