mirror of
https://github.com/technix/ham_radio.git
synced 2024-08-19 04:34:09 +02:00
cache transmitters - avoid serialization
This commit is contained in:
parent
ee047a6266
commit
5c199f251c
24
init.lua
24
init.lua
@ -6,27 +6,27 @@ ham_radio = rawget(_G, "ham_radio") or {}
|
|||||||
ham_radio = {
|
ham_radio = {
|
||||||
playerhuds = {},
|
playerhuds = {},
|
||||||
is_receiver_wielded = {},
|
is_receiver_wielded = {},
|
||||||
|
transmitters = {},
|
||||||
settings = {
|
settings = {
|
||||||
hud_pos = { x = 0.5, y = 0.8 },
|
hud_pos = { x = 0.5, y = 0.8 },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ham_radio.save_transmitter(pos, transmitter_properties)
|
-- preload transmitter data
|
||||||
mod_storage:set_string(
|
local all_transmitters = mod_storage:to_table().fields
|
||||||
minetest.pos_to_string(pos, 0),
|
for key, transmitter_data in pairs(all_transmitters) do
|
||||||
minetest.write_json(transmitter_properties)
|
ham_radio.transmitters[key] = minetest.parse_json(transmitter_data)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ham_radio.read_transmitter(pos)
|
function ham_radio.save_transmitter(pos, transmitter_properties)
|
||||||
return mod_storage:get_string(minetest.pos_to_string(pos, 0))
|
local key = minetest.pos_to_string(pos, 0)
|
||||||
|
ham_radio.transmitters[key] = transmitter_properties -- cache
|
||||||
|
mod_storage:set_string(key, minetest.write_json(transmitter_properties)) -- storage
|
||||||
end
|
end
|
||||||
|
|
||||||
function ham_radio.find_transmitters(frequency)
|
function ham_radio.find_transmitters(frequency)
|
||||||
local transmitter_list = {}
|
local transmitter_list = {}
|
||||||
local all_transmitters = mod_storage:to_table().fields
|
for key, transmitter in pairs(ham_radio.transmitters) do
|
||||||
for key, transmitter_data in pairs(all_transmitters) do
|
|
||||||
local transmitter = minetest.parse_json(transmitter_data)
|
|
||||||
if transmitter.frequency == frequency then
|
if transmitter.frequency == frequency then
|
||||||
transmitter_list[key] = transmitter
|
transmitter_list[key] = transmitter
|
||||||
end
|
end
|
||||||
@ -35,7 +35,9 @@ function ham_radio.find_transmitters(frequency)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ham_radio.delete_transmitter(pos)
|
function ham_radio.delete_transmitter(pos)
|
||||||
mod_storage:set_string(minetest.pos_to_string(pos, 0), '')
|
local key = minetest.pos_to_string(pos, 0)
|
||||||
|
ham_radio.transmitters[key] = nil -- cache
|
||||||
|
mod_storage:set_string(key, '') -- storage
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(modpath.."/craft.lua")
|
dofile(modpath.."/craft.lua")
|
||||||
|
Loading…
Reference in New Issue
Block a user