Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if true # << Make false to disable script, true to enable.
- #===============================================================================
- #
- # ☆ Dekita - Accurate FPS
- # -- Author : Dekita
- # -- Version : 1.0
- # -- Level : Very Easy
- # -- Requires : N/A
- # -- Engine : RPG Maker VX Ace.
- #
- #===============================================================================
- # ☆ Import
- #-------------------------------------------------------------------------------
- ($DEK||={})[:Real_FPS] = 1.0
- #===============================================================================
- # ☆ Updates
- #-------------------------------------------------------------------------------
- # D /M /Y
- # 22/1o/2o14 - Started, Finished,
- #===============================================================================
- # ☆ Introduction
- #-------------------------------------------------------------------------------
- # This script was written by DekitaRPG.
- #
- # The purpose of this script is to give the developer an accurate representation
- # of your frames per second.
- #
- # The default FPS counter (seen by pressing F2 in game) can be wildly inaccurate.
- #
- # IMO - the purpose of a frames per second display, is to show how many times
- # your frames are being refreshed each second.
- # For some reason, the F2 FPS counter is quite different from the actual
- # amount of updates the Graphics module processes each second.
- #
- # Simply pop the script in your game in a new script page and a small hud will
- # be displayed. The hud settings can be configured slightly in the Real_FPS
- # customization module.
- #
- # Along with showing you the real FPS rate, this script gives you an average
- # FPS rate and a total target rate, target rate shows you the percentage of
- # which your games FPS has been equal to the target FPS since the last average
- # FPS refresh occurred..
- #
- #===============================================================================
- # ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
- #===============================================================================
- # Please give credit to Dekita (or DekitaRPG). (requested, not required.)
- # Free to use for all projects (commercial / non commercial).
- #
- # Please do not repost this script on other sites - if you wish, you can
- # provide a link to the webpage below;
- # http://dekitarpg.wordpress.com/2014/10/22/accurate-fps/
- #
- #===============================================================================
- # ☆ Instructions
- #-------------------------------------------------------------------------------
- # Place Below " ▼ Materials " and Above " ▼ Main " in your script editor.
- #
- #===============================================================================
- # ☆ Script Calls
- #-------------------------------------------------------------------------------
- # Graphics.fps
- #--------------
- # This script call will return the value of the current fps.
- #
- #-------------------------------------------------------------------------------
- # Graphics.fps_average
- #----------------------
- # This script call will return a value equal to the average fps your game has
- # had since it began running.
- #
- #-------------------------------------------------------------------------------
- # Graphics.fps_target_rate
- #--------------------------
- # This script call will return a value equal to the percentage of time FPS
- # rate has been equal to the target FPS rate.
- #
- #===============================================================================
- # www.dekyde.com
- # www.dekitarpg.wordpress.com
- #===============================================================================
- module Real_FPS
- #===============================================================================
- #-----------------------------------------------------------------------------
- # // HUD Positioning
- #-----------------------------------------------------------------------------
- HUD_POS = { x: 4, y: 4, w: 90, h: 70 }
- #-----------------------------------------------------------------------------
- # // Draw FPS HUD Fade ?
- # Format = [ draw? , color a, color b]
- #-----------------------------------------------------------------------------
- Draw_Fade = [ true, Color.new(0,0,0,0), Color.new(0,0,0,128) ]
- #-----------------------------------------------------------------------------
- # // Seconds before Average resets.
- # format = [ use?, max_size ]
- # This is to ensure that the average array does not become excessive during
- # long gaming periods as this could cause additional processing times.
- # The data array is simply reduced by its furthest data entry if the array
- # size is above max_size. This only happens is use? = true.
- # NOTE: the array size would increase by 60 each minute of real time.
- # Therefore, if max_size is 60, the average counter will display the last
- # 1 minute of gameplays average FPS rate.
- #-----------------------------------------------------------------------------
- Average_Refresh = [ true , 300 ]
- #-----------------------------------------------------------------------------
- # // When HUD_Switch is not 0, the vaues will be used as the id of a
- # $game_switch to be used to determine wether to show the hud or not.
- #-----------------------------------------------------------------------------
- HUD_Switch = 0
- #-----------------------------------------------------------------------------
- # // Real_FPS.hud - Used to draw fps onto the fps hud (on screen).
- #-----------------------------------------------------------------------------
- def self.hud(hud,target_fps,fps,fps_average,fps_trg_rate)
- # // Shows Target FPS (generally 60)
- textA = "TRG: #{target_fps}"
- # // Shows Current FPS
- textB = "CUR: #{fps}"
- # // Shows Average FPS
- textC = "AVG: #{fps_average}"
- # // FPS Target Accuracy
- textD = "TOT: #{sprintf("%1.0f%",fps_trg_rate)}"
- # // The code below simply draws the text defined above onto the hud.
- hud.font.size = 16
- hud.draw_text(18,HUD_POS[:h]/4*0,HUD_POS[:w],HUD_POS[:h]/4,textA,0)
- hud.draw_text(18,HUD_POS[:h]/4*1,HUD_POS[:w],HUD_POS[:h]/4,textB,0)
- hud.draw_text(18,HUD_POS[:h]/4*2,HUD_POS[:w],HUD_POS[:h]/4,textC,0)
- hud.draw_text(18,HUD_POS[:h]/4*3,HUD_POS[:w],HUD_POS[:h]/4,textD,0)
- end
- #-----------------------------------------------------------------------------
- # [ end module ]
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- # // Customization Section Has Ceased.
- # // Only edit the code below if you are able to comprehend its processing.
- # // This is a precaution to ensure your sanity remains intact. :)
- #===============================================================================
- # www.dekyde.com
- # www.dekitarpg.wordpress.com
- #===============================================================================
- module Graphics
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Alias List
- #-----------------------------------------------------------------------------
- class << self
- alias :update_realfps :update
- end
- #-----------------------------------------------------------------------------
- # // Graphics.update
- #-----------------------------------------------------------------------------
- def update
- update_realfps
- update_fps
- end
- #-----------------------------------------------------------------------------
- # // Important Variables
- #-----------------------------------------------------------------------------
- @@fps_tsec = Time.new.sec
- @@fps_tsol = @@fps_tsec
- @@fps_insc = @@fps = 0
- @@fps_aver = Array.new << frame_rate
- #-----------------------------------------------------------------------------
- # // [ new ] Graphics.fps
- #-----------------------------------------------------------------------------
- def update_fps
- @@fps_insc += 1
- @@fps_tsec = Time.new.sec
- return unless @@fps_tsec != @@fps_tsol
- @@fps_tsol = @@fps_tsec
- @@fps = @@fps_insc
- update_average
- @@fps_insc = 0
- end
- #-----------------------------------------------------------------------------
- # // [ new ] Graphics.update_average
- #-----------------------------------------------------------------------------
- def update_average
- av = Real_FPS::Average_Refresh
- if av[0] && @@fps_aver.size > av[1]
- @@fps_aver.clear
- end
- @@fps_aver << @@fps
- end
- #-----------------------------------------------------------------------------
- # // [ new ] Graphics.fps_average
- #-----------------------------------------------------------------------------
- def fps_average
- @@fps_aver.inject(0) {|r,i| r += i } / @@fps_aver.size
- end
- #-----------------------------------------------------------------------------
- # // [ new ] Graphics.fps_target_rate
- #-----------------------------------------------------------------------------
- def fps_target_rate
- (fps_average.to_f / frame_rate) * 100
- end
- #-----------------------------------------------------------------------------
- # // [ new ] Graphics.fps
- #-----------------------------------------------------------------------------
- def fps; @@fps; end
- #-----------------------------------------------------------------------------
- # // Module Functions
- #-----------------------------------------------------------------------------
- module_function :update
- module_function :update_fps
- module_function :update_average
- module_function :fps_average
- module_function :fps_target_rate
- module_function :fps
- #-----------------------------------------------------------------------------
- # [ end module ]
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- class FPS_HUD
- #===============================================================================
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def initialize(viewport)
- @viewport = viewport
- init_headsupdisplay
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def init_headsupdisplay
- dispose
- @last_fps = Graphics.fps
- @target_fps = Graphics.frame_rate
- @main = Sprite.new(@viewport)
- @main.bitmap = Bitmap.new(Real_FPS::HUD_POS[:w],Real_FPS::HUD_POS[:h])
- @main.x = Real_FPS::HUD_POS[:x]
- @main.y = Real_FPS::HUD_POS[:y]
- @main.z = 201
- update
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def update
- return unless @main
- if Real_FPS::HUD_Switch != 0
- @main.visible = $game_switches[Real_FPS::HUD_Switch]
- end
- return unless @main.visible
- new_fps = Graphics.fps
- new_ave = Graphics.fps_average
- can_fps = @last_fps != new_fps
- can_ave = @last_ave != new_ave
- return unless can_fps || can_ave
- @main.bitmap.clear
- if Real_FPS::Draw_Fade[0]
- w = Real_FPS::HUD_POS[:w]/4
- h = Real_FPS::HUD_POS[:h]
- ca= Real_FPS::Draw_Fade[1]
- cb= Real_FPS::Draw_Fade[2]
- @main.bitmap.gradient_fill_rect(0,0,w,h,ca,cb)
- @main.bitmap.fill_rect(w,0,w*2,h,cb)
- @main.bitmap.gradient_fill_rect(w*3,0,w,h,cb,ca)
- end
- new_rte = Graphics.fps_target_rate
- Real_FPS.hud(@main.bitmap,@target_fps,new_fps,new_ave,new_rte)
- @last_fps = new_fps
- @last_ave = new_ave
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def dispose
- return unless @main
- @main.bitmap.dispose
- @main.dispose
- end
- #-----------------------------------------------------------------------------
- #
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- class Scene_Base
- #===============================================================================
- #-----------------------------------------------------------------------------
- # Aliased Methods
- #-----------------------------------------------------------------------------
- alias :init_fpshud :start
- alias :disp_fpshud :terminate
- alias :updt_fpshud :update
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def start
- init_fpshud
- strt_fps
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def strt_fps
- @fps_hud = FPS_HUD.new(@viewport)
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def terminate
- term_fps
- disp_fpshud
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def term_fps
- return unless @fps_hud
- @fps_hud.dispose
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def update
- updt_fps
- updt_fpshud
- end
- #-----------------------------------------------------------------------------
- # //
- #-----------------------------------------------------------------------------
- def updt_fps
- return unless @fps_hud
- @fps_hud.update
- end
- #-----------------------------------------------------------------------------
- # [ end class ]
- #-----------------------------------------------------------------------------
- end
- #===============================================================================
- # www.dekyde.com
- # www.dekitarpg.wordpress.com
- #===============================================================================
- end # if false / true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement