diff options
author | ubq323 <ubq323@ubq323.website> | 2023-02-25 15:24:33 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-03-14 23:11:13 +0000 |
commit | 3c66e7a4d91e2c891cd3b93346ee1f211eb4b6a5 (patch) | |
tree | d614d872298b11c1e652fb8db9caa212872e7467 /server | |
parent | 242a0b4e7deb356a0015fbf536158962ad2ea29c (diff) |
don't draw chunks definitely not on screen; add targeting reticle; save chunks before exiting on sigint; add /tp 'command'
Diffstat (limited to 'server')
-rw-r--r-- | server/server.lua | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/server/server.lua b/server/server.lua index 097bc99..24b49ae 100644 --- a/server/server.lua +++ b/server/server.lua @@ -7,6 +7,8 @@ local Pos = coords.Pos local worldgen = require"worldgen" local MapS = require"map".MapS local posix_time = require"posix.time" +local posix_signal = require"posix.signal" + math.randomseed(os.time()) local host = enet.host_create("*:8473",nil,2) @@ -181,20 +183,34 @@ local function player_near_chunk(cp) return false end +local function save_things() + for cp,ch in map:iter_chunks() do + map:save_chunk(cp) + if not player_near_chunk(cp) then + -- print("unloading chunk",cp) + map:remove_chunk(cp) + end + end +end + local function tick(ntick) if ntick % 30 == 0 then -- print("saving things") - for cp,ch in map:iter_chunks() do - map:save_chunk(cp) - if not player_near_chunk(cp) then - -- print("unloading chunk",cp) - map:remove_chunk(cp) - end - end + save_things() end end +local stopping=false + +posix_signal.signal(posix_signal.SIGINT, function() stopping=true end) + while true do + if stopping then + print("stopping...") + save_things() + break + end + local now = timenow() local dt = now - last_tick_time local time_till_next_tick = (last_tick_time+tick_interval)-now |