- Timestamp:
- Dec 11, 2005, 6:23:42 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r6048 r6054 22 22 #include "class_list.h" 23 23 24 #include "stdincl.h"25 24 #include "compiler.h" 26 #include "error.h"27 25 #include "debug.h" 28 #include "vector.h" 29 26 27 #include "glincl.h" 30 28 #include "color.h" 31 29 … … 86 84 PNode::~PNode () 87 85 { 88 // remove the Node, delete it's children. 89 PNode* tmp; 90 while (this->children.size() > 0) 91 { 92 tmp = this->children.front(); 93 this->children.pop_front(); 94 delete tmp; 86 // remove the Node, delete it's children (if required). 87 std::list<PNode*>::iterator tmp = this->children.begin(); 88 std::list<PNode*>::iterator deleteNode; 89 while (tmp != this->children.end()) 90 { 91 deleteNode = tmp++; 92 if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT) ) 93 (*deleteNode)->reparent(); 94 else 95 delete (*deleteNode); 95 96 } 96 97 if (this->parent != NULL) … … 120 121 this->parent = parent; 121 122 this->parentMode = PNODE_PARENT_MODE_DEFAULT; 122 123 // iterators 123 this->bActive = true; 124 125 // smooth-movers 124 126 this->toCoordinate = NULL; 125 127 this->toDirection = NULL; … … 269 271 this->setAbsCoor(Vector(x, y, z)); 270 272 } 273 271 274 272 275 /** … … 321 324 } 322 325 326 323 327 /** 324 328 * @brief set relative direction … … 336 340 this->bRelCoorChanged = true; 337 341 } 342 338 343 339 344 /** … … 366 371 } 367 372 373 368 374 /** 369 375 * @see void PNode::setRelDirSoft (const Quaternion& relDir) … … 379 385 } 380 386 387 381 388 /** 382 389 * @brief sets the absolute direction … … 399 406 } 400 407 408 401 409 /** 402 410 * @see void PNode::setAbsDir (const Quaternion& relDir) … … 412 420 } 413 421 422 414 423 /** 415 424 * @brief sets the absolute direction … … 430 439 this->bRelDirChanged = true; 431 440 } 441 432 442 433 443 /** … … 491 501 * @param child the child to remove from this pNode. 492 502 * 493 * Children from pNode will not be lost, they are referenced to NullPointer503 * Children from pNode will not be lost, they are Reparented by the rules of the ParentMode 494 504 */ 495 505 void PNode::removeChild (PNode* child) … … 503 513 } 504 514 515 505 516 /** 506 517 * @brief remove this pnode from the tree and adds all following to NullParent … … 510 521 void PNode::removeNode() 511 522 { 512 list<PNode*>::iterator child; 513 for (child = this->children.begin(); child != this->children.end(); child ++) 514 NullParent::getInstance()->addChild(*child); 515 523 if (this->parentMode & PNODE_REPARENT_CHILDREN_ON_REMOVE) 524 { 525 list<PNode*>::iterator child = this->children.begin(); 526 list<PNode*>::iterator reparenter; 527 while (child != this->children.end()) 528 { 529 reparenter = child++; 530 (*reparenter)->reparent(); 531 } 532 } 516 533 if (this->parent != NULL) 517 534 this->parent->children.remove(this); … … 529 546 parentNode->addChild(this); 530 547 } 548 531 549 532 550 /** … … 568 586 } 569 587 588 570 589 /** 571 590 * @brief does the reparenting in a very smooth way … … 580 599 } 581 600 601 /** 602 * @param parentMode sets the parentingMode of this Node 603 */ 604 void PNode::setParentMode(PARENT_MODE parentMode) 605 { 606 this->parentMode &= (0xfff0 | parentMode); 607 } 582 608 583 609 /** … … 589 615 this->setParentMode(PNode::charToParentingMode(parentingMode)); 590 616 } 617 618 619 /** 620 * !!PRIVATE FUNCTION: 621 * @brief reparents a node (happens on Parents Node delete or remove if Flags are set.) 622 */ 623 void PNode::reparent() 624 { 625 if (this->parentMode & PNODE_REPARENT_TO_NULLPARENT) 626 this->setParent(NullParent::getInstance()); 627 else if (this->parentMode & PNODE_REPARENT_TO_PARENTS_PARENT && this->parent != NULL) 628 this->setParent(this->parent->getParent()); 629 } 630 631 void PNode::addNodeModeFlags(unsigned short nodeFlags) 632 { 633 this->parentMode |= nodeFlags; 634 } 635 636 637 void PNode::removeNodeModeFlags(unsigned short nodeFlags) 638 { 639 this->parentMode &= !nodeFlags; 640 } 641 591 642 592 643 /** … … 602 653 if( likely(this->parent != NULL)) 603 654 { 604 // movement for nodes with smoothMove enabled 605 if (unlikely(this->toCoordinate != NULL)) 655 if (!(this->parentMode & PNODE_STATIC_NODE)) 606 656 { 607 Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;608 if ( likely(moveVect.len() >= PNODE_ITERATION_DELTA))657 // movement for nodes with smoothMove enabled 658 if (unlikely(this->toCoordinate != NULL)) 609 659 { 610 this->shiftCoor(moveVect); 660 Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias; 661 if (likely(moveVect.len() >= PNODE_ITERATION_DELTA)) 662 { 663 this->shiftCoor(moveVect); 664 } 665 else 666 { 667 delete this->toCoordinate; 668 this->toCoordinate = NULL; 669 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 670 } 611 671 } 612 else672 if (unlikely(this->toDirection != NULL)) 613 673 { 614 delete this->toCoordinate; 615 this->toCoordinate = NULL; 616 PRINTF(5)("SmoothMove of %s finished\n", this->getName()); 674 Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias); 675 if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA) 676 { 677 this->relDirection = rotQuat; 678 this->bRelDirChanged; 679 } 680 else 681 { 682 delete this->toDirection; 683 this->toDirection = NULL; 684 PRINTF(5)("SmoothRotate of %s finished\n", this->getName()); 685 } 686 } 687 688 // MAIN UPDATE ///////////////////////////////////// 689 this->lastAbsCoordinate = this->absCoordinate; 690 691 PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 692 693 694 if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged) 695 { 696 /* update the current absDirection - remember * means rotation around sth.*/ 697 this->prevRelCoordinate = this->relCoordinate; 698 this->absDirection = this->relDirection * parent->getAbsDir();; 699 } 700 701 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged)) 702 { 703 /* update the current absCoordinate */ 704 this->prevRelCoordinate = this->relCoordinate; 705 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 706 } 707 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged) 708 { 709 /* update the current absCoordinate */ 710 this->prevRelCoordinate = this->relCoordinate; 711 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate); 712 } 713 ///////////////////////////////////////////////// 714 } 715 } 716 else // Nodes without a Parent are handled faster :: MOST LIKELY THE NULLPARENT 717 { 718 if (!(this->parentMode & PNODE_STATIC_NODE)) 719 { 720 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z); 721 if (this->bRelCoorChanged) 722 { 723 this->prevRelCoordinate = this->relCoordinate; 724 this->absCoordinate = this->relCoordinate; 725 } 726 if (this->bRelDirChanged) 727 { 728 this->prevRelDirection = this->relDirection; 729 this->absDirection = this->getAbsDir () * this->relDirection; 617 730 } 618 731 } 619 if (unlikely(this->toDirection != NULL))620 {621 Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias);622 if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA)623 {624 this->relDirection = rotQuat;625 this->bRelDirChanged;626 }627 else628 {629 delete this->toDirection;630 this->toDirection = NULL;631 PRINTF(5)("SmoothRotate of %s finished\n", this->getName());632 }633 }634 635 // MAIN UPDATE /////////////////////////////////////636 this->lastAbsCoordinate = this->absCoordinate;637 638 PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);639 640 641 if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)642 {643 /* update the current absDirection - remember * means rotation around sth.*/644 this->prevRelCoordinate = this->relCoordinate;645 this->absDirection = this->relDirection * parent->getAbsDir();;646 }647 648 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))649 {650 /* update the current absCoordinate */651 this->prevRelCoordinate = this->relCoordinate;652 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;653 }654 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)655 {656 /* update the current absCoordinate */657 this->prevRelCoordinate = this->relCoordinate;658 this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);659 }660 /////////////////////////////////////////////////661 }662 else663 {664 PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);665 if (this->bRelCoorChanged)666 {667 this->prevRelCoordinate = this->relCoordinate;668 this->absCoordinate = this->relCoordinate;669 }670 if (this->bRelDirChanged)671 {672 this->prevRelDirection = this->relDirection;673 this->absDirection = this->getAbsDir () * this->relDirection;674 }675 732 } 676 733 677 if(!this->children.empty() )734 if(!this->children.empty() && (this->bActive || this->parentMode & PNODE_UPDATE_CHILDREN_IF_INACTIVE )) 678 735 { 679 736 list<PNode*>::iterator child; -
trunk/src/lib/coord/p_node.h
r6048 r6054 28 28 29 29 #define PNODE_ITERATION_DELTA .001 30 30 31 //! Parental linkage modes 31 32 typedef enum … … 45 46 PNODE_REPARENT_TO_PARENTS_PARENT = 0x0020, //!< Reparents the Node to the parents (old) parent it the parent gets removed. 46 47 PNODE_REPARENT_DELETE_CHILDREN = 0x0040, //!< Deletes the Children of the node when This Node is Removed. (Use with care). 47 PNODE_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 48 /// FIXME 49 PNODE_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 48 50 49 51 … … 51 53 PNODE_PROHIBIT_CHILD_DELETE = 0x0100, //!< Prohibits the Children from being deleted if this Node gets deleted. 52 54 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 53 PNODE_REPARENT_CHILDREN_ON_DELETE = 0x0400, //!< Reparents the Children of the Node to 54 PNODE_REPARANT_CHILDREN_ON_REMOVE = 0x0800, //!< Reparents the Children of the Node if the Node gets Removed. 55 PNODE_REPARENT_CHILDREN_ON_REMOVE = 0x0400, //!< Reparents the Children of the Node if the Node gets Removed. 55 56 56 57 // VISIBILITY/ACTIVITY … … 64 65 //! The default mode of the translation-binding. 65 66 #define PNODE_PARENT_MODE_DEFAULT PNODE_ALL | \ 67 PNODE_REPARENT_CHILDREN_ON_REMOVE | \ 66 68 PNODE_REPARENT_KEEP_POSITION 67 69 … … 77 79 78 80 void loadParams(const TiXmlElement* root); 81 82 inline void activateNode() { this->bActive = true; }; 83 inline void deactivateNode() { this->bActive = false; }; 84 inline bool getNodeActiveState() { return this->bActive; }; 79 85 80 86 void setRelCoor (const Vector& relCoord); … … 132 138 void removeNode(); 133 139 134 /** @param the new parent of this node */140 /** @param parent the new parent of this node */ 135 141 inline void setParent (PNode* parent) { parent->addChild(this); }; 136 142 void setParent (const char* parentName); … … 143 149 void setParentSoft(const char* parentName, float bias = 1.0); 144 150 145 /** @param parentMode sets the parentingMode of this Node */ 146 void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; }; 151 void setParentMode (PARENT_MODE parentMode); 147 152 void setParentMode (const char* parentingMode); 148 153 /** @returns the Parenting mode of this node */ 149 int getParentMode() const { return this->parentMode; }; 154 int getParentMode() const { return 0x000f & this->parentMode; }; 155 156 void addNodeModeFlags(unsigned short nodeFlags); 157 void removeNodeModeFlags(unsigned short nodeFlags); 158 150 159 151 160 void updateNode (float dt); -
trunk/src/lib/event/event_handler.cc
r5978 r6054 258 258 void EventHandler::grabEvents(bool grabEvents) 259 259 { 260 261 262 263 264 SDL_WM_GrabInput(SDL_GRAB_ON);260 this->eventsGrabbed = grabEvents; 261 if(!grabEvents) 262 SDL_WM_GrabInput(SDL_GRAB_OFF); 263 else 264 SDL_WM_GrabInput(SDL_GRAB_ON); 265 265 } 266 266 … … 364 364 { 365 365 printf("Not sending event to the WindowManager\n"); 366 367 EventHandler::getInstance()->grabEvents(false); 366 368 return 0; 367 369 } -
trunk/src/lib/event/event_handler.h
r5978 r6054 44 44 void withUNICODE(bool enableUNICODE); 45 45 void grabEvents(bool grabEvents); 46 bool grabbedEvents() const { return this->eventsGrabbed; }; 46 47 47 48 void process(); … … 52 53 private: 53 54 EventHandler(); 54 55 55 56 56 private: -
trunk/src/story_entities/world.cc
r6034 r6054 145 145 // erease everything that is left. 146 146 delete NullParent::getInstance(); 147 148 //secondary cleanup of PNodes; 149 const std::list<BaseObject*>* nodeList = ClassList::getList(CL_PARENT_NODE); 150 if (nodeList != NULL) 151 while (!nodeList->empty()) 152 delete nodeList->front(); 147 153 148 154 Shader::suspendShader(); -
trunk/src/world_entities/npcs/npc.cc
r6004 r6054 59 59 } 60 60 State::getWorldEntityList()->remove(this); 61 this->removeNode(); 61 62 62 63 this->collider = entity; … … 68 69 this->setVisibiliy(false); 69 70 State::getWorldEntityList()->remove(this); 71 this->removeNode(); 70 72 } 71 73 } -
trunk/src/world_entities/npcs/npc_test.cc
r6004 r6054 58 58 59 59 60 void NPC2::collidesWith(WorldEntity* entity, const Vector& location)61 {62 if (entity->isA(CL_PROJECTILE))63 {64 PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);65 this->applyForce(Vector(0,0,0)-location*1000);66 }67 else if (entity->isA(CL_PLAYER))68 this->applyForce(Vector(0,0,0)-location*100);69 else70 {71 this->setVisibiliy(false);72 State::getWorldEntityList()->remove(this);73 }74 }75 76 60 77 61 /** -
trunk/src/world_entities/npcs/npc_test.h
r6004 r6054 20 20 virtual void draw() const; 21 21 22 virtual void collidesWith (WorldEntity* entity, const Vector& location);23 24 25 22 private: 26 23 Vector randomRotAxis; -
trunk/src/world_entities/npcs/npc_test1.cc
r6004 r6054 46 46 47 47 48 void NPCTest1::collidesWith(WorldEntity* entity, const Vector& location)49 {50 if (entity->isA(CL_PROJECTILE) && entity != this->collider)51 {52 // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getName(), entity->getName(), location.x, location.y, location.z);53 // this->applyForce(Vector(0,0,0)-location*1000);54 if ((float)rand()/RAND_MAX < .3)55 {56 WorldEntity* powerUp = new TurretPowerUp();57 powerUp->setAbsCoor(this->getAbsCoor());58 State::getWorldEntityList()->add(powerUp);59 }60 else if ((float)rand()/RAND_MAX < .3)61 {62 WorldEntity* powerUp = new LaserPowerUp();63 powerUp->setAbsCoor(this->getAbsCoor());64 State::getWorldEntityList()->add(powerUp);65 }66 State::getWorldEntityList()->remove(this);67 68 this->collider = entity;69 }70 else if (entity->isA(CL_PLAYER))71 this->applyForce(Vector(0,0,0)-location*100);72 else if (entity->isA(CL_NPC))73 {74 this->setVisibiliy(false);75 State::getWorldEntityList()->remove(this);76 }77 }78 79 48 80 49 void NPCTest1::tick(float dt) -
trunk/src/world_entities/npcs/npc_test1.h
r6004 r6054 18 18 virtual void tick(float dt); 19 19 20 virtual void collidesWith (WorldEntity* entity, const Vector& location);21 22 23 20 private: 24 21 Vector randomRotAxis; -
trunk/src/world_entities/weapons/aim.cc
r5779 r6054 65 65 this->setClassID(CL_CROSSHAIR, "Aim"); 66 66 this->setName("Aim"); 67 68 this->addNodeModeFlags(PNODE_REPARENT_TO_NULLPARENT); 67 69 68 70 this->setLayer(E2D_LAYER_TOP); -
trunk/src/world_entities/weapons/guided_missile.cc
r5994 r6054 152 152 { 153 153 //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); 154 if (target != NULL && target->getParent() != NullParent::getInstance())154 if (target.getParent() != NullParent::getInstance()) 155 155 { 156 velocity += ((target ->getAbsCoor() - this->getAbsCoor()).getNormalized())*agility;156 velocity += ((target.getAbsCoor() - this->getAbsCoor()).getNormalized())*agility; 157 157 float speed = velocity.len(); 158 158 if (speed > this->maxVelocity) -
trunk/src/world_entities/weapons/guided_missile.h
r5766 r6054 9 9 #include "projectile.h" 10 10 11 class Vector;12 11 class Weapon; 13 12 class ParticleSystem; -
trunk/src/world_entities/weapons/projectile.cc
r5994 r6054 38 38 this->lifeCycle = 0.0; 39 39 this->lifeSpan = 1.0f; /* sec */ 40 this->target = NULL; 40 this->target.addNodeModeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | 41 PNODE_REPARENT_TO_NULLPARENT); 41 42 42 43 this->removeNode(); … … 103 104 void Projectile::setTarget(PNode* target) 104 105 { 105 106 if (this->target == NULL) 107 this->target = new PNode(); 108 this->target->setParent(target); 106 this->target.setParent(target); 109 107 } 110 108 -
trunk/src/world_entities/weapons/projectile.h
r5994 r6054 55 55 Vector velocity; //!< velocity of the projectile. 56 56 57 PNode *target; //!< A target for guided Weapons.57 PNode target; //!< A target for guided Weapons. 58 58 }; 59 59 -
trunk/src/world_entities/weapons/weapon.cc
r5930 r6054 528 528 tick(dt); 529 529 } 530 531 /**532 * this will draw the weapon533 */534 void Weapon::draw () const535 {}536 537 530 538 531 -
trunk/src/world_entities/weapons/weapon.h
r5750 r6054 148 148 149 149 virtual void tick(float dt) {}; 150 virtual void draw() const;151 150 152 151 bool check() const; -
trunk/src/world_entities/weapons/weapon_manager.cc
r5982 r6054 35 35 36 36 /** 37 * this initializes the weaponManager for a given nnumber of weapon slots37 * @brief this initializes the weaponManager for a given nnumber of weapon slots 38 38 * @param number of weapon slots of the model/ship <= 8 (limitied) 39 39 */ … … 51 51 52 52 /** 53 * Destroys a WeaponManager53 * @brief Destroys a WeaponManager 54 54 */ 55 55 WeaponManager::~WeaponManager() … … 60 60 61 61 /** 62 * initializes the WeaponManager62 * @brief initializes the WeaponManager 63 63 */ 64 64 void WeaponManager::init()
Note: See TracChangeset
for help on using the changeset viewer.