Mercurial > wow > breuesk
changeset 5:2ce0f4db1a3e
Changelist trimming
author | John@Yosemite-PC |
---|---|
date | Mon, 05 Mar 2012 23:11:45 -0500 |
parents | 6c8f9473b22e |
children | 6d460ff2135c |
files | Core.lua Lists.lua |
diffstat | 2 files changed, 61 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Sat Mar 03 10:25:01 2012 -0500 +++ b/Core.lua Mon Mar 05 23:11:45 2012 -0500 @@ -20,6 +20,8 @@ -- indexing -- 2) a.x === a["x"] -- 3) a["1"] =/= a[1] +-- 4) table.remove() works ok if reverse iterating, terrible at anything else +-- 5) pairs() does not have a guaranteed iteration order bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0", "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0") local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false) @@ -38,7 +40,7 @@ end function bsk:OnEnable() - bsk:CreateWorkingStateFromChanges() + bsk:CreateWorkingStateFromChanges(self.db.profile.changes) --self:HandleCommand() end @@ -100,6 +102,12 @@ return end bsk:PrintLists(param[2]) + elseif param[1] == "trim" then + if param[2] == nil or param[2] == "" then + bsk:PrintTable(param) + return + end + bsk:TrimLists(param[2]) end --if self.frame == nil then
--- a/Lists.lua Sat Mar 03 10:25:01 2012 -0500 +++ b/Lists.lua Mon Mar 05 23:11:45 2012 -0500 @@ -8,6 +8,7 @@ -- TODO: rename player +-- TODO: list trimming -- notes on list storage: -- Storing names as I do now is atrocious. @@ -100,10 +101,9 @@ --}}} -function bsk:CreateWorkingStateFromChanges() +function bsk:CreateWorkingStateFromChanges(changes) local playerBase = self.db.profile.players local listBase = self.db.profile.listBase - local changes = self.db.profile.changes -- copy the base to the working state wipe(bsk.lists) @@ -112,7 +112,7 @@ bsk:tcopy(bsk.players,playerBase) -- now just go through the changes list applying each - for i,v in pairs(changes) do + for i,v in ipairs(changes) do bsk:ProcessChange(v) end end @@ -339,6 +339,42 @@ bsk:CommitChange(change) end end + +function bsk:TrimLists(time) + if not bsk:CheckListCausality() then + self:Print("Unable to trim lists due to violated causality") + + return false + end + + if type(time) ~= "number" then + time = tonumber(time) + end + + -- bisect the changes list by "time" + local before = {} + for i,v in ipairs(self.db.profile.changes) do + if v.time <= time then + tinsert(before,v) + else + break + end + end + + -- apply first half + bsk:CreateWorkingStateFromChanges(before) + + -- save this state permanently; trim the changes permanently + bsk:tcopy(bsk.db.profile.players,bsk.players) + bsk:tcopy(bsk.db.profile.listBase,bsk.lists) + while bsk.db.profile.changes[1].time <= time do + table.remove(bsk.db.profile.changes,1) + end + + -- using the trimmed list and the new bases, recreate the working state + bsk:CreateWorkingStateFromChanges(bsk.db.profile.changes) +end + --}}} -- Higher order actions (ie calls other Doers){{{ function bsk:AddMissingPlayers() @@ -446,7 +482,19 @@ return ret end - +-- returns true if the events in the list are in time order +function bsk:CheckListCausality() + local t = nil + for i,v in ipairs(bsk.db.profile.changes) do + if t ~= nil then + if v.time <= t then + return false + end + end + t = v.time + end + return true +end -- Support functions