I'm currently quite busy with - finally - finishing the Model Editor, so I've not yet looked into this very thoroughly. But to pick up my previous suggestions, I'd add methods like
virtual void Serialize(SpecialOutputStreamT& Stream)=0;
virtual void Deserialize(SpecialInputStreamT& Stream)=0;
to class BaseEntityT
) would newly be created as well, its public methods being mostly operator <<
for the most common POD types (int, bool, float, etc.).
It would store the data in a "bit-field", i.e. an array of uint32_t
that is considered a series of bits.
For example (pseudo-code!):
SpecialOutputStreamT& operator << (int i);
SpecialOutputStreamT& operator << (bool b);
SpecialOutputStreamT& operator << (float f);
const ArrayT<uint32_t>& GetBitField() const;
unsigned int m_BitsWritten;
And an implementation of some entity that implements Serialize()
virtual void SomeEntityT::Serialize(SpecialOutputStreamT& Stream)
Stream << m_myHeading;
Stream << m_myPosX;
Stream << m_myPosY;
Stream << m_myBoolFlag1;
Stream << m_myBoolFlag2;
virtual void SomeEntityT::Deserialize(SpecialInputStreamT& Stream)
Stream >> m_myHeading;
Stream >> m_myPosX;
Stream >> m_myPosY;
const bool OldFlag1=m_myBoolFlag1;
Stream >> m_myBoolFlag1;
// Value changed (i.e., an event occurred)
// -- time to take some action...
Stream >> m_myBoolFlag2;
Now, the interesting and more difficult part is probably the server side processing of the so obtained bit fields.
Typically, we have two such bitfields: the current one, and an older one that we are comparing to.
In order to find the "delta" to send over the network to update the other party, I would first build the XOR of both bitfields in order to obtain a bitfield that expresses where they are different: There will be all 0's where the two bitfields are the same, and 1's otherwise. Probably there'll be a lot more 0's than 1's.
The result can be RLE-compressed and be sent over the wire.
But again, I've only started looking into this. Finishing the Model Editor requires me to take a set of screenshots for the gallery and especially to write some documentation for it (all programming and all tickets that are important for now are done), and to update the Worlds.zip resource file as I've been updating some model paths.
As soon as that done, I'll take another look into the details of the above.