Mercurial > wow > breuesk
changeset 93:df94161e6d7c
Working incremental updates
author | John@Yosemite-PC |
---|---|
date | Sun, 22 Apr 2012 17:12:39 -0400 |
parents | a227f3b61cda |
children | 2058d86778b4 |
files | Comm.lua |
diffstat | 1 files changed, 35 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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()