Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6075 in orxonox.OLD for trunk


Ignore:
Timestamp:
Dec 13, 2005, 12:09:59 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: PNode rearange

Location:
trunk/src/lib/coord
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/coord/p_node.cc

    r6074 r6075  
    9191          ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
    9292      {
    93         if (this == PNode::getNullParent() && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)
     93        if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)
    9494          delete (*deleteNode);
    9595        else
     
    111111  if (this->toDirection != NULL)
    112112    delete this->toDirection;
     113
     114  if (this == PNode::nullParent)
     115    PNode::nullParent = NULL;
    113116}
    114117
     
    459462{
    460463  if( likely(child->parent != NULL))
    461     {
    462       PRINTF(5)("PNode::addChild() - reparenting node: removing it and adding it again\n");
    463464      child->parent->children.remove(child);
    464     }
    465   child->parent = this;
    466   if (unlikely(this != NULL))
    467     this->children.push_back(child);
    468   child->parentCoorChanged();
     465  if (this->checkIntegrity(child))
     466  {
     467    child->parent = this;
     468    if (unlikely(this != NULL))
     469      this->children.push_back(child);
     470    child->parentCoorChanged();
     471  }
     472  else
     473  {
     474    PRINTF(1)("Tried to reparent to own child '%s::%s' to '%s::%s'.\n",
     475              this->getClassName(), this->getName(), child->getClassName(), child->getName());
     476    child->parent = NULL;
     477  }
    469478}
    470479
     
    492501  if (child != NULL)
    493502   child->removeNode();
     503}
     504
     505
     506/**
     507 * !! PRIVATE FUNCTION
     508 * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.)
     509 */
     510void PNode::reparent()
     511{
     512  if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
     513    this->setParent(PNode::getNullParent());
     514  else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
     515    this->setParent(this->parent->getParent());
    494516}
    495517
     
    508530    while (child != this->children.end())
    509531    {
    510       reparenter = child++;
     532      reparenter = child;
     533      child++;
    511534      (*reparenter)->reparent();
    512535    }
     
    526549  if (parentNode != NULL)
    527550    parentNode->addChild(this);
     551  else
     552    PRINTF(2)("Not Found PNode's (%s::%s) new Parent by Name: %s\n",
     553              this->getClassName(), this->getName(), parentName);
    528554}
    529555
     
    537563{
    538564  // return if the new parent and the old one match
    539   if (this->parent == parentNode)
     565  if (this->parent == parentNode )
    540566    return;
     567  if (parentNode == NULL)
     568    parentNode = PNode::getNullParent();
    541569
    542570  // store the Valures to iterate to.
     
    597625}
    598626
    599 
    600 /**
    601  * !!PRIVATE FUNCTION:
    602  * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.)
    603  */
    604 void PNode::reparent()
    605 {
    606   if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT)
    607     this->setParent(PNode::getNullParent());
    608   else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL)
    609     this->setParent(this->parent->getParent());
    610 }
    611 
     627/**
     628 * @brief adds special mode Flags to this PNode
     629 * @see PARENT_MODE
     630 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
     631 */
    612632void PNode::addNodeModeFlags(unsigned short nodeFlags)
    613633{
     
    615635}
    616636
    617 
     637/**
     638 * @brief removes special mode Flags to this PNode
     639 * @see PARENT_MODE
     640 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator.
     641 */
    618642void PNode::removeNodeModeFlags(unsigned short nodeFlags)
    619643{
    620644  this->parentMode &= !nodeFlags;
     645}
     646
     647
     648/**
     649 * !! PRIVATE FUNCTION
     650 * @brief checks the upward integrity (e.g if PNode is somewhere up the Node tree.)
     651 * @param checkParent the Parent to check.
     652 * @returns true if the integrity-check succeeds, false otherwise.
     653 *
     654 * If there is a second occurence of checkParent before NULL, then a loop could get
     655 * into the Tree, and we do not want this.
     656 */
     657bool PNode::checkIntegrity(const PNode* checkParent) const
     658{
     659  const PNode* parent = this;
     660  while ( (parent = parent->getParent()) != NULL)
     661    if (unlikely(parent == checkParent))
     662      return false;
     663  return true;
    621664}
    622665
     
    632675void PNode::updateNode (float dt)
    633676{
    634   if( likely(this->parent != NULL))
     677  if (!(this->parentMode & PNODE_STATIC_NODE))
     678  {
     679    if( likely(this->parent != NULL))
    635680    {
    636       if (!(this->parentMode & PNODE_STATIC_NODE))
    637       {
    638681        // movement for nodes with smoothMove enabled
    639682        if (unlikely(this->toCoordinate != NULL))
     
    663706            delete this->toDirection;
    664707            this->toDirection = NULL;
    665              PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
     708            PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
    666709          }
    667710        }
     
    670713        this->lastAbsCoordinate = this->absCoordinate;
    671714
    672         PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
     715        PRINTF(5)("PNode::update - '%s::%s' - (%f, %f, %f)\n", this->getClassName(), this->getName(),
     716                      this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    673717
    674718
     
    682726        if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
    683727        {
    684          /* update the current absCoordinate */
    685          this->prevRelCoordinate = this->relCoordinate;
    686          this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
     728        /* update the current absCoordinate */
     729        this->prevRelCoordinate = this->relCoordinate;
     730        this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
    687731        }
    688732        else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
    689733        {
    690734          /* update the current absCoordinate */
    691          this->prevRelCoordinate = this->relCoordinate;
    692          this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
     735        this->prevRelCoordinate = this->relCoordinate;
     736        this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
    693737        }
    694738        /////////////////////////////////////////////////
    695739      }
    696   }
    697    else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT
     740
     741  else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT
    698742    {
    699       if (!(this->parentMode & PNODE_STATIC_NODE))
    700       {
    701         PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
     743      PRINTF(4)("update ParentLess Node (%s::%s) - (%f, %f, %f)\n", this->getClassName(), this->getName(),
     744                this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    702745        if (this->bRelCoorChanged)
    703746        {
     
    733776
    734777
     778
     779
     780
     781/*************
     782 * DEBUGGING *
     783 *************/
    735784/**
    736785 * @brief counts total amount the children walking through the entire tree.
  • trunk/src/lib/coord/p_node.h

    r6074 r6075  
    179179
    180180  void reparent();
     181  bool checkIntegrity(const PNode* checkParent) const;
    181182
    182183 private:
Note: See TracChangeset for help on using the changeset viewer.