mirror of
https://github.com/notwa/mm
synced 2024-11-04 20:19:02 -08:00
move save/loading to Monitor
This commit is contained in:
parent
daae4d4bd1
commit
96bad6dbfd
3 changed files with 21 additions and 35 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue