diff --git a/README.md b/README.md index fdc1b15..11d58b6 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ Textures: CC BY-SA 3.0 ### Dependencies Required: default, doors, bucket, stairs, screwdriver, basic_materials, tubelib2, minecart, lcdlib, safer_lua Recommended: signs_bot, hyperloop, compost, techpack_stairway, autobahn -Optional: unified_inventory, wielded_light, unifieddyes +Optional: unified_inventory, wielded_light, unifieddyes, lua-mashal, lsqlite3 + The mods `default`, `doors`, `bucket`, `stairs`, and `screwdriver` are part of Minetest Game. @@ -55,21 +56,21 @@ It is highly recommended that you install the following mods, too: * [techpack_stairway](https://github.com/joe7575/techpack_stairway): Ladders, stairways, and bridges for your machines * [autobahn](https://github.com/joe7575/autobahn): Street blocks and slopes with stripes for faster traveling +For large servers with many player, the following packages are recommended: -### Configuration +* `lua-mashal` for faster serialization/deserialization of data +* `lsqlite3` for storing node and network data -For servers with many players, it is recommended to use the external Lua library 'lua-marshal' to accelarate -the serialization/deserialization of node data and the database SQLite (lsqlite3) to store large amounts of data. -To be able to use 'lua-marshal' and 'lsqlite3', install the packages with: +Both packages are installed via [luarocks](https://luarocks.org/): luarocks install lua-marshal luarocks install lsqlite3 -and add 'techage' to the list of trusted mods in minetest.conf: +To enable this `unsafe` packages, add 'techage' to the list of trusted mods in minetest.conf: secure.trusted_mods = techage -For the installation of 'luarocks' (if not already available), see: https://luarocks.org/ +For the installation of 'luarocks' (if not already available), see [luarocks](https://luarocks.org/) If you enable 'lsqlite3' you also have to enable 'lua-marshal'. Available worlds will be converted to 'lsqlite3' and 'lua-marshal', but there is no way back, so: diff --git a/basis/storage.lua b/basis/storage.lua deleted file mode 100644 index d0353b7..0000000 --- a/basis/storage.lua +++ /dev/null @@ -1,174 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019 Joachim Stolberg - - GPL v3 - See LICENSE.txt for more information - - Memory storage system for volatile and non-volatile memory. - Non-volatile memory is stored from time to time and at shutdown - as node metadata. Volatile memory is lost at every shutdown. - -]]-- - -local S = function(pos) if pos then return minetest.pos_to_string(pos) end end - --- Node data will be stored every NUM_SLOTS * CYCLE_TIME seconds -local NUM_SLOTS = 50 -local CYCLE_TIME = 60 -local NvmStore = {} -local MemStore = {} -local NumNodes = 0 -local StoredNodes = 0 -local NextNum = 0 -local Timeslot = 0 -local FNAME = minetest.get_worldpath()..DIR_DELIM.."techage_metadata.txt" -local use_marshal = minetest.settings:get_bool('techage_use_marshal', false) -local MAR_MAGIC = 0x8e - --- default functions -local serialize = minetest.serialize -local deserialize = minetest.deserialize - -if use_marshal then - if not techage.IE then - error("Please add 'secure.trusted_mods = techage' to minetest.conf!") - end - local marshal = techage.IE.require("marshal") - if not marshal then - error("Please install marshal via 'luarocks install lua-marshal'") - end - - serialize = marshal.encode - - deserialize = function(s) - if s ~= "" then - if s:byte(1) == MAR_MAGIC then - return marshal.decode(s) - else - return minetest.deserialize(s) - end - end - end -end - -local function read_file() - local f = io.open(FNAME, "r") - if f ~= nil then - local s = f:read("*all") - io.close(f) - return minetest.deserialize(s) or {} - end - return {} -end - -local function write_file(tbl) - local s = minetest.serialize(tbl) - local f = io.open(FNAME, "w") - f:write(s) - f:close() -end - -NvmStore = read_file() - -minetest.register_on_shutdown(function() - write_file(NvmStore) -end) - - - - - -local function set_metadata(hash, tbl) - local pos = minetest.get_position_from_hash(hash) - tbl.USED = nil - local data = serialize(tbl) - local meta = minetest.get_meta(pos) - meta:set_string("ta_data", data) - meta:mark_as_private("ta_data") -end - -local function get_metadata(hash) - local pos = minetest.get_position_from_hash(hash) - local meta = minetest.get_meta(pos) - local s = meta:get_string("ta_data") - if s ~= "" then - return deserialize(s) - end -end - -local function nvm_storage() - local ToBeDeleted = {} - for hash,tbl in pairs(NvmStore) do - NumNodes = NumNodes + 1 - if tbl.USED then - if not tbl.SLOT then - tbl.SLOT = NextNum % NUM_SLOTS - NextNum = NextNum + 1 - end - if tbl.SLOT == Timeslot then - set_metadata(hash, tbl) - StoredNodes = StoredNodes + 1 - end - else - ToBeDeleted[#ToBeDeleted+1] = hash - end - end - for _,hash in ipairs(ToBeDeleted) do - NvmStore[hash] = nil - end - return #ToBeDeleted -end - -local function cyclic_task() - local t = minetest.get_us_time() - Timeslot = (Timeslot + 1) % NUM_SLOTS - NumNodes = 0 - StoredNodes = 0 - local deleted = nvm_storage() - t = minetest.get_us_time() - t - if StoredNodes > 0 then - minetest.log("action", "[TA NVM Storage] duration="..t.."us, total="..NumNodes..", stored="..StoredNodes..", deleted="..deleted) - end - minetest.after(CYCLE_TIME, cyclic_task) -end - -minetest.after(CYCLE_TIME, cyclic_task) - - - --- To get the volatile node data as table -function techage.get_mem(pos) - local hash = minetest.hash_node_position(pos) - if not MemStore[hash] then - MemStore[hash] = {} - end - return MemStore[hash] -end - --- To get the nonvolatile node data as table -function techage.get_nvm(pos) - local hash = minetest.hash_node_position(pos) - if not NvmStore[hash] then - NvmStore[hash] = get_metadata(hash) or {} - end - NvmStore[hash].USED = true - return NvmStore[hash] -end - -function techage.peek_nvm(pos) - local hash = minetest.hash_node_position(pos) - return NvmStore[hash] or {} -end - --- To be called when a node is removed -function techage.del_mem(pos) - local meta = minetest.get_meta(pos) - meta:set_string("ta_data", "") - local hash = minetest.hash_node_position(pos) - NvmStore[hash] = nil - MemStore[hash] = nil -end