summaryrefslogtreecommitdiff
path: root/server/server.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-04-02 01:28:21 +0100
committerubq323 <ubq323@ubq323.website>2023-04-02 01:28:21 +0100
commit6e9a052aa877222a1a494ddcdc5507b5bcc3ea68 (patch)
tree811f9c092eb7266faf28002802b5468534b1d76c /server/server.lua
parente77609c5bc8b44aa22ef88063246fd05add5e705 (diff)
minor cleaning
Diffstat (limited to 'server/server.lua')
-rw-r--r--server/server.lua25
1 files changed, 4 insertions, 21 deletions
diff --git a/server/server.lua b/server/server.lua
index 2da7988..701551d 100644
--- a/server/server.lua
+++ b/server/server.lua
@@ -9,6 +9,7 @@ local MapS = require"map".MapS
local Player=require'player'.Player
local posix_time = require"posix.time"
local posix_signal = require"posix.signal"
+local db = require'db'
math.randomseed(os.time())
@@ -138,29 +139,9 @@ local function timenow()
-- this discards some precision but i don't care
return tv.tv_sec + (tv.tv_nsec/1000000000)
end
--- do something only every x seconds
--- returns function(dt) -> bool
--- which returns true if you should, and false otherwise
-local function every(interval)
- local time_since = interval+100
- return function(dt)
- time_since = time_since + dt
- if time_since > interval then
- time_since = 0
- return true
- else
- return false
- end
- end
-end
local tick_interval = 1 -- seconds
local last_tick_time = timenow()
-
--- average tps calculation
-local dts = {}
-local ndt = 1
-local ndts = 100
local ntick = 0
@@ -180,13 +161,15 @@ local function player_near_chunk(cp)
end
local function save_things()
+ local txn = db.txn(true)
for cp,ch in map:iter_chunks() do
- map:save_chunk(cp)
+ map:save_chunk(cp,txn)
if not player_near_chunk(cp) then
-- print("unloading chunk",cp)
map:remove_chunk(cp)
end
end
+ txn:commit()
end
local function tick(ntick)