Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 20, 2005, 2:51:37 PM (18 years ago)
Author:
rennerc
Message:

synchronizeable: added sender parameter to writeBytes
network_stream: creates now a network_game_manager
network_game_manager: implemented some functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/network_game_manager.cc

    r6139 r6190  
    2020#define DEBUG_MODULE_NETWORK
    2121
     22#include "factory.h"
     23#include "network_stream.h"
     24
    2225/* include your own header */
    2326#include "network_game_manager.h"
     
    4144NetworkGameManager::~NetworkGameManager()
    4245{
    43 }
    44 
    45 
    46 void NetworkGameManager::writeBytes(const byte* data, int length)
     46  for ( int i = 0; i<inBuffer.size(); i++)
     47  {
     48    if ( inBuffer[i].buffer )
     49      delete inBuffer[i].buffer;
     50    if ( outBuffer[i].buffer )
     51      delete outBuffer[i].buffer;
     52  }
     53}
     54
     55
     56void NetworkGameManager::writeBytes(const byte* data, int length, int sender)
    4757{
    4858}
     
    121131bool NetworkGameManager::canCreateEntity(int classID)
    122132{
    123 }
     133  return true;
     134}
     135
     136/*!
     137 * Sends the Entities to the new connected client
     138 * @param userID: The ID of the user
     139 */
     140void NetworkGameManager::sendEntityList( int userID )
     141{
     142}
     143
     144/**
     145 * Creates a buffer for user n
     146 * @param n The ID of the user
     147 */
     148void NetworkGameManager::resizeBufferVector( int n )
     149{
     150  for ( int i = inBuffer.size(); i<=n; i++)
     151  {
     152    clientBuffer inBuf;
     153    clientBuffer outBuf;
     154
     155    inBuf.length = 0;
     156    outBuf.length = 0;
     157
     158    inBuf.maxLength = 5*1014;
     159    outBuf.maxLength = 5*1024;
     160
     161    inBuf.buffer = new byte[5*1014];
     162    outBuf.buffer = new byte[5*1014];
     163
     164    inBuffer.push_back(inBuf);
     165    outBuffer.push_back(outBuf);
     166  }
     167}
     168
     169/**
     170 * Creates the entity on this host
     171 * @param classID: ClassID of the entity to create
     172 * @param uniqueID: Unique ID to assign to the synchronizeable
     173 * @param owner: owner of this synchronizealbe
     174 */
     175void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner )
     176{
     177  BaseObject * b = Factory::fabricate( classID );
     178
     179  if ( b->isA(CL_SYNCHRONIZEABLE) )
     180  {
     181    Synchronizeable * s = dynamic_cast<Synchronizeable*>(b);
     182    s->setUniqueID( uniqueID );
     183    s->setOwner( owner );
     184    this->networkStream->connectSynchronizeable( *s );
     185  }
     186  else
     187  {
     188    PRINTF(1)("Class with ID %d is not a synchronizeable!", (int)classID);
     189    delete b;
     190  }
     191}
     192
     193/**
     194 * Removes a entity on this host
     195 * @param uniqueID: unique ID assigned with the entity to remove
     196 */
     197void NetworkGameManager::doRemoveEntity( int uniqueID )
     198{
     199  SynchronizeableList::const_iterator it,e;
     200  it = this->networkStream->getSyncBegin();
     201  e = this->networkStream->getSyncEnd();
     202
     203  while ( it != e )
     204  {
     205    if ( (*it)->getUniqueID() == uniqueID )
     206    {
     207      delete *it;
     208      break;
     209    }
     210  }
     211}
     212
     213/**
     214 * Tell the synchronizeable that a user's synchronizeable is out of sync
     215 * @param uniqueID: unique ID assigned with the entity which is out of sync
     216 * @param userID: user ID who's synchronizeable is out of sync
     217 */
     218void NetworkGameManager::doRequestSync( int uniqueID, int userID )
     219{
     220  SynchronizeableList::const_iterator it,e;
     221  it = this->networkStream->getSyncBegin();
     222  e = this->networkStream->getSyncEnd();
     223
     224  while ( it != e )
     225  {
     226    if ( (*it)->getUniqueID() == uniqueID )
     227    {
     228      (*it)->requestSync( userID );
     229      break;
     230    }
     231  }
     232}
Note: See TracChangeset for help on using the changeset viewer.