More work on diff xmit, not finished yet
This commit is contained in:
@@ -447,23 +447,22 @@ void AnimQueue::deserialize(StreamBuffer *sb) {
|
||||
}
|
||||
}
|
||||
|
||||
bool AnimQueue::make_patch(const AnimQueue &auth, StreamBuffer *sb) const {
|
||||
bool AnimQueue::need_patch(const AnimQueue &auth) const {
|
||||
// Sanity check.
|
||||
assert(valid());
|
||||
assert(auth.valid());
|
||||
|
||||
|
||||
// Fast path to detect equivalence.
|
||||
if (version_number_ == auth.version_number_) {
|
||||
sb->write_uint8(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Special case: if we're already a perfect match.
|
||||
if (size_and_steps_equal(auth)) {
|
||||
sb->write_uint8(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, do a direct comparison.
|
||||
return !size_and_steps_equal(auth);
|
||||
}
|
||||
|
||||
|
||||
void AnimQueue::diff(const AnimQueue &auth, StreamBuffer *sb) const {
|
||||
// Write the first element.
|
||||
sb->write_uint8(auth.steps_.size());
|
||||
sb->write_uint8(auth.size_limit_);
|
||||
@@ -502,14 +501,10 @@ bool AnimQueue::make_patch(const AnimQueue &auth, StreamBuffer *sb) const {
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AnimQueue::apply_patch(StreamBuffer *sb) {
|
||||
void AnimQueue::patch(StreamBuffer *sb) {
|
||||
int len = sb->read_uint8();
|
||||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
size_limit_ = sb->read_uint8();
|
||||
// Decode the diff, stop at eof.
|
||||
std::deque<AnimStep> old = std::move(steps_);
|
||||
@@ -545,8 +540,8 @@ const AnimStep &AnimQueue::back() const {
|
||||
|
||||
static bool diff_works(const AnimQueue &master, AnimQueue &sync) {
|
||||
StreamBuffer sb;
|
||||
sync.make_patch(master, &sb);
|
||||
sync.apply_patch(&sb);
|
||||
sync.diff(master, &sb);
|
||||
sync.patch(&sb);
|
||||
return sync.size_and_steps_equal(master);
|
||||
}
|
||||
|
||||
@@ -647,10 +642,8 @@ LuaDefine(unittests_animqueue, "c") {
|
||||
LuaAssert(L, diff_works(aq, aqds));
|
||||
|
||||
// compare again, should be no differences.
|
||||
sb.clear();
|
||||
LuaAssert(L, !aqds.make_patch(aq, &sb));
|
||||
aqds.apply_patch(&sb);
|
||||
LuaAssert(L, aqds.size_and_steps_equal(aq));
|
||||
LuaAssert(L, !aqds.need_patch(aq));
|
||||
LuaAssert(L, diff_works(aq, aqds));
|
||||
|
||||
// Discard all but the last action.
|
||||
aq.set_limit(1);
|
||||
|
||||
Reference in New Issue
Block a user