Created
January 26, 2011 19:55
-
-
Save dpogue/797319 to your computer and use it in GitHub Desktop.
Potential idea for conditional data in a network packet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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