Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 868


Ignore:
Timestamp:
Mar 6, 2008, 4:45:49 PM (16 years ago)
Author:
scheusso
Message:

some changes

Location:
code/branches/network
Files:
7 edited

Legend:

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

    r790 r868  
    3333
    3434    <!--Fighter camera="true" position="0,0,0" scale="10" yaw="-90" pitch="-90" mesh="assf3.mesh"  forward="500" rotateupdown="200" rotaterightleft="200" looprightleft="200" /-->
    35     <SpaceShip camera="true" position="0,0,0" scale="10" yaw="-90" pitch="-90" mesh="assf5.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
     35    <SpaceShip camera="true" position="0,0,0" scale="10" yaw="-90" pitch="-90" mesh="assf3.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
    3636
    3737    <NPC position="0,100,400" scale="1" mesh="razor.mesh"/>
     
    4141    <NPC position="100,0,400" scale="1" mesh="razor.mesh"/>
    4242
    43     <Model position="200,0,500" scale="10" mesh="starship.mesh" yaw="-90" pitch="-90" />
    44     <Model position="-200,0,500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90" />
     43<!--    <Model position="200,0,500" scale="10" mesh="starship.mesh" yaw="-90" pitch="-90" />
     44    <Model position="-200,0,500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90" />-->
    4545
    4646    <Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yaw="-90" pitch="-90" />
  • code/branches/network/src/network/GameStateClient.cc

    r790 r868  
    6161  * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
    6262  */
    63   bool GameStateClient::loadSnapshot(GameState state) {
    64     unsigned char *data=state.data;
    65     std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;
     63  bool GameStateClient::loadSnapshot(GameState *state) {
     64    unsigned char *data=state->data;
     65    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    6666    // get the start of the Synchronisable list
    6767    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
    6868    syncData sync;
    6969    // loop as long as we have some data ;)
    70     while(data < state.data+state.size){
     70    while(data < state->data+state->size){
    7171      // prepare the syncData struct
    7272      sync.length = (int)*data;
     
    8282        // bad luck ;)
    8383        // delete the synchronisable (obviously seems to be deleted on the server)
    84         while(it != 0 && it->objectID!=sync.objectID){
     84        while(it && it->objectID!=sync.objectID){
    8585          removeObject(it);
    8686        }
    87         if(it==0){
    88           std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
     87        if(!it){
     88          COUT(4) << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
    8989          Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate());
    9090          no->objectID=sync.objectID;
     
    9393          // update data and create object/entity...
    9494          if( !no->updateData(sync) && !no->create() )
    95             COUT(0) << "We couldn't create/update the object: " << sync.objectID << std::endl;
     95            COUT(2) << "We couldn't create/update the object: " << sync.objectID << std::endl;
    9696          ++it;
    9797        }
     
    9999        // we have our object
    100100        if(! it->updateData(sync))
    101           std::cout << "We couldn't update objectID: " \
     101          COUT(2) << "We couldn't update objectID: " \
    102102          << sync.objectID << "; classID: " << sync.classID << std::endl;
    103103      }
     
    108108  }
    109109
    110   GameState GameStateClient::diff(GameState a, GameState b) {
     110  GameState *GameStateClient::diff(GameState a, GameState b) {
    111111    unsigned char *ap = a.data, *bp = b.data;
    112112    int of=0; // pointers offset
     
    137137    // should be finished now
    138138    // FIXME: is it true or false now? (struct has changed, producing warnings)
    139     GameState r = {b.id, dest_length, true, dp};
     139    GameState *r = new GameState;
     140    r->id = b.id;
     141    r->size = dest_length;
     142    r->diffed = true;
     143    r->data = dp;
    140144    return r;
    141145  }
    142146
    143   GameState GameStateClient::decompress(GameStateCompressed a) {
     147  GameState *GameStateClient::decompress(GameStateCompressed a) {
    144148    int normsize = a.normsize;
    145149    int compsize = a.compsize;
     
    157161    //std::cout << "length " << length << std::endl;
    158162    switch ( retval ) {
    159       case Z_OK: std::cout << "successfully decompressed" << std::endl; break;
    160       case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
    161       case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
    162       case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;
    163     }
    164 
    165     GameState gamestate;
    166     gamestate.id = a.id;
    167     gamestate.size = normsize;
    168     gamestate.data = dest;
    169     gamestate.diffed = a.diffed;
    170 
     163      case Z_OK:
     164        COUT(3) << "successfully decompressed" << std::endl; break;
     165      case Z_MEM_ERROR:
     166        COUT(1) << "not enough memory available" << std::endl;
     167        return NULL;
     168      case Z_BUF_ERROR:
     169        COUT(2) << "not enough memory available in the buffer" << std::endl;
     170        return NULL;
     171      case Z_DATA_ERROR:
     172        COUT(2) << "data corrupted" << std::endl;
     173        return NULL;
     174    }
     175
     176    GameState *gamestate = new GameState;
     177    gamestate->id = a.id;
     178    gamestate->size = normsize;
     179    gamestate->data = dest;
     180    gamestate->diffed = a.diffed;
     181
     182    free(a.data);
     183   
    171184    return gamestate;
    172185  }
    173186
    174   GameState GameStateClient::decode(GameState a, GameStateCompressed x) {
    175     GameState t = decompress(x);
    176     return diff(a, t);
    177   }
    178 
    179   GameState GameStateClient::decode(GameStateCompressed x) {
    180     GameState t = decompress(x);
    181     return t;
     187  GameState *GameStateClient::decode(GameState a, GameStateCompressed x) {
     188    GameState *t = decompress(x);
     189    if(t==NULL)
     190      return NULL;
     191    else
     192      return diff(a, *t);
     193  }
     194
     195  GameState *GameStateClient::decode(GameStateCompressed x) {
     196    GameState *t = decompress(x);
     197    if(t==NULL)
     198      return NULL;
     199    else
     200      return t;
    182201  }
    183202
  • code/branches/network/src/network/GameStateClient.h

    r790 r868  
    2525    bool pushGameState(GameStateCompressed *compstate);
    2626  private:
    27     bool loadSnapshot(GameState state);
    28     GameState diff(GameState a, GameState b);
    29     GameState decompress(GameStateCompressed a);
    30     GameState decode(GameState a, GameStateCompressed x);
    31     GameState decode(GameStateCompressed x);
     27    bool loadSnapshot(GameState *state);
     28    GameState *diff(GameState a, GameState b);
     29    GameState *decompress(GameStateCompressed a);
     30    GameState *decode(GameState a, GameStateCompressed x);
     31    GameState *decode(GameStateCompressed x);
    3232    void removeObject(orxonox::Iterator<Synchronisable> &it);
    3333
  • code/branches/network/src/network/GameStateManager.cc

    r790 r868  
    109109    int offset=0;
    110110    // go through all Synchronisables
    111     for(it = orxonox::ObjectList<Synchronisable>::start(); it != 0; ++it){
     111    for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
    112112      //std::cout << "gamestatemanager: in for loop" << std::endl;
    113113      //get size of the synchronisable
  • code/branches/network/src/orxonox/Orxonox.cc

    r790 r868  
    8080namespace orxonox
    8181{
    82    // put this in a seperate Class or solve the problem in another fashion
    83   class OrxListener : public Ogre::FrameListener
     82 
     83 
     84 
     85  // put this in a seperate Class or solve the problem in another fashion
     86  class OrxListenerStandalone : public Ogre::FrameListener
    8487  {
    8588    public:
    86       OrxListener(OIS::Keyboard *keyboard, audio::AudioManager*  auMan, gameMode mode)
     89      OrxListenerStandalone(OIS::Keyboard *keyboard, audio::AudioManager*  auMan)
    8790      {
    8891        mKeyboard = keyboard;
    89         mode_=mode;
    9092        auMan_ = auMan;
    9193      }
     
    9698        updateAI();
    9799
    98         if(mode_ == PRESENTATION)
    99           server_g->tick(evt.timeSinceLastFrame);
    100         else if(mode_ == CLIENT)
    101           client_g->tick(evt.timeSinceLastFrame);
    102100
    103101        usleep(10);
     
    116114
    117115    private:
    118       gameMode mode_;
    119116      OIS::Keyboard *mKeyboard;
    120117      audio::AudioManager*  auMan_;
    121118  };
    122 
     119 
     120  class OrxListenerServer : public Ogre::FrameListener
     121  {
     122    public:
     123      OrxListenerServer(){}
     124
     125      bool frameStarted(const Ogre::FrameEvent& evt)
     126      {
     127        updateAI();
     128
     129        server_g->tick(evt.timeSinceLastFrame);
     130        usleep(10);
     131
     132        return true;
     133      }
     134
     135      void updateAI()
     136      {
     137        for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
     138        {
     139          it->update();
     140        }
     141      }
     142
     143    private:
     144  };
     145 
     146 
     147  class OrxListenerClient : public Ogre::FrameListener
     148  {
     149    public:
     150      OrxListenerClient(OIS::Keyboard *keyboard, audio::AudioManager*  auMan)
     151      {
     152        mKeyboard = keyboard;
     153        auMan_ = auMan;
     154      }
     155
     156      bool frameStarted(const Ogre::FrameEvent& evt)
     157      {
     158        auMan_->update();
     159        updateAI();
     160
     161        client_g->tick(evt.timeSinceLastFrame);
     162
     163        usleep(10);
     164
     165        mKeyboard->capture();
     166        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
     167      }
     168
     169      void updateAI()
     170      {
     171        for(Iterator<NPC> it = ObjectList<NPC>::start(); it; ++it)
     172        {
     173          it->update();
     174        }
     175      }
     176
     177    private:
     178      OIS::Keyboard *mKeyboard;
     179      audio::AudioManager*  auMan_;
     180  };
     181   
    123182  // init static singleton reference of Orxonox
    124183  Orxonox* Orxonox::singletonRef_ = NULL;
     
    137196    this->mouse_ = 0;
    138197    this->inputManager_ = 0;
    139     this->frameListener_ = 0;
     198    this->frameListener_.client = 0;
    140199    this->root_ = 0;
    141200  }
     
    181240      mode_ = CLIENT;
    182241    }
    183     else if(mode == std::string("presentation"))
    184     {
    185       serverInit(path);
    186       mode_ = PRESENTATION;
    187     }
    188242    else{
    189243      standaloneInit(path);
     
    193247
    194248  /**
    195    * start modules
     249   * calls the appropriate start function
    196250   */
    197251  void Orxonox::start()
     252  {
     253    switch (mode_){
     254      case CLIENT:
     255        startClient();
     256        break;
     257      case SERVER:
     258        startServer();
     259        break;
     260      case STANDALONE:
     261      default:
     262        startStandalone();
     263        break;
     264    }
     265  }
     266
     267  /**
     268   * start server modules
     269   */
     270  void Orxonox::startServer()
     271  {
     272    //TODO: start modules
     273    //ogre_->startRender();
     274    //TODO: run engine
     275    Factory::createClassHierarchy();
     276    createScene();
     277    setupScene();
     278    //setupInputSystem();
     279    COUT(4) << "************** Server here *************" << std::endl;
     280    createFrameListener();
     281   
     282    //TODO make a server framelistener caller
     283    // startRenderLoop();
     284  }
     285 
     286  /**
     287   * start client modules
     288   */
     289  void Orxonox::startClient()
     290  {
     291    //TODO: start modules
     292    ogre_->startRender();
     293    //TODO: run engine
     294    Factory::createClassHierarchy();
     295    createScene();
     296    setupInputSystem();
     297   
     298    COUT(4) << "************** Client here *************" << std::endl;
     299    createFrameListener();
     300    client_g->establishConnection();
     301    // TODO : server-client initialization
     302    startRenderLoop();
     303  }
     304 
     305  /**
     306   * start standalone modules
     307   */
     308  void Orxonox::startStandalone()
    198309  {
    199310    //TODO: start modules
     
    210321    createFrameListener();
    211322    switch(mode_){
    212     case PRESENTATION:
    213       //ogre_->getRoot()->addFrameListener(new network::ServerFrameListener());
    214       //std::cout << "could not add framelistener" << std::endl;
    215       server_g->open();
    216       break;
    217     case CLIENT:
    218       client_g->establishConnection();
    219       break;
    220     case SERVER:
    221     case STANDALONE:
    222     default:
    223       break;
     323      case CLIENT:
     324        client_g->establishConnection();
     325        break;
     326      case SERVER:
     327      case STANDALONE:
     328      default:
     329        break;
    224330    }
    225331    startRenderLoop();
    226332  }
    227 
     333 
    228334  /**
    229335   * @return singleton object
     
    379485
    380486    // load this file from config
    381     loader_ = new loader::LevelLoader("sample.oxw");
    382     loader_->loadLevel();
     487    if(mode_==STANDALONE){
     488      loader_ = new loader::LevelLoader("sample.oxw");
     489      loader_->loadLevel();
     490    }
    383491
    384492    Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2");
     
    458566
    459567    //if(mode_!=CLIENT) // FIXME just a hack ------- remove this in future
    460       frameListener_ = new OrxListener(keyboard_, auMan_, mode_);
    461     ogre_->getRoot()->addFrameListener(frameListener_);
     568      if(mode_==CLIENT){
     569        frameListener_.client = new OrxListenerClient(keyboard_, auMan_);
     570        ogre_->getRoot()->addFrameListener(frameListener_.client);
     571      }else if(mode_==SERVER){
     572        frameListener_.server = new OrxListenerServer();
     573        ogre_->getRoot()->addFrameListener(frameListener_.server);
     574      }else{
     575        frameListener_.standalone = new OrxListenerStandalone(keyboard_, auMan_);
     576        ogre_->getRoot()->addFrameListener(frameListener_.standalone);
     577      }
     578   
    462579  }
    463580
     
    479596    ogre_->getRoot()->startRendering();
    480597  }
     598 
    481599}
     600
  • code/branches/network/src/orxonox/Orxonox.h

    r790 r868  
    2727    STANDALONE,
    2828    SERVER,
    29     CLIENT,
    30     PRESENTATION
     29    CLIENT
    3130  };
    3231
     32  union OrxListener{
     33    OrxListenerClient *client;
     34    OrxListenerServer *server;
     35    OrxListenerStandalone *standalone;
     36  };
     37 
    3338  class _OrxonoxExport Orxonox
    3439  {
     
    5055      virtual ~Orxonox();
    5156      // init functions
     57      void startStandalone();
     58      void startServer();
     59      void startClient();
    5260      void serverInit(std::string path);
    5361      void clientInit(std::string path);
     
    7684      OIS::Mouse*           mouse_;
    7785      OIS::InputManager*    inputManager_;
    78       OrxListener*          frameListener_;
     86      OrxListener          frameListener_;
    7987      Ogre::Root*           root_;
    8088
  • code/branches/network/src/orxonox/OrxonoxPrereqs.h

    r790 r868  
    7171  class Model;
    7272  class NPC;
    73   class OrxListener;
     73  class OrxListenerServer;
     74  class OrxListenerClient;
     75  class OrxListenerStandalone;
    7476  class Orxonox;
    7577  class Skybox;
Note: See TracChangeset for help on using the changeset viewer.