Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4462 in orxonox.OLD


Ignore:
Timestamp:
Jun 2, 2005, 12:50:37 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: md2Data loadable over the resourceManager

Location:
orxonox/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/scripts/orxodox.checkFiles.pl

    r3997 r4462  
    7474# Project related configuration options \
    7575#--------------------------------------------------------------------------- \
    76 PROJECT_NAME           = Orxonox \
     76PROJECT_NAME           = orxonox \
    7777PROJECT_NUMBER         = 1 \
    7878OUTPUT_DIRECTORY       = doxygen/ \
  • orxonox/trunk/src/lib/graphics/importer/md2Model.cc

    r4461 r4462  
    8181{
    8282  /* this creates the data container via ressource manager */
    83   this->data = new MD2Data(modelFileName, skinFileName);
     83  this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, (void*)skinFileName);
    8484  this->scaleFactor = this->data->scaleFactor;
    8585
     
    9494MD2Model::~MD2Model()
    9595{
    96 
     96  ResourceManager::getInstance()->unload(this->data);
    9797}
    9898
  • orxonox/trunk/src/util/resource_manager.cc

    r4381 r4462  
    2121#include "objModel.h"
    2222#include "primitive_model.h"
     23#include "md2Model.h"
    2324#include "texture.h"
    2425#include "text_engine.h"
     
    173174{
    174175  ResourceType tmpType;
     176
    175177  if (!strncmp(fileName+(strlen(fileName)-4), ".obj", 4))
    176178    tmpType = OBJ;
     179  if (!strncmp(fileName+(strlen(fileName)-4), ".md2", 4))
     180    tmpType = MD2;
    177181  else if (!strncmp(fileName+(strlen(fileName)-4), ".wav", 4))
    178182    tmpType = WAV;
     
    226230
    227231      // creating the full name. (directoryName + FileName)
    228       char* fullName = new char[strlen(this->getDataDir())+strlen(fileName)+1];
    229       sprintf(fullName, "%s%s", this->getDataDir(), fileName);
     232      char* fullName = ResourceManager::getFullName(fileName);
    230233      // Checking for the type of resource \see ResourceType
    231234      switch(type)
     
    262265            tmpResource->pointer = new PrimitiveModel(CONE, tmpResource->modelSize);
    263266          break;
     267        case MD2:
     268          if(ResourceManager::isFile(fullName))
     269            {
     270              if (param1)
     271                {
     272                  tmpResource->skinFileName = new char[strlen((const char*)param1)+1];
     273                  strcpy(tmpResource->skinFileName, (const char*) fileName);
     274                }
     275              else
     276                tmpResource->skinFileName = NULL;
     277              char* skinFileName = ResourceManager::getFullName(tmpResource->skinFileName);
     278              tmpResource->pointer = new MD2Data(fullName, skinFileName);
     279              delete []skinFileName;
     280            }
     281              break;
    264282        case TTF:
    265283            if (param1)
     
    373391              delete (Model*)resource->pointer;
    374392              break;
     393            case MD2:
     394              delete (MD2Data*)resource->pointer;
     395              break;
    375396            case IMAGE:
    376397              delete (Texture*)resource->pointer;
     
    425446   \returns a Pointer to the Resource if found, NULL otherwise.
    426447*/
    427 Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3)
     448Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
     449                                                void* param1, void* param2, void* param3)
    428450{
    429451  //  Resource* enumRes = resourceList->enumerate();
     
    436458          bool match = false;
    437459          bool subMatch = false;
     460
    438461          switch (type)
    439462            {
     
    446469                }
    447470              else if (enumRes->modelSize == *(float*)param1)
     471                match = true;
     472              break;
     473            case MD2:
     474              if (!param1)
     475                {
     476                  if (enumRes->skinFileName == NULL)
     477                    match = true;
     478                }
     479              else if (!strcmp(enumRes->skinFileName, (const char*) param1))
    448480                match = true;
    449481              break;
     
    519551bool ResourceManager::isDir(const char* directoryName)
    520552{
     553  if (directoryName == NULL)
     554    return false;
     555
    521556  char* tmpDirName = NULL;
    522557  struct stat status;
     
    563598bool ResourceManager::isFile(const char* fileName)
    564599{
     600  if (fileName == NULL)
     601    return false;
    565602  char* tmpFileName = ResourceManager::homeDirCheck(fileName);
    566603  // actually checks the File
     
    597634{
    598635  char* tmpName = ResourceManager::homeDirCheck(fileName);
    599 
     636  if (tmpName == NULL)
     637    return false;
    600638  FILE* stream;
    601639  if( (stream = fopen (tmpName, "w")) == NULL)
     
    615653bool ResourceManager::deleteFile(const char* fileName)
    616654{
     655  if (fileName == NULL)
     656    return false;
    617657  char* tmpName = ResourceManager::homeDirCheck(fileName);
    618658  unlink(tmpName);
     
    627667char* ResourceManager::homeDirCheck(const char* name)
    628668{
     669  if (name == NULL)
     670    return NULL;
    629671  char* retName;
    630672  if (!strncmp(name, "~/", 2))
     
    654696char* ResourceManager::getFullName(const char* fileName)
    655697{
     698  if (fileName == NULL)
     699    return NULL;
     700
    656701  char* retName = new char[strlen(ResourceManager::getInstance()->getDataDir())
    657702                           + strlen(fileName) + 1];
    658703  sprintf(retName, "%s%s", ResourceManager::getInstance()->getDataDir(), fileName);
    659   if (ResourceManager::isFile(retName))
     704  if (ResourceManager::isFile(retName) || ResourceManager::isDir(retName))
    660705    return retName;
    661706  else
  • orxonox/trunk/src/util/resource_manager.h

    r4381 r4462  
    1919template<class T> class tList;
    2020
    21 //! An eumerator for different fileTypes the resourceManager supports \todo WAV, MP3, OGG support
    22 enum ResourceType {OBJ,
    23                    PRIM,
    24                    WAV,
    25                    MP3,
    26                    OGG,
    27                    TTF,
    28                    IMAGE};
     21//! An eumerator for different fileTypes the resourceManager supports
     22typedef enum ResourceType { OBJ,
     23                            PRIM,
     24                            MD2,
     25                            WAV,
     26                            MP3,
     27                            OGG,
     28                            TTF,
     29                            IMAGE };
     30
    2931//! An enumerator for different UNLOAD-types.
    3032/**
    31    RP_NO: will be unloaded on request
    32    RP_LEVEL: will be unloaded at the end of a Level
    33    RP_CAMPAIGN: will be unloaded at the end of a Campaign
    34    RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox)
     33   RP_NO:        will be unloaded on request
     34   RP_LEVEL:     will be unloaded at the end of a Level
     35   RP_CAMPAIGN:  will be unloaded at the end of a Campaign
     36   RP_GAME:      will be unloaded at the end of the whole Game (when closing orxonox)
    3537*/
    36 enum ResourcePriority {RP_NO = 0,
    37                        RP_LEVEL = 1,
    38                        RP_CAMPAIGN = 2,
    39                        RP_GAME = 3};
     38typedef enum ResourcePriority { RP_NO        =  0,
     39                                RP_LEVEL     =  1,
     40                                RP_CAMPAIGN  =  2,
     41                                RP_GAME      =   4 };
    4042
    4143//! A Struct that keeps track about A resource its name its Type, and so on
     
    5557  unsigned char ttfColorG;
    5658  unsigned char ttfColorB;
     59  char* skinFileName;
    5760};
    5861
     
    6669
    6770   It does it by looking, if a desired file has already been loaded.
    68 
    69    \todo loading also dependant by parameters.
    7071*/
    7172class ResourceManager : public BaseObject
  • orxonox/trunk/src/world_entities/test_entity.cc

    r4459 r4462  
    3030  this->setClassID(CL_TEST_ENTITY, "TestEntity");
    3131
    32   this->md2Model = new MD2Model("../data/models/tris.md2", "../data/models/tris.pcx");
     32  this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
    3333  this->md2Model->debug();
    3434}
     
    3636
    3737TestEntity::~TestEntity ()
    38 {}
     38{
     39  delete this->md2Model;
     40}
    3941
    4042
Note: See TracChangeset for help on using the changeset viewer.