Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 5, 2008, 1:19:22 AM (16 years ago)
Author:
scheusso
Message:

a lot of changes in order to make it possible to have mulpiple clients with each one a new ship
camera changes
object changes
synchronisable: backsyncronisation should be possible now
gamestatemanager/gamestateclient: functions for backsyncronisation
some changes in order to get the input system (the old one) on the client working
TODO something with the camera position is wrong at the moment (clientside)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network3/src/network/PacketGenerator.cc

    r1180 r1232  
    6161    return packet;
    6262  }
     63 
     64  ENetPacket* command( int dataLength, void *data, int reliable = ENET_PACKET_FLAG_RELIABLE )
     65  {
     66    void *stream = new char[dataLength + 2*sizeof(int)];
     67    if(!stream)
     68      return NULL;
     69    packet_id a = COMMAND;
     70    memcpy(stream, (void*)&a, sizeof(int));
     71    memcpy((unsigned char *)stream+sizeof(int), (void*)&dataLength, sizeof(int));
     72    memcpy((unsigned char *)stream+2*sizeof(int), data, dataLength);
     73    return enet_packet_create(stream, dataLength+2*sizeof(int), reliable);
     74  }
    6375
    6476  /*### mouseupdates */
     
    108120    //std::cout << "states->compsize " << states->compsize << std::endl;
    109121    int gid = GAMESTATE; //first assign the correct enet id
    110     int totalLen = 5*sizeof( int ) + sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
     122    int totalLen = 5*sizeof( int ) + 2*sizeof(bool) + states->compsize; //calculate the total size of the datastream memory
    111123    //std::cout << "totalLen " << totalLen << std::endl;
    112     unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
     124    //unsigned char *data = (unsigned char*)malloc( totalLen ); //allocate the memory for datastream
     125    unsigned char *data = new unsigned char[totalLen];
    113126    memcpy( (void*)(data), (const void*)&gid, sizeof( int ) ); //this is the enet id
    114127    memcpy( (void*)(data+sizeof(int)), (const void*)&(states->id), sizeof(int) ); //the GameStateCompressed id
     
    118131    memcpy( (void*)(data+5*sizeof(int)), (const void*)&(states->diffed), sizeof(bool));
    119132    //place the GameStateCompressed data at the end of the enet datastream
    120     memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)states->data, states->compsize );
     133    memcpy( (void*)(data+5*sizeof( int ) + sizeof(bool)), (const void*)&(states->complete), sizeof(bool) );
     134    memcpy( (void*)(data+5*sizeof( int ) + 2*sizeof(bool)), (const void*)states->data, states->compsize );
    121135    //create an enet packet with the generated bytestream
    122136    COUT(4) << "PacketGenerator generating totalLen " << totalLen << std::endl;
     
    128142  ENetPacket* PacketGenerator::clid( int classid, std::string classname, int reliable )
    129143  {
    130     unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
     144    //unsigned char* data = (unsigned char *)malloc(3*sizeof(int)+classname.length()+1);
     145    unsigned char *data = new unsigned char[3*sizeof(int)+classname.length()+1];
    131146    std::cout << "PacketGenerator: classid: " << classid << ", name: " << classname << std::endl;
    132147    *(int *)data = CLASSID;
     
    137152    return packet;
    138153  }
     154 
     155  ENetPacket* PacketGenerator::generateWelcome( int clientID,int shipID, bool allowed , int reliable ){
     156    welcome *wc = new welcome;
     157    wc->id = WELCOME;
     158    wc->clientID = clientID;
     159    wc->shipID = shipID;
     160    wc->allowed = true;
     161    ENetPacket *packet = enet_packet_create( wc, sizeof(welcome), reliable);
     162    return packet;
     163  }
     164 
     165  ENetPacket* PacketGenerator::generateConnectRequest( int reliable ){
     166    connectRequest *con = new connectRequest;
     167    con->id=CONNECT;
     168    return enet_packet_create( con, sizeof(connectRequest), reliable);
     169  }
    139170
    140171}
Note: See TracChangeset for help on using the changeset viewer.