Changeset 80b3f94 in network-game for common


Ignore:
Timestamp:
Jan 29, 2013, 7:04:22 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
ad5d122
Parents:
88cdae2
Message:

Cjamged tje serialize/deserialize functions for Player

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    r88cdae2 r80b3f94  
    5151void Player::serialize(char* buffer)
    5252{
    53    ostringstream oss;
    54 
    55    oss << this->id;
    56    oss << this->name;
    57    oss << '\0';
    58    oss << this->pos.x;
    59    oss << this->pos.y;
    60 
    61    memcpy(buffer, oss.str().c_str(), oss.str().length());
     53   memcpy(buffer, &this->id, 4);
     54   strcpy(buffer+4, this->name.c_str());
     55   memcpy(buffer+4+this->name.length(), &this->pos.x, 4);
     56   memcpy(buffer+8+this->name.length(), &this->pos.y, 4);
    6257}
    6358
    6459void Player::deserialize(char* buffer)
    6560{
    66    istringstream iss;
    67    iss.str(buffer);
     61   char test[256];
    6862
    69    iss >> this->id;
    70    iss >> this->name;
    71    iss >> this->pos.x;
    72    iss >> this->pos.y;
     63   memcpy(&this->id, buffer, 4);
     64   strcpy(test, buffer+4);
     65   memcpy(&this->pos.x, buffer+4+strlen(test), 4);
     66   memcpy(&this->pos.y, buffer+8+strlen(test), 4);
     67
     68   cout << "id: " << this->id << endl;
     69   cout << "name: " << test << endl;
     70   cout << "x: " << this->pos.x << endl;
     71   cout << "y: " << this->pos.y << endl;
    7372}
    7473
Note: See TracChangeset for help on using the changeset viewer.