diff --git a/mobf/init.lua b/mobf/init.lua index cccf7ce..f67f66a 100644 --- a/mobf/init.lua +++ b/mobf/init.lua @@ -40,6 +40,8 @@ mobf_rtd = { registred_mob = {}, --!registred mobs_data registred_mob_data = {}, + --!timesource + timesource = "os.clock() (10ms ONLY!)", } --!path of mod @@ -136,6 +138,26 @@ end --! @brief main initialization function function mobf_init_framework() + + --try to get timesource with best accuracy + if type(minetest.get_us_time) == "function" then + mobf_get_time_ms = function() + return minetest.get_us_time() / 1000 + end + mobf_rtd.timesource = "minetest.get_us_time()" + else + if socket == nil then + local status, module = pcall(require, 'socket') + + if status and type(module.gettime) == "function" then + mobf_get_time_ms = function() + return socket.gettime()*1000 + end + mobf_rtd.timesource = "socket.gettime()" + end + end + end + minetest.log(LOGLEVEL_NOTICE,"MOBF: Initializing mob framework") mobf_init_basic_tools() diff --git a/mobf/utils/generic_functions.lua b/mobf/utils/generic_functions.lua index b38e95a..107ac91 100644 --- a/mobf/utils/generic_functions.lua +++ b/mobf/utils/generic_functions.lua @@ -19,10 +19,6 @@ --! @ingroup framework_int --! @{ -if minetest.world_setting_get("mobf_enable_socket_time") then - require "socket" -end - ------------------------------------------------------------------------------- -- name: mobf_get_time_ms() -- @@ -31,11 +27,8 @@ end --! @return current time in ms ------------------------------------------------------------------------------- function mobf_get_time_ms() - if minetest.world_setting_get("mobf_enable_socket_time") then - return socket.gettime()*1000 - else - return os.clock()*1000 - end + --this fct is overwritten on init with best timesource available atm + return os.clock() * 1000 end -------------------------------------------------------------------------------