Mercurial > wow > breuesk
comparison Lists.lua @ 105:c6c748a5823b tip
Collaborative list trimming 80% functional
Updates for the zone-in problem
author | John@Yosemite-PC |
---|---|
date | Sun, 06 May 2012 08:33:34 -0400 |
parents | 25c127c4c1e8 |
children |
comparison
equal
deleted
inserted
replaced
104:9aa2dcbbdc87 | 105:c6c748a5823b |
---|---|
6 -- | 6 -- |
7 -- A separate user list is held - lists index into this | 7 -- A separate user list is held - lists index into this |
8 | 8 |
9 | 9 |
10 -- TODO: switch all action functions to use identifiers rather than names | 10 -- TODO: switch all action functions to use identifiers rather than names |
11 -- TODO: collaborative list trimming | |
12 -- TODO: collapse slists into delimited strings for space (premature optimization?) | 11 -- TODO: collapse slists into delimited strings for space (premature optimization?) |
13 -- TODO: organize working state data a little more carefully - hard to keep | 12 -- TODO: organize working state data a little more carefully - hard to keep |
14 -- track of all the arrays that are floating out there | 13 -- track of all the arrays that are floating out there |
15 | 14 |
16 -- holy crap long notes {{{ | 15 -- holy crap long notes {{{ |
848 else | 847 else |
849 break | 848 break |
850 end | 849 end |
851 end | 850 end |
852 | 851 |
853 -- apply first half | 852 print("before -",#before) |
853 --return | |
854 | |
855 --apply first half | |
854 CreateWorkingStateFromChanges(before) | 856 CreateWorkingStateFromChanges(before) |
855 | 857 |
856 -- save this state permanently; trim the changes permanently | 858 -- save this state permanently; trim the changes permanently |
857 LootLists:SaveToDB(db) | 859 LootLists:SaveToDB(db) |
858 PersonList:SaveToDB(db) | 860 PersonList:SaveToDB(db) |
859 while db.profile.changes ~= nil and db.profile.changes[1] ~= nil and db.profile.changes[1].time <= time do | 861 while db.profile.changes ~= nil and db.profile.changes[1] ~= nil and db.profile.changes[1].time <= time do |
860 table.remove(db.profile.changes,1) | 862 table.remove(db.profile.changes,1) |
861 end | 863 end |
864 print("reapplying ",_G.getn(db.profile.changes)) | |
862 db.profile.time = lastTime | 865 db.profile.time = lastTime |
863 | 866 |
864 -- using the trimmed list and the new bases, recreate the working state | 867 -- using the trimmed list and the new bases, recreate the working state |
865 CreateWorkingStateFromChanges(db.profile.changes) | 868 --CreateWorkingStateFromChanges(db.profile.changes) |
869 | |
870 for i,v in ipairs(db.profile.changes) do | |
871 ProcessChange(v) | |
872 end | |
873 | |
874 if changelistener then | |
875 changelistener:dataevent() | |
876 end | |
866 end | 877 end |
867 | 878 |
868 | 879 |
869 function PopulateListRandom(listIndex) | 880 function PopulateListRandom(listIndex) |
870 -- difference (raid+reserve)-list, then random shuffle that, then add | 881 -- difference (raid+reserve)-list, then random shuffle that, then add |
941 else | 952 else |
942 return false, {} | 953 return false, {} |
943 end | 954 end |
944 end | 955 end |
945 | 956 |
946 function IntegrateChangeDiff(remoteChanges) -- todo: check against remoteBase before committing to insanity | 957 function IntegrateChangeDiff(remoteBase,remoteChanges) |
947 local c = remoteChanges | 958 local c = remoteChanges |
948 local old = db.profile.changes | 959 local old = db.profile.changes |
949 | 960 |
950 local new = {} | 961 local new = {} |
951 | 962 |
952 local op = 1 | 963 local op = 1 |
953 local cp = 1 | 964 local cp = 1 |
954 | 965 |
955 local no = getn(old) | 966 local no = getn(old) |
967 | |
968 local worthRefresh = false -- only worth refreshing if we take changes from c | |
969 | |
970 -- if remotebase is older, don't integrate anything prior to db.profile.time. if they're newer, it's ok to merge in their changes | |
971 if remoteBase < db.profile.time then | |
972 while c[1] and c[1].time < db.profile.time do | |
973 table.remove(c,1) | |
974 end | |
975 end | |
976 | |
956 local nc = getn(c) | 977 local nc = getn(c) |
957 | 978 |
958 if no == 0 then | 979 if no == 0 and nc > 0 then |
980 worthRefresh = true | |
959 db.profile.changes = c | 981 db.profile.changes = c |
960 else | 982 else |
961 while op <= no or cp <= nc do -- lists are pre-sorted. insertion merge them | 983 while op <= no or cp <= nc do -- lists are pre-sorted. insertion merge them |
962 if cp > nc then -- inelegant - edge cases first, then the normal logic | 984 if cp > nc then -- inelegant - edge cases first, then the normal logic |
963 table.insert(new,old[op]) | 985 table.insert(new,old[op]) |
964 op = op + 1 | 986 op = op + 1 |
965 elseif op > no then | 987 elseif op > no then |
988 worthRefresh=true | |
966 table.insert(new,c[cp]) | 989 table.insert(new,c[cp]) |
967 cp = cp + 1 | 990 cp = cp + 1 |
991 elseif c[cp].time == old[op].time then | |
992 -- todo: even though they're the same timestamp, still compare | |
993 -- contents for sanity | |
994 table.insert(new,old[cp]) | |
995 cp = cp + 1 | |
996 op = op + 1 | |
968 elseif c[cp].time < old[op].time then | 997 elseif c[cp].time < old[op].time then |
998 worthRefresh=true | |
969 table.insert(new,c[cp]) | 999 table.insert(new,c[cp]) |
970 cp = cp + 1 | 1000 cp = cp + 1 |
971 elseif c[cp].time > old[op].time then | 1001 elseif c[cp].time > old[op].time then |
972 table.insert(new,old[op]) | 1002 table.insert(new,old[op]) |
973 op = op + 1 | 1003 op = op + 1 |
977 end | 1007 end |
978 print("Updating changes - ",getn(new), "entries") | 1008 print("Updating changes - ",getn(new), "entries") |
979 db.profile.changes = new | 1009 db.profile.changes = new |
980 end | 1010 end |
981 | 1011 |
982 CreateWorkingStateFromChanges(db.profile.changes) | 1012 if worthRefresh then |
983 if changeListener then | 1013 CreateWorkingStateFromChanges(db.profile.changes) |
984 changeListener:DataEvent() | 1014 if changelistener then |
985 end | 1015 changelistener:dataevent() |
986 end | 1016 end |
1017 end | |
1018 end |