From 81ee73e37348eaae6b1e4a23378d13d129133904 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 11 Feb 2023 00:31:54 +0000 Subject: rework of tick interval, refactor of chunk loading/generation into ChunkS class --- server/server.lua | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'server/server.lua') 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 -- cgit v1.2.3