Changeset 3655 in orxonox.OLD for orxonox/trunk/src/lib
- Timestamp:
- Mar 26, 2005, 3:28:39 PM (20 years ago)
- Location:
- orxonox/trunk/src/lib
- Files:
-
- 5 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/importer/material.cc
r3590 r3655 23 23 #include <stdlib.h> 24 24 #include <string.h> 25 26 //! \todo check if we are in RESOURCE MANAGER-mode 27 #include "resource_manager.h" 25 28 26 29 using namespace std; … … 104 107 this->ambientTextureSet = false; 105 108 this->specularTextureSet = false; 106 107 108 109 } 109 110 … … 333 334 { 334 335 PRINTF(4)("setting Diffuse Map %s\n", dMap); 335 diffuseTexture = new Texture(); 336 this->diffuseTextureSet = diffuseTexture->loadImage(dMap); 337 336 diffuseTexture = new Texture(); 337 this->diffuseTextureSet = diffuseTexture->loadImage(dMap); 338 339 //! \todo check if RESOURCE MANAGER is availiable 340 //this->diffuseTextureSet = this->diffuseTexture = (Texture*)ResourceManager::load(dMap, IMAGE); 338 341 } 339 342 -
orxonox/trunk/src/lib/graphics/importer/objModel.cc
r3590 r3655 21 21 22 22 #include "debug.h" 23 24 /**25 \brief Crates a 3D-Model and loads in a File.26 \param fileName file to parse and load (must be a .obj file)27 */28 OBJModel::OBJModel(char* fileName)29 {30 this->initializeOBJ();31 32 this->importFile (fileName);33 34 this->importToGL ();35 36 this->cleanup();37 }38 23 39 24 /** … … 193 178 else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented 194 179 { 195 PRINTF( 3)("smoothing groups not supportet yet. line: %s\n", Buffer);180 PRINTF(2)("smoothing groups not supportet yet. line: %s\n", Buffer); 196 181 } 197 182 } -
orxonox/trunk/src/lib/graphics/importer/objModel.h
r3454 r3655 13 13 { 14 14 public: 15 OBJModel(char* fileName); 16 OBJModel(char* fileName, float scaling); 15 OBJModel(char* fileName, float scaling = 1.0); 17 16 virtual ~OBJModel(); 18 17 void initializeOBJ(void); … … 28 27 bool readFromObjFile (void); 29 28 bool readMtlLib (char* matFile); 30 31 29 }; 32 30 -
orxonox/trunk/src/lib/graphics/importer/texture.cc
r3622 r3655 131 131 132 132 /** 133 \brief Constructor for a Texture 134 */ 135 Texture::Texture(const char* imageName) 136 { 137 this->pImage = new Image; 138 this->pImage->data = NULL; 139 this->map = NULL; 140 this->texture = 0; 141 this->loadImage(imageName); 142 } 143 144 /** 133 145 \brief Destructor of a Texture 134 146 … … 149 161 \returns pathName+texName if texName was found in the pathList. NULL if the Texture is not found. 150 162 */ 151 char* Texture::searchTextureInPaths(c har* texName) const163 char* Texture::searchTextureInPaths(const char* texName) const 152 164 { 153 165 char* tmpName = NULL; … … 215 227 216 228 #ifdef HAVE_SDL_SDL_IMAGE_H 217 bool Texture::loadImage(c har* imageName)229 bool Texture::loadImage(const char* imageName) 218 230 { 219 231 if (GraphicsEngine::texturesEnabled) … … 269 281 \todo Checks where to find the Image 270 282 */ 271 bool Texture::loadImage(c har* imageName)283 bool Texture::loadImage(const char* imageName) 272 284 { 273 285 if (GraphicsEngine::texturesEnabled) -
orxonox/trunk/src/lib/graphics/importer/texture.h
r3548 r3655 70 70 GLuint texture; //!< The Texture-ID of opengl from this Texture. 71 71 SDL_Surface* map; //!< The map SDL initializes for this element. 72 char* searchTextureInPaths(c har* texName) const;72 char* searchTextureInPaths(const char* texName) const; 73 73 inline void swap(unsigned char &a, unsigned char &b); 74 74 public: 75 75 Texture(void); 76 Texture(const char* imageName); 76 77 ~Texture(void); 77 78 /** \returns The textureID of this texture. */ … … 79 80 bool loadTexToGL (Image* pImage); 80 81 81 bool loadImage(c har* imageName);82 bool loadImage(const char* imageName); 82 83 #ifndef HAVE_SDL_SDL_IMAGE_H 83 84 -
orxonox/trunk/src/lib/util/resource_manager.cc
r3645 r3655 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 12 10 13 11 ### File Specific: 14 main-programmer: ...12 main-programmer: Benjamin Grauer 15 13 co-programmer: ... 16 14 */ 17 15 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ WORLD_ENTITY16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD 19 17 20 #include " proto_class.h"18 #include "resource_manager.h" 21 19 22 #include "stdincl.h" // maybe 20 // different resource Types 21 #include "objModel.h" 22 #include "texture.h" 23 24 // File Handling Includes 25 #include <sys/types.h> 26 #include <sys/stat.h> 27 #include <unistd.h> 28 23 29 24 30 using namespace std; … … 27 33 /** 28 34 \brief standard constructor 29 \todo this constructor is not jet implemented - do it30 35 */ 31 ProtoClass::ProtoClass()36 ResourceManager::ResourceManager () 32 37 { 33 this->setClassName ("ProtoClass"); 38 this->setClassName ("ResourceManager"); 39 this->dataDir = NULL; 40 } 41 42 ResourceManager* ResourceManager::getInstance(void) 43 { 44 if (!ResourceManager::singletonRef) 45 ResourceManager::singletonRef = new ResourceManager(); 46 return ResourceManager::singletonRef; 47 } 48 49 ResourceManager* ResourceManager::singletonRef = NULL; 50 51 /** 52 \brief standard deconstructor 53 */ 54 ResourceManager::~ResourceManager (void) 55 { 56 ResourceManager::singletonRef = NULL; 34 57 } 35 58 36 59 60 37 61 /** 38 \brief s tandard deconstructor39 62 \brief sets the data main directory 63 \param dataDir the DataDirectory. 40 64 */ 41 ProtoClass::~ProtoClass () 65 bool ResourceManager::setDataDir(char* dataDir) 42 66 { 43 // delete what has to be deleted here 67 if (isDir(dataDir)) 68 { 69 this->dataDir = new char[strlen(dataDir)+1]; 70 strcpy(this->dataDir, dataDir); 71 } 72 else 73 { 74 PRINTF(1)("%s is not a Directory, and can not be the Data Directory\n", dataDir); 75 } 44 76 } 45 77 46 78 /** 47 \brief nonsense - delete this method 48 \param realy nothing to give 49 \returns true or false - probably nothing? 79 \brief loads resources 80 \param fileName The fileName of the resource to load 81 \returns a pointer to a desired Resource. 82 */ 83 void* ResourceManager::load(const char* fileName) 84 { 85 ResourceType tmpType; 86 if (!strncmp(fileName+(strlen(fileName)-4), ".obj", 4)) 87 tmpType = OBJ; 50 88 51 this is just to show the doxygen abilities (this for example is an extension for a long comment) 89 return ResourceManager::load(fileName, tmpType); 90 } 91 92 /** 93 \brief loads resources 94 \param fileName The fileName of the resource to load 95 \param type The Type of Resource to load (\see ResourceType) 96 \returns a pointer to a desired Resource. 52 97 */ 53 bool ProtoClass::doNonSense (int nothing) {} 98 void* ResourceManager::load(const char* fileName, ResourceType type) 99 { 100 void* tmpResource = NULL; 101 char* tmpName = new char[strlen(fileName)+1]; 102 strcpy(tmpName, fileName); 103 // Checking for the type of resource \see ResourceType 104 switch(type) 105 { 106 case OBJ: 107 if(isFile(tmpName)) 108 tmpResource = new OBJModel(tmpName); 109 else 110 { 111 PRINTF(2)("Sorry, %s does not exist. Loading a cube-Model instead\n", tmpName); 112 tmpResource = new Model(CUBE); 113 } 114 break; 115 case IMAGE: 116 if(isFile(tmpName)) 117 { 118 tmpResource = new Texture(tmpName); 119 } 120 else 121 PRINTF(1)("!!Texture %s not Found!!\n", tmpName); 122 break; 123 default: 124 tmpResource = NULL; 125 PRINTF(2)("No type found for %s.\n !!This should not happen unless the Type is not supported yet.!!\n", tmpName); 126 break; 127 } 128 129 // checking if the File really exists. 130 if(!isFile(tmpName)) 131 { 132 PRINTF(2)("Sorry, %s is not a regular file.\n", tmpName); 133 tmpResource = NULL; 134 } 135 return tmpResource; 136 } 137 138 /** 139 \brief Checks if it is a Directory 140 \param directoryName the Directory to check for 141 \returns true if it is a directory/symlink false otherwise 142 */ 143 bool ResourceManager::isDir(const char* directoryName) 144 { 145 struct stat status; 146 stat(directoryName, &status); 147 if (status.st_mode & (S_IFDIR | S_IFLNK)) 148 return true; 149 else 150 return false; 151 } 152 153 /** 154 \brief Checks if the file is either a Regular file or a Symlink 155 \param fileName the File to check for 156 \returns true if it is a regular file/symlink, false otherwise 157 */ 158 bool ResourceManager::isFile(const char* fileName) 159 { 160 struct stat status; 161 stat(fileName, &status); 162 if (status.st_mode & (S_IFREG | S_IFLNK)) 163 return true; 164 else 165 return false; 166 } -
orxonox/trunk/src/lib/util/resource_manager.h
r3645 r3655 1 1 /*! 2 \file proto_class.h 3 \brief Definition of the proto class template, used quickly start work 4 \todo Example: this shows how to use simply add a Marker that here has to be done something. 2 \file resource_manager.h 3 \brief The Resource Manager checks if a file/resource is loaded. 5 4 6 The Protoclass exists, to help you quikly getting the run for how to develop in orxonox. 7 It is an example for the CODING-CONVENTION, and a starting-point for every class. 5 If a file/resource was already loaded the resourceManager will 6 return a void pointer to the desired resource. 7 Otherwise it will instruct the coresponding resource-loader to load, 8 and receive a pointer to it. 8 9 */ 9 10 10 #ifndef _ PROTO_CLASS_H11 #define _ PROTO_CLASS_H11 #ifndef _RESOURCE_MANAGER_H 12 #define _RESOURCE_MANAGER_H 12 13 13 #include "what realy has to be included"14 14 #include "base_object.h" 15 15 16 16 // FORWARD DEFINITION \\ 17 class someClassWeNeed;18 17 19 18 20 /*class Test;*/ /* forward definition of class Test (without including it here!)*/ 19 enum ResourceType {OBJ, WAV, MP3, OGG, IMAGE}; 21 20 22 //! A default class that aids you to start creating a new class21 //! The ResourceManager is a class, that decides if a file/resource should be loaded 23 22 /** 24 here can be some longer description of this class 23 If a file/resource was already loaded the resourceManager will 24 return a void pointer to the desired resource. 25 Otherwise it will instruct the corresponding resource-loader to load, 26 and receive the pointer to it. 27 28 It does it by looking, if a desired file has already been loaded. 25 29 */ 26 class ProtoClass : public BaseObject { 30 class ResourceManager : public BaseObject 31 { 32 public: 33 static ResourceManager* getInstance(); 34 virtual ~ResourceManager(); 27 35 28 public: 29 ProtoClass(); 30 virtual ~ProtoClass(); 31 32 bool doNonSense (int nothing); 36 bool setDataDir(char* dataDir); 37 static void* load(const char* fileName); 38 static void* load(const char* fileName, ResourceType type); 33 39 34 40 private: 35 int nonSense; //!< doxygen tag here like this for all the variables - delete this variable if you use this 41 ResourceManager(); 42 static ResourceManager* singletonRef; 36 43 44 45 struct file; 46 struct folder 47 { 48 char* name; 49 folder** subfolders; //!< 50 file** files; //!< Files in the directory 51 }; 52 struct file 53 { 54 char* name; //!< exact Name of a file 55 void* pointer; 56 }; 57 58 char* dataDir; //!< The main data directory 59 60 static bool isDir(const char* directory); 61 static bool isFile(const char* directory); 37 62 }; 38 63 39 #endif /* _ PROTO_CLASS_H */64 #endif /* _RESOURCE_MANAGER_H */
Note: See TracChangeset
for help on using the changeset viewer.