changed timing code a bit

This commit is contained in:
Redo 2020-04-01 18:04:46 -05:00
parent 6fce5f4271
commit ce22e04ec7

View File

@ -12,10 +12,13 @@ dofile("port.lua")
dofile("save.lua") dofile("save.lua")
OPT_TICK_ENABLED = true OPT_TICK_ENABLED = true
OPT_TICK_TIME = 0 OPT_TICK_TIME = 0.001
OPT_FX_UPDATES = true OPT_FX_UPDATES = true
OPT_FX_TIME = 0.03 OPT_FX_TIME = 0.03
local tickdelay = 0
local ticksperinterval = 0
bool_to_int = {[false] = 0, [true] = 1} bool_to_int = {[false] = 0, [true] = 1}
local lastticktime = 0 local lastticktime = 0
@ -289,20 +292,21 @@ while 1 do
local time = os.clock() local time = os.clock()
if OPT_TICK_ENABLED then if OPT_TICK_ENABLED then
if time - lastticktime >= OPT_TICK_TIME then if time-lastticktime >= OPT_TICK_TIME then
sim:tick()
ticks = ticks + 1
lastticktime = time lastticktime = time
local timetonext = time+OPT_TICK_TIME-os.clock() sim:tick()
ticks = ticks+1
local sleeptime = timetonext*0.9 local sleeptime = time-os.clock()+OPT_TICK_TIME-0.03
if sleeptime>0 then socket.sleep(sleeptime) end if sleeptime>0 then socket.sleep(sleeptime) end
end end
else else
socket.sleep(0.1) socket.sleep(0.05)
end end
lastticktime = time
if time-lastfxtime >= OPT_FX_TIME then if time-lastfxtime >= OPT_FX_TIME then
sim:sendfxupdate() sim:sendfxupdate()
sim:sendcallbacks() sim:sendcallbacks()
@ -310,7 +314,7 @@ while 1 do
end end
if time-lastmeasuretime >= 0.1 then if time-lastmeasuretime >= 0.1 then
if #avgticks >= 20 then if #avgticks >= 10 then
totalticks = totalticks - table.remove(avgticks, 1) totalticks = totalticks - table.remove(avgticks, 1)
end end