diff options
author | ubq323 <ubq323@ubq323.website> | 2023-02-11 00:31:54 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-02-11 00:31:54 +0000 |
commit | 81ee73e37348eaae6b1e4a23378d13d129133904 (patch) | |
tree | f764a6d08ab788b797fb99a9e4e1ff99fba05cb6 /server/server.lua | |
parent | 7952bbc2a606ab22e04112eb2f21a573d0db116e (diff) |
rework of tick interval, refactor of chunk loading/generation into ChunkS class
Diffstat (limited to 'server/server.lua')
-rw-r--r-- | server/server.lua | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/server/server.lua b/server/server.lua index e9eef30..cc9903e 100644 --- a/server/server.lua +++ b/server/server.lua @@ -1,7 +1,6 @@ local enet = require"enet" local json = require"common.dkjson" local chunk = require"common.chunk" -local Chunk = require"common.chunk".Chunk local noise = require"noise" local coords = require"common.coords" local worldgen = require"worldgen" @@ -170,30 +169,13 @@ end while true do local now = timenow() local dt = now - last_tick_time - - if dt >= tick_interval then - dts[ndt] = dt - ndt = 1+(ndt%ndts) + local time_till_next_tick = (last_tick_time+tick_interval)-now + if time_till_next_tick > 0.001 then + local ev = host:service(time_till_next_tick*1000) + if ev then handle_ev(ev) end + else last_tick_time = now ntick = ntick + 1 - tick(ntick) - - local tps = 0 - for _,d in ipairs(dts) do tps = tps + 1/d end - tps = tps/#dts - - - print(ndt,ndts) - if 1 == ndt%ndts then - print("tps",tps) - end - end - - local now2 = timenow() - local time_till_next_tick = (last_tick_time+tick_interval)-now2 - if time_till_next_tick > 0 then - local ev = host:service(time_till_next_tick/1000) - if ev then handle_ev(ev) end end end |