Douglanilo
Mestre
Postagens : 959 Data de inscrição : 02/04/2009
| Assunto: Sistema Anti Lag Near Fantastica Dom Abr 05, 2009 12:44 pm | |
| Sistema Anti Lag Near Fantastica por Near Fantastica Introdução Script que reduz a lentidão do jogo em mapas com muitos eventos Características • Reduz a lentidão em mapas com muitos eventos • Os eventos devem estar espalhados no mapa para funcionar ScreenshotsNão possiu efeitos visuais perceptíveis por ScreenShots Como usarPara instalá-lo, apenas cole o script acima do main. DemoNão necessita de Demo Script - Código:
-
#=============================================================================== # * Sistema Anti Lag Near Fantastica #------------------------------------------------------------------------------- # f0tz!baerchen # 0.71 # 06.01.2007 #------------------------------------------------------------------------------- # JoaoNeto # 0.90 # 28.08.2007 #------------------------------------------------------------------------------- # Credits/Créditos: # Chaosg1 (for testing ;) ) # NearFantastica (for the Event AntiLag I used and improved) # JoaoNeto - Correção da Redundancia de atualização #------------------------------------------------------------------------------- #=============================================================================== #=============================================================================== # Class for Antilag Settings #=============================================================================== class Antilag_Settings attr_accessor :event attr_accessor :max_cpu_utilization attr_accessor :cpu_tolerance #----------------------------------------------------------------------------- # initializes default settings #----------------------------------------------------------------------------- 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 #----------------------------------------------------------------------------- # turns high priority on/off #----------------------------------------------------------------------------- def high_priority=(value) @high_priority = value if @high_priority @SetPriorityClass.call(-1, 0x00000080) # High Priority else @SetPriorityClass.call(-1, 0x00000020) # Normal Priority end end #----------------------------------------------------------------------------- # returns the current CPU Utilization #----------------------------------------------------------------------------- def get_cpu_utilization # uses API Call to get the Kernel and User Time 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) # converts times into integer (in 100ns) 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] # takes differences to calculate cpu utilization 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 # saves values (to calculate the differences, s.a.) @old_timer = Time.new @old_time = kernel_time user_time return result end end $antilag = Antilag_Settings.new #=============================================================================== # Scene_Map class #=============================================================================== class Scene_Map #----------------------------------------------------------------------------- # update method, smooth antilag has been added #----------------------------------------------------------------------------- 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 # calculates difference between max utilization and current utilization abs = $antilag.max_cpu_utilization - $antilag.get_cpu_utilization # changes Frame Rate if difference is bigger than the tolerance 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 #============================================================================== # Game_Event Class #=============================================================================== class Game_Event #----------------------------------------------------------------------------- # for AntiLag, decides, if an event is on the screen or not. #----------------------------------------------------------------------------- def in_range? # returns true if $event_antilag is false or the event is an # Autostart/Parallel Process event or it has an empty # comment in the first line 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 #----------------------------------------------------------------------------- # update method #----------------------------------------------------------------------------- alias f0tzis_anti_lag_game_event_update update def update return if not self.in_range? f0tzis_anti_lag_game_event_update end end #=============================================================================== # Sprite_Character Class #=============================================================================== class Sprite_Character < RPG::Sprite #----------------------------------------------------------------------------- # update method, parameters added for Loop_Map, rebuild for 8dirs #----------------------------------------------------------------------------- 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 #=============================================================================== # Settings #=============================================================================== $antilag.max_cpu_utilization = 70 # the maximum CPU utilization, the script # try to stay under this value during changing # changing the frame rate. The lower this # value the higher will be the lag reduction # (and the smoothness, too), a value > 100 # will disable this feature completely $antilag.cpu_tolerance = 20 # this value tells the script how many % of # the CPU utilization change should be ignored # If you change it too a higher value you, # your Frame Rate will be more constant but # smaller lags will be ignored. $antilag.high_priority = true # set this to true if you want the game to run # on high priority $antilag.event = true # set this to true to enable normal anti-lag #=============================================================================== # Game_Map Class #=============================================================================== class Game_Map def update # Atualizar o mapa se necessário if $game_map.need_refresh refresh end # Se estiver ocorrendo o scroll if @scroll_rest > 0 # Mudar da velocidade de scroll para as coordenadas de distância do mapa distance = 2 * @scroll_speed # Executar scroll case @scroll_direction when 2 # Baixo scroll_down(distance) when 4 # Esquerda scroll_left(distance) when 6 # Direita scroll_right(distance) when 8 # Cima scroll_up(distance) end # Subtrair a distância do scroll @scroll_rest -= distance end # Atualizar Evento do mapa for event in @events.values if in_range?(event) or event.trigger == 3 or event.trigger == 4 event.update end end # Atualizar Evento Comum do mapa for common_event in @common_events.values common_event.update end # Controlar scroll da Névoa @fog_ox -= @fog_sx / 8.0 @fog_oy -= @fog_sy / 8.0 # Controlar a mudança de cor de Névoa 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 # Controlar a mudança de nível de opacidade de Névoa 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 # size * tiles height = 128 * 19 # size * tiles return !((diff_x > width) or (diff_y > height)) end end #=============================================================================== # Spriteset_Map Class #=============================================================================== class Spriteset_Map def update # Se o Panorama for diferente do atual 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 # Se a Névoa for diferente da atual 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 # Atualizar o Tilemap @tilemap.ox = $game_map.display_x / 4 @tilemap.oy = $game_map.display_y / 4 @tilemap.update # Atualizar o plano do Panorama @panorama.ox = $game_map.display_x / 8 @panorama.oy = $game_map.display_y / 8 # Atualizar o plano da Névoa @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 # Atualizar os sprites dos Heróis for sprite in @character_sprites if in_range?(sprite.character) sprite.update end end # Atualizar o Clima @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 # Atualiza os sprites das Figuras for sprite in @picture_sprites sprite.update end # Atualiza o sprite do Temporizador @timer_sprite.update # Definir cor e tom do Tremor @viewport1.tone = $game_screen.tone @viewport1.ox = $game_screen.shake # Definir cor do Flash @viewport3.color = $game_screen.flash_color # Atualizar os pontos de vista @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 #=============================================================================== # Interpreter Class #=============================================================================== class Interpreter #----------------------------------------------------------------------------- # * Script #----------------------------------------------------------------------------- def command_355 # Set first line to script script = @list[@index].parameters[0] "\n" # Loop loop do # If next event command is second line of script or after if @list[@index 1].code == 655 # Add second line or after to script script = @list[@index 1].parameters[0] "\n" # If event command is not second line or after else # Abort loop break end # Advance index @index = 1 end # Evaluation result = eval(script) #--------------------------------------------------------------------------- # If return value is false # NEW: the last word of the code mustnt be false! #--------------------------------------------------------------------------- if result == false and script[script.length-6..script.length-2] != 'false' # End return false end # Continue return true end end
Perguntas FrequentesNenhuma Pergunta Frequente Créditos e Agradecimentos• Feito por Near Fantastica• Modificados por f0tz!baerchen e JoaoNeto• Formatação por Atoa• Postagem por Douglanilo
Última edição por Douglanilo em Sáb Ago 29, 2009 5:21 pm, editado 1 vez(es) |
|
Raygodness
Veterano
Postagens : 404 Data de inscrição : 04/04/2009 Localização : bragança paulista - SP Emprego/lazer : computadores Mensagem Pessoal : O que vem por trás, não é mole.
| Assunto: Re: Sistema Anti Lag Near Fantastica Ter Abr 14, 2009 1:36 pm | |
| muito util para quem usa muitos eventos |
|