switch os.clock to minetest.get_us_time

This commit is contained in:
oilboi 2020-06-19 16:08:24 -04:00
parent ad5ead15c6
commit 7353208c7a
7 changed files with 22 additions and 22 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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]")