From 3c66e7a4d91e2c891cd3b93346ee1f211eb4b6a5 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 25 Feb 2023 15:24:33 +0000 Subject: don't draw chunks definitely not on screen; add targeting reticle; save chunks before exiting on sigint; add /tp 'command' --- server/server.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'server') 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 -- cgit v1.2.3