Author Topic: sending a list of vector3-like objects, is my logic correct?  (Read 18752 times)


  • Not-a-newbie
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
sending a list of vector3-like objects, is my logic correct?
« on: October 16, 2014, 12:47:51 PM »
Greetings all!  Just picked up RakNet this past weekend for a project and so far it's been a smooth ride; Really great library with tons of useful functionality.  I was hoping someone could double check my logic on this before I dive in, I know this is probably a very simple process, just want to be sure before I go too far down the wrong rabbit hole.

I have a chunk of data that lives as a vector of 3-component type objects and I want to send and receive them via Bitstreams using WriteVector/ReadVector; Going off of a few forum threads and the manual, I think I have a good handle on it, but again if someone could check my logic, I'd certainly appreciate it!

Reference: (Sending an std::vector?) (Sending classes) (Bitstream Overview) (Creating Packets)

Server side code:
Code: [Select]
void writeBitstream()
  BitStream pointData;
  pointData.Write((unsigned char)ID_POINT_CLOUD_FRAME); // Message ID

  //mPoints is an std::vector<Vec3f>
  size_t numElements = mPoints.size();
  pointData.write((unsigned char)numElements);

  for (const Vec3f &cV : mPoints)
    pointData.WriteVector<float>(cV.x, cV.y, cV.z);

  SystemAddress destAddr;
  mServer->Send(&pointData, HIGH_PRIORITY, RELIABLE, 0, destAddr, false);

Client side code:
Code: [Select]
void readBitstream()
  //mPacket is a RakNet::Packet *, data[0] is ID_POINT_CLOUD_FRAME, data[1](?) is numElements from above
  Bitstream pointStream(mPacket->data, mPacket->length, false);
  size_t numElements;
  std::vector<Vec3f> pointData;
  for(size_t i=0;i<numElements;++i)
    float cX,cY,cZ;

Again, I THINK this is correct or at least on the right track, but then I could be completely off.  If anyone has any thoughts or suggestions, I'd love to hear 'em.  Thanks all!