Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5994 in orxonox.OLD for trunk/src/world_entities/world_entity.cc


Ignore:
Timestamp:
Dec 9, 2005, 10:43:31 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: much cleaner Model Loading unloading, model is now private to WorldEntity (not protected)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/world_entity.cc

    r5708 r5994  
    5858WorldEntity::~WorldEntity ()
    5959{
    60   // Delete the model (unregister it with the ResourceManager)
    61   if (likely(this->model != NULL))
    62     ResourceManager::getInstance()->unload(this->model);
    6360  // Delete the obbTree
    6461  if( this->obbTree != NULL)
    6562    delete this->obbTree;
     63
     64  // Delete the model (unregister it with the ResourceManager)
     65  this->setModel(NULL);
    6666}
    6767
     
    9191void WorldEntity::loadModel(const char* fileName, float scaling)
    9292{
    93   if (this->model)
    94     ResourceManager::getInstance()->unload(this->model, RP_LEVEL);
    9593  if (fileName != NULL)
    9694  {
    9795    PRINTF(4)("fetching %s\n", fileName);
    9896    if (scaling == 1.0)
    99       this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN);
     97      this->setModel((Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN));
    10098    else
    101       this->model = (Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, &scaling);
     99      this->setModel((Model*)ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, &scaling));
    102100
    103101    this->buildObbTree(4);
     
    106104    this->model = NULL;
    107105}
     106
     107/**
     108 * sets a specific Model for the Object.
     109 * @param model The Model to set
     110 * @param modelNumber the n'th model in the List to get.
     111 */
     112void WorldEntity::setModel(Model* model, unsigned int modelNumber)
     113{
     114  if (this->model != NULL)
     115  {
     116    Resource* resource = ResourceManager::getInstance()->locateResourceByPointer(this->model);
     117    if (resource != NULL)
     118      ResourceManager::getInstance()->unload(resource, RP_LEVEL);
     119    else
     120      delete this->model;
     121  }
     122  this->model = model;
     123
     124//   if (this->model != NULL) 
     125//     this->buildObbTree(4);
     126}
     127
    108128
    109129/**
Note: See TracChangeset for help on using the changeset viewer.