aboutsummaryrefslogtreecommitdiff
path: root/advtrains/wagons.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-07-19 22:57:29 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2020-07-19 22:57:29 +0200
commit7de2a9142f0b27f2b03235a6a47d9e2f02245852 (patch)
treed921fa94887d8fac215b929c912940a92f7dbf8e /advtrains/wagons.lua
parent3040c53413a5ddb7e0e84f02f85de7868510c889 (diff)
parent19509acf56aef4b6e5f45023ee5603e95822fe69 (diff)
downloadadvtrains-7de2a9142f0b27f2b03235a6a47d9e2f02245852.tar.gz
advtrains-7de2a9142f0b27f2b03235a6a47d9e2f02245852.tar.bz2
advtrains-7de2a9142f0b27f2b03235a6a47d9e2f02245852.zip
Merge branch 'master' of bananach.space:advtrains
Diffstat (limited to 'advtrains/wagons.lua')
-rw-r--r--advtrains/wagons.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 2b0833d..28a471a 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -14,6 +14,8 @@ advtrains.wagons = {}
advtrains.wagon_prototypes = {}
advtrains.wagon_objects = {}
+local unload_wgn_range = advtrains.wagon_load_range + 32
+
local setting_show_ids = minetest.settings:get_bool("advtrains_show_ids")
--
@@ -473,8 +475,29 @@ function wagon:on_step(dtime)
yaw=yaw+math.pi
end
+ -- this timer runs off every 2 seconds.
self.updatepct_timer=(self.updatepct_timer or 0)-dtime
local updatepct_timer_elapsed = self.updatepct_timer<=0
+
+ if updatepct_timer_elapsed then
+ --restart timer
+ self.updatepct_timer=2
+ -- perform checks that are not frequently needed
+
+ -- unload entity if out of range (because relevant pr won't be merged in engine)
+ -- This is a WORKAROUND!
+ local outofrange = false
+ for _,p in pairs(minetest.get_connected_players()) do
+ if vector.distance(p:get_pos(),pos)>=unload_wgn_range then
+ outofrange = true
+ end
+ end
+ if outofrange then
+ --atdebug("wagon",self.id,"unloading (too far away)")
+ self.object:remove()
+ end
+ end
+
if not self.old_velocity_vector
or not vector.equals(velocityvec, self.old_velocity_vector)
or not self.old_acceleration_vector
@@ -520,7 +543,6 @@ function wagon:on_step(dtime)
self.object:setyaw(yaw)
end
- self.updatepct_timer=2
if self.update_animation then
self:update_animation(train.velocity, self.old_velocity)
end