changed timing code a bit
This commit is contained in:
parent
6fce5f4271
commit
ce22e04ec7
20
sim/main.lua
20
sim/main.lua
@ -12,10 +12,13 @@ dofile("port.lua")
|
||||
dofile("save.lua")
|
||||
|
||||
OPT_TICK_ENABLED = true
|
||||
OPT_TICK_TIME = 0
|
||||
OPT_TICK_TIME = 0.001
|
||||
OPT_FX_UPDATES = true
|
||||
OPT_FX_TIME = 0.03
|
||||
|
||||
local tickdelay = 0
|
||||
local ticksperinterval = 0
|
||||
|
||||
bool_to_int = {[false] = 0, [true] = 1}
|
||||
|
||||
local lastticktime = 0
|
||||
@ -289,20 +292,21 @@ while 1 do
|
||||
local time = os.clock()
|
||||
|
||||
if OPT_TICK_ENABLED then
|
||||
if time - lastticktime >= OPT_TICK_TIME then
|
||||
sim:tick()
|
||||
ticks = ticks + 1
|
||||
if time-lastticktime >= OPT_TICK_TIME then
|
||||
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
|
||||
end
|
||||
else
|
||||
socket.sleep(0.1)
|
||||
socket.sleep(0.05)
|
||||
end
|
||||
|
||||
lastticktime = time
|
||||
|
||||
if time-lastfxtime >= OPT_FX_TIME then
|
||||
sim:sendfxupdate()
|
||||
sim:sendcallbacks()
|
||||
@ -310,7 +314,7 @@ while 1 do
|
||||
end
|
||||
|
||||
if time-lastmeasuretime >= 0.1 then
|
||||
if #avgticks >= 20 then
|
||||
if #avgticks >= 10 then
|
||||
totalticks = totalticks - table.remove(avgticks, 1)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user