Animated HP/MP Gauge script causing lag.

Status
Not open for further replies.

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
So the script OC ANIMATED GAUGES (Ace) has been known in my previous thread, in another section, to cause me massive amounts of lag in my project. It caps my FPS to 30 in battles and makes it fall less than that, instead of keeping it the default 60 FPS. (actual FPS 50-60)  This script is 100% the culprit, and I want to know the following:

  • Why does it happen? (the major FPS lag / 30 cap)
  • How can it be fixed?
  • If it cannot, are there any alternative scripts out there that are better with the same goal? (which I wil google search for myself as well tomorrow, but recommendations are nice too. :p  )
Code:
# *****************************************************************************## OC ANIMATED GAUGES# Author: Ocedic# Site: [URL="http://ocedic.wordpress.com/#"]http://ocedic.wordpress.com/#[/URL] Version: 1.3b# Last Updated: 3/16/13## Updates:# 1.3b - Rate methods are now aliased# 1.3  - Now updates every two frames instead of every frame, update rate for#        specific bars can be set# 1.2  - Fixed a bug that prevented HP/MP comparison conditionals from#        functioning correctly# 1.1  - Rate change now works properly, added configuration option to disable#        animation for specific bars# 1.0  - First release## ***************************************************************************** $imported = {} if $imported.nil?$imported["OC-AnimatedGauges"] = true #==============================================================================# ▼ Introduction# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# This script changes HP, MP and TP gauges to have a gradual adjustment rather# than the default instantaneous feedback.#==============================================================================# ▼ Instructions# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# Plug and play script. Simply paste it above Main. Settings can be adjusted# in configuration section.#==============================================================================# ▼ Compatibility# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# This script is designed to work for the Default Battle System and Yanfly's# Battle Engine/Core Engine. Other custom gauge and battle systems may not be# compatible.#==============================================================================# ▼ Terms of Use# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# Can be freely used and modified in non-commercial projects. Proper attribution# must be given to Ocedic, and this header must be preserved.# For commercial terms, see here: [URL="https://ocedic.wordpress.com/terms-of-use/#=============================================================================="]https://ocedic.wordpress.com/terms-of-use/#==============================================================================[/URL] #==============================================================================# ■ Configuration#------------------------------------------------------------------------------#  Change customizable settings here#==============================================================================module OC  module GAUGE   #==============================================================================# * Enable Rates *#------------------------------------------------------------------------------#   This allows you to turn off animated gauges for any of the supported bars.#   To disable bar animation, simply set the corresponding switch to false.#==============================================================================     ENABLE_HP_RATE = true    ENABLE_MP_RATE = true    ENABLE_TP_RATE = false #==============================================================================# * Rate Change *#------------------------------------------------------------------------------#   Sets how much the gauge will change in each frame for each gauge type,#   denoted in %.#==============================================================================# * Max TP *#------------------------------------------------------------------------------#   Input the max TP here if you use a custom value for max TP.#==============================================================================    RATE_CHANGE_HP = 0.03    # Default 0.03    RATE_CHANGE_MP = 0.01    # Default 0.01    RATE_CHANGE_TP = 0.02    # Default 0.02    MAX_TP = 100             # Default 100   end # BATTLEend #OC #==============================================================================# ■ End of Configuration#============================================================================== #==============================================================================# ■ Game_BattlerBase#==============================================================================class Game_BattlerBase #==============================================================================# * Accessors *#==============================================================================  attr_accessor :current_hp_rate                  attr_accessor :current_mp_rate                attr_accessor :current_tp_rate #==============================================================================# * Alias: Initialize *#==============================================================================  alias oc_game_battlerbase_initialize_nl2d9s initialize  def initialize    oc_game_battlerbase_initialize_nl2d9s    @current_hp_rate = 1.0    @current_mp_rate = 1.0    @current_tp_rate = 1.0  end     end #class game_battlerbase #==============================================================================# ■ Game_Actor#==============================================================================class Game_Actor < Game_Battler #==============================================================================# * Alias: HP Rate *#==============================================================================  alias oc_game_actor_hp_rate_n43ps hp_rate  def hp_rate    if OC::GAUGE::ENABLE_HP_RATE && SceneManager.scene_is?(Scene_Battle)      rate_diff = @hp.to_f / mhp - @current_hp_rate      if rate_diff > 0        @current_hp_rate += [OC::GAUGE::RATE_CHANGE_HP, rate_diff.abs / 5].min      elsif rate_diff < 0        @current_hp_rate -= [OC::GAUGE::RATE_CHANGE_HP, rate_diff.abs / 5].min      end      @current_hp_rate    else      oc_game_actor_hp_rate_n43ps    end  end #==============================================================================# * Alias: MP Rate *#==============================================================================  alias oc_game_actor_mp_rate_a02sf mp_rate  def mp_rate    if OC::GAUGE::ENABLE_MP_RATE && SceneManager.scene_is?(Scene_Battle)      return 0 if mmp == 0      rate_diff = @mp.to_f / mmp - @current_mp_rate      if rate_diff > 0        @current_mp_rate += [OC::GAUGE::RATE_CHANGE_MP, rate_diff.abs / 5].min      elsif rate_diff < 0        @current_mp_rate -= [OC::GAUGE::RATE_CHANGE_MP, rate_diff.abs / 5].min      end      @current_mp_rate    else      oc_game_actor_mp_rate_a02sf    end  end   #==============================================================================# * Alias: TP Rate *#==============================================================================  alias oc_game_actor_tp_rate_03ldn tp_rate  def tp_rate    if OC::GAUGE::ENABLE_TP_RATE && SceneManager.scene_is?(Scene_Battle)      rate_diff = @tp.to_f / OC::GAUGE::MAX_TP - @current_tp_rate      if rate_diff > 0        @current_tp_rate += [OC::GAUGE::RATE_CHANGE_TP, rate_diff.abs / 5].min      elsif rate_diff < 0        @current_tp_rate -= [OC::GAUGE::RATE_CHANGE_TP, rate_diff.abs / 5].min      end      @current_tp_rate    else      oc_game_actor_tp_rate_03ldn    end  end   end #class game_actor #==============================================================================# ■ Window_BattleStatus#============================================================================== class Window_BattleStatus < Window_Selectable #==============================================================================# * New Method: Refresh Gauges *#------------------------------------------------------------------------------#   Updates the HP, MP and TP bars of Yanfly's Battle Status. This part is#   isolated from the rest of Draw_Item in order to reduce lag by not having#   to draw actor graphics every update#==============================================================================    def refresh_gauges    i = 0    $game_party.battle_members.each do |member|      rectwidth = contents.width / $game_party.max_battle_members      rectx = i * rectwidth      draw_actor_hp(member, rectx+2, line_height*2+11, rectwidth-4)      if draw_tp?(member) && draw_mp?(member)        dw = rectwidth/2-2        dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE        draw_actor_tp(member, rectx+2, line_height*3, dw)        dw = rectwidth - rectwidth/2 - 2        draw_actor_mp(member, rectx+rectwidth/2, line_height*3, dw)      elsif draw_tp?(member) && !draw_mp?(member)        draw_actor_tp(member, rectx+2, line_height*3, rectwidth-4)      else        draw_actor_mp(member, rectx+2, line_height*3, rectwidth-4)      end      i += 1    end      end end #class window_battlestatus #==============================================================================# ■ Scene_Battle#==============================================================================class Scene_Battle < Scene_Base #==============================================================================# * Alias: Start *#==============================================================================  alias oc_scene_battle_start_3njs9 start  def start    oc_scene_battle_start_3njs9    $game_party.battle_members.each do |actor|      actor.current_hp_rate = actor.hp.to_f / actor.mhp      actor.current_mp_rate = actor.mp.to_f / actor.mmp      actor.current_tp_rate = actor.tp.to_f / OC::GAUGE::MAX_TP    end  end #==============================================================================# * Alias: Update Basic *#==============================================================================  alias oc_scene_battle_update_vj902 update_basic  def update_basic    oc_scene_battle_update_vj902    @update_timer ||= 0    @update_timer += 1    return if @update_timer % 2 != 0    if $imported["YEA-BattleEngine"]      @status_window.refresh_gauges    else      @status_window.refresh    end  end end #class scene_battle
 
Last edited by a moderator:

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
Well, the script is redrawing every bar every other frame, which can take a bit of a toll. By itself it should not cut FPS by the numbers you are reporting, though. If the mentioned Yanfly script is installed, it does do a complete refresh of the window, which would be a bit more intensive. A couple things that might reduce the lag would be to only redraw bars when they need to be redrawn, and to stagger the redrawing of the bars so that only one bar would be redrawn on any given frame but both would require some restructuring of the script.


One quick thing you could try is to decrease the redraw rate. Toward the end there is this line:

Code:
return if @update_timer % 2 != 0
Replacing the 2 with a higher number will decrease the rate of the refresh and might alleviate some of the lag. 2 means once every 2 frames, 3 means once every 3 frames, etc, so a 4 here would still be refreshing the bars 15 times per second, which should be enough for visuals but significantly reduce the load.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Do you have a link to your previous thread?
 

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
@Shaz my previous thread just led into finding this out, so it's irrelevant.

@Mithran that seemed to do the trick! I can now use the script without any lag and keeping enough visual aesthetics. Thanks for explaining it to me as well.

This thread can be closed.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,047
Members
137,569
Latest member
Shtelsky
Top