stop tracking wallclock time
We only need time differences.
This commit is contained in:
parent
d1dd3e441f
commit
0e0f36f8b4
|
@ -16,7 +16,7 @@ function test_creating_drawing_saves()
|
||||||
edit.update(Editor_state, 0.01)
|
edit.update(Editor_state, 0.01)
|
||||||
check_nil(App.filesystem['foo'], 'F - test_creating_drawing_saves/early')
|
check_nil(App.filesystem['foo'], 'F - test_creating_drawing_saves/early')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- filesystem contains drawing and an empty line of text
|
-- filesystem contains drawing and an empty line of text
|
||||||
check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'F - test_creating_drawing_saves')
|
check_eq(App.filesystem['foo'], '```lines\n```\n\n', 'F - test_creating_drawing_saves')
|
||||||
|
@ -51,7 +51,7 @@ function test_draw_line()
|
||||||
check_eq(p2.x, 35, 'F - test_draw_line/p2:x')
|
check_eq(p2.x, 35, 'F - test_draw_line/p2:x')
|
||||||
check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
|
check_eq(p2.y, 36, 'F - test_draw_line/p2:y')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- The format on disk isn't perfectly stable. Table fields can be reordered.
|
-- The format on disk isn't perfectly stable. Table fields can be reordered.
|
||||||
-- So just reload from disk to verify.
|
-- So just reload from disk to verify.
|
||||||
|
@ -430,7 +430,7 @@ function test_name_point()
|
||||||
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_name_point/mode:3')
|
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_name_point/mode:3')
|
||||||
check_eq(p2.name, 'A', 'F - test_name_point')
|
check_eq(p2.name, 'A', 'F - test_name_point')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- change is saved
|
-- change is saved
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
@ -462,7 +462,7 @@ function test_move_point()
|
||||||
check_eq(p2.x, 35, 'F - test_move_point/baseline/p2:x')
|
check_eq(p2.x, 35, 'F - test_move_point/baseline/p2:x')
|
||||||
check_eq(p2.y, 36, 'F - test_move_point/baseline/p2:y')
|
check_eq(p2.y, 36, 'F - test_move_point/baseline/p2:y')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- line is saved to disk
|
-- line is saved to disk
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
@ -489,7 +489,7 @@ function test_move_point()
|
||||||
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_move_point/mode:3')
|
check_eq(Editor_state.current_drawing_mode, 'line', 'F - test_move_point/mode:3')
|
||||||
check_eq(drawing.pending, {}, 'F - test_move_point/pending')
|
check_eq(drawing.pending, {}, 'F - test_move_point/pending')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- change is saved
|
-- change is saved
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
@ -550,7 +550,7 @@ function test_delete_lines_at_point()
|
||||||
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_lines_at_point/shape:1')
|
check_eq(drawing.shapes[1].mode, 'deleted', 'F - test_delete_lines_at_point/shape:1')
|
||||||
check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_delete_lines_at_point/shape:2')
|
check_eq(drawing.shapes[2].mode, 'deleted', 'F - test_delete_lines_at_point/shape:2')
|
||||||
-- wait for some time
|
-- wait for some time
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- deleted points disappear after file is reloaded
|
-- deleted points disappear after file is reloaded
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
@ -684,7 +684,7 @@ function test_undo_name_point()
|
||||||
check_eq(Editor_state.next_history, 3, 'F - test_undo_name_point/next_history')
|
check_eq(Editor_state.next_history, 3, 'F - test_undo_name_point/next_history')
|
||||||
check_eq(p2.name, '', 'F - test_undo_name_point') -- not quite what it was before, but close enough
|
check_eq(p2.name, '', 'F - test_undo_name_point') -- not quite what it was before, but close enough
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- undo is saved
|
-- undo is saved
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
@ -735,7 +735,7 @@ function test_undo_move_point()
|
||||||
check_eq(p2.x, 35, 'F - test_undo_move_point/x')
|
check_eq(p2.x, 35, 'F - test_undo_move_point/x')
|
||||||
check_eq(p2.y, 36, 'F - test_undo_move_point/y')
|
check_eq(p2.y, 36, 'F - test_undo_move_point/y')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- undo is saved
|
-- undo is saved
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
@ -776,7 +776,7 @@ function test_undo_delete_point()
|
||||||
check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/shape:1')
|
check_eq(drawing.shapes[1].mode, 'line', 'F - test_undo_delete_point/shape:1')
|
||||||
check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/shape:2')
|
check_eq(drawing.shapes[2].mode, 'line', 'F - test_undo_delete_point/shape:2')
|
||||||
-- wait until save
|
-- wait until save
|
||||||
App.wait_fake_time(3.1)
|
Current_time = Current_time + 3.1
|
||||||
edit.update(Editor_state, 0)
|
edit.update(Editor_state, 0)
|
||||||
-- undo is saved
|
-- undo is saved
|
||||||
load_from_disk(Editor_state)
|
load_from_disk(Editor_state)
|
||||||
|
|
4
edit.lua
4
edit.lua
|
@ -176,7 +176,7 @@ end
|
||||||
|
|
||||||
function edit.update(State, dt)
|
function edit.update(State, dt)
|
||||||
Drawing.update(State, dt)
|
Drawing.update(State, dt)
|
||||||
if State.next_save and State.next_save < App.getTime() then
|
if State.next_save and State.next_save < Current_time then
|
||||||
save_to_disk(State)
|
save_to_disk(State)
|
||||||
State.next_save = nil
|
State.next_save = nil
|
||||||
end
|
end
|
||||||
|
@ -184,7 +184,7 @@ end
|
||||||
|
|
||||||
function schedule_save(State)
|
function schedule_save(State)
|
||||||
if State.next_save == nil then
|
if State.next_save == nil then
|
||||||
State.next_save = App.getTime() + 3 -- short enough that you're likely to still remember what you did
|
State.next_save = Current_time + 3 -- short enough that you're likely to still remember what you did
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
18
main.lua
18
main.lua
|
@ -81,8 +81,9 @@ function App.initialize_globals()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- for hysteresis in a few places
|
-- for hysteresis in a few places
|
||||||
Last_focus_time = App.getTime() -- https://love2d.org/forums/viewtopic.php?p=249700
|
Current_time = 0
|
||||||
Last_resize_time = App.getTime()
|
Last_focus_time = 0 -- https://love2d.org/forums/viewtopic.php?p=249700
|
||||||
|
Last_resize_time = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.initialize(arg)
|
function App.initialize(arg)
|
||||||
|
@ -103,7 +104,7 @@ function App.resize(w,h)
|
||||||
else
|
else
|
||||||
assert(false, 'unknown app "'..Current_app..'"')
|
assert(false, 'unknown app "'..Current_app..'"')
|
||||||
end
|
end
|
||||||
Last_resize_time = App.getTime()
|
Last_resize_time = Current_time
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.filedropped(file)
|
function App.filedropped(file)
|
||||||
|
@ -118,7 +119,7 @@ end
|
||||||
|
|
||||||
function App.focus(in_focus)
|
function App.focus(in_focus)
|
||||||
if in_focus then
|
if in_focus then
|
||||||
Last_focus_time = App.getTime()
|
Last_focus_time = Current_time
|
||||||
end
|
end
|
||||||
if Current_app == 'run' then
|
if Current_app == 'run' then
|
||||||
if run.focus then run.focus(in_focus) end
|
if run.focus then run.focus(in_focus) end
|
||||||
|
@ -140,8 +141,9 @@ function App.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.update(dt)
|
function App.update(dt)
|
||||||
|
Current_time = Current_time + dt
|
||||||
-- some hysteresis while resizing
|
-- some hysteresis while resizing
|
||||||
if App.getTime() < Last_resize_time + 0.1 then
|
if Current_time < Last_resize_time + 0.1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
@ -156,7 +158,7 @@ end
|
||||||
|
|
||||||
function App.keychord_pressed(chord, key)
|
function App.keychord_pressed(chord, key)
|
||||||
-- ignore events for some time after window in focus (mostly alt-tab)
|
-- ignore events for some time after window in focus (mostly alt-tab)
|
||||||
if App.getTime() < Last_focus_time + 0.01 then
|
if Current_time < Last_focus_time + 0.01 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
@ -194,7 +196,7 @@ end
|
||||||
|
|
||||||
function App.textinput(t)
|
function App.textinput(t)
|
||||||
-- ignore events for some time after window in focus (mostly alt-tab)
|
-- ignore events for some time after window in focus (mostly alt-tab)
|
||||||
if App.getTime() < Last_focus_time + 0.01 then
|
if Current_time < Last_focus_time + 0.01 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
@ -209,7 +211,7 @@ end
|
||||||
|
|
||||||
function App.keyreleased(chord, key)
|
function App.keyreleased(chord, key)
|
||||||
-- ignore events for some time after window in focus (mostly alt-tab)
|
-- ignore events for some time after window in focus (mostly alt-tab)
|
||||||
if App.getTime() < Last_focus_time + 0.01 then
|
if Current_time < Last_focus_time + 0.01 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
|
|
@ -189,7 +189,7 @@ end
|
||||||
|
|
||||||
function edit.update(State, dt)
|
function edit.update(State, dt)
|
||||||
Drawing.update(State, dt)
|
Drawing.update(State, dt)
|
||||||
if State.next_save and State.next_save < App.getTime() then
|
if State.next_save and State.next_save < Current_time then
|
||||||
save_to_disk(State)
|
save_to_disk(State)
|
||||||
State.next_save = nil
|
State.next_save = nil
|
||||||
end
|
end
|
||||||
|
@ -197,7 +197,7 @@ end
|
||||||
|
|
||||||
function schedule_save(State)
|
function schedule_save(State)
|
||||||
if State.next_save == nil then
|
if State.next_save == nil then
|
||||||
State.next_save = App.getTime() + 3 -- short enough that you're likely to still remember what you did
|
State.next_save = Current_time + 3 -- short enough that you're likely to still remember what you did
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ function test_show_log_browser_side()
|
||||||
log_browser.parse(Log_browser_state)
|
log_browser.parse(Log_browser_state)
|
||||||
check(not Show_log_browser_side, 'F - test_show_log_browser_side/baseline')
|
check(not Show_log_browser_side, 'F - test_show_log_browser_side/baseline')
|
||||||
-- pressing ctrl+l shows log-browser side
|
-- pressing ctrl+l shows log-browser side
|
||||||
App.wait_fake_time(0.1)
|
Current_time = Current_time + 0.1
|
||||||
App.run_after_keychord('C-l')
|
App.run_after_keychord('C-l')
|
||||||
check(Show_log_browser_side, 'F - test_show_log_browser_side')
|
check(Show_log_browser_side, 'F - test_show_log_browser_side')
|
||||||
end
|
end
|
||||||
|
@ -56,7 +56,7 @@ function test_show_log_browser_side_doubles_window_width_if_possible()
|
||||||
Text.redraw_all(Log_browser_state)
|
Text.redraw_all(Log_browser_state)
|
||||||
log_browser.parse(Log_browser_state)
|
log_browser.parse(Log_browser_state)
|
||||||
-- display log browser
|
-- display log browser
|
||||||
App.wait_fake_time(0.1)
|
Current_time = Current_time + 0.1
|
||||||
App.run_after_keychord('C-l')
|
App.run_after_keychord('C-l')
|
||||||
-- window width is doubled
|
-- window width is doubled
|
||||||
check_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')
|
check_eq(App.screen.width, 600, 'F - test_show_log_browser_side_doubles_window_width_if_possible/display:width')
|
||||||
|
@ -87,7 +87,7 @@ function test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_w
|
||||||
Text.redraw_all(Log_browser_state)
|
Text.redraw_all(Log_browser_state)
|
||||||
log_browser.parse(Log_browser_state)
|
log_browser.parse(Log_browser_state)
|
||||||
-- display log browser
|
-- display log browser
|
||||||
App.wait_fake_time(0.1)
|
Current_time = Current_time + 0.1
|
||||||
App.run_after_keychord('C-l')
|
App.run_after_keychord('C-l')
|
||||||
-- margins are now adjusted
|
-- margins are now adjusted
|
||||||
check_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:left')
|
check_eq(Editor_state.left, Margin_left, 'F - test_show_log_browser_side_resizes_both_sides_if_cannot_double_window_width/edit:left')
|
||||||
|
|
Loading…
Reference in New Issue