# HG changeset patch # User John@Yosemite-PC # Date 1335129159 14400 # Node ID df94161e6d7cc234cdd757909b1c7cc59fb9e19f # Parent a227f3b61cda96110c2ddc29ed0d2a5e2baae5bc Working incremental updates diff -r a227f3b61cda -r df94161e6d7c Comm.lua --- a/Comm.lua Sun Apr 22 00:03:13 2012 -0400 +++ b/Comm.lua Sun Apr 22 17:12:39 2012 -0400 @@ -118,17 +118,48 @@ end -- j>=n ? add because the remote hit end of road. lt? add because it's a missing stamp print("Received request at timebase",remoteBase,"and returning:") PrintTable(o) + if getn(o) > 0 then + Send("CU",o) -- todo: send privately to the requster + end else - print("Received request at differing timebase",remoteBase,db.profile.time) + print("Received request at differing timebase",remoteBase,db.profile.time," ... pushing") + self:Push() -- todo: send privately to requester end end end, ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master if isloop then return end - print("CU") - db.profile.persons,db.profile.lists,db.profile.time = unpack(packet) - db.profile.changes = {} + + local c = packet + local old = db.profile.changes + + local new = {} + + local op = 1 + local cp = 1 + + local no = getn(old) + local nc = getn(c) + + if no == 0 then + db.profile.changes = c + else + while op <= no and cp <= nc do + if c[cp].time == old[op].time then + error("Bad update received from ",sender) + end + if c[cp].time < old[op].time then + table.insert(new,c[cp]) + cp = cp + 1 + else + table.inert(new,old[cp]) + op = op + 1 + end + end + db.profile.changes = new + end + CreateWorkingStateFromChanges(db.profile.changes) if changeListener then changeListener:DataEvent()