/advtrains_train_track/models/

-- Cycle(~hour), not displayed most time } Railway times can exist in 3 forms: - as table (see above) - as string (like "12;34") - as number (of seconds) Forms are automagically converted as needed by the converter functions to_* To be sure a rwt is in the required form, explicitly use a converter. ]] local rwt = {} --Time Stamp (Seconds since start of world) local e_time = 0 local e_has_loaded = false local setting_rwt_real = minetest.settings:get("advtrains_lines_rwt_realtime") if setting_rwt_real=="" then setting_rwt_real = "independent" end local e_last_epoch -- last real-time timestamp -- Advance RWT to match minute/second to the current real-world time -- only accounts for the minute/second part, leaves hour/cycle untouched local function adapt_real_time() local datetab = os.date("*t") local real_sectotal = 60*datetab.min + datetab.sec local rwttab = rwt.now() local rwt_sectotal = 60*rwttab.m + rwttab.s --calculate the difference and take it %3600 (seconds/hour) to always move forward local secsfwd = (real_sectotal - rwt_sectotal) % 3600 atlog("[lines][rwt] Skipping",secsfwd,"seconds forward to sync rwt (",rwt.to_string(rwttab),") to real time (",os.date("%H:%M:%S"),")") e_time = e_time + secsfwd end function rwt.set_time(t) e_time = t or 0 if setting_rwt_real == "adapt_real" then adapt_real_time() end atlog("[lines][rwt] Initialized railway time: ",rwt.to_string(e_time)) e_last_epoch = os.time() e_has_loaded = true end function rwt.get_time() return e_time end function rwt.step(dt) if not e_has_loaded then rwt.set_time(0) end if setting_rwt_real=="independent" then -- Regular stepping with dtime e_time = e_time + dt else -- advance with real-world time local diff = os.time() - e_last_epoch e_last_epoch = os.time() if diff>0 then e_time = e_time + diff end end end function rwt.now() return rwt.to_table(e_time) end function rwt.new(c, m, s) return { c = c or 0, m = m or 0, s = s or 0 } end function rwt.copy(rwtime) local rwtimet = rwt.to_table(rwtime) return {