ResourceHandler.h

Go to the documentation of this file.
00001 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 5 -*- */
00002 
00003 /*
00004  * Combination of a first person action and a real time strategy battle game.
00005  */
00006 
00007 /*
00008  * ResourceHandler.h
00009  * MetalWarriors
00010  * $Revision: 1.11 $
00011  *
00012  * Created by Daniel Aarno on Sun Oct 12 2003.
00013  * Copyright (c) 2003 Daniel Aarno and Erik Ytterberg - All rights reserved.
00014  *
00015  *     This program is free software; you can redistribute it and/or modify
00016  *     it under the terms of the GNU General Public License as published by
00017  *     the Free Software Foundation; either version 2 of the License, or
00018  *     (at your option) any later version.
00019  *
00020  *     This program is distributed in the hope that it will be useful,
00021  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *     GNU General Public License for more details.
00024  *
00025  *     You should have received a copy of the GNU General Public License
00026  *     along with this program; if not, write to the Free Software
00027  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00028  */
00029 
00030 #ifndef RESOURCEHANDLER_H
00031 #define RESOURCEHANDLER_H
00032 
00033 #include <map>
00034 #include <string>
00035 #include <list>
00036 
00037 #include "Path.h"
00038 
00039 class Resource
00040 {
00041  protected:
00042   int refCount;
00043   class Resource *nResource;
00044   
00045  public:
00046   Resource();
00047   virtual ~Resource();
00048   void addResource(Resource *resource);
00049   void incRef(void);
00050   void decRef(void);
00051   int getRef(void);
00052   virtual int loadResource(char *filename, int &id)=0;
00053   virtual int loadResource(std::string filename, int &id)=0;
00054 };
00055 
00056 class TextureResource : public Resource
00057 {
00058  public:
00059   int texId;
00060   
00061   virtual ~TextureResource(void);
00062   int loadResource(char *filename, int &id);
00063   int loadResource(std::string filename, int &id);
00064   int loadResource(std::string filename, int &id, int texmode);
00065 };
00066 
00067 class ModelResource : public Resource
00068 {
00069  public:
00070   int indexCount;
00071   int vertexCount;
00072   int *indices;
00073   float *vertices;
00074   
00075   virtual ~ModelResource(void);
00076   virtual int loadResource(char *filename, int &id);
00077   virtual int loadResource(std::string filename, int &id);
00078 };
00079 
00080 class TrackModelResource : public ModelResource
00081 {
00082  public:
00083   float *texCoords;
00084   ~TrackModelResource(void);
00085   virtual int loadResource(char *filename, int &id);
00086   virtual int loadResource(std::string filename, int &id);
00087 };
00088 
00089 class ResourceHandler
00090 {
00091  protected:
00092   std::map<std::string, Resource*, std::less<std::string> > resources;
00093   std::list<std::string> searchPaths;
00094   std::list<std::string> subDirs;
00095 
00096  public:
00097   ResourceHandler();
00098   ~ResourceHandler();
00099   Resource *getResourceByFilename(std::string filename);
00100   Resource *getResourceByFilename(const char *filename);
00101   void freeResourceByFilename(const char *filename);
00102   void setResourceByFilename(std::string filename, Resource *resource);
00103   void setResourceByFilename(const char *filename, Resource *resource);
00104   
00105   int getFD4File(const char *filename);
00106   FILE *getFILE4File(const char *filename);
00107   std::string getPath4File(std::string filename);
00108   std::string getPath4File(const char *filename);
00109   std::string getPath4Dir(const char *filename);
00110   
00111   void appendSearchPath(Path path);
00112   void appendSubDir(Path dir);
00113 
00114   int purgeResources(void);
00115 
00116 };
00117 
00118 
00119 
00120 #endif /*RESOURCEHANDLER_H*/
00121 
00122 
00123 
00124 

Generated on Sun Mar 11 15:33:23 2007 for MetalWarriors by  doxygen 1.4.7