- Timestamp:
- Dec 13, 2005, 2:55:08 AM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r6075 r6078 21 21 #include "class_list.h" 22 22 23 #include <algorithm> 23 24 #include "compiler.h" 24 25 #include "debug.h" … … 32 33 /** 33 34 * @brief standard constructor 34 */ 35 PNode::PNode (PNode* parent) 36 { 37 init(); 38 if (parent != NULL) 39 parent->addChild(this); 40 } 41 42 /** 43 * @brief initializes a PNode 44 * @param parent the parent for this PNode 45 */ 46 void PNode::init() 35 * @param parent the Parent of this Node. __NULL__ if __No Parent__ requested, PNode::getNullParent(), if connected to NullParent directly (default) 36 * @param nodeFlags all flags to set. THIS_WILL_OVERWRITE Default_Values. look at creation of NullParent for more Info. 37 */ 38 PNode::PNode (PNode* parent, long nodeFlags) 47 39 { 48 40 this->setClassID(CL_PARENT_NODE, "PNode"); … … 51 43 this->bRelDirChanged = true; 52 44 this->parent = NULL; 53 this->parentMode = PNODE_PARENT_MODE_DEFAULT;45 this->parentMode = nodeFlags; 54 46 this->bActive = true; 55 47 … … 58 50 this->toDirection = NULL; 59 51 this->bias = 1.0; 52 53 if (parent != NULL) 54 parent->addChild(this); 60 55 } 61 56 … … 87 82 deleteNode = tmp; 88 83 ++tmp; 89 printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());84 // printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName()); 90 85 if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || 91 86 ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT)) 92 87 { 93 if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL PARENT)88 if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL) 94 89 delete (*deleteNode); 95 90 else … … 102 97 if (this->parent != NULL) 103 98 { 104 this->parent-> children.remove(this);99 this->parent->eraseChild(this); 105 100 this->parent = NULL; 106 101 } … … 462 457 { 463 458 if( likely(child->parent != NULL)) 464 child->parent-> children.remove(child);459 child->parent->eraseChild(child); 465 460 if (this->checkIntegrity(child)) 466 461 { … … 510 505 void PNode::reparent() 511 506 { 512 if (this->parentMode & PNODE_REPARENT_TO_NULL PARENT)513 this->setParent( PNode::getNullParent());507 if (this->parentMode & PNODE_REPARENT_TO_NULL) 508 this->setParent((PNode*)NULL); 514 509 else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL) 515 510 this->setParent(this->parent->getParent()); 511 else 512 this->setParent(PNode::getNullParent()); 513 } 514 515 void PNode::eraseChild(PNode* child) 516 { 517 std::list<PNode*>::iterator childRemover = std::find(this->children.begin(), this->children.end(), child); 518 if(childRemover != this->children.end()) 519 this->children.erase(childRemover); 516 520 } 517 521 … … 524 528 void PNode::removeNode() 525 529 { 526 if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE) 527 { 528 list<PNode*>::iterator child = this->children.begin(); 529 list<PNode*>::iterator reparenter; 530 while (child != this->children.end()) 531 { 532 reparenter = child; 533 child++; 530 list<PNode*>::iterator child = this->children.begin(); 531 list<PNode*>::iterator reparenter; 532 while (child != this->children.end()) 533 { 534 reparenter = child; 535 child++; 536 if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE || 537 (*reparenter)->parentMode & PNODE_REPARENT_ON_PARENTS_REMOVE) 538 { printf("TEST----------------%s ---- %s\n", this->getClassName(), (*reparenter)->getClassName()); 534 539 (*reparenter)->reparent(); 540 printf("REPARENTED TO: %s::%s\n",(*reparenter)->getParent()->getClassName(),(*reparenter)->getParent()->getName()); 535 541 } 536 542 } 537 543 if (this->parent != NULL) 538 this->parent-> children.remove(this);544 this->parent->eraseChild(this); 539 545 } 540 546 … … 630 636 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator. 631 637 */ 632 void PNode::addNode ModeFlags(unsigned short nodeFlags)638 void PNode::addNodeFlags(unsigned short nodeFlags) 633 639 { 634 640 this->parentMode |= nodeFlags; … … 640 646 * @param nodeFlags a compsition of PARENT_MODE-flags, split by the '|' (or) operator. 641 647 */ 642 void PNode::removeNode ModeFlags(unsigned short nodeFlags)648 void PNode::removeNodeFlags(unsigned short nodeFlags) 643 649 { 644 650 this->parentMode &= !nodeFlags; 651 } 652 653 /** 654 * @returns the NullParent (and if needed creates it) 655 */ 656 PNode* PNode::createNullParent() 657 { 658 if (likely(PNode::nullParent == NULL)) 659 { 660 PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL); 661 PNode::nullParent->setName("NullParent"); 662 } 663 return PNode::nullParent; 645 664 } 646 665 -
trunk/src/lib/coord/p_node.h
r6075 r6078 43 43 44 44 // REPARENTING 45 PNODE_REPARENT_TO_NULL PARENT = 0x0010, //!< Reparents to the NullParent, if the Parent is Removed.45 PNODE_REPARENT_TO_NULL = 0x0010, //!< Reparents to the Null, if the Parent is Removed. Meaning the Node wont have a parent anymore. 46 46 PNODE_REPARENT_TO_PARENTS_PARENT = 0x0020, //!< Reparents the Node to the parents (old) parent it the parent gets removed. 47 ///////////////////////////////////////////// // ELSE: Reparents to the NullParent. 47 48 PNODE_REPARENT_DELETE_CHILDREN = 0x0040, //!< Deletes the Children of the node when This Node is Removed. (Use with care). 48 49 /// FIXME … … 54 55 PNODE_PROHIBIT_DELETE_WITH_PARENT = 0x0200, //!< Prohibits the Node to be deleted if the Parent is. Child will be reparented according to the Repaenting-Rules 55 56 PNODE_REPARENT_CHILDREN_ON_REMOVE = 0x0400, //!< Reparents the Children of the Node if the Node gets Removed. 57 PNODE_REPARENT_ON_PARENTS_REMOVE = 0x0800, //!< The Node gets Reparented if its Parent gets removed. Child will be reparented according to the Reparenting-Rules. 56 58 57 59 // VISIBILITY/ACTIVITY … … 65 67 //! The default mode of the translation-binding. 66 68 #define PNODE_PARENT_MODE_DEFAULT PNODE_ALL | \ 67 PNODE_REPARENT_CHILDREN_ON_REMOVE | \68 69 PNODE_REPARENT_KEEP_POSITION 69 70 … … 72 73 class PNode : virtual public BaseObject { 73 74 public: 74 PNode (PNode* parent = PNode::getNullParent() );75 PNode (PNode* parent = PNode::getNullParent(), long nodeFlags = PNODE_PARENT_MODE_DEFAULT); 75 76 virtual ~PNode (); 76 77 77 78 void loadParams(const TiXmlElement* root); 78 79 80 // ACTIVATION // 79 81 inline void activateNode() { this->bActive = true; }; 80 82 inline void deactivateNode() { this->bActive = false; }; 81 83 inline bool getNodeActiveState() { return this->bActive; }; 82 84 85 // POSITION // 83 86 void setRelCoor (const Vector& relCoord); 84 87 void setRelCoor (float x, float y, float z); … … 98 101 void shiftCoor (float x, float y, float z) { this->shiftCoor(Vector(x, y, z)); }; 99 102 103 // SPEED // 104 /** @returns the Speed of the Node */ 105 inline float getSpeed() const { return this->velocity.len(); }; 106 /** @returns the Velocity of the Node */ 107 inline const Vector& getVelocity() const { return this->velocity; }; 108 109 110 // ROTATION // 100 111 void setRelDir (const Quaternion& relDir); 101 112 void setRelDir (float x, float y, float z); … … 124 135 inline Vector getAbsDirZ() const { return this->absDirection.apply(Vector(0,0,1)); }; 125 136 126 /** @returns the Speed of the Node */ 127 inline float getSpeed() const { return this->velocity.len(); }; 128 /** @returns the Velocity of the Node */ 129 inline const Vector& getVelocity() const { return this->velocity; }; 130 131 137 138 // PARENTING // 132 139 void addChild (PNode* child); 133 140 void addChild (const char* childName); … … 146 153 void setParentSoft(const char* parentName, float bias = 1.0); 147 154 155 // PARENTING_MODE AND OTHER FLAGS // 148 156 void setParentMode (PARENT_MODE parentMode); 149 157 void setParentMode (const char* parentingMode); … … 151 159 int getParentMode() const { return 0x000f & this->parentMode; }; 152 160 153 void addNodeModeFlags(unsigned short nodeFlags); 154 void removeNodeModeFlags(unsigned short nodeFlags); 155 161 void addNodeFlags(unsigned short nodeFlags); 162 void removeNodeFlags(unsigned short nodeFlags); 163 164 // NULL_PARENT // 156 165 /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */ 157 static PNode* getNullParent() { return (PNode::nullParent != NULL || (PNode::nullParent = new PNode(NULL)) != NULL)? PNode::nullParent : NULL; }; 158 166 static PNode* getNullParent() { return (PNode::nullParent != NULL)? PNode::nullParent : PNode::createNullParent(); }; 167 168 // UPDATING // 159 169 void updateNode (float dt); 160 170 171 // DEBUG // 161 172 void countChildNodes(int& nodes) const; 162 173 void debugNode (unsigned int depth = 1, unsigned int level = 0) const; 163 174 void debugDraw(unsigned int depth = 1, float size = 1.0, const Vector& color = Vector(1, 0, 0), unsigned int level = 0) const; 164 175 165 166 // helper functions // 176 // HELPER_FUNCTIONS // 167 177 static const char* parentingModeToChar(int parentingMode); 168 178 static PARENT_MODE charToParentingMode(const char* parentingMode); … … 170 180 171 181 private: 172 void init();173 182 /** tells the child that the parent's Coordinate has changed */ 174 183 inline void parentCoorChanged () { this->bRelCoorChanged = true; } … … 178 187 inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; } 179 188 189 static PNode* createNullParent(); 180 190 void reparent(); 181 191 bool checkIntegrity(const PNode* checkParent) const; 192 void eraseChild(PNode* child); 182 193 183 194 private: -
trunk/src/world_entities/space_ships/space_ship.cc
r6070 r6078 112 112 PRINTF(4)("SPACESHIP INIT\n"); 113 113 114 EventHandler::getInstance()->grabEvents( false);114 EventHandler::getInstance()->grabEvents(true); 115 115 116 116 bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; -
trunk/src/world_entities/weapons/aim.cc
r6054 r6078 65 65 this->setClassID(CL_CROSSHAIR, "Aim"); 66 66 this->setName("Aim"); 67 68 this->addNodeModeFlags(PNODE_REPARENT_TO_NULLPARENT);69 67 70 68 this->setLayer(E2D_LAYER_TOP); -
trunk/src/world_entities/weapons/guided_missile.cc
r6074 r6078 150 150 { 151 151 //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); 152 if (t arget.getParent() != PNode::getNullParent())152 if (this->target != NULL && this->target->getParent() != PNode::getNullParent()) 153 153 { 154 velocity += ((target.getAbsCoor() - this->getAbsCoor()).getNormalized())*agility; 154 printf("========%s::%s\n", target->getParent()->getClassName(), target->getParent()->getName() ); 155 velocity += ((target->getAbsCoor() - this->getAbsCoor()).getNormalized())*agility; 155 156 float speed = velocity.len(); 156 157 if (speed > this->maxVelocity) -
trunk/src/world_entities/weapons/projectile.cc
r6074 r6078 37 37 this->lifeCycle = 0.0; 38 38 this->lifeSpan = 1.0f; /* sec */ 39 this->target.addNodeModeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | 40 PNODE_REPARENT_TO_NULLPARENT); 41 39 this->target = NULL; 42 40 this->removeNode(); 43 41 } … … 103 101 void Projectile::setTarget(PNode* target) 104 102 { 105 this->target.setParent(target); 103 if (this->target == NULL) 104 this->target = new PNode(target, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_ON_PARENTS_REMOVE); 105 else 106 this->target->setParent(target); 106 107 } 107 108 -
trunk/src/world_entities/weapons/projectile.h
r6056 r6078 60 60 Vector velocity; //!< velocity of the projectile. 61 61 62 PNode 62 PNode* target; //!< A target for guided Weapons. 63 63 }; 64 64
Note: See TracChangeset
for help on using the changeset viewer.