Skip to content

Instantly share code, notes, and snippets.

@dpogue
Created January 26, 2011 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpogue/797319 to your computer and use it in GitHub Desktop.
Save dpogue/797319 to your computer and use it in GitHub Desktop.
Potential idea for conditional data in a network packet
class Blah {
enum {
net_X_pos = (1 << 0),
net_Y_pos = (1 << 1),
net_OtherVar = (1 << 2),
net_AnotherVar = (1 << 3),
...
};
private:
int dirty_flags_;
float x_pos_;
float y_pos_;
int othervar_;
char anothervar_;
public:
void setXPos(float x) {
this->x_pos_ = x;
this->dirty_flags_ |= net_X_pos;
/* Setter methods need to update the dirty_flags_ */
}
void ReadNetworkPacket(Stream* s) {
int flags = S->readInt();
if (flags & net_X_pos) {
this->x_pos_ = S->readFloat();
}
if (flags & net_Y_pos) {
this->y_pos_ = S->readFloat();
}
if (flags & net_OtherVar) {
this->othervar_ = S->readInt();
}
if (flags & net_AnotherVar) {
this->anothervar_ = S->readChar();
}
}
/* When you write the fields to a stream, set dirty_flags_ back to 0 */
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment