Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 565 for code


Ignore:
Timestamp:
Dec 17, 2007, 10:39:12 AM (17 years ago)
Author:
scheusso
Message:

added class BaseEntity:

  • !!! please inherit from this class in future (instead of Entity/WorldEntity/BaseObject):
  • this class is able to be synchronised over the network (or at least created so far)
Location:
code/branches/FICN
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/CMakeLists.txt

    r547 r565  
    4646
    4747# pipe $FLAGS to the compiler, and add some local flags. force -O2!
     48#SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O2 -Wall -g -ggdb")
    4849SET(CMAKE_C_FLAGS "$ENV{CFLAGS} -O2 -Wall -g -ggdb")
    49 SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O2 -Wall -g -ggdb")
     50#SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -O2 -Wall -g -ggdb")
     51SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall -g -ggdb")
    5052SET(CMAKE_LD_FLAGS "$ENV{LDFLAGS}")
    5153
  • code/branches/FICN/bin/levels/sample.oxw

    r541 r565  
    2626                <Skybox src="Orxonox/BlueStarSkyBox" />
    2727
    28                 <Entity name="ASSF" src="assf2.mesh" node="OgreHeadNode" />
     28                <BaseEntity name="ASSF" src="assf2.mesh" node="OgreHeadNode" />
    2929
    3030                <SceneNode name="Ogre1" pos="0,200,0" />
  • code/branches/FICN/src/network/Client.cc

    r514 r565  
    127127    if(!isConnected)
    128128      return false;
    129     if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )));
     129    if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))
    130130      return client_connection.sendPackets();
    131131    // send packets
  • code/branches/FICN/src/network/Synchronisable.cc

    r531 r565  
    2626  datasize=0;
    2727  objectID=idCounter++;
    28   //registerAllVariables();
     28//   registerAllVariables();
    2929}
    3030
     
    4141 * @param size size of the datatype the variable consists of
    4242 */
    43 void Synchronisable::registerVar(const void *var, int size){
     43void Synchronisable::registerVar(const void *var, int size, variableType t){
    4444  // create temporary synch.Var struct
    45   synchronisableVariable temp={size, var};
     45  synchronisableVariable temp={size, var, t};
    4646  // increase datasize
    4747  datasize+=sizeof(int)+size;
     
    6565  for(i=syncList.begin(); i!=syncList.end(); i++){
    6666    // increase size (size of variable and size of size of variable ;)
    67     totalsize+=sizeof(int)+i->size;
     67    if(i->type == STRING)
     68      totalsize+=sizeof(int)+((std::string *)i->var)->length()+1;
     69    else
     70      totalsize+=sizeof(int)+i->size;
    6871  }
    6972  syncData retVal;
     
    7780  int n=0;
    7881  for(i=syncList.begin(); n<totalsize && i!=syncList.end(); i++){
    79         //CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID*
    8082    std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
    8183    n+=sizeof(int);
    82     //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i
    83     std::memcpy(retVal.data+n, (const void*)(i->var), i->size);
    84     n+=i->size;
     84    switch(i->type){
     85    case STRING:
     86      std::memcpy(retVal.data+n, (const void *)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1);
     87      n+=((std::string *)i->var)->length()+1;
     88      break;
     89    case DATA:
     90      std::memcpy(retVal.data+n, ((const void*)i->var), i->size);
     91      n+=i->size;
     92      break;
     93    }
    8594  }
    8695  return retVal;
     
    107116  int n=0;
    108117  for(i=syncList.begin(); n<datasize && i!=syncList.end(); i++){
    109         //CHANGED: i->size TO (const void*)(&(i->size)) memcpy WANTS A CONST VOID* SO CONVERT INT TO CONST VOID*
    110118    std::memcpy(retVal.data+n, (const void*)(i->size), sizeof(int));
    111119    n+=sizeof(int);
    112     //CHANGED: i->var TO (const void*)(&(i->var)) SINCE var IS A POINTER, NO & BEFORE i
    113     std::memcpy(retVal.data+n, (const void*)(i->var), i->size);
    114     n+=i->size;
     120    switch(i->type){
     121      case DATA:
     122        std::memcpy(retVal.data+n, (const void*)(i->var), i->size);
     123        n+=i->size;
     124        break;
     125      case STRING:
     126        std::memcpy(retVal.data+n, (const void*)(((std::string *)i->var)->c_str()), ((std::string *)i->var)->length()+1);
     127        n+=((std::string *) i->var)->length()+1;
     128        break;
     129    }
    115130  }
    116131  return retVal;
     
    126141  std::list<synchronisableVariable>::iterator i;
    127142  for(i=syncList.begin(); i!=syncList.end(); i++){
    128     if((int)*data==i->size){
    129       data+=sizeof(int);
    130       //CHANGED: THIS FROM i->var TO (void*)i->var SINCE var IS A CONST VOID* AND memcpy NEEDS A VOID* AS FIRST ARGUMENT
    131       memcpy((void*)i->var, data, i->size);
    132       data+=i->size;
     143    if((int)*data==i->size || i->type==STRING){
     144      switch(i->type){
     145      case DATA:
     146        data+=sizeof(int);
     147        memcpy((void*)i->var, data, i->size);
     148        data+=i->size;
     149        break;
     150      case STRING:
     151        i->size = (int)*data;
     152        data+=sizeof(int);
     153        *((std::string *)i->var) = std::string((const char*)data);
     154        data += i->size;
     155        break;
     156      }
    133157    } else
    134158      return false; //there was some problem with registerVar
     
    142166 */
    143167int Synchronisable::getSize(){
    144   return datasize;
     168  int tsize=0;
     169  std::list<synchronisableVariable>::iterator i;
     170  for(i=syncList.begin(); i!=syncList.end(); i++){
     171    switch(i->type){
     172    case DATA:
     173      tsize+=i->size;
     174      break;
     175    case STRING:
     176      tsize+=((std::string *)i->var)->length()+1;
     177      break;
     178    }
     179  }
     180  return tsize;
    145181}
    146182
  • code/branches/FICN/src/network/Synchronisable.h

    r496 r565  
    1515#include <list>
    1616#include <iostream>
     17#include <string>
    1718
    1819#include "orxonox/core/CoreIncludes.h"
     
    2122namespace network {
    2223
     24enum variableType{
     25  DATA,
     26  STRING,
     27};
    2328 
    2429struct syncData{
     
    3237  int size;
    3338  const void *var;
     39  variableType type;
    3440}SYNCVAR;
    3541
     
    4046 * @author Oliver Scheuss
    4147*/
    42 class Synchronisable : public orxonox::OrxonoxClass{
     48class Synchronisable : virtual public orxonox::OrxonoxClass{
    4349public:
    44   Synchronisable();
    4550
    4651  virtual ~Synchronisable();
     
    4853  int classID;
    4954   
    50   void registerVar(const void *var, int size);
     55  void registerVar(const void *var, int size, variableType t);
    5156  syncData getData();
    5257  syncData getData(unsigned char *mem);
    5358  int getSize();
    5459  bool updateData(syncData vars);
    55   virtual void registerAllVariables() = 0;
    56 
     60  virtual void registerAllVariables()=0;
     61  virtual bool create(){return true;}
     62protected:
     63  Synchronisable();
    5764private:
    5865/*  bool removeObject(Iterator<Synchronisable> it);*/
  • code/branches/FICN/src/orxonox/objects/CMakeLists.txt

    r555 r565  
    1010  Skybox.cc
    1111  SceneNode.cc
     12  BaseEntity.cc
    1213  Entity.cc
    1314  Camera.cc
  • code/branches/FICN/src/orxonox/objects/WorldEntity.cc

    r554 r565  
    7474        }
    7575    }
     76   
     77    void WorldEntity::registerAllVariables(){
     78     
     79     
     80    }
    7681}
  • code/branches/FICN/src/orxonox/objects/WorldEntity.h

    r554 r565  
    77#include "OgreSceneManager.h"
    88#include "OgreSceneNode.h"
     9#include "network/Synchronisable.h"
    910
    1011namespace orxonox
    1112{
    12     class WorldEntity : public BaseObject, public Tickable
    13     {
    14         public:
    15             WorldEntity();
    16             ~WorldEntity();
     13  class WorldEntity : public BaseObject, public Tickable, public network::Synchronisable
     14  {
     15    public:
     16      WorldEntity();
     17      ~WorldEntity();
    1718
    18             void tick(float dt);
     19      void tick(float dt);
    1920
    20             inline Ogre::SceneNode* getNode()
    21                 { return this->node_; }
     21      inline Ogre::SceneNode* getNode()
     22          { return this->node_; }
    2223
    23             inline void setPosition(const Vector3& pos)
    24                 { this->node_->setPosition(pos); }
    25             inline void setPosition(Real x, Real y, Real z)
    26                 { this->node_->setPosition(x, y, z); }
    27             inline const Vector3& getPosition() const
    28                 { return this->node_->getPosition(); }
     24      inline void setPosition(const Vector3& pos)
     25          { this->node_->setPosition(pos); }
     26      inline void setPosition(Real x, Real y, Real z)
     27          { this->node_->setPosition(x, y, z); }
     28      inline const Vector3& getPosition() const
     29          { return this->node_->getPosition(); }
    2930
    30             inline void translate(const Vector3 &d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    31                 { this->node_->translate(d, relativeTo); }
    32             inline void translate(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    33                 { this->node_->translate(x, y, z, relativeTo); }
    34             inline void translate(const Matrix3 &axes, const Vector3 &move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    35                 { this->node_->translate(axes, move, relativeTo); }
    36             inline void translate(const Matrix3 &axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    37                 { this->node_->translate(axes, x, y, z, relativeTo); }
     31      inline void translate(const Vector3 &d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     32          { this->node_->translate(d, relativeTo); }
     33      inline void translate(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     34          { this->node_->translate(x, y, z, relativeTo); }
     35      inline void translate(const Matrix3 &axes, const Vector3 &move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     36          { this->node_->translate(axes, move, relativeTo); }
     37      inline void translate(const Matrix3 &axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     38          { this->node_->translate(axes, x, y, z, relativeTo); }
    3839
    39             inline void yaw(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    40                 { this->node_->yaw(angle, relativeTo); }
    41             inline void pitch(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    42                 { this->node_->pitch(angle, relativeTo); }
    43             inline void roll(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    44                 { this->node_->roll(angle, relativeTo); }
    45 
    46             inline void rotate(const Vector3 &axis, const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    47                 { this->node_->rotate(axis, angle, relativeTo); }
    48             inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
    49                 { this->node_->setDirection(x, y, z, relativeTo, localDirectionVector); }
    50             inline void setDirection(const Vector3 &vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
    51                 { this->node_->setDirection(vec, relativeTo, localDirectionVector); }
    52             inline void setOrientation(const Ogre::Quaternion quat)
    53                 { this->node_->setOrientation(quat); }
    54             inline void lookAt(const Vector3 &targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
    55                 { this->node_->lookAt(targetPoint, relativeTo, localDirectionVector); }
    56 
    57             inline void attachObject(Ogre::MovableObject *obj)
    58                 { this->node_->attachObject(obj); }
    59             inline void detachObject(Ogre::MovableObject *obj)
    60                 { this->node_->detachObject(obj); }
    61             inline void detachAllObjects()
    62                 { this->node_->detachAllObjects(); }
    63 
    64             inline void setVelocity(const Vector3& velocity)
    65                 { this->velocity_ = velocity; }
    66             inline void setVelocity(Real x, Real y, Real z)
    67                 { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
    68             inline const Vector3& getVelocity() const
    69                 { return this->velocity_; }
    70 
    71             inline void setAcceleration(const Vector3& acceleration)
    72                 { this->acceleration_ = acceleration; }
    73             inline void setAcceleration(Real x, Real y, Real z)
    74                 { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
    75             inline const Vector3& getAcceleration() const
    76                 { return this->acceleration_; }
    77 
    78             inline void setRotationAxis(const Vector3& axis)
    79                 { this->rotationAxis_ = axis; }
    80             inline void setRotationAxis(Real x, Real y, Real z)
    81                 { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; }
    82             inline const Vector3& getRotationAxis() const
    83                 { return this->rotationAxis_; }
    84 
    85             inline void setRotationRate(const Radian& angle)
    86                 { this->rotationRate_ = angle; }
    87             inline void setRotationRate(const Degree& angle)
    88                 { this->rotationRate_ = angle; }
    89             inline const Radian& getRotationRate() const
    90                 { return this->rotationRate_; }
    91 
    92             inline void setMomentum(const Radian& angle)
    93                 { this->momentum_ = angle; }
    94             inline void setMomentum(const Degree& angle)
    95                 { this->momentum_ = angle; }
    96             inline const Radian& getMomentum() const
    97                 { return this->momentum_; }
     40      inline void yaw(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     41          { this->node_->yaw(angle, relativeTo); }
     42      inline void pitch(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     43          { this->node_->pitch(angle, relativeTo); }
     44      inline void roll(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     45          { this->node_->roll(angle, relativeTo); }
    9846
    9947
    100             inline const Ogre::Quaternion& getOrientation()
    101                 { return this->node_->getOrientation(); }
     48      inline void rotate(const Vector3 &axis, const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     49          { this->node_->rotate(axis, angle, relativeTo); }
     50      inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
     51          { this->node_->setDirection(x, y, z, relativeTo, localDirectionVector); }
     52      inline void setDirection(const Vector3 &vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
     53          { this->node_->setDirection(vec, relativeTo, localDirectionVector); }
     54      inline void setOrientation(const Ogre::Quaternion quat)
     55          { this->node_->setOrientation(quat); }
     56      inline void lookAt(const Vector3 &targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
     57          { this->node_->lookAt(targetPoint, relativeTo, localDirectionVector); }
    10258
     59      inline void attachObject(Ogre::MovableObject *obj)
     60          { this->node_->attachObject(obj); }
     61      inline void detachObject(Ogre::MovableObject *obj)
     62          { this->node_->detachObject(obj); }
     63      inline void detachAllObjects()
     64          { this->node_->detachAllObjects(); }
    10365
    104         private:
    105             Ogre::SceneNode* node_;
    106             static unsigned int worldEntityCounter_s;
     66      inline void setVelocity(const Vector3& velocity)
     67          { this->velocity_ = velocity; }
     68      inline void setVelocity(Real x, Real y, Real z)
     69          { this->velocity_.x = x; this->velocity_.y = y; this->velocity_.z = z; }
     70      inline const Vector3& getVelocity() const
     71          { return this->velocity_; }
    10772
    108             bool bStatic_;
    109             Vector3 velocity_;
    110             Vector3 acceleration_;
    111             Vector3 rotationAxis_;
    112             Radian rotationRate_;
    113             Radian momentum_;
    114     };
     73      inline void setAcceleration(const Vector3& acceleration)
     74          { this->acceleration_ = acceleration; }
     75      inline void setAcceleration(Real x, Real y, Real z)
     76          { this->acceleration_.x = x; this->acceleration_.y = y; this->acceleration_.z = z; }
     77      inline const Vector3& getAcceleration() const
     78          { return this->acceleration_; }
     79
     80      inline void setRotationAxis(const Vector3& axis)
     81          { this->rotationAxis_ = axis; }
     82      inline void setRotationAxis(Real x, Real y, Real z)
     83          { this->rotationAxis_.x = x; this->rotationAxis_.y = y; this->rotationAxis_.z = z; }
     84      inline const Vector3& getRotationAxis() const
     85          { return this->rotationAxis_; }
     86
     87      inline void setRotationRate(const Radian& angle)
     88          { this->rotationRate_ = angle; }
     89      inline void setRotationRate(const Degree& angle)
     90          { this->rotationRate_ = angle; }
     91      inline const Radian& getRotationRate() const
     92          { return this->rotationRate_; }
     93
     94      inline void setMomentum(const Radian& angle)
     95          { this->momentum_ = angle; }
     96      inline void setMomentum(const Degree& angle)
     97          { this->momentum_ = angle; }
     98      inline const Radian& getMomentum() const
     99          { return this->momentum_; }
     100      inline const Ogre::Quaternion& getOrientation()
     101          { return this->node_->getOrientation(); }
     102     
     103    private:
     104      void registerAllVariables();
     105      Ogre::SceneNode* node_;
     106      static unsigned int worldEntityCounter_s;
     107
     108      bool bStatic_;
     109      Vector3 velocity_;
     110      Vector3 acceleration_;
     111      Vector3 rotationAxis_;
     112      Radian rotationRate_;
     113      Radian momentum_;
     114  };
    115115}
    116116
  • code/branches/FICN/src/orxonox/orxonox.cc

    r560 r565  
    154154        //if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
    155155          //cout << "maximal MouseX: " << maxMouseX << "\tminMouseX: " << minMouseX << endl;
     156        usleep(10);
    156157        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
    157158      }
Note: See TracChangeset for help on using the changeset viewer.