Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 24, 2008, 11:00:30 PM (17 years ago)
Author:
scheusso
Message:

first success: client clones the servers universe and displays it with quite good performance

Location:
code/branches/network3
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network3/bin/levels/sample.oxw

    r1170 r1184  
    4141for i = 1, 226, 1
    4242do ?>
    43   <!--Model position="<?lua print(math.random(-19597, 18732))?>, <?lua print(math.random(-19597, 18732)) ?>, <?lua print(math.random(-19597, 18732)) ?>" scale="<?lua print(math.random( 20, 119)) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random(16, 44)) ?>" /-->
     43  <Model position="<?lua print(math.random(-19597, 18732))?>, <?lua print(math.random(-19597, 18732)) ?>, <?lua print(math.random(-19597, 18732)) ?>" scale="<?lua print(math.random( 20, 119)) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random(16, 44)) ?>" />
    4444<?lua
    4545end
  • code/branches/network3/src/network/Client.cc

    r1168 r1184  
    4444namespace network
    4545{
     46  Client* Client::_sClient = 0;
     47 
     48  Client* Client::createSingleton(){
     49    if(!_sClient)
     50      _sClient = new Client();
     51    return _sClient;
     52  }
     53 
     54  Client* Client::createSingleton(std::string address, int port){
     55    if(!_sClient)
     56      _sClient = new Client(address, port);
     57    return _sClient;
     58  }
     59 
     60  Client* Client::createSingleton(const char *address, int port){
     61    if(!_sClient)
     62      _sClient = new Client(address, port);
     63    return _sClient;
     64  }
     65 
     66  void Client::destroySingleton(){
     67    if(_sClient){
     68      delete _sClient;
     69      _sClient = 0;
     70    }
     71  }
     72 
     73  Client* Client::getSingleton(){
     74    return _sClient;
     75  }
     76 
    4677  /**
    4778  * Constructor for the Client class
     
    71102  }
    72103
     104  Client::~Client(){
     105    if(isConnected)
     106      closeConnection();
     107  }
     108 
    73109  /**
    74110  * Establish the Connection to the Server
  • code/branches/network3/src/network/Client.h

    r1168 r1184  
    6565  class _NetworkExport Client : PacketDecoder, public orxonox::Tickable{
    6666  public:
    67     Client();
    68     Client(std::string address, int port);
    69     Client(const char *address, int port);
    70 
     67   
     68    static Client* createSingleton();
     69    static Client* createSingleton(std::string address, int port);
     70    static Client* createSingleton(const char *address, int port);
     71    static void destroySingleton();
     72    static Client *getSingleton();
     73   
    7174    bool establishConnection();
    7275    bool closeConnection();
     
    8487
    8588  private:
     89    Client();
     90    Client(std::string address, int port);
     91    Client(const char *address, int port);
     92    ~Client();
     93   
     94    static Client* _sClient;
     95   
    8696    ClientConnection client_connection;
    8797    PacketGenerator pck_gen;
  • code/branches/network3/src/network/Server.cc

    r1175 r1184  
    143143    updateGamestate();
    144144
    145     sleep(1); // TODO remove
     145    //sleep(1); // TODO remove
    146146    return;
    147147  }
  • code/branches/network3/src/orxonox/Orxonox.cc

    r1174 r1184  
    184184    GraphicsEngine::getSingleton().destroy();
    185185
    186     if (client_g)
    187       delete client_g;
     186    if (network::Client::getSingleton())
     187      network::Client::destroySingleton();
    188188    if (server_g)
    189189      delete server_g;
     
    281281    ogre_->setup();
    282282    if(serverIp_.compare("")==0)
    283       client_g = new network::Client();
     283      client_g = network::Client::createSingleton();
    284284    else
    285       client_g = new network::Client(serverIp_, NETWORK_PORT);
     285      client_g = network::Client::createSingleton(serverIp_, NETWORK_PORT);
    286286    if(!ogre_->load(this->dataPath_)) abortImmediateForce(/* unable to load */);
    287287  }
     
    422422    ib->registerListener(console, &Testconsole::execute, '\n', false);
    423423    ib->registerListener(console, &Testconsole::hintandcomplete, '\t', true);
    424     ib->registerListener(console, &Testconsole::clear, '§', true);
     424    ib->registerListener(console, &Testconsole::clear, '', true);
    425425    ib->registerListener(console, &Testconsole::removeLast, '\b', true);
    426426    ib->registerListener(console, &Testconsole::exit, (char)0x1B, true);
  • code/branches/network3/src/orxonox/objects/SpaceShip.cc

    r1180 r1184  
    5050#include "core/XMLPort.h"
    5151#include "core/ConsoleCommand.h"
     52#include "network/Client.h"
    5253
    5354namespace orxonox
     
    165166    void SpaceShip::init()
    166167    {
     168        createCamera();
    167169        // START CREATING THRUSTER
    168170        this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
     
    281283    void SpaceShip::setCamera(const std::string& camera)
    282284    {
    283         Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
    284         this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
     285      // change camera attributes here, if you want to ;)
     286    }
     287   
     288    void SpaceShip::createCamera(){
     289      Ogre::Camera *cam = GraphicsEngine::getSingleton().getSceneManager()->createCamera("ShipCam");
     290      this->camNode_ = this->getNode()->createChildSceneNode("CamNode");
    285291/*
    286292//        node->setInheritOrientation(false);
    287         cam->setPosition(Vector3(0,50,-150));
    288         cam->lookAt(Vector3(0,20,0));
    289         cam->roll(Degree(0));
    290 */
    291 
    292         cam->setPosition(Vector3(-200,0,35));
     293      cam->setPosition(Vector3(0,50,-150));
     294      cam->lookAt(Vector3(0,20,0));
     295      cam->roll(Degree(0));
     296*/
     297
     298      cam->setPosition(Vector3(-200,0,35));
    293299//        cam->setPosition(Vector3(0,-350,0));
    294         cam->lookAt(Vector3(0,0,35));
    295         cam->roll(Degree(-90));
    296 
    297         this->camNode_->attachObject(cam);
    298         GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
     300      cam->lookAt(Vector3(0,0,35));
     301      cam->roll(Degree(-90));
     302
     303      this->camNode_->attachObject(cam);
     304      GraphicsEngine::getSingleton().getRenderWindow()->addViewport(cam);
     305     
    299306    }
    300307
     
    427434    void SpaceShip::tick(float dt)
    428435    {
    429       if (InputManager::getSingleton().getMouse()->getEventCallback() != this)
     436        // only do this if not client TODO: remove this hack
     437      if (!network::Client::getSingleton() && InputManager::getSingleton().getMouse()->getEventCallback() != this)
    430438        {
    431439            if (InputManager::getSingleton().getMouse())
     
    526534        }
    527535
    528         if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
    529             this->acceleration_.x = this->translationAcceleration_;
    530         else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
    531             this->acceleration_.x = -this->translationAcceleration_;
    532         else
    533             this->acceleration_.x = 0;
    534 
    535         if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
    536             this->acceleration_.y = -this->translationAcceleration_;
    537         else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
    538             this->acceleration_.y = this->translationAcceleration_;
    539         else
    540             this->acceleration_.y = 0;
    541 
    542         if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
    543             this->momentum_ = Radian(-this->rotationAccelerationRadian_);
    544         else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
    545             this->momentum_ = Radian(this->rotationAccelerationRadian_);
    546         else
    547             this->momentum_ = 0;
     536        if(!network::Client::getSingleton()){
     537          if (mKeyboard->isKeyDown(OIS::KC_UP) || mKeyboard->isKeyDown(OIS::KC_W))
     538              this->acceleration_.x = this->translationAcceleration_;
     539          else if(mKeyboard->isKeyDown(OIS::KC_DOWN) || mKeyboard->isKeyDown(OIS::KC_S))
     540              this->acceleration_.x = -this->translationAcceleration_;
     541          else
     542              this->acceleration_.x = 0;
     543 
     544          if (mKeyboard->isKeyDown(OIS::KC_RIGHT) || mKeyboard->isKeyDown(OIS::KC_D))
     545              this->acceleration_.y = -this->translationAcceleration_;
     546          else if (mKeyboard->isKeyDown(OIS::KC_LEFT) || mKeyboard->isKeyDown(OIS::KC_A))
     547              this->acceleration_.y = this->translationAcceleration_;
     548          else
     549              this->acceleration_.y = 0;
     550 
     551          if (mKeyboard->isKeyDown(OIS::KC_DELETE) || mKeyboard->isKeyDown(OIS::KC_Q))
     552              this->momentum_ = Radian(-this->rotationAccelerationRadian_);
     553          else if (mKeyboard->isKeyDown(OIS::KC_PGDOWN) || mKeyboard->isKeyDown(OIS::KC_E))
     554              this->momentum_ = Radian(this->rotationAccelerationRadian_);
     555          else
     556              this->momentum_ = 0;
     557        }
    548558
    549559        WorldEntity::tick(dt);
  • code/branches/network3/src/orxonox/objects/SpaceShip.h

    r1056 r1184  
    7171
    7272        private:
     73            void createCamera();
    7374            static SpaceShip* instance_s;
    7475
  • code/branches/network3/src/orxonox/objects/WorldEntity.cc

    r1174 r1184  
    216216      registerVar( (void*) &(this->getRotationAxis().y), sizeof(this->getRotationAxis().y), network::DATA);
    217217      registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);
     218     
     219      registerVar( (void*) &(this->getScale().x), sizeof(this->getScale().x), network::DATA);
     220      registerVar( (void*) &(this->getScale().y), sizeof(this->getScale().y), network::DATA);
     221      registerVar( (void*) &(this->getScale().z), sizeof(this->getScale().z), network::DATA);
    218222    }
    219223
Note: See TracChangeset for help on using the changeset viewer.