Changeset ad5d122 in network-game


Ignore:
Timestamp:
Jan 29, 2013, 7:19:59 PM (12 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
5806dc2
Parents:
80b3f94
Message:

Fixed a bug with Player serialization

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r80b3f94 rad5d122  
    303303      }
    304304      else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
    305          mapPlayers[curPlayerId].pos.x = ev.mouse.x;
    306          mapPlayers[curPlayerId].pos.y = ev.mouse.y;
    307 
    308          // send the server a MSG_TYPE_PLAYER_MOVE message
    309          msgTo.type = MSG_TYPE_PLAYER_MOVE;
    310 
    311          ostringstream oss;
    312          oss << ev.mouse.x;
    313          oss << ev.mouse.y;
    314 
    315          memcpy(msgTo.buffer, oss.str().c_str(), oss.str().length());
    316          sendMessage(&msgTo, sock, &server);
     305         if(wndCurrent == wndMain) {
     306            msgTo.type = MSG_TYPE_PLAYER_MOVE;
     307
     308            memcpy(msgTo.buffer, &curPlayerId, 4);
     309            memcpy(msgTo.buffer+4, &ev.mouse.x, 4);
     310            memcpy(msgTo.buffer+8, &ev.mouse.y, 4);
     311
     312            sendMessage(&msgTo, sock, &server);
     313         }
    317314      }
    318315
  • common/Player.cpp

    r80b3f94 rad5d122  
    5353   memcpy(buffer, &this->id, 4);
    5454   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);
     55   memcpy(buffer+5+this->name.length(), &this->pos.x, 4);
     56   memcpy(buffer+9+this->name.length(), &this->pos.y, 4);
    5757}
    5858
     
    6363   memcpy(&this->id, buffer, 4);
    6464   strcpy(test, buffer+4);
    65    memcpy(&this->pos.x, buffer+4+strlen(test), 4);
    66    memcpy(&this->pos.y, buffer+8+strlen(test), 4);
     65   memcpy(&this->pos.x, buffer+5+strlen(test), 4);
     66   memcpy(&this->pos.y, buffer+9+strlen(test), 4);
    6767
    6868   cout << "id: " << this->id << endl;
Note: See TracChangeset for help on using the changeset viewer.