Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: LiTTleDRAgo on June 07, 2022, 09:55:37 pm

Title: [XP] Drago - Event Anti Lag
Post by: LiTTleDRAgo on June 07, 2022, 09:55:37 pm
Drago - Event Anti Lag
Authors: LiTTleDRAgo
Version: 1.01
Type: Type: Performance Improving System
Key Term: Game Utility

Introduction

What this script do is just dispose all event sprites that doesn't have graphics or outside the screen/viewport.
It doesn't prevent any event to be updated.

Well, I dunno if this script is enough to be called Anti-Lag.

Features


Screenshots

N/A

Script

Too lazy to put in the blog.
Spoiler: ShowHide
#==============================================================================
# ** Drago - Event Anti Lag
# Version : 1.01
# forum.chaos-project.com
#==============================================================================
($imported ||= {})[:drg_event_anti_lag] = 1.01
# =============================================================================
# NOTE:
# -----------------------------------------------------------------------------
# What this script do is just disposing all event sprites that doesn't have
# graphics or outside the .
# It doesn't prevent any event to be updated.
#
# =============================================================================

class Spriteset_Map
 
  $@ || alias_method(:"drg_antilag_init", :"initialize")
 
  def initialize(*args)
    drg_antilag_init(*args)
    replace_character_sprites
  end
 
  def replace_character_sprites
    @character_sprites.map! do |sprite|
      if sprite.is_a?(RPG::Sprite)
        Control_Sprite_Character.new(@viewport1,sprite)
      else
        sprite
      end
    end
  end
end

class Control_Sprite_Character
 
  attr_reader :character
  attr_accessor :disable_update, :force_update
 
  def initialize(viewport, char=nil)
    @viewport = viewport
    if char.is_a?(RPG::Sprite)
      @klass = (@sprite = char).class
      self.character = char.character
    else
      @klass = Sprite_Character
      self.character = char
    end
    @disable_update = false
    @force_update   = false
    update
  end
 
  def character=(char)
    @character = char
    @sprite.character = char unless @sprite.nil?
  end
 
  def allow_update?
    char = @character
    return true if @force_update
    return false if @disable_update || char.nil?
    condition =   char.character_name != ""
    condition ||= char.tile_id >= 384
    condition &&= in_screen?
    return condition
  end
 
  def in_screen?
    char = @character
    return false if char.nil? || @viewport.nil?
    vr = @viewport.rect
    screen_x = (dx=$game_map.display_x) - 4*32*4
    screen_width = dx + vr.width*4 + 4*32*4
    return false if char.real_x <= screen_x
    return false if char.real_x >= screen_width
    screen_y = (dy=$game_map.display_y) - 4*32*4
    screen_height = dy + vr.height*4 + 4*32*4
    return false if char.real_y <= screen_y
    return false if char.real_y >= screen_height
    return true
  end
 
  def is_event?
    return true if @character.is_a?(Game_Event)
    return false
  end
 
  def update
    if @character && ((is_event? && allow_update?) || !is_event?)
      @sprite = @klass.new(@viewport, @character) if disposed?
      @sprite.update
      if @sprite.bitmap && (is_event? && !allow_update?)
        dispose
      end
    else
      dispose
    end
  end
 
  def dispose
    @sprite.dispose unless disposed?
    @sprite = nil
  end
 
  def disposed?
    return true if !@sprite
    return @sprite.disposed?
  end
 
  def method_missing(sym, *a, &blk)
    @sprite.send(sym, *a, &blk) unless disposed?
  end
end


Instructions

Put below Scene_Debug

Compatibility

Modified Spriteset_Map#character_sprites
Anything that involved in this variable might need some adjustment.

Credits and Thanks


Author's Notes

No support, I already retired from RMXP.
Title: Re: [XP] Drago - Event Anti Lag
Post by: KK20 on June 07, 2022, 10:09:32 pm
Now that's a name I remember, glad to see you're still around 8)

For some reason I thought you already had made something like this. Is this just an old script you stumbled upon?
Title: Re: [XP] Drago - Event Anti Lag
Post by: LiTTleDRAgo on June 07, 2022, 10:45:44 pm
Yes, I just found this in my old project.
I thought it would be a waste to just be buried there.