diff options
author | orwell96 <mono96.mml@gmail.com> | 2017-04-29 19:13:15 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2017-04-29 19:13:15 +0200 |
commit | 331db7ba5f4e4b308c1f8efa93c2b40c5139766d (patch) | |
tree | c9dc5d02d6c1986ef420004f94154c61be0cc1a9 /advtrains/advtrains/trainlogic.lua | |
parent | 337db2a573ccaa1672e713855022e96106679803 (diff) | |
download | advtrains-331db7ba5f4e4b308c1f8efa93c2b40c5139766d.tar.gz advtrains-331db7ba5f4e4b308c1f8efa93c2b40c5139766d.tar.bz2 advtrains-331db7ba5f4e4b308c1f8efa93c2b40c5139766d.zip |
Unify globalstep, load and save of all components into single functions
Diffstat (limited to 'advtrains/advtrains/trainlogic.lua')
-rw-r--r-- | advtrains/advtrains/trainlogic.lua | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua index d9edd6d..98a0e2b 100644 --- a/advtrains/advtrains/trainlogic.lua +++ b/advtrains/advtrains/trainlogic.lua @@ -36,25 +36,9 @@ advtrains.train_brake_force=3--per second, not divided by number of wagons advtrains.train_roll_force=0.5--per second, not divided by number of wagons, acceleration when rolling without brake advtrains.train_emerg_force=10--for emergency brakes(when going off track) -advtrains.save_interval=10 -advtrains.save_timer=advtrains.save_interval -minetest.register_globalstep(function(dtime_mt) - --limit dtime: if trains move too far in one step, automation may cause stuck and wrongly braking trains - local dtime=dtime_mt - if dtime>0.2 then - atprint("Limiting dtime to 0.2!") - dtime=0.2 - end +advtrains.mainloop_trainlogic(function(dtime) - advtrains.save_timer=advtrains.save_timer-dtime - if advtrains.save_timer<=0 then - local t=os.clock() - --save - advtrains.save() - advtrains.save_timer=advtrains.save_interval - atprintbm("saving", t) - end --build a table of all players indexed by pts. used by damage and door system. advtrains.playersbypts={} for _, player in pairs(minetest.get_connected_players()) do @@ -80,7 +64,7 @@ minetest.register_globalstep(function(dtime_mt) atprintbm("trainsteps", t) endstep() -end) +end minetest.register_on_joinplayer(function(player) local pname=player:get_player_name() |