From 7353208c7af91badea7d152a8618166b815737cc Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Fri, 19 Jun 2020 16:08:24 -0400 Subject: [PATCH] switch os.clock to minetest.get_us_time --- mods/aether/biomes.lua | 4 ++-- mods/boat/init.lua | 8 ++++---- mods/experience/init.lua | 12 ++++++------ mods/nether/biomes.lua | 4 ++-- mods/tnt/init.lua | 6 +++--- mods/void/init.lua | 4 ++-- mods/weather/init.lua | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/mods/aether/biomes.lua b/mods/aether/biomes.lua index 8628427..9006484 100644 --- a/mods/aether/biomes.lua +++ b/mods/aether/biomes.lua @@ -79,7 +79,7 @@ minetest.register_on_generated(function(minp, maxp, seed) return end -- Start time of mapchunk generation. - --local t0 = os.clock() + --local t0 = minetest.get_us_time()/1000000 -- Noise stuff. @@ -185,6 +185,6 @@ minetest.register_on_generated(function(minp, maxp, seed) --vm:update_liquids() -- Print generation time of this mapchunk. - --local chugent = math.ceil((os.clock() - t0) * 1000) + --local chugent = math.ceil((minetest.get_us_time()/1000000- t0) * 1000) --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms") end) diff --git a/mods/boat/init.lua b/mods/boat/init.lua index d01b027..29157d3 100644 --- a/mods/boat/init.lua +++ b/mods/boat/init.lua @@ -202,7 +202,7 @@ minetest.register_entity("boat:boat", { local pos = self.object:get_pos() local velocity = self.object:get_velocity() if self.lag_check then - local chugent = math.ceil((os.clock() - self.lag_check) * 1000) + local chugent = math.ceil(minetest.get_us_time()/1000 - self.lag_check) --print("lag = "..chugent.." ms") if chugent > 70 and self.old_pos and self.old_velocity then @@ -212,7 +212,7 @@ minetest.register_entity("boat:boat", { end self.old_pos = pos self.old_velocity = vel - self.lag_check = os.clock() + self.lag_check = minetest.get_us_time()/1000 end, on_step = function(self, dtime) @@ -470,7 +470,7 @@ minetest.register_entity("boat:iron_boat", { local pos = self.object:get_pos() local velocity = self.object:get_velocity() if self.lag_check then - local chugent = math.ceil((os.clock() - self.lag_check) * 1000) + local chugent = math.ceil(minetest.get_us_time()/1000- self.lag_check) --print("lag = "..chugent.." ms") if chugent > 70 and self.old_pos and self.old_velocity then @@ -480,7 +480,7 @@ minetest.register_entity("boat:iron_boat", { end self.old_pos = pos self.old_velocity = vel - self.lag_check = os.clock() + self.lag_check = minetest.get_us_time()/1000 end, on_step = function(self, dtime) diff --git a/mods/experience/init.lua b/mods/experience/init.lua index 9f7583e..7f3a30c 100644 --- a/mods/experience/init.lua +++ b/mods/experience/init.lua @@ -13,12 +13,12 @@ local load_data = function(player) temp_pool.xp_level = mod_storage:get_int(name.."xp_level") temp_pool.xp_bar = mod_storage:get_int(name.."xp_bar" ) temp_pool.buffer = 0 - temp_pool.last_time= os.clock() + temp_pool.last_time= minetest.get_us_time()/1000000 else temp_pool.xp_level = 0 temp_pool.xp_bar = 0 temp_pool.buffer = 0 - temp_pool.last_time= os.clock() + temp_pool.last_time= minetest.get_us_time()/1000000 end end @@ -189,15 +189,15 @@ local function add_experience(player,experience) temp_pool.xp_bar = temp_pool.xp_bar + experience if temp_pool.xp_bar > 36 then - if os.clock() - temp_pool.last_time > 0.04 then + if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.04 then minetest.sound_play("level_up",{gain=0.2,to_player = name}) - temp_pool.last_time = os.clock() + temp_pool.last_time = minetest.get_us_time()/1000000 end temp_pool.xp_bar = temp_pool.xp_bar - 36 level_up_experience(player) else - if os.clock() - temp_pool.last_time > 0.01 then - temp_pool.last_time = os.clock() + if minetest.get_us_time()/1000000 - temp_pool.last_time > 0.01 then + temp_pool.last_time = minetest.get_us_time()/1000000 minetest.sound_play("experience",{gain=0.1,to_player = name,pitch=math.random(75,99)/100}) end end diff --git a/mods/nether/biomes.lua b/mods/nether/biomes.lua index 181ada6..15e32cb 100644 --- a/mods/nether/biomes.lua +++ b/mods/nether/biomes.lua @@ -129,7 +129,7 @@ minetest.register_on_generated(function(minp, maxp, seed) return end -- Start time of mapchunk generation. - --local t0 = os.clock() + --local t0 = minetest.get_us_time()/1000000 -- Noise stuff. @@ -228,6 +228,6 @@ minetest.register_on_generated(function(minp, maxp, seed) --vm:update_liquids() -- Print generation time of this mapchunk. - --local chugent = math.ceil((os.clock() - t0) * 1000) + --local chugent = math.ceil((minetest.get_us_time()/1000000 - t0) * 1000) --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms") end) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index fdb5f31..f43e254 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -70,7 +70,7 @@ local hp local explosion_force local explosion_depletion local range_calc -local boom_time = os.clock() +local boom_time = minetest.get_us_time()/1000000 function tnt(pos,range,explosion_type) in_node = minetest.get_node(pos).name in_water = ( in_node == "main:water" or minetest.get_node(pos).name == "main:waterflow") @@ -137,8 +137,8 @@ function tnt(pos,range,explosion_type) vm:update_liquids() vm:write_to_map() end - if os.clock() - boom_time >= 0.1 then - boom_time = os.clock() + if minetest.get_us_time()/1000000 - boom_time >= 0.1 then + boom_time = minetest.get_us_time()/1000000 minetest.sound_play("tnt_explode", {pos = pos, gain = 1.0, max_hear_distance = 64}) --hear twice as far away end diff --git a/mods/void/init.lua b/mods/void/init.lua index 34e49f5..2af9999 100644 --- a/mods/void/init.lua +++ b/mods/void/init.lua @@ -88,7 +88,7 @@ minetest.register_on_generated(function(minp, maxp, seed) return end -- Start time of mapchunk generation. - --local t0 = os.clock() + --local t0 = minetest.get_us_time()/1000000 -- Noise stuff. @@ -195,6 +195,6 @@ minetest.register_on_generated(function(minp, maxp, seed) --vm:update_liquids() -- Print generation time of this mapchunk. - --local chugent = math.ceil((os.clock() - t0) * 1000) + --local chugent = math.ceil((minetest.get_us_time()/1000000 - t0) * 1000) --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms") end) diff --git a/mods/weather/init.lua b/mods/weather/init.lua index 6020407..fc29861 100644 --- a/mods/weather/init.lua +++ b/mods/weather/init.lua @@ -199,14 +199,14 @@ local function do_snow() if weather_type == 1 then for _,player in ipairs(minetest.get_connected_players()) do --this is debug - --local t0 = os.clock() + --local t0 = minetest.get_us_time()/1000000 pos = round_it(player:get_pos()) min = subber(pos, snow_radius) max = adder(pos, snow_radius) area_index = under_air(min, max, all_nodes) - --local node_search_time = math.ceil((os.clock() - t0) * 1000) + --local node_search_time = math.ceil((minetest.get_us_time()/1000000 - t0) * 1000) spawn_table = {} @@ -310,7 +310,7 @@ local function do_snow() --this is debug --[[ - local chugent = math.ceil((os.clock() - t0) * 1000) + local chugent = math.ceil((minetest.get_us_time()/1000000 - t0) * 1000) print("---------------------------------") print("find_nodes_in_area_under_air() time: " .. node_search_time .. " ms") print("New Snow generation time: " .. chugent .. " ms [" .. (chugent - node_search_time) .. " ms]")