Anti-Lag tbm acelera o jogo

    Compartilhe
    avatar
    zmarcelo
    Membro
    Membro

    Mensagens : 24
    Credibilidade : 4

    Anti-Lag tbm acelera o jogo

    Mensagem por zmarcelo em Qui Dez 29, 2011 5:03 pm

    Um simples Anti-lag que fiz.(tbm acelera o jogo para não da aquelas travadinhas)

    Spoiler:

    Código:

    ######################################################
    #Garet Anti-Lag #
    # #
    # #
    ######################################################



    class Antilag_Settings

    attr_accessor :event
    attr_accessor :max_cpu_utilization
    attr_accessor :cpu_tolerance

    def initialize
    @event = true
    @high_priority = true
    @max_cpu_utilization = 100
    @cpu_tolerance = 20
    @SetPriorityClass = Win32API.new('kernel32', 'SetPriorityClass',
    ['p', 'i'], 'i')
    @GetProcessTimes = Win32API.new('kernel32', 'GetProcessTimes',
    ['i','p','p','p','p'], 'i')
    end

    def high_priority=(value)
    @high_priority = value

    if @high_priority
    @SetPriorityClass.call(-1, 0x00000080)
    else
    @SetPriorityClass.call(-1, 0x00000020)
    end
    end

    def get_cpu_utilization

    creation_time = '0' * 10
    exit_time = '0' * 10
    kernel_time = '0' * 10
    user_time = '0' * 10
    @GetProcessTimes.call(-1, creation_time, exit_time, kernel_time, user_time)

    kernel_time = kernel_time.unpack('l2')
    user_time = user_time.unpack('l2')
    kernel_time = kernel_time[0] + kernel_time[1]
    user_time = user_time[0] + user_time[1]

    if @old_time != nil
    timer_difference = Time.new - @old_timer
    time_difference = kernel_time + user_time - @old_time
    result = time_difference / timer_difference / 100000
    else
    result = $antilag.max_cpu_utilization
    end

    @old_timer = Time.new
    @old_time = kernel_time + user_time
    return result
    end
    end
    $antilag = Antilag_Settings.new

    class Scene_Map

    alias f0tzis_anti_lag_scene_map_update update
    def update
    f0tzis_anti_lag_scene_map_update
    if Graphics.frame_count % 20 == 0 and $antilag.max_cpu_utilization <= 100

    utilization
    abs = $antilag.max_cpu_utilization - $antilag.get_cpu_utilization

    if abs.abs >= $antilag.max_cpu_utilization * $antilag.cpu_tolerance/100.0
    Graphics.frame_rate = [[10, Graphics.frame_rate + abs / 2].max, 40].min
    end
    end
    end
    end

    class Game_Event


    def in_range?


    if not $antilag.event or (@trigger == 3 or @trigger == 4 or
    (@list != nil and @list[0].code == 108 and @list[0].parameters == ['']))
    return true
    end

    screne_x = $game_map.display_x
    screne_x -= 256
    screne_y = $game_map.display_y
    screne_y -= 256
    screne_width = $game_map.display_x
    screne_width += 2816
    screne_height = $game_map.display_y
    screne_height += 2176

    return false if @real_x <= screne_x
    return false if @real_x >= screne_width
    return false if @real_y <= screne_y
    return false if @real_y >= screne_height
    return true

    end

    alias f0tzis_anti_lag_game_event_update update
    def update
    return if not self.in_range?
    f0tzis_anti_lag_game_event_update
    end

    end



    class Sprite_Character < RPG::Sprite

    alias f0tzis_anti_lag_sprite_char_update update
    def update
    return if @character.is_a?(Game_Event) and not @character.in_range?
    f0tzis_anti_lag_sprite_char_update
    end

    end

    $antilag.max_cpu_utilization = 70 the script

    $antilag.cpu_tolerance = 20

    $antilag.high_priority = true game to run

    $antilag.event = true

    class Game_Map
    def update

    if $game_map.need_refresh
    refresh
    end

    if @scroll_rest > 0
    do mapa
    distance = 2 ** @scroll_speed

    case @scroll_direction
    when 2
    scroll_down(distance)
    when 4
    scroll_left(distance)
    when 6
    scroll_right(distance)
    when 8
    scroll_up(distance)
    end

    @scroll_rest -= distance
    end

    for event in @events.values
    if in_range?(event) or event.trigger == 3 or event.trigger == 4
    event.update
    end
    end

    for common_event in @common_events.values
    common_event.update
    end

    @fog_ox -= @fog_sx / 8.0
    @fog_oy -= @fog_sy / 8.0

    if @fog_tone_duration >= 1
    d = @fog_tone_duration
    target = @fog_tone_target
    @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
    @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
    @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
    @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
    @fog_tone_duration -= 1
    end

    if @fog_opacity_duration >= 1
    d = @fog_opacity_duration
    @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
    @fog_opacity_duration -= 1
    end
    end
    def in_range?(object)
    diff_x = ($game_map.display_x - object.real_x).abs # absolute value
    diff_y = ($game_map.display_x - object.real_x).abs # absolute value
    width = 128 * 24
    height = 128 * 19
    return !((diff_x > width) or (diff_y > height))
    end
    end

    class Spriteset_Map
    def update

    if @panorama_name != $game_map.panorama_name or
    @panorama_hue != $game_map.panorama_hue
    @panorama_name = $game_map.panorama_name
    @panorama_hue = $game_map.panorama_hue
    if @panorama.bitmap != nil
    @panorama.bitmap.dispose
    @panorama.bitmap = nil
    end
    if @panorama_name != ""
    @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
    end
    Graphics.frame_reset
    end

    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
    @fog_name = $game_map.fog_name
    @fog_hue = $game_map.fog_hue
    if @fog.bitmap != nil
    @fog.bitmap.dispose
    @fog.bitmap = nil
    end
    if @fog_name != ""
    @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
    end
    Graphics.frame_reset
    end

    @tilemap.ox = $game_map.display_x / 4
    @tilemap.oy = $game_map.display_y / 4
    @tilemap.update

    @panorama.ox = $game_map.display_x / 8
    @panorama.oy = $game_map.display_y / 8

    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone

    for sprite in @character_sprites
    if in_range?(sprite.character)
    sprite.update
    end
    end

    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update

    for sprite in @picture_sprites
    sprite.update
    end

    @timer_sprite.update
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake

    @viewport3.color = $game_screen.flash_color

    @viewport1.update
    @viewport3.update
    end
    def in_range?(object)
    diff_x = ($game_player.real_x - object.real_x).abs # absolute value
    diff_y = ($game_player.real_y - object.real_y).abs # absolute value
    width = 128 * 24 # size * tiles
    height = 128 * 19 # size * tiles
    return !((diff_x > width) or (diff_y > height))
    end
    end

    class Interpreter

    def command_355

    script = @list[@index].parameters[0] + "\\\\\\\\n"

    loop do

    if @list[@index+1].code == 655

    script += @list[@index+1].parameters[0] + "\\\\\\\\n"

    else

    break
    end

    @index += 1
    end

    result = eval(script)

    if result == false and script[script.length-6..script.length-2] != 'false'

    return false
    end

    return true
    end
    end



    credirtos:
    Garet por criar
    zmarcelo por disponibilizar
    avatar
    Rhazik
    Membro
    Membro

    Mensagens : 12
    Credibilidade : 0

    Re: Anti-Lag tbm acelera o jogo

    Mensagem por Rhazik em Sex Dez 30, 2011 5:57 am

    Ei cara, mais esse anti-lag é compativel com modos de batalha ABS?
    Por que tem uns que trava mais ainda...

    Obg pela atenção.

      Data/hora atual: Dom Set 24, 2017 10:05 am