Skip to content

Commit

Permalink
replace uv.hrtime with love.timer.getTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauumm committed Oct 16, 2024
1 parent c65d1ec commit 2762cc4
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 14 deletions.
3 changes: 1 addition & 2 deletions compat/game192/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ local Timeline = require("compat.game192.timeline")
local set_color = require("compat.game21.color_transform")
local make_fake_config = require("compat.game192.fake_config")
local music = require("compat.music")
local uv = require("luv")
local async = require("async")
local style = require("compat.game192.style")
local status = require("compat.game192.status")
Expand Down Expand Up @@ -128,7 +127,7 @@ public.start = async(function(pack_folder, level_id, level_options)
public.tickrate = 960
level_options.difficulty_mult = level_options.difficulty_mult or 1
local difficulty_mult = level_options.difficulty_mult
local seed = math.floor(uv.hrtime() * 1000)
local seed = math.floor(love.timer.getTime() * 1000000000)
math.randomseed(input.next_seed(seed))

game.real_time = 0
Expand Down
3 changes: 1 addition & 2 deletions compat/game20/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local args = require("args")
local uv = require("luv")
local playsound = require("compat.game21.playsound")
local assets = require("compat.game20.assets")
local make_fake_config = require("compat.game20.fake_config")
Expand Down Expand Up @@ -49,7 +48,7 @@ local instance_colors = {}
public.start = async(function(pack_id, level_id, level_options)
level_options.difficulty_mult = level_options.difficulty_mult or 1
game.difficulty_mult = level_options.difficulty_mult
local seed = math.floor(uv.hrtime())
local seed = math.floor(love.timer.getTime() * 1000000000)
math.randomseed(input.next_seed(seed))
game.pack = async.await(assets.get_pack(pack_id))
level.set(game.pack.levels[level_id])
Expand Down
3 changes: 1 addition & 2 deletions compat/game21/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local Tris = require("compat.game21.dynamic_tris")
local set_color = require("compat.game21.color_transform")
local assets = require("compat.game21.assets")
local utils = require("compat.game192.utils")
local uv = require("luv")
local pulse = require("compat.game21.pulse")
local beat_pulse = require("compat.game21.beat_pulse")
local pseudo3d = require("compat.game21.pseudo3d")
Expand Down Expand Up @@ -82,7 +81,7 @@ public.start = async(function(pack_id, level_id, level_options)
end
level_options.difficulty_mult = level_options.difficulty_mult or 1
local difficulty_mult = level_options.difficulty_mult
local seed = uv.hrtime()
local seed = math.floor(love.timer.getTime() * 1000000000)
math.randomseed(game_input.next_seed(seed))
math.random()
game.pack_data = async.await(assets.get_pack(pack_id))
Expand Down
5 changes: 2 additions & 3 deletions compat/game21/server/packet_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local packet_types = require("compat.game21.server.packet_types")
local version = require("server.version")
local sodium = require("extlibs.luasodium")
local game = require("server.game")
local uv = require("luv")

local packet_handler = {}
local server_pk, server_sk = sodium.crypto_kx_keypair()
Expand Down Expand Up @@ -259,7 +258,7 @@ local handlers = {
if client.login_data and client.login_data.login_token == login_token then
if client.login_data.ready then
client.current_level = read_str(data, 9)
client.start_time = uv.hrtime()
client.start_time = love.timer.getTime()
log("client started game on " .. client.current_level)
else
log("client sent started_game packet before ready")
Expand All @@ -278,7 +277,7 @@ local handlers = {
-- skip reading replay size, it's not required
game.verify_replay_and_save_score(
data:sub(9 + 8),
(uv.hrtime() - client.start_time) / 10 ^ 9,
love.timer.getTime() - client.start_time,
client.login_data.steam_id
)
client.current_level = nil
Expand Down
7 changes: 3 additions & 4 deletions server/game_thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local msgpack = require("extlibs.msgpack.msgpack")
local replay = require("game_handler.replay")
local game_handler = require("game_handler")
local config = require("config")
local uv = require("luv")
local threadify = require("threadify")

-- avoid local redefinition
Expand Down Expand Up @@ -47,7 +46,7 @@ local function get_replay_save_path(hash)
end

function api.verify_replay(compressed_replay, time, steam_id)
local start = uv.hrtime()
local start = love.timer.getTime()
local decoded_replay = replay:new_from_data(compressed_replay)
local around_time = 0
local last_around_time = 0
Expand All @@ -59,8 +58,8 @@ function api.verify_replay(compressed_replay, time, steam_id)
love.timer.sleep(0.01)
end
game_handler.run_until_death(function()
local now = uv.hrtime()
around_time = math.floor((now - start) / (10 ^ 9) % 10)
local now = love.timer.getTime()
around_time = math.floor((now - start) % 10)
if math.abs(around_time - last_around_time) > 2 then
-- print progress every 10s
log(
Expand Down
1 change: 0 additions & 1 deletion server/web_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ local msgpack = require("extlibs.msgpack.msgpack")
local http = require("extlibs.http")
local url = require("socket.url")
local log = require("log")("server.web_api")
local uv = require("luv")
local zip = require("extlibs.love-zip")
local threadify = require("threadify")
local game_handler = require("game_handler")
Expand Down

0 comments on commit 2762cc4

Please sign in to comment.