Changeset 9869 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 18 deleted
- 289 edited
- 46 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/BuildLibs.am
r9668 r9869 1 1 2 2 libORXlibs_a_LIBRARIES_ = \ 3 $(LIB_PREFIX)/util/libORXlibutil.a \4 $(LIB_PREFIX)/shell/libORXshell.a \5 3 $(LIB_PREFIX)/event/libORXevent.a \ 6 4 $(LIB_PREFIX)/gui/qt/libORXqtgui.a \ 7 5 $(LIB_PREFIX)/gui/gl/libORXglgui.a \ 8 6 $(LIB_PREFIX)/gui/libORXbasegui.a \ 9 $(LIB_PREFIX)/script_engine/libORXscript.a \10 $(LIB_PREFIX)/graphics/importer/libORXimporter.a \11 7 $(LIB_PREFIX)/graphics/libORXgraphics.a \ 12 $(LIB_PREFIX)/graphics/importer/libtc.a \13 $(LIB_PREFIX)/sound/libORXsound.a \14 $(LIB_PREFIX)/particles/libORXparticles.a \15 8 $(LIB_PREFIX)/collision_detection/libORXcd.a \ 16 9 $(LIB_PREFIX)/collision_reaction/libORXcr.a \ … … 23 16 $(LIB_PREFIX)/physics/libORXphysics.a \ 24 17 $(LIB_PREFIX)/gui/gl/libORXglgui.a \ 18 \ 19 $(LIB_PREFIX)/graphics/importer/libORXimporter.a \ 20 $(LIB_PREFIX)/graphics/importer/libtc.a \ 21 $(LIB_PREFIX)/sound/libORXsound.a \ 25 22 $(LIB_PREFIX)/shell/libORXshell.a \ 26 $(LIB_PREFIX)/math/libORXmath.a \ 23 $(LIB_PREFIX)/script_engine/libORXscript.a \ 24 $(LIB_PREFIX)/util/libORXexecutor.a \ 27 25 $(LIB_PREFIX)/util/libORXlibutil.a \ 28 26 $(LIB_PREFIX)/lang/libORXlang.a \ 29 $(LIB_PREFIX)/libORXlibs.a 27 $(LIB_PREFIX)/libORXlibs.a \ 28 $(LIB_PREFIX)/math/libORXmath.a -
trunk/src/lib/Makefile.am
r9668 r9869 25 25 event \ 26 26 physics \ 27 particles \28 27 collision_detection \ 29 28 collision_reaction \ 30 29 gui \ 31 30 network \ 31 shell \ 32 32 parser \ 33 shell \34 33 script_engine -
trunk/src/lib/collision_detection/aabb.cc
r9406 r9869 21 21 22 22 23 23 ObjectListDefinition(AABB); 24 24 /** 25 25 * standard constructor … … 27 27 AABB::AABB () 28 28 { 29 this->setClassID(CL_OBB, "AABB");29 this->registerObject(this, AABB::_objectList); 30 30 this->halfLength[0] = this->halfLength[1] = this->halfLength[2] = 0.0f; 31 31 this->bCollided = false; -
trunk/src/lib/collision_detection/aabb.h
r8724 r9869 11 11 #include "bounding_volume.h" 12 12 13 template<class T> class tList;14 15 13 //! A class representing an extended bounding volume tree: an obb tree 16 14 class AABB : public BoundingVolume { 15 ObjectListDeclaration(AABB); 17 16 18 17 public: -
trunk/src/lib/collision_detection/aabb_tree_node.cc
r9494 r9869 32 32 #include "debug.h" 33 33 34 35 36 37 38 39 34 GLUquadricObj* AABBTreeNode_sphereObj = NULL; 40 35 41 36 ObjectListDefinition(AABBTreeNode); 42 37 /** 43 38 * standard constructor … … 48 43 : BVTreeNode() 49 44 { 50 this-> setClassID(CL_OBB_TREE_NODE, "AABBTreeNode");45 this->registerObject(this, AABBTreeNode::_objectList); 51 46 52 47 this->obbTree = &tree; -
trunk/src/lib/collision_detection/aabb_tree_node.h
r8724 r9869 21 21 class AABBTreeNode : public BVTreeNode 22 22 { 23 ObjectListDeclaration(AABBTreeNode); 23 24 24 25 -
trunk/src/lib/collision_detection/bounding_sphere.cc
r9406 r9869 20 20 21 21 22 22 ObjectListDefinition(BoundingSphere); 23 23 /** 24 24 * standard constructor … … 26 26 BoundingSphere::BoundingSphere () 27 27 { 28 this->setClassID(CL_BOUNDING_SPHERE, "BoundingSphere");28 this->registerObject(this, BoundingSphere::_objectList); 29 29 } 30 30 -
trunk/src/lib/collision_detection/bounding_sphere.h
r5039 r9869 1 /*! 1 /*! 2 2 * @file bounding_sphere.h 3 3 * Definition of a bounding sphere … … 14 14 //! A class representing an extended bounding volume tree: an sphere 15 15 class BoundingSphere : public BoundingVolume { 16 ObjectListDeclaration(BoundingSphere); 16 17 17 18 public: -
trunk/src/lib/collision_detection/bounding_volume.cc
r9406 r9869 20 20 21 21 22 22 ObjectListDefinition(BoundingVolume); 23 23 /** 24 24 * standard constructor … … 26 26 BoundingVolume::BoundingVolume () 27 27 { 28 this-> setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");28 this->registerObject(this, BoundingVolume::_objectList); 29 29 this->modelInf = NULL; 30 30 this->triangleIndexes = NULL; -
trunk/src/lib/collision_detection/bounding_volume.h
r9008 r9869 17 17 //! An abstract class representing a bounding volume 18 18 class BoundingVolume : public BaseObject { 19 ObjectListDeclaration(BoundingVolume); 19 20 20 21 public: -
trunk/src/lib/collision_detection/bv_tree.cc
r9406 r9869 21 21 22 22 23 23 ObjectListDefinition(BVTree); 24 24 /** 25 25 * standard constructor … … 27 27 BVTree::BVTree () 28 28 { 29 this->setClassID(CL_BV_TREE, "BVTree");29 this->registerObject(this, BVTree::_objectList); 30 30 31 31 } -
trunk/src/lib/collision_detection/bv_tree.h
r7711 r9869 36 36 class BVTree : public BaseObject 37 37 { 38 ObjectListDeclaration(BVTree); 38 39 39 40 public: -
trunk/src/lib/collision_detection/bv_tree_node.cc
r9406 r9869 20 20 21 21 22 22 ObjectListDefinition(BVTreeNode); 23 23 /** 24 24 * standard constructor … … 26 26 BVTreeNode::BVTreeNode () 27 27 { 28 this->setClassID(CL_BV_TREE_NODE, "BVTreeNode");28 this->registerObject(this, BVTreeNode::_objectList); 29 29 30 30 } -
trunk/src/lib/collision_detection/bv_tree_node.h
r7732 r9869 24 24 //! A class that represents a bounding volume tree 25 25 class BVTreeNode : public BaseObject { 26 ObjectListDeclaration(BVTreeNode); 26 27 27 28 -
trunk/src/lib/collision_detection/cd_engine.cc
r9406 r9869 20 20 #include "debug.h" 21 21 22 #include "class_list.h"23 24 22 #include "model.h" 25 23 #include "world_entity.h" … … 36 34 37 35 38 36 ObjectListDefinition(CDEngine); 39 37 /** 40 * standard constructor38 * @brief standard constructor 41 39 */ 42 40 CDEngine::CDEngine () 43 41 { 44 this-> setClassID(CL_CD_ENGINE, "CDEngine");42 this->registerObject(this, CDEngine::_objectList); 45 43 46 44 this->bAbordOnFirstCollision = false; … … 103 101 void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1) 104 102 { 105 106 std::list<BaseObject*>::const_iterator bspIterator;107 103 std::list<WorldEntity*>::iterator entityIterator; 108 const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);109 if( bspList == NULL)110 return;111 112 104 // for all bsp managers check all entities 113 for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++) { 105 for( ObjectList<BspEntity>::const_iterator bspIterator = BspEntity::objectList().begin(); 106 bspIterator != BspEntity::objectList().end(); 107 bspIterator++) { 114 108 for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++) 115 109 { -
trunk/src/lib/collision_detection/cd_engine.h
r8186 r9869 36 36 //! The class representing the collision detection system of orxonox 37 37 class CDEngine : public BaseObject { 38 ObjectListDeclaration(CDEngine); 38 39 39 40 friend class WorldEntity; -
trunk/src/lib/collision_detection/obb.cc
r9406 r9869 21 21 22 22 23 23 ObjectListDefinition(OBB); 24 24 /** 25 25 * standard constructor … … 27 27 OBB::OBB () 28 28 { 29 this->setClassID(CL_OBB, "OBB");29 this->registerObject(this, OBB::_objectList); 30 30 this->halfLength[0] = this->halfLength[1] = this->halfLength[2] = 0.0f; 31 31 this->bCollided = false; -
trunk/src/lib/collision_detection/obb.h
r7711 r9869 15 15 //! A class representing an extended bounding volume tree: an obb tree 16 16 class OBB : public BoundingVolume { 17 ObjectListDeclaration(OBB); 17 18 18 19 public: -
trunk/src/lib/collision_detection/obb_tree.cc
r9406 r9869 27 27 28 28 29 29 ObjectListDefinition(OBBTree); 30 30 /** 31 31 * standard constructor … … 51 51 void OBBTree::init() 52 52 { 53 this-> setClassID(CL_OBB_TREE, "OBBTree");53 this->registerObject(this, OBBTree::_objectList); 54 54 this->rootNode = NULL; 55 55 this->id = 0; -
trunk/src/lib/collision_detection/obb_tree.h
r9235 r9869 20 20 class OBBTree : public BVTree 21 21 { 22 ObjectListDeclaration(OBBTree); 22 23 23 24 public: -
trunk/src/lib/collision_detection/obb_tree_node.cc
r9406 r9869 38 38 GLUquadricObj* OBBTreeNode_sphereObj = NULL; 39 39 40 40 ObjectListDefinition(OBBTreeNode); 41 41 /** 42 42 * standard constructor … … 47 47 : BVTreeNode() 48 48 { 49 this-> setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");49 this->registerObject(this, OBBTreeNode::_objectList); 50 50 51 51 this->obbTree = &tree; … … 284 284 285 285 /** 286 * calculate the eigenvectors for the object oriented box286 * @brief calculate the eigenvectors for the object oriented box 287 287 * @param box: reference to the box 288 288 * @param modelInf: the model info structure of the model … … 361 361 362 362 /** 363 * this separates an ob-box in the middle363 * @brief this separates an ob-box in the middle 364 364 * @param box: the box to separate 365 365 * -
trunk/src/lib/collision_detection/obb_tree_node.h
r9235 r9869 17 17 class PNode; 18 18 19 20 19 //! A class that represents a bounding volume tree 21 20 class OBBTreeNode : public BVTreeNode 22 21 { 23 24 22 ObjectListDeclaration(OBBTreeNode); 25 23 public: 26 24 OBBTreeNode(const OBBTree& tree, OBBTreeNode* prev, int depth); -
trunk/src/lib/collision_reaction/collision.cc
r9406 r9869 18 18 #include "collision.h" 19 19 #include "debug.h" 20 21 22 23 20 24 21 /** -
trunk/src/lib/collision_reaction/collision.h
r8490 r9869 21 21 class Collision 22 22 { 23 24 23 public: 25 24 Collision(); -
trunk/src/lib/collision_reaction/collision_event.cc
r9406 r9869 18 18 #include "collision_event.h" 19 19 #include "debug.h" 20 21 22 23 20 24 21 /** -
trunk/src/lib/collision_reaction/collision_event.h
r8894 r9869 20 20 //! A class representing a simple collision 21 21 class CollisionEvent { 22 23 22 public: 24 23 CollisionEvent(); -
trunk/src/lib/collision_reaction/collision_handle.cc
r9406 r9869 30 30 31 31 32 32 ObjectListDefinition(CollisionHandle); 33 33 34 34 /** … … 38 38 CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type) 39 39 { 40 this-> setClassID(CL_COLLISION_HANDLE, "CollisionHandle");40 this->registerObject(this, CollisionHandle::_objectList); 41 41 42 42 this->owner = owner; … … 94 94 * @param classID the classid to look for 95 95 */ 96 void CollisionHandle::addTarget( longtarget)96 void CollisionHandle::addTarget(const ClassID& target) 97 97 { 98 98 // make sure there is no dublicate 99 std::vector< long>::iterator it = this->targetList.begin();99 std::vector<ClassID>::iterator it = this->targetList.begin(); 100 100 for( ; it < this->targetList.end(); it++) 101 101 if( (*it) == target) 102 102 return; 103 103 104 104 105 // add element 105 PRINTF(5)("addTarget: %i \n", target); 106 107 this->targetList.push_back(target); 106 this->targetList.push_back(target); 107 PRINTF(5)("addTarget: %i \n", target.id()); 108 108 } 109 109 … … 227 227 bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent) 228 228 { 229 std::vector< long>::iterator it = this->targetList.begin();229 std::vector<ClassID>::iterator it = this->targetList.begin(); 230 230 for(; it < this->targetList.end(); it++) 231 231 { … … 253 253 254 254 if( collisionEvent->getEntityA() == this->owner) { 255 if( collisionEvent->getEntityB()->isA(( ClassID)(*it))) {255 if( collisionEvent->getEntityB()->isA((*it))) { 256 256 PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 257 collisionEvent->getEntityB()->getClassCName(), *it);257 collisionEvent->getEntityB()->getClassCName(), (*it).id()); 258 258 return true; } 259 259 } 260 260 else { 261 if( collisionEvent->getEntityA()->isA(( ClassID)(*it))) {261 if( collisionEvent->getEntityA()->isA((*it))) { 262 262 PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 263 collisionEvent->getEntityA()->getClassCName(), *it);263 collisionEvent->getEntityA()->getClassCName(), (*it).id()); 264 264 return true; } 265 265 } … … 276 276 bool CollisionHandle::filterCollision(Collision* collision) 277 277 { 278 std::vector< long>::iterator it = this->targetList.begin();278 std::vector<ClassID>::iterator it = this->targetList.begin(); 279 279 for(; it < this->targetList.end(); it++) 280 280 { … … 302 302 303 303 if( collision->getEntityA() == this->owner) { 304 if( collision->getEntityA()->isA( (ClassID)(*it)))304 if( collision->getEntityA()->isA(*it)) 305 305 return true; } 306 306 else { 307 if( collision->getEntityB()->isA( (ClassID)(*it)))307 if( collision->getEntityB()->isA(*it)) 308 308 return true; } 309 309 } -
trunk/src/lib/collision_reaction/collision_handle.h
r8490 r9869 23 23 class CollisionHandle : public BaseObject 24 24 { 25 25 ObjectListDeclaration(CollisionHandle); 26 26 public: 27 27 CollisionHandle(WorldEntity* owner, CREngine::CRType type); … … 30 30 void reset(); 31 31 32 void addTarget( longtarget);32 void addTarget(const ClassID& target); 33 33 Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB); 34 34 void registerSharedCollision(Collision* collision); … … 64 64 65 65 std::vector<Collision*> collisionList; //!< a list full of collisions 66 std::vector<long> targetList; //!< a list of target classes for filtering 66 /// TODO Take a std::set here! 67 std::vector<ClassID> targetList; //!< a list of target classes for filtering @TODO TAKE SET INSTEAD OF VECTOR HERE 67 68 68 69 CollisionReaction* collisionReaction; //!< reference to the collision reaction object -
trunk/src/lib/collision_reaction/collision_reaction.cc
r9406 r9869 20 20 21 21 22 22 ObjectListDefinition(CollisionReaction); 23 23 24 24 /** … … 28 28 : BaseObject() 29 29 { 30 this-> setClassID(CL_COLLISION_REACTION, "CollisionReaction");30 this->registerObject(this, CollisionReaction::_objectList); 31 31 } 32 32 -
trunk/src/lib/collision_reaction/collision_reaction.h
r8490 r9869 18 18 class CollisionReaction : public BaseObject 19 19 { 20 20 ObjectListDeclaration(CollisionReaction); 21 21 public: 22 22 CollisionReaction(); -
trunk/src/lib/collision_reaction/cr_engine.cc
r9406 r9869 29 29 30 30 31 31 ObjectListDefinition(CREngine); 32 32 /** 33 33 * standard constructor … … 36 36 : BaseObject() 37 37 { 38 this->setClassID(CL_CR_ENGINE, "CREngine");38 this->registerObject(this, CREngine::_objectList); 39 39 this->setName("CREngine"); 40 40 -
trunk/src/lib/collision_reaction/cr_engine.h
r9235 r9869 25 25 class CREngine : public BaseObject 26 26 { 27 ObjectListDeclaration(CREngine); 27 28 28 29 public: -
trunk/src/lib/collision_reaction/cr_object_damage.cc
r9406 r9869 28 28 29 29 30 30 ObjectListDefinition(CRObjectDamage); 31 31 /** 32 32 * standard constructor … … 35 35 : CollisionReaction() 36 36 { 37 this->setClassID(CL_CR_OBJECT_DAMAGE, "CRObjectDamage"); 38 37 this->registerObject(this, CRObjectDamage::_objectList); 39 38 } 40 39 -
trunk/src/lib/collision_reaction/cr_object_damage.h
r8190 r9869 15 15 class CRObjectDamage : public CollisionReaction 16 16 { 17 ObjectListDeclaration(CRObjectDamage); 17 18 public: 18 19 CRObjectDamage(); -
trunk/src/lib/collision_reaction/cr_physics_full_walk.cc
r9406 r9869 35 35 36 36 37 37 ObjectListDefinition(CRPhysicsFullWalk); 38 38 /** 39 39 * standard constructor … … 42 42 : CollisionReaction() 43 43 { 44 this-> setClassID(CL_CR_PHYSICS_FULL_WALK, "CRPhysicsFullWalk");44 this->registerObject(this, CRPhysicsFullWalk::_objectList); 45 45 } 46 46 -
trunk/src/lib/collision_reaction/cr_physics_full_walk.h
r9235 r9869 15 15 class CRPhysicsFullWalk : public CollisionReaction 16 16 { 17 ObjectListDeclaration(CRPhysicsFullWalk); 17 18 public: 18 19 CRPhysicsFullWalk(); -
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r9406 r9869 35 35 36 36 37 37 ObjectListDefinition(CRPhysicsGroundWalk); 38 38 /** 39 39 * standard constructor … … 42 42 : CollisionReaction() 43 43 { 44 this-> setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");44 this->registerObject(this, CRPhysicsGroundWalk::_objectList); 45 45 } 46 46 -
trunk/src/lib/collision_reaction/cr_physics_ground_walk.h
r8894 r9869 15 15 class CRPhysicsGroundWalk : public CollisionReaction 16 16 { 17 ObjectListDeclaration(CRPhysicsGroundWalk); 17 18 public: 18 19 CRPhysicsGroundWalk(); -
trunk/src/lib/coord/p_node.cc
r9656 r9869 19 19 20 20 #include "util/loading/load_param.h" 21 #include "class_list.h"22 21 23 22 #include "netdefs.h" … … 30 29 #include "color.h" 31 30 31 32 ObjectListDefinition(PNode); 32 33 /** 33 34 * @brief standard constructor … … 38 39 : BaseObject(), Synchronizeable() 39 40 { 40 this-> setClassID(CL_PARENT_NODE, "PNode");41 this->registerObject(this, PNode::_objectList); 41 42 42 43 this->bRelCoorChanged = true; … … 79 80 PRINTF(4)("delete %s::%s\n", this->getClassCName(), this->getCName()); 80 81 // remove the Node, delete it's children (if required). 81 std::list<PNode*>::iterator deleteNode; 82 unsigned int size; 82 PNode* last = NULL; 83 //this->debugNode(0); 84 83 85 while(!this->children.empty()) 84 86 { 85 deleteNode = this->children.begin(); 86 size = this->children.size(); 87 PNode* deleteNode = this->children.front(); 88 if (deleteNode == last) 89 { 90 PRINTF(1)("Node same as last that was tried to be deleted. FORCE reparent to NULL of %p\n", deleteNode); 91 (deleteNode->setParent( NULL)); 92 continue; 93 } 87 94 if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) || 88 ( (*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))95 (deleteNode->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT)) 89 96 { 90 if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL)97 if (this == PNode::nullParent && deleteNode->parentMode & PNODE_REPARENT_TO_NULL) 91 98 { 92 99 PRINTF(4)("%s::%s deletes %s::%s\n", 93 100 this->getClassCName(), this->getCName(), 94 (*deleteNode)->getClassCName(), (*deleteNode)->getCName());95 delete (*deleteNode);101 deleteNode->getClassCName(), deleteNode->getCName()); 102 delete deleteNode; 96 103 } 97 104 else … … 99 106 PRINTF(4)("%s::%s reparents %s::%s\n", 100 107 this->getClassCName(), this->getCName(), 101 (*deleteNode)->getClassCName(), (*deleteNode)->getCName());102 (*deleteNode)->reparent();108 deleteNode->getClassCName(), deleteNode->getCName()); 109 deleteNode->reparent(); 103 110 } 104 111 } … … 107 114 PRINTF(4)("%s::%s deletes PNode: %s::%s\n", 108 115 this->getClassCName(), this->getCName(), 109 (*deleteNode)->getClassCName(), (*deleteNode)->getCName());110 delete (*deleteNode);116 deleteNode->getClassCName(), deleteNode->getCName()); 117 delete deleteNode; 111 118 } 119 last = deleteNode; 112 120 } 113 121 … … 541 549 void PNode::addChild (const std::string& childName) 542 550 { 543 PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));551 PNode* childNode = PNode::objectList().getObject(childName); 544 552 // PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName()); 545 553 // assert( childNode != NULL ); … … 625 633 void PNode::setParent (const std::string& parentName) 626 634 { 627 PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));635 PNode* parentNode = PNode::objectList().getObject(parentName); 628 636 if (parentNode != NULL) 629 637 parentNode->addChild(this); … … 681 689 void PNode::setParentSoft(const std::string& parentName, float bias) 682 690 { 683 PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));691 PNode* parentNode = PNode::objectList().getObject(parentName); 684 692 if (parentNode != NULL) 685 693 this->setParentSoft(parentNode, bias); … … 730 738 if (likely(PNode::nullParent == NULL)) 731 739 { 732 PNode::nullParent = new PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL);733 PNode::nullParent->setClassID(CL_NULL_PARENT, "NullParent");740 PNode::nullParent = new NullParent(); 741 //PNode::nullParent->registerObject(, CL_NULL_PARENT); 734 742 PNode::nullParent->setName("NullParent"); 735 743 PNode::nullParent->setSynchronized(true); … … 915 923 int childNodeCount = 0; 916 924 this->countChildNodes(childNodeCount); 917 925 printf("%p:", this); 918 926 PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f), direction(%0.2f, %0.2f, %0.2f) - %s - %d childs\n", 919 927 this->getClassCName(), … … 1106 1114 } 1107 1115 1108 1116 ObjectListDefinition(NullParent); 1117 1118 NullParent::NullParent() 1119 : PNode(NULL, PNODE_PARENT_MODE_DEFAULT | PNODE_REPARENT_TO_NULL) 1120 { 1121 this->registerObject(this, NullParent::_objectList); 1122 } -
trunk/src/lib/coord/p_node.h
r9406 r9869 50 50 PNODE_REPARENT_DELETE_CHILDREN = 0x0040, //!< Deletes the Children of the node when This Node is Removed. (Use with care). 51 51 /// FIXME 52 52 PNODE_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 53 53 54 54 … … 73 73 74 74 //! Patent Node is a Engine to calculate the position of an Object in respect to the position of its parent. 75 class PNode : virtual public BaseObject, virtual public Synchronizeable { 76 public: 75 class PNode : virtual public BaseObject, virtual public Synchronizeable 76 { 77 ObjectListDeclaration(PNode); 78 79 public: 77 80 PNode (PNode* parent = PNode::getNullParent(), long nodeFlags = PNODE_PARENT_MODE_DEFAULT); 78 81 virtual ~PNode (); … … 95 98 inline const Vector& getRelCoor () const { return this->prevRelCoordinate; }; 96 99 /** @returns the Relative Coordinate Destination */ 97 100 inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)? *this->toCoordinate : this->relCoordinate; }; 98 101 void setAbsCoor (const Vector& absCoord); 99 102 void setAbsCoor (float x, float y, float z); … … 130 133 inline const Quaternion& getRelDir () const { return this->prevRelDirection; }; 131 134 /** @returns the Relative Directional Destination */ 132 135 inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)? *this->toDirection : this->relDirection; }; 133 136 /** @returns a Vector pointing into the relative Direction */ 134 137 inline Vector getRelDirV() const { return this->prevRelDirection.apply(Vector(0,1,0)); }; … … 178 181 void removeNodeFlags(unsigned short nodeFlags); 179 182 180 // NULL_PARENT //181 183 /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */ 182 static PNode* getNullParent() { return (PNode::nullParent != NULL)? PNode::nullParent : PNode::createNullParent(); };184 static PNode* getNullParent() { return (PNode::nullParent != NULL) ? PNode::nullParent : PNode::createNullParent(); }; 183 185 184 186 // UPDATING // … … 195 197 float distance(const PNode* node) const { return (this->getAbsCoor() - node->getAbsCoor()).len(); }; 196 198 197 199 private: 198 200 /** tells the child that the parent's Coordinate has changed */ 199 201 inline void parentCoorChanged () { this->bRelCoorChanged = true; } 200 202 /** tells the child that the parent's Direction has changed */ 201 203 inline void parentDirChanged () { this->bRelDirChanged = true; } 202 204 public: 203 205 /** @returns the last calculated coordinate */ 204 206 inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; } 205 207 private: 206 208 static PNode* createNullParent(); 207 209 void reparent(); … … 209 211 void eraseChild(PNode* child); 210 212 211 213 private: 212 214 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 213 215 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked … … 221 223 Vector lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 222 224 Quaternion prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 223 // Quaternion lastAbsDirection;225 // Quaternion lastAbsDirection; 224 226 225 227 Vector velocity; //!< Saves the velocity. … … 238 240 static PNode* nullParent; //!< The ROOT of the main PNode Tree. 239 241 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 242 private: 243 float coorx; 244 float coory; 245 float coorz; 246 247 float rotw; 248 float rotx; 249 float roty; 250 float rotz; 251 252 private: 253 int relCoordinate_handle; 254 int relDirection_handle; 255 Vector relCoordinate_write; 256 Quaternion relDirection_write; 257 258 public: 259 virtual void varChangeHandler( std::list<int> & id ); 258 260 }; 259 261 262 // NULL_PARENT // 263 class NullParent : public PNode 264 { 265 ObjectListDeclaration(NullParent); 266 friend class PNode; 267 NullParent(); 268 }; 269 270 260 271 #endif /* _P_NODE_H */ -
trunk/src/lib/event/event_handler.cc
r9656 r9869 28 28 #include <algorithm> 29 29 30 31 ObjectListDefinition(EventHandler); 30 32 /** 31 33 * @brief standard constructor … … 33 35 EventHandler::EventHandler () 34 36 { 35 this-> setClassID(CL_EVENT_HANDLER, "EventHandler");37 this->registerObject(this, EventHandler::_objectList); 36 38 this->setName("EventHandler"); 37 39 -
trunk/src/lib/event/event_handler.h
r8743 r9869 21 21 class EventHandler : public BaseObject 22 22 { 23 23 ObjectListDeclaration(EventHandler); 24 24 public: 25 25 virtual ~EventHandler(); -
trunk/src/lib/event/event_listener.cc
r7868 r9869 19 19 #include "event_handler.h" 20 20 21 ObjectListDefinition(EventListener); 21 22 /** 22 23 * @brief standard constructor … … 24 25 EventListener::EventListener () 25 26 { 26 this-> setClassID(CL_EVENT_LISTENER, "EventListener");27 this->registerObject(this, EventListener::_objectList); 27 28 } 28 29 -
trunk/src/lib/event/event_listener.h
r7868 r9869 12 12 13 13 //! A class for event listener 14 class EventListener : virtual public BaseObject { 15 16 public: 14 class EventListener : virtual public BaseObject 15 { 16 ObjectListDeclaration(EventListener); 17 public: 17 18 EventListener(); 18 19 virtual ~EventListener(); -
trunk/src/lib/event/key_mapper.cc
r9406 r9869 25 25 #include "globals.h" 26 26 #include "parser/ini_parser/ini_parser.h" 27 #include " util/preferences.h"27 #include "parser/preferences/preferences.h" 28 28 #include "key_names.h" 29 29 #include "event_def.h" … … 32 32 33 33 34 34 ObjectListDefinition(KeyMapper); 35 35 36 36 /* initialize all variables to a reasonable value*/ … … 116 116 KeyMapper::KeyMapper () 117 117 { 118 this->setClassID(CL_KEY_MAPPER, "KeyMapper");118 this->registerObject(this, KeyMapper::_objectList); 119 119 } 120 120 -
trunk/src/lib/event/key_mapper.h
r8724 r9869 16 16 class KeyMapper : public BaseObject 17 17 { 18 ObjectListDeclaration(KeyMapper); 18 19 public: 19 20 //! A mapping from key-name to key-id -
trunk/src/lib/graphics/Makefile.am
r9006 r9869 6 6 libORXgraphics_a_SOURCES = \ 7 7 graphics_engine.cc \ 8 graphics_effect.cc \ 8 9 light.cc \ 9 10 shader.cc \ 11 shader_data.cc \ 12 resource_shader.cc \ 10 13 \ 11 14 render2D/render_2d.cc \ … … 19 22 text_engine/font.cc \ 20 23 text_engine/font_data.cc \ 21 \ 22 effects/graphics_effect.cc \ 23 effects/atmospheric_engine.cc \ 24 effects/weather_effect.cc \ 25 effects/sun_effect.cc \ 26 effects/fog_effect.cc \ 27 effects/volfog_effect.cc \ 28 effects/rain_effect.cc \ 29 effects/snow_effect.cc \ 30 effects/cloud_effect.cc \ 31 effects/lightning_effect.cc \ 32 effects/lense_flare.cc 24 text_engine/resource_font.cc 33 25 34 26 noinst_HEADERS =\ 35 27 graphics_engine.h \ 28 graphics_effect.h \ 36 29 light.h \ 37 30 shader.h \ 31 shader_data.h \ 32 resource_shader.h \ 38 33 \ 39 34 render2D/render_2d.h \ … … 47 42 text_engine/font.h \ 48 43 text_engine/font_data.h \ 49 text_engine/default_font.xpm \ 50 \ 51 effects/graphics_effect.h \ 52 effects/atmospheric_engine.h \ 53 effects/weather_effect.h \ 54 effects/sun_effect.h \ 55 effects/fog_effect.h \ 56 effects/volfog_effect.h \ 57 effects/rain_effect.h \ 58 effects/snow_effect.h \ 59 effects/cloud_effect.h \ 60 effects/lightning_effect.h \ 61 effects/lense_flare.h 44 text_engine/resource_font.h \ 45 text_engine/default_font.xpm 62 46 63 47 -
trunk/src/lib/graphics/graphics_engine.cc
r9406 r9869 17 17 18 18 #include "graphics_engine.h" 19 #include "util/loading/resource_manager.h"20 19 #include "state.h" 21 20 … … 28 27 #include "debug.h" 29 28 30 #include " util/preferences.h"29 #include "parser/preferences/preferences.h" 31 30 #include "substring.h" 32 31 #include "text.h" … … 35 34 #include "texture.h" 36 35 37 #include "effects/graphics_effect.h" 38 #include "effects/fog_effect.h" 39 #include "effects/lense_flare.h" 36 #include "graphics_effect.h" 40 37 41 38 #include "shell_command.h" 42 39 #include "loading/load_param_xml.h" 43 40 44 41 #include "parser/tinyxml/tinyxml.h" 45 42 #include "util/loading/load_param.h" 46 43 #include "util/loading/factory.h" 47 #include "class_list.h"48 44 49 45 #ifdef __WIN32__ … … 54 50 SHELL_COMMAND(fps, GraphicsEngine, toggleFPSdisplay); 55 51 52 ObjectListDefinition(GraphicsEngine); 53 56 54 /** 57 55 * @brief standard constructor … … 59 57 GraphicsEngine::GraphicsEngine () 60 58 { 61 this-> setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine");59 this->registerObject(this, GraphicsEngine::_objectList); 62 60 this->setName("GraphicsEngine"); 63 61 … … 117 115 { 118 116 LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffects) 119 .describe("loads a graphics effect");117 .describe("loads a graphics effect"); 120 118 } 121 119 … … 590 588 591 589 // tick the graphics effects 592 if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL) 593 { 594 std::list<BaseObject*>::const_iterator it; 595 for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++) 596 dynamic_cast<GraphicsEffect*>(*it)->tick(dt); 597 } 590 for (ObjectList<GraphicsEffect>::const_iterator it = GraphicsEffect::objectList().begin(); 591 it != GraphicsEffect::objectList().end(); 592 ++it) 593 (*it)->tick(dt); 598 594 } 599 595 … … 688 684 { 689 685 case EV_VIDEO_RESIZE: 690 691 692 } 693 } 686 this->resolutionChanged(event.resize); 687 break; 688 } 689 } -
trunk/src/lib/graphics/graphics_engine.h
r9406 r9869 30 30 class GraphicsEngine : public EventListener 31 31 { 32 ObjectListDeclaration(GraphicsEngine); 32 33 public: 33 34 virtual ~GraphicsEngine(); -
trunk/src/lib/graphics/importer/Makefile.am
r8724 r9869 4 4 noinst_LIBRARIES = libORXimporter.a libtc.a 5 5 6 libORXimporter_a_SOURCES = model.cc \ 7 interactive_model.cc \ 8 md_model_structure.cc \ 9 vertex_array_model.cc \ 10 grid.cc \ 11 static_model.cc \ 12 objModel.cc \ 13 primitive_model.cc \ 14 height_map.cc \ 15 bsp_manager.cc \ 16 bsp_file.cc \ 17 bsp_tree_node.cc \ 18 bsp_tree_leaf.cc \ 19 \ 20 material.cc \ 21 texture.cc \ 22 texture_data.cc \ 23 texture_sequence.cc \ 24 media_container.cc \ 25 movie_player.cc \ 26 \ 27 bsp_manager.cc \ 28 bsp_file.cc \ 29 bsp_tree_node.cc \ 30 bsp_tree_leaf.cc \ 31 \ 32 md2/md2Model.cc \ 33 \ 34 md3/md3_model.cc \ 35 md3/md3_animation.cc \ 36 md3/md3_animation_cfg.cc \ 37 md3/md3_bone_frame.cc \ 38 md3/md3_mesh.cc \ 39 md3/md3_data.cc \ 40 md3/md3_tag.cc 6 libORXimporter_a_SOURCES = \ 7 model.cc \ 8 interactive_model.cc \ 9 md_model_structure.cc \ 10 vertex_array_model.cc \ 11 grid.cc \ 12 static_model.cc \ 13 static_model_data.cc \ 14 objModel.cc \ 15 resource_obj.cc \ 16 primitive_model.cc \ 17 height_map.cc \ 18 bsp_manager.cc \ 19 bsp_file.cc \ 20 bsp_tree_node.cc \ 21 bsp_tree_leaf.cc \ 22 \ 23 material.cc \ 24 texture.cc \ 25 texture_data.cc \ 26 resource_texture.cc \ 27 texture_sequence.cc \ 28 media_container.cc \ 29 movie_player.cc \ 30 \ 31 bsp_manager.cc \ 32 bsp_file.cc \ 33 bsp_tree_node.cc \ 34 bsp_tree_leaf.cc \ 35 \ 36 md2/md2Model.cc \ 37 md2/resource_md2.cc 38 # \ 39 md3/md3_model.cc \ 40 md3/md3_animation.cc \ 41 md3/md3_animation_cfg.cc \ 42 md3/md3_bone_frame.cc \ 43 md3/md3_mesh.cc \ 44 md3/md3_data.cc \ 45 md3/md3_tag.cc 41 46 42 47 … … 54 59 grid.h \ 55 60 static_model.h \ 61 static_model_data.h \ 56 62 objModel.h \ 63 resource_obj.h \ 57 64 primitive_model.h \ 58 65 anorms.h \ … … 63 70 texture.h \ 64 71 texture_data.h \ 72 resource_texture.h \ 65 73 texture_sequence.h \ 66 74 \ … … 74 82 \ 75 83 md2/md2Model.h \ 84 md2/resource_md2.h \ 76 85 \ 77 86 md3/md3_model.h \ -
trunk/src/lib/graphics/importer/bsp_file.cc
r9406 r9869 466 466 PRINTF(4)("BSP FILE: Name %s . \n", fileName); 467 467 468 absFileName = Resource Manager::getFullName(fileName);468 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 469 469 470 470 if(File(absFileName).exists()) { … … 481 481 strncat (fileName, ext, strlen(fileName)); 482 482 483 absFileName = Resource Manager::getFullName(fileName);483 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 484 484 485 485 if(File(absFileName).exists()) { … … 496 496 strncat (fileName, ext, strlen(fileName)); 497 497 498 absFileName = Resource Manager::getFullName(fileName);498 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 499 499 500 500 if(File(absFileName).exists()) { … … 511 511 strncat (fileName, ext, strlen(fileName)); 512 512 513 absFileName = Resource Manager::getFullName(fileName);513 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 514 514 515 515 if(File(absFileName).exists()) { … … 524 524 strcpy(ext, ".TGA"); 525 525 strncat (fileName, ext, strlen(fileName)); 526 absFileName = Resource Manager::getFullName(fileName);526 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 527 527 528 528 if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) { … … 537 537 strcpy(ext, ".jpg"); 538 538 strncat (fileName, ext, strlen(fileName)); 539 absFileName = Resource Manager::getFullName(fileName);539 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 540 540 if(File(absFileName).exists()) { 541 541 PRINTF(4)("BSP FILE: gefunden . \n"); … … 551 551 strcpy(ext, ".JPG"); 552 552 strncat (fileName, ext, strlen(fileName)); 553 absFileName = Resource Manager::getFullName(fileName);553 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 554 554 if(File(absFileName).exists()) { 555 555 PRINTF(4)("BSP FILE: gefunden . \n"); … … 566 566 strcpy(ext, ".bmp"); 567 567 strncat (fileName, ext, strlen(fileName)); 568 absFileName = Resource Manager::getFullName(fileName);568 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 569 569 570 570 if(File(absFileName).exists()) { … … 580 580 strcpy(ext, ".BMP"); 581 581 strncat (fileName, ext, strlen(fileName)); 582 absFileName = Resource Manager::getFullName(fileName);582 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 583 583 584 584 if(File(absFileName).exists()) { … … 611 611 this->testSurf = NULL; 612 612 613 this->testSurf = IMG_Load(Resource Manager::getFullName(mat).c_str());613 this->testSurf = IMG_Load(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(mat).c_str()); 614 614 if(this->testSurf != NULL) { 615 615 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; -
trunk/src/lib/graphics/importer/bsp_manager.cc
r9235 r9869 33 33 #include "world_entities/player.h" 34 34 #include "world_entities/playable.h" 35 #include "util/loading/resource_manager.h" 35 36 36 // STL Containers 37 37 #include <vector> … … 41 41 #include "world_entity.h" 42 42 43 #include "util/loading/resource_manager.h" 43 44 #include "util/loading/load_param.h" 44 45 #include "util/loading/factory.h" … … 91 92 this->bspFile = new BspFile(); 92 93 this->bspFile->scale = scale; 93 if(this->bspFile->read(Resource Manager::getFullName(fileName).c_str()) == -1)94 if(this->bspFile->read(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName).c_str()) == -1) 94 95 return -1; 95 96 … … 1376 1377 if( this->outputFraction == 1.0f) // No collision Detected 1377 1378 { 1378 if( this->outputAllSolid ) 1379 if( this->outputAllSolid ) 1379 1380 { 1380 1381 this->collPlane = new plane; -
trunk/src/lib/graphics/importer/height_map.cc
r8316 r9869 22 22 #include "p_node.h" 23 23 #include "state.h" 24 #include "util/loading/resource_manager.h"25 24 #include "debug.h" 26 25 … … 327 326 328 327 328 ObjectListDefinition(HeightMap); 329 329 330 330 … … 413 413 void HeightMap::init(const std::string& heightMapName) 414 414 { 415 this-> setClassID(CL_HEIGHT_MAP, "HeightMap");415 this->registerObject(this, HeightMap::_objectList); 416 416 417 417 this->shiftX = 0; -
trunk/src/lib/graphics/importer/height_map.h
r7526 r9869 29 29 30 30 class SDL_Surface; 31 class Vector;32 31 class Material; 33 class PNode;34 32 class Texture; 35 33 class HeightMap; … … 70 68 71 69 70 72 71 //!< the height map representation itself 73 72 class HeightMap : public VertexArrayModel 74 73 { 74 ObjectListDeclaration(HeightMap); 75 75 friend class Tile; 76 76 -
trunk/src/lib/graphics/importer/interactive_model.cc
r9406 r9869 22 22 23 23 24 ObjectListDefinition(InteractiveModel); 25 24 26 /** 25 27 * standard constructor … … 28 30 InteractiveModel::InteractiveModel() 29 31 { 30 this-> setClassID(CL_INTERACTIVE_MODEL, "InteractiveModel");32 this->registerObject(this, InteractiveModel::_objectList); 31 33 } 32 34 -
trunk/src/lib/graphics/importer/interactive_model.h
r9003 r9869 30 30 class InteractiveModel : public Model 31 31 { 32 ObjectListDeclaration(InteractiveModel); 32 33 public: 33 34 InteractiveModel(); … … 38 39 virtual void setAnimation(int animNum, int playbackMode = 0) = 0; 39 40 virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback) {} 40 virtual int getAnimation() = 0;41 virtual int getAnimation() const = 0; 41 42 42 43 virtual bool isAnimationFinished() { return false; } -
trunk/src/lib/graphics/importer/material.cc
r9406 r9869 25 25 #include "loading/load_param.h" 26 26 27 #include "util/loading/resource_manager.h" 27 #include "resource_texture.h" 28 29 ObjectListDefinition(Material); 28 30 29 31 /** … … 33 35 Material::Material (const std::string& mtlName) 34 36 { 35 this-> setClassID(CL_MATERIAL, "Material");37 this->registerObject(this, Material::_objectList); 36 38 37 39 this->setIllum(3); … … 90 92 PRINTF(5)("delete Material %s.\n", this->getCName()); 91 93 92 if (this->ambientTexture != NULL)93 ResourceManager::getInstance()->unload(this->ambientTexture);94 if (this->specularTexture != NULL)95 ResourceManager::getInstance()->unload(this->specularTexture);96 97 94 if (this == Material::selectedMaterial) 98 95 Material::selectedMaterial = NULL; … … 101 98 102 99 const Material* Material::selectedMaterial = NULL; 103 104 105 /// TODO FIX THIS106 // Material& Material::operator=(const Material& m)107 // {108 // this->setIllum(m.illumModel);109 // this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);110 // this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);111 // this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);112 // this->setShininess(m.shininess);113 // this->setTransparency(m.transparency);114 //115 // if (this->diffuseTexture != NULL)116 // ResourceManager::getInstance()->unload(this->diffuseTexture);117 // if (m.diffuseTexture != NULL)118 // this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);119 // this->ambientTexture = NULL; /// FIXME120 // this->specularTexture = NULL; /// FIXME121 //122 // this->setName(m.getName());123 // }124 125 126 100 127 101 /** … … 288 262 289 263 290 291 /**292 * @brief Adds a Texture Path to the List of already existing Paths293 * @param pathName The Path to add.294 */295 void Material::addTexturePath(const std::string& pathName)296 {297 ResourceManager::getInstance()->addImageDir(pathName);298 }299 300 // MAPPING //301 302 303 264 /** 304 265 * @brief Sets the Diffuse map of this Texture. … … 322 283 * @param textureNumber The Texture-Number from 0 to GL_MAX_TEXTURE_UNITS 323 284 */ 324 void Material::setDiffuseMap(const TextureData Pointer& textureDataPointer, unsigned int textureNumber)285 void Material::setDiffuseMap(const TextureData::Pointer& textureDataPointer, unsigned int textureNumber) 325 286 { 326 287 assert(textureNumber < Material::getMaxTextureUnits()); … … 349 310 if (!dMap.empty()) 350 311 { 351 Texture* tex = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 352 if (tex != NULL) 353 this->textures[textureNumber] = *tex; 312 this->textures[textureNumber] = ResourceTexture(dMap); 313 //dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 314 /* if (tex != NULL) 315 this->textures[textureNumber] = tex; 354 316 else 355 this->textures[textureNumber] = Texture(); 317 this->textures[textureNumber] = Texture();*/ 356 318 } 357 319 else -
trunk/src/lib/graphics/importer/material.h
r8761 r9869 24 24 class Material : public BaseObject 25 25 { 26 ObjectListDeclaration(Material); 26 27 public: 27 28 Material (const std::string& mtlName = ""); 28 29 virtual ~Material (); 29 30 31 Material& operator=(const Material& material); 32 30 33 void loadParams(const TiXmlElement* root); 31 32 Material& operator=(const Material& material);33 34 34 35 bool select () const; … … 53 54 // MAPPING // 54 55 void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); 55 void setDiffuseMap(const TextureData Pointer& texturePointer, unsigned int textureNumber = 0);56 void setDiffuseMap(const TextureData::Pointer& texturePointer, unsigned int textureNumber = 0); 56 57 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 57 58 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); … … 65 66 66 67 const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; }; 67 68 static void addTexturePath(const std::string& pathName);69 68 70 69 static const std::string& blendFuncToString(GLenum blendFunc); -
trunk/src/lib/graphics/importer/md2/md2Model.cc
r9406 r9869 19 19 20 20 #include "debug.h" 21 #include " util/loading/resource_manager.h"22 23 24 21 #include "resource_md2.h" 22 23 24 ObjectListDefinition(MD2Model); 25 25 26 26 //! the model anorms 27 27 sVec3D MD2Model::anorms[NUM_VERTEX_NORMALS] = { 28 29 };28 #include "anorms.h" 29 }; 30 30 31 31 //! anormal dots, no idea of how this shall work, but it does 32 32 float MD2Model::anormsDots[SHADEDOT_QUANT][256] = { 33 34 };33 #include "anormtab.h" 34 }; 35 35 36 36 … … 42 42 sAnim MD2Model::animationList[22] = 43 43 { 44 // begin, end, fps, interruptable44 // begin, end, fps, interruptable 45 45 { 0, 39, 9, 1 }, //!< STAND 46 46 { 40, 45, 10, 1 }, //!< RUN … … 73 73 ********************************************************************************/ 74 74 75 MD2Model::MD2Model() 76 : data(new MD2Data()) 77 { 78 this->init(); 79 } 80 81 #include "resource_md2.h" 75 82 /** 76 83 \brief simple constructor initializing all variables 77 84 */ 78 85 MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale) 79 { 80 this->setClassID(CL_MD2_MODEL, "MD2Model"); 81 /* this creates the data container via ressource manager */ 82 if (!modelFileName.empty()) 83 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 84 if( unlikely(this->data == NULL)) 85 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); 86 86 : data(new MD2Data()) 87 { 88 this->init(); 87 89 this->scaleFactor = scale; 88 this->animationSpeed = 1.0f; 89 90 shadeDots = MD2Model::anormsDots[0]; 91 /* set the animation stat mannualy */ 92 this->animationState.type = STAND; 93 this->animationState.numPlays = 1; 94 this->setAnimation(STAND); 95 96 this->debug(); 97 98 //write the modelinfo information 90 91 this->data = ResourceMD2(modelFileName, skinFileName, scale).data; 92 rebuildInfo(); 93 94 //this->debug(); 95 } 96 97 MD2Model::MD2Model(const MD2Model& model) 98 : data(model.data) 99 { 100 this->init(); 101 this->rebuildInfo(); 102 } 103 104 MD2Model& MD2Model::operator=(const MD2Model& md2model) 105 { 106 this->data = md2model.data; 107 this->rebuildInfo(); 108 return *this; 109 } 110 111 void MD2Model::rebuildInfo() 112 { 113 //write the modelinfo information 99 114 this->pModelInfo.numVertices = this->data->numVertices; 100 115 this->pModelInfo.numTriangles = this->data->numTriangles; … … 107 122 108 123 // triangle conversion 124 if (this->pModelInfo.pTriangles != NULL) 125 delete[] this->pModelInfo.pTriangles; 109 126 this->pModelInfo.pTriangles = new sTriangleExt[this->data->numTriangles]; 110 127 for( int i = 0; i < this->data->numTriangles; i++) … … 118 135 this->pModelInfo.pTriangles[i].indexToTexCoor[2] = this->data->pTriangles[i].indexToTexCoor[2]; 119 136 } 137 } 138 139 bool MD2Model::load(const std::string& modelFileName, const std::string& skinFileName, float scale) 140 { 141 this->data = MD2Data::Pointer(new MD2Data(modelFileName, skinFileName, scale)); 142 this->rebuildInfo(); 120 143 } 121 144 … … 132 155 this->pModelInfo.pTexCoor = NULL; 133 156 this->pModelInfo.pTriangles = NULL; 134 135 ResourceManager::getInstance()->unload(this->data); 136 } 137 157 } 158 159 160 void MD2Model::init() 161 { 162 this->registerObject(this, MD2Model::_objectList); 163 /* this creates the data container via ressource manager */ 164 if( unlikely(this->data.isNull())) 165 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); 166 167 this->scaleFactor = 1.0f; 168 this->animationSpeed = 1.0f; 169 170 shadeDots = MD2Model::anormsDots[0]; 171 /* set the animation stat mannualy */ 172 this->animationState.type = STAND; 173 this->animationState.numPlays = 1; 174 this->setAnimation(STAND); 175 } 138 176 139 177 /** … … 153 191 154 192 for( int i = 0; i < this->data->numVertices; ++i) 155 156 157 158 159 193 { 194 this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]); 195 this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]); 196 this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]); 197 } 160 198 } 161 199 … … 259 297 /* draw the triangles */ 260 298 while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */ 299 { 300 if( i < 0) 261 301 { 262 if( i < 0) 263 { 264 glBegin(GL_TRIANGLE_FAN); 265 i = -i; 266 } 267 else 268 { 269 glBegin(GL_TRIANGLE_STRIP); 270 } 271 272 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 273 { 274 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 275 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); 276 glVertex3fv(this->verticesList[pCommands[2]]); 277 } 278 glEnd(); 279 302 glBegin(GL_TRIANGLE_FAN); 303 i = -i; 280 304 } 305 else 306 { 307 glBegin(GL_TRIANGLE_STRIP); 308 } 309 310 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 311 { 312 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 313 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); 314 glVertex3fv(this->verticesList[pCommands[2]]); 315 } 316 glEnd(); 317 318 } 281 319 glDisable(GL_CULL_FACE); 282 320 glPopAttrib(); … … 289 327 int* pCommands = this->data->pGLCommands; 290 328 /* some face culling stuff */ 291 // glPushAttrib(GL_POLYGON_BIT);292 // glFrontFace(GL_CW);293 // glEnable(GL_CULL_FACE);294 // glCullFace(GL_BACK);295 //296 // this->processLighting();297 // this->interpolate(/*this->verticesList*/);329 // glPushAttrib(GL_POLYGON_BIT); 330 // glFrontFace(GL_CW); 331 // glEnable(GL_CULL_FACE); 332 // glCullFace(GL_BACK); 333 // 334 // this->processLighting(); 335 // this->interpolate(/*this->verticesList*/); 298 336 this->data->material.select(); 299 337 … … 337 375 338 376 if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps)) 377 { 378 this->animationState.currentFrame = this->animationState.nextFrame; 379 this->animationState.nextFrame++; 380 381 if( this->animationState.nextFrame > this->animationState.endFrame ) 339 382 { 340 this->animationState.currentFrame = this->animationState.nextFrame; 341 this->animationState.nextFrame++; 342 343 if( this->animationState.nextFrame > this->animationState.endFrame ) 383 if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 344 384 { 345 if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 346 { 347 this->animationState.nextFrame = this->animationState.startFrame; 348 this->animationState.numPlays++; 349 } 350 else 351 { 352 this->animationState.nextFrame = this->animationState.endFrame; 353 } 385 this->animationState.nextFrame = this->animationState.startFrame; 386 this->animationState.numPlays++; 354 387 } 355 this->animationState.lastTime = this->animationState.localTime; 388 else 389 { 390 this->animationState.nextFrame = this->animationState.endFrame; 391 } 356 392 } 357 358 // if( this->animationState.currentFrame > (this->data->numFrames - 1) ) 359 // this->animationState.currentFrame = 0; 360 361 // if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 362 // this->animationState.nextFrame = 0; 393 this->animationState.lastTime = this->animationState.localTime; 394 } 395 396 // if( this->animationState.currentFrame > (this->data->numFrames - 1) ) 397 // this->animationState.currentFrame = 0; 398 399 // if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 400 // this->animationState.nextFrame = 0; 363 401 364 402 this->animationState.interpolationState = this->animationState.fps * 365 (this->animationState.localTime - this->animationState.lastTime);403 (this->animationState.localTime - this->animationState.lastTime); 366 404 } 367 405 … … 390 428 PRINT(0)("= Number of Frames: \t%i\n", this->data->header->numFrames); 391 429 PRINT(0)("= Height, Width:\t%i, %i\n", this->data->header->skinHeight, this->data->header->skinWidth); 392 PRINT(0)("= Pointer to the data object: %p\n", this->data);430 //PRINT(0)("= Pointer to the data object: %p\n", this->data); 393 431 PRINT(0)("===================================================\n\n"); 394 432 } … … 399 437 ********************************************************************************/ 400 438 439 MD2Data::MD2Data() 440 { 441 this->init(); 442 } 443 401 444 /** 402 445 \brief simple constructor … … 404 447 MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale) 405 448 { 406 scale *= 0.1f; 407 449 this->init(); 450 this->scaleFactor = scale * .1; 451 452 this->loadModel(modelFileName); 453 this->loadSkin(skinFileName); 454 } 455 456 void MD2Data::init() 457 { 458 this->scaleFactor = 1.0; 408 459 this->pVertices = NULL; 409 460 this->pGLCommands = NULL; 410 461 this->pLightNormals = NULL; 411 462 this->pTexCoor = NULL; 463 this->header = NULL; 412 464 413 465 this->numFrames = 0; … … 415 467 this->numGLCommands = 0; 416 468 this->numTexCoor = 0; 417 418 // this->scaleFactor = 1.0f; 419 this->scaleFactor = scale; 420 421 this->fileName = ""; 422 this->skinFileName = ""; 423 this->loadModel(modelFileName); 424 this->loadSkin(skinFileName); 425 } 426 469 } 427 470 428 471 /** … … 462 505 pFile = fopen(fileName.c_str(), "rb"); 463 506 if( unlikely(!pFile)) 464 465 466 467 507 { 508 PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n"); 509 return false; 510 } 468 511 this->header = new MD2Header; 469 512 fread(this->header, 1, sizeof(MD2Header), pFile); 470 513 /* check for the header version: make sure its a md2 file :) */ 471 514 if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT)) 472 473 474 475 515 { 516 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); 517 return false; 518 } 476 519 477 520 this->fileName =fileName; … … 506 549 507 550 for(int i = 0; i < this->numFrames; ++i) 551 { 552 frame = (sFrame*)(buffer + this->header->frameSize * i); 553 pVertex = this->pVertices + this->numVertices * i; 554 pNormals = this->pLightNormals + this->numVertices * i; 555 556 for(int j = 0; j < this->numVertices; ++j) 508 557 { 509 frame = (sFrame*)(buffer + this->header->frameSize * i); 510 pVertex = this->pVertices + this->numVertices * i; 511 pNormals = this->pLightNormals + this->numVertices * i; 512 513 for(int j = 0; j < this->numVertices; ++j) 514 { 515 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 516 pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor; 517 pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor; 518 pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor; 519 520 //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]); 521 522 pNormals[j] = frame->pVertices[j].lightNormalIndex; 523 } 558 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 559 pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor; 560 pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor; 561 pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor; 562 563 //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]); 564 565 pNormals[j] = frame->pVertices[j].lightNormalIndex; 524 566 } 525 PRINTF(4)("Finished loading the md2 file\n"); 567 } 568 PRINTF(4)("Finished loading the md2 file\n"); 526 569 527 570 delete [] buffer; … … 538 581 { 539 582 if( fileName.empty()) 540 541 542 543 583 { 584 this->skinFileName = ""; 585 return false; 586 } 544 587 545 588 this->skinFileName = fileName; -
trunk/src/lib/graphics/importer/md2/md2Model.h
r9235 r9869 20 20 21 21 #include "base_object.h" 22 #include "count_pointer.h" 22 23 23 24 #include "interactive_model.h" … … 45 46 struct MD2Header 46 47 { 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 48 int ident; //!< This is used to identify the file 49 int version; //!< The version number of the file (Must be 8) 50 51 int skinWidth; //!< The skin width in pixels 52 int skinHeight; //!< The skin height in pixels 53 int frameSize; //!< The size in bytes the frames are 54 55 int numSkins; //!< The number of skins associated with the model 56 int numVertices; //!< The number of vertices (constant for each frame) 57 int numTexCoords; //!< The number of texture coordinates 58 int numTriangles; //!< The number of faces (polygons) 59 int numGlCommands; //!< The number of gl commands 60 int numFrames; //!< The number of animation frames 61 62 int offsetSkins; //!< The offset in the file for the skin data 63 int offsetTexCoords; //!< The offset in the file for the texture data 64 int offsetTriangles; //!< The offset in the file for the face data 65 int offsetFrames; //!< The offset in the file for the frames data 66 int offsetGlCommands; //!< The offset in the file for the gl commands data 67 int offsetEnd; //!< The end of the file offset 67 68 }; 68 69 … … 70 71 //! animation names enumeration 71 72 typedef enum MD2animType 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 73 { 74 STAND, //0 75 RUN, //1 76 ATTACK, //2 77 PAIN_A, //3 78 PAIN_B, //4 79 PAIN_C, //5 80 JUMP, //6 81 FLIP, //7 82 SALUTE, //8 83 FALLBACK, //9 84 WAVE, //10 85 POINT, //11 86 CROUCH_STAND, 87 CROUCH_WALK, 88 CROUCH_ATTACK, 89 CROUCH_PAIN, 90 CROUCH_DEATH, 91 DEATH_FALLBACK, 92 DEATH_FALLFORWARD, 93 DEATH_FALLBACKSLOW, 94 BOOM, 95 WALK, 96 97 MAX_ANIMATIONS 98 }; 98 99 99 100 … … 116 117 class MD2Data : public BaseObject 117 118 { 118 public: 119 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 119 public: 120 typedef CountPointer<MD2Data> Pointer; 121 public: 122 MD2Data(); 123 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 120 124 virtual ~MD2Data(); 121 125 122 private: 123 bool loadModel(const std::string& fileName); 124 bool loadSkin(const std::string& fileName = ""); 125 126 public: 126 private: 127 void init(); 128 bool loadModel(const std::string& fileName); 129 bool loadSkin(const std::string& fileName = ""); 130 131 public: 127 132 int numFrames; //!< number of frames 128 133 int numVertices; //!< number of vertices … … 148 153 149 154 //! This is a MD2 Model class 150 class MD2Model : public InteractiveModel { 151 152 public: 155 class MD2Model : public InteractiveModel 156 { 157 ObjectListDeclaration(MD2Model); 158 public: 159 MD2Model(); 153 160 MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 161 MD2Model(const MD2Model& model); 154 162 virtual ~MD2Model(); 163 164 MD2Model& operator=(const MD2Model& md2model); 165 166 bool load(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 155 167 156 168 virtual void draw() const; … … 160 172 virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback); 161 173 /** returns the current animation @returns animation type */ 162 inline int MD2Model::getAnimation(){ return this->animationState.type; }174 inline int getAnimation() const { return this->animationState.type; } 163 175 virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; } 164 virtual bool isAnimationFinished(){ return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }176 virtual bool isAnimationFinished() const { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; } 165 177 /** scales the current model @param scaleFactor: the factor [0..1] to use for scaling */ 166 178 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} 167 179 180 181 void acquireData(const MD2Data::Pointer& data) { this->data = data; rebuildInfo(); }; 182 const MD2Data::Pointer& dataPointer() const { return this->data; }; 168 183 virtual void tick(float dtS); 169 184 void debug(); … … 171 186 172 187 private: 188 void init(); 189 void rebuildInfo(); 190 173 191 void animate(float time); 174 192 void processLighting(); … … 177 195 178 196 179 197 public: 180 198 /* these variables are static, because they are all the same for every model */ 181 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals182 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products183 static sAnim animationList[22]; //!< the anomation list184 185 float* shadeDots;186 187 MD2Data* data;//!< the md2 data pointer188 189 190 float scaleFactor; //!< the scale factor (individual)191 float animationSpeed; //!< the speed of the animation (factor for the time)192 sAnimState animationState; //!< animation state of the model193 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert199 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals 200 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products 201 static sAnim animationList[22]; //!< the anomation list 202 //! again one of these strange id software parts 203 float* shadeDots; 204 205 CountPointer<MD2Data> data; //!< the md2 data pointer 206 207 private: 208 float scaleFactor; //!< the scale factor (individual) 209 float animationSpeed; //!< the speed of the animation (factor for the time) 210 sAnimState animationState; //!< animation state of the model 211 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert 194 212 }; 195 213 -
trunk/src/lib/graphics/importer/md3/md3_model.h
r8724 r9869 45 45 46 46 virtual void setAnimation(int animNum, int playbackMode = 0) {} 47 virtual int getAnimation() { return 0;}47 virtual int getAnimation() const { return 0;} 48 48 49 49 virtual void tick(float dt); -
trunk/src/lib/graphics/importer/media_container.cc
r8316 r9869 26 26 27 27 #include "util/loading/resource_manager.h" 28 29 28 /* header for debug output */ 30 29 #include "debug.h" 31 30 31 ObjectListDefinition(MediaContainer); 32 32 33 33 /** … … 37 37 { 38 38 // set the class id for the base object 39 this-> setClassID(CL_MEDIA_CONTAINER, "MediaContainer");39 this->registerObject(this, MediaContainer::_objectList); 40 40 41 41 fps = 0; … … 91 91 return false; 92 92 // check whether file exists 93 if(!Resource Manager::isInDataDir(filename))93 if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename)) 94 94 { 95 95 PRINTF(1)("Could not find %s\n", filename.c_str()); … … 101 101 102 102 // Open video file 103 if (av_open_input_file(&format_context, Resource Manager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )104 { 105 PRINTF(1)("Could not open %s\n", Resource Manager::getFullName(filename).c_str());103 if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 ) 104 { 105 PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 106 106 return false; 107 107 } … … 110 110 if (av_find_stream_info(format_context) < 0) 111 111 { 112 PRINTF(1)("Could not find stream information in %s\n", Resource Manager::getFullName(filename).c_str());112 PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 113 113 return false; 114 114 } … … 119 119 if(video_stream == -1) 120 120 { 121 PRINTF(1)("Could not find a video stream in %s\n", Resource Manager::getFullName(filename).c_str());121 PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 122 122 return false; 123 123 } -
trunk/src/lib/graphics/importer/media_container.h
r7221 r9869 24 24 class MediaContainer : public TextureSequence 25 25 { 26 26 ObjectListDeclaration(MediaContainer); 27 27 private: 28 28 -
trunk/src/lib/graphics/importer/model.cc
r9406 r9869 20 20 #include "glincl.h" 21 21 22 22 ObjectListDefinition(Model); 23 23 24 24 /** … … 28 28 Model::Model() 29 29 { 30 this-> setClassID(CL_MODEL, "Model");30 this->registerObject(this, Model::_objectList); 31 31 this->pModelInfo.numVertices = 0; 32 32 this->pModelInfo.numTriangles = 0; -
trunk/src/lib/graphics/importer/model.h
r8035 r9869 54 54 //! This class defines the basic components of a model 55 55 class Model : virtual public BaseObject { 56 ObjectListDeclaration(Model); 56 57 57 58 public: -
trunk/src/lib/graphics/importer/movie_player.cc
r7221 r9869 24 24 // include your own header 25 25 #include "movie_player.h" 26 27 26 #include "util/loading/resource_manager.h" 28 27 … … 30 29 #include "debug.h" 31 30 31 ObjectListDefinition(MoviePlayer); 32 32 33 33 MoviePlayer::MoviePlayer(const std::string& filename) 34 34 { 35 35 // set the class id for the base object 36 this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer"); 37 36 this->registerObject(this, MoviePlayer::_objectList); 38 37 status = STOP; 39 38 timer = 0; … … 90 89 return false; 91 90 // check whether file exists 92 if(!Resource Manager::isInDataDir(filename))91 if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename)) 93 92 { 94 93 PRINTF(1)("Could not find %s\n", filename.c_str()); … … 100 99 101 100 // Open video file 102 if (av_open_input_file(&format_context, Resource Manager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )103 { 104 PRINTF(1)("Could not open %s\n", Resource Manager::getFullName(filename).c_str());101 if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 ) 102 { 103 PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 105 104 return false; 106 105 } … … 109 108 if (av_find_stream_info(format_context) < 0) 110 109 { 111 PRINTF(1)("Could not find stream information in %s\n", Resource Manager::getFullName(filename).c_str());110 PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 112 111 return false; 113 112 } … … 118 117 if(video_stream == -1) 119 118 { 120 PRINTF(1)("Could not find a video stream in %s\n", Resource Manager::getFullName(filename).c_str());119 PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 121 120 return false; 122 121 } -
trunk/src/lib/graphics/importer/movie_player.h
r7221 r9869 31 31 class MoviePlayer : public BaseObject 32 32 { 33 ObjectListDeclaration(MoviePlayer); 33 34 34 35 private: -
trunk/src/lib/graphics/importer/objModel.cc
r8369 r9869 18 18 #include "objModel.h" 19 19 20 #include <stdio.h>21 20 #include <string.h> 22 #include <stdlib.h>21 #include "loading/resource_manager.h" 23 22 24 23 #define PARSELINELENGTH 8192 … … 27 26 #include "compiler.h" 28 27 28 ObjectListDefinition(OBJModel); 29 29 /** 30 30 * @brief Crates a 3D-Model, loads in a File and scales it. … … 35 35 : StaticModel(fileName) 36 36 { 37 this-> setClassID(CL_OBJ_MODEL, "OBJModel");37 this->registerObject(this, OBJModel::_objectList); 38 38 39 39 this->objPath = "./"; 40 40 41 this->s caleFactor = scaling;41 this->setScaleFactor(scaling); 42 42 43 43 this->importFile (fileName); … … 77 77 else 78 78 this->objPath = "./"; 79 Material::addTexturePath(this->objPath);79 Resources::ResourceManager::getInstance()->addResourcePath("Texture", this->objPath); 80 80 81 81 this->readFromObjFile (fileName); -
trunk/src/lib/graphics/importer/objModel.h
r8369 r9869 12 12 class OBJModel : public StaticModel 13 13 { 14 public: 15 OBJModel(const std::string& fileName, float scaling = 1.0); 14 ObjectListDeclaration(OBJModel); 15 public: 16 OBJModel(const std::string& fileName, float scaling = 1.0); 16 17 virtual ~OBJModel(); 17 18 18 19 private: 19 20 ///// readin ///// 20 21 22 21 bool importFile (const std::string& fileName); 22 bool readFromObjFile (const std::string& fileName); 23 bool readMtlLib (const std::string& matFile); 23 24 24 25 26 27 28 29 30 25 private: 26 void setIllum (Material* material, const char* illum); 27 void setDiffuse (Material* material, const char* rgb); 28 void setAmbient (Material* material, const char* rgb); 29 void setSpecular (Material* material, const char* rgb); 30 void setShininess (Material* material, const char* shini); 31 void setTransparency (Material* material, const char* trans); 31 32 32 33 33 private: 34 std::string objPath; //!< The Path where the obj and mtl-file are located. 34 35 }; 35 36 -
trunk/src/lib/graphics/importer/static_model.cc
r9406 r9869 26 26 27 27 28 ////////////////////29 /// SUB-Elements ///30 ////////////////////31 /**32 * @brief creates a new ModelFaceElement33 */34 ModelFaceElement::ModelFaceElement()35 {36 this->vertexNumber = -1;37 this->normalNumber = -1;38 this->texCoordNumber = -1;39 40 this->next = NULL;41 }42 43 /**44 * @brief destroys a ModelFaceElement45 */46 ModelFaceElement::~ModelFaceElement()47 {48 if (this->next)49 delete this->next;50 }51 52 /**53 * @brief creates a new ModelFace54 */55 ModelFace::ModelFace()56 {57 this->vertexCount = 0;58 59 this->firstElem = NULL;60 61 this->material = NULL;62 63 this->next = NULL;64 }65 66 /**67 * deletes a ModelFace68 */69 ModelFace::~ModelFace()70 {71 PRINTF(5)("Cleaning up Face\n");72 73 if (this->firstElem != NULL)74 delete this->firstElem;75 76 if (this->next != NULL)77 delete this->next;78 }79 80 /**81 * @brief Creates a new ModelGroup82 */83 ModelGroup::ModelGroup()84 {85 PRINTF(4)("Adding new Group\n");86 this->name = "";87 this->faceMode = -1;88 this->faceCount = 0;89 this->next = NULL;90 this->listNumber = 0;91 this->indices = NULL;92 93 this->firstFace = new ModelFace;94 this->currentFace = this->firstFace;95 }96 97 /**98 * @brief deletes a ModelGroup99 */100 ModelGroup::~ModelGroup()101 {102 PRINTF(5)("Cleaning up group\n");103 if (this->firstFace != NULL)104 delete this->firstFace;105 106 // deleting the glList107 if (this->listNumber != 0)108 glDeleteLists(this->listNumber, 1);109 110 if (this->next !=NULL)111 delete this->next;112 113 }114 115 /**116 * @brief cleans up a ModelGroup117 *118 * actually does the same as the delete Operator, but does not delete the predecessing group119 */120 void ModelGroup::cleanup()121 {122 PRINTF(5)("Cleaning up group\n");123 if (this->firstFace)124 delete this->firstFace;125 this->firstFace = NULL;126 if (this->next)127 this->next->cleanup();128 }129 130 131 28 ///////////// 132 29 /// MODEL /// 133 30 ///////////// 31 ObjectListDefinition(StaticModel); 32 134 33 /** 135 34 * @brief Creates a 3D-Model. … … 138 37 */ 139 38 StaticModel::StaticModel(const std::string& modelName) 39 : data(new StaticModelData(modelName)) 140 40 { 141 this-> setClassID(CL_STATIC_MODEL, "StaticModel");41 this->registerObject(this, StaticModel::_objectList); 142 42 PRINTF(4)("new 3D-Model is being created\n"); 143 43 this->setName(modelName); 44 } 144 45 145 this->finalized = false; 46 StaticModel::StaticModel(const StaticModel& staticModel) 47 : data(staticModel.data) 48 { 49 this->registerObject(this, StaticModel::_objectList); 50 this->setName(staticModel.getName()); 51 this->updateBase(); 52 } 146 53 147 // setting the start group;148 this->currentGroup = this->firstGroup = new ModelGroup;149 this->groupCount = 0;150 this->faceCount = 0;151 152 this->scaleFactor = 1.0f;153 }154 54 155 55 /** … … 161 61 { 162 62 PRINTF(4)("Deleting Model "); 163 if (!this->getName().empty())164 {165 PRINT(4)("%s\n", this->getCName());166 }167 else168 {169 PRINT(4)("\n");170 }171 this->cleanup();172 173 PRINTF(5)("Deleting display Lists.\n");174 delete this->firstGroup;175 176 // deleting the MaterialList177 PRINTF(5)("Deleting Materials.\n");178 179 //! @todo do we really have to delete this material??180 std::list<ModelMaterial*>::iterator modMat;181 for(modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)182 {183 if (!(*modMat)->external)184 delete (*modMat)->material;185 delete (*modMat);186 }187 63 188 64 // mark this stuff as beeing deleted … … 190 66 this->pModelInfo.pNormals = NULL; 191 67 this->pModelInfo.pTexCoor = NULL; 68 this->pModelInfo.pTriangles = NULL; 192 69 } 70 71 StaticModel& StaticModel::operator=(const StaticModel& model) 72 { 73 this->data = model.data; 74 this->updateBase(); 75 return *this; 76 }; 77 193 78 194 79 /** … … 197 82 void StaticModel::finalize() 198 83 { 199 // this creates the display List. 200 this->importToDisplayList(); 201 this->buildTriangleList(); 202 203 // write out the modelInfo data used for the collision detection! 204 this->pModelInfo.pVertices = &this->vertices[0]; 205 this->pModelInfo.pNormals = &this->normals[0]; 206 this->pModelInfo.pTexCoor = &this->vTexture[0]; 207 208 this->finalized = true; 84 data->finalize(); 85 this->updateBase(); 209 86 } 210 87 211 /** 212 * @brief rebuild the Model from the Information we got. 213 */ 214 void StaticModel::rebuild() 88 void StaticModel::acquireData(const StaticModelData::Pointer& data) 215 89 { 216 PRINTF(3)("Rebuilding Model '%s'\n", this->getCName()); 217 this->finalize(); 218 } 219 220 ////////// 221 // DRAW // 222 ////////// 223 /** 224 * @brief Draws the Models of all Groups. 225 * 226 * It does this by just calling the Lists that must have been created earlier. 227 */ 228 void StaticModel::draw () const 229 { 230 PRINTF(4)("drawing the 3D-Models\n"); 231 ModelGroup* tmpGroup = this->firstGroup; 232 while (tmpGroup != NULL) 233 { 234 PRINTF(5)("Drawing model %s\n", tmpGroup->name.c_str()); 235 glCallList (tmpGroup->listNumber); 236 tmpGroup = tmpGroup->next; 237 } 238 } 239 240 241 /** 242 * @brief Draws the Model number groupNumber 243 * @param groupNumber The number of the group that will be displayed. 244 * 245 * It does this by just calling the List that must have been created earlier. 246 */ 247 void StaticModel::draw (int groupNumber) const 248 { 249 if (unlikely(groupNumber >= this->groupCount)) 250 { 251 PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); 252 return; 253 } 254 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 255 ModelGroup* tmpGroup = this->firstGroup; 256 int counter = 0; 257 while (tmpGroup != NULL) 258 { 259 if (counter == groupNumber) 260 { 261 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name.c_str()); 262 glCallList (tmpGroup->listNumber); 263 return; 264 } 265 ++counter; 266 tmpGroup = tmpGroup->next; 267 } 268 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getCName()); 269 return; 270 } 271 272 273 /** 274 * @brief Draws the Model with a specific groupName 275 * @param groupName The name of the group that will be displayed. 276 * 277 * It does this by just calling the List that must have been created earlier. 278 */ 279 void StaticModel::draw (const std::string& groupName) const 280 { 281 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 282 ModelGroup* tmpGroup = this->firstGroup; 283 while (tmpGroup != NULL) 284 { 285 if (tmpGroup->name == groupName) 286 { 287 PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str()); 288 glCallList (tmpGroup->listNumber); 289 return; 290 } 291 tmpGroup = tmpGroup->next; 292 } 293 PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getCName()); 294 return; 295 } 296 297 ////////// 298 // INIT // 299 ////////// 300 301 /** 302 * @brief finalizes an Model. 303 * 304 * This funcion is needed, to delete all the Lists, and arrays that are no more 305 * needed because they are already imported into openGL. 306 * This will be applied at the end of the importing Process. 307 */ 308 bool StaticModel::cleanup() 309 { 310 PRINTF(4)("cleaning up the 3D-Model to save Memory.\n"); 311 this->firstGroup->cleanup(); 312 return true; 313 } 314 315 ////////// 316 // MESH // 317 ////////// 318 /** 319 * @brief adds a new Material to the Material List 320 * @param material the Material to add 321 * @returns the added material 322 * 323 * this also tells this Model, that all the Materials are handled externally 324 * with this option set the Materials will not be deleted with the Model. 325 */ 326 Material* StaticModel::addMaterial(Material* material) 327 { 328 if (material == NULL) 329 return NULL; 330 ModelMaterial* modMat = new ModelMaterial; 331 modMat->external = true; 332 modMat->material = material; 333 this->materialList.push_back(modMat); 334 return modMat->material; 335 } 336 337 /** 338 * @brief adds a new Material to the Material List 339 * @param materialName the name of the Material to add 340 * @returns the added material 341 */ 342 Material* StaticModel::addMaterial(const std::string& materialName) 343 { 344 ModelMaterial* modMat = new ModelMaterial; 345 modMat->external = false; 346 modMat->material = new Material(materialName); 347 348 // adding material to the List of materials 349 this->materialList.push_back(modMat); 350 return modMat->material; 351 } 352 353 /** 354 * @brief finds a Material by its name and returns it 355 * @param materialName the Name of the material to search for. 356 * @returns the Material if found, NULL otherwise 357 */ 358 Material* StaticModel::findMaterialByName(const std::string& materialName) 359 { 360 std::list<ModelMaterial*>::iterator modMat; 361 for (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++) 362 if (materialName == (*modMat)->material->getName()) 363 return (*modMat)->material; 364 return NULL; 365 } 366 367 /** 368 * @brief parses a group String 369 * @param groupString the new Group to create 370 * 371 * This function initializes a new Group. 372 * With it you should be able to create Models with more than one SubModel inside 373 */ 374 bool StaticModel::addGroup(const std::string& groupString) 375 { 376 PRINTF(5)("Read Group: %s.\n", groupString.c_str()); 377 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 378 { 379 // finalizeGroup(currentGroup); 380 this->currentGroup = this->currentGroup->next = new ModelGroup; 381 } 382 // setting the group name if not default. 383 if (groupString == "default") 384 { 385 this->currentGroup->name = groupString; 386 } 387 ++this->groupCount; 388 return true; 389 } 390 391 /** 392 * @brief parses a vertex-String 393 * @param vertexString The String that will be parsed. 394 * 395 * If a vertex line is found this function will inject it into the vertex-Array 396 */ 397 bool StaticModel::addVertex (const std::string& vertexString) 398 { 399 float subbuffer1; 400 float subbuffer2; 401 float subbuffer3; 402 sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 403 this->vertices.push_back(subbuffer1*scaleFactor); 404 this->vertices.push_back(subbuffer2*scaleFactor); 405 this->vertices.push_back(subbuffer3*scaleFactor); 406 this->pModelInfo.numVertices++; 407 return true; 408 } 409 410 /** 411 * @brief parses a vertex-String 412 * @param x the X-coordinate of the Vertex to add. 413 * @param y the Y-coordinate of the Vertex to add. 414 * @param z the Z-coordinate of the Vertex to add. 415 */ 416 bool StaticModel::addVertex(float x, float y, float z) 417 { 418 PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z); 419 this->vertices.push_back(x*scaleFactor); 420 this->vertices.push_back(y*scaleFactor); 421 this->vertices.push_back(z*scaleFactor); 422 this->pModelInfo.numVertices++; 423 return true; 424 } 425 426 /** 427 * @brief parses a vertexNormal-String 428 * @param normalString The String that will be parsed. 429 * 430 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 431 */ 432 bool StaticModel::addVertexNormal (const std::string& normalString) 433 { 434 float subbuffer1; 435 float subbuffer2; 436 float subbuffer3; 437 sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 438 this->normals.push_back(subbuffer1); 439 this->normals.push_back(subbuffer2); 440 this->normals.push_back(subbuffer3); 441 this->pModelInfo.numNormals++; 442 return true; 443 } 444 445 /** 446 * @brief adds a VertexNormal. 447 * @param x The x coordinate of the Normal. 448 * @param y The y coordinate of the Normal. 449 * @param z The z coordinate of the Normal. 450 * 451 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 452 */ 453 bool StaticModel::addVertexNormal(float x, float y, float z) 454 { 455 PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z); 456 this->normals.push_back(x); 457 this->normals.push_back(y); 458 this->normals.push_back(z); 459 this->pModelInfo.numNormals++; 460 return true; 461 } 462 463 /** 464 * @brief parses a vertexTextureCoordinate-String 465 * @param vTextureString The String that will be parsed. 466 * 467 * If a vertexTextureCoordinate line is found, 468 * this function will inject it into the vertexTexture-Array 469 * 470 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 471 */ 472 bool StaticModel::addVertexTexture (const std::string& vTextureString) 473 { 474 float subbuffer1; 475 float subbuffer2; 476 sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2); 477 this->vTexture.push_back(subbuffer1); 478 this->vTexture.push_back(1 - subbuffer2); 479 this->pModelInfo.numTexCoor++; 480 return true; 481 } 482 483 /** 484 * @brief adds a Texture Coordinate 485 * @param u The u coordinate of the TextureCoordinate. 486 * @param v The y coordinate of the TextureCoordinate. 487 * 488 * If a TextureCoordinate line is found this function will 489 * inject it into the TextureCoordinate-Array 490 */ 491 bool StaticModel::addVertexTexture(float u, float v) 492 { 493 PRINTF(5)("found vertex-Texture %f, %f\n", u, v); 494 this->vTexture.push_back(u); 495 this->vTexture.push_back(v); 496 this->pModelInfo.numTexCoor++; 497 return true; 498 } 499 500 /** 501 * @brief parses a face-string 502 * @param faceString The String that will be parsed. 503 * 504 * If a face line is found this function will add it to the glList. 505 * 506 * String is different from the argument addFace, 507 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 508 * 509 * @TODO make it std::string conform 510 */ 511 bool StaticModel::addFace (const std::string& faceStringInput) 512 { 513 const char* faceString = faceStringInput.c_str(); 514 if (this->currentGroup->faceCount >0) 515 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 516 517 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 518 tmpElem->next = NULL; 519 while(strcmp (faceString, "\0")) 520 { 521 if (this->currentGroup->currentFace->vertexCount>0) 522 tmpElem = tmpElem->next = new ModelFaceElement; 523 tmpElem->next = NULL; 524 525 char tmpValue [50]; 526 int tmpLen; 527 char* vertex = NULL; 528 char* texture = NULL; 529 char* normal = NULL; 530 531 sscanf (faceString, "%s", tmpValue); 532 tmpLen = strlen(tmpValue); 533 vertex = tmpValue; 534 535 if ((texture = strstr (vertex, "/")) != NULL) 536 { 537 texture[0] = '\0'; 538 texture ++; 539 540 if ((normal = strstr (texture, "/")) !=NULL) 541 { 542 normal[0] = '\0'; 543 normal ++; 544 } 545 } 546 if (vertex) 547 tmpElem->vertexNumber = atoi(vertex)-1; 548 if (texture) 549 tmpElem->texCoordNumber = atoi(texture)-1; 550 if (normal) 551 tmpElem->normalNumber = atoi(normal)-1; 552 553 faceString += tmpLen; 554 if (strcmp (faceString, "\0")) 555 faceString++; 556 this->currentGroup->currentFace->vertexCount++; 557 } 558 559 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; 560 this->faceCount += this->currentGroup->currentFace->vertexCount -2; 561 return true; 90 this->data = data; 91 this->updateBase(); 562 92 } 563 93 … … 569 99 bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...) 570 100 { 571 if (this->currentGroup->faceCount > 0)572 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;573 574 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;575 576 101 va_list itemlist; 577 102 va_start (itemlist, type); 578 579 for (int i = 0; i < faceElemCount; i++) 580 { 581 if (this->currentGroup->currentFace->vertexCount > 0) 582 tmpElem = tmpElem->next = new ModelFaceElement; 583 584 tmpElem->vertexNumber = va_arg (itemlist, int); 585 if (type & TEXCOORD) 586 tmpElem->texCoordNumber = va_arg (itemlist, int); 587 if (type & NORMAL) 588 tmpElem->normalNumber = va_arg(itemlist, int); 589 this->currentGroup->currentFace->vertexCount++; 590 } 103 bool retVal = this->data->addFace(faceElemCount, type, itemlist); 591 104 va_end(itemlist); 592 593 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2; 594 this->faceCount += this->currentGroup->currentFace->vertexCount -2; 595 return true; 105 return retVal; 596 106 } 597 107 598 /** 599 * Function that selects a material, if changed in the obj file. 600 * @param matString the Material that will be set. 601 */ 602 bool StaticModel::setMaterial(const std::string& matString) 108 void StaticModel::updateBase() 603 109 { 604 if (this->currentGroup->faceCount > 0) 605 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 110 // write out the modelInfo data used for the collision detection! 111 this->pModelInfo.pVertices = &this->data->getVertices()[0]; 112 this->pModelInfo.numVertices = this->data->getVertices().size(); 113 this->pModelInfo.pNormals = &this->data->getNormals()[0]; 114 this->pModelInfo.numNormals = this->data->getNormals().size(); 115 this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0]; 116 this->pModelInfo.numTexCoor = this->data->getTexCoords().size(); 606 117 607 this->currentGroup->currentFace->material = this->findMaterialByName(matString); 608 609 if (this->currentGroup->faceCount == 0) 610 this->currentGroup->faceCount++; 611 return true; 612 } 613 614 /** 615 * Function that selects a material, if changed in the obj file. 616 * @param mtl the Material that will be set. 617 */ 618 bool StaticModel::setMaterial(Material* mtl) 619 { 620 if (this->currentGroup->faceCount > 0) 621 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 622 623 this->currentGroup->currentFace->material = mtl; 624 625 if (this->currentGroup->faceCount == 0) 626 this->currentGroup->faceCount++; 627 return true; 628 } 629 630 /** 631 * @brief A routine that is able to create normals. 632 * 633 * The algorithm does the following: 634 * 1. It calculates creates Vectors for each normale, and sets them to zero. 635 * 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements 636 * 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal. 637 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array. 638 */ 639 bool StaticModel::buildVertexNormals () 640 { 641 PRINTF(4)("Normals are being calculated.\n"); 642 643 Vector* normArray = new Vector [vertices.size()/3]; 644 for (unsigned int i=0; i<vertices.size()/3;i++) 645 normArray[i] = Vector(.0,.0,.0); 646 647 Vector prevV; 648 Vector nextV; 649 Vector curV; 650 651 ModelGroup* tmpGroup = firstGroup; 652 while (tmpGroup != NULL) 653 { 654 ModelFace* tmpFace = tmpGroup->firstFace; 655 while (tmpFace != NULL) 656 { 657 if (tmpFace->firstElem != NULL) 658 { 659 ModelFaceElement* firstElem = tmpFace->firstElem; 660 ModelFaceElement* prevElem; 661 ModelFaceElement* curElem = firstElem; 662 ModelFaceElement* nextElem; 663 ModelFaceElement* lastElem; 664 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 665 while (curElem != NULL) 666 { 667 prevElem = curElem; 668 curElem = curElem->next; 669 } 670 lastElem = prevElem; 671 672 curElem = firstElem; 673 for (unsigned int j = 0; j < tmpFace->vertexCount; j++) 674 { 675 if (!(nextElem = curElem->next)) 676 nextElem = firstElem; 677 curElem->normalNumber = curElem->vertexNumber; 678 679 curV = Vector (this->vertices[curElem->vertexNumber*3], 680 this->vertices[curElem->vertexNumber*3+1], 681 this->vertices[curElem->vertexNumber*3+2]); 682 683 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 684 this->vertices[prevElem->vertexNumber*3+1], 685 this->vertices[prevElem->vertexNumber*3+2]) - curV; 686 687 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 688 this->vertices[nextElem->vertexNumber*3+1], 689 this->vertices[nextElem->vertexNumber*3+2]) - curV; 690 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 691 692 prevElem = curElem; 693 curElem = curElem->next; 694 } 695 } 696 tmpFace = tmpFace->next; 697 } 698 tmpGroup = tmpGroup->next; 699 } 700 701 for (unsigned int i=0; i < this->vertices.size()/3;i++) 702 { 703 normArray[i].normalize(); 704 PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 705 706 this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z); 707 708 } 709 delete[] normArray; 710 return true; 711 } 712 713 //////////// 714 // openGL // 715 //////////// 716 /** 717 * reads and includes the Faces/Materials into the openGL state Machine 718 */ 719 bool StaticModel::importToDisplayList() 720 { 721 // finalize the Arrays 722 if (normals.size() == 0) // vertices-Array must be built for this 723 this->buildVertexNormals(); 724 725 this->currentGroup = this->firstGroup; 726 727 while (this->currentGroup != NULL) 728 { 729 730 // creating a glList for the Group 731 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 732 { 733 PRINTF(2)("glList could not be created for this Model\n"); 734 return false; 735 } 736 glNewList (this->currentGroup->listNumber, GL_COMPILE); 737 738 // Putting Faces to GL 739 ModelFace* tmpFace = this->currentGroup->firstFace; 740 while (tmpFace != NULL) 741 { 742 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 743 { 744 if (this->currentGroup->faceMode != -1) 745 glEnd(); 746 this->currentGroup->faceMode = 0; 747 if (tmpFace->material != NULL) 748 { 749 tmpFace->material->select(); 750 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getCName()); 751 } 752 } 753 754 else if (tmpFace->vertexCount == 3) 755 { 756 if (this->currentGroup->faceMode != 3) 757 { 758 if (this->currentGroup->faceMode != -1) 759 glEnd(); 760 glBegin(GL_TRIANGLES); 761 } 762 763 this->currentGroup->faceMode = 3; 764 PRINTF(5)("found triag.\n"); 765 } 766 767 else if (tmpFace->vertexCount == 4) 768 { 769 if (this->currentGroup->faceMode != 4) 770 { 771 if (this->currentGroup->faceMode != -1) 772 glEnd(); 773 glBegin(GL_QUADS); 774 } 775 this->currentGroup->faceMode = 4; 776 PRINTF(5)("found quad.\n"); 777 } 778 779 else if (tmpFace->vertexCount > 4) 780 { 781 if (this->currentGroup->faceMode != -1) 782 glEnd(); 783 glBegin(GL_POLYGON); 784 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 785 this->currentGroup->faceMode = tmpFace->vertexCount; 786 } 787 788 ModelFaceElement* tmpElem = tmpFace->firstElem; 789 while (tmpElem != NULL) 790 { 791 // PRINTF(2)("%s\n", tmpElem->value); 792 this->addGLElement(tmpElem); 793 tmpElem = tmpElem->next; 794 } 795 tmpFace = tmpFace->next; 796 } 797 glEnd(); 798 glEndList(); 799 800 this->currentGroup = this->currentGroup->next; 801 } 802 return true; 118 this->pModelInfo.pTriangles = this->data->getTrianglesExt(); 119 this->pModelInfo.numTriangles = this->data->getTriangles().size(); 803 120 } 804 121 805 122 806 123 /** 807 * builds an array of triangles, that can later on be used for obb separation and octree separation 124 * Includes a default model 125 * 126 * This will inject a Cube, because this is the most basic model. 808 127 */ 809 bool StaticModel::buildTriangleList()810 {811 if( unlikely(this->pModelInfo.pTriangles != NULL))812 return true;813 /* make sure, that all the arrays are finalized */814 if( normals.size() == 0) // vertices-Array must be built for this815 this->buildVertexNormals();816 817 int index = 0; //!< the counter for the triangle array818 ModelFaceElement* tmpElem; //!< the temporary faceelement reference819 ModelFace* tmpFace; //!< the temporary face referece820 821 bool warned = false;822 823 this->pModelInfo.numTriangles = 0;824 825 /* count the number of triangles */826 /* now iterate through all groups and build up the triangle list */827 this->currentGroup = this->firstGroup;828 while( this->currentGroup != NULL)829 {830 tmpFace = this->currentGroup->firstFace;831 while( tmpFace != NULL)832 {833 /* if its a triangle just add it to the list */834 if( tmpFace->vertexCount == 3){835 ++this->pModelInfo.numTriangles;836 } /* if the polygon is a quad */837 else if( tmpFace->vertexCount == 4) {838 this->pModelInfo.numTriangles += 2;839 }840 else if( tmpFace->vertexCount > 4) {841 if (!warned) {842 PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getCName());843 warned = true;844 }845 }846 tmpFace = tmpFace->next;847 }848 this->currentGroup = this->currentGroup->next;849 }850 851 PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);852 853 854 /* write MODELINFO structure */855 856 /* allocate memory for the new triangle structures */857 if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL)858 {859 PRINTF(1)("Could not allocate memory for triangle list\n");860 return false;861 }862 863 /* now iterate through all groups and build up the triangle list */864 this->currentGroup = this->firstGroup;865 while( this->currentGroup != NULL)866 {867 tmpFace = this->currentGroup->firstFace;868 while( tmpFace != NULL)869 {870 tmpElem = tmpFace->firstElem;871 872 /* if its a triangle just add it to the list */873 if( tmpFace->vertexCount == 3)874 {875 for( int j = 0; j < 3; ++j)876 {877 this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;878 this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;879 this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;880 tmpElem = tmpElem->next;881 882 }883 ++index;884 } /* if the polygon is a quad */885 else if( tmpFace->vertexCount == 4)886 {887 888 this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;889 this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;890 this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;891 892 this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;893 this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;894 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;895 tmpElem = tmpElem->next;896 897 this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;898 this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;899 this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;900 tmpElem = tmpElem->next;901 902 this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;903 this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;904 this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;905 906 this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;907 this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;908 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;909 tmpElem = tmpElem->next;910 911 this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;912 this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;913 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;914 915 index += 2;916 }917 tmpFace = tmpFace->next;918 }919 this->currentGroup = this->currentGroup->next;920 }921 return true;922 }923 924 925 /**926 * Adds a Face-element (one vertex of a face) with all its information.927 * @param elem The FaceElement to add to the OpenGL-environment.928 929 It does this by searching:930 1. The Vertex itself931 2. The VertexNormale932 3. The VertexTextureCoordinate933 merging this information, the face will be drawn.934 */935 bool StaticModel::addGLElement (ModelFaceElement* elem)936 {937 PRINTF(5)("importing grafical Element to openGL.\n");938 939 if (elem->texCoordNumber > -1)940 {941 if (likely((unsigned int)elem->texCoordNumber < this->pModelInfo.numTexCoor))942 glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);943 else944 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",945 elem->texCoordNumber, this->pModelInfo.numTexCoor);946 }947 if (elem->normalNumber > -1)948 {949 if (likely((unsigned int)elem->normalNumber < this->pModelInfo.numNormals))950 glNormal3fv(&this->normals[0] + elem->normalNumber * 3);951 else952 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",953 elem->normalNumber, this->pModelInfo.numNormals);954 }955 if (elem->vertexNumber > -1)956 {957 if (likely((unsigned int)elem->vertexNumber < this->pModelInfo.numVertices))958 glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);959 else960 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",961 elem->vertexNumber, this->pModelInfo.numVertices);962 }963 964 return true;965 }966 967 /**968 * Includes a default model969 970 This will inject a Cube, because this is the most basic model.971 */972 128 void StaticModel::cubeModel() 973 129 { -
trunk/src/lib/graphics/importer/static_model.h
r7221 r9869 10 10 11 11 #include "material.h" 12 #include "glincl.h"13 12 #include <vector> 14 #include <list> 15 16 // definition of different modes for setting up Faces 17 #define VERTEX 0 //!< If Faces are created WITH Vertex-Coordinate 18 #define NORMAL 1 //!< If Faces are created WITH Normals (otherwise autocalculate) 19 #define TEXCOORD 2 //!< If Faces are created WITH TextureCoordinate 20 21 //! an enumerator for VERTEX_FORMAT 22 typedef enum VERTEX_FORMAT { 23 VERTEX_ONLY = VERTEX, 24 VERTEX_NORMAL = NORMAL, 25 VERTEX_TEXCOORD = TEXCOORD, 26 VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD 27 }; 28 29 //////////////////// 30 /// SUB-ELEMENTS /// 31 //////////////////// 32 //! This is the placeholder of one Vertex beloning to a Face. 33 class ModelFaceElement 34 { 35 public: 36 ModelFaceElement(); 37 ~ModelFaceElement(); 38 39 int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. 40 int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. 41 int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. 42 43 ModelFaceElement* next; //!< Point to the next FaceElement in this List. 44 }; 45 46 //! This is the placeholder of a Face belonging to a Group of Faces. 47 class ModelFace 48 { 49 public: 50 ModelFace(); 51 ~ModelFace(); 52 53 unsigned int vertexCount; //!< The Count of vertices this Face has. 54 ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. 55 Material* material; //!< The Material to use. 56 57 ModelFace* next; //!< Pointer to the next Face. 58 }; 59 60 //! Group to handle multiple Models per obj-file. 61 class ModelGroup 62 { 63 public: 64 ModelGroup(); 65 ~ModelGroup(); 66 67 void cleanup(); 68 69 std::string name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function. 70 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 71 GLuint listNumber; //!< The number of the GL-List this Group gets. 72 ModelFace* firstFace; //!< The first Face in this group. 73 ModelFace* currentFace; //!< The current Face in this Group (the one we are currently working with.) 74 int faceMode; //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material, 3 for triangle, 4 for Quad, 5+ for Poly @todo ENUM... 75 int faceCount; //!< The Number of Faces this Group holds. 76 77 ModelGroup* next; //!< Pointer to the next Group. 78 }; 79 80 struct ModelMaterial 81 { 82 Material* material; 83 bool external; 84 }; 13 #include "static_model_data.h" 85 14 86 15 ///////////// … … 94 23 class StaticModel : public Model 95 24 { 96 public: 25 ObjectListDeclaration(StaticModel); 26 public: 97 27 StaticModel(const std::string& modelName = ""); 28 StaticModel(const StaticModel& staticModel); 98 29 virtual ~StaticModel(); 99 30 100 virtual void draw() const; 101 void draw(int groupNumber) const; 102 void draw(const std::string& groupName) const; 31 StaticModel& operator=(const StaticModel& model); 103 32 104 void rebuild(); 33 virtual void draw() const { data->draw(); }; 34 void draw(int groupNumber) const { data->draw(groupNumber); }; 35 void draw(const std::string& groupName) const { data->draw(groupName); }; 105 36 106 Material* addMaterial(Material* material); 107 Material* addMaterial(const std::string& materialName); 37 void rebuild() { data->rebuild(); }; 108 38 109 bool addGroup(const std::string& groupString); 39 Material* addMaterial(Material* material) { return data->addMaterial(material); }; 40 Material* addMaterial(const std::string& materialName) { return data->addMaterial(materialName); }; 110 41 111 bool addVertex(const std::string& vertexString); 112 bool addVertex(float x, float y, float z); 42 bool addGroup(const std::string& groupString) { return data->addGroup(groupString); }; 113 43 114 bool addFace(const std::string& faceString); 44 bool addVertex(const std::string& vertexString) { return data->addVertex(vertexString); }; 45 bool addVertex(float x, float y, float z) { return data->addVertex(x, y, z); }; 46 47 bool addFace(const std::string& faceString) { return data->addFace(faceString); }; 115 48 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 116 49 117 bool addVertexNormal(const std::string& normalString) ;118 bool addVertexNormal(float x, float y, float z) ;50 bool addVertexNormal(const std::string& normalString) { return this->data->addVertexNormal(normalString); }; 51 bool addVertexNormal(float x, float y, float z) { return this->data->addVertexNormal(x,y,z); }; 119 52 120 bool addVertexTexture(const std::string& vTextureString) ;121 bool addVertexTexture(float u, float v) ;53 bool addVertexTexture(const std::string& vTextureString) { return this->data->addVertexTexture(vTextureString); }; 54 bool addVertexTexture(float u, float v) { return this->data->addVertexTexture(u, v); }; 122 55 123 bool setMaterial(const std::string& mtlString) ;124 bool setMaterial(Material* mtl) ;56 bool setMaterial(const std::string& mtlString) { return data->setMaterial(mtlString); }; 57 bool setMaterial(Material* mtl) { return data->setMaterial(mtl);}; 125 58 126 59 void finalize(); 127 60 61 void acquireData(const StaticModelData::Pointer& data); 62 const StaticModelData::Pointer& dataPointer() const { return this->data; }; 128 63 129 protected: 64 inline void setScaleFactor(float scaleFactor) { this->data->setScaleFactor(scaleFactor); }; 65 float getScaleFactor() const { return data->getScaleFactor(); } 66 67 protected: 130 68 void cubeModel(); 131 69 132 Material* findMaterialByName(const std::string& materialName); 133 134 protected: 135 float scaleFactor; //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation 136 137 private: 138 bool buildVertexNormals(); 139 140 bool importToDisplayList(); 141 bool buildTriangleList(); 142 143 bool addGLElement(ModelFaceElement* elem); 144 145 bool cleanup(); 146 147 private: 148 bool finalized; //!< Sets the Object to be finalized. 149 150 unsigned int faceCount; //!< A modelwide Counter for the faces 151 152 std::vector<GLfloat> vertices; //!< The Array that handles the Vertices. 153 std::vector<GLfloat> normals; //!< The Array that handles the Normals. 154 std::vector<GLfloat> vTexture; //!< The Array that handles the VertexTextureCoordinates. 155 156 ModelGroup* firstGroup; //!< The first of all groups. 157 ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. 158 int groupCount; //!< The Count of Groups. 159 160 std::list<ModelMaterial*> materialList; //!< A list for all the Materials in this Model 70 private: 71 void updateBase(); 72 private: 73 StaticModelData::Pointer data; 161 74 }; 162 75 -
trunk/src/lib/graphics/importer/texture.cc
r9406 r9869 64 64 #endif 65 65 66 66 ObjectListDefinition(Texture); 67 67 68 68 /** … … 86 86 : data(texture.data) 87 87 { 88 this-> setClassID(CL_TEXTURE, "Texture");88 this->registerObject(this, Texture::_objectList); 89 89 this->priority = 0.5; 90 90 } … … 149 149 void Texture::init() 150 150 { 151 this-> setClassID(CL_TEXTURE, "Texture");152 153 this->data = TextureData Pointer(new TextureData());151 this->registerObject(this, Texture::_objectList); 152 153 this->data = TextureData::Pointer(new TextureData()); 154 154 155 155 this->priority = 0.5; … … 176 176 } 177 177 178 Texture& Texture::operator=(const TextureData Pointer& textureDataPointer)178 Texture& Texture::operator=(const TextureData::Pointer& textureDataPointer) 179 179 { 180 180 this->data = textureDataPointer; -
trunk/src/lib/graphics/importer/texture.h
r8761 r9869 1 1 /*! 2 2 * @file texture.h 3 * @brief Contains the texture class, that handles the reading of Images into Tex utre-files.3 * @brief Contains the texture class, that handles the reading of Images into Texture-files. 4 4 */ 5 5 … … 20 20 class Texture : public BaseObject 21 21 { 22 ObjectListDeclaration(Texture); 22 23 public: 23 24 Texture(); … … 28 29 29 30 Texture& operator=(const Texture& texture); 30 Texture& operator=(const TextureDataPointer& textureDataPointer); 31 Texture& operator=(const TextureData::Pointer& textureDataPointer); 32 void acquireData(const TextureData::Pointer& textureDataPointer) { this->data = textureDataPointer; }; 33 const TextureData::Pointer& dataPointer() const { return data; } 31 34 32 35 virtual ~Texture(); … … 62 65 63 66 private: 64 TextureData Pointerdata; //!< The TextureData67 TextureData::Pointer data; //!< The TextureData 65 68 GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem) 66 69 -
trunk/src/lib/graphics/importer/texture_data.h
r8761 r9869 18 18 class TextureData 19 19 { 20 public: 21 typedef CountPointer<TextureData> Pointer; 20 22 public: 21 23 TextureData(); … … 43 45 }; 44 46 45 typedef CountPointer<TextureData> TextureDataPointer;46 47 47 #endif /* _TEXTURE_DATA_H */ -
trunk/src/lib/graphics/importer/texture_sequence.cc
r9406 r9869 28 28 #endif 29 29 30 ObjectListDefinition(TextureSequence); 31 30 32 /** 31 33 * @brief Constructor for a Texture … … 33 35 TextureSequence::TextureSequence(unsigned int count, ...) 34 36 { 35 this-> setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");37 this->registerObject(this, TextureSequence::_objectList); 36 38 37 39 va_list textureNameList; … … 54 56 TextureSequence::TextureSequence(const std::vector<std::string>& textureNames, const std::string& prependFolder) 55 57 { 56 this-> setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");58 this->registerObject(this, TextureSequence::_objectList); 57 59 this->loadImageSeries(textureNames, prependFolder); 58 60 } -
trunk/src/lib/graphics/importer/texture_sequence.h
r8324 r9869 15 15 class TextureSequence : public Texture 16 16 { 17 ObjectListDeclaration(TextureSequence); 17 18 public: 18 19 TextureSequence(unsigned int count = 0, ...); -
trunk/src/lib/graphics/importer/vertex_array_model.cc
r9406 r9869 24 24 25 25 26 ObjectListDefinition(VertexArrayModel); 26 27 27 28 ///////////// … … 35 36 VertexArrayModel::VertexArrayModel() 36 37 { 37 this-> setClassID(CL_MODEL, "VertexArrayModel");38 this->registerObject(this, VertexArrayModel::_objectList); 38 39 39 40 this->newStripe(); … … 49 50 VertexArrayModel::VertexArrayModel(const Model& model) 50 51 { 51 this-> setClassID(CL_MODEL, "VertexArrayModel");52 this->registerObject(this, VertexArrayModel::_objectList); 52 53 53 54 // importing the data to the new Model. -
trunk/src/lib/graphics/importer/vertex_array_model.h
r6769 r9869 27 27 class VertexArrayModel : public Model 28 28 { 29 public: 29 ObjectListDeclaration(VertexArrayModel); 30 public: 30 31 VertexArrayModel(); 31 32 VertexArrayModel(const Model& model); -
trunk/src/lib/graphics/light.cc
r8742 r9869 22 22 #include "glincl.h" 23 23 #include "vector.h" 24 #include "parser/tinyxml/tinyxml.h" 25 #include "util/loading/load_param.h" 24 #include "util/loading/load_param_xml.h" 26 25 #include "util/loading/factory.h" 27 26 #include "debug.h" 28 27 29 CREATE_FACTORY(Light, CL_LIGHT); 28 #include "class_id_DEPRECATED.h" 29 30 ObjectListDefinitionID(Light, CL_LIGHT); 31 CREATE_FACTORY(Light); 30 32 31 33 //! Definition of the Lights and their Names … … 51 53 PRINTF(4)("initializing Light number %d.\n", this->lightNumber); 52 54 55 this->registerObject(this, Light::_objectList); 56 53 57 this->lightNumber = LightManager::getInstance()->registerLight(this); 54 58 55 this->setClassID(CL_LIGHT, "Light");56 59 char tmpName[10]; 57 60 sprintf(tmpName, "Light[%d]", this->lightNumber); … … 211 214 ** LIGHT-MANAGER ** 212 215 ******************/ 216 ObjectListDefinition(LightManager); 213 217 /** 214 218 * standard constructor for a Light … … 216 220 LightManager::LightManager () 217 221 { 218 this-> setClassID(CL_LIGHT_MANAGER, "LightManager");222 this->registerObject(this, LightManager::_objectList); 219 223 220 224 glEnable (GL_LIGHTING); -
trunk/src/lib/graphics/light.h
r8255 r9869 25 25 class Light : public PNode 26 26 { 27 public: 28 Light(const TiXmlElement* root = NULL); 29 virtual ~Light(); 30 31 virtual void loadParams(const TiXmlElement* root); 32 33 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 34 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 35 void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 36 void setSpotDirection(const Vector& direction); 37 void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); }; 38 void setSpotCutoff(GLfloat cutoff); 39 40 /** @returns the lightNumber*/ 41 int getLightNumber() const {return this->lightNumber;} 42 43 virtual void draw() const; 44 45 void debug() const; 46 47 // attributes 48 private: 49 int lightNumber; //!< The number of this Light. 50 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. 51 GLfloat specularColor[4]; //!< The specular Color of this Light. 52 float constantAttenuation; //!< The Factor of the the Constant Attenuation. 53 float linearAttenuation; //!< The Factor of the the Linear Attenuation. 54 float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. 55 GLfloat spotDirection[4]; //!< The direction of the Spot Light. 56 GLfloat spotCutoff; //!< The cutoff Angle of the Light Source 27 ObjectListDeclaration(Light); 28 public: 29 Light(const TiXmlElement* root = NULL); 30 virtual ~Light(); 31 32 virtual void loadParams(const TiXmlElement* root); 33 34 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 35 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 36 void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 37 void setSpotDirection(const Vector& direction); 38 void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); }; 39 void setSpotCutoff(GLfloat cutoff); 40 41 /** @returns the lightNumber*/ 42 int getLightNumber() const {return this->lightNumber;} 43 44 virtual void draw() const; 45 46 void debug() const; 47 48 // attributes 49 private: 50 int lightNumber; //!< The number of this Light. 51 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. 52 GLfloat specularColor[4]; //!< The specular Color of this Light. 53 float constantAttenuation; //!< The Factor of the the Constant Attenuation. 54 float linearAttenuation; //!< The Factor of the the Linear Attenuation. 55 float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. 56 GLfloat spotDirection[4]; //!< The direction of the Spot Light. 57 GLfloat spotCutoff; //!< The cutoff Angle of the Light Source 57 58 }; 58 59 60 59 60 61 61 62 //! A class that handles Lights 62 63 /** … … 87 88 */ 88 89 class LightManager : public BaseObject 89 90 friend class Light;90 { 91 ObjectListDeclaration(LightManager); 91 92 92 public: 93 virtual ~LightManager(); 94 /** @returns a Pointer to the only object of this Class */ 95 inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; 93 friend class Light; 94 public: 95 virtual ~LightManager(); 96 /** @returns a Pointer to the only object of this Class */ 97 inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; 96 98 97 98 99 virtual void loadParams(const TiXmlElement* root); 100 void loadLights(const TiXmlElement* root); 99 101 100 101 102 102 void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); 103 // HACK: Assuming r = g = b values 104 inline GLfloat getAmbientColor() { return this->ambientColor[0]; } 103 105 104 105 106 Light* getLight(int lightNumber) const; 107 inline Light* getLight() const { return this->currentLight; }; 106 108 107 109 void draw() const; 108 110 109 111 void debug() const; 110 112 111 112 113 private: 114 LightManager(); 113 115 114 115 116 int registerLight(Light* light); 117 void unregisterLight(Light* light); 116 118 117 118 119 119 private: 120 static LightManager* singletonRef; //!< This is the LightHandlers Reference. 121 GLfloat ambientColor[4]; //!< The ambient Color of the scene. 120 122 121 122 123 Light** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. 124 Light* currentLight; //!< The current Light, we are working with. 123 125 124 126 }; -
trunk/src/lib/graphics/render2D/element_2d.cc
r9406 r9869 29 29 #include "graphics_engine.h" 30 30 #include "util/loading/load_param.h" 31 #include "class_list.h"32 31 33 32 #include "color.h" 34 33 #include "debug.h" 35 34 #include "shell_command.h" 35 36 36 SHELL_COMMAND(debug, Element2D, debug2D); 37 38 ObjectListDefinition(Element2D); 37 39 38 40 … … 46 48 Element2D::Element2D (Element2D* parent, E2D_LAYER layer, short nodeFlags) 47 49 { 48 this-> setClassID(CL_ELEMENT_2D, "Element2D");50 this->registerObject(this, Element2D::_objectList); 49 51 50 52 this->setVisibility(true); … … 268 270 void Element2D::setBindNode(const std::string& bindNode) 269 271 { 270 const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));272 const PNode* tmpBindNode = PNode::objectList().getObject(bindNode); 271 273 if (tmpBindNode != NULL) 272 274 this->bindNode = tmpBindNode; … … 640 642 void Element2D::addChild2D (const std::string& childName) 641 643 { 642 Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));644 Element2D* childNode = Element2D::objectList().getObject(childName); 643 645 if (childNode != NULL) 644 646 this->addChild2D(childNode); … … 718 720 void Element2D::setParent2D (const std::string& parentName) 719 721 { 720 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));722 Element2D* parentNode = Element2D::objectList().getObject(parentName); 721 723 if (parentNode != NULL) 722 724 parentNode->addChild2D(this); … … 771 773 void Element2D::setParentSoft2D(const std::string& parentName, float bias) 772 774 { 773 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));775 Element2D* parentNode = Element2D::objectList().getObject(parentName); 774 776 if (parentNode != NULL) 775 777 this->setParentSoft2D(parentNode, bias); -
trunk/src/lib/graphics/render2D/element_2d.h
r8360 r9869 47 47 48 48 E2D_PARENT_MOVEMENT = 0x0004, //!< Moves all children along with the parent. 49 // special linkage modes49 // special linkage modes 50 50 E2D_PARENT_ALL = 0x0003, //!< Moves all children around the center of their parent, and also rotates their centers 51 51 E2D_PARENT_ROTATE_AND_MOVE = 0x0005, //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent. … … 58 58 E2D_REPARENT_DELETE_CHILDREN = 0x0040, //!< Deletes the Children of the node when This Node is Removed. (Use with care). 59 59 /// FIXME 60 60 E2D_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 61 61 62 62 … … 87 87 * -> the tree is sorted on insertion of a new Child: @see Element2D::addChild2D() 88 88 */ 89 class Element2D : virtual public BaseObject { 90 91 public: 92 Element2D(Element2D* parent = Element2D::getNullElement(), E2D_LAYER layer = E2D_DEFAULT_LAYER, short nodeFlags = E2D_PARENT_MODE_DEFAULT); 93 virtual ~Element2D(); 94 95 virtual void loadParams(const TiXmlElement* root); 96 97 // ACTIVATION // 98 inline void activate2D() { this->bActive = this->bRelCoorChanged = this->bRelDirChanged = true; }; 99 inline void deactivate2D() { this->bActive = false; }; 100 inline bool get2DActiveState() { return this->bActive; }; 101 102 // ALIGNMENT // 103 /** @param alignment the new Alignment of the 2D-Element */ 104 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 105 void setAlignment(const std::string& alignment); 106 inline E2D_ALIGNMENT getAlignment() const { return this->alignment; }; 107 108 // LAYERING // 109 void setLayer(E2D_LAYER layer); 110 void setLayer(const std::string& layer); 111 /** @returns the Layer this Element is drawn to */ 112 inline E2D_LAYER getLayer() const { return this->layer; }; 113 114 // VISIBILITY // 115 /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ 116 inline void setVisibility(bool visible) { this->bVisible = visible; }; 117 /** @returns the visibility state */ 118 inline bool isVisible() const { return (this->bVisible && this->bCurrentlyVisible); }; 119 120 121 // POSITIONAL (E2D-specials) // 122 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 123 void setBindNode(const PNode* bindNode); 124 void setBindNode(const std::string& bindNode); 125 inline const PNode* getBindNode() const { return this->bindNode; }; 126 127 inline void setSize2D(float x, float y) { this->size = Vector2D(x, y); }; 128 inline void setSize2D(const Vector2D& size) { this->size = size; }; 129 inline const Vector2D& getSize2D() const { return this->size; }; 130 void setSizeSoft2D(float x, float y, float bias = 1.0); 131 inline void setSizeX2D(float x) { this->size.x = x; }; 132 inline void setSizeY2D(float y) { this->size.y = y; }; 133 inline float getSizeX2D() const { return this->size.x; }; 134 inline float getSizeY2D() const { return this->size.y; }; 135 136 public: 137 virtual void tick(float dt) {}; 138 virtual void draw() const {}; 139 void tick2D(float dt); 140 void draw2D(E2D_LAYER from, E2D_LAYER to) const; 141 void drawChildren(E2D_LAYER from, E2D_LAYER to) const; 142 143 // LIKE PNODE 144 public: 145 void setRelCoor2D (const Vector2D& relCoord); 146 void setRelCoorX2D(float x); 147 void setRelCoorY2D(float y); 148 void setRelCoor2D (float x, float y); 149 void setRelCoor2Dpx (int x, int y); 150 void setRelCoorSoft2D (const Vector2D& relCoordSoft, float bias = 1.0); 151 void setRelCoorSoft2D (float x, float y, float bias = 1.0); 152 void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0); 153 /** @returns the relative position */ 154 inline const Vector2D& getRelCoor2D () const { return this->prevRelCoordinate; }; 155 /** @returns the Relative Coordinate Destination */ 156 inline const Vector2D& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; }; 157 const Vector2D& getRelCoor2Dpx() const; 158 void setAbsCoor2D (const Vector2D& absCoord); 159 void setAbsCoor2D (float x, float y); 160 void setAbsCoorX2D(float x); 161 void setAbsCoorY2D(float y); 162 void setAbsCoor2Dpx (int x, int y); 163 void setAbsCoorSoft2D (const Vector2D& absCoordSoft, float bias = 1.0); 164 void setAbsCoorSoft2D (float x, float y, float bias = 1.0); 165 /** @returns the absolute position */ 166 inline const Vector2D& getAbsCoor2D () const { return this->absCoordinate; }; 167 const Vector2D& getAbsCoor2Dpx () const; 168 169 void shiftCoor2D (const Vector2D& shift); 170 void shiftCoor2Dpx (int x, int y); 171 172 void setRelDir2D (float relDir); 173 void setRelDirSoft2D(float relDirSoft, float bias = 1.0); 174 /** @returns the relative Direction */ 175 inline float getRelDir2D () const { return this->prevRelDirection; }; 176 /** @returns the Relative Directional Destination */ 177 inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; }; 178 void setAbsDir2D (float absDir); 179 void setAbsDirSoft2D (float absDirSoft, float bias = 1.0); 180 /** @returns the absolute Direction */ 181 inline float getAbsDir2D () const { return this->absDirection; }; 182 void shiftDir2D (float shiftDir); 183 184 /** @returns the Speed of the Node */ 185 inline float getSpeed() const { return 0; }; 186 /** @returns the Velocity of the Node */ 187 inline const Vector2D& getVelocity() const { return this->velocity; }; 188 189 190 void addChild2D (Element2D* child); 191 void addChild2D (const std::string& childName); 192 void removeChild2D (Element2D* child); 193 void remove2D(); 194 195 /** @param parent the new parent of this Element2D */ 196 void setParent2D (Element2D* parent) { parent->addChild2D(this); }; 197 void setParent2D (const std::string& parentName); 198 /** @returns the parent of this Element2D */ 199 inline Element2D* getParent2D () const { return this->parent; }; 200 /** @returns the List of Children of this Element2D */ 201 inline const std::list<Element2D*>& getChildren2D() const { return this->children; }; 202 203 void setParentSoft2D(Element2D* parentNode, float bias = 1.0); 204 void setParentSoft2D(const std::string& parentName, float bias = 1.0); 205 206 void setParentMode2D (E2D_PARENT_MODE parentMode); 207 void setParentMode2D (const std::string& parentingMode); 208 /** @returns the Parenting mode of this node */ 209 int getParentMode2D() const { return this->parentMode; }; 210 211 // NULL_PARENT // 212 /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */ 213 static Element2D* getNullElement() { return (Element2D::nullElement != NULL)? Element2D::nullElement : Element2D::createNullElement(); }; 214 215 216 void update2D (float dt); 217 218 void debug2D (unsigned int depth = 1, unsigned int level = 0) const; 219 void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,0,0), unsigned int level = 0) const; 220 221 // helper functions // 222 static const char* parentingModeToString2D(int parentingMode); 223 static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode); 224 225 static const char* layer2DToChar(E2D_LAYER layer); 226 static E2D_LAYER charToLayer2D(const std::string& layer); 227 228 static bool layerSortPredicate(const Element2D* elem1, const Element2D* elem2); 229 230 private: 231 void eraseChild2D(Element2D* child); 232 /** tells the child that the parent's Coordinate has changed */ 233 inline void parentCoorChanged2D () { this->bRelCoorChanged = true; } 234 /** tells the child that the parent's Direction has changed */ 235 inline void parentDirChanged2D () { this->bRelDirChanged = true; } 236 /** @returns the last calculated coordinate */ 237 inline Vector2D getLastAbsCoor2D() { return this->lastAbsCoordinate; } 238 239 void reparent2D(); 240 static Element2D* createNullElement(); 241 bool checkIntegrity(const Element2D* checkParent) const; 242 243 244 private: 245 const PNode* bindNode; //!< a node over which to display this 2D-element 246 Vector2D size; //!< The size of the rendered item 247 Vector2D* toSize; //!< The Size to iterate to. 248 249 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 250 251 bool bVisible; //!< If the given Element2D is visible. 252 bool bCurrentlyVisible; //!< Evaluated in the TICK process, to see if the Element is Currently visible. 253 bool bActive; //!< If the given Element2D is active. 254 E2D_LAYER layer; //!< What layer this Element2D is on. 255 256 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 257 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 258 259 Vector2D relCoordinate; //!< coordinates relative to the parent 260 Vector2D absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 261 float relDirection; //!< direction relative to the parent 262 float absDirection; //!< absolute diretion in the world ( from (0,0,1) ) 263 264 Vector2D prevRelCoordinate; //!< The last Relative Coordinate from the last update-Cycle. 265 Vector2D lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 266 float prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 267 268 Vector2D velocity; //!< Saves the velocity. 269 270 Vector2D* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft) 271 float* toDirection; //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft) 272 float bias; //!< how fast to iterate to the given position (default is 1) 273 274 Element2D* parent; //!< a pointer to the parent node 275 std::list<Element2D*> children; //!< list of the children of this Element2D 276 277 unsigned int parentMode; //!< the mode of the binding 278 279 static Element2D* nullElement; //!< The top-most Element 89 class Element2D : virtual public BaseObject 90 { 91 ObjectListDeclaration(Element2D); 92 93 public: 94 Element2D(Element2D* parent = Element2D::getNullElement(), E2D_LAYER layer = E2D_DEFAULT_LAYER, short nodeFlags = E2D_PARENT_MODE_DEFAULT); 95 virtual ~Element2D(); 96 97 virtual void loadParams(const TiXmlElement* root); 98 99 // ACTIVATION // 100 inline void activate2D() { this->bActive = this->bRelCoorChanged = this->bRelDirChanged = true; }; 101 inline void deactivate2D() { this->bActive = false; }; 102 inline bool get2DActiveState() { return this->bActive; }; 103 104 // ALIGNMENT // 105 /** @param alignment the new Alignment of the 2D-Element */ 106 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 107 void setAlignment(const std::string& alignment); 108 inline E2D_ALIGNMENT getAlignment() const { return this->alignment; }; 109 110 // LAYERING // 111 void setLayer(E2D_LAYER layer); 112 void setLayer(const std::string& layer); 113 /** @returns the Layer this Element is drawn to */ 114 inline E2D_LAYER getLayer() const { return this->layer; }; 115 116 // VISIBILITY // 117 /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ 118 inline void setVisibility(bool visible) { this->bVisible = visible; }; 119 /** @returns the visibility state */ 120 inline bool isVisible() const { return (this->bVisible && this->bCurrentlyVisible); }; 121 122 123 // POSITIONAL (E2D-specials) // 124 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 125 void setBindNode(const PNode* bindNode); 126 void setBindNode(const std::string& bindNode); 127 inline const PNode* getBindNode() const { return this->bindNode; }; 128 129 inline void setSize2D(float x, float y) { this->size = Vector2D(x, y); }; 130 inline void setSize2D(const Vector2D& size) { this->size = size; }; 131 inline const Vector2D& getSize2D() const { return this->size; }; 132 void setSizeSoft2D(float x, float y, float bias = 1.0); 133 inline void setSizeX2D(float x) { this->size.x = x; }; 134 inline void setSizeY2D(float y) { this->size.y = y; }; 135 inline float getSizeX2D() const { return this->size.x; }; 136 inline float getSizeY2D() const { return this->size.y; }; 137 138 public: 139 virtual void tick(float dt) {}; 140 virtual void draw() const {}; 141 void tick2D(float dt); 142 void draw2D(E2D_LAYER from, E2D_LAYER to) const; 143 void drawChildren(E2D_LAYER from, E2D_LAYER to) const; 144 145 // LIKE PNODE 146 public: 147 void setRelCoor2D (const Vector2D& relCoord); 148 void setRelCoorX2D(float x); 149 void setRelCoorY2D(float y); 150 void setRelCoor2D (float x, float y); 151 void setRelCoor2Dpx (int x, int y); 152 void setRelCoorSoft2D (const Vector2D& relCoordSoft, float bias = 1.0); 153 void setRelCoorSoft2D (float x, float y, float bias = 1.0); 154 void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0); 155 /** @returns the relative position */ 156 inline const Vector2D& getRelCoor2D () const { return this->prevRelCoordinate; }; 157 /** @returns the Relative Coordinate Destination */ 158 inline const Vector2D& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; }; 159 const Vector2D& getRelCoor2Dpx() const; 160 void setAbsCoor2D (const Vector2D& absCoord); 161 void setAbsCoor2D (float x, float y); 162 void setAbsCoorX2D(float x); 163 void setAbsCoorY2D(float y); 164 void setAbsCoor2Dpx (int x, int y); 165 void setAbsCoorSoft2D (const Vector2D& absCoordSoft, float bias = 1.0); 166 void setAbsCoorSoft2D (float x, float y, float bias = 1.0); 167 /** @returns the absolute position */ 168 inline const Vector2D& getAbsCoor2D () const { return this->absCoordinate; }; 169 const Vector2D& getAbsCoor2Dpx () const; 170 171 void shiftCoor2D (const Vector2D& shift); 172 void shiftCoor2Dpx (int x, int y); 173 174 void setRelDir2D (float relDir); 175 void setRelDirSoft2D(float relDirSoft, float bias = 1.0); 176 /** @returns the relative Direction */ 177 inline float getRelDir2D () const { return this->prevRelDirection; }; 178 /** @returns the Relative Directional Destination */ 179 inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; }; 180 void setAbsDir2D (float absDir); 181 void setAbsDirSoft2D (float absDirSoft, float bias = 1.0); 182 /** @returns the absolute Direction */ 183 inline float getAbsDir2D () const { return this->absDirection; }; 184 void shiftDir2D (float shiftDir); 185 186 /** @returns the Speed of the Node */ 187 inline float getSpeed() const { return 0; }; 188 /** @returns the Velocity of the Node */ 189 inline const Vector2D& getVelocity() const { return this->velocity; }; 190 191 192 void addChild2D (Element2D* child); 193 void addChild2D (const std::string& childName); 194 void removeChild2D (Element2D* child); 195 void remove2D(); 196 197 /** @param parent the new parent of this Element2D */ 198 void setParent2D (Element2D* parent) { parent->addChild2D(this); }; 199 void setParent2D (const std::string& parentName); 200 /** @returns the parent of this Element2D */ 201 inline Element2D* getParent2D () const { return this->parent; }; 202 /** @returns the List of Children of this Element2D */ 203 inline const std::list<Element2D*>& getChildren2D() const { return this->children; }; 204 205 void setParentSoft2D(Element2D* parentNode, float bias = 1.0); 206 void setParentSoft2D(const std::string& parentName, float bias = 1.0); 207 208 void setParentMode2D (E2D_PARENT_MODE parentMode); 209 void setParentMode2D (const std::string& parentingMode); 210 /** @returns the Parenting mode of this node */ 211 int getParentMode2D() const { return this->parentMode; }; 212 213 // NULL_PARENT // 214 /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */ 215 static Element2D* getNullElement() { return (Element2D::nullElement != NULL)? Element2D::nullElement : Element2D::createNullElement(); }; 216 217 218 void update2D (float dt); 219 220 void debug2D (unsigned int depth = 1, unsigned int level = 0) const; 221 void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,0,0), unsigned int level = 0) const; 222 223 // helper functions // 224 static const char* parentingModeToString2D(int parentingMode); 225 static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode); 226 227 static const char* layer2DToChar(E2D_LAYER layer); 228 static E2D_LAYER charToLayer2D(const std::string& layer); 229 230 static bool layerSortPredicate(const Element2D* elem1, const Element2D* elem2); 231 232 private: 233 void eraseChild2D(Element2D* child); 234 /** tells the child that the parent's Coordinate has changed */ 235 inline void parentCoorChanged2D () { this->bRelCoorChanged = true; } 236 /** tells the child that the parent's Direction has changed */ 237 inline void parentDirChanged2D () { this->bRelDirChanged = true; } 238 /** @returns the last calculated coordinate */ 239 inline Vector2D getLastAbsCoor2D() { return this->lastAbsCoordinate; } 240 241 void reparent2D(); 242 static Element2D* createNullElement(); 243 bool checkIntegrity(const Element2D* checkParent) const; 244 245 246 private: 247 const PNode* bindNode; //!< a node over which to display this 2D-element 248 Vector2D size; //!< The size of the rendered item 249 Vector2D* toSize; //!< The Size to iterate to. 250 251 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 252 253 bool bVisible; //!< If the given Element2D is visible. 254 bool bCurrentlyVisible; //!< Evaluated in the TICK process, to see if the Element is Currently visible. 255 bool bActive; //!< If the given Element2D is active. 256 E2D_LAYER layer; //!< What layer this Element2D is on. 257 258 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 259 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 260 261 Vector2D relCoordinate; //!< coordinates relative to the parent 262 Vector2D absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 263 float relDirection; //!< direction relative to the parent 264 float absDirection; //!< absolute diretion in the world ( from (0,0,1) ) 265 266 Vector2D prevRelCoordinate; //!< The last Relative Coordinate from the last update-Cycle. 267 Vector2D lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 268 float prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 269 270 Vector2D velocity; //!< Saves the velocity. 271 272 Vector2D* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft) 273 float* toDirection; //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft) 274 float bias; //!< how fast to iterate to the given position (default is 1) 275 276 Element2D* parent; //!< a pointer to the parent node 277 std::list<Element2D*> children; //!< list of the children of this Element2D 278 279 unsigned int parentMode; //!< the mode of the binding 280 281 static Element2D* nullElement; //!< The top-most Element 280 282 }; 281 283 -
trunk/src/lib/graphics/render2D/image_plane.cc
r9406 r9869 21 21 22 22 #include "graphics_engine.h" 23 #include "glincl.h"24 23 #include "p_node.h" 25 24 26 25 26 #include "class_id_DEPRECATED.h" 27 27 28 29 30 CREATE_FACTORY(ImagePlane, CL_IMAGE_ENTITY); 28 ObjectListDefinitionID(ImagePlane, CL_IMAGE_PLANE); 29 CREATE_FACTORY(ImagePlane); 31 30 32 31 … … 56 55 void ImagePlane::init() 57 56 { 58 this-> setClassID(CL_IMAGE_PLANE, "ImagePlane");57 this->registerObject(this, ImagePlane::_objectList); 59 58 this->setName("ImagePlane"); 60 59 -
trunk/src/lib/graphics/render2D/image_plane.h
r7843 r9869 17 17 class ImagePlane : public Element2D 18 18 { 19 19 ObjectListDeclaration(ImagePlane); 20 20 public: 21 21 ImagePlane(const TiXmlElement* root = NULL); -
trunk/src/lib/graphics/render2D/render_2d.cc
r9406 r9869 19 19 20 20 #include "graphics_engine.h" 21 #include "class_list.h"22 21 #include "element_2d.h" 23 22 23 ObjectListDefinition(Render2D); 24 24 25 25 … … 29 29 Render2D::Render2D () 30 30 { 31 this->setClassID(CL_RENDER_2D, "Render2D");32 31 this->registerObject(this, Render2D::_objectList); 32 this->setName("Render2D"); 33 33 34 34 this->showNodes = false; 35 35 } 36 36 -
trunk/src/lib/graphics/render2D/render_2d.h
r7840 r9869 12 12 13 13 //! A default singleton class. 14 class Render2D : public BaseObject { 14 class Render2D : public BaseObject 15 { 16 ObjectListDeclaration(Render2D); 17 15 18 friend class Element2D; 16 19 17 18 19 20 20 public: 21 virtual ~Render2D(); 22 /** @returns a Pointer to the only object of this Class */ 23 inline static Render2D* getInstance() { if (!singletonRef) singletonRef = new Render2D(); return singletonRef; }; 21 24 22 25 void toggleNodesVisibility() { this->showNodes = !this->showNodes; }; 23 26 24 25 26 27 void update(float dt); 28 void tick(float dt); 29 void draw(E2D_LAYER from, E2D_LAYER to) const; 27 30 28 29 30 31 private: 32 Render2D(); 33 static Render2D* singletonRef; //!< Reference to this class. 31 34 32 33 35 bool showNodes; //!< If the debug-Nodes should be visible 36 }; 34 37 35 38 #endif /* _RENDER_2D_H */ -
trunk/src/lib/graphics/shader.cc
r9406 r9869 18 18 #include "shader.h" 19 19 20 #include "stdlibincl.h"21 20 #include "compiler.h" 22 21 //#include <stdio.h> … … 25 24 #include "debug.h" 26 25 27 #include "util/loading/resource_manager.h"28 26 29 27 … … 33 31 34 32 33 ObjectListDefinition(Shader); 35 34 35 void Shader::Uniform::setV(unsigned int count, float* vv) const 36 { 37 switch (count) 38 { 39 case 1: 40 glUniform1fv(this->uniform, 1, vv); 41 break; 42 case 2: 43 glUniform2fv(this->uniform, 2, vv); 44 break; 45 case 3: 46 glUniform3fv(this->uniform, 3, vv); 47 break; 48 case 4: 49 glUniform4fv(this->uniform, 4, vv); 50 break; 51 } 52 } 53 void Shader::Uniform::setV(unsigned int count, int* vv) const 54 { 55 switch (count) 56 { 57 case 1: 58 glUniform1iv(this->uniform, 1, vv); 59 break; 60 case 2: 61 glUniform2iv(this->uniform, 2, vv); 62 break; 63 case 3: 64 glUniform3iv(this->uniform, 3, vv); 65 break; 66 case 4: 67 glUniform4iv(this->uniform, 4, vv); 68 break; 69 } 70 } 71 72 73 74 Shader::Shader() 75 : data(new ShaderData) 76 { 77 78 } 36 79 37 80 /** … … 39 82 */ 40 83 Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 84 : data(new ShaderData) 41 85 { 42 this->setClassID(CL_SHADER, "Shader"); 86 if (!Shader::checkShaderAbility()) 87 PRINTF(2)("Your system does not support shaders\n"); 88 this->load(vertexShaderFile, fragmentShaderFile); 43 89 44 this->shaderProgram = 0;45 this->vertexShader = 0;46 this->fragmentShader = 0;47 48 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)49 {50 this->shaderProgram = glCreateProgramObjectARB();51 52 if (!vertexShaderFile.empty())53 this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);54 if (!fragmentShaderFile.empty())55 this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);56 57 this->linkShaderProgram();58 59 }60 else61 {62 PRINTF(2)("Shaders are not supported on your hardware\n");63 }64 90 } 65 91 92 const Shader* Shader::storedShader = NULL; 66 93 67 /** 68 * standard deconstructor 69 */ 70 Shader::~Shader () 94 void Shader::activateShader() const 71 95 { 72 if (this->shaderProgram == glGetHandleARB(GL_PROGRAM_OBJECT_ARB)) 73 Shader::deactivateShader(); 74 75 // delete what has to be deleted here 76 this->deleteProgram(Shader::Vertex); 77 this->deleteProgram(Shader::Fragment); 78 79 if (this->fragmentShader != 0) 96 if (likely (this->getProgram() != 0)) 80 97 { 81 glDetachObjectARB(this->shaderProgram, this->fragmentShader); 82 glDeleteObjectARB(this->fragmentShader); 83 } 84 if (this->vertexShader != 0) 85 { 86 glDetachObjectARB(this->shaderProgram, this->vertexShader); 87 glDeleteObjectARB(this->vertexShader); 88 } 89 if (this->shaderProgram != 0) 90 { 91 GLint status = 0; 92 //glLinkProgramARB(this->shaderProgram); 93 glDeleteObjectARB(this->shaderProgram); 94 // link error checking 95 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_DELETE_STATUS_ARB, &status); 96 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 97 this->printError(this->shaderProgram); 98 } 99 } 100 101 Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 102 { 103 return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER, RP_LEVEL, fragmentShaderFile); 104 } 105 106 bool Shader::unload(Shader* shader) 107 { 108 return ResourceManager::getInstance()->unload(shader); 109 } 110 111 Shader* Shader::storedShader = NULL; 112 113 114 bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName) 115 { 116 GLhandleARB shader = 0; 117 118 if (type != Shader::Vertex && type != Shader::Fragment) 119 return false; 120 this->deleteProgram(type); 121 122 123 std::string program; 124 if (!readShader(fileName, program)) 125 return false; 126 127 if (type == Shader::Vertex && GLEW_ARB_vertex_shader) 128 { 129 this->vertexShaderFile = fileName; 130 131 shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); 132 } 133 134 if (type == Shader::Fragment && GLEW_ARB_fragment_shader) 135 { 136 this->fragmentShaderFile = fileName; 137 138 shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); 139 } 140 141 if (shader != 0) 142 { 143 GLint status = 0; 144 const char* prog = program.c_str(); 145 146 glShaderSourceARB(shader, 1, &prog, NULL); 147 glCompileShaderARB(shader); 148 // checking on error. 149 glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); 150 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 151 this->printError(shader); 152 else 153 glAttachObjectARB(this->shaderProgram, shader); 154 } 155 return true; 156 } 157 158 159 void Shader::linkShaderProgram() 160 { 161 GLint status = 0; 162 163 glLinkProgramARB(this->shaderProgram); 164 // link error checking 165 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status); 166 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 167 this->printError(this->shaderProgram); 168 } 169 170 171 bool Shader::readShader(const std::string& fileName, std::string& output) 172 { 173 char lineBuffer[PARSELINELENGTH]; 174 175 std::ifstream shader; 176 shader.open(fileName.c_str()); 177 if (!shader.is_open()) 178 return false; 179 180 181 while (!shader.eof()) 182 { 183 shader.getline(lineBuffer, PARSELINELENGTH); 184 output += lineBuffer; 185 output += "\n"; 186 } 187 188 189 shader.close(); 190 return true; 191 } 192 193 194 195 void Shader::activateShader() 196 { 197 if (likely (this->shaderProgram != 0)) 198 { 199 glUseProgramObjectARB(this->shaderProgram); 98 glUseProgramObjectARB(this->getProgram()); 200 99 Shader::storedShader = this; 201 100 } 202 101 } 203 204 void Shader::bindShader(const char* name, const float* value, size_t size)205 {206 if (likely (this->shaderProgram != 0)) {207 glUseProgramObjectARB(this->shaderProgram);208 209 unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);210 /* This is EXPENSIVE and should be avoided. */211 212 if (size == 1) glUniform1fvARB(location, 1, value);213 else if (size == 2) glUniform2fvARB(location, 1, value);214 else if (size == 3) glUniform3fvARB(location, 1, value);215 else if (size == 4) glUniform4fvARB(location, 1, value);216 else if (size == 9) glUniformMatrix3fvARB(location, 1, false, value);217 else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);218 219 }220 }221 222 102 void Shader::deactivateShader() 223 103 { 224 if (storedShader != NULL) 225 glUseProgramObjectARB(0); 226 Shader::storedShader = NULL; 227 } 228 229 230 void Shader::deleteProgram(Shader::Type type) 231 { 232 GLint status = 0; 233 if (type == Shader::Vertex && this->vertexShader != 0) 234 { 235 this->vertexShaderFile = ""; 236 glDetachObjectARB(this->shaderProgram, this->vertexShader); 237 glDeleteObjectARB(this->vertexShader); 238 glGetObjectParameterivARB(this->vertexShader, GL_OBJECT_DELETE_STATUS_ARB, &status); 239 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 240 Shader::printError(this->vertexShader); 241 this->vertexShader = 0; 242 } 243 else if (type == Shader::Fragment && this->fragmentShader != 0) 244 { 245 this->fragmentShaderFile = ""; 246 glDetachObjectARB(this->shaderProgram, this->fragmentShader); 247 glDeleteObjectARB(this->fragmentShader); 248 glGetObjectParameterivARB(this->fragmentShader, GL_OBJECT_DELETE_STATUS_ARB, &status); 249 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 250 Shader::printError(this->fragmentShader); 251 this->fragmentShader = 0; 252 } 253 else 254 return; 255 } 256 257 258 void Shader::printError(GLhandleARB program) 259 { 260 if (program == 0) 261 return; 262 263 int infologLength = 0; 264 int charsWritten = 0; 265 char *infoLog; 266 267 glGetObjectParameterivARB(program, GL_OBJECT_INFO_LOG_LENGTH_ARB, 268 &infologLength); 269 270 if (infologLength > 0) 271 { 272 infoLog = new char[infologLength+1]; 273 glGetInfoLogARB(program, infologLength, &charsWritten, infoLog); 274 printf("%s\n", infoLog); 275 delete[] infoLog; 276 } 104 if (storedShader != NULL) 105 glUseProgramObjectARB(0); 106 Shader::storedShader = NULL; 277 107 } 278 108 … … 288 118 } 289 119 290 void Shader::debug() const291 {292 PRINT(3)("Shader info: (SHADER: %d)\n", this->shaderProgram);293 if (this->vertexShader != 0)294 {295 /* PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);296 if (this->vertexShaderSource != NULL)297 for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)298 PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));299 }300 if (this->fragmentShader != 0)301 {302 PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);303 if (this->fragmentShaderSource != NULL)304 for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)305 PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/306 }307 }308 120 -
trunk/src/lib/graphics/shader.h
r8255 r9869 8 8 9 9 #include "base_object.h" 10 #include "glincl.h" 11 #include <vector> 12 10 #include "shader_data.h" 13 11 14 12 // FORWARD DECLARATION … … 16 14 17 15 18 //! A class for ...16 //! The Shader is a Class-wrapper around the OpenGL Shader Language (GLSL). 19 17 class Shader : public BaseObject 20 18 { 19 ObjectListDeclaration(Shader); 21 20 public: 22 21 class Uniform 23 22 { 24 23 public: 25 Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }26 24 Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; }; 27 25 Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; }; … … 37 35 void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); } 38 36 39 void setV(unsigned int count, float* vv) const 40 { 41 switch (count) 42 { 43 case 1: 44 glUniform1fv(this->uniform, 1, vv); 45 break; 46 case 2: 47 glUniform2fv(this->uniform, 2, vv); 48 break; 49 case 3: 50 glUniform3fv(this->uniform, 3, vv); 51 break; 52 case 4: 53 glUniform4fv(this->uniform, 4, vv); 54 break; 55 } 56 } 57 void setV(unsigned int count, int* vv) const 58 { 59 switch (count) 60 { 61 case 1: 62 glUniform1iv(this->uniform, 1, vv); 63 break; 64 case 2: 65 glUniform2iv(this->uniform, 2, vv); 66 break; 67 case 3: 68 glUniform3iv(this->uniform, 3, vv); 69 break; 70 case 4: 71 glUniform4iv(this->uniform, 4, vv); 72 break; 73 } 74 } 75 private: 37 void setV(unsigned int count, float* vv) const; 38 void setV(unsigned int count, int* vv) const; 39 40 private: 76 41 GLint uniform; 77 42 }; 78 43 79 typedef enum80 {81 None = 0,82 Fragment = 1,83 Vertex = 2,84 85 Program = 4,86 }87 Type;88 44 89 45 public: 90 Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); 91 virtual ~Shader(); 92 static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); 93 static bool unload(Shader* shader); 46 Shader(); 47 Shader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = ""); 48 49 Shader& operator=(const Shader& shader) { this->data = shader.data; return *this; }; 50 const ShaderData::Pointer& dataPointer() const { return data; }; 51 void acquireData(const ShaderData::Pointer& pointer) { this->data = pointer; }; 52 53 bool load(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = "") 54 { return this->data->load(vertexShaderFile, fragmentShaderFile); } 55 56 57 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(*this, location); } 58 59 GLhandleARB getProgram() const { return this->data->getProgram(); } 60 GLhandleARB getVertexS() const { return this->data->getVertexS(); } 61 GLhandleARB getFragmentS() const { return this->data->getFragmentS(); } 62 63 void activateShader() const; 64 static void deactivateShader(); 65 66 void debug() const { this->data->debug(); }; 94 67 95 68 96 69 static bool checkShaderAbility(); 97 void activateShader();98 void bindShader(const char* name, const float* value, size_t size);99 static void deactivateShader();100 70 101 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); } 71 inline static bool isShaderActive() { return (Shader::storedShader != NULL) ? true : false; }; 72 inline static const Shader* getActiveShader() { return Shader::storedShader; }; 102 73 103 bool loadShaderProgramm(Shader::Type type, const std::string& fileName); 104 void deleteProgram(Shader::Type type); 105 106 void linkShaderProgram(); 107 108 109 bool readShader(const std::string& fileName, std::string& output); 110 111 112 inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; 113 inline static Shader* getActiveShader() { return Shader::storedShader; }; 114 inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 74 inline static void suspendShader() { const Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 115 75 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 116 76 77 private: 78 ShaderData::Pointer data; 117 79 118 119 120 GLhandleARB getProgram() const { return this->shaderProgram; } 121 GLhandleARB getVertexS() const { return this->vertexShader; } 122 GLhandleARB getFragmentS() const { return this->fragmentShader; } 123 124 void debug() const; 125 126 static void printError(GLhandleARB program); 127 128 129 private: 130 std::string fragmentShaderFile; 131 std::string vertexShaderFile; 132 133 GLhandleARB shaderProgram; 134 135 GLhandleARB vertexShader; 136 GLhandleARB fragmentShader; 137 138 139 static Shader* storedShader; 80 static const Shader* storedShader; 140 81 }; 141 82 -
trunk/src/lib/graphics/spatial_separation/quadtree.cc
r9406 r9869 27 27 #define QUADTREE_MATERIAL_COUNT 4 28 28 29 ObjectListDefinition(Quadtree); 29 30 /** 30 31 * standard constructor … … 32 33 Quadtree::Quadtree (const modelInfo* pModelInfo, const int treeDepth) 33 34 { 34 this-> setClassID(CL_QUADTREE, "Quadtree");35 this->registerObject(this, Quadtree::_objectList); 35 36 this->pModelInfo = pModelInfo; 36 37 this->treeDepth = treeDepth; -
trunk/src/lib/graphics/spatial_separation/quadtree.h
r6022 r9869 21 21 //! A class for quadtree separation of the world 22 22 class Quadtree : public BaseObject { 23 23 ObjectListDeclaration(Quadtree); 24 24 25 25 public: -
trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r9406 r9869 27 27 28 28 29 29 ObjectListDefinition(QuadtreeNode); 30 30 31 31 /** … … 102 102 void QuadtreeNode::init() 103 103 { 104 this-> setClassID(CL_QUADTREE_NODE, "QuadtreeNode");104 this->registerObject(this, QuadtreeNode::_objectList); 105 105 106 106 /* init the rest of the variables for both init types */ -
trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r6617 r9869 26 26 //! A class for a Quadtree Node representation 27 27 class QuadtreeNode : public BaseObject { 28 ObjectListDeclaration(QuadtreeNode); 28 29 29 30 public: -
trunk/src/lib/graphics/spatial_separation/spatial_separation.cc
r9406 r9869 24 24 25 25 26 26 ObjectListDefinition(SpatialSeparation); 27 27 28 28 /** 29 * standard constructor29 * @brief standard constructor 30 30 * @param model the model that is to be separated 31 31 * @param overlapSize each box will overlap for a given size 32 33 34 32 * 33 * The boxes are overlaping because this makes collision detection a lot simpler 34 * 35 35 */ 36 36 SpatialSeparation::SpatialSeparation (Model* model, float overlapSize) … … 39 39 PRINT(3)("+-| (Event) Spatial Separation process kicked on\n"); 40 40 41 this-> setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");41 this->registerObject(this, SpatialSeparation::_objectList); 42 42 /* debug vice */ 43 43 this->createQuadtree(model); … … 46 46 47 47 /** 48 * standard constructor48 * @brief standard constructor 49 49 * @param model the model that is to be separated 50 50 * @param overlapSize each box will overlap for a given size … … 54 54 SpatialSeparation::SpatialSeparation (Model* model, Model* playerModel) 55 55 { 56 this-> setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");56 this->registerObject(this, SpatialSeparation::_objectList); 57 57 58 58 } … … 60 60 61 61 /** 62 * standard deconstructor62 * @brief standard deconstructor 63 63 */ 64 64 SpatialSeparation::~SpatialSeparation () … … 70 70 71 71 /** 72 * creates a quadtree72 * @brief creates a quadtree 73 73 * @param model the model to do a quadtree on 74 74 * @param minLength the minimal length of a quadtree node … … 83 83 84 84 /** 85 * 85 * @brief creates a quadtree 86 86 * @param model the model to do a quadtree on 87 87 * @param minLength the minimal length of a quadtree node … … 95 95 96 96 /** 97 * creates a quadtree97 * @brief creates a quadtree 98 98 * @param model the model to do a quadtree on 99 99 * @param minLength the minimal length of a quadtree node … … 109 109 110 110 /** 111 * draws all the quadtrees111 * @brief draws all the quadtrees 112 112 */ 113 113 void SpatialSeparation::drawQuadtree() … … 118 118 this->quadtree->drawTree(); 119 119 } 120 121 122 123 124 125 126 127 128 129 130 131 -
trunk/src/lib/graphics/spatial_separation/spatial_separation.h
r6022 r9869 19 19 //! A class for spatial separation of vertices based arrays 20 20 class SpatialSeparation : public BaseObject { 21 ObjectListDeclaration(SpatialSeparation); 21 22 22 23 public: -
trunk/src/lib/graphics/text_engine/font.cc
r8989 r9869 29 29 #include "compiler.h" 30 30 31 ObjectListDefinition(Font); 31 32 32 33 Font::Font() … … 34 35 { 35 36 this->init(); 36 37 37 } 38 38 … … 118 118 Material::operator=(font); 119 119 this->data = font.data; 120 this->setTexture(this->data->textureData()); 120 121 121 122 return *this; … … 130 131 this->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 131 132 132 this-> setClassID(CL_FONT, "Font");133 if (Font::defaultFontData. get() == NULL)133 this->registerObject(this, Font::_objectList); 134 if (Font::defaultFontData.isNull()) 134 135 { 135 136 Font::initDefaultFont(); … … 138 139 } 139 140 140 FontData Pointer Font::defaultFontData(NULL);141 FontData::Pointer Font::defaultFontData(NULL); 141 142 142 143 /** … … 146 147 { 147 148 // temporarily create a Font. 148 Font::defaultFontData = FontData Pointer(new FontData);149 Font::defaultFontData = FontData::Pointer(new FontData); 149 150 // apply the Data. 150 151 Font::defaultFontData = Font(font_xpm).data; … … 159 160 bool Font::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize) 160 161 { 161 this->data = FontData Pointer (new FontData());162 this->data = FontData::Pointer (new FontData()); 162 163 bool retVal = this->data->loadFontFromTTF(fontFile, renderSize); 163 164 if (!retVal) … … 174 175 bool Font::loadFontFromSDL_Surface(SDL_Surface* surface) 175 176 { 176 this->data = FontData Pointer (new FontData());177 this->data = FontData::Pointer (new FontData()); 177 178 bool retVal = this->data->loadFontFromSDL_Surface(surface); 178 179 if (!retVal) … … 196 197 197 198 198 void Font::setTexture(const TextureData Pointer& texDataPointer)199 void Font::setTexture(const TextureData::Pointer& texDataPointer) 199 200 { 200 201 this->setDiffuseMap(texDataPointer); -
trunk/src/lib/graphics/text_engine/font.h
r8766 r9869 19 19 class Font : public Material 20 20 { 21 21 ObjectListDeclaration(Font); 22 public: 23 typedef FontData::Glyph Glyph; 22 24 public: 23 25 Font(); … … 39 41 40 42 /** @returns a Pointer to the Array of Glyphs */ 41 inline Glyph**getGlyphArray() const { return this->data->getGlyphArray(); };43 inline const Glyph* const * const getGlyphArray() const { return this->data->getGlyphArray(); }; 42 44 43 45 inline int getMaxHeight() const { return data->getMaxHeight(); }; … … 50 52 void debug() const; 51 53 54 void acquireData(const FontData::Pointer& data) { this->data = data; }; 55 const FontData::Pointer& dataPointer() const { return data; }; 52 56 private: 53 57 void init(); 54 58 static void initDefaultFont(); 55 59 56 void setTexture(const TextureData Pointer& texDataPointer);60 void setTexture(const TextureData::Pointer& texDataPointer); 57 61 58 62 private: 59 FontData Pointerdata; //!< A Data-Pointer to a Font.63 FontData::Pointer data; //!< A Data-Pointer to a Font. 60 64 61 static FontData PointerdefaultFontData; //!< a default font, that is used, if other fonts were unable to be loaded.65 static FontData::Pointer defaultFontData; //!< a default font, that is used, if other fonts were unable to be loaded. 62 66 }; 63 67 -
trunk/src/lib/graphics/text_engine/font_data.h
r8768 r9869 26 26 #define FONT_DEFAULT_RENDER_SIZE 50 //!< At what Resolution to render fonts. 27 27 28 class FontData 29 { 30 31 32 public: 33 28 34 //! A struct for handling glyphs 29 35 /** 30 36 * a Glyph is one letter of a certain font 31 37 */ 32 struct Glyph33 {38 struct Glyph 39 { 34 40 // Glyph-specific (size and so on) 35 Uint16 character; //!< The character36 float minX; //!< The minimum distance from the origin in X37 float maxX; //!< The maximum distance from the origin in X38 float minY; //!< The minimum distance from the origin in Y39 float maxY; //!< The maximum distance from the origin in Y40 float width; //!< The width of the Glyph41 float height; //!< The height of the Glyph42 float bearingX; //!< How much is right of the Origin43 float bearingY; //!< How much is above the Origin44 float advance; //!< How big a Glyph would be in monospace-mode41 Uint16 character; //!< The character 42 float minX; //!< The minimum distance from the origin in X 43 float maxX; //!< The maximum distance from the origin in X 44 float minY; //!< The minimum distance from the origin in Y 45 float maxY; //!< The maximum distance from the origin in Y 46 float width; //!< The width of the Glyph 47 float height; //!< The height of the Glyph 48 float bearingX; //!< How much is right of the Origin 49 float bearingY; //!< How much is above the Origin 50 float advance; //!< How big a Glyph would be in monospace-mode 45 51 46 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.47 };52 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. 53 }; 48 54 49 50 class FontData 51 { 55 typedef CountPointer<FontData> Pointer; 52 56 public: 53 57 FontData(); … … 61 65 62 66 /** @returns a Pointer to the Array of Glyphs */ 63 inline Glyph**getGlyphArray() const { return this->glyphArray; };67 inline const Glyph* const * const getGlyphArray() const { return this->glyphArray; }; 64 68 65 69 int getMaxHeight() const { return maxHeight; }; … … 68 72 69 73 /** @returns the Texture-Data of this FontData */ 70 const TextureData Pointer& textureData() const { return texData; };74 const TextureData::Pointer& textureData() const { return texData; }; 71 75 72 76 bool rebuild() { return texData->rebuild(); }; … … 91 95 int maxDescent; //!< Max Desent of the Font. 92 96 93 TextureData Pointer texData;97 TextureData::Pointer texData; 94 98 }; 95 99 96 typedef CountPointer<FontData> FontDataPointer;97 98 100 #endif /* _FONT_DATA_H */ -
trunk/src/lib/graphics/text_engine/limited_width_text.cc
r9406 r9869 19 19 #include "font.h" 20 20 21 ObjectListDefinition(LimitedWidthText); 21 22 /** 22 23 * @brief creates a new Text Element … … 27 28 : Text(fontFile, textSize) 28 29 { 29 this-> setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText");30 this->registerObject(this, LimitedWidthText::_objectList); 30 31 31 32 this->_dotsPosition = End; … … 75 76 glRotatef(this->getAbsDir2D(), 0, 0, 1); 76 77 77 Glyph* tmpGlyph;78 const Font::Glyph* tmpGlyph; 78 79 float posX = 0.0f; 79 80 glBegin(GL_QUADS); -
trunk/src/lib/graphics/text_engine/limited_width_text.h
r8980 r9869 14 14 class LimitedWidthText : public Text 15 15 { 16 ObjectListDeclaration(LimitedWidthText); 16 17 public: 17 18 typedef enum { -
trunk/src/lib/graphics/text_engine/multi_line_text.cc
r9406 r9869 19 19 #include "font.h" 20 20 21 ObjectListDefinition(MultiLineText); 22 21 23 /** 22 24 * @brief creates a new Text Element … … 27 29 : Text(fontFile, textSize) 28 30 { 29 this-> setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");31 this->registerObject(this, MultiLineText::_objectList); 30 32 31 33 this->lineSpacing = 1.0; … … 78 80 glRotatef(this->getAbsDir2D(), 0, 0, 1); 79 81 80 Glyph* tmpGlyph;82 const Font::Glyph* tmpGlyph; 81 83 float posX = 0.0f; 82 84 float posY = 0.0f; -
trunk/src/lib/graphics/text_engine/multi_line_text.h
r7757 r9869 14 14 class MultiLineText : public Text 15 15 { 16 ObjectListDeclaration(MultiLineText); 16 17 public: 17 18 MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0); -
trunk/src/lib/graphics/text_engine/text.cc
r9406 r9869 17 17 18 18 #include "text.h" 19 #include "resource_font.h" 19 20 #include "font.h" 20 21 #include "util/loading/resource_manager.h"22 21 #include "debug.h" 22 23 ObjectListDefinition(Text); 23 24 24 25 /** … … 28 29 */ 29 30 Text::Text(const std::string& fontFile, unsigned int textSize) 30 31 { 32 this-> setClassID(CL_TEXT, "Text");31 // : _font(fontFile, FONT_DEFAULT_RENDER_SIZE) 32 { 33 this->registerObject(this, Text::_objectList); 33 34 34 35 // initialize this Text 35 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 36 if (!fontFile.empty()) 37 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 38 else 39 this->setFont("fonts/final_frontier.ttf", FONT_DEFAULT_RENDER_SIZE); 36 40 this->_size = textSize; 37 41 this->setSizeY2D(textSize); … … 44 48 : _font() 45 49 { 46 this-> setClassID(CL_TEXT, "Text");50 this->registerObject(this, Text::_objectList); 47 51 48 52 *this = text; … … 169 173 void Text::setFont(const std::string& fontFile, unsigned int fontSize) 170 174 { 171 Font* newFont = NULL; 172 // Font* oldFont = this->_font; 173 174 // load a new Font 175 if (!fontFile.empty()) 176 { 177 newFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize); 178 if (newFont == NULL) 179 { 180 // newFont = &Font::(); 181 PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str()); 182 } 183 } 184 185 if (newFont == NULL) 186 this->_font = Font(); 187 else 188 this->_font = *newFont; 175 this->_font = ResourceFont(fontFile, fontSize); 189 176 190 177 this->setupTextWidth(); … … 233 220 glRotatef(this->getAbsDir2D(), 0, 0, 1); 234 221 235 Glyph* tmpGlyph;222 const Font::Glyph* tmpGlyph; 236 223 float posX = 0.0f; 237 224 glBegin(GL_QUADS); -
trunk/src/lib/graphics/text_engine/text.h
r8764 r9869 26 26 class Text : public Element2D 27 27 { 28 ObjectListDeclaration(Text); 28 29 public: 29 30 Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); -
trunk/src/lib/graphics/text_engine/text_engine.cc
r9406 r9869 33 33 34 34 #include "graphics_engine.h" 35 #include "util/loading/resource_manager.h"36 #include "class_list.h"37 35 38 36 #include "debug.h" … … 40 38 /// TEXT-ENGINE /// 41 39 /////////////////// 40 ObjectListDefinition(TextEngine); 42 41 /** 43 42 * standard constructor … … 45 44 TextEngine::TextEngine () 46 45 { 47 this->setClassID(CL_TEXT_ENGINE, "TextEngine");48 49 46 this->registerObject(this, TextEngine::_objectList); 47 this->setName("TextEngine"); 48 this->enableFonts(); 50 49 } 51 50 … … 62 61 { 63 62 // first remove all the remaining Texts (if any). 64 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 65 if (textList != NULL) 66 { 67 while(textList->size() > 0) 68 delete dynamic_cast<Text*>(textList->front()); 69 } 63 while (!Text::objectList().empty()) 64 delete Text::objectList().front(); 70 65 // delete all remaining fonts (There should not be Anything to do here) 71 const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 72 if (fontList != NULL) 66 67 //const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 68 //if (fontList != NULL) 73 69 { 74 70 ///FIXME 75 // while (fontList->size() > 0)71 // while (fontList->size() > 0) 76 72 { 77 // Font* font = dynamic_cast<Font*>(fontList->back());73 // Font* font = dynamic_cast<Font*>(fontList->back()); 78 74 //if (likely(font != Font::getDefaultFont())) 79 75 // ResourceManager::getInstance()->unload(font, RP_GAME); … … 91 87 { 92 88 if (!TTF_WasInit()) 93 94 95 89 { 90 if(TTF_Init()==-1) 91 PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); 96 92 97 98 93 TextEngine::checkVersion(); 94 } 99 95 else 100 96 PRINTF(4)("Fonts already initialized\n"); … … 107 103 { 108 104 if (TTF_WasInit()) 109 110 // Font::removeDefaultFont();111 112 105 { 106 // Font::removeDefaultFont(); 107 TTF_Quit(); 108 } 113 109 else 114 110 PRINTF(4)("Fonts were not initialized.\n"); … … 122 118 void TextEngine::debug() const 123 119 { 124 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 125 if (textList != NULL) 120 PRINT(0)("+-------------------------------+\n"); 121 PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); 122 PRINT(0)("+-------------------------------+\n"); 123 PRINT(0)("Reference: %p; Text Counts: %d\n", this, Text::objectList().size()); 124 125 for (ObjectList<Text>::const_iterator it = Text::objectList().begin(); 126 it != Text::objectList().end(); 127 ++it) 126 128 { 127 PRINT(0)("+-------------------------------+\n"); 128 PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); 129 PRINT(0)("+-------------------------------+\n"); 130 PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->size()); 131 132 std::list<BaseObject*>::const_iterator text; 133 for ( text = textList->begin(); text != textList->end(); text++) 134 dynamic_cast<Text*>(*text)->debug(); 129 (*it)->debug(); 135 130 PRINT(0)("+---------------------------TE--+\n"); 136 131 } … … 152 147 compile_version.minor == link_version.minor && 153 148 compile_version.patch == link_version.patch) 154 155 156 149 { 150 return true; 151 } 157 152 else 158 159 160 161 162 153 { 154 PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", 155 compile_version.major, 156 compile_version.minor, 157 compile_version.patch); 163 158 164 165 166 167 168 169 159 PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", 160 link_version.major, 161 link_version.minor, 162 link_version.patch); 163 return false; 164 } 170 165 } -
trunk/src/lib/graphics/text_engine/text_engine.h
r5515 r9869 24 24 class TextEngine : public BaseObject 25 25 { 26 public: 26 ObjectListDeclaration(TextEngine); 27 public: 27 28 virtual ~TextEngine(); 28 29 /** @returns a Pointer to the only object of this Class */ -
trunk/src/lib/gui/gl/glgui_bar.cc
r8991 r9869 23 23 { 24 24 25 ObjectListDefinition(GLGuiBar); 25 26 /** 26 27 * @brief standard constructor … … 44 45 void GLGuiBar::init() 45 46 { 46 this-> setClassID(CL_GLGUI_BAR, "GLGuiBar");47 this->registerObject(this, GLGuiBar::_objectList); 47 48 48 49 this->setFrontColor(_changedValueColor, true); -
trunk/src/lib/gui/gl/glgui_bar.h
r8991 r9869 21 21 class GLGuiBar : public GLGuiWidget 22 22 { 23 23 ObjectListDeclaration(GLGuiBar); 24 24 public: 25 25 GLGuiBar(); -
trunk/src/lib/gui/gl/glgui_box.cc
r9656 r9869 22 22 namespace OrxGui 23 23 { 24 ObjectListDefinition(GLGuiBox); 24 25 /** 25 26 * standard constructor … … 52 53 void GLGuiBox::init() 53 54 { 54 this-> setClassID(CL_GLGUI_BOX, "GLGuiBox");55 this->registerObject(this, GLGuiBox::_objectList); 55 56 } 56 57 … … 149 150 while (itC != this->_children.end()) 150 151 { 151 if ((*itC)->isA( CL_GLGUI_CONTAINER))152 if ((*itC)->isA(GLGuiContainer::staticClassID())) 152 153 static_cast<GLGuiContainer*>(*itC)->showAll(); 153 154 else … … 164 165 while (itC != this->_children.end()) 165 166 { 166 if ((*itC)->isA( CL_GLGUI_CONTAINER))167 if ((*itC)->isA(GLGuiContainer::staticClassID())) 167 168 static_cast<GLGuiContainer*>(*itC)->hideAll(); 168 169 else -
trunk/src/lib/gui/gl/glgui_box.h
r9656 r9869 19 19 class GLGuiBox : public GLGuiContainer 20 20 { 21 21 ObjectListDeclaration(GLGuiBox); 22 22 public: 23 23 GLGuiBox(OrxGui::Orientation orientation = OrxGui::Vertical); -
trunk/src/lib/gui/gl/glgui_button.cc
r9406 r9869 23 23 namespace OrxGui 24 24 { 25 ObjectListDefinition(GLGuiButton); 25 26 /** 26 27 * standard constructor … … 50 51 void GLGuiButton::init() 51 52 { 52 this-> setClassID(CL_GLGUI_BUTTON, "GLGuiButton");53 this->registerObject(this, GLGuiButton::_objectList); 53 54 54 55 this->setSelectable(true); -
trunk/src/lib/gui/gl/glgui_button.h
r9406 r9869 31 31 class GLGuiButton : public GLGuiWidget 32 32 { 33 33 ObjectListDeclaration(GLGuiButton); 34 34 public: 35 35 GLGuiButton(const std::string& label); -
trunk/src/lib/gui/gl/glgui_checkbutton.cc
r9406 r9869 22 22 namespace OrxGui 23 23 { 24 24 ObjectListDefinition(GLGuiCheckButton); 25 25 26 26 /** … … 49 49 void GLGuiCheckButton::init() 50 50 { 51 this-> setClassID(CL_GLGUI_CHECKBUTTON, "GLGuiCheckButton");51 this->registerObject(this, GLGuiCheckButton::_objectList); 52 52 } 53 53 -
trunk/src/lib/gui/gl/glgui_checkbutton.h
r9406 r9869 21 21 class GLGuiCheckButton : public GLGuiButton 22 22 { 23 23 ObjectListDeclaration(GLGuiCheckButton); 24 24 public: 25 25 GLGuiCheckButton(const std::string& label = "", bool active = false); -
trunk/src/lib/gui/gl/glgui_colorselector.h
r8145 r9869 21 21 class GLGui : public GLGui 22 22 { 23 23 ObjectListDeclaration(GLGuiColorSelector); 24 24 public: 25 25 GLGui(); -
trunk/src/lib/gui/gl/glgui_container.cc
r9656 r9869 20 20 namespace OrxGui 21 21 { 22 22 ObjectListDefinition(GLGuiContainer); 23 23 /** 24 24 * standard constructor … … 41 41 void GLGuiContainer::init() 42 42 { 43 this-> setClassID(CL_GLGUI_CONTAINER, "GLGuiContainer");43 this->registerObject(this, GLGuiContainer::_objectList); 44 44 45 45 this->setBackgroundTexture("gui_container_background.png"); -
trunk/src/lib/gui/gl/glgui_container.h
r9656 r9869 20 20 class GLGuiContainer : public GLGuiWidget 21 21 { 22 22 ObjectListDeclaration(GLGuiContainer); 23 23 public: 24 24 GLGuiContainer(); -
trunk/src/lib/gui/gl/glgui_cursor.cc
r8619 r9869 23 23 namespace OrxGui 24 24 { 25 25 ObjectListDefinition(GLGuiCursor); 26 26 /** 27 27 * standard constructor … … 55 55 void GLGuiCursor::init() 56 56 { 57 this-> setClassID(CL_GLGUI_CURSOR, "GLGuiCursor");57 this->registerObject(this, GLGuiCursor::_objectList); 58 58 59 59 this->setBackgroundColor(Color(1.0, 1.0, 1.0, 1.0)); -
trunk/src/lib/gui/gl/glgui_cursor.h
r8324 r9869 26 26 class GLGuiCursor : public GLGuiWidget, public EventListener 27 27 { 28 28 ObjectListDeclaration(GLGuiCursor); 29 29 public: 30 30 GLGuiCursor(); -
trunk/src/lib/gui/gl/glgui_fixedposition_box.cc
r9656 r9869 23 23 namespace OrxGui 24 24 { 25 ObjectListDefinition(GLGuiFixedpositionBox); 25 26 /** 26 27 * standard constructor … … 29 30 : GLGuiBox(orientation) 30 31 { 32 this->registerObject(this, GLGuiFixedpositionBox::_objectList); 33 31 34 this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE); 32 35 this->setPosition(position); -
trunk/src/lib/gui/gl/glgui_fixedposition_box.h
r9656 r9869 21 21 class GLGuiFixedpositionBox : public OrxGui::GLGuiBox, EventListener 22 22 { 23 23 ObjectListDeclaration(GLGuiFixedpositionBox); 24 24 public: 25 25 GLGuiFixedpositionBox(OrxGui::Position position = OrxGui::Center, OrxGui::Orientation orientation = OrxGui::Vertical); -
trunk/src/lib/gui/gl/glgui_frame.cc
r9406 r9869 21 21 namespace OrxGui 22 22 { 23 23 ObjectListDefinition(GLGuiFrame); 24 24 /** 25 25 * standard constructor … … 44 44 void GLGuiFrame::init() 45 45 { 46 this-> setClassID(CL_GLGUI_FRAME, "GLGuiFrame");46 this->registerObject(this, GLGuiFrame::_objectList); 47 47 this->child = NULL; 48 48 } … … 71 71 if (this->child != NULL) 72 72 { 73 if (this->child->isA( CL_GLGUI_CONTAINER))73 if (this->child->isA(GLGuiContainer::staticClassID())) 74 74 static_cast<GLGuiContainer*>(this->child)->showAll(); 75 75 else … … 83 83 if (this->child != NULL) 84 84 { 85 if (this->child->isA( CL_GLGUI_CONTAINER))85 if (this->child->isA(GLGuiContainer::staticClassID())) 86 86 static_cast<GLGuiContainer*>(this->child)->hideAll(); 87 87 else -
trunk/src/lib/gui/gl/glgui_frame.h
r8145 r9869 20 20 class GLGuiFrame : public GLGuiContainer 21 21 { 22 22 ObjectListDeclaration(GLGuiFrame); 23 23 public: 24 24 GLGuiFrame(); -
trunk/src/lib/gui/gl/glgui_handler.cc
r9656 r9869 23 23 #include "glgui_cursor.h" 24 24 25 #include "class_list.h" 25 #include "loading/resource_manager.h" 26 26 27 #include <cassert> 27 28 … … 31 32 /// TAKE THIS OUT OF HERE. 32 33 #include "graphics_engine.h" 33 #include "loading/resource_manager.h"34 34 35 35 namespace OrxGui 36 36 { 37 37 ObjectListDefinition(GLGuiHandler); 38 38 /** 39 39 * standard constructor … … 41 41 GLGuiHandler::GLGuiHandler () 42 42 { 43 this-> setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");43 this->registerObject(this, GLGuiHandler::_objectList); 44 44 this->setName("GLGuiHandler"); 45 45 … … 77 77 this->_cursor->setMaxBorders(Vector2D(GraphicsEngine::getInstance()->getResolutionX(), GraphicsEngine::getInstance()->getResolutionY())); 78 78 79 _cursor->loadTextureSequence(Resource Manager::getInstance()->getDataDir() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49);79 _cursor->loadTextureSequence(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/" + "maps/reap_mouse/reap_mouse_##.png", 1, 49); 80 80 81 81 } … … 117 117 { 118 118 // retrieve Objects. 119 const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET); 120 121 if (objects) 122 { 123 std::list<BaseObject*>::const_iterator it ; 124 std::list<BaseObject*>::const_iterator currentIt = objects->end(); 119 ObjectList<GLGuiWidget>::const_iterator it, currentIt; 120 currentIt = GLGuiWidget::objectList().end(); 121 122 if (GLGuiWidget::selected() != NULL) 123 { 124 it = std::find(GLGuiWidget::objectList().begin(), GLGuiWidget::objectList().end(), GLGuiWidget::selected()); 125 if (it != GLGuiWidget::objectList().end()) 126 { 127 currentIt = it; 128 it++; 129 } 130 } 131 else 132 { 133 it = GLGuiWidget::objectList().begin(); 134 } 135 136 bool cycledOnce = false; 137 138 for (; it != currentIt; ++it) 139 { 140 if (it == GLGuiWidget::objectList().end() && !cycledOnce) 141 { 142 it = GLGuiWidget::objectList().begin(); 143 cycledOnce = true; 144 } 145 146 if ((*it)->selectable() && (*it)->isVisible()) 147 { 148 (*it)->select(); 149 return; 150 } 151 } 152 153 } 154 155 void GLGuiHandler::selectPrevious() 156 { 157 ObjectList<GLGuiWidget>::const_iterator it, currentIt; 158 currentIt = GLGuiWidget::objectList().begin(); 125 159 126 160 if (GLGuiWidget::selected() != NULL) 127 161 { 128 it = std::find(objects->begin(), objects->end(), GLGuiWidget::selected()); 129 if (it != objects->end()) 130 { 131 currentIt = it; 132 it++; 133 } 134 } 135 else 136 { 137 it = objects->begin(); 138 } 139 140 bool cycledOnce = false; 141 142 for (; it != currentIt; ++it) 143 { 144 if (it == objects->end() && !cycledOnce) 145 { 146 it = objects->begin(); 147 cycledOnce = true; 148 } 149 150 if (dynamic_cast<GLGuiWidget*>(*it)->selectable() && dynamic_cast<GLGuiWidget*>(*it)->isVisible()) 151 { 152 dynamic_cast<GLGuiWidget*>(*it)->select(); 153 return; 154 } 155 } 156 157 } 158 else 159 { 160 PRINTF(0)("NO GUI-ELEMENTS EXISTING\n"); 161 } 162 } 163 164 void GLGuiHandler::selectPrevious() 165 { 166 // retrieve Objects. 167 const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET); 168 169 if (objects) 170 { 171 std::list<BaseObject*>::const_iterator it ; 172 std::list<BaseObject*>::const_iterator currentIt = objects->begin(); 173 174 if (GLGuiWidget::selected() != NULL) 175 { 176 it = std::find(objects->begin(), objects->end(), GLGuiWidget::selected()); 177 if (it != objects->end()) 162 it = std::find(GLGuiWidget::objectList().begin(), GLGuiWidget::objectList().end(), GLGuiWidget::selected()); 163 if (it != GLGuiWidget::objectList().end()) 178 164 { 179 165 currentIt = it; … … 183 169 else 184 170 { 185 it = objects->end();171 it = GLGuiWidget::objectList().end(); 186 172 } 187 173 … … 190 176 for (; it != currentIt; --it) 191 177 { 192 if (it == objects->end() && !cycledOnce)178 if (it == GLGuiWidget::objectList().end() && !cycledOnce) 193 179 { 194 180 --it ; … … 196 182 } 197 183 198 if ( dynamic_cast<GLGuiWidget*>(*it)->selectable() && dynamic_cast<GLGuiWidget*>(*it)->isVisible())199 { 200 dynamic_cast<GLGuiWidget*>(*it)->select();184 if ((*it)->selectable() && (*it)->isVisible()) 185 { 186 (*it)->select(); 201 187 return; 202 188 } 203 189 } 204 190 205 }206 else207 {208 PRINTF(0)("NO GUI-ELEMENTS EXISTING\n");209 }210 191 } 211 192 … … 217 198 { 218 199 case EV_MOUSE_MOTION: 219 220 200 this->checkFocus(); 201 break; 221 202 222 203 case EV_MOUSE_BUTTON_LEFT: 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 204 if (GLGuiWidget::mouseFocused() != NULL && event.bPressed) 205 { 206 // if clickable select the Widget. 207 if (GLGuiWidget::mouseFocused()->clickable()) 208 { 209 Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 210 GLGuiWidget::mouseFocused()->select(); 211 GLGuiWidget::mouseFocused()->click(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D()); 212 } 213 } 214 else if (GLGuiWidget::selected() != NULL && !event.bPressed) 215 { 216 if (GLGuiWidget::selected()->clickable()) 217 { 218 Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y); 219 GLGuiWidget::selected()->release(cursorPos - GLGuiWidget::selected()->getAbsCoor2D()); 220 } 221 } 222 223 break; 243 224 case EV_LEAVE_STATE: 244 245 246 247 248 249 225 if (GLGuiWidget::selected() != NULL) 226 GLGuiWidget::selected()->unselect(); 227 228 if (GLGuiWidget::mouseFocused() != NULL) 229 GLGuiWidget::mouseFocused()->breakMouseFocus(); 230 break; 250 231 251 232 case EV_VIDEO_RESIZE: 252 253 254 255 233 if (this->_cursor != NULL) 234 this->_cursor->setMaxBorders(Vector2D(event.resize.w, event.resize.h)); 235 this->_resolution = Vector2D(event.resize.w, event.resize.h); 236 break; 256 237 257 238 case SDLK_TAB: 258 259 260 261 262 263 264 265 239 if (event.bPressed) 240 { 241 if (EventHandler::getInstance()->isPressed(SDLK_LSHIFT) || EventHandler::getInstance()->isPressed(SDLK_RSHIFT)) 242 this->selectPrevious(); 243 else 244 this->selectNext(); 245 } 246 break; 266 247 } 267 248 … … 304 285 { 305 286 // CHECK THE COLLISIONS. 306 const std::list<BaseObject*>* objects = ClassList::getList(CL_GLGUI_WIDGET);307 308 if (objects != NULL && this->_cursor != NULL)309 { 310 for (std::list<BaseObject*>::const_iterator it = objects->begin(); it != objects->end();it++)311 { 312 GLGuiWidget* widget = dynamic_cast<GLGuiWidget*>(*it);287 if (this->_cursor != NULL) 288 { 289 for (ObjectList<GLGuiWidget>::const_iterator it = GLGuiWidget::objectList().begin(); 290 it != GLGuiWidget::objectList().end(); 291 it++) 292 { 293 GLGuiWidget* widget = (*it); 313 294 314 295 if (widget->isVisible() && -
trunk/src/lib/gui/gl/glgui_handler.h
r9656 r9869 19 19 class GLGuiHandler : public EventListener 20 20 { 21 21 ObjectListDeclaration(GLGuiHandler); 22 22 public: 23 23 /** @returns a Pointer to the only object of this Class */ -
trunk/src/lib/gui/gl/glgui_image.cc
r8619 r9869 22 22 namespace OrxGui 23 23 { 24 24 ObjectListDefinition(GLGuiImage); 25 25 /** 26 26 * standard constructor … … 45 45 void GLGuiImage::init() 46 46 { 47 this-> setClassID(CL_GLGUI_IMAGE, "GLGuiImage");47 this->registerObject(this, GLGuiImage::_objectList); 48 48 49 49 this->setForegroundColor(Color(1,1,1,1)); -
trunk/src/lib/gui/gl/glgui_image.h
r9406 r9869 21 21 class GLGuiImage : public GLGuiWidget 22 22 { 23 23 ObjectListDeclaration(GLGuiImage); 24 24 public: 25 25 GLGuiImage(); -
trunk/src/lib/gui/gl/glgui_inputline.cc
r9406 r9869 20 20 namespace OrxGui 21 21 { 22 ObjectListDefinition(GLGuiInputLine); 22 23 /** 23 24 * @brief standard constructor … … 44 45 void GLGuiInputLine::init() 45 46 { 46 this-> setClassID(CL_GLGUI_INPUTLINE, "GLGuiInputLine");47 this->registerObject(this, GLGuiInputLine::_objectList); 47 48 48 49 this->setFocusable(true); -
trunk/src/lib/gui/gl/glgui_inputline.h
r9406 r9869 25 25 class GLGuiInputLine : public OrxGui::GLGuiWidget 26 26 { 27 27 ObjectListDeclaration(GLGuiInputLine); 28 28 public: 29 29 GLGuiInputLine(); -
trunk/src/lib/gui/gl/glgui_mainwidget.cc
r8145 r9869 20 20 namespace OrxGui 21 21 { 22 22 ObjectListDefinition(GLGuiMainWidget); 23 23 24 24 /** … … 27 27 GLGuiMainWidget::GLGuiMainWidget() 28 28 { 29 this-> setClassID(CL_GLGUI_MAIN_WIDGET, "GLGuiMainWidget");29 this->registerObject(this, GLGuiMainWidget::_objectList); 30 30 this->setName("GLGuiMainWidget"); 31 31 } -
trunk/src/lib/gui/gl/glgui_mainwidget.h
r8145 r9869 15 15 class GLGuiMainWidget : public GLGuiWidget 16 16 { 17 17 ObjectListDeclaration(GLGuiMainWidget); 18 18 public: 19 19 virtual ~GLGuiMainWidget(void); -
trunk/src/lib/gui/gl/glgui_menu.cc
r8145 r9869 20 20 namespace OrxGui 21 21 { 22 22 ObjectListDefinition(GLGuiMenu); 23 23 /** 24 24 * standard constructor -
trunk/src/lib/gui/gl/glgui_menu.h
r8145 r9869 19 19 class GLGuiMenu : public GLGuiMenu 20 20 { 21 21 ObjectListDeclaration(GLGuiMenu); 22 22 public: 23 23 GLGuiMenu(); -
trunk/src/lib/gui/gl/glgui_pushbutton.cc
r8717 r9869 23 23 namespace OrxGui 24 24 { 25 25 ObjectListDefinition(GLGuiPushButton); 26 26 /** 27 27 * @brief standard constructor … … 58 58 void GLGuiPushButton::init() 59 59 { 60 this-> setClassID(CL_GLGUI_PUSHBUTTON, "GLGuiPushButton");60 this->registerObject(this, GLGuiPushButton::_objectList); 61 61 } 62 62 -
trunk/src/lib/gui/gl/glgui_pushbutton.h
r8717 r9869 21 21 class GLGuiPushButton : public GLGuiButton 22 22 { 23 23 ObjectListDeclaration(GLGuiPushButton); 24 24 public: 25 25 GLGuiPushButton(const std::string& label = ""); -
trunk/src/lib/gui/gl/glgui_slider.cc
r9406 r9869 23 23 namespace OrxGui 24 24 { 25 25 ObjectListDefinition(GLGuiSlider); 26 26 /** 27 27 * @brief standard constructor … … 46 46 { 47 47 48 this-> setClassID(CL_GLGUI_SLIDER, "GLGuiSlider");48 this->registerObject(this, GLGuiSlider::_objectList); 49 49 50 50 this->setClickable(true); -
trunk/src/lib/gui/gl/glgui_slider.h
r9406 r9869 21 21 class GLGuiSlider : public GLGuiWidget 22 22 { 23 23 ObjectListDeclaration(GLGuiSlider); 24 24 public: 25 25 GLGuiSlider(); -
trunk/src/lib/gui/gl/glgui_table.cc
r8717 r9869 23 23 namespace OrxGui 24 24 { 25 ObjectListDefinition(GLGuiTable); 25 26 /** 26 27 * @brief standard constructor … … 47 48 void GLGuiTable::init() 48 49 { 49 this-> setClassID(CL_GLGUI_TABLE, "GLGuiTable");50 this->registerObject(this, GLGuiTable::_objectList); 50 51 51 52 this->setBorderTop(10); -
trunk/src/lib/gui/gl/glgui_table.h
r8717 r9869 25 25 class GLGuiTable : public OrxGui::GLGuiWidget 26 26 { 27 27 ObjectListDeclaration(GLGuiTable); 28 28 public: 29 29 GLGuiTable(unsigned int rows, unsigned int columns); -
trunk/src/lib/gui/gl/glgui_text.cc
r9656 r9869 22 22 namespace OrxGui 23 23 { 24 ObjectListDefinition(GLGuiText); 24 25 /** 25 26 * standard constructor … … 43 44 void GLGuiText::init() 44 45 { 45 this-> setClassID(CL_GLGUI_TEXT, "GLGuiText");46 this->registerObject(this, GLGuiText::_objectList); 46 47 47 48 this->_text.setParent2D(this); -
trunk/src/lib/gui/gl/glgui_text.h
r9656 r9869 20 20 class GLGuiText : public GLGuiWidget 21 21 { 22 22 ObjectListDeclaration(GLGuiText); 23 23 public: 24 24 GLGuiText(); -
trunk/src/lib/gui/gl/glgui_textfield.cc
r9406 r9869 22 22 namespace OrxGui 23 23 { 24 ObjectListDefinition(GLGuiTextfield); 24 25 /** 25 26 * standard constructor … … 43 44 void GLGuiTextfield::init() 44 45 { 45 this-> setClassID(CL_GLGUI_TEXTFIELD, "GLGuiTextfield");46 this->registerObject(this, GLGuiTextfield::_objectList); 46 47 47 48 this->_text.setParent2D(this); -
trunk/src/lib/gui/gl/glgui_textfield.h
r9406 r9869 20 20 class GLGuiTextfield : public GLGuiWidget 21 21 { 22 22 ObjectListDeclaration(GLGuiTextfield); 23 23 public: 24 24 GLGuiTextfield(); -
trunk/src/lib/gui/gl/glgui_widget.cc
r9656 r9869 25 25 26 26 #include "loading/load_param.h" 27 28 /// TODO TAKE THIS OUT OF HERE29 27 #include "loading/resource_manager.h" 30 28 31 29 namespace OrxGui 32 30 { 33 31 ObjectListDefinition(GLGuiWidget); 34 32 /** 35 33 * @brief standard constructor … … 95 93 void GLGuiWidget::init() 96 94 { 97 this-> setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");95 this->registerObject(this, GLGuiWidget::_objectList); 98 96 99 97 this->_focusable = false; … … 104 102 105 103 if(GLGuiWidget::_defaultFont == NULL) 106 GLGuiWidget::_defaultFont = new Font(Resource Manager::getInstance()->getDataDir() + "/fonts/final_frontier.ttf", 20);104 GLGuiWidget::_defaultFont = new Font(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/fonts/final_frontier.ttf", 20); 107 105 108 106 this->_font = *GLGuiWidget::_defaultFont; -
trunk/src/lib/gui/gl/glgui_widget.h
r9656 r9869 21 21 namespace OrxGui 22 22 { 23 24 23 class GLGuiCursor; 25 24 … … 31 30 class GLGuiWidget : public Element2D 32 31 { 32 ObjectListDeclaration(GLGuiWidget); 33 33 public: 34 34 GLGuiWidget(GLGuiWidget* parent = NULL); -
trunk/src/lib/gui/gl/glgui_window.cc
r8145 r9869 20 20 namespace OrxGui 21 21 { 22 22 ObjectListDefinition(GLGuiWindow); 23 23 /** 24 24 * standard constructor … … 43 43 void GLGuiWindow::init() 44 44 { 45 this-> setClassID(CL_GLGUI_WINDOW, "GLGuiWindow");45 this->registerObject(this, GLGuiWindow::_objectList); 46 46 47 47 } -
trunk/src/lib/gui/gl/glgui_window.h
r8145 r9869 20 20 class GLGuiWindow : public GLGuiContainer 21 21 { 22 22 ObjectListDeclaration(GLGuiWindow); 23 23 public: 24 24 GLGuiWindow(); -
trunk/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc
r9406 r9869 24 24 #include "util/loading/factory.h" 25 25 #include "util/loading/load_param.h" 26 27 CREATE_FACTORY(GLMenuImageScreen, CL_GLMENU_IMAGE_SCREEN); 28 26 #include "debug.h" 27 28 #include "class_id_DEPRECATED.h" 29 ObjectListDefinitionID(GLMenuImageScreen, CL_GLMENU_IMAGE_SCREEN); 30 CREATE_FACTORY(GLMenuImageScreen); 29 31 30 32 /** … … 33 35 GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root) 34 36 { 35 this-> setClassID(CL_GLMENU_IMAGE_SCREEN, "GLMenuImageScreen");37 this->registerObject(this, GLMenuImageScreen::_objectList); 36 38 this->setName("GLMenuLoadScreen"); 37 39 // Select Our VU Meter Background Texture … … 58 60 { 59 61 LoadParam(root, "BackgroundImage", this, GLMenuImageScreen, setBackgroundImage) 60 62 .describe("sets the image to load onto the loadscreen"); 61 63 62 64 LoadParam(root, "BackgroundPS", this, GLMenuImageScreen, setPosScale) 63 65 .describe("The Position and Scale of the Background Image in %(0-1.0). PosX, PosY, SizeX, SizeY"); 64 66 65 67 LoadParam(root, "BarImage", this, GLMenuImageScreen, setBarImage) 66 68 .describe("sets the image of the LoadingBar"); 67 69 68 70 LoadParam(root, "BarPS", this, GLMenuImageScreen, setBarPosScale) 69 71 .describe("The Position and Scale of the Loading Bar in %(0-1.0). PosX, PosY, SizeX, SizeY"); 70 72 71 73 LoadParam(root, "ElementCount", this, GLMenuImageScreen, setMaximum) 72 74 .describe("The Count of elements to load into the bar (this is only a maximum value)"); 73 75 } 74 76 -
trunk/src/lib/gui/gl/glmenu/glmenu_imagescreen.h
r8145 r9869 15 15 class GLMenuImageScreen : public BaseObject 16 16 { 17 17 ObjectListDeclaration(GLMenuImageScreen); 18 18 public: 19 19 GLMenuImageScreen (const TiXmlElement* root = NULL); … … 33 33 void setMaximum (int maxValue); 34 34 /** @returns the maximum of countable steps*/ 35 inline int GLMenuImageScreen::getMaximum() const { return this->maxValue; };35 inline int getMaximum() const { return this->maxValue; }; 36 36 37 37 void setValue (int currentValue); -
trunk/src/lib/gui/gl/specials/glgui_notifier.cc
r8619 r9869 23 23 namespace OrxGui 24 24 { 25 25 ObjectListDefinition(GLGuiNotifier); 26 26 /** 27 27 * @brief standard constructor … … 29 29 GLGuiNotifier::GLGuiNotifier () 30 30 { 31 this-> setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier");31 this->registerObject(this, GLGuiNotifier::_objectList); 32 32 33 33 // Element2D and generals -
trunk/src/lib/gui/gl/specials/glgui_notifier.h
r8619 r9869 24 24 class GLGuiNotifier : public GLGuiWidget 25 25 { 26 ObjectListDeclaration(GLGuiNotifier); 26 27 public: 27 28 GLGuiNotifier(); … … 67 68 MultiLineText* text; 68 69 69 } DisplayLine; 70 } 71 DisplayLine; 70 72 71 73 -
trunk/src/lib/gui/gui.cc
r7661 r9869 18 18 #include "gui.h" 19 19 #include "gui_saveable.h" 20 #include "p references.h"20 #include "parser/preferences/preferences.h" 21 21 22 22 namespace OrxGui -
trunk/src/lib/gui/gui_saveable.cc
r9406 r9869 18 18 #include "gui_saveable.h" 19 19 #include "gui.h" 20 #include "p references.h"20 #include "parser/preferences/preferences.h" 21 21 22 22 #include "debug.h" -
trunk/src/lib/lang/Makefile.am
r9677 r9869 1 MAINSRCDIR=../.. 2 include $(MAINSRCDIR)/defs/include_paths.am 3 4 LIB_PREFIX=$(MAINSRCDIR)/lib 5 include $(MAINSRCDIR)/lib/BuildLibs.am 1 INCLUDES = -I../.. 2 INCLUDES +=-I.. 3 INCLUDES +=-I../util 6 4 7 5 noinst_LIBRARIES = libORXlang.a … … 9 7 libORXlang_a_SOURCES = \ 10 8 base_object.cc \ 11 class_list.cc \ 12 new_class_id.cc \ 13 new_object_list.cc 9 class_id.cc \ 10 object_list.cc 14 11 15 12 noinst_HEADERS = \ 16 13 base_object.h \ 17 class_list.h \ 18 new_class_id.h \ 19 new_object_list.h 20 21 22 23 24 25 ## THIS ALL IS JUST FOR TESTING!! 26 check_PROGRAMS = test_object_list 27 28 test_object_list_SOURCES = \ 29 test_object_list.cc 30 31 test_object_list_DEPENDENCIES = libORXlang.a 32 33 test_object_list_LDADD = \ 34 $(MAINSRCDIR)/util/libORXutils.a \ 35 $(libORXlibs_a_LIBRARIES_) \ 36 $(MAINSRCDIR)/world_entities/libORXwe.a \ 37 $(libORXlibs_a_LIBRARIES_) \ 38 $(MAINSRCDIR)/util/libORXutils.a 39 40 #test_object_list_LDADD = \ 41 libORXlang.a 14 class_id.h \ 15 object_list.h -
trunk/src/lib/lang/base_object.cc
r9406 r9869 1 2 3 1 /* 4 2 orxonox - the future of 3D-vertical-scrollers … … 19 17 #include "base_object.h" 20 18 19 #include "util/debug.h" 21 20 #include "util/loading/load_param.h" 22 #include "class_list.h" 21 22 ObjectListDefinition(BaseObject); 23 23 24 24 /** 25 25 * @brief sets the name from a LoadXML-Element 26 * @param root the element to load from26 * @param objectName: The name of the Object. 27 27 */ 28 28 BaseObject::BaseObject(const std::string& objectName) 29 29 { 30 this->classID = CL_BASE_OBJECT;31 30 this->className = "BaseObject"; 32 31 33 32 this->objectName = objectName; 34 this->classList = NULL;35 33 this->xmlElem = NULL; 36 37 //ClassList::addToClassList(this, this->classID, "BaseObject"); 34 this->registerObject(this, BaseObject::_objectList); 38 35 } 39 36 … … 43 40 BaseObject::~BaseObject () 44 41 { 45 ClassList::removeFromClassList(this); 42 /// Remove from the ObjectLists 43 ClassEntries::iterator it; 44 PRINTF(5)("Deleting Object of type %s::%s\n", this->getClassCName(), getCName()); 45 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 46 { 47 if (ORX_DEBUG >= 5) 48 assert((*it)._objectList->checkIteratorInList((*it)._iterator) || (*it)._objectList->checkObjectInList(this)); 49 (*it)._objectList->unregisterObject((*it)._iterator); 50 delete (*it)._iterator; 51 } 46 52 47 53 if (this->xmlElem != NULL) … … 69 75 70 76 /** 71 * @brief sets the class identifiers72 * @param id a number for the class from class_id.h enumeration73 * @param className the class name74 */75 void BaseObject::setClassID(ClassID classID, const std::string& className)76 {77 //printf("%s(0x%.8X)->%s(0x%.8X)\n", this->className, this->classID, className, classID);78 assert (!(this->classID & classID & !CL_MASK_SUBSUPER_CLASS_IDA ));79 80 this->leafClassID = classID;81 this->classID |= (long)classID;82 this->className = className;83 84 this->classList = ClassList::addToClassList(this, classID, this->classID, className);85 }86 87 88 /**89 77 * @brief set the name of the Object 90 78 * @param objectName The new name of the Object. … … 97 85 98 86 /** 99 * @brief queries for the ClassID of the Leaf Class (the last made class of this type 100 * @returns the ClassID of the Leaf Class (e.g. the ID of the Class) 101 * 102 * the returned ID can be used to generate new Objects of the same type through 103 * Factory::fabricate(Object->getLeafClassID()); 87 * @brief Seeks in the Inheritance if it matches objectList. 88 * @param objectList The ObjectList this should be a member of (by Pointer-comparison). 89 * @return True if found, false if not. 104 90 */ 105 const ClassID& BaseObject::getLeafClassID() const91 bool BaseObject::isA(const ObjectListBase& objectList) const 106 92 { 107 return this->leafClassID; 108 } 109 110 111 112 /** 113 * @brief checks if the class is a classID 114 * @param classID the Identifier to check for 115 * @returns true if it is, false otherwise 116 */ 117 bool BaseObject::isA (ClassID classID) const 118 { 119 // if classID is a derivable object from a SUPERCLASS 120 if (classID & CL_MASK_SUPER_CLASS) 121 { 122 if( likely(this->classID & classID)) 93 ClassEntries::const_iterator it; 94 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 95 if ((*it)._objectList == &objectList) 123 96 return true; 124 }125 // if classID is a SubSuperClass, and126 else if (classID & CL_MASK_SUBSUPER_CLASS)127 {128 if (likely(((this->classID & CL_MASK_SUBSUPER_CLASS_IDA) == (classID & CL_MASK_SUBSUPER_CLASS_IDA)) &&129 this->classID & classID & CL_MASK_SUBSUPER_CLASS_IDB))130 return true;131 }132 // if classID is a LOWLEVEL-class133 else134 {135 if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))136 return true;137 }138 97 return false; 139 98 } 140 99 141 100 101 /** 102 * @brief Seeks in the Inheritance if it matches objectList. 103 * @param classID The ClassID this should be a member of (by Pointer-comparison). 104 * @return True if found, false if not. 105 */ 106 bool BaseObject::isA(const ClassID& classID) const 107 { 108 ClassEntries::const_iterator it; 109 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 110 if (*(*it)._objectList == classID) 111 return true; 112 return false; 113 } 142 114 143 115 /** 144 * @brief checks if the class is a classID145 * @param classID the Identifier to check for146 * @return s true if it is, false otherwise116 * @brief Seeks in the Inheritance if it matches objectList. 117 * @param classID The ClassID of the class this should be a member of. 118 * @return True if found, false if not. 147 119 */ 148 bool BaseObject::isA (const std::string& className) const120 bool BaseObject::isA(int classID) const 149 121 { 150 ClassID classID = ClassList::StringToID(className); 151 if (classID != CL_NULL) 152 return this->isA(classID); 153 else 154 return false; 122 ClassEntries::const_iterator it; 123 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 124 if (*(*it)._objectList == classID) 125 126 return true; 127 return false; 128 } 129 130 /** 131 * @brief Seeks in the Inheritance if it matches objectList. 132 * @param className The ClassName of the class this should be a member of. 133 * @return True if found, false if not. 134 */ 135 bool BaseObject::isA(const std::string& className) const 136 { 137 ClassEntries::const_iterator it; 138 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 139 if (*(*it)._objectList == className) 140 return true; 141 return false; 155 142 } 156 143 157 144 158 145 /** 159 * @brief compares the ObjectName with an external name160 * @param objectName: the name to check.161 * @returns true on match, false otherwise.146 * @brief This is for debug purposes, to see the Inheritances of this Object and its classes. 147 * 148 * The Inheritance will be listed in a Linear fashion, diamand structures are resolved in a linear dependency. 162 149 */ 163 bool BaseObject::operator==(const std::string& objectName) const150 void BaseObject::listInheritance() const 164 151 { 165 return (this->objectName == objectName); 152 PRINT(0)("Listing inheritance diagram for %s::%s: ", getClassCName(), getCName()); 153 ClassEntries::const_iterator it; 154 for (it = this->_classes.begin(); it != this->_classes.end(); ++it) 155 PRINT(0)(" -> %s(id:%d)", (*it)._objectList->name().c_str(), (*it)._objectList->id()); 156 PRINT(0)("\n"); 157 166 158 } 167 -
trunk/src/lib/lang/base_object.h
r9406 r9869 14 14 #define __BASE_OBJECT_H_ 15 15 16 #include " class_id.h"17 #include " sigslot/slot.h"16 #include "object_list.h" 17 #include "util/sigslot/slot.h" 18 18 19 19 #include <string> … … 26 26 class BaseObject : public sigslot::has_slots<> 27 27 { 28 28 //! Declare an ObjectList for this Class. 29 ObjectListDeclaration(BaseObject); 29 30 public: 30 31 BaseObject (const std::string& objectName = ""); … … 41 42 inline TiXmlNode* getXmlElem() const { return this->xmlElem; }; 42 43 43 / ** @returns the className of the corresponding Object */44 inline const std::string& getClassName() const { return this->className; }44 // /** @returns the className of the corresponding Object */ 45 //inline const std::string& getClassName() const { return this->className; } 45 46 /** @returns the className of the corresponding Object as a C-compliant string (const char*) */ 46 inline const char* getClassCName() const { return this->className.c_str(); }; 47 /** @returns the classID of the corresponding Object */ 48 inline int getClassID() const { return this->classID; }; 49 const ClassID& getLeafClassID() const; 47 inline const char* getClassCName() const { return _classes.front()._objectList->name().c_str(); }; 48 /** @returns the ClassName of the Topmost Object of the ClassStack */ 49 inline const std::string& getClassName() const { return _classes.front()._objectList->name(); }; 50 50 51 bool isA (ClassID classID) const; 52 bool isA (const std::string& className) const; 51 /** @returns the ClassID of this Object */ 52 inline const ClassID& getClassID() const { return _classes.front()._objectList->identity(); } 53 /** @returns the ID of the Topmost object of the ClassStack */ 54 inline const int& getLeafClassID() const { return _classes.front()._objectList->identity().id(); } 55 56 bool isA(const ObjectListBase& objectList) const; 57 bool isA(const ClassID& classID) const; 58 bool isA(int classID) const; 59 bool isA(const std::string& className) const; 60 61 void listInheritance() const; 53 62 54 63 /** @param classID comparer for a ClassID @returns true on match, false otherwise */ 55 bool operator==(ClassID classID) const { return this->isA(classID); }; 56 bool operator==(const std::string& objectName) const; 64 bool operator==(int classID) const { return this->isA(classID); }; 65 /** @param objectName: the name to check. * @returns true on match, false otherwise. */ 66 bool operator==(const std::string& objectName) const { return this->objectName == objectName;}; 57 67 58 68 protected: 59 void setClassID(ClassID classID, const std::string& className);69 template<class T> void registerObject(T* object, ObjectList<T>& list); 60 70 61 71 protected: … … 63 73 64 74 private: 65 std::string className; //!< the name of the class66 long classID; //!< this is the id from the class_id.h enumeration67 ClassID leafClassID; //!< The Leaf Class ID68 69 ClassList* classList; //!< Pointer to the ClassList this Object is inside of70 75 71 76 TiXmlNode* xmlElem; //!< The XML Element with wich this Object was loaded(saved). 77 78 ////////////////////////////// 79 //// Type Definition Part //// 80 ////////////////////////////// 81 //! A ClassEntry so we can store Classes inside of Objects 82 struct ClassEntry 83 { 84 /** Simple Constuctor @param objectList the ObjectList, @param iterator the (intrusive) Iterator inside of the ObjectList */ 85 inline ClassEntry (ObjectListBase* objectList, ObjectListBase::IteratorBase* iterator) : _objectList(objectList), _iterator(iterator) {} 86 ObjectListBase* _objectList; //!< An ObjectList this Object is part of 87 ObjectListBase::IteratorBase* _iterator; //!< An iterator pointing to the position of the Object inside of the List. 88 }; 89 typedef std::list<ClassEntry> ClassEntries; //!< Type definition for the List. 90 91 std::string className; //!< the name of the class 92 ClassEntries _classes; //!< All Classes this object is part of. 72 93 }; 73 94 95 96 /** 97 * @brief Registeres an Object of Type T to objectList 98 * @param object The Object to append to the objectList. 99 * @param objectList The ObjectList to append the Object to. 100 * 101 * This function is essential to integrate objects into their designated ObjectList. 102 * Remember if you do not want objects to be stored in Lists (less overhead), 103 * do not attempt to call this function. 104 */ 105 template<class T> 106 inline void BaseObject::registerObject(T* object, ObjectList<T>& objectList) 107 { 108 this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object))); 109 } 110 74 111 #endif /* __BASE_OBJECT_H_ */ -
trunk/src/lib/network/converter.cc
r9406 r9869 28 28 SHELL_COMMAND_STATIC(debug, Converter, Converter::debug); 29 29 30 30 ObjectListDefinition(Converter); 31 31 /* using namespace std is default, this needs to be here */ 32 32 -
trunk/src/lib/network/converter.h
r7230 r9869 24 24 class Converter : public BaseObject 25 25 { 26 ObjectListDeclaration(Converter); 26 27 public: 27 28 static byte* intToByteArray(int x); -
trunk/src/lib/network/data_stream.cc
r9406 r9869 20 20 /* using namespace std is default, this needs to be here */ 21 21 22 23 22 ObjectListDefinition(DataStream); 24 23 25 24 /** … … 28 27 DataStream::DataStream() 29 28 { 30 this->setClassID(CL_DATA_STREAM, "DataStream");31 29 this->upBuffer = new byte[DATA_STREAM_BUFFER_SIZE]; 32 30 this->downBuffer = new byte[DATA_STREAM_BUFFER_SIZE]; … … 38 36 DataStream::DataStream(DataStream& inStream, DataStream& outStream) 39 37 { 40 this->setClassID(CL_DATA_STREAM, "DataStream");38 this->registerObject(this, DataStream::_objectList); 41 39 this->downStream = &outStream; 42 40 this->upStream = &inStream; -
trunk/src/lib/network/data_stream.h
r6981 r9869 17 17 class DataStream : public BaseObject 18 18 { 19 public: 19 ObjectListDeclaration(DataStream); 20 public: 20 21 DataStream(); 21 22 DataStream(DataStream& inStream, DataStream& outStream); -
trunk/src/lib/network/handshake.cc
r9656 r9869 23 23 24 24 25 25 ObjectListDefinition(Handshake); 26 26 27 27 … … 30 30 { 31 31 /* set the class id for the base object */ 32 this-> setClassID(CL_HANDSHAKE, "Handshake");32 this->registerObject(this, Handshake::_objectList); 33 33 34 34 -
trunk/src/lib/network/handshake.h
r9494 r9869 42 42 class Handshake : public Synchronizeable 43 43 { 44 44 ObjectListDeclaration(Handshake); 45 45 public: 46 46 Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); -
trunk/src/lib/network/message_manager.cc
r9656 r9869 28 28 29 29 30 30 ObjectListDefinition(MessageManager); 31 31 MessageManager* MessageManager::singletonRef = NULL; 32 32 … … 37 37 MessageManager::MessageManager () 38 38 { 39 this-> setClassID( CL_MESSAGE_MANAGER, "MessageManager");39 this->registerObject(this, MessageManager::_objectList); 40 40 newNumber = 1; 41 41 setSynchronized( true ); -
trunk/src/lib/network/message_manager.h
r9656 r9869 96 96 class MessageManager : public Synchronizeable { 97 97 98 98 ObjectListDeclaration(MessageManager); 99 99 public: 100 100 inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager(); return singletonRef; } -
trunk/src/lib/network/monitor/connection_monitor.cc
r9494 r9869 23 23 /* using namespace std is default, this needs to be here */ 24 24 25 25 ObjectListDefinition(ConnectionMonitor); 26 26 /** 27 27 * constructor … … 31 31 { 32 32 /* set the class id for the base object and add ist to class list*/ 33 this-> setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor");33 this->registerObject(this, ConnectionMonitor::_objectList); 34 34 35 35 this->userId = userId; -
trunk/src/lib/network/monitor/connection_monitor.h
r9494 r9869 19 19 class ConnectionMonitor : virtual public BaseObject 20 20 { 21 ObjectListDeclaration(ConnectionMonitor); 21 22 public: 22 23 ConnectionMonitor( int userId ); -
trunk/src/lib/network/monitor/network_monitor.cc
r9656 r9869 37 37 SHELL_COMMAND(debug, NetworkMonitor, debug); 38 38 39 ObjectListDefinition(NetworkMonitor); 39 40 40 41 … … 45 46 : Synchronizeable() 46 47 { 47 this-> setClassID(CL_NETWORK_MONITOR, "NetworkMonitor");48 this->registerObject(this, NetworkMonitor::_objectList); 48 49 49 50 this->networkStream = networkStream; -
trunk/src/lib/network/monitor/network_monitor.h
r9656 r9869 27 27 class NetworkMonitor : public Synchronizeable 28 28 { 29 29 ObjectListDeclaration(NetworkMonitor); 30 30 public: 31 31 NetworkMonitor(NetworkStream* networkStream); -
trunk/src/lib/network/monitor/network_stats_widget.cc
r9656 r9869 20 20 #include "peer_info.h" 21 21 22 #include "loading/resource_manager.h" 23 22 24 #include "multi_type.h" 23 25 24 26 #include "shell_command.h" 25 26 #include "loading/resource_manager.h"27 27 28 28 // this fcuk does not work! … … 30 30 // ->setAlias("ProxyGui"); 31 31 32 33 32 HostWidget::HostWidget(const std::string& name, const IP& ip) 34 33 : GLGuiBox(OrxGui::Horizontal) … … 57 56 { 58 57 if(_font == NULL) 59 _font = new Font(Resource Manager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20);58 _font = new Font(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/fonts/arial.ttf", 20); 60 59 61 60 //this->_name.setFont(*_font); … … 211 210 //======================================================// 212 211 212 213 ObjectListDefinition(NetworkStatsWidget); 213 214 /** 214 215 * @brief standard constructor … … 273 274 NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL; 274 275 275 #include "class_list.h"276 277 276 void NetworkStatsWidget::toggleGUI() 278 277 { 279 BaseObject* bo = NULL; 280 const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR); 281 if (ls != NULL && !ls->empty()) 282 bo = ls->front(); 283 284 if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL) 285 { 286 NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo)); 278 NetworkMonitor* monitor; 279 if (!NetworkMonitor::objectList().empty()) 280 monitor = NetworkMonitor::objectList().front(); 281 282 if (monitor != NULL && NetworkStatsWidget::_statsWidget == NULL) 283 { 284 NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(monitor); 287 285 NetworkStatsWidget::_statsWidget->showAll(); 288 286 } -
trunk/src/lib/network/monitor/network_stats_widget.h
r9656 r9869 81 81 class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox 82 82 { 83 ObjectListDeclaration(NetworkStatsWidget); 83 84 public: 84 85 static void toggleGUI(); -
trunk/src/lib/network/network_game_manager.cc
r9656 r9869 23 23 #include "util/loading/factory.h" 24 24 #include "state.h" 25 #include "class_list.h"26 25 #include "debug.h" 27 26 … … 43 42 #include "multiplayer_team_deathmatch.h" 44 43 45 #include "p references.h"46 47 48 49 44 #include "parser/preferences/preferences.h" 45 46 47 48 ObjectListDefinition(NetworkGameManager); 50 49 NetworkGameManager* NetworkGameManager::singletonRef = NULL; 51 50 … … 59 58 60 59 /* set the class id for the base object */ 61 this-> setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");60 this->registerObject(this, NetworkGameManager::_objectList); 62 61 63 62 this->setSynchronized(true); … … 93 92 assert( SharedNetworkData::getInstance()->isMasterServer()); 94 93 assert( State::getGameRules() ); 95 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES) );94 assert( State::getGameRules()->isA( NetworkGameRules::staticClassID()) ); 96 95 97 96 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); 98 97 99 98 int team = rules.getTeamForNewUser(); 100 ClassID 99 ClassID playableClassId = rules.getPlayableClassId( userId, team ); 101 100 std::string playableModel = rules.getPlayableModelFileName( userId, team, playableClassId ); 102 101 std::string playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId ); … … 106 105 107 106 assert( bo != NULL ); 108 assert( bo->isA( CL_PLAYABLE) );107 assert( bo->isA( Playable::staticClassID()) ); 109 108 110 109 Playable & playable = *(dynamic_cast<Playable*>(bo)); … … 131 130 stats->setNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Server" ) ); 132 131 133 if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH) )132 if ( rules.isA( MultiplayerTeamDeathmatch::staticClassID()) ) 134 133 dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f ); 135 134 … … 187 186 } 188 187 189 const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE);190 191 for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++)192 { 193 if ( dynamic_cast<Synchronizeable*>(*it)->getUniqueID() == uniqueId )188 for (ObjectList<Synchronizeable>::const_iterator it = Synchronizeable::objectList().begin(); 189 it != Synchronizeable::objectList().end(); 190 ++it) 191 { 192 if ( (*it)->getUniqueID() == uniqueId ) 194 193 { 195 if ( (*it)->isA( CL_PLAYABLE) )194 if ( (*it)->isA(Playable::staticClassID()) ) 196 195 { 197 196 getInstance()->playablesToDelete.push_back( dynamic_cast<Playable*>(*it) ); … … 199 198 } 200 199 201 delete dynamic_cast<Synchronizeable*>(*it);200 delete (*it); 202 201 return true; 203 202 } … … 297 296 if ( State::getPlayer()->getPlayable() != *it ) 298 297 { 299 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE ); 300 301 if ( list && std::find( list->begin(), list->end(), *it ) != list->end() ) 298 if ( std::find( Playable::objectList().begin(), Playable::objectList().end(), *it ) != Playable::objectList().end() ) 302 299 { 303 300 PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassCName(), (*it)->getOwner() ); … … 324 321 325 322 assert( State::getGameRules() ); 326 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES) );323 assert( State::getGameRules()->isA( NetworkGameRules::staticClassID()) ); 327 324 328 325 NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules())); -
trunk/src/lib/network/network_game_manager.h
r9656 r9869 33 33 class NetworkGameManager: public Synchronizeable 34 34 { 35 35 ObjectListDeclaration(NetworkGameManager); 36 36 public: 37 37 virtual ~NetworkGameManager(); 38 38 39 static NetworkGameManager* NetworkGameManager::getInstance()39 static NetworkGameManager* getInstance() 40 40 { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; } 41 41 -
trunk/src/lib/network/network_log.cc
r7954 r9869 15 15 16 16 #include "network_log.h" 17 #include <cassert> 17 18 18 19 /** … … 53 54 return false; 54 55 } 55 56 56 57 listensock = SDLNet_TCP_Open( &ip ); 57 58 58 59 if( !listensock ) { 59 60 PRINT(1)( "SDLNet_TCP_Open: %s\n", SDLNet_GetError() ); 60 61 return false; 61 } 62 } 62 63 63 64 return true; … … 71 72 va_list ap; 72 73 va_start( ap, format ); 73 74 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 75 76 va_end( ap ); 77 74 75 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 76 77 va_end( ap ); 78 78 79 printfnet(); 79 80 } … … 85 86 { 86 87 TCPsocket newSock = SDLNet_TCP_Accept( listensock ); 87 88 88 89 if ( newSock ) 89 90 sockets.push_back( newSock ); … … 97 98 va_list ap; 98 99 va_start( ap, format ); 99 100 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 101 102 va_end( ap ); 103 100 101 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 102 103 va_end( ap ); 104 104 105 PRINT(0)( buf ); 105 106 printfnet(); … … 114 115 va_list ap; 115 116 va_start( ap, format ); 116 117 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 118 119 va_end( ap ); 120 117 118 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 119 120 va_end( ap ); 121 121 122 PRINT(1)( buf ); 122 123 printfnet(); … … 131 132 va_list ap; 132 133 va_start( ap, format ); 133 134 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 135 136 va_end( ap ); 137 134 135 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 136 137 va_end( ap ); 138 138 139 PRINT(2)( buf ); 139 140 printfnet(); … … 148 149 va_list ap; 149 150 va_start( ap, format ); 150 151 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 152 153 va_end( ap ); 154 151 152 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 153 154 va_end( ap ); 155 155 156 PRINT(3)( buf ); 156 157 printfnet(); … … 165 166 va_list ap; 166 167 va_start( ap, format ); 167 168 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 169 170 va_end( ap ); 171 168 169 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 170 171 va_end( ap ); 172 172 173 PRINT(4)( buf ); 173 174 printfnet(); … … 182 183 va_list ap; 183 184 va_start( ap, format ); 184 185 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 186 187 va_end( ap ); 188 185 186 assert( vsnprintf( buf, NETWORK_LOG_BUFLEN, format, ap ) < NETWORK_LOG_BUFLEN ); 187 188 va_end( ap ); 189 189 190 PRINT(5)( buf ); 190 191 printfnet(); … … 200 201 if ( !listensock ) 201 202 return; 202 203 203 204 acceptNewConnections(); 204 205 … … 213 214 continue; 214 215 } 215 216 216 217 it++; 217 218 } -
trunk/src/lib/network/network_log.h
r7954 r9869 38 38 class NetworkLog 39 39 { 40 41 40 public: 42 41 virtual ~NetworkLog(void); -
trunk/src/lib/network/network_manager.cc
r9656 r9869 20 20 #define DEBUG_MODULE_NETWORK 21 21 22 #include "class_list.h"23 22 #include "debug.h" 24 23 #include "shell_command.h" … … 28 27 #include "shared_network_data.h" 29 28 #include "network_stream.h" 30 #include "p references.h"29 #include "parser/preferences/preferences.h" 31 30 #include "network_log.h" 32 31 #include "network_game_manager.h" … … 41 40 42 41 43 42 ObjectListDefinition(NetworkManager); 44 43 NetworkManager* NetworkManager::singletonRef = NULL; 45 44 … … 50 49 { 51 50 /* set the class id for the base object */ 52 this-> setClassID(CL_NETWORK_MANAGER, "NetworkManager");51 this->registerObject(this, NetworkManager::_objectList); 53 52 PRINTF(0)("START\n"); 54 53 -
trunk/src/lib/network/network_manager.h
r9656 r9869 25 25 class NetworkManager : public BaseObject 26 26 { 27 27 ObjectListDeclaration(NetworkManager); 28 28 public: 29 29 -
trunk/src/lib/network/network_protocol.cc
r9406 r9869 35 35 36 36 37 37 ObjectListDefinition(NetworkProtocol); 38 38 /** 39 39 standard constructor … … 42 42 { 43 43 /* set the class id for the base object */ 44 this-> setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol");44 this->registerObject(this, NetworkProtocol::_objectList); 45 45 this->headerLength = INTSIZE+FLOATSIZE; 46 46 } -
trunk/src/lib/network/network_protocol.h
r6981 r9869 25 25 class NetworkProtocol : virtual public BaseObject 26 26 { 27 ObjectListDeclaration(NetworkProtocol); 27 28 public: 28 29 NetworkProtocol(); -
trunk/src/lib/network/network_socket.cc
r9406 r9869 24 24 #include "network_socket.h" 25 25 26 /* header for debug output */ 27 #include "debug.h" 28 26 ObjectListDefinition(NetworkSocket); 29 27 /** 30 28 * Default constructor -
trunk/src/lib/network/network_socket.h
r9406 r9869 17 17 class NetworkSocket : public BaseObject 18 18 { 19 ObjectListDeclaration(NetworkSocket); 19 20 public: 20 21 NetworkSocket(); -
trunk/src/lib/network/network_stream.cc
r9656 r9869 33 33 #include "shared_network_data.h" 34 34 #include "message_manager.h" 35 #include "p references.h"35 #include "parser/preferences/preferences.h" 36 36 #include "zip.h" 37 37 38 #include "src/lib/util/loading/resource_manager.h"39 40 38 #include "network_log.h" 41 39 42 40 #include "player_stats.h" 43 41 44 #include "lib/util/loading/factory.h" 42 #include "loading/factory.h" 43 #include "loading/resource_manager.h" 45 44 46 45 #include "debug.h" 47 #include "class_list.h"48 #include <algorithm>49 50 46 51 47 #include "network_stream.h" … … 57 53 #define PACKAGE_SIZE 256 58 54 59 55 ObjectListDefinition(NetworkStream); 60 56 /** 61 57 * empty constructor … … 118 114 { 119 115 /* set the class id for the base object */ 120 this-> setClassID(CL_NETWORK_STREAM, "NetworkStream");116 this->registerObject(this, NetworkStream::_objectList); 121 117 this->clientSocket = NULL; 122 118 this->clientSoftSocket = NULL; … … 970 966 971 967 // if handshake not finished only sync handshake 972 if ( peer->second.handshake && sync.getLeafClassID() != CL_HANDSHAKE)968 if ( peer->second.handshake && Handshake::staticClassID() != sync.getLeafClassID()) 973 969 continue; 974 970 … … 976 972 if ( ( SharedNetworkData::getInstance()->isMasterServer() || 977 973 SharedNetworkData::getInstance()->isProxyServerActive() && peer->second.isClient()) 978 && sync.getLeafClassID() == CL_HANDSHAKE&& sync.getUniqueID() != peer->second.userId )974 && Handshake::staticClassID() == sync.getLeafClassID() && sync.getUniqueID() != peer->second.userId ) 979 975 continue; 980 976 981 977 /* list of synchronizeables that will never be synchronized over the network: */ 982 978 // do not sync null parent 983 if ( sync.getLeafClassID() == CL_NULL_PARENT)979 if ( NullParent::staticClassID() == sync.getLeafClassID()) 984 980 continue; 985 981 … … 1190 1186 /* These are some small exeptions in creation: Not all objects can/should be created via Factory */ 1191 1187 /* Exception 1: NullParent */ 1192 if( leafClassId == CL_NULL_PARENT || leafClassId == CL_SYNCHRONIZEABLE || leafClassId == CL_NETWORK_GAME_MANAGER)1188 if( NullParent::staticClassID() == leafClassId || Synchronizeable::staticClassID() == leafClassId || NetworkGameManager::staticClassID() == leafClassId) 1193 1189 { 1194 1190 PRINTF(1)("Don't create Object with ID %x, ignored!\n", (int)leafClassId); … … 1197 1193 } 1198 1194 else 1199 b = Factory::fabricate( (ClassID)leafClassId );1195 ; /// FIXME CLASS_ID :: b = Factory::fabricate( leafClassId ); 1200 1196 1201 1197 if ( !b ) … … 1206 1202 } 1207 1203 1208 if ( b->isA(CL_SYNCHRONIZEABLE) )1204 if ( b->isA(Synchronizeable::staticClassID()) ) 1209 1205 { 1210 1206 sync = dynamic_cast<Synchronizeable*>(b); … … 1303 1299 length = remainingBytesToWriteToDict; 1304 1300 1305 std::string fileName = Resource Manager::getInstance()->getDataDir();1301 std::string fileName = Resources::ResourceManager::getInstance()->mainGlobalPath().name(); 1306 1302 fileName += "/dicts/newdict"; 1307 1303 -
trunk/src/lib/network/network_stream.h
r9656 r9869 33 33 class NetworkStream : public DataStream 34 34 { 35 35 ObjectListDeclaration(NetworkStream); 36 36 public: 37 37 NetworkStream(); -
trunk/src/lib/network/player_stats.cc
r9656 r9869 16 16 #include "player_stats.h" 17 17 18 #include "class_list.h"19 18 #include "src/lib/util/loading/factory.h" 20 19 21 20 #include "player.h" 21 #include "playable.h" 22 22 #include "state.h" 23 23 #include "shared_network_data.h" … … 25 25 #include "converter.h" 26 26 27 #include "p references.h"27 #include "parser/preferences/preferences.h" 28 28 29 29 #include "debug.h" 30 30 #include "shell_command.h" 31 31 32 33 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS); 34 32 #include "class_id_DEPRECATED.h" 33 34 ObjectListDefinitionID(PlayerStats, CL_PLAYER_STATS); 35 CREATE_FACTORY(PlayerStats); 35 36 36 37 /** … … 54 55 void PlayerStats::init( ) 55 56 { 56 this-> setClassID( CL_PLAYER_STATS, "PlayerStats");57 this->registerObject(this, PlayerStats::_objectList); 57 58 58 59 this->assignedUserId = 0; … … 122 123 PlayerStats * PlayerStats::getStats( int userId ) 123 124 { 124 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 125 126 if ( !list ) 127 { 128 return NULL; 129 } 130 131 for ( std::list<BaseObject*>::const_iterator it = list-> 132 begin(); 133 it != list->end(); 134 it++ ) 135 { 136 137 138 if ( dynamic_cast<PlayerStats*>(*it)->getAssignedUserId() == userId ) 125 for (ObjectList<PlayerStats>::const_iterator it = PlayerStats::objectList().begin(); 126 it != PlayerStats::objectList().end(); 127 ++it) 128 { 129 if ( (*it)->getAssignedUserId() == userId ) 139 130 { 140 return dynamic_cast<PlayerStats*>(*it);131 return (*it); 141 132 } 142 133 } … … 150 141 void PlayerStats::setPlayableUniqueId( int uniqueId ) 151 142 { 152 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );153 154 if ( !list )155 {156 this->playableUniqueId = uniqueId;157 return;158 }159 160 143 this->playable = NULL; 161 for ( std::list<BaseObject*>::const_iterator it = list-> 162 begin(); 163 it != list->end(); 164 it++ ) 165 { 166 if ( dynamic_cast<Playable*>(*it)-> 167 getUniqueID() == uniqueId ) 144 for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin(); 145 it != Playable::objectList().end(); 146 ++it) 147 { 148 if ( (*it)->getUniqueID() == uniqueId ) 168 149 { 169 this->playable = dynamic_cast<Playable*>(*it);150 this->playable = (*it); 170 151 //TODO when OM_PLAYERS is ticked add line: 171 152 //this->playable->toList( OM_PLAYERS ); … … 174 155 } 175 156 176 if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance() 177 ->getHostID() ) 157 if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance()->getHostID() ) 178 158 { 179 159 State::getPlayer()->setPlayable( this->playable ); … … 272 252 void PlayerStats::deleteAllPlayerStats( ) 273 253 { 274 const std::list<BaseObject*> * list; 275 276 while ( (list = ClassList::getList( CL_PLAYER_STATS )) != NULL && list->begin() != list->end() ) 277 delete *list->begin(); 254 255 while(!PlayerStats::objectList().empty()) 256 delete PlayerStats::objectList().front(); 278 257 } 279 258 … … 287 266 ScoreList result; 288 267 289 const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYER_STATS ); 290 291 if ( !list ) 292 { 293 return result; 294 } 295 296 for ( std::list<BaseObject*>::const_iterator it = list-> 297 begin(); 298 it != list->end(); 299 it++ ) 300 { 301 PlayerStats & stats = *dynamic_cast<PlayerStats*>(*it); 268 for (ObjectList<PlayerStats>::const_iterator it = PlayerStats::objectList().begin(); 269 it != PlayerStats::objectList().end(); 270 ++it) 271 { 272 PlayerStats& stats = *(*it); 302 273 303 274 TeamScoreList::iterator it = result[stats.getTeamId()].begin(); -
trunk/src/lib/network/player_stats.h
r9656 r9869 36 36 class PlayerStats : public Synchronizeable 37 37 { 38 38 ObjectListDeclaration(PlayerStats); 39 39 public: 40 40 PlayerStats( const TiXmlElement* root = NULL ); … … 58 58 59 59 inline int getPlayableClassId(){ return playableClassId; } 60 void setPlayableClassId( int classId ){ this->playableClassId = classId; };60 void setPlayableClassId( const ClassID& classId ){ this->playableClassId = classId.id(); }; 61 61 62 62 inline int getPlayableUniqueId(){ return playableUniqueId; } -
trunk/src/lib/network/proxy/network_settings.cc
r9656 r9869 21 21 #include "shared_network_data.h" 22 22 23 #include "loading/load_param.h" 23 24 #include "loading/resource_manager.h" 24 #include "loading/load_param.h"25 26 25 #include "debug.h" 27 26 28 27 28 ObjectListDefinition(NetworkSettings); 29 29 30 30 NetworkSettings* NetworkSettings::singletonRef = NULL; … … 36 36 { 37 37 /* set the class id for the base object */ 38 this-> setClassID(CL_NETWORK_SETTINGS, "NetworkSettings");38 this->registerObject(this, NetworkSettings::_objectList); 39 39 40 40 // suggest a good standard max players value … … 64 64 void NetworkSettings::loadData() 65 65 { 66 std::string fileName = Resource Manager::getInstance()->getDataDir();66 std::string fileName = Resources::ResourceManager::getInstance()->mainGlobalPath().name(); 67 67 fileName += "configs/network_settings.conf"; 68 68 -
trunk/src/lib/network/proxy/network_settings.h
r9494 r9869 24 24 class NetworkSettings : public BaseObject 25 25 { 26 26 ObjectListDeclaration(NetworkSettings); 27 27 public: 28 28 inline static NetworkSettings* getInstance() { if (!NetworkSettings::singletonRef) NetworkSettings::singletonRef = new NetworkSettings(); -
trunk/src/lib/network/proxy/proxy_control.cc
r9656 r9869 15 15 #include "proxy_control.h" 16 16 17 #include "class_list.h"18 17 #include "shell_command.h" 19 18 … … 28 27 #include "converter.h" 29 28 30 #include "p references.h"29 #include "parser/preferences/preferences.h" 31 30 32 31 #include "debug.h" … … 41 40 42 41 SHELL_COMMAND(forceReconnect, ProxyControl, forceReconnectionShell); 42 ObjectListDefinition(ProxyControl); 43 43 44 44 /** … … 47 47 ProxyControl::ProxyControl() 48 48 { 49 this-> setClassID( CL_PROXY_CONTROL, "ProxyControl");49 this->registerObject(this, ProxyControl::_objectList); 50 50 51 51 this->setSynchronized(false); -
trunk/src/lib/network/proxy/proxy_control.h
r9656 r9869 30 30 class ProxyControl : public Synchronizeable 31 31 { 32 32 ObjectListDeclaration(ProxyControl); 33 33 public: 34 34 inline static ProxyControl* getInstance() { if (!ProxyControl::singletonRef) ProxyControl::singletonRef = new ProxyControl(); -
trunk/src/lib/network/server_socket.cc
r7954 r9869 23 23 #include "server_socket.h" 24 24 25 /* header for debug output */ 26 #include "debug.h" 27 28 25 ObjectListDefinition(ServerSocket); 29 26 /** 30 27 * constructor -
trunk/src/lib/network/server_socket.h
r9656 r9869 19 19 class ServerSocket : public BaseObject 20 20 { 21 ObjectListDeclaration(ServerSocket); 21 22 public: 22 23 ServerSocket( int port); -
trunk/src/lib/network/shared_network_data.cc
r9494 r9869 25 25 26 26 27 27 ObjectListDefinition(SharedNetworkData); 28 28 SharedNetworkData* SharedNetworkData::singletonRef = NULL; 29 29 … … 34 34 { 35 35 /* set the class id for the base object */ 36 this-> setClassID(CL_SHARED_NETWORK_DATA, "SharedNetworkData");36 this->registerObject(this, SharedNetworkData::_objectList); 37 37 38 38 this->nodeType = NET_MASTER_SERVER; -
trunk/src/lib/network/shared_network_data.h
r9656 r9869 22 22 class SharedNetworkData : public BaseObject 23 23 { 24 24 ObjectListDeclaration(SharedNetworkData); 25 25 public: 26 26 inline static SharedNetworkData* getInstance() { if (!SharedNetworkData::singletonRef) SharedNetworkData::singletonRef = new SharedNetworkData(); -
trunk/src/lib/network/synchronizeable.cc
r9656 r9869 32 32 33 33 34 ObjectListDefinition(Synchronizeable); 34 35 35 36 /** … … 38 39 Synchronizeable::Synchronizeable() 39 40 { 40 this-> setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");41 this->registerObject(this, Synchronizeable::_objectList); 41 42 this->owner = 0; 42 43 // this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0); … … 74 75 // remove the message manager only by the server 75 76 if ( (SharedNetworkData::getInstance()->isMasterServer() ) 76 && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER) )77 && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( MessageManager::staticClassID() ) ) 77 78 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); 78 79 } -
trunk/src/lib/network/synchronizeable.h
r9406 r9869 41 41 class Synchronizeable : virtual public BaseObject 42 42 { 43 ObjectListDeclaration(Synchronizeable); 43 44 44 45 public: -
trunk/src/lib/network/tcp_server_socket.cc
r9494 r9869 26 26 #include "debug.h" 27 27 28 ObjectListDefinition(TcpServerSocket); 28 29 TcpServerSocket::TcpServerSocket( int port ) : ServerSocket( port ) 29 30 { … … 48 49 { 49 50 /* set the class id for the base object */ 50 this-> setClassID(CL_SERVER_SOCKET, "TcpServerSocket");51 this->registerObject(this, TcpServerSocket::_objectList); 51 52 52 53 terminateThread = false; -
trunk/src/lib/network/tcp_server_socket.h
r9406 r9869 19 19 class TcpServerSocket : public ServerSocket 20 20 { 21 ObjectListDeclaration(TcpServerSocket); 21 22 public: 22 23 TcpServerSocket( int port ); -
trunk/src/lib/network/tcp_socket.cc
r7954 r9869 30 30 #include "debug.h" 31 31 32 ObjectListDefinition(TcpSocket); 32 33 /** 33 34 * Default constructor … … 60 61 { 61 62 /* set the class id for the base object */ 62 this-> setClassID(CL_NETWORK_SOCKET, "TcpSocket");63 this->registerObject(this, TcpSocket::_objectList); 63 64 64 65 tcpSocket = NULL; … … 122 123 { 123 124 IPaddress ip; 124 125 bOk = true; 126 125 126 bOk = true; 127 127 128 if ( SDLNet_ResolveHost( &ip, host.c_str(), port ) != 0 ) 128 129 { … … 131 132 return; 132 133 } 133 134 134 135 //check if not already connected or listening 135 136 if (tcpSocket) … … 345 346 } 346 347 #endif 347 348 348 349 PRINTF(0)("QUIT READ THREAD\n"); 349 350 350 351 return 0; 351 352 } … … 425 426 426 427 return 0; 427 428 428 429 } 429 430 -
trunk/src/lib/network/tcp_socket.h
r9406 r9869 40 40 class TcpSocket : public NetworkSocket 41 41 { 42 ObjectListDeclaration(TcpSocket); 42 43 public: 43 44 TcpSocket(); -
trunk/src/lib/network/udp_broadcast.cc
r8623 r9869 26 26 this->port = 0; 27 27 packet = SDLNet_AllocPacket( BROADCAST_PACKET_SIZE ); 28 29 if ( !packet ) 28 29 if ( !packet ) 30 30 { 31 31 printf( "SDLNet_AllocPacket: %s\n", SDLNet_GetError() ); 32 32 assert( packet ); 33 33 } 34 34 35 35 this->socket = NULL; 36 36 } … … 47 47 this->packet = NULL; 48 48 } 49 49 50 50 if ( this->socket ) 51 51 { … … 53 53 this->socket = NULL; 54 54 } 55 55 56 56 } 57 57 58 58 /** 59 59 * listen for incoming broadcast packets 60 * @param port port to listen on 60 * @param port port to listen on 61 61 * @return true on success 62 62 */ … … 74 74 { 75 75 this->port = port; 76 76 77 77 return true; 78 78 } … … 80 80 /** 81 81 * send packet 82 * @param data data to send 82 * @param data data to send 83 83 * @param length length of data 84 84 * @param ip if ip == NULL broadcast is used -
trunk/src/lib/network/udp_broadcast.h
r8623 r9869 15 15 class UdpBroadcast 16 16 { 17 18 17 public: 19 18 UdpBroadcast(); 20 19 virtual ~UdpBroadcast(); 21 20 22 21 bool listen( int port ); 23 22 bool open( int port ); -
trunk/src/lib/network/udp_server_socket.cc
r9494 r9869 18 18 19 19 20 20 ObjectListDefinition(UdpServerSocket); 21 21 /** 22 22 * constructor -
trunk/src/lib/network/udp_server_socket.h
r9494 r9869 50 50 class UdpServerSocket : public ServerSocket 51 51 { 52 ObjectListDeclaration(UdpServerSocket); 52 53 public: 53 54 UdpServerSocket( int port); -
trunk/src/lib/network/udp_socket.cc
r9406 r9869 18 18 #include "debug.h" 19 19 20 ObjectListDefinition(UdpSocket); 20 21 21 22 void UdpSocket::init( ) -
trunk/src/lib/network/udp_socket.h
r9656 r9869 24 24 class UdpSocket : public NetworkSocket 25 25 { 26 ObjectListDeclaration(UdpSocket); 26 27 public: 27 28 UdpSocket(); -
trunk/src/lib/network/zip.cc
r8623 r9869 15 15 16 16 #include "zip.h" 17 18 #include "src/lib/util/loading/resource_manager.h" 17 #include "loading/resource_manager.h" 19 18 #include "debug.h" 20 19 … … 51 50 int Zip::loadDictionary( std::string name ) 52 51 { 53 std::string fileName = Resource Manager::getInstance()->getDataDir();52 std::string fileName = Resources::ResourceManager::getInstance()->mainGlobalPath().name(); 54 53 //PRINTF(0)("datadir: %s\n", fileName.c_str()); 55 54 fileName = fileName + "/dicts/" + name; -
trunk/src/lib/parser/Makefile.am
r7256 r9869 2 2 tinyxml \ 3 3 ini_parser \ 4 preferences\5 cmdline_parser4 cmdline_parser \ 5 preferences 6 6 7 7 -
trunk/src/lib/parser/cmdline_parser/Makefile.am
r7256 r9869 1 2 INCLUDES = -I../../.. 1 3 2 4 noinst_LIBRARIES = libCmdLineParser.a -
trunk/src/lib/parser/cmdline_parser/cmdline_parser.cc
r9406 r9869 16 16 #include "cmdline_parser.h" 17 17 18 #include <cassert> 18 19 #include "src/lib/util/substring.h" 19 20 -
trunk/src/lib/parser/cmdline_parser/cmdline_parser.h
r8316 r9869 11 11 #include <vector> 12 12 13 #include " src/defs/debug.h"14 #include " src/lib/util/multi_type.h"13 #include "lib/util/debug.h" 14 #include "lib/util/multi_type.h" 15 15 16 16 -
trunk/src/lib/parser/ini_parser/Makefile.am
r8330 r9869 1 INCLUDES =-I../../util1 INCLUDES = -I../../.. 2 2 3 3 -
trunk/src/lib/parser/ini_parser/ini_parser.cc
r9406 r9869 29 29 30 30 #ifdef DEBUG_LEVEL 31 #include "../../../ defs/debug.h"31 #include "../../../lib/util/debug.h" 32 32 #else 33 33 #define PRINTF(x) printf … … 165 165 else if( (ptr = strchr( lineBegin, '=')) != NULL) 166 166 { 167 if (currentSection == NULL)167 if (currentSection == this->sections.end()) 168 168 { 169 169 PRINTF(2)("Not in a Section yet for %s\n", lineBegin); … … 470 470 { 471 471 std::list<IniEntry>::const_iterator entry = this->getEntryIT(entryName, sectionName); 472 if ( entry != NULL &&(*entry).name == entryName)472 if (/** FIXME entry != NULL && */ (*entry).name == entryName) 473 473 return (*entry).value; 474 474 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str()); … … 627 627 if ((*entry).name == entryName) 628 628 break; 629 if (entry == (*section).entries.end()) 630 return NULL; 631 else 632 return entry; 629 return entry; 633 630 } 634 631 … … 650 647 if ((*entry).name == entryName) 651 648 break; 652 if (entry == (*section).entries.end()) 653 return NULL; 654 else 655 return entry; 649 return entry; 656 650 } 657 651 -
trunk/src/lib/parser/ini_parser/ini_parser.h
r8330 r9869 11 11 #define PARSELINELENGHT 512 //!< how many chars to read at once 12 12 13 #include " filesys/file.h"13 #include "lib/util/filesys/file.h" 14 14 #include <list> 15 15 … … 66 66 bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" ); 67 67 const std::string& getVar(const std::string& entryName, const std::string& sectionName, const std::string& defaultValue = "") const; 68 bool IniParser::editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "", bool createMissing = true);68 bool editVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "", bool createMissing = true); 69 69 void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName); 70 70 const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const; -
trunk/src/lib/parser/preferences/Makefile.am
r7256 r9869 6 6 libPrefsParser_a_SOURCES = \ 7 7 cmd_line_prefs_reader.cc \ 8 ini_file_prefs_reader.cc 8 ini_file_prefs_reader.cc \ 9 preferences.cc 9 10 10 11 11 12 noinst_HEADERS = \ 12 13 cmd_line_prefs_reader.h \ 13 ini_file_prefs_reader.h 14 ini_file_prefs_reader.h \ 15 preferences.h -
trunk/src/lib/parser/preferences/cmd_line_prefs_reader.h
r7256 r9869 7 7 #define _CMD_LINE_PREFS_READER_H 8 8 9 #include "stdincl.h"10 9 #include "debug.h" 11 10 … … 45 44 }; 46 45 47 #define REGISTER_ARG_FLAG(shortOption,longOption,section,key,description,value) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,"",value) 46 #define REGISTER_ARG_FLAG(shortOption,longOption,section,key,description,value) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,"",value) 48 47 49 #define REGISTER_ARG_ARG(shortOption,longOption,section,key,description,argname) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,argname) 48 #define REGISTER_ARG_ARG(shortOption,longOption,section,key,description,argname) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,argname) 50 49 51 50 //! A class for reading commandline arguments into Preferences 52 class CmdLinePrefsReader 51 class CmdLinePrefsReader 53 52 { 54 53 … … 58 57 59 58 bool parse(int argc, char** argv); 60 59 61 60 static bool registerArgument( const char shortOption, const std::string & longOption, const std::string & section, const std::string & key, const std::string & help, const std::string & argName = "", const std::string & value = "%arg%" ); 62 61 63 62 static bool asdf; 64 63 65 64 private: 66 65 static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<MultiType> & argArgs ); 67 66 68 67 static RegistredArgs regArgs; 69 68 -
trunk/src/lib/parser/preferences/ini_file_prefs_reader.h
r7256 r9869 7 7 #define _INI_FILE_PREFS_READER_H 8 8 9 #include " src/lib/parser/ini_parser/ini_parser.h"10 #include " src/lib/util/preferences.h"9 #include "lib/parser/ini_parser/ini_parser.h" 10 #include "lib/parser/preferences/preferences.h" 11 11 12 12 -
trunk/src/lib/physics/fields/field.cc
r9406 r9869 23 23 #include "util/loading/load_param.h" 24 24 25 ObjectListDefinition(Field); 25 26 26 27 /** 27 * standard constructor28 * @brief standard constructor 28 29 */ 29 30 Field::Field () … … 33 34 34 35 /** 35 * standard deconstructor 36 37 */ 36 * @brief standard deconstructor 37 */ 38 38 Field::~Field () 39 39 { … … 42 42 43 43 /** 44 \brief initializes a Field45 */44 * @brief initializes a Field 45 */ 46 46 void Field::init() 47 47 { 48 this-> setClassID(CL_FIELD, "Field");48 this->registerObject(this, Field::_objectList); 49 49 this->setMagnitude(1); 50 50 this->setAttenuation(0); … … 54 54 55 55 /** 56 * @param root The XML-element to load settings from56 * @param root The XML-element to load settings from 57 57 */ 58 58 void Field::loadParams(const TiXmlElement* root) -
trunk/src/lib/physics/fields/field.h
r6512 r9869 16 16 /*! 17 17 * @file field.h 18 *abstract definition of a Physical Field19 20 21 22 */18 * abstract definition of a Physical Field 19 * 20 * This is a totally abstract class, that only enables different Physical Fields to 21 * exist on a common Level. 22 */ 23 23 24 24 #ifndef _FIELD_H … … 34 34 class Field : public PNode 35 35 { 36 ObjectListDeclaration(Field); 36 37 public: 37 38 Field(); -
trunk/src/lib/physics/fields/gravity.cc
r9406 r9869 21 21 #include "util/loading/factory.h" 22 22 23 #include "class_id_DEPRECATED.h" 24 ObjectListDefinitionID(Gravity, CL_FIELD_GRAVITY); 23 25 24 25 CREATE_FACTORY(Gravity, CL_FIELD_GRAVITY); 26 CREATE_FACTORY(Gravity); 26 27 27 28 Gravity::Gravity(const TiXmlElement* root) 28 29 { 29 this-> setClassID(CL_FIELD_GRAVITY, "Gravity");30 this->registerObject(this, Gravity::_objectList); 30 31 31 32 if (root != NULL) -
trunk/src/lib/physics/fields/gravity.h
r6512 r9869 16 16 //! A class for ... 17 17 class Gravity : public Field { 18 ObjectListDeclaration(Gravity); 18 19 19 20 public: -
trunk/src/lib/physics/fields/point_gravity.cc
r9406 r9869 20 20 21 21 22 #include "class_id_DEPRECATED.h" 23 ObjectListDefinitionID(PointGravity, CL_FIELD_POINT_GRAVITY); 24 22 25 23 26 /** … … 27 30 PointGravity::PointGravity () 28 31 { 29 this->setClassID(CL_FIELD_POINT_GRAVITY, "PointGravity");32 this->registerObject(this, PointGravity::_objectList); 30 33 } 31 34 -
trunk/src/lib/physics/fields/point_gravity.h
r5405 r9869 1 /*! 1 /*! 2 2 * @file point_gravity.h 3 3 * Definition of ... … … 16 16 //! A class for ... 17 17 class PointGravity : public Field { 18 ObjectListDeclaration(PointGravity); 18 19 19 20 public: -
trunk/src/lib/physics/fields/twirl.cc
r9406 r9869 20 20 21 21 22 #include "class_id_DEPRECATED.h" 23 ObjectListDefinitionID(Twirl, CL_FIELD_TWIRL); 24 22 25 23 26 /** … … 27 30 Twirl::Twirl () 28 31 { 29 this->setClassID(CL_FIELD_TWIRL, "Twirl");32 this->registerObject(this, Twirl::_objectList); 30 33 } 31 34 -
trunk/src/lib/physics/fields/twirl.h
r5405 r9869 1 /*! 1 /*! 2 2 * @file twirl.h 3 3 * Definition of ... … … 16 16 //! A class for ... 17 17 class Twirl : public Field { 18 ObjectListDeclaration(Twirl); 18 19 19 20 public: -
trunk/src/lib/physics/physics_connection.cc
r9406 r9869 19 19 20 20 #include "physics_engine.h" 21 #include "debug.h" 21 22 22 #include "field .h"23 #include "particle _system.h"23 #include "fields/field.h" 24 #include "particles/particle_system.h" 24 25 #include "physics_interface.h" 25 26 … … 27 28 #include "util/loading/load_param.h" 28 29 29 30 31 CREATE_FACTORY(PhysicsConnection, CL_PHYSICS_CONNECTION); 32 30 #include "class_id_DEPRECATED.h" 31 ObjectListDefinition(PhysicsConnection); 32 CREATE_FACTORY(PhysicsConnection); 33 33 /** 34 34 * creates a PhysicsConnection … … 36 36 PhysicsConnection::PhysicsConnection(PhysicsInterface* subject, Field* field) 37 37 { 38 this-> setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");38 this->registerObject(this, PhysicsConnection::_objectList); 39 39 this->type = PCON_PhysIField; 40 40 … … 47 47 PhysicsConnection::PhysicsConnection(const TiXmlElement* root) 48 48 { 49 this-> setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");49 this->registerObject(this, PhysicsConnection::_objectList); 50 50 this->type = PCON_PhysIField; 51 51 -
trunk/src/lib/physics/physics_connection.h
r7221 r9869 27 27 class PhysicsConnection : public BaseObject 28 28 { 29 29 ObjectListDeclaration(PhysicsConnection); 30 30 public: 31 31 PhysicsConnection(PhysicsInterface* subject, Field* field); -
trunk/src/lib/physics/physics_engine.cc
r9406 r9869 18 18 #include "physics_engine.h" 19 19 20 #include "class_list.h"21 #include "parser/tinyxml/tinyxml.h"22 20 #include "util/loading/factory.h" 23 #include "util/loading/load_param .h"24 25 26 27 28 /** 29 * standard constructor30 */21 #include "util/loading/load_param_xml.h" 22 23 24 25 ObjectListDefinition(PhysicsEngine); 26 /** 27 * @brief standard constructor 28 */ 31 29 PhysicsEngine::PhysicsEngine() 32 30 { 33 this-> setClassID(CL_PHYSICS_ENGINE, "PhysicsEngine");31 this->registerObject(this, PhysicsEngine::_objectList); 34 32 this->setName("PhysicsEngine"); 35 33 this->interfaces = NULL; … … 130 128 PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const std::string& physicsInterfaceName) const 131 129 { 132 BaseObject* interface = ClassList::getObject(physicsInterfaceName, CL_PHYSICS_INTERFACE); 133 return (interface != NULL)? dynamic_cast<PhysicsInterface*>(interface) : NULL; 130 return PhysicsInterface::objectList().getObject(physicsInterfaceName); 134 131 } 135 132 … … 223 220 224 221 /* actually tick all the PhysicsInterfaces. Move the objects around */ 225 if (this->interfaces != NULL || (this->interfaces = ClassList::getList(CL_PHYSICS_INTERFACE)) != NULL) 226 {227 std::list<BaseObject*>::const_iterator tickPhys;228 for (tickPhys = this->interfaces->begin(); tickPhys != this->interfaces->end(); tickPhys++)229 dynamic_cast<PhysicsInterface*>(*tickPhys)->tickPhys(dt);230 }222 223 ObjectList<PhysicsInterface>::const_iterator it; 224 for (it = PhysicsInterface::objectList().begin(); 225 it != PhysicsInterface::objectList().end(); 226 ++it) 227 (*it)->tickPhys(dt); 231 228 } 232 229 -
trunk/src/lib/physics/physics_engine.h
r7221 r9869 12 12 #include "physics_connection.h" 13 13 #include "physics_interface.h" 14 #include "field .h"14 #include "fields/field.h" 15 15 #include <list> 16 16 … … 20 20 21 21 //! A class, that brings things into motion through Physics. 22 class PhysicsEngine : public BaseObject { 23 24 public: 22 class PhysicsEngine : public BaseObject 23 { 24 ObjectListDeclaration(PhysicsEngine); 25 public: 25 26 virtual ~PhysicsEngine(); 26 27 /** @returns a Pointer to the only object of this Class */ … … 46 47 void debug() const; 47 48 48 49 private: 49 50 PhysicsEngine(); 50 51 51 52 private: 52 53 static PhysicsEngine* singletonRef; //!< the singleton reference of the PhysicsEngine 53 54 -
trunk/src/lib/physics/physics_interface.cc
r9406 r9869 23 23 #include "physics_engine.h" 24 24 25 #include "field .h"25 #include "fields/field.h" 26 26 #include "p_node.h" 27 27 … … 31 31 32 32 33 33 ObjectListDefinition(PhysicsInterface); 34 34 /** 35 * standard constructor35 * @brief standard constructor 36 36 */ 37 37 PhysicsInterface::PhysicsInterface () 38 38 { 39 this-> setClassID(CL_PHYSICS_INTERFACE, "PhysicsInterface");39 this->registerObject(this, PhysicsInterface::_objectList); 40 40 41 41 this->mass = 1; -
trunk/src/lib/physics/physics_interface.h
r8190 r9869 29 29 class PhysicsInterface : virtual public BaseObject 30 30 { 31 ObjectListDeclaration(PhysicsInterface); 31 32 public: 32 33 PhysicsInterface(); -
trunk/src/lib/script_engine/Makefile.am
r8711 r9869 16 16 script_manager.cc \ 17 17 script_class.cc \ 18 script_method.cc 19 18 script_method.cc \ 19 executor_lua_state.cc 20 20 21 AM_CPPFLAGS= @LUA_INCLUDES@ 21 22 … … 25 26 script_manager.h \ 26 27 script_class.h \ 27 script_method.h 28 script_method.h \ 29 executor_lua_state.h 28 30 29 31 -
trunk/src/lib/script_engine/lunar.h
r8408 r9869 16 16 userdataType; 17 17 public: 18 typedef Executor * mfp;18 typedef Executor<lua_State*>* mfp; 19 19 typedef struct { const char *name; mfp mfunc; } 20 20 RegType; … … 184 184 lua_remove(L, 1); // remove self so member function args start at index 1 185 185 // get member function from upvalue 186 Executor *l = static_cast<Executor*>(lua_touserdata(L, lua_upvalueindex(1))); 187 int value; 188 (*l)(obj, value, L); // call member function 189 return value; 186 mfp l = static_cast<mfp>(lua_touserdata(L, lua_upvalueindex(1))); 187 (*l)(obj, L); // call member function 188 return l->hasRetVal()? 1 : 0; 190 189 } 191 190 -
trunk/src/lib/script_engine/script.cc
r9298 r9869 18 18 #include "luaincl.h" 19 19 #include "debug.h" 20 #include "util/loading/resource_manager.h" 21 20 21 #include "loading/resource_manager.h" 22 22 #include "loading/load_param.h" 23 23 #include "parser/tinyxml/tinyxml.h" 24 24 25 #include "class_list.h" 26 CREATE_SCRIPTABLE_CLASS(Script, CL_SCRIPT, 27 addMethod("addObject", ExecutorLua2<Script,const std::string&, const std::string& >(&Script::addObject)) 28 ->addMethod("registerClass", ExecutorLua1<Script,const std::string&>(&Script::registerClass)) 29 ->addMethod("selectFunction", ExecutorLua2ret<Script, bool, const std::string&, int >(&Script::selectFunction)) 30 ->addMethod("executeFunction", ExecutorLua0ret<Script,bool >(&Script::executeFunction)) 25 ObjectListDefinition(Script); 26 27 CREATE_SCRIPTABLE_CLASS(Script, 28 addMethod("addObject", Executor2<Script, lua_State*,const std::string&, const std::string& >(&Script::addObject)) 29 ->addMethod("registerClass", Executor1<Script, lua_State*,const std::string&>(&Script::registerClass)) 30 ->addMethod("selectFunction", Executor2ret<Script, lua_State*, bool, const std::string&, int >(&Script::selectFunction)) 31 ->addMethod("executeFunction", Executor0ret<Script, lua_State*,bool >(&Script::executeFunction)) 31 32 ); 33 32 34 33 35 Script::Script(const TiXmlElement* root) 34 36 { 35 this-> setClassID(CL_SCRIPT, "Script");37 this->registerObject(this, Script::_objectList); 36 38 37 39 returnCount = argumentCount = 0; … … 52 54 Script::Script(const std::string& filename) 53 55 { 54 this-> setClassID(CL_SCRIPT, "Script");56 this->registerObject(this, Script::_objectList); 55 57 56 58 returnCount = argumentCount = 0; … … 64 66 luaopen_math(luaState); 65 67 luaopen_debug(luaState); 66 68 67 69 this->loadFile(filename); 68 70 … … 98 100 bool Script::loadFile(const std::string& filename) 99 101 { 100 std::string filedest(Resource Manager::getInstance()->getDataDir());101 filedest += " scripts/" + filename;102 102 std::string filedest(Resources::ResourceManager::getInstance()->mainGlobalPath().name()); 103 filedest += "/scripts/" + filename; 104 103 105 this->addThisScript(); 104 106 this->registerStandartClasses(); 105 107 106 108 if(currentFile.length() != 0) 107 109 { … … 142 144 //printf(("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str()); 143 145 144 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);146 ScriptClass* scriptClass = ScriptClass::objectList().getObject(className); 145 147 // printf(("The script class for %s is at %p \n",className.c_str(),scriptClass); 146 148 WorldObject tmpObj; … … 150 152 if( !classIsRegistered(className) ) 151 153 { 152 static_cast<ScriptClass*>(scriptClass)->registerClass(this);153 } 154 155 BaseObject* object = ClassList::getObject(objectName, className);154 scriptClass->registerClass(this); 155 } 156 157 BaseObject* object = ObjectListBase::getBaseObject(className, objectName); 156 158 // printf(("%s is at %p \n",objectName.c_str(),object); 157 159 if (object != NULL && !objectIsAdded(objectName)) 158 160 { 159 s tatic_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);161 scriptClass->insertObject(this, object, false); 160 162 tmpObj.name = objectName; 161 163 registeredObjects.push_back(tmpObj); … … 169 171 bool Script::executeFile() 170 172 { 171 PRINT (2)("WARNING:script.executeFile is not implemented yet\n");173 PRINTF(2)("script.executeFile is not implemented yet\n"); 172 174 /*if(currentFile.length() != 0) 173 175 { … … 214 216 if(error != 0) 215 217 { 216 printf("SCRIPT %s : ERROR: Failed to execute function %s: \n",currentFile.c_str(),currentFunction.c_str());218 PRINTF(1)("Script '%s' : Failed to execute function '%s': \n",currentFile.c_str(),currentFunction.c_str()); 217 219 reportError(error); 218 220 //clean up … … 229 231 } 230 232 else 231 printf("SCRIPT %s : ERROR: no function selected.\n",currentFile.c_str());233 PRINTF(1)("SCRIPT '%s' : no function selected.\n",currentFile.c_str()); 232 234 233 235 return false; … … 295 297 lua_remove(luaState,-1*returnCount); 296 298 returnCount--; 297 299 298 300 } 299 301 } … … 352 354 void Script::addThisScript() 353 355 { 354 BaseObject* scriptClass = ClassList::getObject("Script", CL_SCRIPT_CLASS); 355 if (scriptClass != NULL) 356 { 357 static_cast<ScriptClass*>(scriptClass)->registerClass(this); 358 static_cast<ScriptClass*>(scriptClass)->insertObject(this, this,"thisscript", false); 356 ScriptClass* scriptClass = ScriptClass::objectList().getObject("Script"); 357 358 if (scriptClass != NULL) 359 { 360 scriptClass->registerClass(this); 361 scriptClass->insertObject(this, this,"thisscript", false); 359 362 } 360 363 } … … 375 378 { 376 379 bool success = false; 377 380 378 381 //this->registerClass(std::string("Vector")); 379 382 this->registerClass("ScriptTrigger"); … … 382 385 return success; 383 386 } 384 385 387 388 386 389 void Script::registerClass( const std::string& className) 387 390 { 388 BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);391 ScriptClass* scriptClass = ScriptClass::objectList().getObject(className); 389 392 //printf(("The script class for %s is at %p \n",className.c_str(),scriptClass); 393 390 394 WorldObject tmpObj; 391 395 if (scriptClass != NULL) … … 400 404 } 401 405 } 402 406 403 407 } 404 408 -
trunk/src/lib/script_engine/script.h
r9298 r9869 22 22 class Script : public BaseObject 23 23 { 24 ObjectListDeclaration(Script); 24 25 public: 25 26 Script(const TiXmlElement* root = NULL); … … 33 34 bool loadFile(const std::string& filename); 34 35 void addObject( const std::string& className,const std::string& objectName); 35 void registerClass(const std::string& className); //!< Register a class but dont add any instances 36 void registerClass(const std::string& className); //!< Register a class but dont add any instances 36 37 37 38 /// QUERRYING -
trunk/src/lib/script_engine/script_class.cc
r8711 r9869 19 19 #include <cassert> 20 20 21 ObjectListDefinition(ScriptClass); 21 22 /** 22 23 * @brief standard constructor 23 24 * @todo this constructor is not jet implemented - do it 24 25 */ 25 ScriptClass::ScriptClass(const std::string& name, ClassIDclassID, ScriptMethod* scriptMethods)26 : BaseObject(name) 26 ScriptClass::ScriptClass(const std::string& name, const ClassID& classID, ScriptMethod* scriptMethods) 27 : BaseObject(name), _classID(classID) 27 28 { 28 29 assert(scriptMethods != NULL); 29 this-> setClassID(CL_SCRIPT_CLASS, "ScriptClass");30 this->registerObject(this, ScriptClass::_objectList); 30 31 31 32 this->_classID = classID; -
trunk/src/lib/script_engine/script_class.h
r9003 r9869 18 18 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 19 19 */ 20 #define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, CLASS_ID,SCRIPT_METHODS) \21 tScriptClass<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_ ID, (new ScriptMethod)->SCRIPT_METHODS)20 #define CREATE_SCRIPTABLE_CLASS(CLASS_NAME, SCRIPT_METHODS) \ 21 tScriptClass<CLASS_NAME> global_##CLASS_NAME##_ScriptableClass(#CLASS_NAME, CLASS_NAME::staticClassID(), (new ScriptMethod)->SCRIPT_METHODS) 22 22 23 23 24 24 //! A class for ... 25 class ScriptClass : p rotectedBaseObject25 class ScriptClass : public BaseObject 26 26 { 27 ObjectListDeclaration(ScriptClass); 27 28 28 29 public: 29 30 virtual ~ScriptClass(); 30 31 31 bool operator==(const std::string& name) { return (this->getName() == name); }32 bool operator==(ClassID classID) { return (this->_classID == classID); }33 34 32 virtual void registerClass(Script* script) = 0; 35 33 virtual int insertObject(Script* L, BaseObject* obj, bool gc=false) = 0; 36 virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0; 34 virtual int insertObject(Script* L, BaseObject* obj, const std::string& name, bool gc=false) = 0; 37 35 38 36 const ScriptMethod* scriptMethods() const { return this->_scriptMethods; } 39 37 40 38 protected: 41 ScriptClass(const std::string& name, ClassIDclassID, ScriptMethod* scriptMethods);39 ScriptClass(const std::string& name, const ClassID& classID, ScriptMethod* scriptMethods); 42 40 43 41 private: -
trunk/src/lib/script_engine/script_manager.cc
r9003 r9869 24 24 #include "lunar.h" 25 25 26 #include "class_list.h"27 28 26 #include "script.h" 29 27 #include "script_trigger.h" 30 28 #include "luaincl.h" 31 #include "loading/load_param.h" 32 #include "parser/tinyxml/tinyxml.h" 29 #include "loading/load_param_xml.h" 33 30 34 31 … … 37 34 { 38 35 this->setName("ScriptManager"); 39 this->scripts = NULL;40 this->triggers = NULL;41 36 42 37 if (root != NULL) … … 62 57 63 58 // fill the scripts and triggers (doing that on runtime is very slow!) 64 getTriggers();65 getScripts();66 59 } 67 60 … … 71 64 { 72 65 //Delete all scripts as they aren't deleted automatically 73 if(this->getScripts()) 74 while(!scripts->empty()) 75 delete scripts->front(); 66 while(!Script::objectList().empty()) 67 delete Script::objectList().front(); 76 68 //Delete all triggers 77 if(this->getTriggers()) 78 while(!triggers->empty()) 79 delete triggers->front(); 80 69 while(!ScriptTrigger::objectList().empty()) 70 delete ScriptTrigger::objectList().front(); 71 81 72 } 82 73 … … 105 96 Script* ScriptManager::getScriptByFile(const std::string& file) 106 97 { 107 if(getScripts()) 108 for(std::list<BaseObject*>::const_iterator it = scripts->begin(); it != scripts->end(); it++ ) 109 { 110 if( (dynamic_cast<Script*>(*it))->getFileName().compare(file) == 0) 111 { 112 return dynamic_cast<Script*>(*it); 113 } 114 } 98 for (ObjectList<Script>::const_iterator it = Script::objectList().begin(); 99 it != Script::objectList().end(); 100 ++it) 101 if( ((*it))->getFileName().compare(file) == 0) 102 return (*it); 115 103 116 104 return NULL; 117 105 118 106 } 119 120 121 bool ScriptManager::getScripts()122 {123 return (this->scripts != NULL || (this->scripts = ClassList::getList(CL_SCRIPT)) != NULL);124 }125 126 bool ScriptManager::getTriggers()127 {128 return (this->triggers != NULL || (this->triggers = ClassList::getList(CL_SCRIPT_TRIGGER)) != NULL);129 }130 131 132 -
trunk/src/lib/script_engine/script_manager.h
r8894 r9869 34 34 void createTriggers(const TiXmlElement* triggers); 35 35 36 bool getTriggers();37 bool getScripts();38 39 36 static ScriptManager* singletonRef; //!< Reference to this class 40 41 const std::list<BaseObject*>* triggers; //!< A list of all the triggers in the world42 43 const std::list<BaseObject*>* scripts; //!< A list of all the scripts in the world44 45 46 37 }; 47 38 #endif -
trunk/src/lib/script_engine/script_method.cc
r8711 r9869 25 25 { } 26 26 27 ScriptMethod* ScriptMethod::addMethod(const std::string& methodName, const Executor & executor)27 ScriptMethod* ScriptMethod::addMethod(const std::string& methodName, const Executor<lua_State*>& executor) 28 28 { 29 29 this->methods.push_back(ScriptMethod::Method(methodName, executor)); … … 32 32 } 33 33 34 ScriptMethod::Method::Method(const std::string& name, const Executor & executor)34 ScriptMethod::Method::Method(const std::string& name, const Executor<lua_State*>& executor) 35 35 { 36 36 this->name = name; -
trunk/src/lib/script_engine/script_method.h
r8711 r9869 9 9 #include <vector> 10 10 11 #include "executor /executor_lua.h"12 11 #include "executor_lua_state.h" 12 #include "executor/executor_member.h" 13 13 14 14 class ScriptMethod … … 18 18 ~ScriptMethod(); 19 19 20 ScriptMethod* addMethod(const std::string& methodName, const Executor & executor);20 ScriptMethod* addMethod(const std::string& methodName, const Executor<lua_State*>& executor); 21 21 22 22 unsigned int size() const { return methods.size(); }; 23 23 24 24 const std::string& name(unsigned int methodNumber) const { return methods[methodNumber].name; }; 25 const Executor * executor(unsigned int methodNumber) const { return methods[methodNumber].executor; };25 const Executor<lua_State*>* executor(unsigned int methodNumber) const { return methods[methodNumber].executor; }; 26 26 27 27 … … 29 29 struct Method 30 30 { 31 Method(const std::string& name, const Executor & executor);32 std::string name;33 Executor *executor;31 Method(const std::string& name, const Executor<lua_State*>& executor); 32 std::string name; 33 Executor<lua_State*>* executor; 34 34 }; 35 35 -
trunk/src/lib/shell/Makefile.am
r7428 r9869 6 6 libORXshell_a_SOURCES = \ 7 7 shell.cc \ 8 shell_buffer.cc \9 8 shell_input.cc \ 10 9 shell_command.cc \ … … 16 15 noinst_HEADERS= \ 17 16 shell.h \ 18 shell_buffer.h \19 17 shell_input.h \ 18 shell_command_class.h \ 20 19 shell_command.h \ 21 shell_command_class.h \22 20 shell_completion.h \ 23 21 shell_completion_plugin.h -
trunk/src/lib/shell/shell.cc
r8362 r9869 18 18 #include "shell.h" 19 19 #include "shell_command.h" 20 #include " shell_buffer.h"20 #include "debug_buffer.h" 21 21 #include "shell_input.h" 22 22 … … 54 54 ->completionPlugin(0, OrxShell::CompletorFileSystem(".ttf", "fonts/")); 55 55 56 ObjectListDefinition(Shell); 56 57 57 58 /** … … 60 61 Shell::Shell () 61 62 { 62 this->setClassID(CL_SHELL, "Shell"); 63 this->registerObject(this, Shell::_objectList); 64 63 65 this->setName("Shell"); 64 66 65 this->shellBuffer = ShellBuffer::getInstance();67 this->shellBuffer = DebugBuffer::getInstance(); 66 68 67 69 // EVENT-Handler subscription of '`' to all States. … … 246 248 this->setSizeX2D(width); 247 249 for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt) 248 {249 250 (*textIt)->setLineWidth(width); 250 }251 251 } 252 252 … … 444 444 { 445 445 this->flush(); 446 ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);446 DebugBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL); 447 447 } 448 448 … … 470 470 this->moveDisplayBuffer(-this->bufferDisplaySize+1); 471 471 } 472 else if (event.type == EV_VIDEO_RESIZE)473 {474 this->updateResolution(event.resize.w);475 this->repositionText();476 }472 } 473 else if (event.type == EV_VIDEO_RESIZE) 474 { 475 this->updateResolution(event.resize.w); 476 this->repositionText(); 477 477 } 478 478 } -
trunk/src/lib/shell/shell.h
r7762 r9869 14 14 15 15 #include "shell_input.h" 16 #include " shell_buffer.h"16 #include "debug_buffer.h" 17 17 #include "material.h" 18 18 … … 48 48 class Shell : public Element2D, public EventListener 49 49 { 50 50 ObjectListDeclaration(Shell); 51 51 public: 52 52 Shell(); … … 93 93 private: 94 94 // GENERAL 95 ShellBuffer* shellBuffer; //!< The local ShellBuffer.95 DebugBuffer* shellBuffer; //!< The local ShellBuffer. 96 96 97 97 bool bActive; //!< If the shell is active. -
trunk/src/lib/shell/shell_command.cc
r9406 r9869 20 20 21 21 #include "compiler.h" 22 #include "helper_functions.h" 22 23 #include "debug.h" 23 #include "class_list.h"24 24 25 25 #include "key_names.h" … … 27 27 namespace OrxShell 28 28 { 29 ObjectListDefinition(ShellCommand); 29 30 SHELL_COMMAND(debug, ShellCommandClass, help); 30 31 … … 36 37 * @param paramCount the count of parameters this command takes 37 38 */ 38 ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor * executor)39 { 40 this-> setClassID(CL_SHELL_COMMAND, "ShellCommand");39 ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor) 40 { 41 this->registerObject(this, ShellCommand::_objectList); 41 42 PRINTF(4)("create shellcommand '%s' for class '%s'\n", commandName.c_str(), className.c_str()); 42 43 this->setName(commandName); … … 44 45 // copy the executor: 45 46 this->executor = executor; 46 this->executor->setName(commandName);47 47 48 48 for (unsigned int i = 0; i < this->executor->getParamCount(); i++) … … 75 75 * @brief registers a new ShellCommand 76 76 */ 77 ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor * executor)77 ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor) 78 78 { 79 79 if (ShellCommand::exists(commandName, className)) … … 94 94 void ShellCommand::unregisterCommand(const std::string& commandName, const std::string& className) 95 95 { 96 97 96 ShellCommandClass* cmdClass = ShellCommandClass::acquireCommandClass(className); 98 97 if (cmdClass != NULL) 99 98 { 100 99 CmdList::iterator cmd; 101 for (cmd = cmdClass-> commandList.begin(); cmd != cmdClass->commandList.end(); cmd++)100 for (cmd = cmdClass->_commandList.begin(); cmd != cmdClass->_commandList.end(); cmd++) 102 101 if (commandName == (*cmd)->getName()) 103 102 { … … 119 118 120 119 CmdList::const_iterator elem; 121 for (unsigned int i = 0; i < cmdClass-> commandList.size(); i++)122 { 123 if (commandName == cmdClass-> commandList[i]->getName())124 return (cmdClass-> commandList[i]);120 for (unsigned int i = 0; i < cmdClass->_commandList.size(); i++) 121 { 122 if (commandName == cmdClass->_commandList[i]->getName()) 123 return (cmdClass->_commandList[i]); 125 124 } 126 125 return NULL; … … 242 241 return false; 243 242 244 const std::list<BaseObject*>* objectList = ClassList::getList(cmd->shellClass->getName());243 const ObjectListBase* const objectList = ObjectListBase::getObjectList(cmd->shellClass->getName()); 245 244 if (objectList != NULL) 246 245 { 247 std::list<BaseObject*>::const_iterator bo; 246 ObjectListBase::base_list list; 247 objectList->getBaseObjectList(&list); 248 ObjectListBase::base_iterator it; 248 249 249 250 // No Description given (only for speedup) 250 251 if (objectDescriptor.empty()) 251 252 { 252 for ( bo = objectList->begin(); bo != objectList->end(); bo++)253 boList->push_back(* bo);253 for (it = list.begin(); it != list.end(); it++) 254 boList->push_back(*it); 254 255 } 255 256 // some description 256 257 else 257 258 { 258 for ( bo = objectList->begin(); bo != objectList->end(); bo++)259 if (!nocaseCmp(objectDescriptor, (* bo)->getName(), objectDescriptor.size()))260 boList->push_back(* bo);259 for (it = list.begin(); it != list.end(); it++) 260 if (!nocaseCmp(objectDescriptor, (*it)->getName(), objectDescriptor.size())) 261 boList->push_back(*it); 261 262 } 262 263 } … … 299 300 if (sc != NULL) 300 301 { 301 for(std::vector<BaseObject*>::const_iterator bo = boList.begin(); bo != boList.end(); ++bo) 302 { 303 PRINT(0)("Command '%s' on '%s::%s'\n", sc->getCName(), (*bo)->getClassCName(), (*bo)->getCName()); 304 (*sc->executor)((*bo), inputSplits.subSet(paramBegin)); 305 } 302 303 if(sc->executor->getType() == Executor<const SubString>::FunctionStatic ) 304 { 305 PRINT(0)("Static Command '%s' of Class '%s' with parameters\n", sc->getCName(), sc->shellClass->getCName()); 306 (*sc->executor)(NULL, inputSplits.subSet(paramBegin)); 307 } 308 else 309 for(std::vector<BaseObject*>::const_iterator bo = boList.begin(); bo != boList.end(); ++bo) 310 { 311 PRINT(0)("Command '%s' on '%s::%s'\n", sc->getCName(), (*bo)->getClassCName(), (*bo)->getCName()); 312 (*sc->executor)((*bo), inputSplits.subSet(paramBegin)); 313 } 306 314 return true; 307 315 } … … 376 384 else 377 385 { 378 // if(this->completors[parameter] == NULL)379 // delete this->completors[parameter];380 // this->completors[parameter] = completorPlugin.clone();386 // if(this->completors[parameter] == NULL) 387 // delete this->completors[parameter]; 388 // this->completors[parameter] = completorPlugin.clone(); 381 389 } 382 390 return this; -
trunk/src/lib/shell/shell_command.h
r8145 r9869 9 9 #include "base_object.h" 10 10 11 #include "executor/executor.h" 11 /// THIS IS USED TO LOAD CONSTANT AND STATIC FUNCTIONS EASILY. 12 #include "executor/executor_substring.h" 13 #include "executor/functor_member.h" 14 #include "executor/functor_const_member.h" 15 #include "executor/functor_static.h" 16 12 17 #include "shell_completion_plugin.h" 13 18 … … 35 40 */ 36 41 #define SHELL_COMMAND(command, class, function) \ 37 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class >(&class::function))42 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(&class::function)) 38 43 39 44 /** … … 51 56 */ 52 57 #define SHELL_COMMAND_STATIC(command, class, function) \ 53 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class >(function))58 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(function)) 54 59 55 60 … … 58 63 class ShellCommand : public BaseObject 59 64 { 65 ObjectListDeclaration(ShellCommand); 66 60 67 friend class ShellCommandClass; 61 68 public: … … 69 76 ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin); 70 77 71 static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor * executor);78 static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor); 72 79 static void unregisterCommand(const std::string& commandName, const std::string& className); 73 80 static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className); … … 85 92 86 93 protected: 87 ShellCommand(const std::string& commandName, const std::string& className, Executor * executor);94 ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor); 88 95 virtual ~ShellCommand(); 89 96 … … 97 104 std::string description; //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla"); 98 105 std::vector<CompletorPlugin*> completors; //!< Completors for the Parameters 99 Executor *executor; //!< The Executor, that really executes the Function.106 Executor<const SubString>* executor; //!< The Executor, that really executes the Function. 100 107 }; 101 108 -
trunk/src/lib/shell/shell_command_class.cc
r9406 r9869 21 21 22 22 #include "debug.h" 23 #include "class_list.h"24 23 #include "compiler.h" 25 24 … … 28 27 namespace OrxShell 29 28 { 30 CmdClassList* ShellCommandClass::commandClassList = NULL; 29 ObjectListDefinition(ShellCommandClass); 30 31 CmdClassList* ShellCommandClass::_commandClassList = NULL; 31 32 32 33 /** … … 35 36 */ 36 37 ShellCommandClass::ShellCommandClass(const std::string& className) 37 : className(className)38 { 39 this-> setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");38 : _className(className) 39 { 40 this->registerObject(this, ShellCommandClass::_objectList); 40 41 this->setName(className); 41 42 42 this->classID = CL_NULL; 43 44 if (ShellCommandClass::commandClassList == NULL) 45 ShellCommandClass::commandClassList = new CmdClassList; 46 ShellCommandClass::commandClassList->push_back(this); 43 if (ShellCommandClass::_commandClassList == NULL) 44 ShellCommandClass::_commandClassList = new CmdClassList; 45 ShellCommandClass::_commandClassList->push_back(this); 47 46 } 48 47 … … 52 51 ShellCommandClass::~ShellCommandClass() 53 52 { 54 while(!this-> commandList.empty())55 delete this-> commandList.back();56 57 if (ShellCommandClass:: commandClassList != NULL)58 { 59 CmdClassList::iterator delClass = std::find(ShellCommandClass:: commandClassList->begin(), ShellCommandClass::commandClassList->end(), this);60 if (delClass != ShellCommandClass:: commandClassList->end())61 ShellCommandClass:: commandClassList->erase(delClass);53 while(!this->_commandList.empty()) 54 delete this->_commandList.back(); 55 56 if (ShellCommandClass::_commandClassList != NULL) 57 { 58 CmdClassList::iterator delClass = std::find(ShellCommandClass::_commandClassList->begin(), ShellCommandClass::_commandClassList->end(), this); 59 if (delClass != ShellCommandClass::_commandClassList->end()) 60 ShellCommandClass::_commandClassList->erase(delClass); 62 61 } 63 62 } … … 68 67 void ShellCommandClass::registerCommand(ShellCommand* command) 69 68 { 70 this-> commandList.push_back(command);69 this->_commandList.push_back(command); 71 70 } 72 71 … … 77 76 void ShellCommandClass::unregisterCommand(ShellCommand* command) 78 77 { 79 CmdList::iterator delC = std::find(this-> commandList.begin(), this->commandList.end(), command);80 if (delC != this-> commandList.end())81 this-> commandList.erase(delC);78 CmdList::iterator delC = std::find(this->_commandList.begin(), this->_commandList.end(), command); 79 if (delC != this->_commandList.end()) 80 this->_commandList.erase(delC); 82 81 } 83 82 … … 89 88 // unregister all commands and Classes 90 89 CmdClassList::iterator classIT; 91 if (ShellCommandClass:: commandClassList == NULL)90 if (ShellCommandClass::_commandClassList == NULL) 92 91 return; 93 92 94 while (!ShellCommandClass:: commandClassList->empty())95 delete ShellCommandClass:: commandClassList->back();96 delete ShellCommandClass:: commandClassList;97 ShellCommandClass:: commandClassList = NULL;93 while (!ShellCommandClass::_commandClassList->empty()) 94 delete ShellCommandClass::_commandClassList->back(); 95 delete ShellCommandClass::_commandClassList; 96 ShellCommandClass::_commandClassList = NULL; 98 97 } 99 98 … … 107 106 bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList) 108 107 { 109 if (ShellCommandClass:: commandClassList == NULL)108 if (ShellCommandClass::_commandClassList == NULL) 110 109 return false; 111 110 112 111 113 112 CmdClassList::const_iterator elem; 114 for(elem = ShellCommandClass:: commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)113 for(elem = ShellCommandClass::_commandClassList->begin(); elem != ShellCommandClass::_commandClassList->end(); elem++) 115 114 { 116 115 if (className == (*elem)->getName()) 117 116 { 118 117 CmdList::iterator command; 119 for(command = (*elem)-> commandList.begin(); command != (*elem)->commandList.end(); command++)118 for(command = (*elem)->_commandList.begin(); command != (*elem)->_commandList.end(); command++) 120 119 stringList.push_back((*command)->getName()); 121 120 return true; … … 133 132 ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className) 134 133 { 135 if (ShellCommandClass:: commandClassList == NULL)134 if (ShellCommandClass::_commandClassList == NULL) 136 135 return false; 137 136 138 137 139 138 CmdClassList::const_iterator classIT; 140 for (classIT = ShellCommandClass:: commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)141 if (className == (*classIT)-> className)139 for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++) 140 if (className == (*classIT)->_className) 142 141 return (*classIT); 143 142 return NULL; … … 152 151 { 153 152 return (ShellCommandClass::getCommandClass(className) != NULL); 154 }155 156 ClassID ShellCommandClass::getClassID()157 {158 if (this->classID == CL_NULL)159 this->classID = ClassList::StringToID(this->className);160 return this->classID;161 153 } 162 154 … … 181 173 void ShellCommandClass::help(const std::string& className) 182 174 { 183 if (ShellCommandClass:: commandClassList == NULL)175 if (ShellCommandClass::_commandClassList == NULL) 184 176 { 185 177 PRINT(0)("No Commands Registered\n"); … … 187 179 } 188 180 if (className.empty()) 189 PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass:: commandClassList->size());181 PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::_commandClassList->size()); 190 182 191 183 192 184 CmdClassList::iterator classIT; 193 for (classIT = ShellCommandClass:: commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)194 { 195 if (className.empty() || className == (*classIT)-> className)185 for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++) 186 { 187 if (className.empty() || className == (*classIT)->_className) 196 188 { 197 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)-> className.c_str(), (*classIT)->commandList.size());189 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->_className.c_str(), (*classIT)->_commandList.size()); 198 190 CmdList::const_iterator cmdIT; 199 for (cmdIT = (*classIT)-> commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)191 for (cmdIT = (*classIT)->_commandList.begin(); cmdIT != (*classIT)->_commandList.end(); cmdIT++) 200 192 { 201 193 PRINT(0)(" command:'%s' : params:%d: ", (*cmdIT)->getCName(), (*cmdIT)->executor->getParamCount()); -
trunk/src/lib/shell/shell_command_class.h
r8362 r9869 25 25 class ShellCommandClass : public BaseObject 26 26 { 27 ObjectListDeclaration(ShellCommandClass); 28 27 29 friend class ShellCommand; 28 30 public: 29 31 /** @returns the CommandClassList */ 30 static const CmdClassList& getCommandClassList() { return *ShellCommandClass:: commandClassList; };32 static const CmdClassList& getCommandClassList() { return *ShellCommandClass::_commandClassList; }; 31 33 32 34 static bool getCommandListOfClass(const std::string& className, std::list<std::string>& stringList); … … 51 53 52 54 private: 53 const std::string className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 54 ClassID classID; //!< The classID of this Class 55 CmdList commandList; //!< A list of Commands from this Class 55 const std::string _className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 56 CmdList _commandList; //!< A list of Commands from this Class 56 57 57 static CmdClassList* commandClassList; //!< A list of Classes58 static CmdClassList* _commandClassList; //!< A list of Classes 58 59 }; 59 60 } -
trunk/src/lib/shell/shell_completion.cc
r9406 r9869 22 22 #include "shell_command.h" 23 23 24 #include "substring.h" 25 #include "class_list.h" 24 #include "helper_functions.h" 26 25 #include "debug.h" 27 26 … … 51 50 bool ShellCompletion::autoComplete(std::string& input) 52 51 { 53 long classID = CL_NULL; //< the classID retrieved from the Class.54 const std::list<BaseObject*>* objectList = NULL;//< the list of Objects stored in classID's ClassList52 ClassID classID; 53 const ObjectListBase* objectList = NULL; //< the list of Objects stored in classID's ClassList 55 54 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 56 55 long completeType = NullCompletion; //< the Type we'd like to complete. … … 85 84 (!emptyComplete && inputSplits.size() == 2)) 86 85 { 87 classID = ClassList::StringToID(inputSplits.getString(0)); 88 objectList = ClassList::getList((ClassID)classID); 89 if (classID != CL_NULL) 86 objectList = ObjectListBase::getObjectList(inputSplits[0]); 87 if (objectList != NULL) 88 classID = objectList->identity(); 89 if (classID != NullClass::staticClassID()) 90 90 completeType |= ObjectCompletion; 91 91 completeType |= FunctionCompletion; … … 95 95 (!emptyComplete && inputSplits.size() == 3)) 96 96 { 97 if ( ClassList::exists(inputSplits[0], inputSplits[1]))97 if (ObjectListBase::getBaseObject(inputSplits[0], inputSplits[1])) 98 98 completeType |= FunctionCompletion; 99 99 } … … 113 113 114 114 if (completeType & ClassCompletion) 115 this->objectComplete(completeString, CL_SHELL_COMMAND_CLASS);115 this->objectComplete(completeString, &ShellCommandClass::objectList()); 116 116 if (completeType & ObjectCompletion) 117 this->objectComplete(completeString, classID);117 this->objectComplete(completeString, objectList); 118 118 if (completeType & FunctionCompletion) 119 119 this->commandComplete(completeString, inputSplits[0]); … … 133 133 * @return true on success, false otherwise 134 134 */ 135 bool ShellCompletion::objectComplete(const std::string& objectBegin, long classID) 136 { 137 const std::list<BaseObject*>* boList = ClassList::getList((ClassID)classID); 138 if (boList != NULL) 139 { 140 CompletionType type = ObjectCompletion; 141 if (classID == CL_SHELL_COMMAND_CLASS) 142 type = ClassCompletion; 143 if (!this->addToCompleteList(*boList, objectBegin, type)) 144 return false; 145 } 146 else 147 return false; 135 bool ShellCompletion::objectComplete(const std::string& objectBegin, const ObjectListBase* objectList) 136 { 137 assert (objectList != NULL); 138 139 CompletionType type = ObjectCompletion; 140 if (objectList == &ShellCommandClass::objectList()) 141 type = ClassCompletion; 142 143 ObjectListBase::base_list list; 144 objectList->getBaseObjectList(&list); 145 146 if (!this->addToCompleteList(list, objectBegin, type)) 147 return false; 148 148 149 return true; 149 150 } … … 321 322 switch (type) 322 323 { 323 324 325 326 327 328 329 330 331 332 333 334 324 default:// SHELLC_NONE 325 return typeNames[0]; 326 case ClassCompletion: 327 return typeNames[1]; 328 case ObjectCompletion: 329 return typeNames[2]; 330 case FunctionCompletion: 331 return typeNames[3]; 332 case AliasCompletion: 333 return typeNames[4]; 334 case ParamCompletion: 335 return typeNames[5]; 335 336 } 336 337 } -
trunk/src/lib/shell/shell_completion.h
r7415 r9869 16 16 // FORWARD DECLARATION 17 17 class BaseObject; 18 class ObjectListBase; 18 19 19 20 namespace OrxShell … … 50 51 bool autoComplete(std::string& input); 51 52 52 static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type);53 static const std::string& typeToString(ShellCompletion::CompletionType type); 53 54 54 55 private: 55 bool objectComplete(const std::string& objectBegin, long classID);56 bool objectComplete(const std::string& objectBegin, const ObjectListBase* const objectList); 56 57 bool commandComplete(const std::string& commandBegin, const std::string& className); 57 58 bool aliasComplete(const std::string& aliasBegin); -
trunk/src/lib/shell/shell_completion_plugin.cc
r8330 r9869 21 21 #include "shell_command.h" 22 22 23 #include "substring.h" 24 #include "class_list.h" 23 #include "helper_functions.h" 25 24 #include "loading/resource_manager.h" 26 25 … … 98 97 if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir. 99 98 { 100 dir.setFileName(Resource Manager::getInstance()->getDataDir() + this->_subDir);99 dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + this->_subDir); 101 100 dir.open(); 102 101 for(unsigned int i = 0; i < dir.fileCount(); i++ ) … … 113 112 directoryName = completionBegin.substr(0, pos); 114 113 115 dir.setFileName(Resource Manager::getInstance()->getDataDir() + directoryName);114 dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + directoryName); 116 115 dir.open(); 117 116 … … 136 135 continue; 137 136 } 138 printf("%s\n", (ResourceManager::getInstance()->getDataDir() + fileName).c_str());137 printf("%s\n", (Resources::ResourceManager::getInstance()->mainGlobalPath().name() + fileName).c_str()); 139 138 if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) && 140 ResourceManager::isInDataDir(fileName))139 Resources::ResourceManager::getInstance()->checkFileInMainPath(fileName)) 141 140 { 142 141 printf("Dir %s\n", fileName.c_str()); -
trunk/src/lib/shell/shell_input.cc
r8339 r9869 24 24 #include "compiler.h" 25 25 #include "key_names.h" 26 26 27 27 28 namespace OrxShell … … 31 32 ->setAlias("help"); 32 33 34 ObjectListDefinition(ShellInput); 33 35 34 36 /** … … 39 41 : Text ("") 40 42 { 43 this->registerObject(this, ShellInput::_objectList); 44 41 45 this->pressedKey = SDLK_FIRST; 42 this->setClassID(CL_SHELL_INPUT, "ShellInput"); 43 44 this->inputLine = ""; 46 45 47 this->historyIT = ShellInput::history.begin(); 46 48 this->setHistoryLength(50); … … 53 55 { 54 56 //if (!this->isEventSubscribed(ES_SHELL, i)) 55 57 this->subscribeEvent(ES_SHELL, i); 56 58 } 57 59 // unsubscribe unused TODO improve. … … 60 62 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP); 61 63 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN); 62 63 64 } 64 65 … … 87 88 void ShellInput::flush() 88 89 { 89 this->inputLine.clear(); 90 this->setText(this->inputLine); 90 this->inputLineBegin.clear(); 91 this->inputLineEnd.clear(); 92 this->clear(); 91 93 } 92 94 … … 97 99 void ShellInput::setInputText(const std::string& text) 98 100 { 99 this->inputLine = text; 100 this->setText(this->inputLine); 101 this->inputLineBegin = text; 102 this->inputLineEnd.clear(); 103 this->setText(text); 101 104 } 102 105 … … 114 117 } 115 118 116 this->inputLine += character;117 this->setText(this->inputLine );119 this->inputLineBegin += character; 120 this->setText(this->inputLineBegin + this->inputLineEnd); 118 121 } 119 122 … … 130 133 } 131 134 132 this->inputLine += characters;133 this->setText(this->inputLine );135 this->inputLineBegin += characters; 136 this->setText(this->inputLineBegin + this->inputLineEnd); 134 137 } 135 138 … … 145 148 this->historyScrolling = false; 146 149 } 147 if (this->inputLine .size() < characterCount)148 characterCount = this->inputLine .size();149 150 this->inputLine .erase(this->inputLine.size() - characterCount, this->inputLine.size());151 this->setText(this->inputLine );150 if (this->inputLineBegin.size() < characterCount) 151 characterCount = this->inputLineBegin.size(); 152 153 this->inputLineBegin.erase(this->inputLineBegin.size() - characterCount, this->inputLineBegin.size()); 154 this->setText(this->inputLineBegin + this->inputLineEnd); 152 155 } 153 156 … … 158 161 bool ShellInput::executeCommand() 159 162 { 160 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 161 162 if (this->inputLine.empty()) 163 if (this->getInput().empty()) 163 164 return false; 164 165 ShellCommand::execute(this->inputLine); 165 DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str()); 166 167 ShellCommand::execute(this->getInput()); 166 168 167 169 // removing the eventually added Entry (from scrolling) to the List … … 173 175 174 176 // adding the new Command to the History 175 if (history.empty() || history.back() != this-> inputLine)176 this->history.push_back(this-> inputLine);177 if (history.empty() || history.back() != this->getInput()) 178 this->history.push_back(this->getInput()); 177 179 if (this->history.size() > this->historyLength) 178 180 { … … 193 195 if (!this->historyScrolling) 194 196 { 195 this->history.push_back(this-> inputLine);197 this->history.push_back(this->getInput()); 196 198 this->historyScrolling = true; 197 199 this->historyIT = --this->history.end(); … … 231 233 } 232 234 235 /** 236 * @brief moves the cursor chars Characters to the right. 237 * @param chars how much to move the cursor. 238 */ 239 void ShellInput::moveCursor(int chars) 240 { 241 if (chars > 0) 242 { 243 PRINTF(5)("move cursor %d to the right\n", chars); 244 if (chars >= (int) this->inputLineEnd.size()) 245 chars = inputLineEnd.size(); 246 this->inputLineBegin += this->inputLineEnd.substr(0, chars); 247 this->inputLineEnd.erase(0, chars); 248 } 249 else if (chars < 0) 250 { 251 chars = -chars; 252 PRINTF(5)("move cursor %d to the left\n", chars); 253 254 if (chars >= (int) this->inputLineBegin.size()) 255 chars = inputLineBegin.size(); 256 this->inputLineEnd = this->inputLineBegin.substr(this->inputLineBegin.size() - chars) + this->inputLineEnd; 257 this->inputLineBegin.erase(this->inputLineBegin.size() - chars); 258 } 259 } 260 233 261 234 262 /** … … 237 265 void ShellInput::help(const std::string& className, const std::string& functionName) 238 266 { 239 printf("%s::%s\n", className.c_str(), functionName.c_str());240 241 267 if (className.empty()) 242 268 { 243 PRINT(0)(" Help for the most important Shell-commands\n");244 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");245 PRINT(0)(" input order:\n");246 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n");247 PRINT(0)(" Alias [parameter]\n");248 PRINT(0)("- Also try 'help className' ");269 PRINT(0)("== Help for the most important Shell-commands\n"); 270 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n"); 271 PRINT(0)(" input order:\n"); 272 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n"); 273 PRINT(0)(" Alias [parameter]\n"); 274 PRINT(0)("- Also try 'help className' or pushing 'TAB'\n"); 249 275 } 250 276 else if (!className.empty() && functionName.empty()) … … 269 295 { 270 296 case SDLK_BACKSPACE: 271 272 297 this->removeCharacters(1); 298 break; 273 299 case SDLK_UP: 274 275 300 this->historyMoveUp(); 301 break; 276 302 case SDLK_DOWN: 277 278 303 this->historyMoveDown(); 304 break; 279 305 default: 280 281 282 283 306 { 307 if (likely(pressedKey < 127)) 308 this->addCharacter(this->pressedKey); 309 } 284 310 } 285 311 } … … 313 339 this->pressedEvent = event.type; 314 340 } 341 else if (event.type == SDLK_LEFT) 342 { 343 this->moveCursor(-1); 344 this->pressedKey = event.type; 345 this->pressedEvent = event.type; 346 } 347 else if (event.type == SDLK_RIGHT) 348 { 349 this->moveCursor(+1); 350 this->pressedKey = event.type; 351 this->pressedEvent = event.type; 352 } 315 353 else if (event.type == SDLK_TAB) 316 354 { 317 this->completion.autoComplete(this->inputLine );318 this->setText(this-> inputLine);355 this->completion.autoComplete(this->inputLineBegin); 356 this->setText(this->getInput()); 319 357 } 320 358 else if (event.type == SDLK_BACKSPACE) … … 325 363 this->removeCharacters(1); 326 364 } 365 else if (event.type == SDLK_DELETE) 366 { 367 if (!this->inputLineEnd.empty()) 368 { 369 this->inputLineEnd.erase(0, 1); 370 this->setText(this->getInput()); 371 } 372 } 327 373 else if (event.type == SDLK_RETURN) 328 374 { -
trunk/src/lib/shell/shell_input.h
r7858 r9869 30 30 class ShellInput : public Text, public EventListener 31 31 { 32 ObjectListDeclaration(ShellInput); 32 33 33 34 public: … … 36 37 37 38 /** @returns the inputLine */ 38 const std::string& getInput() const { return this->inputLine; };39 std::string getInput() const { return this->inputLineBegin + this->inputLineEnd; }; 39 40 40 41 // InputLine … … 54 55 void historyMoveDown(); 55 56 57 void moveCursor(int chars); 58 56 59 void help(const std::string& className = "", const std::string& function = ""); 57 60 … … 63 66 ShellCompletion completion; //!< The Completion Interface. 64 67 65 std::string inputLine; //!< the Char-Array of the Buffer 68 std::string inputLineBegin; //!< The Line up to the cursor. 69 std::string inputLineEnd; //!< The Line from the cursor on 70 66 71 float repeatRate; //!< The Repeat-Delay. 67 72 float repeatDelay; //!< The delay of the first Character of a given Character. -
trunk/src/lib/shell/some_shell_commands.cc
r8623 r9869 29 29 30 30 #include "network_game_rules.h" 31 31 SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say"); 32 32 33 33 #include "player_stats.h" 34 34 SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick"); 35 35 36 #include "class_list.h"37 SHELL_COMMAND(debug, ClassList, ClassList::debugS)38 ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output")39 ->defaultValues(MT_NULL, 1);36 // #include "class_list.h" 37 // SHELL_COMMAND(debug, ClassList, ClassList::debugS) 38 // ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output") 39 // ->defaultValues(MT_NULL, 1); 40 40 41 41 #include "p_node.h" 42 43 42 SHELL_COMMAND(debugNode, PNode, debugNode); 43 SHELL_COMMAND(setPosition, PNode, setAbsCoor); 44 44 45 45 #include "render_2d.h" 46 46 SHELL_COMMAND(toggleNodeVisibility, Render2D, toggleNodesVisibility); 47 47 48 48 49 49 #include "material.h" 50 51 52 50 SHELL_COMMAND(setDiffuseTexture, Material, setDiffuseMap) 51 ->defaultValues(MT_NULL, (int)GL_TEXTURE_2D) 52 ->completionPlugin(0, CompletorFileSystem()); 53 53 54 #include "loading/resource_manager.h" 55 namespace Resources { 56 SHELL_COMMAND(debug, ResourceManager, debug); 57 SHELL_COMMAND(load, ResourceManager, loadFromLoadStringHACK); 58 SHELL_COMMAND(unload, ResourceManager, unloadAllBelowKeepLevelINT); 59 } 60 61 #include "loading/load_param_class_description.h" 62 SHELL_COMMAND_STATIC(printAll, LoadParamClassDescription, &LoadParamClassDescription::printAll) 63 ->defaultValues(MT_NULL, true); 64 SHELL_COMMAND_STATIC(capture, LoadParamClassDescription, &LoadParamClassDescription::captureDescriptions) 65 ->defaultValues(true); 66 67 #include "loading/game_loader.h" 68 SHELL_COMMAND(quit, GameLoader, stop) 69 ->describe("quits the game") 70 ->setAlias("orxoquit"); 71 72 #include "object_list.h" 73 SHELL_COMMAND_STATIC(debugAll, ObjectListBase, &ObjectListBase::debugAll); -
trunk/src/lib/sound/Makefile.am
r5475 r9869 7 7 sound_source.cc \ 8 8 sound_buffer.cc \ 9 sound_buffer_data.cc \ 10 resource_sound_buffer.cc \ 9 11 ogg_player.cc 10 12 … … 12 14 sound_source.h \ 13 15 sound_buffer.h \ 16 sound_buffer_data.h \ 17 resource_sound_buffer.h \ 14 18 ogg_player.h -
trunk/src/lib/sound/ogg_player.cc
r9406 r9869 34 34 35 35 #include "helper_functions.h" 36 37 #ifdef HAVE_SDL_SDL_H 38 39 #include <SDL/SDL.h> 40 #include <SDL/SDL_endian.h> 41 42 #else 43 44 #include <SDL.h> 45 #include <SDL_endian.h> 46 47 #endif 36 #include "sdlincl.h" 48 37 49 38 namespace OrxSound 50 39 { 40 ObjectListDefinition(OggPlayer); 51 41 /** 52 42 * initializes an Ogg-player from a file … … 55 45 OggPlayer::OggPlayer(const std::string& fileName) 56 46 { 57 this-> setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer");47 this->registerObject(this, OggPlayer::_objectList); 58 48 59 49 this->state = OggPlayer::None; … … 276 266 ogg->update(); 277 267 } 278 SDL_Delay(1 0);268 SDL_Delay(1); 279 269 } 280 270 PRINTF(4)("End the AudioThread\n"); -
trunk/src/lib/sound/ogg_player.h
r9019 r9869 13 13 #include <ogg/ogg.h> 14 14 #include <vorbis/vorbisfile.h> 15 #include " threading.h"15 #include "util/threading.h" 16 16 17 17 struct File; … … 25 25 class OggPlayer : public BaseObject 26 26 { 27 ObjectListDeclaration(OggPlayer); 28 27 29 public: 28 30 /** … … 98 100 99 101 100 std::string _title; 101 std::string _artist; 102 std::string _album; 103 std::string _vendor; 102 std::string _title; //!< Song Title. 103 std::string _artist; //!< Artist Name of the current song. 104 std::string _album; //!< Album Name of the current song. 105 std::string _vendor; //!< Vendor Name of the current song. 104 106 }; 105 107 -
trunk/src/lib/sound/sound_buffer.cc
r8971 r9869 18 18 #include "sound_buffer.h" 19 19 20 #include "sound_engine.h"21 20 22 #include "sdlincl.h"23 #include <cassert>24 #include "debug.h"25 #include "sys/stat.h"26 #include "helper_functions.h"27 28 #ifdef HAVE_SDL_SDL_H29 #include <SDL/SDL.h>30 #include <SDL/SDL_endian.h>31 #else32 #include <SDL.h>33 #include <SDL_endian.h>34 #endif35 21 namespace OrxSound 36 22 { 23 ObjectListDefinition(SoundBuffer); 37 24 ////////////////// 38 25 /* SOUND-BUFFER */ 39 26 ////////////////// 27 SoundBuffer::SoundBuffer() 28 : data(new SoundBufferData) 29 { 30 this->registerObject(this, SoundBuffer::_objectList); 31 } 40 32 /** 41 * Creates a Soundbuffer out of an inputfile33 * @brief Creates a Soundbuffer out of an inputfile 42 34 * @param fileName The name of the File 43 35 */ 44 36 SoundBuffer::SoundBuffer(const std::string& fileName) 37 : data(new SoundBufferData) 45 38 { 46 this->setClassID(CL_SOUND_BUFFER, "SoundBuffer"); 47 this->setName(fileName); 39 this->registerObject(this, SoundBuffer::_objectList); 40 this->load(fileName); 41 } 48 42 49 // generate a Buffer 50 alGenBuffers(1, &this->bufferID); 51 SoundEngine::checkError("Generate Buffer", __LINE__); 52 if (!nocaseCmp(fileName.substr(fileName.size() - 3), "WAV")) 53 { 54 this->loadWAV(fileName); 55 } 56 else if (!nocaseCmp(fileName.substr(fileName.size() - 3), "OGG")) 57 this->loadOGG(fileName); 43 SoundBuffer::SoundBuffer(const SoundBuffer& buffer) 44 : data(buffer.data) 45 { 46 this->registerObject(this, SoundBuffer::_objectList); 47 } 58 48 59 } 49 SoundBuffer::SoundBuffer(const SoundBufferData::Pointer& dataPointer) 50 : data(dataPointer) 51 { 52 this->registerObject(this, SoundBuffer::_objectList); 53 }; 60 54 61 55 SoundBuffer::~SoundBuffer() 62 56 { 63 // SoundEngine::getInstance()->removeBuffer(this);64 alDeleteBuffers(1, &this->bufferID);65 SoundEngine::checkError("SoundBuffer: Delete Buffer", __LINE__);66 57 } 67 58 68 /**69 * @brief loads a Waveform from the local fileSystem into this Source.70 * @param fileName the Name of the File to Load.71 * @returns true on success.72 */73 bool SoundBuffer::loadWAV(const std::string& fileName)74 {75 SDL_AudioSpec wavSpec;76 Uint32 wavLength;77 Uint8 *wavBuffer;78 79 /* Load the WAV */80 if( SDL_LoadWAV(fileName.c_str(), &wavSpec, &wavBuffer, &wavLength) == NULL)81 {82 PRINTF(2)("Could not open %s: %s\n", fileName.c_str(), SDL_GetError());83 return false;84 }85 #if SDL_BYTEORDER == SDL_BIG_ENDIAN86 if ( !( wavSpec.format == AUDIO_U8 || wavSpec.format == AUDIO_S8 ) )87 {88 int cnt = wavLength/2;89 Uint16* wavBufferAsShorts = ( Uint16* )wavBuffer;90 for ( int i = 0; i < cnt; ++i, ++wavBufferAsShorts )91 *wavBufferAsShorts = SDL_Swap16( *wavBufferAsShorts );92 }93 #endif94 alBufferData(this->bufferID, SoundBuffer::sdlAudioSpecToAlFormat(&wavSpec),95 wavBuffer, wavLength, wavSpec.freq);96 97 SDL_FreeWAV(wavBuffer);98 if (SoundEngine::checkError("Could not load Wave file", __LINE__))99 return true;100 else101 return false;102 }103 104 105 #ifndef AL_FORMAT_VORBIS_EXT106 #define AL_FORMAT_VORBIS_EXT 0x100030107 #endif108 /**109 * @brief loads an OGG-file into a SOundBuffer110 * @param fileName the Name of the File to load.111 * @returns true on success (file exists and is fully loaded), false otherwise.112 */113 bool SoundBuffer::loadOGG(const std::string& fileName)114 {115 void* ovdata;116 FILE* fh;117 118 fh = fopen( fileName.c_str() , "rb") ;119 if( fh != NULL )120 {121 struct stat sbuf ;122 123 if(stat( fileName.c_str(), &sbuf ) != -1)124 {125 ovdata = malloc(sbuf.st_size);126 if(ovdata != NULL)127 {128 fread( ovdata, 1, sbuf.st_size, fh);129 130 alBufferData( this->bufferID,131 AL_FORMAT_VORBIS_EXT,132 ovdata,133 sbuf.st_size,134 1) ;135 SoundEngine::checkError("Could not load OGG file", __LINE__);136 137 free(ovdata);138 }139 fclose(fh);140 }141 else142 return false;143 }144 else145 return false;146 147 return true ;148 149 }150 151 152 /**153 * @brief converts an SDL_AudioSpec into a valid OpenAL AUDIO_FORMAT enumerator154 * @param audiospec the AudioSpec to convert.155 * @returns the AL_FORMAT156 */157 ALenum SoundBuffer::sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec)158 {159 assert (audiospec != NULL);160 bool stereo = true;161 bool is16Bit = true;162 if (audiospec->format == AUDIO_U8 || audiospec->format == AUDIO_S8)163 is16Bit = false;164 if (audiospec->channels == 1)165 stereo = false;166 167 if (!stereo && !is16Bit)168 return AL_FORMAT_MONO8;169 else if (!stereo && is16Bit)170 return AL_FORMAT_MONO16;171 else if (stereo && !is16Bit)172 return AL_FORMAT_STEREO8;173 else /* if (stereo && is16Bit) */174 return AL_FORMAT_STEREO16;175 }176 59 } -
trunk/src/lib/sound/sound_buffer.h
r8969 r9869 8 8 9 9 #include "base_object.h" 10 #include "alincl.h" 11 12 // FORWARD DECLARATION 13 typedef struct SDL_AudioSpec; 10 #include "sound_buffer_data.h" 14 11 15 12 namespace OrxSound 16 13 { 17 14 //! A class that represents a datastructure to play Sounds. 18 class SoundBuffer : public BaseObject15 class SoundBuffer : virtual public BaseObject 19 16 { 17 ObjectListDeclaration(SoundBuffer); 20 18 public: 19 SoundBuffer(); 20 SoundBuffer(const SoundBuffer& buffer); 21 SoundBuffer(const SoundBufferData::Pointer& dataPointer); 21 22 SoundBuffer(const std::string& fileName); 22 23 virtual ~SoundBuffer(); 23 24 24 bool loadWAV(const std::string& fileName); 25 bool loadOGG(const std::string& fileName); 25 /** @brief assignment operator */ 26 SoundBuffer& operator=(const SoundBuffer& buffer) { this->data = buffer.data; return *this; }; 27 bool operator==(const SoundBuffer& buffer) const {return this->data == buffer.data; }; 28 29 /** @see SoundBufferData::load */ 30 inline bool load(const std::string& fileName) { return this->data->load(fileName); }; 31 /** @see SoundBufferData::loadWav */ 32 inline bool loadWAV(const std::string& fileName) { return this->data->loadWAV(fileName); }; 33 /** @see SoundBufferData::loadOgg */ 34 inline bool loadOGG(const std::string& fileName) { return this->data->loadOGG(fileName); }; 26 35 27 36 /** @returns the ID of the buffer used in this SoundBuffer */ 28 inline ALuint getID() const { return this->bufferID; } 37 inline ALuint getID() const { return this->data->getID(); } 38 inline bool loaded() const { return this->data->loaded(); } 39 40 /** @returns the DataPointer */ 41 const SoundBufferData::Pointer& dataPointer() const { return data; } 42 /** @param dataPointer the data to acquire @brief Buffer shall acquire dataPointers data */ 43 void acquireData(const SoundBufferData::Pointer& dataPointer) { data = dataPointer; }; 29 44 30 45 private: 31 ALenum sdlAudioSpecToAlFormat(const SDL_AudioSpec* audiospec); 32 33 private: 34 ALuint bufferID; //!< The address of the Buffer. 35 36 ALsizei size; //!< The size of the Buffer. 37 ALboolean loop; //!< loop information. 46 SoundBufferData::Pointer data; //!< Pointer to the Stored Data 38 47 }; 39 48 } -
trunk/src/lib/sound/sound_engine.cc
r9235 r9869 21 21 #include "sound_engine.h" 22 22 23 #include "class_list.h"24 25 23 #include "p_node.h" 26 #include "util/loading/resource_manager.h"27 24 #include "debug.h" 28 #include " util/preferences.h"25 #include "parser/preferences/preferences.h" 29 26 #include "globals.h" 27 #include "resource_sound_buffer.h" 30 28 31 29 namespace OrxSound 32 30 { 33 31 ObjectListDefinition(SoundEngine); 34 32 ////////////////// 35 33 /* SOUND-ENGINE */ … … 40 38 SoundEngine::SoundEngine () 41 39 { 42 this-> setClassID(CL_SOUND_ENGINE, "SoundEngine");40 this->registerObject(this, SoundEngine::_objectList); 43 41 this->setName("SoundEngine"); 44 42 45 43 this->listener = NULL; 46 this->bufferList = NULL;47 this->sourceList = NULL;48 44 49 45 this->device = NULL; … … 69 65 { 70 66 // deleting all the SoundSources 71 if(this->sourceList != NULL) 72 { 73 while (this->sourceList->size() > 0) 74 delete static_cast<SoundSource*>(this->sourceList->front()); 75 } 67 while (!SoundSource::objectList().empty()) 68 delete (SoundSource::objectList().front()); 76 69 77 70 while(!this->ALSources.empty()) … … 89 82 90 83 // deleting all the SoundBuffers 91 if (this->bufferList != NULL) 92 { 93 while(this->bufferList->size() > 0) 94 ResourceManager::getInstance()->unload(static_cast<SoundBuffer*>(this->bufferList->front())); 95 } 84 // while(!SoundBuffer::objectList().empty()) 85 //ResourceManager::getInstance()->unload(SoundBuffer::objectList().front()); 96 86 97 87 // removing openAL from AudioResource … … 129 119 SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode) 130 120 { 131 SoundBuffer * buffer = NULL;121 SoundBuffer buffer; 132 122 if (!fileName.empty()) 133 123 { 134 buffer = (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL);135 if ( buffer == NULL)124 buffer = ResourceSoundBuffer(fileName); 125 if (!buffer.loaded()) 136 126 PRINTF(2)("Wav-Sound %s could not be loaded onto new Source\n", fileName.c_str()); 137 127 } … … 212 202 213 203 // updating all the Sources positions 214 if (likely(this->sourceList != NULL || (this->sourceList = ClassList::getList(CL_SOUND_SOURCE)) != NULL)) 215 { 216 std::list<BaseObject*>::const_iterator sourceIT; 217 SoundSource* source; 218 for (sourceIT = this->sourceList->begin(); sourceIT != this->sourceList->end(); sourceIT++) 204 ObjectList<SoundSource>::const_iterator sourceIT; 205 for (sourceIT = SoundSource::objectList().begin(); 206 sourceIT != SoundSource::objectList().end(); 207 sourceIT++) 208 { 209 if ((*sourceIT)->isPlaying()) 219 210 { 220 source = static_cast<SoundSource*>(*sourceIT); 221 if (source->isPlaying()) 211 int play = 0x000; 212 alGetSourcei((*sourceIT)->getID(), AL_SOURCE_STATE, &play); 213 if (DEBUG_LEVEL > 2) 214 SoundEngine::checkError("SoundEngine::update() Play", __LINE__); 215 if(play == AL_PLAYING) 222 216 { 223 int play = 0x000; 224 alGetSourcei(source->getID(), AL_SOURCE_STATE, &play); 225 if (DEBUG_LEVEL > 2) 226 SoundEngine::checkError("SoundEngine::update() Play", __LINE__); 227 if(play == AL_PLAYING) 217 if (likely((*sourceIT)->getNode() != NULL)) 228 218 { 229 if (likely(source->getNode() != NULL)) 230 { 231 alSource3f(source->getID(), AL_POSITION, 232 source->getNode()->getAbsCoor().x, 233 source->getNode()->getAbsCoor().y, 234 source->getNode()->getAbsCoor().z); 235 if (DEBUG_LEVEL > 2) 236 SoundEngine::checkError("SoundEngine::update() Set Source Position", __LINE__); 237 alSource3f(source->getID(), AL_VELOCITY, 238 source->getNode()->getVelocity().x, 239 source->getNode()->getVelocity().y, 240 source->getNode()->getVelocity().z); 241 if (DEBUG_LEVEL > 2) 242 SoundEngine::checkError("SoundEngine::update() Set Source Velocity", __LINE__); 243 } 219 alSource3f((*sourceIT)->getID(), AL_POSITION, 220 (*sourceIT)->getNode()->getAbsCoor().x, 221 (*sourceIT)->getNode()->getAbsCoor().y, 222 (*sourceIT)->getNode()->getAbsCoor().z); 223 if (DEBUG_LEVEL > 2) 224 SoundEngine::checkError("SoundEngine::update() Set Source Position", __LINE__); 225 alSource3f((*sourceIT)->getID(), AL_VELOCITY, 226 (*sourceIT)->getNode()->getVelocity().x, 227 (*sourceIT)->getNode()->getVelocity().y, 228 (*sourceIT)->getNode()->getVelocity().z); 229 if (DEBUG_LEVEL > 2) 230 SoundEngine::checkError("SoundEngine::update() Set Source Velocity", __LINE__); 244 231 } 245 else246 {247 source->stop();248 }232 } 233 else 234 { 235 (*sourceIT)->stop(); 249 236 } 250 237 } … … 393 380 default: 394 381 case AL_NO_ERROR: 395 382 return ("AL_NO_ERROR"); 396 383 case AL_INVALID_NAME: 397 384 return ("AL_INVALID_NAME"); 398 385 case AL_INVALID_ENUM: 399 386 return ("AL_INVALID_ENUM"); 400 387 case AL_INVALID_VALUE: 401 388 return ("AL_INVALID_VALUE"); 402 389 case AL_INVALID_OPERATION: 403 390 return ("AL_INVALID_OPERATION"); 404 391 case AL_OUT_OF_MEMORY: 405 392 return ("AL_OUT_OF_MEMORY"); 406 393 }; 407 394 } … … 414 401 default: 415 402 case ALC_NO_ERROR: 416 403 return ("AL_NO_ERROR"); 417 404 case ALC_INVALID_DEVICE: 418 405 return ("ALC_INVALID_DEVICE"); 419 406 case ALC_INVALID_CONTEXT: 420 407 return("ALC_INVALID_CONTEXT"); 421 408 case ALC_INVALID_ENUM: 422 409 return("ALC_INVALID_ENUM"); 423 410 case ALC_INVALID_VALUE: 424 411 return ("ALC_INVALID_VALUE"); 425 412 case ALC_OUT_OF_MEMORY: 426 413 return("ALC_OUT_OF_MEMORY"); 427 414 }; 428 415 } -
trunk/src/lib/sound/sound_engine.h
r7847 r9869 27 27 class SoundEngine : public BaseObject 28 28 { 29 public: 29 ObjectListDeclaration(SoundEngine); 30 public: 30 31 virtual ~SoundEngine(); 31 32 /** @returns a Pointer to the only object of this Class */ … … 75 76 const PNode* listener; //!< The listener of the Scene 76 77 77 const std::list<BaseObject*>* bufferList; //!< A list of buffers78 const std::list<BaseObject*>* sourceList; //!< A list for all the sources in the scene.79 80 78 unsigned int maxSourceCount; //!< How many Sources is the Maximum 81 79 std::stack<ALuint> ALSources; //!< A list of real openAL-Sources, the engine allocates, and stores for reuse. -
trunk/src/lib/sound/sound_source.cc
r8969 r9869 19 19 #include "sound_engine.h" 20 20 21 #include "alincl.h"22 21 #include "compiler.h" 23 22 #include "debug.h" … … 25 24 namespace OrxSound 26 25 { 26 ObjectListDefinition(SoundSource); 27 27 /** 28 28 * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer 29 29 */ 30 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) 31 { 32 this->setClassID(CL_SOUND_SOURCE, "SoundSource"); 33 30 SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer& buffer) 31 { 32 this->registerObject(this, SoundSource::_objectList); 34 33 // adding the Source to the SourcesList of the SoundEngine 35 34 this->buffer = buffer; … … 51 50 SoundSource::SoundSource(const SoundSource& source) 52 51 { 53 this-> setClassID(CL_SOUND_SOURCE, "SoundSource");52 this->registerObject(this, SoundSource::_objectList); 54 53 55 54 // adding the Source to the SourcesList of the SoundEngine … … 120 119 void SoundSource::play() 121 120 { 122 if (this-> buffer && this->retrieveSource())121 if (this->retrieveSource()) 123 122 { 124 123 if (this->bPlay) 125 124 alSourceStop(this->sourceID); 126 125 127 alSourcei (this->sourceID, AL_BUFFER, this->buffer ->getID());126 alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID()); 128 127 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 129 128 alSourcef (this->sourceID, AL_GAIN, 1); … … 141 140 * @param buffer the buffer to play back on this Source 142 141 */ 143 void SoundSource::play(const SoundBuffer *buffer)142 void SoundSource::play(const SoundBuffer& buffer) 144 143 { 145 144 if (!this->retrieveSource()) … … 150 149 151 150 alSourceStop(this->sourceID); 152 alSourcei (this->sourceID, AL_BUFFER, buffer ->getID());151 alSourcei (this->sourceID, AL_BUFFER, buffer.getID()); 153 152 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 154 153 alSourcef (this->sourceID, AL_GAIN, 1); … … 156 155 alSourcePlay(this->sourceID); 157 156 158 if (unlikely(this->buffer != NULL))159 alSourcei (this->sourceID, AL_BUFFER, this->buffer ->getID());157 if (unlikely(this->buffer.getID() != 0)) 158 alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID()); 160 159 this->bPlay = true; 161 160 … … 170 169 * @param gain the gain of the sound buffer 171 170 */ 172 void SoundSource::play(const SoundBuffer *buffer, float gain)171 void SoundSource::play(const SoundBuffer& buffer, float gain) 173 172 { 174 173 if (!this->retrieveSource()) … … 179 178 180 179 alSourceStop(this->sourceID); 181 alSourcei (this->sourceID, AL_BUFFER, buffer ->getID());180 alSourcei (this->sourceID, AL_BUFFER, buffer.getID()); 182 181 alSourcei (this->sourceID, AL_LOOPING, AL_FALSE); 183 182 alSourcef (this->sourceID, AL_GAIN, gain); … … 185 184 alSourcePlay(this->sourceID); 186 185 187 if (unlikely(this->buffer != NULL))188 alSourcei (this->sourceID, AL_BUFFER, this->buffer ->getID());186 if (unlikely(this->buffer.getID() != 0)) 187 alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID()); 189 188 this->bPlay = true; 190 189 … … 199 198 * @param loop if true, sound gets looped 200 199 */ 201 void SoundSource::play(const SoundBuffer *buffer, float gain, bool loop)200 void SoundSource::play(const SoundBuffer& buffer, float gain, bool loop) 202 201 { 203 202 if (!this->retrieveSource()) … … 208 207 209 208 alSourceStop(this->sourceID); 210 alSourcei (this->sourceID, AL_BUFFER, buffer ->getID());209 alSourcei (this->sourceID, AL_BUFFER, buffer.getID()); 211 210 212 211 if (loop) … … 219 218 alSourcePlay(this->sourceID); 220 219 221 if (unlikely(this->buffer != NULL))222 alSourcei (this->sourceID, AL_BUFFER, this->buffer ->getID());220 if (unlikely(this->buffer.getID() != 0)) 221 alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID()); 223 222 this->bPlay = true; 224 223 … … 232 231 * @param gain the new gain value 233 232 */ 234 void SoundSource::gain(const SoundBuffer *buffer, float gain)233 void SoundSource::gain(const SoundBuffer& buffer, float gain) 235 234 { 236 235 // alSourcei (this->sourceID, AL_BUFFER, buffer->getID()); … … 347 346 * @param duration time perios to fade in 348 347 */ 349 void SoundSource::fadein(const SoundBuffer *buffer, ALfloat duration)348 void SoundSource::fadein(const SoundBuffer& buffer, ALfloat duration) 350 349 { 351 350 //if (this->buffer && this->retrieveSource()) -
trunk/src/lib/sound/sound_source.h
r8793 r9869 8 8 9 9 #include "base_object.h" 10 #include "sound_buffer.h" 10 11 #include "alincl.h" 11 12 … … 14 15 namespace OrxSound 15 16 { 16 class SoundBuffer;17 17 //! A class that represents a SoundSource 18 18 class SoundSource : public BaseObject 19 19 { 20 ObjectListDeclaration(SoundSource); 20 21 public: 21 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer * buffer = NULL);22 SoundSource(const PNode* sourceNode = NULL, const SoundBuffer& buffer = SoundBuffer()); 22 23 SoundSource(const SoundSource& source); 23 24 SoundSource& operator=(const SoundSource& source); … … 28 29 // user interaction 29 30 void play(); 30 void play(const SoundBuffer *buffer);31 void play(const SoundBuffer *buffer, float gain);32 void play(const SoundBuffer *buffer, float gain, bool loop);31 void play(const SoundBuffer& buffer); 32 void play(const SoundBuffer& buffer, float gain); 33 void play(const SoundBuffer& buffer, float gain, bool loop); 33 34 34 void gain(const SoundBuffer *buffer, float gain);35 void gain(const SoundBuffer& buffer, float gain); 35 36 36 37 void stop(); 37 38 void pause(); 38 39 void rewind(); 39 void fadein(const SoundBuffer *buffer, ALfloat duration);40 void fadein(const SoundBuffer& buffer, ALfloat duration); 40 41 41 42 // development functions … … 46 47 void setSourceNode(const PNode* sourceNode); 47 48 /** @returns the SoundBuffer of this Source */ 48 inline const SoundBuffer *getBuffer() const { return this->buffer; };49 inline const SoundBuffer& getBuffer() const { return this->buffer; }; 49 50 /** @returns the SourceNode of this Source */ 50 51 inline const PNode* getNode() const { return this->sourceNode; }; … … 65 66 bool resident; //!< If the alSource should be resident (if true, the alSource will be returned on deletion). 66 67 ALuint sourceID; //!< The ID of the Source 67 const SoundBuffer*buffer; //!< The buffer to play in this source.68 SoundBuffer buffer; //!< The buffer to play in this source. 68 69 const PNode* sourceNode; //!< The SourceNode representing the position/velocity... of this source. 69 70 }; -
trunk/src/lib/util/Makefile.am
r9406 r9869 2 2 include $(MAINSRCDIR)/defs/include_paths.am 3 3 4 noinst_LIBRARIES = libORXlibutil.a 4 noinst_LIBRARIES = \ 5 libORXlibutil.a \ 6 libORXexecutor.a 7 8 libORXexecutor_a_SOURCES = \ 9 executor/executor_substring.cc 5 10 6 11 libORXlibutil_a_SOURCES = \ … … 9 14 helper_functions.cc \ 10 15 multi_type.cc \ 11 executor/executor.cc \ 12 executor/executor_functional.cc \ 13 executor/executor_lua.cc \ 16 debug_buffer.cc \ 14 17 \ 15 18 loading/resource_manager.cc \ … … 18 21 loading/load_param.cc \ 19 22 loading/load_param_description.cc \ 23 loading/load_param_class_description.cc \ 20 24 loading/factory.cc \ 21 loading/ dynamic_loader.cc \25 loading/fast_factory.cc \ 22 26 \ 23 27 filesys/file.cc \ … … 25 29 filesys/net_link.cc \ 26 30 \ 27 preferences.cc \28 31 threading.cc \ 29 32 timer.cc 33 34 # loading/dynamic_loader.cc 30 35 31 36 … … 35 40 color.h \ 36 41 helper_functions.h \ 42 debug.h \ 43 debug_buffer.h \ 44 \ 45 \ 37 46 executor/executor.h \ 38 executor/executor_functional.h \39 47 executor/executor_xml.h \ 40 executor/executor_lua.h \ 48 executor/executor_substring.h \ 49 executor/executor_generic.h \ 50 executor/executor_member.h \ 51 executor/executor_const_member.h \ 52 executor/executor_static.h \ 53 \ 41 54 executor/functor_list.h \ 55 executor/functor_generic.h \ 56 executor/functor_member.h \ 57 executor/functor_const_member.h \ 58 executor/functor_static.h \ 59 \ 42 60 \ 43 61 filesys/file.h \ … … 45 63 filesys/net_link.h \ 46 64 \ 47 preferences.h \48 65 threading.h \ 49 66 timer.h \ … … 53 70 loading/game_loader.h \ 54 71 loading/load_param.h \ 72 loading/load_param_xml.h \ 55 73 loading/load_param_description.h \ 74 loading/load_param_class_description.h \ 56 75 loading/factory.h \ 76 loading/fast_factory.h \ 57 77 loading/dynamic_loader.h \ 58 78 \ -
trunk/src/lib/util/color.cc
r8986 r9869 30 30 //! Black Color 31 31 const Color Color::black(0,0,0,1); 32 //! Orx Color 33 const Color Color::orx(.2, .5, .7, .8); //!< TODO Define the ORX-color :) 34 35 32 33 /** 34 * @brief slerps the Color in the HSV color space into the direction of c 35 * @param c the Color to slerp to 36 * @param v the Value to slerp 0 means stay at *this, 1 means at c. 37 */ 36 38 void Color::slerpHSV(const Color& c, float v) 37 39 { … … 52 54 } 53 55 56 /** 57 * @brief simple slerp wrapper. 58 * @param from from this color 59 * @param to to this one 60 * @param v how much 61 * @see void Color::slerpHSV(const Color& c, float v) 62 */ 54 63 Color Color::slerpHSVColor(const Color& from, const Color& to, float v) 55 64 { … … 59 68 } 60 69 61 70 /** 71 * @brief nice and simple debug output for the colors (colorless :) ) 72 */ 62 73 void Color::debug() const 63 74 { … … 214 225 215 226 216 // Needed by rgb2hsv() 227 /** 228 * @returns the maximum of r g and a. 229 * @param r Red. 230 * @param g Green 231 * @param b Blue 232 */ 217 233 float Color::maxrgb(float r, float g, float b) 218 234 { … … 227 243 } 228 244 229 230 // Needed by rgb2hsv() 245 /** 246 * @returns the minimum of r g and a. 247 * @param r Red. 248 * @param g Green 249 * @param b Blue 250 */ 231 251 float Color::minrgb(float r,float g,float b) 232 252 { -
trunk/src/lib/util/color.h
r9656 r9869 14 14 #include "vector.h" 15 15 16 //! a very abstract Class that helps transforming Colors into different Systems 16 //! A Class that handles Colors. 17 /** 18 * A Color is a collection of 4 values: 19 * <ul> 20 * <li>Red</li> 21 * <li>Green</li> 22 * <li>Blue</li> 23 * <li>Alpha</li> 24 * </ul> 25 * With these four values any color of the entire spectrum can be defined. 26 * 27 * By default a Color lies between 0 and 1 for each component. 28 * for example [1,0,0,.5] means red and half visible. 29 */ 17 30 class Color 18 31 { 19 32 public: 33 /** @param r red, @param g green @param b blue @param a alpha @brief constructs a Color. */ 20 34 Color(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f) { _rgba[0] = r; _rgba[1] = g; _rgba[2] = b; _rgba[3] = a; }; 35 /** @param c Color @brief copy constructor */ 21 36 Color(const Color& c) { _rgba[0] = c.r(); _rgba[1] = c.g(); _rgba[2] = c.b(); _rgba[3] = c.a(); } 22 37 38 /** @param c the Color to set to this color @returns the copied color */ 23 39 inline const Color& operator=(const Color& c) { _rgba[0] = c.r(); _rgba[1] = c.g(); _rgba[2] = c.b(); _rgba[3] = c.a(); return *this; }; 40 /** @param c the color to compare @returns true on match. @brief compares two colors */ 24 41 inline bool operator==(const Color& c) const { return (r() == c.r() && g() == c.g() && b() == c.b() && a() == c.a()); }; 25 42 43 /** @returns the i'th Value of the Color @param i part of the color 0:r, 1:g, 2:b, 3:a */ 26 44 inline float& operator[](unsigned int i) { return _rgba[i]; } 45 /** @returns a Constant Value of the color. @param i part of the color 0:r, 1:g, 2:b, 3:a */ 27 46 inline const float& operator[](unsigned int i) const { return _rgba[i]; } 28 47 48 /** @returns the red part. */ 29 49 inline float r() const { return _rgba[0]; } 50 /** @returns the reference to the red part */ 30 51 inline float& r() { return _rgba[0]; } 52 /** @returns the green part. */ 31 53 inline float g() const { return _rgba[1]; } 54 /** @returns the reference to the green part */ 32 55 inline float& g() { return _rgba[1]; } 56 /** @returns the blue part */ 33 57 inline float b() const { return _rgba[2]; } 58 /** @returns the reference to the blue part */ 34 59 inline float& b() { return _rgba[2]; } 60 /** @returns the alpha part */ 35 61 inline float a() const { return _rgba[3]; } 62 /** @returns the reference to the alpha part */ 36 63 inline float& a() { return _rgba[3]; } 37 64 38 65 39 40 66 /** @param r red, @param g green @param b blue @param a alpha @brief sets the color. */ 41 67 void setColor(float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f) { _rgba[0] = r; _rgba[1] = g; _rgba[2] = b; _rgba[3] = a; }; 68 /** @param c the color to set. @brief sets the color. */ 42 69 void setColor(const Color& c) { r() = c.r(); g()= c.g(); b() = c.b(); a() = c.a(); }; 43 70 71 /** @returns the distance to the color @param c the color to calculate the distance to. */ 44 72 inline float dist(const Color& c) const { return (sqrt((r()-c.r())*(r()-c.r()) + (g()-c.g())*(g()-c.g()) + (b()-c.b())*(b()-c.b()) + (a()-c.a())*(a()-c.a()))); } 45 73 /// Maths 74 /** @param c the color to add to this one @returns the two added colors */ 46 75 inline const Color& operator+=(const Color& c) { r()+=c.r(); g()+=c.g(); b()+=c.b(); a()+=c.a(); return *this; }; 76 /** @returns the result of the added colors @param c the color to add */ 47 77 inline Color operator+(const Color& c) const { return Color(r()+c.r(), g()+c.g(), b()+c.b(), a()+c.a()); }; 78 /** @param c the color to substract to this one @returns the two substracted colors */ 48 79 inline const Color& operator-=(const Color& c) { r()-=c.r(); g()-=c.g(); b()-=c.b(); a()-=c.a(); return *this; }; 80 /** @returns the result of the substracted colors @param c the color to substract */ 49 81 inline Color operator-(const Color& c) const { return Color(r()-c.r(), g()-c.g(), b()-c.b(), a()-c.a()); }; 82 /** @param v the multiplier @returns the Color multiplied by v */ 50 83 inline const Color& operator*=(float v) { r()*=v, g()*=v, b()*=v, a()*=v; return *this; }; 84 /** @param v the multiplier @returns a multiplied color */ 51 85 inline Color operator*(float v) const { return Color(r()*v, g()*v, b()*v, a()*v); }; 52 86 87 /** @param c the color to slerp to @param v how much to slerp [0:1] @brief moves the color into the direction of another color */ 53 88 void slerp(const Color& c, float v) { *this += (c - *this) * v; }; 54 89 void slerpHSV(const Color& c, float v); 55 56 90 static Color slerpHSVColor(const Color& from, const Color& to, float v); 57 91 … … 75 109 static const Color white; 76 110 static const Color black; 77 static const Color orx;78 111 79 112 private: 80 float _rgba[4]; //!< Color Values 81 82 /* float _r; //!< Red Value. 83 float _g; //!< Green Value. 84 float _b; //!< Blue Value. 85 float _a; //!< Alpha Value.*/ 113 float _rgba[4]; //!< Color Values [r,g,b,a] (red green blue alpha) 86 114 }; 87 115 -
trunk/src/lib/util/count_pointer.h
r8761 r9869 9 9 { 10 10 public: 11 explicit CountPointer(X* p = 0) // allocate a new counter 12 : itsCounter(0) { if (p) itsCounter = new counter(p); } 13 virtual ~CountPointer() { release(); } 14 CountPointer(const CountPointer& r) { acquire(r.itsCounter); } 15 CountPointer& operator=(const CountPointer& r) 11 explicit CountPointer(X* p = NULL) // allocate a new counter 12 : itsCounter(NULL) { if (p) itsCounter = new counter(p); } 13 ~CountPointer() { release(); } 14 CountPointer(const CountPointer& r) { acquire(r.itsCounter); } 15 CountPointer& operator=(const CountPointer& r) 16 { 17 if (this != &r) 16 18 { 17 if (this != &r) { 18 release(); 19 acquire(r.itsCounter); 20 } 21 return *this; 19 release(); 20 acquire(r.itsCounter); 22 21 } 23 bool operator==(const CountPointer& r) const { return this->itsCounter->ptr == r.itsCounter->ptr; }; 24 X& operator*() const { return *itsCounter->ptr; } 25 X* operator->() const { return itsCounter->ptr; } 26 X* get() const { return itsCounter ? itsCounter->ptr : 0; } 27 bool unique() const { return (itsCounter ? itsCounter->count == 1 : true); } 28 virtual unsigned int count() const { return (this->itsCounter ? itsCounter->count : 0); } 22 return *this; 23 } 24 bool operator==(const CountPointer& r) const { return this->itsCounter->ptr == r.itsCounter->ptr; }; 25 inline X& operator*() const { return *itsCounter->ptr; } 26 inline X* operator->() const { return itsCounter->ptr; } 27 inline bool unique() const { return (itsCounter ? itsCounter->count == 1 : true); } 28 inline bool isNull() const { return (!itsCounter); } 29 30 unsigned int count() const { return (this->itsCounter ? itsCounter->count : 0); } 29 31 private: 30 32 31 struct counter { 32 counter(X* p = 0, unsigned c = 1) : ptr(p), count(c) {} 33 X* ptr; 34 unsigned count; 35 }* itsCounter; 33 struct counter 34 { 35 counter(X* p = NULL, unsigned c = 1) : ptr(p), count(c) {} 36 X* ptr; 37 unsigned count; 38 } 39 * itsCounter; 36 40 37 void acquire(counter* c) 41 void acquire(counter* c) 42 { 43 // increment the count 44 itsCounter = c; 45 if (c) ++c->count; 46 } 47 48 void release() 49 { 50 // decrement the count, delete if it is 0 51 if (itsCounter) 38 52 { 39 // increment the count 40 itsCounter = c; 41 if (c) ++c->count; 53 if (--itsCounter->count == 0) 54 { 55 delete itsCounter->ptr; 56 delete itsCounter; 57 } 58 itsCounter = NULL; 42 59 } 43 44 void release() 45 { 46 // decrement the count, delete if it is 0 47 if (itsCounter) { 48 if (--itsCounter->count == 0) { 49 delete itsCounter->ptr; 50 delete itsCounter; 51 } 52 itsCounter = 0; 53 } 54 } 60 } 55 61 }; 56 62 -
trunk/src/lib/util/executor/executor.h
r8894 r9869 9 9 #include "base_object.h" 10 10 11 #include "helper_functions.h"12 11 #include "multi_type.h" 13 #include "substring.h" 14 #include "functor_list.h" //< MUST BE INCLUDED HERE AT LEAST ONCE. 15 16 //! an enumerator for the definition of the Type. 17 typedef enum { 18 Executor_Objective = 1, 19 Executor_Static = 2, 20 21 Executor_NoLoadString = 8, 22 } Executor_Type; 12 13 //! The maximum Count of Arguments of the Executor 14 /** This is Hardcoded, for each Executor. */ 15 #define EXECUTOR_MAX_ARGUMENTS 7 16 17 18 /** @returns the Type of an Argument taken by the Executor */ 19 template<typename type> inline MT_Type ExecutorParamType() { return MT_EXT1; }; 20 /** @returns the Type of an Argument taken by the Executor in this case MT_BOOL */ 21 template<> inline MT_Type ExecutorParamType<bool>() { return MT_BOOL; }; 22 /** @returns the Type of an Argument taken by the Executor in this case MT_INT*/ 23 template<> inline MT_Type ExecutorParamType<int>() { return MT_INT; }; 24 /** @returns the Type of an Argument taken by the Executor in this case MT_UINT*/ 25 template<> inline MT_Type ExecutorParamType<unsigned int>() { return MT_UINT; }; 26 /** @returns the Type of an Argument taken by the Executor in this case MT_FLOAT*/ 27 template<> inline MT_Type ExecutorParamType<float>() { return MT_FLOAT; }; 28 /** @returns the Type of an Argument taken by the Executor in this case MT_CHAR*/ 29 template<> inline MT_Type ExecutorParamType<char>() { return MT_CHAR; }; 30 /** @returns the Type of an Argument taken by the Executor in this case MT_STRING*/ 31 template<> inline MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; }; 23 32 24 33 //////////////// … … 36 45 * Functions with many types (@see functor_list.h) 37 46 */ 38 class Executor : public BaseObject 47 template <typename CallType, class BaseClass = BaseObject> class Executor 39 48 { 40 public: 41 virtual ~Executor(); 42 43 virtual Executor* clone () const = 0; 44 // virtual bool operator==(const Executor* executor) const = 0; 45 46 // SETTING up the EXECUTOR 47 Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 48 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 49 const MultiType& value4 = MT_NULL, const MultiType& param5 = MT_NULL, 50 const MultiType& param6 = MT_NULL); 51 /** @param i the i'th defaultValue, @returns reference to the MultiType */ 52 inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; }; 53 54 // EXECUTE 55 /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */ 56 virtual void operator()(BaseObject* object, int& count, void* values) const = 0; 57 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ 58 virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0; 59 60 // RETRIEVE INFORMATION 61 /** @returns the Type of this Function (either static or objective) */ 62 inline long getType() const { return this->functorType; }; 63 /** @returns the Count of Parameters this Executor takes */ 64 inline unsigned int getParamCount() const { return this->paramCount; }; 65 66 static void debug(); 67 68 protected: 69 Executor(const MultiType& param0 = MT_NULL, const MultiType& param1 = MT_NULL, 70 const MultiType& param2 = MT_NULL, const MultiType& param3 = MT_NULL, 71 const MultiType& param4 = MT_NULL, const MultiType& param5 = MT_NULL, 72 const MultiType& param6 = MT_NULL); 73 74 void cloning(Executor* executor) const; 75 76 protected: 77 short functorType; //!< The type of Function we've got (either static or objective). 78 unsigned int paramCount; //!< the count of parameters. 79 MultiType defaultValue[7]; //!< Default Values. 49 public: 50 //! an enumerator for the definition of the Type. 51 typedef enum { 52 FunctionMember, //!< The function is neither Static nor Constant 53 FunctionStatic, //!< The Function is Static and pointing to either a Static Member or a C-style function. 54 FunctionConstMember, //!< The Function is Constant and pointing to a Member that does not change the Object. 55 } FunctionType; 56 57 public: 58 virtual ~Executor() {}; 59 60 // RETRIEVE INFORMATION 61 /** @param i the i'th defaultValue, @returns reference to the MultiType */ 62 inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; }; 63 /** @returns the default Values as a List */ 64 inline const MultiType* const getDefaultValues() { return defaultValue; }; 65 66 /** @returns the Type of this Function (either static or objective) */ 67 inline FunctionType getType() const { return this->functionType; }; 68 69 /** @returns the Count of Parameters this Executor takes */ 70 inline unsigned int getParamCount() const { return this->paramCount; }; 71 /** @returns true if the Executor has a return Value. */ 72 inline bool hasRetVal() const { return bRetVal; }; 73 74 /** executes a Command. @param object the Object, @param values The Value of type CallType to pass to the Executor. */ 75 virtual void operator()(BaseClass* object, CallType& values) const = 0; 76 77 /** 78 * @brief set the default values of the executor 79 * @param value0 the first default value 80 * @param value1 the second default value 81 * @param value2 the third default value 82 * @param value3 the fourth default value 83 * @param value4 the fifth default value 84 * @param value5 the sixth default value 85 * @param value6 the seventh default value 86 * @returns itself 87 * @note: THIS FUNCTION WILL BE REPLACED BY A CONFIGURATOR (most probably). 88 */ 89 Executor* defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 90 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 91 const MultiType& value4 = MT_NULL, const MultiType& value5 = MT_NULL, 92 const MultiType& value6 = MT_NULL) 93 { 94 const MultiType* value[5]; 95 value[0] = &value0; 96 value[1] = &value1; 97 value[2] = &value2; 98 value[3] = &value3; 99 value[4] = &value4; 100 value[5] = &value5; 101 value[6] = &value6; 102 for (unsigned int i = 0; i < this->paramCount; i++) 103 { 104 if (*value[i] != MT_NULL) 105 { 106 this->defaultValue[i].setValueOf(*value[i]); 107 this->defaultValue[i].storeString(); 108 } 109 } 110 return this; 111 } 112 113 /** @returns the Clone as a new Copy of the Executor. */ 114 virtual Executor<CallType, BaseClass>* clone () const = 0; 115 116 117 protected: 118 //! Now follows a List of Executor Constructors, to be fast in creating. 119 //! Creates an Executor with no Argument. 120 Executor(bool hasRetVal, FunctionType functionType = FunctionMember) 121 : bRetVal(hasRetVal), paramCount(0), functionType(functionType) 122 { }; 123 124 //! Creates an Executor with 1 Argument. 125 Executor(bool hasRetVal, const MultiType& param0, 126 FunctionType functionType = FunctionMember) 127 : bRetVal(hasRetVal), paramCount(1), functionType(functionType) 128 { 129 this->defaultValue[0] = param0; 130 }; 131 132 //! Creates an Executor with 2 Arguments. 133 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 134 FunctionType functionType = FunctionMember) 135 : bRetVal(hasRetVal), paramCount(2), functionType(functionType) 136 { 137 this->defaultValue[0] = param0; 138 this->defaultValue[1] = param1; 139 }; 140 141 //! Creates an Executor with 3 Arguments. 142 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 143 const MultiType& param2, 144 FunctionType functionType = FunctionMember) 145 : bRetVal(hasRetVal), paramCount(3), functionType(functionType) 146 { 147 this->defaultValue[0] = param0; 148 this->defaultValue[1] = param1; 149 this->defaultValue[2] = param2; 150 }; 151 152 //! Creates an Executor with 4 Arguments. 153 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 154 const MultiType& param2, const MultiType& param3, 155 FunctionType functionType = FunctionMember) 156 : bRetVal(hasRetVal), paramCount(4), functionType(functionType) 157 { 158 this->defaultValue[0] = param0; 159 this->defaultValue[1] = param1; 160 this->defaultValue[2] = param2; 161 this->defaultValue[3] = param3; 162 }; 163 164 //! Creates an Executor with 5 Arguments. 165 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 166 const MultiType& param2, const MultiType& param3, 167 const MultiType& param4, 168 FunctionType functionType = FunctionMember) 169 : bRetVal(hasRetVal), paramCount(5), functionType(functionType) 170 { 171 this->defaultValue[0] = param0; 172 this->defaultValue[1] = param1; 173 this->defaultValue[2] = param2; 174 this->defaultValue[3] = param3; 175 this->defaultValue[4] = param4; 176 }; 177 178 //! Creates an Executor with 6 Arguments. 179 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 180 const MultiType& param2, const MultiType& param3, 181 const MultiType& param4, const MultiType& param5, 182 FunctionType functionType = FunctionMember) 183 : bRetVal(hasRetVal), paramCount(6), functionType(functionType) 184 { 185 this->defaultValue[0] = param0; 186 this->defaultValue[1] = param1; 187 this->defaultValue[2] = param2; 188 this->defaultValue[3] = param3; 189 this->defaultValue[4] = param4; 190 this->defaultValue[5] = param5; 191 }; 192 193 //! Creates an Executor with 7 Arguments. 194 Executor(bool hasRetVal, const MultiType& param0, const MultiType& param1, 195 const MultiType& param2, const MultiType& param3, 196 const MultiType& param4, const MultiType& param5, 197 const MultiType& param6, 198 FunctionType functionType = FunctionMember) 199 : bRetVal(hasRetVal), paramCount(7), functionType(functionType) 200 { 201 this->defaultValue[0] = param0; 202 this->defaultValue[1] = param1; 203 this->defaultValue[2] = param2; 204 this->defaultValue[3] = param3; 205 this->defaultValue[4] = param4; 206 this->defaultValue[5] = param5; 207 this->defaultValue[6] = param6; 208 }; 209 210 protected: 211 const bool bRetVal; //!< True if the Executor has a return Value. 212 const unsigned int paramCount; //!< the count of parameters. 213 MultiType defaultValue[7]; //!< Default Values. 214 215 const FunctionType functionType; //!< What Type of Function it is. 80 216 }; 81 217 82 #include "executor/executor_functional.h"83 #define EXECUTOR_FUNCTIONAL_USE_CONST84 #include "executor/executor_functional.h"85 #define EXECUTOR_FUNCTIONAL_USE_STATIC86 #include "executor/executor_functional.h"87 88 218 #endif /* _EXECUTOR_H */ -
trunk/src/lib/util/executor/executor_xml.h
r8362 r9869 19 19 * What must be defined is a XML-root to search the ParameterName under an a Function to call. 20 20 */ 21 template<class T > class ExecutorXML : public Executor21 template<class T, class BaseClass = BaseObject> class ExecutorXML : public Executor<const TiXmlElement*> 22 22 { 23 24 23 public: 24 /** 25 25 * @brief Constructor of a ExecutorXML 26 27 28 29 30 ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const char*paramName)31 : Executor (MT_EXT1)32 33 PRINTF(4)("Loading %s from XML-element %p\n", paramName, root);26 * @param function a Function to call 27 * @param root The XML root to search paramName under 28 * @param paramName the ParameterName the search in root, and lookup the TiXmlElement from 29 */ 30 ExecutorXML(void(T::*function)(const TiXmlElement*), const TiXmlElement* root, const std::string& paramName) 31 : Executor<const TiXmlElement*>(false, MT_EXT1) 32 { 33 PRINTF(4)("Loading %s from XML-element %p\n", paramName.c_str(), root); 34 34 35 if (likely(root != NULL && paramName!= NULL))36 37 38 35 if (likely(root != NULL)) 36 this->element = root->FirstChildElement(paramName); 37 else 38 this->element = NULL; 39 39 40 this->functionPointer = function;41 this->functorType = Executor_Objective | Executor_NoLoadString;42 40 this->paramName = paramName; 41 this->functionPointer = function; 42 } 43 43 44 /** 45 * @brief clones an ExecutorXML, used to copy this Element. 46 * @returns a _new_ Copy of this Executor 47 */ 48 virtual Executor* clone () const 49 { 50 ExecutorXML<T>* executor = new ExecutorXML<T>(); 51 this->cloning(executor); 52 executor->functionPointer = this->functionPointer; 53 executor->element = this->element; 54 return executor; 55 } 44 /** 45 * @brief clones an ExecutorXML, used to copy this Element. 46 * @returns a _new_ Copy of this Executor 47 */ 48 virtual Executor<const TiXmlElement*>* clone () const 49 { 50 return new ExecutorXML<T>(functionPointer, element, paramName); 51 } 56 52 57 /** 58 * @brief executes the Command on BaseObject 59 * @param object the BaseObject to execute this Executor on 60 * @param loadString ignored in this case 61 */ 62 virtual void operator()(BaseObject* object, const SubString& = SubString()) const 63 { 64 if (object != NULL && this->element != NULL) 65 (dynamic_cast<T*>(object)->*(functionPointer))(this->element); 66 } 53 /** 54 * @brief executes the Command on BaseObject 55 * @param object the BaseObject to execute this Executor on 56 * @param element ignored in this case 57 */ 58 virtual void operator()(BaseObject* object, const TiXmlElement*& element) const 59 { 60 assert (object != NULL); 61 if (this->element != NULL) 62 (dynamic_cast<T*>(object)->*(functionPointer))(this->element); 63 } 67 64 68 virtual void operator()(BaseObject* object, int& count, void* values) const 69 { 70 PRINTF(1)("missuse of XML-operator, OR IMPLEMENT.\n"); 71 } 72 73 private: 74 /** 75 * @brief used for the copy-(Clone)-constructor 76 */ 77 ExecutorXML() : Executor() { }; 78 79 80 private: 81 void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called 82 const TiXmlElement* element; //!< The XML-element to call. 65 private: 66 void (T::*functionPointer)(const TiXmlElement*); //!< The functionPointer to the function to be called. 67 const TiXmlElement* element; //!< The XML-element to call. 68 std::string paramName; //!< The Name of the Parameter this Executor should call. 83 69 }; 84 70 -
trunk/src/lib/util/executor/functor_list.h
r9406 r9869 1 /*! 2 * @file functor_list.h 3 * all the Different types of Functions one can include by using a simple createExecutor call 4 * with a FunctionPointer as Argument 5 */ 1 6 /* 2 7 orxonox - the future of 3D-vertical-scrollers … … 8 13 the Free Software Foundation; either version 2, or (at your option) 9 14 any later version. 10 */11 12 /*!13 * @file functors_list.h14 * all the Different types of Functions one can include15 15 */ 16 17 /**18 useable FunctionParameters are:19 l_INT: int20 l_LONG: long21 l_SHORT: short22 l_FLOAT: float23 l_STRING: const std::string&24 l_XML_ELEM: TiXmlElement*25 */26 27 #ifndef __FUNCTOR_PARAMETERS__28 #define __FUNCTOR_PARAMETERS__29 30 //! defines the maximum count of arguments function pointers might have31 #define FUNCTOR_MAX_ARGUMENTS 732 #include "multi_type.h"33 34 35 #define l_BOOL_TYPE bool //!< The type of an BOOL36 #define l_BOOL_FUNC isBool //!< The function to call to parse BOOL37 #define l_BOOL_PARAM MT_BOOL //!< the type of the parameter BOOL38 #define l_BOOL_DEFAULT false //!< a default Value for an BOOL39 #define l_BOOL_DEFGRAB(i) this->defaultValue[i].getBool()40 41 #define l_INT_TYPE int //!< The type of an INT42 #define l_INT_FUNC isInt //!< The function to call to parse INT43 #define l_INT_PARAM MT_INT //!< the type of the parameter INT44 #define l_INT_DEFAULT 0 //!< a default Value for an INT45 #define l_INT_DEFGRAB(i) this->defaultValue[i].getInt()46 47 #define l_UINT_TYPE unsigned int //!< The type of an UINT48 #define l_UINT_FUNC isInt //!< The function to call to parse UINT49 #define l_UINT_PARAM MT_INT //!< the type of the parameter UINT50 #define l_UINT_DEFAULT 0 //!< a default Value for an UINT51 #define l_UINT_DEFGRAB(i) (unsigned int)this->defaultValue[i].getInt()52 53 #define l_LONG_TYPE long //!< The type of a LONG54 #define l_LONG_FUNC isInt //!< The function to parse a LONG55 #define l_LONG_PARAM MT_INT //!< the type of the parameter LONG56 #define l_LONG_DEFAULT 0 //!< a default Value for a LONG57 #define l_LONG_DEFGRAB(i) (long)this->defaultValue[i].getInt()58 59 // #define l_SHORT_TYPE short //!< The type of a SHORT60 // #define l_SHORT_FUNC atoi //!< The function to parse a SHORT61 // #define l_SHORT_NAME "short" //!< The name of a SHORT62 // #define l_SHORT_PARAM ParameterShort //!< the type of the parameter SHORT63 // #define l_SHORT_DEFAULT 0 //!< a default Value for a SHORT64 65 #define l_FLOAT_TYPE float //!< The type of a FLOAT66 #define l_FLOAT_FUNC isFloat //!< The function to parse a FLOAT67 #define l_FLOAT_PARAM MT_FLOAT //!< the type of the parameter FLOAT68 #define l_FLOAT_DEFAULT 0.0 //!< a default Value for a FLOAT69 #define l_FLOAT_DEFGRAB(i) this->defaultValue[i].getFloat()70 71 //#define l_VECTOR_TYPE const Vector& //!< The type of a VECTOR72 //#define l_VECTOR_FUNC isVector //!< The function to parse a VECTOR73 //#define l_VECTOR_NAME "Vector[x/y/z]" //!< The name of a VECTOR74 //#define l_VECTOR_DEFAULT Vector(0,0,0) //!< Default value for a VECTOR75 76 #define l_STRING_TYPE const std::string& //!< The type of a STRING77 #define l_STRING_FUNC isString //!< The function to parse a STRING78 #define l_STRING_PARAM MT_STRING //!< the type of the parameter STRING79 #define l_STRING_DEFAULT "" //!< a default Value for an STRING80 #define l_STRING_DEFGRAB(i) this->defaultValue[i].getString()81 82 #define l_XML_ELEM_TYPE const TiXmlElement* //!< The type of an XML_ELEM83 #define l_XML_ELEM_FUNC //!< The function to parse an XML_ELEM84 //#define l_XML_ELEM_PARAM Parameter //!< the type of the parameter XML_ELEM85 #define l_XML_ELEM_DEFAULT NULL //!< The dafault Value for an XML_ELEM86 87 #endif /* __FUNCTOR_PARAMETERS__ */88 16 89 17 90 18 #ifdef FUNCTOR_LIST 91 92 FUNCTOR_LIST(0)(); 19 FUNCTOR_LIST(0)(FUNCTOR_CALL_TYPE); 93 20 //! makes functions with one string 94 FUNCTOR_LIST(1)( l_STRING);21 FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, const std::string&); 95 22 //! makes functions with two strings 96 FUNCTOR_LIST(2)( l_STRING, l_STRING);23 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, const std::string&, const std::string&); 97 24 //! makes functions with three strings 98 FUNCTOR_LIST(3)( l_STRING, l_STRING, l_STRING);25 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, const std::string&, const std::string&, const std::string&); 99 26 //! makes functions with four strings 100 FUNCTOR_LIST(4)( l_STRING, l_STRING, l_STRING, l_STRING);27 FUNCTOR_LIST(4)(FUNCTOR_CALL_TYPE, const std::string&, const std::string&, const std::string&, const std::string&); 101 28 102 29 103 30 //! makes functions with one bool 104 FUNCTOR_LIST(1)( l_BOOL);31 FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, bool); 105 32 106 33 //! makes functions with one int 107 FUNCTOR_LIST(1)( l_INT);34 FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, int); 108 35 //! makes functions with two ints 109 FUNCTOR_LIST(2)( l_INT, l_INT);36 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, int, int); 110 37 //! makes functions with three ints 111 FUNCTOR_LIST(3)( l_INT, l_INT, l_INT);38 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, int, int, int); 112 39 //! makes functions with four ints 113 FUNCTOR_LIST(4)( l_INT, l_INT, l_INT, l_INT);40 FUNCTOR_LIST(4)(FUNCTOR_CALL_TYPE, int, int, int, int); 114 41 115 42 116 43 //! makes functions with one unsigned int 117 FUNCTOR_LIST(1)( l_UINT);44 FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, unsigned int); 118 45 //! makes functions with two unsigned ints 119 FUNCTOR_LIST(2)( l_UINT, l_UINT);46 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, unsigned int, unsigned int); 120 47 //! makes functions with three unsigned ints 121 FUNCTOR_LIST(3)( l_UINT, l_UINT, l_UINT);48 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, unsigned int, unsigned int, unsigned int); 122 49 //! makes functions with four unsigned ints 123 FUNCTOR_LIST(4)( l_UINT, l_UINT, l_UINT, l_UINT);50 FUNCTOR_LIST(4)(FUNCTOR_CALL_TYPE, unsigned int, unsigned int, unsigned int, unsigned int); 124 51 125 52 //! makes functions with one float 126 FUNCTOR_LIST(1)( l_FLOAT);53 FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, float); 127 54 //! makes functions with two floats 128 FUNCTOR_LIST(2)( l_FLOAT, l_FLOAT);55 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, float, float); 129 56 //! makes functions with three floats 130 FUNCTOR_LIST(3)( l_FLOAT, l_FLOAT, l_FLOAT);57 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, float, float, float); 131 58 //! makes functions with four floats 132 FUNCTOR_LIST(4)( l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);59 FUNCTOR_LIST(4)(FUNCTOR_CALL_TYPE, float, float, float, float); 133 60 //! makes functions with four floats 134 FUNCTOR_LIST(5)( l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT);61 FUNCTOR_LIST(5)(FUNCTOR_CALL_TYPE, float, float, float, float, float); 135 62 136 63 //! mixed values: 137 FUNCTOR_LIST(2)(l_STRING, l_INT); 138 FUNCTOR_LIST(2)(l_STRING, l_FLOAT); 139 FUNCTOR_LIST(2)(l_UINT, l_LONG); 140 FUNCTOR_LIST(2)(l_STRING, l_UINT); 64 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, const std::string&, bool); 65 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, const std::string&, int); 66 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, const std::string&, float); 67 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, unsigned int, long); 68 FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, const std::string&, unsigned int); 141 69 142 FUNCTOR_LIST(3)( l_STRING, l_FLOAT, l_UINT);143 FUNCTOR_LIST(4)( l_STRING, l_FLOAT, l_UINT, l_UINT);144 FUNCTOR_LIST(3)( l_STRING, l_INT, l_UINT);145 FUNCTOR_LIST(3)( l_STRING, l_UINT, l_UINT);70 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, const std::string&, float, unsigned int); 71 FUNCTOR_LIST(4)(FUNCTOR_CALL_TYPE, const std::string&, float, unsigned int, unsigned int); 72 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, const std::string&, int, unsigned int); 73 FUNCTOR_LIST(3)(FUNCTOR_CALL_TYPE, const std::string&, unsigned int, unsigned int); 146 74 147 FUNCTOR_LIST(5)( l_FLOAT, l_FLOAT, l_FLOAT, l_FLOAT, l_STRING);75 FUNCTOR_LIST(5)(FUNCTOR_CALL_TYPE, float, float, float, float, const std::string&); 148 76 149 77 #endif /* FUNCTOR_LIST */ -
trunk/src/lib/util/filesys/directory.cc
r8523 r9869 41 41 #include <sys/stat.h> 42 42 #include <dirent.h> 43 const char Directory::delimiter = '/'; 43 44 #else 44 45 #include <windows.h> 45 46 #include <winbase.h> 47 const char Direcotry::delimiter = '\\'; 46 48 #endif 47 49 … … 63 65 */ 64 66 Directory::Directory(const Directory& directory) 65 : File(directory)67 : File(directory) 66 68 { 67 69 this->_opened = directory._opened; … … 166 168 #endif 167 169 } 170 171 172 Directory Directory::operator+(const Directory& dir) const 173 { 174 return Directory(*this) += dir; 175 } 176 177 /** 178 * @param dir the Directory to append to this one (say this one is "/var", then dir can be "log") 179 * @returns The Directory appended by dir. 180 * 181 * @note the Directoy will again be closed even if it was opened previously! 182 */ 183 Directory& Directory::operator+=(const Directory& dir) 184 { 185 this->setFileName(this->name() + Directory::delimiter + dir.name()); 186 return *this; 187 } 188 189 /** 190 * @brief Traverses the Directory tree one step up. (Parent Directory) 191 * @returns a Reference to the Directory. 192 */ 193 Directory& Directory::operator--() 194 { 195 } 196 197 198 /** 199 * @brief Traverses the Directory tree one step up. (Parent Directory) 200 * @param int the PostFix iterator 201 * @returns a Reference to the Directory. 202 */ 203 Directory& Directory::operator--(int) 204 { 205 } 206 207 /** 208 * @returns The Parent Directory. 209 */ 210 Directory Directory::parentDir() const 211 { 212 213 } 214 215 File operator+(const Directory& dir, const File& file) 216 { 217 return File(dir.name() + Directory::delimiter + file.name()); 218 } -
trunk/src/lib/util/filesys/directory.h
r8333 r9869 29 29 #include <vector> 30 30 31 //! A Directory is a Special file, that contains multiple Files. 32 /** 33 * @example Correct usage 34 * Directory dir("/var/log"); 35 * dir.open(); 36 * if (dir.fileNameInDir("emerge.log")) 37 * { // do stuff; } 38 */ 31 39 class Directory : public File 32 40 { … … 41 49 bool create(); 42 50 51 Directory operator+(const Directory& dir) const; 52 Directory& operator+=(const Directory& dir); 53 Directory& operator--(); 54 Directory& operator--(int); 55 Directory parentDir() const; 56 57 43 58 /** @returns if the Directory was opened */ 44 59 bool isOpen() const { return this->_opened; } … … 50 65 const std::string& operator[](unsigned int fileNumber) const { return this->_fileNames[fileNumber]; }; 51 66 /** @returns a formated string containing the FileName, prepended with the directory-Name */ 52 std::string fileNameInDir(unsigned int fileNumber) const { return this->name() + "/"+ _fileNames[fileNumber]; };67 std::string fileNameInDir(unsigned int fileNumber) const { return this->name() + Directory::delimiter + _fileNames[fileNumber]; }; 53 68 /** @returns a File pointing to the File @param fileNumber the fileNumber (must not bigger than fileCount()) */ 54 69 File getFile(unsigned int fileNumber) const { return File(fileNameInDir(fileNumber)); }; 70 71 public: 72 static const char delimiter; //!< A Delimiter (*nix: '/', windows: '\\') 55 73 56 74 private: … … 58 76 std::vector<std::string> _fileNames; //!< The List of Files contained in the directory. (will be filled when open was called.) 59 77 }; 78 79 File operator+(const Directory& dir, const File& file); 60 80 61 81 #endif /* __DIRECTORY_H_ */ -
trunk/src/lib/util/filesys/file.cc
r8619 r9869 326 326 } 327 327 328 /** 329 * @brief converts an Absolute Filename to a Relative one 330 * @param absFileName the FileName to convert. The Relative path will be stored in absFileName. 331 */ 328 332 void File::absToRel(std::string& absFileName) 329 333 { -
trunk/src/lib/util/loading/dynamic_loader.cc
r9406 r9869 24 24 25 25 26 26 ObjectListDefinition(DynamicLoader); 27 27 28 28 /** … … 31 31 */ 32 32 DynamicLoader::DynamicLoader (const std::string& libName) 33 : Factory( NULL, CL_NULL)33 : Factory(libName) 34 34 { 35 this-> setClassID(CL_DYNAMIC_LOADER, "DynamicLoader");35 this->registerObject(this, DynamicLoader::_objectList); 36 36 37 37 this->handle = NULL; -
trunk/src/lib/util/loading/dynamic_loader.h
r7193 r9869 19 19 class DynamicLoader : public Factory 20 20 { 21 ObjectListDeclaration(DynamicLoader); 21 22 22 23 public: -
trunk/src/lib/util/loading/factory.cc
r9675 r9869 15 15 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING 16 16 17 #include " util/loading/factory.h"17 #include "factory.h" 18 18 #include "debug.h" 19 19 //#include "shell_command.h" 20 20 21 21 ObjectListDefinition(Factory); 22 22 23 23 //SHELL_COMMAND(create, Factory, fabricate); … … 28 28 * set everything to zero and define factoryName 29 29 */ 30 Factory::Factory (const std::string& factoryName, ClassIDclassID)31 : classID(classID), className(factoryName)30 Factory::Factory (const ClassID& classID) 31 : _classID(classID) 32 32 { 33 this->setClassID(CL_FACTORY, "Factory"); 34 this->setName(factoryName); 33 PRINTF(4)("Factory::create(%s::%d)\n", classID.name().c_str(), classID.id()); 34 //this->registerObject(this, Factory::_objectList); 35 this->setName(classID.name()); 35 36 36 if( Factory::factoryList == NULL) 37 Factory::factoryList = new std::list<Factory*>; 38 39 Factory::factoryList->push_back(this); 37 Factory::_factoryIDMap[classID] = this; 38 Factory::_factoryStringMap[classID.name()] = this; 40 39 } 41 40 42 /** @brief a reference to the First Factory */ 43 std::list<Factory*>* Factory::factoryList = NULL; 41 /** @brief A Map of all Factories ordered by ID. */ 42 Factory::FactoryIDMap Factory::_factoryIDMap; 43 44 /** @brief A Map of all Factories ordered by Name. */ 45 Factory::FactoryStringMap Factory::_factoryStringMap; 44 46 45 47 /** … … 48 50 Factory::~Factory () 49 51 { 50 // printf("%s\n", this->factoryName); 51 // Factory* tmpDel = this->next; 52 // this->next = NULL; 53 } 52 FactoryIDMap::iterator it = Factory::_factoryIDMap.find(this->_classID); 53 if (it != Factory::_factoryIDMap.end() && (*it).second == this) 54 Factory::_factoryIDMap.erase(it); 54 55 55 /** 56 * @brief deletes all the Factories. (cleanup) 57 */ 58 void Factory::deleteFactories() 59 { 60 if (Factory::factoryList != NULL) 61 { 62 while(!Factory::factoryList->empty()) 63 { 64 delete Factory::factoryList->front(); 65 Factory::factoryList->pop_front(); 66 } 67 delete Factory::factoryList; 68 Factory::factoryList = NULL; 69 } 56 FactoryStringMap::iterator stringIt = Factory::_factoryStringMap.find(this->_classID.name()); 57 if (stringIt != Factory::_factoryStringMap.end() && (*stringIt).second == this) 58 Factory::_factoryStringMap.erase(stringIt); 70 59 } 71 60 … … 74 63 * @returns true on match, false otherwise 75 64 */ 76 bool Factory::operator==( ClassIDclassID) const65 bool Factory::operator==(int classID) const 77 66 { 78 return (this-> classID == classID);67 return (this->_classID == classID); 79 68 } 80 69 81 /**82 * @brief Compares the Factories Name against a given ClassName83 * @param className the Name of the Class to Query84 * @returns true on match, false otherwise.85 */86 bool Factory::operator==(const char* className) const87 {88 return (className != NULL && this->className == className);89 }90 70 91 71 /** … … 96 76 bool Factory::operator==(const std::string& className) const 97 77 { 98 return (this-> className== className);78 return (this->_classID.name() == className); 99 79 } 100 80 … … 107 87 BaseObject* Factory::fabricate(const TiXmlElement* root) 108 88 { 109 assert (root != NULL && Factory::factoryList != NULL); 110 111 std::list<Factory*>::const_iterator factory; 112 for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++) 113 if (*(*factory) == root->Value()) 114 { 115 PRINTF(2)("Create a new Object of type %s\n", (*factory)->getCName()); 116 return (*factory)->fabricateObject(root); 117 } 118 119 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value()); 120 return NULL; 89 FactoryStringMap::const_iterator it = Factory::_factoryStringMap.find(root->Value()); 90 if (it != Factory::_factoryStringMap.end()) 91 { 92 PRINTF(2)("Create a new Object of type %s\n", (*it).second->getCName()); 93 return (*it).second->fabricateObject(root); 94 } 95 else 96 { 97 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value()); 98 return NULL; 99 } 121 100 } 122 101 … … 129 108 BaseObject* Factory::fabricate(const std::string& className) 130 109 { 131 if (Factory::factoryList == NULL) 110 FactoryStringMap::const_iterator it = Factory::_factoryStringMap.find(className); 111 if (it != Factory::_factoryStringMap.end()) 112 { 113 PRINTF(2)("Create a new Object of type %s\n", (*it).second->getCName()); 114 return (*it).second->fabricateObject(NULL); 115 } 116 else 117 { 118 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str()); 132 119 return NULL; 133 134 std::list<Factory*>::const_iterator factory; 135 for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++) 136 if (*(*factory) == className) 137 { 138 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName()); 139 return (*factory)->fabricateObject(NULL); 140 } 141 PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className.c_str()); 142 return NULL; 120 } 143 121 } 144 145 122 146 123 /** … … 149 126 * @returns a new Object of Type classID on match, NULL otherwise 150 127 */ 151 BaseObject* Factory::fabricate( ClassIDclassID)128 BaseObject* Factory::fabricate(const ClassID& classID) 152 129 { 153 if (Factory::factoryList == NULL) 130 FactoryIDMap::const_iterator it = Factory::_factoryIDMap.find(classID); 131 if (it != Factory::_factoryIDMap.end()) 132 { 133 PRINTF(4)("Create a new Object of type %s\n", (*it).second->getCName()); 134 return (*it).second->fabricateObject(NULL); 135 } 136 else 137 { 138 PRINTF(2)("Could not Fabricate an Object of ClassID '%d'\n", classID.id()); 154 139 return NULL; 140 } 141 } 155 142 156 std::list<Factory*>::const_iterator factory;157 for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)158 if (*(*factory) == classID)159 {160 PRINTF(4)("Create a new Object of type %s\n", (*factory)->getCName());161 return (*factory)->fabricateObject(NULL);162 143 163 } 164 PRINTF(2)("Could not Fabricate an Object of ClassID '0x%h'\n", classID); 165 return NULL; 144 /** 145 * @brief print out some nice litte debug information about the Factory. 146 */ 147 void Factory::debug() const 148 { 149 PRINTF(0)("Factory of class '%s' with ClassID: %d\n", this->_classID.name().c_str(), this->_classID.id()); 166 150 } 151 152 /** 153 * @brief Prints out some nice Debug information about all factories 154 */ 155 void Factory::debugAll() 156 { 157 PRINTF(0)("Debugging all %d Factories\n", Factory::_factoryStringMap.size()); 158 Factory::FactoryStringMap::const_iterator it; 159 for (it = Factory::_factoryStringMap.begin(); it != Factory::_factoryStringMap.end(); ++it) 160 (*it).second->debug(); 161 } -
trunk/src/lib/util/loading/factory.h
r8148 r9869 20 20 21 21 22 #ifndef _ FACTORY_H23 #define _ FACTORY_H22 #ifndef __FACTORY_H 23 #define __FACTORY_H 24 24 25 25 class BaseObject; … … 27 27 #include "parser/tinyxml/tinyxml.h" 28 28 #include "base_object.h" 29 #include <vector> 30 #include <list> 29 #include <map> 31 30 32 31 /** … … 34 33 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file) 35 34 */ 36 #define CREATE_FACTORY(CLASS_NAME , CLASS_ID) \37 tFactory<CLASS_NAME> * global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME, CLASS_ID)35 #define CREATE_FACTORY(CLASS_NAME) \ 36 tFactory<CLASS_NAME> global_##CLASS_NAME##_Factory = tFactory<CLASS_NAME>(CLASS_NAME::staticClassID()) 38 37 39 38 //! The Factory is a loadable object handler 40 class Factory : public BaseObject { 41 42 public: 39 class Factory : public BaseObject 40 { 41 //! Declare the ObjectList at the BaseObject List 42 ObjectListDeclaration(Factory); 43 public: 43 44 virtual ~Factory (); 44 45 45 static void deleteFactories(); 46 static BaseObject* fabricate(const std::string& className); 47 static BaseObject* fabricate(const ClassID& classID); 48 static BaseObject* fabricate(const TiXmlElement* root); 46 49 47 static BaseObject* fabricate(const std::string& className); 48 static BaseObject* fabricate(ClassID classID); 49 static BaseObject* fabricate(const TiXmlElement* root = NULL); 50 bool operator==(int classID) const; 51 bool operator==(const std::string& className) const; 52 /** @param classID the ID to compare @returns true if the ID's match */ 53 bool operator==(const ClassID& classID) const { return _classID == classID; }; 50 54 51 55 52 bool operator==(ClassID classID) const; 53 bool operator==(const char* className) const; 54 bool operator==(const std::string& className) const; 56 void debug() const; 57 static void debugAll(); 55 58 56 protected: 57 Factory (const std::string& factoryName, ClassID classID); 58 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0; 59 protected: 60 Factory (const ClassID& id); 61 /** 62 * @brief The core function of the Factory. Creates objects of the Factories Type. 63 * @param root The TiXmlElement of the Factory. 64 * @returns the created Object in BaseType* format. 65 */ 66 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0; 59 67 60 protected: 61 const ClassID classID; //!< The Class-Identifyer of the Factory. 62 const std::string className; //!< The name of the Class. 63 static std::list<Factory*>* factoryList; //!< List of Registered Factories 68 private: 69 //! Copy Constructor is hidden. 70 Factory (const Factory&) {}; 71 72 protected: 73 /** The Type of the FactoryMap that is sorted by ID */ 74 typedef std::map<const ClassID, Factory*> FactoryIDMap; 75 /** The Type of the FactoryMap that is sorted by Name */ 76 typedef std::map<std::string, Factory*> FactoryStringMap; 77 78 const ClassID _classID; //!< The Class-Identifyer of the Factory. 79 static FactoryIDMap _factoryIDMap; //!< List of Registered Factories 80 static FactoryStringMap _factoryStringMap; //!< List of Registered Factories 64 81 }; 65 82 … … 70 87 template<class T> class tFactory : public Factory 71 88 { 72 public: 73 /** 74 * @brief creates a new type Factory to enable the loading of T 75 * @param factoryName the Name of the Factory to load. 76 * @param classID the ID of the Class to be created. 77 */ 78 tFactory (const char* factoryName, ClassID classID) 79 : Factory(factoryName, classID) 89 public: 90 /** 91 * @brief creates a new type Factory to enable the loading of T 92 * @param classID the ID of the Class to be created. 93 */ 94 tFactory (const ClassID& classID) 95 : Factory(classID) 80 96 { } 97 /** 98 * @brief copy constructor 99 * @param factory the Factory to copy 100 */ 101 tFactory (const tFactory& factory) : Factory(factory._classID) {}; 81 102 82 private: 83 /** 84 * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) 85 * @param root the TiXmlElement T should load parameters from. 86 * @return the newly fabricated T. 87 */ 88 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const 89 { 90 return new T(root); 91 } 103 /** 104 * @brief fabricates an Object of type T, with the constructor T::T(const TiXmlElemnt*) 105 * @param root the TiXmlElement T should load parameters from. 106 * @return the newly fabricated T. 107 */ 108 virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const 109 { 110 return new T(root); 111 } 92 112 }; 93 113 -
trunk/src/lib/util/loading/game_loader.cc
r9110 r9869 20 20 #include "game_loader.h" 21 21 #include "util/loading/load_param.h" 22 23 #include " shell_command.h"22 #include "util/loading/resource_manager.h" 23 #include "debug.h" 24 24 #include "campaign.h" 25 25 26 #include "util/loading/resource_manager.h"27 28 26 #include "key_mapper.h" 29 27 30 31 32 SHELL_COMMAND(quit, GameLoader, stop) 33 ->describe("quits the game") 34 ->setAlias("orxoquit"); 35 28 ObjectListDefinition(GameLoader); 36 29 37 30 GameLoader* GameLoader::singletonRef = NULL; … … 43 36 GameLoader::GameLoader () 44 37 { 45 this-> setClassID(CL_GAME_LOADER, "GameLoader");38 this->registerObject(this, GameLoader::_objectList); 46 39 this->setName("GameLoader"); 47 40 this->bRun = true; … … 57 50 delete this->currentCampaign; 58 51 this->currentCampaign = NULL; 59 52 60 53 GameLoader::singletonRef = NULL; 61 54 } … … 90 83 { 91 84 ErrorMessage errorCode; 92 std::string campaignName = Resource Manager::getFullName(fileName);85 std::string campaignName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 93 86 if (!campaignName.empty()) 94 87 { … … 110 103 { 111 104 ErrorMessage errorCode; 112 std::string campaignName = Resource Manager::getFullName(fileName);105 std::string campaignName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 113 106 if (!campaignName.empty()) 114 107 { -
trunk/src/lib/util/loading/game_loader.h
r7868 r9869 38 38 class GameLoader : public EventListener 39 39 { 40 public: 40 ObjectListDeclaration(GameLoader); 41 public: 41 42 virtual ~GameLoader (); 42 43 /** this class is a singleton class @returns an instance of itself */ -
trunk/src/lib/util/loading/load_param.cc
r9406 r9869 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING 17 17 18 #include "util/loading/load_param.h" 19 #include "load_param_description.h" 20 21 #include <stdarg.h> 22 18 #include "load_param.h" 19 #include "load_param_class_description.h" 20 #include "compiler.h" 21 #include "debug.h" 23 22 /** 24 * Constructs a new LoadParameter23 * @brief Constructs a new LoadParameter 25 24 * @param root the XML-element to load this Parameter from 26 25 * @param paramName the Parameter to load 27 * @param object the BaseObject, to load this parameter on to (will be cast to executor's Parameter) 28 * @param executor the Executor, that executes the loading procedure. 26 * @param inLoadCycle If we are in a LoadCycle (loading differs.). 29 27 */ 30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle)31 : object(object), paramName(paramName)28 LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle) 29 : paramName(paramName), inLoadCycle(inLoadCycle) 32 30 { 33 this->inLoadCycle = inLoadCycle;34 35 31 // determin the LoadString. 36 32 if (likely(!inLoadCycle)) … … 40 36 else 41 37 this->loadElem = NULL; 38 } 42 39 43 // set the Executor.44 this->executor = executor;45 40 46 //if (this->executor) 47 // this->executor->setName(paramName); 41 /** 42 * @param classID the ID of the class. This is needed to identify into what class this Parameter belongs. 43 * @param descriptionText The text to set as a description for this Parameter 44 * @returns a pointer to itself. 45 */ 46 void LoadParamBase::describe(const ClassID& classID, const std::string& descriptionText) 47 { 48 PRINTF(5)("Describing Class '%s'(id:%d) Parameter '%s': description '%s'\n", 49 classID.name().c_str(), classID.id(), paramName.c_str(), descriptionText.c_str()); 50 51 if (LoadParamClassDescription::descriptionsCaptured()) 52 LoadParamClassDescription::describeClass(classID, paramName, descriptionText); 48 53 } 49 54 50 55 /** 51 * This is a VERY SPECIAL deconsrtuctor. 52 * It is made, so that it loads the Parameters on destruction. 53 * meaning, if an Executor a valid Object exist, and all 54 * Execution-Conditions are met, they are executed here. 56 * @brief sets the Values of the Description to a usefull text. 55 57 */ 56 CLoadParam::~CLoadParam()58 void LoadParamBase::setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal) 57 59 { 58 if (likely(this->executor != NULL)) 59 { 60 std::string loadString = ""; 61 if (this->loadElem != NULL && this->loadElem->ToText()) 62 loadString = this->loadElem->Value(); 63 if (likely(this->object != NULL) && 64 ( !loadString.empty() || 65 ((this->executor->getType() & Executor_NoLoadString) == Executor_NoLoadString))) 66 { 67 PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName()); 68 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\')); 69 } 70 delete this->executor; 71 } 60 if(LoadParamClassDescription::descriptionsCaptured()) 61 LoadParamClassDescription::setValuesOf(classID, paramName, paramCount, defaultValues, retVal); 72 62 } 73 74 /**75 * @brief set the default values of the executor76 * @param value0 the first default value77 * @param value1 the second default value78 * @param value2 the third default value79 * @param value3 the fourth default value80 * @param value4 the fifth default value81 */82 CLoadParam& CLoadParam::defaultValues(const MultiType& value0, const MultiType& value1,83 const MultiType& value2, const MultiType& value3,84 const MultiType& value4)85 {86 assert(this->executor != NULL);87 this->executor->defaultValues(value0, value1, value2, value3, value4);88 89 return *this;90 }91 92 93 94 /**95 * @param descriptionText The text to set as a description for this Parameter96 * @returns a pointer to itself.97 */98 CLoadParam& CLoadParam::describe(const std::string& descriptionText)99 {100 if (LoadClassDescription::parametersDescription && this->paramDesc && this->paramDesc->getDescription().empty())101 {102 this->paramDesc->setDescription(descriptionText);103 }104 return *this;105 }106 107 // const LoadParamDescription* LoadParamDescription::getClass(const char* className)108 // {109 // tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();110 // LoadClassDescription* enumClassDesc = iterator->firstElement();111 // while (enumClassDesc)112 // {113 // if (!strcmp(enumClassDesc->className, classNameBegin, className))114 // {115 // delete iterator;116 // return enumClassDesc;117 // }118 // enumClassDesc = iterator->nextElement();119 // }120 // delete iterator;121 //122 // return NULL;123 // }124 125 126 127 128 /*129 * @param object The object this Parameter is loaded too.130 * @param root: the XML-element to load this option from.131 * @param paramName: The name of the parameter loaded.132 * @param paramCount: how many parameters this loading-function takes133 * @param multi: if false LoadParam assumes only one occurence of this parameter in root, if true it assumes multiple occurences.134 * @param ...: the parameter information (1. Parameter, 2. Default Value for the Parameter, ...)135 */136 /*LoadParam::LoadParam(const TiXmlElement* root, BaseObject* object, const char* paramName,137 int paramCount, bool multi, const void* pointerToParam, ...)138 {139 this->setClassID(CL_LOAD_PARAM, "LoadParam");140 this->executor = NULL;141 142 this->loadString = NULL;143 this->pointerToParam = pointerToParam;144 145 if (paramCount == 0 || this->pointerToParam != NULL)146 this->loadString = "none";147 else148 {149 if (likely(!multi))150 this->loadString = grabParameter(root, paramName);151 else152 {153 if (!strcmp(root->Value(), paramName))154 {155 const TiXmlNode* val = root->FirstChild();156 if( val->ToText())157 this->loadString = val->Value();158 }159 }160 }161 162 this->paramDesc = NULL;163 if (LoadClassDescription::parametersDescription)164 {165 // locating the class166 this->classDesc = LoadClassDescription::addClass(object->getClassCName());167 168 if ((this->paramDesc = this->classDesc->addParam(paramName)) != NULL)169 {170 171 this->paramDesc->paramCount = paramCount;172 this->paramDesc->types = new int[paramCount];173 this->paramDesc->defaultValues = new char*[paramCount];174 175 va_list types;176 va_start (types, pointerToParam);177 char defaultVal[512];178 for(int i = 0; i < paramCount; i++)179 {180 defaultVal[0] = '\0';181 // parameters parsed182 int tmpType = va_arg (types, int);183 this->paramDesc->types[i] = tmpType;184 switch (tmpType)185 {186 case MT_INT:187 sprintf(defaultVal, "%d", va_arg(types, int));188 break;189 // case MT_LONG:190 // sprintf(defaultVal, "%0.3f", va_arg(types, l_LONG_TYPE));191 // break;192 case MT_FLOAT:193 sprintf(defaultVal, "%0.3f", va_arg(types, double));194 break;195 case MT_STRING:196 sprintf(defaultVal, "%s", va_arg(types, l_STRING_TYPE));197 break;198 case MT_EXT1:199 sprintf(defaultVal, "");200 break;201 }202 this->paramDesc->defaultValues[i] = new char[strlen(defaultVal)+1];203 strcpy(this->paramDesc->defaultValues[i], defaultVal);204 }205 va_end(types);206 207 int argCount = 0;208 }209 }210 }*/211 212 213 214 215 216 217 218 219 63 220 64 … … 227 71 * @returns the Value of the parameter if found, NULL otherwise 228 72 */ 229 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName)73 std::string LoadParamBase::grabParameter(const TiXmlElement* root, const std::string& parameterName) 230 74 { 231 const TiXmlElement* element; 232 const TiXmlNode* node; 233 234 if (root == NULL) 235 return ""; 236 237 element = root->FirstChildElement( parameterName); 238 if( element == NULL) return ""; 239 240 node = element->FirstChild(); 241 while( node != NULL) 75 const TiXmlElement* const element = grabParameterElement(root, parameterName); 76 if (element != NULL) 77 return element->Value(); 78 else 242 79 { 243 if( node->ToText()) return node->Value();244 node = node->NextSibling();80 static std::string empty(""); 81 return empty; 245 82 } 246 return "";247 83 } 248 84 … … 252 88 * @returns the Element of the parameter if found, NULL otherwise 253 89 */ 254 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName)90 const TiXmlElement* LoadParamBase::grabParameterElement(const TiXmlElement* root, const std::string& parameterName) 255 91 { 256 92 const TiXmlElement* element; … … 271 107 return NULL; 272 108 } 273 274 275 -
trunk/src/lib/util/loading/load_param.h
r8048 r9869 22 22 #define _LOAD_PARAM_H 23 23 24 #include "base_object.h" 24 #include "util/executor/executor_substring.h" 25 #include "util/executor/executor_member.h" 26 #include "util/executor/functor_member.h" 25 27 26 #include "executor/executor.h" 27 #include "executor/executor_xml.h" 28 #include "parser/tinyxml/tinyxml.h" 28 29 29 30 // Forward Declaration // 30 31 class LoadClassDescription; 31 32 class LoadParamDescription; 32 class MultiType; 33 33 class TiXmlElement; 34 34 35 35 /** 36 36 * Loads a Parameter from ROOT named PARAMETER_NAME 37 * onto OBJECT of CLASS, trough theFUNCTION37 * onto OBJECT of CLASS, trough FUNCTION 38 38 * @param ROOT the TiXmlElement to load the Parameter from 39 39 * @param PARAMETER_NAME the Name of the Parameter to load … … 43 43 */ 44 44 #define LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 45 CLoadParam (ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), false)45 CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), false) 46 46 47 /** 48 * @brief Does essentially the same as LoadParam, but within a Cycle in an ordered fashion. 49 * 50 * This Function looks in each Element, if the PARAMETER_NAME matches, and loads onto OBJECT 51 * of CLASS the ROOT through FUNCTION 52 * 53 * @see LoadParam(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) 54 */ 47 55 #define LoadParam_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 48 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS>(&CLASS::FUNCTION), true) 49 50 #define LoadParamXML(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 51 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), false) 52 53 #define LoadParamXML_CYCLE(ROOT, PARAMETER_NAME, OBJECT, CLASS, FUNCTION) \ 54 CLoadParam(ROOT, PARAMETER_NAME, OBJECT, new ExecutorXML<CLASS>(&CLASS::FUNCTION, ROOT, PARAMETER_NAME), true) 55 56 CLoadParam<CLASS>(ROOT, PARAMETER_NAME, OBJECT, createExecutor<CLASS, CLASS>(&CLASS::FUNCTION), true) 56 57 57 58 /** … … 78 79 } 79 80 81 80 82 /************************** 81 83 **** REAL DECLARATIONS **** 82 84 **************************/ 83 //! abstract Base class for a Loadable parameter84 class CLoadParam : public BaseObject85 //!< A BaseClass for all LoadParam's. 86 class LoadParamBase 85 87 { 86 public: 87 CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false); 88 virtual ~CLoadParam(); 88 protected: 89 LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle = false); 89 90 90 CLoadParam& describe(const std::string& descriptionText); 91 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 92 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 93 const MultiType& value4 = MT_NULL); 94 CLoadParam& attribute(const std::string& attributeName, const Executor& executor); 91 protected: 92 void describe(const ClassID& classID, const std::string& descriptionText); 93 void setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal = false); 94 95 public: 96 static std::string grabParameter(const TiXmlElement* root, const std::string& parameterName); 97 static const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName); 98 99 protected: 100 const std::string paramName; //!< The Name of the Parameter this LoadParams applies to. 101 bool inLoadCycle; //!< If the Parameter is in a LoadCycle. 102 103 const TiXmlElement* loadElem; //!< The Element to load. 104 }; 95 105 96 106 97 private: 98 bool inLoadCycle; 99 Executor* executor; 100 BaseObject* object; 101 const std::string paramName; 107 //! The Loading Class of the LoadParam, that acctually executes the loading process. 108 template <class OperateClass> class CLoadParam : public LoadParamBase 109 { 110 public: 111 /** 112 * @brief generates a LoadParam based on: 113 * @param root the Root Element to load onto the object. @param paramName the Parameter name that is loaded. 114 * @param object the Object to apply the changes on. @param executor the Functional Object, that actually executes the function Call. 115 * @param inLoadCycle If we are inside of a loading cycle. (Loading will be different here) 116 */ 117 CLoadParam(const TiXmlElement* root, const std::string& paramName, OperateClass* object, Executor<const SubString, OperateClass>* executor, bool inLoadCycle = false) 118 : LoadParamBase(root, paramName, inLoadCycle) 119 { 120 assert (executor != NULL); 121 this->object = object; 122 this->executor = executor; 123 } 124 virtual ~CLoadParam() 125 { 126 std::string loadString; 127 if (this->loadElem != NULL && this->loadElem->ToText()) 128 { 129 loadString = this->loadElem->Value(); 130 if (!loadString.empty()) 131 { 132 /* PRINTF(4)("Loading value '%s' with Parameters '%s' onto: %s::%s\n", 133 this->paramName.c_str(), loadString.c_str(), this->object->getClassCName(), this->object->getCName());*/ 134 (*this->executor)(this->object, SubString(loadString, ",", SubString::WhiteSpaces, false, '\\')); 135 } 136 } 137 this->setDescriptionValues(OperateClass::staticClassID(), executor->getParamCount(), executor->getDefaultValues(), executor->hasRetVal()); 138 delete this->executor; 139 } 140 /** 141 * @brief set the default values of the executor 142 * @param value0 the first default value @param value1 the second default value 143 * @param value2 the third default value @param value3 the fourth default value 144 * @param value4 the fifth default value 145 */ 146 CLoadParam& defaultValues(const MultiType& value0 = MT_NULL, const MultiType& value1 = MT_NULL, 147 const MultiType& value2 = MT_NULL, const MultiType& value3 = MT_NULL, 148 const MultiType& value4 = MT_NULL) 149 { this->executor->defaultValues(value0, value1, value2, value3, value4); return *this; }; 150 //! Describes a LoadParam 151 CLoadParam& describe(const std::string& descriptionText) { LoadParamBase::describe(OperateClass::staticClassID(), descriptionText); return *this; }; 152 // CLoadParam& attribute(const std::string& attributeName, const Executor<SubString>& executor); 102 153 103 LoadClassDescription* classDesc; //!< The LoadClassDescription of this CLoadParameter 104 LoadParamDescription* paramDesc; //!< The LoadParameterDescription of this LoadParameter 105 const TiXmlElement* loadElem; //!< The Element to load. 106 const void* pointerToParam; //!< A Pointer to a Parameter. 107 108 MultiType* defaultValue; 154 private: 155 Executor<const SubString, OperateClass>* executor; //!< The Executor, that actually executes the Loading process. 156 OperateClass* object; //!< The Object this LoadParam operates on. 109 157 }; 110 158 111 // helper function112 113 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);114 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);115 116 159 #endif /* _LOAD_PARAM_H */ -
trunk/src/lib/util/loading/load_param_description.cc
r8362 r9869 17 17 18 18 #include "multi_type.h" 19 #include <stdarg.h>20 19 #include "debug.h" 21 20 22 21 /** 22 * @brief Creates a Description of a LoadParam 23 23 * @param paramName the name of the parameter to load 24 24 */ 25 25 LoadParamDescription::LoadParamDescription(const std::string& paramName) 26 { 27 this->types = NULL; 28 this->defaultValues = NULL; 29 this->paramName = paramName; 30 } 31 32 /** 33 * removes all the alocated memory 34 */ 35 LoadParamDescription::~LoadParamDescription() 36 { 37 if (this->defaultValues != NULL) 38 { 39 for(int i = 0; i < this->paramCount; i++) 40 { 41 delete[] this->defaultValues[i]; 42 } 43 } 44 45 delete[] this->types; 46 delete[] this->defaultValues; 47 } 26 : _name(paramName), _parameterCount(0) 27 { } 48 28 49 29 /** … … 52 32 void LoadParamDescription::setDescription(const std::string& descriptionText) 53 33 { 54 this-> description = descriptionText;34 this->_description = descriptionText; 55 35 } 56 36 57 37 /** 58 * prints out this parameter, its input method and the description (if availiable) 38 * @brief sets the Values of the LoadParam in the Description. 39 * @param paramCount the count of arguments the underlying paramDescription takes. 40 * @param defaultValues the default Values the underlying parameter takes. 41 * @param retVal if the underlying parameter has a return value 59 42 */ 60 void LoadParamDescription::print() const 43 void LoadParamDescription::setValues(unsigned int paramCount, 44 const MultiType* const defaultValues, 45 bool retVal) 61 46 { 62 PRINT(3)(" <%s>", this->paramName.c_str());63 for ( int i = 0; i < this->paramCount; i++)47 this->_parameterCount = paramCount; 48 for (unsigned int i = 0; i < paramCount; ++i) 64 49 { 65 if (i > 0) 66 PRINT(3)(","); 67 // FIXME 68 // switch (this->types[i]) 69 // { 70 // default: 71 // PRINTF(3)("none"); 72 // break; 73 // case ParameterBool: 74 // PRINT(3)("bool"); 75 // break; 76 // case ParameterChar: 77 // PRINT(3)("char"); 78 // break; 79 // case ParameterString: 80 // PRINT(3)("string"); 81 // break; 82 // case ParameterInt: 83 // PRINT(3)("int"); 84 // break; 85 // case ParameterUInt: 86 // PRINT(3)("Uint"); 87 // break; 88 // case ParameterFloat: 89 // PRINT(3)("float"); 90 // break; 91 // case ParameterLong: 92 // PRINT(3)("long"); 93 // break; 94 // case ParameterXML: 95 // PRINT(3)("XML"); 96 // break; 97 // } 50 this->_defaultValues.push_back(defaultValues[i].getString()); 51 this->_types.push_back(MultiType::MultiTypeToString(defaultValues[i].getType())); 98 52 } 99 PRINT(3)("</%s>", this->paramName.c_str());100 if (!this->description.empty())101 PRINT(3)(" -- %s", this->description.c_str());102 // default values103 if (this->paramCount > 0)104 {105 PRINT(3)(" (Default: ");106 for (int i = 0; i < this->paramCount; i++)107 {108 if (i > 0)109 PRINT(3)(", ");110 if (this->types[i] & MT_STRING)111 { // leave brackets !!112 PRINT(3)("\"%s\"", this->defaultValues[i]);113 }114 else115 {116 PRINT(3)("%s", this->defaultValues[i]);117 }118 }119 PRINT(3)(")");120 }121 PRINT(3)("\n");122 }123 53 124 /**125 * A list, that holds all the classes that are loadable (classes not objects!!)126 */127 std::list<LoadClassDescription*>* LoadClassDescription::classList = NULL;128 129 /**130 * if the description of Parameters should be executed131 */132 bool LoadClassDescription::parametersDescription = false;133 134 /**135 * @param className the name of the class to be loadable136 */137 LoadClassDescription::LoadClassDescription(const std::string& className)138 {139 this->className = className;140 141 if (LoadClassDescription::classList == NULL)142 LoadClassDescription::classList = new std::list<LoadClassDescription*>;143 144 LoadClassDescription::classList->push_back(this);145 }146 147 /**148 * deletes a classDescription (deletes all the parameterDescriptions as well149 */150 LoadClassDescription::~LoadClassDescription()151 {152 std::list<LoadParamDescription*>::iterator it = this->paramList.begin();153 while (!this->paramList.empty())154 {155 delete this->paramList.front();156 this->paramList.pop_front();157 }158 }159 160 void LoadClassDescription::deleteAllDescriptions()161 {162 if (LoadClassDescription::classList != NULL)163 {164 while (!LoadClassDescription::classList->empty())165 {166 delete LoadClassDescription::classList->front();167 LoadClassDescription::classList->pop_front();168 }169 delete LoadClassDescription::classList;170 }171 LoadClassDescription::classList = NULL;172 54 } 173 55 174 56 175 57 /** 176 * adds a class to the list of loadable classes 177 * @param className The name of the class to add 178 179 this function searches for the className string, and if found just returns the appropriate Class. 180 Otherwise it returns a new classDescription 58 * @brief prints out this parameter, its input method and the description (if availiable) 59 * @param stream the stream to print to. 60 * @param withComments if the comments should be appended. 181 61 */ 182 LoadClassDescription* LoadClassDescription::addClass(const std::string& className) 62 void LoadParamDescription::print(FILE* stream, bool withComments) const 183 63 { 184 if (LoadClassDescription::classList != NULL) 64 fprintf(stream, " <%s>", this->_name.c_str()); 65 for (unsigned int i = 0; i < this->_parameterCount; i++) 185 66 { 186 std::list<LoadClassDescription*>::iterator it = LoadClassDescription::classList->begin(); 187 while (it != LoadClassDescription::classList->end()) 67 if (i > 0) 68 fprintf(stream, ","); 69 fprintf(stream, "%s", this->_types[i].c_str()); 70 } 71 fprintf(stream, "</%s>", this->_name.c_str()); 72 // here the comments are printed out. 73 if (withComments) 74 { 75 if (!this->_description.empty()) 76 fprintf(stream, " <!-- %s", this->_description.c_str()); 77 // default values 78 if (this->_parameterCount > 0) 188 79 { 189 if ((*it)->className == className) 80 fprintf(stream, " (Default: "); 81 for (unsigned int i = 0; i < this->_parameterCount; i++) 190 82 { 191 return (*it); 83 if (i > 0) 84 fprintf(stream, ", "); 85 if (this->_types[i] == "string") 86 { // leave brackets !! 87 fprintf(stream, "\"%s\"", this->_defaultValues[i].c_str()); 88 } 89 else 90 { 91 fprintf(stream, "%s", this->_defaultValues[i].c_str()); 92 } 192 93 } 193 it++;94 fprintf(stream, ")"); 194 95 } 96 if (!this->_description.empty() || this->_parameterCount > 0) 97 fprintf(stream, " -->"); 195 98 } 196 return new LoadClassDescription(className);99 fprintf(stream, "\n"); 197 100 } 198 101 199 /**200 * does the same as addClass(const std::string& className), but with params201 * @param paramName the name of the parameter to add.202 */203 LoadParamDescription* LoadClassDescription::addParam(const std::string& paramName)204 {205 std::list<LoadParamDescription*>::iterator it = this->paramList.begin();206 while (it != this->paramList.end())207 {208 if ((*it)->paramName == paramName)209 {210 return NULL;211 }212 it++;213 }214 102 215 LoadParamDescription* newParam = new LoadParamDescription(paramName);216 217 this->paramList.push_back(newParam);218 return newParam;219 }220 221 /**222 * prints out all loadable Classes, and their parameters223 * @param fileName prints the output to a File224 * @todo implement it225 */226 void LoadClassDescription::printAll(const std::string& fileName)227 {228 PRINT(3)("===============================================================\n");229 PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");230 if (LoadClassDescription::classList != NULL)231 {232 std::list<LoadClassDescription*>::iterator classDesc = LoadClassDescription::classList->begin();233 while (classDesc != LoadClassDescription::classList->end())234 {235 PRINT(3)("<%s>\n", (*classDesc)->className.c_str());236 std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin();237 while (param != (*classDesc)->paramList.end())238 {239 (*param)->print();240 param++;241 }242 PRINT(3)("</%s>\n\n", (*classDesc)->className.c_str());243 classDesc++;244 }245 }246 else247 PRINT(3)("no Classes defined so far\n");248 PRINT(3)("===============================================================\n");249 }250 251 /**252 * searches for classes, which beginn with classNameBegin253 * @param classNameBegin the beginning string of a Class254 * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,255 * !! The strings MUST NOT be deleted !!256 */257 std::list<std::string> LoadClassDescription::searchClassWithShort(const std::string& classNameBegin)258 {259 /// FIXME260 // NOT USED261 /* unsigned int searchLength = strlen(classNameBegin);262 std::list<const std::string&> retVal;263 264 tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();265 LoadClassDescription* enumClassDesc = iterator->firstElement();266 while (enumClassDesc)267 {268 if (strlen(enumClassDesc->className)>searchLength+1 &&269 !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))270 {271 retVal->add(enumClassDesc->className);272 }273 enumClassDesc = iterator->nextElement();274 }275 delete iterator;276 277 return retVal;*/278 std::list<std::string> a;279 return a;280 } -
trunk/src/lib/util/loading/load_param_description.h
r7221 r9869 15 15 16 16 /*! 17 * @file load_param .h17 * @file load_param_description.h 18 18 * A Class and macro-functions, that makes our lives easy to load-in parameters 19 19 */ … … 22 22 #define _LOAD_PARAM_DESCRIPTION_H 23 23 24 #include "base_object.h"25 #include < list>24 #include <vector> 25 #include <string> 26 26 27 27 // Forward Declaration // … … 34 34 class LoadParamDescription 35 35 { 36 friend class LoadParam;37 friend class LoadClassDescription;38 36 public: 39 LoadParamDescription(const std::string& paramName); 40 ~LoadParamDescription(); 37 LoadParamDescription(const std::string& paramName = ""); 38 39 //! Compares a LoadParamDescription with a String. 40 bool operator==(const std::string& paramName) const { return this->_name == paramName; }; 41 //! Compares two LoadParamDescription 42 bool operator==(const LoadParamDescription& paramDescr) const { return this->_name == paramDescr._name; }; 43 //! Compares two LoadParamDescription with the less operator 44 bool operator<(const LoadParamDescription& paramDescr) const { return this->_name < paramDescr._name; }; 41 45 42 46 void setDescription(const std::string& descriptionText); 47 void setValues(unsigned int paramCount, 48 const MultiType* const defaultValues, 49 bool retVal = false); 50 43 51 /** @returns the descriptionString */ 44 const std::string& getDescription() { return this->description; };52 const std::string& description() { return this->_description; }; 45 53 46 void print( ) const;54 void print(FILE* stream = stdout, bool withComments = true) const; 47 55 48 56 private: 49 std::string paramName; //!< The name of the parameter. 50 int paramCount; //!< The count of parameters. 51 int* types; //!< What kind of parameters does this function take ?? 52 std::string description; //!< A longer description about this function. 53 char** defaultValues; //!< The 'Default Values'. @TODO MAKE THIS A MULTITYPE 54 }; 57 std::string _name; //!< The Name of the Parameter. 58 unsigned int _parameterCount; //!< The Count of parameters. 59 std::string _description; //!< A longer description about this function. 55 60 56 //! A class for descriptions of a loadable module 57 class LoadClassDescription 58 { 59 friend class CLoadParam; 60 public: 61 LoadClassDescription(const std::string& className); 62 ~LoadClassDescription(); 63 64 static LoadClassDescription* addClass(const std::string& className); 65 LoadParamDescription* addParam(const std::string& paramName); 66 67 static void deleteAllDescriptions(); 68 69 static void printAll(const std::string& fileName = ""); 70 static std::list<std::string> searchClassWithShort(const std::string& classNameBegin); 71 // static const LoadParamDescription* getClass(const std::string& className); 72 73 private: 74 static bool parametersDescription; //!< if parameter-description should be enabled. 75 static std::list<LoadClassDescription*>* classList; //!< a list, that stores all the loadable classes. (after one instance has been loaded) 76 std::string className; //!< name of the class 77 78 std::list<LoadParamDescription*> paramList; //!< List of parameters this class knows. 61 std::vector<std::string> _types; //!< A Vector of types of this Parameter. 62 std::vector<std::string> _defaultValues; //!< A Vector of defaultValues of this Parameter. 79 63 }; 80 64 -
trunk/src/lib/util/loading/resource.cc
r9406 r9869 14 14 */ 15 15 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD ING16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD 17 17 18 18 #include "resource.h" 19 20 21 22 23 /** 24 * standard constructor 25 */ 26 Resource::Resource (const std::string& fileName) 19 #include "resource_manager.h" 20 21 #include "debug.h" 22 23 24 namespace Resources 27 25 { 28 // this->setClassID(CL_RESOURCE, "Resource"); 29 26 //! Define an ObjectList for the Resources 27 ObjectListDefinition(Resource); 28 29 30 /** 31 * @brief standard constructor 32 * @param type the Type this resource belongs to. 33 */ 34 Resource::Resource (Type* type) 35 : _pointer(NULL), _type(type) 36 { 37 this->registerObject(this, Resource::_objectList); 38 } 39 40 /** 41 * @brief standard deconstructor 42 */ 43 Resource::~Resource () 44 { 45 // delete what has to be deleted here 46 } 47 48 /** 49 * @brief Locates a File inside of the Resources Paths and returns the appended path. 50 * 51 * @param fileName the Name of the file to look for. 52 * @returns the Name of the File prepended with the PAth it is in, if found, empty String ("") otherwise. 53 * 54 * This Function searches in (ordered): 55 * 1. mainGlobalPath (from ResourceManger) 56 * 2. all of the global Paths (from ResourceManger) 57 * 3. all of the Resources Paths (from Resources::Type) 58 * 59 * in each of these directory, first "./" is searched, and afterwards all of the subDirs (from Resources::Type) are searched. 60 * 61 * @todo finish it!! 62 */ 63 std::string Resource::locateFile(const std::string& fileName) const 64 { 65 if ((ResourceManager::getInstance()->mainGlobalPath() + File(fileName)).exists() ) 66 return (ResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 67 68 std::string locatedFile; 69 locatedFile = locateFileInSubDir(ResourceManager::getInstance()->mainGlobalPath(), fileName); 70 if (!locatedFile.empty()) 71 { 72 return locatedFile; 73 } 74 75 if (File(fileName).exists()) 76 return fileName; 77 78 return (ResourceManager::getInstance()->mainGlobalPath() + File(fileName)).name(); 79 } 80 81 /** 82 * @brief tests in all the SubDirectories defined in Resource under Directory if the fileName exists. 83 * @param directory the directory to in what to search for all subdirectories for. 84 * @param fileName the Name of the File to query for 85 * @return true on success. 86 */ 87 std::string Resource::locateFileInSubDir(const Directory& directory, const std::string& fileName) const 88 { 89 std::vector<Directory>::const_iterator it; 90 for (it = this->_type->resourceSubPaths().begin(); it != this->_type->resourceSubPaths().end(); ++it) 91 { 92 Directory dir = directory + (*it); 93 File file = dir + File(fileName); 94 if ((dir+ File(fileName)).exists()) 95 return (dir+File(fileName)).name(); 96 } 97 return ""; 98 } 99 100 101 /** 102 * @param loadString the Identifier of the Resource. 103 * @returns a Store-Pointer to the Resource if found, NULL otherwise 104 */ 105 StorePointer* Resource::acquireResource(const std::string& loadString) 106 { 107 //const Type* const type = _resourceTypes[this->_type->id()]; 108 109 for (unsigned int i = 0; i < _type->storedResources().size(); ++i) 110 { 111 if (_type->storedResources()[i]->loadString() == loadString) 112 return _type->storedResources()[i]; 113 } 114 115 return NULL; 116 } 117 118 /** 119 * @brief registers a StorePointer to a Resource's Type. 120 * @param pointer the StorePointer to register. 121 */ 122 void Resource::addResource(StorePointer* pointer) 123 { 124 assert(pointer != NULL); 125 this->_type->addResource(pointer); 126 } 127 128 129 130 131 132 133 /////////////////// 134 //// KEEPLEVEL //// 135 /////////////////// 136 137 //! Constructs a default KeepLevel as Set in the ResourceManager via setDefaultKeepLevel. 138 KeepLevel::KeepLevel() 139 { 140 this->_keepLevel = ResourceManager::getInstance()->defaultKeepLevel().keepLevel(); 141 } 142 /** 143 * @param keepLevel the level to set. 144 */ 145 KeepLevel::KeepLevel(unsigned int keepLevel) 146 { 147 _keepLevel = keepLevel; 148 } 149 150 /** 151 * @brief constructor of a KeepLevel. 152 * @param keepLevelName the Name of the KeepLevel. Must be one Name of the defined Names in the ResourceManager. 153 * 154 * @note the Name is transformed into an Integer for fast interpretation. 155 */ 156 KeepLevel::KeepLevel(const std::string& keepLevelName) 157 { 158 this->_keepLevel = ResourceManager::getInstance()->getKeepLevelID(keepLevelName); 159 } 160 161 /** 162 * @returns the name of the KeepLevel. 163 */ 164 const std::string& KeepLevel::name() const 165 { 166 return ResourceManager::getInstance()->getKeepLevelName(this->_keepLevel); 167 } 168 169 170 171 /////////////////////// 172 //// STORE POINTER //// 173 /////////////////////// 174 /** 175 * @brief allocates a StorePointer. 176 * @param loadString An identifier String that is unique between all resources of this type. 177 * @param keepLevel the KeepLevel at wich to keep this resource. 178 */ 179 StorePointer::StorePointer(const std::string& loadString, const KeepLevel& keeplevel) 180 : _loadString(loadString), _keepLevel(keeplevel) 181 { 182 PRINTF(4)("Acquired a Resource with LoadString '%s' and KeepLevel '%s'\n", _loadString.c_str(), _keepLevel.name().c_str()); 183 } 184 185 StorePointer::~StorePointer() 186 { 187 PRINTF(4)("Deleting Stored Resource '%s' from KeepLevel '%s'\n", _loadString.c_str(), _keepLevel.name().c_str()); 188 }; 189 190 191 192 ////////////// 193 //// TYPE //// 194 ////////////// 195 /** 196 * @brief allocates a Type. 197 * @param typeName the Name of the Type to be stored in this Container. 198 */ 199 Type::Type(const std::string& typeName) 200 : _typeName(typeName) 201 { 202 ResourceManager::getInstance()->registerType(this); 203 PRINTF(4)("Created ResourceType '%s'\n", typeName.c_str()); 204 } 205 206 //! Destructs a Type. 207 Type::~Type() 208 { 209 ResourceManager::getInstance()->unregisterType(this); 210 } 211 212 /** 213 * @brief adds a Resource to this Resource's type. 214 * @param resource the Resource to add. 215 */ 216 void Type::addResource(StorePointer* resource) 217 { 218 this->_storedResources.push_back(resource); 219 } 220 221 /** 222 * @brief adds a Path to the Type's resource-paths. 223 * @param path the path-name to add. 224 */ 225 bool Type::addResourcePath(const std::string& path) 226 { 227 std::vector<Directory>::const_iterator it; 228 for (it = this->_resourcePaths.begin(); it != this->_resourcePaths.end(); ++it) 229 if ((*it) == path) 230 return false; 231 this->_resourcePaths.push_back(path); 232 return true; 233 234 } 235 236 /** 237 * @brief Adds a SubPath to the Type's resource-subpaths. 238 * @param subPath the subpath to add. 239 */ 240 bool Type::addResourceSubPath(const std::string& subPath) 241 { 242 std::vector<Directory>::const_iterator it; 243 for (it = this->_resourceSubPaths.begin(); it != this->_resourceSubPaths.end(); ++it) 244 if ((*it) == subPath) 245 return false; 246 this->_resourceSubPaths.push_back(subPath); 247 return true; 248 } 249 250 /** 251 * @brief Unloads all Resources below a certain Level. 252 * @param keepLevel the KeepLevel at what to remove the Resources from. 253 */ 254 void Type::unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel) 255 { 256 std::vector<Resources::StorePointer*>::iterator it, it2; 257 bool finished = false; 258 259 while (!finished) 260 { 261 finished = true; 262 for (it = this->_storedResources.begin(); it != this->_storedResources.end();++it) 263 if((*it)->keepLevel() < keepLevel && (*it)->last()) 264 { 265 delete (*it); 266 this->_storedResources.erase(it); 267 finished = false; 268 break; 269 } 270 } 271 } 272 273 /** 274 * @brief print out some nice Debug information in a beatifully designed style 275 */ 276 void Type::debug() const 277 { 278 PRINT(0)(" ResourceType '%s' stores %d Resources\n", this->_typeName.c_str(), this->_storedResources.size()); 279 PRINT(0)(" Paths:\n"); 280 for (unsigned int i = 0; i < this->_resourcePaths.size(); ++i) 281 PRINT(0)(" %s\n", this->_resourcePaths[i].name().c_str()); 282 PRINT(0)(" Sub-Paths:"); 283 for (unsigned int i = 0; i < this->_resourceSubPaths.size(); ++i) 284 PRINT(0)(" '%s'", this->_resourceSubPaths[i].name().c_str()); 285 PRINT(0)("\n"); 286 287 PRINT(0)(" Loaded Resources:\n"); 288 std::vector<Resources::StorePointer*>::const_iterator it; 289 for (it = this->_storedResources.begin(); it != this->_storedResources.end(); ++it) 290 PRINT(0)(" '%s' : KeepLevel '%s'\n", (*it)->loadString().c_str(), (*it)->keepLevel().name().c_str()); 291 } 30 292 } 31 32 /**33 * standard deconstructor34 */35 Resource::~Resource ()36 {37 // delete what has to be deleted here38 } -
trunk/src/lib/util/loading/resource.h
r7195 r9869 8 8 9 9 #include "base_object.h" 10 #include "multi_type.h"11 10 #include <string> 11 #include <vector> 12 #include <set> 12 13 13 // FORWARD DECLARATION 14 #include "filesys/directory.h" 15 16 //! A Namespace Resources and ResourceHandling is defined in. 17 namespace Resources 18 { 19 //! The KeepLevel handles the unloading of Resources. 20 /** 21 * Allocating a Resource also appends a KeepLevel to the Resource. 22 * When the Resource is not used anymore it is decided on the grounds of the KeepLevel, 23 * if the Resource should be deleted. (e.g. at the end of a Level, Campaign, or something like this). 24 */ 25 class KeepLevel 26 { 27 public: 28 KeepLevel(); 29 KeepLevel(unsigned int keepLevel); 30 KeepLevel(const std::string& keepLevelName); 31 32 //! Compare equality 33 inline bool operator==(const KeepLevel& keepLevel) const { return this->_keepLevel == keepLevel._keepLevel; }; 34 //! Compares inequality 35 inline bool operator!=(const KeepLevel& keepLevel) const { return this->_keepLevel != keepLevel._keepLevel; }; 36 //! Compares less/equal than 37 inline bool operator<=(const KeepLevel& keepLevel) const { return this->_keepLevel <= keepLevel._keepLevel; }; 38 //! Compares less than 39 inline bool operator<(const KeepLevel& keepLevel) const { return this->_keepLevel < keepLevel._keepLevel; }; 40 41 /** @returns the KeepLevel as a number */ 42 inline unsigned int keepLevel() const { return _keepLevel; }; 43 const std::string& name() const; 44 private: 45 unsigned int _keepLevel; //!< The KeepLevel a Resource is in. 46 }; 47 48 49 /////////////////// 50 // STORE POINTER // 51 /////////////////// 52 //! Stores a Resource-Pointer, the LoadString and it's keepLevel. 53 class StorePointer 54 { 55 public: 56 //! Virtual Destructor, that removes the Stored information-pointer. 57 virtual ~StorePointer(); 58 59 /** @returns the LoadString this resource was loaded with */ 60 const std::string& loadString() const { return _loadString; }; 61 /** @returns the KeepLevel of this resource */ 62 const Resources::KeepLevel& keepLevel() const { return _keepLevel; }; 63 64 virtual bool last() const = 0; 65 66 protected: 67 StorePointer(const std::string& loadString, const Resources::KeepLevel& keeplevel); 68 69 private: 70 StorePointer(const StorePointer&) : _keepLevel(0) {}; 71 72 private: 73 std::string _loadString; //!< An identifier, to match when loading a File. 74 Resources::KeepLevel _keepLevel; //!< The Priority of this resource. (can only be increased, so none else will delete this) 75 }; 14 76 15 77 16 78 17 //! An enumerator for different (UN)LOAD-types. 18 /** 19 * RP_NO: will be unloaded on request 20 * RP_LEVEL: will be unloaded at the end of a Level 21 * RP_CAMPAIGN: will be unloaded at the end of a Campaign 22 * RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) 23 */ 24 typedef enum ResourcePriority 25 { 26 RP_NO = 0, 27 RP_LEVEL = 1, 28 RP_CAMPAIGN = 2, 29 RP_GAME = 3 30 }; 79 /////////////////// 80 // RESOURCE TYPE // 81 /////////////////// 82 //! A Type of Resources. 83 /** 84 * The Type is used to store the Pointers to already loaded Resources, 85 * and also to store type-specific properties. 86 * These are the Loading Paths, the subpaths and so on. 87 */ 88 class Type 89 { 90 public: 91 virtual ~Type(); 92 /** @returns true if the names match @param typeName the Name to compare. @brief compare the Type with a Name */ 93 bool operator==(const std::string& typeName) const { return this->_typeName == typeName; }; 94 95 //////////////////// 96 //// EXTENSIONS //// 97 void addExtension(const std::string& extension); 98 99 /////////////// 100 //// PATHS //// 101 bool addResourcePath(const std::string& path); 102 bool addResourceSubPath(const std::string& subPath); 103 104 /// Retrieve Functions 105 /** @returns the name of the stored Class this Type loads Resources for */ 106 const std::string& storedClassName() const { return _typeName; }; 107 /** @returns the ID of the Type != ClassID */ 108 /** @returns the type-specific paths this Resource searches in. */ 109 const std::vector<Directory>& resourcePaths() const { return _resourcePaths; }; 110 /** @returns the Type specific SubPaths this Resource Searches in @see std::vector<std::string> _resourceSubPaths */ 111 const std::vector<Directory>& resourceSubPaths() const { return _resourceSubPaths; }; 112 /** @returns the Pointers to the Stored resources. @note do not use this, for more than some lookup */ 113 const std::vector<Resources::StorePointer*>& storedResources() const { return _storedResources; }; 114 115 /////////////////////////////// 116 //// LOADING AND UNLOADING //// 117 virtual void createFromString(const std::string& loadString, const KeepLevel& keepLevel = KeepLevel()) = 0; 118 void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel); 119 120 /////////////////// 121 //// INTERNALS //// 122 void addResource(Resources::StorePointer* resource); 123 124 /////////////// 125 //// DEBUG //// 126 void debug() const; 127 128 protected: 129 Type(const std::string& typeName); 130 131 private: 132 Type(const Type& type) {}; 133 private: 134 const std::string _typeName; //!< Name of the Type. (Name of the Resource this loads.) 135 std::vector<Directory> _resourcePaths; //!< The Paths to search for files in this type 136 std::vector<Directory> _resourceSubPaths; //!< The subpaths that will be searched under all the _resourcePaths. 137 std::vector<std::string> _fileExtensions; //!< File Extensions, this Resource supports. 138 139 std::vector<Resources::StorePointer*> _storedResources; //!< An array of all the stored Resources. 140 }; 141 142 /** 143 * @brief A Type Definition Class for any Object that is resourceable. 144 * 145 * This Class's main reason of Existence is, that resources can be dynamically 146 * created over a loadString. For this the Type of Resource is required, and the Resource must 147 * itself support the 'void createFromString(const std::string&)' function. 148 */ 149 template<class T> class tType : public Type 150 { 151 public: 152 /** Create the ResourceType @see Type(const std::string&) */ 153 tType(const std::string& typeName) : Type(typeName) {}; 154 /** @param loadString the String to load a Resource with @brief tries to create a Resource of Type T with a loadString */ 155 virtual void createFromString(const std::string& loadString, const KeepLevel& keepLevel = KeepLevel()) { T::createFromString(loadString, keepLevel); } 156 }; 31 157 32 158 33 159 34 //! A Resource is an Object, that can be loaded from Disk 35 /** 36 * 37 */ 38 class Resource : virtual public BaseObject { 160 ///////////////////// 161 // RESOURCE ITSELF // 162 ///////////////////// 163 //! A Resource is an Object, that can be loaded from Disk 164 /** 165 * The Resource Hanldes the location and stores pointers to data that can be retrieved. 166 */ 167 class Resource : virtual public BaseObject 168 { 169 ObjectListDeclaration(Resource); 39 170 40 public:41 Resource(const std::string& fileName);42 virtual ~Resource();171 public: 172 Resource(Resources::Type* type); 173 virtual ~Resource(); 43 174 44 virtual bool load(std::string& fileName, const MultiType& param1, const MultiType& param2); 45 virtual bool reload(); 46 virtual bool unload(); 175 /** @brief reloads the underlying resource */ 176 virtual bool reload() { return false; }; 177 /** @brief unloads the underlying Resource */ 178 virtual bool unload() { return false; }; 47 179 48 private: 49 std::string fileName; 180 std::string locateFile(const std::string& fileName) const; 50 181 51 unsigned int referenceCount; //!< How many times this Resource has been loaded.52 /// TODO REMOVE THIS: ResourceType type; //!< ResourceType of this Resource. 53 ResourcePriority prio; //!< The Priority of this resource. (can only be increased, so noone else will delete this)182 protected: 183 Resources::StorePointer* acquireResource(const std::string& loadString); 184 void addResource(Resources::StorePointer* pointer); 54 185 55 MultiType param[3]; //!< The Parameters given to this Resource. 56 }; 186 private: 187 std::string locateFileInSubDir(const Directory& directory, const std::string& fileName) const; 188 189 private: 190 Resources::StorePointer* _pointer; //!< Virtual Pointer to the ResourceData. 191 Resources::Type* _type; //!< Type of the Resource. 192 }; 193 } 57 194 58 195 #endif /* _RESOURCE_H */ -
trunk/src/lib/util/loading/resource_manager.cc
r9406 r9869 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD 17 17 18 #include "util/loading/resource_manager.h" 19 #include "substring.h" 18 #include "resource_manager.h" 20 19 #include "debug.h" 21 20 22 21 #include <algorithm> 23 #include <assert.h> 24 25 // different resource Types 26 #ifndef NO_MODEL 27 #include "objModel.h" 28 #include "primitive_model.h" 29 #include "md2/md2Model.h" 30 #include "md3/md3_data.h" 31 #include "md3/md3_animation_cfg.h" 32 #endif /* NO_MODEL */ 33 #ifndef NO_TEXTURES 34 #include "texture.h" 35 #endif /* NO_TEXTURES */ 36 #ifndef NO_TEXT 37 #include "font.h" 38 #endif /* NO_TEXT */ 39 #ifndef NO_AUDIO 40 #include "sound_buffer.h" 41 #include "ogg_player.h" 42 #endif /* NO_AUDIO */ 43 #ifndef NO_SHADERS 44 #include "shader.h" 45 #endif /* NO_SHADERS */ 46 47 // File Handling Includes 48 #include <sys/types.h> 49 #include <sys/stat.h> 50 #include <unistd.h> 51 52 53 54 /** 55 * @brief standard constructor 56 */ 57 ResourceManager::ResourceManager () 22 #include <cassert> 23 24 25 namespace Resources 58 26 { 59 this->setClassID(CL_RESOURCE_MANAGER, "ResourceManager"); 60 this->setName("ResourceManager"); 61 62 this->dataDir = "./"; 63 this->tryDataDir("./data"); 27 /// Definition of the ResourceManager's ObjectList. 28 ObjectListDefinition(ResourceManager); 29 //! Singleton Reference to the ResourceManager 30 ResourceManager* ResourceManager::_singletonRef = NULL; 31 32 33 /** 34 * @brief standard constructor 35 */ 36 ResourceManager::ResourceManager () 37 : _defaultKeepLevel(0) 38 { 39 this->registerObject(this, ResourceManager::_objectList); 40 this->setName("ResourceManager"); 41 this->_mainGlobalPath = Directory("./"); 42 } 43 44 45 /** 46 * @brief standard destructor 47 */ 48 ResourceManager::~ResourceManager () 49 { 50 this->unloadAllBelowKeepLevel(this->_keepLevelNames.size()); 51 ResourceManager::_singletonRef = NULL; 52 } 53 54 /** 55 * @brief Registers a new Type to the ResourceManager. 56 * @param type the Type to register. 57 */ 58 void ResourceManager::registerType(Resources::Type* type) 59 { 60 this->_resourceTypes.push_back(type); 61 PRINTF(5)("ResourceType '%s' added\n", type->storedClassName().c_str()); 62 } 63 64 /** 65 * @brief Unregisters a new Type to the ResourceManager. 66 * @param type the Type to unregister. 67 */ 68 void ResourceManager::unregisterType(Resources::Type* type) 69 { 70 std::vector<Resources::Type*>::iterator it = std::find (this->_resourceTypes.begin(), this->_resourceTypes.end(), type); 71 if (it != this->_resourceTypes.end()) 72 { 73 this->_resourceTypes.erase(it); 74 PRINTF(5)("ResourceType '%s' removed\n", type->storedClassName().c_str()); 75 } 76 } 77 78 /** 79 * @brief Sets the main Global path (the main path Resources are searched for) 80 * @param directory the directory to set. 81 * @see Resource::locateFile 82 */ 83 void ResourceManager::setMainGlobalPath(const Directory& directory) 84 { 85 this->_mainGlobalPath = directory; 86 this->_mainGlobalPath.open(); 87 } 88 89 /** 90 * @brief add a Global search path. (global paths besided the main path.) 91 * @param directory a directory to add. 92 */ 93 void ResourceManager::addGlobalPath(const Directory& directory) 94 { 95 std::vector<Directory>::const_iterator it = std::find(this->_globalPaths.begin(), this->_globalPaths.end(), directory); 96 if (it == this->_globalPaths.end()) 97 this->_globalPaths.push_back(directory); 98 } 99 100 /** 101 * @brief add a ResourcePath to a Type's Paths. 102 * @param resourceName the Type's name of Resource to add the path to. 103 * @param pathName pathName the Name of the path to add. 104 * @return true on success. (if a path was added (no duplicate, and resourceName existed). 105 */ 106 bool ResourceManager::addResourcePath(const std::string& resourceName, const std::string& pathName) 107 { 108 std::vector<Resources::Type*>::iterator it; 109 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 110 if (*(*it) == resourceName) 111 return (*it)->addResourcePath(pathName); 112 PRINTF(2)("ResourcePath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); 113 return false; 114 } 115 116 /** 117 * @brief add a ResourcePath to a Type's SubPaths. 118 * @param resourceName the Type's name of Resource to add the subpath to. 119 * @param pathName pathName the Name of the path to add. 120 * @return true on success. (if a path was added (no duplicate, and resourceName existed). 121 */ 122 bool ResourceManager::addResourceSubPath(const std::string& resourceName, const std::string& pathName) 123 { 124 std::vector<Resources::Type*>::iterator it; 125 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 126 if (*(*it) == resourceName) 127 return (*it)->addResourceSubPath(pathName); 128 PRINTF(2)("ResourceSubPath %s could not be added to the ResourceType %s\n", pathName.c_str(), resourceName.c_str()); 129 return false; 130 } 131 132 /** 133 * @brief checks wether a File is inside of the MainPath. 134 * @param fileInside the file to check 135 * @return true if the file is inside. 136 */ 137 bool ResourceManager::checkFileInMainPath(const File& fileInside) 138 { 139 return (this->_mainGlobalPath + fileInside).exists(); 140 } 141 142 /** 143 * @brief prepends the fileName by the MainGlobalPath (same as mainGlobalPath + '/' + fileName). 144 * @param fileName The FileName to prepend 145 * @returns the prepended file-name 146 */ 147 std::string ResourceManager::prependAbsoluteMainPath(const std::string& fileName) 148 { 149 return (this->_mainGlobalPath + File(fileName)).name(); 150 } 151 152 /** 153 * @brief add a KeepLevelName (this function just counts upwards). 154 * @param keepLevelName the Name of the KeepLevel to set. 155 * @returns the Level the Name was set to. 156 */ 157 unsigned int ResourceManager::addKeepLevelName(const std::string& keepLevelName) 158 { 159 this->_keepLevelNames.push_back(keepLevelName); 160 return _keepLevelNames.size()-1; 161 } 162 163 /** 164 * @param keepLevelName the Name of the KeepLevel. 165 * @returns the ID of the KeepLevel named keepLevelName 166 */ 167 unsigned int ResourceManager::getKeepLevelID(const std::string& keepLevelName) const 168 { 169 for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i) 170 if (this->_keepLevelNames[i] == keepLevelName) 171 return i; 172 173 PRINTF(2)("KeepLevel '%s' not found. Using 0 instead\n", keepLevelName.c_str()); 174 return 0; 175 } 176 177 /** 178 * @param keepLevelID the ID to check. 179 * @return the name of the KeepLevel. 180 */ 181 const std::string& ResourceManager::getKeepLevelName(unsigned int keepLevelID) const 182 { 183 assert(keepLevelID < this->_keepLevelNames.size()); 184 return this->_keepLevelNames[keepLevelID]; 185 } 186 187 188 /** 189 * @brief loads a Resource from a TypeName and a loadString. 190 * @param resourceTypeName The Name of the Type to what to load a Resource from. 191 * @param loadString the loadString to load in the Type. 192 */ 193 void ResourceManager::loadFromLoadString(const std::string& resourceTypeName, const std::string& loadString, const KeepLevel& keepLevel) 194 { 195 std::vector<Resources::Type*>::const_iterator it; 196 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 197 { 198 if (*(*it) == resourceTypeName) 199 { 200 (*it)->createFromString(loadString, keepLevel); 201 /// TODO check if the resource was allocated!! 202 return ; 203 } 204 } 205 return ; 206 } 207 208 /** 209 * @brief unloads all Resources below a certain threshhold. 210 * @param keepLevel the KeepLevel below which to erase. 211 * 212 * @not Resources will only be erased, if th keepLevel is below, and the resources are not 213 * referenced anymore. 214 */ 215 void ResourceManager::unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel) 216 { 217 std::vector<Resources::Type*>::const_iterator it; 218 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 219 { 220 (*it)->unloadAllBelowKeepLevel(keepLevel); 221 } 222 } 223 224 225 /** 226 * @brief outputs debug information about the ResourceManager 227 */ 228 void ResourceManager::debug() const 229 { 230 PRINT(0)("/==RM================================\\\n"); 231 PRINT(0)("| RESOURCE-MANAGER DEBUG INFORMATION |\n"); 232 PRINT(0)("\\====================================/\n"); 233 PRINT(0)(" MainGlobal search path is %s\n", this->_mainGlobalPath.name().c_str()); 234 if(!this->_globalPaths.empty()) 235 { 236 PRINT(0)(" Additional Global search Paths are: "); 237 for (unsigned int i = 0; i < this->_globalPaths.size(); ++i) 238 PRINT(0)("'%s' ", this->_globalPaths[i].name().c_str()); 239 PRINT(0)("\n"); 240 } 241 PRINT(0)(" Listing %d Types: \n", this->_resourceTypes.size()); 242 std::vector<Resources::Type*>::const_iterator it; 243 for (it = this->_resourceTypes.begin(); it != this->_resourceTypes.end(); ++it) 244 { 245 (*it)->debug(); 246 if (it != --this->_resourceTypes.end()) 247 PRINT(0)(" ------------------------------------\n "); 248 } 249 250 PRINT(0)("KeepLevels are: "); 251 for (unsigned int i = 0; i < this->_keepLevelNames.size(); ++i) 252 PRINT(0)("%d:'%s' ", i, this->_keepLevelNames[i].c_str()); 253 PRINT(0)("\n"); 254 PRINT(0)("=================================RM==/\n"); 255 } 64 256 } 65 66 //! Singleton Reference to the ResourceManager67 ResourceManager* ResourceManager::singletonRef = NULL;68 69 /**70 * @brief standard destructor71 */72 ResourceManager::~ResourceManager ()73 {74 // deleting the Resources-List75 this->unloadAllByPriority(RP_GAME);76 77 if (!this->resourceList.empty())78 PRINTF(1)("Not removed all Resources, since there are still %d resources registered\n", this->resourceList.size());79 80 ResourceManager::singletonRef = NULL;81 }82 83 /**84 * @brief sets the data main directory85 * @param dataDir the DataDirectory.86 */87 bool ResourceManager::setDataDir(const std::string& dataDir)88 {89 File dataDirectory(dataDir);90 if (dataDirectory.isDirectory())91 {92 this->dataDir = dataDirectory.name();93 94 if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\')95 {96 this->dataDir += '/';97 }98 return true;99 }100 else101 {102 PRINTF(1)("%s is not a Directory, and can not be the Data Directory, leaving as %s \n", dataDir.c_str(), this->dataDir.c_str());103 return false;104 }105 }106 107 /**108 * @brief sets the data main directory109 * @param dataDir the DataDirectory.110 *111 * this is essentially the same as setDataDir, but it ommits the error-message112 */113 bool ResourceManager::tryDataDir(const std::string& dataDir)114 {115 File dataDirectory(dataDir);116 if (dataDirectory.isDirectory())117 {118 this->dataDir = dataDirectory.name();119 120 if (dataDir[dataDir.size()-1] != '/' && dataDir[dataDir.size()-1] != '\\')121 {122 this->dataDir += '/';123 }124 return true;125 }126 return false;127 }128 129 130 /**131 * @brief checks for the DataDirectory, by looking if132 * @param fileInside is iniside of the given directory.133 */134 bool ResourceManager::verifyDataDir(const std::string& fileInside)135 {136 File dataDirectory(this->dataDir);137 if (!dataDirectory.isDirectory())138 {139 PRINTF(1)("'%s' is not a directory\n", this->dataDir.c_str());140 return false;141 }142 143 File testFile(this->dataDir + fileInside);144 return testFile.isFile();145 }146 147 #ifndef NO_TEXTURES148 /**149 * @brief adds a new Path for Images150 * @param imageDir The path to insert151 * @returns true, if the Path was well and injected (or already existent within the list)152 false otherwise153 */154 bool ResourceManager::addImageDir(const std::string& imageDir)155 {156 std::string newDir = imageDir;157 if (imageDir[imageDir.size()-1] != '/' && imageDir[imageDir.size()-1] != '\\')158 {159 newDir += '/';160 }161 // check if the param is a Directory162 if (File(newDir).isDirectory())163 {164 // check if the Directory has been added before165 std::vector<std::string>::const_iterator imageDir;166 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)167 {168 if (*imageDir == newDir)169 {170 PRINTF(3)("Path %s already loaded\n", newDir.c_str());171 return true;172 }173 }174 // adding the directory to the List175 this->imageDirs.push_back(newDir);176 return true;177 }178 else179 {180 PRINTF(1)("%s is not a Directory, and can not be added to the Paths of Images\n", newDir.c_str());181 return false;182 }183 }184 #endif /* NO_TEXTURES */185 186 /**187 * @brief loads resources188 * @param fileName: The fileName of the resource to load189 * @param prio: The ResourcePriority of this resource (will only be increased)190 * @param param0: an additional option to parse (see the constuctors for more help)191 * @param param1: an additional option to parse (see the constuctors for more help)192 * @param param2: an additional option to parse (see the constuctors for more help)193 * @returns a pointer to a desired Resource.194 */195 BaseObject* ResourceManager::load(const std::string& fileName, ResourcePriority prio,196 const MultiType& param0, const MultiType& param1, const MultiType& param2)197 {198 ResourceType tmpType;199 #ifndef NO_MODEL200 #define __IF_OK201 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".obj", 4))202 tmpType = OBJ;203 else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md2", 4))204 tmpType = MD2;205 else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".md3", 4))206 tmpType = MD3;207 else if (!strncmp(fileName.c_str()+(fileName.size()-4), ".cfg", 4))208 tmpType = MD3_CONFIG;209 else if (!strcasecmp(fileName.c_str(), "cube") ||210 !strcasecmp(fileName.c_str(), "sphere") ||211 !strcasecmp(fileName.c_str(), "plane") ||212 !strcasecmp(fileName.c_str(), "cylinder") ||213 !strcasecmp(fileName.c_str(), "cone"))214 tmpType = PRIM;215 #endif /* NO_MODEL */216 #ifndef NO_AUDIO217 #ifdef __IF_OK218 else219 #endif220 #define __IF_OK221 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".wav", 4))222 tmpType = WAV;223 else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".mp3", 4))224 tmpType = MP3;225 else if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ogg", 4))226 tmpType = OGG;227 #endif /* NO_AUDIO */228 #ifndef NO_TEXT229 #ifdef __IF_OK230 else231 #endif232 #define __IF_OK233 if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4))234 tmpType = TTF;235 #endif /* NO_TEXT */236 #ifndef NO_SHADERS237 #ifdef __IF_OK238 else239 #endif240 #define __IF_OK241 if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5))242 tmpType = SHADER;243 #endif /* NO_SHADERS */244 #ifndef NO_TEXTURES245 #ifdef __IF_OK246 else247 #else248 if249 #endif250 tmpType = IMAGE;251 #endif /* NO_TEXTURES */252 #undef __IF_OK253 return this->load(fileName, tmpType, prio, param0, param1, param2);254 }255 256 /**257 * @brief caches a Resource258 *259 * @see load;260 *261 * @brief returns true if ok, false otherwise.262 * This function loads a Resource without applying it to an Object.263 * This is for loading purposes, e.g, when the user is loading a Resource264 * during the initialisation instead of at Runtime.265 */266 bool ResourceManager::cache(const std::string& fileName, ResourceType type, ResourcePriority prio,267 const MultiType& param0, const MultiType& param1, const MultiType& param2)268 {269 // searching if the resource was loaded before.270 Resource* tmpResource;271 // check if we already loaded this Resource272 tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);273 // otherwise load it274 if (tmpResource == NULL)275 tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);276 // return cached pointer.277 if (tmpResource != NULL) // if the resource was loaded before.278 {279 if(tmpResource->prio < prio)280 tmpResource->prio = prio;281 return true;282 }283 else284 return false;285 }286 287 /**288 * tells the ResourceManager to generate a Copy of the Resource.289 * @brief resourcePointer: The Pointer to the resource to copy290 * @returns the Resource pointed to resourcePointer.291 */292 BaseObject* ResourceManager::copy(BaseObject* resourcePointer)293 {294 Resource* tmp = locateResourceByPointer(resourcePointer);295 if (tmp!=NULL)296 {297 tmp->count++;298 return tmp->pointer;299 }300 else301 return NULL;302 }303 304 305 /**306 * @brief loads resources307 * @param fileName: The fileName of the resource to load308 * @param type: The Type of Resource to load.309 * @param prio: The ResourcePriority of this resource (will only be increased)310 * @param param0: an additional option to parse (see the constuctors for more help)311 * @param param1: an additional option to parse (see the constuctors for more help)312 * @param param2: an additional option to parse (see the constuctors for more help)313 * @returns a pointer to a desired Resource.314 */315 BaseObject* ResourceManager::load(const std::string& fileName, ResourceType type, ResourcePriority prio,316 const MultiType& param0, const MultiType& param1, const MultiType& param2)317 {318 319 // searching if the resource was loaded before.320 Resource* tmpResource;321 // check if we already loaded this Resource322 tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);323 // otherwise load it324 if (tmpResource == NULL)325 {326 tmpResource = this->loadResource(fileName, type, prio, param0, param1, param2);327 }328 // return cached pointer.329 if (tmpResource != NULL) // if the resource was loaded before.330 {331 tmpResource->count++;332 if(tmpResource->prio < prio)333 tmpResource->prio = prio;334 335 return tmpResource->pointer;336 }337 else338 return NULL;339 }340 341 342 /**343 * @brief loads resources for internal purposes344 * @param fileName: The fileName of the resource to load345 * @param type: The Type of Resource to load.346 * @param prio: The ResourcePriority of this resource (will only be increased)347 * @param param0: an additional option to parse (see the constuctors for more help)348 * @param param1: an additional option to parse (see the constuctors for more help)349 * @param param2: an additional option to parse (see the constuctors for more help)350 * @returns a pointer to a desired Resource.351 */352 Resource* ResourceManager::loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio,353 const MultiType& param0, const MultiType& param1, const MultiType& param2)354 {355 // Setting up the new Resource356 Resource* tmpResource = new Resource;357 tmpResource->count = 0;358 tmpResource->type = type;359 tmpResource->prio = prio;360 tmpResource->pointer = NULL;361 tmpResource->name = fileName;362 363 // creating the full name. (directoryName + FileName)364 std::string fullName = ResourceManager::getFullName(fileName);365 // Checking for the type of resource \see ResourceType366 switch(type)367 {368 #ifndef NO_MODEL369 case OBJ:370 if (param0.getType() != MT_NULL)371 tmpResource->param[0] = param0;372 else373 tmpResource->param[0] = 1.0f;374 375 if(File(fullName).isFile())376 tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat());377 else378 {379 PRINTF(2)("File %s in %s does not exist. Loading a cube-Model instead\n", fileName.c_str(), dataDir.c_str());380 tmpResource->pointer = ResourceManager::load("cube", PRIM, prio, tmpResource->param[0].getFloat());381 }382 break;383 case PRIM:384 if (param0 != MT_NULL)385 tmpResource->param[0] = param0;386 else387 tmpResource->param[0] = 1.0f;388 389 if (tmpResource->name == "cube")390 tmpResource->pointer = new PrimitiveModel(PRIM_CUBE, tmpResource->param[0].getFloat());391 else if (tmpResource->name == "sphere")392 tmpResource->pointer = new PrimitiveModel(PRIM_SPHERE, tmpResource->param[0].getFloat());393 else if (tmpResource->name == "plane")394 tmpResource->pointer = new PrimitiveModel(PRIM_PLANE, tmpResource->param[0].getFloat());395 else if (tmpResource->name == "cylinder")396 tmpResource->pointer = new PrimitiveModel(PRIM_CYLINDER, tmpResource->param[0].getFloat());397 else if (tmpResource->name == "cone")398 tmpResource->pointer = new PrimitiveModel(PRIM_CONE, tmpResource->param[0].getFloat());399 break;400 case MD2:401 if(File(fullName).isFile())402 {403 tmpResource->param[0] = param0;404 tmpResource->param[1] = param1;405 tmpResource->pointer = new MD2Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat());406 }407 break;408 case MD3:409 if(File(fullName).isFile())410 {411 tmpResource->param[0] = param0;412 tmpResource->param[1] = param1;413 tmpResource->pointer = new md3::MD3Data(fullName, tmpResource->param[0].getCString(), tmpResource->param[1].getFloat());414 }415 break;416 case MD3_CONFIG:417 if(File(fullName).isFile())418 {419 tmpResource->param[0] = param0;420 tmpResource->param[1] = param1;421 tmpResource->pointer = new md3::MD3AnimationCfg(fullName);422 }423 break;424 #endif /* NO_MODEL */425 #ifndef NO_TEXT426 case TTF:427 if (param0 != MT_NULL)428 {429 assert(param0.getInt() >= 0);430 tmpResource->param[0] = param0;431 }432 else433 tmpResource->param[0] = FONT_DEFAULT_RENDER_SIZE;434 435 if(File(fullName).isFile())436 tmpResource->pointer = new Font(fullName, (unsigned int) tmpResource->param[0].getInt());437 else438 PRINTF(2)("%s does not exist in %s. Not loading Font\n", fileName.c_str(), this->dataDir.c_str());439 break;440 #endif /* NO_TEXT */441 #ifndef NO_AUDIO442 case WAV:443 if(File(fullName).isFile())444 tmpResource->pointer = new OrxSound::SoundBuffer(fullName);445 break;446 case OGG:447 if (File(fullName).isFile())448 tmpResource->pointer = new OrxSound::OggPlayer(fullName);449 break;450 #endif /* NO_AUDIO */451 #ifndef NO_TEXTURES452 case IMAGE:453 if (param0 != MT_NULL)454 tmpResource->param[0] = param0;455 else456 tmpResource->param[0] = GL_TEXTURE_2D;457 if(File(fullName).isFile())458 {459 PRINTF(4)("Image %s resides to %s\n", fileName.c_str(), fullName.c_str());460 tmpResource->pointer = new Texture(fullName, tmpResource->param[0].getInt());461 }462 else463 {464 std::vector<std::string>::iterator imageDir;465 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)466 {467 std::string imgName = *imageDir + fileName;468 if(File(imgName).isFile())469 {470 PRINTF(4)("Image %s resides to %s\n", fileName.c_str(), imgName.c_str());471 tmpResource->pointer = new Texture(imgName, tmpResource->param[0].getInt());472 break;473 }474 }475 }476 if(!tmpResource)477 PRINTF(2)("!!Image %s not Found!!\n", fileName.c_str());478 break;479 #endif /* NO_TEXTURES */480 #ifndef NO_SHADERS481 case SHADER:482 if(File(fullName).isFile())483 {484 if (param0 != MT_NULL)485 {486 MultiType param = param0; /// HACK487 std::string secFullName = ResourceManager::getFullName(param.getCString());488 if (File(secFullName).isFile())489 {490 tmpResource->param[0] = secFullName;491 tmpResource->pointer = new Shader(fullName, secFullName);492 }493 }494 else495 {496 tmpResource->param[0] = param0;497 tmpResource->pointer = new Shader(fullName, "");498 }499 }500 break;501 #endif /* NO_SHADERS */502 default:503 tmpResource->pointer = NULL;504 PRINTF(1)("No type found for %s.\n !!This should not happen unless the Type is not supported yet. JUST DO IT!!\n", tmpResource->name.c_str());505 break;506 }507 if (tmpResource->pointer != NULL)508 this->resourceList.push_back(tmpResource);509 510 if (tmpResource->pointer != NULL)511 return tmpResource;512 else513 {514 PRINTF(2)("Resource %s could not be loaded\n", fileName.c_str());515 delete tmpResource;516 return NULL;517 }518 }519 520 /**521 * @brief unloads a Resource522 * @param pointer: The pointer to free523 * @param prio: the PriorityLevel to unload this resource524 * @returns true if successful (pointer found, and deleted), false otherwise525 */526 bool ResourceManager::unload(BaseObject* pointer, ResourcePriority prio)527 {528 if (pointer == NULL)529 return false;530 // if pointer is existent. and only one resource of this type exists.531 Resource* tmpResource = this->locateResourceByPointer(pointer);532 if (tmpResource != NULL)533 return unload(tmpResource, prio);534 else535 {536 PRINTF(2)("Resource not Found %p\n", pointer);537 return false;538 }539 }540 541 /**542 * @brief unloads a Resource543 * @param resource: The resource to unloade544 * @param prio the PriorityLevel to unload this resource545 * @returns true on success, false otherwise.546 */547 bool ResourceManager::unload(Resource* resource, ResourcePriority prio)548 {549 if (resource == NULL)550 return false;551 if (resource->count > 0)552 resource->count--;553 554 if (resource->prio <= prio)555 {556 if (resource->count == 0)557 {558 delete resource->pointer;559 // deleting the List Entry:560 PRINTF(4)("Resource %s safely removed.\n", resource->name.c_str());561 std::vector<Resource*>::iterator resourceIT = std::find(this->resourceList.begin(), this->resourceList.end(), resource);562 this->resourceList.erase(resourceIT);563 delete resource;564 }565 else566 PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count);567 }568 else569 PRINTF(4)("not deleting resource %s because DeleteLevel to high\n", resource->name.c_str());570 return true;571 }572 573 574 /**575 * @brief unloads all alocated Memory of Resources with a pririty lower than prio576 * @param prio The priority to delete577 */578 bool ResourceManager::unloadAllByPriority(ResourcePriority prio)579 {580 bool removedAll = true;581 unsigned int removeCount;582 for (unsigned int round = 0; round < 3; round++)583 {584 int index = this->resourceList.size() - 1;585 removeCount = 0;586 while (index >= 0)587 {588 if (this->resourceList[index]->prio <= prio)589 {590 if (this->resourceList[index]->count == 0)591 unload(this->resourceList[index], prio);592 else593 {594 if (round == 3)595 {596 PRINTF(2)("unable to unload %s because there are still %d references to it\n",597 this->resourceList[index]->name.c_str(), this->resourceList[index]->count);598 removedAll = false;599 }600 removeCount++;601 }602 }603 index--;604 }605 if (removeCount == 0) break;606 }607 return removedAll;608 }609 610 611 /**612 * @brief Searches for a Resource by some information613 * @param fileName: The name to look for614 * @param type the Type of resource to locate.615 * @param param0: an additional option to parse (see the constuctors for more help)616 * @param param1: an additional option to parse (see the constuctors for more help)617 * @param param2: an additional option to parse (see the constuctors for more help)618 * @returns a Pointer to the Resource if found, NULL otherwise.619 */620 Resource* ResourceManager::locateResourceByInfo(const std::string& fileName, ResourceType type,621 const MultiType& param0, const MultiType& param1, const MultiType& param2) const622 {623 std::vector<Resource*>::const_iterator resource;624 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)625 {626 if ((*resource)->type == type && fileName == (*resource)->name)627 {628 bool match = false;629 switch (type)630 {631 #ifndef NO_MODEL632 case PRIM:633 case OBJ:634 if (param0 == MT_NULL)635 {636 if ((*resource)->param[0] == 1.0f)637 match = true;638 }639 else if ((*resource)->param[0] == param0.getFloat())640 match = true;641 break;642 case MD2:643 if (param0 == MT_NULL && ((*resource)->param[0] == "") && param1 == MT_NULL && ((*resource)->param[0] == 1.0f))644 match = true;645 else if ((*resource)->param[0] == ((MultiType)param0).getString() && (*resource)->param[1] == ((MultiType)param1).getFloat())646 match = true;647 break;648 case MD3:649 if (param0 == MT_NULL && ((*resource)->param[0] == "") && param1 == MT_NULL && ((*resource)->param[0] == 1.0f))650 match = true;651 else if ((*resource)->param[0] == ((MultiType)param0).getString() && (*resource)->param[1] == ((MultiType)param1).getFloat())652 match = true;653 break;654 case MD3_CONFIG:655 if (param0 == MT_NULL && ((*resource)->param[0] == ""))656 match = true;657 else if ((*resource)->param[0] == ((MultiType)param0).getString())658 match = true;659 break;660 661 #endif /* NO_MODEL */662 #ifndef NO_TEXT663 case TTF:664 if (param0 == MT_NULL)665 {666 if ((*resource)->param[0] == FONT_DEFAULT_RENDER_SIZE)667 match = true;668 }669 else if ((*resource)->param[0] == param0.getInt())670 match = true;671 break;672 #endif /* NO_TEXT */673 #ifndef NO_SHADERS674 case SHADER:675 if (param0 == MT_NULL)676 {677 if ((*resource)->param[0] == "")678 match = true;679 }680 else if ((*resource)->param[0] == ((MultiType)param0).getString())681 match = true;682 break;683 #endif /* NO_SHADERS */684 #ifndef NO_TEXTURES685 case IMAGE:686 if (param0 == MT_NULL)687 {688 if ((*resource)->param[0] == GL_TEXTURE_2D)689 match = true;690 }691 else if ((*resource)->param[0] == param0.getInt())692 match = true;693 break;694 #endif /* NO_TEXTURES */695 default:696 match = true;697 break;698 }699 if (match)700 {701 return (*resource);702 }703 }704 }705 return NULL;706 }707 708 /**709 * @brief Searches for a Resource by Pointer710 * @param pointer the Pointer to search for711 * @returns a Pointer to the Resource if found, NULL otherwise.712 */713 Resource* ResourceManager::locateResourceByPointer(const void* pointer) const714 {715 // Resource* enumRes = resourceList->enumerate();716 std::vector<Resource*>::const_iterator resource;717 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)718 if (pointer == (*resource)->pointer)719 return (*resource);720 return NULL;721 }722 723 std::string ResourceManager::toResourcableString(unsigned int i)724 {725 /* int len = strlen(ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));726 len += this->resourceList[i]->name.size();727 if (this->resourceList[i]->param[0].getCString()) len += strlen(this->resourceList[i]->param[0].getCString()) +1;728 if (this->resourceList[i]->param[1].getCString()) len += strlen(this->resourceList[i]->param[1].getCString()) +1;729 if (this->resourceList[i]->param[2].getCString()) len += strlen(this->resourceList[i]->param[2].getCString()) +1;730 len += 10;731 std::string tmp = new char[len];732 tmp[0] = '\0';733 strcat(tmp, ResourceManager::ResourceTypeToChar(this->resourceList[i]->type));734 strcat(tmp,",");735 strcat (tmp, this->resourceList[i]->name);736 if (this->resourceList[i]->param[0].getCString() && this->resourceList[i]->param[0].getCString() != '\0')737 {738 strcat(tmp,",");739 strcat( tmp, this->resourceList[i]->param[0].getCString());740 }741 if (this->resourceList[i]->param[1].getCString() && this->resourceList[i]->param[1].getCString() != '\0')742 {743 strcat(tmp,",");744 strcat( tmp, this->resourceList[i]->param[1].getCString());745 }746 if (this->resourceList[i]->param[2].getCString() && this->resourceList[i]->param[2].getCString() != '\0')747 {748 strcat(tmp,",");749 strcat( tmp, this->resourceList[i]->param[2].getCString());750 }751 return tmp;*/752 return "";753 }754 755 /**756 * @brief caches a Resource from a ResourceableString created with the toResourcableString-function757 * @param resourceableString the String to cache the resource from.758 */759 bool ResourceManager::fromResourceableString(const std::string& resourceableString)760 {761 /* SubString splits(resourceableString, ',');762 splits.debug();763 if (splits.getCount() == 2)764 this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),765 RP_LEVEL);766 else if (splits.getCount() == 3)767 return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),768 RP_LEVEL, splits[2]);769 else if (splits.getCount() == 4)770 return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),771 RP_LEVEL, splits[2], splits[3]);772 else if (splits.getCount() == 5)773 return this->cache(splits[1], ResourceManager::stringToResourceType(splits[0]),774 RP_LEVEL, splits[2], splits[3], splits[4]);*/775 return false;776 }777 778 779 /**780 * @param fileName the Name of the File to check781 * @returns The full name of the file, including the DataDir, and NULL if the file does not exist782 * !!IMPORTANT: this has to be deleted from the outside!!783 */784 std::string ResourceManager::getFullName(const std::string& fileName)785 {786 if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())787 return "";788 789 std::string retName = ResourceManager::getInstance()->getDataDir() +fileName;790 if (File(retName).isFile() || File(retName).isDirectory())791 return retName;792 else793 return "";794 }795 796 797 /**798 * @brief checks wether a file is in the DataDir.799 * @param fileName the File to check if it is in the Data-Dir structure.800 * @returns true if the file exists, false otherwise801 */802 bool ResourceManager::isInDataDir(const std::string& fileName)803 {804 if (fileName.empty() || ResourceManager::getInstance()->getDataDir().empty())805 return false;806 807 bool retVal = false;808 std::string checkFile = ResourceManager::getInstance()->getDataDir() + fileName;809 810 if (File(checkFile).exists())811 retVal = true;812 else813 retVal = false;814 return retVal;815 }816 817 818 /**819 * @brief outputs debug information about the ResourceManager820 */821 void ResourceManager::debug() const822 {823 PRINT(0)("=RM===================================\n");824 PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");825 PRINT(0)("======================================\n");826 // if it is not initialized827 PRINT(0)(" Reference is: %p\n", ResourceManager::singletonRef);828 PRINT(0)(" Data-Directory is: %s\n", this->dataDir.c_str());829 PRINT(0)(" List of Image-Directories: ");830 std::vector<std::string>::const_iterator imageDir;831 for (imageDir = this->imageDirs.begin(); imageDir != this->imageDirs.end(); imageDir++)832 PRINT(0)("%s ", (*imageDir).c_str());833 PRINT(0)("\n");834 835 PRINT(0)("List of all stored Resources:\n");836 std::vector<Resource*>::const_iterator resource;837 for (resource = this->resourceList.begin(); resource != this->resourceList.end(); resource++)838 839 {840 PRINT(0)("-----------------------------------------\n");841 PRINT(0)("Name: %s; References: %d; Type: %s ", (*resource)->name.c_str(), (*resource)->count, ResourceManager::ResourceTypeToChar((*resource)->type));842 843 PRINT(0)("gets deleted at ");844 switch((*resource)->prio)845 {846 default:847 case RP_NO:848 PRINT(0)("first posibility (0)\n");849 break;850 case RP_LEVEL:851 PRINT(0)("the end of the Level (1)\n");852 break;853 case RP_CAMPAIGN:854 PRINT(0)("the end of the campaign (2)\n");855 break;856 case RP_GAME:857 PRINT(0)("when leaving the game (3)\n");858 break;859 }860 }861 862 863 864 PRINT(0)("==================================RM==\n");865 }866 867 868 /**869 * @brief converts a ResourceType into the corresponding String870 * @param type the ResourceType to translate871 * @returns the converted String.872 */873 const char* ResourceManager::ResourceTypeToChar(ResourceType type)874 {875 return ResourceManager::resourceNames[type];876 }877 878 /**879 * @brief converts a String into a ResourceType (good for loading)880 * @param resourceType the name of the Type881 * @returns the Number of the Type, or 0 (defautl) if not found.882 */883 ResourceType ResourceManager::stringToResourceType(const std::string& resourceType)884 {885 for (unsigned int i = 0; i < RESOURCE_TYPE_SIZE; i++)886 if (resourceType == ResourceManager::resourceNames[i])887 return (ResourceType)i;888 return (ResourceType)0;889 }890 891 /**892 * The Names of the ResourceTypes893 */894 const char* ResourceManager::resourceNames[] =895 {896 #ifndef NO_MODEL897 "ObjectModel",898 "PrimitiveModel",899 "MD2-Data",900 "MD3-Data",901 "MD3-Config"902 #endif903 #ifndef NO_TEXT904 "Font",905 #endif906 #ifndef NO_AUDIO907 "Wav",908 "mp3",909 "ogg",910 #endif911 #ifndef NO_TEXTURES912 "Texture",913 #endif914 #ifndef NO_SHADERS915 "Shader",916 #endif917 918 }; -
trunk/src/lib/util/loading/resource_manager.h
r8724 r9869 1 1 /*! 2 2 * @file resource_manager.h 3 * The Resource Manager checks if a file/resource is loaded. 4 5 If a file/resource was already loaded the resourceManager will 6 return a void pointer to the desired resource. 7 Otherwise it will instruct the coresponding resource-loader to load, 8 and receive a pointer to it. 9 10 it is possible to compile the resource Manager without some modules by 11 just adding the compile flag -D.... 12 (NO_MODEL) 13 (NO_AUDIO) 14 (NO_TEXT) 15 (NO_TEXTURES) 16 (NO_SHADERS) 17 */ 3 */ 18 4 19 5 #ifndef _RESOURCE_MANAGER_H 20 6 #define _RESOURCE_MANAGER_H 21 7 22 #include " base_object.h"8 #include "resource.h" 23 9 #include "filesys/file.h" 10 #include "filesys/directory.h" 24 11 25 #include "multi_type.h" 26 #include <vector> 12 namespace Resources 13 { 27 14 28 //! An eumerator for different fileTypes the resourceManager supports 29 typedef enum ResourceType 30 { 31 #ifndef NO_MODEL 32 OBJ, //!< loading .obj file 33 PRIM, //!< loading primitive model 34 MD2, //!< loading md2-file 35 MD3, //!< loading md3-file 36 MD3_CONFIG, //!< the md3 config file 37 #endif /* NO_MODEL */ 38 #ifndef NO_TEXT 39 TTF, //!< loading a TrueTypeFont 40 #endif /* NO_TEXT */ 41 #ifndef NO_AUDIO 42 WAV, //!< loading wav 43 MP3, //!< loading mp3 44 OGG, //!< loading ogg 45 #endif /* NO_AUDIO */ 46 #ifndef NO_TEXTURES 47 IMAGE, //!< loading an image 48 #endif /* NO_TEXTURES */ 49 #ifndef NO_SHADERS 50 SHADER, //!< openGL-shader program 51 #endif /* NO_SHADERS */ 52 RESOURCE_TYPE_SIZE 53 }; 15 class ResourceManager : public BaseObject 16 { 17 ObjectListDeclaration(ResourceManager); 18 public: 19 /////////////////////// 20 //// INSTANZIATION //// 21 /** @returns a Pointer to the only object of this Class */ 22 inline static ResourceManager* getInstance() { if (!_singletonRef) _singletonRef = new ResourceManager(); return _singletonRef; }; 23 /** @brief deletes the Instance if it exists. */ 24 inline static void deleteInstance() { if (_singletonRef) delete _singletonRef; }; 54 25 55 //! An enumerator for different UNLOAD-types. 56 /** 57 RP_NO: will be unloaded on request 58 RP_LEVEL: will be unloaded at the end of a Level 59 RP_CAMPAIGN: will be unloaded at the end of a Campaign 60 RP_GAME: will be unloaded at the end of the whole Game (when closing orxonox) 61 */ 62 typedef enum ResourcePriority 63 { 64 RP_NO = 0, 65 RP_LEVEL = 1, 66 RP_CAMPAIGN = 2, 67 RP_GAME = 4 68 }; 26 //////////////////////// 27 //// RESOURCE PATHS //// 28 void setMainGlobalPath(const Directory& directory); 29 void addGlobalPath(const Directory& directory); 69 30 70 //! A Struct that keeps track about a resource its name its Type, and so on 71 struct Resource 72 { 73 BaseObject* pointer; //!< Pointer to the Resource. 74 unsigned int count; //!< How many times this Resource has been loaded. 31 bool addResourcePath(const std::string& resourceName, const std::string& pathName); 32 bool addResourceSubPath(const std::string& resourceName, const std::string& pathName); 33 void registerType(Resources::Type* type); 34 void unregisterType(Resources::Type* type); 75 35 76 std::string name; //!< Name of the Resource. 77 ResourceType type; //!< ResourceType of this Resource. 78 ResourcePriority prio; //!< The Priority of this resource. (This will only be increased) 36 /** @returns the main global search Path */ 37 const Directory& mainGlobalPath() const { return _mainGlobalPath; }; 38 /** @returns all global paths without mainGlobalPath */ 39 const std::vector<Directory>& globalPaths() const { return _globalPaths; }; 79 40 80 MultiType param[3]; //!< The Parameters given to this Resource. 81 }; 41 //////////////////// 42 //// KEEPLEVELS //// 43 unsigned int addKeepLevelName(const std::string& keepLevelName); 44 unsigned int getKeepLevelID(const std::string& keepLevelName) const; 45 const std::string& getKeepLevelName(unsigned int keepLevelID) const; 46 void setDefaultKeepLevel(const KeepLevel& keepLevel) { this->_defaultKeepLevel = keepLevel; }; 47 const KeepLevel& defaultKeepLevel() const { return this->_defaultKeepLevel; }; 82 48 49 ////////////////////////// 50 //// GENERAL QUERIES //// 51 /** @returns the Types of Resources */ 52 const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; }; 83 53 84 //! The ResourceManager is a class, that decides if a file/resource should be loaded 85 /** 86 * If a file/resource was already loaded the resourceManager will 87 * return a pointer to the desired resource. 88 * Otherwise it will instruct the corresponding resource-loader to load, 89 * and receive the pointer to it. 90 * 91 * It does it by looking, if a desired file has already been loaded. 92 * There is also the possibility to check for some variables 93 */ 94 class ResourceManager : public BaseObject 95 { 96 public: 97 virtual ~ResourceManager(); 98 /** @returns a Pointer to the only object of this Class */ 99 inline static ResourceManager* getInstance() { if (!singletonRef) singletonRef = new ResourceManager(); return singletonRef; }; 54 bool checkFileInMainPath(const File& fileInside); 55 std::string prependAbsoluteMainPath(const std::string& fileName); 100 56 101 bool setDataDir(const std::string& dataDir); 102 /** @returns the Name of the data directory */ 103 inline const std::string& getDataDir() const { return this->dataDir; }; 57 //////////////////////////////////////// 58 //// RESOURCE LOADING AND UNLOADING //// 59 void loadFromLoadString(const std::string& resourceTypeName, const std::string& loadString, const KeepLevel& keepLevel = KeepLevel()); 60 void loadFromLoadStringHACK(const std::string& resourceTypeName, const std::string& loadString) { this->loadFromLoadString(resourceTypeName, loadString); }; 104 61 62 void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel); 63 void unloadAllBelowKeepLevelINT(unsigned int level) { unloadAllBelowKeepLevel(level); }; 105 64 106 bool tryDataDir(const std::string& dataDir);107 bool verifyDataDir(const std::string& fileInside);108 bool addImageDir(const std::string& imageDir);65 /////////////// 66 //// DEBUG //// 67 void debug() const; 109 68 110 bool cache(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO,111 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType());112 BaseObject* copy(BaseObject* resourcePointer);69 private: 70 ResourceManager(); 71 virtual ~ResourceManager(); 113 72 114 BaseObject* load(const std::string& fileName, ResourcePriority prio = RP_NO, 115 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 116 BaseObject* load(const std::string& fileName, ResourceType type, ResourcePriority prio = RP_NO, 117 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()); 118 bool unload(BaseObject* pointer, ResourcePriority prio = RP_NO); 119 bool unload(Resource* resource, ResourcePriority = RP_NO); 120 bool unloadAllByPriority(ResourcePriority prio); 73 private: 74 static ResourceManager* _singletonRef; //!< singleton Reference 121 75 122 Resource* locateResourceByInfo(const std::string& fileName, ResourceType type, 123 const MultiType& param0 = MultiType(), const MultiType& param1 = MultiType(), const MultiType& param2 = MultiType()) const; 124 Resource* locateResourceByPointer(const void* pointer) const; 76 Directory _mainGlobalPath; //!< The main include directory (default at "./") 77 std::vector<Directory> _globalPaths; //!< Additional Global include directories. 125 78 126 std::string toResourcableString(unsigned int i); 127 bool fromResourceableString(const std::string& resourceableString); 128 /** @returns the Count of Resources the ResourceManager handles */ 129 unsigned int resourceCount() const { return this->resourceList.size(); } 79 std::vector<Resources::Type*> _resourceTypes; //!< A Vector of all the stored ResourceTypes @see Resources::Type 130 80 131 void debug() const; 81 std::vector<std::string> _keepLevelNames; //!< Names of KeepLevels @see Resources::KeepLevel 82 KeepLevel _defaultKeepLevel; //!< The default KeepLevel. 83 }; 132 84 133 134 // utility functions for handling files in and around the data-directory 135 static std::string getFullName(const std::string& fileName); 136 static bool isInDataDir(const std::string& fileName); 137 138 static const char* ResourceTypeToChar(ResourceType type); 139 static ResourceType stringToResourceType(const std::string& resourceType); 140 141 private: 142 ResourceManager(); 143 Resource* loadResource(const std::string& fileName, ResourceType type, ResourcePriority prio, 144 const MultiType& param0, const MultiType& param1, const MultiType& param2); 145 146 private: 147 static ResourceManager* singletonRef; //!< singleton Reference 148 149 std::string dataDir; //!< The Data Directory, where all relevant Data is stored. 150 std::vector<std::string> imageDirs; //!< A list of directories in which images are stored. 151 152 std::vector<Resource*> resourceList; //!< The List of Resources, that has already been loaded. 153 154 static const char* resourceNames[RESOURCE_TYPE_SIZE]; 155 }; 85 } 156 86 157 87 #endif /* _RESOURCE_MANAGER_H */ -
trunk/src/lib/util/multi_type.cc
r9406 r9869 33 33 { 34 34 default: 35 36 35 this->value.Float = 0.0f; 36 break; 37 37 case MT_BOOL: 38 39 38 this->value.Bool = false; 39 break; 40 40 case MT_INT: 41 42 41 this->value.Int = 0; 42 break; 43 43 case MT_FLOAT: 44 45 44 this->value.Float = 0.0f; 45 break; 46 46 case MT_CHAR: 47 48 47 this->value.Char = '\0'; 48 break; 49 49 case MT_STRING: 50 51 50 this->storedString = ""; 51 break; 52 52 } 53 53 } … … 142 142 { 143 143 case MT_NULL: 144 144 return true; 145 145 case MT_BOOL: 146 146 return (this->value.Bool == mt.value.Bool); 147 147 case MT_INT: 148 148 return (this->value.Int == mt.value.Int); 149 149 case MT_CHAR: 150 150 return (this->value.Char == mt.value.Char); 151 151 case MT_FLOAT: 152 152 return (this->value.Float == mt.value.Float); 153 153 case MT_STRING: 154 154 return (this->storedString == mt.storedString); 155 155 default: 156 156 return false; 157 157 } 158 158 } … … 171 171 { 172 172 case MT_BOOL: 173 174 173 this->setBool(this->getBool()); 174 break; 175 175 case MT_INT: 176 177 176 this->setInt(this->getInt()); 177 break; 178 178 case MT_FLOAT: 179 180 179 this->setFloat(this->getFloat()); 180 break; 181 181 case MT_CHAR: 182 183 182 this->setChar(this->getChar()); 183 break; 184 184 case MT_STRING: 185 186 185 this->setString(this->getString()); 186 break; 187 187 default: 188 188 this->type = type; 189 189 } 190 190 } … … 195 195 * 196 196 * This is a pure Value copy. The current type will be preserved. 197 *198 * @TODO speedup199 197 */ 200 198 void MultiType::setValueOf(const MultiType& mt) … … 257 255 } 258 256 257 /** 258 * @brief stores any value to the string. 259 * @note this Value can be grabbed by using the getStoredString function. 260 */ 261 void MultiType::storeString() 262 { 263 if (!(this->type & MT_STRING)) 264 this->storedString = this->getString(); 265 } 259 266 260 267 /************************** … … 275 282 else if (this->type & MT_STRING) return (this->storedString == "true" || 276 283 this->storedString == "TRUE" || 277 this->storedString != "0"); // ! @TODO make this better...284 this->storedString != "0"); // TODO make this better... 278 285 279 286 return false; … … 381 388 * @brief returns a Constant string (actually this is slower than getString() 382 389 * @returns a constant string of the stored version's one. 383 * @note this could lead to a inconsistency of data 390 * @note this could lead to a inconsistency of data AND IS HIGHLY NON_THREAD_SAFE! 391 * PLEASE THINK ABOUT USING THE getStoredString function in conjunction with storeString(). 384 392 */ 385 393 const std::string& MultiType::getConstString() const 386 394 { 387 388 395 MultiType::constString = this->getString(); 389 396 return MultiType::constString; 390 397 } 391 398 399 /** 400 * @brief returns the currently stored string. 401 * @returns the Stored string. 402 * @note Storing a string works as follows: \\ 403 * MultiType a(3); // Creates a MultiType of Type int with value 3 \\ 404 * a.storeString(); // Stores the String in the internal structure. \\ 405 * std::string name = a.getStoredString(); 406 * 407 * This would be the same as 408 * name = a.getString(); 409 * but with much more const'ness. 410 */ 411 const std::string& MultiType::getStoredString() const 412 { 413 MultiType::constString = this->getString(); 414 return MultiType::constString; 415 } 392 416 393 417 /** … … 433 457 { 434 458 case MT_BOOL: 435 436 459 this->setBool(false); 460 break; 437 461 case MT_INT: 438 439 462 this->setInt(0); 463 break; 440 464 case MT_FLOAT: 441 442 465 this->setFloat(0.0f); 466 break; 443 467 case MT_CHAR: 444 445 468 this->setChar('\0'); 469 break; 446 470 case MT_STRING: 447 448 471 this->setString(""); 472 break; 449 473 default: 450 474 #ifdef DEBUG 451 475 PRINTF(2)("Unknown Type not reseting\n"); 452 476 #endif 453 477 break; 454 478 } 455 479 } … … 465 489 { 466 490 case MT_BOOL: 467 491 return MultiType::typeNames[1]; 468 492 case MT_INT: 469 493 return MultiType::typeNames[2]; 470 494 case MT_FLOAT: 471 495 return MultiType::typeNames[3]; 472 496 case MT_CHAR: 473 497 return MultiType::typeNames[4]; 474 498 case MT_STRING: 475 499 return MultiType::typeNames[5]; 476 500 default: 477 501 return MultiType::typeNames[0]; 478 502 } 479 503 } -
trunk/src/lib/util/multi_type.h
r8035 r9869 17 17 MT_BOOL = 1, //!< A bool Value. 18 18 MT_INT = 2, //!< An int Value. 19 MT_UINT = 2, 20 MT_LONG = 2, 19 MT_UINT = 2, //!< A insigned int Value. 20 MT_LONG = 2, //!< A long Value 21 21 MT_FLOAT = 4, //!< A float Value. 22 22 MT_CHAR = 8, //!< A single char. … … 44 44 45 45 MultiType& operator=(const MultiType& mt); 46 /** @param value the value to set (here a bool) @returns the MultiType where this the bool is stored */ 46 47 MultiType& operator=(bool value) { this->setBool(value); return *this; }; 48 /** @param value the value to set (here an int) @returns the MultiType where this the int is stored */ 47 49 MultiType& operator=(int value) { this->setInt(value); return *this; }; 50 /** @param value the value to set (here an int) @returns the MultiType where this the float is stored */ 48 51 MultiType& operator=(float value) { this->setFloat(value); return *this; }; 52 /** @param value the value to set (here a char) @returns the MultiType where this the char is stored */ 49 53 MultiType& operator=(char value) { this->setChar(value); return *this; }; 54 /** @param value the value to set (here a string) @returns the MultiType where this the string is stored */ 50 55 MultiType& operator=(const std::string& value) { this->setString(value); return *this; }; 51 56 52 57 bool operator==(const MultiType& mt) const; 58 /** @param value the value to compare this MultiType against @returns true if comparison was io */ 53 59 bool operator==(bool value) const { return (this->getBool() == value); }; 60 /** @param value the value to compare this MultiType against @returns true if comparison was io */ 54 61 bool operator==(int value) const { return (this->getInt() == value); }; 62 /** @param value the value to compare this MultiType against @returns true if comparison was io */ 55 63 bool operator==(float value) const { return (this->getFloat() == value); }; 64 /** @param value the value to compare this MultiType against @returns true if comparison was io */ 56 65 bool operator==(char value) const { return (this->getChar() == value); }; 66 /** @param value the value to compare this MultiType against @returns true if comparison was io */ 57 67 bool operator==(const std::string& value) const { return (this->getString() == value); }; 68 /** @param type the Type to compare this MultiType against @returns true if the types matched */ 58 69 bool operator==(MT_Type type) const { return (this->type == type); } 70 /** @param type the type to compare this MultiType against @returns true if the types do not match */ 59 71 bool operator!=(MT_Type type) const { return (this->type != type); } 60 72 … … 68 80 69 81 // for your convenience. 82 /** @param value the value to set. Here a bool */ 70 83 inline void setValue(bool value) { this->setBool(value); }; 84 /** @param value the value to set. Here an int */ 71 85 inline void setValue(int value) { this->setInt(value); }; 86 /** @param value the value to set. Here a float */ 72 87 inline void setValue(float value) { this->setFloat(value); }; 88 /** @param value the value to set. Here a char */ 73 89 inline void setValue(char value) { this->setChar(value); }; 90 /** @param value the value to set. Here a char array (string) */ 74 91 inline void setValue(const char* value) { this->setString(value); }; 92 /** @param value the value to set. Here a string */ 75 93 inline void setValue(const std::string& value) { this->setString(value); }; 76 94 void setValueOf(const MultiType& mt); … … 79 97 inline MT_Type getType() const { return this->type; }; 80 98 99 void storeString(); 81 100 82 101 /* RETRIEVING FUNCTIONS */ … … 88 107 std::string getString() const; 89 108 const std::string& getConstString() const; 109 const std::string& getStoredString() const; 90 110 91 111 void reset(); -
trunk/src/lib/util/sigslot/signal.h
r9406 r9869 96 96 { 97 97 public: 98 virtual ~_connection_base0() {}; 98 99 virtual has_slots<mt_policy>* getdest() const = 0; 99 100 virtual void emit() = 0; … … 106 107 { 107 108 public: 109 virtual ~_connection_base1() {}; 108 110 virtual has_slots<mt_policy>* getdest() const = 0; 109 111 virtual void emit(arg1_type) = 0; … … 116 118 { 117 119 public: 120 virtual ~_connection_base2() {}; 118 121 virtual has_slots<mt_policy>* getdest() const = 0; 119 122 virtual void emit(arg1_type, arg2_type) = 0; … … 126 129 { 127 130 public: 131 virtual ~_connection_base3() {}; 128 132 virtual has_slots<mt_policy>* getdest() const = 0; 129 133 virtual void emit(arg1_type, arg2_type, arg3_type) = 0; … … 136 140 { 137 141 public: 142 virtual ~_connection_base4() {}; 138 143 virtual has_slots<mt_policy>* getdest() const = 0; 139 144 virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type) = 0; … … 147 152 { 148 153 public: 154 virtual ~_connection_base5() {}; 149 155 virtual has_slots<mt_policy>* getdest() const = 0; 150 156 virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, … … 161 167 { 162 168 public: 169 virtual ~_connection_base6() {}; 163 170 virtual has_slots<mt_policy>* getdest() const = 0; 164 171 virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, … … 175 182 { 176 183 public: 184 virtual ~_connection_base7() {}; 177 185 virtual has_slots<mt_policy>* getdest() const = 0; 178 186 virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, … … 189 197 { 190 198 public: 199 virtual ~_connection_base8() {}; 191 200 virtual has_slots<mt_policy>* getdest() const = 0; 192 201 virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type, -
trunk/src/lib/util/substring.cc
r9406 r9869 51 51 * @param delimiters multiple set of characters at what to split. (delimiters) 52 52 * @param delimiterNeighbours neighbours of the delimiters, that will be erased only when near a delimiter. 53 * @param emptyEntries If empty entries should be allewed or removed. 53 54 * @param escapeChar The Escape Character that overrides splitters commends and so on... 54 55 * @param safemode_char within these characters splitting won't happen … … 109 110 /** @brief Helper that gets you a String consisting of all WhiteSpaces and the Comma */ 110 111 const std::string SubString::WhiteSpacesWithComma = " \n\t,"; 112 /** An Empty SubString */ 113 const SubString SubString::NullSubString = SubString(); 111 114 112 115 /** … … 145 148 * @brief comparator. 146 149 * @param subString the SubString to compare against this one. 150 * @param length how many entries to compare. (from 0 to length) 147 151 * @returns true if the Stored Strings match 148 152 */ … … 273 277 * @brief splits line into tokens and stores them in ret. 274 278 * @param ret the Array, where the Splitted strings will be stored in 275 * @param offsets an Array of Offsets, here the distance from the inputstring276 279 * to the beginning of the current token is stored 277 280 * @param line the inputLine to split 278 281 * @param delimiters a String of Delimiters (here the input will be splitted) 279 * @param delimiterNeighbour Naighbours to the Delimitter, that will be removed if they are to the left or the right of a Delimiter.282 * @param delimiterNeighbours Naighbours to the Delimitter, that will be removed if they are to the left or the right of a Delimiter. 280 283 * @param emptyEntries: if empty Strings are added to the List of Strings. 281 284 * @param escape_char: Escape carater (escapes splitters) -
trunk/src/lib/util/substring.h
r9406 r9869 33 33 { 34 34 public: 35 //! An enumerator for the State the Parser is in 35 36 typedef enum { 36 SL_NORMAL, 37 SL_ESCAPE, 38 SL_SAFEMODE, 39 SL_SAFEESCAPE, 40 SL_COMMENT, 37 SL_NORMAL, //!< Normal state 38 SL_ESCAPE, //!< After an escape character 39 SL_SAFEMODE, //!< In safe mode (between "" mostly). 40 SL_SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character. 41 SL_COMMENT, //!< In Comment mode. 41 42 } SPLIT_LINE_STATE; 42 43 … … 48 49 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 49 50 char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0'); 51 SubString(unsigned int argc, const char** argv); 50 52 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ 51 SubString(unsigned int argc, const char** argv);52 53 SubString(const SubString& subString) { *this = subString; }; 53 54 SubString(const SubString& subString, unsigned int subSetBegin); … … 110 111 static const std::string WhiteSpaces; 111 112 static const std::string WhiteSpacesWithComma; 113 static const SubString NullSubString; 112 114 113 115 private:
Note: See TracChangeset
for help on using the changeset viewer.