Jump to content
  • entries
  • comments
  • views

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.


Recommended Comments

Cool beans.  Good to have two people with different angles but still helping each other on the same idea.


I haven't run into lag issues yet, I guess I keep my sprites and events low enough?

Share this comment

Link to comment

Hey there, you responded to me in Theo's Insane Anti-Lag thread a few days back, I didn't see your further suggestion until now, ^^;

So I tried setting both OPTIMIZE_EVENTS_XY and OPTIMIZE_STARTING_EVENTS, and placing the script both under and on top of my pixel/ABS script, and on top of every script and below every script, but I keep getting the same error whether starting a new game or continuing a save:

Script 'Sprite Character' line 93: RGSSError occurred.
disposed bitmap

Any idea on what could be going on? I'm more than happy to provide anymore info if you need it~

Share this comment

Link to comment

I guess it could be possible the pixel/ABS script messes around for how sprites are updated for some reason? Maybe it calls the bitmap update because it has to know the proper size of the sprite. I really can't help much, pixel and ABS scripts are a crapshoot in the first place. You are better off talking to whoever made your pixel movement/ABS script and asking them about lag I guess. :(

Share this comment

Link to comment