Advertisement
Dekita

Untitled

Apr 19th, 2014
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.84 KB | None | 0 0
  1. if true # << Make true to use this script, false to disable.
  2. #===============================================================================
  3. #
  4. # ☆ $D13x - Simple Antilag
  5. # -- Author : Dekita
  6. # -- Version : 1.0
  7. # -- Level : Easy / Normal
  8. # -- Requires : N/A
  9. # -- Engine : RPG Maker VX Ace.
  10. #
  11. #===============================================================================
  12. # ☆ Import
  13. #-------------------------------------------------------------------------------
  14. $D13x={}if$D13x==nil
  15. $D13x[:Antilag]=true
  16. #===============================================================================
  17. # ☆ Updates
  18. #-------------------------------------------------------------------------------
  19. # D /M /Y
  20. # 29/o3/2o13 - Started, Finished,
  21. #
  22. #===============================================================================
  23. # ☆ Introduction
  24. #-------------------------------------------------------------------------------
  25. # This simple script slightly reduces lag caused by events.
  26. # It also stops animations from causing lag spikes when being played.
  27. #
  28. #===============================================================================
  29. # ★☆★☆★☆★☆★☆★☆★☆★ TERMS AND CONDITIONS: ☆★☆★☆★☆★☆★☆★☆★☆★☆
  30. #===============================================================================
  31. # 1. You MUST give credit to "Dekita" !!
  32. # 2. You are NOT allowed to repost this script.(or modified versions)
  33. # 3. You are NOT allowed to convert this script.
  34. # 4. You are NOT allowed to use this script for Commercial games.
  35. # 5. ENJOY!
  36. #
  37. # "FINE PRINT"
  38. # By using this script you hereby agree to the above terms and conditions,
  39. # if any violation of the above terms occurs "legal action" may be taken.
  40. # Not understanding the above terms and conditions does NOT mean that
  41. # they do not apply to you.
  42. # If you wish to discuss the terms and conditions in further detail you can
  43. # contact me at http://dekitarpg.wordpress.com/
  44. #
  45. #===============================================================================
  46. # ☆ Instructions
  47. #-------------------------------------------------------------------------------
  48. # Place Below " ▼ Materials " and Above " ▼ Main " in your script editor.
  49. #
  50. #===============================================================================
  51. # ☆ Script Calls
  52. #-------------------------------------------------------------------------------
  53. # $game_system.anti_lag = Boolean
  54. # ^- Event anti Lag
  55. #
  56. # $game_system.anti_lag_ani = Boolean
  57. # ^- Animation anti Lag
  58. #
  59. #===============================================================================
  60. # ☆ Notetags ( default )
  61. #-------------------------------------------------------------------------------
  62. # N/A
  63. #
  64. #===============================================================================
  65. # ☆ HELP
  66. #-------------------------------------------------------------------------------
  67. # N/A
  68. #
  69. #===============================================================================
  70. module Anti_Lag
  71. #===============================================================================
  72. #-----------------------------------------------------------------------------
  73. # Out Of Screen Update Range
  74. #-----------------------------------------------------------------------------
  75. Event_Update_Range = 3
  76. #-----------------------------------------------------------------------------
  77. # Event Antilag
  78. #-----------------------------------------------------------------------------
  79. Event_Anti_Lag_On = true
  80. #-----------------------------------------------------------------------------
  81. # Animation Antilag
  82. #-----------------------------------------------------------------------------
  83. Anima_Anti_lag_On = true
  84. #####################
  85. # CUSTOMISATION END #
  86. end #####################
  87. #☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#
  88. # #
  89. # http://dekitarpg.wordpress.com/ #
  90. # #
  91. #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#
  92. #===============================================================================#
  93. # ARE YOU MODIFYING BEYOND THIS POINT? \.\. #
  94. # YES?\.\. #
  95. # OMG, REALLY? \| #
  96. # WELL SLAP MY FACE AND CALL ME A DRAGONITE.\..\.. #
  97. # I REALLY DIDN'T THINK YOU HAD IT IN YOU.\..\.. #
  98. #===============================================================================#
  99. module SceneManager
  100. #===============================================================================
  101. #-----------------------------------------------------------------------------
  102. # Alias List
  103. #-----------------------------------------------------------------------------
  104. class << self
  105. alias :call_antilag :call
  106. alias :goto_antilag :goto
  107. end
  108. #-----------------------------------------------------------------------------
  109. # Call Scene
  110. #-----------------------------------------------------------------------------
  111. def self.call(scene_class)
  112. call_antilag(scene_class)
  113. dispose_ani_crap
  114. end
  115. #-----------------------------------------------------------------------------
  116. # Goto Scene
  117. #-----------------------------------------------------------------------------
  118. def self.goto(scene_class)
  119. goto_antilag(scene_class)
  120. dispose_ani_crap
  121. end
  122. #-----------------------------------------------------------------------------
  123. # Dispose Ani Crap
  124. #-----------------------------------------------------------------------------
  125. def self.dispose_ani_crap
  126. return if $game_temp.ani_crap == nil
  127. $game_temp.ani_crap.each do |ani|
  128. ani.dispose
  129. end
  130. $game_temp.ani_crap = nil
  131. end
  132. end
  133. #===============================================================================
  134. class Game_Temp
  135. #===============================================================================
  136. #-----------------------------------------------------------------------------
  137. # Alias List
  138. #-----------------------------------------------------------------------------
  139. alias :init_abs_antilag :initialize
  140. #-----------------------------------------------------------------------------
  141. # Pi Variables
  142. #-----------------------------------------------------------------------------
  143. attr_accessor :ani_crap
  144. #-----------------------------------------------------------------------------
  145. # Initialize
  146. #-----------------------------------------------------------------------------
  147. def initialize
  148. @ani_crap = []
  149. init_abs_antilag
  150. end
  151. end
  152. #===============================================================================
  153. class Game_System
  154. #===============================================================================
  155. #-----------------------------------------------------------------------------
  156. # Pi Variables
  157. #-----------------------------------------------------------------------------
  158. attr_accessor :anti_lag
  159. attr_accessor :anti_lag_ani
  160. #-----------------------------------------------------------------------------
  161. # Alias List
  162. #-----------------------------------------------------------------------------
  163. alias :initantilag :initialize
  164. #-----------------------------------------------------------------------------
  165. # Initialize
  166. #-----------------------------------------------------------------------------
  167. def initialize
  168. @anti_lag = Anti_Lag::Event_Anti_Lag_On
  169. @anti_lag_ani = Anti_Lag::Anima_Anti_lag_On
  170. initantilag
  171. end
  172. end
  173. #===============================================================================
  174. class Game_Map
  175. #===============================================================================
  176. #-----------------------------------------------------------------------------
  177. # Alias List
  178. #-----------------------------------------------------------------------------
  179. alias :setup_de_antilag :setup
  180. #-----------------------------------------------------------------------------
  181. # Setup
  182. #-----------------------------------------------------------------------------
  183. def setup(map_id)
  184. SceneManager.dispose_ani_crap
  185. setup_de_antilag(map_id)
  186. end
  187. end
  188. #===============================================================================
  189. class Game_Event < Game_Character
  190. #===============================================================================
  191. #-----------------------------------------------------------------------------
  192. # Pi Variables
  193. #-----------------------------------------------------------------------------
  194. attr_reader :can_update
  195. #-----------------------------------------------------------------------------
  196. # Alias List
  197. #-----------------------------------------------------------------------------
  198. alias :anti_lag_init_GE :initialize
  199. alias :updt_anti_lag :update
  200. #-----------------------------------------------------------------------------
  201. # Initialize
  202. #-----------------------------------------------------------------------------
  203. def initialize(map_id, event)
  204. @can_anti_lag = $game_system.anti_lag
  205. @can_update = true
  206. if $game_map.loop_horizontal? or $game_map.loop_vertical?
  207. @can_anti_lag = false
  208. end
  209. anti_lag_init_GE(map_id, event)
  210. end
  211. #-----------------------------------------------------------------------------
  212. # Update
  213. #-----------------------------------------------------------------------------
  214. def update
  215. update_anti_lag
  216. return unless @can_update
  217. updt_anti_lag
  218. end
  219. #-----------------------------------------------------------------------------
  220. # Update Anti Lag
  221. #-----------------------------------------------------------------------------
  222. def update_anti_lag
  223. if @can_anti_lag != $game_system.anti_lag
  224. @can_anti_lag = $game_system.anti_lag
  225. if $game_map.loop_horizontal? or $game_map.loop_vertical?
  226. @can_anti_lag = false
  227. end
  228. end
  229. event_is_on_screen?
  230. end
  231. #-----------------------------------------------------------------------------
  232. # Event Is On Screen ?
  233. #-----------------------------------------------------------------------------
  234. def event_is_on_screen?
  235. return unless @can_anti_lag
  236. w = Graphics.width / 32
  237. h = Graphics.height / 32
  238. @can_update = false
  239. os = Anti_Lag::Event_Update_Range
  240. px = ($game_map.display_x).truncate
  241. py = ($game_map.display_y).truncate
  242. dx = @x - px
  243. dy = @y - py
  244. if dx.between?(0-os,w+os) && dy.between?(0-os,h+os)
  245. @can_update = true
  246. end
  247. end
  248. end
  249. #===============================================================================
  250. class Sprite_Base < Sprite
  251. #===============================================================================
  252. #-----------------------------------------------------------------------------
  253. # Alias List
  254. #-----------------------------------------------------------------------------
  255. alias :dispose_antilagani :dispose_animation
  256. #-----------------------------------------------------------------------------
  257. # Dispose Animation
  258. #-----------------------------------------------------------------------------
  259. def dispose_animation
  260. if $game_system.anti_lag_ani
  261. make_ani_into_crap
  262. return
  263. end
  264. dispose_antilagani
  265. end
  266. #-----------------------------------------------------------------------------
  267. # Make Animation Garbage
  268. #-----------------------------------------------------------------------------
  269. def make_ani_into_crap
  270. $game_temp.ani_crap = [] if $game_temp.ani_crap == nil
  271. if @ani_bitmap1
  272. @@_reference_count[@ani_bitmap1] -= 1
  273. if @@_reference_count[@ani_bitmap1] == 0
  274. $game_temp.ani_crap << @ani_bitmap1
  275. end
  276. end
  277. if @ani_bitmap2
  278. @@_reference_count[@ani_bitmap2] -= 1
  279. if @@_reference_count[@ani_bitmap2] == 0
  280. $game_temp.ani_crap << @ani_bitmap2
  281. end
  282. end
  283. if @ani_sprites
  284. @ani_sprites.each {|sprite| sprite.dispose }
  285. @ani_sprites = nil
  286. @animation = nil
  287. end
  288. @ani_bitmap1 = nil
  289. @ani_bitmap2 = nil
  290. end
  291. end
  292. #===============================================================================
  293. class Sprite_Character < Sprite_Base
  294. #===============================================================================
  295. #-----------------------------------------------------------------------------
  296. # Alias List
  297. #-----------------------------------------------------------------------------
  298. alias :anti_lag_update :update
  299. #-----------------------------------------------------------------------------
  300. # Update
  301. #-----------------------------------------------------------------------------
  302. def update
  303. if $game_system.anti_lag and @character.is_a?(Game_Event)
  304. check_can_update_sprite
  305. return unless self.visible
  306. end
  307. anti_lag_update
  308. end
  309. #-----------------------------------------------------------------------------
  310. # Update
  311. #-----------------------------------------------------------------------------
  312. def check_can_update_sprite
  313. if self.visible and !@character.can_update
  314. reset_sprite_animation
  315. end
  316. self.visible = @character.can_update
  317. end
  318. #-----------------------------------------------------------------------------
  319. # Reset Sprite Animation
  320. #-----------------------------------------------------------------------------
  321. def reset_sprite_animation
  322. dispose_animation
  323. end
  324. end
  325. #===============================================================================
  326. class Scene_Base
  327. #===============================================================================
  328. #-----------------------------------------------------------------------------
  329. # Alias List
  330. #-----------------------------------------------------------------------------
  331. alias :term_antilag :terminate
  332. #-----------------------------------------------------------------------------
  333. # Terminate
  334. #-----------------------------------------------------------------------------
  335. def terminate
  336. term_antilag
  337. SceneManager.dispose_ani_crap
  338. end
  339. end
  340. #==============================================================================#
  341. # http://dekitarpg.wordpress.com/ #
  342. #==============================================================================#
  343. end # if true # << Make true to use this script, false to disable.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement