Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9869 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

Location:
trunk/src/lib
Files:
18 deleted
289 edited
46 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/BuildLibs.am

    r9668 r9869  
    11
    22libORXlibs_a_LIBRARIES_ = \
    3                 $(LIB_PREFIX)/util/libORXlibutil.a \
    4                 $(LIB_PREFIX)/shell/libORXshell.a \
    53                $(LIB_PREFIX)/event/libORXevent.a \
    64                $(LIB_PREFIX)/gui/qt/libORXqtgui.a \
    75                $(LIB_PREFIX)/gui/gl/libORXglgui.a \
    86                $(LIB_PREFIX)/gui/libORXbasegui.a \
    9                 $(LIB_PREFIX)/script_engine/libORXscript.a \
    10                 $(LIB_PREFIX)/graphics/importer/libORXimporter.a \
    117                $(LIB_PREFIX)/graphics/libORXgraphics.a \
    12                 $(LIB_PREFIX)/graphics/importer/libtc.a \
    13                 $(LIB_PREFIX)/sound/libORXsound.a \
    14                 $(LIB_PREFIX)/particles/libORXparticles.a \
    158                $(LIB_PREFIX)/collision_detection/libORXcd.a \
    169                $(LIB_PREFIX)/collision_reaction/libORXcr.a \
     
    2316                $(LIB_PREFIX)/physics/libORXphysics.a \
    2417                $(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 \
    2522                $(LIB_PREFIX)/shell/libORXshell.a \
    26                 $(LIB_PREFIX)/math/libORXmath.a \
     23                $(LIB_PREFIX)/script_engine/libORXscript.a \
     24                $(LIB_PREFIX)/util/libORXexecutor.a \
    2725                $(LIB_PREFIX)/util/libORXlibutil.a \
    2826                $(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  
    2525        event \
    2626        physics \
    27         particles \
    2827        collision_detection \
    2928        collision_reaction \
    3029        gui \
    3130        network \
     31        shell \
    3232        parser \
    33         shell \
    3433        script_engine
  • trunk/src/lib/collision_detection/aabb.cc

    r9406 r9869  
    2121
    2222
    23 
     23ObjectListDefinition(AABB);
    2424/**
    2525 *  standard constructor
     
    2727AABB::AABB ()
    2828{
    29    this->setClassID(CL_OBB, "AABB");
     29  this->registerObject(this, AABB::_objectList);
    3030   this->halfLength[0] = this->halfLength[1] = this->halfLength[2] = 0.0f;
    3131   this->bCollided = false;
  • trunk/src/lib/collision_detection/aabb.h

    r8724 r9869  
    1111#include "bounding_volume.h"
    1212
    13 template<class T> class tList;
    14 
    1513//! A class representing an extended bounding volume tree: an obb tree
    1614class AABB : public BoundingVolume {
     15  ObjectListDeclaration(AABB);
    1716
    1817 public:
  • trunk/src/lib/collision_detection/aabb_tree_node.cc

    r9494 r9869  
    3232#include "debug.h"
    3333
    34 
    35 
    36 
    37 
    38 
    3934GLUquadricObj* AABBTreeNode_sphereObj = NULL;
    4035
    41 
     36ObjectListDefinition(AABBTreeNode);
    4237/**
    4338 *  standard constructor
     
    4843    : BVTreeNode()
    4944{
    50   this->setClassID(CL_OBB_TREE_NODE, "AABBTreeNode");
     45  this->registerObject(this, AABBTreeNode::_objectList);
    5146
    5247  this->obbTree = &tree;
  • trunk/src/lib/collision_detection/aabb_tree_node.h

    r8724 r9869  
    2121class AABBTreeNode : public BVTreeNode
    2222{
     23  ObjectListDeclaration(AABBTreeNode);
    2324
    2425
  • trunk/src/lib/collision_detection/bounding_sphere.cc

    r9406 r9869  
    2020
    2121
    22 
     22ObjectListDefinition(BoundingSphere);
    2323/**
    2424 *  standard constructor
     
    2626BoundingSphere::BoundingSphere ()
    2727{
    28    this->setClassID(CL_BOUNDING_SPHERE, "BoundingSphere");
     28  this->registerObject(this, BoundingSphere::_objectList);
    2929}
    3030
  • trunk/src/lib/collision_detection/bounding_sphere.h

    r5039 r9869  
    1 /*! 
     1/*!
    22 * @file bounding_sphere.h
    33  *  Definition of a bounding sphere
     
    1414//! A class representing an extended bounding volume tree: an sphere
    1515class BoundingSphere : public BoundingVolume {
     16  ObjectListDeclaration(BoundingSphere);
    1617
    1718 public:
  • trunk/src/lib/collision_detection/bounding_volume.cc

    r9406 r9869  
    2020
    2121
    22 
     22ObjectListDefinition(BoundingVolume);
    2323/**
    2424 *  standard constructor
     
    2626BoundingVolume::BoundingVolume ()
    2727{
    28   this->setClassID(CL_BOUNDING_VOLUME, "BoundingVolume");
     28  this->registerObject(this, BoundingVolume::_objectList);
    2929  this->modelInf = NULL;
    3030  this->triangleIndexes = NULL;
  • trunk/src/lib/collision_detection/bounding_volume.h

    r9008 r9869  
    1717//! An abstract class representing a bounding volume
    1818class BoundingVolume : public BaseObject {
     19  ObjectListDeclaration(BoundingVolume);
    1920
    2021  public:
  • trunk/src/lib/collision_detection/bv_tree.cc

    r9406 r9869  
    2121
    2222
    23 
     23ObjectListDefinition(BVTree);
    2424/**
    2525 *  standard constructor
     
    2727BVTree::BVTree ()
    2828{
    29    this->setClassID(CL_BV_TREE, "BVTree");
     29  this->registerObject(this, BVTree::_objectList);
    3030
    3131}
  • trunk/src/lib/collision_detection/bv_tree.h

    r7711 r9869  
    3636class BVTree : public BaseObject
    3737{
     38  ObjectListDeclaration(BVTree);
    3839
    3940  public:
  • trunk/src/lib/collision_detection/bv_tree_node.cc

    r9406 r9869  
    2020
    2121
    22 
     22ObjectListDefinition(BVTreeNode);
    2323/**
    2424 *  standard constructor
     
    2626BVTreeNode::BVTreeNode ()
    2727{
    28    this->setClassID(CL_BV_TREE_NODE, "BVTreeNode");
     28  this->registerObject(this, BVTreeNode::_objectList);
    2929
    3030}
  • trunk/src/lib/collision_detection/bv_tree_node.h

    r7732 r9869  
    2424//! A class that represents a bounding volume tree
    2525class BVTreeNode : public BaseObject {
     26  ObjectListDeclaration(BVTreeNode);
    2627
    2728
  • trunk/src/lib/collision_detection/cd_engine.cc

    r9406 r9869  
    2020#include "debug.h"
    2121
    22 #include "class_list.h"
    23 
    2422#include "model.h"
    2523#include "world_entity.h"
     
    3634
    3735
    38 
     36ObjectListDefinition(CDEngine);
    3937/**
    40  * standard constructor
     38 * @brief standard constructor
    4139 */
    4240CDEngine::CDEngine ()
    4341{
    44   this->setClassID(CL_CD_ENGINE, "CDEngine");
     42  this->registerObject(this, CDEngine::_objectList);
    4543
    4644  this->bAbordOnFirstCollision = false;
     
    103101void CDEngine::checkCollisionGround(std::list<WorldEntity*>& list1)
    104102{
    105 
    106   std::list<BaseObject*>::const_iterator bspIterator;
    107103  std::list<WorldEntity*>::iterator entityIterator;
    108   const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);
    109   if( bspList == NULL)
    110     return;
    111 
    112104  // 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++) {
    114108      for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
    115109      {
  • trunk/src/lib/collision_detection/cd_engine.h

    r8186 r9869  
    3636//! The class representing the collision detection system of orxonox
    3737class CDEngine : public BaseObject {
     38  ObjectListDeclaration(CDEngine);
    3839
    3940  friend class WorldEntity;
  • trunk/src/lib/collision_detection/obb.cc

    r9406 r9869  
    2121
    2222
    23 
     23ObjectListDefinition(OBB);
    2424/**
    2525 *  standard constructor
     
    2727OBB::OBB ()
    2828{
    29    this->setClassID(CL_OBB, "OBB");
     29  this->registerObject(this, OBB::_objectList);
    3030   this->halfLength[0] = this->halfLength[1] = this->halfLength[2] = 0.0f;
    3131   this->bCollided = false;
  • trunk/src/lib/collision_detection/obb.h

    r7711 r9869  
    1515//! A class representing an extended bounding volume tree: an obb tree
    1616class OBB : public BoundingVolume {
     17  ObjectListDeclaration(OBB);
    1718
    1819 public:
  • trunk/src/lib/collision_detection/obb_tree.cc

    r9406 r9869  
    2727
    2828
    29 
     29ObjectListDefinition(OBBTree);
    3030/**
    3131 *  standard constructor
     
    5151void OBBTree::init()
    5252{
    53   this->setClassID(CL_OBB_TREE, "OBBTree");
     53  this->registerObject(this, OBBTree::_objectList);
    5454  this->rootNode = NULL;
    5555  this->id = 0;
  • trunk/src/lib/collision_detection/obb_tree.h

    r9235 r9869  
    2020class OBBTree : public BVTree
    2121{
     22  ObjectListDeclaration(OBBTree);
    2223
    2324  public:
  • trunk/src/lib/collision_detection/obb_tree_node.cc

    r9406 r9869  
    3838GLUquadricObj* OBBTreeNode_sphereObj = NULL;
    3939
    40 
     40ObjectListDefinition(OBBTreeNode);
    4141/**
    4242 *  standard constructor
     
    4747    : BVTreeNode()
    4848{
    49   this->setClassID(CL_OBB_TREE_NODE, "OBBTreeNode");
     49  this->registerObject(this, OBBTreeNode::_objectList);
    5050
    5151  this->obbTree = &tree;
     
    284284
    285285/**
    286  * calculate the eigenvectors for the object oriented box
     286 * @brief calculate the eigenvectors for the object oriented box
    287287 * @param box: reference to the box
    288288 * @param modelInf: the model info structure of the model
     
    361361
    362362/**
    363  * this separates an ob-box in the middle
     363 * @brief this separates an ob-box in the middle
    364364 * @param box: the box to separate
    365365 *
  • trunk/src/lib/collision_detection/obb_tree_node.h

    r9235 r9869  
    1717class PNode;
    1818
    19 
    2019//! A class that represents a bounding volume tree
    2120class OBBTreeNode : public BVTreeNode
    2221{
    23 
    24 
     22  ObjectListDeclaration(OBBTreeNode);
    2523  public:
    2624    OBBTreeNode(const OBBTree& tree, OBBTreeNode* prev, int depth);
  • trunk/src/lib/collision_reaction/collision.cc

    r9406 r9869  
    1818#include "collision.h"
    1919#include "debug.h"
    20 
    21 
    22 
    2320
    2421/**
  • trunk/src/lib/collision_reaction/collision.h

    r8490 r9869  
    2121class Collision
    2222{
    23 
    2423  public:
    2524    Collision();
  • trunk/src/lib/collision_reaction/collision_event.cc

    r9406 r9869  
    1818#include "collision_event.h"
    1919#include "debug.h"
    20 
    21 
    22 
    2320
    2421/**
  • trunk/src/lib/collision_reaction/collision_event.h

    r8894 r9869  
    2020//! A class representing a simple collision
    2121class CollisionEvent {
    22 
    2322 public:
    2423   CollisionEvent();
  • trunk/src/lib/collision_reaction/collision_handle.cc

    r9406 r9869  
    3030
    3131
    32 
     32ObjectListDefinition(CollisionHandle);
    3333
    3434/**
     
    3838CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type)
    3939{
    40   this->setClassID(CL_COLLISION_HANDLE, "CollisionHandle");
     40  this->registerObject(this, CollisionHandle::_objectList);
    4141
    4242  this->owner = owner;
     
    9494 *  @param classID the classid to look for
    9595 */
    96 void CollisionHandle::addTarget(long target)
     96void CollisionHandle::addTarget(const ClassID& target)
    9797{
    9898  // make sure there is no dublicate
    99   std::vector<long>::iterator it = this->targetList.begin();
     99  std::vector<ClassID>::iterator it = this->targetList.begin();
    100100  for( ; it < this->targetList.end(); it++)
    101101    if( (*it) == target)
    102102      return;
    103103
     104
    104105  // 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());
    108108}
    109109
     
    227227bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent)
    228228{
    229   std::vector<long>::iterator it = this->targetList.begin();
     229  std::vector<ClassID>::iterator it = this->targetList.begin();
    230230  for(; it < this->targetList.end(); it++)
    231231  {
     
    253253
    254254    if( collisionEvent->getEntityA() == this->owner) {
    255       if( collisionEvent->getEntityB()->isA((ClassID)(*it))) {
     255      if( collisionEvent->getEntityB()->isA((*it))) {
    256256        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());
    258258        return true; }
    259259    }
    260260    else {
    261       if( collisionEvent->getEntityA()->isA((ClassID)(*it))) {
     261      if( collisionEvent->getEntityA()->isA((*it))) {
    262262        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());
    264264      return true; }
    265265    }
     
    276276bool CollisionHandle::filterCollision(Collision* collision)
    277277{
    278   std::vector<long>::iterator it = this->targetList.begin();
     278  std::vector<ClassID>::iterator it = this->targetList.begin();
    279279  for(; it < this->targetList.end(); it++)
    280280  {
     
    302302
    303303    if( collision->getEntityA() == this->owner) {
    304       if( collision->getEntityA()->isA((ClassID)(*it)))
     304      if( collision->getEntityA()->isA(*it))
    305305        return true; }
    306306      else {
    307         if( collision->getEntityB()->isA((ClassID)(*it)))
     307        if( collision->getEntityB()->isA(*it))
    308308          return true; }
    309309  }
  • trunk/src/lib/collision_reaction/collision_handle.h

    r8490 r9869  
    2323class CollisionHandle : public BaseObject
    2424{
    25 
     25  ObjectListDeclaration(CollisionHandle);
    2626  public:
    2727    CollisionHandle(WorldEntity* owner, CREngine::CRType type);
     
    3030    void reset();
    3131
    32     void addTarget(long target);
     32    void addTarget(const ClassID& target);
    3333    Collision* registerCollision(WorldEntity* entityA, WorldEntity* entityB);
    3434    void registerSharedCollision(Collision* collision);
     
    6464
    6565    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
    6768
    6869    CollisionReaction*            collisionReaction;       //!< reference to the collision reaction object
  • trunk/src/lib/collision_reaction/collision_reaction.cc

    r9406 r9869  
    2020
    2121
    22 
     22ObjectListDefinition(CollisionReaction);
    2323
    2424/**
     
    2828  : BaseObject()
    2929{
    30   this->setClassID(CL_COLLISION_REACTION, "CollisionReaction");
     30  this->registerObject(this, CollisionReaction::_objectList);
    3131}
    3232
  • trunk/src/lib/collision_reaction/collision_reaction.h

    r8490 r9869  
    1818class CollisionReaction : public BaseObject
    1919{
    20 
     20  ObjectListDeclaration(CollisionReaction);
    2121  public:
    2222    CollisionReaction();
  • trunk/src/lib/collision_reaction/cr_engine.cc

    r9406 r9869  
    2929
    3030
    31 
     31ObjectListDefinition(CREngine);
    3232/**
    3333 * standard constructor
     
    3636  : BaseObject()
    3737{
    38    this->setClassID(CL_CR_ENGINE, "CREngine");
     38  this->registerObject(this, CREngine::_objectList);
    3939   this->setName("CREngine");
    4040
  • trunk/src/lib/collision_reaction/cr_engine.h

    r9235 r9869  
    2525class CREngine : public BaseObject
    2626{
     27  ObjectListDeclaration(CREngine);
    2728
    2829  public:
  • trunk/src/lib/collision_reaction/cr_object_damage.cc

    r9406 r9869  
    2828
    2929
    30 
     30ObjectListDefinition(CRObjectDamage);
    3131/**
    3232 *  standard constructor
     
    3535  : CollisionReaction()
    3636{
    37   this->setClassID(CL_CR_OBJECT_DAMAGE, "CRObjectDamage");
    38 
     37  this->registerObject(this, CRObjectDamage::_objectList);
    3938}
    4039
  • trunk/src/lib/collision_reaction/cr_object_damage.h

    r8190 r9869  
    1515class CRObjectDamage : public CollisionReaction
    1616{
     17  ObjectListDeclaration(CRObjectDamage);
    1718  public:
    1819    CRObjectDamage();
  • trunk/src/lib/collision_reaction/cr_physics_full_walk.cc

    r9406 r9869  
    3535
    3636
    37 
     37ObjectListDefinition(CRPhysicsFullWalk);
    3838/**
    3939 *  standard constructor
     
    4242    : CollisionReaction()
    4343{
    44   this->setClassID(CL_CR_PHYSICS_FULL_WALK, "CRPhysicsFullWalk");
     44  this->registerObject(this, CRPhysicsFullWalk::_objectList);
    4545}
    4646
  • trunk/src/lib/collision_reaction/cr_physics_full_walk.h

    r9235 r9869  
    1515class CRPhysicsFullWalk : public CollisionReaction
    1616{
     17  ObjectListDeclaration(CRPhysicsFullWalk);
    1718  public:
    1819    CRPhysicsFullWalk();
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r9406 r9869  
    3535
    3636
    37 
     37ObjectListDefinition(CRPhysicsGroundWalk);
    3838/**
    3939 *  standard constructor
     
    4242    : CollisionReaction()
    4343{
    44   this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");
     44  this->registerObject(this, CRPhysicsGroundWalk::_objectList);
    4545}
    4646
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.h

    r8894 r9869  
    1515class CRPhysicsGroundWalk : public CollisionReaction
    1616{
     17  ObjectListDeclaration(CRPhysicsGroundWalk);
    1718  public:
    1819    CRPhysicsGroundWalk();
  • trunk/src/lib/coord/p_node.cc

    r9656 r9869  
    1919
    2020#include "util/loading/load_param.h"
    21 #include "class_list.h"
    2221
    2322#include "netdefs.h"
     
    3029#include "color.h"
    3130
     31
     32ObjectListDefinition(PNode);
    3233/**
    3334 * @brief standard constructor
     
    3839  : BaseObject(), Synchronizeable()
    3940{
    40   this->setClassID(CL_PARENT_NODE, "PNode");
     41  this->registerObject(this, PNode::_objectList);
    4142
    4243  this->bRelCoorChanged = true;
     
    7980  PRINTF(4)("delete %s::%s\n", this->getClassCName(), this->getCName());
    8081  // 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
    8385  while(!this->children.empty())
    8486  {
    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    }
    8794    if ((this->parentMode & PNODE_PROHIBIT_CHILD_DELETE) ||
    88         ((*deleteNode)->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
     95        (deleteNode->parentMode & PNODE_PROHIBIT_DELETE_WITH_PARENT))
    8996    {
    90       if (this == PNode::nullParent && (*deleteNode)->parentMode & PNODE_REPARENT_TO_NULL)
     97      if (this == PNode::nullParent && deleteNode->parentMode & PNODE_REPARENT_TO_NULL)
    9198      {
    9299        PRINTF(4)("%s::%s deletes %s::%s\n",
    93100                  this->getClassCName(), this->getCName(),
    94                   (*deleteNode)->getClassCName(), (*deleteNode)->getCName());
    95         delete (*deleteNode);
     101                  deleteNode->getClassCName(), deleteNode->getCName());
     102        delete deleteNode;
    96103      }
    97104      else
     
    99106        PRINTF(4)("%s::%s reparents %s::%s\n",
    100107                  this->getClassCName(), this->getCName(),
    101                   (*deleteNode)->getClassCName(), (*deleteNode)->getCName());
    102         (*deleteNode)->reparent();
     108                  deleteNode->getClassCName(), deleteNode->getCName());
     109        deleteNode->reparent();
    103110      }
    104111    }
     
    107114      PRINTF(4)("%s::%s deletes PNode: %s::%s\n",
    108115                this->getClassCName(), this->getCName(),
    109                 (*deleteNode)->getClassCName(), (*deleteNode)->getCName());
    110       delete (*deleteNode);
     116                deleteNode->getClassCName(), deleteNode->getCName());
     117      delete deleteNode;
    111118    }
     119    last = deleteNode;
    112120  }
    113121
     
    541549void PNode::addChild (const std::string& childName)
    542550{
    543   PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
     551  PNode* childNode = PNode::objectList().getObject(childName);
    544552  //  PRINTF(0)("Adding the Child: %s to: %s\n", childName, this->getName());
    545553  //  assert( childNode != NULL );
     
    625633void PNode::setParent (const std::string& parentName)
    626634{
    627   PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
     635  PNode* parentNode = PNode::objectList().getObject(parentName);
    628636  if (parentNode != NULL)
    629637    parentNode->addChild(this);
     
    681689void PNode::setParentSoft(const std::string& parentName, float bias)
    682690{
    683   PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
     691  PNode* parentNode = PNode::objectList().getObject(parentName);
    684692  if (parentNode != NULL)
    685693    this->setParentSoft(parentNode, bias);
     
    730738  if (likely(PNode::nullParent == NULL))
    731739  {
    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);
    734742    PNode::nullParent->setName("NullParent");
    735743    PNode::nullParent->setSynchronized(true);
     
    915923  int childNodeCount = 0;
    916924  this->countChildNodes(childNodeCount);
    917 
     925  printf("%p:", this);
    918926  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",
    919927           this->getClassCName(),
     
    11061114}
    11071115
    1108 
     1116ObjectListDefinition(NullParent);
     1117
     1118NullParent::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  
    5050  PNODE_REPARENT_DELETE_CHILDREN       = 0x0040,    //!< Deletes the Children of the node when This Node is Removed. (Use with care).
    5151  /// FIXME
    52    PNODE_REPARENT_KEEP_POSITION         = 0x0080,    //!< Tries to keep the Position if the Node is reparented.
     52  PNODE_REPARENT_KEEP_POSITION         = 0x0080,    //!< Tries to keep the Position if the Node is reparented.
    5353
    5454
     
    7373
    7474//! 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:
     75class PNode : virtual public BaseObject, virtual public Synchronizeable
     76{
     77  ObjectListDeclaration(PNode);
     78
     79public:
    7780  PNode (PNode* parent = PNode::getNullParent(), long nodeFlags = PNODE_PARENT_MODE_DEFAULT);
    7881  virtual ~PNode ();
     
    9598  inline const Vector& getRelCoor () const { return this->prevRelCoordinate; };
    9699  /** @returns the Relative Coordinate Destination */
    97   inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)? *this->toCoordinate : this->relCoordinate; };
     100inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)? *this->toCoordinate : this->relCoordinate; };
    98101  void setAbsCoor (const Vector& absCoord);
    99102  void setAbsCoor (float x, float y, float z);
     
    130133  inline const Quaternion& getRelDir () const { return this->prevRelDirection; };
    131134  /** @returns the Relative Directional Destination */
    132   inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)? *this->toDirection : this->relDirection; };
     135inline const Quaternion& getRelDirSoft2D() const { return (this->toDirection)? *this->toDirection : this->relDirection; };
    133136  /** @returns a Vector pointing into the relative Direction */
    134137  inline Vector getRelDirV() const { return this->prevRelDirection.apply(Vector(0,1,0)); };
     
    178181  void removeNodeFlags(unsigned short nodeFlags);
    179182
    180   // NULL_PARENT //
    181183  /** @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(); };
     184static PNode* getNullParent()  { return (PNode::nullParent != NULL) ? PNode::nullParent : PNode::createNullParent(); };
    183185
    184186  // UPDATING //
     
    195197  float distance(const PNode* node) const { return (this->getAbsCoor() - node->getAbsCoor()).len(); };
    196198
    197  private:
     199private:
    198200  /** tells the child that the parent's Coordinate has changed */
    199201  inline void parentCoorChanged () { this->bRelCoorChanged = true; }
    200202  /** tells the child that the parent's Direction has changed */
    201203  inline void parentDirChanged () { this->bRelDirChanged = true; }
    202  public:
     204public:
    203205  /** @returns the last calculated coordinate */
    204206  inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
    205  private:
     207private:
    206208  static PNode* createNullParent();
    207209  void reparent();
     
    209211  void eraseChild(PNode* child);
    210212
    211  private:
     213private:
    212214  bool               bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
    213215  bool               bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
     
    221223  Vector             lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
    222224  Quaternion         prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
    223 //  Quaternion         lastAbsDirection;
     225  //  Quaternion         lastAbsDirection;
    224226
    225227  Vector             velocity;           //!< Saves the velocity.
     
    238240  static PNode*      nullParent;         //!< The ROOT of the main PNode Tree.
    239241
    240   private:
    241     float coorx;
    242     float coory;
    243     float coorz;
    244 
    245     float rotw;
    246     float rotx;
    247     float roty;
    248     float rotz;
    249 
    250   private:
    251     int relCoordinate_handle;
    252     int relDirection_handle;
    253     Vector relCoordinate_write;
    254     Quaternion relDirection_write;
    255 
    256   public:
    257     virtual void varChangeHandler( std::list<int> & id );
     242private:
     243  float coorx;
     244  float coory;
     245  float coorz;
     246
     247  float rotw;
     248  float rotx;
     249  float roty;
     250  float rotz;
     251
     252private:
     253  int relCoordinate_handle;
     254  int relDirection_handle;
     255  Vector relCoordinate_write;
     256  Quaternion relDirection_write;
     257
     258public:
     259  virtual void varChangeHandler( std::list<int> & id );
    258260};
    259261
     262// NULL_PARENT //
     263class NullParent : public PNode
     264{
     265  ObjectListDeclaration(NullParent);
     266  friend class PNode;
     267  NullParent();
     268};
     269
     270
    260271#endif /* _P_NODE_H */
  • trunk/src/lib/event/event_handler.cc

    r9656 r9869  
    2828#include <algorithm>
    2929
     30
     31ObjectListDefinition(EventHandler);
    3032/**
    3133 * @brief standard constructor
     
    3335EventHandler::EventHandler ()
    3436{
    35   this->setClassID(CL_EVENT_HANDLER, "EventHandler");
     37  this->registerObject(this, EventHandler::_objectList);
    3638  this->setName("EventHandler");
    3739
  • trunk/src/lib/event/event_handler.h

    r8743 r9869  
    2121class EventHandler : public BaseObject
    2222{
    23 
     23  ObjectListDeclaration(EventHandler);
    2424public:
    2525  virtual ~EventHandler();
  • trunk/src/lib/event/event_listener.cc

    r7868 r9869  
    1919#include "event_handler.h"
    2020
     21ObjectListDefinition(EventListener);
    2122/**
    2223 * @brief standard constructor
     
    2425EventListener::EventListener ()
    2526{
    26   this->setClassID(CL_EVENT_LISTENER, "EventListener");
     27  this->registerObject(this, EventListener::_objectList);
    2728}
    2829
  • trunk/src/lib/event/event_listener.h

    r7868 r9869  
    1212
    1313//! A class for event listener
    14 class EventListener : virtual public BaseObject {
    15 
    16  public:
     14class EventListener : virtual public BaseObject
     15{
     16  ObjectListDeclaration(EventListener);
     17public:
    1718  EventListener();
    1819  virtual ~EventListener();
  • trunk/src/lib/event/key_mapper.cc

    r9406 r9869  
    2525#include "globals.h"
    2626#include "parser/ini_parser/ini_parser.h"
    27 #include "util/preferences.h"
     27#include "parser/preferences/preferences.h"
    2828#include "key_names.h"
    2929#include "event_def.h"
     
    3232
    3333
    34 
     34ObjectListDefinition(KeyMapper);
    3535
    3636/* initialize all variables to a reasonable value*/
     
    116116KeyMapper::KeyMapper ()
    117117{
    118    this->setClassID(CL_KEY_MAPPER, "KeyMapper");
     118  this->registerObject(this, KeyMapper::_objectList);
    119119}
    120120
  • trunk/src/lib/event/key_mapper.h

    r8724 r9869  
    1616class KeyMapper : public BaseObject
    1717{
     18  ObjectListDeclaration(KeyMapper);
    1819public:
    1920  //! A mapping from key-name to key-id
  • trunk/src/lib/graphics/Makefile.am

    r9006 r9869  
    66libORXgraphics_a_SOURCES = \
    77                graphics_engine.cc \
     8                graphics_effect.cc \
    89                light.cc \
    910                shader.cc \
     11                shader_data.cc \
     12                resource_shader.cc \
    1013                \
    1114                render2D/render_2d.cc \
     
    1922                text_engine/font.cc \
    2023                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
    3325
    3426noinst_HEADERS =\
    3527                graphics_engine.h \
     28                graphics_effect.h \
    3629                light.h \
    3730                shader.h \
     31                shader_data.h \
     32                resource_shader.h \
    3833                \
    3934                render2D/render_2d.h \
     
    4742                text_engine/font.h \
    4843                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
    6246
    6347
  • trunk/src/lib/graphics/graphics_engine.cc

    r9406 r9869  
    1717
    1818#include "graphics_engine.h"
    19 #include "util/loading/resource_manager.h"
    2019#include "state.h"
    2120
     
    2827#include "debug.h"
    2928
    30 #include "util/preferences.h"
     29#include "parser/preferences/preferences.h"
    3130#include "substring.h"
    3231#include "text.h"
     
    3534#include "texture.h"
    3635
    37 #include "effects/graphics_effect.h"
    38 #include "effects/fog_effect.h"
    39 #include "effects/lense_flare.h"
     36#include "graphics_effect.h"
    4037
    4138#include "shell_command.h"
    42 
     39#include "loading/load_param_xml.h"
    4340
    4441#include "parser/tinyxml/tinyxml.h"
    4542#include "util/loading/load_param.h"
    4643#include "util/loading/factory.h"
    47 #include "class_list.h"
    4844
    4945#ifdef __WIN32__
     
    5450SHELL_COMMAND(fps, GraphicsEngine, toggleFPSdisplay);
    5551
     52ObjectListDefinition(GraphicsEngine);
     53
    5654/**
    5755 * @brief standard constructor
     
    5957GraphicsEngine::GraphicsEngine ()
    6058{
    61   this->setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine");
     59  this->registerObject(this, GraphicsEngine::_objectList);
    6260  this->setName("GraphicsEngine");
    6361
     
    117115{
    118116  LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffects)
    119   .describe("loads a graphics effect");
     117   .describe("loads a graphics effect");
    120118}
    121119
     
    590588
    591589  // 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);
    598594}
    599595
     
    688684  {
    689685    case EV_VIDEO_RESIZE:
    690       this->resolutionChanged(event.resize);
    691       break;
    692   }
    693 }
     686    this->resolutionChanged(event.resize);
     687    break;
     688  }
     689}
  • trunk/src/lib/graphics/graphics_engine.h

    r9406 r9869  
    3030class GraphicsEngine : public EventListener
    3131{
     32  ObjectListDeclaration(GraphicsEngine);
    3233  public:
    3334    virtual ~GraphicsEngine();
  • trunk/src/lib/graphics/importer/Makefile.am

    r8724 r9869  
    44noinst_LIBRARIES = libORXimporter.a libtc.a
    55
    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
     6libORXimporter_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
    4146
    4247
     
    5459                grid.h \
    5560                static_model.h \
     61                static_model_data.h \
    5662                objModel.h \
     63                resource_obj.h \
    5764                primitive_model.h \
    5865                anorms.h \
     
    6370                texture.h \
    6471                texture_data.h \
     72                resource_texture.h \
    6573                texture_sequence.h \
    6674                \
     
    7482                \
    7583                md2/md2Model.h \
     84                md2/resource_md2.h \
    7685                \
    7786                md3/md3_model.h \
  • trunk/src/lib/graphics/importer/bsp_file.cc

    r9406 r9869  
    466466    PRINTF(4)("BSP FILE: Name %s . \n", fileName);
    467467
    468     absFileName = ResourceManager::getFullName(fileName);
     468    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    469469
    470470    if(File(absFileName).exists()) {
     
    481481    strncat (fileName, ext, strlen(fileName));
    482482
    483     absFileName = ResourceManager::getFullName(fileName);
     483    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    484484
    485485    if(File(absFileName).exists()) {
     
    496496    strncat (fileName, ext, strlen(fileName));
    497497
    498     absFileName = ResourceManager::getFullName(fileName);
     498    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    499499
    500500    if(File(absFileName).exists()) {
     
    511511    strncat (fileName, ext, strlen(fileName));
    512512
    513     absFileName = ResourceManager::getFullName(fileName);
     513    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    514514
    515515    if(File(absFileName).exists()) {
     
    524524    strcpy(ext, ".TGA");
    525525    strncat (fileName, ext, strlen(fileName));
    526     absFileName = ResourceManager::getFullName(fileName);
     526    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    527527
    528528    if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) {
     
    537537    strcpy(ext, ".jpg");
    538538    strncat (fileName, ext, strlen(fileName));
    539     absFileName = ResourceManager::getFullName(fileName);
     539    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    540540    if(File(absFileName).exists()) {
    541541      PRINTF(4)("BSP FILE: gefunden . \n");
     
    551551    strcpy(ext, ".JPG");
    552552    strncat (fileName, ext, strlen(fileName));
    553     absFileName = ResourceManager::getFullName(fileName);
     553    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    554554    if(File(absFileName).exists()) {
    555555      PRINTF(4)("BSP FILE: gefunden . \n");
     
    566566    strcpy(ext, ".bmp");
    567567    strncat (fileName, ext, strlen(fileName));
    568     absFileName = ResourceManager::getFullName(fileName);
     568    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    569569
    570570    if(File(absFileName).exists()) {
     
    580580    strcpy(ext, ".BMP");
    581581    strncat (fileName, ext, strlen(fileName));
    582     absFileName = ResourceManager::getFullName(fileName);
     582    absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    583583
    584584    if(File(absFileName).exists()) {
     
    611611  this->testSurf = NULL;
    612612
    613   this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str());
     613  this->testSurf = IMG_Load(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(mat).c_str());
    614614  if(this->testSurf != NULL) {
    615615    if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true;
  • trunk/src/lib/graphics/importer/bsp_manager.cc

    r9235 r9869  
    3333#include "world_entities/player.h"
    3434#include "world_entities/playable.h"
    35 #include "util/loading/resource_manager.h"
     35
    3636// STL Containers
    3737#include <vector>
     
    4141#include "world_entity.h"
    4242
     43#include "util/loading/resource_manager.h"
    4344#include "util/loading/load_param.h"
    4445#include "util/loading/factory.h"
     
    9192  this->bspFile = new BspFile();
    9293  this->bspFile->scale =  scale;
    93   if(this->bspFile->read(ResourceManager::getFullName(fileName).c_str()) == -1)
     94  if(this->bspFile->read(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName).c_str()) == -1)
    9495    return -1;
    9596
     
    13761377    if( this->outputFraction == 1.0f) // No collision Detected
    13771378    {
    1378       if( this->outputAllSolid ) 
     1379      if( this->outputAllSolid )
    13791380      {
    13801381        this->collPlane = new plane;
  • trunk/src/lib/graphics/importer/height_map.cc

    r8316 r9869  
    2222#include "p_node.h"
    2323#include "state.h"
    24 #include "util/loading/resource_manager.h"
    2524#include "debug.h"
    2625
     
    327326
    328327
     328ObjectListDefinition(HeightMap);
    329329
    330330
     
    413413void HeightMap::init(const std::string& heightMapName)
    414414{
    415   this->setClassID(CL_HEIGHT_MAP, "HeightMap");
     415  this->registerObject(this, HeightMap::_objectList);
    416416
    417417  this->shiftX = 0;
  • trunk/src/lib/graphics/importer/height_map.h

    r7526 r9869  
    2929
    3030class SDL_Surface;
    31 class Vector;
    3231class Material;
    33 class PNode;
    3432class Texture;
    3533class HeightMap;
     
    7068
    7169
     70
    7271//!< the height map representation itself
    7372class HeightMap : public VertexArrayModel
    7473{
     74  ObjectListDeclaration(HeightMap);
    7575  friend class Tile;
    7676
  • trunk/src/lib/graphics/importer/interactive_model.cc

    r9406 r9869  
    2222
    2323
     24ObjectListDefinition(InteractiveModel);
     25
    2426/**
    2527 * standard constructor
     
    2830InteractiveModel::InteractiveModel()
    2931{
    30   this->setClassID(CL_INTERACTIVE_MODEL, "InteractiveModel");
     32  this->registerObject(this, InteractiveModel::_objectList);
    3133}
    3234
  • trunk/src/lib/graphics/importer/interactive_model.h

    r9003 r9869  
    3030class InteractiveModel : public Model
    3131{
     32  ObjectListDeclaration(InteractiveModel);
    3233  public:
    3334    InteractiveModel();
     
    3839    virtual void setAnimation(int animNum, int playbackMode = 0) = 0;
    3940    virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback) {}
    40     virtual int getAnimation() = 0;
     41    virtual int getAnimation() const = 0;
    4142
    4243    virtual bool isAnimationFinished() { return false; }
  • trunk/src/lib/graphics/importer/material.cc

    r9406 r9869  
    2525#include "loading/load_param.h"
    2626
    27 #include "util/loading/resource_manager.h"
     27#include "resource_texture.h"
     28
     29ObjectListDefinition(Material);
    2830
    2931/**
     
    3335Material::Material (const std::string& mtlName)
    3436{
    35   this->setClassID(CL_MATERIAL, "Material");
     37  this->registerObject(this, Material::_objectList);
    3638
    3739  this->setIllum(3);
     
    9092  PRINTF(5)("delete Material %s.\n", this->getCName());
    9193
    92   if (this->ambientTexture != NULL)
    93     ResourceManager::getInstance()->unload(this->ambientTexture);
    94   if (this->specularTexture != NULL)
    95     ResourceManager::getInstance()->unload(this->specularTexture);
    96 
    9794  if (this == Material::selectedMaterial)
    9895    Material::selectedMaterial = NULL;
     
    10198
    10299const Material* Material::selectedMaterial = NULL;
    103 
    104 
    105 /// TODO FIX THIS
    106 // 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; /// FIXME
    120 //   this->specularTexture = NULL; /// FIXME
    121 //
    122 //   this->setName(m.getName());
    123 // }
    124 
    125 
    126100
    127101/**
     
    288262
    289263
    290 
    291 /**
    292  * @brief Adds a Texture Path to the List of already existing Paths
    293  * @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 
    303264/**
    304265 * @brief Sets the Diffuse map of this Texture.
     
    322283 * @param textureNumber The Texture-Number from 0 to GL_MAX_TEXTURE_UNITS
    323284 */
    324 void Material::setDiffuseMap(const TextureDataPointer& textureDataPointer, unsigned int textureNumber)
     285void Material::setDiffuseMap(const TextureData::Pointer& textureDataPointer, unsigned int textureNumber)
    325286{
    326287  assert(textureNumber < Material::getMaxTextureUnits());
     
    349310  if (!dMap.empty())
    350311  {
    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;
    354316    else
    355       this->textures[textureNumber] = Texture();
     317      this->textures[textureNumber] = Texture();*/
    356318  }
    357319  else
  • trunk/src/lib/graphics/importer/material.h

    r8761 r9869  
    2424class Material : public BaseObject
    2525{
     26  ObjectListDeclaration(Material);
    2627public:
    2728  Material (const std::string& mtlName = "");
    2829  virtual ~Material ();
    2930
     31  Material& operator=(const Material& material);
     32
    3033  void loadParams(const TiXmlElement* root);
    31 
    32   Material& operator=(const Material& material);
    3334
    3435  bool select () const;
     
    5354  // MAPPING //
    5455  void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0);
    55   void setDiffuseMap(const TextureDataPointer& texturePointer, unsigned int textureNumber = 0);
     56  void setDiffuseMap(const TextureData::Pointer& texturePointer, unsigned int textureNumber = 0);
    5657  void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
    5758  void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0);
     
    6566
    6667  const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; };
    67 
    68   static void addTexturePath(const std::string& pathName);
    6968
    7069  static const std::string& blendFuncToString(GLenum blendFunc);
  • trunk/src/lib/graphics/importer/md2/md2Model.cc

    r9406 r9869  
    1919
    2020#include "debug.h"
    21 #include "util/loading/resource_manager.h"
    22 
    23 
    24 
     21#include "resource_md2.h"
     22
     23
     24ObjectListDefinition(MD2Model);
    2525
    2626//! the model anorms
    2727sVec3D MD2Model::anorms[NUM_VERTEX_NORMALS] = {
    28  #include "anorms.h"
    29 };
     28#include "anorms.h"
     29    };
    3030
    3131//! anormal dots, no idea of how this shall work, but it does
    3232float MD2Model::anormsDots[SHADEDOT_QUANT][256] = {
    33   #include "anormtab.h"
    34 };
     33#include "anormtab.h"
     34    };
    3535
    3636
     
    4242sAnim MD2Model::animationList[22] =
    4343  {
    44  // begin, end, fps, interruptable
     44    // begin, end, fps, interruptable
    4545    {   0,  39,  9, 1 },   //!< STAND
    4646    {  40,  45, 10, 1 },   //!< RUN
     
    7373 ********************************************************************************/
    7474
     75MD2Model::MD2Model()
     76  : data(new MD2Data())
     77{
     78  this->init();
     79}
     80
     81#include "resource_md2.h"
    7582/**
    7683  \brief simple constructor initializing all variables
    7784*/
    7885MD2Model::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();
    8789  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
     97MD2Model::MD2Model(const MD2Model& model)
     98  : data(model.data)
     99{
     100  this->init();
     101  this->rebuildInfo();
     102}
     103
     104MD2Model& MD2Model::operator=(const MD2Model& md2model)
     105{
     106  this->data = md2model.data;
     107  this->rebuildInfo();
     108  return *this;
     109}
     110
     111void MD2Model::rebuildInfo()
     112{
     113  //write the modelinfo information
    99114  this->pModelInfo.numVertices = this->data->numVertices;
    100115  this->pModelInfo.numTriangles = this->data->numTriangles;
     
    107122
    108123  // triangle conversion
     124  if (this->pModelInfo.pTriangles != NULL)
     125    delete[] this->pModelInfo.pTriangles;
    109126  this->pModelInfo.pTriangles = new sTriangleExt[this->data->numTriangles];
    110127  for( int i = 0; i < this->data->numTriangles; i++)
     
    118135    this->pModelInfo.pTriangles[i].indexToTexCoor[2] = this->data->pTriangles[i].indexToTexCoor[2];
    119136  }
     137}
     138
     139bool 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();
    120143}
    121144
     
    132155  this->pModelInfo.pTexCoor = NULL;
    133156  this->pModelInfo.pTriangles = NULL;
    134 
    135   ResourceManager::getInstance()->unload(this->data);
    136 }
    137 
     157}
     158
     159
     160void 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}
    138176
    139177/**
     
    153191
    154192  for( int i = 0; i < this->data->numVertices; ++i)
    155     {
    156       this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]);
    157       this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]);
    158       this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]);
    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  }
    160198}
    161199
     
    259297  /* draw the triangles */
    260298  while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */
     299  {
     300    if( i < 0)
    261301    {
    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;
    280304    }
     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  }
    281319  glDisable(GL_CULL_FACE);
    282320  glPopAttrib();
     
    289327  int* pCommands = this->data->pGLCommands;
    290328  /* 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*/);
    298336  this->data->material.select();
    299337
     
    337375
    338376  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 )
    339382    {
    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)
    344384      {
    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++;
    354387      }
    355       this->animationState.lastTime = this->animationState.localTime;
     388      else
     389      {
     390        this->animationState.nextFrame = this->animationState.endFrame;
     391      }
    356392    }
    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;
    363401
    364402  this->animationState.interpolationState = this->animationState.fps *
    365     (this->animationState.localTime - this->animationState.lastTime);
     403      (this->animationState.localTime - this->animationState.lastTime);
    366404}
    367405
     
    390428  PRINT(0)("=  Number of Frames: \t%i\n", this->data->header->numFrames);
    391429  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);
    393431  PRINT(0)("===================================================\n\n");
    394432}
     
    399437 ********************************************************************************/
    400438
     439MD2Data::MD2Data()
     440{
     441  this->init();
     442}
     443
    401444/**
    402445  \brief simple constructor
     
    404447MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale)
    405448{
    406   scale *= 0.1f;
    407 
     449  this->init();
     450  this->scaleFactor = scale * .1;
     451
     452  this->loadModel(modelFileName);
     453  this->loadSkin(skinFileName);
     454}
     455
     456void MD2Data::init()
     457{
     458  this->scaleFactor = 1.0;
    408459  this->pVertices = NULL;
    409460  this->pGLCommands = NULL;
    410461  this->pLightNormals = NULL;
    411462  this->pTexCoor = NULL;
     463  this->header = NULL;
    412464
    413465  this->numFrames = 0;
     
    415467  this->numGLCommands = 0;
    416468  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}
    427470
    428471/**
     
    462505  pFile = fopen(fileName.c_str(), "rb");
    463506  if( unlikely(!pFile))
    464     {
    465       PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
    466       return false;
    467     }
     507  {
     508    PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
     509    return false;
     510  }
    468511  this->header = new MD2Header;
    469512  fread(this->header, 1, sizeof(MD2Header), pFile);
    470513  /* check for the header version: make sure its a md2 file :) */
    471514  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
    472     {
    473       PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
    474       return false;
    475     }
     515  {
     516    PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
     517    return false;
     518  }
    476519
    477520  this->fileName =fileName;
     
    506549
    507550  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)
    508557    {
    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;
    524566    }
    525     PRINTF(4)("Finished loading the md2 file\n");
     567  }
     568  PRINTF(4)("Finished loading the md2 file\n");
    526569
    527570  delete [] buffer;
     
    538581{
    539582  if( fileName.empty())
    540     {
    541       this->skinFileName = "";
    542       return false;
    543     }
     583  {
     584    this->skinFileName = "";
     585    return false;
     586  }
    544587
    545588  this->skinFileName = fileName;
  • trunk/src/lib/graphics/importer/md2/md2Model.h

    r9235 r9869  
    2020
    2121#include "base_object.h"
     22#include "count_pointer.h"
    2223
    2324#include "interactive_model.h"
     
    4546struct MD2Header
    4647{
    47    int ident;                           //!< This is used to identify the file
    48    int version;                         //!< The version number of the file (Must be 8)
    49 
    50    int skinWidth;                       //!< The skin width in pixels
    51    int skinHeight;                      //!< The skin height in pixels
    52    int frameSize;                       //!< The size in bytes the frames are
    53 
    54    int numSkins;                        //!< The number of skins associated with the model
    55    int numVertices;                     //!< The number of vertices (constant for each frame)
    56    int numTexCoords;                    //!< The number of texture coordinates
    57    int numTriangles;                    //!< The number of faces (polygons)
    58    int numGlCommands;                   //!< The number of gl commands
    59    int numFrames;                       //!< The number of animation frames
    60 
    61    int offsetSkins;                     //!< The offset in the file for the skin data
    62    int offsetTexCoords;                 //!< The offset in the file for the texture data
    63    int offsetTriangles;                 //!< The offset in the file for the face data
    64    int offsetFrames;                    //!< The offset in the file for the frames data
    65    int offsetGlCommands;                //!< The offset in the file for the gl commands data
    66    int offsetEnd;                       //!< The end of the file offset
     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
    6768};
    6869
     
    7071//! animation names enumeration
    7172typedef enum MD2animType
    72   {
    73     STAND,                       //0
    74     RUN,                         //1
    75     ATTACK,                      //2
    76     PAIN_A,                      //3
    77     PAIN_B,                      //4
    78     PAIN_C,          //5
    79     JUMP,            //6
    80     FLIP,            //7
    81     SALUTE,          //8
    82     FALLBACK,        //9
    83     WAVE,            //10
    84     POINT,           //11
    85     CROUCH_STAND,
    86     CROUCH_WALK,
    87     CROUCH_ATTACK,
    88     CROUCH_PAIN,
    89     CROUCH_DEATH,
    90     DEATH_FALLBACK,
    91     DEATH_FALLFORWARD,
    92     DEATH_FALLBACKSLOW,
    93     BOOM,
    94     WALK,
    95 
    96     MAX_ANIMATIONS
    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};
    9899
    99100
     
    116117class MD2Data : public BaseObject
    117118{
    118  public:
    119    MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
     119public:
     120  typedef CountPointer<MD2Data>    Pointer;
     121public:
     122  MD2Data();
     123  MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f);
    120124  virtual ~MD2Data();
    121125
    122  private:
    123    bool loadModel(const std::string& fileName);
    124    bool loadSkin(const std::string& fileName = "");
    125 
    126  public:
     126private:
     127  void init();
     128  bool loadModel(const std::string& fileName);
     129  bool loadSkin(const std::string& fileName = "");
     130
     131public:
    127132  int                numFrames;             //!< number of frames
    128133  int                numVertices;           //!< number of vertices
     
    148153
    149154//! This is a MD2 Model class
    150 class MD2Model : public InteractiveModel {
    151 
    152 public:
     155class MD2Model : public InteractiveModel
     156{
     157  ObjectListDeclaration(MD2Model);
     158public:
     159  MD2Model();
    153160  MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f);
     161  MD2Model(const MD2Model& model);
    154162  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);
    155167
    156168  virtual void draw() const;
     
    160172  virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback);
    161173  /**  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; }
    163175  virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; }
    164   virtual bool isAnimationFinished() { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
     176virtual bool isAnimationFinished() const { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }
    165177  /**  scales the current model @param scaleFactor: the factor [0..1] to use for scaling */
    166178  void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}
    167179
     180
     181  void acquireData(const MD2Data::Pointer& data) { this->data = data; rebuildInfo(); };
     182  const MD2Data::Pointer& dataPointer() const { return this->data; };
    168183  virtual void tick(float dtS);
    169184  void debug();
     
    171186
    172187private:
     188  void init();
     189  void rebuildInfo();
     190
    173191  void animate(float time);
    174192  void processLighting();
     
    177195
    178196
    179  public:
     197public:
    180198  /* these variables are static, because they are all the same for every model */
    181   static sVec3D       anorms[NUM_VERTEX_NORMALS];       //!< the anormals
    182   static float        anormsDots[SHADEDOT_QUANT][256];  //!< the anormals dot products
    183   static sAnim        animationList[22];                //!< the anomation list
    184    //! again one of these strange id software parts
    185   float*              shadeDots;
    186 
    187   MD2Data*            data;                             //!< the md2 data pointer
    188 
    189  private:
    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 model
    193   sVec3D              verticesList[MD2_MAX_VERTICES];   //!< place to temp sav the vert
     199  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
     207private:
     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
    194212};
    195213
  • trunk/src/lib/graphics/importer/md3/md3_model.h

    r8724 r9869  
    4545
    4646    virtual void setAnimation(int animNum, int playbackMode = 0) {}
    47     virtual int getAnimation() { return 0;}
     47    virtual int getAnimation() const { return 0;}
    4848
    4949    virtual void tick(float dt);
  • trunk/src/lib/graphics/importer/media_container.cc

    r8316 r9869  
    2626
    2727#include "util/loading/resource_manager.h"
    28 
    2928/* header for debug output */
    3029#include "debug.h"
    3130
     31ObjectListDefinition(MediaContainer);
    3232
    3333/**
     
    3737{
    3838  // set the class id for the base object
    39   this->setClassID(CL_MEDIA_CONTAINER, "MediaContainer");
     39  this->registerObject(this, MediaContainer::_objectList);
    4040
    4141  fps = 0;
     
    9191    return false;
    9292  // check whether file exists
    93   if(!ResourceManager::isInDataDir(filename))
     93  if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename))
    9494  {
    9595    PRINTF(1)("Could not find %s\n", filename.c_str());
     
    101101
    102102  // Open video file
    103   if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )
    104   {
    105     PRINTF(1)("Could not open %s\n", ResourceManager::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());
    106106    return false;
    107107  }
     
    110110  if (av_find_stream_info(format_context) < 0)
    111111  {
    112     PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str());
     112    PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    113113    return false;
    114114  }
     
    119119  if(video_stream == -1)
    120120  {
    121     PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str());
     121    PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    122122    return false;
    123123  }
  • trunk/src/lib/graphics/importer/media_container.h

    r7221 r9869  
    2424class MediaContainer : public TextureSequence
    2525{
    26 
     26  ObjectListDeclaration(MediaContainer);
    2727private:
    2828
  • trunk/src/lib/graphics/importer/model.cc

    r9406 r9869  
    2020#include "glincl.h"
    2121
    22 
     22ObjectListDefinition(Model);
    2323
    2424/**
     
    2828Model::Model()
    2929{
    30   this->setClassID(CL_MODEL, "Model");
     30  this->registerObject(this, Model::_objectList);
    3131  this->pModelInfo.numVertices = 0;
    3232  this->pModelInfo.numTriangles = 0;
  • trunk/src/lib/graphics/importer/model.h

    r8035 r9869  
    5454//! This class defines the basic components of a model
    5555class Model : virtual public BaseObject {
     56  ObjectListDeclaration(Model);
    5657
    5758  public:
  • trunk/src/lib/graphics/importer/movie_player.cc

    r7221 r9869  
    2424// include your own header
    2525#include "movie_player.h"
    26 
    2726#include "util/loading/resource_manager.h"
    2827
     
    3029#include "debug.h"
    3130
     31ObjectListDefinition(MoviePlayer);
    3232
    3333MoviePlayer::MoviePlayer(const std::string& filename)
    3434{
    3535  // set the class id for the base object
    36   this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer");
    37 
     36  this->registerObject(this, MoviePlayer::_objectList);
    3837  status = STOP;
    3938  timer = 0;
     
    9089    return false;
    9190  // check whether file exists
    92   if(!ResourceManager::isInDataDir(filename))
     91  if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename))
    9392  {
    9493    PRINTF(1)("Could not find %s\n", filename.c_str());
     
    10099
    101100  // Open video file
    102   if (av_open_input_file(&format_context, ResourceManager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )
    103   {
    104     PRINTF(1)("Could not open %s\n", ResourceManager::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());
    105104    return false;
    106105  }
     
    109108  if (av_find_stream_info(format_context) < 0)
    110109  {
    111     PRINTF(1)("Could not find stream information in %s\n", ResourceManager::getFullName(filename).c_str());
     110    PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    112111    return false;
    113112  }
     
    118117  if(video_stream == -1)
    119118  {
    120     PRINTF(1)("Could not find a video stream in %s\n", ResourceManager::getFullName(filename).c_str());
     119    PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str());
    121120    return false;
    122121  }
  • trunk/src/lib/graphics/importer/movie_player.h

    r7221 r9869  
    3131class MoviePlayer : public BaseObject
    3232{
     33  ObjectListDeclaration(MoviePlayer);
    3334
    3435private:
  • trunk/src/lib/graphics/importer/objModel.cc

    r8369 r9869  
    1818#include "objModel.h"
    1919
    20 #include <stdio.h>
    2120#include <string.h>
    22 #include <stdlib.h>
     21#include "loading/resource_manager.h"
    2322
    2423#define PARSELINELENGTH 8192
     
    2726#include "compiler.h"
    2827
     28ObjectListDefinition(OBJModel);
    2929/**
    3030 * @brief Crates a 3D-Model, loads in a File and scales it.
     
    3535  : StaticModel(fileName)
    3636{
    37   this->setClassID(CL_OBJ_MODEL, "OBJModel");
     37  this->registerObject(this, OBJModel::_objectList);
    3838
    3939  this->objPath = "./";
    4040
    41   this->scaleFactor = scaling;
     41  this->setScaleFactor(scaling);
    4242
    4343  this->importFile (fileName);
     
    7777  else
    7878    this->objPath = "./";
    79   Material::addTexturePath(this->objPath);
     79  Resources::ResourceManager::getInstance()->addResourcePath("Texture", this->objPath);
    8080
    8181  this->readFromObjFile (fileName);
  • trunk/src/lib/graphics/importer/objModel.h

    r8369 r9869  
    1212class OBJModel : public StaticModel
    1313{
    14  public:
    15    OBJModel(const std::string& fileName, float scaling = 1.0);
     14  ObjectListDeclaration(OBJModel);
     15public:
     16  OBJModel(const std::string& fileName, float scaling = 1.0);
    1617  virtual ~OBJModel();
    1718
    18  private:
     19private:
    1920  ///// readin /////
    20    bool importFile (const std::string& fileName);
    21    bool readFromObjFile (const std::string& fileName);
    22    bool readMtlLib (const std::string& matFile);
     21  bool importFile (const std::string& fileName);
     22  bool readFromObjFile (const std::string& fileName);
     23  bool readMtlLib (const std::string& matFile);
    2324
    24   private:
    25    void setIllum (Material* material, const char* illum);
    26    void setDiffuse (Material* material, const char* rgb);
    27    void setAmbient (Material* material, const char* rgb);
    28    void setSpecular (Material* material, const char* rgb);
    29    void setShininess (Material* material, const char* shini);
    30    void setTransparency (Material* material, const char* trans);
     25private:
     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);
    3132
    32  private:
    33    std::string       objPath;     //!< The Path where the obj and mtl-file are located.
     33private:
     34  std::string       objPath;     //!< The Path where the obj and mtl-file are located.
    3435};
    3536
  • trunk/src/lib/graphics/importer/static_model.cc

    r9406 r9869  
    2626
    2727
    28 ////////////////////
    29 /// SUB-Elements ///
    30 ////////////////////
    31 /**
    32  * @brief creates a new ModelFaceElement
    33  */
    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 ModelFaceElement
    45  */
    46 ModelFaceElement::~ModelFaceElement()
    47 {
    48   if (this->next)
    49     delete this->next;
    50 }
    51 
    52 /**
    53  * @brief creates a new ModelFace
    54  */
    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 ModelFace
    68 */
    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 ModelGroup
    82  */
    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 ModelGroup
    99  */
    100 ModelGroup::~ModelGroup()
    101 {
    102   PRINTF(5)("Cleaning up group\n");
    103   if (this->firstFace != NULL)
    104     delete this->firstFace;
    105 
    106   // deleting the glList
    107   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 ModelGroup
    117  *
    118  * actually does the same as the delete Operator, but does not delete the predecessing group
    119  */
    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 
    13128/////////////
    13229/// MODEL ///
    13330/////////////
     31ObjectListDefinition(StaticModel);
     32
    13433/**
    13534 * @brief Creates a 3D-Model.
     
    13837 */
    13938StaticModel::StaticModel(const std::string& modelName)
     39    : data(new StaticModelData(modelName))
    14040{
    141   this->setClassID(CL_STATIC_MODEL, "StaticModel");
     41  this->registerObject(this, StaticModel::_objectList);
    14242  PRINTF(4)("new 3D-Model is being created\n");
    14343  this->setName(modelName);
     44}
    14445
    145   this->finalized = false;
     46StaticModel::StaticModel(const StaticModel& staticModel)
     47  : data(staticModel.data)
     48{
     49  this->registerObject(this, StaticModel::_objectList);
     50  this->setName(staticModel.getName());
     51  this->updateBase();
     52}
    14653
    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 }
    15454
    15555/**
     
    16161{
    16262  PRINTF(4)("Deleting Model ");
    163   if (!this->getName().empty())
    164   {
    165     PRINT(4)("%s\n", this->getCName());
    166   }
    167   else
    168   {
    169     PRINT(4)("\n");
    170   }
    171   this->cleanup();
    172 
    173   PRINTF(5)("Deleting display Lists.\n");
    174   delete this->firstGroup;
    175 
    176   // deleting the MaterialList
    177   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   }
    18763
    18864  // mark this stuff as beeing deleted
     
    19066  this->pModelInfo.pNormals = NULL;
    19167  this->pModelInfo.pTexCoor = NULL;
     68  this->pModelInfo.pTriangles = NULL;
    19269}
     70
     71StaticModel& StaticModel::operator=(const StaticModel& model)
     72{
     73  this->data = model.data;
     74  this->updateBase();
     75  return *this;
     76};
     77
    19378
    19479/**
     
    19782void StaticModel::finalize()
    19883{
    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();
    20986}
    21087
    211 /**
    212  * @brief rebuild the Model from the Information we got.
    213  */
    214 void StaticModel::rebuild()
     88void StaticModel::acquireData(const StaticModelData::Pointer& data)
    21589{
    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();
    56292}
    56393
     
    56999bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
    570100{
    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 
    576101  va_list itemlist;
    577102  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);
    591104  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;
    596106}
    597107
    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)
     108void StaticModel::updateBase()
    603109{
    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();
    606117
    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();
    803120}
    804121
    805122
    806123/**
    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.
    808127 */
    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 this
    815     this->buildVertexNormals();
    816 
    817   int                index = 0;                   //!< the counter for the triangle array
    818   ModelFaceElement*  tmpElem;       //!< the temporary faceelement reference
    819   ModelFace*         tmpFace;              //!< the temporary face referece
    820 
    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 itself
    931    2. The VertexNormale
    932    3. The VertexTextureCoordinate
    933    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     else
    944       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     else
    952       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     else
    960       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 model
    969 
    970    This will inject a Cube, because this is the most basic model.
    971 */
    972128void StaticModel::cubeModel()
    973129{
  • trunk/src/lib/graphics/importer/static_model.h

    r7221 r9869  
    1010
    1111#include "material.h"
    12 #include "glincl.h"
    1312#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"
    8514
    8615/////////////
     
    9423class StaticModel : public Model
    9524{
    96  public:
     25  ObjectListDeclaration(StaticModel);
     26public:
    9727  StaticModel(const std::string& modelName = "");
     28  StaticModel(const StaticModel& staticModel);
    9829  virtual ~StaticModel();
    9930
    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);
    10332
    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); };
    10536
    106   Material* addMaterial(Material* material);
    107   Material* addMaterial(const std::string& materialName);
     37  void rebuild() { data->rebuild(); };
    10838
    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); };
    11041
    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); };
    11343
    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); };
    11548  bool addFace(int faceElemCount, VERTEX_FORMAT type, ...);
    11649
    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); };
    11952
    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); };
    12255
    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);};
    12558
    12659  void finalize();
    12760
     61  void acquireData(const StaticModelData::Pointer& data);
     62  const StaticModelData::Pointer& dataPointer() const { return this->data; };
    12863
    129  protected:
     64  inline void setScaleFactor(float scaleFactor) { this->data->setScaleFactor(scaleFactor); };
     65  float getScaleFactor() const { return data->getScaleFactor(); }
     66
     67protected:
    13068  void cubeModel();
    13169
    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
     70private:
     71  void updateBase();
     72private:
     73  StaticModelData::Pointer         data;
    16174};
    16275
  • trunk/src/lib/graphics/importer/texture.cc

    r9406 r9869  
    6464#endif
    6565
    66 
     66ObjectListDefinition(Texture);
    6767
    6868/**
     
    8686    : data(texture.data)
    8787{
    88   this->setClassID(CL_TEXTURE, "Texture");
     88  this->registerObject(this, Texture::_objectList);
    8989  this->priority = 0.5;
    9090}
     
    149149void Texture::init()
    150150{
    151   this->setClassID(CL_TEXTURE, "Texture");
    152 
    153   this->data = TextureDataPointer(new TextureData());
     151  this->registerObject(this, Texture::_objectList);
     152
     153  this->data = TextureData::Pointer(new TextureData());
    154154
    155155  this->priority = 0.5;
     
    176176}
    177177
    178 Texture& Texture::operator=(const TextureDataPointer& textureDataPointer)
     178Texture& Texture::operator=(const TextureData::Pointer& textureDataPointer)
    179179{
    180180  this->data = textureDataPointer;
  • trunk/src/lib/graphics/importer/texture.h

    r8761 r9869  
    11/*!
    22 * @file texture.h
    3  * @brief Contains the texture class, that handles the reading of Images into Texutre-files.
     3 * @brief Contains the texture class, that handles the reading of Images into Texture-files.
    44 */
    55
     
    2020class Texture : public BaseObject
    2121{
     22  ObjectListDeclaration(Texture);
    2223public:
    2324  Texture();
     
    2829
    2930  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; }
    3134
    3235  virtual ~Texture();
     
    6265
    6366private:
    64   TextureDataPointer            data;               //!< The TextureData
     67  TextureData::Pointer          data;               //!< The TextureData
    6568  GLclampf                      priority;           //!< the priority of the current texture (used for garphics cards with limited mem)
    6669
  • trunk/src/lib/graphics/importer/texture_data.h

    r8761 r9869  
    1818class TextureData
    1919{
     20  public:
     21    typedef CountPointer<TextureData> Pointer;
    2022  public:
    2123    TextureData();
     
    4345};
    4446
    45 typedef CountPointer<TextureData> TextureDataPointer;
    46 
    4747#endif /* _TEXTURE_DATA_H */
  • trunk/src/lib/graphics/importer/texture_sequence.cc

    r9406 r9869  
    2828#endif
    2929
     30ObjectListDefinition(TextureSequence);
     31
    3032/**
    3133 * @brief Constructor for a Texture
     
    3335TextureSequence::TextureSequence(unsigned int count, ...)
    3436{
    35   this->setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");
     37  this->registerObject(this, TextureSequence::_objectList);
    3638
    3739  va_list textureNameList;
     
    5456TextureSequence::TextureSequence(const std::vector<std::string>& textureNames, const std::string& prependFolder)
    5557{
    56   this->setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");
     58  this->registerObject(this, TextureSequence::_objectList);
    5759  this->loadImageSeries(textureNames, prependFolder);
    5860}
  • trunk/src/lib/graphics/importer/texture_sequence.h

    r8324 r9869  
    1515class TextureSequence : public Texture
    1616{
     17  ObjectListDeclaration(TextureSequence);
    1718  public:
    1819    TextureSequence(unsigned int count = 0, ...);
  • trunk/src/lib/graphics/importer/vertex_array_model.cc

    r9406 r9869  
    2424
    2525
     26ObjectListDefinition(VertexArrayModel);
    2627
    2728/////////////
     
    3536VertexArrayModel::VertexArrayModel()
    3637{
    37   this->setClassID(CL_MODEL, "VertexArrayModel");
     38  this->registerObject(this, VertexArrayModel::_objectList);
    3839
    3940  this->newStripe();
     
    4950VertexArrayModel::VertexArrayModel(const Model& model)
    5051{
    51   this->setClassID(CL_MODEL, "VertexArrayModel");
     52  this->registerObject(this, VertexArrayModel::_objectList);
    5253
    5354  // importing the data to the new Model.
  • trunk/src/lib/graphics/importer/vertex_array_model.h

    r6769 r9869  
    2727class VertexArrayModel : public Model
    2828{
    29  public:
     29  ObjectListDeclaration(VertexArrayModel);
     30  public:
    3031  VertexArrayModel();
    3132  VertexArrayModel(const Model& model);
  • trunk/src/lib/graphics/light.cc

    r8742 r9869  
    2222#include "glincl.h"
    2323#include "vector.h"
    24 #include "parser/tinyxml/tinyxml.h"
    25 #include "util/loading/load_param.h"
     24#include "util/loading/load_param_xml.h"
    2625#include "util/loading/factory.h"
    2726#include "debug.h"
    2827
    29 CREATE_FACTORY(Light, CL_LIGHT);
     28#include "class_id_DEPRECATED.h"
     29
     30ObjectListDefinitionID(Light, CL_LIGHT);
     31CREATE_FACTORY(Light);
    3032
    3133//! Definition of the Lights and their Names
     
    5153  PRINTF(4)("initializing Light number %d.\n", this->lightNumber);
    5254
     55  this->registerObject(this, Light::_objectList);
     56
    5357  this->lightNumber = LightManager::getInstance()->registerLight(this);
    5458
    55   this->setClassID(CL_LIGHT, "Light");
    5659  char tmpName[10];
    5760  sprintf(tmpName, "Light[%d]", this->lightNumber);
     
    211214** LIGHT-MANAGER **
    212215******************/
     216ObjectListDefinition(LightManager);
    213217/**
    214218 *  standard constructor for a Light
     
    216220LightManager::LightManager ()
    217221{
    218   this->setClassID(CL_LIGHT_MANAGER, "LightManager");
     222  this->registerObject(this, LightManager::_objectList);
    219223
    220224  glEnable (GL_LIGHTING);
  • trunk/src/lib/graphics/light.h

    r8255 r9869  
    2525class Light : public PNode
    2626{
    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);
     28public:
     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
     49private:
     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
    5758};
    58        
    59        
    60        
     59
     60
     61
    6162//! A class that handles Lights
    6263/**
     
    8788*/
    8889class LightManager : public BaseObject
    89         {
    90         friend class Light;
     90{
     91  ObjectListDeclaration(LightManager);
    9192
    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;
     94public:
     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; };
    9698
    97                 virtual void loadParams(const TiXmlElement* root);
    98                 void loadLights(const TiXmlElement* root);
     99  virtual void loadParams(const TiXmlElement* root);
     100  void loadLights(const TiXmlElement* root);
    99101
    100                 void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
    101                 // HACK: Assuming r = g = b values
    102                 inline GLfloat getAmbientColor() {  return this->ambientColor[0]; }
     102  void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
     103  // HACK: Assuming r = g = b values
     104inline GLfloat getAmbientColor() {  return this->ambientColor[0]; }
    103105
    104                 Light* getLight(int lightNumber) const;
    105                 inline Light* getLight() const { return this->currentLight; };
     106  Light* getLight(int lightNumber) const;
     107  inline Light* getLight() const { return this->currentLight; };
    106108
    107                 void draw() const;
     109  void draw() const;
    108110
    109                 void debug() const;
     111  void debug() const;
    110112
    111         private:
    112                 LightManager();
     113private:
     114  LightManager();
    113115
    114                 int  registerLight(Light* light);
    115                 void unregisterLight(Light* light);
     116  int  registerLight(Light* light);
     117  void unregisterLight(Light* light);
    116118
    117         private:
    118                 static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
    119                 GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
     119private:
     120  static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
     121  GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
    120122
    121                 Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
    122                 Light*                  currentLight;       //!< The current Light, we are working with.
     123  Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
     124  Light*                  currentLight;       //!< The current Light, we are working with.
    123125
    124126};
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r9406 r9869  
    2929#include "graphics_engine.h"
    3030#include "util/loading/load_param.h"
    31 #include "class_list.h"
    3231
    3332#include "color.h"
    34 
     33#include "debug.h"
    3534#include "shell_command.h"
     35
    3636SHELL_COMMAND(debug, Element2D, debug2D);
     37
     38ObjectListDefinition(Element2D);
    3739
    3840
     
    4648Element2D::Element2D (Element2D* parent, E2D_LAYER layer, short nodeFlags)
    4749{
    48   this->setClassID(CL_ELEMENT_2D, "Element2D");
     50  this->registerObject(this, Element2D::_objectList);
    4951
    5052  this->setVisibility(true);
     
    268270void Element2D::setBindNode(const std::string& bindNode)
    269271{
    270   const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));
     272  const PNode* tmpBindNode = PNode::objectList().getObject(bindNode);
    271273  if (tmpBindNode != NULL)
    272274    this->bindNode = tmpBindNode;
     
    640642void Element2D::addChild2D (const std::string& childName)
    641643{
    642   Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));
     644  Element2D* childNode = Element2D::objectList().getObject(childName);
    643645  if (childNode != NULL)
    644646    this->addChild2D(childNode);
     
    718720void Element2D::setParent2D (const std::string& parentName)
    719721{
    720   Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     722  Element2D* parentNode = Element2D::objectList().getObject(parentName);
    721723  if (parentNode != NULL)
    722724    parentNode->addChild2D(this);
     
    771773void Element2D::setParentSoft2D(const std::string& parentName, float bias)
    772774{
    773   Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     775  Element2D* parentNode = Element2D::objectList().getObject(parentName);
    774776  if (parentNode != NULL)
    775777    this->setParentSoft2D(parentNode, bias);
  • trunk/src/lib/graphics/render2D/element_2d.h

    r8360 r9869  
    4747
    4848  E2D_PARENT_MOVEMENT                = 0x0004,    //!< Moves all children along with the parent.
    49 // special linkage modes
     49  // special linkage modes
    5050  E2D_PARENT_ALL                     = 0x0003,    //!< Moves all children around the center of their parent, and also rotates their centers
    5151  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.
     
    5858  E2D_REPARENT_DELETE_CHILDREN       = 0x0040,    //!< Deletes the Children of the node when This Node is Removed. (Use with care).
    5959  /// FIXME
    60    E2D_REPARENT_KEEP_POSITION         = 0x0080,   //!< Tries to keep the Position if the Node is reparented.
     60  E2D_REPARENT_KEEP_POSITION         = 0x0080,   //!< Tries to keep the Position if the Node is reparented.
    6161
    6262
     
    8787 * -> the tree is sorted on insertion of a new Child: @see Element2D::addChild2D()
    8888 */
    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
     89class Element2D : virtual public BaseObject
     90{
     91  ObjectListDeclaration(Element2D);
     92
     93public:
     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
     138public:
     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
     146public:
     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 */
     158inline 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 */
     179inline 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. */
     215static 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
     232private:
     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
     246private:
     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
    280282};
    281283
  • trunk/src/lib/graphics/render2D/image_plane.cc

    r9406 r9869  
    2121
    2222#include "graphics_engine.h"
    23 #include "glincl.h"
    2423#include "p_node.h"
    2524
    2625
     26#include "class_id_DEPRECATED.h"
    2727
    28 
    29 
    30 CREATE_FACTORY(ImagePlane, CL_IMAGE_ENTITY);
     28ObjectListDefinitionID(ImagePlane, CL_IMAGE_PLANE);
     29CREATE_FACTORY(ImagePlane);
    3130
    3231
     
    5655void ImagePlane::init()
    5756{
    58   this->setClassID(CL_IMAGE_PLANE, "ImagePlane");
     57  this->registerObject(this, ImagePlane::_objectList);
    5958  this->setName("ImagePlane");
    6059
  • trunk/src/lib/graphics/render2D/image_plane.h

    r7843 r9869  
    1717class ImagePlane :  public Element2D
    1818{
    19 
     19  ObjectListDeclaration(ImagePlane);
    2020  public:
    2121    ImagePlane(const TiXmlElement* root = NULL);
  • trunk/src/lib/graphics/render2D/render_2d.cc

    r9406 r9869  
    1919
    2020#include "graphics_engine.h"
    21 #include "class_list.h"
    2221#include "element_2d.h"
    2322
     23ObjectListDefinition(Render2D);
    2424
    2525
     
    2929Render2D::Render2D ()
    3030{
    31    this->setClassID(CL_RENDER_2D, "Render2D");
    32    this->setName("Render2D");
     31  this->registerObject(this, Render2D::_objectList);
     32  this->setName("Render2D");
    3333
    34    this->showNodes = false;
     34  this->showNodes = false;
    3535}
    3636
  • trunk/src/lib/graphics/render2D/render_2d.h

    r7840 r9869  
    1212
    1313//! A default singleton class.
    14 class Render2D : public BaseObject {
     14class Render2D : public BaseObject
     15{
     16  ObjectListDeclaration(Render2D);
     17
    1518  friend class Element2D;
    1619
    17   public:
    18     virtual ~Render2D();
    19     /** @returns a Pointer to the only object of this Class */
    20     inline static Render2D* getInstance() { if (!singletonRef) singletonRef = new Render2D();  return singletonRef; };
     20public:
     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; };
    2124
    22     void toggleNodesVisibility() { this->showNodes = !this->showNodes; };
     25void toggleNodesVisibility() { this->showNodes = !this->showNodes; };
    2326
    24     void update(float dt);
    25     void tick(float dt);
    26     void draw(E2D_LAYER from, E2D_LAYER to) const;
     27  void update(float dt);
     28  void tick(float dt);
     29  void draw(E2D_LAYER from, E2D_LAYER to) const;
    2730
    28   private:
    29     Render2D();
    30     static Render2D*              singletonRef;                    //!< Reference to this class.
     31private:
     32  Render2D();
     33  static Render2D*              singletonRef;                    //!< Reference to this class.
    3134
    32     bool                          showNodes;                       //!< If the debug-Nodes should be visible
    33  };
     35  bool                          showNodes;                       //!< If the debug-Nodes should be visible
     36};
    3437
    3538#endif /* _RENDER_2D_H */
  • trunk/src/lib/graphics/shader.cc

    r9406 r9869  
    1818#include "shader.h"
    1919
    20 #include "stdlibincl.h"
    2120#include "compiler.h"
    2221//#include <stdio.h>
     
    2524#include "debug.h"
    2625
    27 #include "util/loading/resource_manager.h"
    2826
    2927
     
    3331
    3432
     33ObjectListDefinition(Shader);
    3534
     35void 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}
     53void 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
     74Shader::Shader()
     75  : data(new ShaderData)
     76{
     77
     78}
    3679
    3780/**
     
    3982*/
    4083Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile)
     84  : data(new ShaderData)
    4185{
    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);
    4389
    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    else
    61      {
    62        PRINTF(2)("Shaders are not supported on your hardware\n");
    63      }
    6490}
    6591
     92const Shader* Shader::storedShader = NULL;
    6693
    67 /**
    68  * standard deconstructor
    69  */
    70 Shader::~Shader ()
     94void Shader::activateShader() const
    7195{
    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))
    8097  {
    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());
    20099    Shader::storedShader = this;
    201100  }
    202101}
    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 
    222102void Shader::deactivateShader()
    223103{
    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;
    277107}
    278108
     
    288118}
    289119
    290 void Shader::debug() const
    291 {
    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 }
    308120
  • trunk/src/lib/graphics/shader.h

    r8255 r9869  
    88
    99#include "base_object.h"
    10 #include "glincl.h"
    11 #include <vector>
    12 
     10#include "shader_data.h"
    1311
    1412// FORWARD DECLARATION
     
    1614
    1715
    18 //! A class for ...
     16//! The Shader is a Class-wrapper around the OpenGL Shader Language (GLSL).
    1917class Shader : public BaseObject
    2018{
     19  ObjectListDeclaration(Shader);
    2120public:
    2221  class Uniform
    2322  {
    2423  public:
    25     Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }
    2624    Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; };
    2725    Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; };
     
    3735    void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); }
    3836
    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:
    7641    GLint uniform;
    7742  };
    7843
    79   typedef enum
    80   {
    81     None       = 0,
    82     Fragment   = 1,
    83     Vertex     = 2,
    84 
    85     Program    = 4,
    86   }
    87   Type;
    8844
    8945public:
    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(); };
    9467
    9568
    9669  static bool checkShaderAbility();
    97   void activateShader();
    98   void bindShader(const char* name, const float* value, size_t size);
    99   static void deactivateShader();
    10070
    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; };
    10273
    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;} };
    11575  inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; };
    11676
     77private:
     78  ShaderData::Pointer    data;
    11779
    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;
    14081};
    14182
  • trunk/src/lib/graphics/spatial_separation/quadtree.cc

    r9406 r9869  
    2727#define QUADTREE_MATERIAL_COUNT       4
    2828
     29ObjectListDefinition(Quadtree);
    2930/**
    3031 *  standard constructor
     
    3233Quadtree::Quadtree (const modelInfo* pModelInfo, const int treeDepth)
    3334{
    34   this->setClassID(CL_QUADTREE, "Quadtree");
     35  this->registerObject(this, Quadtree::_objectList);
    3536  this->pModelInfo = pModelInfo;
    3637  this->treeDepth = treeDepth;
  • trunk/src/lib/graphics/spatial_separation/quadtree.h

    r6022 r9869  
    2121//! A class for quadtree separation of the world
    2222class Quadtree : public BaseObject {
    23 
     23  ObjectListDeclaration(Quadtree);
    2424
    2525  public:
  • trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r9406 r9869  
    2727
    2828
    29 
     29ObjectListDefinition(QuadtreeNode);
    3030
    3131/**
     
    102102void QuadtreeNode::init()
    103103{
    104   this->setClassID(CL_QUADTREE_NODE, "QuadtreeNode");
     104  this->registerObject(this, QuadtreeNode::_objectList);
    105105
    106106  /* init the rest of the variables for both init types */
  • trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r6617 r9869  
    2626//! A class for a Quadtree Node representation
    2727class QuadtreeNode : public BaseObject {
     28  ObjectListDeclaration(QuadtreeNode);
    2829
    2930  public:
  • trunk/src/lib/graphics/spatial_separation/spatial_separation.cc

    r9406 r9869  
    2424
    2525
    26 
     26ObjectListDefinition(SpatialSeparation);
    2727
    2828/**
    29  * standard constructor
     29 * @brief standard constructor
    3030 * @param model the model that is to be separated
    3131 * @param overlapSize each box will overlap for a given size
    32 
    33    The boxes are overlaping because this makes collision detection a lot simpler
    34 
     32 *
     33 * The boxes are overlaping because this makes collision detection a lot simpler
     34 *
    3535 */
    3636SpatialSeparation::SpatialSeparation (Model* model, float overlapSize)
     
    3939  PRINT(3)("+-| (Event) Spatial Separation process kicked on\n");
    4040
    41   this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");
     41  this->registerObject(this, SpatialSeparation::_objectList);
    4242  /* debug vice */
    4343  this->createQuadtree(model);
     
    4646
    4747/**
    48  * standard constructor
     48 * @brief standard constructor
    4949 * @param model the model that is to be separated
    5050 * @param overlapSize each box will overlap for a given size
     
    5454SpatialSeparation::SpatialSeparation (Model* model, Model* playerModel)
    5555{
    56   this->setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");
     56  this->registerObject(this, SpatialSeparation::_objectList);
    5757
    5858}
     
    6060
    6161/**
    62  * standard deconstructor
     62 * @brief standard deconstructor
    6363 */
    6464SpatialSeparation::~SpatialSeparation ()
     
    7070
    7171/**
    72  * creates a quadtree
     72 * @brief creates a quadtree
    7373 * @param model the model to do a quadtree on
    7474 * @param minLength the minimal length of a quadtree node
     
    8383
    8484/**
    85  *  brief creates a quadtree
     85 * @brief creates a quadtree
    8686 * @param model the model to do a quadtree on
    8787 * @param minLength the minimal length of a quadtree node
     
    9595
    9696/**
    97  * creates a quadtree
     97 * @brief creates a quadtree
    9898 * @param model the model to do a quadtree on
    9999 * @param minLength the minimal length of a quadtree node
     
    109109
    110110/**
    111  * draws all the quadtrees
     111 * @brief draws all the quadtrees
    112112 */
    113113void SpatialSeparation::drawQuadtree()
     
    118118  this->quadtree->drawTree();
    119119}
    120 
    121 
    122 
    123 
    124 
    125 
    126 
    127 
    128 
    129 
    130 
    131 
  • trunk/src/lib/graphics/spatial_separation/spatial_separation.h

    r6022 r9869  
    1919//! A class for spatial separation of vertices based arrays
    2020class SpatialSeparation : public BaseObject {
     21  ObjectListDeclaration(SpatialSeparation);
    2122
    2223  public:
  • trunk/src/lib/graphics/text_engine/font.cc

    r8989 r9869  
    2929#include "compiler.h"
    3030
     31ObjectListDefinition(Font);
    3132
    3233Font::Font()
     
    3435{
    3536  this->init();
    36 
    3737}
    3838
     
    118118  Material::operator=(font);
    119119  this->data = font.data;
     120  this->setTexture(this->data->textureData());
    120121
    121122  return *this;
     
    130131  this->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    131132
    132   this->setClassID(CL_FONT, "Font");
    133   if (Font::defaultFontData.get() == NULL)
     133  this->registerObject(this, Font::_objectList);
     134  if (Font::defaultFontData.isNull())
    134135  {
    135136    Font::initDefaultFont();
     
    138139}
    139140
    140 FontDataPointer Font::defaultFontData(NULL);
     141FontData::Pointer Font::defaultFontData(NULL);
    141142
    142143/**
     
    146147{
    147148  // temporarily create a Font.
    148   Font::defaultFontData = FontDataPointer(new FontData);
     149  Font::defaultFontData = FontData::Pointer(new FontData);
    149150  // apply the Data.
    150151  Font::defaultFontData = Font(font_xpm).data;
     
    159160bool Font::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize)
    160161{
    161   this->data = FontDataPointer (new FontData());
     162  this->data = FontData::Pointer (new FontData());
    162163  bool retVal = this->data->loadFontFromTTF(fontFile, renderSize);
    163164  if (!retVal)
     
    174175bool Font::loadFontFromSDL_Surface(SDL_Surface* surface)
    175176{
    176   this->data = FontDataPointer (new FontData());
     177  this->data = FontData::Pointer (new FontData());
    177178  bool retVal = this->data->loadFontFromSDL_Surface(surface);
    178179  if (!retVal)
     
    196197
    197198
    198 void Font::setTexture(const TextureDataPointer& texDataPointer)
     199void Font::setTexture(const TextureData::Pointer& texDataPointer)
    199200{
    200201  this->setDiffuseMap(texDataPointer);
  • trunk/src/lib/graphics/text_engine/font.h

    r8766 r9869  
    1919class Font : public Material
    2020{
    21 
     21  ObjectListDeclaration(Font);
     22public:
     23  typedef FontData::Glyph Glyph;
    2224public:
    2325  Font();
     
    3941
    4042  /** @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(); };
    4244
    4345  inline int getMaxHeight() const { return data->getMaxHeight(); };
     
    5052  void debug() const;
    5153
     54  void acquireData(const FontData::Pointer& data) { this->data = data; };
     55  const FontData::Pointer& dataPointer() const { return data; };
    5256private:
    5357  void init();
    5458  static void initDefaultFont();
    5559
    56   void setTexture(const TextureDataPointer& texDataPointer);
     60  void setTexture(const TextureData::Pointer& texDataPointer);
    5761
    5862private:
    59   FontDataPointer           data;                //!< A Data-Pointer to a Font.
     63  FontData::Pointer         data;                //!< A Data-Pointer to a Font.
    6064
    61   static FontDataPointer    defaultFontData;     //!< 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.
    6266};
    6367
  • trunk/src/lib/graphics/text_engine/font_data.h

    r8768 r9869  
    2626#define FONT_DEFAULT_RENDER_SIZE     50            //!< At what Resolution to render fonts.
    2727
     28class FontData
     29{
     30
     31
     32public:
     33
    2834//! A struct for handling glyphs
    2935/**
    3036 * a Glyph is one letter of a certain font
    3137 */
    32 struct Glyph
    33 {
     38  struct Glyph
     39  {
    3440  // Glyph-specific (size and so on)
    35   Uint16   character;         //!< The character
    36   float    minX;              //!< The minimum distance from the origin in X
    37   float    maxX;              //!< The maximum distance from the origin in X
    38   float    minY;              //!< The minimum distance from the origin in Y
    39   float    maxY;              //!< The maximum distance from the origin in Y
    40   float    width;             //!< The width of the Glyph
    41   float    height;            //!< The height of the Glyph
    42   float    bearingX;          //!< How much is right of the Origin
    43   float    bearingY;          //!< How much is above the Origin
    44   float    advance;           //!< How big a Glyph would be in monospace-mode
     41    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
    4551
    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  };
    4854
    49 
    50 class FontData
    51 {
     55  typedef CountPointer<FontData> Pointer;
    5256public:
    5357  FontData();
     
    6165
    6266  /** @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; };
    6468
    6569  int getMaxHeight() const { return maxHeight; };
     
    6872
    6973  /** @returns the Texture-Data of this FontData */
    70   const TextureDataPointer& textureData() const { return texData; };
     74  const TextureData::Pointer& textureData() const { return texData; };
    7175
    7276  bool rebuild() { return texData->rebuild(); };
     
    9195  int           maxDescent;          //!< Max Desent of the Font.
    9296
    93   TextureDataPointer   texData;
     97  TextureData::Pointer   texData;
    9498};
    9599
    96 typedef CountPointer<FontData> FontDataPointer;
    97 
    98100#endif /* _FONT_DATA_H */
  • trunk/src/lib/graphics/text_engine/limited_width_text.cc

    r9406 r9869  
    1919#include "font.h"
    2020
     21ObjectListDefinition(LimitedWidthText);
    2122/**
    2223 * @brief creates a new Text Element
     
    2728    : Text(fontFile, textSize)
    2829{
    29   this->setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText");
     30  this->registerObject(this, LimitedWidthText::_objectList);
    3031
    3132  this->_dotsPosition = End;
     
    7576  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    7677
    77   Glyph* tmpGlyph;
     78  const Font::Glyph* tmpGlyph;
    7879  float posX = 0.0f;
    7980  glBegin(GL_QUADS);
  • trunk/src/lib/graphics/text_engine/limited_width_text.h

    r8980 r9869  
    1414class LimitedWidthText : public Text
    1515{
     16  ObjectListDeclaration(LimitedWidthText);
    1617  public:
    1718    typedef enum {
  • trunk/src/lib/graphics/text_engine/multi_line_text.cc

    r9406 r9869  
    1919#include "font.h"
    2020
     21ObjectListDefinition(MultiLineText);
     22
    2123/**
    2224 * @brief creates a new Text Element
     
    2729  : Text(fontFile, textSize)
    2830{
    29   this->setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");
     31  this->registerObject(this, MultiLineText::_objectList);
    3032
    3133  this->lineSpacing = 1.0;
     
    7880  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    7981
    80   Glyph* tmpGlyph;
     82  const Font::Glyph* tmpGlyph;
    8183  float posX = 0.0f;
    8284  float posY = 0.0f;
  • trunk/src/lib/graphics/text_engine/multi_line_text.h

    r7757 r9869  
    1414class MultiLineText : public Text
    1515{
     16  ObjectListDeclaration(MultiLineText);
    1617  public:
    1718    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  
    1717
    1818#include "text.h"
     19#include "resource_font.h"
    1920#include "font.h"
    20 
    21 #include "util/loading/resource_manager.h"
    2221#include "debug.h"
     22
     23ObjectListDefinition(Text);
    2324
    2425/**
     
    2829 */
    2930Text::Text(const std::string& fontFile, unsigned int textSize)
    30     // : _font(fontFile, FONT_DEFAULT_RENDER_SIZE)
    31 {
    32   this->setClassID(CL_TEXT, "Text");
     31// : _font(fontFile, FONT_DEFAULT_RENDER_SIZE)
     32{
     33  this->registerObject(this, Text::_objectList);
    3334
    3435  // 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);
    3640  this->_size = textSize;
    3741  this->setSizeY2D(textSize);
     
    4448    : _font()
    4549{
    46   this->setClassID(CL_TEXT, "Text");
     50  this->registerObject(this, Text::_objectList);
    4751
    4852  *this = text;
     
    169173void Text::setFont(const std::string& fontFile, unsigned int fontSize)
    170174{
    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);
    189176
    190177  this->setupTextWidth();
     
    233220  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    234221
    235   Glyph* tmpGlyph;
     222  const Font::Glyph* tmpGlyph;
    236223  float posX = 0.0f;
    237224  glBegin(GL_QUADS);
  • trunk/src/lib/graphics/text_engine/text.h

    r8764 r9869  
    2626class Text : public Element2D
    2727{
     28  ObjectListDeclaration(Text);
    2829  public:
    2930    Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE);
  • trunk/src/lib/graphics/text_engine/text_engine.cc

    r9406 r9869  
    3333
    3434#include "graphics_engine.h"
    35 #include "util/loading/resource_manager.h"
    36 #include "class_list.h"
    3735
    3836#include "debug.h"
     
    4038/// TEXT-ENGINE ///
    4139///////////////////
     40ObjectListDefinition(TextEngine);
    4241/**
    4342 *  standard constructor
     
    4544TextEngine::TextEngine ()
    4645{
    47    this->setClassID(CL_TEXT_ENGINE, "TextEngine");
    48    this->setName("TextEngine");
    49    this->enableFonts();
     46  this->registerObject(this, TextEngine::_objectList);
     47  this->setName("TextEngine");
     48  this->enableFonts();
    5049}
    5150
     
    6261{
    6362  // 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();
    7065  // 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)
    7369  {
    7470    ///FIXME
    75 //    while (fontList->size() > 0)
     71    //    while (fontList->size() > 0)
    7672    {
    77 //      Font* font = dynamic_cast<Font*>(fontList->back());
     73      //      Font* font = dynamic_cast<Font*>(fontList->back());
    7874      //if (likely(font != Font::getDefaultFont()))
    7975      //        ResourceManager::getInstance()->unload(font, RP_GAME);
     
    9187{
    9288  if (!TTF_WasInit())
    93     {
    94       if(TTF_Init()==-1)
    95         PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
     89  {
     90    if(TTF_Init()==-1)
     91      PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
    9692
    97       TextEngine::checkVersion();
    98     }
     93    TextEngine::checkVersion();
     94  }
    9995  else
    10096    PRINTF(4)("Fonts already initialized\n");
     
    107103{
    108104  if (TTF_WasInit())
    109     {
    110 //      Font::removeDefaultFont();
    111       TTF_Quit();
    112     }
     105  {
     106    //      Font::removeDefaultFont();
     107    TTF_Quit();
     108  }
    113109  else
    114110    PRINTF(4)("Fonts were not initialized.\n");
     
    122118void TextEngine::debug() const
    123119{
    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)
    126128  {
    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();
    135130    PRINT(0)("+---------------------------TE--+\n");
    136131  }
     
    152147      compile_version.minor == link_version.minor &&
    153148      compile_version.patch == link_version.patch)
    154     {
    155       return true;
    156     }
     149  {
     150    return true;
     151  }
    157152  else
    158     {
    159       PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n",
    160                 compile_version.major,
    161                 compile_version.minor,
    162                 compile_version.patch);
     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);
    163158
    164       PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n",
    165                 link_version.major,
    166                 link_version.minor,
    167                 link_version.patch);
    168       return false;
    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  }
    170165}
  • trunk/src/lib/graphics/text_engine/text_engine.h

    r5515 r9869  
    2424class TextEngine : public BaseObject
    2525{
    26  public:
     26  ObjectListDeclaration(TextEngine);
     27  public:
    2728  virtual ~TextEngine();
    2829  /** @returns a Pointer to the only object of this Class */
  • trunk/src/lib/gui/gl/glgui_bar.cc

    r8991 r9869  
    2323{
    2424
     25  ObjectListDefinition(GLGuiBar);
    2526  /**
    2627   * @brief standard constructor
     
    4445  void GLGuiBar::init()
    4546  {
    46     this->setClassID(CL_GLGUI_BAR, "GLGuiBar");
     47    this->registerObject(this, GLGuiBar::_objectList);
    4748
    4849    this->setFrontColor(_changedValueColor, true);
  • trunk/src/lib/gui/gl/glgui_bar.h

    r8991 r9869  
    2121  class GLGuiBar : public GLGuiWidget
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiBar);
    2424  public:
    2525    GLGuiBar();
  • trunk/src/lib/gui/gl/glgui_box.cc

    r9656 r9869  
    2222namespace OrxGui
    2323{
     24  ObjectListDefinition(GLGuiBox);
    2425  /**
    2526   * standard constructor
     
    5253  void GLGuiBox::init()
    5354  {
    54     this->setClassID(CL_GLGUI_BOX, "GLGuiBox");
     55    this->registerObject(this, GLGuiBox::_objectList);
    5556  }
    5657
     
    149150    while (itC != this->_children.end())
    150151    {
    151       if ((*itC)->isA(CL_GLGUI_CONTAINER))
     152      if ((*itC)->isA(GLGuiContainer::staticClassID()))
    152153        static_cast<GLGuiContainer*>(*itC)->showAll();
    153154      else
     
    164165    while (itC != this->_children.end())
    165166    {
    166       if ((*itC)->isA(CL_GLGUI_CONTAINER))
     167      if ((*itC)->isA(GLGuiContainer::staticClassID()))
    167168        static_cast<GLGuiContainer*>(*itC)->hideAll();
    168169      else
  • trunk/src/lib/gui/gl/glgui_box.h

    r9656 r9869  
    1919  class GLGuiBox : public GLGuiContainer
    2020  {
    21 
     21    ObjectListDeclaration(GLGuiBox);
    2222  public:
    2323    GLGuiBox(OrxGui::Orientation orientation = OrxGui::Vertical);
  • trunk/src/lib/gui/gl/glgui_button.cc

    r9406 r9869  
    2323namespace OrxGui
    2424{
     25  ObjectListDefinition(GLGuiButton);
    2526  /**
    2627   * standard constructor
     
    5051  void GLGuiButton::init()
    5152  {
    52     this->setClassID(CL_GLGUI_BUTTON, "GLGuiButton");
     53    this->registerObject(this, GLGuiButton::_objectList);
    5354
    5455    this->setSelectable(true);
  • trunk/src/lib/gui/gl/glgui_button.h

    r9406 r9869  
    3131  class GLGuiButton : public GLGuiWidget
    3232  {
    33 
     33    ObjectListDeclaration(GLGuiButton);
    3434    public:
    3535      GLGuiButton(const std::string& label);
  • trunk/src/lib/gui/gl/glgui_checkbutton.cc

    r9406 r9869  
    2222namespace OrxGui
    2323{
    24 
     24  ObjectListDefinition(GLGuiCheckButton);
    2525
    2626  /**
     
    4949  void GLGuiCheckButton::init()
    5050  {
    51     this->setClassID(CL_GLGUI_CHECKBUTTON, "GLGuiCheckButton");
     51    this->registerObject(this, GLGuiCheckButton::_objectList);
    5252  }
    5353
  • trunk/src/lib/gui/gl/glgui_checkbutton.h

    r9406 r9869  
    2121  class GLGuiCheckButton : public GLGuiButton
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiCheckButton);
    2424  public:
    2525    GLGuiCheckButton(const std::string& label = "", bool active = false);
  • trunk/src/lib/gui/gl/glgui_colorselector.h

    r8145 r9869  
    2121  class GLGui : public GLGui
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiColorSelector);
    2424  public:
    2525    GLGui();
  • trunk/src/lib/gui/gl/glgui_container.cc

    r9656 r9869  
    2020namespace OrxGui
    2121{
    22 
     22  ObjectListDefinition(GLGuiContainer);
    2323  /**
    2424   * standard constructor
     
    4141  void GLGuiContainer::init()
    4242  {
    43     this->setClassID(CL_GLGUI_CONTAINER, "GLGuiContainer");
     43    this->registerObject(this, GLGuiContainer::_objectList);
    4444
    4545    this->setBackgroundTexture("gui_container_background.png");
  • trunk/src/lib/gui/gl/glgui_container.h

    r9656 r9869  
    2020  class GLGuiContainer : public GLGuiWidget
    2121  {
    22 
     22    ObjectListDeclaration(GLGuiContainer);
    2323  public:
    2424    GLGuiContainer();
  • trunk/src/lib/gui/gl/glgui_cursor.cc

    r8619 r9869  
    2323namespace OrxGui
    2424{
    25 
     25  ObjectListDefinition(GLGuiCursor);
    2626  /**
    2727   * standard constructor
     
    5555  void GLGuiCursor::init()
    5656  {
    57     this->setClassID(CL_GLGUI_CURSOR, "GLGuiCursor");
     57    this->registerObject(this, GLGuiCursor::_objectList);
    5858
    5959    this->setBackgroundColor(Color(1.0, 1.0, 1.0, 1.0));
  • trunk/src/lib/gui/gl/glgui_cursor.h

    r8324 r9869  
    2626  class GLGuiCursor : public GLGuiWidget, public EventListener
    2727  {
    28 
     28    ObjectListDeclaration(GLGuiCursor);
    2929  public:
    3030    GLGuiCursor();
  • trunk/src/lib/gui/gl/glgui_fixedposition_box.cc

    r9656 r9869  
    2323namespace OrxGui
    2424{
     25  ObjectListDefinition(GLGuiFixedpositionBox);
    2526  /**
    2627   * standard constructor
     
    2930      : GLGuiBox(orientation)
    3031  {
     32    this->registerObject(this, GLGuiFixedpositionBox::_objectList);
     33
    3134    this->subscribeEvent(ES_ALL, EV_VIDEO_RESIZE);
    3235    this->setPosition(position);
  • trunk/src/lib/gui/gl/glgui_fixedposition_box.h

    r9656 r9869  
    2121  class GLGuiFixedpositionBox : public OrxGui::GLGuiBox, EventListener
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiFixedpositionBox);
    2424    public:
    2525      GLGuiFixedpositionBox(OrxGui::Position position = OrxGui::Center, OrxGui::Orientation orientation = OrxGui::Vertical);
  • trunk/src/lib/gui/gl/glgui_frame.cc

    r9406 r9869  
    2121namespace OrxGui
    2222{
    23 
     23  ObjectListDefinition(GLGuiFrame);
    2424  /**
    2525   * standard constructor
     
    4444  void GLGuiFrame::init()
    4545  {
    46     this->setClassID(CL_GLGUI_FRAME, "GLGuiFrame");
     46    this->registerObject(this, GLGuiFrame::_objectList);
    4747    this->child = NULL;
    4848  }
     
    7171    if (this->child != NULL)
    7272    {
    73       if (this->child->isA(CL_GLGUI_CONTAINER))
     73      if (this->child->isA(GLGuiContainer::staticClassID()))
    7474        static_cast<GLGuiContainer*>(this->child)->showAll();
    7575      else
     
    8383    if (this->child != NULL)
    8484    {
    85       if (this->child->isA(CL_GLGUI_CONTAINER))
     85      if (this->child->isA(GLGuiContainer::staticClassID()))
    8686        static_cast<GLGuiContainer*>(this->child)->hideAll();
    8787      else
  • trunk/src/lib/gui/gl/glgui_frame.h

    r8145 r9869  
    2020  class GLGuiFrame : public GLGuiContainer
    2121  {
    22 
     22    ObjectListDeclaration(GLGuiFrame);
    2323  public:
    2424    GLGuiFrame();
  • trunk/src/lib/gui/gl/glgui_handler.cc

    r9656 r9869  
    2323#include "glgui_cursor.h"
    2424
    25 #include "class_list.h"
     25#include "loading/resource_manager.h"
     26
    2627#include <cassert>
    2728
     
    3132/// TAKE THIS OUT OF HERE.
    3233#include "graphics_engine.h"
    33 #include "loading/resource_manager.h"
    3434
    3535namespace OrxGui
    3636{
    37 
     37  ObjectListDefinition(GLGuiHandler);
    3838  /**
    3939   * standard constructor
     
    4141  GLGuiHandler::GLGuiHandler ()
    4242  {
    43     this->setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");
     43    this->registerObject(this, GLGuiHandler::_objectList);
    4444    this->setName("GLGuiHandler");
    4545
     
    7777    this->_cursor->setMaxBorders(Vector2D(GraphicsEngine::getInstance()->getResolutionX(), GraphicsEngine::getInstance()->getResolutionY()));
    7878
    79     _cursor->loadTextureSequence(ResourceManager::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);
    8080
    8181  }
     
    117117  {
    118118    // 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();
    125159
    126160      if (GLGuiWidget::selected() != NULL)
    127161      {
    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())
    178164        {
    179165          currentIt = it;
     
    183169      else
    184170      {
    185         it = objects->end();
     171        it = GLGuiWidget::objectList().end();
    186172      }
    187173
     
    190176      for (; it != currentIt; --it)
    191177      {
    192         if (it == objects->end() && !cycledOnce)
     178        if (it == GLGuiWidget::objectList().end() && !cycledOnce)
    193179        {
    194180          --it ;
     
    196182        }
    197183
    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();
    201187          return;
    202188        }
    203189      }
    204190
    205     }
    206     else
    207     {
    208       PRINTF(0)("NO GUI-ELEMENTS EXISTING\n");
    209     }
    210191  }
    211192
     
    217198    {
    218199      case EV_MOUSE_MOTION:
    219         this->checkFocus();
    220         break;
     200      this->checkFocus();
     201      break;
    221202
    222203      case  EV_MOUSE_BUTTON_LEFT:
    223         if (GLGuiWidget::mouseFocused() != NULL && event.bPressed)
    224         {
    225           // if clickable select the Widget.
    226           if (GLGuiWidget::mouseFocused()->clickable())
    227           {
    228             Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
    229             GLGuiWidget::mouseFocused()->select();
    230             GLGuiWidget::mouseFocused()->click(cursorPos - GLGuiWidget::mouseFocused()->getAbsCoor2D());
    231           }
    232         }
    233         else if (GLGuiWidget::selected() != NULL && !event.bPressed)
    234         {
    235           if (GLGuiWidget::selected()->clickable())
    236           {
    237             Vector2D cursorPos = (this->_cursor != NULL) ? this->_cursor->getAbsCoor2D() : Vector2D(event.x, event.y);
    238             GLGuiWidget::selected()->release(cursorPos - GLGuiWidget::selected()->getAbsCoor2D());
    239           }
    240         }
    241 
    242         break;
     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;
    243224      case EV_LEAVE_STATE:
    244         if (GLGuiWidget::selected() != NULL)
    245           GLGuiWidget::selected()->unselect();
    246 
    247         if (GLGuiWidget::mouseFocused() != NULL)
    248           GLGuiWidget::mouseFocused()->breakMouseFocus();
    249         break;
     225      if (GLGuiWidget::selected() != NULL)
     226        GLGuiWidget::selected()->unselect();
     227
     228      if (GLGuiWidget::mouseFocused() != NULL)
     229        GLGuiWidget::mouseFocused()->breakMouseFocus();
     230      break;
    250231
    251232      case EV_VIDEO_RESIZE:
    252         if (this->_cursor != NULL)
    253           this->_cursor->setMaxBorders(Vector2D(event.resize.w, event.resize.h));
    254         this->_resolution = Vector2D(event.resize.w, event.resize.h);
    255         break;
     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;
    256237
    257238      case SDLK_TAB:
    258         if (event.bPressed)
    259         {
    260           if (EventHandler::getInstance()->isPressed(SDLK_LSHIFT) || EventHandler::getInstance()->isPressed(SDLK_RSHIFT))
    261             this->selectPrevious();
    262           else
    263             this->selectNext();
    264         }
    265         break;
     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;
    266247    }
    267248
     
    304285  {
    305286    // 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);
    313294
    314295        if (widget->isVisible() &&
  • trunk/src/lib/gui/gl/glgui_handler.h

    r9656 r9869  
    1919  class GLGuiHandler : public EventListener
    2020  {
    21 
     21    ObjectListDeclaration(GLGuiHandler);
    2222  public:
    2323    /** @returns a Pointer to the only object of this Class */
  • trunk/src/lib/gui/gl/glgui_image.cc

    r8619 r9869  
    2222namespace OrxGui
    2323{
    24 
     24  ObjectListDefinition(GLGuiImage);
    2525  /**
    2626   * standard constructor
     
    4545  void GLGuiImage::init()
    4646  {
    47     this->setClassID(CL_GLGUI_IMAGE, "GLGuiImage");
     47    this->registerObject(this, GLGuiImage::_objectList);
    4848
    4949    this->setForegroundColor(Color(1,1,1,1));
  • trunk/src/lib/gui/gl/glgui_image.h

    r9406 r9869  
    2121  class GLGuiImage : public GLGuiWidget
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiImage);
    2424  public:
    2525    GLGuiImage();
  • trunk/src/lib/gui/gl/glgui_inputline.cc

    r9406 r9869  
    2020namespace OrxGui
    2121{
     22  ObjectListDefinition(GLGuiInputLine);
    2223  /**
    2324   * @brief standard constructor
     
    4445  void GLGuiInputLine::init()
    4546  {
    46     this->setClassID(CL_GLGUI_INPUTLINE, "GLGuiInputLine");
     47    this->registerObject(this, GLGuiInputLine::_objectList);
    4748
    4849    this->setFocusable(true);
  • trunk/src/lib/gui/gl/glgui_inputline.h

    r9406 r9869  
    2525  class GLGuiInputLine : public OrxGui::GLGuiWidget
    2626  {
    27 
     27    ObjectListDeclaration(GLGuiInputLine);
    2828  public:
    2929    GLGuiInputLine();
  • trunk/src/lib/gui/gl/glgui_mainwidget.cc

    r8145 r9869  
    2020namespace OrxGui
    2121{
    22 
     22  ObjectListDefinition(GLGuiMainWidget);
    2323
    2424  /**
     
    2727  GLGuiMainWidget::GLGuiMainWidget()
    2828  {
    29     this->setClassID(CL_GLGUI_MAIN_WIDGET, "GLGuiMainWidget");
     29    this->registerObject(this, GLGuiMainWidget::_objectList);
    3030    this->setName("GLGuiMainWidget");
    3131  }
  • trunk/src/lib/gui/gl/glgui_mainwidget.h

    r8145 r9869  
    1515  class GLGuiMainWidget : public GLGuiWidget
    1616  {
    17 
     17    ObjectListDeclaration(GLGuiMainWidget);
    1818  public:
    1919    virtual ~GLGuiMainWidget(void);
  • trunk/src/lib/gui/gl/glgui_menu.cc

    r8145 r9869  
    2020namespace OrxGui
    2121{
    22 
     22  ObjectListDefinition(GLGuiMenu);
    2323  /**
    2424   * standard constructor
  • trunk/src/lib/gui/gl/glgui_menu.h

    r8145 r9869  
    1919  class GLGuiMenu : public GLGuiMenu
    2020  {
    21 
     21    ObjectListDeclaration(GLGuiMenu);
    2222  public:
    2323    GLGuiMenu();
  • trunk/src/lib/gui/gl/glgui_pushbutton.cc

    r8717 r9869  
    2323namespace OrxGui
    2424{
    25 
     25  ObjectListDefinition(GLGuiPushButton);
    2626  /**
    2727   * @brief standard constructor
     
    5858  void GLGuiPushButton::init()
    5959  {
    60     this->setClassID(CL_GLGUI_PUSHBUTTON, "GLGuiPushButton");
     60    this->registerObject(this, GLGuiPushButton::_objectList);
    6161  }
    6262
  • trunk/src/lib/gui/gl/glgui_pushbutton.h

    r8717 r9869  
    2121  class GLGuiPushButton : public GLGuiButton
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiPushButton);
    2424  public:
    2525    GLGuiPushButton(const std::string& label = "");
  • trunk/src/lib/gui/gl/glgui_slider.cc

    r9406 r9869  
    2323namespace OrxGui
    2424{
    25 
     25  ObjectListDefinition(GLGuiSlider);
    2626  /**
    2727   * @brief standard constructor
     
    4646  {
    4747
    48     this->setClassID(CL_GLGUI_SLIDER, "GLGuiSlider");
     48    this->registerObject(this, GLGuiSlider::_objectList);
    4949
    5050    this->setClickable(true);
  • trunk/src/lib/gui/gl/glgui_slider.h

    r9406 r9869  
    2121  class GLGuiSlider : public GLGuiWidget
    2222  {
    23 
     23    ObjectListDeclaration(GLGuiSlider);
    2424  public:
    2525    GLGuiSlider();
  • trunk/src/lib/gui/gl/glgui_table.cc

    r8717 r9869  
    2323namespace OrxGui
    2424{
     25  ObjectListDefinition(GLGuiTable);
    2526  /**
    2627   * @brief standard constructor
     
    4748  void GLGuiTable::init()
    4849  {
    49     this->setClassID(CL_GLGUI_TABLE, "GLGuiTable");
     50    this->registerObject(this, GLGuiTable::_objectList);
    5051
    5152    this->setBorderTop(10);
  • trunk/src/lib/gui/gl/glgui_table.h

    r8717 r9869  
    2525  class GLGuiTable : public OrxGui::GLGuiWidget
    2626  {
    27 
     27    ObjectListDeclaration(GLGuiTable);
    2828  public:
    2929    GLGuiTable(unsigned int rows, unsigned int columns);
  • trunk/src/lib/gui/gl/glgui_text.cc

    r9656 r9869  
    2222namespace OrxGui
    2323{
     24  ObjectListDefinition(GLGuiText);
    2425  /**
    2526   * standard constructor
     
    4344  void GLGuiText::init()
    4445  {
    45     this->setClassID(CL_GLGUI_TEXT, "GLGuiText");
     46    this->registerObject(this, GLGuiText::_objectList);
    4647
    4748    this->_text.setParent2D(this);
  • trunk/src/lib/gui/gl/glgui_text.h

    r9656 r9869  
    2020  class GLGuiText : public GLGuiWidget
    2121  {
    22 
     22    ObjectListDeclaration(GLGuiText);
    2323  public:
    2424    GLGuiText();
  • trunk/src/lib/gui/gl/glgui_textfield.cc

    r9406 r9869  
    2222namespace OrxGui
    2323{
     24  ObjectListDefinition(GLGuiTextfield);
    2425  /**
    2526   * standard constructor
     
    4344  void GLGuiTextfield::init()
    4445  {
    45     this->setClassID(CL_GLGUI_TEXTFIELD, "GLGuiTextfield");
     46    this->registerObject(this, GLGuiTextfield::_objectList);
    4647
    4748    this->_text.setParent2D(this);
  • trunk/src/lib/gui/gl/glgui_textfield.h

    r9406 r9869  
    2020  class GLGuiTextfield : public GLGuiWidget
    2121  {
    22 
     22    ObjectListDeclaration(GLGuiTextfield);
    2323  public:
    2424    GLGuiTextfield();
  • trunk/src/lib/gui/gl/glgui_widget.cc

    r9656 r9869  
    2525
    2626#include "loading/load_param.h"
    27 
    28 /// TODO TAKE THIS OUT OF HERE
    2927#include "loading/resource_manager.h"
    3028
    3129namespace OrxGui
    3230{
    33 
     31  ObjectListDefinition(GLGuiWidget);
    3432  /**
    3533   * @brief standard constructor
     
    9593  void GLGuiWidget::init()
    9694  {
    97     this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget");
     95    this->registerObject(this, GLGuiWidget::_objectList);
    9896
    9997    this->_focusable = false;
     
    104102
    105103    if(GLGuiWidget::_defaultFont == NULL)
    106       GLGuiWidget::_defaultFont = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/final_frontier.ttf", 20);
     104      GLGuiWidget::_defaultFont = new Font(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/fonts/final_frontier.ttf", 20);
    107105
    108106    this->_font = *GLGuiWidget::_defaultFont;
  • trunk/src/lib/gui/gl/glgui_widget.h

    r9656 r9869  
    2121namespace OrxGui
    2222{
    23 
    2423  class GLGuiCursor;
    2524
     
    3130  class GLGuiWidget : public Element2D
    3231  {
     32    ObjectListDeclaration(GLGuiWidget);
    3333  public:
    3434    GLGuiWidget(GLGuiWidget* parent = NULL);
  • trunk/src/lib/gui/gl/glgui_window.cc

    r8145 r9869  
    2020namespace OrxGui
    2121{
    22 
     22  ObjectListDefinition(GLGuiWindow);
    2323  /**
    2424   * standard constructor
     
    4343  void GLGuiWindow::init()
    4444  {
    45     this->setClassID(CL_GLGUI_WINDOW, "GLGuiWindow");
     45    this->registerObject(this, GLGuiWindow::_objectList);
    4646
    4747  }
  • trunk/src/lib/gui/gl/glgui_window.h

    r8145 r9869  
    2020  class GLGuiWindow : public GLGuiContainer
    2121  {
    22 
     22    ObjectListDeclaration(GLGuiWindow);
    2323  public:
    2424    GLGuiWindow();
  • trunk/src/lib/gui/gl/glmenu/glmenu_imagescreen.cc

    r9406 r9869  
    2424#include "util/loading/factory.h"
    2525#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"
     29ObjectListDefinitionID(GLMenuImageScreen, CL_GLMENU_IMAGE_SCREEN);
     30CREATE_FACTORY(GLMenuImageScreen);
    2931
    3032/**
     
    3335GLMenuImageScreen::GLMenuImageScreen(const TiXmlElement* root)
    3436{
    35   this->setClassID(CL_GLMENU_IMAGE_SCREEN, "GLMenuImageScreen");
     37  this->registerObject(this, GLMenuImageScreen::_objectList);
    3638  this->setName("GLMenuLoadScreen");
    3739  // Select Our VU Meter Background Texture
     
    5860{
    5961  LoadParam(root, "BackgroundImage", this, GLMenuImageScreen, setBackgroundImage)
    60     .describe("sets the image to load onto the loadscreen");
     62  .describe("sets the image to load onto the loadscreen");
    6163
    6264  LoadParam(root, "BackgroundPS", this, GLMenuImageScreen, setPosScale)
    63     .describe("The Position and Scale of the Background Image in %(0-1.0). PosX, PosY, SizeX, SizeY");
     65  .describe("The Position and Scale of the Background Image in %(0-1.0). PosX, PosY, SizeX, SizeY");
    6466
    6567  LoadParam(root, "BarImage", this, GLMenuImageScreen, setBarImage)
    66     .describe("sets the image of the LoadingBar");
     68  .describe("sets the image of the LoadingBar");
    6769
    6870  LoadParam(root, "BarPS", this, GLMenuImageScreen, setBarPosScale)
    69     .describe("The Position and Scale of the Loading Bar in %(0-1.0). PosX, PosY, SizeX, SizeY");
     71  .describe("The Position and Scale of the Loading Bar in %(0-1.0). PosX, PosY, SizeX, SizeY");
    7072
    7173  LoadParam(root, "ElementCount", this, GLMenuImageScreen, setMaximum)
    72     .describe("The Count of elements to load into the bar (this is only a maximum value)");
     74  .describe("The Count of elements to load into the bar (this is only a maximum value)");
    7375}
    7476
  • trunk/src/lib/gui/gl/glmenu/glmenu_imagescreen.h

    r8145 r9869  
    1515class GLMenuImageScreen : public BaseObject
    1616{
    17 
     17  ObjectListDeclaration(GLMenuImageScreen);
    1818public:
    1919  GLMenuImageScreen (const TiXmlElement* root = NULL);
     
    3333  void setMaximum (int maxValue);
    3434  /** @returns the maximum of countable steps*/
    35   inline int GLMenuImageScreen::getMaximum() const { return this->maxValue; };
     35  inline int getMaximum() const { return this->maxValue; };
    3636
    3737  void setValue (int currentValue);
  • trunk/src/lib/gui/gl/specials/glgui_notifier.cc

    r8619 r9869  
    2323namespace OrxGui
    2424{
    25 
     25  ObjectListDefinition(GLGuiNotifier);
    2626  /**
    2727   * @brief standard constructor
     
    2929  GLGuiNotifier::GLGuiNotifier ()
    3030  {
    31     this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier");
     31    this->registerObject(this, GLGuiNotifier::_objectList);
    3232
    3333    // Element2D and generals
  • trunk/src/lib/gui/gl/specials/glgui_notifier.h

    r8619 r9869  
    2424  class GLGuiNotifier : public GLGuiWidget
    2525  {
     26    ObjectListDeclaration(GLGuiNotifier);
    2627  public:
    2728    GLGuiNotifier();
     
    6768      MultiLineText*    text;
    6869
    69     } DisplayLine;
     70    }
     71    DisplayLine;
    7072
    7173
  • trunk/src/lib/gui/gui.cc

    r7661 r9869  
    1818#include "gui.h"
    1919#include "gui_saveable.h"
    20 #include "preferences.h"
     20#include "parser/preferences/preferences.h"
    2121
    2222namespace OrxGui
  • trunk/src/lib/gui/gui_saveable.cc

    r9406 r9869  
    1818#include "gui_saveable.h"
    1919#include "gui.h"
    20 #include "preferences.h"
     20#include "parser/preferences/preferences.h"
    2121
    2222#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
     1INCLUDES = -I../..
     2INCLUDES +=-I..
     3INCLUDES +=-I../util
    64
    75noinst_LIBRARIES = libORXlang.a
     
    97libORXlang_a_SOURCES = \
    108                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
    1411
    1512noinst_HEADERS = \
    1613                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 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
     
    1917#include "base_object.h"
    2018
     19#include "util/debug.h"
    2120#include "util/loading/load_param.h"
    22 #include "class_list.h"
     21
     22ObjectListDefinition(BaseObject);
    2323
    2424/**
    2525 * @brief sets the name from a LoadXML-Element
    26  * @param root the element to load from
     26 * @param objectName: The name of the Object.
    2727 */
    2828BaseObject::BaseObject(const std::string& objectName)
    2929{
    30   this->classID = CL_BASE_OBJECT;
    3130  this->className = "BaseObject";
    3231
    3332  this->objectName = objectName;
    34   this->classList = NULL;
    3533  this->xmlElem = NULL;
    36 
    37   //ClassList::addToClassList(this, this->classID, "BaseObject");
     34  this->registerObject(this, BaseObject::_objectList);
    3835}
    3936
     
    4340BaseObject::~BaseObject ()
    4441{
    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  }
    4652
    4753  if (this->xmlElem != NULL)
     
    6975
    7076/**
    71  * @brief sets the class identifiers
    72  * @param id a number for the class from class_id.h enumeration
    73  * @param className the class name
    74 */
    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 /**
    8977 * @brief set the name of the Object
    9078 * @param objectName The new name of the Object.
     
    9785
    9886/**
    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.
    10490 */
    105 const ClassID& BaseObject::getLeafClassID() const
     91bool BaseObject::isA(const ObjectListBase& objectList) const
    10692{
    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)
    12396      return true;
    124   }
    125   // if classID is a SubSuperClass, and
    126   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-class
    133   else
    134   {
    135     if( likely((this->classID & CL_MASK_LOWLEVEL_CLASS) == classID))
    136       return true;
    137   }
    13897  return false;
    13998}
    14099
    141100
     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 */
     106bool 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}
    142114
    143115/**
    144  * @brief checks if the class is a classID
    145  * @param classID the Identifier to check for
    146  * @returns true if it is, false otherwise
     116 * @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.
    147119 */
    148 bool BaseObject::isA (const std::string& className) const
     120bool BaseObject::isA(int classID) const
    149121{
    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 */
     135bool 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;
    155142}
    156143
    157144
    158145/**
    159  * @brief compares the ObjectName with an external name
    160  * @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.
    162149 */
    163 bool BaseObject::operator==(const std::string& objectName) const
     150void BaseObject::listInheritance() const
    164151{
    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
    166158}
    167 
  • trunk/src/lib/lang/base_object.h

    r9406 r9869  
    1414#define __BASE_OBJECT_H_
    1515
    16 #include "class_id.h"
    17 #include "sigslot/slot.h"
     16#include "object_list.h"
     17#include "util/sigslot/slot.h"
    1818
    1919#include <string>
     
    2626class BaseObject : public sigslot::has_slots<>
    2727{
    28 
     28  //! Declare an ObjectList for this Class.
     29  ObjectListDeclaration(BaseObject);
    2930public:
    3031  BaseObject (const std::string& objectName = "");
     
    4142  inline TiXmlNode* getXmlElem() const { return this->xmlElem; };
    4243
    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; }
    4546  /** @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(); };
    5050
    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;
    5362
    5463  /** @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;};
    5767
    5868protected:
    59   void setClassID(ClassID classID, const std::string& className);
     69  template<class T> void registerObject(T* object, ObjectList<T>& list);
    6070
    6171protected:
     
    6373
    6474private:
    65   std::string        className;        //!< the name of the class
    66   long               classID;          //!< this is the id from the class_id.h enumeration
    67   ClassID            leafClassID;      //!< The Leaf Class ID
    68 
    69   ClassList*         classList;        //!< Pointer to the ClassList this Object is inside of
    7075
    7176  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.
    7293};
    7394
     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 */
     105template<class T>
     106inline void BaseObject::registerObject(T* object, ObjectList<T>& objectList)
     107{
     108  this->_classes.push_front(ClassEntry(&objectList, objectList.registerObject(object)));
     109}
     110
    74111#endif /* __BASE_OBJECT_H_ */
  • trunk/src/lib/network/converter.cc

    r9406 r9869  
    2828SHELL_COMMAND_STATIC(debug, Converter, Converter::debug);
    2929
    30 
     30ObjectListDefinition(Converter);
    3131/* using namespace std is default, this needs to be here */
    3232
  • trunk/src/lib/network/converter.h

    r7230 r9869  
    2424class Converter : public BaseObject
    2525{
     26  ObjectListDeclaration(Converter);
    2627  public:
    2728    static byte* intToByteArray(int x);
  • trunk/src/lib/network/data_stream.cc

    r9406 r9869  
    2020/* using namespace std is default, this needs to be here */
    2121
    22 
    23 
     22ObjectListDefinition(DataStream);
    2423
    2524/**
     
    2827DataStream::DataStream()
    2928{
    30   this->setClassID(CL_DATA_STREAM, "DataStream");
    3129  this->upBuffer = new byte[DATA_STREAM_BUFFER_SIZE];
    3230  this->downBuffer = new byte[DATA_STREAM_BUFFER_SIZE];
     
    3836DataStream::DataStream(DataStream& inStream, DataStream& outStream)
    3937{
    40     this->setClassID(CL_DATA_STREAM, "DataStream");
     38  this->registerObject(this, DataStream::_objectList);
    4139    this->downStream = &outStream;
    4240    this->upStream = &inStream;
  • trunk/src/lib/network/data_stream.h

    r6981 r9869  
    1717class DataStream : public BaseObject
    1818{
    19       public:
     19  ObjectListDeclaration(DataStream);
     20  public:
    2021      DataStream();
    2122      DataStream(DataStream& inStream, DataStream& outStream);
  • trunk/src/lib/network/handshake.cc

    r9656 r9869  
    2323
    2424
    25 
     25ObjectListDefinition(Handshake);
    2626
    2727
     
    3030{
    3131  /* set the class id for the base object */
    32   this->setClassID(CL_HANDSHAKE, "Handshake");
     32  this->registerObject(this, Handshake::_objectList);
    3333
    3434
  • trunk/src/lib/network/handshake.h

    r9494 r9869  
    4242class Handshake : public Synchronizeable
    4343{
    44 
     44  ObjectListDeclaration(Handshake);
    4545  public:
    4646    Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
  • trunk/src/lib/network/message_manager.cc

    r9656 r9869  
    2828
    2929
    30 
     30ObjectListDefinition(MessageManager);
    3131MessageManager* MessageManager::singletonRef = NULL;
    3232
     
    3737MessageManager::MessageManager ()
    3838{
    39   this->setClassID( CL_MESSAGE_MANAGER, "MessageManager" );
     39  this->registerObject(this, MessageManager::_objectList);
    4040  newNumber = 1;
    4141  setSynchronized( true );
  • trunk/src/lib/network/message_manager.h

    r9656 r9869  
    9696class MessageManager : public Synchronizeable {
    9797
    98 
     98  ObjectListDeclaration(MessageManager);
    9999 public:
    100100   inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager();  return singletonRef; }
  • trunk/src/lib/network/monitor/connection_monitor.cc

    r9494 r9869  
    2323/* using namespace std is default, this needs to be here */
    2424
    25 
     25ObjectListDefinition(ConnectionMonitor);
    2626/**
    2727 * constructor
     
    3131{
    3232  /* 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);
    3434
    3535  this->userId = userId;
  • trunk/src/lib/network/monitor/connection_monitor.h

    r9494 r9869  
    1919class ConnectionMonitor : virtual public BaseObject
    2020{
     21  ObjectListDeclaration(ConnectionMonitor);
    2122  public:
    2223    ConnectionMonitor( int userId );
  • trunk/src/lib/network/monitor/network_monitor.cc

    r9656 r9869  
    3737SHELL_COMMAND(debug, NetworkMonitor, debug);
    3838
     39ObjectListDefinition(NetworkMonitor);
    3940
    4041
     
    4546  : Synchronizeable()
    4647{
    47   this->setClassID(CL_NETWORK_MONITOR, "NetworkMonitor");
     48  this->registerObject(this, NetworkMonitor::_objectList);
    4849
    4950  this->networkStream = networkStream;
  • trunk/src/lib/network/monitor/network_monitor.h

    r9656 r9869  
    2727class NetworkMonitor : public Synchronizeable
    2828{
    29 
     29  ObjectListDeclaration(NetworkMonitor);
    3030  public:
    3131    NetworkMonitor(NetworkStream* networkStream);
  • trunk/src/lib/network/monitor/network_stats_widget.cc

    r9656 r9869  
    2020#include "peer_info.h"
    2121
     22#include "loading/resource_manager.h"
     23
    2224#include "multi_type.h"
    2325
    2426#include "shell_command.h"
    25 
    26 #include "loading/resource_manager.h"
    2727
    2828// this fcuk does not work!
     
    3030// ->setAlias("ProxyGui");
    3131
    32 
    3332HostWidget::HostWidget(const std::string& name, const IP& ip)
    3433    : GLGuiBox(OrxGui::Horizontal)
     
    5756{
    5857  if(_font == NULL)
    59     _font = new Font(ResourceManager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20);
     58    _font = new Font(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + "/fonts/arial.ttf", 20);
    6059
    6160  //this->_name.setFont(*_font);
     
    211210//======================================================//
    212211
     212
     213ObjectListDefinition(NetworkStatsWidget);
    213214/**
    214215 * @brief standard constructor
     
    273274NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL;
    274275
    275 #include "class_list.h"
    276 
    277276void NetworkStatsWidget::toggleGUI()
    278277{
    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);
    287285    NetworkStatsWidget::_statsWidget->showAll();
    288286  }
  • trunk/src/lib/network/monitor/network_stats_widget.h

    r9656 r9869  
    8181class NetworkStatsWidget : public OrxGui::GLGuiFixedpositionBox
    8282{
     83  ObjectListDeclaration(NetworkStatsWidget);
    8384  public:
    8485    static void toggleGUI();
  • trunk/src/lib/network/network_game_manager.cc

    r9656 r9869  
    2323#include "util/loading/factory.h"
    2424#include "state.h"
    25 #include "class_list.h"
    2625#include "debug.h"
    2726
     
    4342#include "multiplayer_team_deathmatch.h"
    4443
    45 #include "preferences.h"
    46 
    47 
    48 
    49 
     44#include "parser/preferences/preferences.h"
     45
     46
     47
     48ObjectListDefinition(NetworkGameManager);
    5049NetworkGameManager* NetworkGameManager::singletonRef = NULL;
    5150
     
    5958
    6059  /* set the class id for the base object */
    61   this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
     60  this->registerObject(this, NetworkGameManager::_objectList);
    6261
    6362  this->setSynchronized(true);
     
    9392  assert( SharedNetworkData::getInstance()->isMasterServer());
    9493  assert( State::getGameRules() );
    95   assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     94  assert( State::getGameRules()->isA( NetworkGameRules::staticClassID()) );
    9695
    9796  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
    9897
    9998  int          team = rules.getTeamForNewUser();
    100   ClassID      playableClassId = rules.getPlayableClassId( userId, team );
     99  ClassID   playableClassId = rules.getPlayableClassId( userId, team );
    101100  std::string  playableModel = rules.getPlayableModelFileName( userId, team, playableClassId );
    102101  std::string  playableTexture = rules.getPlayableModelFileName( userId, team, playableClassId );
     
    106105
    107106  assert( bo != NULL );
    108   assert( bo->isA( CL_PLAYABLE ) );
     107  assert( bo->isA( Playable::staticClassID()) );
    109108
    110109  Playable & playable = *(dynamic_cast<Playable*>(bo));
     
    131130    stats->setNickName( Preferences::getInstance()->getString( "multiplayer", "nickname", "Server" ) );
    132131
    133   if ( rules.isA( CL_MULTIPLAYER_TEAM_DEATHMATCH ) )
     132  if ( rules.isA( MultiplayerTeamDeathmatch::staticClassID()) )
    134133    dynamic_cast<MultiplayerTeamDeathmatch*>(&rules)->respawnPlayable( &playable, team, 0.0f );
    135134
     
    187186  }
    188187
    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 )
    194193    {
    195       if ( (*it)->isA(CL_PLAYABLE) )
     194      if ( (*it)->isA(Playable::staticClassID()) )
    196195      {
    197196        getInstance()->playablesToDelete.push_back( dynamic_cast<Playable*>(*it) );
     
    199198      }
    200199
    201       delete dynamic_cast<Synchronizeable*>(*it);
     200      delete (*it);
    202201      return true;
    203202    }
     
    297296    if ( State::getPlayer()->getPlayable() != *it )
    298297    {
    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() )
    302299      {
    303300        PRINTF(0)("Delete unused playable: %s owner: %d\n", (*it)->getClassCName(), (*it)->getOwner() );
     
    324321
    325322  assert( State::getGameRules() );
    326   assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
     323  assert( State::getGameRules()->isA( NetworkGameRules::staticClassID()) );
    327324
    328325  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
  • trunk/src/lib/network/network_game_manager.h

    r9656 r9869  
    3333class NetworkGameManager: public Synchronizeable
    3434{
    35 
     35  ObjectListDeclaration(NetworkGameManager);
    3636  public:
    3737    virtual ~NetworkGameManager();
    3838
    39     static NetworkGameManager* NetworkGameManager::getInstance()
     39    static NetworkGameManager* getInstance()
    4040    { if (!NetworkGameManager::singletonRef) NetworkGameManager::singletonRef = new NetworkGameManager(); return NetworkGameManager::singletonRef; }
    4141
  • trunk/src/lib/network/network_log.cc

    r7954 r9869  
    1515
    1616#include "network_log.h"
     17#include <cassert>
    1718
    1819/**
     
    5354    return false;
    5455  }
    55  
     56
    5657  listensock = SDLNet_TCP_Open( &ip );
    57  
     58
    5859  if( !listensock ) {
    5960    PRINT(1)( "SDLNet_TCP_Open: %s\n", SDLNet_GetError() );
    6061    return false;
    61   } 
     62  }
    6263
    6364  return true;
     
    7172  va_list ap;
    7273  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
    7879  printfnet();
    7980}
     
    8586{
    8687  TCPsocket newSock = SDLNet_TCP_Accept( listensock );
    87  
     88
    8889  if ( newSock )
    8990    sockets.push_back( newSock );
     
    9798  va_list ap;
    9899  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
    104105  PRINT(0)( buf );
    105106  printfnet();
     
    114115  va_list ap;
    115116  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
    121122  PRINT(1)( buf );
    122123  printfnet();
     
    131132  va_list ap;
    132133  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
    138139  PRINT(2)( buf );
    139140  printfnet();
     
    148149  va_list ap;
    149150  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
    155156  PRINT(3)( buf );
    156157  printfnet();
     
    165166  va_list ap;
    166167  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
    172173  PRINT(4)( buf );
    173174  printfnet();
     
    182183  va_list ap;
    183184  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
    189190  PRINT(5)( buf );
    190191  printfnet();
     
    200201  if ( !listensock )
    201202    return;
    202  
     203
    203204  acceptNewConnections();
    204205
     
    213214      continue;
    214215    }
    215    
     216
    216217    it++;
    217218  }
  • trunk/src/lib/network/network_log.h

    r7954 r9869  
    3838class NetworkLog
    3939{
    40 
    4140  public:
    4241    virtual ~NetworkLog(void);
  • trunk/src/lib/network/network_manager.cc

    r9656 r9869  
    2020#define DEBUG_MODULE_NETWORK
    2121
    22 #include "class_list.h"
    2322#include "debug.h"
    2423#include "shell_command.h"
     
    2827#include "shared_network_data.h"
    2928#include "network_stream.h"
    30 #include "preferences.h"
     29#include "parser/preferences/preferences.h"
    3130#include "network_log.h"
    3231#include "network_game_manager.h"
     
    4140
    4241
    43 
     42ObjectListDefinition(NetworkManager);
    4443NetworkManager* NetworkManager::singletonRef = NULL;
    4544
     
    5049{
    5150  /* set the class id for the base object */
    52   this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
     51  this->registerObject(this, NetworkManager::_objectList);
    5352  PRINTF(0)("START\n");
    5453
  • trunk/src/lib/network/network_manager.h

    r9656 r9869  
    2525class NetworkManager : public BaseObject
    2626{
    27 
     27  ObjectListDeclaration(NetworkManager);
    2828  public:
    2929
  • trunk/src/lib/network/network_protocol.cc

    r9406 r9869  
    3535
    3636
    37 
     37ObjectListDefinition(NetworkProtocol);
    3838/**
    3939  standard constructor
     
    4242{
    4343  /* set the class id for the base object */
    44   this->setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol");
     44  this->registerObject(this, NetworkProtocol::_objectList);
    4545  this->headerLength = INTSIZE+FLOATSIZE;
    4646}
  • trunk/src/lib/network/network_protocol.h

    r6981 r9869  
    2525class NetworkProtocol : virtual public BaseObject
    2626{
     27  ObjectListDeclaration(NetworkProtocol);
    2728  public:
    2829    NetworkProtocol();
  • trunk/src/lib/network/network_socket.cc

    r9406 r9869  
    2424#include "network_socket.h"
    2525
    26 /* header for debug output */
    27 #include "debug.h"
    28 
     26ObjectListDefinition(NetworkSocket);
    2927/**
    3028 * Default constructor
  • trunk/src/lib/network/network_socket.h

    r9406 r9869  
    1717class NetworkSocket : public BaseObject
    1818{
     19  ObjectListDeclaration(NetworkSocket);
    1920  public:
    2021    NetworkSocket();
  • trunk/src/lib/network/network_stream.cc

    r9656 r9869  
    3333#include "shared_network_data.h"
    3434#include "message_manager.h"
    35 #include "preferences.h"
     35#include "parser/preferences/preferences.h"
    3636#include "zip.h"
    3737
    38 #include "src/lib/util/loading/resource_manager.h"
    39 
    4038#include "network_log.h"
    4139
    4240#include "player_stats.h"
    4341
    44 #include "lib/util/loading/factory.h"
     42#include "loading/factory.h"
     43#include "loading/resource_manager.h"
    4544
    4645#include "debug.h"
    47 #include "class_list.h"
    48 #include <algorithm>
    49 
    5046
    5147#include "network_stream.h"
     
    5753#define PACKAGE_SIZE  256
    5854
    59 
     55ObjectListDefinition(NetworkStream);
    6056/**
    6157 * empty constructor
     
    118114{
    119115  /* set the class id for the base object */
    120   this->setClassID(CL_NETWORK_STREAM, "NetworkStream");
     116  this->registerObject(this, NetworkStream::_objectList);
    121117  this->clientSocket = NULL;
    122118  this->clientSoftSocket = NULL;
     
    970966
    971967      // 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())
    973969        continue;
    974970
     
    976972      if ( ( SharedNetworkData::getInstance()->isMasterServer() ||
    977973             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 )
    979975        continue;
    980976
    981977      /* list of synchronizeables that will never be synchronized over the network: */
    982978      // do not sync null parent
    983       if ( sync.getLeafClassID() == CL_NULL_PARENT )
     979      if ( NullParent::staticClassID() == sync.getLeafClassID())
    984980        continue;
    985981
     
    11901186          /* These are some small exeptions in creation: Not all objects can/should be created via Factory */
    11911187          /* 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)
    11931189          {
    11941190            PRINTF(1)("Don't create Object with ID %x, ignored!\n", (int)leafClassId);
     
    11971193          }
    11981194          else
    1199             b = Factory::fabricate( (ClassID)leafClassId );
     1195            ; /// FIXME CLASS_ID :: b = Factory::fabricate( leafClassId );
    12001196
    12011197          if ( !b )
     
    12061202          }
    12071203
    1208           if ( b->isA(CL_SYNCHRONIZEABLE) )
     1204          if ( b->isA(Synchronizeable::staticClassID()) )
    12091205          {
    12101206            sync = dynamic_cast<Synchronizeable*>(b);
     
    13031299    length = remainingBytesToWriteToDict;
    13041300
    1305   std::string fileName = ResourceManager::getInstance()->getDataDir();
     1301  std::string fileName = Resources::ResourceManager::getInstance()->mainGlobalPath().name();
    13061302  fileName += "/dicts/newdict";
    13071303
  • trunk/src/lib/network/network_stream.h

    r9656 r9869  
    3333class NetworkStream : public DataStream
    3434{
    35 
     35  ObjectListDeclaration(NetworkStream);
    3636  public:
    3737    NetworkStream();
  • trunk/src/lib/network/player_stats.cc

    r9656 r9869  
    1616#include "player_stats.h"
    1717
    18 #include "class_list.h"
    1918#include "src/lib/util/loading/factory.h"
    2019
    2120#include "player.h"
     21#include "playable.h"
    2222#include "state.h"
    2323#include "shared_network_data.h"
     
    2525#include "converter.h"
    2626
    27 #include "preferences.h"
     27#include "parser/preferences/preferences.h"
    2828
    2929#include "debug.h"
    3030#include "shell_command.h"
    3131
    32 
    33 CREATE_FACTORY(PlayerStats, CL_PLAYER_STATS);
    34 
     32#include "class_id_DEPRECATED.h"
     33
     34ObjectListDefinitionID(PlayerStats, CL_PLAYER_STATS);
     35CREATE_FACTORY(PlayerStats);
    3536
    3637/**
     
    5455void PlayerStats::init( )
    5556{
    56   this->setClassID( CL_PLAYER_STATS, "PlayerStats" );
     57  this->registerObject(this, PlayerStats::_objectList);
    5758
    5859  this->assignedUserId = 0;
     
    122123PlayerStats * PlayerStats::getStats( int userId )
    123124{
    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 )
    139130    {
    140       return dynamic_cast<PlayerStats*>(*it);
     131      return (*it);
    141132    }
    142133  }
     
    150141void PlayerStats::setPlayableUniqueId( int uniqueId )
    151142{
    152   const std::list<BaseObject*> * list = ClassList::getList( CL_PLAYABLE );
    153 
    154   if ( !list )
    155   {
    156     this->playableUniqueId = uniqueId;
    157     return;
    158   }
    159 
    160143  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 )
    168149    {
    169       this->playable = dynamic_cast<Playable*>(*it);
     150      this->playable = (*it);
    170151      //TODO when OM_PLAYERS is ticked add line:
    171152      //this->playable->toList( OM_PLAYERS );
     
    174155  }
    175156
    176   if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance()
    177        ->getHostID() )
     157  if ( this->playable && this->assignedUserId == SharedNetworkData::getInstance()->getHostID() )
    178158  {
    179159    State::getPlayer()->setPlayable( this->playable );
     
    272252void PlayerStats::deleteAllPlayerStats( )
    273253{
    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();
    278257}
    279258
     
    287266  ScoreList result;
    288267
    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);
    302273
    303274    TeamScoreList::iterator it = result[stats.getTeamId()].begin();
  • trunk/src/lib/network/player_stats.h

    r9656 r9869  
    3636class PlayerStats : public Synchronizeable
    3737{
    38 
     38  ObjectListDeclaration(PlayerStats);
    3939  public:
    4040    PlayerStats( const TiXmlElement* root = NULL );
     
    5858
    5959    inline int getPlayableClassId(){ return playableClassId; }
    60     void setPlayableClassId( int classId ){ this->playableClassId = classId; };
     60    void setPlayableClassId( const ClassID& classId ){ this->playableClassId = classId.id(); };
    6161
    6262    inline int getPlayableUniqueId(){ return playableUniqueId; }
  • trunk/src/lib/network/proxy/network_settings.cc

    r9656 r9869  
    2121#include "shared_network_data.h"
    2222
     23#include "loading/load_param.h"
    2324#include "loading/resource_manager.h"
    24 #include "loading/load_param.h"
    25 
    2625#include "debug.h"
    2726
    2827
     28ObjectListDefinition(NetworkSettings);
    2929
    3030NetworkSettings* NetworkSettings::singletonRef = NULL;
     
    3636{
    3737  /* set the class id for the base object */
    38   this->setClassID(CL_NETWORK_SETTINGS, "NetworkSettings");
     38  this->registerObject(this, NetworkSettings::_objectList);
    3939
    4040  // suggest a good standard max players value
     
    6464void NetworkSettings::loadData()
    6565{
    66   std::string fileName = ResourceManager::getInstance()->getDataDir();
     66  std::string fileName = Resources::ResourceManager::getInstance()->mainGlobalPath().name();
    6767  fileName += "configs/network_settings.conf";
    6868
  • trunk/src/lib/network/proxy/network_settings.h

    r9494 r9869  
    2424class NetworkSettings : public BaseObject
    2525{
    26 
     26  ObjectListDeclaration(NetworkSettings);
    2727  public:
    2828    inline static NetworkSettings* getInstance() { if (!NetworkSettings::singletonRef) NetworkSettings::singletonRef = new NetworkSettings();
  • trunk/src/lib/network/proxy/proxy_control.cc

    r9656 r9869  
    1515#include "proxy_control.h"
    1616
    17 #include "class_list.h"
    1817#include "shell_command.h"
    1918
     
    2827#include "converter.h"
    2928
    30 #include "preferences.h"
     29#include "parser/preferences/preferences.h"
    3130
    3231#include "debug.h"
     
    4140
    4241SHELL_COMMAND(forceReconnect, ProxyControl, forceReconnectionShell);
     42ObjectListDefinition(ProxyControl);
    4343
    4444/**
     
    4747ProxyControl::ProxyControl()
    4848{
    49   this->setClassID( CL_PROXY_CONTROL, "ProxyControl" );
     49  this->registerObject(this, ProxyControl::_objectList);
    5050
    5151  this->setSynchronized(false);
  • trunk/src/lib/network/proxy/proxy_control.h

    r9656 r9869  
    3030class ProxyControl : public Synchronizeable
    3131{
    32 
     32  ObjectListDeclaration(ProxyControl);
    3333  public:
    3434    inline static ProxyControl* getInstance() { if (!ProxyControl::singletonRef) ProxyControl::singletonRef = new ProxyControl();
  • trunk/src/lib/network/server_socket.cc

    r7954 r9869  
    2323#include "server_socket.h"
    2424
    25 /* header for debug output */
    26 #include "debug.h"
    27 
    28 
     25ObjectListDefinition(ServerSocket);
    2926/**
    3027 * constructor
  • trunk/src/lib/network/server_socket.h

    r9656 r9869  
    1919class ServerSocket : public BaseObject
    2020{
     21  ObjectListDeclaration(ServerSocket);
    2122  public:
    2223    ServerSocket( int port);
  • trunk/src/lib/network/shared_network_data.cc

    r9494 r9869  
    2525
    2626
    27 
     27ObjectListDefinition(SharedNetworkData);
    2828SharedNetworkData* SharedNetworkData::singletonRef = NULL;
    2929
     
    3434{
    3535  /* set the class id for the base object */
    36   this->setClassID(CL_SHARED_NETWORK_DATA, "SharedNetworkData");
     36  this->registerObject(this, SharedNetworkData::_objectList);
    3737
    3838  this->nodeType = NET_MASTER_SERVER;
  • trunk/src/lib/network/shared_network_data.h

    r9656 r9869  
    2222class SharedNetworkData : public BaseObject
    2323{
    24 
     24  ObjectListDeclaration(SharedNetworkData);
    2525  public:
    2626    inline static SharedNetworkData* getInstance() { if (!SharedNetworkData::singletonRef) SharedNetworkData::singletonRef = new SharedNetworkData();
  • trunk/src/lib/network/synchronizeable.cc

    r9656 r9869  
    3232
    3333
     34ObjectListDefinition(Synchronizeable);
    3435
    3536/**
     
    3839Synchronizeable::Synchronizeable()
    3940{
    40   this->setClassID(CL_SYNCHRONIZEABLE, "Synchronizeable");
     41  this->registerObject(this, Synchronizeable::_objectList);
    4142  this->owner = 0;
    4243//   this->setIsServer(SharedNetworkData::getInstance()->getHostID() == 0);
     
    7475    // remove the message manager only by the server
    7576    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() ) )
    7778      NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() );
    7879  }
  • trunk/src/lib/network/synchronizeable.h

    r9406 r9869  
    4141class Synchronizeable : virtual public BaseObject
    4242{
     43  ObjectListDeclaration(Synchronizeable);
    4344
    4445  public:
  • trunk/src/lib/network/tcp_server_socket.cc

    r9494 r9869  
    2626#include "debug.h"
    2727
     28ObjectListDefinition(TcpServerSocket);
    2829TcpServerSocket::TcpServerSocket( int port ) : ServerSocket( port )
    2930{
     
    4849{
    4950  /* set the class id for the base object */
    50   this->setClassID(CL_SERVER_SOCKET, "TcpServerSocket");
     51  this->registerObject(this, TcpServerSocket::_objectList);
    5152
    5253  terminateThread = false;
  • trunk/src/lib/network/tcp_server_socket.h

    r9406 r9869  
    1919class TcpServerSocket : public ServerSocket
    2020{
     21  ObjectListDeclaration(TcpServerSocket);
    2122  public:
    2223    TcpServerSocket( int port );
  • trunk/src/lib/network/tcp_socket.cc

    r7954 r9869  
    3030#include "debug.h"
    3131
     32ObjectListDefinition(TcpSocket);
    3233/**
    3334 * Default constructor
     
    6061{
    6162  /* set the class id for the base object */
    62   this->setClassID(CL_NETWORK_SOCKET, "TcpSocket");
     63  this->registerObject(this, TcpSocket::_objectList);
    6364
    6465  tcpSocket = NULL;
     
    122123{
    123124  IPaddress ip;
    124  
    125   bOk = true; 
    126  
     125
     126  bOk = true;
     127
    127128  if ( SDLNet_ResolveHost( &ip, host.c_str(), port ) != 0 )
    128129  {
     
    131132    return;
    132133  }
    133  
     134
    134135  //check if not already connected or listening
    135136  if (tcpSocket)
     
    345346}
    346347#endif
    347  
     348
    348349  PRINTF(0)("QUIT READ THREAD\n");
    349  
     350
    350351  return 0;
    351352}
     
    425426
    426427  return 0;
    427  
     428
    428429}
    429430
  • trunk/src/lib/network/tcp_socket.h

    r9406 r9869  
    4040class TcpSocket : public NetworkSocket
    4141{
     42  ObjectListDeclaration(TcpSocket);
    4243  public:
    4344    TcpSocket();
  • trunk/src/lib/network/udp_broadcast.cc

    r8623 r9869  
    2626  this->port = 0;
    2727  packet = SDLNet_AllocPacket( BROADCAST_PACKET_SIZE );
    28  
    29   if ( !packet ) 
     28
     29  if ( !packet )
    3030  {
    3131    printf( "SDLNet_AllocPacket: %s\n", SDLNet_GetError() );
    3232    assert( packet );
    3333  }
    34  
     34
    3535  this->socket = NULL;
    3636}
     
    4747    this->packet = NULL;
    4848  }
    49  
     49
    5050  if ( this->socket )
    5151  {
     
    5353    this->socket = NULL;
    5454  }
    55  
     55
    5656}
    5757
    5858/**
    5959 * listen for incoming broadcast packets
    60  * @param port port to listen on 
     60 * @param port port to listen on
    6161 * @return true on success
    6262 */
     
    7474{
    7575  this->port = port;
    76  
     76
    7777  return true;
    7878}
     
    8080/**
    8181 * send packet
    82  * @param data data to send 
     82 * @param data data to send
    8383 * @param length length of data
    8484 * @param ip if ip == NULL broadcast is used
  • trunk/src/lib/network/udp_broadcast.h

    r8623 r9869  
    1515class UdpBroadcast
    1616{
    17 
    1817  public:
    1918    UdpBroadcast();
    2019    virtual ~UdpBroadcast();
    21    
     20
    2221    bool listen( int port );
    2322    bool open( int port );
  • trunk/src/lib/network/udp_server_socket.cc

    r9494 r9869  
    1818
    1919
    20 
     20ObjectListDefinition(UdpServerSocket);
    2121/**
    2222 * constructor
  • trunk/src/lib/network/udp_server_socket.h

    r9494 r9869  
    5050class UdpServerSocket : public ServerSocket
    5151{
     52  ObjectListDeclaration(UdpServerSocket);
    5253  public:
    5354    UdpServerSocket( int port);
  • trunk/src/lib/network/udp_socket.cc

    r9406 r9869  
    1818#include "debug.h"
    1919
     20ObjectListDefinition(UdpSocket);
    2021
    2122void UdpSocket::init( )
  • trunk/src/lib/network/udp_socket.h

    r9656 r9869  
    2424class UdpSocket : public NetworkSocket
    2525{
     26  ObjectListDeclaration(UdpSocket);
    2627  public:
    2728    UdpSocket();
  • trunk/src/lib/network/zip.cc

    r8623 r9869  
    1515
    1616#include "zip.h"
    17 
    18 #include "src/lib/util/loading/resource_manager.h"
     17#include "loading/resource_manager.h"
    1918#include "debug.h"
    2019
     
    5150int Zip::loadDictionary( std::string name )
    5251{
    53   std::string fileName = ResourceManager::getInstance()->getDataDir();
     52  std::string fileName = Resources::ResourceManager::getInstance()->mainGlobalPath().name();
    5453  //PRINTF(0)("datadir: %s\n", fileName.c_str());
    5554  fileName = fileName + "/dicts/" + name;
  • trunk/src/lib/parser/Makefile.am

    r7256 r9869  
    22          tinyxml \
    33          ini_parser \
    4           preferences \
    5           cmdline_parser
     4          cmdline_parser \
     5          preferences
    66
    77
  • trunk/src/lib/parser/cmdline_parser/Makefile.am

    r7256 r9869  
     1
     2INCLUDES = -I../../..
    13
    24noinst_LIBRARIES = libCmdLineParser.a
  • trunk/src/lib/parser/cmdline_parser/cmdline_parser.cc

    r9406 r9869  
    1616#include "cmdline_parser.h"
    1717
     18#include <cassert>
    1819#include "src/lib/util/substring.h"
    1920
  • trunk/src/lib/parser/cmdline_parser/cmdline_parser.h

    r8316 r9869  
    1111#include <vector>
    1212
    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"
    1515
    1616
  • trunk/src/lib/parser/ini_parser/Makefile.am

    r8330 r9869  
    1 INCLUDES=-I../../util
     1INCLUDES = -I../../..
    22
    33
  • trunk/src/lib/parser/ini_parser/ini_parser.cc

    r9406 r9869  
    2929
    3030#ifdef DEBUG_LEVEL
    31  #include "../../../defs/debug.h"
     31 #include "../../../lib/util/debug.h"
    3232#else
    3333 #define PRINTF(x) printf
     
    165165      else if( (ptr = strchr( lineBegin, '=')) != NULL)
    166166      {
    167         if (currentSection == NULL)
     167        if (currentSection == this->sections.end())
    168168        {
    169169          PRINTF(2)("Not in a Section yet for %s\n", lineBegin);
     
    470470  {
    471471    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)
    473473      return (*entry).value;
    474474    PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName.c_str(), sectionName.c_str());
     
    627627      if ((*entry).name == entryName)
    628628        break;
    629   if (entry == (*section).entries.end())
    630     return NULL;
    631   else
    632     return entry;
     629  return entry;
    633630}
    634631
     
    650647      if ((*entry).name == entryName)
    651648        break;
    652   if (entry == (*section).entries.end())
    653     return NULL;
    654   else
    655     return entry;
     649  return entry;
    656650}
    657651
  • trunk/src/lib/parser/ini_parser/ini_parser.h

    r8330 r9869  
    1111#define PARSELINELENGHT     512       //!< how many chars to read at once
    1212
    13 #include "filesys/file.h"
     13#include "lib/util/filesys/file.h"
    1414#include <list>
    1515
     
    6666    bool addVar(const std::string& entryName, const std::string& value, const std::string& sectionName = "" );
    6767    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);
    6969    void setEntryComment(const std::string& comment, const std::string& entryName, const std::string& sectionName);
    7070    const std::string& getEntryComment(const std::string& entryName, const std::string& sectionName) const;
  • trunk/src/lib/parser/preferences/Makefile.am

    r7256 r9869  
    66libPrefsParser_a_SOURCES = \
    77                cmd_line_prefs_reader.cc \
    8                 ini_file_prefs_reader.cc
     8                ini_file_prefs_reader.cc \
     9                preferences.cc
    910
    1011
    1112noinst_HEADERS = \
    1213                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  
    77#define _CMD_LINE_PREFS_READER_H
    88
    9 #include "stdincl.h"
    109#include "debug.h"
    1110
     
    4544};
    4645
    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)
    4847
    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)
    5049
    5150//! A class for reading commandline arguments into Preferences
    52 class CmdLinePrefsReader 
     51class CmdLinePrefsReader
    5352{
    5453
     
    5857
    5958    bool parse(int argc, char** argv);
    60    
     59
    6160    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
    6362    static bool asdf;
    64    
     63
    6564  private:
    6665    static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<MultiType> & argArgs );
    67    
     66
    6867    static RegistredArgs regArgs;
    6968
  • trunk/src/lib/parser/preferences/ini_file_prefs_reader.h

    r7256 r9869  
    77#define _INI_FILE_PREFS_READER_H
    88
    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"
    1111
    1212
  • trunk/src/lib/physics/fields/field.cc

    r9406 r9869  
    2323#include "util/loading/load_param.h"
    2424
     25ObjectListDefinition(Field);
    2526
    2627/**
    27  * standard constructor
     28 * @brief standard constructor
    2829*/
    2930Field::Field ()
     
    3334
    3435/**
    35  *  standard deconstructor
    36 
    37 */
     36 * @brief standard deconstructor
     37 */
    3838Field::~Field ()
    3939{
     
    4242
    4343/**
    44   \brief initializes a Field
    45 */
     44  * @brief initializes a Field
     45 */
    4646void Field::init()
    4747{
    48   this->setClassID(CL_FIELD, "Field");
     48  this->registerObject(this, Field::_objectList);
    4949  this->setMagnitude(1);
    5050  this->setAttenuation(0);
     
    5454
    5555/**
    56 * @param root The XML-element to load settings from
     56 * @param root The XML-element to load settings from
    5757 */
    5858void Field::loadParams(const TiXmlElement* root)
  • trunk/src/lib/physics/fields/field.h

    r6512 r9869  
    1616/*!
    1717 * @file field.h
    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 */
     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 */
    2323
    2424#ifndef _FIELD_H
     
    3434class Field : public PNode
    3535{
     36  ObjectListDeclaration(Field);
    3637 public:
    3738  Field();
  • trunk/src/lib/physics/fields/gravity.cc

    r9406 r9869  
    2121#include "util/loading/factory.h"
    2222
     23#include "class_id_DEPRECATED.h"
     24ObjectListDefinitionID(Gravity, CL_FIELD_GRAVITY);
    2325
    24 
    25 CREATE_FACTORY(Gravity, CL_FIELD_GRAVITY);
     26CREATE_FACTORY(Gravity);
    2627
    2728Gravity::Gravity(const TiXmlElement* root)
    2829{
    29   this->setClassID(CL_FIELD_GRAVITY, "Gravity");
     30  this->registerObject(this, Gravity::_objectList);
    3031
    3132  if (root != NULL)
  • trunk/src/lib/physics/fields/gravity.h

    r6512 r9869  
    1616//! A class for ...
    1717class Gravity : public Field {
     18  ObjectListDeclaration(Gravity);
    1819
    1920 public:
  • trunk/src/lib/physics/fields/point_gravity.cc

    r9406 r9869  
    2020
    2121
     22#include "class_id_DEPRECATED.h"
     23ObjectListDefinitionID(PointGravity, CL_FIELD_POINT_GRAVITY);
     24
    2225
    2326/**
     
    2730PointGravity::PointGravity ()
    2831{
    29    this->setClassID(CL_FIELD_POINT_GRAVITY, "PointGravity");
     32  this->registerObject(this, PointGravity::_objectList);
    3033}
    3134
  • trunk/src/lib/physics/fields/point_gravity.h

    r5405 r9869  
    1 /*! 
     1/*!
    22 * @file point_gravity.h
    33  *  Definition of ...
     
    1616//! A class for ...
    1717class PointGravity : public Field {
     18  ObjectListDeclaration(PointGravity);
    1819
    1920 public:
  • trunk/src/lib/physics/fields/twirl.cc

    r9406 r9869  
    2020
    2121
     22#include "class_id_DEPRECATED.h"
     23ObjectListDefinitionID(Twirl, CL_FIELD_TWIRL);
     24
    2225
    2326/**
     
    2730Twirl::Twirl ()
    2831{
    29    this->setClassID(CL_FIELD_TWIRL, "Twirl");
     32  this->registerObject(this, Twirl::_objectList);
    3033}
    3134
  • trunk/src/lib/physics/fields/twirl.h

    r5405 r9869  
    1 /*! 
     1/*!
    22 * @file twirl.h
    33  *  Definition of ...
     
    1616//! A class for ...
    1717class Twirl : public Field {
     18  ObjectListDeclaration(Twirl);
    1819
    1920 public:
  • trunk/src/lib/physics/physics_connection.cc

    r9406 r9869  
    1919
    2020#include "physics_engine.h"
     21#include "debug.h"
    2122
    22 #include "field.h"
    23 #include "particle_system.h"
     23#include "fields/field.h"
     24#include "particles/particle_system.h"
    2425#include "physics_interface.h"
    2526
     
    2728#include "util/loading/load_param.h"
    2829
    29 
    30 
    31 CREATE_FACTORY(PhysicsConnection, CL_PHYSICS_CONNECTION);
    32 
     30#include "class_id_DEPRECATED.h"
     31ObjectListDefinition(PhysicsConnection);
     32CREATE_FACTORY(PhysicsConnection);
    3333/**
    3434 *  creates a PhysicsConnection
     
    3636PhysicsConnection::PhysicsConnection(PhysicsInterface* subject, Field* field)
    3737{
    38   this->setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");
     38  this->registerObject(this, PhysicsConnection::_objectList);
    3939  this->type = PCON_PhysIField;
    4040
     
    4747PhysicsConnection::PhysicsConnection(const TiXmlElement* root)
    4848{
    49   this->setClassID(CL_PHYSICS_CONNECTION, "PhysicsConnection");
     49  this->registerObject(this, PhysicsConnection::_objectList);
    5050  this->type = PCON_PhysIField;
    5151
  • trunk/src/lib/physics/physics_connection.h

    r7221 r9869  
    2727class PhysicsConnection : public BaseObject
    2828{
    29 
     29  ObjectListDeclaration(PhysicsConnection);
    3030 public:
    3131  PhysicsConnection(PhysicsInterface* subject, Field* field);
  • trunk/src/lib/physics/physics_engine.cc

    r9406 r9869  
    1818#include "physics_engine.h"
    1919
    20 #include "class_list.h"
    21 #include "parser/tinyxml/tinyxml.h"
    2220#include "util/loading/factory.h"
    23 #include "util/loading/load_param.h"
    24 
    25 
    26 
    27 
    28 /**
    29  * standard constructor
    30 */
     21#include "util/loading/load_param_xml.h"
     22
     23
     24
     25ObjectListDefinition(PhysicsEngine);
     26/**
     27 * @brief standard constructor
     28 */
    3129PhysicsEngine::PhysicsEngine()
    3230{
    33   this->setClassID(CL_PHYSICS_ENGINE, "PhysicsEngine");
     31  this->registerObject(this, PhysicsEngine::_objectList);
    3432  this->setName("PhysicsEngine");
    3533  this->interfaces = NULL;
     
    130128PhysicsInterface* PhysicsEngine::getPhysicsInterfaceByName(const std::string& physicsInterfaceName) const
    131129{
    132   BaseObject* interface = ClassList::getObject(physicsInterfaceName, CL_PHYSICS_INTERFACE);
    133   return (interface != NULL)?  dynamic_cast<PhysicsInterface*>(interface) : NULL;
     130  return PhysicsInterface::objectList().getObject(physicsInterfaceName);
    134131}
    135132
     
    223220
    224221  /* 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);
    231228}
    232229
  • trunk/src/lib/physics/physics_engine.h

    r7221 r9869  
    1212#include "physics_connection.h"
    1313#include "physics_interface.h"
    14 #include "field.h"
     14#include "fields/field.h"
    1515#include <list>
    1616
     
    2020
    2121//! A class, that brings things into motion through Physics.
    22 class PhysicsEngine : public BaseObject {
    23 
    24  public:
     22class PhysicsEngine : public BaseObject
     23{
     24  ObjectListDeclaration(PhysicsEngine);
     25public:
    2526  virtual ~PhysicsEngine();
    2627  /** @returns a Pointer to the only object of this Class */
     
    4647  void                   debug() const;
    4748
    48  private:
     49private:
    4950  PhysicsEngine();
    5051
    51  private:
     52private:
    5253  static PhysicsEngine*         singletonRef;         //!< the singleton reference of the PhysicsEngine
    5354
  • trunk/src/lib/physics/physics_interface.cc

    r9406 r9869  
    2323#include "physics_engine.h"
    2424
    25 #include "field.h"
     25#include "fields/field.h"
    2626#include "p_node.h"
    2727
     
    3131
    3232
    33 
     33ObjectListDefinition(PhysicsInterface);
    3434/**
    35  * standard constructor
     35 * @brief standard constructor
    3636 */
    3737PhysicsInterface::PhysicsInterface ()
    3838{
    39   this->setClassID(CL_PHYSICS_INTERFACE, "PhysicsInterface");
     39  this->registerObject(this, PhysicsInterface::_objectList);
    4040
    4141  this->mass = 1;
  • trunk/src/lib/physics/physics_interface.h

    r8190 r9869  
    2929class PhysicsInterface : virtual public BaseObject
    3030{
     31  ObjectListDeclaration(PhysicsInterface);
    3132 public:
    3233  PhysicsInterface();
  • trunk/src/lib/script_engine/Makefile.am

    r8711 r9869  
    1616                script_manager.cc \
    1717                script_class.cc \
    18                 script_method.cc
    19                
     18                script_method.cc \
     19                executor_lua_state.cc
     20
    2021AM_CPPFLAGS= @LUA_INCLUDES@
    2122
     
    2526                script_manager.h \
    2627                script_class.h \
    27                 script_method.h
     28                script_method.h \
     29                executor_lua_state.h
    2830
    2931
  • trunk/src/lib/script_engine/lunar.h

    r8408 r9869  
    1616  userdataType;
    1717public:
    18   typedef Executor* mfp;
     18  typedef Executor<lua_State*>* mfp;
    1919  typedef struct { const char *name; mfp mfunc; }
    2020  RegType;
     
    184184    lua_remove(L, 1);  // remove self so member function args start at index 1
    185185    // 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;
    190189  }
    191190
  • trunk/src/lib/script_engine/script.cc

    r9298 r9869  
    1818#include "luaincl.h"
    1919#include "debug.h"
    20 #include "util/loading/resource_manager.h"
    21 
     20
     21#include "loading/resource_manager.h"
    2222#include "loading/load_param.h"
    2323#include "parser/tinyxml/tinyxml.h"
    2424
    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))
     25ObjectListDefinition(Script);
     26
     27CREATE_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))
    3132                     );
     33
    3234
    3335Script::Script(const TiXmlElement* root)
    3436{
    35   this->setClassID(CL_SCRIPT, "Script");
     37  this->registerObject(this, Script::_objectList);
    3638
    3739  returnCount = argumentCount = 0;
     
    5254Script::Script(const std::string& filename)
    5355{
    54   this->setClassID(CL_SCRIPT, "Script");
     56  this->registerObject(this, Script::_objectList);
    5557
    5658  returnCount = argumentCount = 0;
     
    6466  luaopen_math(luaState);
    6567  luaopen_debug(luaState);
    66  
     68
    6769  this->loadFile(filename);
    6870
     
    98100bool Script::loadFile(const std::string& filename)
    99101 {
    100    std::string filedest(ResourceManager::getInstance()->getDataDir());
    101    filedest += "scripts/" + filename;
    102    
     102   std::string filedest(Resources::ResourceManager::getInstance()->mainGlobalPath().name());
     103   filedest += "/scripts/" + filename;
     104
    103105   this->addThisScript();
    104106   this->registerStandartClasses();
    105    
     107
    106108   if(currentFile.length() != 0)
    107109   {
     
    142144   //printf(("Script %s: I am about to add %s of class %s\n",this->getName(),objectName.c_str(),className.c_str());
    143145
    144    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     146   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
    145147  // printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
    146148   WorldObject tmpObj;
     
    150152     if( !classIsRegistered(className) )
    151153     {
    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);
    156158    // printf(("%s is at %p \n",objectName.c_str(),object);
    157159     if (object != NULL && !objectIsAdded(objectName))
    158160     {
    159         static_cast<ScriptClass*>(scriptClass)->insertObject(this, object, false);
     161        scriptClass->insertObject(this, object, false);
    160162        tmpObj.name = objectName;
    161163        registeredObjects.push_back(tmpObj);
     
    169171 bool Script::executeFile()
    170172 {
    171    PRINT(2)("WARNING: script.executeFile is not implemented yet\n");
     173   PRINTF(2)("script.executeFile is not implemented yet\n");
    172174   /*if(currentFile.length() != 0)
    173175   {
     
    214216    if(error != 0)
    215217    {
    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());
    217219     reportError(error);
    218220     //clean up
     
    229231   }
    230232   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());
    232234
    233235   return false;
     
    295297       lua_remove(luaState,-1*returnCount);
    296298       returnCount--;
    297        
     299
    298300     }
    299301   }
     
    352354void Script::addThisScript()
    353355{
    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);
    359362   }
    360363}
     
    375378 {
    376379   bool success = false;
    377    
     380
    378381   //this->registerClass(std::string("Vector"));
    379382    this->registerClass("ScriptTrigger");
     
    382385   return success;
    383386 }
    384  
    385  
     387
     388
    386389 void Script::registerClass( const std::string& className)
    387390 {
    388    BaseObject* scriptClass = ClassList::getObject(className, CL_SCRIPT_CLASS);
     391   ScriptClass* scriptClass = ScriptClass::objectList().getObject(className);
    389392   //printf(("The script class for %s is at %p \n",className.c_str(),scriptClass);
     393
    390394   WorldObject tmpObj;
    391395   if (scriptClass != NULL)
     
    400404     }
    401405   }
    402  
     406
    403407 }
    404408
  • trunk/src/lib/script_engine/script.h

    r9298 r9869  
    2222class Script : public BaseObject
    2323{
     24  ObjectListDeclaration(Script);
    2425  public:
    2526    Script(const TiXmlElement* root = NULL);
     
    3334    bool loadFile(const std::string& filename);
    3435    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
    3637
    3738    /// QUERRYING
  • trunk/src/lib/script_engine/script_class.cc

    r8711 r9869  
    1919#include <cassert>
    2020
     21ObjectListDefinition(ScriptClass);
    2122/**
    2223 * @brief standard constructor
    2324 * @todo this constructor is not jet implemented - do it
    2425*/
    25 ScriptClass::ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods)
    26     : BaseObject(name)
     26ScriptClass::ScriptClass(const std::string& name, const ClassID& classID, ScriptMethod* scriptMethods)
     27    : BaseObject(name), _classID(classID)
    2728{
    2829  assert(scriptMethods != NULL);
    29   this->setClassID(CL_SCRIPT_CLASS, "ScriptClass");
     30  this->registerObject(this, ScriptClass::_objectList);
    3031
    3132  this->_classID = classID;
  • trunk/src/lib/script_engine/script_class.h

    r9003 r9869  
    1818 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    1919 */
    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)
    2222
    2323
    2424//! A class for ...
    25 class ScriptClass : protected BaseObject
     25class ScriptClass : public BaseObject
    2626{
     27  ObjectListDeclaration(ScriptClass);
    2728
    2829public:
    2930  virtual ~ScriptClass();
    3031
    31   bool operator==(const std::string& name) { return (this->getName() == name); }
    32   bool operator==(ClassID classID) { return (this->_classID == classID); }
    33 
    3432  virtual void registerClass(Script* script) = 0;
    3533  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;
    3735
    3836  const ScriptMethod* scriptMethods() const { return this->_scriptMethods; }
    3937
    4038protected:
    41   ScriptClass(const std::string& name, ClassID classID, ScriptMethod* scriptMethods);
     39  ScriptClass(const std::string& name, const ClassID& classID, ScriptMethod* scriptMethods);
    4240
    4341private:
  • trunk/src/lib/script_engine/script_manager.cc

    r9003 r9869  
    2424#include "lunar.h"
    2525
    26 #include "class_list.h"
    27 
    2826#include "script.h"
    2927#include "script_trigger.h"
    3028#include "luaincl.h"
    31 #include "loading/load_param.h"
    32 #include "parser/tinyxml/tinyxml.h"
     29#include "loading/load_param_xml.h"
    3330
    3431
     
    3734{
    3835  this->setName("ScriptManager");
    39   this->scripts = NULL;
    40   this->triggers = NULL;
    4136
    4237  if (root != NULL)
     
    6257
    6358  // fill the scripts and triggers (doing that on runtime is very slow!)
    64   getTriggers();
    65   getScripts();
    6659}
    6760
     
    7164{
    7265  //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();
    7668  //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
    8172}
    8273
     
    10596Script* ScriptManager::getScriptByFile(const std::string& file)
    10697{
    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);
    115103
    116104  return NULL;
    117105
    118106}
    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  
    3434   void  createTriggers(const TiXmlElement* triggers);
    3535
    36    bool getTriggers();
    37    bool getScripts();
    38 
    3936   static ScriptManager*             singletonRef;   //!< Reference to this class
    40 
    41    const std::list<BaseObject*>*     triggers;       //!< A list of all the triggers in the world
    42 
    43    const std::list<BaseObject*>*     scripts;        //!< A list of all the scripts in the world
    44 
    45 
    4637};
    4738#endif
  • trunk/src/lib/script_engine/script_method.cc

    r8711 r9869  
    2525{ }
    2626
    27 ScriptMethod* ScriptMethod::addMethod(const std::string& methodName, const Executor& executor)
     27ScriptMethod* ScriptMethod::addMethod(const std::string& methodName, const Executor<lua_State*>& executor)
    2828{
    2929  this->methods.push_back(ScriptMethod::Method(methodName, executor));
     
    3232}
    3333
    34 ScriptMethod::Method::Method(const std::string& name, const Executor& executor)
     34ScriptMethod::Method::Method(const std::string& name, const Executor<lua_State*>& executor)
    3535{
    3636  this->name = name;
  • trunk/src/lib/script_engine/script_method.h

    r8711 r9869  
    99#include <vector>
    1010
    11 #include "executor/executor_lua.h"
    12 
     11#include "executor_lua_state.h"
     12#include "executor/executor_member.h"
    1313
    1414class ScriptMethod
     
    1818  ~ScriptMethod();
    1919
    20   ScriptMethod* addMethod(const std::string& methodName, const Executor& executor);
     20  ScriptMethod* addMethod(const std::string& methodName, const Executor<lua_State*>& executor);
    2121
    2222  unsigned int size() const { return methods.size(); };
    2323
    2424  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; };
    2626
    2727
     
    2929  struct Method
    3030  {
    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;
    3434  };
    3535
  • trunk/src/lib/shell/Makefile.am

    r7428 r9869  
    66libORXshell_a_SOURCES = \
    77                shell.cc \
    8                 shell_buffer.cc \
    98                shell_input.cc \
    109                shell_command.cc \
     
    1615noinst_HEADERS= \
    1716                shell.h \
    18                 shell_buffer.h \
    1917                shell_input.h \
     18                shell_command_class.h \
    2019                shell_command.h \
    21                 shell_command_class.h \
    2220                shell_completion.h \
    2321                shell_completion_plugin.h
  • trunk/src/lib/shell/shell.cc

    r8362 r9869  
    1818#include "shell.h"
    1919#include "shell_command.h"
    20 #include "shell_buffer.h"
     20#include "debug_buffer.h"
    2121#include "shell_input.h"
    2222
     
    5454  ->completionPlugin(0, OrxShell::CompletorFileSystem(".ttf", "fonts/"));
    5555
     56  ObjectListDefinition(Shell);
    5657
    5758  /**
     
    6061  Shell::Shell ()
    6162  {
    62     this->setClassID(CL_SHELL, "Shell");
     63    this->registerObject(this, Shell::_objectList);
     64
    6365    this->setName("Shell");
    6466
    65     this->shellBuffer = ShellBuffer::getInstance();
     67    this->shellBuffer = DebugBuffer::getInstance();
    6668
    6769    // EVENT-Handler subscription of '`' to all States.
     
    246248    this->setSizeX2D(width);
    247249    for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt)
    248     {
    249250      (*textIt)->setLineWidth(width);
    250     }
    251251  }
    252252
     
    444444  {
    445445    this->flush();
    446     ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
     446    DebugBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
    447447  }
    448448
     
    470470        this->moveDisplayBuffer(-this->bufferDisplaySize+1);
    471471      }
    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();
    477477    }
    478478  }
  • trunk/src/lib/shell/shell.h

    r7762 r9869  
    1414
    1515#include "shell_input.h"
    16 #include "shell_buffer.h"
     16#include "debug_buffer.h"
    1717#include "material.h"
    1818
     
    4848  class Shell : public Element2D, public EventListener
    4949  {
    50 
     50    ObjectListDeclaration(Shell);
    5151  public:
    5252    Shell();
     
    9393  private:
    9494    // GENERAL
    95     ShellBuffer*                shellBuffer;            //!< The local ShellBuffer.
     95    DebugBuffer*                shellBuffer;            //!< The local ShellBuffer.
    9696
    9797    bool                        bActive;                //!< If the shell is active.
  • trunk/src/lib/shell/shell_command.cc

    r9406 r9869  
    2020
    2121#include "compiler.h"
     22#include "helper_functions.h"
    2223#include "debug.h"
    23 #include "class_list.h"
    2424
    2525#include "key_names.h"
     
    2727namespace OrxShell
    2828{
     29  ObjectListDefinition(ShellCommand);
    2930  SHELL_COMMAND(debug, ShellCommandClass, help);
    3031
     
    3637   * @param paramCount the count of parameters this command takes
    3738   */
    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);
    4142    PRINTF(4)("create shellcommand '%s' for class '%s'\n", commandName.c_str(), className.c_str());
    4243    this->setName(commandName);
     
    4445    // copy the executor:
    4546    this->executor = executor;
    46     this->executor->setName(commandName);
    4747
    4848    for (unsigned int i = 0; i < this->executor->getParamCount(); i++)
     
    7575   * @brief registers a new ShellCommand
    7676   */
    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)
    7878  {
    7979    if (ShellCommand::exists(commandName, className))
     
    9494  void ShellCommand::unregisterCommand(const std::string& commandName, const std::string& className)
    9595  {
    96 
    9796    ShellCommandClass* cmdClass = ShellCommandClass::acquireCommandClass(className);
    9897    if (cmdClass != NULL)
    9998    {
    10099      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++)
    102101        if (commandName == (*cmd)->getName())
    103102        {
     
    119118
    120119    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]);
    125124    }
    126125    return NULL;
     
    242241      return false;
    243242
    244     const std::list<BaseObject*>* objectList = ClassList::getList(cmd->shellClass->getName());
     243    const ObjectListBase* const objectList = ObjectListBase::getObjectList(cmd->shellClass->getName());
    245244    if (objectList != NULL)
    246245    {
    247       std::list<BaseObject*>::const_iterator bo;
     246      ObjectListBase::base_list list;
     247      objectList->getBaseObjectList(&list);
     248      ObjectListBase::base_iterator it;
    248249
    249250      // No Description given (only for speedup)
    250251      if (objectDescriptor.empty())
    251252      {
    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);
    254255      }
    255256      // some description
    256257      else
    257258      {
    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);
    261262      }
    262263    }
     
    299300    if (sc != NULL)
    300301    {
    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        }
    306314      return true;
    307315    }
     
    376384    else
    377385    {
    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();
    381389    }
    382390    return this;
  • trunk/src/lib/shell/shell_command.h

    r8145 r9869  
    99#include "base_object.h"
    1010
    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
    1217#include "shell_completion_plugin.h"
    1318
     
    3540   */
    3641#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))
    3843
    3944  /**
     
    5156   */
    5257#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))
    5459
    5560
     
    5863  class ShellCommand : public BaseObject
    5964  {
     65    ObjectListDeclaration(ShellCommand);
     66
    6067    friend class ShellCommandClass;
    6168  public:
     
    6976    ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin);
    7077
    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);
    7279    static void unregisterCommand(const std::string& commandName, const std::string& className);
    7380    static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className);
     
    8592
    8693  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);
    8895    virtual ~ShellCommand();
    8996
     
    97104    std::string                      description;           //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla");
    98105    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.
    100107  };
    101108
  • trunk/src/lib/shell/shell_command_class.cc

    r9406 r9869  
    2121
    2222#include "debug.h"
    23 #include "class_list.h"
    2423#include "compiler.h"
    2524
     
    2827namespace OrxShell
    2928{
    30   CmdClassList* ShellCommandClass::commandClassList = NULL;
     29  ObjectListDefinition(ShellCommandClass);
     30
     31  CmdClassList* ShellCommandClass::_commandClassList = NULL;
    3132
    3233  /**
     
    3536   */
    3637  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);
    4041    this->setName(className);
    4142
    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);
    4746  }
    4847
     
    5251  ShellCommandClass::~ShellCommandClass()
    5352  {
    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);
    6261    }
    6362  }
     
    6867  void ShellCommandClass::registerCommand(ShellCommand* command)
    6968  {
    70     this->commandList.push_back(command);
     69    this->_commandList.push_back(command);
    7170  }
    7271
     
    7776  void ShellCommandClass::unregisterCommand(ShellCommand* command)
    7877  {
    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);
    8281  }
    8382
     
    8988    // unregister all commands and Classes
    9089    CmdClassList::iterator classIT;
    91     if (ShellCommandClass::commandClassList == NULL)
     90    if (ShellCommandClass::_commandClassList == NULL)
    9291      return;
    9392
    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;
    9897  }
    9998
     
    107106  bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList)
    108107  {
    109     if (ShellCommandClass::commandClassList == NULL)
     108    if (ShellCommandClass::_commandClassList == NULL)
    110109      return false;
    111110
    112111
    113112    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++)
    115114    {
    116115      if (className == (*elem)->getName())
    117116      {
    118117        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++)
    120119          stringList.push_back((*command)->getName());
    121120        return true;
     
    133132  ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className)
    134133  {
    135     if (ShellCommandClass::commandClassList == NULL)
     134    if (ShellCommandClass::_commandClassList == NULL)
    136135      return false;
    137136
    138137
    139138    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)
    142141        return (*classIT);
    143142    return NULL;
     
    152151  {
    153152    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;
    161153  }
    162154
     
    181173  void ShellCommandClass::help(const std::string& className)
    182174  {
    183     if (ShellCommandClass::commandClassList == NULL)
     175    if (ShellCommandClass::_commandClassList == NULL)
    184176    {
    185177      PRINT(0)("No Commands Registered\n");
     
    187179    }
    188180    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());
    190182
    191183
    192184    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)
    196188      {
    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());
    198190        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++)
    200192        {
    201193          PRINT(0)("  command:'%s' : params:%d: ", (*cmdIT)->getCName(), (*cmdIT)->executor->getParamCount());
  • trunk/src/lib/shell/shell_command_class.h

    r8362 r9869  
    2525  class ShellCommandClass : public BaseObject
    2626  {
     27    ObjectListDeclaration(ShellCommandClass);
     28
    2729    friend class ShellCommand;
    2830  public:
    2931    /** @returns the CommandClassList */
    30     static const CmdClassList& getCommandClassList() { return *ShellCommandClass::commandClassList; };
     32    static const CmdClassList& getCommandClassList() { return *ShellCommandClass::_commandClassList; };
    3133
    3234    static bool getCommandListOfClass(const std::string& className, std::list<std::string>& stringList);
     
    5153
    5254  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
    5657
    57     static CmdClassList*                   commandClassList;          //!< A list of Classes
     58    static CmdClassList*                   _commandClassList;          //!< A list of Classes
    5859  };
    5960}
  • trunk/src/lib/shell/shell_completion.cc

    r9406 r9869  
    2222#include "shell_command.h"
    2323
    24 #include "substring.h"
    25 #include "class_list.h"
     24#include "helper_functions.h"
    2625#include "debug.h"
    2726
     
    5150  bool ShellCompletion::autoComplete(std::string& input)
    5251  {
    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 ClassList
     52    ClassID classID;
     53    const ObjectListBase* objectList = NULL;      //< the list of Objects stored in classID's ClassList
    5554    bool emptyComplete = false;                      //< if the completion input is empty string. e.g ""
    5655    long completeType = NullCompletion;              //< the Type we'd like to complete.
     
    8584             (!emptyComplete && inputSplits.size() == 2))
    8685    {
    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())
    9090        completeType |= ObjectCompletion;
    9191      completeType |= FunctionCompletion;
     
    9595             (!emptyComplete && inputSplits.size() == 3))
    9696    {
    97       if (ClassList::exists(inputSplits[0], inputSplits[1]))
     97      if (ObjectListBase::getBaseObject(inputSplits[0], inputSplits[1]))
    9898        completeType |= FunctionCompletion;
    9999    }
     
    113113
    114114    if (completeType & ClassCompletion)
    115       this->objectComplete(completeString, CL_SHELL_COMMAND_CLASS);
     115      this->objectComplete(completeString, &ShellCommandClass::objectList());
    116116    if (completeType & ObjectCompletion)
    117       this->objectComplete(completeString, classID);
     117      this->objectComplete(completeString, objectList);
    118118    if (completeType & FunctionCompletion)
    119119      this->commandComplete(completeString, inputSplits[0]);
     
    133133   * @return true on success, false otherwise
    134134   */
    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
    148149    return true;
    149150  }
     
    321322    switch (type)
    322323    {
    323         default:// SHELLC_NONE
    324         return typeNames[0];
    325         case  ClassCompletion:
    326         return typeNames[1];
    327         case ObjectCompletion:
    328         return typeNames[2];
    329         case FunctionCompletion:
    330         return typeNames[3];
    331         case AliasCompletion:
    332         return typeNames[4];
    333         case ParamCompletion:
    334         return typeNames[5];
     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];
    335336    }
    336337  }
  • trunk/src/lib/shell/shell_completion.h

    r7415 r9869  
    1616// FORWARD DECLARATION
    1717class BaseObject;
     18class ObjectListBase;
    1819
    1920namespace OrxShell
     
    5051      bool autoComplete(std::string& input);
    5152
    52       static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type);
     53      static const std::string& typeToString(ShellCompletion::CompletionType type);
    5354
    5455    private:
    55       bool objectComplete(const std::string& objectBegin, long classID);
     56      bool objectComplete(const std::string& objectBegin, const ObjectListBase* const objectList);
    5657      bool commandComplete(const std::string& commandBegin, const std::string& className);
    5758      bool aliasComplete(const std::string& aliasBegin);
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r8330 r9869  
    2121#include "shell_command.h"
    2222
    23 #include "substring.h"
    24 #include "class_list.h"
     23#include "helper_functions.h"
    2524#include "loading/resource_manager.h"
    2625
     
    9897    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
    9998    {
    100       dir.setFileName(ResourceManager::getInstance()->getDataDir() + this->_subDir);
     99      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + this->_subDir);
    101100      dir.open();
    102101      for(unsigned int i = 0; i < dir.fileCount(); i++ )
     
    113112        directoryName = completionBegin.substr(0, pos);
    114113
    115       dir.setFileName(ResourceManager::getInstance()->getDataDir() + directoryName);
     114      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + directoryName);
    116115      dir.open();
    117116
     
    136135          continue;
    137136        }
    138         printf("%s\n", (ResourceManager::getInstance()->getDataDir() + fileName).c_str());
     137        printf("%s\n", (Resources::ResourceManager::getInstance()->mainGlobalPath().name() + fileName).c_str());
    139138        if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) &&
    140              ResourceManager::isInDataDir(fileName))
     139             Resources::ResourceManager::getInstance()->checkFileInMainPath(fileName))
    141140        {
    142141          printf("Dir %s\n", fileName.c_str());
  • trunk/src/lib/shell/shell_input.cc

    r8339 r9869  
    2424#include "compiler.h"
    2525#include "key_names.h"
     26
    2627
    2728namespace OrxShell
     
    3132  ->setAlias("help");
    3233
     34  ObjectListDefinition(ShellInput);
    3335
    3436  /**
     
    3941      : Text ("")
    4042  {
     43    this->registerObject(this, ShellInput::_objectList);
     44
    4145    this->pressedKey = SDLK_FIRST;
    42     this->setClassID(CL_SHELL_INPUT, "ShellInput");
    43 
    44     this->inputLine = "";
     46
    4547    this->historyIT = ShellInput::history.begin();
    4648    this->setHistoryLength(50);
     
    5355    {
    5456      //if (!this->isEventSubscribed(ES_SHELL, i))
    55         this->subscribeEvent(ES_SHELL, i);
     57      this->subscribeEvent(ES_SHELL, i);
    5658    }
    5759    // unsubscribe unused TODO improve.
     
    6062    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP);
    6163    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    62 
    6364  }
    6465
     
    8788  void ShellInput::flush()
    8889  {
    89     this->inputLine.clear();
    90     this->setText(this->inputLine);
     90    this->inputLineBegin.clear();
     91    this->inputLineEnd.clear();
     92    this->clear();
    9193  }
    9294
     
    9799  void ShellInput::setInputText(const std::string& text)
    98100  {
    99     this->inputLine = text;
    100     this->setText(this->inputLine);
     101    this->inputLineBegin = text;
     102    this->inputLineEnd.clear();
     103    this->setText(text);
    101104  }
    102105
     
    114117    }
    115118
    116     this->inputLine += character;
    117     this->setText(this->inputLine);
     119    this->inputLineBegin += character;
     120    this->setText(this->inputLineBegin + this->inputLineEnd);
    118121  }
    119122
     
    130133    }
    131134
    132     this->inputLine += characters;
    133     this->setText(this->inputLine);
     135    this->inputLineBegin += characters;
     136    this->setText(this->inputLineBegin + this->inputLineEnd);
    134137  }
    135138
     
    145148      this->historyScrolling = false;
    146149    }
    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);
    152155  }
    153156
     
    158161  bool ShellInput::executeCommand()
    159162  {
    160     ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str());
    161 
    162     if (this->inputLine.empty())
     163    if (this->getInput().empty())
    163164      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());
    166168
    167169    // removing the eventually added Entry (from scrolling) to the List
     
    173175
    174176    // 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());
    177179    if (this->history.size() > this->historyLength)
    178180    {
     
    193195    if (!this->historyScrolling)
    194196    {
    195       this->history.push_back(this->inputLine);
     197      this->history.push_back(this->getInput());
    196198      this->historyScrolling = true;
    197199      this->historyIT = --this->history.end();
     
    231233  }
    232234
     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
    233261
    234262  /**
     
    237265  void ShellInput::help(const std::string& className, const std::string& functionName)
    238266  {
    239     printf("%s::%s\n", className.c_str(), functionName.c_str());
    240 
    241267    if (className.empty())
    242268    {
    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");
    249275    }
    250276    else if (!className.empty() && functionName.empty())
     
    269295      {
    270296        case SDLK_BACKSPACE:
    271           this->removeCharacters(1);
    272           break;
     297        this->removeCharacters(1);
     298        break;
    273299        case SDLK_UP:
    274           this->historyMoveUp();
    275           break;
     300        this->historyMoveUp();
     301        break;
    276302        case SDLK_DOWN:
    277           this->historyMoveDown();
    278           break;
     303        this->historyMoveDown();
     304        break;
    279305        default:
    280           {
    281             if (likely(pressedKey < 127))
    282               this->addCharacter(this->pressedKey);
    283           }
     306        {
     307          if (likely(pressedKey < 127))
     308            this->addCharacter(this->pressedKey);
     309        }
    284310      }
    285311    }
     
    313339        this->pressedEvent = event.type;
    314340      }
     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      }
    315353      else if (event.type == SDLK_TAB)
    316354      {
    317         this->completion.autoComplete(this->inputLine);
    318         this->setText(this->inputLine);
     355        this->completion.autoComplete(this->inputLineBegin);
     356        this->setText(this->getInput());
    319357      }
    320358      else if (event.type == SDLK_BACKSPACE)
     
    325363        this->removeCharacters(1);
    326364      }
     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      }
    327373      else if (event.type == SDLK_RETURN)
    328374      {
  • trunk/src/lib/shell/shell_input.h

    r7858 r9869  
    3030  class ShellInput : public Text,  public EventListener
    3131  {
     32    ObjectListDeclaration(ShellInput);
    3233
    3334  public:
     
    3637
    3738    /** @returns the inputLine */
    38     const std::string& getInput() const { return this->inputLine; };
     39    std::string getInput() const { return this->inputLineBegin + this->inputLineEnd; };
    3940
    4041    // InputLine
     
    5455    void historyMoveDown();
    5556
     57    void moveCursor(int chars);
     58
    5659    void help(const std::string& className = "", const std::string& function = "");
    5760
     
    6366    ShellCompletion                   completion;       //!< The Completion Interface.
    6467
    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
    6671    float                             repeatRate;       //!< The Repeat-Delay.
    6772    float                             repeatDelay;      //!< The delay of the first Character of a given Character.
  • trunk/src/lib/shell/some_shell_commands.cc

    r8623 r9869  
    2929
    3030#include "network_game_rules.h"
    31   SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say");
     31SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say");
    3232
    3333#include "player_stats.h"
    34   SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick");
     34SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick");
    3535
    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);
    4040
    4141#include "p_node.h"
    42   SHELL_COMMAND(debugNode, PNode, debugNode);
    43   SHELL_COMMAND(setPosition, PNode, setAbsCoor);
     42SHELL_COMMAND(debugNode, PNode, debugNode);
     43SHELL_COMMAND(setPosition, PNode, setAbsCoor);
    4444
    4545#include "render_2d.h"
    46   SHELL_COMMAND(toggleNodeVisibility, Render2D, toggleNodesVisibility);
     46SHELL_COMMAND(toggleNodeVisibility, Render2D, toggleNodesVisibility);
    4747
    4848
    4949#include "material.h"
    50   SHELL_COMMAND(setDiffuseTexture, Material, setDiffuseMap)
    51       ->defaultValues(MT_NULL, (int)GL_TEXTURE_2D)
    52       ->completionPlugin(0, CompletorFileSystem());
     50SHELL_COMMAND(setDiffuseTexture, Material, setDiffuseMap)
     51->defaultValues(MT_NULL, (int)GL_TEXTURE_2D)
     52->completionPlugin(0, CompletorFileSystem());
    5353
     54#include "loading/resource_manager.h"
     55namespace 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"
     62SHELL_COMMAND_STATIC(printAll, LoadParamClassDescription, &LoadParamClassDescription::printAll)
     63->defaultValues(MT_NULL, true);
     64SHELL_COMMAND_STATIC(capture, LoadParamClassDescription, &LoadParamClassDescription::captureDescriptions)
     65    ->defaultValues(true);
     66
     67#include "loading/game_loader.h"
     68SHELL_COMMAND(quit, GameLoader, stop)
     69    ->describe("quits the game")
     70    ->setAlias("orxoquit");
     71
     72#include "object_list.h"
     73SHELL_COMMAND_STATIC(debugAll, ObjectListBase, &ObjectListBase::debugAll);
  • trunk/src/lib/sound/Makefile.am

    r5475 r9869  
    77                        sound_source.cc \
    88                        sound_buffer.cc \
     9                        sound_buffer_data.cc \
     10                        resource_sound_buffer.cc \
    911                        ogg_player.cc
    1012
     
    1214                 sound_source.h \
    1315                 sound_buffer.h \
     16                 sound_buffer_data.h \
     17                 resource_sound_buffer.h \
    1418                 ogg_player.h
  • trunk/src/lib/sound/ogg_player.cc

    r9406 r9869  
    3434
    3535#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"
    4837
    4938namespace OrxSound
    5039{
     40  ObjectListDefinition(OggPlayer);
    5141  /**
    5242   * initializes an Ogg-player from a file
     
    5545  OggPlayer::OggPlayer(const std::string& fileName)
    5646  {
    57     this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer");
     47    this->registerObject(this, OggPlayer::_objectList);
    5848
    5949    this->state = OggPlayer::None;
     
    276266        ogg->update();
    277267      }
    278       SDL_Delay(10);
     268      SDL_Delay(1);
    279269    }
    280270    PRINTF(4)("End the AudioThread\n");
  • trunk/src/lib/sound/ogg_player.h

    r9019 r9869  
    1313#include <ogg/ogg.h>
    1414#include <vorbis/vorbisfile.h>
    15 #include "threading.h"
     15#include "util/threading.h"
    1616
    1717struct File;
     
    2525  class OggPlayer : public BaseObject
    2626  {
     27    ObjectListDeclaration(OggPlayer);
     28
    2729  public:
    2830    /**
     
    98100
    99101
    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.
    104106  };
    105107
  • trunk/src/lib/sound/sound_buffer.cc

    r8971 r9869  
    1818#include "sound_buffer.h"
    1919
    20 #include "sound_engine.h"
    2120
    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_H
    29 #include <SDL/SDL.h>
    30 #include <SDL/SDL_endian.h>
    31 #else
    32 #include <SDL.h>
    33 #include <SDL_endian.h>
    34 #endif
    3521namespace OrxSound
    3622{
     23  ObjectListDefinition(SoundBuffer);
    3724  //////////////////
    3825  /* SOUND-BUFFER */
    3926  //////////////////
     27  SoundBuffer::SoundBuffer()
     28      : data(new SoundBufferData)
     29  {
     30    this->registerObject(this, SoundBuffer::_objectList);
     31  }
    4032  /**
    41    * Creates a Soundbuffer out of an inputfile
     33   * @brief Creates a Soundbuffer out of an inputfile
    4234   * @param fileName The name of the File
    4335   */
    4436  SoundBuffer::SoundBuffer(const std::string& fileName)
     37      : data(new SoundBufferData)
    4538  {
    46     this->setClassID(CL_SOUND_BUFFER, "SoundBuffer");
    47     this->setName(fileName);
     39    this->registerObject(this, SoundBuffer::_objectList);
     40    this->load(fileName);
     41  }
    4842
    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  }
    5848
    59   }
     49  SoundBuffer::SoundBuffer(const SoundBufferData::Pointer& dataPointer)
     50      : data(dataPointer)
     51  {
     52    this->registerObject(this, SoundBuffer::_objectList);
     53  };
    6054
    6155  SoundBuffer::~SoundBuffer()
    6256  {
    63     //  SoundEngine::getInstance()->removeBuffer(this);
    64     alDeleteBuffers(1, &this->bufferID);
    65     SoundEngine::checkError("SoundBuffer: Delete Buffer", __LINE__);
    6657  }
    6758
    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_ENDIAN
    86     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 #endif
    94     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     else
    101       return false;
    102   }
    103 
    104 
    105 #ifndef AL_FORMAT_VORBIS_EXT
    106 #define AL_FORMAT_VORBIS_EXT 0x100030
    107 #endif
    108   /**
    109    * @brief loads an OGG-file into a SOundBuffer
    110    * @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       else
    142         return false;
    143     }
    144     else
    145       return false;
    146 
    147     return true ;
    148 
    149   }
    150 
    151 
    152   /**
    153    * @brief converts an SDL_AudioSpec into a valid OpenAL AUDIO_FORMAT enumerator
    154    * @param audiospec the AudioSpec to convert.
    155    * @returns the AL_FORMAT
    156    */
    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   }
    17659}
  • trunk/src/lib/sound/sound_buffer.h

    r8969 r9869  
    88
    99#include "base_object.h"
    10 #include "alincl.h"
    11 
    12 // FORWARD DECLARATION
    13 typedef struct SDL_AudioSpec;
     10#include "sound_buffer_data.h"
    1411
    1512namespace OrxSound
    1613{
    1714  //! A class that represents a datastructure to play Sounds.
    18   class SoundBuffer : public BaseObject
     15  class SoundBuffer : virtual public BaseObject
    1916  {
     17    ObjectListDeclaration(SoundBuffer);
    2018  public:
     19    SoundBuffer();
     20    SoundBuffer(const SoundBuffer& buffer);
     21    SoundBuffer(const SoundBufferData::Pointer& dataPointer);
    2122    SoundBuffer(const std::string& fileName);
    2223    virtual ~SoundBuffer();
    2324
    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); };
    2635
    2736    /** @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; };
    2944
    3045  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
    3847  };
    3948}
  • trunk/src/lib/sound/sound_engine.cc

    r9235 r9869  
    2121#include "sound_engine.h"
    2222
    23 #include "class_list.h"
    24 
    2523#include "p_node.h"
    26 #include "util/loading/resource_manager.h"
    2724#include "debug.h"
    28 #include "util/preferences.h"
     25#include "parser/preferences/preferences.h"
    2926#include "globals.h"
     27#include "resource_sound_buffer.h"
    3028
    3129namespace OrxSound
    3230{
    33 
     31  ObjectListDefinition(SoundEngine);
    3432  //////////////////
    3533  /* SOUND-ENGINE */
     
    4038  SoundEngine::SoundEngine ()
    4139  {
    42     this->setClassID(CL_SOUND_ENGINE, "SoundEngine");
     40    this->registerObject(this, SoundEngine::_objectList);
    4341    this->setName("SoundEngine");
    4442
    4543    this->listener = NULL;
    46     this->bufferList = NULL;
    47     this->sourceList = NULL;
    4844
    4945    this->device = NULL;
     
    6965  {
    7066    // 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());
    7669
    7770    while(!this->ALSources.empty())
     
    8982
    9083    // 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());
    9686
    9787    // removing openAL from AudioResource
     
    129119  SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode)
    130120  {
    131     SoundBuffer* buffer = NULL;
     121    SoundBuffer buffer;
    132122    if (!fileName.empty())
    133123    {
    134       buffer= (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL);
    135       if (buffer == NULL)
     124      buffer = ResourceSoundBuffer(fileName);
     125      if (!buffer.loaded())
    136126        PRINTF(2)("Wav-Sound %s could not be loaded onto new Source\n", fileName.c_str());
    137127    }
     
    212202
    213203    // 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())
    219210      {
    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)
    222216        {
    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))
    228218          {
    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__);
    244231          }
    245           else
    246           {
    247             source->stop();
    248           }
     232        }
     233        else
     234        {
     235          (*sourceIT)->stop();
    249236        }
    250237      }
     
    393380      default:
    394381      case AL_NO_ERROR:
    395         return ("AL_NO_ERROR");
     382      return ("AL_NO_ERROR");
    396383      case AL_INVALID_NAME:
    397         return ("AL_INVALID_NAME");
     384      return ("AL_INVALID_NAME");
    398385      case AL_INVALID_ENUM:
    399         return ("AL_INVALID_ENUM");
     386      return ("AL_INVALID_ENUM");
    400387      case AL_INVALID_VALUE:
    401         return ("AL_INVALID_VALUE");
     388      return ("AL_INVALID_VALUE");
    402389      case AL_INVALID_OPERATION:
    403         return ("AL_INVALID_OPERATION");
     390      return ("AL_INVALID_OPERATION");
    404391      case AL_OUT_OF_MEMORY:
    405         return ("AL_OUT_OF_MEMORY");
     392      return ("AL_OUT_OF_MEMORY");
    406393    };
    407394  }
     
    414401      default:
    415402      case ALC_NO_ERROR:
    416         return ("AL_NO_ERROR");
     403      return ("AL_NO_ERROR");
    417404      case ALC_INVALID_DEVICE:
    418         return ("ALC_INVALID_DEVICE");
     405      return ("ALC_INVALID_DEVICE");
    419406      case ALC_INVALID_CONTEXT:
    420         return("ALC_INVALID_CONTEXT");
     407      return("ALC_INVALID_CONTEXT");
    421408      case ALC_INVALID_ENUM:
    422         return("ALC_INVALID_ENUM");
     409      return("ALC_INVALID_ENUM");
    423410      case ALC_INVALID_VALUE:
    424         return ("ALC_INVALID_VALUE");
     411      return ("ALC_INVALID_VALUE");
    425412      case ALC_OUT_OF_MEMORY:
    426         return("ALC_OUT_OF_MEMORY");
     413      return("ALC_OUT_OF_MEMORY");
    427414    };
    428415  }
  • trunk/src/lib/sound/sound_engine.h

    r7847 r9869  
    2727  class SoundEngine : public BaseObject
    2828  {
    29   public:
     29    ObjectListDeclaration(SoundEngine);
     30    public:
    3031    virtual ~SoundEngine();
    3132    /** @returns a Pointer to the only object of this Class */
     
    7576    const PNode*                   listener;                 //!< The listener of the Scene
    7677
    77     const std::list<BaseObject*>*  bufferList;               //!< A list of buffers
    78     const std::list<BaseObject*>*  sourceList;               //!< A list for all the sources in the scene.
    79 
    8078    unsigned int                   maxSourceCount;           //!< How many Sources is the Maximum
    8179    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  
    1919#include "sound_engine.h"
    2020
    21 #include "alincl.h"
    2221#include "compiler.h"
    2322#include "debug.h"
     
    2524namespace OrxSound
    2625{
     26  ObjectListDefinition(SoundSource);
    2727  /**
    2828  * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer
    2929  */
    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);
    3433    // adding the Source to the SourcesList of the SoundEngine
    3534    this->buffer = buffer;
     
    5150  SoundSource::SoundSource(const SoundSource& source)
    5251  {
    53     this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     52    this->registerObject(this, SoundSource::_objectList);
    5453
    5554    // adding the Source to the SourcesList of the SoundEngine
     
    120119  void SoundSource::play()
    121120  {
    122     if (this->buffer && this->retrieveSource())
     121    if (this->retrieveSource())
    123122    {
    124123      if (this->bPlay)
    125124        alSourceStop(this->sourceID);
    126125
    127       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     126      alSourcei (this->sourceID, AL_BUFFER, this->buffer.getID());
    128127      alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
    129128      alSourcef (this->sourceID, AL_GAIN, 1);
     
    141140  * @param buffer the buffer to play back on this Source
    142141  */
    143   void SoundSource::play(const SoundBuffer* buffer)
     142  void SoundSource::play(const SoundBuffer& buffer)
    144143  {
    145144    if (!this->retrieveSource())
     
    150149
    151150    alSourceStop(this->sourceID);
    152     alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     151    alSourcei (this->sourceID, AL_BUFFER, buffer.getID());
    153152    alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
    154153    alSourcef (this->sourceID, AL_GAIN, 1);
     
    156155    alSourcePlay(this->sourceID);
    157156
    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());
    160159    this->bPlay = true;
    161160
     
    170169   * @param gain the gain of the sound buffer
    171170  */
    172   void SoundSource::play(const SoundBuffer* buffer, float gain)
     171  void SoundSource::play(const SoundBuffer& buffer, float gain)
    173172  {
    174173    if (!this->retrieveSource())
     
    179178
    180179    alSourceStop(this->sourceID);
    181     alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     180    alSourcei (this->sourceID, AL_BUFFER, buffer.getID());
    182181    alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
    183182    alSourcef (this->sourceID, AL_GAIN, gain);
     
    185184    alSourcePlay(this->sourceID);
    186185
    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());
    189188    this->bPlay = true;
    190189
     
    199198   * @param loop if true, sound gets looped
    200199   */
    201   void SoundSource::play(const SoundBuffer* buffer, float gain, bool loop)
     200  void SoundSource::play(const SoundBuffer& buffer, float gain, bool loop)
    202201  {
    203202    if (!this->retrieveSource())
     
    208207
    209208    alSourceStop(this->sourceID);
    210     alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     209    alSourcei (this->sourceID, AL_BUFFER, buffer.getID());
    211210
    212211    if (loop)
     
    219218    alSourcePlay(this->sourceID);
    220219
    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());
    223222    this->bPlay = true;
    224223
     
    232231   * @param gain the new gain value
    233232   */
    234   void SoundSource::gain(const SoundBuffer* buffer, float gain)
     233  void SoundSource::gain(const SoundBuffer& buffer, float gain)
    235234  {
    236235    // alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     
    347346  * @param duration time perios to fade in
    348347  */
    349   void SoundSource::fadein(const SoundBuffer* buffer, ALfloat duration)
     348  void SoundSource::fadein(const SoundBuffer& buffer, ALfloat duration)
    350349  {
    351350    //if (this->buffer && this->retrieveSource())
  • trunk/src/lib/sound/sound_source.h

    r8793 r9869  
    88
    99#include "base_object.h"
     10#include "sound_buffer.h"
    1011#include "alincl.h"
    1112
     
    1415namespace OrxSound
    1516{
    16   class SoundBuffer;
    1717  //! A class that represents a SoundSource
    1818  class SoundSource : public BaseObject
    1919  {
     20    ObjectListDeclaration(SoundSource);
    2021  public:
    21     SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
     22    SoundSource(const PNode* sourceNode = NULL, const SoundBuffer& buffer = SoundBuffer());
    2223    SoundSource(const SoundSource& source);
    2324    SoundSource& operator=(const SoundSource& source);
     
    2829    // user interaction
    2930    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);
    3334
    34     void gain(const SoundBuffer* buffer, float gain);
     35    void gain(const SoundBuffer& buffer, float gain);
    3536
    3637    void stop();
    3738    void pause();
    3839    void rewind();
    39     void fadein(const SoundBuffer* buffer, ALfloat duration);
     40    void fadein(const SoundBuffer& buffer, ALfloat duration);
    4041
    4142    // development functions
     
    4647    void setSourceNode(const PNode* sourceNode);
    4748    /** @returns the SoundBuffer of this Source */
    48     inline const SoundBuffer* getBuffer() const { return this->buffer; };
     49    inline const SoundBuffer& getBuffer() const { return this->buffer; };
    4950    /** @returns the SourceNode of this Source */
    5051    inline const PNode* getNode() const { return this->sourceNode; };
     
    6566    bool                   resident;    //!< If the alSource should be resident (if true, the alSource will be returned on deletion).
    6667    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.
    6869    const PNode*           sourceNode;  //!< The SourceNode representing the position/velocity... of this source.
    6970  };
  • trunk/src/lib/util/Makefile.am

    r9406 r9869  
    22include $(MAINSRCDIR)/defs/include_paths.am
    33
    4 noinst_LIBRARIES = libORXlibutil.a
     4noinst_LIBRARIES = \
     5                libORXlibutil.a \
     6                libORXexecutor.a
     7
     8libORXexecutor_a_SOURCES = \
     9                executor/executor_substring.cc
    510
    611libORXlibutil_a_SOURCES = \
     
    914                helper_functions.cc \
    1015                multi_type.cc \
    11                 executor/executor.cc \
    12                 executor/executor_functional.cc \
    13                 executor/executor_lua.cc \
     16                debug_buffer.cc \
    1417                \
    1518                loading/resource_manager.cc \
     
    1821                loading/load_param.cc \
    1922                loading/load_param_description.cc \
     23                loading/load_param_class_description.cc \
    2024                loading/factory.cc \
    21                 loading/dynamic_loader.cc \
     25                loading/fast_factory.cc \
    2226                \
    2327                filesys/file.cc \
     
    2529                filesys/net_link.cc \
    2630                \
    27                 preferences.cc \
    2831                threading.cc \
    2932                timer.cc
     33
     34#               loading/dynamic_loader.cc
    3035
    3136
     
    3540                color.h \
    3641                helper_functions.h \
     42                debug.h \
     43                debug_buffer.h \
     44                \
     45                \
    3746                executor/executor.h \
    38                 executor/executor_functional.h \
    3947                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                \
    4154                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                \
    4260                \
    4361                filesys/file.h \
     
    4563                filesys/net_link.h \
    4664                \
    47                 preferences.h \
    4865                threading.h \
    4966                timer.h \
     
    5370                loading/game_loader.h \
    5471                loading/load_param.h \
     72                loading/load_param_xml.h \
    5573                loading/load_param_description.h \
     74                loading/load_param_class_description.h \
    5675                loading/factory.h \
     76                loading/fast_factory.h \
    5777                loading/dynamic_loader.h \
    5878                \
  • trunk/src/lib/util/color.cc

    r8986 r9869  
    3030//! Black Color
    3131const 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 */
    3638void Color::slerpHSV(const Color& c, float v)
    3739{
     
    5254}
    5355
     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 */
    5463Color Color::slerpHSVColor(const Color& from, const Color& to, float v)
    5564{
     
    5968}
    6069
    61 
     70/**
     71 * @brief nice and simple debug output for the colors (colorless :) )
     72 */
    6273void Color::debug() const
    6374{
     
    214225
    215226
    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 */
    217233float Color::maxrgb(float r, float g, float b)
    218234{
     
    227243}
    228244
    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 */
    231251float Color::minrgb(float r,float g,float b)
    232252{
  • trunk/src/lib/util/color.h

    r9656 r9869  
    1414#include "vector.h"
    1515
    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 */
    1730class Color
    1831{
    1932public:
     33  /** @param r red, @param g green @param b blue @param a alpha @brief constructs a Color. */
    2034  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 */
    2136  Color(const Color& c) { _rgba[0] = c.r(); _rgba[1] = c.g(); _rgba[2] = c.b(); _rgba[3] = c.a(); }
    2237
     38  /** @param c the Color to set to this color @returns the copied color */
    2339  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 */
    2441  inline bool operator==(const Color& c) const { return (r() == c.r() && g() == c.g() && b() == c.b() && a() == c.a()); };
    2542
     43  /** @returns the i'th Value of the Color @param i part of the color 0:r, 1:g, 2:b, 3:a */
    2644  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 */
    2746  inline const float& operator[](unsigned int i) const { return _rgba[i]; }
    2847
     48  /** @returns the red part. */
    2949  inline float r() const { return _rgba[0]; }
     50  /** @returns the reference to the red part */
    3051  inline float& r() { return _rgba[0]; }
     52  /** @returns the green part. */
    3153  inline float g() const { return _rgba[1]; }
     54  /** @returns the reference to the green part */
    3255  inline float& g() { return _rgba[1]; }
     56  /** @returns the blue part */
    3357  inline float b() const { return _rgba[2]; }
     58  /** @returns the reference to the blue part */
    3459  inline float& b() { return _rgba[2]; }
     60  /** @returns the alpha part */
    3561  inline float a() const { return _rgba[3]; }
     62  /** @returns the reference to the alpha part */
    3663  inline float& a() { return _rgba[3]; }
    3764
    3865
    39 
    40 
     66  /** @param r red, @param g green @param b blue @param a alpha @brief sets the color. */
    4167  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. */
    4269  void setColor(const Color& c) { r() = c.r();  g()= c.g(); b() = c.b(); a() = c.a(); };
    4370
     71  /** @returns the distance to the color @param c the color to calculate the distance to. */
    4472  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()))); }
    4573  /// Maths
     74  /** @param c the color to add to this one @returns the two added colors */
    4675  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 */
    4777  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 */
    4879  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 */
    4981  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 */
    5083  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 */
    5185  inline Color operator*(float v) const { return Color(r()*v, g()*v, b()*v, a()*v); };
    5286
     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 */
    5388  void slerp(const Color& c, float v) { *this += (c - *this) * v; };
    5489  void slerpHSV(const Color& c, float v);
    55 
    5690  static Color slerpHSVColor(const Color& from, const Color& to, float v);
    5791
     
    75109  static const Color white;
    76110  static const Color black;
    77   static const Color orx;
    78111
    79112private:
    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)
    86114};
    87115
  • trunk/src/lib/util/count_pointer.h

    r8761 r9869  
    99{
    1010public:
    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)
    1618    {
    17         if (this != &r) {
    18             release();
    19             acquire(r.itsCounter);
    20         }
    21         return *this;
     19      release();
     20      acquire(r.itsCounter);
    2221    }
    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); }
    2931private:
    3032
    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;
    3640
    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)
    3852    {
    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;
    4259    }
    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  }
    5561};
    5662
  • trunk/src/lib/util/executor/executor.h

    r8894 r9869  
    99#include "base_object.h"
    1010
    11 #include "helper_functions.h"
    1211#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 */
     19template<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 */
     21template<> inline MT_Type ExecutorParamType<bool>() { return MT_BOOL; };
     22/** @returns the Type of an Argument taken by the Executor in this case MT_INT*/
     23template<> inline MT_Type ExecutorParamType<int>() { return MT_INT; };
     24/** @returns the Type of an Argument taken by the Executor in this case MT_UINT*/
     25template<> 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*/
     27template<> inline MT_Type ExecutorParamType<float>() { return MT_FLOAT; };
     28/** @returns the Type of an Argument taken by the Executor in this case MT_CHAR*/
     29template<> inline MT_Type ExecutorParamType<char>() { return MT_CHAR; };
     30/** @returns the Type of an Argument taken by the Executor in this case MT_STRING*/
     31template<> inline MT_Type ExecutorParamType<const std::string&>() { return MT_STRING; };
    2332
    2433////////////////
     
    3645 *  Functions with many types (@see functor_list.h)
    3746 */
    38 class Executor : public BaseObject
     47template <typename CallType, class BaseClass = BaseObject> class Executor
    3948{
    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.
     49public:
     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
     57public:
     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
     117protected:
     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
     210protected:
     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.
    80216};
    81217
    82 #include "executor/executor_functional.h"
    83 #define EXECUTOR_FUNCTIONAL_USE_CONST
    84 #include "executor/executor_functional.h"
    85 #define EXECUTOR_FUNCTIONAL_USE_STATIC
    86 #include "executor/executor_functional.h"
    87 
    88218#endif /* _EXECUTOR_H */
  • trunk/src/lib/util/executor/executor_xml.h

    r8362 r9869  
    1919 * What must be defined is a XML-root to search the ParameterName under an  a Function to call.
    2020 */
    21 template<class T> class ExecutorXML : public Executor
     21template<class T, class BaseClass = BaseObject> class ExecutorXML : public Executor<const TiXmlElement*>
    2222{
    23   public:
    24     /**
     23public:
     24  /**
    2525   * @brief Constructor of a ExecutorXML
    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 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);
    3434
    35       if (likely(root != NULL && paramName != NULL))
    36         this->element = root->FirstChildElement(paramName);
    37       else
    38         this->element = NULL;
     35    if (likely(root != NULL))
     36      this->element = root->FirstChildElement(paramName);
     37    else
     38      this->element = NULL;
    3939
    40       this->functionPointer = function;
    41       this->functorType = Executor_Objective | Executor_NoLoadString;
    42     }
     40    this->paramName = paramName;
     41    this->functionPointer = function;
     42  }
    4343
    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  }
    5652
    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  }
    6764
    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.
     65private:
     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.
    8369};
    8470
  • 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 */
    16/*
    27   orxonox - the future of 3D-vertical-scrollers
     
    813   the Free Software Foundation; either version 2, or (at your option)
    914   any later version.
    10    */
    11 
    12 /*!
    13  * @file functors_list.h
    14  * all the Different types of Functions one can include
    1515*/
    16 
    17 /**
    18    useable FunctionParameters are:
    19    l_INT:       int
    20    l_LONG:      long
    21    l_SHORT:     short
    22    l_FLOAT:     float
    23    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 have
    31 #define FUNCTOR_MAX_ARGUMENTS                7
    32 #include "multi_type.h"
    33 
    34 
    35 #define l_BOOL_TYPE        bool                 //!< The type of an BOOL
    36 #define l_BOOL_FUNC        isBool               //!< The function to call to parse BOOL
    37 #define l_BOOL_PARAM       MT_BOOL              //!< the type of the parameter BOOL
    38 #define l_BOOL_DEFAULT     false                //!< a default Value for an BOOL
    39 #define l_BOOL_DEFGRAB(i)  this->defaultValue[i].getBool()
    40 
    41 #define l_INT_TYPE         int                  //!< The type of an INT
    42 #define l_INT_FUNC         isInt                //!< The function to call to parse INT
    43 #define l_INT_PARAM        MT_INT               //!< the type of the parameter INT
    44 #define l_INT_DEFAULT      0                    //!< a default Value for an INT
    45 #define l_INT_DEFGRAB(i)   this->defaultValue[i].getInt()
    46 
    47 #define l_UINT_TYPE        unsigned int         //!< The type of an UINT
    48 #define l_UINT_FUNC        isInt                //!< The function to call to parse UINT
    49 #define l_UINT_PARAM       MT_INT        //!< the type of the parameter UINT
    50 #define l_UINT_DEFAULT     0                    //!< a default Value for an UINT
    51 #define l_UINT_DEFGRAB(i)  (unsigned int)this->defaultValue[i].getInt()
    52 
    53 #define l_LONG_TYPE        long                 //!< The type of a LONG
    54 #define l_LONG_FUNC        isInt                //!< The function to parse a LONG
    55 #define l_LONG_PARAM       MT_INT //!< the type of the parameter LONG
    56 #define l_LONG_DEFAULT     0                    //!< a default Value for a LONG
    57 #define l_LONG_DEFGRAB(i)  (long)this->defaultValue[i].getInt()
    58 
    59 // #define l_SHORT_TYPE       short                //!< The type of a SHORT
    60 // #define l_SHORT_FUNC       atoi                 //!< The function to parse a SHORT
    61 // #define l_SHORT_NAME       "short"              //!< The name of a SHORT
    62 // #define l_SHORT_PARAM      ParameterShort       //!< the type of the parameter SHORT
    63 // #define l_SHORT_DEFAULT    0                    //!< a default Value for a SHORT
    64 
    65 #define l_FLOAT_TYPE       float                //!< The type of a FLOAT
    66 #define l_FLOAT_FUNC       isFloat              //!< The function to parse a FLOAT
    67 #define l_FLOAT_PARAM      MT_FLOAT             //!< the type of the parameter FLOAT
    68 #define l_FLOAT_DEFAULT    0.0                  //!< a default Value for a FLOAT
    69 #define l_FLOAT_DEFGRAB(i) this->defaultValue[i].getFloat()
    70 
    71 //#define l_VECTOR_TYPE      const Vector&        //!< The type of a VECTOR
    72 //#define l_VECTOR_FUNC      isVector             //!< The function to parse a VECTOR
    73 //#define l_VECTOR_NAME      "Vector[x/y/z]"      //!< The name of a VECTOR
    74 //#define l_VECTOR_DEFAULT   Vector(0,0,0)        //!< Default value for a VECTOR
    75 
    76 #define l_STRING_TYPE      const std::string&   //!< The type of a STRING
    77 #define l_STRING_FUNC      isString             //!< The function to parse a STRING
    78 #define l_STRING_PARAM     MT_STRING            //!< the type of the parameter STRING
    79 #define l_STRING_DEFAULT   ""                   //!< a default Value for an STRING
    80 #define l_STRING_DEFGRAB(i) this->defaultValue[i].getString()
    81 
    82 #define l_XML_ELEM_TYPE    const TiXmlElement*  //!< The type of an XML_ELEM
    83 #define l_XML_ELEM_FUNC                         //!< The function to parse an XML_ELEM
    84 //#define l_XML_ELEM_PARAM   Parameter            //!< the type of the parameter XML_ELEM
    85 #define l_XML_ELEM_DEFAULT NULL                 //!< The dafault Value for an XML_ELEM
    86 
    87 #endif /* __FUNCTOR_PARAMETERS__ */
    8816
    8917
    9018#ifdef FUNCTOR_LIST
    91 
    92   FUNCTOR_LIST(0)();
     19  FUNCTOR_LIST(0)(FUNCTOR_CALL_TYPE);
    9320  //! makes functions with one string
    94   FUNCTOR_LIST(1)(l_STRING);
     21  FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, const std::string&);
    9522  //! 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&);
    9724  //! 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&);
    9926  //! 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&);
    10128
    10229
    10330  //! makes functions with one bool
    104   FUNCTOR_LIST(1)(l_BOOL);
     31  FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, bool);
    10532
    10633  //! makes functions with one int
    107   FUNCTOR_LIST(1)(l_INT);
     34  FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, int);
    10835  //! makes functions with two ints
    109   FUNCTOR_LIST(2)(l_INT, l_INT);
     36  FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, int, int);
    11037  //! 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);
    11239  //! 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);
    11441
    11542
    11643  //! makes functions with one unsigned int
    117   FUNCTOR_LIST(1)(l_UINT);
     44  FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, unsigned int);
    11845  //! 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);
    12047  //! 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);
    12249  //! 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);
    12451
    12552  //! makes functions with one float
    126   FUNCTOR_LIST(1)(l_FLOAT);
     53  FUNCTOR_LIST(1)(FUNCTOR_CALL_TYPE, float);
    12754  //! makes functions with two floats
    128   FUNCTOR_LIST(2)(l_FLOAT, l_FLOAT);
     55  FUNCTOR_LIST(2)(FUNCTOR_CALL_TYPE, float, float);
    12956  //! 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);
    13158  //! 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);
    13360  //! 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);
    13562
    13663  //! 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);
    14169
    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);
    14674
    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&);
    14876
    14977#endif /* FUNCTOR_LIST */
  • trunk/src/lib/util/filesys/directory.cc

    r8523 r9869  
    4141#include <sys/stat.h>
    4242#include <dirent.h>
     43const char Directory::delimiter = '/';
    4344#else
    4445#include <windows.h>
    4546#include <winbase.h>
     47const char Direcotry::delimiter = '\\';
    4648#endif
    4749
     
    6365 */
    6466Directory::Directory(const Directory& directory)
    65   : File(directory)
     67    : File(directory)
    6668{
    6769  this->_opened = directory._opened;
     
    166168#endif
    167169}
     170
     171
     172Directory 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 */
     183Directory& 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 */
     193Directory& 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 */
     203Directory& Directory::operator--(int)
     204{
     205}
     206
     207/**
     208 * @returns The Parent Directory.
     209 */
     210Directory Directory::parentDir() const
     211{
     212
     213}
     214
     215File 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  
    2929#include <vector>
    3030
     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 */
    3139class Directory : public File
    3240{
     
    4149  bool create();
    4250
     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
    4358  /** @returns if the Directory was opened */
    4459  bool isOpen() const { return this->_opened; }
     
    5065  const std::string& operator[](unsigned int fileNumber) const { return this->_fileNames[fileNumber]; };
    5166  /** @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]; };
    5368  /** @returns a File pointing to the File @param fileNumber the fileNumber (must not bigger than fileCount()) */
    5469  File getFile(unsigned int fileNumber) const { return File(fileNameInDir(fileNumber)); };
     70
     71public:
     72  static const char           delimiter;        //!< A Delimiter (*nix: '/', windows: '\\')
    5573
    5674private:
     
    5876  std::vector<std::string>    _fileNames;       //!< The List of Files contained in the directory. (will be filled when open was called.)
    5977};
     78
     79File operator+(const Directory& dir, const File& file);
    6080
    6181#endif /* __DIRECTORY_H_ */
  • trunk/src/lib/util/filesys/file.cc

    r8619 r9869  
    326326}
    327327
     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 */
    328332void File::absToRel(std::string& absFileName)
    329333{
  • trunk/src/lib/util/loading/dynamic_loader.cc

    r9406 r9869  
    2424
    2525
    26 
     26ObjectListDefinition(DynamicLoader);
    2727
    2828/**
     
    3131*/
    3232DynamicLoader::DynamicLoader (const std::string& libName)
    33     : Factory(NULL, CL_NULL)
     33    : Factory(libName)
    3434{
    35   this->setClassID(CL_DYNAMIC_LOADER, "DynamicLoader");
     35  this->registerObject(this, DynamicLoader::_objectList);
    3636
    3737  this->handle = NULL;
  • trunk/src/lib/util/loading/dynamic_loader.h

    r7193 r9869  
    1919class DynamicLoader : public Factory
    2020{
     21  ObjectListDeclaration(DynamicLoader);
    2122
    2223public:
  • trunk/src/lib/util/loading/factory.cc

    r9675 r9869  
    1515#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
    1616
    17 #include "util/loading/factory.h"
     17#include "factory.h"
    1818#include "debug.h"
    1919//#include "shell_command.h"
    2020
    21 
     21ObjectListDefinition(Factory);
    2222
    2323//SHELL_COMMAND(create, Factory, fabricate);
     
    2828 * set everything to zero and define factoryName
    2929 */
    30 Factory::Factory (const std::string& factoryName, ClassID classID)
    31     : classID(classID), className(factoryName)
     30Factory::Factory (const ClassID& classID)
     31    : _classID(classID)
    3232{
    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());
    3536
    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;
    4039}
    4140
    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. */
     42Factory::FactoryIDMap Factory::_factoryIDMap;
     43
     44/** @brief A Map of all Factories ordered by Name. */
     45Factory::FactoryStringMap Factory::_factoryStringMap;
    4446
    4547/**
     
    4850Factory::~Factory ()
    4951{
    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);
    5455
    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);
    7059}
    7160
     
    7463 * @returns true on match, false otherwise
    7564 */
    76 bool Factory::operator==(ClassID classID) const
     65bool Factory::operator==(int classID) const
    7766{
    78   return (this->classID == classID);
     67  return (this->_classID == classID);
    7968}
    8069
    81 /**
    82  * @brief Compares the Factories Name against a given ClassName
    83  * @param className the Name of the Class to Query
    84  * @returns true on match, false otherwise.
    85  */
    86 bool Factory::operator==(const char* className) const
    87 {
    88   return (className != NULL && this->className == className);
    89 }
    9070
    9171/**
     
    9676bool Factory::operator==(const std::string& className) const
    9777{
    98   return (this->className == className);
     78  return (this->_classID.name() == className);
    9979}
    10080
     
    10787BaseObject* Factory::fabricate(const TiXmlElement* root)
    10888{
    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  }
    121100}
    122101
     
    129108BaseObject* Factory::fabricate(const std::string& className)
    130109{
    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());
    132119    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  }
    143121}
    144 
    145122
    146123/**
     
    149126 * @returns a new Object of Type classID on match, NULL otherwise
    150127 */
    151 BaseObject* Factory::fabricate(ClassID classID)
     128BaseObject* Factory::fabricate(const ClassID& classID)
    152129{
    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());
    154139    return NULL;
     140  }
     141}
    155142
    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);
    162143
    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 */
     147void Factory::debug() const
     148{
     149  PRINTF(0)("Factory of class '%s' with ClassID: %d\n", this->_classID.name().c_str(), this->_classID.id());
    166150}
     151
     152/**
     153 * @brief Prints out some nice Debug information about all factories
     154 */
     155void 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  
    2020
    2121
    22 #ifndef _FACTORY_H
    23 #define _FACTORY_H
     22#ifndef __FACTORY_H
     23#define __FACTORY_H
    2424
    2525class BaseObject;
     
    2727#include "parser/tinyxml/tinyxml.h"
    2828#include "base_object.h"
    29 #include <vector>
    30 #include <list>
     29#include <map>
    3130
    3231/**
     
    3433 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    3534 */
    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())
    3837
    3938//! The Factory is a loadable object handler
    40 class Factory : public BaseObject {
    41 
    42  public:
     39class Factory : public BaseObject
     40{
     41  //! Declare the ObjectList at the BaseObject List
     42  ObjectListDeclaration(Factory);
     43public:
    4344  virtual ~Factory ();
    4445
    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);
    4649
    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; };
    5054
    5155
    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();
    5558
    56   protected:
    57     Factory (const std::string& factoryName, ClassID classID);
    58     virtual BaseObject* fabricateObject(const TiXmlElement* root = NULL) const = 0;
     59protected:
     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;
    5967
    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
     68private:
     69  //! Copy Constructor is hidden.
     70  Factory (const Factory&) {};
     71
     72protected:
     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
    6481};
    6582
     
    7087template<class T> class tFactory : public Factory
    7188{
    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)
     89public:
     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)
    8096  {  }
     97  /**
     98   * @brief copy constructor
     99   * @param factory the Factory to copy
     100   */
     101  tFactory (const tFactory& factory) : Factory(factory._classID) {};
    81102
    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  }
    92112};
    93113
  • trunk/src/lib/util/loading/game_loader.cc

    r9110 r9869  
    2020#include "game_loader.h"
    2121#include "util/loading/load_param.h"
    22 
    23 #include "shell_command.h"
     22#include "util/loading/resource_manager.h"
     23#include "debug.h"
    2424#include "campaign.h"
    2525
    26 #include "util/loading/resource_manager.h"
    27 
    2826#include "key_mapper.h"
    2927
    30 
    31 
    32 SHELL_COMMAND(quit, GameLoader, stop)
    33 ->describe("quits the game")
    34 ->setAlias("orxoquit");
    35 
     28ObjectListDefinition(GameLoader);
    3629
    3730GameLoader* GameLoader::singletonRef = NULL;
     
    4336GameLoader::GameLoader ()
    4437{
    45   this->setClassID(CL_GAME_LOADER, "GameLoader");
     38  this->registerObject(this, GameLoader::_objectList);
    4639  this->setName("GameLoader");
    4740  this->bRun = true;
     
    5750    delete this->currentCampaign;
    5851  this->currentCampaign = NULL;
    59  
     52
    6053  GameLoader::singletonRef = NULL;
    6154}
     
    9083{
    9184  ErrorMessage errorCode;
    92   std::string campaignName = ResourceManager::getFullName(fileName);
     85  std::string campaignName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    9386  if (!campaignName.empty())
    9487  {
     
    110103{
    111104  ErrorMessage errorCode;
    112   std::string campaignName = ResourceManager::getFullName(fileName);
     105  std::string campaignName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName);
    113106  if (!campaignName.empty())
    114107  {
  • trunk/src/lib/util/loading/game_loader.h

    r7868 r9869  
    3838class GameLoader : public EventListener
    3939{
    40  public:
     40  ObjectListDeclaration(GameLoader);
     41  public:
    4142  virtual ~GameLoader ();
    4243  /**  this class is a singleton class @returns an instance of itself  */
  • trunk/src/lib/util/loading/load_param.cc

    r9406 r9869  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
    1717
    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"
    2322/**
    24  * Constructs a new LoadParameter
     23 * @brief Constructs a new LoadParameter
    2524 * @param root the XML-element to load this Parameter from
    2625 * @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.).
    2927 */
    30 CLoadParam::CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle)
    31   :  object(object), paramName(paramName)
     28LoadParamBase::LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle)
     29    :  paramName(paramName), inLoadCycle(inLoadCycle)
    3230{
    33   this->inLoadCycle = inLoadCycle;
    34 
    3531  // determin the LoadString.
    3632  if (likely(!inLoadCycle))
     
    4036  else
    4137    this->loadElem = NULL;
     38}
    4239
    43   // set the Executor.
    44   this->executor = executor;
    4540
    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 */
     46void 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);
    4853}
    4954
    5055/**
    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.
    5557 */
    56 CLoadParam::~CLoadParam()
     58void LoadParamBase::setDescriptionValues(const ClassID& classID, unsigned int paramCount, const MultiType* const defaultValues, bool retVal)
    5759{
    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);
    7262}
    73 
    74 /**
    75  * @brief set the default values of the executor
    76  * @param value0 the first default value
    77  * @param value1 the second default value
    78  * @param value2 the third default value
    79  * @param value3 the fourth default value
    80  * @param value4 the fifth default value
    81  */
    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 Parameter
    96  * @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 takes
    133  * @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   else
    148 {
    149       if (likely(!multi))
    150         this->loadString = grabParameter(root, paramName);
    151       else
    152 {
    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 class
    166     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 parsed
    182         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 
    21963
    22064
     
    22771 * @returns the Value of the parameter if found, NULL otherwise
    22872*/
    229 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName)
     73std::string LoadParamBase::grabParameter(const TiXmlElement* root, const std::string& parameterName)
    23074{
    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
    24279  {
    243     if( node->ToText()) return node->Value();
    244     node = node->NextSibling();
     80    static std::string empty("");
     81    return empty;
    24582  }
    246   return "";
    24783}
    24884
     
    25288 * @returns the Element of the parameter if found, NULL otherwise
    25389 */
    254 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName)
     90const TiXmlElement* LoadParamBase::grabParameterElement(const TiXmlElement* root, const std::string& parameterName)
    25591{
    25692  const TiXmlElement* element;
     
    271107  return NULL;
    272108}
    273 
    274 
    275 
  • trunk/src/lib/util/loading/load_param.h

    r8048 r9869  
    2222#define _LOAD_PARAM_H
    2323
    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"
    2527
    26 #include "executor/executor.h"
    27 #include "executor/executor_xml.h"
     28#include "parser/tinyxml/tinyxml.h"
    2829
    2930// Forward Declaration //
    3031class LoadClassDescription;
    3132class LoadParamDescription;
    32 class MultiType;
    33 
     33class TiXmlElement;
    3434
    3535/**
    3636 * Loads a Parameter from ROOT named PARAMETER_NAME
    37  * onto OBJECT of CLASS, trough the FUNCTION
     37 * onto OBJECT of CLASS, trough FUNCTION
    3838 * @param ROOT the TiXmlElement to load the Parameter from
    3939 * @param PARAMETER_NAME the Name of the Parameter to load
     
    4343 */
    4444#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)
    4646
     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 */
    4755#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)
    5657
    5758/**
     
    7879}
    7980
     81
    8082/**************************
    8183**** REAL DECLARATIONS ****
    8284**************************/
    83 //! abstract Base class for a Loadable parameter
    84 class CLoadParam : public BaseObject
     85//!< A BaseClass for all LoadParam's.
     86class LoadParamBase
    8587{
    86   public:
    87     CLoadParam(const TiXmlElement* root, const std::string& paramName, BaseObject* object, Executor* executor, bool inLoadCycle = false);
    88     virtual ~CLoadParam();
     88protected:
     89  LoadParamBase(const TiXmlElement* root, const std::string& paramName, bool inLoadCycle = false);
    8990
    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);
     91protected:
     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
     95public:
     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
     99protected:
     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};
    95105
    96106
    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.
     108template <class OperateClass> class CLoadParam : public LoadParamBase
     109{
     110public:
     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);
    102153
    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;
     154private:
     155  Executor<const SubString, OperateClass>*         executor;            //!< The Executor, that actually executes the Loading process.
     156  OperateClass*                                    object;              //!< The Object this LoadParam operates on.
    109157};
    110158
    111 // helper function
    112 
    113 std::string grabParameter(const TiXmlElement* root, const std::string& parameterName);
    114 const TiXmlElement* grabParameterElement(const TiXmlElement* root, const std::string& parameterName);
    115 
    116159#endif /* _LOAD_PARAM_H */
  • trunk/src/lib/util/loading/load_param_description.cc

    r8362 r9869  
    1717
    1818#include "multi_type.h"
    19 #include <stdarg.h>
    2019#include "debug.h"
    2120
    2221/**
     22 * @brief Creates a Description of a LoadParam
    2323 * @param paramName the name of the parameter to load
    2424 */
    2525LoadParamDescription::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{ }
    4828
    4929/**
     
    5232void LoadParamDescription::setDescription(const std::string& descriptionText)
    5333{
    54   this->description = descriptionText;
     34  this->_description = descriptionText;
    5535}
    5636
    5737/**
    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
    5942 */
    60 void LoadParamDescription::print() const
     43void LoadParamDescription::setValues(unsigned int paramCount,
     44                                     const MultiType* const defaultValues,
     45                                     bool retVal)
    6146{
    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)
    6449  {
    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()));
    9852  }
    99   PRINT(3)("</%s>", this->paramName.c_str());
    100   if (!this->description.empty())
    101     PRINT(3)(" -- %s", this->description.c_str());
    102   // default values
    103   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       else
    115       {
    116         PRINT(3)("%s", this->defaultValues[i]);
    117       }
    118     }
    119     PRINT(3)(")");
    120   }
    121   PRINT(3)("\n");
    122 }
    12353
    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 executed
    131  */
    132 bool LoadClassDescription::parametersDescription = false;
    133 
    134 /**
    135  * @param className the name of the class to be loadable
    136  */
    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 well
    149  */
    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;
    17254}
    17355
    17456
    17557/**
    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.
    18161 */
    182 LoadClassDescription* LoadClassDescription::addClass(const std::string& className)
     62void LoadParamDescription::print(FILE* stream, bool withComments) const
    18363{
    184   if (LoadClassDescription::classList != NULL)
     64  fprintf(stream, " <%s>", this->_name.c_str());
     65  for (unsigned int i = 0; i < this->_parameterCount; i++)
    18566  {
    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)
    18879    {
    189       if ((*it)->className == className)
     80      fprintf(stream, " (Default: ");
     81      for (unsigned int i = 0; i < this->_parameterCount; i++)
    19082      {
    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        }
    19293      }
    193       it++;
     94      fprintf(stream, ")");
    19495    }
     96    if (!this->_description.empty() || this->_parameterCount > 0)
     97      fprintf(stream, " -->");
    19598  }
    196   return new LoadClassDescription(className);
     99  fprintf(stream, "\n");
    197100}
    198101
    199 /**
    200  *  does the same as addClass(const std::string& className), but with params
    201  * @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   }
    214102
    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 parameters
    223  * @param fileName prints the output to a File
    224  * @todo implement it
    225  */
    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   else
    247     PRINT(3)("no Classes defined so far\n");
    248   PRINT(3)("===============================================================\n");
    249 }
    250 
    251 /**
    252  * searches for classes, which beginn with classNameBegin
    253  * @param classNameBegin the beginning string of a Class
    254  * @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   /// FIXME
    260   // NOT USED
    261 /*  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  
    1515
    1616/*!
    17  * @file load_param.h
     17 * @file load_param_description.h
    1818 * A Class and macro-functions, that makes our lives easy to load-in parameters
    1919 */
     
    2222#define _LOAD_PARAM_DESCRIPTION_H
    2323
    24 #include "base_object.h"
    25 #include <list>
     24#include <vector>
     25#include <string>
    2626
    2727// Forward Declaration //
     
    3434class LoadParamDescription
    3535{
    36   friend class LoadParam;
    37   friend class LoadClassDescription;
    3836public:
    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; };
    4145
    4246  void setDescription(const std::string& descriptionText);
     47  void setValues(unsigned int paramCount,
     48                 const MultiType* const defaultValues,
     49                 bool retVal = false);
     50
    4351  /** @returns the descriptionString */
    44   const std::string& getDescription() { return this->description; };
     52  const std::string& description() { return this->_description; };
    4553
    46   void print() const;
     54  void print(FILE* stream = stdout, bool withComments = true) const;
    4755
    4856private:
    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.
    5560
    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.
    7963};
    8064
  • trunk/src/lib/util/loading/resource.cc

    r9406 r9869  
    1414*/
    1515
    16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
    1717
    1818#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
     24namespace Resources
    2725{
    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  }
    30292}
    31 
    32 /**
    33  * standard deconstructor
    34  */
    35 Resource::~Resource ()
    36 {
    37   // delete what has to be deleted here
    38 }
  • trunk/src/lib/util/loading/resource.h

    r7195 r9869  
    88
    99#include "base_object.h"
    10 #include "multi_type.h"
    1110#include <string>
     11#include <vector>
     12#include <set>
    1213
    13 // FORWARD DECLARATION
     14#include "filesys/directory.h"
     15
     16//! A Namespace Resources and ResourceHandling is defined in.
     17namespace 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  };
    1476
    1577
    1678
    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  };
    31157
    32158
    33159
    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);
    39170
    40  public:
    41    Resource(const std::string& fileName);
    42   virtual ~Resource();
     171  public:
     172    Resource(Resources::Type* type);
     173    virtual ~Resource();
    43174
    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; };
    47179
    48  private:
    49    std::string       fileName;
     180    std::string locateFile(const std::string& fileName) const;
    50181
    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);
    54185
    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}
    57194
    58195#endif /* _RESOURCE_H */
  • trunk/src/lib/util/loading/resource_manager.cc

    r9406 r9869  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOAD
    1717
    18 #include "util/loading/resource_manager.h"
    19 #include "substring.h"
     18#include "resource_manager.h"
    2019#include "debug.h"
    2120
    2221#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
     25namespace Resources
    5826{
    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  }
    64256}
    65 
    66 //! Singleton Reference to the ResourceManager
    67 ResourceManager* ResourceManager::singletonRef = NULL;
    68 
    69 /**
    70  * @brief standard destructor
    71 */
    72 ResourceManager::~ResourceManager ()
    73 {
    74   // deleting the Resources-List
    75   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 directory
    85  * @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   else
    101   {
    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 directory
    109  * @param dataDir the DataDirectory.
    110  *
    111  * this is essentially the same as setDataDir, but it ommits the error-message
    112  */
    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 if
    132  * @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_TEXTURES
    148 /**
    149  * @brief adds a new Path for Images
    150  * @param imageDir The path to insert
    151  * @returns true, if the Path was well and injected (or already existent within the list)
    152    false otherwise
    153 */
    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 Directory
    162   if (File(newDir).isDirectory())
    163   {
    164     // check if the Directory has been added before
    165     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 List
    175     this->imageDirs.push_back(newDir);
    176     return true;
    177   }
    178   else
    179   {
    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 resources
    188  * @param fileName: The fileName of the resource to load
    189  * @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_MODEL
    200 #define __IF_OK
    201   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_AUDIO
    217 #ifdef __IF_OK
    218   else
    219 #endif
    220 #define __IF_OK
    221     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_TEXT
    229 #ifdef __IF_OK
    230     else
    231 #endif
    232 #define __IF_OK
    233       if (!strncasecmp(fileName.c_str()+(fileName.size()-4), ".ttf", 4))
    234         tmpType = TTF;
    235 #endif /* NO_TEXT */
    236 #ifndef NO_SHADERS
    237 #ifdef __IF_OK
    238       else
    239 #endif
    240 #define __IF_OK
    241         if (!strncasecmp(fileName.c_str()+(fileName.size()-5), ".vert", 5))
    242           tmpType = SHADER;
    243 #endif /* NO_SHADERS */
    244 #ifndef NO_TEXTURES
    245 #ifdef __IF_OK
    246         else
    247 #else
    248   if
    249 #endif
    250           tmpType = IMAGE;
    251 #endif /* NO_TEXTURES */
    252 #undef __IF_OK
    253   return this->load(fileName, tmpType, prio, param0, param1, param2);
    254 }
    255 
    256 /**
    257  * @brief caches a Resource
    258  *
    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 Resource
    264  * 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 Resource
    272   tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
    273   // otherwise load it
    274   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   else
    284     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 copy
    290  * @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   else
    301     return NULL;
    302 }
    303 
    304 
    305 /**
    306  * @brief loads resources
    307  * @param fileName: The fileName of the resource to load
    308  * @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 Resource
    322   tmpResource = this->locateResourceByInfo(fileName, type, param0, param1, param2);
    323   // otherwise load it
    324   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   else
    338     return NULL;
    339 }
    340 
    341 
    342 /**
    343  * @brief loads resources for internal purposes
    344  * @param fileName: The fileName of the resource to load
    345  * @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 Resource
    356   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 ResourceType
    366   switch(type)
    367   {
    368 #ifndef NO_MODEL
    369     case OBJ:
    370       if (param0.getType() != MT_NULL)
    371         tmpResource->param[0] = param0;
    372       else
    373         tmpResource->param[0] = 1.0f;
    374 
    375       if(File(fullName).isFile())
    376         tmpResource->pointer = new OBJModel(fullName, tmpResource->param[0].getFloat());
    377       else
    378       {
    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       else
    387         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_TEXT
    426     case TTF:
    427       if (param0 != MT_NULL)
    428       {
    429         assert(param0.getInt() >= 0);
    430         tmpResource->param[0] = param0;
    431       }
    432       else
    433         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       else
    438         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_AUDIO
    442     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_TEXTURES
    452     case IMAGE:
    453       if (param0 != MT_NULL)
    454         tmpResource->param[0] = param0;
    455       else
    456         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       else
    463       {
    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_SHADERS
    481     case SHADER:
    482       if(File(fullName).isFile())
    483       {
    484         if (param0 != MT_NULL)
    485         {
    486           MultiType param = param0; /// HACK
    487           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         else
    495         {
    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   else
    513   {
    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 Resource
    522  * @param pointer: The pointer to free
    523  * @param prio: the PriorityLevel to unload this resource
    524  * @returns true if successful (pointer found, and deleted), false otherwise
    525 */
    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   else
    535   {
    536     PRINTF(2)("Resource not Found %p\n", pointer);
    537     return false;
    538   }
    539 }
    540 
    541 /**
    542  * @brief unloads a Resource
    543  * @param resource: The resource to unloade
    544  * @param prio the PriorityLevel to unload this resource
    545  * @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     else
    566       PRINTF(4)("Resource %s not removed, because there are still %d References to it.\n", resource->name.c_str(), resource->count);
    567   }
    568   else
    569     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 prio
    576  * @param prio The priority to delete
    577 */
    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         else
    593         {
    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 information
    613  * @param fileName: The name to look for
    614  * @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) const
    622 {
    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_MODEL
    632         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_TEXT
    663         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_SHADERS
    674         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_TEXTURES
    685         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 Pointer
    710  * @param pointer the Pointer to search for
    711  * @returns a Pointer to the Resource if found, NULL otherwise.
    712  */
    713 Resource* ResourceManager::locateResourceByPointer(const void* pointer) const
    714 {
    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-function
    757  * @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 check
    781  * @returns The full name of the file, including the DataDir, and NULL if the file does not exist
    782  * !!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   else
    793     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 otherwise
    801  */
    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   else
    813     retVal = false;
    814   return retVal;
    815 }
    816 
    817 
    818 /**
    819  * @brief outputs debug information about the ResourceManager
    820  */
    821 void ResourceManager::debug() const
    822 {
    823   PRINT(0)("=RM===================================\n");
    824   PRINT(0)("= RESOURCE-MANAGER DEBUG INFORMATION =\n");
    825   PRINT(0)("======================================\n");
    826   // if it is not initialized
    827   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 String
    870  * @param type the ResourceType to translate
    871  * @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 Type
    881  * @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 ResourceTypes
    893  */
    894 const char* ResourceManager::resourceNames[] =
    895   {
    896 #ifndef NO_MODEL
    897     "ObjectModel",
    898     "PrimitiveModel",
    899     "MD2-Data",
    900     "MD3-Data",
    901     "MD3-Config"
    902 #endif
    903 #ifndef NO_TEXT
    904     "Font",
    905 #endif
    906 #ifndef NO_AUDIO
    907     "Wav",
    908     "mp3",
    909     "ogg",
    910 #endif
    911 #ifndef NO_TEXTURES
    912     "Texture",
    913 #endif
    914 #ifndef NO_SHADERS
    915     "Shader",
    916 #endif
    917 
    918   };
  • trunk/src/lib/util/loading/resource_manager.h

    r8724 r9869  
    11/*!
    22 * @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 */
    184
    195#ifndef _RESOURCE_MANAGER_H
    206#define _RESOURCE_MANAGER_H
    217
    22 #include "base_object.h"
     8#include "resource.h"
    239#include "filesys/file.h"
     10#include "filesys/directory.h"
    2411
    25 #include "multi_type.h"
    26 #include <vector>
     12namespace Resources
     13{
    2714
    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; };
    5425
    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);
    6930
    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);
    7535
    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; };
    7940
    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; };
    8248
     49    //////////////////////////
     50    //// GENERAL QUERIES ////
     51    /** @returns the Types of Resources */
     52    const std::vector<Resources::Type*> resourceTypes() const { return _resourceTypes; };
    8353
    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);
    10056
    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); };
    10461
     62    void unloadAllBelowKeepLevel(const Resources::KeepLevel& keepLevel);
     63    void unloadAllBelowKeepLevelINT(unsigned int level) { unloadAllBelowKeepLevel(level); };
    10564
    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;
    10968
    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();
    11372
    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
    12175
    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.
    12578
    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
    13080
    131   void debug() const;
     81    std::vector<std::string>           _keepLevelNames;     //!< Names of KeepLevels @see Resources::KeepLevel
     82    KeepLevel                          _defaultKeepLevel;   //!< The default KeepLevel.
     83  };
    13284
    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}
    15686
    15787#endif /* _RESOURCE_MANAGER_H */
  • trunk/src/lib/util/multi_type.cc

    r9406 r9869  
    3333  {
    3434    default:
    35       this->value.Float = 0.0f;
    36       break;
     35    this->value.Float = 0.0f;
     36    break;
    3737    case MT_BOOL:
    38       this->value.Bool = false;
    39       break;
     38    this->value.Bool = false;
     39    break;
    4040    case MT_INT:
    41       this->value.Int = 0;
    42       break;
     41    this->value.Int = 0;
     42    break;
    4343    case MT_FLOAT:
    44       this->value.Float = 0.0f;
    45       break;
     44    this->value.Float = 0.0f;
     45    break;
    4646    case MT_CHAR:
    47       this->value.Char = '\0';
    48       break;
     47    this->value.Char = '\0';
     48    break;
    4949    case MT_STRING:
    50       this->storedString = "";
    51       break;
     50    this->storedString = "";
     51    break;
    5252  }
    5353}
     
    142142  {
    143143    case MT_NULL:
    144       return true;
     144    return true;
    145145    case MT_BOOL:
    146       return (this->value.Bool == mt.value.Bool);
     146    return (this->value.Bool == mt.value.Bool);
    147147    case MT_INT:
    148       return (this->value.Int == mt.value.Int);
     148    return (this->value.Int == mt.value.Int);
    149149    case MT_CHAR:
    150       return (this->value.Char == mt.value.Char);
     150    return (this->value.Char == mt.value.Char);
    151151    case MT_FLOAT:
    152       return (this->value.Float == mt.value.Float);
     152    return (this->value.Float == mt.value.Float);
    153153    case MT_STRING:
    154       return (this->storedString == mt.storedString);
     154    return (this->storedString == mt.storedString);
    155155    default:
    156       return false;
     156    return false;
    157157  }
    158158}
     
    171171  {
    172172    case MT_BOOL:
    173       this->setBool(this->getBool());
    174       break;
     173    this->setBool(this->getBool());
     174    break;
    175175    case MT_INT:
    176       this->setInt(this->getInt());
    177       break;
     176    this->setInt(this->getInt());
     177    break;
    178178    case MT_FLOAT:
    179       this->setFloat(this->getFloat());
    180       break;
     179    this->setFloat(this->getFloat());
     180    break;
    181181    case MT_CHAR:
    182       this->setChar(this->getChar());
    183       break;
     182    this->setChar(this->getChar());
     183    break;
    184184    case MT_STRING:
    185       this->setString(this->getString());
    186       break;
     185    this->setString(this->getString());
     186    break;
    187187    default:
    188       this->type = type;
     188    this->type = type;
    189189  }
    190190}
     
    195195 *
    196196 * This is a pure Value copy. The current type will be preserved.
    197  *
    198  * @TODO speedup
    199197 */
    200198void MultiType::setValueOf(const MultiType& mt)
     
    257255}
    258256
     257/**
     258 * @brief stores any value to the string.
     259 * @note this Value can be grabbed by using the getStoredString function.
     260 */
     261void MultiType::storeString()
     262{
     263  if (!(this->type & MT_STRING))
     264    this->storedString = this->getString();
     265}
    259266
    260267/**************************
     
    275282  else if (this->type & MT_STRING) return (this->storedString == "true" ||
    276283                                            this->storedString == "TRUE" ||
    277                                             this->storedString != "0"); //! @TODO make this better...
     284                                            this->storedString != "0"); // TODO make this better...
    278285
    279286  return false;
     
    381388 * @brief returns a Constant string (actually this is slower than getString()
    382389 * @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().
    384392 */
    385393const std::string& MultiType::getConstString() const
    386394{
    387 
    388395  MultiType::constString = this->getString();
    389396  return MultiType::constString;
    390397}
    391398
     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 */
     411const std::string& MultiType::getStoredString() const
     412{
     413  MultiType::constString = this->getString();
     414  return MultiType::constString;
     415}
    392416
    393417/**
     
    433457  {
    434458    case MT_BOOL:
    435       this->setBool(false);
    436       break;
     459    this->setBool(false);
     460    break;
    437461    case MT_INT:
    438       this->setInt(0);
    439       break;
     462    this->setInt(0);
     463    break;
    440464    case MT_FLOAT:
    441       this->setFloat(0.0f);
    442       break;
     465    this->setFloat(0.0f);
     466    break;
    443467    case MT_CHAR:
    444       this->setChar('\0');
    445       break;
     468    this->setChar('\0');
     469    break;
    446470    case MT_STRING:
    447       this->setString("");
    448       break;
     471    this->setString("");
     472    break;
    449473    default:
    450474#ifdef DEBUG
    451       PRINTF(2)("Unknown Type not reseting\n");
     475    PRINTF(2)("Unknown Type not reseting\n");
    452476#endif
    453       break;
     477    break;
    454478  }
    455479}
     
    465489  {
    466490    case MT_BOOL:
    467       return MultiType::typeNames[1];
     491    return MultiType::typeNames[1];
    468492    case MT_INT:
    469       return MultiType::typeNames[2];
     493    return MultiType::typeNames[2];
    470494    case MT_FLOAT:
    471       return MultiType::typeNames[3];
     495    return MultiType::typeNames[3];
    472496    case MT_CHAR:
    473       return MultiType::typeNames[4];
     497    return MultiType::typeNames[4];
    474498    case MT_STRING:
    475       return MultiType::typeNames[5];
     499    return MultiType::typeNames[5];
    476500    default:
    477       return MultiType::typeNames[0];
     501    return MultiType::typeNames[0];
    478502  }
    479503}
  • trunk/src/lib/util/multi_type.h

    r8035 r9869  
    1717  MT_BOOL            = 1,                  //!< A bool Value.
    1818  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
    2121  MT_FLOAT           = 4,                  //!< A float Value.
    2222  MT_CHAR            = 8,                  //!< A single char.
     
    4444
    4545    MultiType& operator=(const MultiType& mt);
     46    /** @param value the value to set (here a bool) @returns the MultiType where this the bool is stored */
    4647    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 */
    4749    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 */
    4851    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 */
    4953    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 */
    5055    MultiType& operator=(const std::string& value) { this->setString(value); return *this; };
    5156
    5257    bool operator==(const MultiType& mt) const;
     58    /** @param value the value to compare this MultiType against @returns true if comparison was io */
    5359    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 */
    5461    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 */
    5563    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 */
    5665    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 */
    5767    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 */
    5869    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 */
    5971    bool operator!=(MT_Type type) const { return (this->type != type); }
    6072
     
    6880
    6981    // for your convenience.
     82    /** @param value the value to set. Here a bool */
    7083    inline void setValue(bool value) { this->setBool(value); };
     84    /** @param value the value to set. Here an int */
    7185    inline void setValue(int value) { this->setInt(value); };
     86    /** @param value the value to set. Here a float */
    7287    inline void setValue(float value) { this->setFloat(value); };
     88    /** @param value the value to set. Here a char */
    7389    inline void setValue(char value) { this->setChar(value); };
     90    /** @param value the value to set. Here a char array (string) */
    7491    inline void setValue(const char* value) { this->setString(value); };
     92    /** @param value the value to set. Here a string */
    7593    inline void setValue(const std::string& value) { this->setString(value); };
    7694    void setValueOf(const MultiType& mt);
     
    7997    inline MT_Type getType() const { return this->type; };
    8098
     99    void storeString();
    81100
    82101    /* RETRIEVING FUNCTIONS */
     
    88107    std::string getString() const;
    89108    const std::string& getConstString() const;
     109    const std::string& getStoredString() const;
    90110
    91111    void reset();
  • trunk/src/lib/util/sigslot/signal.h

    r9406 r9869  
    9696  {
    9797  public:
     98    virtual ~_connection_base0() {};
    9899    virtual has_slots<mt_policy>* getdest() const = 0;
    99100    virtual void emit() = 0;
     
    106107  {
    107108  public:
     109    virtual ~_connection_base1() {};
    108110    virtual has_slots<mt_policy>* getdest() const = 0;
    109111    virtual void emit(arg1_type) = 0;
     
    116118  {
    117119  public:
     120    virtual ~_connection_base2() {};
    118121    virtual has_slots<mt_policy>* getdest() const = 0;
    119122    virtual void emit(arg1_type, arg2_type) = 0;
     
    126129  {
    127130  public:
     131    virtual ~_connection_base3() {};
    128132    virtual has_slots<mt_policy>* getdest() const = 0;
    129133    virtual void emit(arg1_type, arg2_type, arg3_type) = 0;
     
    136140  {
    137141  public:
     142    virtual ~_connection_base4() {};
    138143    virtual has_slots<mt_policy>* getdest() const = 0;
    139144    virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type) = 0;
     
    147152  {
    148153  public:
     154    virtual ~_connection_base5() {};
    149155    virtual has_slots<mt_policy>* getdest() const = 0;
    150156    virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type,
     
    161167  {
    162168  public:
     169    virtual ~_connection_base6() {};
    163170    virtual has_slots<mt_policy>* getdest() const = 0;
    164171    virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type,
     
    175182  {
    176183  public:
     184    virtual ~_connection_base7() {};
    177185    virtual has_slots<mt_policy>* getdest() const = 0;
    178186    virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type,
     
    189197  {
    190198  public:
     199    virtual ~_connection_base8() {};
    191200    virtual has_slots<mt_policy>* getdest() const = 0;
    192201    virtual void emit(arg1_type, arg2_type, arg3_type, arg4_type, arg5_type,
  • trunk/src/lib/util/substring.cc

    r9406 r9869  
    5151 * @param delimiters multiple set of characters at what to split. (delimiters)
    5252 * @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.
    5354 * @param escapeChar The Escape Character that overrides splitters commends and so on...
    5455 * @param safemode_char within these characters splitting won't happen
     
    109110/** @brief Helper that gets you a String consisting of all WhiteSpaces and the Comma */
    110111const std::string SubString::WhiteSpacesWithComma = " \n\t,";
     112/** An Empty SubString */
     113const SubString SubString::NullSubString = SubString();
    111114
    112115/**
     
    145148 * @brief comparator.
    146149 * @param subString the SubString to compare against this one.
     150 * @param length how many entries to compare. (from 0 to length)
    147151 * @returns true if the Stored Strings match
    148152 */
     
    273277 * @brief splits line into tokens and stores them in ret.
    274278 * @param ret the Array, where the Splitted strings will be stored in
    275  * @param offsets an Array of Offsets, here the distance from the inputstring
    276279 * to the beginning of the current token is stored
    277280 * @param line the inputLine to split
    278281 * @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.
    280283 * @param emptyEntries: if empty Strings are added to the List of Strings.
    281284 * @param escape_char: Escape carater (escapes splitters)
  • trunk/src/lib/util/substring.h

    r9406 r9869  
    3333{
    3434public:
     35  //! An enumerator for the State the Parser is in
    3536  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.
    4142  } SPLIT_LINE_STATE;
    4243
     
    4849            const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false,
    4950            char escapeChar ='\\', char safemode_char = '"', char comment_char = '\0');
     51  SubString(unsigned int argc, const char** argv);
    5052  /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */
    51   SubString(unsigned int argc, const char** argv);
    5253  SubString(const SubString& subString) { *this = subString; };
    5354  SubString(const SubString& subString, unsigned int subSetBegin);
     
    110111  static const std::string WhiteSpaces;
    111112  static const std::string WhiteSpacesWithComma;
     113  static const SubString   NullSubString;
    112114
    113115private:
Note: See TracChangeset for help on using the changeset viewer.