Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5994 in orxonox.OLD for trunk/src


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

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

Location:
trunk/src
Files:
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/particles/particle_system.cc

    r5944 r5994  
    383383      break;
    384384    case PARTICLE_MODEL:
    385       if (this->model)
    386         return this->count * this->model->getFaceCount();
     385      if (this->getModel(0))
     386        return this->count * this->getModel()->getFaceCount();
    387387      break;
    388388  }
     
    483483        GLfloat matrix[4][4];
    484484
    485         if (likely(this->model != NULL))
     485        if (likely(this->getModel() != NULL))
    486486          while (likely(drawPart != NULL))
    487487        {
     
    496496          glMultMatrixf((float*)matrix);
    497497
    498           this->model->draw();
     498          this->getModel()->draw();
    499499
    500500          glPopMatrix();
  • trunk/src/lib/sound/sound_engine.cc

    r5982 r5994  
    289289  }
    290290  // INITIALIZING THE DEVICE:
    291 #ifndef AL_VERSION_1_1
     291#ifdef AL_VERSION_1_1
    292292  ALubyte deviceName[] =
    293293#else
  • trunk/src/util/loading/resource_manager.cc

    r5930 r5994  
    606606}
    607607
     608
    608609/**
    609610 * Searches for a Resource by some information
     
    616617*/
    617618Resource* ResourceManager::locateResourceByInfo(const char* fileName, ResourceType type,
    618                                                 void* param1, void* param2, void* param3)
     619                                                void* param1, void* param2, void* param3) const
    619620{
    620621  //  Resource* enumRes = resourceList->enumerate();
     
    692693 * @returns a Pointer to the Resource if found, NULL otherwise.
    693694*/
    694 Resource* ResourceManager::locateResourceByPointer(const void* pointer)
     695Resource* ResourceManager::locateResourceByPointer(const void* pointer) const
    695696{
    696697  //  Resource* enumRes = resourceList->enumerate();
  • trunk/src/util/loading/resource_manager.h

    r5480 r5994  
    119119  bool unloadAllByPriority(ResourcePriority prio);
    120120
     121  Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3) const;
     122  Resource* locateResourceByPointer(const void* pointer) const;
     123
    121124  void debug() const;
    122125
     
    137140  ResourceManager();
    138141
    139   Resource* locateResourceByInfo(const char* fileName, ResourceType type, void* param1, void* param2, void* param3);
    140   Resource* locateResourceByPointer(const void* pointer);
    141 
    142142 private:
    143143  static ResourceManager*  singletonRef;       //!< singleton Reference
  • trunk/src/world_entities/environment.cc

    r5750 r5994  
    3737  this->init();
    3838  this->loadModel("models/ships/bolido.obj");
    39 
    40   if(this->obbTree == NULL)
    41     this->obbTree = new OBBTree(4, (sVec3D*)this->model->getVertexArray(), this->model->getVertexCount());
    4239}
    4340
     
    8481
    8582
    86 /**
    87  *  draws the Environment
    88 */
    89 void Environment::draw () const
    90 {
    91   glMatrixMode(GL_MODELVIEW);
    92   glPushMatrix();
    93   float matrix[4][4];
    94 
    95   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
    96   //rotate
    97   this->getAbsDir().matrix (matrix);
    98   glMultMatrixf((float*)matrix);
    99 
    100   this->model->draw();
    101 
    102   glPopMatrix();
    103 }
    104 
  • trunk/src/world_entities/environment.h

    r5500 r5994  
    3030  virtual void tick (float time);
    3131
    32   virtual void draw () const;
    33 
    3432};
    3533
  • trunk/src/world_entities/power_ups/laser_power_up.cc

    r5915 r5994  
    112112  Vector tmpRot = this->getAbsDir().getSpacialAxis();
    113113  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    114   this->model->draw();
     114  this->getModel()->draw();
    115115
    116116  this->sphereMaterial->select();
  • trunk/src/world_entities/power_ups/turret_power_up.cc

    r5915 r5994  
    112112  Vector tmpRot = this->getAbsDir().getSpacialAxis();
    113113  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    114   this->model->draw();
     114  this->getModel()->draw();
    115115
    116116  this->sphereMaterial->select();
  • trunk/src/world_entities/satellite.cc

    r5500 r5994  
    3434  this->setClassID(CL_SATELLITE, "Satellite");
    3535
    36   this->model = (Model*) ResourceManager::getInstance()->load("cube", RP_LEVEL);
     36  this->loadModel("cube");
    3737  this->speed = speed;
    3838  this->axis = new Vector();
     
    6464}
    6565
    66 
    67 /**
    68  *  the entity is drawn onto the screen with this function
    69 
    70    This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
    71 */
    72 void Satellite::draw() const
    73 {
    74   glMatrixMode(GL_MODELVIEW);
    75   glPushMatrix();
    76   float matrix[4][4];
    77 
    78   /* translate */
    79   glTranslatef (this->getAbsCoor ().x,
    80                 this->getAbsCoor ().y,
    81                 this->getAbsCoor ().z);
    82   /* rotate */
    83   this->getAbsDir ().matrix (matrix);
    84   glMultMatrixf((float*)matrix);
    85 
    86   this->model->draw();
    87   glPopMatrix();
    88 
    89 }
    90 
  • trunk/src/world_entities/satellite.h

    r5500 r5994  
    2525  virtual ~Satellite ();
    2626
    27   virtual void draw () const;
    2827  virtual void tick (float time);
    2928
  • trunk/src/world_entities/skybox.cc

    r5750 r5994  
    9292{
    9393  PRINTF(5)("Deleting SkyBox\n");
     94  this->setModel(NULL); //< so that WorldEntity does not try to delete it again.
    9495  for (int i = 0; i < 6; i++)
    9596    delete this->material[i];
    9697  delete[] this->material;
    97   delete this->model;
    98   this->model = NULL; //< so that WorldEntity does not try to delete it again.
    99 }
     98 }
    10099
    101100/**
     
    171170void SkyBox::rebuild()
    172171{
    173   if (this->model)
    174     delete this->model;
    175   model = new Model();
    176 
    177   this->model->addVertex (-0.5*size, -0.5*size, 0.5*size);
    178   this->model->addVertex (0.5*size, -0.5*size, 0.5*size);
    179   this->model->addVertex (-0.5*size, 0.5*size, 0.5*size);
    180   this->model->addVertex (0.5*size, 0.5*size, 0.5*size);
    181   this->model->addVertex (-0.5*size, 0.5*size, -0.5*size);
    182   this->model->addVertex (0.5*size, 0.5*size, -0.5*size);
    183   this->model->addVertex (-0.5*size, -0.5*size, -0.5*size);
    184   this->model->addVertex (0.5*size, -0.5*size, -0.5*size);
    185 
    186   this->model->addVertexTexture (0.0, 1.0);
    187   this->model->addVertexTexture (1.0, 1.0);
    188   this->model->addVertexTexture (1.0, 0.0);
    189   this->model->addVertexTexture (0.0, 0.0);
    190 
    191   this->model->addVertexNormal (0.0, 0.0, 1.0);
    192   this->model->addVertexNormal (0.0, 1.0, 0.0);
    193   this->model->addVertexNormal (0.0, 0.0, -1.0);
    194   this->model->addVertexNormal (0.0, -1.0, 0.0);
    195   this->model->addVertexNormal (1.0, 0.0, 0.0);
    196   this->model->addVertexNormal (-1.0, 0.0, 0.0);
    197 
    198   this->model->setMaterial(material[0]);
    199   this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,0,3, 3,1,3, 5,2,3, 4,3,3); // top
    200   this->model->setMaterial(material[1]);
    201   this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,1, 7,1,1, 1,2,1, 0,3,1); // bottom
    202   this->model->setMaterial(material[2]);
    203   this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,2, 5,3,2, 7,0,2, 6,1,2); // left
    204   this->model->setMaterial(material[3]);
    205   this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,0, 3,2,0, 2,3,0); // right
    206   this->model->setMaterial(material[4]);
    207   this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,5); // front
    208   this->model->setMaterial(material[5]);
    209   this->model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back
    210 
    211   this->model->finalize();
    212 }
     172  Model* model = new Model();
     173
     174  model->addVertex (-0.5*size, -0.5*size, 0.5*size);
     175  model->addVertex (0.5*size, -0.5*size, 0.5*size);
     176  model->addVertex (-0.5*size, 0.5*size, 0.5*size);
     177  model->addVertex (0.5*size, 0.5*size, 0.5*size);
     178  model->addVertex (-0.5*size, 0.5*size, -0.5*size);
     179  model->addVertex (0.5*size, 0.5*size, -0.5*size);
     180  model->addVertex (-0.5*size, -0.5*size, -0.5*size);
     181  model->addVertex (0.5*size, -0.5*size, -0.5*size);
     182
     183  model->addVertexTexture (0.0, 1.0);
     184  model->addVertexTexture (1.0, 1.0);
     185  model->addVertexTexture (1.0, 0.0);
     186  model->addVertexTexture (0.0, 0.0);
     187
     188  model->addVertexNormal (0.0, 0.0, 1.0);
     189  model->addVertexNormal (0.0, 1.0, 0.0);
     190  model->addVertexNormal (0.0, 0.0, -1.0);
     191  model->addVertexNormal (0.0, -1.0, 0.0);
     192  model->addVertexNormal (1.0, 0.0, 0.0);
     193  model->addVertexNormal (-1.0, 0.0, 0.0);
     194
     195  model->setMaterial(material[0]);
     196  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,0,3, 3,1,3, 5,2,3, 4,3,3); // top
     197  model->setMaterial(material[1]);
     198  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,1, 7,1,1, 1,2,1, 0,3,1); // bottom
     199  model->setMaterial(material[2]);
     200  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,2, 5,3,2, 7,0,2, 6,1,2); // left
     201  model->setMaterial(material[3]);
     202  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,0, 3,2,0, 2,3,0); // right
     203  model->setMaterial(material[4]);
     204  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,5); // front
     205  model->setMaterial(material[5]);
     206  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back
     207
     208  model->finalize();
     209
     210  this->setModel(model);
     211}
  • trunk/src/world_entities/space_ships/space_ship.cc

    r5982 r5994  
    250250  Vector tmpRot = this->getAbsDir().getSpacialAxis();
    251251  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    252   this->model->draw();
     252  this->getModel()->draw();
    253253  glPopMatrix();
    254254
  • trunk/src/world_entities/terrain.cc

    r5750 r5994  
    138138  if (this->objectList)
    139139    glCallList(this->objectList);
    140   else if (this->model)
    141     this->model->draw();
     140  else if (this->getModel())
     141    this->getModel()->draw();
    142142  if (this->vegetation)
    143143    this->vegetation->draw();
  • trunk/src/world_entities/test_entity.cc

    r5500 r5994  
    3737//   this->md2Model = new MD2Model("models/tris.md2", "models/tris.pcx");
    3838// this->md2Model = new MD2Model("models/goblin.md2", "maps/goblin.bmp");
    39   this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
     39
     40/// FIXME
     41//  this->obbTree = new OBBTree(4, (sVec3D*)this->md2Model->data->pVertices, this->md2Model->data->numVertices);
    4042
    4143  this->md2Model->setAnim(RUN);
  • trunk/src/world_entities/weapons/aiming_turret.cc

    r5930 r5994  
    169169  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    170170
    171   this->model->draw();
     171  this->getModel()->draw();
    172172  glPopMatrix();
    173173}
  • trunk/src/world_entities/weapons/bomb.cc

    r5828 r5994  
    147147  if (this->lifeCycle < .9)
    148148  {
    149     if (model)
    150       model->draw();
     149    if (this->getModel() != NULL)
     150      this->getModel()->draw();
    151151  }
    152152  else
  • trunk/src/world_entities/weapons/cannon.cc

    r5930 r5994  
    194194  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    195195
    196   this->model->draw();
     196  this->getModel()->draw();
    197197  glPopMatrix();
    198198
  • trunk/src/world_entities/weapons/ground_turret.cc

    r5982 r5994  
    128128  glMultMatrixf((float*)matrix);
    129129
    130   if (this->model)
    131     this->model->draw();
     130  if (this->getModel())
     131    this->getModel()->draw();
    132132
    133133  glPopMatrix();
  • trunk/src/world_entities/weapons/guided_missile.cc

    r5915 r5994  
    202202  glMultMatrixf((float*)matrix);
    203203  glScalef(2.0, 2.0, 2.0);
    204   this->model->draw();
     204  this->getModel()->draw();
    205205
    206206  glPopMatrix();
  • trunk/src/world_entities/weapons/laser.cc

    r5779 r5994  
    156156  glMultMatrixf((float*)matrix);
    157157  glScalef(2.0, 2.0, 2.0);
    158   this->model->draw();
     158  this->getModel()->draw();
    159159  glPopAttrib();
    160160  glPopMatrix();
  • trunk/src/world_entities/weapons/projectile.cc

    r5769 r5994  
    137137{}
    138138
    139 
    140 void Projectile::draw () const
    141 {
    142   glMatrixMode(GL_MODELVIEW);
    143   glPushMatrix();
    144 
    145   float matrix[4][4];
    146   glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
    147   this->getAbsDir().matrix (matrix);
    148   glMultMatrixf((float*)matrix);
    149   this->model->draw();
    150 
    151   glPopMatrix();
    152 }
    153 
  • trunk/src/world_entities/weapons/projectile.h

    r5766 r5994  
    4141
    4242    virtual void tick (float time);
    43     virtual void draw () const;
    4443
    4544  protected:
  • trunk/src/world_entities/weapons/rocket.cc

    r5819 r5994  
    187187  glMultMatrixf((float*)matrix);
    188188  glScalef(2.0, 2.0, 2.0);
    189   this->model->draw();
     189  this->getModel()->draw();
    190190
    191191  glPopMatrix();
  • trunk/src/world_entities/weapons/test_bullet.cc

    r5779 r5994  
    181181  glMultMatrixf((float*)matrix);
    182182  glScalef(2.0, 2.0, 2.0);
    183   this->model->draw();
     183  this->getModel()->draw();
    184184
    185185  glPopMatrix();
  • trunk/src/world_entities/weapons/test_gun.cc

    r5930 r5994  
    219219  if( this->leftRight == W_RIGHT)
    220220    glScalef(1.0, 1.0, -1.0);
    221   this->model->draw(1);
     221  this->getModel()->draw(1);
    222222  glPopMatrix();
    223223
     
    230230  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
    231231  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    232   this->model->draw(0);
     232  this->getModel()->draw(0);
    233233  glPopMatrix();
    234234}
  • trunk/src/world_entities/weapons/turret.cc

    r5930 r5994  
    147147void Turret::destroy ()
    148148{}
    149 
    150 /**
    151  * draws the Turret
    152 */
    153 void Turret::draw () const
    154 {
    155   if (this->model != NULL)
    156   {
    157     /* draw gun body */
    158     glMatrixMode(GL_MODELVIEW);
    159     glPushMatrix();
    160     glTranslatef (this->getAbsCoor ().x,
    161                   this->getAbsCoor ().y,
    162                   this->getAbsCoor ().z);
    163     Vector tmpRot = this->getAbsDir().getSpacialAxis();
    164     glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    165 
    166     this->model->draw();
    167     glPopMatrix();
    168   }
    169 }
  • trunk/src/world_entities/weapons/turret.h

    r5750 r5994  
    2626    virtual void destroy();
    2727
    28     virtual void draw() const;
    2928
    3029  private:
  • 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/**
  • trunk/src/world_entities/world_entity.h

    r5511 r5994  
    2828
    2929  void loadParams(const TiXmlElement* root);
     30
    3031  void loadModel(const char* fileName, float scaling = 1.0f);
     32  void setModel(Model* model, unsigned int modelNumber = 0);
     33  Model* getModel(unsigned int modelNumber = 0) const { return this->model; };
     34
    3135  bool buildObbTree(unsigned int depth);
     36  /** @returns a reference to the obb tree of this worldentity */
     37  BVTree* getOBBTree() const { return this->obbTree; };
    3238
    3339  /** @param visibility if the Entity should be visible (been draw) */
     
    4652
    4753  void drawBVTree(unsigned int depth, int drawMode) const;
    48   /** @returns a reference to the obb tree of this worldentity */
    49   BVTree* getOBBTree() const { return this->obbTree; };
    5054
    5155  /* @returns the Count of Faces on this WorldEntity */
     
    5862
    5963 protected:
    60   Model*                  model;            //!< The model that should be loaded for this entity.
    61   BVTree*                 obbTree;          //!< this is the obb tree reference needed for collision detection
    6264  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
    6365
    6466 private:
     67  Model*                  model;            //!< The model that should be loaded for this entity.
     68  BVTree*                 obbTree;          //!< this is the obb tree reference needed for collision detection
     69
    6570  bool                    bCollide;         //!< If it should be considered for the collisiontest.
    6671  bool                    bVisible;         //!< If it should be visible.
Note: See TracChangeset for help on using the changeset viewer.