summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2025-08-08 20:35:56 -0500
committercheapie <no-email-for-you@example.com>2025-08-08 20:35:56 -0500
commita3bf40bf1419c7366547781b195fdbe04e8365d8 (patch)
treed771fe8af5b4fddb63f98a1bb6bc1a79b07dc20d
parent17a87534f2af05b2826618f74f4a6c82493f881b (diff)
downloadcelevator-a3bf40bf1419c7366547781b195fdbe04e8365d8.tar
celevator-a3bf40bf1419c7366547781b195fdbe04e8365d8.tar.gz
celevator-a3bf40bf1419c7366547781b195fdbe04e8365d8.tar.bz2
celevator-a3bf40bf1419c7366547781b195fdbe04e8365d8.tar.xz
celevator-a3bf40bf1419c7366547781b195fdbe04e8365d8.zip
Minor (very minor) performance improvementsHEADmain
-rw-r--r--doors.lua14
-rw-r--r--drive_entity.lua4
-rw-r--r--drive_null.lua4
3 files changed, 22 insertions, 0 deletions
diff --git a/doors.lua b/doors.lua
index 8528449..75cbb8b 100644
--- a/doors.lua
+++ b/doors.lua
@@ -2,6 +2,12 @@ celevator.doors = {}
celevator.doors.erefs = {}
+--These get overwritten on globalstep and aren't settings.
+--They're just set to true here so the globalstep functions run at least once,
+--in case a door was moving when the server last shut down.
+celevator.doors.hwdoor_step_enabled = true
+celevator.doors.cardoor_step_enabled = true
+
local function placesill(pos,node)
local erefs = minetest.get_objects_inside_radius(pos,0.5)
for _,ref in pairs(erefs) do
@@ -412,6 +418,7 @@ minetest.register_entity("celevator:hwdoor_moving",{
})
function celevator.doors.hwopen(pos,drivepos)
+ celevator.doors.hwdoor_step_enabled = true
local hwdoors_moving = minetest.deserialize(celevator.storage:get_string("hwdoors_moving")) or {}
local hash = minetest.hash_node_position(pos)
if not hwdoors_moving[hash] then
@@ -475,6 +482,7 @@ function celevator.doors.hwopen(pos,drivepos)
end
function celevator.doors.hwclose(pos,drivepos,nudge)
+ celevator.doors.hwdoor_step_enabled = true
local hwdoors_moving = minetest.deserialize(celevator.storage:get_string("hwdoors_moving")) or {}
local hash = minetest.hash_node_position(pos)
if hwdoors_moving[hash] then
@@ -513,6 +521,7 @@ function celevator.doors.hwclose(pos,drivepos,nudge)
end
function celevator.doors.hwstep(dtime)
+ if not celevator.doors.hwdoor_step_enabled then return end
local hwdoors_moving = minetest.deserialize(celevator.storage:get_string("hwdoors_moving")) or {}
local save = false
for hash,data in pairs(hwdoors_moving) do
@@ -587,11 +596,13 @@ function celevator.doors.hwstep(dtime)
if save then
celevator.storage:set_string("hwdoors_moving",minetest.serialize(hwdoors_moving))
end
+ celevator.doors.hwdoor_step_enabled = save
end
minetest.register_globalstep(celevator.doors.hwstep)
function celevator.doors.carstep(dtime)
+ if not celevator.doors.cardoor_step_enabled then return end
local cardoors_moving = minetest.deserialize(celevator.storage:get_string("cardoors_moving")) or {}
local save = false
for hash,data in pairs(cardoors_moving) do
@@ -663,6 +674,7 @@ function celevator.doors.carstep(dtime)
if save then
celevator.storage:set_string("cardoors_moving",minetest.serialize(cardoors_moving))
end
+ celevator.doors.cardoor_step_enabled = save
end
minetest.register_globalstep(celevator.doors.carstep)
@@ -708,6 +720,7 @@ function celevator.doors.spawncardoors(pos,dir,doortype,replace)
end
function celevator.doors.caropen(pos)
+ celevator.doors.cardoor_step_enabled = true
local cardoors_moving = minetest.deserialize(celevator.storage:get_string("cardoors_moving")) or {}
local hash = minetest.hash_node_position(pos)
local cartimer = minetest.get_node_timer(pos)
@@ -770,6 +783,7 @@ function celevator.doors.caropen(pos)
end
function celevator.doors.carclose(pos,nudge)
+ celevator.doors.cardoor_step_enabled = true
local cardoors_moving = minetest.deserialize(celevator.storage:get_string("cardoors_moving")) or {}
local hash = minetest.hash_node_position(pos)
if cardoors_moving[hash] then
diff --git a/drive_entity.lua b/drive_entity.lua
index 0ddd4c4..532b919 100644
--- a/drive_entity.lua
+++ b/drive_entity.lua
@@ -9,6 +9,7 @@ celevator.drives.entity = {
carsoundstate = {},
entityinfo = {},
sheaverefs = {},
+ step_enabled = true, --Not a setting, is overwritten on globalstep, true here to check for running drives on startup
}
local playerposlimits = {}
@@ -459,6 +460,7 @@ function celevator.drives.entity.entitiestonodes(refs,carid)
end
function celevator.drives.entity.step(dtime)
+ if not celevator.drives.entity.step_enabled then return end
local entitydrives_running = minetest.deserialize(celevator.storage:get_string("entitydrives_running")) or {}
local save = false
for i,hash in ipairs(entitydrives_running) do
@@ -644,6 +646,7 @@ function celevator.drives.entity.step(dtime)
if save then
celevator.storage:set_string("entitydrives_running",minetest.serialize(entitydrives_running))
end
+ celevator.drives.entity.step_enabled = save
end
minetest.register_globalstep(celevator.drives.entity.step)
@@ -704,6 +707,7 @@ function celevator.drives.entity.moveto(pos,target,inspection)
end
end
if not running then
+ celevator.drives.entity.step_enabled = true
table.insert(entitydrives_running,hash)
celevator.storage:set_string("entitydrives_running",minetest.serialize(entitydrives_running))
--Controller needs to see something so it knows the drive is running
diff --git a/drive_null.lua b/drive_null.lua
index 1a22e22..2664d47 100644
--- a/drive_null.lua
+++ b/drive_null.lua
@@ -3,6 +3,7 @@ celevator.drives.null = {
description = "Simulation only, no movement, for testing and demonstration",
nname = "celevator:drive_null",
soundhandles = {},
+ step_enabled = true, --Not a setting, is overwritten on globalstep, true here to check for running drives on startup
}
local function update_ui(pos)
@@ -90,6 +91,7 @@ minetest.register_node("celevator:drive_null",{
})
function celevator.drives.null.step(dtime)
+ if not celevator.drives.null.step_enabled then return end
local nulldrives_running = minetest.deserialize(celevator.storage:get_string("nulldrives_running")) or {}
local save = false
for i,hash in ipairs(nulldrives_running) do
@@ -146,6 +148,7 @@ function celevator.drives.null.step(dtime)
if save then
celevator.storage:set_string("nulldrives_running",minetest.serialize(nulldrives_running))
end
+ celevator.drives.null.step_enabled = save
end
minetest.register_globalstep(celevator.drives.null.step)
@@ -163,6 +166,7 @@ function celevator.drives.null.moveto(pos,target)
end
end
if not running then
+ celevator.drives.null.step_enabled = true
table.insert(nulldrives_running,hash)
celevator.storage:set_string("nulldrives_running",minetest.serialize(nulldrives_running))
end