Came up with a solution for the joypad.get() issue.
-adelikat has informed me that in FCEUX, savestates contained the button state of the frame on which you saved on. He claims that this is redundant because you could retrieve the state from the frame you're loading on, so BizHawk will not do this. -As such, I just retrieved the input for the frame you're saving on before associating the data with the state. --This essentially includes the missing info without having to depend on a movie frame to get the data from. --In order for this to make sense, I made it so that the main joypad.get() doesn't run on a frame you're saving / loading on. --Finally, in order to show the data from before the save frame when loading the data, I cached that data as well. ---The two above steps require collecting the data for a state once and using that until the frame is advanced or a state is loaded. Otherwise, I'd be able to increase the count significantly by saving multiple times. -All this said and done, I think this script is perfect now, and is way more convenient to use than the FCEUX counterpart. Notes: -As mentioned before, it seems that the scripts are disabled when the console is reset / a movie begins playing. I don't like this to begin with, but worse yet, I noticed that this somehow makes the button data carry over from before the reset. Why is this? -It seems that using gui.text in savestate.registersave/load causes the text to be written over the previous text instead of clearing the screen and then writing. Is this expected? How can I avoid overlapping text?
This commit is contained in:
parent
b295d7cd23
commit
7e75d983ae
|
@ -4,22 +4,32 @@
|
|||
local x = 0
|
||||
local y = 36
|
||||
|
||||
local holds
|
||||
local pressed
|
||||
local presses
|
||||
local data = {}
|
||||
local registered = false
|
||||
local state = {}
|
||||
local states = {}
|
||||
|
||||
function table.copy(t)
|
||||
local t2 = {}
|
||||
for k, v in pairs(t) do
|
||||
t2[k] = v
|
||||
function deepcopy(object)
|
||||
local lookup_table = {}
|
||||
local function _copy(object)
|
||||
if type(object) ~= "table" then
|
||||
return object
|
||||
elseif lookup_table[object] then
|
||||
return lookup_table[object]
|
||||
end
|
||||
local new_table = {}
|
||||
lookup_table[object] = new_table
|
||||
for index, value in pairs(object) do
|
||||
new_table[_copy(index)] = _copy(value)
|
||||
end
|
||||
return setmetatable(new_table, getmetatable(object))
|
||||
end
|
||||
return t2
|
||||
return _copy(object)
|
||||
end
|
||||
|
||||
function counts()
|
||||
gui.text(x, y, 'Holds: ' .. holds)
|
||||
gui.text(x, y + 14, 'Presses: ' .. presses)
|
||||
function counts(obj)
|
||||
gui.text(x, y, 'Holds: ' .. obj.holds)
|
||||
gui.text(x, y + 14, 'Presses: ' .. obj.presses)
|
||||
end
|
||||
|
||||
function frames()
|
||||
|
@ -34,47 +44,52 @@ function frames()
|
|||
record(movie.getinput(frame))
|
||||
end
|
||||
console.output('Data loaded from frames')
|
||||
counts()
|
||||
counts(data)
|
||||
end
|
||||
|
||||
function load(name)
|
||||
registered = true
|
||||
state = {}
|
||||
if not states[name] then
|
||||
frames()
|
||||
save(name)
|
||||
return
|
||||
end
|
||||
holds = states[name].holds
|
||||
pressed = table.copy(states[name].pressed)
|
||||
presses = states[name].presses
|
||||
data = deepcopy(states[name])
|
||||
console.output('Data loaded from ' .. name)
|
||||
counts()
|
||||
--Show the data from before the state's frame.
|
||||
local previous = states[name].previous
|
||||
counts(previous)
|
||||
end
|
||||
|
||||
function record(buttons)
|
||||
for button, value in pairs(buttons) do
|
||||
if value then
|
||||
holds = holds + 1
|
||||
if not pressed[button] then
|
||||
presses = presses + 1
|
||||
data.holds = data.holds + 1
|
||||
if not data.pressed[button] then
|
||||
data.presses = data.presses + 1
|
||||
end
|
||||
end
|
||||
pressed[button] = value
|
||||
data.pressed[button] = value
|
||||
end
|
||||
end
|
||||
|
||||
function reset()
|
||||
holds = 0
|
||||
pressed = {}
|
||||
presses = 0
|
||||
data.holds = 0
|
||||
data.pressed = {}
|
||||
data.presses = 0
|
||||
end
|
||||
|
||||
function save(name)
|
||||
states[name] = {}
|
||||
states[name].holds = holds
|
||||
states[name].pressed = table.copy(pressed)
|
||||
states[name].presses = presses
|
||||
registered = true
|
||||
if next(state) == nil then
|
||||
data.previous = deepcopy(data)
|
||||
--Include the state's frame in the data.
|
||||
record(joypad.get())
|
||||
state = deepcopy(data)
|
||||
end
|
||||
states[name] = deepcopy(state)
|
||||
console.output('Data saved to ' .. name)
|
||||
counts()
|
||||
end
|
||||
|
||||
reset()
|
||||
|
@ -90,7 +105,11 @@ while true do
|
|||
if emu.framecount() == 0 then
|
||||
reset()
|
||||
end
|
||||
record(joypad.get())
|
||||
counts()
|
||||
if not registered then
|
||||
record(joypad.get())
|
||||
end
|
||||
registered = false
|
||||
state = {}
|
||||
counts(data)
|
||||
emu.frameadvance()
|
||||
end
|
Loading…
Reference in New Issue