From 96bad6dbfdfb9f95e75d8029779e21cdfb70d4e0 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sun, 3 May 2015 10:37:45 -0700 Subject: [PATCH] move save/loading to Monitor --- Lua/classes.lua | 17 +++++++++++++++++ Lua/event flag monitor.lua | 23 ++--------------------- Lua/oot memory editor monitor.lua | 16 ++-------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/Lua/classes.lua b/Lua/classes.lua index 1fdda07..e59d006 100644 --- a/Lua/classes.lua +++ b/Lua/classes.lua @@ -1,3 +1,5 @@ +require "serialize" + Monitor = Class() function Monitor:init(name, a) self.name = name @@ -5,6 +7,8 @@ function Monitor:init(name, a) self.len = a.type self.once = false self.old_bytes = {} + self.modified = {} + self.dirty = false end function Monitor:diff() @@ -25,3 +29,16 @@ function Monitor:diff() self.once = true end +function Monitor:load(fn) + self.modified = deserialize(fn) or {} + self.dirty = false + self.fn = fn +end + +function Monitor:save(fn) + if self.dirty then + serialize(fn or self.fn, self.modified) + self.dirty = false + end +end + diff --git a/Lua/event flag monitor.lua b/Lua/event flag monitor.lua index 536e324..1c561cb 100644 --- a/Lua/event flag monitor.lua +++ b/Lua/event flag monitor.lua @@ -1,7 +1,6 @@ require "boilerplate" require "addrs.init" require "classes" -require "serialize" local ignore = { -- every time a scene (un)loads @@ -24,11 +23,6 @@ local ignore = { } FlagMonitor = Class(Monitor) -function FlagMonitor:init(name, a) - Monitor.init(self, name, a) - self.seen = {} - self.dirty = false -end function FlagMonitor:mark(i, x, x1) local now = emu.framecount() @@ -42,27 +36,14 @@ function FlagMonitor:mark(i, x, x1) gui.addmessage(str) end local ib = i*8 + which - if not self.seen[ib] then - self.seen[ib] = true + if not self.modified[ib] then + self.modified[ib] = true self.dirty = true end end end end -function FlagMonitor:load(fn) - self.seen = deserialize(fn) or {} - self.dirty = false - self.fn = fn -end - -function FlagMonitor:save(fn) - if self.dirty then - serialize(fn or self.fn, self.seen) - self.dirty = false - end -end - local weg = FlagMonitor('weg', addrs.week_event_reg) local inf = FlagMonitor('inf', addrs.event_inf) local mmb = FlagMonitor('mmb', addrs.mask_mask_bit) diff --git a/Lua/oot memory editor monitor.lua b/Lua/oot memory editor monitor.lua index 63e91ff..3dd3edf 100644 --- a/Lua/oot memory editor monitor.lua +++ b/Lua/oot memory editor monitor.lua @@ -1,9 +1,7 @@ require "boilerplate" require "addrs.init" require "classes" -require "serialize" -local fn = 'data/_ootmemod.lua' local blocknames = { 'R ', 'RS', 'RO', 'RP', 'RQ', 'RM', 'RY', 'RD', @@ -24,11 +22,6 @@ function distribute_index(ih) end ShortMonitor = Class(Monitor) -function ShortMonitor:init(name, a) - Monitor.init(self, name, a) - self.modified = {} - self.dirty = false -end function ShortMonitor:mark(i, x, x1) local ih = math.floor(i/2) @@ -58,14 +51,9 @@ end -- 2 bytes each, 16 values per page, 6 pages per block, 29 blocks -- = 5568 bytes (0x15C0) me = ShortMonitor('me', A(0x210A24, 0x15C0)) - -me.modified = deserialize(fn) or {} - +me:load('data/_ootmemod.lua') while version == "O EUDB MQ" do me:diff() - if me.dirty then - serialize(fn, me.modified) - me.dirty = false - end + me:save() emu.frameadvance() end