Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3084 for code/trunk/src


Ignore:
Timestamp:
May 26, 2009, 9:20:57 PM (16 years ago)
Author:
landauf
Message:

merged netp3 branch back to trunk

Location:
code/trunk
Files:
52 edited
10 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/CMakeLists.txt

    r3060 r3084  
    106106  # Bullet headers really need the include directory
    107107  ${CMAKE_CURRENT_SOURCE_DIR}/bullet
     108  # OIS headers need the root dir as well
     109  ${CMAKE_CURRENT_SOURCE_DIR}/ois
    108110  # Convenience directory
    109111  ${CMAKE_CURRENT_SOURCE_DIR}/orxonox
  • code/trunk/src/core/Game.cc

    r3037 r3084  
    185185            for (std::vector<GameState*>::const_iterator it = this->activeStates_.begin();
    186186                it != this->activeStates_.end(); ++it)
     187            {
     188                // Add tick time for most of the states
     189                uint64_t timeBeforeTick;
     190                if ((*it)->getCountTickTime())
     191                    timeBeforeTick = this->gameClock_->getRealMicroseconds();
     192               
    187193                (*it)->update(*this->gameClock_);
     194
     195                if ((*it)->getCountTickTime())
     196                    this->addTickTime(this->gameClock_->getRealMicroseconds() - timeBeforeTick);
     197            }
    188198
    189199            // STATISTICS
  • code/trunk/src/core/Game.h

    r3037 r3084  
    4343#include "OrxonoxClass.h"
    4444
    45 #define AddGameState(classname, name) \
    46     static bool MACRO_CONCATENATE(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(name))
     45/**
     46@def
     47    Adds a new GameState to the Game. The second parameter is the name as string
     48    and every following paramter is a constructor argument (which is usually non existent)
     49*/
     50#define AddGameState(classname, ...) \
     51    static bool MACRO_CONCATENATE(bGameStateDummy_##classname, __LINE__) = orxonox::Game::addGameState(new classname(__VA_ARGS__))
    4752
    4853// tolua_begin
  • code/trunk/src/core/GameState.cc

    r2896 r3084  
    4545        Constructor only initialises variables and sets the name permanently.
    4646    */
    47     GameState::GameState(const std::string& name)
     47    GameState::GameState(const std::string& name, bool countTickTime)
    4848        : name_(name)
     49        , bCountTickTime_(countTickTime)
    4950        , parent_(0)
    5051    {
  • code/trunk/src/core/GameState.h

    r2896 r3084  
    7878
    7979    public:
    80         GameState(const std::string& name);
     80        GameState(const std::string& name, bool countTicktime = true);
    8181        virtual ~GameState();
    8282
    8383        const std::string& getName() const { return name_; }
    84         State getActivity() const    { return this->activity_; }
    85         GameState* getParent() const       { return this->parent_; }
     84        State getActivity()          const { return this->activity_; }
     85        GameState* getParent()       const { return this->parent_; }
     86
     87        bool getCountTickTime()      const { return this->bCountTickTime_; }
    8688
    8789        void addChild(GameState* state);
     
    102104        const std::string                        name_;
    103105        State                                    activity_;
     106        const bool                               bCountTickTime_;
    104107        GameState*                               parent_;
    105108        std::map<std::string, GameState*>        children_;
  • code/trunk/src/core/input/InputManager.cc

    r2896 r3084  
    4141#include "ois/OISException.h"
    4242#include "ois/OISInputManager.h"
     43#include "core/ConsoleCommand.h"
     44
     45// HACK
     46#ifdef ORXONOX_PLATFORM_LINUX
     47#  include "ois/linux/LinuxMouse.h"
     48#endif
    4349
    4450#include "util/Exception.h"
     
    4753#include "core/ConfigValueIncludes.h"
    4854#include "core/CommandExecutor.h"
    49 #include "core/ConsoleCommand.h"
    5055#include "core/CommandLine.h"
    5156#include "util/Debug.h"
     
    6469    SetConsoleCommand(InputManager, calibrate, true);
    6570    SetConsoleCommand(InputManager, reload, false);
     71#ifdef ORXONOX_PLATFORM_LINUX
     72    SetConsoleCommand(InputManager, grabMouse, true);
     73    SetConsoleCommand(InputManager, ungrabMouse, true);
     74#endif
    6675    SetCommandLineSwitch(keyboard_no_grab);
    6776
     
    14691478        getInstance().reloadInputSystem(joyStickSupport);
    14701479    }
     1480
     1481
     1482    // ############################################################
     1483    // #####                   ugly hacks                     #####
     1484    // ##########                                        ##########
     1485    // ############################################################
     1486
     1487#ifdef ORXONOX_PLATFORM_LINUX
     1488    void InputManager::grabMouse()
     1489    {
     1490        OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(singletonRef_s->mouse_);
     1491        assert(linuxMouse);
     1492        linuxMouse->grab(true);
     1493    }
     1494
     1495    void InputManager::ungrabMouse()
     1496    {
     1497        OIS::LinuxMouse* linuxMouse = dynamic_cast<OIS::LinuxMouse*>(singletonRef_s->mouse_);
     1498        assert(linuxMouse);
     1499        linuxMouse->grab(false);
     1500    }
     1501#endif
    14711502}
  • code/trunk/src/core/input/InputManager.h

    r2896 r3084  
    137137        bool requestEnterState     (const std::string& name);
    138138        bool requestLeaveState     (const std::string& name);
     139
     140#ifdef ORXONOX_PLATFORM_LINUX
     141        // HACK!
     142        static void grabMouse();
     143        static void ungrabMouse();
     144#endif
    139145
    140146        void update(const Clock& time);
  • code/trunk/src/network/CMakeLists.txt

    r2748 r3084  
    2525  ClientConnectionListener.cc
    2626  ConnectionManager.cc
     27  FunctionCallManager.cc
    2728  GamestateManager.cc
    2829  GamestateClient.cc
    2930  GamestateHandler.cc
     31  NetworkFunction.cc
     32  Host.cc
    3033  PacketBuffer.cc
    3134  Server.cc
    3235  TrafficControl.cc
    33   Host.cc
    3436)
    3537ADD_SUBDIRECTORY(packet)
  • code/trunk/src/network/Client.cc

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    4848#include "core/CoreIncludes.h"
    4949#include "packet/Packet.h"
     50#include "FunctionCallManager.h"
    5051
    5152// #include "packet/Acknowledgement.h"
     
    140141   */
    141142  void Client::update(const Clock& time){
    142 //     COUT(3) << ".";
    143     if(client_connection.isConnected() && isSynched_){
    144       COUT(4) << "popping partial gamestate: " << std::endl;
    145       packet::Gamestate *gs = gamestate.getGamestate();
    146       if(gs){
    147         COUT(4) << "client tick: sending gs " << gs << std::endl;
    148         if( !gs->send() )
    149           COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
     143    //this steers our network frequency
     144    timeSinceLastUpdate_+=time.getDeltaTime();
     145    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
     146      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
     147      //     COUT(3) << ".";
     148      if(client_connection.isConnected() && isSynched_){
     149        COUT(4) << "popping partial gamestate: " << std::endl;
     150        packet::Gamestate *gs = gamestate.getGamestate();
     151        //assert(gs); <--- there might be the case that no data has to be sent, so its commented out now
     152        if(gs){
     153          COUT(4) << "client tick: sending gs " << gs << std::endl;
     154          if( !gs->send() )
     155            COUT(3) << "Problem adding partial gamestate to queue" << std::endl;
    150156        // gs gets automatically deleted by enet callback
     157        }
     158        FunctionCallManager::sendCalls();
    151159      }
    152160    }
     161   
    153162    ENetEvent *event;
    154163    // stop if the packet queue is empty
     
    167176    }
    168177    gamestate.cleanup();
     178
    169179    return;
    170180  }
  • code/trunk/src/network/Client.h

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    8888
    8989    bool gameStateFailure_;
     90    float timeSinceLastUpdate_;
    9091  };
    9192
  • code/trunk/src/network/ClientConnection.cc

    r2773 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    4242#include <enet/enet.h>
    4343#include <iostream>
     44#include <cassert>
    4445// boost.thread library for multithreading support
    4546#include <boost/thread/thread.hpp>
     
    5758
    5859  ClientConnection::ClientConnection(int port, const std::string& address) {
    59     quit=false;
     60    quit_=false;
    6061    server=NULL;
    6162    serverAddress = new ENetAddress();
     
    6667
    6768  ClientConnection::ClientConnection(int port, const char *address) {
    68     quit=false;
     69    quit_=false;
    6970    server=NULL;
    7071    serverAddress = new ENetAddress();
     
    106107
    107108  bool ClientConnection::closeConnection() {
    108     quit=true;
     109    quit_=true;
    109110    //network_threads.join_all();
    110111    receiverThread_->join();
     
    150151      COUT(2) << "ClientConnection: could not create client host" << std::endl;
    151152      // add some error handling here ==========================
    152       quit=true;
     153      quit_=true;
    153154    }
    154155    //connect to the server
    155156    if(!establishConnection()){
    156157      COUT(2) << "clientConn: receiver thread: could not establishConnection" << std::endl;
    157       quit=true;
     158      quit_=true;
    158159      return;
    159160    }
    160161    event = new ENetEvent;
    161162    //main loop
    162     while(!quit){
     163    while(!quit_){
    163164      //std::cout << "connection loop" << std::endl;
    164165      {
     
    166167        if(enet_host_service(client, event, NETWORK_CLIENT_WAIT_TIME)<0){
    167168          // we should never reach this point
    168           quit=true;
    169           continue;
     169//              assert(0);
     170          printf("ClientConnection: ENet returned with an error!\n");
     171          quit_=true;
     172          break;
    170173          // add some error handling here ========================
    171174        }
     
    183186        break;
    184187      case ENET_EVENT_TYPE_DISCONNECT:
    185         quit=true;
     188        quit_=true;
     189        printf("Received disconnect Packet from Server!\n");
    186190        // server closed the connection
    187191        return;
     
    204208  bool ClientConnection::disconnectConnection() {
    205209    ENetEvent event;
     210    if(this->quit_)
     211      return true;
    206212    boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    207213    enet_peer_disconnect(server, 0);
    208     while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) > 0){
     214    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME) >= 0){
    209215      switch (event.type)
    210216      {
     
    233239    }
    234240    // handshake
    235     while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit){
     241    while(enet_host_service(client, &event, NETWORK_CLIENT_WAIT_TIME)>=0 && !quit_){
    236242      if( event.type == ENET_EVENT_TYPE_CONNECT ){
    237243        established=true;
  • code/trunk/src/network/ClientConnection.h

    r2773 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    5353    const int NETWORK_PORT = 55556;
    5454    const int NETWORK_CLIENT_MAX_CONNECTIONS = 5;
    55     const int NETWORK_CLIENT_WAIT_TIME = 1;
     55    const int NETWORK_CLIENT_WAIT_TIME = 10;
    5656    const int NETWORK_CLIENT_CONNECT_TIMEOUT = 3000; // miliseconds
    5757    const int NETWORK_CLIENT_CHANNELS = 2;
     
    7676    //bool sendPackets(ENetEvent *event);
    7777    bool waitEstablished(int milisec);
    78     bool isConnected(){return established;}
     78    inline bool isConnected(){return established;}
     79    inline bool checkConnection(){ return !quit_ && isConnected(); }
    7980  private:
    8081    ClientConnection(const ClientConnection& copy); // not used
     
    9091    ENetAddress *serverAddress;
    9192    // quit-variable (communication with threads)
    92     bool quit;
     93    bool quit_;
    9394    bool established;
    9495    // clientlist
  • code/trunk/src/network/ConnectionManager.cc

    r2896 r3084  
    5858{
    5959  bool operator< (ENetAddress a, ENetAddress b) {
    60     if(a.host <= b.host)
    61       return true;
    62     else
    63       return false;
     60    return a.host <= b.host;
    6461  }
    6562}
     
    7572    assert(instance_==0);
    7673    instance_=this;
    77     quit=false;
     74    quit_=false;
    7875    bindAddress = new ENetAddress();
    7976    bindAddress->host = ENET_HOST_ANY;
     
    8481    assert(instance_==0);
    8582    instance_=this;
    86     quit=false;
     83    quit_=false;
    8784    bindAddress = new ENetAddress();
    8885    bindAddress->host = ENET_HOST_ANY;
     
    9390    assert(instance_==0);
    9491    instance_=this;
    95     quit=false;
     92    quit_=false;
    9693    bindAddress = new ENetAddress();
    9794    enet_address_set_host (bindAddress, address.c_str());
     
    10299    assert(instance_==0);
    103100    instance_=this;
    104     quit=false;
     101    quit_=false;
    105102    bindAddress = new ENetAddress();
    106103    enet_address_set_host (bindAddress, address);
     
    109106
    110107  ConnectionManager::~ConnectionManager(){
    111     if(!quit)
     108    if(!quit_)
    112109      quitListener();
    113110    instance_=0;
     
    133130
    134131  bool ConnectionManager::quitListener() {
    135     quit=true;
     132    quit_=true;
    136133    receiverThread_->join();
    137134    return true;
     
    189186    if(server==NULL){
    190187      // add some error handling here ==========================
    191       quit=true;
     188      quit_=true;
    192189      return;
    193190    }
    194191
    195192    event = new ENetEvent;
    196     while(!quit){
     193    while(!quit_)
     194    {
    197195      { //mutex scope
    198196        boost::recursive_mutex::scoped_lock lock(enet_mutex_g);
    199197        if(enet_host_service(server, event, NETWORK_WAIT_TIMEOUT)<0){
    200198          // we should never reach this point
    201           quit=true;
     199          printf("ConnectionManager: ENet returned with an error\n");
     200          quit_=true;
     201          printf("waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhh\n");
    202202          continue;
    203203          // add some error handling here ========================
     
    208208        // log handling ================
    209209        case ENET_EVENT_TYPE_CONNECT:
     210//             printf("====================================================================");
    210211        case ENET_EVENT_TYPE_DISCONNECT:
    211212        case ENET_EVENT_TYPE_RECEIVE:
     
    215216        case ENET_EVENT_TYPE_NONE:
    216217          //receiverThread_->yield();
    217           msleep(1);
     218          msleep(10);
    218219          break;
    219220      }
     
    267268  }
    268269
    269   bool ConnectionManager::processData(ENetEvent *event) {
    270     // just add packet to the buffer
    271     // this can be extended with some preprocessing
    272     return buffer.push(event);
    273   }
    274 
    275 
    276270
    277271  int ConnectionManager::getClientID(ENetPeer* peer) {
  • code/trunk/src/network/ConnectionManager.h

    r2773 r3084  
    5555    const int NETWORK_PORT = 55556;
    5656    const int NETWORK_MAX_CONNECTIONS = 50;
    57     const int NETWORK_WAIT_TIMEOUT = 1;
     57    const int NETWORK_WAIT_TIMEOUT = 10;
    5858    const int NETWORK_DEFAULT_CHANNEL = 0;
    5959
     
    8181    void disconnectClient(ClientInformation *client);
    8282    void syncClassid(unsigned int clientID);
     83    bool checkReceiverThread(){ return !quit_; }
    8384
    8485  private:
    8586    ConnectionManager(const ConnectionManager& copy); // not used
    86     bool processData(ENetEvent *event);
     87    inline bool processData(ENetEvent *event){ return buffer.push(event); }
    8788    void receiverThread();
    8889    void disconnectClients();
     
    9596    ENetAddress *bindAddress;
    9697
    97     bool quit; // quit-variable (communication with threads)
     98    bool quit_; // quit-variable (communication with threads)
    9899
    99100    boost::thread *receiverThread_;
  • code/trunk/src/network/FunctionCallManager.cc

    • Property svn:eol-style set to native
  • code/trunk/src/network/FunctionCallManager.h

    • Property svn:eol-style set to native
  • code/trunk/src/network/GamestateManager.cc

    r2710 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    132132    if(client){
    133133//       COUT(3) << "diffing" << std::endl;
     134//       packet::Gamestate* gs1  = gs;
    134135      gs = gs->diff(client);
     136//       packet::Gamestate* gs2 = gs->undiff(client);
    135137//       gs = new packet::Gamestate(*gs);
     138//       assert(*gs1==*gs2);
    136139    }
    137140    else{
     
    161164      for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){
    162165        delete it->second;
     166
    163167        gamestateMap_[clientID].erase(it++);
    164168      }
  • code/trunk/src/network/GamestateManager.h

    r2662 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
  • code/trunk/src/network/Host.h

    r2171 r3084  
    3535
    3636namespace orxonox {
     37
     38  const int CLIENTID_SERVER = 0;
     39  const unsigned int NETWORK_FREQUENCY = 30;
     40  const float NETWORK_PERIOD = 1.0f/NETWORK_FREQUENCY;
    3741
    3842/**
  • code/trunk/src/network/NetworkFunction.cc

    • Property svn:eol-style set to native
  • code/trunk/src/network/NetworkFunction.h

    • Property svn:eol-style set to native
  • code/trunk/src/network/NetworkPrereqs.h

    r2773 r3084  
    9090  class ClientInformation;
    9191  class ConnectionManager;
     92  class FunctionCallManager;
    9293  class GamestateClient;
    9394  class GamestateManager;
     
    9697  template <class T> class NetworkCallback;
    9798  class NetworkCallbackManager;
     99  class NetworkFunctionBase;
     100  class NetworkFunctionStatic;
     101  class NetworkMemberFunctionBase;
     102  template <class T> class NetworkMemeberFunction;
     103  struct NetworkFunctionPointer;
    98104  class PacketBuffer;
    99105  class Server;
     
    112118  namespace packet
    113119  {
     120    class Acknowledgement;
     121    class Chat;
     122    class ClassID;
     123    class FunctionCalls;
     124    class FunctionIDs;
    114125    class Gamestate;
     126    class NetworkIDs;
    115127    class Packet;
    116     class Acknowledgement;
    117     class ClassID;
    118128    class Welcome;
    119     class Chat;
    120129  }
    121130}
  • code/trunk/src/network/Server.cc

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    6161#include "util/Convert.h"
    6262#include "ChatListener.h"
     63#include "FunctionCallManager.h"
     64#include "packet/FunctionIDs.h"
     65
    6366
    6467namespace orxonox
     
    152155  void Server::update(const Clock& time) {
    153156    processQueue();
     157    gamestates_->processGamestates();
    154158    //this steers our network frequency
    155159    timeSinceLastUpdate_+=time.getDeltaTime();
    156160    if(timeSinceLastUpdate_>=NETWORK_PERIOD){
    157161      timeSinceLastUpdate_ -= static_cast<unsigned int>( timeSinceLastUpdate_ / NETWORK_PERIOD ) * NETWORK_PERIOD;
    158       gamestates_->processGamestates();
    159162      updateGamestate();
     163      FunctionCallManager::sendCalls();
    160164    }
    161165  }
     
    341345      return false;
    342346    }
    343     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     347    COUT(5) << "Con.Man: creating client id: " << temp->getID() << std::endl;
     348   
     349    // synchronise class ids
    344350    connection->syncClassid(temp->getID());
     351   
     352    // now synchronise functionIDs
     353    packet::FunctionIDs *fIDs = new packet::FunctionIDs();
     354    fIDs->setClientID(clientID);
     355    bool b = fIDs->send();
     356    assert(b);
     357   
    345358    temp->setSynched(true);
    346     COUT(3) << "sending welcome" << std::endl;
     359    COUT(4) << "sending welcome" << std::endl;
    347360    packet::Welcome *w = new packet::Welcome(temp->getID(), temp->getShipID());
    348361    w->setClientID(temp->getID());
    349     bool b = w->send();
     362    b = w->send();
    350363    assert(b);
    351364    packet::Gamestate *g = new packet::Gamestate();
  • code/trunk/src/network/Server.h

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2007
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
    2626 *
    2727 */
    28 
    29 //
    30 // C++ Interface: Server
    31 //
    32 // Description:
    33 //
    34 //
    35 // Author:  Oliver Scheuss, (C) 2007
    36 //
    37 // Copyright: See COPYING file that comes with this distribution
    38 //
    39 //
    4028
    4129#ifndef _Server_H__
     
    5139namespace orxonox
    5240{
    53   const int CLIENTID_SERVER = 0;
    54   const unsigned int NETWORK_FREQUENCY = 25;
    55   const float NETWORK_PERIOD = 1.f/NETWORK_FREQUENCY;
    5641
    5742  /**
  • code/trunk/src/network/TrafficControl.cc

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>
    2424 *   Co-authors:
    2525 *      ...
     
    9191  void TrafficControl::setConfigValues()
    9292  {
    93     SetConfigValue ( bActive_, true );
    94     SetConfigValue ( targetSize, 5000 );
     93    SetConfigValue ( bActive_, false );
     94    SetConfigValue ( targetSize, 10000 );
    9595  }
    9696
     
    121121
    122122
    123         void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj> *list)
    124         {
    125 //        copiedVector = *list;
     123        void TrafficControl::processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list)
     124        {
    126125          currentClientID=clientID;
    127126          currentGamestateID=gamestateID;
     
    143142    assert(clientListTemp_.find(clientID) != clientListTemp_.end() );
    144143    assert(clientListPerm_.find(clientID) != clientListPerm_.end() );
    145           assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
    146 
    147     for(itvec = clientListTemp_[clientID][gamestateID].begin(); itvec != clientListTemp_[clientID][gamestateID].end(); itvec++)
     144    assert( clientListTemp_[clientID].find(gamestateID) != clientListTemp_[clientID].end() );
     145   
     146    // shortcut for maps
     147    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     148    std::map<unsigned int, std::list<obj> >& objectListTemp = clientListTemp_[clientID];
     149
     150    for(itvec = objectListTemp[gamestateID].begin(); itvec != objectListTemp[gamestateID].end(); itvec++)
    148151          {
    149       if(clientListPerm_[clientID].find((*itvec).objID) != clientListPerm_[clientID].end()) // check whether the obj already exists in our lists
    150       {
    151         clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;
    152         clientListPerm_[clientID][(*itvec).objID].objValueSched = 0; //set scheduling value back
     152      if(objectListPerm.find((*itvec).objID) != objectListPerm.end()) // check whether the obj already exists in our lists
     153      {
     154        objectListPerm[(*itvec).objID].objCurGS = gamestateID;
     155        objectListPerm[(*itvec).objID].objValueSched = 0; //set scheduling value back
    153156      }
    154157      else
    155158      {
    156159        assert(0);
    157         clientListPerm_[clientID][(*itvec).objID].objCurGS = gamestateID;
    158         clientListPerm_[clientID][(*itvec).objID].objID = (*itvec).objID;
    159         clientListPerm_[clientID][(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
    160         clientListPerm_[clientID][(*itvec).objID].objSize = (*itvec).objSize;
     160        objectListPerm[(*itvec).objID].objCurGS = gamestateID;
     161        objectListPerm[(*itvec).objID].objID = (*itvec).objID;
     162        objectListPerm[(*itvec).objID].objCreatorID = (*itvec).objCreatorID;
     163        objectListPerm[(*itvec).objID].objSize = (*itvec).objSize;
    161164      }
    162165          }
    163166           // remove temporary list (with acked objects) from the map
    164     clientListTemp_[clientID].erase( clientListTemp_[clientID].find(gamestateID) );
     167    objectListTemp.erase( objectListTemp.find(gamestateID) );
    165168        }
    166169
     
    176179        {
    177180          std::map<unsigned int,std::map<unsigned int, objInfo> >::iterator itperm;//iterator clientListPerm over clientIDs
    178 //        itperm = (clientListPerm_).find(clientID);
    179 //        assert(itperm != clientListPerm_.end() );
    180181    unsigned int gsid=GAMESTATEID_INITIAL, gsdiff=currentGamestateID, prioperm=Synchronisable::getSynchronisable(objinf.objID)->getPriority(), priomom=0;
    181182    clientListPerm_[clientID][objinf.objID] = objInfo(objinf.objID, objinf.objCreatorID,gsid,gsdiff, objinf.objSize,prioperm,priomom);
    182 //        itperm->second.insert(std::pair<unsigned int, objInfo>(objid,objinf));
    183 //     permObjPrio_.insert(objid, objinf.objValuePerm);
    184183        }
    185184
     
    188187  * takes the shortened list which will be sent to the gsmanager and puts the *info into clientListTemp
    189188  */
    190   void TrafficControl::updateClientListTemp(std::list<obj> *list)
    191   {
    192     clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(*list);
     189  void TrafficControl::updateClientListTemp(std::list<obj>& list)
     190  {
     191    clientListTemp_[currentClientID][currentGamestateID] = std::list<obj>(list);
    193192  }
    194193
     
    197196  *takes the current list that has to be returned to the gsmanager and shortens it in criteria of bandwidth of clientID(XY)
    198197  */
    199   void TrafficControl::cut(std::list<obj> *list, unsigned int targetsize)
     198  void TrafficControl::cut(std::list<obj>& list, unsigned int targetsize)
    200199  {
    201200    unsigned int size=0;
    202201    std::list<obj>::iterator itvec, ittemp;
    203     assert(!list->empty());
    204     for(itvec = list->begin(); itvec != list->end();)
     202    assert(!list.empty());
     203    for(itvec = list.begin(); itvec != list.end();)
    205204    {
    206205      assert( (*itvec).objSize < 1000);
     
    213212      {
    214213        clientListPerm_[currentClientID][(*itvec).objID].objValueSched += SCHED_PRIORITY_OFFSET; // NOTE: SCHED_PRIORITY_OFFSET is negative
    215         list->erase(itvec++);
     214        list.erase(itvec, list.end());
     215        break;
    216216      }
    217217//       printList(list, currentClientID);
    218218    }
    219     assert(!list->empty());
     219    assert(!list.empty());
    220220  }
    221221
     
    224224        *evaluateList evaluates whether new obj are there, whether there are things to be updatet and manipulates all this.
    225225        */
    226         void TrafficControl::evaluateList(unsigned int clientID, std::list<obj> *list)
     226        void TrafficControl::evaluateList(unsigned int clientID, std::list<obj>& list)
    227227        {
    228228
     
    232232    //if listToProcess contains new Objects, add them to clientListPerm
    233233    std::list<obj>::iterator itvec;
    234           for( itvec=list->begin(); itvec != list->end(); itvec++)
     234   
     235    std::map<unsigned int, objInfo >& objectListPerm = clientListPerm_[clientID];
     236   
     237          for( itvec=list.begin(); itvec != list.end(); itvec++)
    235238          {
    236             if ( clientListPerm_[clientID].find( (*itvec).objID) != clientListPerm_[clientID].end() )
     239            if ( objectListPerm.find( (*itvec).objID) != objectListPerm.end() )
    237240      {
    238241        // we already have the object in our map
    239242        //obj bleibt in liste und permanente prio wird berechnet
    240         clientListPerm_[clientID][(*itvec).objID].objDiffGS = currentGamestateID - clientListPerm_[clientID][(*itvec).objID].objCurGS;
     243        objectListPerm[(*itvec).objID].objDiffGS = currentGamestateID - objectListPerm[(*itvec).objID].objCurGS;
    241244        continue;//check next objId
    242245      }
     
    254257      //sort copied list according to priorities
    255258      // use boost bind here because we need to pass a memberfunction to stl sort
    256       list->sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
     259//       sort( list.begin(), list.end(), boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
     260      list.sort( boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
     261     
     262//       list.sort(boost::bind(&TrafficControl::prioritySort, this, clientID, _1, _2) );
    257263
    258264      //now we check, that the creator of an object always exists on a client
    259265      std::list<obj>::iterator itcreator;
    260       for(itvec = list->begin(); itvec != list->end(); itvec++)
     266      for(itvec = list.begin(); itvec != list.end(); itvec++)
    261267      {
    262268        fixCreatorDependencies(itvec, list, clientID);
     
    266272//       printList(list, clientID);
    267273      cut(list, targetSize);
    268 
    269274      //now sort again after objDataOffset
    270       list->sort(boost::bind(&TrafficControl::dataSort, this, _1, _2) );
     275//       sort(list.begin(), list.end(), boost::bind(&TrafficControl::dataSort, this, _1, _2) );
     276      list.sort( boost::bind(&TrafficControl::dataSort, this, _1, _2) );
    271277    }
    272278    //diese Funktion updateClientList muss noch gemacht werden
     
    275281  }
    276282
    277   void TrafficControl::printList(std::list<obj> *list, unsigned int clientID)
     283  void TrafficControl::printList(std::list<obj>& list, unsigned int clientID)
    278284  {
    279285    std::list<obj>::iterator it;
    280286    COUT(0) << "=========== Objectlist ===========" << endl;
    281     for( it=list->begin(); it!=list->end(); it++)
     287    for( it=list.begin(); it!=list.end(); it++)
    282288      COUT(0) << "ObjectID: " << (*it).objID << " creatorID: " << (*it).objCreatorID << " Priority: " << clientListPerm_[clientID][(*it).objID].objValuePerm + clientListPerm_[clientID][(*it).objID].objValueSched << " size: " << (*it).objSize << endl;
    283289  }
    284290
    285   void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj> *list, unsigned int clientID)
     291  void TrafficControl::fixCreatorDependencies(std::list<obj>::iterator it1, std::list<obj>& list, unsigned int clientID)
    286292  {
    287293    if ( (*it1).objCreatorID == OBJECTID_UNKNOWN )
     
    290296      return;
    291297    std::list<obj>::iterator it2, it3=it1;
    292     for( it2 = ++it3; it2 != list->end(); it2++ )
     298    for( it2 = ++it3; it2 != list.end(); it2++ )
    293299    {
    294300      if( (*it2).objID == (*it1).objCreatorID )
    295301      {
    296         it3 = list->insert(it1, *it2); //insert creator before it1
    297         list->erase(it2);
     302        it3 = list.insert(it1, *it2); //insert creator before it1
     303        list.erase(it2);
    298304//         printList(list, clientID);
    299305        fixCreatorDependencies( it3, list, clientID );
  • code/trunk/src/network/TrafficControl.h

    r2710 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss <scheusso [at] ee.ethz.ch>, (C) 2008
     23 *      Oliver Scheuss <scheusso [at] ee.ethz.ch>
    2424 *   Co-authors:
    2525 *      ...
     
    8383
    8484    /**
    85     *Lists that will be used:
    86     *listToProcess
    87     *clientListPerm
    88     *clientListTemp
    89     *referenceList
    90     *permObjPrio list
    91     *schedObjPrio
    92     */
    93     //start: lists to be used
    94     /**
    95     *creates list (typ map) that contains objids, struct with info concerning object(objid)
    96     */
    97 //     std::map<unsigned int, objInfo> listToProcess_;//copy of argument, when traffic control tool is being called, the original of this must be returned later on, eg the list given by GS
    98     /**
    9985    *permanent client list: contains client ids, object ids and objectInfos (in this order)
    10086    */
     
    10692    */
    10793    std::map<unsigned int, std::map<unsigned int, std::list<obj> > > clientListTemp_;
    108     /**
    109     *static priority list: contains obj id, basic priority (in this order)
    110     */
    111 //     std::map<unsigned int, unsigned int> permObjPrio_;
    112     /**
    113     *dynamic priority list: contains obj id, dynamic priority (eg scheduled) (in this order)
    114     */
    115 //     std::map<unsigned int, unsigned int> schedObjPrio_;
    116     //end: lists to be used
    11794
    11895    /**updateReferenceList
     
    123100    unsigned int targetSize;
    124101    bool         bActive_;
    125     /**
    126     *copiedVector is a copy of the given Vector by the GSmanager, on this list all manipulations are performed
    127     */
    128 //     std::list<obj> copiedVector;
    129 
    130 //     void updateReferenceList(std::map<unsigned int, objInfo> *list);//done
    131     void insertinClientListPerm(unsigned int clientID, obj objinf);//done
    132     /**
    133     *creates listToProcess, which can be easialy compared with other lists
    134     */
    135 //     void copyList(std::list<obj> *list);//done
    136102   
    137     void cut(std::list<obj> *list, unsigned int targetsize);
    138     void updateClientListTemp(std::list<obj> *list);//done
     103    void insertinClientListPerm(unsigned int clientID, obj objinf);
     104   
     105    void cut(std::list<obj>& list, unsigned int targetsize);
     106    void updateClientListTemp(std::list<obj>& list);//done
    139107    /**
    140108    *evaluates Data given (list) and produces result(->Data to be updated)
    141109    */
    142     void evaluateList(unsigned int clientID, std::list<obj> *list);//done   
     110    void evaluateList(unsigned int clientID, std::list<obj>& list);//done   
    143111    void ack(unsigned int clientID, unsigned int gamestateID);  // this function gets called when the server receives an ack from the client
    144112   
     
    162130    void setConfigValues();
    163131    static TrafficControl *getInstance();
    164     void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>* list); //gets a pointer to the list (containing objectIDs) and sorts it
    165     //done
     132    void processObjectList(unsigned int clientID, unsigned int gamestateID, std::list<obj>& list); //gets a pointer to the list (containing objectIDs) and sorts it
    166133    static void processAck(unsigned int clientID, unsigned int gamestateID)
    167134    { return instance_->ack(clientID, gamestateID); }
    168     //done
    169135    void deleteObject(unsigned int objectID);                           // this function gets called when an object has been deleted (in order to clean up lists and maps)
    170136   
    171137    bool prioritySort(uint32_t clientID, obj i, obj j);
    172138    bool dataSort(obj i, obj j);
    173     void printList(std::list<obj> *list, unsigned int clientID);
    174     void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj> *list, unsigned int clientID);
     139    void printList(std::list<obj>& list, unsigned int clientID);
     140    void fixCreatorDependencies(std::list<obj>::iterator it, std::list<obj>& list, unsigned int clientID);
    175141};
    176142
  • code/trunk/src/network/packet/CMakeLists.txt

    r2710 r3084  
    11ADD_SOURCE_FILES(NETWORK_SRC_FILES
    22  Packet.cc
     3  Acknowledgement.cc
    34  Chat.cc
    45  ClassID.cc
    5   Acknowledgement.cc
     6  DeleteObjects.cc
     7  FunctionIDs.cc
     8  FunctionCalls.cc
    69  Gamestate.cc
    710  Welcome.cc
    8   DeleteObjects.cc
    911)
  • code/trunk/src/network/packet/ClassID.cc

    r2773 r3084  
    9393  }
    9494 
    95   COUT(0) << "classid packetSize is " << packetSize << endl;
     95  COUT(5) << "classid packetSize is " << packetSize << endl;
    9696 
    9797}
  • code/trunk/src/network/packet/FunctionCalls.cc

    • Property svn:eol-style set to native
  • code/trunk/src/network/packet/FunctionCalls.h

    • Property svn:eol-style set to native
  • code/trunk/src/network/packet/FunctionIDs.cc

    • Property svn:eol-style set to native
  • code/trunk/src/network/packet/FunctionIDs.h

    • Property svn:eol-style set to native
  • code/trunk/src/network/packet/Gamestate.cc

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2008
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    107107  for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    108108   
    109     tempsize=it->getSize(id, mode);
     109//     tempsize=it->getSize(id, mode);
     110
     111    tempsize = it->getData(mem, id, mode);
     112    if ( tempsize != 0 )
     113      dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     114   
    110115#ifndef NDEBUG
    111116    if(currentsize+tempsize > size){
     
    123128    }// stop allocate additional memory
    124129#endif
    125 
    126     if ( it->doSync( id, mode ) )
    127       dataMap_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
    128     if(!it->getData(mem, id, mode))
    129       return false; // mem pointer gets automatically increased because of call by reference
     130//     if(!it->getData(mem, id, mode))
     131//       return false; // mem pointer gets automatically increased because of call by reference
    130132    // increase size counter by size of current synchronisable
    131133    currentsize+=tempsize;
     
    177179    }
    178180  }
    179 
    180181   // In debug mode, check first, whether there are no duplicate objectIDs
    181182#ifndef NDEBUG
    182   ObjectList<Synchronisable>::iterator it;
    183   for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) {
    184     if (it->getObjectID() == OBJECTID_UNKNOWN) {
    185       if (it->objectMode_ != 0x0) {
    186         COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl;
    187         COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
    188         COUT(0) << "Objects class: " << it->getIdentifier()->getName() << std::endl;
    189         assert(false);
     183  if(this->getID()%1000==0){
     184    std::list<uint32_t> v1;
     185    ObjectList<Synchronisable>::iterator it;
     186    for (it = ObjectList<Synchronisable>::begin(); it != ObjectList<Synchronisable>::end(); ++it) {
     187      if (it->getObjectID() == OBJECTID_UNKNOWN) {
     188        if (it->objectMode_ != 0x0) {
     189          COUT(0) << "Found object with OBJECTID_UNKNOWN on the client with objectMode != 0x0!" << std::endl;
     190          COUT(0) << "Possible reason for this error: Client created a synchronized object without the Server's approval." << std::endl;
     191          COUT(0) << "Objects class: " << it->getIdentifier()->getName() << std::endl;
     192          assert(false);
     193        }
    190194      }
    191     }
    192     else {
    193       ObjectList<Synchronisable>::iterator it2;
    194       for (it2 = ObjectList<Synchronisable>::begin(); it2 != ObjectList<Synchronisable>::end(); ++it2) {
    195         if (it->getObjectID() == it2->getObjectID() && *it != *it2) {
    196            COUT(0) << "Found duplicate objectIDs on the client!" << std::endl
    197                    << "Are you sure you don't create a Sychnronisable objcect with 'new' \
    198                        that doesn't have objectMode = 0x0?" << std::endl;
    199            assert(false);
     195      else {
     196        std::list<uint32_t>::iterator it2;
     197        for (it2 = v1.begin(); it2 != v1.end(); ++it2) {
     198          if (it->getObjectID() == *it2) {
     199            COUT(0) << "Found duplicate objectIDs on the client!" << std::endl
     200                    << "Are you sure you don't create a Sychnronisable objcect with 'new' \
     201                        that doesn't have objectMode = 0x0?" << std::endl;
     202            assert(false);
     203          }
    200204        }
     205        v1.push_back(it->getObjectID());
    201206      }
    202207    }
     
    221226  uint8_t *d1 = data_+GamestateHeader::getSize();
    222227  uint8_t *d2 = gs.data_+GamestateHeader::getSize();
     228  GamestateHeader* h1 = new GamestateHeader(data_);
     229  GamestateHeader* h2 = new GamestateHeader(gs.data_);
     230  assert(h1->getDataSize() == h2->getDataSize());
    223231  assert(!isCompressed());
    224232  assert(!gs.isCompressed());
    225   while(d1<data_+header_->getDataSize())
    226   {
    227     if(*d1!=*d2)
    228       return false;
    229     d1++;
    230     d2++;
    231   }
    232   return true;
     233  return memcmp(d1, d2, h1->getDataSize())==0;
    233234}
    234235
     
    357358}
    358359
     360// Gamestate *Gamestate::diff(Gamestate *base)
     361// {
     362//   assert(data_);
     363//   assert(!header_->isCompressed());
     364//   assert(!header_->isDiffed());
     365//   GamestateHeader diffHeader(base->data_);
     366//   uint8_t *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
     367//   uint32_t of=0; // pointers offset
     368//   uint32_t dest_length=0;
     369//   dest_length=header_->getDataSize();
     370//   if(dest_length==0)
     371//     return NULL;
     372//   uint8_t *ndata = new uint8_t[dest_length*sizeof(uint8_t)+GamestateHeader::getSize()];
     373//   uint8_t *dest = ndata + GamestateHeader::getSize();
     374//   
     375//   
     376//   // LOOP-UNROLLED DIFFING
     377//   uint32_t *dest32 = (uint32_t*)dest, *base32 = (uint32_t*)basep, *gs32 = (uint32_t*)gs;
     378//   // diff in 4-byte steps
     379//   while( of < (uint32_t)(header_->getDataSize())/4 ){
     380//     if( of < (uint32_t)(diffHeader.getDataSize())/4 )
     381//     {
     382//       *(dest32+of)=*(base32+of) ^ *(gs32+of); // do the xor
     383//       ++of;
     384//     }
     385//     else
     386//     {
     387//       *(dest32+of)=*(gs32+of); // same as 0 ^ *(gs32+of)
     388//       ++of;
     389//     }
     390//   }
     391//   for( unsigned int of2 = 0; of2 < header_->getDataSize()%4; ++of2 )
     392//   {
     393//     if( of*4+of2 < diffHeader.getDataSize() )
     394//     {
     395//       *(dest+4*of+of2)=*(basep+4*of+of2) ^ *(gs+4*of+of2); // do the xor
     396//     }
     397//     else
     398//     {
     399//       *(dest+4*of+of2)=*(gs+4*of+of2); // same as 0 ^ *(gs32+of)
     400//     }
     401//   }
     402//
     403//   Gamestate *g = new Gamestate(ndata, getClientID());
     404//   *(g->header_) = *header_;
     405//   g->header_->setDiffed( true );
     406//   g->header_->setBaseID( base->getID() );
     407//   g->flags_=flags_;
     408//   g->packetDirection_ = packetDirection_;
     409//   return g;
     410// }
     411
    359412Gamestate* Gamestate::doSelection(unsigned int clientID, unsigned int targetSize){
    360413  assert(data_);
     
    378431
    379432  //call TrafficControl
    380   TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), &dataMap_ );
     433  TrafficControl::getInstance()->processObjectList( clientID, header_->getID(), dataVector_ );
    381434
    382435  //copy in the zeros
    383   for(it=dataMap_.begin(); it!=dataMap_.end();){
     436//   std::list<obj>::iterator itt;
     437//   COUT(0) << "myvector contains:";
     438//   for ( itt=dataVector_.begin() ; itt!=dataVector_.end(); itt++ )
     439//     COUT(0) << " " << (*itt).objID;
     440//   COUT(0) << endl;
     441  for(it=dataVector_.begin(); it!=dataVector_.end();){
    384442    SynchronisableHeader oldobjectheader(origdata);
    385443    SynchronisableHeader newobjectheader(newdata);
  • code/trunk/src/network/packet/Gamestate.h

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2008
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    3737#include <string.h>
    3838#include <map>
    39 #include <list>
     39#include <vector>
    4040#include <cassert>
    4141#ifndef NDEBUG
     
    120120    bool compressData();
    121121    bool decompressData();
     122    bool operator ==(packet::Gamestate gs);
    122123
    123124    // Packet functions
     
    126127    virtual inline bool process();
    127128
    128     bool operator ==(packet::Gamestate gs);
    129129  private:
    130130    uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0);
    131     std::list<obj> dataMap_;
     131    std::list<obj> dataVector_;
    132132    GamestateHeader* header_;
    133133};
  • code/trunk/src/network/packet/Packet.cc

    r2773 r3084  
    3939
    4040#include "Acknowledgement.h"
     41#include "DeleteObjects.h"
    4142#include "Chat.h"
    4243#include "ClassID.h"
     44#include "FunctionCalls.h"
     45#include "FunctionIDs.h"
    4346#include "Gamestate.h"
    4447#include "Welcome.h"
    45 #include "DeleteObjects.h"
    4648#include "network/Host.h"
    4749#include "core/CoreIncludes.h"
     
    153155    case ENUM::Welcome:
    154156    case ENUM::DeleteObjects:
     157    case ENUM::FunctionIDs:
     158    case ENUM::FunctionCalls:
    155159      break;
    156160    default:
     
    170174  unsigned int clientID = ClientInformation::findClient(&peer->address)->getID();
    171175  Packet *p = 0;
    172   COUT(5) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
     176  COUT(6) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl;
    173177  switch( *(ENUM::Type *)(data + _PACKETID) )
    174178  {
    175179    case ENUM::Acknowledgement:
    176       COUT(4) << "ack" << std::endl;
     180      COUT(5) << "ack" << std::endl;
    177181      p = new Acknowledgement( data, clientID );
    178182      break;
    179183    case ENUM::Chat:
    180       COUT(4) << "chat" << std::endl;
     184      COUT(5) << "chat" << std::endl;
    181185      p = new Chat( data, clientID );
    182186      break;
    183187    case ENUM::ClassID:
    184       COUT(4) << "classid" << std::endl;
     188      COUT(5) << "classid" << std::endl;
    185189      p = new ClassID( data, clientID );
    186190      break;
    187191    case ENUM::Gamestate:
    188       COUT(4) << "gamestate" << std::endl;
     192      COUT(5) << "gamestate" << std::endl;
    189193      // TODO: remove brackets
    190194      p = new Gamestate( data, clientID );
    191195      break;
    192196    case ENUM::Welcome:
    193       COUT(4) << "welcome" << std::endl;
     197      COUT(5) << "welcome" << std::endl;
    194198      p = new Welcome( data, clientID );
    195199      break;
    196200    case ENUM::DeleteObjects:
    197       COUT(4) << "deleteobjects" << std::endl;
     201      COUT(5) << "deleteobjects" << std::endl;
    198202      p = new DeleteObjects( data, clientID );
     203      break;
     204    case ENUM::FunctionCalls:
     205      COUT(5) << "functionCalls" << std::endl;
     206      p = new FunctionCalls( data, clientID );
     207      break;
     208    case ENUM::FunctionIDs:
     209      COUT(5) << "functionIDs" << std::endl;
     210      p = new FunctionIDs( data, clientID );
    199211      break;
    200212    default:
  • code/trunk/src/network/packet/Packet.h

    r2773 r3084  
    4545  enum Type{
    4646    Acknowledgement,
     47    Chat,
     48    ClassID,
     49    DeleteObjects,
     50    FunctionIDs,
     51    FunctionCalls,
    4752    Gamestate,
    48     ClassID,
    49     Chat,
    50     Welcome,
    51     DeleteObjects
     53    Welcome
    5254  };
    5355}
     
    6668    virtual unsigned int getSize() const =0;
    6769    virtual bool process()=0;
    68     uint32_t getFlags()
     70    inline uint32_t getFlags()
    6971      { return flags_; }
    70     int getClientID()
     72    inline int getClientID()
    7173      { return clientID_; }
    72     void setClientID( int id )
     74    inline void setClientID( int id )
    7375      { clientID_ = id; }
    7476
     
    7880    Packet(uint8_t *data, unsigned int clientID);
    7981//    Packet(ENetPacket *packet, ENetPeer *peer);
     82    inline bool isDataENetAllocated() const
     83      { return bDataENetAllocated_; }
     84
    8085    uint32_t flags_;
    8186    unsigned int clientID_;
  • code/trunk/src/network/synchronisable/NetworkCallbackManager.cc

    r2662 r3084  
    3232
    3333namespace orxonox{
    34 
     34 
    3535  std::set<NetworkCallbackBase*> NetworkCallbackManager::callbackSet_;
    3636  std::queue<NetworkCallbackBase*> NetworkCallbackManager::triggeredCallbacks_;
     
    6060    while( triggeredCallbacks_.empty()==false )
    6161    {
    62       triggeredCallbacks_.front()->call();
     62      //make sure callback hasn't been deleted before
     63      if ( callbackSet_.find(triggeredCallbacks_.front()) != callbackSet_.end() )
     64        triggeredCallbacks_.front()->call();
    6365      triggeredCallbacks_.pop();
    6466    }
  • code/trunk/src/network/synchronisable/Synchronisable.cc

    r3068 r3084  
    6666      objectID=OBJECTID_UNKNOWN;
    6767    classID = static_cast<uint32_t>(-1);
    68 
     68   
     69    // set dataSize to 0
     70    this->dataSize_ = 0;
    6971    // set standard priority
    7072    this->setPriority( priority::normal );
     
    9698    // delete callback function objects
    9799    if(!Identifier::isCreatingHierarchy()){
    98       for(std::list<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
     100      for(std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin(); it!=syncList.end(); it++)
    99101        delete (*it);
    100102      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
     
    236238   * @return true: if !doSync or if everything was successfully saved
    237239   */
    238   bool Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
     240  uint32_t Synchronisable::getData(uint8_t*& mem, int32_t id, uint8_t mode){
    239241    if(mode==0x0)
    240242      mode=state_;
    241243    //if this tick is we dont synchronise, then abort now
    242244    if(!doSync(id, mode))
    243       return true;
     245      return 0;
    244246    uint32_t tempsize = 0;
    245247    if (this->classID==0)
     
    250252
    251253    assert(this->classID==this->getIdentifier()->getNetworkID());
    252     std::list<SynchronisableVariableBase*>::iterator i;
    253     uint32_t size;
    254     size=getSize(id, mode);
     254    std::vector<SynchronisableVariableBase*>::iterator i;
    255255
    256256    // start copy header
    257257    SynchronisableHeader header(mem);
    258     header.setDataSize( size );
     258    mem += SynchronisableHeader::getSize();
     259    // end copy header
     260
     261
     262    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
     263    // copy to location
     264    for(i=syncList.begin(); i!=syncList.end(); ++i){
     265      tempsize += (*i)->getData( mem, mode );
     266      //tempsize += (*i)->getSize( mode );
     267    }
     268   
     269    tempsize += SynchronisableHeader::getSize();
    259270    header.setObjectID( this->objectID );
    260271    header.setCreatorID( this->creatorID );
    261272    header.setClassID( this->classID );
    262273    header.setDataAvailable( true );
    263     tempsize += SynchronisableHeader::getSize();
    264     mem += SynchronisableHeader::getSize();
    265     // end copy header
    266 
    267 
    268     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
    269     // copy to location
    270     for(i=syncList.begin(); i!=syncList.end(); ++i){
    271       (*i)->getData( mem, mode );
    272       tempsize += (*i)->getSize( mode );
    273     }
     274    header.setDataSize( tempsize );
     275   
     276#ifndef NDEBUG
     277    uint32_t size;
     278    size=getSize(id, mode);
    274279    assert(tempsize==size);
    275     return true;
     280#endif
     281    return tempsize;
    276282  }
    277283
     
    286292    if(mode==0x0)
    287293      mode=state_;
    288     std::list<SynchronisableVariableBase *>::iterator i;
     294    std::vector<SynchronisableVariableBase *>::iterator i;
    289295    if(syncList.empty()){
    290296      assert(0);
     
    325331  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
    326332    int tsize=SynchronisableHeader::getSize();
    327     if(mode==0x0)
     333    if (mode==0x0)
    328334      mode=state_;
    329     if(!doSync(id, mode))
     335    if (!doSync(id, mode))
    330336      return 0;
    331     std::list<SynchronisableVariableBase*>::iterator i;
    332     for(i=syncList.begin(); i!=syncList.end(); i++){
     337    assert( mode==state_ );
     338    tsize += this->dataSize_;
     339    std::vector<SynchronisableVariableBase*>::iterator i;
     340    for(i=stringList.begin(); i!=stringList.end(); ++i){
    333341      tsize += (*i)->getSize( mode );
    334342    }
  • code/trunk/src/network/synchronisable/Synchronisable.h

    r3068 r3084  
    3333
    3434#include <list>
     35#include <vector>
    3536#include <map>
    3637#include <queue>
    3738#include <cassert>
     39#include <string>
    3840#include "util/Math.h"
    3941#include "util/mbool.h"
     
    120122  public:
    121123    friend class packet::Gamestate;
    122 //     friend class Server;
    123124    virtual ~Synchronisable();
    124125
     
    139140    Synchronisable(BaseObject* creator);
    140141    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    141     template <class T> void unregisterVariable(T& var);
     142    //template <class T> void unregisterVariable(T& var);
    142143    void setObjectMode(uint8_t mode);
    143144    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    145146
    146147  private:
    147     bool getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
     148    uint32_t getData(uint8_t*& men, int32_t id, uint8_t mode=0x0);
    148149    uint32_t getSize(int32_t id, uint8_t mode=0x0);
    149150    bool updateData(uint8_t*& mem, uint8_t mode=0x0, bool forceCallback=false);
     
    155156    uint32_t classID;
    156157
    157     std::list<SynchronisableVariableBase*> syncList;
     158    std::vector<SynchronisableVariableBase*> syncList;
     159    std::vector<SynchronisableVariableBase*> stringList;
     160    uint32_t dataSize_; //size of all variables except strings
    158161    static uint8_t state_; // detemines wheter we are server (default) or client
    159162    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     
    164167  };
    165168
    166   template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
    167   {
    168     if (bidirectional)
    169       syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
    170     else
    171       syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
    172   }
    173 
    174   template <class T> void Synchronisable::unregisterVariable(T& var){
    175     std::list<SynchronisableVariableBase*>::iterator it = syncList.begin();
    176     while(it!=syncList.end()){
    177       if( ((*it)->getReference()) == &var ){
    178         delete (*it);
    179         syncList.erase(it);
    180         return;
    181       }
    182       else
    183         it++;
    184     }
    185     bool unregistered_nonexistent_variable = false;
    186     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
    187     // the variable has not been registered before
    188   }
    189 
    190169  // ================= Specialisation declarations
     170 
     171//   template <> _NetworkExport void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     172  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
    191173  template <> _NetworkExport void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    192174  template <> _NetworkExport void Synchronisable::registerVariable( ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     
    200182  template <> _NetworkExport void Synchronisable::registerVariable( const Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
    201183  template <> _NetworkExport void Synchronisable::registerVariable( Quaternion& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional);
     184 
     185  template <class T> void Synchronisable::registerVariable(T& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     186  {
     187    if (bidirectional)
     188    {
     189      syncList.push_back(new SynchronisableVariableBidirectional<const T>(variable, mode, cb));
     190      this->dataSize_ += syncList.back()->getSize(state_);
     191    }
     192    else
     193    {
     194      syncList.push_back(new SynchronisableVariable<const T>(variable, mode, cb));
     195      if ( this->state_ == mode )
     196        this->dataSize_ += syncList.back()->getSize(state_);
     197    }
     198  }
     199 
     200
     201
     202//   template <class T> void Synchronisable::unregisterVariable(T& var){
     203//     std::vector<SynchronisableVariableBase*>::iterator it = syncList.begin();
     204//     while(it!=syncList.end()){
     205//       if( ((*it)->getReference()) == &var ){
     206//         delete (*it);
     207//         syncList.erase(it);
     208//         return;
     209//       }
     210//       else
     211//         it++;
     212//     }
     213//     bool unregistered_nonexistent_variable = false;
     214//     assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     215//     // the variable has not been registered before
     216//   }
     217
     218 
    202219}
    203220
  • code/trunk/src/network/synchronisable/SynchronisableSpecialisations.cc

    r2662 r3084  
    2929
    3030#include "network/synchronisable/Synchronisable.h"
     31#include <string>
    3132
    3233// ================ template spezialisation
     
    3435 
    3536namespace orxonox{
     37 
     38//   template <> void Synchronisable::registerVariable( const std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     39//   {
     40//     if (bidirectional)
     41//       syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     42//     else
     43//       syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
     44//     stringList.push_back(syncList.back());
     45//   }
     46 
     47  template <> void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional)
     48  {
     49    if (bidirectional)
     50      syncList.push_back(new SynchronisableVariableBidirectional<const std::string>(variable, mode, cb));
     51    else
     52      syncList.push_back(new SynchronisableVariable<const std::string>(variable, mode, cb));
     53    stringList.push_back(syncList.back());
     54  }
    3655 
    3756  template <> void Synchronisable::registerVariable( const ColourValue& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
     
    5271    registerVariable(variable.y, mode, cb, bidirectional);
    5372  }
    54   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
    55   {
    56     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
    57   }
     73//   template <> void Synchronisable::registerVariable( Vector2& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
     74//   {
     75//     registerVariable( (const ColourValue&)variable, mode, cb, bidirectional);
     76//   }
    5877 
    5978  template <> void Synchronisable::registerVariable( const Vector3& variable, uint8_t mode, NetworkCallbackBase* cb, bool bidirectional)
  • code/trunk/src/network/synchronisable/SynchronisableVariable.cc

    • Property svn:eol-style set to native
  • code/trunk/src/network/synchronisable/SynchronisableVariable.h

    r2896 r3084  
    2121 *
    2222 *   Author:
    23  *      Oliver Scheuss, (C) 2008
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    2525 *      ...
     
    3535#include <string>
    3636#include <cassert>
    37 #include "util/Math.h"
     37#include "util/Serialise.h"
     38#include "core/Core.h"
     39#include "core/CoreIncludes.h"
     40#include "core/GameMode.h"
    3841#include "network/synchronisable/NetworkCallback.h"
    3942#include "network/synchronisable/NetworkCallbackManager.h"
     
    5558  {
    5659    public:
    57       virtual void getData(uint8_t*& mem, uint8_t mode)=0;
     60      virtual uint32_t getData(uint8_t*& mem, uint8_t mode)=0;
    5861      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false)=0;
    5962      virtual uint32_t getSize(uint8_t mode)=0;
     
    6265      virtual ~SynchronisableVariableBase() {}
    6366    protected:
    64       static void setState();
    6567      static uint8_t state_;
    6668  };
     
    7476
    7577      virtual inline uint8_t getMode(){ return mode_; }
    76       virtual inline void getData(uint8_t*& mem, uint8_t mode);
     78      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
    7779      virtual inline void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    7880      virtual inline uint32_t getSize(uint8_t mode);
    7981      virtual inline void* getReference(){ return (void *)&this->variable_; }
    8082    protected:
    81       bool checkEquality(uint8_t* mem);
    82       void setAndIncrease(uint8_t*& mem);
    83       void getAndIncrease(uint8_t*& mem);
    84       uint32_t returnSize();
    8583     
    8684      T& variable_;
     
    9795     
    9896      virtual inline uint8_t getMode(){ return 0x3; } //this basically is a hack ^^
    99       virtual void getData(uint8_t*& mem, uint8_t mode);
     97      virtual inline uint32_t getData(uint8_t*& mem, uint8_t mode);
    10098      virtual void putData(uint8_t*& mem, uint8_t mode, bool forceCallback = false);
    101       virtual uint32_t getSize(uint8_t mode);
     99      virtual inline uint32_t getSize(uint8_t mode);
    102100    private:
    103101      T varBuffer_;
     
    110108      variable_( variable ), mode_( syncDirection ), callback_( cb )
    111109  {
    112       setState();
     110    if ( state_ == 0x0 )
     111    {
     112      state_ = GameMode::isMaster() ? 0x1 : 0x2;  // set the appropriate mode here
     113    }
    113114  }
    114115 
     
    119120  }
    120121
    121   template <class T> void SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
     122  template <class T> inline uint32_t SynchronisableVariable<T>::getData(uint8_t*& mem, uint8_t mode)
    122123  {
    123124    if ( state_ == this->mode_ )
    124       getAndIncrease( mem );
    125 //   mem += SynchronisableVariable<T>::getSize();
     125    {
     126      saveAndIncrease( this->variable_, mem );
     127      return returnSize( this->variable_ );
     128    }
     129    else
     130      return 0;
    126131  }
    127132
     
    135140    if ( this->callback_ != 0 )
    136141    {
    137       if( forceCallback || !checkEquality( mem ) )
     142      if( forceCallback || !checkEquality( this->variable_, mem ) )
    138143        callback = true;
    139144    }
    140145  // write the data
    141     setAndIncrease( mem );
    142 //   mem += SynchronisableVariable<T>::getSize();
     146    loadAndIncrease( this->variable_, mem );
    143147  // now do a callback if neccessary
    144148    if ( callback )
    145149      NetworkCallbackManager::triggerCallback( this->callback_ );
    146       //this->callback_->call();
    147   }
    148 
    149   template <class T> uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
     150  }
     151
     152  template <class T> inline uint32_t SynchronisableVariable<T>::getSize(uint8_t mode)
    150153  {
    151154    if ( mode == this->mode_ )
    152       return returnSize();
     155      return returnSize( this->variable_ );
    153156    else
    154157      return 0;
    155158  }
    156159
    157   template <> _NetworkExport uint32_t SynchronisableVariable<const bool>::returnSize();
    158   template <> _NetworkExport void     SynchronisableVariable<const bool>::setAndIncrease(uint8_t*& mem);
    159   template <> _NetworkExport void     SynchronisableVariable<const bool>::getAndIncrease(uint8_t*& mem);
    160   template <> _NetworkExport bool     SynchronisableVariable<const bool>::checkEquality(uint8_t* mem);
    161   template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned char>::returnSize();
    162   template <> _NetworkExport void     SynchronisableVariable<const unsigned char>::setAndIncrease(uint8_t*& mem);
    163   template <> _NetworkExport void     SynchronisableVariable<const unsigned char>::getAndIncrease(uint8_t*& mem);
    164   template <> _NetworkExport bool     SynchronisableVariable<const unsigned char>::checkEquality(uint8_t* mem);
    165   template <> _NetworkExport uint32_t SynchronisableVariable<const short>::returnSize();
    166   template <> _NetworkExport void     SynchronisableVariable<const short>::setAndIncrease(uint8_t*& mem);
    167   template <> _NetworkExport void     SynchronisableVariable<const short>::getAndIncrease(uint8_t*& mem);
    168   template <> _NetworkExport bool     SynchronisableVariable<const short>::checkEquality(uint8_t* mem);
    169   template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned short>::returnSize();
    170   template <> _NetworkExport void     SynchronisableVariable<const unsigned short>::setAndIncrease(uint8_t*& mem);
    171   template <> _NetworkExport void     SynchronisableVariable<const unsigned short>::getAndIncrease(uint8_t*& mem);
    172   template <> _NetworkExport bool     SynchronisableVariable<const unsigned short>::checkEquality(uint8_t* mem);
    173   template <> _NetworkExport uint32_t SynchronisableVariable<const int>::returnSize();
    174   template <> _NetworkExport void     SynchronisableVariable<const int>::setAndIncrease(uint8_t*& mem);
    175   template <> _NetworkExport void     SynchronisableVariable<const int>::getAndIncrease(uint8_t*& mem);
    176   template <> _NetworkExport bool     SynchronisableVariable<const int>::checkEquality(uint8_t* mem);
    177   template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned int>::returnSize();
    178   template <> _NetworkExport void     SynchronisableVariable<const unsigned int>::setAndIncrease(uint8_t*& mem);
    179   template <> _NetworkExport void     SynchronisableVariable<const unsigned int>::getAndIncrease(uint8_t*& mem);
    180   template <> _NetworkExport bool     SynchronisableVariable<const unsigned int>::checkEquality(uint8_t* mem);
    181   template <> _NetworkExport uint32_t SynchronisableVariable<const long>::returnSize();
    182   template <> _NetworkExport void     SynchronisableVariable<const long>::setAndIncrease(uint8_t*& mem);
    183   template <> _NetworkExport void     SynchronisableVariable<const long>::getAndIncrease(uint8_t*& mem);
    184   template <> _NetworkExport bool     SynchronisableVariable<const long>::checkEquality(uint8_t* mem);
    185   template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long>::returnSize();
    186   template <> _NetworkExport void     SynchronisableVariable<const unsigned long>::setAndIncrease(uint8_t*& mem);
    187   template <> _NetworkExport void     SynchronisableVariable<const unsigned long>::getAndIncrease(uint8_t*& mem);
    188   template <> _NetworkExport bool     SynchronisableVariable<const unsigned long>::checkEquality(uint8_t* mem);
    189   template <> _NetworkExport uint32_t SynchronisableVariable<const long long>::returnSize();
    190   template <> _NetworkExport void     SynchronisableVariable<const long long>::setAndIncrease(uint8_t*& mem);
    191   template <> _NetworkExport void     SynchronisableVariable<const long long>::getAndIncrease(uint8_t*& mem);
    192   template <> _NetworkExport bool     SynchronisableVariable<const long long>::checkEquality(uint8_t* mem);
    193   template <> _NetworkExport uint32_t SynchronisableVariable<const unsigned long long>::returnSize();
    194   template <> _NetworkExport void     SynchronisableVariable<const unsigned long long>::setAndIncrease(uint8_t*& mem);
    195   template <> _NetworkExport void     SynchronisableVariable<const unsigned long long>::getAndIncrease(uint8_t*& mem);
    196   template <> _NetworkExport bool     SynchronisableVariable<const unsigned long long>::checkEquality(uint8_t* mem);
    197   template <> _NetworkExport uint32_t SynchronisableVariable<const float>::returnSize();
    198   template <> _NetworkExport void     SynchronisableVariable<const float>::setAndIncrease(uint8_t*& mem);
    199   template <> _NetworkExport void     SynchronisableVariable<const float>::getAndIncrease(uint8_t*& mem);
    200   template <> _NetworkExport bool     SynchronisableVariable<const float>::checkEquality(uint8_t* mem);
    201   template <> _NetworkExport uint32_t SynchronisableVariable<const double>::returnSize();
    202   template <> _NetworkExport void     SynchronisableVariable<const double>::setAndIncrease(uint8_t*& mem);
    203   template <> _NetworkExport void     SynchronisableVariable<const double>::getAndIncrease(uint8_t*& mem);
    204   template <> _NetworkExport bool     SynchronisableVariable<const double>::checkEquality(uint8_t* mem);
    205   template <> _NetworkExport uint32_t SynchronisableVariable<const long double>::returnSize();
    206   template <> _NetworkExport void     SynchronisableVariable<const long double>::setAndIncrease(uint8_t*& mem);
    207   template <> _NetworkExport void     SynchronisableVariable<const long double>::getAndIncrease(uint8_t*& mem);
    208   template <> _NetworkExport bool     SynchronisableVariable<const long double>::checkEquality(uint8_t* mem);
    209   template <> _NetworkExport uint32_t SynchronisableVariable<const std::string>::returnSize();
    210   template <> _NetworkExport void     SynchronisableVariable<const std::string>::setAndIncrease(uint8_t*& mem);
    211   template <> _NetworkExport void     SynchronisableVariable<const std::string>::getAndIncrease(uint8_t*& mem);
    212   template <> _NetworkExport bool     SynchronisableVariable<const std::string>::checkEquality(uint8_t* mem);
    213   template <> _NetworkExport uint32_t SynchronisableVariable<const Degree>::returnSize();
    214   template <> _NetworkExport void     SynchronisableVariable<const Degree>::setAndIncrease(uint8_t*& mem);
    215   template <> _NetworkExport void     SynchronisableVariable<const Degree>::getAndIncrease(uint8_t*& mem);
    216   template <> _NetworkExport bool     SynchronisableVariable<const Degree>::checkEquality(uint8_t* mem);
    217160
    218161
     
    229172    }
    230173
    231     template <class T> void SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
     174    template <class T> uint32_t SynchronisableVariableBidirectional<T>::getData(uint8_t*& mem, uint8_t mode)
    232175    {
    233176      if ( this->mode_ == mode )
     
    243186      mem += sizeof(this->varReference_);
    244187  // now write the content
    245       SynchronisableVariable<T>::getAndIncrease( mem );
    246 //   mem += SynchronisableVariable<T>::getSize();
     188      saveAndIncrease( this->variable_, mem );
     189      return SynchronisableVariableBidirectional::getSize(mode);
    247190    }
    248191
     
    255198        if ( *static_cast<uint8_t*>(mem) != this->varReference_ )
    256199        { // wrong reference number, so discard the data
     200//           COUT(0) << "discharding data" << endl;
    257201          mem += getSize( mode ); // SynchronisableVariableBidirectional::getSize returns size of variable + reference
    258202          return;
     
    260204        else{
    261205          // apply data
    262           mem += sizeof(varReference_);
    263           if ( SynchronisableVariableBidirectional<T>::checkEquality( mem )==true )
     206          if ( checkEquality( this->variable_, mem+sizeof(varReference_) )==true )
    264207          {
    265             mem += SynchronisableVariable<T>::getSize( mode );
     208            mem += getSize( mode );
    266209            return;
    267210          }
    268211          else
    269212          {
     213            mem += sizeof(varReference_);
    270214            memcpy((void*)&this->varBuffer_, &this->variable_, sizeof(T));
    271215            if ( this->callback_ != 0 )
     
    285229          this->varReference_ = *static_cast<uint8_t*>(mem);
    286230          mem += sizeof(varReference_);
    287           if ( SynchronisableVariable<T>::checkEquality( mem ) == false )
     231          if ( checkEquality( this->variable_, mem ) == false )
    288232          {
    289233            // value changed so remark for callback
     
    294238      }
    295239  // now write the data
    296       SynchronisableVariable<T>::setAndIncrease(mem);
     240      loadAndIncrease(this->variable_, mem);
    297241  // now do a callback if neccessary
    298242      if ( callback )
    299243        NetworkCallbackManager::triggerCallback( this->callback_ );
    300         //this->callback_->call();
    301     }
    302 
    303     template <class T> uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
    304     {
    305       return SynchronisableVariable<T>::returnSize() + sizeof(varReference_);
     244    }
     245
     246    template <class T> inline uint32_t SynchronisableVariableBidirectional<T>::getSize(uint8_t mode)
     247    {
     248      return returnSize( this->variable_ ) + sizeof(varReference_);
    306249    }
    307250 
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r3079 r3084  
    140140    class SpawnPoint;
    141141    class TeamSpawnPoint;
     142    class Test;
    142143
    143144    class Spectator;
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r2928 r3084  
    5757namespace orxonox
    5858{
    59     AddGameState(GSGraphics, "graphics");
    60 
    61     GSGraphics::GSGraphics(const std::string& name)
    62         : GameState(name)
     59    AddGameState(GSGraphics, "graphics", false);
     60
     61    GSGraphics::GSGraphics(const std::string& name, bool countTickTime)
     62        : GameState(name, countTickTime)
    6363        , inputManager_(0)
    6464        , console_(0)
     
    213213        uint64_t timeBeforeTick = time.getRealMicroseconds();
    214214
    215         this->inputManager_->update(time);        // tick console
     215        this->inputManager_->update(time);
    216216        this->console_->update(time);
    217         this->guiManager_->update(time);
    218217
    219218        uint64_t timeAfterTick = time.getRealMicroseconds();
     
    222221        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    223222
     223        // Process gui events
     224        this->guiManager_->update(time);
    224225        // Render
    225226        this->graphicsManager_->update(time);
  • code/trunk/src/orxonox/gamestates/GSGraphics.h

    r2896 r3084  
    5151    {
    5252    public:
    53         GSGraphics(const std::string& name);
     53        GSGraphics(const std::string& name, bool countTickTime);
    5454        ~GSGraphics();
    5555        void setConfigValues();
  • code/trunk/src/orxonox/gamestates/GSRoot.cc

    r2928 r3084  
    4343namespace orxonox
    4444{
    45     AddGameState(GSRoot, "root");
     45    AddGameState(GSRoot, "root", false);
    4646    SetCommandLineSwitch(console);
    4747    // Shortcuts for easy direct loading
     
    5151    SetCommandLineSwitch(standalone);
    5252
    53     GSRoot::GSRoot(const std::string& name)
    54         : GameState(name)
     53    GSRoot::GSRoot(const std::string& name, bool countTickTime)
     54        : GameState(name, countTickTime)
    5555        , timeFactor_(1.0f)
    5656        , bPaused_(false)
  • code/trunk/src/orxonox/gamestates/GSRoot.h

    r2896 r3084  
    3939    {
    4040    public:
    41         GSRoot(const std::string& name);
     41        GSRoot(const std::string& name, bool countTickTime);
    4242        ~GSRoot();
    4343
  • code/trunk/src/orxonox/objects/CMakeLists.txt

    r3053 r3084  
    1010  Teamcolourable.cc
    1111  Tickable.cc
    12   Test.cc
    1312  Scene.cc
    1413  Script.cc
  • code/trunk/src/orxonox/objects/Test.cc

    r2662 r3084  
    3131#include "core/ConfigValueIncludes.h"
    3232#include "core/ConsoleCommand.h"
     33#include "network/NetworkFunction.h"
    3334#include "Test.h"
     35#include "util/MultiType.h"
    3436
    3537namespace orxonox
     
    4143  SetConsoleCommand(Test, printV3, true).accessLevel(AccessLevel::User);
    4244  SetConsoleCommand(Test, printV4, true).accessLevel(AccessLevel::User);
     45  SetConsoleCommand(Test, call, true).accessLevel(AccessLevel::User);
     46  SetConsoleCommand(Test, call2, true).accessLevel(AccessLevel::User);
     47 
     48 
     49  //void=* aaaaa = copyPtr<sizeof(&Test::printV1)>( &NETWORK_FUNCTION_POINTER, &Test::printV1 );
     50  //void* NETWORK_FUNCTION_TEST_B = memcpy(&NETWORK_FUNCTION_POINTER, &a, sizeof(a));
     51//   NetworkFunctionBase* NETWORK_FUNCTION_TEST_C = new NetworkFunctionStatic( createFunctor(&Test::printV1), "bla", NETWORK_FUNCTION_POINTER );
     52 
     53  registerStaticNetworkFunction( &Test::printV1 );
     54  registerMemberNetworkFunction( Test, checkU1 );
     55  registerMemberNetworkFunction( Test, printBlaBla );
    4356 
    4457  Test* Test::instance_ = 0;
     
    7386
    7487
    75         void Test::registerVariables()
    76         {
    77                 registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
     88  void Test::registerVariables()
     89  {
     90    registerVariable ( u1, variableDirection::toclient, new NetworkCallback<Test> ( this, &Test::checkU1 ));
    7891    registerVariable ( u2, variableDirection::toserver, new NetworkCallback<Test> ( this, &Test::checkU2 ));
    79                 registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
     92    registerVariable ( u3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkU3 ), true );
    8093    registerVariable ( u4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkU4 ), true );
    8194   
     
    8497    registerVariable ( s3, variableDirection::serverMaster, new NetworkCallback<Test> ( this, &Test::checkS3 ), true );
    8598    registerVariable ( s4, variableDirection::clientMaster, new NetworkCallback<Test> ( this, &Test::checkS4 ), true );
    86         }
    87 
     99  }
     100 
     101  void Test::call(unsigned int clientID)
     102  {
     103    callStaticNetworkFunction( &Test::printV1, clientID );
     104    callStaticNetworkFunction( &Test::printV1, clientID );
     105  }
     106 
     107  void Test::call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4)
     108  {
     109    callMemberNetworkFunction( Test, printBlaBla, this->getObjectID(), clientID, s1, s2, s3, s4, s4 );
     110  }
     111 
     112  void Test::tick(float dt)
     113  {
     114//     std::string str1 = "blub";
     115//     //MultiType mt1(std::string("blub"));
     116//     MultiType mt1(str1);
     117//     uint8_t* mem = new uint8_t[mt1.getNetworkSize()];
     118//     uint8_t* temp = mem;
     119//     mt1.exportData( temp );
     120//     assert( temp-mem == mt1.getNetworkSize() );
     121//     MultiType mt2;
     122//     temp = mem;
     123//     mt2.importData( temp );
     124//     assert( temp-mem == mt1.getNetworkSize() );
     125//     COUT(0) << mt2 << endl;
     126    if(!Core::isMaster())
     127      call2(0, "bal", "a", "n", "ce");
     128//       callMemberNetworkFunction( Test, checkU1, this->getObjectID(), 0 );
     129  }
     130 
     131  void Test::printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5)
     132  {
     133    COUT(0) << s1 << s2 << s3 << s4 << s5 << endl;
     134  }
     135 
    88136  void Test::checkU1(){ COUT(1) << "U1 changed: " << u1 << std::endl; }
    89137  void Test::checkU2(){ COUT(1) << "U2 changed: " << u2 << std::endl; }
  • code/trunk/src/orxonox/objects/Test.h

    r2662 r3084  
    3333#include "core/BaseObject.h"
    3434#include "network/synchronisable/Synchronisable.h"
     35#include "Tickable.h"
    3536
    3637
     
    4142namespace orxonox
    4243{
    43   class _OrxonoxExport Test: public BaseObject, public Synchronisable
     44  class _OrxonoxExport Test: public BaseObject, public Synchronisable, public Tickable
    4445  {
    4546    public:
     
    4950      void setConfigValues();
    5051      void registerVariables();
     52     
     53      static void call(unsigned int clientID);
     54      void call2(unsigned int clientID, std::string s1, std::string s2, std::string s3, std::string s4);
     55      virtual void tick(float dt);
    5156
    5257
     
    7580      static void printV3(){ instance_->checkU3(); }
    7681      static void printV4(){ instance_->checkU4(); }
     82     
     83      void printBlaBla(std::string s1, std::string s2, std::string s3, std::string s4, std::string s5);
    7784
    7885    private:
  • code/trunk/src/orxonox/objects/controllers/AIController.cc

    r3053 r3084  
    3030#include "AIController.h"
    3131
    32 #include "core/GameMode.h"
    3332#include "core/CoreIncludes.h"
    3433#include "core/Executor.h"
     
    4544        RegisterObject(AIController);
    4645
    47         if (GameMode::isMaster())
    48             this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&AIController::action)));
     46        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&AIController::action)));
    4947    }
    5048
  • code/trunk/src/orxonox/objects/worldentities/ControllableEntity.cc

    r3049 r3084  
    379379        registerVariable(this->client_orientation_,      variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation));
    380380        registerVariable(this->client_angular_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity));
     381       
    381382
    382383        registerVariable(this->playerID_,                variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
  • code/trunk/src/orxonox/objects/worldentities/MobileEntity.h

    r3068 r3084  
    6161                { this->setAngularVelocity(Vector3(x, y, z)); }
    6262            inline const Vector3& getAngularVelocity() const
    63                 { return this->linearAcceleration_; }
     63                { return this->angularVelocity_; }
    6464
    6565            void setAcceleration(const Vector3& acceleration);
  • code/trunk/src/orxonox/objects/worldentities/PongBall.cc

    r2896 r3084  
    3232#include "core/CoreIncludes.h"
    3333#include "core/GameMode.h"
    34 #include "objects/worldentities/PongBat.h"
    3534#include "objects/gametypes/Gametype.h"
    3635
     
    4746        this->speed_ = 0;
    4847        this->bat_ = 0;
     48        this->batID_ = new unsigned int[2];
     49        this->batID_[0] = OBJECTID_UNKNOWN;
     50        this->batID_[1] = OBJECTID_UNKNOWN;
    4951        this->relMercyOffset_ = 0.05;
     52       
     53        this->registerVariables();
     54    }
     55   
     56    void PongBall::registerVariables()
     57    {
     58        registerVariable( this->fieldWidth_ );
     59        registerVariable( this->fieldHeight_ );
     60        registerVariable( this->batlength_ );
     61        registerVariable( this->speed_ );
     62        registerVariable( this->relMercyOffset_ );
     63        registerVariable( this->batID_[0] );
     64        registerVariable( this->batID_[1], variableDirection::toclient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) );
    5065    }
    5166
     
    119134                this->setPosition(position);
    120135        }
     136        else
     137        {
     138          Vector3 position = this->getPosition();
     139          Vector3 velocity = this->getVelocity();
     140
     141          if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
     142          {
     143            velocity.z = -velocity.z;
     144
     145            if (position.z > this->fieldHeight_ / 2)
     146              position.z = this->fieldHeight_ / 2;
     147            if (position.z < -this->fieldHeight_ / 2)
     148              position.z = -this->fieldHeight_ / 2;
     149          }
     150
     151          if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
     152          {
     153            float distance = 0;
     154
     155            if (this->bat_)
     156            {
     157              if (position.x > this->fieldWidth_ / 2 && this->bat_[1])
     158              {
     159                distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     160                if (fabs(distance) <= 1)
     161                {
     162                  position.x = this->fieldWidth_ / 2;
     163                  velocity.x = -velocity.x;
     164                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     165                }
     166              }
     167              if (position.x < -this->fieldWidth_ / 2 && this->bat_[0])
     168              {
     169                distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2);
     170                if (fabs(distance) <= 1)
     171                {
     172                  position.x = -this->fieldWidth_ / 2;
     173                  velocity.x = -velocity.x;
     174                  velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_;
     175                }
     176              }
     177            }
     178          }
     179
     180          if (velocity != this->getVelocity())
     181            this->setVelocity(velocity);
     182          if (position != this->getPosition())
     183            this->setPosition(position);
     184        }
    121185    }
    122186
  • code/trunk/src/orxonox/objects/worldentities/PongBall.h

    r2885 r3084  
    3333
    3434#include "objects/worldentities/MovableEntity.h"
     35#include "objects/worldentities/PongBat.h"
    3536
    3637namespace orxonox
     
    4344
    4445            virtual void tick(float dt);
     46           
     47            void registerVariables();
    4548
    4649            void setFieldDimension(float width, float height)
     
    6164
    6265            void setBats(PongBat** bats)
    63                 { this->bat_ = bats; }
     66            { this->bat_ = bats; this->batID_[0] = this->bat_[0]->getObjectID(); this->batID_[1] = this->bat_[1]->getObjectID(); }
     67           
     68            void applyBats()
     69            { if(!this->bat_) this->bat_ = new PongBat*[2]; if(this->batID_[0] != OBJECTID_UNKNOWN) this->bat_[0] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0])); if(this->batID_[1] != OBJECTID_UNKNOWN) this->bat_[1] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1])); }
    6470
    6571            static const float MAX_REL_Z_VELOCITY;
     
    7177            float batlength_;
    7278            PongBat** bat_;
     79            unsigned int* batID_;
    7380            float relMercyOffset_;
    7481    };
  • code/trunk/src/orxonox/objects/worldentities/PongBat.cc

    r2839 r3084  
    5454    {
    5555        registerVariable(this->speed_);
    56         registerVariable(this->speed_);
    57         registerVariable(this->speed_);
     56        registerVariable(this->fieldHeight_);
     57        registerVariable(this->length_);
    5858    }
    5959
     
    9191            position.z = -this->fieldHeight_ / 2 + this->fieldHeight_ * this->length_ / 2;
    9292        if (position != this->getPosition())
     93        {
    9394            this->setPosition(position);
     95            this->setVelocity( Vector3::ZERO );
     96        }
    9497    }
    9598
     
    97100    {
    98101        this->bMoveLocal_ = false;
    99         this->movement_ -= value.x;
     102        this->movement_ = -value.x;
    100103    }
    101104
  • code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r3073 r3084  
    3939#include "objects/worldentities/ParticleSpawner.h"
    4040#include "objects/worldentities/ExplosionChunk.h"
     41
    4142#include "objects/weaponsystem/WeaponSystem.h"
    4243#include "objects/weaponsystem/WeaponSlot.h"
     
    4445#include "objects/weaponsystem/WeaponSet.h"
    4546
     47#include "network/NetworkFunction.h"
     48
    4649namespace orxonox
    4750{
    4851    CreateFactory(Pawn);
     52
     53    registerMemberNetworkFunction( Pawn, doFire );
    4954
    5055    Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator)
     
    123128        SUPER(Pawn, tick, dt);
    124129
    125         if (this->weaponSystem_ && GameMode::isMaster())
    126         {
    127             for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
    128                 if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
    129                     this->weaponSystem_->fire(firemode);
    130 
    131             if (this->bReload_)
    132                 this->weaponSystem_->reload();
    133         }
    134 
    135         this->fire_ = this->firehack_;
    136         this->firehack_ = 0x0;
     130//        if (this->weaponSystem_ && GameMode::isMaster())
     131//        {
     132//            for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++)
     133//                if (this->fire_ & WeaponSystem::getFiremodeMask(firemode))
     134//                    this->weaponSystem_->fire(firemode);
     135//
     136//            if (this->bReload_)
     137//                this->weaponSystem_->reload();
     138//        }
     139//
     140//        this->fire_ = this->firehack_;
     141//        this->firehack_ = 0x0;
    137142        this->bReload_ = false;
    138143
    139         if (this->health_ <= 0)
     144        if (GameMode::isMaster())
     145          if (this->health_ <= 0)
    140146            this->death();
    141147    }
     
    263269    void Pawn::fire(unsigned int firemode)
    264270    {
    265         this->firehack_ |= WeaponSystem::getFiremodeMask(firemode);
     271        this->doFire(firemode);
     272    }
     273
     274    void Pawn::doFire(uint8_t firemode)
     275    {
     276        if(GameMode::isMaster())
     277        {
     278            if (this->weaponSystem_)
     279                this->weaponSystem_->fire(firemode);
     280        }
     281        else
     282        {
     283            callMemberNetworkFunction(Pawn, doFire, this->getObjectID(), 0, ((uint8_t)firemode));
     284            if (this->weaponSystem_)
     285                this->weaponSystem_->fire(firemode);
     286        }
    266287    }
    267288
  • code/trunk/src/orxonox/objects/worldentities/pawns/Pawn.h

    r3073 r3084  
    7979            virtual void fire(unsigned int firemode);
    8080            virtual void reload();
     81            virtual void doFire(uint8_t firemode);
    8182            virtual void postSpawn();
    8283
  • code/trunk/src/util/MultiType.h

    r2662 r3084  
    8080    enum MT_Type
    8181    {
    82         MT_null,
    83         MT_char,
    84         MT_uchar,
    85         MT_short,
    86         MT_ushort,
    87         MT_int,
    88         MT_uint,
    89         MT_long,
    90         MT_ulong,
    91         MT_longlong,
    92         MT_ulonglong,
    93         MT_float,
    94         MT_double,
    95         MT_longdouble,
    96         MT_bool,
    97         MT_void,
    98         MT_string,
    99         MT_vector2,
    100         MT_vector3,
    101         MT_vector4,
    102         MT_colourvalue,
    103         MT_quaternion,
    104         MT_radian,
    105         MT_degree
     82        MT_null=0,
     83        MT_char=1,
     84        MT_uchar=2,
     85        MT_short=3,
     86        MT_ushort=4,
     87        MT_int=5,
     88        MT_uint=6,
     89        MT_long=7,
     90        MT_ulong=8,
     91        MT_longlong=9,
     92        MT_ulonglong=10,
     93        MT_float=11,
     94        MT_double=12,
     95        MT_longdouble=13,
     96        MT_bool=14,
     97        MT_void=15,
     98        MT_string=16,
     99        MT_vector2=17,
     100        MT_vector3=18,
     101        MT_vector4=19,
     102        MT_colourvalue=20,
     103        MT_quaternion=21,
     104        MT_radian=22,
     105        MT_degree=23
    106106    };
    107107
     
    223223
    224224            virtual void toString(std::ostream& outstream) const = 0;
     225           
     226            virtual void importData( uint8_t*& mem )=0;
     227            virtual void exportData( uint8_t*& mem ) const=0;
     228            virtual uint8_t getSize() const=0;
    225229
    226230            MT_Type type_;          //!< The type of the current value
     
    320324            template <typename T> inline bool isType()                  const { return false; } // Only works for specialized values - see below
    321325            std::string                       getTypename()             const;
     326           
     327            /** @brief Saves the value of the MT to a bytestream (pointed at by mem) and increases mem pointer by size of MT */
     328            inline void                       exportData(uint8_t*& mem) const { assert(sizeof(MT_Type)<=8); *(uint8_t*)(mem) = this->getType(); mem+=sizeof(uint8_t); this->value_->exportData(mem); }
     329            /** @brief Loads the value of the MT from a bytestream (pointed at by mem) and increases mem pointer by size of MT */
     330            inline void                       importData(uint8_t*& mem) { assert(sizeof(MT_Type)<=8); this->setType(static_cast<MT_Type>(*(uint8_t*)mem)); mem+=sizeof(uint8_t); this->value_->importData(mem); }
     331            /** @brief Saves the value of the MT to a bytestream and increases pointer to bytestream by size of MT */
     332            inline uint8_t*&                  operator << (uint8_t*& mem) { importData(mem); return mem; }
     333            /** @brief Loads the value of the MT to a bytestream and increases pointer to bytestream by size of MT */
     334            inline void                       operator >> (uint8_t*& mem) const { exportData(mem); }
     335            inline uint32_t                   getNetworkSize() const { assert(this->value_); return this->value_->getSize() + sizeof(uint8_t); }
    322336
    323337            /** @brief Checks whether the value is a default one. */
  • code/trunk/src/util/MultiTypeValue.h

    r2171 r3084  
    4040#include "MathConvert.h"
    4141#include "MultiType.h"
     42#include "Serialise.h"
     43#include <cassert>
    4244
    4345namespace orxonox
     
    147149        /** @brief Puts the current value on the stream */
    148150        inline void toString(std::ostream& outstream) const { outstream << this->value_; }
     151       
     152        /** @brief loads data from the bytestream (mem) into the MT and increases the bytestream pointer by the size of the data */
     153        inline void importData( uint8_t*& mem )         { loadAndIncrease( /*(const T&)*/this->value_, mem ); }
     154        /** @brief saves data from the MT into the bytestream (mem) and increases the bytestream pointer by the size of the data */
     155        inline void exportData( uint8_t*& mem ) const   { saveAndIncrease( /*(const T&)*/this->value_, mem ); }
     156        /** @brief returns the size of the data that would be saved by exportData */
     157        inline uint8_t getSize() const { return returnSize( this->value_ ); }
    149158
    150159        T value_; //!< The stored value
    151160    };
     161   
     162    // Import / Export specialisation
     163    // ColourValue
     164    template <> inline void MT_Value<ColourValue>::importData( uint8_t*& mem )
     165    {
     166        loadAndIncrease( this->value_.r, mem );
     167        loadAndIncrease( this->value_.g, mem );
     168        loadAndIncrease( this->value_.b, mem );
     169        loadAndIncrease( this->value_.a, mem );
     170    }
     171    template <> inline void MT_Value<ColourValue>::exportData( uint8_t*& mem ) const
     172    {
     173        saveAndIncrease( this->value_.r, mem );
     174        saveAndIncrease( this->value_.g, mem );
     175        saveAndIncrease( this->value_.b, mem );
     176        saveAndIncrease( this->value_.a, mem );
     177    }
     178    template <> inline uint8_t MT_Value<ColourValue>::getSize() const
     179    {
     180        return 4*returnSize(this->value_.r);
     181    }
     182    // Ogre::Quaternion
     183    template <> inline void MT_Value<Ogre::Quaternion>::importData( uint8_t*& mem )
     184    {
     185        loadAndIncrease( this->value_.x, mem );
     186        loadAndIncrease( this->value_.y, mem );
     187        loadAndIncrease( this->value_.z, mem );
     188        loadAndIncrease( this->value_.w, mem );
     189    }
     190    template <> inline void MT_Value<Ogre::Quaternion>::exportData( uint8_t*& mem ) const
     191    {
     192        saveAndIncrease( this->value_.x, mem );
     193        saveAndIncrease( this->value_.y, mem );
     194        saveAndIncrease( this->value_.z, mem );
     195        saveAndIncrease( this->value_.w, mem );
     196    }template <> inline uint8_t MT_Value<Ogre::Quaternion>::getSize() const
     197    {
     198        return 4*returnSize(this->value_.x);
     199    }
     200    // Ogre::Vector2
     201    template <> inline void MT_Value<Ogre::Vector2>::importData( uint8_t*& mem )
     202    {
     203        loadAndIncrease( this->value_.x, mem );
     204        loadAndIncrease( this->value_.y, mem );
     205    }
     206    template <> inline void MT_Value<Ogre::Vector2>::exportData( uint8_t*& mem ) const
     207    {
     208        saveAndIncrease( this->value_.x, mem );
     209        saveAndIncrease( this->value_.y, mem );
     210    }
     211    template <> inline uint8_t MT_Value<Ogre::Vector2>::getSize() const
     212    {
     213        return 2*returnSize(this->value_.x);
     214    }
     215    // Ogre::Vector3
     216    template <> inline void MT_Value<Ogre::Vector3>::importData( uint8_t*& mem )
     217    {
     218        loadAndIncrease( this->value_.x, mem );
     219        loadAndIncrease( this->value_.y, mem );
     220        loadAndIncrease( this->value_.z, mem );
     221    }
     222    template <> inline void MT_Value<Ogre::Vector3>::exportData( uint8_t*& mem ) const
     223    {
     224        saveAndIncrease( this->value_.x, mem );
     225        saveAndIncrease( this->value_.y, mem );
     226        saveAndIncrease( this->value_.z, mem );
     227    }
     228    template <> inline uint8_t MT_Value<Ogre::Vector3>::getSize() const
     229    {
     230        return 3*returnSize(this->value_.x);
     231    }
     232    // Ogre::Vector4
     233    template <> inline void MT_Value<Ogre::Vector4>::importData( uint8_t*& mem )
     234    {
     235        loadAndIncrease( this->value_.x, mem );
     236        loadAndIncrease( this->value_.y, mem );
     237        loadAndIncrease( this->value_.z, mem );
     238        loadAndIncrease( this->value_.w, mem );
     239    }
     240    template <> inline void MT_Value<Ogre::Vector4>::exportData( uint8_t*& mem ) const
     241    {
     242        saveAndIncrease( this->value_.x, mem );
     243        saveAndIncrease( this->value_.y, mem );
     244        saveAndIncrease( this->value_.z, mem );
     245        saveAndIncrease( this->value_.w, mem );
     246    }
     247    template <> inline uint8_t MT_Value<Ogre::Vector4>::getSize() const
     248    {
     249        return 4*returnSize(this->value_.x);
     250    }
     251    template <> inline void MT_Value<void*>::importData( uint8_t*& mem )
     252    {
     253        assert(0);
     254    }
     255    template <> inline void MT_Value<void*>::exportData( uint8_t*& mem ) const
     256    {
     257        assert(0);
     258    }
     259    template <> inline uint8_t MT_Value<void*>::getSize() const
     260    {
     261        assert(0); return 0;
     262    }
    152263}
    153264
  • code/trunk/src/util/Serialise.h

    • Property svn:eol-style set to native
Note: See TracChangeset for help on using the changeset viewer.