Alternitive Antilag
For the last week or so, I have been working with TheoAllen on his antilag script, mostly swapping ideas and code back and forth. Some of my ides and code made it into his script and some didn't, and while I was working on my own personal copy, he started added his "insane" optimizations, really trying to be able to support as many events as he could. I on the other hand, decided to try more for compatibility and speeding up sprites. Doesn't include the "insane" optimization for large numbers of events, so Theo's script is definitely faster when there are more events on the map, but mine might work better for people when there are fewer events or when there are compatibility issues, so I will post what I have so far here:
#------------------------------------------------------------------------------module Antilag_Config OPTIMIZE_EVENTS_XY = true OPTIMIZE_STARTING_EVENTS = true OPTIMIZE_SPRITES = trueend#------------------------------------------------------------------------------#------------------------------------------------------------------------------if Antilag_Config::OPTIMIZE_EVENTS_XY#------------------------------------------------------------------------------class MapTable def initialize @data = [] $game_map.width.times do |x| @data[x] = [] $game_map.height.times do |y| @data[x][y] = [] end end end def get(x,y) (@data[x] && @data[x][y]) || [] end def set(x,y,val) self.get(x,y) << val end def remove(x,y,val) return unless x && y data = self.get(x,y) @data.values.each do |xarray| xarray.each do |yarray| yarray.delete(val) end end unless data.delete(val) end endclass Game_Map attr_reader :table attr_reader :starting_events alias theo_antilag_setup_events setup_events def setup_events theo_antilag_setup_events setup_table end def setup_table @table = MapTable.new @events.each_value do |event| @table.set(event.x, event.y, event) end end def events_xy(x, y) @table.get(x,y) end def events_xy_nt(x, y) @table.get(x,y).select do |event| event.pos_nt?(x, y) end end endclass Game_Event alias theo_antilag_update update def update theo_antilag_update if @last_update_x != @x || @last_update_y != @y $game_map.table.remove(@last_update_x, @last_update_y, self) $game_map.table.set(x, y, self) end @last_update_x = @x @last_update_y = @y end end#------------------------------------------------------------------------------end # end of events_xy optimization#------------------------------------------------------------------------------#------------------------------------------------------------------------------if Antilag_Config::OPTIMIZE_STARTING_EVENTS#------------------------------------------------------------------------------class Game_Map attr_reader :starting_events alias theo_antilag_starting_setup_events setup_events def setup_events @starting_events = [] theo_antilag_starting_setup_events end def setup_starting_map_event event = @starting_events[0] event.clear_starting_flag if event if event # this just makes it compatible with Saba Kan's dungeon scripts. # as well as my scripts based on them. id = event.respond_to?(:event_id) ? event.event_id : event.id @interpreter.setup(event.list, id) end event end def any_event_starting? !@starting_events.empty? end endclass Game_Event alias theo_antilag_start start def start theo_antilag_start $game_map.starting_events << self if @starting end alias theo_antilag_clear_start clear_starting_flag def clear_starting_flag theo_antilag_clear_start $game_map.starting_events.delete(self) endend#------------------------------------------------------------------------------end # end of starting events optimization#------------------------------------------------------------------------------#------------------------------------------------------------------------------if Antilag_Config::OPTIMIZE_SPRITES#------------------------------------------------------------------------------module Cache #-------------------------------------------------------------------------- # * Create Empty Bitmap #-------------------------------------------------------------------------- def self.empty_bitmap @empty_bitmap ||= Bitmap.new(32, 32) endendclass Spriteset_Map #alias theo_antilag_update_characters update_characters def update_characters #theo_antilag_update_characters refresh_characters if @map_id != $game_map.map_id # replace all sprites with child sprites @character_sprites.map! do |sprite| sprite.update sprite.child_sprite || sprite end end endclass Sprite_Character attr_reader :child_sprite alias theo_antilag_update update def update unless (on_screen? && !invisible?) || keep_alive? unless self.disposed? #puts('"' +@character.character_name.to_s + '" sprite disposed.') @old_viewport = self.viewport self.dispose end return end if self.disposed? #puts('"' +@character.character_name.to_s + '" sprite reborn.') @child_sprite = Sprite_Character.new(@old_viewport, @character) @child_sprite.update end theo_antilag_update unless @child_sprite end def keep_alive? graphic_changed? || animation? || @balloon_sprite || @character.animation_id != 0 || @character.balloon_id != 0 end def invisible? @character.transparent || self.bitmap == Cache.empty_bitmap end def on_screen? w = Graphics.width h = Graphics.height @sx = @character.screen_x @sy = @character.screen_y cw = @cw || 32 ch = @ch || 32 @sx.between?(-cw,w+cw) && @sy.between?(0,h+ch) end #---------------------------------------------------------------------------- # Overwrite update position. # To limit screen_x and screen_y to be called many times #---------------------------------------------------------------------------- def update_position move_animation(@sx - x, @sy - y) self.x = @sx self.y = @sy self.z = @character.screen_z endend #------------------------------------------------------------------------------end # end of sprite optimization#------------------------------------------------------------------------------
You should probably turn off OPTIMIZE_EVENTS_XY for any pixel movement or ABS scripts but give it a try with it on! This is not meant to compete with Theo's script and is only meant for better compatibility and/or to possibly speed up maps with fewer events.

10 Comments
Recommended Comments