Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #=======================================================
  2. # Lune Ultimate Anti-Lag
  3. # Author: Raizen
  4. # Compatible with: RMVXAce
  5. # Comunity: centrorpg.com
  6. # This script allows a very well balanced anti-lag, in which
  7. # considers the own PC of the player, using a smart frame-skipper
  8. # to slow lags,
  9. #========================================================
  10.  
  11. #To update constantly the event, put a commentary on the first
  12. # command of the script written :update:
  13.  
  14. module Anti_conf
  15. #==============================================================================
  16. # ** Configurations
  17. #------------------------------------------------------------------------------
  18. # Configure what is necessary for a better performance.
  19. #==============================================================================
  20. # Choose how the script will act.
  21. # <=====Quality============================Performance=====>
  22. # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  23. # Default = 10
  24. Fr = 10
  25.  
  26. # Configure the FPS rate (default = 60)
  27. Fps = 60
  28. # Configure the minimum FPS rate (default = 25)
  29. Mini = 25
  30. # Quantity of frames the anti-lag will study,
  31. # the higher the time, the more precise the script,
  32. # but will take longer to load the anti-lag
  33. Time = 60
  34.  
  35. end
  36. =begin
  37.  
  38.  
  39.  
  40.  
  41. Functions on this Anti-Lag
  42.  
  43. * Common event positioning bug fixed
  44. * Smart Frame Skipper
  45. * updates what is only necessary
  46. * helps to lower lags from visual system/scripts
  47. * Changes its behavior according to the players PC
  48. * Increases the RPG Maker priority over other programs
  49.  
  50.  
  51. =end
  52.  
  53. #=================================================================#
  54. #=================================================================#
  55. #==================== Alias methods =============================#
  56. # command_203 => Game_Interpreter
  57. # start => Scene_Map
  58. # update => Scene_Map
  59. # perform_transfer => Scene_Map
  60. #=================================================================#
  61. #==================== Rewrite methods ===========================#
  62. # update_events => Game_Map
  63. # update_one_event => Spriteset_Map
  64. #=================================================================#
  65. #======================== New methods ===========================#
  66. # need_to_update? => Game_Event
  67. # near_the_screen? => Sprite_Character
  68. # call_position_event => Scene_Map
  69. # skip_calculate => Scene_Map
  70. # update_one_event => Spriteset_Map
  71. #=================================================================#
  72. #=================================================================#
  73.  
  74. #==============================================================================
  75. #============================ Início do Script! =============================
  76. #==============================================================================
  77. #==============================================================================
  78. # ** Scene_Map
  79. #------------------------------------------------------------------------------
  80. # Esta classe executa o processamento da tela de mapa.
  81. #==============================================================================
  82.  
  83. class Scene_Map < Scene_Base
  84. alias lune_skip_start start
  85. alias lune_skip_update update
  86. alias lune_perform perform_transfer
  87. #--------------------------------------------------------------------------
  88. # * Inicialização do processo
  89. #--------------------------------------------------------------------------
  90. def start
  91. Graphics.frame_rate = Anti_conf::Fps
  92. @update_skip = false
  93. @count_up = 0
  94. lune_skip_start
  95. end
  96. #--------------------------------------------------------------------------
  97. # * Execução da transferência
  98. #--------------------------------------------------------------------------
  99. def perform_transfer
  100. $get_new_ids = Array.new
  101. Graphics.frame_rate = Anti_conf::Fps
  102. lune_perform
  103. @count_up = 0
  104. @update_skip = false
  105. end
  106. #--------------------------------------------------------------------------
  107. # * Atualização da tela
  108. #--------------------------------------------------------------------------
  109. def update
  110. @update_skip ? lune_skip_update : skip_calculate
  111. end
  112. #--------------------------------------------------------------------------
  113. # * Atualização de um personagem especifico
  114. #--------------------------------------------------------------------------
  115. def call_position_event(id)
  116. @spriteset.update_one_event(id)
  117. end
  118. #--------------------------------------------------------------------------
  119. # * Calcula o tempo necessário para rodar o update do Scene_Map
  120. #--------------------------------------------------------------------------
  121. def skip_calculate
  122. @count_up += 1
  123. return unless @count_up >= Anti_conf::Time
  124. auto_skip = Time.now
  125. lune_skip_update
  126. old_skip = Time.now
  127. get_skip = old_skip - auto_skip
  128. Graphics.frame_rate -= (get_skip * Graphics.frame_rate * 2 * Anti_conf::Fr - 1).to_i
  129. Graphics.frame_rate = [Graphics.frame_rate, Anti_conf::Mini].max
  130. @update_skip = true
  131. end
  132. end
  133.  
  134.  
  135. #==============================================================================
  136. # ** Scene_Base
  137. #------------------------------------------------------------------------------
  138. # Esta é a superclasse de todas as cenas do jogo.
  139. #==============================================================================
  140. class Scene_Base
  141. alias skipper_main main
  142. #--------------------------------------------------------------------------
  143. # * Processamento principal
  144. #--------------------------------------------------------------------------
  145. def main
  146. @fr_cont = 0
  147. skipper_main
  148. end
  149. #--------------------------------------------------------------------------
  150. # * Execução da transição
  151. #--------------------------------------------------------------------------
  152. def perform_transition
  153. Graphics.transition(transition_speed * Graphics.frame_rate / 60)
  154. end
  155. #--------------------------------------------------------------------------
  156. # * Atualização da tela (básico)
  157. #--------------------------------------------------------------------------
  158. def update_basic
  159. if @fr_cont >= 60
  160. Graphics.update
  161. @fr_cont -= 60
  162. end
  163. @fr_cont += Graphics.frame_rate
  164. update_all_windows
  165. Input.update
  166. end
  167. end
  168.  
  169. #==============================================================================
  170. # ** Aumento da prioridade do rpg maker
  171. #------------------------------------------------------------------------------
  172. Lune_high = Win32API.new("kernel32", "SetPriorityClass", "pi", "i")
  173. Lune_high.call(-1, 0x90)
  174. #==============================================================================
  175.  
  176. #==============================================================================
  177. # ** Game_Event
  178. #------------------------------------------------------------------------------
  179. # Esta classe gerencia os eventos. Ela controla funções incluindo a mudança
  180. # de páginas de event por condições determinadas, e processos paralelos.
  181. # Esta classe é usada internamente pela classe Game_Map.
  182. #==============================================================================
  183.  
  184. class Game_Event < Game_Character
  185. #--------------------------------------------------------------------------
  186. # * necessário atualizar?
  187. #--------------------------------------------------------------------------
  188. def need_to_update?
  189. ax = $game_map.adjust_x(@real_x) - 8
  190. ay = $game_map.adjust_y(@real_y) - 6
  191. ax.between?(-9, 9) && ay.between?(-7, 7) || @list[0].parameters.include?(':update:')
  192. end
  193. end
  194.  
  195. #==============================================================================
  196. # ** Sprite_Character
  197. #------------------------------------------------------------------------------
  198. # Este sprite é usado para mostrar personagens. Ele observa uma instância
  199. # da classe Game_Character e automaticamente muda as condições do sprite.
  200. #==============================================================================
  201.  
  202. class Sprite_Character < Sprite_Base
  203. #--------------------------------------------------------------------------
  204. # * Evento próximo a tela?
  205. #--------------------------------------------------------------------------
  206. def near_the_screen?
  207. ax = $game_map.adjust_x(@character.x) - 8
  208. ay = $game_map.adjust_y(@character.y) - 6
  209. ax.between?(-11, 11) && ay.between?(-8, 8)
  210. end
  211. end
  212. #==============================================================================
  213. # ** Game_Event
  214. #------------------------------------------------------------------------------
  215. # Esta classe gerencia os eventos. Ela controla funções incluindo a mudança
  216. # de páginas de event por condições determinadas, e processos paralelos.
  217. # Esta classe é usada internamente pela classe Game_Map.
  218. #==============================================================================
  219.  
  220. class Game_Event < Game_Character
  221. alias lune_ant_initialize initialize
  222. #--------------------------------------------------------------------------
  223. # * Inicialização do objeto
  224. # event : RPG::Event
  225. #--------------------------------------------------------------------------
  226. def initialize(*args, &block)
  227. lune_ant_initialize(*args, &block)
  228. $get_new_ids.push(@event.id)
  229. end
  230. end
  231.  
  232. #==============================================================================
  233. # ** Game_Interpreter
  234. #------------------------------------------------------------------------------
  235. # Um interpretador para executar os comandos de evento. Esta classe é usada
  236. # internamente pelas classes Game_Map, Game_Troop e Game_Event.
  237. #==============================================================================
  238.  
  239. class Game_Interpreter
  240. alias lune_lag_command_203 command_203
  241. #--------------------------------------------------------------------------
  242. # Definir posição do evento
  243. #--------------------------------------------------------------------------
  244. def command_203
  245. lune_lag_command_203
  246. SceneManager.scene.call_position_event($get_new_ids.index(@event_id))
  247. end
  248. end
  249. #==============================================================================
  250. # ** Game_Map
  251. #------------------------------------------------------------------------------
  252. # Esta classe gerencia o mapa. Inclui funções de rolagem e definição de
  253. # passagens. A instância desta classe é referenciada por $game_map.
  254. #==============================================================================
  255.  
  256. class Game_Map
  257. #--------------------------------------------------------------------------
  258. # * Atualização dos comandos dos eventos
  259. #--------------------------------------------------------------------------
  260. def update_events
  261. @events.each_value {|event| event.update if event.need_to_update?}
  262. @common_events.each {|event| event.update}
  263. end
  264. end
  265.  
  266.  
  267. $get_new_ids = Array.new
  268. #==============================================================================
  269. # ** Spriteset_Map
  270. #------------------------------------------------------------------------------
  271. # Esta classe reune os sprites da tela de mapa e tilesets. Esta classe é
  272. # usada internamente pela classe Scene_Map.
  273. #==============================================================================
  274. class Spriteset_Map
  275. #--------------------------------------------------------------------------
  276. # * Atualização dos personagens
  277. #--------------------------------------------------------------------------
  278. def update_characters
  279. refresh_characters if @map_id != $game_map.map_id
  280. @character_sprites.each {|sprite| sprite.update if sprite.near_the_screen? }
  281. end
  282. #--------------------------------------------------------------------------
  283. # * Atualização de algum personagem remoto
  284. #--------------------------------------------------------------------------
  285. def update_one_event(id)
  286. @character_sprites[id].update
  287. end
  288. end