Lots of work on debugging diff xmit
This commit is contained in:
@@ -463,23 +463,29 @@ void AnimQueue::deserialize(StreamBuffer *sb) {
|
||||
version_number_ = 0;
|
||||
}
|
||||
|
||||
bool AnimQueue::need_patch(const AnimQueue &auth) const {
|
||||
// Sanity check.
|
||||
bool AnimQueue::version_identical(const AnimQueue &auth) const {
|
||||
return version_number_ == auth.version_number_;
|
||||
}
|
||||
|
||||
bool AnimQueue::diff(const AnimQueue &auth, StreamBuffer *sb) const {
|
||||
assert(valid());
|
||||
assert(auth.valid());
|
||||
|
||||
// Fast path to detect equivalence.
|
||||
if (version_number_ == auth.version_number_) {
|
||||
// Fast path to equivalence detection
|
||||
if (version_identical(auth)) {
|
||||
assert(size_and_steps_equal(auth));
|
||||
sb->write_uint8(255);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, do a direct comparison.
|
||||
return !size_and_steps_equal(auth);
|
||||
}
|
||||
// Another path to equivalence detection
|
||||
if (size_and_steps_equal(auth)) {
|
||||
sb->write_uint8(255);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void AnimQueue::diff(const AnimQueue &auth, StreamBuffer *sb) const {
|
||||
// Write the first element.
|
||||
assert(auth.steps_.size() < 255);
|
||||
sb->write_uint8(auth.steps_.size());
|
||||
sb->write_uint8(auth.size_limit_);
|
||||
const AnimStep &first = auth.steps_[0];
|
||||
@@ -517,10 +523,16 @@ void AnimQueue::diff(const AnimQueue &auth, StreamBuffer *sb) const {
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void AnimQueue::patch(StreamBuffer *sb) {
|
||||
void AnimQueue::patch(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
int len = sb->read_uint8();
|
||||
if (len == 255) {
|
||||
return;
|
||||
}
|
||||
DebugLine(dbc) << "AnimQueue modified";
|
||||
|
||||
size_limit_ = sb->read_uint8();
|
||||
// Decode the diff, stop at eof.
|
||||
std::deque<AnimStep> old = std::move(steps_);
|
||||
@@ -557,7 +569,7 @@ const AnimStep &AnimQueue::back() const {
|
||||
static bool diff_works(const AnimQueue &master, AnimQueue &sync) {
|
||||
StreamBuffer sb;
|
||||
sync.diff(master, &sb);
|
||||
sync.patch(&sb);
|
||||
sync.patch(&sb, nullptr);
|
||||
return sync.size_and_steps_equal(master);
|
||||
}
|
||||
|
||||
@@ -658,7 +670,8 @@ LuaDefine(unittests_animqueue, "c") {
|
||||
LuaAssert(L, diff_works(aq, aqds));
|
||||
|
||||
// compare again, should be no differences.
|
||||
LuaAssert(L, !aqds.need_patch(aq));
|
||||
LuaAssert(L, aqds.version_identical(aq));
|
||||
LuaAssert(L, aqds.size_and_steps_equal(aq));
|
||||
LuaAssert(L, diff_works(aq, aqds));
|
||||
|
||||
// Discard all but the last action.
|
||||
|
||||
Reference in New Issue
Block a user