comparison Comm.lua @ 93:df94161e6d7c

Working incremental updates
author John@Yosemite-PC
date Sun, 22 Apr 2012 17:12:39 -0400
parents a227f3b61cda
children 2058d86778b4
comparison
equal deleted inserted replaced
92:a227f3b61cda 93:df94161e6d7c
116 end 116 end
117 while j<n and t[j] <= v.time do j = j+1 end -- advance the foreign pointer past our current entry 117 while j<n and t[j] <= v.time do j = j+1 end -- advance the foreign pointer past our current entry
118 end -- j>=n ? add because the remote hit end of road. lt? add because it's a missing stamp 118 end -- j>=n ? add because the remote hit end of road. lt? add because it's a missing stamp
119 print("Received request at timebase",remoteBase,"and returning:") 119 print("Received request at timebase",remoteBase,"and returning:")
120 PrintTable(o) 120 PrintTable(o)
121 if getn(o) > 0 then
122 Send("CU",o) -- todo: send privately to the requster
123 end
121 else 124 else
122 print("Received request at differing timebase",remoteBase,db.profile.time) 125 print("Received request at differing timebase",remoteBase,db.profile.time," ... pushing")
126 self:Push() -- todo: send privately to requester
123 end 127 end
124 end 128 end
125 end, 129 end,
126 130
127 ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master 131 ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master
128 if isloop then return end 132 if isloop then return end
129 print("CU") 133
130 db.profile.persons,db.profile.lists,db.profile.time = unpack(packet) 134 local c = packet
131 db.profile.changes = {} 135 local old = db.profile.changes
136
137 local new = {}
138
139 local op = 1
140 local cp = 1
141
142 local no = getn(old)
143 local nc = getn(c)
144
145 if no == 0 then
146 db.profile.changes = c
147 else
148 while op <= no and cp <= nc do
149 if c[cp].time == old[op].time then
150 error("Bad update received from ",sender)
151 end
152 if c[cp].time < old[op].time then
153 table.insert(new,c[cp])
154 cp = cp + 1
155 else
156 table.inert(new,old[cp])
157 op = op + 1
158 end
159 end
160 db.profile.changes = new
161 end
162
132 CreateWorkingStateFromChanges(db.profile.changes) 163 CreateWorkingStateFromChanges(db.profile.changes)
133 if changeListener then 164 if changeListener then
134 changeListener:DataEvent() 165 changeListener:DataEvent()
135 end 166 end
136 end, 167 end,