Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10314 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jan 24, 2007, 12:45:39 AM (18 years ago)
Author:
patrick
Message:

merged branche mount_point to trunk. this will add mount point abilities, bsp transparency fix and some other smaller stuff to this trunk

Location:
trunk/src/world_entities
Files:
4 edited

Legend:

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

    r10147 r10314  
    1010
    1111   ### File Specific
    12    main-programmer: Patrick Boenzli patrick@orxonox.net
     12   main-programmer: Patrick Boenzli, patrick@orxonox.net
    1313   co-programmer:
    1414*/
     
    1919#include "util/loading/factory.h"
    2020#include "util/loading/load_param.h"
     21#include "util/loading/load_param_xml.h"
     22
    2123
    2224
     
    2729
    2830ObjectListDefinition(MountPoint);
    29 CREATE_FACTORY(MountPoint);
    3031
    3132
     
    3334 * construct
    3435 */
    35 MountPoint::MountPoint ()
    36 {
     36MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name)
     37{
     38  PRINTF(5)("Created mount point %s\n", name.c_str());
     39
     40  this->_name = name;
     41  this->setAbsCoor( center);
     42  this->setAbsDir( Quaternion(forward, up));
     43
    3744  this->init();
    3845}
    3946
    40 
    41 /**
    42  * constructor
    43  * @param root the xml root element
    44  */
    45 MountPoint::MountPoint(const TiXmlElement* root)
    46 {
    47   this->init();
    48 
    49   if( root != NULL)
    50     this->loadParams(root);
    51 }
    5247
    5348
     
    7570 * @param root the XML-element to load the MD2Creature's properties from
    7671 */
    77 void MountPoint::loadParams(const TiXmlElement* root)
    78 {
    79   WorldEntity::loadParams(root);
     72void MountPoint::initMountPoint(const TiXmlElement* root)
     73{
     74  if( root == NULL)
     75  {
     76    PRINTF(1)("MountPoint - initialization failed, since I got no valid xml element\n");
     77    return;
     78  }
     79  // now get the first element
     80  const TiXmlElement* element = root->FirstChildElement("MountPoints");
     81  if( element == NULL)
     82  {
     83    PRINTF(1)("I am in section: %s, Object Information file is missing a proper 'MountPoints' section\n", root->Value());
     84//     element = root->FirstChildElement( );
     85//     PRINTF(0)("first child: %s\n", element->Value());
     86  }
     87  else
     88  {
     89    element = element->FirstChildElement();
     90    // parse the information for this mount point
     91
     92    PRINTF(4)("Loading WorldEntities\n");
     93    while( element != NULL)
     94    {
     95      std::string name = element->Value();
     96
     97      PRINTF(5)("checking %s against local %s\n", name.c_str(), this->_name.c_str());
     98      // check if we got the right mount point
     99      if( this->_name.find(name, 0) != std::string::npos)
     100      {
     101        PRINTF(5)("found mount point %s\n", this->_name.c_str());
     102        // load it
     103        this->loadParam(element);
     104      }
     105
     106      element = element->NextSiblingElement();
     107    }
     108  }
     109}
     110
     111
     112
     113/**
     114 * load the parameters from the xml section
     115 * @param root the root element of this xml branche
     116 */
     117void MountPoint::loadParam(const TiXmlElement* root)
     118{
     119  // first check for the description
     120  LoadParam(root, "Description", this, MountPoint, setDescription)
     121  .describe("Sets this mount point a description");
     122
     123  // now check for the orx class to create
     124  LoadParam(root, "OrxClass", this, MountPoint, setOrxClass)
     125  .describe("Sets the class this mount points should host");
     126
     127  LoadParamXML(root, "Details", this, MountPoint, loadDetails);
     128}
     129
     130
     131/**
     132 * load the parameters from the world entity
     133 * @param root the root element of this xml branche
     134 */
     135void MountPoint::loadDetails(const TiXmlElement* root)
     136{
     137  if( this->_mount != NULL)
     138  {
     139    PRINTF(0)("Got detail informations\n");
     140    this->_mount->loadParams( root);
     141  }
     142}
     143
     144
     145/**
     146 * setst the description (optional) via xml tag
     147 * @param description string containing the description
     148 */
     149void MountPoint::setDescription(const std::string& description)
     150{
     151  this->_description = description;
     152}
     153
     154
     155
     156/**
     157 * sets the class of this mount point
     158 * @param orxClass class
     159 */
     160void MountPoint::setOrxClass(const std::string& orxClass)
     161{
     162  // create the object for this mount point
     163  BaseObject* obj = Factory::fabricate(orxClass);
     164  // check if the object is created correctly
     165  if( obj != NULL)
     166  {
     167    if( obj->isA( WorldEntity::staticClassID()))
     168    {
     169      // cast down the object to WE
     170      this->_mount = dynamic_cast<WorldEntity*>(obj);
     171
     172      // now set the position, direction and reparent it to this node
     173      this->_mount->setAbsCoor( this->getAbsCoor());
     174      this->_mount->setAbsDir( this->getAbsDir());
     175      this->_mount->setParent( this);
     176
     177      this->_mount->toList( (OM_LIST)(this->getOMListNumber()+1));
     178    }
     179  }
     180  else
     181    PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str());
    80182}
    81183
     
    89191{
    90192
    91 
    92193}
    93194
     
    98199void MountPoint::draw() const
    99200{
    100 
    101201}
    102202
     
    108208void MountPoint::debugDraw() const
    109209{
    110 
     210  // invoke the underlying pnode debug draw
     211  this->debugDraw();
    111212}
    112213
  • trunk/src/world_entities/mount_point.h

    r10147 r10314  
    1212
    1313  public:
    14     MountPoint ();
    15     MountPoint(const TiXmlElement* root);
     14    MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name);
    1615    virtual ~MountPoint ();
    1716
    1817    void init();
    19     virtual void loadParams(const TiXmlElement* root);
     18    void initMountPoint(const TiXmlElement* root);
     19    void loadParam(const TiXmlElement* root);
     20    void loadDetails(const TiXmlElement* root);
    2021
     22    void setDescription(const std::string& description);
     23    void setOrxClass(const std::string& orxClass);
    2124
    2225    virtual void tick (float time);
     
    3235  private:
    3336    WorldEntity*         _mount;       //!< the entity mounted at this mount point
     37    std::string          _name;        //!< the name of the mount point
     38
     39    std::string          _description; //!< string containing an optional description
    3440
    3541};
  • trunk/src/world_entities/world_entity.cc

    r10147 r10314  
    1212
    1313   ### File Specific:
    14    main-programmer: Patrick Boenzli, Benjamin Grauer
    15    co-programmer: Christian Meier
     14   main-programmer: Patrick Boenzli
     15   main-programmer: Benjamin Grauer
     16   co-programmer:   Christian Meier
    1617*/
    1718#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     
    7374  this->scaling = 1.0f;
    7475  this->oiFile = NULL;
     76  // add 10 members to this array
     77  this->mountPoints.reserve(10);
    7578
    7679  /* OSOLETE */
     
    141144  .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
    142145  .defaultValues("", 1.0f, 0);
     146
     147  LoadParam(root, "mountpoints", this, WorldEntity, loadMountPoints)
     148  .describe("the fileName of the object information file (optional)");
    143149
    144150  LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax)
     
    204210      StaticModel* model = new StaticModel();
    205211      *model = ResourceOBJ(fileName, this->scaling);
     212
     213      // check if ther is a valid model and load other stuff
    206214      if (model->getVertexCount() > 0)
    207215      {
    208216        this->setModel(model, modelNumber);
    209         if( modelNumber == 0 /* FIXME && !this->isA(CL_WEAPON) */)
     217
     218        if( modelNumber == 0)
     219        {
    210220          this->buildObbTree(obbTreeDepth);
     221        }
    211222      }
    212223      else
    213224        delete model;
    214 
    215       // now get the object information file for this model, if any
    216       std::string oifName = fileName.substr(0, fileName.length() - 4) + ".oif";
    217       this->loadObjectInformationFile( oifName);
    218225    }
    219226    /// LOADING AN MD2-model
     
    269276 * @param fileName the name of the file
    270277 */
    271 void WorldEntity::loadObjectInformationFile(const std::string& fileName)
    272 {
    273   PRINTF(4)("loading the oif File: %s\n", fileName.c_str());
    274 
     278void WorldEntity::loadMountPoints(const std::string& fileName)
     279{
     280  PRINTF(5)("loading the oif File: %s\n", fileName.c_str());
     281
     282  // now load the object information file
    275283  this->oiFile = new ObjectInformationFile(fileName);
     284
     285  // get the model to load
     286  Model* model = this->getModel();
     287
     288  // extract the mount points
     289  model->extractMountPoints();
     290
     291  // first get all mount points from the model
     292  const std::list<mountPointSkeleton> mpList = model->getMountPoints();
     293  // for each skeleton create a mounting point world entity
     294  std::list<mountPointSkeleton>::const_iterator it = mpList.begin();
     295
     296  for( ; it != mpList.end(); it++)
     297  {
     298    // create the mount points world entity
     299    MountPoint* mp = new MountPoint( (*it).up, (*it).forward, (*it).center, (*it).name);
     300    // parent it to this WE
     301    mp->setParent( this);
     302    // now add to the right group
     303    mp->toList( (OM_LIST)(this->getOMListNumber()+1));
     304    // now get the number and add the mount point to the slot
     305    std::string nrStr = (*it).name.substr(3, 2);
     306    // add the mount point
     307    this->addMountPoint(atoi(nrStr.c_str()), mp);
     308
     309    // now fill the mount point
     310    mp->initMountPoint( this->oiFile->getMountPointDescription());
     311  }
     312
    276313}
    277314
     
    337374void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint)
    338375{
    339   if( this->mountPoints[slot] != NULL)
    340   {
    341     PRINTF(0)("adding a mount point to a slot, that already exists! ignoring - maybe some object do not get connected well (object: %s)\n", this->getClassCName());
     376  if( this->mountPoints.capacity() < (unsigned int)slot)
     377  {
     378    // reserve 5 more slots than needed so this function is called as rare as possible
     379    this->mountPoints.reserve(slot + 5);
     380  }
     381  else if( this->mountPoints[slot] != NULL)
     382  {
     383    PRINTF(4)("adding a mount point to a slot, that already is occupied! ignoring - maybe some object did not get connected well (object: %s)\n", this->getClassCName());
    342384  }
    343385
     
    794836
    795837
     838
     839/**
     840 * draw the mounting points
     841 */
     842void WorldEntity::debugDrawMountPoints() const
     843{
     844
     845  std::vector<MountPoint*>::const_iterator it = this->mountPoints.begin();
     846  for( ; it < this->mountPoints.end(); it++)
     847  {
     848    if( (*it) != NULL)
     849    {
     850      (*it)->debugDraw();
     851    }
     852  }
     853}
     854
     855
    796856/**
    797857 * Debug the WorldEntity
  • trunk/src/world_entities/world_entity.h

    r10147 r10314  
    5353  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
    5454
    55   void loadObjectInformationFile(const std::string& fileName);
     55  void loadMountPoints(const std::string& fileName);
    5656  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
    5757
     
    7373  virtual void tick (float time);
    7474  virtual void draw () const;
     75  void debugDrawMountPoints() const;
    7576
    7677  /* --- Collision Detection Block  --- */
Note: See TracChangeset for help on using the changeset viewer.