防止事件过多卡机
作者
Near Fantastica
版本与更新
2005年12月
ver 3
相关网址
点此进入讨论贴
范例工程
脚本功能
防止事件卡机。介绍如下:
This script uses my view range script to limit which events are being updated... therefore a large map with lots of events 300 + can still run at 40 fps... this is probably not a final version as I can think of a few more ways to limit event lag...
“这个脚本用我的视野范围去限制刷新的事件,因此一个有300多个事件的大地图仍然可以运行在40的帧速率。这可能不是最后一个版本,我还在考虑更多的方法减少事件的拖慢”
使用方法
main前插入脚本即可
注意!只有屏幕内的事件才会刷新。自动事件请注意放的位置
其它
没什么了
--------------------------------------------------------------------------------
脚本内容
#======================================
# ■ Anti Event Lag Script
#======================================
# By: Near Fantastica
# Date: 12.06.05
# Version: 3
#======================================
#======================================
# ■ Game_Map
#======================================
class Game_Map
#--------------------------------------------------------------------------
def in_range?(object)
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 object.real_x <= screne_x
return false if object.real_x >= screne_width
return false if object.real_y <= screne_y
return false if object.real_y >= screne_height
return true
end
#--------------------------------------------------------------------------
def update
if $game_map.need_refresh
refresh
end
if @scroll_rest > 0
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
end
#======================================
# ■ Spriteset_Map
#======================================
class Spriteset_Map
#--------------------------------------------------------------------------
def in_range?(object)
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 object.real_x <= screne_x
return false if object.real_x >= screne_width
return false if object.real_y <= screne_y
return false if object.real_y >= screne_height
return true
end
#--------------------------------------------------------------------------
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
i=0
for sprite in @character_sprites
if sprite.character.is_a?(Game_Event)
if in_range?(sprite.character) or sprite.character.trigger == 3 or sprite.character.trigger == 4
sprite.update
i+=1
end
else
sprite.update
i+=1
end
end
#p i
@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
end
复制代码