Changeset 6075 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Dec 13, 2005, 12:09:59 AM (19 years ago)
- Location:
- trunk/src/lib/coord
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r6074 r6075 91 91 ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT)) 92 92 { 93 if (this == PNode:: getNullParent()&& (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT)93 if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULLPARENT) 94 94 delete (*deleteNode); 95 95 else … … 111 111 if (this->toDirection != NULL) 112 112 delete this->toDirection; 113 114 if (this == PNode::nullParent) 115 PNode::nullParent = NULL; 113 116 } 114 117 … … 459 462 { 460 463 if( likely(child->parent != NULL)) 461 {462 PRINTF(5)("PNode::addChild() - reparenting node: removing it and adding it again\n");463 464 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 } 469 478 } 470 479 … … 492 501 if (child != NULL) 493 502 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 */ 510 void 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()); 494 516 } 495 517 … … 508 530 while (child != this->children.end()) 509 531 { 510 reparenter = child++; 532 reparenter = child; 533 child++; 511 534 (*reparenter)->reparent(); 512 535 } … … 526 549 if (parentNode != NULL) 527 550 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); 528 554 } 529 555 … … 537 563 { 538 564 // return if the new parent and the old one match 539 if (this->parent == parentNode )565 if (this->parent == parentNode ) 540 566 return; 567 if (parentNode == NULL) 568 parentNode = PNode::getNullParent(); 541 569 542 570 // store the Valures to iterate to. … … 597 625 } 598 626 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 */ 612 632 void PNode::addNodeModeFlags(unsigned short nodeFlags) 613 633 { … … 615 635 } 616 636 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 */ 618 642 void PNode::removeNodeModeFlags(unsigned short nodeFlags) 619 643 { 620 644 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 */ 657 bool 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; 621 664 } 622 665 … … 632 675 void PNode::updateNode (float dt) 633 676 { 634 if( likely(this->parent != NULL)) 677 if (!(this->parentMode & PNODE_STATIC_NODE)) 678 { 679 if( likely(this->parent != NULL)) 635 680 { 636 if (!(this->parentMode & PNODE_STATIC_NODE))637 {638 681 // movement for nodes with smoothMove enabled 639 682 if (unlikely(this->toCoordinate != NULL)) … … 663 706 delete this->toDirection; 664 707 this->toDirection = NULL; 665 708 PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); 666 709 } 667 710 } … … 670 713 this->lastAbsCoordinate = this->absCoordinate; 671 714 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); 673 717 674 718 … … 682 726 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged)) 683 727 { 684 685 686 728 /* update the current absCoordinate */ 729 this->prevRelCoordinate = this->relCoordinate; 730 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 687 731 } 688 732 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged) 689 733 { 690 734 /* update the current absCoordinate */ 691 692 735 this->prevRelCoordinate = this->relCoordinate; 736 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 693 737 } 694 738 ///////////////////////////////////////////////// 695 739 } 696 } 697 740 741 else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT 698 742 { 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); 702 745 if (this->bRelCoorChanged) 703 746 { … … 733 776 734 777 778 779 780 781 /************* 782 * DEBUGGING * 783 *************/ 735 784 /** 736 785 * @brief counts total amount the children walking through the entire tree. -
trunk/src/lib/coord/p_node.h
r6074 r6075 179 179 180 180 void reparent(); 181 bool checkIntegrity(const PNode* checkParent) const; 181 182 182 183 private:
Note: See TracChangeset
for help on using the changeset viewer.