Improved usage of Time.now and pbGetTimeNow

This commit is contained in:
Maruno17
2023-05-17 19:24:38 +01:00
parent 28a2b7c9c1
commit 62e372f4d7
14 changed files with 49 additions and 52 deletions

View File

@@ -144,14 +144,14 @@ class File
# Copies the source file to the destination path. # Copies the source file to the destination path.
def self.copy(source, destination) def self.copy(source, destination)
data = "" data = ""
t = Time.now t = System.uptime
File.open(source, "rb") do |f| File.open(source, "rb") do |f|
loop do loop do
r = f.read(4096) r = f.read(4096)
break if !r break if !r
if Time.now - t > 1 if System.uptime - t >= 5
t += 5
Graphics.update Graphics.update
t = Time.now
end end
data += r data += r
end end

View File

@@ -7,12 +7,12 @@ module Translator
def gather_script_and_event_texts def gather_script_and_event_texts
Graphics.update Graphics.update
begin begin
t = Time.now.to_i t = System.uptime
texts = [] texts = []
# Get script texts from Scripts.rxdata # Get script texts from Scripts.rxdata
$RGSS_SCRIPTS.each do |script| $RGSS_SCRIPTS.each do |script|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
scr = Zlib::Inflate.inflate(script[2]) scr = Zlib::Inflate.inflate(script[2])
@@ -22,8 +22,8 @@ module Translator
# script texts from .rb files in Data/Scripts # script texts from .rb files in Data/Scripts
if $RGSS_SCRIPTS.length == 1 if $RGSS_SCRIPTS.length == 1
Dir.all("Data/Scripts").each do |script_file| Dir.all("Data/Scripts").each do |script_file|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
File.open(script_file, "rb") do |f| File.open(script_file, "rb") do |f|
@@ -36,8 +36,8 @@ module Translator
plugin_scripts = load_data("Data/PluginScripts.rxdata") plugin_scripts = load_data("Data/PluginScripts.rxdata")
plugin_scripts.each do |plugin| plugin_scripts.each do |plugin|
plugin[2].each do |script| plugin[2].each do |script|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
scr = Zlib::Inflate.inflate(script[1]).force_encoding(Encoding::UTF_8) scr = Zlib::Inflate.inflate(script[1]).force_encoding(Encoding::UTF_8)
@@ -51,8 +51,8 @@ module Translator
items = [] items = []
choices = [] choices = []
commonevents.compact.each do |event| commonevents.compact.each do |event|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
begin begin
@@ -99,8 +99,8 @@ module Translator
end end
end end
end end
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
items |= [] items |= []
@@ -110,8 +110,8 @@ module Translator
# Find all text in map events and add them to messages # Find all text in map events and add them to messages
mapinfos = pbLoadMapInfos mapinfos = pbLoadMapInfos
mapinfos.each_key do |id| mapinfos.each_key do |id|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
filename = sprintf("Data/Map%03d.rxdata", id) filename = sprintf("Data/Map%03d.rxdata", id)
@@ -120,8 +120,8 @@ module Translator
items = [] items = []
choices = [] choices = []
map.events.each_value do |event| map.events.each_value do |event|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
begin begin
@@ -170,16 +170,16 @@ module Translator
end end
end end
end end
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
items |= [] items |= []
choices |= [] choices |= []
items.concat(choices) items.concat(choices)
MessageTypes.setMapMessagesAsHash(id, items) if items.length > 0 MessageTypes.setMapMessagesAsHash(id, items) if items.length > 0
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
end end

View File

@@ -4,7 +4,7 @@
# Pokérus check # Pokérus check
EventHandlers.add(:on_frame_update, :pokerus_counter, EventHandlers.add(:on_frame_update, :pokerus_counter,
proc { proc {
next if !$player next if !$player&.party.any? { |pkmn| pkmn.pokerusStage == 1 }
last = $PokemonGlobal.pokerusTime last = $PokemonGlobal.pokerusTime
next if !last next if !last
now = pbGetTimeNow now = pbGetTimeNow
@@ -48,7 +48,7 @@ EventHandlers.add(:on_frame_update, :low_battery_warning,
next if $game_temp.warned_low_battery || !pbBatteryLow? next if $game_temp.warned_low_battery || !pbBatteryLow?
next if $game_temp.in_menu || $game_temp.in_battle || $game_player.move_route_forcing || next if $game_temp.in_menu || $game_temp.in_battle || $game_player.move_route_forcing ||
$game_temp.message_window_showing || pbMapInterpreterRunning? $game_temp.message_window_showing || pbMapInterpreterRunning?
next if pbGetTimeNow.sec != 0 next if Time.now.sec != 0
$game_temp.warned_low_battery = true $game_temp.warned_low_battery = true
pbMessage(_INTL("The game has detected that the battery is low. You should save soon to avoid losing your progress.")) pbMessage(_INTL("The game has detected that the battery is low. You should save soon to avoid losing your progress."))
} }

View File

@@ -1207,7 +1207,7 @@ class Pokemon
@obtain_text = nil @obtain_text = nil
@obtain_level = level @obtain_level = level
@hatched_map = 0 @hatched_map = 0
@timeReceived = pbGetTimeNow.to_i @timeReceived = Time.now.to_i
@timeEggHatched = nil @timeEggHatched = nil
@fused = nil @fused = nil
@personalID = rand(2**16) | (rand(2**16) << 16) @personalID = rand(2**16) | (rand(2**16) << 16)

View File

@@ -209,7 +209,7 @@ def pbHatch(pokemon)
pokemon.name = nil pokemon.name = nil
pokemon.owner = Pokemon::Owner.new_from_trainer($player) pokemon.owner = Pokemon::Owner.new_from_trainer($player)
pokemon.happiness = 120 pokemon.happiness = 120
pokemon.timeEggHatched = pbGetTimeNow pokemon.timeEggHatched = Time.now.to_i
pokemon.obtain_method = 1 # hatched from egg pokemon.obtain_method = 1 # hatched from egg
pokemon.hatched_map = $game_map.map_id pokemon.hatched_map = $game_map.map_id
pokemon.record_first_moves pokemon.record_first_moves

View File

@@ -43,7 +43,7 @@ class PokemonTrainerCard_Scene
hour = totalsec / 60 / 60 hour = totalsec / 60 / 60
min = totalsec / 60 % 60 min = totalsec / 60 % 60
time = (hour > 0) ? _INTL("{1}h {2}m", hour, min) : _INTL("{1}m", min) time = (hour > 0) ? _INTL("{1}h {2}m", hour, min) : _INTL("{1}m", min)
$PokemonGlobal.startTime = pbGetTimeNow if !$PokemonGlobal.startTime $PokemonGlobal.startTime = Time.now if !$PokemonGlobal.startTime
starttime = _INTL("{1} {2}, {3}", starttime = _INTL("{1} {2}, {3}",
pbGetAbbrevMonthName($PokemonGlobal.startTime.mon), pbGetAbbrevMonthName($PokemonGlobal.startTime.mon),
$PokemonGlobal.startTime.day, $PokemonGlobal.startTime.day,

View File

@@ -378,8 +378,7 @@ def pbReceiveMysteryGift(id)
if gift[1] == 0 # Pokémon if gift[1] == 0 # Pokémon
gift[2].personalID = rand(2**16) | (rand(2**16) << 16) gift[2].personalID = rand(2**16) | (rand(2**16) << 16)
gift[2].calc_stats gift[2].calc_stats
time = pbGetTimeNow gift[2].timeReceived = Time.now.to_i
gift[2].timeReceived = time.getgm.to_i
gift[2].obtain_method = 4 # Fateful encounter gift[2].obtain_method = 4 # Fateful encounter
gift[2].record_first_moves gift[2].record_first_moves
gift[2].obtain_level = gift[2].level gift[2].obtain_level = gift[2].level

View File

@@ -27,8 +27,7 @@ class BugContestState
# Returns whether the last contest ended less than 24 hours ago. # Returns whether the last contest ended less than 24 hours ago.
def pbContestHeld? def pbContestHeld?
return false if !@lastContest return false if !@lastContest
timenow = pbGetTimeNow return pbGetTimeNow.to_i - @lastContest < 24 * 60 * 60 # 24 hours
return timenow.to_i - @lastContest < 24 * 60 * 60 # 24 hours
end end
def expired? def expired?
@@ -222,8 +221,7 @@ class BugContestState
@otherparty = [] @otherparty = []
@contestMaps = [] @contestMaps = []
@reception = [] @reception = []
timenow = pbGetTimeNow @lastContest = pbGetTimeNow.to_i
@lastContest = timenow.to_i
$game_map.need_refresh = true $game_map.need_refresh = true
end end
end end

View File

@@ -320,16 +320,16 @@ def pbWriteCup(id, rules)
when 2 # Yes, use new when 2 # Yes, use new
return if !pbConfirmMessage(_INTL("This may take a long time. Are you sure?")) return if !pbConfirmMessage(_INTL("This may take a long time. Are you sure?"))
mw = pbCreateMessageWindow mw = pbCreateMessageWindow
t = Time.now t = System.uptime
pbGenerateChallenge(rules, id) do |message| pbGenerateChallenge(rules, id) do |message|
if Time.now - t >= 5 if System.uptime - t >= 5
t += 5
Graphics.update Graphics.update
t = Time.now
end end
if message if message
pbMessageDisplay(mw, message, false) pbMessageDisplay(mw, message, false)
t = System.uptime
Graphics.update Graphics.update
t = Time.now
end end
end end
pbDisposeMessageWindow(mw) pbDisposeMessageWindow(mw)

View File

@@ -609,7 +609,7 @@ def pbChooseLanguage
end end
def pbScreenCapture def pbScreenCapture
t = pbGetTimeNow t = Time.now
filestart = t.strftime("[%Y-%m-%d] %H_%M_%S.%L") filestart = t.strftime("[%Y-%m-%d] %H_%M_%S.%L")
capturefile = RTP.getSaveFileName(sprintf("%s.png", filestart)) capturefile = RTP.getSaveFileName(sprintf("%s.png", filestart))
Graphics.screenshot(capturefile) Graphics.screenshot(capturefile)

View File

@@ -12,10 +12,10 @@ def findBottom(bitmap)
end end
def pbAutoPositionAll def pbAutoPositionAll
t = Time.now.to_i t = System.uptime
GameData::Species.each do |sp| GameData::Species.each do |sp|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t = Time.now.to_i t += 5
Graphics.update Graphics.update
end end
metrics = GameData::SpeciesMetrics.get_species_form(sp.species, sp.form) metrics = GameData::SpeciesMetrics.get_species_form(sp.species, sp.form)

View File

@@ -670,14 +670,14 @@ def pbDebugFixInvalidTiles
num_error_maps = 0 num_error_maps = 0
tilesets = $data_tilesets tilesets = $data_tilesets
mapData = Compiler::MapData.new mapData = Compiler::MapData.new
t = Time.now.to_i t = System.uptime
Graphics.update Graphics.update
total_maps = mapData.mapinfos.keys.length total_maps = mapData.mapinfos.keys.length
Console.echo_h1(_INTL("Checking {1} maps for invalid tiles", total_maps)) Console.echo_h1(_INTL("Checking {1} maps for invalid tiles", total_maps))
mapData.mapinfos.keys.sort.each do |id| mapData.mapinfos.keys.sort.each do |id|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t += 5
Graphics.update Graphics.update
t = Time.now.to_i
end end
map_errors = 0 map_errors = 0
map = mapData.getMap(id) map = mapData.getMap(id)

View File

@@ -36,7 +36,7 @@ module FilenameUpdater
def update_berry_tree_event_charsets def update_berry_tree_event_charsets
ret = [] ret = []
mapData = Compiler::MapData.new mapData = Compiler::MapData.new
t = Time.now.to_i t = System.uptime
Graphics.update Graphics.update
Console.echo_li(_INTL("Checking {1} maps for used berry tree charsets...", mapData.mapinfos.keys.length)) Console.echo_li(_INTL("Checking {1} maps for used berry tree charsets...", mapData.mapinfos.keys.length))
idx = 0 idx = 0
@@ -48,9 +48,9 @@ module FilenameUpdater
next if !map || !mapData.mapinfos[id] next if !map || !mapData.mapinfos[id]
changed = false changed = false
map.events.each_key do |key| map.events.each_key do |key|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t += 5
Graphics.update Graphics.update
t = Time.now.to_i
end end
map.events[key].pages.each do |page| map.events[key].pages.each do |page|
next if nil_or_empty?(page.graphic.character_name) next if nil_or_empty?(page.graphic.character_name)

View File

@@ -1682,7 +1682,7 @@ module Compiler
#============================================================================= #=============================================================================
def compile_trainer_events(_mustcompile) def compile_trainer_events(_mustcompile)
mapData = MapData.new mapData = MapData.new
t = Time.now.to_i t = System.uptime
Graphics.update Graphics.update
trainerChecker = TrainerChecker.new trainerChecker = TrainerChecker.new
change_record = [] change_record = []
@@ -1696,9 +1696,9 @@ module Compiler
map = mapData.getMap(id) map = mapData.getMap(id)
next if !map || !mapData.mapinfos[id] next if !map || !mapData.mapinfos[id]
map.events.each_key do |key| map.events.each_key do |key|
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t += 5
Graphics.update Graphics.update
t = Time.now.to_i
end end
newevent = convert_to_trainer_event(map.events[key], trainerChecker) newevent = convert_to_trainer_event(map.events[key], trainerChecker)
if newevent if newevent
@@ -1718,9 +1718,9 @@ module Compiler
changed = true changed = true
end end
end end
if Time.now.to_i - t >= 5 if System.uptime - t >= 5
t += 5
Graphics.update Graphics.update
t = Time.now.to_i
end end
changed = true if check_counters(map, id, mapData) changed = true if check_counters(map, id, mapData)
if changed if changed