Sign in to follow this  
Followers 0
Fegarur

[RMVX] Anti-lag

6 posts in this topic

Descripción:
Script creado por PR Coders para reducir el lag (retraso) que se pueda causar en juegos creados con RMVX.

Script:
[SPOILER]
CODE
###############################################################################
############################# PR Coders - AntiLag #############################
###############################################################################
#==============================================================================
# AntiLag del grupo PR Coders.
# Solamente copiar y usar
#==============================================================================

# Añade el script AntiLag a la base de datos de PR Coders
$PRCoders ||= {}
# Habilita o script, para desabilitar deixe false
$PRCoders["AntiLag"] = true

if $PRCoders["AntiLag"]

#==============================================================================
# AntiLag
#==============================================================================

module AntiLag
 
 SPC = Win32API.new("kernel32", "SetPriorityClass", "pi", "i")
 # ¿Ejecutar el juego en Prioridad Alta?
 @@high_priority = true
 # ¿Usar el AntiLag de eventos?
 @@event = true
 
 if @@high_priority
   SPC.call(-1, 0x80)
 else
   SPC.call(-1, 0x20)
 end
 @@cache = {}
 
 #--------------------------------------------------------------------------
 # ¿Prioridad Alta?
 #--------------------------------------------------------------------------
 
 def self.high_priority?
   return @@high_priority
 end
 
 #--------------------------------------------------------------------------
 # Prioridad Alta
 #--------------------------------------------------------------------------
 
 def self.high_priority
   return @@high_priority
 end
 
 #--------------------------------------------------------------------------
 # ¿AntiLag de Evento?
 #--------------------------------------------------------------------------
 
 def self.event?
   return @@event
 end
 
 #--------------------------------------------------------------------------
 # AntiLag de Evento
 #--------------------------------------------------------------------------
 
 def self.event
   return @@event
 end
 
 #--------------------------------------------------------------------------
 # AntiLag de Evento = (true / false)
 #--------------------------------------------------------------------------
 
 def self.event=(valor)
   if valor
     @@event = true
   else
     @@event = false
   end
 end
 
 #--------------------------------------------------------------------------
 # Prioridad Alta = (true / false)
 #--------------------------------------------------------------------------
 
 def self.high_priority=(valor)
   return if @@high_priority == valor
   if valor
     @@high_priority = true
     SPC.call(-1, 0x80)
     return
   end
   @@high_priority = false
   SPC.call(-1, 0x20)
 end
 
 #--------------------------------------------------------------------------
 # Largo de Bitmap
 #--------------------------------------------------------------------------
 
 def self.bitmap_width(character_name)
   if @@cache[character_name].nil?
     bitmap = Cache.character(character_name)
     sign = character_name[/^[\!\$]./]
     if sign != nil and sign.include?('$')
       cw = bitmap.width / 3
       ch = bitmap.height / 4
     else
       cw = bitmap.width / 12
       ch = bitmap.height / 8
     end
     @@cache[character_name] = [cw, ch]
   end
   return @@cache[character_name][0]
 end
 
 #--------------------------------------------------------------------------
 # Altura de Bitmap
 #--------------------------------------------------------------------------
 
 def self.bitmap_height(character_name)
   if @@cache[character_name].nil?
     bitmap = Cache.character(character_name)
     sign = character_name[/^[\!\$]./]
     if sign != nil and sign.include?('$')
       cw = bitmap.width / 3
       ch = bitmap.height / 4
     else
       cw = bitmap.width / 12
       ch = bitmap.height / 8
     end
     @@cache[character_name] = [cw, ch]
   end
   return @@cache[character_name][1]
 end
 
 
end

#==============================================================================
# Game_Character
#==============================================================================

class Game_Character
 
 #--------------------------------------------------------------------------
 # Verifica si está en pantalla (Coordenada X)?
 #--------------------------------------------------------------------------
 
 def in_screen_x?(add_x=0)
   ax = @x * 256
   min_ax = ax
   max_ax = ax
   if add_x > 0
     min_ax = ax - add_x / 2
     max_ax = ax + add_x / 2
   end
   if $game_map.loop_horizontal?
     if $game_map.display_x > ($game_map.width - 17) * 256
       w = ($game_map.width * 256)
       min_x = ($game_map.display_x - 2 * 256) % w
       max_x = ($game_map.display_x + 19 * 256) % w
       if max_x == 0
         max_x = w
       end
       if min_ax > min_x
         return true
       end
       if max_ax < max_x
         return true
       end
       return false
     end
   end
   return false if (min_ax < $game_map.display_x - 2 * 256)
   return false if (max_ax > $game_map.display_x + 19 * 256)
   return true
 end
 
 #--------------------------------------------------------------------------
 # Verifica si está en pantalla (Coordenada Y)?
 #--------------------------------------------------------------------------
 
 def in_screen_y?(add_y=0)
   ay = @y * 256
   min_ay = ay
   max_ay = ay
   if add_y > 0
     min_ay = ay - add_y
   end
   if $game_map.loop_vertical?
     if $game_map.display_y > ($game_map.height - 13) * 256
       h = ($game_map.height * 256)
       min_y = ($game_map.display_y - 2 * 256) % h
       max_y = ($game_map.display_y + 15 * 256) % h
       if max_y == 0
         max_y = h
       end
       if min_ay > min_y
         return true
       end
       if max_ay < max_y
         return true
       end
       return false
     end
   end
   return false if (min_ay < $game_map.display_y - 2 * 256)
   return false if (max_ay > $game_map.display_y + 15 * 256)
   return true
 end
 
 #--------------------------------------------------------------------------
 # ¿Está en pantalla?
 #--------------------------------------------------------------------------
 
 def in_screen?(add_x=0, add_y=0)
   return false unless in_screen_x?(add_x)
   return false unless in_screen_y?(add_y)
   return true
 end
 
 #--------------------------------------------------------------------------
 # Verifica si colisiona con algún evento
 #--------------------------------------------------------------------------
 
 def collide_with_screen_characters?(x, y)
   for event in $game_map.screen_events_xy(x, y)   # ??????????
     unless event.through                          # ???? OFF?
       return true if self.is_a?(Game_Event)       # ???????
       return true if event.priority_type == 1     # ????????
     end
   end
   if @priority_type == 1                          # ????????
     return true if $game_player.pos_nt?(x, y)     # ???????????
     return true if $game_map.boat.pos_nt?(x, y)   # ?????????
     return true if $game_map.ship.pos_nt?(x, y)   # ?????????
   end
   return false
 end
 
 #--------------------------------------------------------------------------
 # Verifica si es atravesable
 #--------------------------------------------------------------------------
 
 def passable?(x, y)
   x = $game_map.round_x(x)                    
   y = $game_map.round_y(y)                  
   return false unless $game_map.valid?(x, y)
   return true if @through or debug_through?
   return false unless map_passable?(x, y)
   if self.in_screen?
     return false if collide_with_screen_characters?(x, y)
   else
     return false if collide_with_characters?(x, y)
   end
   return true                                    
 end
 
end

#==============================================================================
# Game_Player
#==============================================================================

class Game_Player < Game_Character
 
 #--------------------------------------------------------------------------
 # Verifica si hay eventos en el héroe
 #--------------------------------------------------------------------------
 
 def check_event_trigger_here(triggers)
   return false if $game_map.interpreter.running?
   result = false
   for event in $game_map.screen_events_xy(@x, @y)
     if triggers.include?(event.trigger) and event.priority_type != 1
       event.start
       result = true if event.starting
     end
   end
   return result
 end
 
 #--------------------------------------------------------------------------
 # Verifica si hay eventon en frente del héroe
 #--------------------------------------------------------------------------
 
 def check_event_trigger_there(triggers)
   return false if $game_map.interpreter.running?
   result = false
   front_x = $game_map.x_with_direction(@x, @direction)
   front_y = $game_map.y_with_direction(@y, @direction)
   for event in $game_map.screen_events_xy(front_x, front_y)
     if triggers.include?(event.trigger) and event.priority_type == 1
       event.start
       result = true
     end
   end
   if result == false and $game_map.counter?(front_x, front_y)
     front_x = $game_map.x_with_direction(front_x, @direction)
     front_y = $game_map.y_with_direction(front_y, @direction)
     for event in $game_map.screen_events_xy(front_x, front_y)
       if triggers.include?(event.trigger) and event.priority_type == 1
         event.start
         result = true
       end
     end
   end
   return result
 end
 
 #--------------------------------------------------------------------------
 # Verifica si hay eventos en posición X, Y
 #--------------------------------------------------------------------------
 
 def check_event_trigger_touch(x, y)
   return false if $game_map.interpreter.running?
   result = false
   for event in $game_map.screen_events_xy(x, y)
     if [1,2].include?(event.trigger) and event.priority_type == 1
       event.start
       result = true
     end
   end
   return result
 end

end

#==============================================================================
# Game_Event
#==============================================================================

class Game_Event < Game_Character
 
 #--------------------------------------------------------------------------
 # alias
 #--------------------------------------------------------------------------
 
 alias pr_coders_antilag_game_event_setup setup
 
 #--------------------------------------------------------------------------
 # ¿En pantalla?
 #--------------------------------------------------------------------------
 
 def in_screen?(*args)
   return true if @antilag_always_update
   if @large_bitmap
     return super(AntiLag.bitmap_width(@character_name), AntiLag.bitmap_height(@character_name))
   end
   return super
 end
 
 #--------------------------------------------------------------------------
 # Define una nueva página de evento
 #--------------------------------------------------------------------------
 
 def setup(new_page)
   pr_coders_antilag_game_event_setup(new_page)
   @large_bitmap = false
   @antilag_always_update = false
   @antilag_always_update |= (not AntiLag.event?)
   @antilag_always_update |= [3, 4].include?(@trigger)
   return if @list.nil?
   for item in @list
     if item.code == 108 or item.code == 408
       case item.parameters[0].downcase
       when "always_update"
         @antilag_always_update |= true
       when "large_bitmap"
         @large_bitmap = true
       end
     end
   end
 end
 
end

#==============================================================================
# Game_Map
#==============================================================================

class Game_Map
 
 attr_reader :screen_events
 
 #--------------------------------------------------------------------------
 # alias
 #--------------------------------------------------------------------------
 
 alias pr_coders_antilag_game_map_setup_events setup_events
 
 #--------------------------------------------------------------------------
 # Crear los eventos
 #--------------------------------------------------------------------------
 
 def setup_events
   @screen_events = {}
   pr_coders_antilag_game_map_setup_events
 end
 
 #--------------------------------------------------------------------------
 # Verifica si es atravesable
 #--------------------------------------------------------------------------
 
 def passable?(x, y, flag = 0x01)
   for event in screen_events_xy(x, y)            # ???????????????
     next if event.tile_id == 0            # ??????????????
     next if event.priority_type > 0       # [???????] ????
     next if event.through                 # ??????
     pass = @passages[event.tile_id]       # ???????
     next if pass & 0x10 == 0x10           # [?] : ????????
     return true if pass & flag == 0x00    # [?] : ???
     return false if pass & flag == flag   # [×] : ????
   end
   for i in [2, 1, 0]                      # ?????????????
     tile_id = @map.data[x, y, i]          # ??? ID ???
     return false if tile_id == nil        # ??? ID ???? : ????
     pass = @passages[tile_id]             # ???????
     next if pass & 0x10 == 0x10           # [?] : ????????
     return true if pass & flag == 0x00    # [?] : ???
     return false if pass & flag == flag   # [×] : ????
   end
   return false                            # ????
 end
 
 #--------------------------------------------------------------------------
 # Eventos en posición X e Y de la pantalla
 #--------------------------------------------------------------------------
 
 def screen_events_xy(x, y)
   result = []
   for event in @screen_events.values
     result.push(event) if event.pos?(x, y)
   end
   return result
 end
 
 #--------------------------------------------------------------------------
 # Actualiza los Eventos
 #--------------------------------------------------------------------------
 
 def update_events
   @screen_events.clear
   for k, event in @events
     next unless event.in_screen?
     @screen_events[k] = event
     event.update
   end
   for common_event in @common_events.values
     common_event.update
   end
 end
 
 #--------------------------------------------------------------------------
 # Actualiza los Vehículos
 #--------------------------------------------------------------------------
 
 def update_vehicles
   for vehicle in @vehicles
     next unless vehicle.in_screen?
     vehicle.update
   end
 end
 
end

#==============================================================================
# Spriteset_Map
#==============================================================================

class Spriteset_Map
 
 #--------------------------------------------------------------------------
 # Actualiza los Characters
 #--------------------------------------------------------------------------
 
 def update_characters
   for sprite in @character_sprites
     next if sprite.character.nil?
     next unless sprite.character.in_screen?
     sprite.update
   end
 end

end

end
[/SPOILER]

Instrucciones:
Funciona nada más instalarlo sobre Main, pero hay alguna cosilla que s epuede tocar en el script.

Aparte, se pueden configurar eventos para que se actualicen pese al efecto de este script. Es sencillo, coloca un comentario en el evento de nombre always_update.

Para finalizar, si hay algún problema con imágenes de evento muy grandes, haz igual igual que en el apartado anterior, pero escribiendo large_bitmap.

Créditos:
Script creado por PR Coders. Edited by Fegarur
0

Share this post


Link to post
Share on other sites
este script me iría genial si no fuera por que unos músico que tenían que estar sentados, y moviendose, empiezan a andar, mientras tocan.
y atraviesan la barrera que puse en medio para que no se movieran... llorar.gif
0

Share this post


Link to post
Share on other sites
Prueba a hacer que el antilag no les afecte. icon13.gif
0

Share this post


Link to post
Share on other sites
En esos eventos pon un comentario que diga always_update. icon13.gif
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0